From 1ef8bdaedbd98bee35a573b8bc87149f2182cb5e Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Thu, 30 Dec 2004 05:36:08 +0000 Subject: For PR351: * Place a try/catch block around the entire tool to Make sure std::string exceptions are caught and printed before exiting the tool. * Make sure we catch unhandled exceptions at the top level so that we don't abort with a useless message but indicate than an unhandled exception was generated. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19192 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-nm/llvm-nm.cpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'tools/llvm-nm') diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index ba5e031851..42349058fc 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -152,20 +152,27 @@ void DumpSymbolNamesFromFile (std::string &Filename) { } int main(int argc, char **argv) { - cl::ParseCommandLineOptions(argc, argv, " llvm symbol table dumper\n"); - sys::PrintStackTraceOnErrorSignal(); - - ToolName = argv[0]; - if (BSDFormat) OutputFormat = bsd; - if (POSIXFormat) OutputFormat = posix; + try { + cl::ParseCommandLineOptions(argc, argv, " llvm symbol table dumper\n"); + sys::PrintStackTraceOnErrorSignal(); + + ToolName = argv[0]; + if (BSDFormat) OutputFormat = bsd; + if (POSIXFormat) OutputFormat = posix; + + switch (InputFilenames.size()) { + case 0: InputFilenames.push_back("-"); + case 1: break; + default: MultipleFiles = true; + } - switch (InputFilenames.size()) { - case 0: InputFilenames.push_back("-"); - case 1: break; - default: MultipleFiles = true; + std::for_each (InputFilenames.begin (), InputFilenames.end (), + DumpSymbolNamesFromFile); + return 0; + } catch (const std::string& msg) { + std::cerr << argv[0] << ": " << msg << "\n"; + } catch (...) { + std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; } - - std::for_each (InputFilenames.begin (), InputFilenames.end (), - DumpSymbolNamesFromFile); - return 0; + return 1; } -- cgit v1.2.3