kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

dwarfsym.h (1591B)


      1 #ifndef KIT_DRIVER_DWARFSYM_H
      2 #define KIT_DRIVER_DWARFSYM_H
      3 
      4 #include <kit/core.h>
      5 #include <kit/dwarf.h>
      6 #include <kit/object.h>
      7 #include <stdint.h>
      8 
      9 #include "env.h"
     10 
     11 /* Shared image-open core for the `addr2line` and `symbolize` tools.
     12  *
     13  * A DriverDwarfSym holds one image's loaded bytes plus its opened DWARF
     14  * reader, so a tool opens the object once and translates many addresses. The
     15  * per-address lookup itself is the public libkit kit_dwarf_resolve (over
     16  * `s->dwarf`); each tool then formats that result however it likes (addr2line
     17  * one line per address; symbolize annotating a backtrace stream in place).
     18  *
     19  * Addresses are image-relative, matching the kit_dwarf_* contract. The of /
     20  * dwarf borrow from the loaded bytes, so driver_dwarfsym_close frees in the
     21  * reverse order (dwarf, then object, then the byte buffer). */
     22 
     23 typedef struct DriverDwarfSym {
     24   DriverEnv* env;
     25   KitContext ctx;
     26   KitObjFile* of;
     27   KitDebugInfo* dwarf;
     28   DriverLoad ld;
     29 } DriverDwarfSym;
     30 
     31 /* Load `path` and open its DWARF, keyed off the (already-initialized) `env`.
     32  * Returns 0 on success. On failure emits a diagnostic via driver_errf(tool,...)
     33  * and returns 1; the caller must still call driver_dwarfsym_close to release
     34  * any partial state. */
     35 int driver_dwarfsym_open(DriverDwarfSym* s, DriverEnv* env, const char* tool,
     36                          const char* path);
     37 
     38 /* Release the DWARF reader, object, and byte buffer. Idempotent; the `env`
     39  * itself is owned by the caller and is left untouched. */
     40 void driver_dwarfsym_close(DriverDwarfSym* s);
     41 
     42 #endif /* KIT_DRIVER_DWARFSYM_H */