From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id zN6fLzEha19DEQAAWB0awg (envelope-from ) for ; Wed, 23 Sep 2020 06:19:29 -0400 Received: by simark.ca (Postfix, from userid 112) id 02E5B1EE05; Wed, 23 Sep 2020 06:19:28 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 0CFF81E790 for ; Wed, 23 Sep 2020 06:19:20 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DF5733894C1C; Wed, 23 Sep 2020 10:19:19 +0000 (GMT) Received: from sender2-op-o12.zoho.com.cn (sender2-op-o12.zoho.com.cn [163.53.93.243]) by sourceware.org (Postfix) with ESMTPS id B6CC73894C1C for ; Wed, 23 Sep 2020 10:19:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B6CC73894C1C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=euphon.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=fam@euphon.net ARC-Seal: i=1; a=rsa-sha256; t=1600856352; cv=none; d=zoho.com.cn; s=zohoarc; b=emU136ZPzI+32w5qtM10XfZbj9TY23GG+3xeChCInzY8uHim1Z9u3pUfqYDSAMrLiuXJ0pGW3yJbGGjlZjO+xCeV8B3U4SHRwIBmdTk+3OpP07j0N7Oe8Xl9vRpL7HLk0iL/gUGg6g+dFMR3LeDxzid1dIIqqiOfByy5JJ6Mcw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com.cn; s=zohoarc; t=1600856352; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=6IOwwNvxynXJflucTPZ2z96q9eLnVhz4X+nZY917y3A=; b=S1O/JtnaZFbVwkqyxHBNZjOE6vPnpbFw2OJQ1OQAkZr4ggZdfA4j+jjgcvIO44q+ulcHf8zbe3njz6DjalrBwtQjykRVjWUK/6ll2ZPn+E9u2n9bNbk3ELwdn4AHgGWZwIiKqO5ifWw4yZkMce+OSAdGBc7ic4lLnW/oFCOwRaE= ARC-Authentication-Results: i=1; mx.zoho.com.cn; dkim=pass header.i=euphon.net; spf=pass smtp.mailfrom=fam@euphon.net; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1600856352; s=zoho; d=euphon.net; i=fam@euphon.net; h=From:To:Cc:Message-ID:Subject:Date:MIME-Version:Content-Transfer-Encoding:Content-Type; bh=6IOwwNvxynXJflucTPZ2z96q9eLnVhz4X+nZY917y3A=; b=V7jPdT1UKhhQPOM3g1YRp9N1zwa8udVehTjOoUooZH+De2TchsQqz9x5DHKmZ+0X wEePk0SId3XwovKtK5ghOQm7896Tx1WJw23ICO9Denu4KSo0gC02TuQqvFAoKAfUL3U sJpyGokecwFd2ThfWaYnm/ElM7CaFnXr5ST5rvd4= Received: from localhost (ec2-52-56-101-76.eu-west-2.compute.amazonaws.com [52.56.101.76]) by mx.zoho.com.cn with SMTPS id 1600856350336738.7491183692916; Wed, 23 Sep 2020 18:19:10 +0800 (CST) From: fam@euphon.net To: gdb-patches@sourceware.org Message-ID: <20200923101906.2897399-1-fam@euphon.net> Subject: [PATCH v2] disass: Add /x modifier to print offsets in hex Date: Wed, 23 Sep 2020 10:19:06 +0000 X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoCNMailClient: External Content-Type: text/plain; charset=utf8 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" From: Fam Zheng Backtrace messages printed by Linux kernel and Xen have hex offsets, e.g.: (XEN) Xen call trace: (XEN) [] R guest_walk_tables_2_levels+0x189/0x66d (XEN) [] F hap_p2m_ga_to_gfn_2_levels+0x112/0x25b (XEN) [] F hap_gva_to_gfn_2_levels+0x1c/0x1e (XEN) [] F paging_gva_to_gfn+0x14a/0x167 Having this modifier saves converting between hex values from the backtrace log and offsets in gdb disass output. --- v2: Drop a overlooked change on file header. --- gdb/cli/cli-cmds.c | 17 ++++++++++++----- gdb/disasm.c | 6 +++++- gdb/disasm.h | 1 + gdb/record.c | 3 +++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index e3965fea07..2266f67695 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -1456,12 +1456,12 @@ disassemble_current_function (gdb_disassembly_flags= flags) /* Dump a specified section of assembly code. =20 Usage: - disassemble [/mrs] + disassemble [/mrsx] - dump the assembly code for the function of the current pc - disassemble [/mrs] addr + disassemble [/mrsx] addr - dump the assembly code for the function at ADDR - disassemble [/mrs] low,high - disassemble [/mrs] low,+length + disassemble [/mrsx] low,high + disassemble [/mrsx] low,+length - dump the assembly code in the range [LOW,HIGH), or [LOW,LOW+lengt= h) =20 A /m modifier will include source code with the assembly in a @@ -1472,6 +1472,8 @@ disassemble_current_function (gdb_disassembly_flags f= lags) =20 A /r modifier will include raw instructions in hex with the assembly. =20 + A /x modifier will print offsets in hex. + A /s modifier will include source code with the assembly, like /m, with two important differences: 1) The output is still in pc address order. @@ -1510,6 +1512,9 @@ disassemble_command (const char *arg, int from_tty) =09 case 'r': =09 flags |=3D DISASSEMBLY_RAW_INSN; =09 break; +=09 case 'x': +=09 flags |=3D DISASSEMBLY_HEX_OFFSET; +=09 break; =09 case 's': =09 flags |=3D DISASSEMBLY_SOURCE; =09 break; @@ -2535,7 +2540,7 @@ can be shown using \"show listsize\".")); =20 c =3D add_com ("disassemble", class_vars, disassemble_command, _("\ Disassemble a specified section of memory.\n\ -Usage: disassemble[/m|/r|/s] START [, END]\n\ +Usage: disassemble[/m|/r|/s|/r] START [, END]\n\ Default is the function surrounding the pc of the selected frame.\n\ \n\ With a /s modifier, source lines are included (if available).\n\ @@ -2551,6 +2556,8 @@ in favor of /s.\n\ \n\ With a /r modifier, raw instructions in hex are included.\n\ \n\ +With a /x modifier, offsets are printed as hex.\n\ +\n\ With a single argument, the function surrounding that address is dumped.\n= \ Two arguments (separated by a comma) are taken as a range of memory to dum= p,\n\ in the form of \"start,end\", or \"start,+length\".\n\ diff --git a/gdb/disasm.c b/gdb/disasm.c index e45c840068..47936e54f1 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -201,6 +201,7 @@ gdb_pretty_print_disassembler::pretty_print_insn (const= struct disasm_insn *insn int size; CORE_ADDR pc; struct gdbarch *gdbarch =3D arch (); + char offset_buf[32]; =20 { ui_out_emit_tuple tuple_emitter (m_uiout, NULL); @@ -250,7 +251,10 @@ gdb_pretty_print_disassembler::pretty_print_insn (cons= t struct disasm_insn *insn =09 the offset takes the place of the "+" here. */ =09if (offset >=3D 0) =09 m_uiout->text ("+"); -=09m_uiout->field_signed ("offset", offset); +=09snprintf(offset_buf, sizeof(offset_buf), + flags & DISASSEMBLY_HEX_OFFSET ? "0x%x" : "%d", + offset); +=09m_uiout->field_string("offset", offset_buf); =09m_uiout->text (">:\t"); } else diff --git a/gdb/disasm.h b/gdb/disasm.h index b0f535eaa2..fb293650de 100644 --- a/gdb/disasm.h +++ b/gdb/disasm.h @@ -31,6 +31,7 @@ enum gdb_disassembly_flag DISASSEMBLY_OMIT_PC =3D (0x1 << 4), DISASSEMBLY_SOURCE =3D (0x1 << 5), DISASSEMBLY_SPECULATIVE =3D (0x1 << 6), + DISASSEMBLY_HEX_OFFSET =3D (0x1 << 7), }; DEF_ENUM_FLAGS_TYPE (enum gdb_disassembly_flag, gdb_disassembly_flags); =20 diff --git a/gdb/record.c b/gdb/record.c index 759395d5bc..44591e8cf0 100644 --- a/gdb/record.c +++ b/gdb/record.c @@ -494,6 +494,9 @@ get_insn_history_modifiers (const char **arg) =09 case 'r': =09 modifiers |=3D DISASSEMBLY_RAW_INSN; =09 break; +=09 case 'x': +=09 modifiers |=3D DISASSEMBLY_HEX_OFFSET; +=09 break; =09 case 'f': =09 modifiers |=3D DISASSEMBLY_OMIT_FNAME; =09 break; --=20 2.25.1