[PATCH] binutils/dwarf: Print embedded source, when available

Will Hawkins hawkinsw@obs.cr
Thu Apr 16 14:56:11 GMT 2026


Thank you for the quick reply! See inline!

On Thu, Apr 16, 2026 at 10:47 AM Jan Beulich <jbeulich@suse.com> wrote:
>
> 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.

You got it!

>
> > 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.
>

Will do!

> > --- 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.

Nuts. Missed that! Absolutely will change!

>
> > @@ -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.  */).

Sorry!! I have no idea how that one slipped through!

>
> > @@ -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?
>

The literal comes from
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/BinaryFormat/Dwarf.def#L1213

I chose to use that one because clang is the most popular compiler
that implements this feature and I was hoping for as much
compatibility as possible.

However, its value in v6 will be 0x6
(https://dwarfstd.org/issues/180201.1.html).

We could consider using both? I have been working with this feature in
lldb and would be more than happy to submit a patch there that changes
it to use 0x6. Of course, there will likely need to be some support
for backwards compatibility (assuming that there are binaries in the
wild using 0x2001).

I would be more than happy to do whatever you think is best!

Thank you again for the review! I will prepare a v2 ASAP!

Will



> Jan


More information about the Binutils mailing list