aboutsummaryrefslogtreecommitdiffstats
path: root/tools/llvm-bcanalyzer
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-12-30 05:36:08 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-12-30 05:36:08 +0000
commit1ef8bdaedbd98bee35a573b8bc87149f2182cb5e (patch)
treedc21da7903997dfbcf6061f19b35a2a522c740b9 /tools/llvm-bcanalyzer
parentc18671cdcd53df08cbeff7ecf443475f61971b9d (diff)
downloadexternal_llvm-1ef8bdaedbd98bee35a573b8bc87149f2182cb5e.zip
external_llvm-1ef8bdaedbd98bee35a573b8bc87149f2182cb5e.tar.gz
external_llvm-1ef8bdaedbd98bee35a573b8bc87149f2182cb5e.tar.bz2
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
Diffstat (limited to 'tools/llvm-bcanalyzer')
-rw-r--r--tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp88
1 files changed, 47 insertions, 41 deletions
diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
index d4be138..b79b6fe 100644
--- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
+++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
@@ -49,52 +49,58 @@ static cl::opt<bool> Dump ("dump", cl::desc("Dump low level bytecode trace"
static cl::opt<bool> 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