1 #include "kvm/symbol.h"
12 void symbol__init(const char *vmlinux
)
19 abfd
= bfd_openr(vmlinux
, NULL
);
22 static asymbol
*lookup(asymbol
**symbols
, int nr_symbols
, const char *symbol_name
)
26 for (i
= 0; i
< nr_symbols
; i
++) {
27 asymbol
*symbol
= symbols
[i
];
29 if (!strcmp(bfd_asymbol_name(symbol
), symbol_name
))
36 char *symbol__lookup(struct kvm
*kvm
, unsigned long addr
, char *sym
, size_t size
)
53 if (!bfd_check_format(abfd
, bfd_object
))
56 symtab_size
= bfd_get_symtab_upper_bound(abfd
);
60 syms
= malloc(symtab_size
);
64 nr_syms
= bfd_canonicalize_symtab(abfd
, syms
);
66 section
= bfd_get_section_by_name(abfd
, ".debug_aranges");
70 if (!bfd_find_nearest_line(abfd
, section
, NULL
, addr
, &filename
, &func
, &line
))
76 symbol
= lookup(syms
, nr_syms
, func
);
80 sym_start
= bfd_asymbol_value(symbol
);
82 sym_offset
= addr
- sym_start
;
84 snprintf(sym
, size
, "%s+%llx (%s:%i)", func
, (long long) sym_offset
, filename
, line
);
93 s
= strncpy(sym
, "<unknown>", size
);