diff mbox

[1/2] trace: [linux-user] Commandline arguments to control tracing

Message ID 146651541133.29362.6693427750748986464.stgit@fimbulvetr.bsc.es
State New
Headers show

Commit Message

Lluís Vilanova June 21, 2016, 1:23 p.m. UTC
Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 linux-user/main.c |   28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Comments

Eric Blake June 21, 2016, 10:08 p.m. UTC | #1
On 06/21/2016 07:23 AM, Lluís Vilanova wrote:
> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
> ---
>  linux-user/main.c |   28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 

> +    {"trace-enable", "QEMU_TRACE_ENABLE",true,  handle_arg_trace_enable,
> +     "name",       "enable tracing of specified event names (pass '?' to show a list of events)"},

? is a shell metacharacter, and it requires quoting to be safe against
globbing against any single-letter files in the current directory.  A
better suggestion would be to pass 'help' to show a list of events.
Lluís Vilanova June 22, 2016, 9:53 a.m. UTC | #2
Eric Blake writes:

> On 06/21/2016 07:23 AM, Lluís Vilanova wrote:
>> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
>> ---
>> linux-user/main.c |   28 ++++++++++++++++++++++++++++
>> 1 file changed, 28 insertions(+)
>> 

>> +    {"trace-enable", "QEMU_TRACE_ENABLE",true,  handle_arg_trace_enable,
>> +     "name",       "enable tracing of specified event names (pass '?' to show a list of events)"},

> ? is a shell metacharacter, and it requires quoting to be safe against
> globbing against any single-letter files in the current directory.  A
> better suggestion would be to pass 'help' to show a list of events.

Right. The code internally uses 'is_help_option()' (also used by "-trace
enable=" and "-cpu" in vl.c), which accepts both '?' and 'help'. I'll just cite
using 'help' (even if both are accepted).

Thanks,
  Lluis
diff mbox

Patch

diff --git a/linux-user/main.c b/linux-user/main.c
index f8a8764..b0d7d2b 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -33,6 +33,7 @@ 
 #include "qemu/envlist.h"
 #include "elf.h"
 #include "exec/log.h"
+#include "trace/control.h"
 
 char *exec_path;
 
@@ -4000,6 +4001,22 @@  static void handle_arg_version(const char *arg)
     exit(EXIT_SUCCESS);
 }
 
+static void handle_arg_trace_enable(const char *arg)
+{
+    trace_enable_events(arg);
+}
+
+static void handle_arg_trace_events(const char *arg)
+{
+    trace_init_events(arg);
+}
+
+static const char *trace_file = NULL;
+static void handle_arg_trace_file(const char *arg)
+{
+    trace_file = arg;
+}
+
 struct qemu_argument {
     const char *argv;
     const char *env;
@@ -4047,6 +4064,12 @@  static const struct qemu_argument arg_table[] = {
      "",           "log system calls"},
     {"seed",       "QEMU_RAND_SEED",   true,  handle_arg_randseed,
      "",           "Seed for pseudo-random number generator"},
+    {"trace-enable", "QEMU_TRACE_ENABLE",true,  handle_arg_trace_enable,
+     "name",       "enable tracing of specified event names (pass '?' to show a list of events)"},
+    {"trace-events", "QEMU_TRACE_EVENTS",true,  handle_arg_trace_events,
+     "eventsfile", "enable tracing of specified event names (one name/pattern per line)"},
+    {"trace-file", "QEMU_TRACE_FILE",  true,  handle_arg_trace_file,
+     "tracefile",  "output trace file"},
     {"version",    "QEMU_VERSION",     false, handle_arg_version,
      "",           "display version information and exit"},
     {NULL, NULL, false, NULL, NULL, NULL}
@@ -4238,6 +4261,11 @@  int main(int argc, char **argv, char **envp)
 
     optind = parse_args(argc, argv);
 
+    if (!trace_init_backends()) {
+        exit(1);
+    }
+    trace_init_file(trace_file);
+
     /* Zero out regs */
     memset(regs, 0, sizeof(struct target_pt_regs));