[PATCH] binutils/dwarf: Print embedded source, when available
Jan Beulich
jbeulich@suse.com
Thu Apr 16 14:47:32 GMT 2026
On 16.04.2026 16:21, Will Hawkins wrote:
> 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.
Please go ahead with adding some testing.
> I tried to follow all the proper coding style requirements, but I am
> sure that there is something that I missed! Sorry in advance!
Well, first, and unless you have a copyright assignment in place with the
FSF, you need to sign-off on your patch.
> --- 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;
The new variable doesn't need scope wider than the loop its used in. Then
questions towards the change to the loop itself will also be easier to
answer.
> @@ -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.
Please follow GNU comment style (/* Skip source; display on next line. */).
> @@ -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)
DW_LNCT_LLVM_source being in the DW_LNCT_{lo,hi}_user range, how do you
know here that 0x2001 actually means DW_LNCT_LLVM_source?
Jan
More information about the Binutils
mailing list