aboutsummaryrefslogtreecommitdiff
path: root/gdb/elfread.c
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2023-03-02 10:56:40 +0100
committerTom de Vries <tdevries@suse.de>2023-03-02 10:56:40 +0100
commit0d5adb56c85da38a0f95e872fda05cc6446010c3 (patch)
treec72c25208ea040b0662f5015b5b9d90d1b848506 /gdb/elfread.c
parent14ade916606152d67689842eef8b4b4f2a5eadf7 (diff)
downloadgdb-0d5adb56c85da38a0f95e872fda05cc6446010c3.zip
gdb-0d5adb56c85da38a0f95e872fda05cc6446010c3.tar.gz
gdb-0d5adb56c85da38a0f95e872fda05cc6446010c3.tar.bz2
[gdb/symtab] Add set/show always-read-ctf on/off
[ This is a simplified rewrite of an earlier submission "[RFC][gdb/symtab] Add maint set symbol-read-order", submitted here ( https://sourceware.org/pipermail/gdb-patches/2022-September/192044.html ). ] With the test-case included in this patch, we run into: ... (gdb) file dwarf2-and-ctf (gdb) print var_ctf^M 'var_ctf' has unknown type; cast it to its declared type^M ... The problem is that the executable contains both ctf and dwarf2, so the ctf info (which contains the type information about var_ctf) is ignored. GDB has support for handling multiple debug formats, but the common use case for ctf is to be used when dwarf2 is not present, and gdb reflects that, assuming that by reading ctf in addition there won't be any extra information, so it's not worth the additional cycles and memory. Add a new command "set/show always-read-ctf on/off", that when on forces unconditional reading of ctf, allowing us to do: ... (gdb) set always-read-ctf on (gdb) file dwarf2-and-ctf (gdb) print var_ctf^M $2 = 2^M ... The setting is off by default, preserving current behaviour. A bit of background on the relevance of reading order: the formats have a priority relationship between them, where reading earlier means lower priority. By reading the format with the most detail last, we ensure it has the highest priority, which makes sure that in case there is overlapping info, the most detailed info is found. This explains the current reading order of mdebug, stabs and dwarf2. Add the unconditional reading of ctf before dwarf2, because it's less detailed than dwarf2. The conditional reading of ctf is still done after the attempt to read dwarf2, necessarily so because we only know whether there's dwarf2 after we've tried to read it. The new command allow us to replace uses of -Wl,--strip-debug added in commit 908a926ec4e ("[gdb/testsuite] Fix ctf test-cases on openSUSE Tumbleweed") by uses of "set always-read-ctf on", but I've left that for another commit. Tested on x86_64-linux. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Reviewed-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/elfread.c')
-rw-r--r--gdb/elfread.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/gdb/elfread.c b/gdb/elfread.c
index ca684aa..00939a0 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -51,6 +51,10 @@
#include "gdbsupport/scoped_fd.h"
#include "debuginfod-support.h"
#include "dwarf2/public.h"
+#include "cli/cli-cmds.h"
+
+/* Whether ctf should always be read, or only if no dwarf is present. */
+static bool always_read_ctf;
/* The struct elfinfo is available only during ELF symbol table and
psymtab reading. It is destroyed at the completion of psymtab-reading.
@@ -1349,10 +1353,16 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
bfd_section_size (str_sect));
}
+ /* Read the CTF section only if there is no DWARF info. */
+ if (always_read_ctf && ei.ctfsect)
+ {
+ elfctf_build_psymtabs (objfile);
+ }
+
bool has_dwarf2 = elf_symfile_read_dwarf2 (objfile, symfile_flags);
/* Read the CTF section only if there is no DWARF info. */
- if (!has_dwarf2 && ei.ctfsect)
+ if (!always_read_ctf && !has_dwarf2 && ei.ctfsect)
{
elfctf_build_psymtabs (objfile);
}
@@ -1449,4 +1459,16 @@ _initialize_elfread ()
add_symtab_fns (bfd_target_elf_flavour, &elf_sym_fns);
gnu_ifunc_fns_p = &elf_gnu_ifunc_fns;
+
+ /* Add "set always-read-ctf on/off". */
+ add_setshow_boolean_cmd ("always-read-ctf", class_support, &always_read_ctf,
+ _("\
+Set whether CTF is always read."),
+ _("\
+Show whether CTF is always read."),
+ _("\
+When off, CTF is only read if DWARF is not present. When on, CTF is read\
+ regardless of whether DWARF is present."),
+ nullptr /* set_func */, nullptr /* show_func */,
+ &setlist, &showlist);
}