[llvm-commits] CVS: llvm/tools/llvm-db/llvm-db.cpp

Reid Spencer reid at x10sys.com
Wed Dec 29 21:36:22 PST 2004



Changes in directory llvm/tools/llvm-db:

llvm-db.cpp updated: 1.7 -> 1.8
---
Log message:

For PR351: http://llvm.cs.uiuc.edu/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.


---
Diffs of the changes:  (+39 -32)

Index: llvm/tools/llvm-db/llvm-db.cpp
diff -u llvm/tools/llvm-db/llvm-db.cpp:1.7 llvm/tools/llvm-db/llvm-db.cpp:1.8
--- llvm/tools/llvm-db/llvm-db.cpp:1.7	Sat Oct 16 21:49:08 2004
+++ llvm/tools/llvm-db/llvm-db.cpp	Wed Dec 29 23:36:07 2004
@@ -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();
-
-  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);
-
-  // Create the CLI debugger...
-  CLIDebugger D;
-
-  // 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";
+  try {
+    cl::ParseCommandLineOptions(argc, argv,
+                                " llvm source-level debugger\n");
+    sys::PrintStackTraceOnErrorSignal();
+
+    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);
+
+    // Create the CLI debugger...
+    CLIDebugger D;
+
+    // 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";
+      }
+
+      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;
 }






More information about the llvm-commits mailing list