Merge Ted's patch for writing symbols to stdout for linux.

git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@149 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
luly81 2007-05-02 19:13:09 +00:00
parent 3c27dcc1b6
commit e219ba182e
3 changed files with 10 additions and 20 deletions

View File

@ -616,7 +616,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,
const std::string &symbol_file) { int sym_fd) {
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;
@ -636,16 +636,10 @@ 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.
int sym_fd = open(symbol_file.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666);
if (sym_fd < 0)
return false;
FDWrapper sym_fd_wrapper(sym_fd);
if (WriteModuleInfo(sym_fd, elf_header->e_machine, obj_file) && if (WriteModuleInfo(sym_fd, elf_header->e_machine, obj_file) &&
DumpStabSymbols(sym_fd, symbols)) DumpStabSymbols(sym_fd, symbols))
return true; return true;
// Remove the symbol file if failed to write the symbols.
unlink(symbol_file.c_str());
return false; return false;
} }

View File

@ -40,7 +40,7 @@ namespace google_breakpad {
class DumpSymbols { class DumpSymbols {
public: public:
bool WriteSymbolFile(const std::string &obj_file, bool WriteSymbolFile(const std::string &obj_file,
const std::string &symbol_file); int sym_fd);
}; };
} // namespace google_breakpad } // namespace google_breakpad

View File

@ -28,29 +28,25 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string> #include <string>
#include <cstdio>
#include "common/linux/dump_symbols.h" #include "common/linux/dump_symbols.h"
using namespace google_breakpad; using namespace google_breakpad;
int main(int argc, char **argv) { int main(int argc, char **argv) {
if (argc < 2 || argc > 3) { if (argc != 2) {
fprintf(stderr, fprintf(stderr, "Usage: %s <binary-with-stab-symbol>\n", argv[0]);
"Usage: %s <binary-with-stab-symbol> [output-symbol-file]\n",
argv[0]);
return 1; return 1;
} }
const char *binary = argv[1]; const char *binary = argv[1];
std::string symbol_file(binary);
symbol_file += ".sym";
if (argc == 3)
symbol_file = argv[2];
DumpSymbols dumper; DumpSymbols dumper;
if (dumper.WriteSymbolFile(binary, symbol_file)) if (!dumper.WriteSymbolFile(binary, fileno(stdout))) {
printf("Symbol file successfully written: %s\n", symbol_file.c_str()); fprintf(stderr, "Failed to write symbol file.\n");
else return 1;
printf("Failed to write symbol file.\n"); }
return 0; return 0;
} }