[PATCH v2 1/2] gdb: Move most of get_function_name (COREADDR) in symtab.h
Lancelot SIX
lancelot.six@amd.com
Fri Jan 28 14:29:30 GMT 2022
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
More information about the Gdb-patches
mailing list