From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id uLBwD3N9bF+veQAAWB0awg (envelope-from ) for ; Thu, 24 Sep 2020 07:05:23 -0400 Received: by simark.ca (Postfix, from userid 112) id 294F71EE05; Thu, 24 Sep 2020 07:05:23 -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 279421E509 for ; Thu, 24 Sep 2020 07:05:21 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 849613850408; Thu, 24 Sep 2020 11:05:20 +0000 (GMT) Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by sourceware.org (Postfix) with ESMTPS id 921183857C65 for ; Thu, 24 Sep 2020 11:05:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 921183857C65 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x443.google.com with SMTP id e16so3362413wrm.2 for ; Thu, 24 Sep 2020 04:05:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=F9ywjkSh9LsWoPTLmiMRrROjGKuweTOzR89ayypHA6I=; b=I7qPqCMdYRAFgYKm4jVsWcPMzlKoCsFUuh1YICZ2I1wJgMMheofhMGhGz523zPePhk iVeJkzi1Po3hhwoL0fKBm5rkyZXMFB6kVEO0QMmMqKa603kKMY8SSIJNNubU3yii5c0R rDVWGybRxf6FlwhmIBLYa0LlENs/SNHQw9c3MDv0dA0F5KDpxUba3doFdVbklt8wj3eM D2l3CFpmhJxCNi4iWvrpzivnySg2Sj2t3r6j/6/HHdXvMEhboe+BN+P13kP9PkF1ioCs lTbR9YL9ErTp6fpeh8nAkarWFuDpVZ6nT7Z5pAHQ0r+//71hMJ9u4aaV0KGRva+LxqEh ad8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=F9ywjkSh9LsWoPTLmiMRrROjGKuweTOzR89ayypHA6I=; b=EGbKfY/tJrDBmGj/fJzog5gEMVWEA8X5VC39KhVSvz+sRxlImpXvZsy0YbCP6+BLeI gUQxc8icZbtKalw8QYqt6S4HBBTOc729rYpNf8L/AcVgCVFz7KMiNyOF0Gj4cnb5xwV1 ykmG8r+CTrAPJz9Fjo+SSWTipmIQH4vsG4b366+wqY7vy3397PHdoSvZV+MNTgNOB82J QEzeuvJKyB9ChgVwEO3MUerZ6ttksvEsYFZmdXVSKeNMlf2wKVWgGCiu9gkJIJwWP4oE ojK0rmwkGM/ZLquU9uaX1QoKad5PO4X7Bb+EakKL07Mnh9QMKABYs5zYnlyJi52SfI9G V1zg== X-Gm-Message-State: AOAM532nkj26B+z+h0aOAx+e2wqEY6XzjM520WI+Oljx0yGqUJF6VD1Y QRpTersGwjWoVhYX48j6J2VvZeE/XnAH6g== X-Google-Smtp-Source: ABdhPJybCKkRqovcqRJeOHq2MkGDoC6gekrQ66Z1FYV/MojFzggUdvpRrSx4HKFjQ0nPeJbWwrAisg== X-Received: by 2002:adf:f890:: with SMTP id u16mr4276376wrp.183.1600945516670; Thu, 24 Sep 2020 04:05:16 -0700 (PDT) Received: from localhost (host31-53-80-104.range31-53.btcentralplus.com. [31.53.80.104]) by smtp.gmail.com with ESMTPSA id u66sm3074159wme.12.2020.09.24.04.05.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 04:05:15 -0700 (PDT) Date: Thu, 24 Sep 2020 12:05:14 +0100 From: Andrew Burgess To: fam@euphon.net Subject: Re: [PATCH v2] disass: Add /x modifier to print offsets in hex Message-ID: <20200924110514.GJ1540618@embecosm.com> References: <20200923101906.2897399-1-fam@euphon.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200923101906.2897399-1-fam@euphon.net> X-Operating-System: Linux/5.8.9-101.fc31.x86_64 (x86_64) X-Uptime: 12:03:08 up 5 days, 19:10, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] 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: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" * fam@euphon.net [2020-09-23 10:19:06 +0000]: > 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. > > 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+length) > > A /m modifier will include source code with the assembly in a > @@ -1472,6 +1472,8 @@ disassemble_current_function (gdb_disassembly_flags flags) > > A /r modifier will include raw instructions in hex with the assembly. > > + A /x modifier will print offsets in hex. Shouldn't this be 'An /x modified ...' ? Saying it out loud it certainly seems that way. > + > 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) > case 'r': > flags |= DISASSEMBLY_RAW_INSN; > break; > + case 'x': > + flags |= DISASSEMBLY_HEX_OFFSET; > + break; > case 's': > flags |= DISASSEMBLY_SOURCE; > break; > @@ -2535,7 +2540,7 @@ can be shown using \"show listsize\".")); > > c = 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\ Same I think. Thanks, Andrew > +\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 dump,\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 = arch (); > + char offset_buf[32]; > > { > ui_out_emit_tuple tuple_emitter (m_uiout, NULL); > @@ -250,7 +251,10 @@ gdb_pretty_print_disassembler::pretty_print_insn (const struct disasm_insn *insn > the offset takes the place of the "+" here. */ > if (offset >= 0) > m_uiout->text ("+"); > - m_uiout->field_signed ("offset", offset); > + snprintf(offset_buf, sizeof(offset_buf), > + flags & DISASSEMBLY_HEX_OFFSET ? "0x%x" : "%d", > + offset); > + m_uiout->field_string("offset", offset_buf); > m_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 = (0x1 << 4), > DISASSEMBLY_SOURCE = (0x1 << 5), > DISASSEMBLY_SPECULATIVE = (0x1 << 6), > + DISASSEMBLY_HEX_OFFSET = (0x1 << 7), > }; > DEF_ENUM_FLAGS_TYPE (enum gdb_disassembly_flag, gdb_disassembly_flags); > > 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) > case 'r': > modifiers |= DISASSEMBLY_RAW_INSN; > break; > + case 'x': > + modifiers |= DISASSEMBLY_HEX_OFFSET; > + break; > case 'f': > modifiers |= DISASSEMBLY_OMIT_FNAME; > break; > -- > 2.25.1 > >