Bug 6977 - Incorrect resolution of variables in function scope
Summary: Incorrect resolution of variables in function scope
Status: RESOLVED FIXED
Alias: None
Product: systemtap
Classification: Unclassified
Component: translator (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-24 05:38 UTC by Prerna
Modified: 2015-10-14 21:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Prerna 2008-10-24 05:38:54 UTC
The following script fails when run on a NUMA machine :
probe kernel.function("get_page_from_freelist")
{
        printf("zone_reclaim_mode = %x\n", $zone_reclaim_mode);
}

Error :
semantic error: failed to retrieve location attribute for local
'zone_reclaim_mode' (dieoffset: 0xzone_reclaim_mode): identifier
'$zone_reclaim_mode' at scripts/zrm.stp:5:44
source:         printf("zone_reclaim_mode = %x\n", $zone_reclaim_mode)
                                                           ^
Comment 1 Prerna 2008-10-24 05:52:41 UTC
This arises because the variable "zone_reclaim_mode" is a global variable
defined in a different compilation unit than that of the function
"get_page_from_freelist()"
The Dwarf entry for "zone_reclaim_mode" in the CU of the function is simply a
declaration which doesnt have location info for it (since the variable is
defined as an extern int in this CU). This causes a semantic error when the stap
translator tries to fetch DWARF location info from its declaration.

To me, it appears similar to the problem of trying to access a global variable
in a different compile unit than the one in which it is defined.
Comment 2 Prerna 2008-10-24 06:32:55 UTC
A similar illustration would be the following script :

probe kernel.function("vmap")
{
	printf("\n num_physpages = %d",$num_physpages);
}

which fails with the following error :

semantic error: failed to retrieve location attribute for local 'num_physpages'
(dieoffset: 0xe_mmapnum_physpages): identifier '$num_physpages' at
scripts/num_physpages.stp:4:33
        source: 	printf("\n num_physpages = %d",$num_physpages);
                	                               ^

Here too, the variable "num_physpages" is defined in a different CU than the CU
of the function vmap, hence the location is not fetched. 
Comment 3 Prerna 2008-10-24 08:09:06 UTC
IMHO,presently, in order to find a DWARF debugging information entry for a
global object name, the translator tries to search inside the parent scope
within the relevant compilation unit inside the .debug_info section of DWARF
information.

DWARF has another section ".debug_pubnames" which is a table listing the names
of global objects whose definitions or declarations are represented by debugging
information entries owned by each compilation unit.
However, this section cant be used directly for name lookup because :
1) the offset/object-name pairs are listed on a compilation-unit basis. So one
still has to determine which CU the global variable is defined to be able to
look up.
2) The section lists tuples which list the object name for a given offset for
each CU. (so a search on names is not possible)

For fast lookup, a table is needed which hashes a given global object name to
the CU in which it is defined and the offset within the .debug_info section
where its debuging information entry would be found. 

I'm not sure if such a structure ought to be included as a separate section in
dwarf itself or whether systemtap translator must build it independently based
on kernel debuginfo..
Comment 4 Frank Ch. Eigler 2015-10-14 21:37:06 UTC
This has been working for some time, via more scope-aware resolution paths for $variables.