diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-11-18 15:28:20 +0000 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-11-28 00:03:04 +0000 |
commit | 1296bc99b1bf5da38be18ac1fdf6ad8d1b697e6b (patch) | |
tree | 5f810f6208df89370c4de3119ca77f9fc4584601 | |
parent | 99f6fdd9eb60f5b8b9b172b1b2cfa627be566a9d (diff) | |
download | gdb-1296bc99b1bf5da38be18ac1fdf6ad8d1b697e6b.zip gdb-1296bc99b1bf5da38be18ac1fdf6ad8d1b697e6b.tar.gz gdb-1296bc99b1bf5da38be18ac1fdf6ad8d1b697e6b.tar.bz2 |
binutils: Make DWARF register name lookup be via a function pointer
Add a layer of indirection for DWARF register name lookup by
introducing a function pointer. Right now all targets use the same
table based implementation that they always have, however, this will
change in a later commit.
binutils/ChangeLog:
* dwarf.c (typedef dwarf_regname_lookup_ftype): New typedef.
(dwarf_regnames_lookup_func): New static global.
(init_dwarf_regnames_i386): Set dwarf_regnames_lookup_func.
(init_dwarf_regnames_iamcu): Likewise.
(init_dwarf_regnames_x86_64): Likewise.
(init_dwarf_regnames_aarch64): Likewise.
(init_dwarf_regnames_s390): Likewise.
(init_dwarf_regnames_riscv): Likewise.
(init_dwarf_regnames_by_elf_machine_code): Reset
dwarf_regnames_lookup_func to NULL.
(init_dwarf_regnames_by_bfd_arch_and_mach): Likewise.
(regname_internal_by_table_only): New function.
(regname): Make use of dwarf_regnames_lookup_func.
Change-Id: Ibbff61c0abea32927f35c9e478793039ab8bb57d
-rw-r--r-- | binutils/ChangeLog | 16 | ||||
-rw-r--r-- | binutils/dwarf.c | 43 |
2 files changed, 51 insertions, 8 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 8251db2..9aace13 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,5 +1,21 @@ 2019-11-22 Andrew Burgess <andrew.burgess@embecosm.com> + * dwarf.c (typedef dwarf_regname_lookup_ftype): New typedef. + (dwarf_regnames_lookup_func): New static global. + (init_dwarf_regnames_i386): Set dwarf_regnames_lookup_func. + (init_dwarf_regnames_iamcu): Likewise. + (init_dwarf_regnames_x86_64): Likewise. + (init_dwarf_regnames_aarch64): Likewise. + (init_dwarf_regnames_s390): Likewise. + (init_dwarf_regnames_riscv): Likewise. + (init_dwarf_regnames_by_elf_machine_code): Reset + dwarf_regnames_lookup_func to NULL. + (init_dwarf_regnames_by_bfd_arch_and_mach): Likewise. + (regname_internal_by_table_only): New function. + (regname): Make use of dwarf_regnames_lookup_func. + +2019-11-22 Andrew Burgess <andrew.burgess@embecosm.com> + * dwarf.c (init_dwarf_regnames_i386): Make static. (init_dwarf_regnames_iamcu): Make static. (init_dwarf_regnames_x86_64): Make static. diff --git a/binutils/dwarf.c b/binutils/dwarf.c index fc73fa7..483d7c0 100644 --- a/binutils/dwarf.c +++ b/binutils/dwarf.c @@ -38,6 +38,7 @@ #define MIN(a, b) ((a) < (b) ? (a) : (b)) static const char *regname (unsigned int regno, int row); +static const char *regname_internal_by_table_only (unsigned int regno); static int have_frame_base; static int need_base_address; @@ -7360,9 +7361,12 @@ typedef struct Frame_Chunk } Frame_Chunk; +typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); +static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; static const char *const *dwarf_regnames; static unsigned int dwarf_regnames_count; + /* A marker for a col_type that means this column was never referenced in the frame info. */ #define DW_CFA_unreferenced (-1) @@ -7469,6 +7473,7 @@ init_dwarf_regnames_i386 (void) { dwarf_regnames = dwarf_regnames_i386; dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); + dwarf_regnames_lookup_func = regname_internal_by_table_only; } static void @@ -7476,6 +7481,7 @@ init_dwarf_regnames_iamcu (void) { dwarf_regnames = dwarf_regnames_iamcu; dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); + dwarf_regnames_lookup_func = regname_internal_by_table_only; } static const char *const dwarf_regnames_x86_64[] = @@ -7515,6 +7521,7 @@ init_dwarf_regnames_x86_64 (void) { dwarf_regnames = dwarf_regnames_x86_64; dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); + dwarf_regnames_lookup_func = regname_internal_by_table_only; } static const char *const dwarf_regnames_aarch64[] = @@ -7542,6 +7549,7 @@ init_dwarf_regnames_aarch64 (void) { dwarf_regnames = dwarf_regnames_aarch64; dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); + dwarf_regnames_lookup_func = regname_internal_by_table_only; } static const char *const dwarf_regnames_s390[] = @@ -7566,6 +7574,7 @@ init_dwarf_regnames_s390 (void) { dwarf_regnames = dwarf_regnames_s390; dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); + dwarf_regnames_lookup_func = regname_internal_by_table_only; } static const char *const dwarf_regnames_riscv[] = @@ -7587,11 +7596,14 @@ init_dwarf_regnames_riscv (void) { dwarf_regnames = dwarf_regnames_riscv; dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_riscv); + dwarf_regnames_lookup_func = regname_internal_by_table_only; } void init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) { + dwarf_regnames_lookup_func = NULL; + switch (e_machine) { case EM_386: @@ -7632,6 +7644,8 @@ void init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, unsigned long mach) { + dwarf_regnames_lookup_func = NULL; + switch (arch) { case bfd_arch_i386: @@ -7674,18 +7688,31 @@ init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, } static const char * -regname (unsigned int regno, int row) +regname_internal_by_table_only (unsigned int regno) { - static char reg[64]; - - if (dwarf_regnames + if (dwarf_regnames != NULL && regno < dwarf_regnames_count && dwarf_regnames [regno] != NULL) + return dwarf_regnames [regno]; + + return NULL; +} + +static const char * +regname (unsigned int regno, int name_only_p) +{ + static char reg[64]; + + const char *name = NULL; + + if (dwarf_regnames_lookup_func != NULL) + name = dwarf_regnames_lookup_func (regno); + + if (name != NULL) { - if (row) - return dwarf_regnames [regno]; - snprintf (reg, sizeof (reg), "r%d (%s)", regno, - dwarf_regnames [regno]); + if (name_only_p) + return name; + snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); } else snprintf (reg, sizeof (reg), "r%d", regno); |