linux-user: Use `qemu_log' for strace

This change switches linux-user strace logging to use the newer `qemu_log`
logging subsystem rather than the older `gemu_log` (notice the "g")
logger. `qemu_log` has several advantages, namely that it allows logging
to a file, and provides a more unified interface for configuration
of logging (via the QEMU_LOG environment variable or options).

This change introduces a new log mask: `LOG_STRACE` which is used for
logging of user-mode strace messages.

Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Josh Kunz <jkz@google.com>
Message-Id: <20200204025416.111409-3-jkz@google.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
master
Josh Kunz 2020-02-03 18:54:14 -08:00 committed by Laurent Vivier
parent 39be535008
commit 4b25a50674
7 changed files with 278 additions and 251 deletions

View File

@ -62,6 +62,8 @@ static inline bool qemu_log_separate(void)
#define CPU_LOG_TB_OP_IND (1 << 16)
#define CPU_LOG_TB_FPU (1 << 17)
#define CPU_LOG_PLUGIN (1 << 18)
/* LOG_STRACE is used for user-mode strace logging. */
#define LOG_STRACE (1 << 19)
/* Lock output for a series of related logs. Since this is not needed
* for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we

View File

@ -60,6 +60,19 @@ unsigned long mmap_min_addr;
unsigned long guest_base;
int have_guest_base;
/*
* Used to implement backwards-compatibility for the `-strace`, and
* QEMU_STRACE options. Without this, the QEMU_LOG can be overwritten by
* -strace, or vice versa.
*/
static bool enable_strace;
/*
* The last log mask given by the user in an environment variable or argument.
* Used to support command line arguments overriding environment variables.
*/
static int last_log_mask;
/*
* When running 32-on-64 we should make sure we can fit all of the possible
* guest address space into a contiguous chunk of virtual host memory.
@ -223,15 +236,11 @@ static void handle_arg_help(const char *arg)
static void handle_arg_log(const char *arg)
{
int mask;
mask = qemu_str_to_log_mask(arg);
if (!mask) {
last_log_mask = qemu_str_to_log_mask(arg);
if (!last_log_mask) {
qemu_print_log_usage(stdout);
exit(EXIT_FAILURE);
}
qemu_log_needs_buffers();
qemu_set_log(mask);
}
static void handle_arg_dfilter(const char *arg)
@ -375,7 +384,7 @@ static void handle_arg_singlestep(const char *arg)
static void handle_arg_strace(const char *arg)
{
do_strace = 1;
enable_strace = true;
}
static void handle_arg_version(const char *arg)
@ -629,6 +638,7 @@ int main(int argc, char **argv, char **envp)
int i;
int ret;
int execfd;
int log_mask;
unsigned long max_reserved_va;
error_init(argv[0]);
@ -661,6 +671,12 @@ int main(int argc, char **argv, char **envp)
optind = parse_args(argc, argv);
log_mask = last_log_mask | (enable_strace ? LOG_STRACE : 0);
if (log_mask) {
qemu_log_needs_buffers();
qemu_set_log(log_mask);
}
if (!trace_init_backends()) {
exit(1);
}

View File

@ -386,7 +386,6 @@ void print_syscall_ret(int num, abi_long arg1);
* --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
*/
void print_taken_signal(int target_signum, const target_siginfo_t *tinfo);
extern int do_strace;
/* signal.c */
void process_pending_signals(CPUArchState *cpu_env);

View File

@ -934,7 +934,7 @@ static void handle_pending_signal(CPUArchState *cpu_env, int sig,
handler = sa->_sa_handler;
}
if (do_strace) {
if (unlikely(qemu_loglevel_mask(LOG_STRACE))) {
print_taken_signal(sig, &k->info);
}

File diff suppressed because it is too large Load Diff

View File

@ -12171,14 +12171,15 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
record_syscall_start(cpu, num, arg1,
arg2, arg3, arg4, arg5, arg6, arg7, arg8);
if (unlikely(do_strace)) {
if (unlikely(qemu_loglevel_mask(LOG_STRACE))) {
print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
ret = do_syscall1(cpu_env, num, arg1, arg2, arg3, arg4,
arg5, arg6, arg7, arg8);
}
ret = do_syscall1(cpu_env, num, arg1, arg2, arg3, arg4,
arg5, arg6, arg7, arg8);
if (unlikely(qemu_loglevel_mask(LOG_STRACE))) {
print_syscall_ret(num, ret);
} else {
ret = do_syscall1(cpu_env, num, arg1, arg2, arg3, arg4,
arg5, arg6, arg7, arg8);
}
record_syscall_return(cpu, num, ret);

View File

@ -332,6 +332,8 @@ const QEMULogItem qemu_log_items[] = {
#ifdef CONFIG_PLUGIN
{ CPU_LOG_PLUGIN, "plugin", "output from TCG plugins\n"},
#endif
{ LOG_STRACE, "strace",
"log every user-mode syscall, its input, and its result" },
{ 0, NULL, NULL },
};