diff mbox

[2/2] linux-user: Add -stracefile to log strace elsewhere than stderr

Message ID 1338493043-31206-3-git-send-email-rth@twiddle.net
State New
Headers show

Commit Message

Richard Henderson May 31, 2012, 7:37 p.m. UTC
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 linux-user/main.c |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)

Comments

Peter Maydell June 1, 2012, 12:49 a.m. UTC | #1
On 31 May 2012 20:37, Richard Henderson <rth@twiddle.net> wrote:
>  void gemu_log(const char *fmt, ...)
>  {
>     va_list ap;
>
>     va_start(ap, fmt);
> -    vfprintf(stderr, fmt, ap);
> +    vfprintf(strace_log_file, fmt, ap);
>     va_end(ap);
>  }

gemu_log() is used for more than just strace output... are
we happy for the various other random error messages to go
to the "strace log" file too?

-- PMM
Riku Voipio June 1, 2012, 2:12 a.m. UTC | #2
On Fri, Jun 01, 2012 at 01:49:26AM +0100, Peter Maydell wrote:
> On 31 May 2012 20:37, Richard Henderson <rth@twiddle.net> wrote:
> >  void gemu_log(const char *fmt, ...)
> >  {
> >     va_list ap;
> >
> >     va_start(ap, fmt);
> > -    vfprintf(stderr, fmt, ap);
> > +    vfprintf(strace_log_file, fmt, ap);
> >     va_end(ap);
> >  }
 
> gemu_log() is used for more than just strace output... are
> we happy for the various other random error messages to go
> to the "strace log" file too?

Perhaps it would make more sense to introduce a "-d strace" loglevel
and use the standard qemu_log feature? Then the output file would be
set with the -D option.

Riku
diff mbox

Patch

diff --git a/linux-user/main.c b/linux-user/main.c
index f507a32..c728253 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -73,12 +73,14 @@  const char *qemu_uname_release = CONFIG_UNAME_RELEASE;
    by remapping the process stack directly at the right place */
 unsigned long guest_stack_size = 8 * 1024 * 1024UL;
 
+static FILE *strace_log_file;
+
 void gemu_log(const char *fmt, ...)
 {
     va_list ap;
 
     va_start(ap, fmt);
-    vfprintf(stderr, fmt, ap);
+    vfprintf(strace_log_file, fmt, ap);
     va_end(ap);
 }
 
@@ -3120,6 +3122,18 @@  static void handle_arg_strace(const char *arg)
     do_strace = 1;
 }
 
+static void handle_arg_strace_filename(const char *arg)
+{
+    do_strace = 1;
+    if (strace_log_file != NULL) {
+        fclose(strace_log_file);
+    }
+    strace_log_file = fopen(arg, "w");
+    if (strace_log_file != NULL) {
+        setbuf(strace_log_file, NULL);
+    }
+}
+
 static void handle_arg_version(const char *arg)
 {
     printf("qemu-" TARGET_ARCH " version " QEMU_VERSION QEMU_PKGVERSION
@@ -3171,6 +3185,8 @@  struct qemu_argument arg_table[] = {
      "",           "run in singlestep mode"},
     {"strace",     "QEMU_STRACE",      false, handle_arg_strace,
      "",           "log system calls"},
+    {"stracefile", "QEMU_STRACEFILE",  true,  handle_arg_strace_filename,
+     "",           "log system calls to file"},
     {"version",    "QEMU_VERSION",     false, handle_arg_version,
      "",           "display version information and exit"},
     {NULL, NULL, false, NULL, NULL, NULL}
@@ -3351,6 +3367,9 @@  int main(int argc, char **argv, char **envp)
     /* init debug */
     cpu_set_log_filename(log_file);
     optind = parse_args(argc, argv);
+    if (do_strace && strace_log_file == NULL) {
+        strace_log_file = stderr;
+    }
 
     /* Zero out regs */
     memset(regs, 0, sizeof(struct target_pt_regs));
@@ -3413,10 +3432,6 @@  int main(int argc, char **argv, char **envp)
 
     thread_env = env;
 
-    if (getenv("QEMU_STRACE")) {
-        do_strace = 1;
-    }
-
     target_environ = envlist_to_environ(envlist, NULL);
     envlist_free(envlist);