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-bcanalyzer/llvm-bcanalyzer.cpp | 88 +++++++++++++++++-------------- 1 file changed, 47 insertions(+), 41 deletions(-) (limited to 'tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp') diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp index d4be138fe7..b79b6fe278 100644 --- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -49,52 +49,58 @@ static cl::opt Dump ("dump", cl::desc("Dump low level bytecode trace" static cl::opt Verify ("verify", cl::desc("Progressively verify module")); int -main(int argc, char **argv) -{ - cl::ParseCommandLineOptions(argc, argv, - " llvm-bcanalyzer Analysis of ByteCode Dumper\n"); - - sys::PrintStackTraceOnErrorSignal(); - - std::ostream* Out = &std::cout; // Default to printing to stdout... - std::istream* In = &std::cin; // Default to reading stdin - std::string ErrorMessage; - BytecodeAnalysis bca; - - /// Determine what to generate - bca.detailedResults = !NoDetails; - bca.progressiveVerify = Verify; - - /// Analyze the bytecode file - Module* M = AnalyzeBytecodeFile(InputFilename, bca, &ErrorMessage, (Dump?Out:0)); - - // All that bcanalyzer does is write the gathered statistics to the output - PrintBytecodeAnalysis(bca,*Out); - - if ( M && Verify ) { - std::string verificationMsg; - try { - verifyModule( *M, ThrowExceptionAction ); - } catch (std::string& errmsg ) { - verificationMsg = errmsg; +main(int argc, char **argv) { + try { + cl::ParseCommandLineOptions(argc, argv, + " llvm-bcanalyzer Analysis of ByteCode Dumper\n"); + + sys::PrintStackTraceOnErrorSignal(); + + std::ostream* Out = &std::cout; // Default to printing to stdout... + std::istream* In = &std::cin; // Default to reading stdin + std::string ErrorMessage; + BytecodeAnalysis bca; + + /// Determine what to generate + bca.detailedResults = !NoDetails; + bca.progressiveVerify = Verify; + + /// Analyze the bytecode file + Module* M = AnalyzeBytecodeFile(InputFilename, bca, &ErrorMessage, (Dump?Out:0)); + + // All that bcanalyzer does is write the gathered statistics to the output + PrintBytecodeAnalysis(bca,*Out); + + if ( M && Verify ) { + std::string verificationMsg; + try { + verifyModule( *M, ThrowExceptionAction ); + } catch (std::string& errmsg ) { + verificationMsg = errmsg; + } + if ( verificationMsg.length() > 0 ) + std::cerr << "Final Verification Message: " << verificationMsg << "\n"; } - if ( verificationMsg.length() > 0 ) - std::cerr << "Final Verification Message: " << verificationMsg << "\n"; - } - // If there was an error, print it and stop. - if ( ErrorMessage.size() ) { - std::cerr << argv[0] << ": " << ErrorMessage << "\n"; - return 1; - } - + // If there was an error, print it and stop. + if ( ErrorMessage.size() ) { + std::cerr << argv[0] << ": " << ErrorMessage << "\n"; + return 1; + } + - if (Out != &std::cout) { - ((std::ofstream*)Out)->close(); - delete Out; + if (Out != &std::cout) { + ((std::ofstream*)Out)->close(); + delete Out; + } + return 0; + } catch (const std::string& msg) { + std::cerr << argv[0] << ": " << msg << "\n"; + } catch (...) { + std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; } - return 0; + return 1; } // vim: sw=2 -- cgit v1.2.3