rm Dwarf
This commit is contained in:
@@ -5,7 +5,8 @@ OBJECTS=$(SOURCES:.cc=.o)
|
||||
|
||||
CFLAGS=-g -O0
|
||||
INCLUDES=-I/usr/include/elf
|
||||
LIBS=-lunwind-x86_64 -lunwind -lelf -ldwarf -ldw
|
||||
LIBS=-lunwind-x86_64 -lunwind -lelf
|
||||
#-ldwarf -ldw
|
||||
|
||||
%.o: %.cc
|
||||
$(CXX) $(CFLAGS) $(INCLUDES) -c $< -o $@
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#include <sys/utsname.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <dwarf.h>
|
||||
#include <elfutils/libdw.h>
|
||||
// #include <dwarf.h>
|
||||
// #include <elfutils/libdw.h>
|
||||
|
||||
#define NS_NAME_LEN 128
|
||||
|
||||
@@ -227,44 +227,44 @@ static void get_all_symbols(std::set<symbol> &ss, symbol_sections_ctx *si,
|
||||
__get_plt_symbol(ss, si, elf);
|
||||
}
|
||||
|
||||
static void get_debug_symbols(std::set<symbol>& ss, Dwarf* dw) {
|
||||
Dwarf_Off die_offset = 0, next_offset;
|
||||
size_t header_size;
|
||||
while (dwarf_nextcu(dw, die_offset, &next_offset, &header_size, NULL, NULL, NULL) == 0) {
|
||||
Dwarf_Die cudie;
|
||||
if (dwarf_offdie(dw, die_offset + header_size, &cudie) == NULL) {
|
||||
continue;
|
||||
}
|
||||
// static void get_debug_symbols(std::set<symbol>& ss, Dwarf* dw) {
|
||||
// Dwarf_Off die_offset = 0, next_offset;
|
||||
// size_t header_size;
|
||||
// while (dwarf_nextcu(dw, die_offset, &next_offset, &header_size, NULL, NULL, NULL) == 0) {
|
||||
// Dwarf_Die cudie;
|
||||
// if (dwarf_offdie(dw, die_offset + header_size, &cudie) == NULL) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
Dwarf_Die die;
|
||||
if (dwarf_child(&cudie, &die) != 0) {
|
||||
continue;
|
||||
}
|
||||
// Dwarf_Die die;
|
||||
// if (dwarf_child(&cudie, &die) != 0) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
do {
|
||||
const char* die_name = dwarf_diename(&die);
|
||||
if (!die_name) {
|
||||
continue;
|
||||
}
|
||||
// do {
|
||||
// const char* die_name = dwarf_diename(&die);
|
||||
// if (!die_name) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
Dwarf_Attribute attr_mem;
|
||||
Dwarf_Attribute* attr = dwarf_attr(&die, DW_AT_low_pc, &attr_mem);
|
||||
if (attr) {
|
||||
Dwarf_Addr low_pc;
|
||||
if (dwarf_formaddr(attr, &low_pc) == 0) {
|
||||
symbol s;
|
||||
s.name = die_name;
|
||||
s.start = low_pc;
|
||||
s.end = s.start; // You need to find the high_pc to set the end.
|
||||
// Dwarf_Attribute attr_mem;
|
||||
// Dwarf_Attribute* attr = dwarf_attr(&die, DW_AT_low_pc, &attr_mem);
|
||||
// if (attr) {
|
||||
// Dwarf_Addr low_pc;
|
||||
// if (dwarf_formaddr(attr, &low_pc) == 0) {
|
||||
// symbol s;
|
||||
// s.name = die_name;
|
||||
// s.start = low_pc;
|
||||
// s.end = s.start; // You need to find the high_pc to set the end.
|
||||
|
||||
ss.insert(s);
|
||||
}
|
||||
}
|
||||
} while (dwarf_siblingof(&die, &die) == 0);
|
||||
// ss.insert(s);
|
||||
// }
|
||||
// }
|
||||
// } while (dwarf_siblingof(&die, &die) == 0);
|
||||
|
||||
die_offset = next_offset;
|
||||
}
|
||||
}
|
||||
// die_offset = next_offset;
|
||||
// }
|
||||
// }
|
||||
|
||||
bool get_symbol_from_elf(std::set<symbol> &ss, const char *path) {
|
||||
static int first_init = 0;
|
||||
@@ -375,11 +375,11 @@ bool get_symbol_from_elf(std::set<symbol> &ss, const char *path) {
|
||||
elf_end(elf);
|
||||
|
||||
// After getting all symbols from .symtab and .dynsym
|
||||
Dwarf *dw = dwarf_begin(fd, DWARF_C_READ);
|
||||
if (dw) {
|
||||
get_debug_symbols(ss, dw);
|
||||
dwarf_end(dw);
|
||||
}
|
||||
// Dwarf *dw = dwarf_begin(fd, DWARF_C_READ);
|
||||
// if (dw) {
|
||||
// get_debug_symbols(ss, dw);
|
||||
// dwarf_end(dw);
|
||||
// }
|
||||
|
||||
close(fd);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user