summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-11-22 20:57:42 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2021-12-01 21:50:31 -0500
commitab557072b8ecd11c77916d00312d80b85ce3284c (patch)
tree65c36d5fae2dab4f121caef68f67437ea150ea7e
parent1f1d0f8888a6c944e612b416a2a6e11abcf5199f (diff)
downloadbinutils-gdb-ab557072b8ecd11c77916d00312d80b85ce3284c.tar.gz
gdb: use actual DWARF version in compunit's debugformat field
The "info source" command, with a DWARF-compile program, always show that the debug info is "DWARF 2": (gdb) info source Current source file is test.c Compilation directory is /home/smarchi/build/binutils-gdb/gdb Located in /home/smarchi/build/binutils-gdb/gdb/test.c Contains 2 lines. Source language is c. Producer is GNU C17 9.3.0 -mtune=generic -march=x86-64 -g3 -gdwarf-5 -O0 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection. Compiled with DWARF 2 debugging format. Includes preprocessor macro info. Change it to display the actual DWARF version: (gdb) info source Current source file is test.c Compilation directory is /home/smarchi/build/binutils-gdb/gdb Located in /home/smarchi/build/binutils-gdb/gdb/test.c Contains 2 lines. Source language is c. Producer is GNU C17 9.3.0 -mtune=generic -march=x86-64 -g3 -gdwarf-5 -O0 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection. Compiled with DWARF 5 debugging format. Includes preprocessor macro info. The comp_unit_head::version field is guaranteed to be between 2 and 5, thanks to the check in read_comp_unit_head. So we can still use static strings to pass to record_debugformat, and keep it efficient. In the future, when somebody will update GDB to support DWARF 6, they'll hit this assert and have to update this code. Change-Id: I3270b7ebf5e9a17b4215405bd2e365662a4d6172
-rw-r--r--gdb/dwarf2/cu.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c
index e7aed774c25..61981a45f8a 100644
--- a/gdb/dwarf2/cu.c
+++ b/gdb/dwarf2/cu.c
@@ -64,7 +64,18 @@ dwarf2_cu::start_symtab (const char *name, const char *comp_dir,
list_in_scope = get_builder ()->get_file_symbols ();
- get_builder ()->record_debugformat ("DWARF 2");
+ /* DWARF versions are restricted to [2, 5], thanks to the check in
+ read_comp_unit_head. */
+ gdb_assert (this->header.version >= 2 && this->header.version <= 5);
+ static const char *debugformat_strings[] = {
+ "DWARF 2",
+ "DWARF 3",
+ "DWARF 4",
+ "DWARF 5",
+ };
+ const char *debugformat = debugformat_strings[this->header.version - 2];
+
+ get_builder ()->record_debugformat (debugformat);
get_builder ()->record_producer (producer);
processing_has_namespace_info = false;