MachoResolveAddress
Description
Look up the symbol whose value is closest-not-greater than vaddr and within a reasonable function span (next symbol’s value or the segment end).
vaddr is the file-relative virtual address: for a runtime IP in a PIE binary, subtract the slide first.
Success
Returns a pointer to the matching MachoSymbol.
Failure
Returns NULL.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
MachoCache.c:171:
// (1) Main file's LC_SYMTAB.
const MachoSymbol *s = MachoResolveAddress(&entry->main, file_relative);
if (s && s->name && s->name[0]) {
*out_name = s->name;- In
MachoCache.c:181:
// (2) Sidecar dSYM's LC_SYMTAB.
if (entry_open_dsym(entry, self->allocator)) {
s = MachoResolveAddress(&entry->dsym, file_relative);
if (s && s->name && s->name[0]) {
*out_name = s->name;- In
MachO.c:500:
// same section (or the section end). N_STAB entries are skipped:
// stab iff any of the high three bits of n_type is set.
const MachoSymbol *MachoResolveAddress(const Macho *self, u64 vaddr) {
if (!self || VecLen(&self->symbols) == 0)
return NULL;- In
MachO.c:387:
// Address at the function start.
const MachoSymbol *s = MachoResolveAddress(&m, 0x100000010ull);
bool ok = s && s->name && ZstrCompare(s->name, "my_function") == 0;- In
MachO.c:391:
// Address just past the start, still inside the function body.
s = MachoResolveAddress(&m, 0x100000020ull);
ok = ok && s && ZstrCompare(s->name, "my_function") == 0;- In
MachO.c:395:
// Address below the symbol value: no match.
s = MachoResolveAddress(&m, 0x100000000ull);
ok = ok && s == NULL;- In
MachO.c:536:
// Inside the first symbol's span [0x10, 0x40): resolves to it.
const MachoSymbol *s = MachoResolveAddress(&m, 0x100000010ull);
ok = ok && s != NULL && s->value == 0x100000010ull;
s = MachoResolveAddress(&m, 0x100000030ull);- In
MachO.c:538:
const MachoSymbol *s = MachoResolveAddress(&m, 0x100000010ull);
ok = ok && s != NULL && s->value == 0x100000010ull;
s = MachoResolveAddress(&m, 0x100000030ull);
ok = ok && s != NULL && s->value == 0x100000010ull;- In
MachO.c:543:
// At the next symbol's value: resolves to the second symbol, not the
// first.
s = MachoResolveAddress(&m, 0x100000040ull);
ok = ok && s != NULL && s->value == 0x100000040ull;- In
MachO.c:620:
u64 vaddr = runtime_addr - slide;
const MachoSymbol *sym = MachoResolveAddress(&m, vaddr);
bool ok = sym != NULL && sym->name != NULL &&
ZstrFindSubstring(sym->name, "test_macho_resolves_running_binary_symbol") != NULL;- In
MachO.c:1350:
// Query above both; correct best is the 0x...40 symbol (max <= vaddr).
const MachoSymbol *s = MachoResolveAddress(&m, 0x100000050ull);
ok = ok && s != NULL && s->value == 0x100000040ull;- In
MachO.c:1389:
bool ok = VecLen(&m.symbols) == 2;
const MachoSymbol *s = MachoResolveAddress(&m, 0x100000020ull);
// The later equal-valued symbol (n_sect 2) wins under `>=`.
ok = ok && s != NULL && s->value == 0x100000010ull && s->section_index == 2;
Last updated on