mirror of https://github.com/xqemu/xqemu.git
trace: Replace fprintf with error_report and print location
This replaces fprintf(stderr) with error_report. This moves local variables to the beginning of the function to comply with QEMU's coding style. Suggested-by: Lluís Vilanova <vilanova@ac.upc.edu> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
5b808275f3
commit
a35d9be622
|
@ -14,7 +14,7 @@
|
||||||
#ifdef CONFIG_TRACE_FTRACE
|
#ifdef CONFIG_TRACE_FTRACE
|
||||||
#include "trace/ftrace.h"
|
#include "trace/ftrace.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "qemu/error-report.h"
|
||||||
|
|
||||||
TraceEvent *trace_event_name(const char *name)
|
TraceEvent *trace_event_name(const char *name)
|
||||||
{
|
{
|
||||||
|
@ -100,18 +100,24 @@ void trace_print_events(FILE *stream, fprintf_function stream_printf)
|
||||||
|
|
||||||
static void trace_init_events(const char *fname)
|
static void trace_init_events(const char *fname)
|
||||||
{
|
{
|
||||||
|
Location loc;
|
||||||
|
FILE *fp;
|
||||||
|
char line_buf[1024];
|
||||||
|
size_t line_idx = 0;
|
||||||
|
|
||||||
if (fname == NULL) {
|
if (fname == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *fp = fopen(fname, "r");
|
loc_push_none(&loc);
|
||||||
|
loc_set_file(fname, 0);
|
||||||
|
fp = fopen(fname, "r");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
fprintf(stderr, "error: could not open trace events file '%s': %s\n",
|
error_report("%s", strerror(errno));
|
||||||
fname, strerror(errno));
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
char line_buf[1024];
|
|
||||||
while (fgets(line_buf, sizeof(line_buf), fp)) {
|
while (fgets(line_buf, sizeof(line_buf), fp)) {
|
||||||
|
loc_set_file(fname, ++line_idx);
|
||||||
size_t len = strlen(line_buf);
|
size_t len = strlen(line_buf);
|
||||||
if (len > 1) { /* skip empty lines */
|
if (len > 1) { /* skip empty lines */
|
||||||
line_buf[len - 1] = '\0';
|
line_buf[len - 1] = '\0';
|
||||||
|
@ -130,12 +136,10 @@ static void trace_init_events(const char *fname)
|
||||||
} else {
|
} else {
|
||||||
TraceEvent *ev = trace_event_name(line_ptr);
|
TraceEvent *ev = trace_event_name(line_ptr);
|
||||||
if (ev == NULL) {
|
if (ev == NULL) {
|
||||||
fprintf(stderr,
|
error_report("WARNING: trace event '%s' does not exist",
|
||||||
"WARNING: trace event '%s' does not exist\n",
|
|
||||||
line_ptr);
|
line_ptr);
|
||||||
} else if (!trace_event_get_state_static(ev)) {
|
} else if (!trace_event_get_state_static(ev)) {
|
||||||
fprintf(stderr,
|
error_report("WARNING: trace event '%s' is not traceable\n",
|
||||||
"WARNING: trace event '%s' is not traceable\n",
|
|
||||||
line_ptr);
|
line_ptr);
|
||||||
} else {
|
} else {
|
||||||
trace_event_set_state_dynamic(ev, enable);
|
trace_event_set_state_dynamic(ev, enable);
|
||||||
|
@ -144,10 +148,11 @@ static void trace_init_events(const char *fname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fclose(fp) != 0) {
|
if (fclose(fp) != 0) {
|
||||||
fprintf(stderr, "error: closing file '%s': %s\n",
|
loc_set_file(fname, 0);
|
||||||
fname, strerror(errno));
|
error_report("%s", strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
loc_pop(&loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool trace_init_backends(const char *events, const char *file)
|
bool trace_init_backends(const char *events, const char *file)
|
||||||
|
|
Loading…
Reference in New Issue