From: Lancelot SIX <lancelot.six@amd.com>
To: <gdb-patches@sourceware.org>
Cc: <lsix@lancelotsix.com>, Lancelot SIX <lancelot.six@amd.com>
Subject: [PATCH v2 1/2] gdb: Move most of get_function_name (COREADDR) in symtab.h
Date: Fri, 28 Jan 2022 08:29:30 -0600 [thread overview]
Message-ID: <20220128142931.39750-2-lancelot.six@amd.com> (raw)
In-Reply-To: <20220128142931.39750-1-lancelot.six@amd.com>
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 <list>
-/* 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. */
--
2.25.1
next prev parent reply other threads:[~2022-01-28 14:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-28 14:29 [PATCH v2 0/2] Make GDB respect the DW_CC_nocall attribute Lancelot SIX
2022-01-28 14:29 ` Lancelot SIX [this message]
2022-01-31 13:17 ` [PATCH v2 1/2] gdb: Move most of get_function_name (COREADDR) in symtab.h Bruno Larsen
2022-01-28 14:29 ` [PATCH v2 2/2] gdb: Respect the DW_CC_nocall attribute Lancelot SIX
2022-01-31 13:19 ` Bruno Larsen
2022-01-31 14:05 ` Simon Marchi
2022-01-31 14:34 ` Six, Lancelot
2022-01-31 14:36 ` Simon Marchi
2022-01-31 14:19 ` Six, Lancelot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220128142931.39750-2-lancelot.six@amd.com \
--to=lancelot.six@amd.com \
--cc=gdb-patches@sourceware.org \
--cc=lsix@lancelotsix.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).