Lines Matching defs:symtab

30 #include "symtab.h"
49 typedef struct symtab {
255 static struct symtab* build_symtab_internal(int fd, const char *filename, bool try_debuginfo);
259 static struct symtab *build_symtab_from_debug_link(const char *name,
268 struct symtab *symtab = build_symtab_internal(fd, NULL, /* try_debuginfo */ false);
270 return symtab;
300 // and return its symtab
301 static struct symtab* build_symtab_from_build_id(Elf64_Nhdr *note)
304 struct symtab *symtab = NULL;
313 symtab = build_symtab_internal(fd, NULL, /* try_debuginfo */ false);
318 return symtab;
323 static struct symtab* build_symtab_internal(int fd, const char *filename, bool try_debuginfo) {
326 struct symtab* symtab = NULL;
385 // guarantee(symtab == NULL, "multiple symtab");
386 symtab = (struct symtab*)calloc(1, sizeof(struct symtab));
387 if (symtab == NULL) {
398 symtab->hash_table = (struct hsearch_data*) calloc(1, sizeof(struct hsearch_data));
399 rslt = hcreate_r(n, symtab->hash_table);
407 symtab->strs = (char *)malloc(size);
408 memcpy(symtab->strs, scn_cache[shdr->sh_link].c_data, size);
411 symtab->num_symbols = n;
412 symtab->symbols = (struct elf_symbol *)calloc(n , sizeof(struct elf_symbol));
414 // copy symbols info our symtab and enter them info the hash table
417 char *sym_name = symtab->strs + syms->st_name;
426 symtab->symbols[j].name = sym_name;
427 symtab->symbols[j].offset = syms->st_value - baseaddr;
428 symtab->symbols[j].size = syms->st_size;
431 item.data = (void *)&(symtab->symbols[j]);
433 hsearch_r(item, ENTER, &ret, symtab->hash_table);
441 // We prefer a debug symtab to an object's own symtab, so look in
442 // the debuginfo file. We stash a copy of the old symtab in case
444 struct symtab* prev_symtab = symtab;
445 symtab = NULL;
450 symtab == NULL && cnt < ehdr.e_shnum;
455 symtab = build_symtab_from_build_id(note);
463 if (symtab == NULL) {
464 symtab = build_symtab_from_debug_link(filename, fd, &ehdr, shbuf,
468 // If we still haven't found a symtab, use the object's own symtab.
469 if (symtab != NULL) {
473 symtab = prev_symtab;
488 return symtab;
491 struct symtab* build_symtab(int fd, const char *filename) {
496 void destroy_symtab(struct symtab* symtab) {
497 if (!symtab) return;
498 if (symtab->strs) free(symtab->strs);
499 if (symtab->symbols) free(symtab->symbols);
500 if (symtab->hash_table) {
501 hdestroy_r(symtab->hash_table);
502 free(symtab->hash_table);
504 free(symtab);
507 uintptr_t search_symbol(struct symtab* symtab, uintptr_t base,
513 if (!symtab || !symtab->hash_table)
517 hsearch_r(item, FIND, &ret, symtab->hash_table);
531 const char* nearest_symbol(struct symtab* symtab, uintptr_t offset,
534 if (!symtab) return NULL;
535 for (; n < symtab->num_symbols; n++) {
536 struct elf_symbol* sym = &(symtab->symbols[n]);