From patchwork Wed Jun 11 14:29:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 31774 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f198.google.com (mail-pd0-f198.google.com [209.85.192.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 20A3E2054B for ; Wed, 11 Jun 2014 14:36:13 +0000 (UTC) Received: by mail-pd0-f198.google.com with SMTP id w10sf18076483pde.5 for ; Wed, 11 Jun 2014 07:36:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=KImE8uyOUuiiHXkPaBFW2luC7hXTs1c0QGOwjnZ2/Do=; b=bTfe3fQkq2kyQ4H8D9MkDPwUogjoyX06zPAhVu8rp0e4TVB4OT7Zzsutw5p2Ehk/9l 58Uv8eYJRsy9bz6Yh5Dnu6UZiXtcuC7L4HphlTnz3qxHFGewWLcCAVK5xys9ipMcmXIh ZEXuZd8L68qxT8Y924wTyDW3oo/TEweZlDz3OtmyjaXrdWMW7Y0o+Gg2z3M8txkXhu9G CBVuPWeWQ6QKGhbyI2Sxr90DvrnIXbs2m+QZadADZ8JiOY4/ESfJdrkxP/0AuJC1DrZa PlOb0xnfYSKBnnZ6BIYRMevsUf93EtqQ4ZozuMAUdqevYzUWGaPyKrXwOlqfPT222LLG OZyw== X-Gm-Message-State: ALoCoQlun5ieEGUKlU4b0gQBj97ecOv0LcY+WL63UwohwLZN+cNPoUFxx3vLUrIPtxT8s93B09z+ X-Received: by 10.66.142.9 with SMTP id rs9mr3301869pab.47.1402497373339; Wed, 11 Jun 2014 07:36:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.23.7 with SMTP id 7ls2703666qgo.60.gmail; Wed, 11 Jun 2014 07:36:13 -0700 (PDT) X-Received: by 10.58.74.164 with SMTP id u4mr94549vev.81.1402497372631; Wed, 11 Jun 2014 07:36:12 -0700 (PDT) Received: from mail-ve0-f170.google.com (mail-ve0-f170.google.com [209.85.128.170]) by mx.google.com with ESMTPS id so6si14251389vdb.76.2014.06.11.07.36.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Jun 2014 07:36:12 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.170 as permitted sender) client-ip=209.85.128.170; Received: by mail-ve0-f170.google.com with SMTP id oz11so6504979veb.1 for ; Wed, 11 Jun 2014 07:36:12 -0700 (PDT) X-Received: by 10.52.190.138 with SMTP id gq10mr2697406vdc.47.1402497372530; Wed, 11 Jun 2014 07:36:12 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.54.6 with SMTP id vs6csp308803vcb; Wed, 11 Jun 2014 07:36:12 -0700 (PDT) X-Received: by 10.229.239.197 with SMTP id kx5mr46720800qcb.14.1402497372020; Wed, 11 Jun 2014 07:36:12 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id r10si31668801qad.65.2014.06.11.07.36.11 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 11 Jun 2014 07:36:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:46867 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WujdL-00045S-J3 for patch@linaro.org; Wed, 11 Jun 2014 10:36:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WujXS-0004qf-0X for qemu-devel@nongnu.org; Wed, 11 Jun 2014 10:30:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WujXQ-0008La-8k for qemu-devel@nongnu.org; Wed, 11 Jun 2014 10:30:05 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:48600) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WujXP-0008DN-Vp for qemu-devel@nongnu.org; Wed, 11 Jun 2014 10:30:04 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WujXG-00075q-07; Wed, 11 Jun 2014 15:29:54 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Wed, 11 Jun 2014 15:29:47 +0100 Message-Id: <1402496993-27206-10-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1402496993-27206-1-git-send-email-peter.maydell@linaro.org> References: <1402496993-27206-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: Blue Swirl Subject: [Qemu-devel] [PULL 09/15] bsd-user: GPL v2 attribution update and style X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Sean Bruno Signed-off-by: Sean Bruno Message-id: 1402246651-71099-3-git-send-email-sbruno@freebsd.org Signed-off-by: Peter Maydell --- bsd-user/qemu.h | 26 +++++++++++ bsd-user/strace.c | 126 +++++++++++++++++++++++++++++------------------------- 2 files changed, 94 insertions(+), 58 deletions(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 9d90668..5362297 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -1,3 +1,19 @@ +/* + * qemu bsd user mode definition + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ #ifndef QEMU_H #define QEMU_H @@ -150,6 +166,16 @@ void fork_end(int child); #include "qemu/log.h" /* strace.c */ +struct syscallname { + int nr; + const char *name; + const char *format; + void (*call)(const struct syscallname *, + abi_long, abi_long, abi_long, + abi_long, abi_long, abi_long); + void (*result)(const struct syscallname *, abi_long); +}; + void print_freebsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3, diff --git a/bsd-user/strace.c b/bsd-user/strace.c index d73bbca..47e5e76 100644 --- a/bsd-user/strace.c +++ b/bsd-user/strace.c @@ -1,37 +1,49 @@ +/* + * System call tracing and debugging + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + #include #include #include #include #include #include -#include "qemu.h" +#include +#include -int do_strace=0; +#include "qemu.h" -struct syscallname { - int nr; - const char *name; - const char *format; - void (*call)(const struct syscallname *, - abi_long, abi_long, abi_long, - abi_long, abi_long, abi_long); - void (*result)(const struct syscallname *, abi_long); -}; +int do_strace; /* * Utility functions */ -static void -print_execve(const struct syscallname *name, - abi_long arg1, abi_long arg2, abi_long arg3, - abi_long arg4, abi_long arg5, abi_long arg6) +static void print_execve(const struct syscallname *name, abi_long arg1, + abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, + abi_long arg6) { abi_ulong arg_ptr_addr; char *s; - if (!(s = lock_user_string(arg1))) + s = lock_user_string(arg1); + if (s == NULL) { return; + } gemu_log("%s(\"%s\",{", name->name, s); unlock_user(s, arg1, 0); @@ -39,18 +51,19 @@ print_execve(const struct syscallname *name, abi_ulong *arg_ptr, arg_addr; arg_ptr = lock_user(VERIFY_READ, arg_ptr_addr, sizeof(abi_ulong), 1); - if (!arg_ptr) + if (!arg_ptr) { return; + } arg_addr = tswapl(*arg_ptr); unlock_user(arg_ptr, arg_ptr_addr, 0); - if (!arg_addr) + if (!arg_addr) { break; + } if ((s = lock_user_string(arg_addr))) { gemu_log("\"%s\",", s); unlock_user(s, arg_addr, 0); } } - gemu_log("NULL})"); } @@ -58,10 +71,9 @@ print_execve(const struct syscallname *name, * Variants for the return value output function */ -static void -print_syscall_ret_addr(const struct syscallname *name, abi_long ret) +static void print_syscall_ret_addr(const struct syscallname *name, abi_long ret) { -if( ret == -1 ) { + if (ret == -1) { gemu_log(" = -1 errno=%d (%s)\n", errno, strerror(errno)); } else { gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret); @@ -90,10 +102,9 @@ static const struct syscallname openbsd_scnames[] = { #include "openbsd/strace.list" }; -static void -print_syscall(int num, const struct syscallname *scnames, unsigned int nscnames, - abi_long arg1, abi_long arg2, abi_long arg3, - abi_long arg4, abi_long arg5, abi_long arg6) +static void print_syscall(int num, const struct syscallname *scnames, + unsigned int nscnames, abi_long arg1, abi_long arg2, abi_long arg3, + abi_long arg4, abi_long arg5, abi_long arg6) { unsigned int i; const char *format="%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," @@ -102,36 +113,37 @@ print_syscall(int num, const struct syscallname *scnames, unsigned int nscnames, gemu_log("%d ", getpid() ); - for (i = 0; i < nscnames; i++) + for (i = 0; i < nscnames; i++) { if (scnames[i].nr == num) { if (scnames[i].call != NULL) { scnames[i].call(&scnames[i], arg1, arg2, arg3, arg4, arg5, - arg6); + arg6); } else { /* XXX: this format system is broken because it uses host types and host pointers for strings */ - if (scnames[i].format != NULL) + if (scnames[i].format != NULL) { format = scnames[i].format; - gemu_log(format, scnames[i].name, arg1, arg2, arg3, arg4, - arg5, arg6); + } + gemu_log(format, scnames[i].name, arg1, arg2, arg3, arg4, arg5, + arg6); } return; } + } gemu_log("Unknown syscall %d\n", num); } -static void -print_syscall_ret(int num, abi_long ret, const struct syscallname *scnames, - unsigned int nscnames) +static void print_syscall_ret(int num, abi_long ret, + const struct syscallname *scnames, unsigned int nscnames) { unsigned int i; - for (i = 0; i < nscnames; i++) + for (i = 0; i < nscnames; i++) { if (scnames[i].nr == num) { if (scnames[i].result != NULL) { scnames[i].result(&scnames[i], ret); } else { - if( ret < 0 ) { + if (ret < 0) { gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n", -ret, strerror(-ret)); } else { @@ -140,52 +152,50 @@ print_syscall_ret(int num, abi_long ret, const struct syscallname *scnames, } break; } + } } /* * The public interface to this module. */ -void -print_freebsd_syscall(int num, - abi_long arg1, abi_long arg2, abi_long arg3, - abi_long arg4, abi_long arg5, abi_long arg6) +void print_freebsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3, + abi_long arg4, abi_long arg5, abi_long arg6) { - print_syscall(num, freebsd_scnames, ARRAY_SIZE(freebsd_scnames), - arg1, arg2, arg3, arg4, arg5, arg6); + + print_syscall(num, freebsd_scnames, ARRAY_SIZE(freebsd_scnames), arg1, arg2, + arg3, arg4, arg5, arg6); } -void -print_freebsd_syscall_ret(int num, abi_long ret) +void print_freebsd_syscall_ret(int num, abi_long ret) { + print_syscall_ret(num, ret, freebsd_scnames, ARRAY_SIZE(freebsd_scnames)); } -void -print_netbsd_syscall(int num, - abi_long arg1, abi_long arg2, abi_long arg3, - abi_long arg4, abi_long arg5, abi_long arg6) +void print_netbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3, + abi_long arg4, abi_long arg5, abi_long arg6) { + print_syscall(num, netbsd_scnames, ARRAY_SIZE(netbsd_scnames), arg1, arg2, arg3, arg4, arg5, arg6); } -void -print_netbsd_syscall_ret(int num, abi_long ret) +void print_netbsd_syscall_ret(int num, abi_long ret) { + print_syscall_ret(num, ret, netbsd_scnames, ARRAY_SIZE(netbsd_scnames)); } -void -print_openbsd_syscall(int num, - abi_long arg1, abi_long arg2, abi_long arg3, - abi_long arg4, abi_long arg5, abi_long arg6) +void print_openbsd_syscall(int num, abi_long arg1, abi_long arg2, abi_long arg3, + abi_long arg4, abi_long arg5, abi_long arg6) { - print_syscall(num, openbsd_scnames, ARRAY_SIZE(openbsd_scnames), - arg1, arg2, arg3, arg4, arg5, arg6); + + print_syscall(num, openbsd_scnames, ARRAY_SIZE(openbsd_scnames), arg1, arg2, + arg3, arg4, arg5, arg6); } -void -print_openbsd_syscall_ret(int num, abi_long ret) +void print_openbsd_syscall_ret(int num, abi_long ret) { + print_syscall_ret(num, ret, openbsd_scnames, ARRAY_SIZE(openbsd_scnames)); }