Add options to set OS and filename

This allows Fuchsia to use dump_syms directly without a
postprocessing step.

Change-Id: I84507f8bedddfcdcdb237119457c8ddf8ac354d5
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/1850718
Reviewed-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
Jake Ehrlich 2019-10-04 13:29:26 -07:00 committed by Mike Frysinger
parent 3e56ef9d4e
commit 17958ef62c
4 changed files with 73 additions and 26 deletions

View file

@ -921,6 +921,7 @@ bool SanitizeDebugFile(const typename ElfClass::Ehdr* debug_elf_header,
template<typename ElfClass>
bool InitModuleForElfClass(const typename ElfClass::Ehdr* elf_header,
const string& obj_filename,
const string& obj_os,
scoped_ptr<Module>& module) {
PageAllocator allocator;
wasteful_vector<uint8_t> identifier(&allocator, kDefaultBuildIdSize);
@ -945,7 +946,6 @@ bool InitModuleForElfClass(const typename ElfClass::Ehdr* elf_header,
? name_buf
: google_breakpad::BaseName(obj_filename);
string os = "Linux";
// Add an extra "0" at the end. PDB files on Windows have an 'age'
// number appended to the end of the file identifier; this isn't
// really used or necessary on other platforms, but be consistent.
@ -953,7 +953,7 @@ bool InitModuleForElfClass(const typename ElfClass::Ehdr* elf_header,
// This is just the raw Build ID in hex.
string code_id = FileID::ConvertIdentifierToString(identifier);
module.reset(new Module(name, os, architecture, id, code_id));
module.reset(new Module(name, obj_os, architecture, id, code_id));
return true;
}
@ -961,6 +961,7 @@ bool InitModuleForElfClass(const typename ElfClass::Ehdr* elf_header,
template<typename ElfClass>
bool ReadSymbolDataElfClass(const typename ElfClass::Ehdr* elf_header,
const string& obj_filename,
const string& obj_os,
const std::vector<string>& debug_dirs,
const DumpOptions& options,
Module** out_module) {
@ -969,7 +970,8 @@ bool ReadSymbolDataElfClass(const typename ElfClass::Ehdr* elf_header,
*out_module = NULL;
scoped_ptr<Module> module;
if (!InitModuleForElfClass<ElfClass>(elf_header, obj_filename, module)) {
if (!InitModuleForElfClass<ElfClass>(elf_header, obj_filename, obj_os,
module)) {
return false;
}
@ -1017,6 +1019,7 @@ namespace google_breakpad {
// Not explicitly exported, but not static so it can be used in unit tests.
bool ReadSymbolDataInternal(const uint8_t* obj_file,
const string& obj_filename,
const string& obj_os,
const std::vector<string>& debug_dirs,
const DumpOptions& options,
Module** module) {
@ -1028,24 +1031,27 @@ bool ReadSymbolDataInternal(const uint8_t* obj_file,
int elfclass = ElfClass(obj_file);
if (elfclass == ELFCLASS32) {
return ReadSymbolDataElfClass<ElfClass32>(
reinterpret_cast<const Elf32_Ehdr*>(obj_file), obj_filename, debug_dirs,
options, module);
reinterpret_cast<const Elf32_Ehdr*>(obj_file), obj_filename, obj_os,
debug_dirs, options, module);
}
if (elfclass == ELFCLASS64) {
return ReadSymbolDataElfClass<ElfClass64>(
reinterpret_cast<const Elf64_Ehdr*>(obj_file), obj_filename, debug_dirs,
options, module);
reinterpret_cast<const Elf64_Ehdr*>(obj_file), obj_filename, obj_os,
debug_dirs, options, module);
}
return false;
}
bool WriteSymbolFile(const string &obj_file,
bool WriteSymbolFile(const string &load_path,
const string &obj_file,
const string &obj_os,
const std::vector<string>& debug_dirs,
const DumpOptions& options,
std::ostream &sym_stream) {
Module* module;
if (!ReadSymbolData(obj_file, debug_dirs, options, &module))
if (!ReadSymbolData(load_path, obj_file, obj_os, debug_dirs, options,
&module))
return false;
bool result = module->Write(sym_stream, options.symbol_data);
@ -1056,11 +1062,13 @@ bool WriteSymbolFile(const string &obj_file,
// Read the selected object file's debugging information, and write out the
// header only to |stream|. Return true on success; if an error occurs, report
// it and return false.
bool WriteSymbolFileHeader(const string& obj_file,
bool WriteSymbolFileHeader(const string& load_path,
const string& obj_file,
const string& obj_os,
std::ostream &sym_stream) {
MmapWrapper map_wrapper;
void* elf_header = NULL;
if (!LoadELF(obj_file, &map_wrapper, &elf_header)) {
if (!LoadELF(load_path, &map_wrapper, &elf_header)) {
fprintf(stderr, "Could not load ELF file: %s\n", obj_file.c_str());
return false;
}
@ -1074,13 +1082,15 @@ bool WriteSymbolFileHeader(const string& obj_file,
scoped_ptr<Module> module;
if (elfclass == ELFCLASS32) {
if (!InitModuleForElfClass<ElfClass32>(
reinterpret_cast<const Elf32_Ehdr*>(elf_header), obj_file, module)) {
reinterpret_cast<const Elf32_Ehdr*>(elf_header), obj_file, obj_os,
module)) {
fprintf(stderr, "Failed to load ELF module: %s\n", obj_file.c_str());
return false;
}
} else if (elfclass == ELFCLASS64) {
if (!InitModuleForElfClass<ElfClass64>(
reinterpret_cast<const Elf64_Ehdr*>(elf_header), obj_file, module)) {
reinterpret_cast<const Elf64_Ehdr*>(elf_header), obj_file, obj_os,
module)) {
fprintf(stderr, "Failed to load ELF module: %s\n", obj_file.c_str());
return false;
}
@ -1092,17 +1102,19 @@ bool WriteSymbolFileHeader(const string& obj_file,
return module->Write(sym_stream, ALL_SYMBOL_DATA);
}
bool ReadSymbolData(const string& obj_file,
bool ReadSymbolData(const string& load_path,
const string& obj_file,
const string& obj_os,
const std::vector<string>& debug_dirs,
const DumpOptions& options,
Module** module) {
MmapWrapper map_wrapper;
void* elf_header = NULL;
if (!LoadELF(obj_file, &map_wrapper, &elf_header))
if (!LoadELF(load_path, &map_wrapper, &elf_header))
return false;
return ReadSymbolDataInternal(reinterpret_cast<uint8_t*>(elf_header),
obj_file, debug_dirs, options, module);
obj_file, obj_os, debug_dirs, options, module);
}
} // namespace google_breakpad

View file

@ -62,21 +62,28 @@ struct DumpOptions {
// If OBJ_FILE has been stripped but contains a .gnu_debuglink section,
// then look for the debug file in DEBUG_DIRS.
// SYMBOL_DATA allows limiting the type of symbol data written.
bool WriteSymbolFile(const string &obj_file,
bool WriteSymbolFile(const string &load_path,
const string &obj_file,
const string &obj_os,
const std::vector<string>& debug_dirs,
const DumpOptions& options,
std::ostream &sym_stream);
// Read the selected object file's debugging information, and write out the
// header only to |stream|. Return true on success; if an error occurs, report
// it and return false.
bool WriteSymbolFileHeader(const string& obj_file,
// it and return false. |obj_file| becomes the MODULE file name and |obj_os|
// becomes the MODULE operating system.
bool WriteSymbolFileHeader(const string& load_path,
const string& obj_file,
const string& obj_os,
std::ostream &sym_stream);
// As above, but simply return the debugging information in MODULE
// instead of writing it to a stream. The caller owns the resulting
// Module object and must delete it when finished.
bool ReadSymbolData(const string& obj_file,
bool ReadSymbolData(const string& load_path,
const string& obj_file,
const string& obj_os,
const std::vector<string>& debug_dirs,
const DumpOptions& options,
Module** module);

View file

@ -51,6 +51,7 @@ namespace google_breakpad {
bool ReadSymbolDataInternal(const uint8_t* obj_file,
const string& obj_filename,
const string& obj_os,
const std::vector<string>& debug_dir,
const DumpOptions& options,
Module** module);
@ -94,6 +95,7 @@ TYPED_TEST(DumpSymbols, Invalid) {
DumpOptions options(ALL_SYMBOL_DATA, true);
EXPECT_FALSE(ReadSymbolDataInternal(reinterpret_cast<uint8_t*>(&header),
"foo",
"Linux",
vector<string>(),
options,
&module));
@ -130,6 +132,7 @@ TYPED_TEST(DumpSymbols, SimplePublic) {
DumpOptions options(ALL_SYMBOL_DATA, true);
EXPECT_TRUE(ReadSymbolDataInternal(this->elfdata,
"foo",
"Linux",
vector<string>(),
options,
&module));
@ -186,6 +189,7 @@ TYPED_TEST(DumpSymbols, SimpleBuildID) {
DumpOptions options(ALL_SYMBOL_DATA, true);
EXPECT_TRUE(ReadSymbolDataInternal(this->elfdata,
"foo",
"Linux",
vector<string>(),
options,
&module));