In particular, I am looking for why we identified the symbol
represented by MSYMBOL
as the function containing PC. What is this symbol's name? That
would be printed
with MSYMBOL_LINKAGE_NAME(msymbol.minsym), I think. Or if you expand,
"msymbol.minsym.mginfo.name".
What is its address (should be msymbol.minsym.mginfo.value.address)?
>
>> How come by looking up a symbol for PC (what is PC's value, btw) we found this symbol?
That's because it's the symbol with the lowest address that satisfies
all the conditions in lookup_minimal_symbol_by_pc_section. It goes
like this:
The loop which does a binary search through the minsyms finds the the
symbol immediately preceding the address of PC is this:
(top-gdb) p newobj
$28 = 26
(top-gdb) p msymbol[newobj]
$29 = {mginfo = {name = 0x10448845 "_image_base__", value = {
ivalue = 4194304, block = 0x400000, bytes = 0x400000 "MZ\220",
address = 0x400000, common_block = 0x400000, chain = 0x400000},
language_specific = {obstack = 0x0, demangled_name = 0x0},
language = language_auto, ada_mangled = 0, section = 0}, size =
0,
filename = 0x0, type = mst_abs, created_by_gdb = 0, target_flag_1 =
0,
target_flag_2 = 0, has_size = 0, hash_next = 0x0,
demangled_hash_next = 0x0}
(our PC is 0x40126d).
Then this loop:
/* Skip various undesirable symbols. */
while (hi >= 0)
{
decrements 'hi' all the way down to 5, because all the preceding
symbols have the type mst_abs:
(top-gdb) p hi
$46 = 5
(top-gdb) p msymbol[hi]
$47 = {mginfo = {name = 0x1044858d "__register_frame_info", value = {
ivalue = 0, block = 0x0, bytes = 0x0, address = 0x0,
common_block = 0x0, chain = 0x0}, language_specific = {obstack = 0x0,
demangled_name = 0x0}, language = language_auto, ada_mangled = 0,
section = 0}, size = 0, filename = 0x0, type = mst_text,
created_by_gdb = 0, target_flag_1 = 0, target_flag_2 = 0, has_size
= 0,
hash_next = 0x0, demangled_hash_next = 0x0}
Note that this symbol's address is zero. This symbol is then
returned, and so cache_pc_function_low becomes zero. Then we get to
this:
cache_pc_function_high = minimal_symbol_upper_bound (msymbol);
minimal_symbol_upper_bound then looks at the following symbols trying
to find the one whose address is different from zero:
for (i = 1; MSYMBOL_LINKAGE_NAME (msymbol + i) != NULL; i++)
{
if ((MSYMBOL_VALUE_RAW_ADDRESS (msymbol + i)
!= MSYMBOL_VALUE_RAW_ADDRESS (msymbol))
&& MSYMBOL_SECTION (msymbol + i) == section)
break;
}
It finds such a symbol in the 10th entry:
(top-gdb) p msymbol[1]
$76 = {mginfo = {name = 0x10448a55 "__set_app_type", value = {ivalue
= 0,
block = 0x0, bytes = 0x0, address = 0x0, common_block = 0x0,
chain = 0x0}, language_specific = {obstack = 0x0,
demangled_name = 0x0}, language = language_auto, ada_mangled = 0,
section = 0}, size = 0, filename = 0x0, type = mst_abs,
created_by_gdb = 0, target_flag_1 = 0, target_flag_2 = 0, has_size
= 0,
hash_next = 0x0, demangled_hash_next = 0x0}
(top-gdb) p msymbol[2]
$77 = {mginfo = {name = 0x104487ad "_dll__", value = {ivalue = 0,
block = 0x0, bytes = 0x0, address = 0x0, common_block = 0x0,
chain = 0x0}, language_specific = {obstack = 0x0,
demangled_name = 0x0}, language = language_auto, ada_mangled = 0,
section = 0}, size = 0, filename = 0x0, type = mst_abs,
created_by_gdb = 0, target_flag_1 = 0, target_flag_2 = 0, has_size
= 0,
hash_next = 0x0, demangled_hash_next = 0x0}
(top-gdb) p msymbol[3]
$78 = {mginfo = {name = 0x104483cd "_dll_characteristics__", value =
{
ivalue = 0, block = 0x0, bytes = 0x0, address = 0x0,
common_block = 0x0, chain = 0x0}, language_specific = {obstack = 0x0,
demangled_name = 0x0}, language = language_auto, ada_mangled = 0,
section = 0}, size = 0, filename = 0x0, type = mst_abs,
created_by_gdb = 0, target_flag_1 = 0, target_flag_2 = 0, has_size
= 0,
hash_next = 0x0, demangled_hash_next = 0x0}
(top-gdb) p msymbol[3]
$79 = {mginfo = {name = 0x104483cd "_dll_characteristics__", value =
{
ivalue = 0, block = 0x0, bytes = 0x0, address = 0x0,
common_block = 0x0, chain = 0x0}, language_specific = {obstack = 0x0,
demangled_name = 0x0}, language = language_auto, ada_mangled = 0,
section = 0}, size = 0, filename = 0x0, type = mst_abs,
created_by_gdb = 0, target_flag_1 = 0, target_flag_2 = 0, has_size
= 0,
hash_next = 0x0, demangled_hash_next = 0x0}
(top-gdb) p msymbol[4]
$80 = {mginfo = {name = 0x1044868d "_fpreset", value = {ivalue = 0,
block = 0x0, bytes = 0x0, address = 0x0, common_block = 0x0,
chain = 0x0}, language_specific = {obstack = 0x0,
demangled_name = 0x0}, language = language_auto, ada_mangled = 0,
section = 0}, size = 0, filename = 0x0, type = mst_abs,
created_by_gdb = 0, target_flag_1 = 0, target_flag_2 = 0, has_size
= 0,
hash_next = 0x0, demangled_hash_next = 0x0}
(top-gdb) p msymbol[5]
$81 = {mginfo = {name = 0x1044fead "_loader_flags__", value = {ivalue
= 0,
block = 0x0, bytes = 0x0, address = 0x0, common_block = 0x0,
chain = 0x0}, language_specific = {obstack = 0x0,
demangled_name = 0x0}, language = language_auto, ada_mangled = 0,
section = 0}, size = 0, filename = 0x0, type = mst_abs,
created_by_gdb = 0, target_flag_1 = 0, target_flag_2 = 0, has_size
= 0,
hash_next = 0x0, demangled_hash_next = 0x0}
(top-gdb) p msymbol[6]
$82 = {mginfo = {name = 0x1044ff9d "_minor_image_version__", value =
{
ivalue = 0, block = 0x0, bytes = 0x0, address = 0x0,
common_block = 0x0, chain = 0x0}, language_specific = {obstack = 0x0,
demangled_name = 0x0}, language = language_auto, ada_mangled = 0,
section = 0}, size = 0, filename = 0x0, type = mst_abs,
created_by_gdb = 0, target_flag_1 = 0, target_flag_2 = 0, has_size
= 0,
hash_next = 0x0, demangled_hash_next = 0x0}
(top-gdb) p msymbol[7]
$83 = {mginfo = {name = 0x104487cd "_minor_os_version__", value = {
ivalue = 0, block = 0x0, bytes = 0x0, address = 0x0,
common_block = 0x0, chain = 0x0}, language_specific = {obstack = 0x0,
demangled_name = 0x0}, language = language_auto, ada_mangled = 0,
section = 0}, size = 0, filename = 0x0, type = mst_abs,
created_by_gdb = 0, target_flag_1 = 0, target_flag_2 = 0, has_size
= 0,
hash_next = 0x0, demangled_hash_next = 0x0}
(top-gdb) p msymbol[8]
$84 = {mginfo = {name = 0x1044ff65 "_minor_subsystem_version__",
value = {
ivalue = 0, block = 0x0, bytes = 0x0, address = 0x0,
common_block = 0x0, chain = 0x0}, language_specific = {obstack = 0x0,
demangled_name = 0x0}, language = language_auto, ada_mangled = 0,
section = 0}, size = 0, filename = 0x0, type = mst_abs,
created_by_gdb = 0, target_flag_1 = 0, target_flag_2 = 0, has_size
= 0,
hash_next = 0x0, demangled_hash_next = 0x0}
(top-gdb) p msymbol[9]
$85 = {mginfo = {name = 0x10448b35 "_rt_psrelocs_size", value =
{ivalue = 0,
block = 0x0, bytes = 0x0, address = 0x0, common_block = 0x0,
chain = 0x0}, language_specific = {obstack = 0x0,
demangled_name = 0x0}, language = language_auto, ada_mangled = 0,
section = 0}, size = 0, filename = 0x0, type = mst_abs,
created_by_gdb = 0, target_flag_1 = 0, target_flag_2 = 0, has_size
= 0,
hash_next = 0x0, demangled_hash_next = 0x0}
(top-gdb) p msymbol[10]
$86 = {mginfo = {name = 0x1044fe8d "_major_image_version__", value =
{
ivalue = 1, block = 0x1,
bytes = 0x1 <error: Cannot access memory at address 0x1>,
address = 0x1, common_block = 0x1, chain = 0x1}, language_specific = {
obstack = 0x0, demangled_name = 0x0}, language = language_auto,
ada_mangled = 0, section = 0}, size = 0, filename = 0x0, type =
mst_abs,
created_by_gdb = 0, target_flag_1 = 0, target_flag_2 = 0, has_size
= 0,
hash_next = 0x0, demangled_hash_next = 0x0}
And so cache_pc_function_high becomes 1.