kit

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

dwarfsym.h (2349B)


      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 address -> symbol 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.
     15  * driver_dwarfsym_lookup runs the same kit_dwarf_func_at /
     16  * kit_dwarf_addr_to_line queries both tools share and reports the result in a
     17  * DriverSymLoc; each tool then formats that however it likes (addr2line one
     18  * line per address; symbolize annotating a backtrace stream in place).
     19  *
     20  * Addresses are image-relative, matching the kit_dwarf_* contract. The of /
     21  * dwarf borrow from the loaded bytes, so driver_dwarfsym_close frees in the
     22  * reverse order (dwarf, then object, then the byte buffer). */
     23 
     24 typedef struct DriverDwarfSym {
     25   DriverEnv* env;
     26   KitContext ctx;
     27   KitObjFile* of;
     28   KitDebugInfo* dwarf;
     29   DriverLoad ld;
     30 } DriverDwarfSym;
     31 
     32 /* Load `path` and open its DWARF, keyed off the (already-initialized) `env`.
     33  * Returns 0 on success. On failure emits a diagnostic via driver_errf(tool,...)
     34  * and returns 1; the caller must still call driver_dwarfsym_close to release
     35  * any partial state. */
     36 int driver_dwarfsym_open(DriverDwarfSym* s, DriverEnv* env, const char* tool,
     37                          const char* path);
     38 
     39 /* Release the DWARF reader, object, and byte buffer. Idempotent; the `env`
     40  * itself is owned by the caller and is left untouched. */
     41 void driver_dwarfsym_close(DriverDwarfSym* s);
     42 
     43 /* The resolved location for one address. `have_func` / `have_line` say which
     44  * fields are valid; an unresolved query returns with both clear (and the
     45  * slices empty). `func`, `file`, `line`, and `col` mirror kit_dwarf_func_at /
     46  * kit_dwarf_addr_to_line outputs. */
     47 typedef struct DriverSymLoc {
     48   int have_func;
     49   KitSlice func;
     50   int have_line;
     51   KitSlice file;
     52   uint32_t line;
     53   uint32_t col;
     54 } DriverSymLoc;
     55 
     56 /* Translate one image-relative address. `want_func` gates the (separate)
     57  * DW function-name query so callers that never print a name skip the work. */
     58 void driver_dwarfsym_lookup(DriverDwarfSym* s, uint64_t addr, int want_func,
     59                             DriverSymLoc* out);
     60 
     61 #endif /* KIT_DRIVER_DWARFSYM_H */