[Dwarf-Discuss] DW_LNE_set_discriminator usage

Roland McGrath roland at redhat.com
Thu Jun 17 16:46:07 PDT 2010


I've never seen DW_LNE_set_discriminator used.  GCC doesn't generate it.

The definition of the "discriminator register" in 6.2.2 is clear enough:
"Discriminator values are assigned arbitrarily by the DWARF producer ..."
But nothing anywhere mentions what this might be for.

The 3->4 changes list includes, "Add new line number table support to
facilitate profile based compiler optimization."  This is quite cryptic.
The term "profile" never appears again in the document, so I can only guess
that the one unexplained new .debug_line feature is what this refers to.

I can surmise that if a compiler generated multiple different chunks of
code from the same source, optimized in different ways for later "profile
based" selection, the discriminator would group such chunks somehow.
But how, and for what?

It's already the case that PC->source-location is a one->many mapping.
This appears commonly today for inlined functions, or with similar effects
from multiply #include'd macroized source code and such.  Consumers already
handle those cases without having any explicit discriminator.

If you did have multiple chunks of code doing the same thing,
i.e. associated with the same "program scope" entry, how would that look?
In the inline case, it's always clear enough because a given PC resides in
only one DW_TAG_inlined_subroutine's ranges, so multiple .debug_line PCs
mapping to the same source location can be understood unambiguously by
finding the different DW_TAG_inlined_subroutine or DW_TAG_subprogram
whose ranges cover disjoint PCs.

If there are two variants of code generated for the same function or part
of a function, would there be just one DW_TAG_subprogram (or whatever) with
all those code ranges covered in its DW_AT_ranges?  In that case, I guess
the discriminator helps you identify two parallel code chunks in the same
program scope entry as variants of the same semantic code.  Is that the plan?

Enough of my speculations.  Someone just reveal it!  What is the plan?
What does any extant or imagined DWARF consumer actually use the
discriminator for?

The DWARF specification document doesn't have big informative "rationale"
appendices like some other standards do.  It sure would be nice to have
some quasi-official commentary about where all this stuff came from.  In
some parts of the specification, there are long italicized paragraphs that
serve the same purpose as "rationale" sections do in other standards.  But
there are plenty more things like DW_LNE_set_discriminator where there is
just nothing to be found in the document itself to help a person figure out
what the intent of the feature was.


Thanks,
Roland



More information about the Dwarf-Discuss mailing list