@@ -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);
Signed-off-by: Richard Henderson <rth@twiddle.net> --- linux-user/main.c | 25 ++++++++++++++++++++----- 1 files changed, 20 insertions(+), 5 deletions(-)