From patchwork Sat Aug 17 06:29:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 267960 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B0E652C0134 for ; Sat, 17 Aug 2013 16:31:14 +1000 (EST) Received: from localhost ([::1]:34672 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VAa2a-0000bx-Rz for incoming@patchwork.ozlabs.org; Sat, 17 Aug 2013 02:31:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53650) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VAa20-0000Xu-G0 for qemu-devel@nongnu.org; Sat, 17 Aug 2013 02:30:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VAa1m-0002HC-IQ for qemu-devel@nongnu.org; Sat, 17 Aug 2013 02:30:36 -0400 Received: from mail-qc0-x22b.google.com ([2607:f8b0:400d:c01::22b]:34943) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VAa1m-0002H4-En for qemu-devel@nongnu.org; Sat, 17 Aug 2013 02:30:22 -0400 Received: by mail-qc0-f171.google.com with SMTP id n1so1556822qcw.30 for ; Fri, 16 Aug 2013 23:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=7DYdv8pX8YBPILy9AM/d1g15bv4+obPodM4WbdTWnzo=; b=TBK3eQlTH6AaA/L/83lpAsiIuOA3w4JKFVS6gnwpB7yZSxZIOYnlRJVCnm2Msak/+l nTVV9z6ftgg+67+qZ7s7oi4C6tiZFlFroJt66L9iqJCJOcq9HIH4iGJHvdSYkPDDIDx5 R91sKrRYJEJi6Gll7MZLzBlqlNcPypnZPKzbH+h0e7UEoyp7eUsTR4JPFJYbH4DebC7e xMkwI5IyarHd4NBDGmX4dLKNBZBLA6u8nGC2eb/tvacNA0IH1OrZdh0joLe+hPlH3vXE 9TexJId5MfwKAhYdVkY+vMPKxHoB9WjelwmsHdzKc+rRXOsO3h66NobNHId8vkWmqGQu MCUQ== X-Received: by 10.49.81.237 with SMTP id d13mr1637257qey.44.1376721022091; Fri, 16 Aug 2013 23:30:22 -0700 (PDT) Received: from anchor.com (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPSA id h6sm1873236qej.4.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 16 Aug 2013 23:30:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 16 Aug 2013 23:29:45 -0700 Message-Id: <1376720987-2576-2-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1376720987-2576-1-git-send-email-rth@twiddle.net> References: <1376720987-2576-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c01::22b Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH v2 1/3] disas: Implement fallback to dump object code as hex 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The OBJD-[HT] tags will be used by a script to run the hex blob through objdump --disassemble. Signed-off-by: Richard Henderson --- disas.c | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/disas.c b/disas.c index 71007fb..0203ef2 100644 --- a/disas.c +++ b/disas.c @@ -158,6 +158,35 @@ print_insn_thumb1(bfd_vma pc, disassemble_info *info) } #endif +static int print_insn_objdump(bfd_vma pc, disassemble_info *info, + const char *prefix) +{ + int i, n = info->buffer_length; + uint8_t *buf = g_malloc(n); + + info->read_memory_func(pc, buf, n, info); + + for (i = 0; i < n; ++i) { + if (i % 32 == 0) { + info->fprintf_func(info->stream, "\n%s: ", prefix); + } + info->fprintf_func(info->stream, "%02x", buf[i]); + } + + g_free(buf); + return n; +} + +static int print_insn_od_host(bfd_vma pc, disassemble_info *info) +{ + return print_insn_objdump(pc, info, "OBJD-H"); +} + +static int print_insn_od_target(bfd_vma pc, disassemble_info *info) +{ + return print_insn_objdump(pc, info, "OBJD-T"); +} + /* Disassemble this for me please... (debugging). 'flags' has the following values: i386 - 1 means 16 bit code, 2 means 64 bit code @@ -171,7 +200,7 @@ void target_disas(FILE *out, CPUArchState *env, target_ulong code, target_ulong pc; int count; CPUDebug s; - int (*print_insn)(bfd_vma pc, disassemble_info *info); + int (*print_insn)(bfd_vma pc, disassemble_info *info) = NULL; INIT_DISASSEMBLE_INFO(s.info, out, fprintf); @@ -263,11 +292,10 @@ void target_disas(FILE *out, CPUArchState *env, target_ulong code, #elif defined(TARGET_LM32) s.info.mach = bfd_mach_lm32; print_insn = print_insn_lm32; -#else - fprintf(out, "0x" TARGET_FMT_lx - ": Asm output not supported on this arch\n", code); - return; #endif + if (print_insn == NULL) { + print_insn = print_insn_od_target; + } for (pc = code; size > 0; pc += count, size -= count) { fprintf(out, "0x" TARGET_FMT_lx ": ", pc); @@ -303,7 +331,7 @@ void disas(FILE *out, void *code, unsigned long size) uintptr_t pc; int count; CPUDebug s; - int (*print_insn)(bfd_vma pc, disassemble_info *info); + int (*print_insn)(bfd_vma pc, disassemble_info *info) = NULL; INIT_DISASSEMBLE_INFO(s.info, out, fprintf); s.info.print_address_func = generic_print_host_address; @@ -347,11 +375,10 @@ void disas(FILE *out, void *code, unsigned long size) print_insn = print_insn_hppa; #elif defined(__ia64__) print_insn = print_insn_ia64; -#else - fprintf(out, "0x%lx: Asm output not supported on this arch\n", - (long) code); - return; #endif + if (print_insn == NULL) { + print_insn = print_insn_od_host; + } for (pc = (uintptr_t)code; size > 0; pc += count, size -= count) { fprintf(out, "0x%08" PRIxPTR ": ", pc); count = print_insn(pc, &s.info);