dwarfsym.c (1031B)
1 #include "dwarfsym.h" 2 3 #include <string.h> 4 5 #include "driver.h" 6 7 int driver_dwarfsym_open(DriverDwarfSym* s, DriverEnv* env, const char* tool, 8 const char* path) { 9 KitSlice input; 10 11 memset(s, 0, sizeof *s); 12 s->env = env; 13 s->ctx = driver_env_to_context(env); 14 15 if (driver_load_bytes(&env->file_io, tool, path, &s->ld, &input) != 0) 16 return 1; 17 18 { 19 KitSlice name_slice = kit_slice_cstr(path); 20 if (kit_obj_open(&s->ctx, name_slice, &input, &s->of) != KIT_OK) { 21 driver_errf(tool, "%s: not a recognized object file", path); 22 return 1; 23 } 24 } 25 26 if (kit_dwarf_open(&s->ctx, s->of, &s->dwarf) != KIT_OK) { 27 driver_errf(tool, "%s: no debug info available", path); 28 return 1; 29 } 30 31 return 0; 32 } 33 34 void driver_dwarfsym_close(DriverDwarfSym* s) { 35 if (!s) return; 36 if (s->dwarf) { 37 kit_dwarf_free(s->dwarf); 38 s->dwarf = NULL; 39 } 40 if (s->of) { 41 kit_obj_free(s->of); 42 s->of = NULL; 43 } 44 if (s->env && s->ld.loaded) driver_release_bytes(&s->env->file_io, &s->ld); 45 }