From dc16e41747d8252c4c0753cfb6afdd05781e32c1 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 11 Nov 2015 13:52:03 -0500 Subject: [PATCH] dump_syms: add a -v flag dump_syms generates a lot of warnings. This CL puts logging behind a command line flag URL=https://android-review.googlesource.com/181558 BUG=b:25460551 BUG=google-breakpad:441 R=mark@chromium.org Review URL: https://codereview.chromium.org/1437763002 . --- src/tools/linux/dump_syms/dump_syms.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/tools/linux/dump_syms/dump_syms.cc b/src/tools/linux/dump_syms/dump_syms.cc index c8ade33a..c51ae8cd 100644 --- a/src/tools/linux/dump_syms/dump_syms.cc +++ b/src/tools/linux/dump_syms/dump_syms.cc @@ -27,7 +27,9 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include #include +#include #include #include @@ -44,6 +46,7 @@ int usage(const char* self) { fprintf(stderr, "Options:\n"); fprintf(stderr, " -c Do not generate CFI section\n"); fprintf(stderr, " -r Do not handle inter-compilation unit references\n"); + fprintf(stderr, " -v Print all warnings to stderr\n"); return 1; } @@ -53,6 +56,7 @@ int main(int argc, char **argv) { bool cfi = true; bool handle_inter_cu_refs = true; + bool log_to_stderr = false; int arg_index = 1; while (arg_index < argc && strlen(argv[arg_index]) > 0 && argv[arg_index][0] == '-') { @@ -60,6 +64,8 @@ int main(int argc, char **argv) { cfi = false; } else if (strcmp("-r", argv[arg_index]) == 0) { handle_inter_cu_refs = false; + } else if (strcmp("-v", argv[arg_index]) == 0) { + log_to_stderr = true; } else { return usage(argv[0]); } @@ -68,6 +74,15 @@ int main(int argc, char **argv) { if (arg_index == argc) return usage(argv[0]); + // Save stderr so it can be used below. + FILE* saved_stderr = fdopen(dup(fileno(stderr)), "w"); + if (!log_to_stderr) { + if (freopen(_PATH_DEVNULL, "w", stderr)) { + // If it fails, not a lot we can (or should) do. + // Add this brace section to silence gcc warnings. + } + } + const char* binary; std::vector debug_dirs; binary = argv[arg_index]; @@ -80,7 +95,7 @@ int main(int argc, char **argv) { SymbolData symbol_data = cfi ? ALL_SYMBOL_DATA : NO_CFI; google_breakpad::DumpOptions options(symbol_data, handle_inter_cu_refs); if (!WriteSymbolFile(binary, debug_dirs, options, std::cout)) { - fprintf(stderr, "Failed to write symbol file.\n"); + fprintf(saved_stderr, "Failed to write symbol file.\n"); return 1; }