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
This commit is contained in:
jimblandy@gmail.com 2009-08-05 00:57:48 +00:00
parent 3c4de8e8a7
commit 68c8481df6

View file

@ -43,6 +43,7 @@
#include <unistd.h> #include <unistd.h>
#include <algorithm> #include <algorithm>
#include <string>
#include <functional> #include <functional>
#include <list> #include <list>
#include <vector> #include <vector>
@ -81,7 +82,7 @@ typedef std::list<struct LineInfo> LineInfoList;
// Information of a function. // Information of a function.
struct FuncInfo { struct FuncInfo {
// Name of the function. // Name of the function.
const char *name; std::string name;
// Offset from the base of the loading address. // Offset from the base of the loading address.
ElfW(Off) rva_to_base; ElfW(Off) rva_to_base;
// Virtual address of the function. // Virtual address of the function.
@ -317,9 +318,16 @@ static int LoadFuncSymbols(struct nlist *list,
} }
if (cur_list->n_type == N_FUN) { if (cur_list->n_type == N_FUN) {
struct FuncInfo func_info; struct FuncInfo func_info;
func_info.name = // The STABS data for an N_FUN entry is the function's (mangled)
reinterpret_cast<char *>(cur_list->n_un.n_strx + // name, followed by a colon, followed by type information. We
stabstr_section->sh_offset); // want to retain the name only.
const char *stabs_name
= reinterpret_cast<char *>(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.addr = cur_list->n_value;
func_info.rva_to_base = 0; func_info.rva_to_base = 0;
func_info.size = 0; func_info.size = 0;
@ -609,12 +617,7 @@ static bool WriteSourceFileInfo(FILE *file, struct SymbolInfo &symbols) {
static bool WriteOneFunction(FILE *file, static bool WriteOneFunction(FILE *file,
const struct FuncInfo &func_info){ const struct FuncInfo &func_info){
// Discard the ending part of the name. std::string func_name = Demangle(func_info.name.c_str());
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());
if (func_info.size <= 0) if (func_info.size <= 0)
return true; return true;