[Dwarf-Discuss] Does gcc optimization impacts retriving Dwarf information?
M. Mohan Kumar
Thu May 28 08:52:25 GMT 2009
We are implementing a feature in the crash utility to display the
information about local variables for a selected stack frame in a kernel
Even though we could retrive the local variable information (like variable
name, type), most of the time we were not able to retrive the values for the
variables. The dwarf library function 'dwarf_attr_integrate'
(dwarf_attr_integrate(var_die, DW_AT_location, &loc_attr)) returns error.
The kernel is compiled with -O2 option. We tested this case with gdb, gdb
prints 'optimized out' for most of the local variables.
We tried testing this functionality in a user space application. We compiled
a program using -O0 and -O2 and generated dumps core.o0 and core.o2. While
we could watch the local variables values using core.o0, we could not get
the variables value using core.o2. Does it mean that compiling with -O2
option removes some of the information needed by DWARF library functions?
A sample output from our crash extension local:
crash> local locals
display locals for function .pseries_dedicated_idle_sleep
cpu unsigned int
start_snooze long unsigned int value:1
in_purr long unsigned int
out_purr long unsigned int
In above output, we could retrieve value for 'start_snooze' variable only,
for all other variables some of the dwarf APIs fail.
When checked with gdb,
(gdb) bt full
#0 0xc00000000003b118 in pseries_dedicated_idle_sleep () at
cpu = <value optimized out>
start_snooze = 1
This problem (unable to retrieve variable values) raises two questions:
1. Does it mean that compiling with -O2 option removes some of the
information needed by DWARF library functions?
2. Does it require handling it differently in our implementation?
The location information is accessed in the function in variable_address in
the file local.c
M. Mohan Kumar
More information about the Dwarf-discuss