summaryrefslogtreecommitdiff
path: root/tools/lli
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/lli
parentc18671cdcd53df08cbeff7ecf443475f61971b9d (diff)
downloadllvm-1ef8bdaedbd98bee35a573b8bc87149f2182cb5e.tar.gz
llvm-1ef8bdaedbd98bee35a573b8bc87149f2182cb5e.tar.bz2
llvm-1ef8bdaedbd98bee35a573b8bc87149f2182cb5e.tar.xz
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/lli')
-rw-r--r--tools/lli/lli.cpp117
1 files changed, 62 insertions, 55 deletions
diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp
index eb8ac0126e..6d16ea5c80 100644
--- a/tools/lli/lli.cpp
+++ b/tools/lli/lli.cpp
@@ -47,62 +47,69 @@ namespace {
// main Driver function
//
int main(int argc, char **argv, char * const *envp) {
- cl::ParseCommandLineOptions(argc, argv,
- " llvm interpreter & dynamic compiler\n");
- sys::PrintStackTraceOnErrorSignal();
-
- // Load the bytecode...
- std::string ErrorMsg;
- ModuleProvider *MP = 0;
try {
- MP = getBytecodeModuleProvider(InputFile);
- } catch (std::string &err) {
- std::cerr << "Error loading program '" << InputFile << "': " << err << "\n";
- exit(1);
- }
-
- ExecutionEngine *EE = ExecutionEngine::create(MP, ForceInterpreter);
- assert(EE && "Couldn't create an ExecutionEngine, not even an interpreter?");
-
- // If the user specifically requested an argv[0] to pass into the program, do
- // it now.
- if (!FakeArgv0.empty()) {
- InputFile = FakeArgv0;
- } else {
- // Otherwise, if there is a .bc suffix on the executable strip it off, it
- // might confuse the program.
- if (InputFile.rfind(".bc") == InputFile.length() - 3)
- InputFile.erase(InputFile.length() - 3);
- }
-
- // Add the module's name to the start of the vector of arguments to main().
- InputArgv.insert(InputArgv.begin(), InputFile);
-
- // Call the main function from M as if its signature were:
- // int main (int argc, char **argv, const char **envp)
- // using the contents of Args to determine argc & argv, and the contents of
- // EnvVars to determine envp.
- //
- Function *Fn = MP->getModule()->getMainFunction();
- if (!Fn) {
- std::cerr << "'main' function not found in module.\n";
- return -1;
+ cl::ParseCommandLineOptions(argc, argv,
+ " llvm interpreter & dynamic compiler\n");
+ sys::PrintStackTraceOnErrorSignal();
+
+ // Load the bytecode...
+ std::string ErrorMsg;
+ ModuleProvider *MP = 0;
+ try {
+ MP = getBytecodeModuleProvider(InputFile);
+ } catch (std::string &err) {
+ std::cerr << "Error loading program '" << InputFile << "': " << err << "\n";
+ exit(1);
+ }
+
+ ExecutionEngine *EE = ExecutionEngine::create(MP, ForceInterpreter);
+ assert(EE && "Couldn't create an ExecutionEngine, not even an interpreter?");
+
+ // If the user specifically requested an argv[0] to pass into the program, do
+ // it now.
+ if (!FakeArgv0.empty()) {
+ InputFile = FakeArgv0;
+ } else {
+ // Otherwise, if there is a .bc suffix on the executable strip it off, it
+ // might confuse the program.
+ if (InputFile.rfind(".bc") == InputFile.length() - 3)
+ InputFile.erase(InputFile.length() - 3);
+ }
+
+ // Add the module's name to the start of the vector of arguments to main().
+ InputArgv.insert(InputArgv.begin(), InputFile);
+
+ // Call the main function from M as if its signature were:
+ // int main (int argc, char **argv, const char **envp)
+ // using the contents of Args to determine argc & argv, and the contents of
+ // EnvVars to determine envp.
+ //
+ Function *Fn = MP->getModule()->getMainFunction();
+ if (!Fn) {
+ std::cerr << "'main' function not found in module.\n";
+ return -1;
+ }
+
+ // Run main...
+ int Result = EE->runFunctionAsMain(Fn, InputArgv, envp);
+
+ // If the program didn't explicitly call exit, call exit now, for the program.
+ // This ensures that any atexit handlers get called correctly.
+ Function *Exit = MP->getModule()->getOrInsertFunction("exit", Type::VoidTy,
+ Type::IntTy, 0);
+
+ std::vector<GenericValue> Args;
+ GenericValue ResultGV;
+ ResultGV.IntVal = Result;
+ Args.push_back(ResultGV);
+ EE->runFunction(Exit, Args);
+
+ std::cerr << "ERROR: exit(" << Result << ") returned!\n";
+ abort();
+ } catch (const std::string& msg) {
+ std::cerr << argv[0] << ": " << msg << "\n";
+ } catch (...) {
+ std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
}
-
- // Run main...
- int Result = EE->runFunctionAsMain(Fn, InputArgv, envp);
-
- // If the program didn't explicitly call exit, call exit now, for the program.
- // This ensures that any atexit handlers get called correctly.
- Function *Exit = MP->getModule()->getOrInsertFunction("exit", Type::VoidTy,
- Type::IntTy, 0);
-
- std::vector<GenericValue> Args;
- GenericValue ResultGV;
- ResultGV.IntVal = Result;
- Args.push_back(ResultGV);
- EE->runFunction(Exit, Args);
-
- std::cerr << "ERROR: exit(" << Result << ") returned!\n";
abort();
}