From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 8CDB3385800F for ; Mon, 31 Jan 2022 13:17:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8CDB3385800F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-623-SeW1dAG_NoihcBlMkqfwTw-1; Mon, 31 Jan 2022 08:17:43 -0500 X-MC-Unique: SeW1dAG_NoihcBlMkqfwTw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6207F1F2DA; Mon, 31 Jan 2022 13:17:42 +0000 (UTC) Received: from [10.97.116.5] (ovpn-116-5.gru2.redhat.com [10.97.116.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2398D10A33CB; Mon, 31 Jan 2022 13:17:39 +0000 (UTC) Message-ID: <03c0c6e6-9206-bb47-5d3d-6af1be3b76fd@redhat.com> Date: Mon, 31 Jan 2022 10:17:35 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v2 1/2] gdb: Move most of get_function_name (COREADDR) in symtab.h To: Lancelot SIX , gdb-patches@sourceware.org Cc: lsix@lancelotsix.com References: <20220128142931.39750-1-lancelot.six@amd.com> <20220128142931.39750-2-lancelot.six@amd.com> From: Bruno Larsen In-Reply-To: <20220128142931.39750-2-lancelot.six@amd.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Mon, 31 Jan 2022 13:17:52 -0000 On 1/28/22 11:29, Lancelot SIX via Gdb-patches wrote: > A later commit will need to be able to print the name of a function > given its address. This functionality is currently implemented in a > static function in gdb/infcall.c. > > In order to make this functionality available to other parts of GDB, > this commit moves it to gdb/symtab.h and gdb/blockframe.c. > > No user visible change after this commit. > > Tested on x86_64. > > Change-Id: I3d32d64f298bdb49acc9e224fdeff33dcc7aa6cb > --- > gdb/blockframe.c | 29 +++++++++++++++++++++++++++++ > gdb/infcall.c | 38 -------------------------------------- > gdb/symtab.h | 15 +++++++++++++++ > 3 files changed, 44 insertions(+), 38 deletions(-) > > diff --git a/gdb/blockframe.c b/gdb/blockframe.c > index 88595d4fcb0..bf557690f61 100644 > --- a/gdb/blockframe.c > +++ b/gdb/blockframe.c > @@ -479,3 +479,32 @@ block_innermost_frame (const struct block *block) > > return NULL; > } > + > +/* See symtab.h. */ > + > +const char * > +get_function_name (CORE_ADDR funaddr, char *buf, int buf_size) > +{ > + { > + struct symbol *symbol = find_pc_function (funaddr); > + > + if (symbol) > + return symbol->print_name (); > + } > + > + { > + /* Try the minimal symbols. */ > + struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (funaddr); > + > + if (msymbol.minsym) > + return msymbol.minsym->print_name (); > + } > + > + { > + std::string tmp = string_printf (_(RAW_FUNCTION_ADDRESS_FORMAT), > + hex_string (funaddr)); > + > + gdb_assert (tmp.length () + 1 <= buf_size); > + return strcpy (buf, tmp.c_str ()); > + } > +} > diff --git a/gdb/infcall.c b/gdb/infcall.c > index 05cf18f0a7f..571e790fbee 100644 > --- a/gdb/infcall.c > +++ b/gdb/infcall.c > @@ -44,11 +44,6 @@ > #include "gdbsupport/scope-exit.h" > #include > > -/* If we can't find a function's name from its address, > - we print this instead. */ > -#define RAW_FUNCTION_ADDRESS_FORMAT "at 0x%s" > -#define RAW_FUNCTION_ADDRESS_SIZE (sizeof (RAW_FUNCTION_ADDRESS_FORMAT) \ > - + 2 * sizeof (CORE_ADDR)) > > /* NOTE: cagney/2003-04-16: What's the future of this code? > > @@ -374,39 +369,6 @@ error_call_unknown_return_type (const char *func_name) > "cast the call to its declared return type")); > } > > -/* Fetch the name of the function at FUNADDR. > - This is used in printing an error message for call_function_by_hand. > - BUF is used to print FUNADDR in hex if the function name cannot be > - determined. It must be large enough to hold formatted result of > - RAW_FUNCTION_ADDRESS_FORMAT. */ > - > -static const char * > -get_function_name (CORE_ADDR funaddr, char *buf, int buf_size) > -{ > - { > - struct symbol *symbol = find_pc_function (funaddr); > - > - if (symbol) > - return symbol->print_name (); > - } > - > - { > - /* Try the minimal symbols. */ > - struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (funaddr); > - > - if (msymbol.minsym) > - return msymbol.minsym->print_name (); > - } > - > - { > - std::string tmp = string_printf (_(RAW_FUNCTION_ADDRESS_FORMAT), > - hex_string (funaddr)); > - > - gdb_assert (tmp.length () + 1 <= buf_size); > - return strcpy (buf, tmp.c_str ()); > - } > -} > - > /* All the meta data necessary to extract the call's return value. */ > > struct call_return_meta_info > diff --git a/gdb/symtab.h b/gdb/symtab.h > index 55d1b772c45..aa951706c16 100644 > --- a/gdb/symtab.h > +++ b/gdb/symtab.h > @@ -1821,6 +1821,21 @@ extern bool find_function_entry_range_from_pc (CORE_ADDR pc, > > extern struct type *find_function_type (CORE_ADDR pc); > > +/* If we can't find a function's name from its address, > + we print this instead. */ > +#define RAW_FUNCTION_ADDRESS_FORMAT "at 0x%s" > +#define RAW_FUNCTION_ADDRESS_SIZE (sizeof (RAW_FUNCTION_ADDRESS_FORMAT) \ > + + 2 * sizeof (CORE_ADDR)) > + > +/* Fetch the name of the function at FUNADDR. > + > + BUF is used to print FUNADDR in hex if the function name cannot be > + determined. It must be large enough to hold formatted result of > + RAW_FUNCTION_ADDRESS_FORMAT. */ > + > +extern const char *get_function_name (CORE_ADDR funaddr, char *buf, > + int buf_size); > + > /* See if we can figure out the function's actual type from the type > that the resolver returns. RESOLVER_FUNADDR is the address of the > ifunc resolver. */ Hi Lancelot, LGTM, but I can't approve for pushing. -- Cheers! Bruno Larsen