From 68c8481df65940e90151ff2a6a6bd3c01f73f702 Mon Sep 17 00:00:00 2001 From: "jimblandy@gmail.com" Date: Wed, 5 Aug 2009 00:57:48 +0000 Subject: Linux dumper: Make the 'name' field of FuncInfo a std::string instead of a char *. Because the actual N_FUN strings in the .stabstr section contain type information after the mangled name, representing this information using a pointer into .stabstr, while efficient with memory, makes the FuncInfo data structure STABS-specific: one must know the details of a STABS N_FUN string's syntax to interpret FuncInfo::name. This patch removes this STABS dependency from the data structure, and moves us closer to having an appropriate structure for representing unified STABS and DWARF data. a=jimblandy r=nealsid git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@375 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/common/linux/dump_symbols.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/common/linux/dump_symbols.cc') diff --git a/src/common/linux/dump_symbols.cc b/src/common/linux/dump_symbols.cc index 3b2331df..505c517e 100644 --- a/src/common/linux/dump_symbols.cc +++ b/src/common/linux/dump_symbols.cc @@ -43,6 +43,7 @@ #include #include +#include #include #include #include @@ -81,7 +82,7 @@ typedef std::list LineInfoList; // Information of a function. struct FuncInfo { // Name of the function. - const char *name; + std::string name; // Offset from the base of the loading address. ElfW(Off) rva_to_base; // Virtual address of the function. @@ -317,9 +318,16 @@ static int LoadFuncSymbols(struct nlist *list, } if (cur_list->n_type == N_FUN) { struct FuncInfo func_info; - func_info.name = - reinterpret_cast(cur_list->n_un.n_strx + - stabstr_section->sh_offset); + // The STABS data for an N_FUN entry is the function's (mangled) + // name, followed by a colon, followed by type information. We + // want to retain the name only. + const char *stabs_name + = reinterpret_cast(cur_list->n_un.n_strx + + stabstr_section->sh_offset); + const char *name_end = strchr(stabs_name, ':'); + if (! name_end) + name_end = stabs_name + strlen(stabs_name); + func_info.name = std::string(stabs_name, name_end - stabs_name); func_info.addr = cur_list->n_value; func_info.rva_to_base = 0; func_info.size = 0; @@ -609,12 +617,7 @@ static bool WriteSourceFileInfo(FILE *file, struct SymbolInfo &symbols) { static bool WriteOneFunction(FILE *file, const struct FuncInfo &func_info){ - // Discard the ending part of the name. - std::string func_name(func_info.name); - std::string::size_type last_colon = func_name.find_first_of(':'); - if (last_colon != std::string::npos) - func_name = func_name.substr(0, last_colon); - func_name = Demangle(func_name.c_str()); + std::string func_name = Demangle(func_info.name.c_str()); if (func_info.size <= 0) return true; -- cgit v1.2.1