OLD | NEW |
1 // Copyright (c) 2011, Google Inc. | 1 // Copyright (c) 2011, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include <unistd.h> | 32 #include <unistd.h> |
33 | 33 |
34 #include <cstring> | 34 #include <cstring> |
35 #include <iostream> | 35 #include <iostream> |
36 #include <string> | 36 #include <string> |
37 #include <vector> | 37 #include <vector> |
38 | 38 |
39 #include "common/linux/dump_symbols.h" | 39 #include "common/linux/dump_symbols.h" |
40 | 40 |
41 using google_breakpad::WriteSymbolFile; | 41 using google_breakpad::WriteSymbolFile; |
| 42 using google_breakpad::WriteSymbolFileHeader; |
42 | 43 |
43 int usage(const char* self) { | 44 int usage(const char* self) { |
44 fprintf(stderr, "Usage: %s [OPTION] <binary-with-debugging-info> " | 45 fprintf(stderr, "Usage: %s [OPTION] <binary-with-debugging-info> " |
45 "[directories-for-debug-file]\n\n", self); | 46 "[directories-for-debug-file]\n\n", self); |
46 fprintf(stderr, "Options:\n"); | 47 fprintf(stderr, "Options:\n"); |
| 48 fprintf(stderr, " -i: Output module header information only.\n"); |
47 fprintf(stderr, " -c Do not generate CFI section\n"); | 49 fprintf(stderr, " -c Do not generate CFI section\n"); |
48 fprintf(stderr, " -r Do not handle inter-compilation unit references\n"); | 50 fprintf(stderr, " -r Do not handle inter-compilation unit references\n"); |
49 fprintf(stderr, " -v Print all warnings to stderr\n"); | 51 fprintf(stderr, " -v Print all warnings to stderr\n"); |
50 return 1; | 52 return 1; |
51 } | 53 } |
52 | 54 |
53 int main(int argc, char **argv) { | 55 int main(int argc, char **argv) { |
54 if (argc < 2) | 56 if (argc < 2) |
55 return usage(argv[0]); | 57 return usage(argv[0]); |
56 | 58 bool header_only = false; |
57 bool cfi = true; | 59 bool cfi = true; |
58 bool handle_inter_cu_refs = true; | 60 bool handle_inter_cu_refs = true; |
59 bool log_to_stderr = false; | 61 bool log_to_stderr = false; |
60 int arg_index = 1; | 62 int arg_index = 1; |
61 while (arg_index < argc && strlen(argv[arg_index]) > 0 && | 63 while (arg_index < argc && strlen(argv[arg_index]) > 0 && |
62 argv[arg_index][0] == '-') { | 64 argv[arg_index][0] == '-') { |
63 if (strcmp("-c", argv[arg_index]) == 0) { | 65 if (strcmp("-i", argv[arg_index]) == 0) { |
| 66 header_only = true; |
| 67 } else if (strcmp("-c", argv[arg_index]) == 0) { |
64 cfi = false; | 68 cfi = false; |
65 } else if (strcmp("-r", argv[arg_index]) == 0) { | 69 } else if (strcmp("-r", argv[arg_index]) == 0) { |
66 handle_inter_cu_refs = false; | 70 handle_inter_cu_refs = false; |
67 } else if (strcmp("-v", argv[arg_index]) == 0) { | 71 } else if (strcmp("-v", argv[arg_index]) == 0) { |
68 log_to_stderr = true; | 72 log_to_stderr = true; |
69 } else { | 73 } else { |
| 74 printf("2.4 %s\n", argv[arg_index]); |
70 return usage(argv[0]); | 75 return usage(argv[0]); |
71 } | 76 } |
72 ++arg_index; | 77 ++arg_index; |
73 } | 78 } |
74 if (arg_index == argc) | 79 if (arg_index == argc) |
75 return usage(argv[0]); | 80 return usage(argv[0]); |
76 | |
77 // Save stderr so it can be used below. | 81 // Save stderr so it can be used below. |
78 FILE* saved_stderr = fdopen(dup(fileno(stderr)), "w"); | 82 FILE* saved_stderr = fdopen(dup(fileno(stderr)), "w"); |
79 if (!log_to_stderr) { | 83 if (!log_to_stderr) { |
80 if (freopen(_PATH_DEVNULL, "w", stderr)) { | 84 if (freopen(_PATH_DEVNULL, "w", stderr)) { |
81 // If it fails, not a lot we can (or should) do. | 85 // If it fails, not a lot we can (or should) do. |
82 // Add this brace section to silence gcc warnings. | 86 // Add this brace section to silence gcc warnings. |
83 } | 87 } |
84 } | 88 } |
85 | |
86 const char* binary; | 89 const char* binary; |
87 std::vector<string> debug_dirs; | 90 std::vector<string> debug_dirs; |
88 binary = argv[arg_index]; | 91 binary = argv[arg_index]; |
89 for (int debug_dir_index = arg_index + 1; | 92 for (int debug_dir_index = arg_index + 1; |
90 debug_dir_index < argc; | 93 debug_dir_index < argc; |
91 ++debug_dir_index) { | 94 ++debug_dir_index) { |
92 debug_dirs.push_back(argv[debug_dir_index]); | 95 debug_dirs.push_back(argv[debug_dir_index]); |
93 } | 96 } |
94 | 97 |
95 SymbolData symbol_data = cfi ? ALL_SYMBOL_DATA : NO_CFI; | 98 if (header_only) { |
96 google_breakpad::DumpOptions options(symbol_data, handle_inter_cu_refs); | 99 if (!WriteSymbolFileHeader(binary, std::cout)) { |
97 if (!WriteSymbolFile(binary, debug_dirs, options, std::cout)) { | 100 fprintf(saved_stderr, "Failed to process file.\n"); |
98 fprintf(saved_stderr, "Failed to write symbol file.\n"); | 101 return 1; |
99 return 1; | 102 } |
| 103 } else { |
| 104 SymbolData symbol_data = cfi ? ALL_SYMBOL_DATA : NO_CFI; |
| 105 google_breakpad::DumpOptions options(symbol_data, handle_inter_cu_refs); |
| 106 if (!WriteSymbolFile(binary, debug_dirs, options, std::cout)) { |
| 107 fprintf(saved_stderr, "Failed to write symbol file.\n"); |
| 108 return 1; |
| 109 } |
100 } | 110 } |
101 | 111 |
102 return 0; | 112 return 0; |
103 } | 113 } |
OLD | NEW |