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
diff --git a/tools/llvm-db/llvm-db.cpp b/tools/llvm-db/llvm-db.cpp
index 2e8dc83..f7913df 100644
--- a/tools/llvm-db/llvm-db.cpp
+++ b/tools/llvm-db/llvm-db.cpp
@@ -50,39 +50,46 @@
 // main Driver function
 //
 int main(int argc, char **argv, char * const *envp) {
-  cl::ParseCommandLineOptions(argc, argv,
-                              " llvm source-level debugger\n");
-  sys::PrintStackTraceOnErrorSignal();
+  try {
+    cl::ParseCommandLineOptions(argc, argv,
+                                " llvm source-level debugger\n");
+    sys::PrintStackTraceOnErrorSignal();
 
-  if (!Quiet)
-    std::cout << "llvm-db: The LLVM source-level debugger\n";
+    if (!Quiet)
+      std::cout << "llvm-db: The LLVM source-level debugger\n";
 
-  // Merge Inputfile and InputArgs into the InputArgs list...
-  if (!InputFile.empty() && InputArgs.empty())
-    InputArgs.push_back(InputFile);
+    // Merge Inputfile and InputArgs into the InputArgs list...
+    if (!InputFile.empty() && InputArgs.empty())
+      InputArgs.push_back(InputFile);
 
-  // Create the CLI debugger...
-  CLIDebugger D;
+    // Create the CLI debugger...
+    CLIDebugger D;
 
-  // Initialize the debugger with the command line options we read...
-  Debugger &Dbg = D.getDebugger();
+    // Initialize the debugger with the command line options we read...
+    Debugger &Dbg = D.getDebugger();
 
-  // Initialize the debugger environment.
-  Dbg.initializeEnvironment(envp);
-  Dbg.setWorkingDirectory(WorkingDirectory);
-  for (unsigned i = 0, e = SourceDirectories.size(); i != e; ++i)
-    D.addSourceDirectory(SourceDirectories[i]);
-  
-  if (!InputArgs.empty()) {
-    try {
-      D.fileCommand(InputArgs[0]);
-    } catch (const std::string &Error) {
-      std::cout << "Error: " << Error << "\n";
+    // Initialize the debugger environment.
+    Dbg.initializeEnvironment(envp);
+    Dbg.setWorkingDirectory(WorkingDirectory);
+    for (unsigned i = 0, e = SourceDirectories.size(); i != e; ++i)
+      D.addSourceDirectory(SourceDirectories[i]);
+    
+    if (!InputArgs.empty()) {
+      try {
+        D.fileCommand(InputArgs[0]);
+      } catch (const std::string &Error) {
+        std::cout << "Error: " << Error << "\n";
+      }
+
+      Dbg.setProgramArguments(InputArgs.begin()+1, InputArgs.end());
     }
 
-    Dbg.setProgramArguments(InputArgs.begin()+1, InputArgs.end());
+    // Now that we have initialized the debugger, run it.
+    return D.run();
+  } catch (const std::string& msg) {
+    std::cerr << argv[0] << ": " << msg << "\n";
+  } catch (...) {
+    std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
   }
-
-  // Now that we have initialized the debugger, run it.
-  return D.run();
+  return 1;
 }