diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
commit | cfca06d7963fa0909f90483b42a6d7d194d01e08 (patch) | |
tree | 209fb2a2d68f8f277793fc8df46c753d31bc853b /lldb/tools | |
parent | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (diff) |
Notes
Diffstat (limited to 'lldb/tools')
-rw-r--r-- | lldb/tools/driver/Driver.cpp | 180 | ||||
-rw-r--r-- | lldb/tools/driver/Driver.h | 6 | ||||
-rw-r--r-- | lldb/tools/driver/Options.td | 8 | ||||
-rw-r--r-- | lldb/tools/driver/Platform.h | 6 | ||||
-rw-r--r-- | lldb/tools/lldb-instr/Instrument.cpp | 7 | ||||
-rw-r--r-- | lldb/tools/lldb-mi/lldb-mi.exports | 0 | ||||
-rw-r--r-- | lldb/tools/lldb-server/Acceptor.cpp | 2 | ||||
-rw-r--r-- | lldb/tools/lldb-server/Acceptor.h | 6 | ||||
-rw-r--r-- | lldb/tools/lldb-server/LLDBServerUtilities.h | 6 | ||||
-rw-r--r-- | lldb/tools/lldb-server/SystemInitializerLLGS.h | 6 | ||||
-rw-r--r-- | lldb/tools/lldb-server/lldb-platform.cpp | 4 |
11 files changed, 130 insertions, 101 deletions
diff --git a/lldb/tools/driver/Driver.cpp b/lldb/tools/driver/Driver.cpp index 73874389aa1b..cea9e5a44aa8 100644 --- a/lldb/tools/driver/Driver.cpp +++ b/lldb/tools/driver/Driver.cpp @@ -9,6 +9,7 @@ #include "Driver.h" #include "lldb/API/SBCommandInterpreter.h" +#include "lldb/API/SBCommandInterpreterRunOptions.h" #include "lldb/API/SBCommandReturnObject.h" #include "lldb/API/SBDebugger.h" #include "lldb/API/SBFile.h" @@ -360,13 +361,8 @@ SBError Driver::ProcessArgs(const opt::InputArgList &args, bool &exiting) { if (m_option_data.m_process_name.empty() && m_option_data.m_process_pid == LLDB_INVALID_PROCESS_ID) { - // If the option data args array is empty that means the file was not - // specified with -f and we need to get it from the input args. - if (m_option_data.m_args.empty()) { - if (auto *arg = args.getLastArgNoClaim(OPT_INPUT)) { - m_option_data.m_args.push_back(arg->getAsString((args))); - } - } + for (auto *arg : args.filtered(OPT_INPUT)) + m_option_data.m_args.push_back(arg->getAsString((args))); // Any argument following -- is an argument for the inferior. if (auto *arg = args.getLastArgNoClaim(OPT_REM)) { @@ -587,74 +583,75 @@ int Driver::MainLoop() { 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; + bool go_interactive = true; if ((commands_data != nullptr) && (commands_size != 0u)) { - bool success = true; FILE *commands_file = PrepareCommandsForSourcing(commands_data, commands_size); - if (commands_file != nullptr) { - 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 = 0; - - 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()) { - 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); - if (commands_file != nullptr) { - 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); - } else - success = false; - // Something went wrong with command pipe - if (!success) { + if (commands_file == nullptr) { + // We should have already printed an error in PrepareCommandsForSourcing. exit(1); } - } - // Now set the input file handle to STDIN and run the command - // interpreter again in interactive mode or repl mode and let the debugger - // take ownership of stdin + 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); + + SBCommandInterpreterRunOptions options; + options.SetAutoHandleEvents(true); + options.SetSpawnThread(false); + options.SetStopOnError(true); + options.SetStopOnCrash(m_option_data.m_batch); + + SBCommandInterpreterRunResult results = + m_debugger.RunCommandInterpreter(options); + if (results.GetResult() == lldb::eCommandInterpreterResultQuitRequested) + go_interactive = false; + if (m_option_data.m_batch && + results.GetResult() != lldb::eCommandInterpreterResultInferiorCrash) + go_interactive = false; + + // When running in batch mode and stopped because of an error, exit with a + // non-zero exit status. + if (m_option_data.m_batch && + results.GetResult() == lldb::eCommandInterpreterResultCommandError) + exit(1); - bool go_interactive = true; - if (quit_requested) - go_interactive = false; - else if (m_option_data.m_batch && !stopped_for_crash) - go_interactive = false; + if (m_option_data.m_batch && + results.GetResult() == lldb::eCommandInterpreterResultInferiorCrash && + !m_option_data.m_after_crash_commands.empty()) { + 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); + if (commands_file != nullptr) { + m_debugger.SetInputFileHandle(commands_file, true); + SBCommandInterpreterRunResult local_results = + m_debugger.RunCommandInterpreter(options); + if (local_results.GetResult() == + lldb::eCommandInterpreterResultQuitRequested) + go_interactive = false; + + // When running in batch mode and an error occurred while sourcing + // the crash commands, exit with a non-zero exit status. + if (m_option_data.m_batch && + local_results.GetResult() == + lldb::eCommandInterpreterResultCommandError) + exit(1); + } + } + m_debugger.SetAsync(old_async); + } + // Now set the input file handle to STDIN and run the command interpreter + // again in interactive mode or repl mode and let the debugger take ownership + // of stdin. if (go_interactive) { m_debugger.SetInputFileHandle(stdin, true); @@ -763,10 +760,15 @@ EXAMPLES: The debugger can be started in several modes. Passing an executable as a positional argument prepares lldb to debug the - given executable. Arguments passed after -- are considered arguments to the - debugged executable. + given executable. To disambiguate between arguments passed to lldb and + arguments passed to the debugged executable, arguments starting with a - must + be passed after --. + + lldb --arch x86_64 /path/to/program program argument -- --arch arvm7 + + For convenience, passing the executable after -- is also supported. - lldb --arch x86_64 /path/to/program -- --arch arvm7 + lldb --arch x86_64 -- /path/to/program program argument --arch arvm7 Passing one of the attach options causes lldb to immediately attach to the given process. @@ -795,11 +797,12 @@ EXAMPLES: llvm::outs() << examples << '\n'; } -llvm::Optional<int> InitializeReproducer(opt::InputArgList &input_args) { +llvm::Optional<int> InitializeReproducer(llvm::StringRef argv0, + opt::InputArgList &input_args) { if (auto *replay_path = input_args.getLastArg(OPT_replay)) { - const bool skip_version_check = input_args.hasArg(OPT_skip_version_check); + const bool no_version_check = input_args.hasArg(OPT_no_version_check); if (const char *error = - SBReproducer::Replay(replay_path->getValue(), skip_version_check)) { + SBReproducer::Replay(replay_path->getValue(), no_version_check)) { WithColor::error() << "reproducer replay failed: " << error << '\n'; return 1; } @@ -807,9 +810,21 @@ llvm::Optional<int> InitializeReproducer(opt::InputArgList &input_args) { } bool capture = input_args.hasArg(OPT_capture); + bool generate_on_exit = input_args.hasArg(OPT_generate_on_exit); auto *capture_path = input_args.getLastArg(OPT_capture_path); + if (generate_on_exit && !capture) { + WithColor::warning() + << "-reproducer-generate-on-exit specified without -capture\n"; + } + if (capture || capture_path) { + // Register the reproducer signal handler. + if (!input_args.hasArg(OPT_no_generate_on_signal)) { + llvm::sys::AddSignalHandler(reproducer_handler, + const_cast<char *>(argv0.data())); + } + if (capture_path) { if (!capture) WithColor::warning() << "-capture-path specified without -capture\n"; @@ -824,6 +839,8 @@ llvm::Optional<int> InitializeReproducer(opt::InputArgList &input_args) { return 1; } } + if (generate_on_exit) + SBReproducer::SetAutoGenerate(true); } return llvm::None; @@ -840,24 +857,27 @@ int main(int argc, char const *argv[]) { unsigned MAC; ArrayRef<const char *> arg_arr = makeArrayRef(argv + 1, argc - 1); opt::InputArgList input_args = T.ParseArgs(arg_arr, MAI, MAC); + llvm::StringRef argv0 = llvm::sys::path::filename(argv[0]); if (input_args.hasArg(OPT_help)) { - printHelp(T, llvm::sys::path::filename(argv[0])); + printHelp(T, argv0); return 0; } - for (auto *arg : input_args.filtered(OPT_UNKNOWN)) { - WithColor::warning() << "ignoring unknown option: " << arg->getSpelling() - << '\n'; + // Error out on unknown options. + if (input_args.hasArg(OPT_UNKNOWN)) { + for (auto *arg : input_args.filtered(OPT_UNKNOWN)) { + WithColor::error() << "unknown option: " << arg->getSpelling() << '\n'; + } + llvm::errs() << "Use '" << argv0 + << " --help' for a complete list of options.\n"; + return 1; } - if (auto exit_code = InitializeReproducer(input_args)) { + if (auto exit_code = InitializeReproducer(argv[0], input_args)) { return *exit_code; } - // Register the reproducer signal handler. - llvm::sys::AddSignalHandler(reproducer_handler, const_cast<char *>(argv[0])); - SBError error = SBDebugger::InitializeWithErrorHandling(); if (error.Fail()) { WithColor::error() << "initialization failed: " << error.GetCString() diff --git a/lldb/tools/driver/Driver.h b/lldb/tools/driver/Driver.h index f442458ae401..2d91491a2540 100644 --- a/lldb/tools/driver/Driver.h +++ b/lldb/tools/driver/Driver.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef lldb_Driver_h_ -#define lldb_Driver_h_ +#ifndef LLDB_TOOLS_DRIVER_DRIVER_H +#define LLDB_TOOLS_DRIVER_DRIVER_H #include "Platform.h" @@ -99,4 +99,4 @@ private: OptionData m_option_data; }; -#endif // lldb_Driver_h_ +#endif // LLDB_TOOLS_DRIVER_DRIVER_H diff --git a/lldb/tools/driver/Options.td b/lldb/tools/driver/Options.td index c237f568f64c..96f696ec3ca6 100644 --- a/lldb/tools/driver/Options.td +++ b/lldb/tools/driver/Options.td @@ -232,7 +232,11 @@ def capture_path: Separate<["--", "-"], "capture-path">, def replay: Separate<["--", "-"], "replay">, MetaVarName<"<filename>">, HelpText<"Tells the debugger to replay a reproducer from <filename>.">; -def skip_version_check: F<"reproducer-skip-version-check">, - HelpText<"Skip the reproducer version check.">; +def no_version_check: F<"reproducer-no-version-check">, + HelpText<"Disable the reproducer version check.">; +def no_generate_on_signal: F<"reproducer-no-generate-on-signal">, + HelpText<"Don't generate reproducer when a signal is received.">; +def generate_on_exit: F<"reproducer-generate-on-exit">, + HelpText<"Generate reproducer on exit.">; def REM : R<["--"], "">; diff --git a/lldb/tools/driver/Platform.h b/lldb/tools/driver/Platform.h index cf6c4ec8e146..6b893f91f442 100644 --- a/lldb/tools/driver/Platform.h +++ b/lldb/tools/driver/Platform.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef lldb_Platform_h_ -#define lldb_Platform_h_ +#ifndef LLDB_TOOLS_DRIVER_PLATFORM_H +#define LLDB_TOOLS_DRIVER_PLATFORM_H #include "lldb/Host/Config.h" @@ -87,4 +87,4 @@ extern int tcgetattr(int fildes, struct termios *termios_p); #include <sys/time.h> #endif -#endif // lldb_Platform_h_ +#endif // LLDB_TOOLS_DRIVER_PLATFORM_H diff --git a/lldb/tools/lldb-instr/Instrument.cpp b/lldb/tools/lldb-instr/Instrument.cpp index 9b2970030cb0..8ec01304891b 100644 --- a/lldb/tools/lldb-instr/Instrument.cpp +++ b/lldb/tools/lldb-instr/Instrument.cpp @@ -194,10 +194,9 @@ public: ParamTypes.push_back(T.getAsString(Policy)); ParamNames.push_back(P->getNameAsString()); - // Currently we don't support functions that have void pointers or - // function pointers as an argument, in which case we insert a dummy - // macro. - ShouldInsertDummy |= T->isFunctionPointerType() || T->isVoidPointerType(); + // Currently we don't support functions that have function pointers as an + // argument, in which case we insert a dummy macro. + ShouldInsertDummy |= T->isFunctionPointerType(); } // Convert the two lists to string for the macros. diff --git a/lldb/tools/lldb-mi/lldb-mi.exports b/lldb/tools/lldb-mi/lldb-mi.exports deleted file mode 100644 index e69de29bb2d1..000000000000 --- a/lldb/tools/lldb-mi/lldb-mi.exports +++ /dev/null diff --git a/lldb/tools/lldb-server/Acceptor.cpp b/lldb/tools/lldb-server/Acceptor.cpp index 2cfb34d215c8..b8be9c5c2661 100644 --- a/lldb/tools/lldb-server/Acceptor.cpp +++ b/lldb/tools/lldb-server/Acceptor.cpp @@ -118,7 +118,7 @@ std::unique_ptr<Acceptor> Acceptor::Create(StringRef name, return (local_port != 0) ? llvm::to_string(local_port) : ""; }; } else { - const std::string socket_name = name; + const std::string socket_name = std::string(name); local_socket_id = [socket_name]() { return socket_name; }; } diff --git a/lldb/tools/lldb-server/Acceptor.h b/lldb/tools/lldb-server/Acceptor.h index 1e7337f14113..b441e92dcd22 100644 --- a/lldb/tools/lldb-server/Acceptor.h +++ b/lldb/tools/lldb-server/Acceptor.h @@ -5,8 +5,8 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// -#ifndef lldb_server_Acceptor_h_ -#define lldb_server_Acceptor_h_ +#ifndef LLDB_TOOLS_LLDB_SERVER_ACCEPTOR_H +#define LLDB_TOOLS_LLDB_SERVER_ACCEPTOR_H #include "lldb/Host/Socket.h" #include "lldb/Utility/Connection.h" @@ -57,4 +57,4 @@ private: } // namespace lldb_server } // namespace lldb_private -#endif // lldb_server_Acceptor_h_ +#endif // LLDB_TOOLS_LLDB_SERVER_ACCEPTOR_H diff --git a/lldb/tools/lldb-server/LLDBServerUtilities.h b/lldb/tools/lldb-server/LLDBServerUtilities.h index 3ade1f9f5b8a..b59d1e411540 100644 --- a/lldb/tools/lldb-server/LLDBServerUtilities.h +++ b/lldb/tools/lldb-server/LLDBServerUtilities.h @@ -1,3 +1,7 @@ +#ifndef LLDB_TOOLS_LLDB_SERVER_LLDBSERVERUTILITIES_H + +#define LLDB_TOOLS_LLDB_SERVER_LLDBSERVERUTILITIES_H + //===-- LLDBServerUtilities.h -----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. @@ -21,3 +25,5 @@ public: }; } } + +#endif diff --git a/lldb/tools/lldb-server/SystemInitializerLLGS.h b/lldb/tools/lldb-server/SystemInitializerLLGS.h index 59a1fa14e81c..f3d015e94f8c 100644 --- a/lldb/tools/lldb-server/SystemInitializerLLGS.h +++ b/lldb/tools/lldb-server/SystemInitializerLLGS.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLDB_SYSTEMINITIALIZERLLGS_H -#define LLDB_SYSTEMINITIALIZERLLGS_H +#ifndef LLDB_TOOLS_LLDB_SERVER_SYSTEMINITIALIZERLLGS_H +#define LLDB_TOOLS_LLDB_SERVER_SYSTEMINITIALIZERLLGS_H #include "lldb/Initialization/SystemInitializer.h" #include "lldb/Initialization/SystemInitializerCommon.h" @@ -18,4 +18,4 @@ public: void Terminate() override; }; -#endif // LLDB_SYSTEMINITIALIZERLLGS_H +#endif // LLDB_TOOLS_LLDB_SERVER_SYSTEMINITIALIZERLLGS_H diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp index a6fb5639d642..33f918ffc2a1 100644 --- a/lldb/tools/lldb-server/lldb-platform.cpp +++ b/lldb/tools/lldb-server/lldb-platform.cpp @@ -96,7 +96,7 @@ static void display_usage(const char *progname, const char *subcommand) { static Status save_socket_id_to_file(const std::string &socket_id, const FileSpec &file_spec) { - FileSpec temp_file_spec(file_spec.GetDirectory().AsCString()); + FileSpec temp_file_spec(file_spec.GetDirectory().GetStringRef()); Status error(llvm::sys::fs::create_directory(temp_file_spec.GetPath())); if (error.Fail()) return Status("Failed to create directory %s: %s", @@ -343,7 +343,7 @@ int main_platform(int argc, char *argv[]) { // connections while a connection is active. acceptor_up.reset(); } - platform.SetConnection(conn); + platform.SetConnection(std::unique_ptr<Connection>(conn)); if (platform.IsConnected()) { if (inferior_arguments.GetArgumentCount() > 0) { |