aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <swo-dev@marcschink.de>2015-07-15 22:19:45 +0200
committerMarc Schink <swo-dev@marcschink.de>2015-07-17 19:59:06 +0200
commit72ca2fee945c820b4a5a95efe3b700dea696be54 (patch)
tree58084383c1dc9ced3e4e87ffdd58791524a9aac7
parent70e145f9e1557f0223f0958b4f71e3be21a7fb99 (diff)
Improve log output.
-rw-r--r--src/dwt.c25
-rw-r--r--src/main.c31
2 files changed, 35 insertions, 21 deletions
diff --git a/src/dwt.c b/src/dwt.c
index 5649254..29dbe30 100644
--- a/src/dwt.c
+++ b/src/dwt.c
@@ -19,6 +19,7 @@
#include <stdio.h>
#include <stdint.h>
+#include <glib.h>
#include <libswo/libswo.h>
@@ -126,8 +127,8 @@ static void handle_evcnt_packet(const struct libswo_packet_hw *packet)
unsigned int cyc;
if (packet->size != EVCNT_SIZE) {
- printf("Event counter packet with invalid size of %zu bytes.\n",
- packet->size);
+ g_warning("Event counter packet with invalid size of "
+ "%zu bytes.", packet->size);
return;
}
@@ -172,8 +173,8 @@ static void handle_extrace_packet(const struct libswo_packet_hw *packet)
const char *func;
if (packet->size != EXTRACE_SIZE) {
- printf("Exception trace packet with invalid size of "
- "%zu bytes.\n", packet->size);
+ g_warning("Exception trace packet with invalid size of "
+ "%zu bytes.", packet->size);
return;
}
@@ -204,8 +205,8 @@ static void handle_pc_sample_packet(const struct libswo_packet_hw *packet)
{
if (packet->size == PC_SAMPLE_SLEEP_SIZE) {
if (packet->value > 0) {
- printf("Periodic PC sleep packet contains invalid "
- "value: %x.\n", packet->value);
+ g_warning("Periodic PC sleep packet contains invalid "
+ "value: %x.", packet->value);
return;
}
@@ -213,8 +214,8 @@ static void handle_pc_sample_packet(const struct libswo_packet_hw *packet)
} else if (packet->size == PC_SAMPLE_SIZE) {
printf("Periodic PC sample (value = %x)\n", packet->value);
} else {
- printf("Periodic PC sample packet with invalid size of "
- "%zu bytes.\n", packet->size);
+ g_warning("Periodic PC sample packet with invalid size of "
+ "%zu bytes.", packet->size);
}
}
@@ -223,8 +224,8 @@ static void handle_pc_value_packet(const struct libswo_packet_hw *packet)
unsigned int cmpn;
if (packet->size != PC_VALUE_SIZE) {
- printf("Data trace PC value packet with invalid size of "
- "%zu bytes.\n", packet->size);
+ g_warning("Data trace PC value packet with invalid size of "
+ "%zu bytes.", packet->size);
return;
}
@@ -239,8 +240,8 @@ static void handle_address_offset_packet(const struct libswo_packet_hw *packet)
unsigned int cmpn;
if (packet->size != ADDR_OFFSET_SIZE) {
- printf("Data trace address offset packet with invalid size of "
- "%zu bytes.\n", packet->size);
+ g_warning("Data trace address offset packet with invalid size "
+ "of %zu bytes.", packet->size);
return;
}
diff --git a/src/main.c b/src/main.c
index 710db7d..35f21d2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -387,7 +387,7 @@ static int parse_options(int *argc, char ***argv)
g_option_context_add_main_entries(context, entries, NULL);
if (!g_option_context_parse(context, argc, argv, &error)) {
- g_critical("%s.\n", error->message);
+ g_critical("%s.", error->message);
g_error_free(error);
g_option_context_free(context);
return FALSE;
@@ -398,6 +398,17 @@ static int parse_options(int *argc, char ***argv)
return TRUE;
}
+void log_handler(const gchar *domain, GLogLevelFlags level,
+ const gchar *message, gpointer user_data)
+{
+ (void)domain;
+ (void)level;
+ (void)user_data;
+
+ fprintf(stderr, "%s\n", message);
+ fflush(stderr);
+}
+
int main(int argc, char **argv)
{
int ret;
@@ -408,6 +419,8 @@ int main(int argc, char **argv)
GIOStatus iostat;
gsize num;
+ g_log_set_default_handler(&log_handler, NULL);
+
opt_version = FALSE;
opt_dump_inst = FALSE;
opt_decode_dwt = FALSE;
@@ -443,7 +456,7 @@ int main(int argc, char **argv)
input = g_io_channel_new_file(input_file, "r", &error);
if (!input) {
- g_critical("%s: %s.\n", input_file, error->message);
+ g_critical("%s: %s.", input_file, error->message);
g_error_free(error);
g_free(input_file);
return EXIT_FAILURE;
@@ -458,7 +471,7 @@ int main(int argc, char **argv)
iostat = g_io_channel_set_encoding(input, NULL, &error);
if (iostat != G_IO_STATUS_NORMAL) {
- g_critical("%s.\n", error->message);
+ g_critical("%s.", error->message);
g_error_free(error);
g_io_channel_unref(input);
return EXIT_FAILURE;
@@ -469,7 +482,7 @@ int main(int argc, char **argv)
ret = libswo_init(&ctx, NULL, BUFFER_SIZE * 2);
if (ret != LIBSWO_OK) {
- g_critical("libswo_init() failed: %s.\n",
+ g_critical("libswo_init() failed: %s.",
libswo_strerror_name(ret));
g_io_channel_unref(input);
return EXIT_FAILURE;
@@ -478,7 +491,7 @@ int main(int argc, char **argv)
ret = libswo_set_callback(ctx, &packet_cb, NULL);
if (ret != LIBSWO_OK) {
- g_critical("libswo_set_callback() failed: %s.\n",
+ g_critical("libswo_set_callback() failed: %s.",
libswo_strerror_name(ret));
g_io_channel_unref(input);
libswo_exit(ctx);
@@ -495,7 +508,7 @@ int main(int argc, char **argv)
ret = libswo_feed(ctx, buffer, num);
if (ret != LIBSWO_OK) {
- g_critical("libswo_feed() failed: %s.\n",
+ g_critical("libswo_feed() failed: %s.",
libswo_strerror_name(ret));
g_io_channel_unref(input);
libswo_exit(ctx);
@@ -505,7 +518,7 @@ int main(int argc, char **argv)
ret = libswo_decode(ctx, 0, 0);
if (ret < LIBSWO_OK) {
- g_critical("libswo_decode() failed: %s.\n",
+ g_critical("libswo_decode() failed: %s.",
libswo_strerror_name(ret));
g_io_channel_unref(input);
libswo_exit(ctx);
@@ -517,7 +530,7 @@ int main(int argc, char **argv)
}
if (iostat == G_IO_STATUS_ERROR) {
- g_critical("%s.\n", error->message);
+ g_critical("%s.", error->message);
g_error_free(error);
g_io_channel_unref(input);
libswo_exit(ctx);
@@ -527,7 +540,7 @@ int main(int argc, char **argv)
ret = libswo_decode(ctx, 0, LIBSWO_DF_EOS);
if (ret < LIBSWO_OK) {
- g_critical("libswo_decode() failed: %s.\n",
+ g_critical("libswo_decode() failed: %s.",
libswo_strerror_name(ret));
g_io_channel_unref(input);
libswo_exit(ctx);