Skip to content

Commit e90c7d0

Browse files
committed
refactor(debuginfo): use find_rx_mapping for fallback DI lookup
The fallback added in 938e424 used VG_(am_find_nsegment) + VG_(am_get_filename) + strcmp against each DI's fsm.filename. Replace it with ML_(find_rx_mapping)(di, a, a), which walks the same set of rx mappings already recorded for each DebugInfo and keeps a per-DI single-entry cache (last_rx_map), so the hot path is O(1). No coverage change for BOLT-style binaries: both R-E PT_LOADs are recorded as rx DebugInfoMappings during ELF acceptance, so the loop finds them just as well as the filename match did. Also emit a Vg_DebugMsg trace when the fallback fires (only with -v -v).
1 parent fe0dbfc commit e90c7d0

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

coregrind/m_debuginfo/debuginfo.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,21 +2621,28 @@ DebugInfo* VG_(find_DebugInfo) ( DiEpoch ep, Addr a )
26212621
optimized binaries: .bolt.org.text + .text + .text.warm + .text.cold
26222622
live in two separate R-E PT_LOAD segments). The text-range check above
26232623
only covers the section named ".text", so addresses in the other
2624-
executable region are missed and end up attributed to "???". Ask the
2625-
address-space manager which file backs this address, and match it to
2626-
a DebugInfo by filename. */
2624+
executable region are missed and end up attributed to "???". Match
2625+
against the rx mappings recorded for each DebugInfo. find_rx_mapping
2626+
keeps a per-DI single-entry cache (last_rx_map) so the hot case is
2627+
O(1) after the first hit. */
26272628
if (eq_DiEpoch(ep, VG_(current_DiEpoch)())) {
2628-
const NSegment* seg = VG_(am_find_nsegment)(a);
2629-
const HChar* filename;
2630-
if (seg != NULL && (filename = VG_(am_get_filename)(seg)) != NULL) {
2631-
for (di = debugInfo_list; di != NULL; di = di->next) {
2632-
if (!is_DI_valid_for_epoch(di, ep))
2633-
continue;
2634-
if (di->fsm.filename != NULL
2635-
&& 0 == VG_(strcmp)(di->fsm.filename, filename)) {
2636-
return di;
2637-
}
2638-
}
2629+
for (di = debugInfo_list; di != NULL; di = di->next) {
2630+
if (!is_DI_valid_for_epoch(di, ep))
2631+
continue;
2632+
2633+
const DebugInfoMapping* map = ML_(find_rx_mapping)(di, a, a);
2634+
if (map == NULL)
2635+
continue;
2636+
2637+
if (VG_(clo_verbosity) >= 2) {
2638+
VG_(message)(Vg_DebugMsg,
2639+
"find_DebugInfo: rx-mapping fallback matched 0x%lx -> "
2640+
"DI %p (%s) [avma=0x%lx size=%lu]\n",
2641+
a, di,
2642+
di->fsm.filename ? di->fsm.filename : "(no filename)",
2643+
map->avma, map->size);
2644+
}
2645+
return di;
26392646
}
26402647
}
26412648
return NULL;

0 commit comments

Comments
 (0)