[PATCH] binutils/dwarf: Print embedded source, when available
Will Hawkins
hawkinsw@obs.cr
Thu Apr 16 14:21:06 GMT 2026
When an object file with debugging information has the source embedded
(via DW_LNCT_LLVM_source), the `--dwarf=rawline` output from objdump
prints the source but the format leaves something to be desired.
This small patch makes it so that the source is printed started on a
new line in the File Name Table when the user invokes `objdump` with
`--dwarf=rawline`.
The DW_LNCT_LLVM_source line number header entry format is slated to
be added to DWARFv6: https://dwarfstd.org/issues/180201.1.html and
lldb supports it (and gdb will soon support it).
If this is a feature that seems worthwhile, I would be more than happy
to add tests. I just didn't want to waste anyone's time with a long(ish)
patch at first.
I tried to follow all the proper coding style requirements, but I am
sure that there is something that I missed! Sorry in advance!
---
binutils/dwarf.c | 32 ++++++++++++++++++++++++++------
include/dwarf2.h | 1 +
2 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index fa8dce25..fbf42c29 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -5776,7 +5776,7 @@ display_formatted_table (unsigned char *data,
{
unsigned char *format_start, format_count, *format, formati;
uint64_t data_count, datai;
- unsigned int namepass, last_entry = 0;
+ unsigned int namepass, namesourcepass, last_entry = 0;
const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table");
SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
@@ -5847,6 +5847,9 @@ display_formatted_table (unsigned char *data,
case DW_LNCT_MD5:
printf (_("\tMD5\t\t\t"));
break;
+ case DW_LNCT_LLVM_source:
+ // Skip source ... display on next line.
+ break;
default:
printf (_("\t(Unknown format content type %" PRIu64 ")"),
content_type);
@@ -5861,8 +5864,9 @@ display_formatted_table (unsigned char *data,
unsigned char *datapass = data;
printf (" %d", last_entry++);
- /* Delay displaying name as the last entry for better screen layout. */
- for (namepass = 0; namepass < 2; namepass++)
+ /* Delay displaying name/source as the last entry for better screen
+ layout. */
+ for (namesourcepass = 0; namesourcepass < 3; namesourcepass++)
{
format = format_start;
data = datapass;
@@ -5872,13 +5876,29 @@ display_formatted_table (unsigned char *data,
READ_ULEB (content_type, format, end);
READ_ULEB (form, format, end);
- bool do_loc = (content_type == DW_LNCT_path) != (namepass == 1);
+
+ bool do_loc = (content_type == DW_LNCT_path)
+ != (namesourcepass == 1);
+ do_loc |= (content_type == DW_LNCT_LLVM_source)
+ != (namesourcepass == 2);
+
+ char delimiter = '\t';
+
+ /* Print Source last (if available) and print it
+ starting on the next line. */
+ if (namesourcepass == 2 && content_type == DW_LNCT_LLVM_source)
+ {
+ delimiter = ' ';
+ putchar ('\n');
+ printf (" Source:");
+ }
data = read_and_display_attr_value (0, form, 0, start, data, end,
0, linfo->li_address_size,
linfo->li_offset_size,
linfo->li_version, NULL,
- do_loc, section, NULL, '\t',
- -1, false, 0, 0, false);
+ do_loc, section, NULL,
+ delimiter, -1, false, 0, 0,
+ false);
}
}
diff --git a/include/dwarf2.h b/include/dwarf2.h
index bf9287f1..ee546a40 100644
--- a/include/dwarf2.h
+++ b/include/dwarf2.h
@@ -294,6 +294,7 @@ enum dwarf_line_number_content_type
DW_LNCT_size = 0x4,
DW_LNCT_MD5 = 0x5,
DW_LNCT_lo_user = 0x2000,
+ DW_LNCT_LLVM_source = 0x2001,
DW_LNCT_hi_user = 0x3fff
};
--
2.49.0
More information about the Binutils
mailing list