DynamoRIO / dynamorio

Dynamic Instrumentation Tool Platform
Other
2.57k stars 550 forks source link

[CRASH] when using drsym_lookup_address [Windows 19045] #6789

Closed hxm-cpp closed 2 months ago

hxm-cpp commented 2 months ago
static dr_emit_flags_t event_bb(void* drcontext, void* tag, instrlist_t* bb, bool for_trace, bool translating)
{

    file_t f = dr_open_file("trace.log", DR_FILE_WRITE_APPEND);

    for (instr_t* instr = instrlist_first(bb); instr != NULL; instr = instr_get_next(instr))
    {
        app_pc rip        = instr_get_app_pc(instr);
        module_data_t* md = dr_lookup_module(rip);
        if (md != NULL)
        {
            drsym_info_t sym_info;
            sym_info.struct_size = sizeof(sym_info);
            sym_info.name_size   = 256; 
            sym_info.file_size   = 256; 
            sym_info.name        = static_cast<char*>(dr_global_alloc(sym_info.name_size));
            sym_info.file        = static_cast<char*>(dr_global_alloc(sym_info.file_size));
            drsym_error_t symres = drsym_lookup_address(md->full_path, rip - md->start, &sym_info, 0);
            if (symres == DRSYM_SUCCESS || symres == DRSYM_ERROR_LINE_NOT_AVAILABLE)
            {
                dr_fprintf(f, "RIP: %p Function: %s\n", rip, sym_info.name);
            }
            else
            {
                dr_fprintf(f, "RIP: %p\n", rip);
            }
            dr_global_free(sym_info.name, sym_info.name_size);
            dr_global_free(sym_info.file, sym_info.file_size);
            dr_free_module_data(md);
        }
        else
        {
            dr_fprintf(f, "RIP: %p\n", rip);
        }
        instr_disassemble(drcontext, instr, f);
        dr_fprintf(f, "\n");
    }
    dr_close_file(f);

    return DR_EMIT_DEFAULT;
}

stack :

H:\dev\DynamoRIO-Windows-10.0.19700/lib64\debug\dynamorio.dll=0x0000000015000000
H:\dev\Tracer\build\RelWithDebInfo\Tracer.dll=0x00000000e7b90000
H:\dev\DynamoRIO-Windows-10.0.19700/ext\lib64\debug/drsyms.dll=0x00000000e7bc0000
H:\dev\DynamoRIO-Windows-10.0.19700/ext\lib64\debug/dbghelp.dll=0x00000000e7c60000
C:\Windows/system32/ucrtbase.dll=0x0000000002de0000
C:\Windows/system32/kernel32.dll=0x00000000023f0000
C:\Windows/system32/KERNELBASE.dll>
<CURIOSITY : instr_new == instrlist_first(ilist) || instr_new == instr_get_next(instrlist_first(ilist)) in file D:\a\dynamorio\dynamorio\core\win32\callback.c line 2085
version 10.0.19700, custom build
-no_dynamic_options -syntax_intel -disasm_mask 1 -client_lib 'H:\dev\Tracer\build\RelWithDebInfo\Tracer.dll;0;' -client_lib64 'H:\dev\Tracer\build\RelWithDebInfo\Tracer.dll;0;' -code_api -probe_api -stack_size 56K -max_elide_jmp 0 -max_elide_call 0 -no_inline_ignored_syscalls -native_exec_default_list '' -no_native_exec_
H:\dev\DynamoRIO-Windows-10.0.19700/lib64\debug\dynamorio.dll=0x0000000015000000
H:\dev\Tracer\build\RelWithDebInfo\Tracer.dll=0x00000000e7b90000
H:\dev\DynamoRIO-Windows-10.0.19700/ext\lib64\debug/drsyms.dll=0x00000000e7bc0000
H:\dev\DynamoRIO-Windows-10.0.19700/ext\lib64\debug/dbghelp.dll=0x00000000e7c60000
C:\Windows/system32/ucrtbase.dll=0x0000000002de0000
C:\Windows/system32/kernel32.dll=0x00000000023f0000
C:\Windows/system32/KERNELBASE.dll>
<Cleaning hooked Nt wrapper @0x00007ff8ae990800 sysnum=0x1c2>
<Application H:\S\common\x\x.exe (18696).  DynamoRIO Sample Client 'tracer' internal crash at PC 0x00000000150fff58.  Please report this at http://dynamorio.org.  Program aborted.
0xc0000005 0x00000000 0x00000000150fff58 0x00000000150fff58 0x0000000000000000 0x0000000000000088
Base: 0x0000000015000000
Registers: eax=0x0000000000000088 ebx=0x00007ff8ae942690 ecx=0x0000000000000088 edx=0x0000000000000000
    esi=0x0000000147c7d058 edi=0x0000000000000380 esp=0x0000000147c4dee0 ebp=0x0000000147c893f0
    r8 =0x0000000147c4e0e0 r9 =0x0000000000000000 r10=0x78f8fcf8f8f8f8fc r11=0x0000000147c78490
    r12=0x000000000014fbb0 r13=0x0000000000000000 r14=0x0000000147c2f080 r15=0x0000000000000000
    eflags=0x0000000000010246
version 10.0.19700, custom build
-no_dynamic_options -syntax_intel -disasm_mask 1 -client_lib 'H:\dev\Tracer\build\RelWithDebInfo\Tracer.dll;0;' -client_lib64 'H:\dev\Tracer\build\RelWithDebInfo\Tracer.dll;0;' -code_api -probe_api -stack_size 56K -max_elide_jmp 0 -max_elide_call 0 -no_inline_ignored_syscalls -native_exec_default_list '' -no_native_exec_
0x0000000147c893f0 0x00007ff8aeae8000
0x00007ff8ae8f0000 0x0000ffff00000004>