From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 018983857002 for ; Thu, 23 Jul 2020 16:22:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 018983857002 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-x42a.google.com with SMTP id f18so5771481wrs.0 for ; Thu, 23 Jul 2020 09:22:34 -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=4uhd0zqlZHDU6tZmcKtGsEln5V/1iyq5PLmpg/2EVf8=; b=hhPCwzpwt0+5wdxvpiYBztkxcED04Hj9n4l6zavfEY9jWvM+Zbmd16uW0bZKrswyG4 5c5426j9F62ai0P2OljAyXMUxw8fMfpfmwaUKnLpFDAlW+Dfsz/DJLHkBgTYiJm7ugEM VxBV7UOSPeSoqxeAfQt4Lnr8zlEb/1SOfpAvX9yBJrSlqwa7yrXntVRmwDQVssZN+ZfR njQE6CbXEyqKW9YFDV0SvkCFKG81AwpPgNbzNpj5jH+04aBZLVtqNOO3lFHjjOGSox47 pfG2IAfnzA2kQvYn8s6xrBFwb2jmjWMeBEF/H/QPU/k7T5PksaUp53Duu8H08LofOwkk r9Cg== 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=4uhd0zqlZHDU6tZmcKtGsEln5V/1iyq5PLmpg/2EVf8=; b=QikXH9IDXtPXOBFqB33V2AF9dzQRp75mclKdY9UF5bESdxt3l+lCTL2keWSxrOOYPW jQbEux6WbTvU4xXJ59CgM/npmAfCfGQvA2jQU7WY37vdaC6laDWuGY11SNz07BfOyKDj RufHIioOGeQ6cY5lUsgdLp+LydAQQoTJZVd5kZQOH99geQk5qZmCXdOSXamMXr1jKvF0 QNjrwO9SrvwCvmrbFUGE83EDYI60xlce7f6VjDyyvOhC8JX1vqsMztnlmbPXwmvck6cg Awt+YFtALKKEuYU/pEbnKIqz/7DbxMZh/5Bm4Yl5lyqarqkpFhCqZGTJTvu+ApsaN7NE Hx+A== X-Gm-Message-State: AOAM530HV3kay0haLlnfGGrPXEnaukAUrKLtoB/RI1uCe7PWilJAL7Is tqpy7pNjecLmX+07P1uv3t8e+uUHdEM= X-Google-Smtp-Source: ABdhPJwxtSigfNThSfNvk57+ScvZVvTrwZ6mc5pZAOpBra6nvIuvGCF9qAe8/ttEulDy4aID+cTykw== X-Received: by 2002:adf:b198:: with SMTP id q24mr4551575wra.335.1595521353815; Thu, 23 Jul 2020 09:22:33 -0700 (PDT) Received: from localhost (host86-134-151-238.range86-134.btcentralplus.com. [86.134.151.238]) by smtp.gmail.com with ESMTPSA id c25sm4136432wml.18.2020.07.23.09.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2020 09:22:32 -0700 (PDT) Date: Thu, 23 Jul 2020 17:22:32 +0100 From: Andrew Burgess To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] Demangle function names when disassembling Message-ID: <20200723162232.GM853475@embecosm.com> References: <20200723161043.2191184-1-tromey@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200723161043.2191184-1-tromey@adacore.com> X-Operating-System: Linux/5.6.15-200.fc31.x86_64 (x86_64) X-Uptime: 17:21:32 up 5 days, 1:36, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , X-List-Received-Date: Thu, 23 Jul 2020 16:22:37 -0000 * Tom Tromey [2020-07-23 10:10:43 -0600]: > From: Andrew Burgess > > Andrew Burgess pointed out a regression, which he described in > PR symtab/26270: > > ================ > After commit: > > commit bcfe6157ca288efed127c5efe21ad7924e0d98cf (refs/bisect/bad) > Date: Fri Apr 24 15:35:01 2020 -0600 > > Use the linkage name if it exists > > The disassembler no longer demangles function names in its output. So > we see things like this: > > (gdb) disassemble tree_insert > Dump of assembler code for function _Z11tree_insertP4nodei: > .... > > Instead of this: > > (gdb) disassemble tree_insert > Dump of assembler code for function tree_insert(node*, int): > .... > > This is because find_pc_partial_function now returns the linkage name > rather than the demangled name. > ================ > > This patch fixes the problem by introducing a new "overload" of > find_pc_partial_function, which returns the general_symbol_info rather > than simply the name. This lets the disassemble command choose which > name to show. > > Regression tested on x86-64 Fedora 32. LGTM. Thanks for fixing this one. Andrew > > gdb/ChangeLog > 2020-07-23 Tom Tromey > > PR symtab/26270: > * symtab.h (find_pc_partial_function_sym): Declare. > * cli/cli-cmds.c (disassemble_command): Use > find_pc_partial_function_sym. Check asm_demangle. > * blockframe.c (cache_pc_function_sym): New global. > (cache_pc_function_name): Remove. > (clear_pc_function_cache): Update. > (find_pc_partial_function_sym): New function, from > find_pc_partial_function. > (find_pc_partial_function): Rewrite using > find_pc_partial_function_sym. > > gdb/testsuite/ChangeLog > 2020-07-23 Andrew Burgess > > PR symtab/26270: > * gdb.cp/disasm-func-name.cc: New file. > * gdb.cp/disasm-func-name.exp: New file. > --- > gdb/ChangeLog | 14 +++++++ > gdb/blockframe.c | 36 +++++++++++----- > gdb/cli/cli-cmds.c | 9 +++- > gdb/symtab.h | 8 ++++ > gdb/testsuite/ChangeLog | 6 +++ > gdb/testsuite/gdb.cp/disasm-func-name.cc | 48 ++++++++++++++++++++++ > gdb/testsuite/gdb.cp/disasm-func-name.exp | 50 +++++++++++++++++++++++ > 7 files changed, 160 insertions(+), 11 deletions(-) > create mode 100644 gdb/testsuite/gdb.cp/disasm-func-name.cc > create mode 100644 gdb/testsuite/gdb.cp/disasm-func-name.exp > > diff --git a/gdb/blockframe.c b/gdb/blockframe.c > index 05c26bc2c2a..80b769514eb 100644 > --- a/gdb/blockframe.c > +++ b/gdb/blockframe.c > @@ -191,7 +191,7 @@ find_pc_sect_containing_function (CORE_ADDR pc, struct obj_section *section) > > static CORE_ADDR cache_pc_function_low = 0; > static CORE_ADDR cache_pc_function_high = 0; > -static const char *cache_pc_function_name = 0; > +static const general_symbol_info *cache_pc_function_sym = nullptr; > static struct obj_section *cache_pc_function_section = NULL; > static const struct block *cache_pc_function_block = nullptr; > > @@ -202,7 +202,7 @@ clear_pc_function_cache (void) > { > cache_pc_function_low = 0; > cache_pc_function_high = 0; > - cache_pc_function_name = (char *) 0; > + cache_pc_function_sym = nullptr; > cache_pc_function_section = NULL; > cache_pc_function_block = nullptr; > } > @@ -210,8 +210,10 @@ clear_pc_function_cache (void) > /* See symtab.h. */ > > bool > -find_pc_partial_function (CORE_ADDR pc, const char **name, CORE_ADDR *address, > - CORE_ADDR *endaddr, const struct block **block) > +find_pc_partial_function_sym (CORE_ADDR pc, > + const struct general_symbol_info **sym, > + CORE_ADDR *address, CORE_ADDR *endaddr, > + const struct block **block) > { > struct obj_section *section; > struct symbol *f; > @@ -257,7 +259,7 @@ find_pc_partial_function (CORE_ADDR pc, const char **name, CORE_ADDR *address, > { > const struct block *b = SYMBOL_BLOCK_VALUE (f); > > - cache_pc_function_name = f->linkage_name (); > + cache_pc_function_sym = f; > cache_pc_function_section = section; > cache_pc_function_block = b; > > @@ -313,8 +315,8 @@ find_pc_partial_function (CORE_ADDR pc, const char **name, CORE_ADDR *address, > if (msymbol.minsym == NULL) > { > /* No available symbol. */ > - if (name != NULL) > - *name = 0; > + if (sym != nullptr) > + *sym = 0; > if (address != NULL) > *address = 0; > if (endaddr != NULL) > @@ -325,7 +327,7 @@ find_pc_partial_function (CORE_ADDR pc, const char **name, CORE_ADDR *address, > } > > cache_pc_function_low = BMSYMBOL_VALUE_ADDRESS (msymbol); > - cache_pc_function_name = msymbol.minsym->linkage_name (); > + cache_pc_function_sym = msymbol.minsym; > cache_pc_function_section = section; > cache_pc_function_high = minimal_symbol_upper_bound (msymbol); > cache_pc_function_block = nullptr; > @@ -340,8 +342,8 @@ find_pc_partial_function (CORE_ADDR pc, const char **name, CORE_ADDR *address, > *address = cache_pc_function_low; > } > > - if (name) > - *name = cache_pc_function_name; > + if (sym != nullptr) > + *sym = cache_pc_function_sym; > > if (endaddr) > { > @@ -365,6 +367,20 @@ find_pc_partial_function (CORE_ADDR pc, const char **name, CORE_ADDR *address, > return true; > } > > +/* See symtab.h. */ > + > +bool > +find_pc_partial_function (CORE_ADDR pc, const char **name, CORE_ADDR *address, > + CORE_ADDR *endaddr, const struct block **block) > +{ > + const general_symbol_info *gsi; > + bool r = find_pc_partial_function_sym (pc, &gsi, address, endaddr, block); > + if (name != nullptr) > + *name = r ? gsi->linkage_name () : nullptr; > + return r; > +} > + > + > /* See symtab.h. */ > > bool > diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c > index 14718d1181a..07b119038d2 100644 > --- a/gdb/cli/cli-cmds.c > +++ b/gdb/cli/cli-cmds.c > @@ -1482,6 +1482,7 @@ disassemble_command (const char *arg, int from_tty) > { > struct gdbarch *gdbarch = get_current_arch (); > CORE_ADDR low, high; > + const general_symbol_info *symbol = nullptr; > const char *name; > CORE_ADDR pc; > gdb_disassembly_flags flags; > @@ -1537,8 +1538,14 @@ disassemble_command (const char *arg, int from_tty) > if (p[0] == '\0') > { > /* One argument. */ > - if (find_pc_partial_function (pc, &name, &low, &high, &block) == 0) > + if (!find_pc_partial_function_sym (pc, &symbol, &low, &high, &block)) > error (_("No function contains specified address.")); > + > + if (asm_demangle) > + name = symbol->print_name (); > + else > + name = symbol->linkage_name (); > + > #if defined(TUI) > /* NOTE: cagney/2003-02-13 The `tui_active' was previously > `tui_version'. */ > diff --git a/gdb/symtab.h b/gdb/symtab.h > index 0b186554ea1..026ffcaa016 100644 > --- a/gdb/symtab.h > +++ b/gdb/symtab.h > @@ -1769,6 +1769,14 @@ extern bool find_pc_partial_function (CORE_ADDR pc, const char **name, > CORE_ADDR *address, CORE_ADDR *endaddr, > const struct block **block = nullptr); > > +/* Like find_pc_partial_function, above, but returns the underlying > + general_symbol_info (rather than the name) as an out parameter. */ > + > +extern bool find_pc_partial_function_sym > + (CORE_ADDR pc, const general_symbol_info **sym, > + CORE_ADDR *address, CORE_ADDR *endaddr, > + const struct block **block = nullptr); > + > /* Like find_pc_partial_function, above, but *ADDRESS and *ENDADDR are > set to start and end addresses of the range containing the entry pc. > > diff --git a/gdb/testsuite/gdb.cp/disasm-func-name.cc b/gdb/testsuite/gdb.cp/disasm-func-name.cc > new file mode 100644 > index 00000000000..428baf98964 > --- /dev/null > +++ b/gdb/testsuite/gdb.cp/disasm-func-name.cc > @@ -0,0 +1,48 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2020 Free Software Foundation, Inc. > + > + 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 3 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 . */ > + > +class A > +{ > +private: > + int m_i; > + > +public: > + A(int i); > + > + int get_i () const > + { return m_i; } > + > + void set_i (int i) > + { m_i = i; } > +}; > + > +A::A(int i) > + : m_i (i) > +{ /* Nothing. */ } > + > +void process (A *obj, int num) > +{ > + obj->set_i (obj->get_i () + num); > +} > + > +int > +main (void) > +{ > + A a(42); > + process (&a, 2); > + return a.get_i (); > +} > diff --git a/gdb/testsuite/gdb.cp/disasm-func-name.exp b/gdb/testsuite/gdb.cp/disasm-func-name.exp > new file mode 100644 > index 00000000000..3fb63c89a28 > --- /dev/null > +++ b/gdb/testsuite/gdb.cp/disasm-func-name.exp > @@ -0,0 +1,50 @@ > +# Copyright 2020 Free Software Foundation, Inc. > + > +# 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 3 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 . > + > +# This file is part of the gdb testsuite > + > +# Test that the disassembler correctly demangles C++ function names in > +# it's header line. > + > +if {[skip_cplus_tests]} { continue } > + > +standard_testfile .cc > + > +if [get_compiler_info "c++"] { > + return -1 > +} > + > +if {[prepare_for_testing "failed to prepare" $testfile \ > + $srcfile {debug c++}]} { > + return -1 > +} > + > +if ![runto_main] then { > + perror "couldn't run to breakpoint" > + continue > +} > + > +proc check_disassembly_header { request expected } { > + gdb_test "disassemble ${request}" \ > + "Dump of assembler code for function ${expected}:\r\n.*" > +} > + > +gdb_test_no_output "set print asm-demangle on" > + > +check_disassembly_header "main" "main\\(\\)" > +check_disassembly_header "process" "process\\(A\\*, int\\)" > +check_disassembly_header "A::A" "A::A\\(int\\)" > +check_disassembly_header "A::get_i" "A::get_i\\(\\) const" > +check_disassembly_header "A::set_i" "A::set_i\\(int\\)" > -- > 2.26.2 >