diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:55:28 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:55:28 +0000 |
commit | e81d9d49145e432d917eea3a70d2ae74dcad1d89 (patch) | |
tree | 9ed5e1a91f242e2cb5911577356e487a55c01b78 /tools/driver | |
parent | 85d8ef8f1f0e0e063a8571944302be2d2026f823 (diff) | |
download | src-e81d9d49145e432d917eea3a70d2ae74dcad1d89.tar.gz src-e81d9d49145e432d917eea3a70d2ae74dcad1d89.zip |
Vendor import of stripped lldb trunk r256633:
Notes
Notes:
svn path=/vendor/lldb/dist/; revision=292932
Diffstat (limited to 'tools/driver')
-rw-r--r-- | tools/driver/Driver.cpp | 217 | ||||
-rw-r--r-- | tools/driver/Driver.h | 3 |
2 files changed, 136 insertions, 84 deletions
diff --git a/tools/driver/Driver.cpp b/tools/driver/Driver.cpp index 3b2eadd836b3..0b72e22c80c8 100644 --- a/tools/driver/Driver.cpp +++ b/tools/driver/Driver.cpp @@ -35,6 +35,7 @@ #include "lldb/API/SBDebugger.h" #include "lldb/API/SBEvent.h" #include "lldb/API/SBHostOS.h" +#include "lldb/API/SBLanguageRuntime.h" #include "lldb/API/SBListener.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBTarget.h" @@ -132,6 +133,10 @@ static OptionDefinition g_options[] = "extensions have been implemented." }, { LLDB_3_TO_5, false, "debug" , 'd', no_argument , 0, eArgTypeNone, "Tells the debugger to print out extra information for debugging itself." }, + { LLDB_OPT_SET_7, true , "repl" , 'r', optional_argument, 0, eArgTypeNone, + "Runs lldb in REPL mode with a stub process." }, + { LLDB_OPT_SET_7, true , "repl-language" , 'R', required_argument, 0, eArgTypeNone, + "Chooses the language for the REPL." }, { 0, false, NULL , 0 , 0 , 0, eArgTypeNone, NULL } }; @@ -341,21 +346,27 @@ ShowUsage (FILE *out, OptionDefinition *option_table, Driver::OptionData data) indent_level, ""); indent_level += 5; - fprintf (out, "\n%*sMultiple \"-s\" and \"-o\" options can be provided. They will be processed from left to right in order, " - "\n%*swith the source files and commands interleaved. The same is true of the \"-S\" and \"-O\" options." - "\n%*sThe before file and after file sets can intermixed freely, the command parser will sort them out." - "\n%*sThe order of the file specifiers (\"-c\", \"-f\", etc.) is not significant in this regard.\n\n", + fprintf (out, "\n%*sMultiple \"-s\" and \"-o\" options can be provided. They will be processed" + "\n%*sfrom left to right in order, with the source files and commands" + "\n%*sinterleaved. The same is true of the \"-S\" and \"-O\" options. The before" + "\n%*sfile and after file sets can intermixed freely, the command parser will" + "\n%*ssort them out. The order of the file specifiers (\"-c\", \"-f\", etc.) is" + "\n%*snot significant in this regard.\n\n", indent_level, "", indent_level, "", indent_level, "", + indent_level, "", + indent_level, "", indent_level, ""); - fprintf (out, "\n%*sIf you don't provide -f then the first argument will be the file to be debugged" - "\n%*swhich means that '%s -- <filename> [<ARG1> [<ARG2>]]' also works." - "\n%*sBut remember to end the options with \"--\" if any of your arguments have a \"-\" in them.\n\n", + fprintf (out, "\n%*sIf you don't provide -f then the first argument will be the file to be" + "\n%*sdebugged which means that '%s -- <filename> [<ARG1> [<ARG2>]]' also" + "\n%*sworks. But remember to end the options with \"--\" if any of your" + "\n%*sarguments have a \"-\" in them.\n\n", indent_level, "", indent_level, "", name, + indent_level, "", indent_level, ""); } @@ -408,6 +419,9 @@ Driver::OptionData::OptionData () : m_print_python_path (false), m_print_help (false), m_wait_for(false), + m_repl (false), + m_repl_lang (eLanguageTypeUnknown), + m_repl_options (), m_process_name(), m_process_pid(LLDB_INVALID_PROCESS_ID), m_use_external_editor(false), @@ -769,6 +783,23 @@ Driver::ParseArgs (int argc, const char *argv[], FILE *out_fh, bool &exiting) optarg); } break; + + case 'r': + m_option_data.m_repl = true; + if (optarg && optarg[0]) + m_option_data.m_repl_options = optarg; + else + m_option_data.m_repl_options.clear(); + break; + + case 'R': + m_option_data.m_repl_lang = SBLanguageRuntime::GetLanguageTypeFromString (optarg); + if (m_option_data.m_repl_lang == eLanguageTypeUnknown) + { + error.SetErrorStringWithFormat ("Unrecognized language name: \"%s\"", optarg); + } + break; + case 's': m_option_data.AddInitialCommand(optarg, eCommandPlacementAfterFile, true, error); break; @@ -1056,96 +1087,114 @@ Driver::MainLoop () bool handle_events = true; bool spawn_thread = false; - // Check if we have any data in the commands stream, and if so, save it to a temp file - // so we can then run the command interpreter using the file contents. - const char *commands_data = commands_stream.GetData(); - const size_t commands_size = commands_stream.GetSize(); - - // The command file might have requested that we quit, this variable will track that. - bool quit_requested = false; - bool stopped_for_crash = false; - if (commands_data && commands_size) + if (m_option_data.m_repl) { - int initial_commands_fds[2]; - bool success = true; - FILE *commands_file = PrepareCommandsForSourcing (commands_data, commands_size, initial_commands_fds); - if (commands_file) + const char *repl_options = NULL; + if (!m_option_data.m_repl_options.empty()) + repl_options = m_option_data.m_repl_options.c_str(); + SBError error (m_debugger.RunREPL(m_option_data.m_repl_lang, repl_options)); + if (error.Fail()) { - m_debugger.SetInputFileHandle (commands_file, true); - - // Set the debugger into Sync mode when running the command file. Otherwise command files - // that run the target won't run in a sensible way. - bool old_async = m_debugger.GetAsync(); - m_debugger.SetAsync(false); - int num_errors; - - SBCommandInterpreterRunOptions options; - options.SetStopOnError (true); - if (m_option_data.m_batch) - options.SetStopOnCrash (true); - - m_debugger.RunCommandInterpreter(handle_events, - spawn_thread, - options, - num_errors, - quit_requested, - stopped_for_crash); - - if (m_option_data.m_batch && stopped_for_crash && !m_option_data.m_after_crash_commands.empty()) + const char *error_cstr = error.GetCString(); + if (error_cstr && error_cstr[0]) + fprintf (stderr, "error: %s\n", error_cstr); + else + fprintf (stderr, "error: %u\n", error.GetError()); + } + } + else + { + // Check if we have any data in the commands stream, and if so, save it to a temp file + // so we can then run the command interpreter using the file contents. + const char *commands_data = commands_stream.GetData(); + const size_t commands_size = commands_stream.GetSize(); + + // The command file might have requested that we quit, this variable will track that. + bool quit_requested = false; + bool stopped_for_crash = false; + if (commands_data && commands_size) + { + int initial_commands_fds[2]; + bool success = true; + FILE *commands_file = PrepareCommandsForSourcing (commands_data, commands_size, initial_commands_fds); + if (commands_file) { - int crash_command_fds[2]; - SBStream crash_commands_stream; - WriteCommandsForSourcing (eCommandPlacementAfterCrash, crash_commands_stream); - const char *crash_commands_data = crash_commands_stream.GetData(); - const size_t crash_commands_size = crash_commands_stream.GetSize(); - commands_file = PrepareCommandsForSourcing (crash_commands_data, crash_commands_size, crash_command_fds); - if (commands_file) + m_debugger.SetInputFileHandle (commands_file, true); + + // Set the debugger into Sync mode when running the command file. Otherwise command files + // that run the target won't run in a sensible way. + bool old_async = m_debugger.GetAsync(); + m_debugger.SetAsync(false); + int num_errors; + + SBCommandInterpreterRunOptions options; + options.SetStopOnError (true); + if (m_option_data.m_batch) + options.SetStopOnCrash (true); + + m_debugger.RunCommandInterpreter(handle_events, + spawn_thread, + options, + num_errors, + quit_requested, + stopped_for_crash); + + if (m_option_data.m_batch && stopped_for_crash && !m_option_data.m_after_crash_commands.empty()) { - bool local_quit_requested; - bool local_stopped_for_crash; - m_debugger.SetInputFileHandle (commands_file, true); - - m_debugger.RunCommandInterpreter(handle_events, - spawn_thread, - options, - num_errors, - local_quit_requested, - local_stopped_for_crash); - if (local_quit_requested) - quit_requested = true; + int crash_command_fds[2]; + SBStream crash_commands_stream; + WriteCommandsForSourcing (eCommandPlacementAfterCrash, crash_commands_stream); + const char *crash_commands_data = crash_commands_stream.GetData(); + const size_t crash_commands_size = crash_commands_stream.GetSize(); + commands_file = PrepareCommandsForSourcing (crash_commands_data, crash_commands_size, crash_command_fds); + if (commands_file) + { + bool local_quit_requested; + bool local_stopped_for_crash; + m_debugger.SetInputFileHandle (commands_file, true); + + m_debugger.RunCommandInterpreter(handle_events, + spawn_thread, + options, + num_errors, + local_quit_requested, + local_stopped_for_crash); + if (local_quit_requested) + quit_requested = true; + } } + m_debugger.SetAsync(old_async); } - m_debugger.SetAsync(old_async); - } - else - success = false; + else + success = false; - // Close any pipes that we still have ownership of - CleanupAfterCommandSourcing(initial_commands_fds); + // Close any pipes that we still have ownership of + CleanupAfterCommandSourcing(initial_commands_fds); - // Something went wrong with command pipe - if (!success) - { - exit(1); - } + // Something went wrong with command pipe + if (!success) + { + exit(1); + } - } + } - // Now set the input file handle to STDIN and run the command - // interpreter again in interactive mode and let the debugger - // take ownership of stdin + // Now set the input file handle to STDIN and run the command + // interpreter again in interactive mode and let the debugger + // take ownership of stdin - bool go_interactive = true; - if (quit_requested) - go_interactive = false; - else if (m_option_data.m_batch && !stopped_for_crash) - go_interactive = false; + bool go_interactive = true; + if (quit_requested) + go_interactive = false; + else if (m_option_data.m_batch && !stopped_for_crash) + go_interactive = false; - if (go_interactive) - { - m_debugger.SetInputFileHandle (stdin, true); - m_debugger.RunCommandInterpreter(handle_events, spawn_thread); + if (go_interactive) + { + m_debugger.SetInputFileHandle (stdin, true); + m_debugger.RunCommandInterpreter(handle_events, spawn_thread); + } } reset_stdin_termios(); diff --git a/tools/driver/Driver.h b/tools/driver/Driver.h index b1e536d43c05..639ac41d7fe6 100644 --- a/tools/driver/Driver.h +++ b/tools/driver/Driver.h @@ -105,6 +105,9 @@ public: bool m_print_python_path; bool m_print_help; bool m_wait_for; + bool m_repl; + lldb::LanguageType m_repl_lang; + std::string m_repl_options; std::string m_process_name; lldb::pid_t m_process_pid; bool m_use_external_editor; // FIXME: When we have set/show variables we can remove this from here. |