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 10 matching lines...) Expand all Loading... | |
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 #include <stdio.h> | 30 #include <stdio.h> |
31 #include <unistd.h> | |
31 | 32 |
32 #include <cstring> | 33 #include <cstring> |
33 #include <iostream> | 34 #include <iostream> |
34 #include <string> | 35 #include <string> |
35 #include <vector> | 36 #include <vector> |
36 | 37 |
37 #include "common/linux/dump_symbols.h" | 38 #include "common/linux/dump_symbols.h" |
38 | 39 |
39 using google_breakpad::WriteSymbolFile; | 40 using google_breakpad::WriteSymbolFile; |
40 | 41 |
41 int usage(const char* self) { | 42 int usage(const char* self) { |
42 fprintf(stderr, "Usage: %s [OPTION] <binary-with-debugging-info> " | 43 fprintf(stderr, "Usage: %s [OPTION] <binary-with-debugging-info> " |
43 "[directories-for-debug-file]\n\n", self); | 44 "[directories-for-debug-file]\n\n", self); |
44 fprintf(stderr, "Options:\n"); | 45 fprintf(stderr, "Options:\n"); |
45 fprintf(stderr, " -c Do not generate CFI section\n"); | 46 fprintf(stderr, " -c Do not generate CFI section\n"); |
46 fprintf(stderr, " -r Do not handle inter-compilation unit references\n"); | 47 fprintf(stderr, " -r Do not handle inter-compilation unit references\n"); |
48 fprintf(stderr, " -v Verbose logging. Print all warnings to stderr\n"); | |
47 return 1; | 49 return 1; |
48 } | 50 } |
49 | 51 |
50 int main(int argc, char **argv) { | 52 int main(int argc, char **argv) { |
51 if (argc < 2) | 53 if (argc < 2) |
52 return usage(argv[0]); | 54 return usage(argv[0]); |
53 | 55 |
54 bool cfi = true; | 56 bool cfi = true; |
55 bool handle_inter_cu_refs = true; | 57 bool handle_inter_cu_refs = true; |
58 bool log_to_stderr = false; | |
56 int arg_index = 1; | 59 int arg_index = 1; |
57 while (arg_index < argc && strlen(argv[arg_index]) > 0 && | 60 while (arg_index < argc && strlen(argv[arg_index]) > 0 && |
58 argv[arg_index][0] == '-') { | 61 argv[arg_index][0] == '-') { |
59 if (strcmp("-c", argv[arg_index]) == 0) { | 62 if (strcmp("-c", argv[arg_index]) == 0) { |
60 cfi = false; | 63 cfi = false; |
61 } else if (strcmp("-r", argv[arg_index]) == 0) { | 64 } else if (strcmp("-r", argv[arg_index]) == 0) { |
62 handle_inter_cu_refs = false; | 65 handle_inter_cu_refs = false; |
66 } else if (strcmp("-v", argv[arg_index]) == 0) { | |
67 log_to_stderr = true; | |
63 } else { | 68 } else { |
64 return usage(argv[0]); | 69 return usage(argv[0]); |
65 } | 70 } |
66 ++arg_index; | 71 ++arg_index; |
67 } | 72 } |
68 if (arg_index == argc) | 73 if (arg_index == argc) |
69 return usage(argv[0]); | 74 return usage(argv[0]); |
70 | 75 |
76 // Save stderr so it can be used below. | |
77 FILE* saved_stderr = fdopen(dup(STDERR_FILENO), "w"); | |
Mark Mentovai
2015/11/11 15:05:13
fileno(stderr) since everything else is working wi
| |
78 if (!log_to_stderr) { | |
79 freopen("/dev/null", "w", stderr); | |
Mark Mentovai
2015/11/11 15:05:13
<paths.h> _PATH_DEVNULL
| |
80 } | |
81 | |
71 const char* binary; | 82 const char* binary; |
72 std::vector<string> debug_dirs; | 83 std::vector<string> debug_dirs; |
73 binary = argv[arg_index]; | 84 binary = argv[arg_index]; |
74 for (int debug_dir_index = arg_index + 1; | 85 for (int debug_dir_index = arg_index + 1; |
75 debug_dir_index < argc; | 86 debug_dir_index < argc; |
76 ++debug_dir_index) { | 87 ++debug_dir_index) { |
77 debug_dirs.push_back(argv[debug_dir_index]); | 88 debug_dirs.push_back(argv[debug_dir_index]); |
78 } | 89 } |
79 | 90 |
80 SymbolData symbol_data = cfi ? ALL_SYMBOL_DATA : NO_CFI; | 91 SymbolData symbol_data = cfi ? ALL_SYMBOL_DATA : NO_CFI; |
81 google_breakpad::DumpOptions options(symbol_data, handle_inter_cu_refs); | 92 google_breakpad::DumpOptions options(symbol_data, handle_inter_cu_refs); |
82 if (!WriteSymbolFile(binary, debug_dirs, options, std::cout)) { | 93 if (!WriteSymbolFile(binary, debug_dirs, options, std::cout)) { |
83 fprintf(stderr, "Failed to write symbol file.\n"); | 94 fprintf(saved_stderr, "Failed to write symbol file.\n"); |
84 return 1; | 95 return 1; |
85 } | 96 } |
86 | 97 |
87 return 0; | 98 return 0; |
88 } | 99 } |
OLD | NEW |