lookup symbols

63 views
Skip to first unread message

Marina Minkin

unread,
Mar 17, 2022, 1:58:12 PM3/17/22
to DynamoRIO Users

Hi,

I am trying to lookup symbols for certain addresses, but the only symbols I am getting are either __memmove_avx_unaligned_ermsfrom libc both for addresses that actually match this symbol and for addresses that do not match it and are in a different module. I also sometimes get symbol unavailable for addresses that should match __memmove_avx_unaligned_erms. Can you please help me? Attached the code that does not work. I want to at least get a symbol from the correct module.

Thanks.

Marina

module_data_t *data;
data = dr_lookup_module(pc);
DR_ASSERT(data != NULL);

this->filename = std::string(data->full_path);

drsym_error_t symres;
drsym_info_t sym;

static char name[STR_MAX_LEN]; // I made it static to use less stack
sym.struct_size = sizeof(sym);
sym.name = name;
sym.name_size = STR_MAX_LEN;
static char file[STR_MAX_LEN]; // I made it static to use less stack
sym.file = file; // can also be NULL
sym.file_size = STR_MAX_LEN;

symres = drsym_lookup_address(data->full_path, pc - data->start, &sym,
                DRSYM_DEFAULT_FLAGS);
DR_ASSERT(symres);
if(symres != DRSYM_ERROR_LINE_NOT_AVAILABLE) {
        this->func_name = std::string(sym.name);
        this->func_offset = pc - data->start - sym.start_offs;
} else {
        this->func_name = "Symbol unavailable";
}

dr_free_module_data(data);

Derek Bruening

unread,
Mar 21, 2022, 11:47:00 PM3/21/22
to Marina Minkin, DynamoRIO Users
It looks like success and error codes are not properly handled.  drsym_error_t is an enum with DRSYM_SUCCESS equal to 0, so asserting its value would fail on success (, and the check for not being the line-not-avail code will include errors.

--
You received this message because you are subscribed to the Google Groups "DynamoRIO Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dynamorio-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dynamorio-users/dcef2032-b539-461b-8ea6-8c0588330d73n%40googlegroups.com.

Marina Minkin

unread,
Mar 22, 2022, 11:38:33 AM3/22/22
to DynamoRIO Users

Thanks! Looks like drsym_lookup_address ALWAYS fails

Derek Bruening

unread,
Mar 22, 2022, 12:14:42 PM3/22/22
to Marina Minkin, DynamoRIO Users
On Tue, Mar 22, 2022 at 11:38 AM Marina Minkin <thema...@gmail.com> wrote:

Thanks! Looks like drsym_lookup_address ALWAYS fails

"fails" is not very descriptive: what is the error code?  Did you check drsym_module_has_symbols and drsym_get_module_debug_kind?
 

Marina Minkin

unread,
Mar 22, 2022, 12:35:39 PM3/22/22
to DynamoRIO Users
Thanks for the help! I get either `DRSYM_ERROR_SYMBOL_NOT_FOUND` or `DRSYM_ERROR_LINE_NOT_AVAILABLE` (errors 5 and 6)
If I get `DRSYM_ERROR_LINE_NOT_AVAILABLE` (6) from `drsym_lookup_address()`, then `drsym_module_has_symbols()` returns ` DRSYM_SUCCESS` (0) and `drsym_get_module_debug_kind()` returns 257 (not sure what this is).
If I get `DRSYM_ERROR_SYMBOL_NOT_FOUND` (5) from `drsym_lookup_address()`, then  `drsym_module_has_symbols()` returns `DRSYM_ERROR` (1) and `drsym_get_module_debug_kind()` returns `DRSYM_SYMBOLS` (0).
Both modules have some symbols if I look at them with objdump.

Derek Bruening

unread,
Mar 22, 2022, 1:49:11 PM3/22/22
to Marina Minkin, DynamoRIO Users
On Tue, Mar 22, 2022 at 12:35 PM Marina Minkin <thema...@gmail.com> wrote:
Thanks for the help! I get either `DRSYM_ERROR_SYMBOL_NOT_FOUND` or `DRSYM_ERROR_LINE_NOT_AVAILABLE` (errors 5 and 6)

As the documentation describes DRSYM_ERROR_LINE_NOT_AVAILABLE is a successful symbol lookup just without a function+line number:

 * When returning DRSYM_ERROR_LINE_NOT_AVAILABLE, the symbol information
 * start_offs, end_offs, and name will still be valid.
 
If I get `DRSYM_ERROR_LINE_NOT_AVAILABLE` (6) from `drsym_lookup_address()`, then `drsym_module_has_symbols()` returns ` DRSYM_SUCCESS` (0) and `drsym_get_module_debug_kind()` returns 257 (not sure what this is).

The docs/header files tell you what 257 is: please read them.
 
If I get `DRSYM_ERROR_SYMBOL_NOT_FOUND` (5) from `drsym_lookup_address()`, then  `drsym_module_has_symbols()` returns `DRSYM_ERROR` (1) and `drsym_get_module_debug_kind()` returns `DRSYM_SYMBOLS` (0).

DRSYM_SYMBOLS is 1.  0 means there is no symbol information which IIRC for ELF means no .symtab.  drsyms should still look at exports in .dynsym in that case.  Are the symbols you think it should find exported?Are they in .dynsym?  You could walk the drsyms code in the debugger to see whether it finds any symbol table at all or whether it can't find the address in whatever table it does find.
 

Marina Minkin

unread,
Mar 22, 2022, 1:57:16 PM3/22/22
to DynamoRIO Users
Thank you so much!! Now I am getting correct symbols from one library, and printing an error message from the other library, which is awesome :)
Reply all
Reply to author
Forward
0 new messages