int main( int argc, char ** argv ) { int status = 0; int fid = -1; Elf * elfp = NULL; Dwarf_Error error = (Dwarf_Error) NULL; Dwarf_Debug dbg; Dwarf_Cie * cie_data = NULL; Dwarf_Fde * fde_data = NULL; Dwarf_Signed cie_count, fde_count; if( argc != 2 ) { fprintf( stderr, "usage: %s <binary>\n", argv[0] ); return 1; } fid = open( argv[1], O_RDONLY ); if( fid == -1 ) { fprintf( stderr, "failed to open( %s ).\n", argv[1] ); return 4; } if( elf_version( EV_CURRENT ) == EV_NONE ) { fprintf( stderr, "elf version check failed.\n" ); return 6; } #if defined( USE_ELF_POINTER ) elfp = elf_begin( fid, ELF_C_READ, (Elf *)NULL ); if( elfp == NULL ) { fprintf( stderr, "failed to elf_begin().\n" ); return 5; } status = dwarf_elf_init( elfp, DW_DLC_READ, NULL, NULL, & dbg, & error ); if( status != DW_DLV_OK ) { fprintf( stderr, "failed to dwarf_elf_init().\n" ); return 2; } #else status = dwarf_init( fid, DW_DLC_READ, NULL, NULL, & dbg, NULL ); if( status != DW_DLV_OK ) { fprintf( stderr, "failed to dwarf_init().\n" ); return 2; } #endif status = dwarf_get_fde_list_eh( dbg, & cie_data, & cie_count, & fde_data, & fde_count, & error ); if( status != DW_DLV_OK ) { fprintf( stderr, "failed to dwarf_get_fde_list_eh().\n" ); return 3; } return 0; } /* end main() */
bool drsym_obj_dwarf_init(void *mod_in, Dwarf_Debug *dbg) { elf_info_t *mod = (elf_info_t *) mod_in; Dwarf_Error de = {0}; if (mod == NULL) return false; if (dwarf_elf_init(mod->elf, DW_DLC_READ, NULL, NULL, dbg, &de) != DW_DLV_OK) { NOTIFY_DWARF(de); return false; } return true; }
static int process_one_file(Elf *elf) { Dwarf_Debug dbg; int ret; ret = dwarf_elf_init(elf, DW_DLC_READ, NULL, NULL, &dbg, NULL); if (ret != DW_DLV_OK) { fprintf(stderr, "SET dwarf: Error in dwarf_elf_init()\n"); return 1; } ret = process_CUs(dbg); dwarf_finish(dbg, NULL); return ret; }
int _dwarf_addr_finder(dwarf_elf_handle elf_file_ptr, Dwarf_addr_callback_func cb_func, int *dwerr) { Dwarf_Error err = 0; Dwarf_Debug dbg = 0; int res = 0; int errval = 0; int sections_found = 0; res = dwarf_elf_init(elf_file_ptr, DW_DLC_READ, /* errhand */ 0, /* errarg */ 0, &dbg, &err); if (res == DW_DLV_ERROR) { int errv = (int) dwarf_errno(err); return errv; } if (res == DW_DLV_NO_ENTRY) { return res; } send_addr_note = cb_func; res = handle_debug_info(dbg, &errval); switch (res) { case DW_DLV_OK: ++sections_found; break; case DW_DLV_NO_ENTRY: break; default: case DW_DLV_ERROR: dwarf_finish(dbg, &err); *dwerr = errval; return res; } res = handle_debug_aranges(dbg, cb_func, &errval); switch (res) { case DW_DLV_OK: ++sections_found; break; case DW_DLV_NO_ENTRY: break; default: case DW_DLV_ERROR: dwarf_finish(dbg, &err); *dwerr = errval; return res; } res = handle_debug_frame(dbg, cb_func, &errval); switch (res) { case DW_DLV_OK: ++sections_found; break; case DW_DLV_NO_ENTRY: break; default: case DW_DLV_ERROR: dwarf_finish(dbg, &err); *dwerr = errval; return res; } res = handle_debug_loc(); /* does nothing */ switch (res) { case DW_DLV_OK: ++sections_found; break; case DW_DLV_NO_ENTRY: break; default: case DW_DLV_ERROR: /* IMPOSSIBLE : handle_debug_loc cannot return this */ dwarf_finish(dbg, &err); *dwerr = errval; return res; } *dwerr = 0; res = dwarf_finish(dbg, &err); if (res == DW_DLV_ERROR) { *dwerr = (int) dwarf_errno(err); return DW_DLV_ERROR; } if (sections_found == 0) { return DW_DLV_NO_ENTRY; } return DW_DLV_OK; }