Use ctsdio streams for dump_syms for significant speedup. Also contains a makefile fix to build in 32-bit mode, even on 64-bit systems.

A=jim blandy
R=nealsid



git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@347 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
nealsid 2009-06-05 22:40:28 +00:00
parent 2eb356a68d
commit 0eb52ff8cc
4 changed files with 28 additions and 39 deletions

View File

@ -169,18 +169,6 @@ static ElfW(Addr) GetLoadingAddress(const ElfW(Phdr) *program_headers,
return 0; return 0;
} }
static bool WriteFormat(int fd, const char *fmt, ...) {
va_list list;
char buffer[4096];
ssize_t expected, written;
va_start(list, fmt);
vsnprintf(buffer, sizeof(buffer), fmt, list);
expected = strlen(buffer);
written = write(fd, buffer, strlen(buffer));
va_end(list);
return expected == written;
}
static bool IsValidElf(const ElfW(Ehdr) *elf_header) { static bool IsValidElf(const ElfW(Ehdr) *elf_header) {
return memcmp(elf_header, ELFMAG, SELFMAG) == 0; return memcmp(elf_header, ELFMAG, SELFMAG) == 0;
} }
@ -593,7 +581,7 @@ static bool LoadSymbols(ElfW(Ehdr) *elf_header, struct SymbolInfo *symbols) {
return LoadSymbols(stab_section, stabstr_section, loading_addr, symbols); return LoadSymbols(stab_section, stabstr_section, loading_addr, symbols);
} }
static bool WriteModuleInfo(int fd, static bool WriteModuleInfo(FILE *file,
ElfW(Half) arch, ElfW(Half) arch,
const std::string &obj_file) { const std::string &obj_file) {
const char *arch_name = NULL; const char *arch_name = NULL;
@ -622,26 +610,26 @@ static bool WriteModuleInfo(int fd,
size_t slash_pos = obj_file.find_last_of("/"); size_t slash_pos = obj_file.find_last_of("/");
if (slash_pos != std::string::npos) if (slash_pos != std::string::npos)
filename = obj_file.substr(slash_pos + 1); filename = obj_file.substr(slash_pos + 1);
return WriteFormat(fd, "MODULE Linux %s %s %s\n", arch_name, return 0 <= fprintf(file, "MODULE Linux %s %s %s\n", arch_name,
id_no_dash, filename.c_str()); id_no_dash, filename.c_str());
} }
return false; return false;
} }
static bool WriteSourceFileInfo(int fd, const struct SymbolInfo &symbols) { static bool WriteSourceFileInfo(FILE *file, const struct SymbolInfo &symbols) {
for (SourceFileInfoList::const_iterator it = for (SourceFileInfoList::const_iterator it =
symbols.source_file_info.begin(); symbols.source_file_info.begin();
it != symbols.source_file_info.end(); it++) { it != symbols.source_file_info.end(); it++) {
if (it->source_id != -1) { if (it->source_id != -1) {
const char *name = it->name; const char *name = it->name;
if (!WriteFormat(fd, "FILE %d %s\n", it->source_id, name)) if (0 > fprintf(file, "FILE %d %s\n", it->source_id, name))
return false; return false;
} }
} }
return true; return true;
} }
static bool WriteOneFunction(int fd, static bool WriteOneFunction(FILE *file,
const struct FuncInfo &func_info){ const struct FuncInfo &func_info){
// Discard the ending part of the name. // Discard the ending part of the name.
std::string func_name(func_info.name); std::string func_name(func_info.name);
@ -653,17 +641,17 @@ static bool WriteOneFunction(int fd,
if (func_info.size <= 0) if (func_info.size <= 0)
return true; return true;
if (WriteFormat(fd, "FUNC %lx %lx %d %s\n", if (0 <= fprintf(file, "FUNC %lx %lx %d %s\n",
func_info.rva_to_base, (unsigned long) func_info.rva_to_base,
func_info.size, (unsigned long) func_info.size,
func_info.stack_param_size, func_info.stack_param_size,
func_name.c_str())) { func_name.c_str())) {
for (LineInfoList::const_iterator it = func_info.line_info.begin(); for (LineInfoList::const_iterator it = func_info.line_info.begin();
it != func_info.line_info.end(); it++) { it != func_info.line_info.end(); it++) {
const struct LineInfo &line_info = *it; const struct LineInfo &line_info = *it;
if (!WriteFormat(fd, "%lx %lx %d %d\n", if (0 > fprintf(file, "%lx %lx %d %d\n",
line_info.rva_to_base, (unsigned long) line_info.rva_to_base,
line_info.size, (unsigned long) line_info.size,
line_info.line_num, line_info.line_num,
line_info.source_id)) line_info.source_id))
return false; return false;
@ -673,7 +661,7 @@ static bool WriteOneFunction(int fd,
return false; return false;
} }
static bool WriteFunctionInfo(int fd, const struct SymbolInfo &symbols) { static bool WriteFunctionInfo(FILE *file, const struct SymbolInfo &symbols) {
for (SourceFileInfoList::const_iterator it = for (SourceFileInfoList::const_iterator it =
symbols.source_file_info.begin(); symbols.source_file_info.begin();
it != symbols.source_file_info.end(); it++) { it != symbols.source_file_info.end(); it++) {
@ -681,16 +669,16 @@ static bool WriteFunctionInfo(int fd, const struct SymbolInfo &symbols) {
for (FuncInfoList::const_iterator fiIt = file_info.func_info.begin(); for (FuncInfoList::const_iterator fiIt = file_info.func_info.begin();
fiIt != file_info.func_info.end(); fiIt++) { fiIt != file_info.func_info.end(); fiIt++) {
const struct FuncInfo &func_info = *fiIt; const struct FuncInfo &func_info = *fiIt;
if (!WriteOneFunction(fd, func_info)) if (!WriteOneFunction(file, func_info))
return false; return false;
} }
} }
return true; return true;
} }
static bool DumpStabSymbols(int fd, const struct SymbolInfo &symbols) { static bool DumpStabSymbols(FILE *file, const struct SymbolInfo &symbols) {
return WriteSourceFileInfo(fd, symbols) && return WriteSourceFileInfo(file, symbols) &&
WriteFunctionInfo(fd, symbols); WriteFunctionInfo(file, symbols);
} }
// //
@ -750,7 +738,7 @@ class MmapWrapper {
namespace google_breakpad { namespace google_breakpad {
bool DumpSymbols::WriteSymbolFile(const std::string &obj_file, bool DumpSymbols::WriteSymbolFile(const std::string &obj_file,
int sym_fd) { FILE *sym_file) {
int obj_fd = open(obj_file.c_str(), O_RDONLY); int obj_fd = open(obj_file.c_str(), O_RDONLY);
if (obj_fd < 0) if (obj_fd < 0)
return false; return false;
@ -772,8 +760,8 @@ bool DumpSymbols::WriteSymbolFile(const std::string &obj_file,
if (!LoadSymbols(elf_header, &symbols)) if (!LoadSymbols(elf_header, &symbols))
return false; return false;
// Write to symbol file. // Write to symbol file.
if (WriteModuleInfo(sym_fd, elf_header->e_machine, obj_file) && if (WriteModuleInfo(sym_file, elf_header->e_machine, obj_file) &&
DumpStabSymbols(sym_fd, symbols)) DumpStabSymbols(sym_file, symbols))
return true; return true;
return false; return false;

View File

@ -34,13 +34,14 @@
#define COMMON_LINUX_DUMP_SYMBOLS_H__ #define COMMON_LINUX_DUMP_SYMBOLS_H__
#include <string> #include <string>
#include <cstdio>
namespace google_breakpad { namespace google_breakpad {
class DumpSymbols { class DumpSymbols {
public: public:
bool WriteSymbolFile(const std::string &obj_file, bool WriteSymbolFile(const std::string &obj_file,
int sym_fd); FILE *sym_file);
}; };
} // namespace google_breakpad } // namespace google_breakpad

View File

@ -1,7 +1,7 @@
CXX=g++ CXX=g++
CC=gcc CC=gcc
CXXFLAGS=-gstabs -I../../.. -DNDEBUG -Wall -D_REENTRANT CXXFLAGS=-gstabs -I../../.. -DNDEBUG -Wall -D_REENTRANT -m32
.PHONY:all clean .PHONY:all clean

View File

@ -43,7 +43,7 @@ int main(int argc, char **argv) {
const char *binary = argv[1]; const char *binary = argv[1];
DumpSymbols dumper; DumpSymbols dumper;
if (!dumper.WriteSymbolFile(binary, fileno(stdout))) { if (!dumper.WriteSymbolFile(binary, stdout)) {
fprintf(stderr, "Failed to write symbol file.\n"); fprintf(stderr, "Failed to write symbol file.\n");
return 1; return 1;
} }