This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: get a PC from a label


> Can you reliably, with regard to optimization, get the pc for  a 
> DW_TAG_label that does not have a DW_AT_low_pc associated with it?

Reliable, and with regard to optimization, are both the compiler's bailiwick.
We can just give you what the compiler emitted.  (And we're glad to advise
you when to read the compiler maintainers the riot act. ;-)

In DWARF, the line information is not correlated with the DIE tree at all
(except by CU).  You can assume that since the compiler produced both, the
actual details were correlated to begin with.  But, you know, you might
also have assumed that the compiler would emit the right attributes. ;-)

By the spec, DW_TAG_label without DW_AT_low_pc is just wrong.
Shoot the hostage.

To be civilized about it, the DW_TAG_label ought to have decl_{file,line}
attributes as well.  But if the compiler is omitting the (required) low_pc,
then depending on it for the decl coordinate attribues (which are obviously
right and are shown in the Appendix A table, but are not explicitly
mentioned in section 3.5) does not make confidence well up.

In a trivial test, F10's gcc-4.3.2-7.x86_64 emits a label with
decl_{file,line}; without optimization, it emits low_pc too, but with
optimization it doesn't.

> For instance doing something like:
>  dwarf_getsrclines
>  for each line until a close match
>      dwarf_onesrcline
>      dwarf__lineno

dwarf_getsrc_file does this for you.  If you have decl_file/decl_line
(and, theoretically, decl_column) from the DW_TAG_label, you can do:

	dwarf_getsrc_file (dw, dwarf_decl_file (die),
			       dwarf_decl_file (die),
			       dwarf_decl_column (die),
			   &result, &nresult)

I guess it looks through all CUs, so maybe you actually don't want to use it.
When doing it by hand, you can actually use just == pointer comparisons on the
file name, because what you get from decl_file and what you get in the line
table will be the very same string in the CU's file table.

If you get multiple hits, you have to filter on the one (hopefully just
one!) address that the label's containing scope DIE dwarf_haspc.

>  dwarf_lineaddr to get its address

Right.


Thanks,
Roland

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]