diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
commit | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (patch) | |
tree | 4adf86a776049cbf7f69a1929c4babcbbef925eb /lldb/source/Commands | |
parent | 7cc9cf2bf09f069cb2dd947ead05d0b54301fb71 (diff) | |
download | src-706b4fc47bbc608932d3b491ae19a3b9cde9497b.tar.gz src-706b4fc47bbc608932d3b491ae19a3b9cde9497b.zip |
Vendor import of llvm-project master e26a78e70, the last commit beforevendor/llvm-project/llvmorg-10-init-17466-ge26a78e7085
the llvmorg-11-init tag, from which release/10.x was branched.
Notes
Notes:
svn path=/vendor/llvm-project/master/; revision=356843
svn path=/vendor/llvm-project/llvmorg-10-init-17466-ge26a78e7085/; revision=356844; tag=vendor/llvm-project/llvmorg-10-init-17466-ge26a78e7085
Diffstat (limited to 'lldb/source/Commands')
46 files changed, 966 insertions, 987 deletions
diff --git a/lldb/source/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp index 469a6bbbadf6..d9bee66b442a 100644 --- a/lldb/source/Commands/CommandCompletions.cpp +++ b/lldb/source/Commands/CommandCompletions.cpp @@ -6,11 +6,6 @@ // //===----------------------------------------------------------------------===// -#include <sys/stat.h> -#if defined(__APPLE__) || defined(__linux__) -#include <pwd.h> -#endif - #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringSet.h" @@ -23,13 +18,10 @@ #include "lldb/Interpreter/OptionValueProperties.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/Variable.h" -#include "lldb/Target/Target.h" -#include "lldb/Utility/Args.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/StreamString.h" #include "lldb/Utility/TildeExpressionResolver.h" -#include "llvm/ADT/SmallString.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" @@ -378,8 +370,10 @@ CommandCompletions::SourceFileCompleter::SearchCallback(SearchFilter &filter, } } } else { - const char *cur_file_name = context.comp_unit->GetFilename().GetCString(); - const char *cur_dir_name = context.comp_unit->GetDirectory().GetCString(); + const char *cur_file_name = + context.comp_unit->GetPrimaryFile().GetFilename().GetCString(); + const char *cur_dir_name = + context.comp_unit->GetPrimaryFile().GetDirectory().GetCString(); bool match = false; if (m_file_name && cur_file_name && @@ -391,7 +385,7 @@ CommandCompletions::SourceFileCompleter::SearchCallback(SearchFilter &filter, match = false; if (match) { - m_matching_files.AppendIfUnique(context.comp_unit); + m_matching_files.AppendIfUnique(context.comp_unit->GetPrimaryFile()); } } } @@ -411,10 +405,7 @@ void CommandCompletions::SourceFileCompleter::DoCompletion( // SymbolCompleter static bool regex_chars(const char comp) { - return (comp == '[' || comp == ']' || comp == '(' || comp == ')' || - comp == '{' || comp == '}' || comp == '+' || comp == '.' || - comp == '*' || comp == '|' || comp == '^' || comp == '$' || - comp == '\\' || comp == '?'); + return llvm::StringRef("[](){}+.*|^$\\?").contains(comp); } CommandCompletions::SymbolCompleter::SymbolCompleter( diff --git a/lldb/source/Commands/CommandObjectApropos.cpp b/lldb/source/Commands/CommandObjectApropos.cpp index 7ba0b250fbd5..15a20737273d 100644 --- a/lldb/source/Commands/CommandObjectApropos.cpp +++ b/lldb/source/Commands/CommandObjectApropos.cpp @@ -10,7 +10,6 @@ #include "CommandObjectApropos.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" -#include "lldb/Interpreter/Options.h" #include "lldb/Interpreter/Property.h" #include "lldb/Utility/Args.h" diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp index ad699975b507..7c4c50ecf3f9 100644 --- a/lldb/source/Commands/CommandObjectBreakpoint.cpp +++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp @@ -12,7 +12,6 @@ #include "lldb/Breakpoint/BreakpointIDList.h" #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Host/OptionParser.h" -#include "lldb/Interpreter/CommandCompletions.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/OptionArgParser.h" @@ -24,7 +23,6 @@ #include "lldb/Target/Language.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" -#include "lldb/Target/Thread.h" #include "lldb/Target/ThreadSpec.h" #include "lldb/Utility/RegularExpression.h" #include "lldb/Utility/StreamString.h" @@ -48,13 +46,10 @@ static void AddBreakpointDescription(Stream *s, Breakpoint *bp, #define LLDB_OPTIONS_breakpoint_modify #include "CommandOptions.inc" -class lldb_private::BreakpointOptionGroup : public OptionGroup -{ +class lldb_private::BreakpointOptionGroup : public OptionGroup { public: - BreakpointOptionGroup() : - OptionGroup(), - m_bp_opts(false) {} - + BreakpointOptionGroup() : OptionGroup(), m_bp_opts(false) {} + ~BreakpointOptionGroup() override = default; llvm::ArrayRef<OptionDefinition> GetDefinitions() override { @@ -62,9 +57,10 @@ public: } Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, - ExecutionContext *execution_context) override { + ExecutionContext *execution_context) override { Status error; - const int short_option = g_breakpoint_modify_options[option_idx].short_option; + const int short_option = + g_breakpoint_modify_options[option_idx].short_option; switch (short_option) { case 'c': @@ -91,18 +87,15 @@ public: error.SetErrorStringWithFormat( "invalid boolean value '%s' passed for -G option", option_arg.str().c_str()); - } - break; - case 'i': - { + } break; + case 'i': { uint32_t ignore_count; if (option_arg.getAsInteger(0, ignore_count)) error.SetErrorStringWithFormat("invalid ignore count '%s'", option_arg.str().c_str()); else m_bp_opts.SetIgnoreCount(ignore_count); - } - break; + } break; case 'o': { bool value, success; value = OptionArgParser::ToBoolean(option_arg, false, &success); @@ -113,8 +106,7 @@ public: "invalid boolean value '%s' passed for -o option", option_arg.str().c_str()); } break; - case 't': - { + case 't': { lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID; if (option_arg[0] != '\0') { if (option_arg.getAsInteger(0, thread_id)) @@ -122,16 +114,14 @@ public: option_arg.str().c_str()); } m_bp_opts.SetThreadID(thread_id); - } - break; + } break; case 'T': m_bp_opts.GetThreadSpec()->SetName(option_arg.str().c_str()); break; case 'q': m_bp_opts.GetThreadSpec()->SetQueueName(option_arg.str().c_str()); break; - case 'x': - { + case 'x': { uint32_t thread_index = UINT32_MAX; if (option_arg[0] != '\n') { if (option_arg.getAsInteger(0, thread_index)) @@ -139,8 +129,7 @@ public: option_arg.str().c_str()); } m_bp_opts.GetThreadSpec()->SetIndex(thread_index); - } - break; + } break; default: llvm_unreachable("Unimplemented option"); } @@ -152,43 +141,33 @@ public: m_bp_opts.Clear(); m_commands.clear(); } - + Status OptionParsingFinished(ExecutionContext *execution_context) override { - if (!m_commands.empty()) - { - if (!m_commands.empty()) - { - auto cmd_data = std::make_unique<BreakpointOptions::CommandData>(); - - for (std::string &str : m_commands) - cmd_data->user_source.AppendString(str); - - cmd_data->stop_on_error = true; - m_bp_opts.SetCommandDataCallback(cmd_data); - } + if (!m_commands.empty()) { + auto cmd_data = std::make_unique<BreakpointOptions::CommandData>(); + + for (std::string &str : m_commands) + cmd_data->user_source.AppendString(str); + + cmd_data->stop_on_error = true; + m_bp_opts.SetCommandDataCallback(cmd_data); } return Status(); } - - const BreakpointOptions &GetBreakpointOptions() - { - return m_bp_opts; - } + + const BreakpointOptions &GetBreakpointOptions() { return m_bp_opts; } std::vector<std::string> m_commands; BreakpointOptions m_bp_opts; - }; #define LLDB_OPTIONS_breakpoint_dummy #include "CommandOptions.inc" -class BreakpointDummyOptionGroup : public OptionGroup -{ +class BreakpointDummyOptionGroup : public OptionGroup { public: - BreakpointDummyOptionGroup() : - OptionGroup() {} - + BreakpointDummyOptionGroup() : OptionGroup() {} + ~BreakpointDummyOptionGroup() override = default; llvm::ArrayRef<OptionDefinition> GetDefinitions() override { @@ -196,14 +175,15 @@ public: } Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, - ExecutionContext *execution_context) override { + ExecutionContext *execution_context) override { Status error; - const int short_option = g_breakpoint_modify_options[option_idx].short_option; + const int short_option = + g_breakpoint_dummy_options[option_idx].short_option; switch (short_option) { - case 'D': - m_use_dummy = true; - break; + case 'D': + m_use_dummy = true; + break; default: llvm_unreachable("Unimplemented option"); } @@ -216,7 +196,6 @@ public: } bool m_use_dummy; - }; #define LLDB_OPTIONS_breakpoint_set @@ -242,11 +221,11 @@ public: interpreter, "breakpoint set", "Sets a breakpoint or set of breakpoints in the executable.", "breakpoint set <cmd-options>"), - m_bp_opts(), m_python_class_options("scripted breakpoint", 'P'), + m_bp_opts(), m_python_class_options("scripted breakpoint", true, 'P'), m_options() { // We're picking up all the normal options, commands and disable. - m_all_options.Append(&m_python_class_options, LLDB_OPT_SET_1, - LLDB_OPT_SET_11); + m_all_options.Append(&m_python_class_options, + LLDB_OPT_SET_1 | LLDB_OPT_SET_2, LLDB_OPT_SET_11); m_all_options.Append(&m_bp_opts, LLDB_OPT_SET_1 | LLDB_OPT_SET_3 | LLDB_OPT_SET_4, LLDB_OPT_SET_ALL); @@ -262,21 +241,23 @@ public: class CommandOptions : public OptionGroup { public: CommandOptions() - : OptionGroup(), m_condition(), m_filenames(), m_line_num(0), m_column(0), - m_func_names(), m_func_name_type_mask(eFunctionNameTypeNone), - m_func_regexp(), m_source_text_regexp(), m_modules(), m_load_addr(), - m_catch_bp(false), m_throw_bp(true), m_hardware(false), + : OptionGroup(), m_condition(), m_filenames(), m_line_num(0), + m_column(0), m_func_names(), + m_func_name_type_mask(eFunctionNameTypeNone), m_func_regexp(), + m_source_text_regexp(), m_modules(), m_load_addr(), m_catch_bp(false), + m_throw_bp(true), m_hardware(false), m_exception_language(eLanguageTypeUnknown), m_language(lldb::eLanguageTypeUnknown), - m_skip_prologue(eLazyBoolCalculate), - m_all_files(false), m_move_to_nearest_code(eLazyBoolCalculate) {} + m_skip_prologue(eLazyBoolCalculate), m_all_files(false), + m_move_to_nearest_code(eLazyBoolCalculate) {} ~CommandOptions() override = default; Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override { Status error; - const int short_option = g_breakpoint_set_options[option_idx].short_option; + const int short_option = + g_breakpoint_set_options[option_idx].short_option; switch (short_option) { case 'a': { @@ -342,7 +323,7 @@ public: m_func_names.push_back(option_arg); m_func_name_type_mask |= eFunctionNameTypeFull; break; - + case 'h': { bool success; m_catch_bp = OptionArgParser::ToBoolean(option_arg, true, &success); @@ -355,7 +336,7 @@ public: case 'H': m_hardware = true; break; - + case 'K': { bool success; bool value; @@ -436,7 +417,7 @@ public: case 'p': m_source_text_regexp.assign(option_arg); break; - + case 'r': m_func_regexp.assign(option_arg); break; @@ -543,7 +524,7 @@ protected: BreakpointSetType break_type = eSetTypeInvalid; - if (!m_python_class_options.GetClassName().empty()) + if (!m_python_class_options.GetName().empty()) break_type = eSetTypeScripted; else if (m_options.m_line_num != 0) break_type = eSetTypeFileAndLine; @@ -635,22 +616,21 @@ protected: case eSetTypeFunctionRegexp: // Breakpoint by regular expression function // name - { - RegularExpression regexp(m_options.m_func_regexp); - if (llvm::Error err = regexp.GetError()) { - result.AppendErrorWithFormat( - "Function name regular expression could not be compiled: \"%s\"", - llvm::toString(std::move(err)).c_str()); - result.SetStatus(eReturnStatusFailed); - return false; - } - - bp_sp = target.CreateFuncRegexBreakpoint( - &(m_options.m_modules), &(m_options.m_filenames), std::move(regexp), - m_options.m_language, m_options.m_skip_prologue, internal, - m_options.m_hardware); + { + RegularExpression regexp(m_options.m_func_regexp); + if (llvm::Error err = regexp.GetError()) { + result.AppendErrorWithFormat( + "Function name regular expression could not be compiled: \"%s\"", + llvm::toString(std::move(err)).c_str()); + result.SetStatus(eReturnStatusFailed); + return false; } - break; + + bp_sp = target.CreateFuncRegexBreakpoint( + &(m_options.m_modules), &(m_options.m_filenames), std::move(regexp), + m_options.m_language, m_options.m_skip_prologue, internal, + m_options.m_hardware); + } break; case eSetTypeSourceRegexp: // Breakpoint by regexp on source text. { const size_t num_files = m_options.m_filenames.GetSize(); @@ -699,13 +679,12 @@ protected: Status error; bp_sp = target.CreateScriptedBreakpoint( - m_python_class_options.GetClassName().c_str(), &(m_options.m_modules), + m_python_class_options.GetName().c_str(), &(m_options.m_modules), &(m_options.m_filenames), false, m_options.m_hardware, m_python_class_options.GetStructuredData(), &error); if (error.Fail()) { result.AppendErrorWithFormat( - "Error setting extra exception arguments: %s", - error.AsCString()); + "Error setting extra exception arguments: %s", error.AsCString()); target.RemoveBreakpointByID(bp_sp->GetID()); result.SetStatus(eReturnStatusFailed); return false; @@ -733,12 +712,12 @@ protected: } } } - + if (bp_sp) { Stream &output_stream = result.GetOutputStream(); const bool show_locations = false; bp_sp->GetDescription(&output_stream, lldb::eDescriptionLevelInitial, - show_locations); + show_locations); if (&target == &GetDummyTarget()) output_stream.Printf("Breakpoint set in dummy target, will get copied " "into future targets.\n"); @@ -822,9 +801,9 @@ public: // Add the entry for the first argument for this command to the object's // arguments vector. m_arguments.push_back(arg); - - m_options.Append(&m_bp_opts, - LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3, + + m_options.Append(&m_bp_opts, + LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3, LLDB_OPT_SET_ALL); m_options.Append(&m_dummy_opts, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL); m_options.Finalize(); @@ -859,11 +838,11 @@ protected: BreakpointLocation *location = bp->FindLocationByID(cur_bp_id.GetLocationID()).get(); if (location) - location->GetLocationOptions() - ->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); + location->GetLocationOptions()->CopyOverSetOptions( + m_bp_opts.GetBreakpointOptions()); } else { - bp->GetOptions() - ->CopyOverSetOptions(m_bp_opts.GetBreakpointOptions()); + bp->GetOptions()->CopyOverSetOptions( + m_bp_opts.GetBreakpointOptions()); } } } @@ -1183,7 +1162,7 @@ protected: for (size_t i = 0; i < num_breakpoints; ++i) { Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex(i).get(); if (breakpoint->AllowList()) - AddBreakpointDescription(&output_stream, breakpoint, + AddBreakpointDescription(&output_stream, breakpoint, m_options.m_level); } result.SetStatus(eReturnStatusSuccessFinishNoResult); @@ -1580,62 +1559,61 @@ public: Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override { Status error; - const int short_option - = g_breakpoint_access_options[option_idx].short_option; + const int short_option = + g_breakpoint_access_options[option_idx].short_option; switch (short_option) { - case 'L': { - bool value, success; - value = OptionArgParser::ToBoolean(option_arg, false, &success); - if (success) { - m_permissions.SetAllowList(value); - } else - error.SetErrorStringWithFormat( - "invalid boolean value '%s' passed for -L option", - option_arg.str().c_str()); - } break; - case 'A': { - bool value, success; - value = OptionArgParser::ToBoolean(option_arg, false, &success); - if (success) { - m_permissions.SetAllowDisable(value); - } else - error.SetErrorStringWithFormat( - "invalid boolean value '%s' passed for -L option", - option_arg.str().c_str()); - } break; - case 'D': { - bool value, success; - value = OptionArgParser::ToBoolean(option_arg, false, &success); - if (success) { - m_permissions.SetAllowDelete(value); - } else - error.SetErrorStringWithFormat( - "invalid boolean value '%s' passed for -L option", - option_arg.str().c_str()); - } break; - default: - llvm_unreachable("Unimplemented option"); + case 'L': { + bool value, success; + value = OptionArgParser::ToBoolean(option_arg, false, &success); + if (success) { + m_permissions.SetAllowList(value); + } else + error.SetErrorStringWithFormat( + "invalid boolean value '%s' passed for -L option", + option_arg.str().c_str()); + } break; + case 'A': { + bool value, success; + value = OptionArgParser::ToBoolean(option_arg, false, &success); + if (success) { + m_permissions.SetAllowDisable(value); + } else + error.SetErrorStringWithFormat( + "invalid boolean value '%s' passed for -L option", + option_arg.str().c_str()); + } break; + case 'D': { + bool value, success; + value = OptionArgParser::ToBoolean(option_arg, false, &success); + if (success) { + m_permissions.SetAllowDelete(value); + } else + error.SetErrorStringWithFormat( + "invalid boolean value '%s' passed for -L option", + option_arg.str().c_str()); + } break; + default: + llvm_unreachable("Unimplemented option"); } - + return error; } - - void OptionParsingStarting(ExecutionContext *execution_context) override { - } - - const BreakpointName::Permissions &GetPermissions() const - { + + void OptionParsingStarting(ExecutionContext *execution_context) override {} + + const BreakpointName::Permissions &GetPermissions() const { return m_permissions; } - BreakpointName::Permissions m_permissions; + BreakpointName::Permissions m_permissions; }; class CommandObjectBreakpointNameConfigure : public CommandObjectParsed { public: CommandObjectBreakpointNameConfigure(CommandInterpreter &interpreter) : CommandObjectParsed( - interpreter, "configure", "Configure the options for the breakpoint" + interpreter, "configure", + "Configure the options for the breakpoint" " name provided. " "If you provide a breakpoint id, the options will be copied from " "the breakpoint, otherwise only the options specified will be set " @@ -1652,14 +1630,10 @@ public: arg1.push_back(id_arg); m_arguments.push_back(arg1); - m_option_group.Append(&m_bp_opts, - LLDB_OPT_SET_ALL, - LLDB_OPT_SET_1); - m_option_group.Append(&m_access_options, - LLDB_OPT_SET_ALL, + m_option_group.Append(&m_bp_opts, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); + m_option_group.Append(&m_access_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_ALL); - m_option_group.Append(&m_bp_id, - LLDB_OPT_SET_2|LLDB_OPT_SET_4, + m_option_group.Append(&m_bp_id, LLDB_OPT_SET_2 | LLDB_OPT_SET_4, LLDB_OPT_SET_ALL); m_option_group.Finalize(); } @@ -1686,8 +1660,7 @@ protected: // Make a pass through first to see that all the names are legal. for (auto &entry : command.entries()) { Status error; - if (!BreakpointID::StringIsBreakpointName(entry.ref(), error)) - { + if (!BreakpointID::StringIsBreakpointName(entry.ref(), error)) { result.AppendErrorWithFormat("Invalid breakpoint name: %s - %s", entry.c_str(), error.AsCString()); result.SetStatus(eReturnStatusFailed); @@ -1697,14 +1670,12 @@ protected: // Now configure them, we already pre-checked the names so we don't need to // check the error: BreakpointSP bp_sp; - if (m_bp_id.m_breakpoint.OptionWasSet()) - { + if (m_bp_id.m_breakpoint.OptionWasSet()) { lldb::break_id_t bp_id = m_bp_id.m_breakpoint.GetUInt64Value(); bp_sp = target.GetBreakpointByID(bp_id); - if (!bp_sp) - { + if (!bp_sp) { result.AppendErrorWithFormatv("Could not find specified breakpoint {0}", - bp_id); + bp_id); result.SetStatus(eReturnStatusFailed); return false; } @@ -1718,7 +1689,7 @@ protected: continue; if (m_bp_id.m_help_string.OptionWasSet()) bp_name->SetHelp(m_bp_id.m_help_string.GetStringValue().str().c_str()); - + if (bp_sp) target.ConfigureBreakpointName(*bp_name, *bp_sp->GetOptions(), m_access_options.GetPermissions()); @@ -1797,7 +1768,7 @@ protected: } size_t num_valid_ids = valid_bp_ids.GetSize(); const char *bp_name = m_name_options.m_name.GetCurrentValue(); - Status error; // This error reports illegal names, but we've already + Status error; // This error reports illegal names, but we've already // checked that, so we don't need to check it again here. for (size_t index = 0; index < num_valid_ids; index++) { lldb::break_id_t bp_id = @@ -1918,12 +1889,11 @@ protected: if (command.empty()) { target.GetBreakpointNames(name_list); } else { - for (const Args::ArgEntry &arg : command) - { + for (const Args::ArgEntry &arg : command) { name_list.push_back(arg.c_str()); } } - + if (name_list.empty()) { result.AppendMessage("No breakpoint names found."); } else { @@ -1933,15 +1903,13 @@ protected: Status error; BreakpointName *bp_name = target.FindBreakpointName(ConstString(name), false, error); - if (bp_name) - { + if (bp_name) { StreamString s; result.AppendMessageWithFormat("Name: %s\n", name); - if (bp_name->GetDescription(&s, eDescriptionLevelFull)) - { + if (bp_name->GetDescription(&s, eDescriptionLevelFull)) { result.AppendMessage(s.GetString()); } - + std::unique_lock<std::recursive_mutex> lock; target.GetBreakpointList().GetListMutex(lock); @@ -2274,13 +2242,10 @@ CommandObjectMultiwordBreakpoint::CommandObjectMultiwordBreakpoint( CommandObjectMultiwordBreakpoint::~CommandObjectMultiwordBreakpoint() = default; -void CommandObjectMultiwordBreakpoint::VerifyIDs(Args &args, Target *target, - bool allow_locations, - CommandReturnObject &result, - BreakpointIDList *valid_ids, - BreakpointName::Permissions - ::PermissionKinds - purpose) { +void CommandObjectMultiwordBreakpoint::VerifyIDs( + Args &args, Target *target, bool allow_locations, + CommandReturnObject &result, BreakpointIDList *valid_ids, + BreakpointName::Permissions ::PermissionKinds purpose) { // args can be strings representing 1). integers (for breakpoint ids) // 2). the full breakpoint & location // canonical representation @@ -2313,7 +2278,7 @@ void CommandObjectMultiwordBreakpoint::VerifyIDs(Args &args, Target *target, // breakpoint ids in the range, and shove all of those breakpoint id strings // into TEMP_ARGS. - BreakpointIDList::FindAndReplaceIDRanges(args, target, allow_locations, + BreakpointIDList::FindAndReplaceIDRanges(args, target, allow_locations, purpose, result, temp_args); // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual diff --git a/lldb/source/Commands/CommandObjectBreakpoint.h b/lldb/source/Commands/CommandObjectBreakpoint.h index cba1f3f774ee..b29bbc0a74fa 100644 --- a/lldb/source/Commands/CommandObjectBreakpoint.h +++ b/lldb/source/Commands/CommandObjectBreakpoint.h @@ -10,16 +10,8 @@ #define liblldb_CommandObjectBreakpoint_h_ -#include <utility> -#include <vector> - -#include "lldb/lldb-private.h" #include "lldb/Breakpoint/BreakpointName.h" -#include "lldb/Core/Address.h" -#include "lldb/Core/STLUtils.h" #include "lldb/Interpreter/CommandObjectMultiword.h" -#include "lldb/Interpreter/Options.h" - namespace lldb_private { @@ -31,19 +23,17 @@ public: ~CommandObjectMultiwordBreakpoint() override; - static void VerifyBreakpointOrLocationIDs(Args &args, Target *target, - CommandReturnObject &result, - BreakpointIDList *valid_ids, - BreakpointName::Permissions - ::PermissionKinds purpose) { + static void VerifyBreakpointOrLocationIDs( + Args &args, Target *target, CommandReturnObject &result, + BreakpointIDList *valid_ids, + BreakpointName::Permissions ::PermissionKinds purpose) { VerifyIDs(args, target, true, result, valid_ids, purpose); } - static void VerifyBreakpointIDs(Args &args, Target *target, - CommandReturnObject &result, - BreakpointIDList *valid_ids, - BreakpointName::Permissions::PermissionKinds - purpose) { + static void + VerifyBreakpointIDs(Args &args, Target *target, CommandReturnObject &result, + BreakpointIDList *valid_ids, + BreakpointName::Permissions::PermissionKinds purpose) { VerifyIDs(args, target, false, result, valid_ids, purpose); } @@ -51,8 +41,7 @@ private: static void VerifyIDs(Args &args, Target *target, bool allow_locations, CommandReturnObject &result, BreakpointIDList *valid_ids, - BreakpointName::Permissions::PermissionKinds - purpose); + BreakpointName::Permissions::PermissionKinds purpose); }; } // namespace lldb_private diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp index a6bcd1d8dc32..bbd2ca570126 100644 --- a/lldb/source/Commands/CommandObjectBreakpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.cpp @@ -11,17 +11,13 @@ #include "lldb/Breakpoint/Breakpoint.h" #include "lldb/Breakpoint/BreakpointIDList.h" #include "lldb/Breakpoint/BreakpointLocation.h" -#include "lldb/Breakpoint/StoppointCallbackContext.h" #include "lldb/Core/IOHandler.h" #include "lldb/Host/OptionParser.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/OptionArgParser.h" +#include "lldb/Interpreter/OptionGroupPythonClassWithDict.h" #include "lldb/Target/Target.h" -#include "lldb/Target/Thread.h" -#include "lldb/Utility/State.h" - -#include "llvm/ADT/STLExtras.h" using namespace lldb; using namespace lldb_private; @@ -41,7 +37,12 @@ static constexpr OptionEnumValueElement g_script_option_enumeration[] = { "Commands are in the Python language.", }, { - eSortOrderByName, + eScriptLanguageLua, + "lua", + "Commands are in the Lua language.", + }, + { + eScriptLanguageDefault, "default-script", "Commands are in the default scripting language.", }, @@ -66,7 +67,7 @@ public: nullptr), IOHandlerDelegateMultiline("DONE", IOHandlerDelegate::Completion::LLDBCommand), - m_options() { + m_options(), m_func_options("breakpoint command", false, 'F') { SetHelpLong( R"( General information about entering breakpoint commands @@ -201,6 +202,11 @@ LLDB to stop." "Final Note: A warning that no breakpoint command was generated when there \ are no syntax errors may indicate that a function was declared but never called."); + m_all_options.Append(&m_options); + m_all_options.Append(&m_func_options, LLDB_OPT_SET_2 | LLDB_OPT_SET_3, + LLDB_OPT_SET_2); + m_all_options.Finalize(); + CommandArgumentEntry arg; CommandArgumentData bp_id_arg; @@ -218,7 +224,7 @@ are no syntax errors may indicate that a function was declared but never called. ~CommandObjectBreakpointCommandAdd() override = default; - Options *GetOptions() override { return &m_options; } + Options *GetOptions() override { return &m_all_options; } void IOHandlerActivated(IOHandler &io_handler, bool interactive) override { StreamFileSP output_sp(io_handler.GetOutputStreamFileSP()); @@ -250,7 +256,6 @@ are no syntax errors may indicate that a function was declared but never called. m_interpreter.GetLLDBCommandsFromIOHandler( "> ", // Prompt *this, // IOHandlerDelegate - true, // Run IOHandler in async mode &bp_options_vec); // Baton for the "io_handler" that will be passed back // into our IOHandlerDelegate functions } @@ -269,19 +274,20 @@ are no syntax errors may indicate that a function was declared but never called. } } - class CommandOptions : public Options { + class CommandOptions : public OptionGroup { public: CommandOptions() - : Options(), m_use_commands(false), m_use_script_language(false), + : OptionGroup(), m_use_commands(false), m_use_script_language(false), m_script_language(eScriptLanguageNone), m_use_one_liner(false), - m_one_liner(), m_function_name() {} + m_one_liner() {} ~CommandOptions() override = default; Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override { Status error; - const int short_option = m_getopt_table[option_idx].val; + const int short_option = + g_breakpoint_command_add_options[option_idx].short_option; switch (short_option) { case 'o': @@ -294,12 +300,15 @@ are no syntax errors may indicate that a function was declared but never called. option_arg, g_breakpoint_command_add_options[option_idx].enum_values, eScriptLanguageNone, error); - - if (m_script_language == eScriptLanguagePython || - m_script_language == eScriptLanguageDefault) { + switch (m_script_language) { + case eScriptLanguagePython: + case eScriptLanguageLua: m_use_script_language = true; - } else { + break; + case eScriptLanguageNone: + case eScriptLanguageUnknown: m_use_script_language = false; + break; } break; @@ -313,12 +322,6 @@ are no syntax errors may indicate that a function was declared but never called. option_arg.str().c_str()); } break; - case 'F': - m_use_one_liner = false; - m_use_script_language = true; - m_function_name.assign(option_arg); - break; - case 'D': m_use_dummy = true; break; @@ -337,7 +340,6 @@ are no syntax errors may indicate that a function was declared but never called. m_use_one_liner = false; m_stop_on_error = true; m_one_liner.clear(); - m_function_name.clear(); m_use_dummy = false; } @@ -355,7 +357,6 @@ are no syntax errors may indicate that a function was declared but never called. bool m_use_one_liner; std::string m_one_liner; bool m_stop_on_error; - std::string m_function_name; bool m_use_dummy; }; @@ -372,12 +373,12 @@ protected: return false; } - if (!m_options.m_use_script_language && - !m_options.m_function_name.empty()) { - result.AppendError("need to enable scripting to have a function run as a " - "breakpoint command"); - result.SetStatus(eReturnStatusFailed); - return false; + if (!m_func_options.GetName().empty()) { + m_options.m_use_one_liner = false; + if (!m_options.m_use_script_language) { + m_options.m_script_language = GetDebugger().GetScriptLanguage(); + m_options.m_use_script_language = true; + } } BreakpointIDList valid_bp_ids; @@ -416,14 +417,18 @@ protected: // to set or collect command callback. Otherwise, call the methods // associated with this object. if (m_options.m_use_script_language) { - ScriptInterpreter *script_interp = GetDebugger().GetScriptInterpreter(); + ScriptInterpreter *script_interp = GetDebugger().GetScriptInterpreter( + /*can_create=*/true, m_options.m_script_language); // Special handling for one-liner specified inline. if (m_options.m_use_one_liner) { script_interp->SetBreakpointCommandCallback( m_bp_options_vec, m_options.m_one_liner.c_str()); - } else if (!m_options.m_function_name.empty()) { - script_interp->SetBreakpointCommandCallbackFunction( - m_bp_options_vec, m_options.m_function_name.c_str()); + } else if (!m_func_options.GetName().empty()) { + Status error = script_interp->SetBreakpointCommandCallbackFunction( + m_bp_options_vec, m_func_options.GetName().c_str(), + m_func_options.GetStructuredData()); + if (!error.Success()) + result.SetError(error); } else { script_interp->CollectDataForBreakpointCommandCallback( m_bp_options_vec, result); @@ -443,6 +448,9 @@ protected: private: CommandOptions m_options; + OptionGroupPythonClassWithDict m_func_options; + OptionGroupOptions m_all_options; + std::vector<BreakpointOptions *> m_bp_options_vec; // This stores the // breakpoint options that // we are currently @@ -646,9 +654,8 @@ protected: if (bp) { BreakpointLocationSP bp_loc_sp; if (cur_bp_id.GetLocationID() != LLDB_INVALID_BREAK_ID) { - bp_loc_sp = bp->FindLocationByID(cur_bp_id.GetLocationID()); - if (!bp_loc_sp) - { + bp_loc_sp = bp->FindLocationByID(cur_bp_id.GetLocationID()); + if (!bp_loc_sp) { result.AppendErrorWithFormat("Invalid breakpoint ID: %u.%u.\n", cur_bp_id.GetBreakpointID(), cur_bp_id.GetLocationID()); @@ -663,19 +670,20 @@ protected: cur_bp_id.GetLocationID()); const Baton *baton = nullptr; if (bp_loc_sp) - baton = bp_loc_sp - ->GetOptionsSpecifyingKind(BreakpointOptions::eCallback) - ->GetBaton(); + baton = + bp_loc_sp + ->GetOptionsSpecifyingKind(BreakpointOptions::eCallback) + ->GetBaton(); else baton = bp->GetOptions()->GetBaton(); if (baton) { result.GetOutputStream().Printf("Breakpoint %s:\n", id_str.GetData()); - result.GetOutputStream().IndentMore(); - baton->GetDescription(&result.GetOutputStream(), - eDescriptionLevelFull); - result.GetOutputStream().IndentLess(); + baton->GetDescription(result.GetOutputStream().AsRawOstream(), + eDescriptionLevelFull, + result.GetOutputStream().GetIndentLevel() + + 2); } else { result.AppendMessageWithFormat( "Breakpoint %s does not have an associated command.\n", @@ -700,9 +708,10 @@ protected: CommandObjectBreakpointCommand::CommandObjectBreakpointCommand( CommandInterpreter &interpreter) : CommandObjectMultiword( - interpreter, "command", "Commands for adding, removing and listing " - "LLDB commands executed when a breakpoint is " - "hit.", + interpreter, "command", + "Commands for adding, removing and listing " + "LLDB commands executed when a breakpoint is " + "hit.", "command <sub-command> [<sub-command-options>] <breakpoint-id>") { CommandObjectSP add_command_object( new CommandObjectBreakpointCommandAdd(interpreter)); diff --git a/lldb/source/Commands/CommandObjectBreakpointCommand.h b/lldb/source/Commands/CommandObjectBreakpointCommand.h index b18e003368be..fb246d47abfd 100644 --- a/lldb/source/Commands/CommandObjectBreakpointCommand.h +++ b/lldb/source/Commands/CommandObjectBreakpointCommand.h @@ -9,13 +9,7 @@ #ifndef liblldb_CommandObjectBreakpointCommand_h_ #define liblldb_CommandObjectBreakpointCommand_h_ - - -#include "lldb/Interpreter/CommandObject.h" #include "lldb/Interpreter/CommandObjectMultiword.h" -#include "lldb/Interpreter/CommandReturnObject.h" -#include "lldb/Interpreter/Options.h" -#include "lldb/lldb-types.h" namespace lldb_private { diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index 259affbe6e0a..388db6fad631 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -12,7 +12,6 @@ #include "CommandObjectHelp.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/IOHandler.h" -#include "lldb/Host/OptionParser.h" #include "lldb/Interpreter/CommandHistory.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandObjectRegexCommand.h" @@ -900,9 +899,10 @@ class CommandObjectCommandsAddRegex : public CommandObjectParsed, public: CommandObjectCommandsAddRegex(CommandInterpreter &interpreter) : CommandObjectParsed( - interpreter, "command regex", "Define a custom command in terms of " - "existing commands by matching " - "regular expressions.", + interpreter, "command regex", + "Define a custom command in terms of " + "existing commands by matching " + "regular expressions.", "command regex <cmd-name> [s/<regex>/<subst>/ ...]"), IOHandlerDelegateMultiline("", IOHandlerDelegate::Completion::LLDBCommand), @@ -1197,8 +1197,8 @@ public: CommandObjectPythonFunction(CommandInterpreter &interpreter, std::string name, std::string funct, std::string help, ScriptedCommandSynchronicity synch) - : CommandObjectRaw(interpreter, name), - m_function_name(funct), m_synchro(synch), m_fetched_help_long(false) { + : CommandObjectRaw(interpreter, name), m_function_name(funct), + m_synchro(synch), m_fetched_help_long(false) { if (!help.empty()) SetHelp(help); else { @@ -1241,10 +1241,9 @@ protected: result.SetStatus(eReturnStatusInvalid); - if (!scripter || - !scripter->RunScriptBasedCommand(m_function_name.c_str(), - raw_command_line, m_synchro, result, - error, m_exe_ctx)) { + if (!scripter || !scripter->RunScriptBasedCommand( + m_function_name.c_str(), raw_command_line, m_synchro, + result, error, m_exe_ctx)) { result.AppendError(error.AsCString()); result.SetStatus(eReturnStatusFailed); } else { @@ -1272,8 +1271,8 @@ public: std::string name, StructuredData::GenericSP cmd_obj_sp, ScriptedCommandSynchronicity synch) - : CommandObjectRaw(interpreter, name), - m_cmd_obj_sp(cmd_obj_sp), m_synchro(synch), m_fetched_help_short(false), + : CommandObjectRaw(interpreter, name), m_cmd_obj_sp(cmd_obj_sp), + m_synchro(synch), m_fetched_help_short(false), m_fetched_help_long(false) { StreamString stream; stream.Printf("For more information run 'help %s'", name.c_str()); @@ -1404,7 +1403,7 @@ protected: switch (short_option) { case 'r': - m_allow_reload = true; + // NO-OP break; default: llvm_unreachable("Unimplemented option"); @@ -1414,26 +1413,14 @@ protected: } void OptionParsingStarting(ExecutionContext *execution_context) override { - m_allow_reload = true; } llvm::ArrayRef<OptionDefinition> GetDefinitions() override { return llvm::makeArrayRef(g_script_import_options); } - - // Instance variables to hold the values for command options. - - bool m_allow_reload; }; bool DoExecute(Args &command, CommandReturnObject &result) override { - if (GetDebugger().GetScriptLanguage() != lldb::eScriptLanguagePython) { - result.AppendError("only scripting language supported for module " - "importing is currently Python"); - result.SetStatus(eReturnStatusFailed); - return false; - } - if (command.empty()) { result.AppendError("command script import needs one or more arguments"); result.SetStatus(eReturnStatusFailed); @@ -1454,7 +1441,7 @@ protected: // more) m_exe_ctx.Clear(); if (GetDebugger().GetScriptInterpreter()->LoadScriptingModule( - entry.c_str(), m_options.m_allow_reload, init_session, error)) { + entry.c_str(), init_session, error)) { result.SetStatus(eReturnStatusSuccessFinishNoResult); } else { result.AppendErrorWithFormat("module importing failed: %s", @@ -1663,11 +1650,8 @@ protected: if (m_options.m_class_name.empty()) { if (m_options.m_funct_name.empty()) { m_interpreter.GetPythonCommandsFromIOHandler( - " ", // Prompt - *this, // IOHandlerDelegate - true, // Run IOHandler in async mode - nullptr); // Baton for the "io_handler" that will be passed back - // into our IOHandlerDelegate functions + " ", // Prompt + *this); // IOHandlerDelegate } else { CommandObjectSP new_cmd(new CommandObjectPythonFunction( m_interpreter, m_cmd_name, m_options.m_funct_name, @@ -1821,9 +1805,10 @@ class CommandObjectMultiwordCommandsScript : public CommandObjectMultiword { public: CommandObjectMultiwordCommandsScript(CommandInterpreter &interpreter) : CommandObjectMultiword( - interpreter, "command script", "Commands for managing custom " - "commands implemented by " - "interpreter scripts.", + interpreter, "command script", + "Commands for managing custom " + "commands implemented by " + "interpreter scripts.", "command script <subcommand> [<subcommand-options>]") { LoadSubCommand("add", CommandObjectSP( new CommandObjectCommandsScriptAdd(interpreter))); diff --git a/lldb/source/Commands/CommandObjectCommands.h b/lldb/source/Commands/CommandObjectCommands.h index 468ee53344f1..dcf02f3a7da9 100644 --- a/lldb/source/Commands/CommandObjectCommands.h +++ b/lldb/source/Commands/CommandObjectCommands.h @@ -10,8 +10,6 @@ #ifndef liblldb_CommandObjectCommands_h_ #define liblldb_CommandObjectCommands_h_ -#include "lldb/Core/STLUtils.h" -#include "lldb/Interpreter/CommandObject.h" #include "lldb/Interpreter/CommandObjectMultiword.h" namespace lldb_private { diff --git a/lldb/source/Commands/CommandObjectDisassemble.cpp b/lldb/source/Commands/CommandObjectDisassemble.cpp index 69e2d757b5fe..63679e996e70 100644 --- a/lldb/source/Commands/CommandObjectDisassemble.cpp +++ b/lldb/source/Commands/CommandObjectDisassemble.cpp @@ -10,16 +10,13 @@ #include "lldb/Core/AddressRange.h" #include "lldb/Core/Disassembler.h" #include "lldb/Core/Module.h" -#include "lldb/Core/SourceManager.h" #include "lldb/Host/OptionParser.h" -#include "lldb/Interpreter/CommandCompletions.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/OptionArgParser.h" #include "lldb/Interpreter/Options.h" #include "lldb/Symbol/Function.h" #include "lldb/Symbol/Symbol.h" -#include "lldb/Target/Process.h" #include "lldb/Target/SectionLoadList.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" @@ -249,9 +246,8 @@ bool CommandObjectDisassemble::DoExecute(Args &command, m_options.arch.GetArchitectureName()); result.SetStatus(eReturnStatusFailed); return false; - } else if (flavor_string != nullptr && - !disassembler->FlavorValidForArchSpec(m_options.arch, - flavor_string)) + } else if (flavor_string != nullptr && !disassembler->FlavorValidForArchSpec( + m_options.arch, flavor_string)) result.AppendWarningWithFormat( "invalid disassembler flavor \"%s\", using default.\n", flavor_string); diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index 9bafdc149804..db90dde98eff 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -6,29 +6,20 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "CommandObjectExpression.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Value.h" -#include "lldb/Core/ValueObjectVariable.h" -#include "lldb/DataFormatters/ValueObjectPrinter.h" -#include "lldb/Expression/DWARFExpression.h" #include "lldb/Expression/REPL.h" #include "lldb/Expression/UserExpression.h" -#include "lldb/Host/Host.h" #include "lldb/Host/OptionParser.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/OptionArgParser.h" -#include "lldb/Symbol/ObjectFile.h" -#include "lldb/Symbol/Variable.h" #include "lldb/Target/Language.h" #include "lldb/Target/Process.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" -#include "lldb/Target/Thread.h" using namespace lldb; using namespace lldb_private; @@ -202,11 +193,12 @@ CommandObjectExpression::CommandOptions::GetDefinitions() { CommandObjectExpression::CommandObjectExpression( CommandInterpreter &interpreter) - : CommandObjectRaw( - interpreter, "expression", "Evaluate an expression on the current " - "thread. Displays any returned value " - "with LLDB's default formatting.", - "", eCommandProcessMustBePaused | eCommandTryTargetAPILock), + : CommandObjectRaw(interpreter, "expression", + "Evaluate an expression on the current " + "thread. Displays any returned value " + "with LLDB's default formatting.", + "", + eCommandProcessMustBePaused | eCommandTryTargetAPILock), IOHandlerDelegate(IOHandlerDelegate::Completion::Expression), m_option_group(), m_format_options(eFormatDefault), m_repl_option(LLDB_OPT_SET_1, false, "repl", 'r', "Drop into REPL", false, @@ -588,60 +580,58 @@ bool CommandObjectExpression::DoExecute(llvm::StringRef command, return false; if (m_repl_option.GetOptionValue().GetCurrentValue()) { - Target *target = m_interpreter.GetExecutionContext().GetTargetPtr(); - if (target) { - // Drop into REPL - m_expr_lines.clear(); - m_expr_line_count = 0; - - Debugger &debugger = target->GetDebugger(); - - // Check if the LLDB command interpreter is sitting on top of a REPL - // that launched it... - if (debugger.CheckTopIOHandlerTypes(IOHandler::Type::CommandInterpreter, - IOHandler::Type::REPL)) { - // the LLDB command interpreter is sitting on top of a REPL that - // launched it, so just say the command interpreter is done and - // fall back to the existing REPL - m_interpreter.GetIOHandler(false)->SetIsDone(true); - } else { - // We are launching the REPL on top of the current LLDB command - // interpreter, so just push one - bool initialize = false; - Status repl_error; - REPLSP repl_sp(target->GetREPL(repl_error, m_command_options.language, - nullptr, false)); - - if (!repl_sp) { - initialize = true; - repl_sp = target->GetREPL(repl_error, m_command_options.language, - nullptr, true); - if (!repl_error.Success()) { - result.SetError(repl_error); - return result.Succeeded(); - } + Target &target = GetSelectedOrDummyTarget(); + // Drop into REPL + m_expr_lines.clear(); + m_expr_line_count = 0; + + Debugger &debugger = target.GetDebugger(); + + // Check if the LLDB command interpreter is sitting on top of a REPL + // that launched it... + if (debugger.CheckTopIOHandlerTypes(IOHandler::Type::CommandInterpreter, + IOHandler::Type::REPL)) { + // the LLDB command interpreter is sitting on top of a REPL that + // launched it, so just say the command interpreter is done and + // fall back to the existing REPL + m_interpreter.GetIOHandler(false)->SetIsDone(true); + } else { + // We are launching the REPL on top of the current LLDB command + // interpreter, so just push one + bool initialize = false; + Status repl_error; + REPLSP repl_sp(target.GetREPL(repl_error, m_command_options.language, + nullptr, false)); + + if (!repl_sp) { + initialize = true; + repl_sp = target.GetREPL(repl_error, m_command_options.language, + nullptr, true); + if (!repl_error.Success()) { + result.SetError(repl_error); + return result.Succeeded(); } + } - if (repl_sp) { - if (initialize) { - repl_sp->SetEvaluateOptions( - GetExprOptions(exe_ctx, m_command_options)); - repl_sp->SetFormatOptions(m_format_options); - repl_sp->SetValueObjectDisplayOptions(m_varobj_options); - } + if (repl_sp) { + if (initialize) { + repl_sp->SetEvaluateOptions( + GetExprOptions(exe_ctx, m_command_options)); + repl_sp->SetFormatOptions(m_format_options); + repl_sp->SetValueObjectDisplayOptions(m_varobj_options); + } - IOHandlerSP io_handler_sp(repl_sp->GetIOHandler()); + IOHandlerSP io_handler_sp(repl_sp->GetIOHandler()); - io_handler_sp->SetIsDone(false); + io_handler_sp->SetIsDone(false); - debugger.PushIOHandler(io_handler_sp); - } else { - repl_error.SetErrorStringWithFormat( - "Couldn't create a REPL for %s", - Language::GetNameForLanguageType(m_command_options.language)); - result.SetError(repl_error); - return result.Succeeded(); - } + debugger.PushIOHandler(io_handler_sp); + } else { + repl_error.SetErrorStringWithFormat( + "Couldn't create a REPL for %s", + Language::GetNameForLanguageType(m_command_options.language)); + result.SetError(repl_error); + return result.Succeeded(); } } } diff --git a/lldb/source/Commands/CommandObjectExpression.h b/lldb/source/Commands/CommandObjectExpression.h index 8ef764239069..de159863b43a 100644 --- a/lldb/source/Commands/CommandObjectExpression.h +++ b/lldb/source/Commands/CommandObjectExpression.h @@ -14,7 +14,6 @@ #include "lldb/Interpreter/OptionGroupBoolean.h" #include "lldb/Interpreter/OptionGroupFormat.h" #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" -#include "lldb/Target/ExecutionContext.h" #include "lldb/lldb-private-enumerations.h" namespace lldb_private { diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp index 6a7facdaff35..50d5c751de5c 100644 --- a/lldb/source/Commands/CommandObjectFrame.cpp +++ b/lldb/source/Commands/CommandObjectFrame.cpp @@ -7,14 +7,10 @@ //===----------------------------------------------------------------------===// #include "CommandObjectFrame.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Module.h" -#include "lldb/Core/StreamFile.h" -#include "lldb/Core/Value.h" #include "lldb/Core/ValueObject.h" -#include "lldb/Core/ValueObjectVariable.h" #include "lldb/DataFormatters/DataVisualization.h" #include "lldb/DataFormatters/ValueObjectPrinter.h" -#include "lldb/Host/Host.h" +#include "lldb/Host/Config.h" #include "lldb/Host/OptionParser.h" #include "lldb/Host/StringConvert.h" #include "lldb/Interpreter/CommandInterpreter.h" @@ -23,23 +19,16 @@ #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" #include "lldb/Interpreter/OptionGroupVariable.h" #include "lldb/Interpreter/Options.h" -#include "lldb/Symbol/CompilerType.h" #include "lldb/Symbol/Function.h" -#include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/SymbolContext.h" -#include "lldb/Symbol/Type.h" #include "lldb/Symbol/Variable.h" #include "lldb/Symbol/VariableList.h" -#include "lldb/Target/Process.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/StackFrameRecognizer.h" #include "lldb/Target/StopInfo.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/Utility/Args.h" -#include "lldb/Utility/LLDBAssert.h" -#include "lldb/Utility/StreamString.h" -#include "lldb/Utility/Timer.h" #include <memory> #include <string> @@ -177,10 +166,10 @@ protected: return false; } - - DumpValueObjectOptions::DeclPrintingHelper helper = [&valobj_sp]( - ConstString type, ConstString var, const DumpValueObjectOptions &opts, - Stream &stream) -> bool { + DumpValueObjectOptions::DeclPrintingHelper helper = + [&valobj_sp](ConstString type, ConstString var, + const DumpValueObjectOptions &opts, + Stream &stream) -> bool { const ValueObject::GetExpressionPathFormat format = ValueObject:: GetExpressionPathFormat::eGetExpressionPathFormatHonorPointers; const bool qualify_cxx_base_classes = false; @@ -209,12 +198,13 @@ protected: class CommandObjectFrameInfo : public CommandObjectParsed { public: CommandObjectFrameInfo(CommandInterpreter &interpreter) - : CommandObjectParsed( - interpreter, "frame info", "List information about the current " - "stack frame in the current thread.", - "frame info", - eCommandRequiresFrame | eCommandTryTargetAPILock | - eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {} + : CommandObjectParsed(interpreter, "frame info", + "List information about the current " + "stack frame in the current thread.", + "frame info", + eCommandRequiresFrame | eCommandTryTargetAPILock | + eCommandProcessMustBeLaunched | + eCommandProcessMustBePaused) {} ~CommandObjectFrameInfo() override = default; @@ -275,13 +265,14 @@ public: }; CommandObjectFrameSelect(CommandInterpreter &interpreter) - : CommandObjectParsed( - interpreter, "frame select", "Select the current stack frame by " - "index from within the current thread " - "(see 'thread backtrace'.)", - nullptr, - eCommandRequiresThread | eCommandTryTargetAPILock | - eCommandProcessMustBeLaunched | eCommandProcessMustBePaused), + : CommandObjectParsed(interpreter, "frame select", + "Select the current stack frame by " + "index from within the current thread " + "(see 'thread backtrace'.)", + nullptr, + eCommandRequiresThread | eCommandTryTargetAPILock | + eCommandProcessMustBeLaunched | + eCommandProcessMustBePaused), m_options() { CommandArgumentEntry arg; CommandArgumentData index_arg; @@ -415,14 +406,14 @@ public: "uses debug information and memory reads directly, rather than " "parsing and evaluating an expression, which may even involve " "JITing and running code in the target program.", - nullptr, eCommandRequiresFrame | eCommandTryTargetAPILock | - eCommandProcessMustBeLaunched | - eCommandProcessMustBePaused | eCommandRequiresProcess), + nullptr, + eCommandRequiresFrame | eCommandTryTargetAPILock | + eCommandProcessMustBeLaunched | eCommandProcessMustBePaused | + eCommandRequiresProcess), m_option_group(), m_option_variable( true), // Include the frame specific options by passing "true" - m_option_format(eFormatDefault), - m_varobj_options() { + m_option_format(eFormatDefault), m_varobj_options() { CommandArgumentEntry arg; CommandArgumentData var_name_arg; @@ -849,7 +840,7 @@ Process 1234 stopped bool CommandObjectFrameRecognizerAdd::DoExecute(Args &command, CommandReturnObject &result) { -#ifndef LLDB_DISABLE_PYTHON +#if LLDB_ENABLE_PYTHON if (m_options.m_class_name.empty()) { result.AppendErrorWithFormat( "%s needs a Python class name (-l argument).\n", m_cmd_name.c_str()); @@ -875,9 +866,8 @@ bool CommandObjectFrameRecognizerAdd::DoExecute(Args &command, if (interpreter && !interpreter->CheckObjectExists(m_options.m_class_name.c_str())) { - result.AppendWarning( - "The provided class does not exist - please define it " - "before attempting to use this frame recognizer"); + result.AppendWarning("The provided class does not exist - please define it " + "before attempting to use this frame recognizer"); } StackFrameRecognizerSP recognizer_sp = @@ -904,7 +894,7 @@ class CommandObjectFrameRecognizerClear : public CommandObjectParsed { public: CommandObjectFrameRecognizerClear(CommandInterpreter &interpreter) : CommandObjectParsed(interpreter, "frame recognizer clear", - "Delete all frame recognizers.", nullptr) {} + "Delete all frame recognizers.", nullptr) {} ~CommandObjectFrameRecognizerClear() override = default; @@ -917,14 +907,14 @@ protected: }; class CommandObjectFrameRecognizerDelete : public CommandObjectParsed { - public: +public: CommandObjectFrameRecognizerDelete(CommandInterpreter &interpreter) : CommandObjectParsed(interpreter, "frame recognizer delete", "Delete an existing frame recognizer.", nullptr) {} ~CommandObjectFrameRecognizerDelete() override = default; - protected: +protected: bool DoExecute(Args &command, CommandReturnObject &result) override { if (command.GetArgumentCount() == 0) { if (!m_interpreter.Confirm( @@ -957,7 +947,7 @@ class CommandObjectFrameRecognizerDelete : public CommandObjectParsed { }; class CommandObjectFrameRecognizerList : public CommandObjectParsed { - public: +public: CommandObjectFrameRecognizerList(CommandInterpreter &interpreter) : CommandObjectParsed(interpreter, "frame recognizer list", "Show a list of active frame recognizers.", @@ -965,14 +955,15 @@ class CommandObjectFrameRecognizerList : public CommandObjectParsed { ~CommandObjectFrameRecognizerList() override = default; - protected: +protected: bool DoExecute(Args &command, CommandReturnObject &result) override { bool any_printed = false; StackFrameRecognizerManager::ForEach( [&result, &any_printed](uint32_t recognizer_id, std::string name, std::string function, std::string symbol, bool regexp) { - if (name == "") name = "(internal)"; + if (name == "") + name = "(internal)"; result.GetOutputStream().Printf( "%d: %s, module %s, function %s%s\n", recognizer_id, name.c_str(), function.c_str(), symbol.c_str(), regexp ? " (regexp)" : ""); @@ -990,7 +981,7 @@ class CommandObjectFrameRecognizerList : public CommandObjectParsed { }; class CommandObjectFrameRecognizerInfo : public CommandObjectParsed { - public: +public: CommandObjectFrameRecognizerInfo(CommandInterpreter &interpreter) : CommandObjectParsed( interpreter, "frame recognizer info", @@ -1013,7 +1004,7 @@ class CommandObjectFrameRecognizerInfo : public CommandObjectParsed { ~CommandObjectFrameRecognizerInfo() override = default; - protected: +protected: bool DoExecute(Args &command, CommandReturnObject &result) override { Process *process = m_exe_ctx.GetProcessPtr(); if (process == nullptr) { @@ -1061,27 +1052,24 @@ class CommandObjectFrameRecognizerInfo : public CommandObjectParsed { }; class CommandObjectFrameRecognizer : public CommandObjectMultiword { - public: +public: CommandObjectFrameRecognizer(CommandInterpreter &interpreter) : CommandObjectMultiword( interpreter, "frame recognizer", "Commands for editing and viewing frame recognizers.", "frame recognizer [<sub-command-options>] ") { - LoadSubCommand( - "add", - CommandObjectSP(new CommandObjectFrameRecognizerAdd(interpreter))); + LoadSubCommand("add", CommandObjectSP(new CommandObjectFrameRecognizerAdd( + interpreter))); LoadSubCommand( "clear", CommandObjectSP(new CommandObjectFrameRecognizerClear(interpreter))); LoadSubCommand( "delete", CommandObjectSP(new CommandObjectFrameRecognizerDelete(interpreter))); - LoadSubCommand( - "list", - CommandObjectSP(new CommandObjectFrameRecognizerList(interpreter))); - LoadSubCommand( - "info", - CommandObjectSP(new CommandObjectFrameRecognizerInfo(interpreter))); + LoadSubCommand("list", CommandObjectSP(new CommandObjectFrameRecognizerList( + interpreter))); + LoadSubCommand("info", CommandObjectSP(new CommandObjectFrameRecognizerInfo( + interpreter))); } ~CommandObjectFrameRecognizer() override = default; @@ -1093,9 +1081,10 @@ class CommandObjectFrameRecognizer : public CommandObjectMultiword { CommandObjectMultiwordFrame::CommandObjectMultiwordFrame( CommandInterpreter &interpreter) - : CommandObjectMultiword(interpreter, "frame", "Commands for selecting and " - "examing the current " - "thread's stack frames.", + : CommandObjectMultiword(interpreter, "frame", + "Commands for selecting and " + "examing the current " + "thread's stack frames.", "frame <subcommand> [<subcommand-options>]") { LoadSubCommand("diagnose", CommandObjectSP(new CommandObjectFrameDiagnose(interpreter))); @@ -1105,10 +1094,9 @@ CommandObjectMultiwordFrame::CommandObjectMultiwordFrame( CommandObjectSP(new CommandObjectFrameSelect(interpreter))); LoadSubCommand("variable", CommandObjectSP(new CommandObjectFrameVariable(interpreter))); -#ifndef LLDB_DISABLE_PYTHON - LoadSubCommand( - "recognizer", - CommandObjectSP(new CommandObjectFrameRecognizer(interpreter))); +#if LLDB_ENABLE_PYTHON + LoadSubCommand("recognizer", CommandObjectSP(new CommandObjectFrameRecognizer( + interpreter))); #endif } diff --git a/lldb/source/Commands/CommandObjectFrame.h b/lldb/source/Commands/CommandObjectFrame.h index 46a59f71733b..b2378f14290d 100644 --- a/lldb/source/Commands/CommandObjectFrame.h +++ b/lldb/source/Commands/CommandObjectFrame.h @@ -10,7 +10,6 @@ #define liblldb_CommandObjectFrame_h_ #include "lldb/Interpreter/CommandObjectMultiword.h" -#include "lldb/Interpreter/Options.h" namespace lldb_private { diff --git a/lldb/source/Commands/CommandObjectGUI.cpp b/lldb/source/Commands/CommandObjectGUI.cpp index fac2e9627783..67ddc68a169e 100644 --- a/lldb/source/Commands/CommandObjectGUI.cpp +++ b/lldb/source/Commands/CommandObjectGUI.cpp @@ -8,9 +8,10 @@ #include "CommandObjectGUI.h" +#include "lldb/Core/IOHandlerCursesGUI.h" +#include "lldb/Host/Config.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" -#include "lldb/lldb-private.h" using namespace lldb; using namespace lldb_private; @@ -24,7 +25,7 @@ CommandObjectGUI::CommandObjectGUI(CommandInterpreter &interpreter) CommandObjectGUI::~CommandObjectGUI() {} bool CommandObjectGUI::DoExecute(Args &args, CommandReturnObject &result) { -#ifndef LLDB_DISABLE_CURSES +#if LLDB_ENABLE_CURSES if (args.GetArgumentCount() == 0) { Debugger &debugger = GetDebugger(); diff --git a/lldb/source/Commands/CommandObjectHelp.cpp b/lldb/source/Commands/CommandObjectHelp.cpp index c02a583bf9df..6e908dc496a0 100644 --- a/lldb/source/Commands/CommandObjectHelp.cpp +++ b/lldb/source/Commands/CommandObjectHelp.cpp @@ -8,9 +8,7 @@ #include "CommandObjectHelp.h" #include "lldb/Interpreter/CommandInterpreter.h" -#include "lldb/Interpreter/CommandObjectMultiword.h" #include "lldb/Interpreter/CommandReturnObject.h" -#include "lldb/Interpreter/Options.h" using namespace lldb; using namespace lldb_private; @@ -27,25 +25,27 @@ void CommandObjectHelp::GenerateAdditionalHelpAvenuesMessage( std::string command_str = command.str(); std::string prefix_str = prefix.str(); std::string subcommand_str = subcommand.str(); - const std::string &lookup_str = !subcommand_str.empty() ? subcommand_str : command_str; + const std::string &lookup_str = + !subcommand_str.empty() ? subcommand_str : command_str; s->Printf("'%s' is not a known command.\n", command_str.c_str()); s->Printf("Try '%shelp' to see a current list of commands.\n", prefix.str().c_str()); if (include_upropos) { s->Printf("Try '%sapropos %s' for a list of related commands.\n", - prefix_str.c_str(), lookup_str.c_str()); + prefix_str.c_str(), lookup_str.c_str()); } if (include_type_lookup) { s->Printf("Try '%stype lookup %s' for information on types, methods, " "functions, modules, etc.", - prefix_str.c_str(), lookup_str.c_str()); + prefix_str.c_str(), lookup_str.c_str()); } } CommandObjectHelp::CommandObjectHelp(CommandInterpreter &interpreter) - : CommandObjectParsed(interpreter, "help", "Show a list of all debugger " - "commands, or give details " - "about a specific command.", + : CommandObjectParsed(interpreter, "help", + "Show a list of all debugger " + "commands, or give details " + "about a specific command.", "help [<cmd-name>]"), m_options() { CommandArgumentEntry arg; diff --git a/lldb/source/Commands/CommandObjectLanguage.cpp b/lldb/source/Commands/CommandObjectLanguage.cpp index 47c9e2a52023..35ce6e3193e8 100644 --- a/lldb/source/Commands/CommandObjectLanguage.cpp +++ b/lldb/source/Commands/CommandObjectLanguage.cpp @@ -8,12 +8,8 @@ #include "CommandObjectLanguage.h" -#include "lldb/Host/Host.h" -#include "lldb/Interpreter/CommandInterpreter.h" -#include "lldb/Interpreter/CommandReturnObject.h" -#include "lldb/Target/Language.h" #include "lldb/Target/LanguageRuntime.h" using namespace lldb; diff --git a/lldb/source/Commands/CommandObjectLanguage.h b/lldb/source/Commands/CommandObjectLanguage.h index b86457c99af3..47079e219d03 100644 --- a/lldb/source/Commands/CommandObjectLanguage.h +++ b/lldb/source/Commands/CommandObjectLanguage.h @@ -9,10 +9,7 @@ #ifndef liblldb_CommandObjectLanguage_h_ #define liblldb_CommandObjectLanguage_h_ - - #include "lldb/Interpreter/CommandObjectMultiword.h" -#include "lldb/lldb-types.h" namespace lldb_private { class CommandObjectLanguage : public CommandObjectMultiword { diff --git a/lldb/source/Commands/CommandObjectLog.cpp b/lldb/source/Commands/CommandObjectLog.cpp index 31a876c3430e..9bf0b30bc152 100644 --- a/lldb/source/Commands/CommandObjectLog.cpp +++ b/lldb/source/Commands/CommandObjectLog.cpp @@ -8,23 +8,13 @@ #include "CommandObjectLog.h" #include "lldb/Core/Debugger.h" -#include "lldb/Core/Module.h" -#include "lldb/Core/StreamFile.h" #include "lldb/Host/OptionParser.h" -#include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/OptionArgParser.h" #include "lldb/Interpreter/Options.h" -#include "lldb/Symbol/LineTable.h" -#include "lldb/Symbol/ObjectFile.h" -#include "lldb/Symbol/SymbolFile.h" -#include "lldb/Symbol/SymbolVendor.h" -#include "lldb/Target/Process.h" -#include "lldb/Target/Target.h" #include "lldb/Utility/Args.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/Log.h" -#include "lldb/Utility/RegularExpression.h" #include "lldb/Utility/Stream.h" #include "lldb/Utility/Timer.h" diff --git a/lldb/source/Commands/CommandObjectLog.h b/lldb/source/Commands/CommandObjectLog.h index b2da900e21ed..eae41bf6b8d1 100644 --- a/lldb/source/Commands/CommandObjectLog.h +++ b/lldb/source/Commands/CommandObjectLog.h @@ -9,8 +9,6 @@ #ifndef liblldb_CommandObjectLog_h_ #define liblldb_CommandObjectLog_h_ -#include <map> -#include <string> #include "lldb/Interpreter/CommandObjectMultiword.h" diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 38bd3d179096..e497b5246b8d 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -7,15 +7,11 @@ //===----------------------------------------------------------------------===// #include "CommandObjectMemory.h" -#include "lldb/Core/Debugger.h" #include "lldb/Core/DumpDataExtractor.h" -#include "lldb/Core/Module.h" #include "lldb/Core/Section.h" #include "lldb/Core/ValueObjectMemory.h" -#include "lldb/DataFormatters/ValueObjectPrinter.h" #include "lldb/Expression/ExpressionVariable.h" #include "lldb/Host/OptionParser.h" -#include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/OptionArgParser.h" #include "lldb/Interpreter/OptionGroupFormat.h" @@ -38,7 +34,6 @@ #include "lldb/Utility/DataBufferLLVM.h" #include "lldb/Utility/StreamString.h" -#include "lldb/lldb-private.h" #include <cinttypes> #include <memory> @@ -1440,8 +1435,7 @@ protected: case eFormatBytes: case eFormatHex: case eFormatHexUppercase: - case eFormatPointer: - { + case eFormatPointer: { // Decode hex bytes // Be careful, getAsInteger with a radix of 16 rejects "0xab" so we // have to special case that: @@ -1597,13 +1591,14 @@ protected: class CommandObjectMemoryHistory : public CommandObjectParsed { public: CommandObjectMemoryHistory(CommandInterpreter &interpreter) - : CommandObjectParsed( - interpreter, "memory history", "Print recorded stack traces for " - "allocation/deallocation events " - "associated with an address.", - nullptr, - eCommandRequiresTarget | eCommandRequiresProcess | - eCommandProcessMustBePaused | eCommandProcessMustBeLaunched) { + : CommandObjectParsed(interpreter, "memory history", + "Print recorded stack traces for " + "allocation/deallocation events " + "associated with an address.", + nullptr, + eCommandRequiresTarget | eCommandRequiresProcess | + eCommandProcessMustBePaused | + eCommandProcessMustBeLaunched) { CommandArgumentEntry arg1; CommandArgumentData addr_arg; @@ -1730,15 +1725,12 @@ protected: section_name = section_sp->GetName(); } } - result.AppendMessageWithFormat( - "[0x%16.16" PRIx64 "-0x%16.16" PRIx64 ") %c%c%c%s%s%s%s\n", + result.AppendMessageWithFormatv( + "[{0:x16}-{1:x16}) {2:r}{3:w}{4:x}{5}{6}{7}{8}\n", range_info.GetRange().GetRangeBase(), - range_info.GetRange().GetRangeEnd(), - range_info.GetReadable() ? 'r' : '-', - range_info.GetWritable() ? 'w' : '-', - range_info.GetExecutable() ? 'x' : '-', - name ? " " : "", name.AsCString(""), - section_name ? " " : "", section_name.AsCString("")); + range_info.GetRange().GetRangeEnd(), range_info.GetReadable(), + range_info.GetWritable(), range_info.GetExecutable(), + name ? " " : "", name, section_name ? " " : "", section_name); m_prev_end_addr = range_info.GetRange().GetRangeEnd(); result.SetStatus(eReturnStatusSuccessFinishResult); } else { diff --git a/lldb/source/Commands/CommandObjectMultiword.cpp b/lldb/source/Commands/CommandObjectMultiword.cpp index 03a3770d8df7..67225d3d6b8d 100644 --- a/lldb/source/Commands/CommandObjectMultiword.cpp +++ b/lldb/source/Commands/CommandObjectMultiword.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "lldb/Interpreter/CommandObjectMultiword.h" -#include "lldb/Core/Debugger.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/Options.h" diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp index fbd13aa37bda..10e6a4aa1793 100644 --- a/lldb/source/Commands/CommandObjectPlatform.cpp +++ b/lldb/source/Commands/CommandObjectPlatform.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include <mutex> #include "CommandObjectPlatform.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/Module.h" @@ -22,10 +21,8 @@ #include "lldb/Target/Platform.h" #include "lldb/Target/Process.h" #include "lldb/Utility/Args.h" -#include "lldb/Utility/DataExtractor.h" #include "llvm/ADT/SmallString.h" -#include "llvm/Support/Threading.h" using namespace lldb; using namespace lldb_private; @@ -1152,8 +1149,7 @@ protected: class CommandOptions : public Options { public: CommandOptions() - : Options(), match_info(), show_args(false), verbose(false) { - } + : Options(), match_info(), show_args(false), verbose(false) {} ~CommandOptions() override = default; @@ -1607,7 +1603,6 @@ public: ExecutionContext exe_ctx = GetCommandInterpreter().GetExecutionContext(); m_options.NotifyOptionParsingStarting(&exe_ctx); - // Print out an usage syntax on an empty command line. if (raw_command_line.empty()) { result.GetOutputStream().Printf("%s\n", this->GetSyntax().str().c_str()); diff --git a/lldb/source/Commands/CommandObjectPlatform.h b/lldb/source/Commands/CommandObjectPlatform.h index c94d2ea2cc4d..45e4a41c5b20 100644 --- a/lldb/source/Commands/CommandObjectPlatform.h +++ b/lldb/source/Commands/CommandObjectPlatform.h @@ -10,7 +10,6 @@ #define liblldb_CommandObjectPlatform_h_ #include "lldb/Interpreter/CommandObjectMultiword.h" -#include "lldb/Interpreter/Options.h" namespace lldb_private { diff --git a/lldb/source/Commands/CommandObjectPlugin.cpp b/lldb/source/Commands/CommandObjectPlugin.cpp index b70885061385..6fcb64f207b2 100644 --- a/lldb/source/Commands/CommandObjectPlugin.cpp +++ b/lldb/source/Commands/CommandObjectPlugin.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "CommandObjectPlugin.h" -#include "lldb/Host/Host.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" diff --git a/lldb/source/Commands/CommandObjectPlugin.h b/lldb/source/Commands/CommandObjectPlugin.h index 0aabb1399407..94cea7db4111 100644 --- a/lldb/source/Commands/CommandObjectPlugin.h +++ b/lldb/source/Commands/CommandObjectPlugin.h @@ -9,10 +9,7 @@ #ifndef liblldb_CommandObjectPlugin_h_ #define liblldb_CommandObjectPlugin_h_ - - #include "lldb/Interpreter/CommandObjectMultiword.h" -#include "lldb/lldb-types.h" namespace lldb_private { diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index e5aa78afabb3..d825647728f8 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -12,7 +12,6 @@ #include "lldb/Breakpoint/BreakpointSite.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Host/Host.h" #include "lldb/Host/OptionParser.h" #include "lldb/Host/StringConvert.h" #include "lldb/Interpreter/CommandInterpreter.h" @@ -1014,10 +1013,10 @@ protected: class CommandObjectProcessSignal : public CommandObjectParsed { public: CommandObjectProcessSignal(CommandInterpreter &interpreter) - : CommandObjectParsed(interpreter, "process signal", - "Send a UNIX signal to the current target process.", - nullptr, eCommandRequiresProcess | - eCommandTryTargetAPILock) { + : CommandObjectParsed( + interpreter, "process signal", + "Send a UNIX signal to the current target process.", nullptr, + eCommandRequiresProcess | eCommandTryTargetAPILock) { CommandArgumentEntry arg; CommandArgumentData signal_arg; @@ -1224,7 +1223,7 @@ public: const uint32_t start_frame = 0; const uint32_t num_frames = 1; const uint32_t num_frames_with_source = 1; - const bool stop_format = true; + const bool stop_format = true; process->GetStatus(strm); process->GetThreadStatus(strm, only_threads_with_stop_reason, start_frame, num_frames, num_frames_with_source, stop_format); diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 13266f8fce35..523b32a996b2 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -10,7 +10,6 @@ #include "lldb/Core/Debugger.h" #include "lldb/Core/DumpRegisterValue.h" #include "lldb/Host/OptionParser.h" -#include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/OptionGroupFormat.h" #include "lldb/Interpreter/OptionValueArray.h" @@ -25,7 +24,6 @@ #include "lldb/Utility/Args.h" #include "lldb/Utility/DataExtractor.h" #include "lldb/Utility/RegisterValue.h" -#include "lldb/Utility/Scalar.h" #include "llvm/Support/Errno.h" using namespace lldb; diff --git a/lldb/source/Commands/CommandObjectReproducer.cpp b/lldb/source/Commands/CommandObjectReproducer.cpp index dc4579c20fc2..d15f622314d9 100644 --- a/lldb/source/Commands/CommandObjectReproducer.cpp +++ b/lldb/source/Commands/CommandObjectReproducer.cpp @@ -15,7 +15,8 @@ #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/OptionArgParser.h" -#include "lldb/Interpreter/OptionGroupBoolean.h" + +#include <csignal> using namespace lldb; using namespace llvm; @@ -68,7 +69,32 @@ static constexpr OptionEnumValues ReproducerProviderType() { return OptionEnumValues(g_reproducer_provider_type); } -#define LLDB_OPTIONS_reproducer +#define LLDB_OPTIONS_reproducer_dump +#include "CommandOptions.inc" + +enum ReproducerCrashSignal { + eReproducerCrashSigill, + eReproducerCrashSigsegv, +}; + +static constexpr OptionEnumValueElement g_reproducer_signaltype[] = { + { + eReproducerCrashSigill, + "SIGILL", + "Illegal instruction", + }, + { + eReproducerCrashSigsegv, + "SIGSEGV", + "Segmentation fault", + }, +}; + +static constexpr OptionEnumValues ReproducerSignalType() { + return OptionEnumValues(g_reproducer_signaltype); +} + +#define LLDB_OPTIONS_reproducer_xcrash #include "CommandOptions.inc" class CommandObjectReproducerGenerate : public CommandObjectParsed { @@ -78,7 +104,7 @@ public: interpreter, "reproducer generate", "Generate reproducer on disk. When the debugger is in capture " "mode, this command will output the reproducer to a directory on " - "disk. In replay mode this command in a no-op.", + "disk and quit. In replay mode this command in a no-op.", nullptr) {} ~CommandObjectReproducerGenerate() override = default; @@ -95,7 +121,7 @@ protected: if (auto generator = r.GetGenerator()) { generator->Keep(); } else if (r.IsReplaying()) { - // Make this operation a NOP in replay mode. + // Make this operation a NO-OP in replay mode. result.SetStatus(eReturnStatusSuccessFinishNoResult); return result.Succeeded(); } else { @@ -110,9 +136,94 @@ protected: << "Please have a look at the directory to assess if you're willing to " "share the contained information.\n"; - result.SetStatus(eReturnStatusSuccessFinishResult); + m_interpreter.BroadcastEvent( + CommandInterpreter::eBroadcastBitQuitCommandReceived); + result.SetStatus(eReturnStatusQuit); + return result.Succeeded(); + } +}; + +class CommandObjectReproducerXCrash : public CommandObjectParsed { +public: + CommandObjectReproducerXCrash(CommandInterpreter &interpreter) + : CommandObjectParsed(interpreter, "reproducer xcrash", + "Intentionally force the debugger to crash in " + "order to trigger and test reproducer generation.", + nullptr) {} + + ~CommandObjectReproducerXCrash() override = default; + + Options *GetOptions() override { return &m_options; } + + class CommandOptions : public Options { + public: + CommandOptions() : Options() {} + + ~CommandOptions() override = default; + + Status SetOptionValue(uint32_t option_idx, StringRef option_arg, + ExecutionContext *execution_context) override { + Status error; + const int short_option = m_getopt_table[option_idx].val; + + switch (short_option) { + case 's': + signal = (ReproducerCrashSignal)OptionArgParser::ToOptionEnum( + option_arg, GetDefinitions()[option_idx].enum_values, 0, error); + if (!error.Success()) + error.SetErrorStringWithFormat("unrecognized value for signal '%s'", + option_arg.str().c_str()); + break; + default: + llvm_unreachable("Unimplemented option"); + } + + return error; + } + + void OptionParsingStarting(ExecutionContext *execution_context) override { + signal = eReproducerCrashSigsegv; + } + + ArrayRef<OptionDefinition> GetDefinitions() override { + return makeArrayRef(g_reproducer_xcrash_options); + } + + ReproducerCrashSignal signal = eReproducerCrashSigsegv; + }; + +protected: + bool DoExecute(Args &command, CommandReturnObject &result) override { + if (!command.empty()) { + result.AppendErrorWithFormat("'%s' takes no arguments", + m_cmd_name.c_str()); + return false; + } + + auto &r = Reproducer::Instance(); + + if (!r.IsCapturing() && !r.IsReplaying()) { + result.SetError( + "forcing a crash is only supported when capturing a reproducer."); + result.SetStatus(eReturnStatusSuccessFinishNoResult); + return false; + } + + switch (m_options.signal) { + case eReproducerCrashSigill: + std::raise(SIGILL); + break; + case eReproducerCrashSigsegv: + std::raise(SIGSEGV); + break; + } + + result.SetStatus(eReturnStatusQuit); return result.Succeeded(); } + +private: + CommandOptions m_options; }; class CommandObjectReproducerStatus : public CommandObjectParsed { @@ -120,7 +231,8 @@ public: CommandObjectReproducerStatus(CommandInterpreter &interpreter) : CommandObjectParsed( interpreter, "reproducer status", - "Show the current reproducer status. In capture mode the debugger " + "Show the current reproducer status. In capture mode the " + "debugger " "is collecting all the information it needs to create a " "reproducer. In replay mode the reproducer is replaying a " "reproducer. When the reproducers are off, no data is collected " @@ -206,7 +318,7 @@ public: } ArrayRef<OptionDefinition> GetDefinitions() override { - return makeArrayRef(g_reproducer_options); + return makeArrayRef(g_reproducer_dump_options); } FileSpec file; @@ -294,10 +406,9 @@ protected: return true; } case eReproducerProviderCommands: { - // Create a new command loader. - std::unique_ptr<repro::CommandLoader> command_loader = - repro::CommandLoader::Create(loader); - if (!command_loader) { + std::unique_ptr<repro::MultiLoader<repro::CommandProvider>> multi_loader = + repro::MultiLoader<repro::CommandProvider>::Create(loader); + if (!multi_loader) { SetError(result, make_error<StringError>(llvm::inconvertibleErrorCode(), "Unable to create command loader.")); @@ -305,9 +416,8 @@ protected: } // Iterate over the command files and dump them. - while (true) { - llvm::Optional<std::string> command_file = - command_loader->GetNextFile(); + llvm::Optional<std::string> command_file; + while ((command_file = multi_loader->GetNextFile())) { if (!command_file) break; @@ -323,24 +433,29 @@ protected: return true; } case eReproducerProviderGDB: { - FileSpec gdb_file = loader->GetFile<ProcessGDBRemoteProvider::Info>(); - auto error_or_file = MemoryBuffer::getFile(gdb_file.GetPath()); - if (auto err = error_or_file.getError()) { - SetError(result, errorCodeToError(err)); - return false; - } + std::unique_ptr<repro::MultiLoader<repro::GDBRemoteProvider>> + multi_loader = + repro::MultiLoader<repro::GDBRemoteProvider>::Create(loader); + llvm::Optional<std::string> gdb_file; + while ((gdb_file = multi_loader->GetNextFile())) { + auto error_or_file = MemoryBuffer::getFile(*gdb_file); + if (auto err = error_or_file.getError()) { + SetError(result, errorCodeToError(err)); + return false; + } - std::vector<GDBRemotePacket> packets; - yaml::Input yin((*error_or_file)->getBuffer()); - yin >> packets; + std::vector<GDBRemotePacket> packets; + yaml::Input yin((*error_or_file)->getBuffer()); + yin >> packets; - if (auto err = yin.error()) { - SetError(result, errorCodeToError(err)); - return false; - } + if (auto err = yin.error()) { + SetError(result, errorCodeToError(err)); + return false; + } - for (GDBRemotePacket &packet : packets) { - packet.Dump(result.GetOutputStream()); + for (GDBRemotePacket &packet : packets) { + packet.Dump(result.GetOutputStream()); + } } result.SetStatus(eReturnStatusSuccessFinishResult); @@ -363,7 +478,8 @@ CommandObjectReproducer::CommandObjectReproducer( CommandInterpreter &interpreter) : CommandObjectMultiword( interpreter, "reproducer", - "Commands for manipulating reproducers. Reproducers make it possible " + "Commands for manipulating reproducers. Reproducers make it " + "possible " "to capture full debug sessions with all its dependencies. The " "resulting reproducer is used to replay the debug session while " "debugging the debugger.\n" @@ -380,6 +496,8 @@ CommandObjectReproducer::CommandObjectReproducer( new CommandObjectReproducerStatus(interpreter))); LoadSubCommand("dump", CommandObjectSP(new CommandObjectReproducerDump(interpreter))); + LoadSubCommand("xcrash", CommandObjectSP( + new CommandObjectReproducerXCrash(interpreter))); } CommandObjectReproducer::~CommandObjectReproducer() = default; diff --git a/lldb/source/Commands/CommandObjectReproducer.h b/lldb/source/Commands/CommandObjectReproducer.h index ad377241f814..8a85c21d6510 100644 --- a/lldb/source/Commands/CommandObjectReproducer.h +++ b/lldb/source/Commands/CommandObjectReproducer.h @@ -10,7 +10,6 @@ #define liblldb_CommandObjectReproducer_h_ #include "lldb/Interpreter/CommandObjectMultiword.h" -#include "lldb/Interpreter/Options.h" namespace lldb_private { diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp index 248a04613d7a..95f79f45e22b 100644 --- a/lldb/source/Commands/CommandObjectSettings.cpp +++ b/lldb/source/Commands/CommandObjectSettings.cpp @@ -143,25 +143,24 @@ insert-before or insert-after."); request, nullptr); return; } - arg = - request.GetParsedLine().GetArgumentAtIndex(request.GetCursorIndex()); + arg = request.GetParsedLine().GetArgumentAtIndex(request.GetCursorIndex()); - if (!arg) - return; + if (!arg) + return; - // Complete option name - if (arg[0] != '-') - return; + // Complete option name + if (arg[0] != '-') + return; - // Complete setting value - const char *setting_var_name = - request.GetParsedLine().GetArgumentAtIndex(setting_var_idx); - Status error; - lldb::OptionValueSP value_sp(GetDebugger().GetPropertyValue( - &m_exe_ctx, setting_var_name, false, error)); - if (!value_sp) - return; - value_sp->AutoComplete(m_interpreter, request); + // Complete setting value + const char *setting_var_name = + request.GetParsedLine().GetArgumentAtIndex(setting_var_idx); + Status error; + lldb::OptionValueSP value_sp(GetDebugger().GetPropertyValue( + &m_exe_ctx, setting_var_name, false, error)); + if (!value_sp) + return; + value_sp->AutoComplete(m_interpreter, request); } protected: diff --git a/lldb/source/Commands/CommandObjectSettings.h b/lldb/source/Commands/CommandObjectSettings.h index 730425953ea7..4db0ca1f83f8 100644 --- a/lldb/source/Commands/CommandObjectSettings.h +++ b/lldb/source/Commands/CommandObjectSettings.h @@ -9,9 +9,7 @@ #ifndef liblldb_CommandObjectSettings_h_ #define liblldb_CommandObjectSettings_h_ -#include "lldb/Interpreter/CommandObject.h" #include "lldb/Interpreter/CommandObjectMultiword.h" -#include "lldb/Interpreter/Options.h" namespace lldb_private { diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp index 78c8bc811926..19a554fb290a 100644 --- a/lldb/source/Commands/CommandObjectSource.cpp +++ b/lldb/source/Commands/CommandObjectSource.cpp @@ -14,18 +14,14 @@ #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/SourceManager.h" #include "lldb/Host/OptionParser.h" -#include "lldb/Interpreter/CommandCompletions.h" -#include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/OptionArgParser.h" #include "lldb/Interpreter/Options.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/Function.h" #include "lldb/Symbol/Symbol.h" -#include "lldb/Target/Process.h" #include "lldb/Target/SectionLoadList.h" #include "lldb/Target/StackFrame.h" -#include "lldb/Target/TargetList.h" #include "lldb/Utility/FileSpec.h" using namespace lldb; @@ -111,7 +107,7 @@ class CommandObjectSourceInfo : public CommandObjectParsed { uint32_t start_line; uint32_t end_line; uint32_t num_lines; - STLStringArray modules; + std::vector<std::string> modules; }; public: @@ -146,12 +142,6 @@ protected: Target *target = m_exe_ctx.GetTargetPtr(); uint32_t num_matches = 0; - bool has_path = false; - if (file_spec) { - assert(file_spec.GetFilename().AsCString()); - has_path = (file_spec.GetDirectory().AsCString() != nullptr); - } - // Dump all the line entries for the file in the list. ConstString last_module_file_name; uint32_t num_scs = sc_list.GetSize(); @@ -168,9 +158,7 @@ protected: if (module_list.GetSize() && module_list.GetIndexForModule(module) == LLDB_INVALID_INDEX32) continue; - if (file_spec && - !lldb_private::FileSpec::Equal(file_spec, line_entry.file, - has_path)) + if (!FileSpec::Match(file_spec, line_entry.file)) continue; if (start_line > 0 && line_entry.line < start_line) continue; @@ -180,8 +168,7 @@ protected: continue; // Print a new header if the module changed. - ConstString module_file_name = - module->GetFileSpec().GetFilename(); + ConstString module_file_name = module->GetFileSpec().GetFilename(); assert(module_file_name); if (module_file_name != last_module_file_name) { if (num_matches > 0) @@ -227,8 +214,7 @@ protected: // Dump all matching lines at or above start_line for the file in the // CU. ConstString file_spec_name = file_spec.GetFilename(); - ConstString module_file_name = - module->GetFileSpec().GetFilename(); + ConstString module_file_name = module->GetFileSpec().GetFilename(); bool cu_header_printed = false; uint32_t line = start_line; while (true) { @@ -253,13 +239,13 @@ protected: num_matches++; if (num_lines > 0 && num_matches > num_lines) break; - assert(lldb_private::FileSpec::Equal(cu_file_spec, line_entry.file, - has_path)); + assert(cu_file_spec == line_entry.file); if (!cu_header_printed) { if (num_matches > 0) strm << "\n\n"; strm << "Lines found for file " << file_spec_name - << " in compilation unit " << cu->GetFilename() << " in `" + << " in compilation unit " + << cu->GetPrimaryFile().GetFilename() << " in `" << module_file_name << "\n"; cu_header_printed = true; } @@ -345,9 +331,8 @@ protected: if (target->GetSectionLoadList().ResolveLoadAddress(addr, so_addr)) { ModuleSP module_sp(so_addr.GetModule()); // Check to make sure this module is in our list. - if (module_sp && - module_list.GetIndexForModule(module_sp.get()) != - LLDB_INVALID_INDEX32) { + if (module_sp && module_list.GetIndexForModule(module_sp.get()) != + LLDB_INVALID_INDEX32) { SymbolContext sc; sc.Clear(true); if (module_sp->ResolveSymbolContextForAddress( @@ -401,8 +386,8 @@ protected: // If we didn't find any functions with that name, try searching for // symbols that line up exactly with function addresses. SymbolContextList sc_list_symbols; - module_list.FindFunctionSymbols( - name, eFunctionNameTypeAuto, sc_list_symbols); + module_list.FindFunctionSymbols(name, eFunctionNameTypeAuto, + sc_list_symbols); size_t num_symbol_matches = sc_list_symbols.GetSize(); for (size_t i = 0; i < num_symbol_matches; i++) { SymbolContext sc; @@ -712,7 +697,7 @@ class CommandObjectSourceList : public CommandObjectParsed { lldb::addr_t address; uint32_t start_line; uint32_t num_lines; - STLStringArray modules; + std::vector<std::string> modules; bool show_bp_locs; bool reverse; }; @@ -875,7 +860,7 @@ protected: // passed to the various ModuleList::Find* calls, which would either be a // vector of string names or a ModuleSpecList. void FindMatchingFunctions(Target *target, ConstString name, - SymbolContextList &sc_list) { + SymbolContextList &sc_list) { // Displaying the source for a symbol: bool include_inlines = true; bool include_symbols = false; @@ -892,9 +877,9 @@ protected: ModuleSpec module_spec(module_file_spec); matching_modules.Clear(); target->GetImages().FindModules(module_spec, matching_modules); - matching_modules.FindFunctions( - name, eFunctionNameTypeAuto, include_symbols, include_inlines, - sc_list); + matching_modules.FindFunctions(name, eFunctionNameTypeAuto, + include_symbols, include_inlines, + sc_list); } } } else { @@ -949,7 +934,7 @@ protected: // symbols that line up exactly with function addresses. SymbolContextList sc_list_symbols; FindMatchingFunctionSymbols(target, name, sc_list_symbols); - size_t num_symbol_matches =sc_list_symbols.GetSize(); + size_t num_symbol_matches = sc_list_symbols.GetSize(); for (size_t i = 0; i < num_symbol_matches; i++) { SymbolContext sc; @@ -1081,7 +1066,8 @@ protected: if (m_options.show_bp_locs) { m_breakpoint_locations.Clear(); const bool show_inlines = true; - m_breakpoint_locations.Reset(*sc.comp_unit, 0, show_inlines); + m_breakpoint_locations.Reset(sc.comp_unit->GetPrimaryFile(), 0, + show_inlines); SearchFilterForUnconstrainedSearches target_search_filter( target->shared_from_this()); target_search_filter.Search(m_breakpoint_locations); @@ -1110,8 +1096,8 @@ protected: ? sc.line_entry.column : 0; target->GetSourceManager().DisplaySourceLinesWithLineNumbers( - sc.comp_unit, sc.line_entry.line, column, lines_to_back_up, - m_options.num_lines - lines_to_back_up, "->", + sc.comp_unit->GetPrimaryFile(), sc.line_entry.line, column, + lines_to_back_up, m_options.num_lines - lines_to_back_up, "->", &result.GetOutputStream(), GetBreakpointLocations()); result.SetStatus(eReturnStatusSuccessFinishResult); } @@ -1194,18 +1180,18 @@ protected: if (num_matches > 1) { bool got_multiple = false; - FileSpec *test_cu_spec = nullptr; + CompileUnit *test_cu = nullptr; for (unsigned i = 0; i < num_matches; i++) { SymbolContext sc; sc_list.GetContextAtIndex(i, sc); if (sc.comp_unit) { - if (test_cu_spec) { - if (test_cu_spec != static_cast<FileSpec *>(sc.comp_unit)) + if (test_cu) { + if (test_cu != sc.comp_unit) got_multiple = true; break; } else - test_cu_spec = sc.comp_unit; + test_cu = sc.comp_unit; } } if (got_multiple) { @@ -1222,7 +1208,8 @@ protected: if (sc.comp_unit) { if (m_options.show_bp_locs) { const bool show_inlines = true; - m_breakpoint_locations.Reset(*sc.comp_unit, 0, show_inlines); + m_breakpoint_locations.Reset(sc.comp_unit->GetPrimaryFile(), 0, + show_inlines); SearchFilterForUnconstrainedSearches target_search_filter( target->shared_from_this()); target_search_filter.Search(m_breakpoint_locations); @@ -1233,9 +1220,9 @@ protected: m_options.num_lines = 10; const uint32_t column = 0; target->GetSourceManager().DisplaySourceLinesWithLineNumbers( - sc.comp_unit, m_options.start_line, column, - 0, m_options.num_lines, - "", &result.GetOutputStream(), GetBreakpointLocations()); + sc.comp_unit->GetPrimaryFile(), m_options.start_line, column, 0, + m_options.num_lines, "", &result.GetOutputStream(), + GetBreakpointLocations()); result.SetStatus(eReturnStatusSuccessFinishResult); } else { @@ -1265,10 +1252,11 @@ protected: CommandObjectMultiwordSource::CommandObjectMultiwordSource( CommandInterpreter &interpreter) - : CommandObjectMultiword(interpreter, "source", "Commands for examining " - "source code described by " - "debug information for the " - "current target process.", + : CommandObjectMultiword(interpreter, "source", + "Commands for examining " + "source code described by " + "debug information for the " + "current target process.", "source <subcommand> [<subcommand-options>]") { LoadSubCommand("info", CommandObjectSP(new CommandObjectSourceInfo(interpreter))); diff --git a/lldb/source/Commands/CommandObjectSource.h b/lldb/source/Commands/CommandObjectSource.h index d72122d55dc7..a4b8823a4fa9 100644 --- a/lldb/source/Commands/CommandObjectSource.h +++ b/lldb/source/Commands/CommandObjectSource.h @@ -10,8 +10,6 @@ #ifndef liblldb_CommandObjectSource_h_ #define liblldb_CommandObjectSource_h_ -#include "lldb/Core/STLUtils.h" -#include "lldb/Interpreter/CommandObject.h" #include "lldb/Interpreter/CommandObjectMultiword.h" namespace lldb_private { diff --git a/lldb/source/Commands/CommandObjectStats.cpp b/lldb/source/Commands/CommandObjectStats.cpp index e3a1f9433662..eeec4a8d3e77 100644 --- a/lldb/source/Commands/CommandObjectStats.cpp +++ b/lldb/source/Commands/CommandObjectStats.cpp @@ -7,8 +7,6 @@ //===----------------------------------------------------------------------===// #include "CommandObjectStats.h" -#include "lldb/Host/Host.h" -#include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Target/Target.h" @@ -81,7 +79,8 @@ protected: for (auto &stat : target.GetStatistics()) { result.AppendMessageWithFormat( "%s : %u\n", - lldb_private::GetStatDescription(static_cast<lldb_private::StatisticKind>(i)) + lldb_private::GetStatDescription( + static_cast<lldb_private::StatisticKind>(i)) .c_str(), stat); i += 1; diff --git a/lldb/source/Commands/CommandObjectStats.h b/lldb/source/Commands/CommandObjectStats.h index 27e9a6ff865a..593c4521e175 100644 --- a/lldb/source/Commands/CommandObjectStats.h +++ b/lldb/source/Commands/CommandObjectStats.h @@ -9,7 +9,6 @@ #ifndef liblldb_CommandObjectStats_h_ #define liblldb_CommandObjectStats_h_ -#include "lldb/Interpreter/CommandObject.h" #include "lldb/Interpreter/CommandObjectMultiword.h" namespace lldb_private { diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index abf7895a7384..8738e850c9f7 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -24,7 +24,6 @@ #include "lldb/Interpreter/OptionGroupBoolean.h" #include "lldb/Interpreter/OptionGroupFile.h" #include "lldb/Interpreter/OptionGroupFormat.h" -#include "lldb/Interpreter/OptionGroupPlatform.h" #include "lldb/Interpreter/OptionGroupString.h" #include "lldb/Interpreter/OptionGroupUInt64.h" #include "lldb/Interpreter/OptionGroupUUID.h" @@ -53,7 +52,6 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/FormatAdapters.h" -#include <cerrno> using namespace lldb; using namespace lldb_private; @@ -78,7 +76,7 @@ static void DumpTargetInfo(uint32_t target_idx, Target *target, uint32_t properties = 0; if (target_arch.IsValid()) { strm.Printf("%sarch=", properties++ > 0 ? ", " : " ( "); - target_arch.DumpTriple(strm); + target_arch.DumpTriple(strm.AsRawOstream()); properties++; } PlatformSP platform_sp(target->GetPlatform()); @@ -107,11 +105,11 @@ static void DumpTargetInfo(uint32_t target_idx, Target *target, const uint32_t start_frame = 0; const uint32_t num_frames = 1; const uint32_t num_frames_with_source = 1; - const bool stop_format = false; + const bool stop_format = false; process_sp->GetStatus(strm); process_sp->GetThreadStatus(strm, only_threads_with_stop_reason, - start_frame, num_frames, - num_frames_with_source, stop_format); + start_frame, num_frames, num_frames_with_source, + stop_format); } } @@ -398,8 +396,8 @@ protected: debugger.GetTargetList().SetSelectedTarget(target_sp.get()); if (must_set_platform_path) { ModuleSpec main_module_spec(file_spec); - ModuleSP module_sp = target_sp->GetOrCreateModule(main_module_spec, - true /* notify */); + ModuleSP module_sp = + target_sp->GetOrCreateModule(main_module_spec, true /* notify */); if (module_sp) module_sp->SetPlatformFileSpec(remote_file); } @@ -812,32 +810,28 @@ protected: void DumpGlobalVariableList(const ExecutionContext &exe_ctx, const SymbolContext &sc, const VariableList &variable_list, Stream &s) { - size_t count = variable_list.GetSize(); - if (count > 0) { - if (sc.module_sp) { - if (sc.comp_unit) { - s.Printf("Global variables for %s in %s:\n", - sc.comp_unit->GetPath().c_str(), - sc.module_sp->GetFileSpec().GetPath().c_str()); - } else { - s.Printf("Global variables for %s\n", - sc.module_sp->GetFileSpec().GetPath().c_str()); - } - } else if (sc.comp_unit) { - s.Printf("Global variables for %s\n", sc.comp_unit->GetPath().c_str()); + if (variable_list.Empty()) + return; + if (sc.module_sp) { + if (sc.comp_unit) { + s.Format("Global variables for {0} in {1}:\n", + sc.comp_unit->GetPrimaryFile(), sc.module_sp->GetFileSpec()); + } else { + s.Printf("Global variables for %s\n", + sc.module_sp->GetFileSpec().GetPath().c_str()); } + } else if (sc.comp_unit) { + s.Format("Global variables for {0}\n", sc.comp_unit->GetPrimaryFile()); + } - for (uint32_t i = 0; i < count; ++i) { - VariableSP var_sp(variable_list.GetVariableAtIndex(i)); - if (var_sp) { - ValueObjectSP valobj_sp(ValueObjectVariable::Create( - exe_ctx.GetBestExecutionContextScope(), var_sp)); + for (VariableSP var_sp : variable_list) { + if (!var_sp) + continue; + ValueObjectSP valobj_sp(ValueObjectVariable::Create( + exe_ctx.GetBestExecutionContextScope(), var_sp)); - if (valobj_sp) - DumpValueObject(s, var_sp, valobj_sp, - var_sp->GetName().GetCString()); - } - } + if (valobj_sp) + DumpValueObject(s, var_sp, valobj_sp, var_sp->GetName().GetCString()); } } @@ -929,9 +923,9 @@ protected: if (!success) { if (frame) { if (comp_unit) - result.AppendErrorWithFormat( - "no global variables in current compile unit: %s\n", - comp_unit->GetPath().c_str()); + result.AppendErrorWithFormatv( + "no global variables in current compile unit: {0}\n", + comp_unit->GetPrimaryFile()); else result.AppendErrorWithFormat( "no debug information for frame %u\n", @@ -1295,7 +1289,7 @@ static void DumpModuleArchitecture(Stream &strm, Module *module, StreamString arch_strm; if (full_triple) - module->GetArchitecture().DumpTriple(arch_strm); + module->GetArchitecture().DumpTriple(arch_strm.AsRawOstream()); else arch_strm.PutCString(module->GetArchitecture().GetArchitectureName()); std::string arch_str = arch_strm.GetString(); @@ -1330,8 +1324,8 @@ static uint32_t DumpCompileUnitLineTable(CommandInterpreter &interpreter, if (i > 0) strm << "\n\n"; - strm << "Line table for " << *static_cast<FileSpec *>(sc.comp_unit) - << " in `" << module->GetFileSpec().GetFilename() << "\n"; + strm << "Line table for " << sc.comp_unit->GetPrimaryFile() << " in `" + << module->GetFileSpec().GetFilename() << "\n"; LineTable *line_table = sc.comp_unit->GetLineTable(); if (line_table) line_table->GetDescription( @@ -1353,7 +1347,7 @@ static void DumpFullpath(Stream &strm, const FileSpec *file_spec_ptr, strm.Printf("%-*s", width, fullpath.c_str()); return; } else { - file_spec_ptr->Dump(&strm); + file_spec_ptr->Dump(strm.AsRawOstream()); return; } } @@ -1420,12 +1414,13 @@ static size_t DumpModuleObjfileHeaders(Stream &strm, ModuleList &module_list) { } static void DumpModuleSymtab(CommandInterpreter &interpreter, Stream &strm, - Module *module, SortOrder sort_order) { + Module *module, SortOrder sort_order, + Mangled::NamePreference name_preference) { if (!module) return; if (Symtab *symtab = module->GetSymtab()) symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), - sort_order); + sort_order, name_preference); } static void DumpModuleSections(CommandInterpreter &interpreter, Stream &strm, @@ -1970,6 +1965,11 @@ public: const int short_option = m_getopt_table[option_idx].val; switch (short_option) { + case 'm': + m_prefer_mangled.SetCurrentValue(true); + m_prefer_mangled.SetOptionWasSet(); + break; + case 's': m_sort_order = (SortOrder)OptionArgParser::ToOptionEnum( option_arg, GetDefinitions()[option_idx].enum_values, @@ -1984,6 +1984,7 @@ public: void OptionParsingStarting(ExecutionContext *execution_context) override { m_sort_order = eSortOrderNone; + m_prefer_mangled.Clear(); } llvm::ArrayRef<OptionDefinition> GetDefinitions() override { @@ -1991,12 +1992,16 @@ public: } SortOrder m_sort_order; + OptionValueBoolean m_prefer_mangled = {false, false}; }; protected: bool DoExecute(Args &command, CommandReturnObject &result) override { Target *target = &GetSelectedTarget(); uint32_t num_dumped = 0; + Mangled::NamePreference name_preference = + (m_options.m_prefer_mangled ? Mangled::ePreferMangled + : Mangled::ePreferDemangled); uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); result.GetOutputStream().SetAddressByteSize(addr_byte_size); @@ -2022,7 +2027,7 @@ protected: DumpModuleSymtab( m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndexUnlocked(image_idx), - m_options.m_sort_order); + m_options.m_sort_order, name_preference); } } else { result.AppendError("the target has no associated executable images"); @@ -2050,7 +2055,7 @@ protected: break; num_dumped++; DumpModuleSymtab(m_interpreter, result.GetOutputStream(), module, - m_options.m_sort_order); + m_options.m_sort_order, name_preference); } } } else @@ -3139,18 +3144,17 @@ protected: Address base_addr(objfile->GetBaseAddress()); if (base_addr.IsValid()) { if (target && !target->GetSectionLoadList().IsEmpty()) { - lldb::addr_t load_addr = - base_addr.GetLoadAddress(target); + lldb::addr_t load_addr = base_addr.GetLoadAddress(target); if (load_addr == LLDB_INVALID_ADDRESS) { base_addr.Dump(&strm, target, - Address::DumpStyleModuleWithFileAddress, - Address::DumpStyleFileAddress); + Address::DumpStyleModuleWithFileAddress, + Address::DumpStyleFileAddress); } else { if (format_char == 'o') { // Show the offset of slide for the image - strm.Printf( - "0x%*.*" PRIx64, addr_nibble_width, addr_nibble_width, - load_addr - base_addr.GetFileAddress()); + strm.Printf("0x%*.*" PRIx64, addr_nibble_width, + addr_nibble_width, + load_addr - base_addr.GetFileAddress()); } else { // Show the load address of the image strm.Printf("0x%*.*" PRIx64, addr_nibble_width, @@ -3452,8 +3456,7 @@ protected: } UnwindPlanSP of_unwind_augmented_sp = - func_unwinders_sp->GetObjectFileAugmentedUnwindPlan(*target, - *thread); + func_unwinders_sp->GetObjectFileAugmentedUnwindPlan(*target, *thread); if (of_unwind_augmented_sp) { result.GetOutputStream().Printf("object file augmented UnwindPlan:\n"); of_unwind_augmented_sp->Dump(result.GetOutputStream(), thread.get(), @@ -3751,7 +3754,7 @@ public: break; } - return true; + return false; } bool LookupInModule(CommandInterpreter &interpreter, Module *module, @@ -4035,169 +4038,165 @@ protected: bool AddModuleSymbols(Target *target, ModuleSpec &module_spec, bool &flush, CommandReturnObject &result) { const FileSpec &symbol_fspec = module_spec.GetSymbolFileSpec(); - if (symbol_fspec) { - char symfile_path[PATH_MAX]; - symbol_fspec.GetPath(symfile_path, sizeof(symfile_path)); + if (!symbol_fspec) { + result.AppendError( + "one or more executable image paths must be specified"); + result.SetStatus(eReturnStatusFailed); + return false; + } - if (!module_spec.GetUUID().IsValid()) { - if (!module_spec.GetFileSpec() && !module_spec.GetPlatformFileSpec()) - module_spec.GetFileSpec().GetFilename() = symbol_fspec.GetFilename(); - } - // We now have a module that represents a symbol file that can be used - // for a module that might exist in the current target, so we need to - // find that module in the target - ModuleList matching_module_list; - - size_t num_matches = 0; - // First extract all module specs from the symbol file - lldb_private::ModuleSpecList symfile_module_specs; - if (ObjectFile::GetModuleSpecifications(module_spec.GetSymbolFileSpec(), - 0, 0, symfile_module_specs)) { - // Now extract the module spec that matches the target architecture - ModuleSpec target_arch_module_spec; - ModuleSpec symfile_module_spec; - target_arch_module_spec.GetArchitecture() = target->GetArchitecture(); - if (symfile_module_specs.FindMatchingModuleSpec(target_arch_module_spec, - symfile_module_spec)) { - // See if it has a UUID? - if (symfile_module_spec.GetUUID().IsValid()) { - // It has a UUID, look for this UUID in the target modules - ModuleSpec symfile_uuid_module_spec; - symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID(); - target->GetImages().FindModules(symfile_uuid_module_spec, - matching_module_list); - num_matches = matching_module_list.GetSize(); - } + char symfile_path[PATH_MAX]; + symbol_fspec.GetPath(symfile_path, sizeof(symfile_path)); + + if (!module_spec.GetUUID().IsValid()) { + if (!module_spec.GetFileSpec() && !module_spec.GetPlatformFileSpec()) + module_spec.GetFileSpec().GetFilename() = symbol_fspec.GetFilename(); + } + + // We now have a module that represents a symbol file that can be used + // for a module that might exist in the current target, so we need to + // find that module in the target + ModuleList matching_module_list; + + size_t num_matches = 0; + // First extract all module specs from the symbol file + lldb_private::ModuleSpecList symfile_module_specs; + if (ObjectFile::GetModuleSpecifications(module_spec.GetSymbolFileSpec(), + 0, 0, symfile_module_specs)) { + // Now extract the module spec that matches the target architecture + ModuleSpec target_arch_module_spec; + ModuleSpec symfile_module_spec; + target_arch_module_spec.GetArchitecture() = target->GetArchitecture(); + if (symfile_module_specs.FindMatchingModuleSpec(target_arch_module_spec, + symfile_module_spec)) { + // See if it has a UUID? + if (symfile_module_spec.GetUUID().IsValid()) { + // It has a UUID, look for this UUID in the target modules + ModuleSpec symfile_uuid_module_spec; + symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID(); + target->GetImages().FindModules(symfile_uuid_module_spec, + matching_module_list); + num_matches = matching_module_list.GetSize(); } + } - if (num_matches == 0) { - // No matches yet, iterate through the module specs to find a UUID - // value that we can match up to an image in our target - const size_t num_symfile_module_specs = - symfile_module_specs.GetSize(); - for (size_t i = 0; i < num_symfile_module_specs && num_matches == 0; - ++i) { - if (symfile_module_specs.GetModuleSpecAtIndex( - i, symfile_module_spec)) { - if (symfile_module_spec.GetUUID().IsValid()) { - // It has a UUID, look for this UUID in the target modules - ModuleSpec symfile_uuid_module_spec; - symfile_uuid_module_spec.GetUUID() = - symfile_module_spec.GetUUID(); - target->GetImages().FindModules(symfile_uuid_module_spec, - matching_module_list); - num_matches = matching_module_list.GetSize(); - } + if (num_matches == 0) { + // No matches yet, iterate through the module specs to find a UUID + // value that we can match up to an image in our target + const size_t num_symfile_module_specs = + symfile_module_specs.GetSize(); + for (size_t i = 0; i < num_symfile_module_specs && num_matches == 0; + ++i) { + if (symfile_module_specs.GetModuleSpecAtIndex( + i, symfile_module_spec)) { + if (symfile_module_spec.GetUUID().IsValid()) { + // It has a UUID, look for this UUID in the target modules + ModuleSpec symfile_uuid_module_spec; + symfile_uuid_module_spec.GetUUID() = + symfile_module_spec.GetUUID(); + target->GetImages().FindModules(symfile_uuid_module_spec, + matching_module_list); + num_matches = matching_module_list.GetSize(); } } } } + } - // Just try to match up the file by basename if we have no matches at - // this point - if (num_matches == 0) { - target->GetImages().FindModules(module_spec, matching_module_list); - num_matches = matching_module_list.GetSize(); - } + // Just try to match up the file by basename if we have no matches at + // this point + if (num_matches == 0) { + target->GetImages().FindModules(module_spec, matching_module_list); + num_matches = matching_module_list.GetSize(); + } - while (num_matches == 0) { - ConstString filename_no_extension( - module_spec.GetFileSpec().GetFileNameStrippingExtension()); - // Empty string returned, lets bail - if (!filename_no_extension) - break; + while (num_matches == 0) { + ConstString filename_no_extension( + module_spec.GetFileSpec().GetFileNameStrippingExtension()); + // Empty string returned, let's bail + if (!filename_no_extension) + break; - // Check if there was no extension to strip and the basename is the - // same - if (filename_no_extension == module_spec.GetFileSpec().GetFilename()) - break; + // Check if there was no extension to strip and the basename is the same + if (filename_no_extension == module_spec.GetFileSpec().GetFilename()) + break; - // Replace basename with one less extension - module_spec.GetFileSpec().GetFilename() = filename_no_extension; + // Replace basename with one fewer extension + module_spec.GetFileSpec().GetFilename() = filename_no_extension; + target->GetImages().FindModules(module_spec, matching_module_list); + num_matches = matching_module_list.GetSize(); + } - target->GetImages().FindModules(module_spec, matching_module_list); - num_matches = matching_module_list.GetSize(); - } + if (num_matches > 1) { + result.AppendErrorWithFormat("multiple modules match symbol file '%s', " + "use the --uuid option to resolve the " + "ambiguity.\n", + symfile_path); + } else if (num_matches == 1) { + ModuleSP module_sp(matching_module_list.GetModuleAtIndex(0)); + + // The module has not yet created its symbol vendor, we can just give + // the existing target module the symfile path to use for when it + // decides to create it! + module_sp->SetSymbolFileFileSpec(symbol_fspec); + + SymbolFile *symbol_file = + module_sp->GetSymbolFile(true, &result.GetErrorStream()); + if (symbol_file) { + ObjectFile *object_file = symbol_file->GetObjectFile(); + + if (object_file && object_file->GetFileSpec() == symbol_fspec) { + // Provide feedback that the symfile has been successfully added. + const FileSpec &module_fs = module_sp->GetFileSpec(); + result.AppendMessageWithFormat( + "symbol file '%s' has been added to '%s'\n", symfile_path, + module_fs.GetPath().c_str()); - if (num_matches > 1) { - result.AppendErrorWithFormat("multiple modules match symbol file '%s', " - "use the --uuid option to resolve the " - "ambiguity.\n", - symfile_path); - } else if (num_matches == 1) { - ModuleSP module_sp(matching_module_list.GetModuleAtIndex(0)); - - // The module has not yet created its symbol vendor, we can just give - // the existing target module the symfile path to use for when it - // decides to create it! - module_sp->SetSymbolFileFileSpec(symbol_fspec); - - SymbolFile *symbol_file = - module_sp->GetSymbolFile(true, &result.GetErrorStream()); - if (symbol_file) { - ObjectFile *object_file = symbol_file->GetObjectFile(); - - if (object_file && object_file->GetFileSpec() == symbol_fspec) { - // Provide feedback that the symfile has been successfully added. - const FileSpec &module_fs = module_sp->GetFileSpec(); - result.AppendMessageWithFormat( - "symbol file '%s' has been added to '%s'\n", symfile_path, - module_fs.GetPath().c_str()); - - // Let clients know something changed in the module if it is - // currently loaded - ModuleList module_list; - module_list.Append(module_sp); - target->SymbolsDidLoad(module_list); - - // Make sure we load any scripting resources that may be embedded - // in the debug info files in case the platform supports that. - Status error; - StreamString feedback_stream; - module_sp->LoadScriptingResourceInTarget(target, error, - &feedback_stream); - if (error.Fail() && error.AsCString()) - result.AppendWarningWithFormat( - "unable to load scripting data for module %s - error " - "reported was %s", - module_sp->GetFileSpec() - .GetFileNameStrippingExtension() - .GetCString(), - error.AsCString()); - else if (feedback_stream.GetSize()) - result.AppendWarningWithFormat("%s", feedback_stream.GetData()); + // Let clients know something changed in the module if it is + // currently loaded + ModuleList module_list; + module_list.Append(module_sp); + target->SymbolsDidLoad(module_list); - flush = true; - result.SetStatus(eReturnStatusSuccessFinishResult); - return true; - } + // Make sure we load any scripting resources that may be embedded + // in the debug info files in case the platform supports that. + Status error; + StreamString feedback_stream; + module_sp->LoadScriptingResourceInTarget(target, error, + &feedback_stream); + if (error.Fail() && error.AsCString()) + result.AppendWarningWithFormat( + "unable to load scripting data for module %s - error " + "reported was %s", + module_sp->GetFileSpec() + .GetFileNameStrippingExtension() + .GetCString(), + error.AsCString()); + else if (feedback_stream.GetSize()) + result.AppendWarningWithFormat("%s", feedback_stream.GetData()); + + flush = true; + result.SetStatus(eReturnStatusSuccessFinishResult); + return true; } - // Clear the symbol file spec if anything went wrong - module_sp->SetSymbolFileFileSpec(FileSpec()); } + // Clear the symbol file spec if anything went wrong + module_sp->SetSymbolFileFileSpec(FileSpec()); + } - namespace fs = llvm::sys::fs; - if (module_spec.GetUUID().IsValid()) { - StreamString ss_symfile_uuid; - module_spec.GetUUID().Dump(&ss_symfile_uuid); - result.AppendErrorWithFormat( - "symbol file '%s' (%s) does not match any existing module%s\n", - symfile_path, ss_symfile_uuid.GetData(), - !fs::is_regular_file(symbol_fspec.GetPath()) - ? "\n please specify the full path to the symbol file" - : ""); - } else { - result.AppendErrorWithFormat( - "symbol file '%s' does not match any existing module%s\n", - symfile_path, - !fs::is_regular_file(symbol_fspec.GetPath()) - ? "\n please specify the full path to the symbol file" - : ""); - } - } else { - result.AppendError( - "one or more executable image paths must be specified"); + namespace fs = llvm::sys::fs; + StreamString ss_symfile_uuid; + if (module_spec.GetUUID().IsValid()) { + ss_symfile_uuid << " ("; + module_spec.GetUUID().Dump(&ss_symfile_uuid); + ss_symfile_uuid << ')'; } + result.AppendErrorWithFormat( + "symbol file '%s'%s does not match any existing module%s\n", + symfile_path, ss_symfile_uuid.GetData(), + !fs::is_regular_file(symbol_fspec.GetPath()) + ? "\n please specify the full path to the symbol file" + : ""); result.SetStatus(eReturnStatusFailed); return false; } @@ -4450,8 +4449,7 @@ public: error.SetErrorStringWithFormat( "invalid boolean value '%s' passed for -G option", option_arg.str().c_str()); - } - break; + } break; case 'l': if (option_arg.getAsInteger(0, m_line_start)) { error.SetErrorStringWithFormat("invalid start line number: \"%s\"", @@ -4655,48 +4653,43 @@ protected: } } - if (specifier_up) - new_hook_sp->SetSpecifier(specifier_up.release()); + if (specifier_up) + new_hook_sp->SetSpecifier(specifier_up.release()); - // Next see if any of the thread options have been entered: + // Next see if any of the thread options have been entered: - if (m_options.m_thread_specified) { - ThreadSpec *thread_spec = new ThreadSpec(); + if (m_options.m_thread_specified) { + ThreadSpec *thread_spec = new ThreadSpec(); - if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) { - thread_spec->SetTID(m_options.m_thread_id); - } + if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) { + thread_spec->SetTID(m_options.m_thread_id); + } - if (m_options.m_thread_index != UINT32_MAX) - thread_spec->SetIndex(m_options.m_thread_index); + if (m_options.m_thread_index != UINT32_MAX) + thread_spec->SetIndex(m_options.m_thread_index); - if (!m_options.m_thread_name.empty()) - thread_spec->SetName(m_options.m_thread_name.c_str()); + if (!m_options.m_thread_name.empty()) + thread_spec->SetName(m_options.m_thread_name.c_str()); - if (!m_options.m_queue_name.empty()) - thread_spec->SetQueueName(m_options.m_queue_name.c_str()); + if (!m_options.m_queue_name.empty()) + thread_spec->SetQueueName(m_options.m_queue_name.c_str()); - new_hook_sp->SetThreadSpecifier(thread_spec); - } - - new_hook_sp->SetAutoContinue(m_options.m_auto_continue); - if (m_options.m_use_one_liner) { - // Use one-liners. - for (auto cmd : m_options.m_one_liner) - new_hook_sp->GetCommandPointer()->AppendString( - cmd.c_str()); - result.AppendMessageWithFormat("Stop hook #%" PRIu64 " added.\n", - new_hook_sp->GetID()); - } else { - m_stop_hook_sp = new_hook_sp; - m_interpreter.GetLLDBCommandsFromIOHandler( - "> ", // Prompt - *this, // IOHandlerDelegate - true, // Run IOHandler in async mode - nullptr); // Baton for the "io_handler" that will be passed back - // into our IOHandlerDelegate functions - } - result.SetStatus(eReturnStatusSuccessFinishNoResult); + new_hook_sp->SetThreadSpecifier(thread_spec); + } + + new_hook_sp->SetAutoContinue(m_options.m_auto_continue); + if (m_options.m_use_one_liner) { + // Use one-liners. + for (auto cmd : m_options.m_one_liner) + new_hook_sp->GetCommandPointer()->AppendString(cmd.c_str()); + result.AppendMessageWithFormat("Stop hook #%" PRIu64 " added.\n", + new_hook_sp->GetID()); + } else { + m_stop_hook_sp = new_hook_sp; + m_interpreter.GetLLDBCommandsFromIOHandler("> ", // Prompt + *this); // IOHandlerDelegate + } + result.SetStatus(eReturnStatusSuccessFinishNoResult); return result.Succeeded(); } @@ -4751,7 +4744,7 @@ protected: } } } - result.SetStatus(eReturnStatusSuccessFinishNoResult); + result.SetStatus(eReturnStatusSuccessFinishNoResult); return result.Succeeded(); } }; @@ -4798,7 +4791,7 @@ protected: } } } - result.SetStatus(eReturnStatusSuccessFinishNoResult); + result.SetStatus(eReturnStatusSuccessFinishNoResult); return result.Succeeded(); } diff --git a/lldb/source/Commands/CommandObjectTarget.h b/lldb/source/Commands/CommandObjectTarget.h index 86d554c8a310..bf1dae6bfdc1 100644 --- a/lldb/source/Commands/CommandObjectTarget.h +++ b/lldb/source/Commands/CommandObjectTarget.h @@ -10,7 +10,6 @@ #define liblldb_CommandObjectTarget_h_ #include "lldb/Interpreter/CommandObjectMultiword.h" -#include "lldb/Interpreter/Options.h" namespace lldb_private { diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp index 8c5274553902..83c7cb50d142 100644 --- a/lldb/source/Commands/CommandObjectThread.cpp +++ b/lldb/source/Commands/CommandObjectThread.cpp @@ -8,9 +8,7 @@ #include "CommandObjectThread.h" -#include "lldb/Core/SourceManager.h" #include "lldb/Core/ValueObject.h" -#include "lldb/Host/Host.h" #include "lldb/Host/OptionParser.h" #include "lldb/Host/StringConvert.h" #include "lldb/Interpreter/CommandInterpreter.h" @@ -29,11 +27,7 @@ #include "lldb/Target/Thread.h" #include "lldb/Target/ThreadPlan.h" #include "lldb/Target/ThreadPlanStepInRange.h" -#include "lldb/Target/ThreadPlanStepInstruction.h" -#include "lldb/Target/ThreadPlanStepOut.h" -#include "lldb/Target/ThreadPlanStepRange.h" #include "lldb/Utility/State.h" -#include "lldb/lldb-private.h" using namespace lldb; using namespace lldb_private; @@ -339,8 +333,7 @@ protected: const bool stop_format = false; if (ext_thread_sp->GetStatus(strm, m_options.m_start, m_options.m_count, - num_frames_with_source, - stop_format)) { + num_frames_with_source, stop_format)) { DoExtendedBacktrace(ext_thread_sp.get(), result); } } @@ -393,7 +386,7 @@ static constexpr OptionEnumValueElement g_tri_running_mode[] = { {eOnlyThisThread, "this-thread", "Run only this thread"}, {eAllThreads, "all-threads", "Run all threads"}, {eOnlyDuringStepping, "while-stepping", - "Run only this thread while stepping"} }; + "Run only this thread while stepping"}}; static constexpr OptionEnumValues TriRunningModes() { return OptionEnumValues(g_tri_running_mode); @@ -419,8 +412,8 @@ public: Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override { Status error; - const int short_option - = g_thread_step_scope_options[option_idx].short_option; + const int short_option = + g_thread_step_scope_options[option_idx].short_option; switch (short_option) { case 'a': { @@ -428,11 +421,10 @@ public: bool avoid_no_debug = OptionArgParser::ToBoolean(option_arg, true, &success); if (!success) - error.SetErrorStringWithFormat( - "invalid boolean value for option '%c'", short_option); + error.SetErrorStringWithFormat("invalid boolean value for option '%c'", + short_option); else { - m_step_in_avoid_no_debug = - avoid_no_debug ? eLazyBoolYes : eLazyBoolNo; + m_step_in_avoid_no_debug = avoid_no_debug ? eLazyBoolYes : eLazyBoolNo; } } break; @@ -441,11 +433,10 @@ public: bool avoid_no_debug = OptionArgParser::ToBoolean(option_arg, true, &success); if (!success) - error.SetErrorStringWithFormat( - "invalid boolean value for option '%c'", short_option); + error.SetErrorStringWithFormat("invalid boolean value for option '%c'", + short_option); else { - m_step_out_avoid_no_debug = - avoid_no_debug ? eLazyBoolYes : eLazyBoolNo; + m_step_out_avoid_no_debug = avoid_no_debug ? eLazyBoolYes : eLazyBoolNo; } } break; @@ -518,7 +509,6 @@ public: class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed { public: - CommandObjectThreadStepWithTypeAndScope(CommandInterpreter &interpreter, const char *name, const char *help, const char *syntax, @@ -530,7 +520,7 @@ public: eCommandProcessMustBeLaunched | eCommandProcessMustBePaused), m_step_type(step_type), m_step_scope(step_scope), m_options(), - m_class_options("scripted step", 'C') { + m_class_options("scripted step") { CommandArgumentEntry arg; CommandArgumentData thread_id_arg; @@ -544,9 +534,10 @@ public: // Push the data for the first argument into the m_arguments vector. m_arguments.push_back(arg); - + if (step_type == eStepTypeScripted) { - m_all_options.Append(&m_class_options, LLDB_OPT_SET_1, LLDB_OPT_SET_1); + m_all_options.Append(&m_class_options, LLDB_OPT_SET_1 | LLDB_OPT_SET_2, + LLDB_OPT_SET_1); } m_all_options.Append(&m_options); m_all_options.Finalize(); @@ -554,9 +545,7 @@ public: ~CommandObjectThreadStepWithTypeAndScope() override = default; - Options *GetOptions() override { - return &m_all_options; - } + Options *GetOptions() override { return &m_all_options; } protected: bool DoExecute(Args &command, CommandReturnObject &result) override { @@ -596,15 +585,15 @@ protected: } if (m_step_type == eStepTypeScripted) { - if (m_class_options.GetClassName().empty()) { + if (m_class_options.GetName().empty()) { result.AppendErrorWithFormat("empty class name for scripted step."); result.SetStatus(eReturnStatusFailed); return false; } else if (!GetDebugger().GetScriptInterpreter()->CheckObjectExists( - m_class_options.GetClassName().c_str())) { + m_class_options.GetName().c_str())) { result.AppendErrorWithFormat( "class for scripted step: \"%s\" does not exist.", - m_class_options.GetClassName().c_str()); + m_class_options.GetName().c_str()); result.SetStatus(eReturnStatusFailed); return false; } @@ -720,9 +709,9 @@ protected: m_options.m_step_out_avoid_no_debug); } else if (m_step_type == eStepTypeScripted) { new_plan_sp = thread->QueueThreadPlanForStepScripted( - abort_other_plans, m_class_options.GetClassName().c_str(), - m_class_options.GetStructuredData(), - bool_stop_other_threads, new_plan_status); + abort_other_plans, m_class_options.GetName().c_str(), + m_class_options.GetStructuredData(), bool_stop_other_threads, + new_plan_status); } else { result.AppendError("step type is not supported"); result.SetStatus(eReturnStatusFailed); @@ -969,7 +958,7 @@ public: static constexpr OptionEnumValueElement g_duo_running_mode[] = { {eOnlyThisThread, "this-thread", "Run only this thread"}, - {eAllThreads, "all-threads", "Run all threads"} }; + {eAllThreads, "all-threads", "Run all threads"}}; static constexpr OptionEnumValues DuoRunningModes() { return OptionEnumValues(g_duo_running_mode); @@ -1063,7 +1052,8 @@ public: "Continue until a line number or address is reached by the " "current or specified thread. Stops when returning from " "the current function as a safety measure. " - "The target line number(s) are given as arguments, and if more than one" + "The target line number(s) are given as arguments, and if more " + "than one" " is provided, stepping will stop when the first one is hit.", nullptr, eCommandRequiresThread | eCommandTryTargetAPILock | @@ -1197,7 +1187,7 @@ protected: LineEntry line_entry; const bool exact = false; start_idx_ptr = sc.comp_unit->FindLineEntry( - start_idx_ptr, line_number, sc.comp_unit, exact, &line_entry); + start_idx_ptr, line_number, nullptr, exact, &line_entry); if (start_idx_ptr == UINT32_MAX) break; @@ -1430,9 +1420,10 @@ public: CommandObjectThreadInfo(CommandInterpreter &interpreter) : CommandObjectIterateOverThreads( - interpreter, "thread info", "Show an extended summary of one or " - "more threads. Defaults to the " - "current thread.", + interpreter, "thread info", + "Show an extended summary of one or " + "more threads. Defaults to the " + "current thread.", "thread info", eCommandRequiresProcess | eCommandTryTargetAPILock | eCommandProcessMustBeLaunched | eCommandProcessMustBePaused), @@ -1474,7 +1465,7 @@ public: // CommandObjectThreadException class CommandObjectThreadException : public CommandObjectIterateOverThreads { - public: +public: CommandObjectThreadException(CommandInterpreter &interpreter) : CommandObjectIterateOverThreads( interpreter, "thread exception", @@ -2006,9 +1997,10 @@ public: CommandObjectMultiwordThread::CommandObjectMultiwordThread( CommandInterpreter &interpreter) - : CommandObjectMultiword(interpreter, "thread", "Commands for operating on " - "one or more threads in " - "the current process.", + : CommandObjectMultiword(interpreter, "thread", + "Commands for operating on " + "one or more threads in " + "the current process.", "thread <subcommand> [<subcommand-options>]") { LoadSubCommand("backtrace", CommandObjectSP(new CommandObjectThreadBacktrace( interpreter))); @@ -2026,9 +2018,8 @@ CommandObjectMultiwordThread::CommandObjectMultiwordThread( CommandObjectSP(new CommandObjectThreadUntil(interpreter))); LoadSubCommand("info", CommandObjectSP(new CommandObjectThreadInfo(interpreter))); - LoadSubCommand( - "exception", - CommandObjectSP(new CommandObjectThreadException(interpreter))); + LoadSubCommand("exception", CommandObjectSP(new CommandObjectThreadException( + interpreter))); LoadSubCommand("step-in", CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope( interpreter, "thread step-in", diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp index 5e31fd5e8bce..87c107cfb943 100644 --- a/lldb/source/Commands/CommandObjectType.cpp +++ b/lldb/source/Commands/CommandObjectType.cpp @@ -11,6 +11,7 @@ #include "lldb/Core/Debugger.h" #include "lldb/Core/IOHandler.h" #include "lldb/DataFormatters/DataVisualization.h" +#include "lldb/Host/Config.h" #include "lldb/Host/OptionParser.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandObject.h" @@ -23,20 +24,16 @@ #include "lldb/Interpreter/Options.h" #include "lldb/Symbol/Symbol.h" #include "lldb/Target/Language.h" -#include "lldb/Target/Process.h" #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" -#include "lldb/Target/ThreadList.h" #include "lldb/Utility/ConstString.h" #include "lldb/Utility/RegularExpression.h" -#include "lldb/Utility/State.h" #include "lldb/Utility/StringList.h" #include "llvm/ADT/STLExtras.h" #include <algorithm> -#include <cctype> #include <functional> #include <memory> @@ -162,7 +159,7 @@ public: std::string &data) override { StreamFileSP error_sp = io_handler.GetErrorStreamFileSP(); -#ifndef LLDB_DISABLE_PYTHON +#if LLDB_ENABLE_PYTHON ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter(); if (interpreter) { StringList lines; @@ -255,7 +252,7 @@ public: "error: script interpreter missing, didn't add python command.\n"); error_sp->Flush(); } -#endif // LLDB_DISABLE_PYTHON +#endif io_handler.SetIsDone(true); } @@ -394,7 +391,7 @@ protected: std::string &data) override { StreamFileSP error_sp = io_handler.GetErrorStreamFileSP(); -#ifndef LLDB_DISABLE_PYTHON +#if LLDB_ENABLE_PYTHON ScriptInterpreter *interpreter = GetDebugger().GetScriptInterpreter(); if (interpreter) { StringList lines; @@ -474,7 +471,7 @@ protected: error_sp->Flush(); } -#endif // LLDB_DISABLE_PYTHON +#endif io_handler.SetIsDone(true); } @@ -1059,8 +1056,9 @@ protected: bool any_printed = false; - auto category_closure = [&result, &formatter_regex, &any_printed]( - const lldb::TypeCategoryImplSP &category) -> void { + auto category_closure = + [&result, &formatter_regex, + &any_printed](const lldb::TypeCategoryImplSP &category) -> void { result.GetOutputStream().Printf( "-----------------------\nCategory: %s%s\n-----------------------\n", category->GetName(), category->IsEnabled() ? "" : " (disabled)"); @@ -1166,12 +1164,6 @@ public: "Show a list of current formats.") {} }; -#ifndef LLDB_DISABLE_PYTHON - -// CommandObjectTypeSummaryAdd - -#endif // LLDB_DISABLE_PYTHON - Status CommandObjectTypeSummaryAdd::CommandOptions::SetOptionValue( uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) { @@ -1254,7 +1246,7 @@ void CommandObjectTypeSummaryAdd::CommandOptions::OptionParsingStarting( m_category = "default"; } -#ifndef LLDB_DISABLE_PYTHON +#if LLDB_ENABLE_PYTHON bool CommandObjectTypeSummaryAdd::Execute_ScriptSummary( Args &command, CommandReturnObject &result) { @@ -1340,7 +1332,6 @@ bool CommandObjectTypeSummaryAdd::Execute_ScriptSummary( m_interpreter.GetPythonCommandsFromIOHandler( " ", // Prompt *this, // IOHandlerDelegate - true, // Run IOHandler in async mode options); // Baton for the "io_handler" that will be passed back into // our IOHandlerDelegate functions result.SetStatus(eReturnStatusSuccessFinishNoResult); @@ -1379,7 +1370,7 @@ bool CommandObjectTypeSummaryAdd::Execute_ScriptSummary( return result.Succeeded(); } -#endif // LLDB_DISABLE_PYTHON +#endif bool CommandObjectTypeSummaryAdd::Execute_StringSummary( Args &command, CommandReturnObject &result) { @@ -1577,13 +1568,13 @@ bool CommandObjectTypeSummaryAdd::DoExecute(Args &command, WarnOnPotentialUnquotedUnsignedType(command, result); if (m_options.m_is_add_script) { -#ifndef LLDB_DISABLE_PYTHON +#if LLDB_ENABLE_PYTHON return Execute_ScriptSummary(command, result); #else result.AppendError("python is disabled"); result.SetStatus(eReturnStatusFailed); return false; -#endif // LLDB_DISABLE_PYTHON +#endif } return Execute_StringSummary(command, result); @@ -2151,7 +2142,7 @@ public: "Show a list of current filters.") {} }; -#ifndef LLDB_DISABLE_PYTHON +#if LLDB_ENABLE_PYTHON // CommandObjectTypeSynthList @@ -2164,7 +2155,7 @@ public: "Show a list of current synthetic providers.") {} }; -#endif // LLDB_DISABLE_PYTHON +#endif // CommandObjectTypeFilterDelete @@ -2179,7 +2170,7 @@ public: ~CommandObjectTypeFilterDelete() override = default; }; -#ifndef LLDB_DISABLE_PYTHON +#if LLDB_ENABLE_PYTHON // CommandObjectTypeSynthDelete @@ -2195,7 +2186,7 @@ public: ~CommandObjectTypeSynthDelete() override = default; }; -#endif // LLDB_DISABLE_PYTHON +#endif // CommandObjectTypeFilterClear @@ -2208,7 +2199,7 @@ public: "type filter clear", "Delete all existing filter.") {} }; -#ifndef LLDB_DISABLE_PYTHON +#if LLDB_ENABLE_PYTHON // CommandObjectTypeSynthClear class CommandObjectTypeSynthClear : public CommandObjectTypeFormatterClear { @@ -2240,7 +2231,6 @@ bool CommandObjectTypeSynthAdd::Execute_HandwritePython( m_interpreter.GetPythonCommandsFromIOHandler( " ", // Prompt *this, // IOHandlerDelegate - true, // Run IOHandler in async mode options); // Baton for the "io_handler" that will be passed back into our // IOHandlerDelegate functions result.SetStatus(eReturnStatusSuccessFinishNoResult); @@ -2343,9 +2333,9 @@ bool CommandObjectTypeSynthAdd::AddSynth(ConstString type_name, type = eRegexSynth; } - if (category->AnyMatches(type_name, eFormatCategoryItemFilter | - eFormatCategoryItemRegexFilter, - false)) { + if (category->AnyMatches( + type_name, eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter, + false)) { if (error) error->SetErrorStringWithFormat("cannot add synthetic for type %s when " "filter is defined in same category!", @@ -2372,7 +2362,7 @@ bool CommandObjectTypeSynthAdd::AddSynth(ConstString type_name, } } -#endif // LLDB_DISABLE_PYTHON +#endif #define LLDB_OPTIONS_type_filter_add #include "CommandOptions.inc" @@ -2468,9 +2458,9 @@ private: type = eRegexFilter; } - if (category->AnyMatches(type_name, eFormatCategoryItemSynth | - eFormatCategoryItemRegexSynth, - false)) { + if (category->AnyMatches( + type_name, eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth, + false)) { if (error) error->SetErrorStringWithFormat("cannot add filter for type %s when " "synthetic is defined in same " @@ -2828,8 +2818,7 @@ public: CommandObjectFormatterInfo(CommandInterpreter &interpreter, const char *formatter_name, DiscoveryFunction discovery_func) - : CommandObjectRaw(interpreter, "", "", "", - eCommandRequiresFrame), + : CommandObjectRaw(interpreter, "", "", "", eCommandRequiresFrame), m_formatter_name(formatter_name ? formatter_name : ""), m_discovery_function(discovery_func) { StreamString name; @@ -2923,7 +2912,7 @@ public: ~CommandObjectTypeFormat() override = default; }; -#ifndef LLDB_DISABLE_PYTHON +#if LLDB_ENABLE_PYTHON class CommandObjectTypeSynth : public CommandObjectMultiword { public: @@ -2952,7 +2941,7 @@ public: ~CommandObjectTypeSynth() override = default; }; -#endif // LLDB_DISABLE_PYTHON +#endif class CommandObjectTypeFilter : public CommandObjectMultiword { public: @@ -3038,10 +3027,10 @@ CommandObjectType::CommandObjectType(CommandInterpreter &interpreter) CommandObjectSP(new CommandObjectTypeFormat(interpreter))); LoadSubCommand("summary", CommandObjectSP(new CommandObjectTypeSummary(interpreter))); -#ifndef LLDB_DISABLE_PYTHON +#if LLDB_ENABLE_PYTHON LoadSubCommand("synthetic", CommandObjectSP(new CommandObjectTypeSynth(interpreter))); -#endif // LLDB_DISABLE_PYTHON +#endif LoadSubCommand("lookup", CommandObjectSP(new CommandObjectTypeLookup(interpreter))); } diff --git a/lldb/source/Commands/CommandObjectType.h b/lldb/source/Commands/CommandObjectType.h index ebb19039e503..938e481a6b87 100644 --- a/lldb/source/Commands/CommandObjectType.h +++ b/lldb/source/Commands/CommandObjectType.h @@ -9,11 +9,7 @@ #ifndef liblldb_CommandObjectType_h_ #define liblldb_CommandObjectType_h_ - - #include "lldb/Interpreter/CommandObjectMultiword.h" -#include "lldb/Interpreter/Options.h" -#include "lldb/lldb-types.h" namespace lldb_private { diff --git a/lldb/source/Commands/CommandObjectVersion.cpp b/lldb/source/Commands/CommandObjectVersion.cpp index 904baf5b7d44..227d5d132d96 100644 --- a/lldb/source/Commands/CommandObjectVersion.cpp +++ b/lldb/source/Commands/CommandObjectVersion.cpp @@ -8,7 +8,6 @@ #include "CommandObjectVersion.h" -#include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/lldb-private.h" diff --git a/lldb/source/Commands/CommandObjectWatchpoint.cpp b/lldb/source/Commands/CommandObjectWatchpoint.cpp index 44dfb29b19b5..c965d354f734 100644 --- a/lldb/source/Commands/CommandObjectWatchpoint.cpp +++ b/lldb/source/Commands/CommandObjectWatchpoint.cpp @@ -16,9 +16,7 @@ #include "lldb/Breakpoint/Watchpoint.h" #include "lldb/Breakpoint/WatchpointList.h" #include "lldb/Core/ValueObject.h" -#include "lldb/Core/ValueObjectVariable.h" #include "lldb/Host/OptionParser.h" -#include "lldb/Interpreter/CommandCompletions.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Symbol/Variable.h" @@ -417,6 +415,10 @@ protected: }; // CommandObjectWatchpointDelete +#define LLDB_OPTIONS_watchpoint_delete +#include "CommandOptions.inc" + +// CommandObjectWatchpointDelete #pragma mark Delete class CommandObjectWatchpointDelete : public CommandObjectParsed { @@ -425,7 +427,8 @@ public: : CommandObjectParsed(interpreter, "watchpoint delete", "Delete the specified watchpoint(s). If no " "watchpoints are specified, delete them all.", - nullptr, eCommandRequiresTarget) { + nullptr, eCommandRequiresTarget), + m_options() { CommandArgumentEntry arg; CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange); @@ -436,6 +439,41 @@ public: ~CommandObjectWatchpointDelete() override = default; + Options *GetOptions() override { return &m_options; } + + class CommandOptions : public Options { + public: + CommandOptions() : Options(), m_force(false) {} + + ~CommandOptions() override = default; + + Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, + ExecutionContext *execution_context) override { + const int short_option = m_getopt_table[option_idx].val; + + switch (short_option) { + case 'f': + m_force = true; + break; + default: + llvm_unreachable("Unimplemented option"); + } + + return {}; + } + + void OptionParsingStarting(ExecutionContext *execution_context) override { + m_force = false; + } + + llvm::ArrayRef<OptionDefinition> GetDefinitions() override { + return llvm::makeArrayRef(g_watchpoint_delete_options); + } + + // Instance variables to hold the values for command options. + bool m_force; + }; + protected: bool DoExecute(Args &command, CommandReturnObject &result) override { Target *target = &GetSelectedTarget(); @@ -455,8 +493,9 @@ protected: return false; } - if (command.GetArgumentCount() == 0) { - if (!m_interpreter.Confirm( + if (command.empty()) { + if (!m_options.m_force && + !m_interpreter.Confirm( "About to delete all watchpoints, do you want to do that?", true)) { result.AppendMessage("Operation cancelled..."); @@ -467,27 +506,31 @@ protected: (uint64_t)num_watchpoints); } result.SetStatus(eReturnStatusSuccessFinishNoResult); - } else { - // Particular watchpoints selected; delete them. - std::vector<uint32_t> wp_ids; - if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs( - target, command, wp_ids)) { - result.AppendError("Invalid watchpoints specification."); - result.SetStatus(eReturnStatusFailed); - return false; - } + return result.Succeeded(); + } - int count = 0; - const size_t size = wp_ids.size(); - for (size_t i = 0; i < size; ++i) - if (target->RemoveWatchpointByID(wp_ids[i])) - ++count; - result.AppendMessageWithFormat("%d watchpoints deleted.\n", count); - result.SetStatus(eReturnStatusSuccessFinishNoResult); + // Particular watchpoints selected; delete them. + std::vector<uint32_t> wp_ids; + if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, + wp_ids)) { + result.AppendError("Invalid watchpoints specification."); + result.SetStatus(eReturnStatusFailed); + return false; } + int count = 0; + const size_t size = wp_ids.size(); + for (size_t i = 0; i < size; ++i) + if (target->RemoveWatchpointByID(wp_ids[i])) + ++count; + result.AppendMessageWithFormat("%d watchpoints deleted.\n", count); + result.SetStatus(eReturnStatusSuccessFinishNoResult); + return result.Succeeded(); } + +private: + CommandOptions m_options; }; // CommandObjectWatchpointIgnore diff --git a/lldb/source/Commands/CommandObjectWatchpoint.h b/lldb/source/Commands/CommandObjectWatchpoint.h index f21796e6bc8d..4f4f80bbd620 100644 --- a/lldb/source/Commands/CommandObjectWatchpoint.h +++ b/lldb/source/Commands/CommandObjectWatchpoint.h @@ -9,10 +9,8 @@ #ifndef liblldb_CommandObjectWatchpoint_h_ #define liblldb_CommandObjectWatchpoint_h_ - #include "lldb/Interpreter/CommandObjectMultiword.h" #include "lldb/Interpreter/OptionGroupWatchpoint.h" -#include "lldb/Interpreter/Options.h" namespace lldb_private { diff --git a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp index 5683381efc85..1b83e885d27e 100644 --- a/lldb/source/Commands/CommandObjectWatchpointCommand.cpp +++ b/lldb/source/Commands/CommandObjectWatchpointCommand.cpp @@ -18,8 +18,6 @@ #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Interpreter/OptionArgParser.h" #include "lldb/Target/Target.h" -#include "lldb/Target/Thread.h" -#include "lldb/Utility/State.h" using namespace lldb; using namespace lldb_private; @@ -39,6 +37,11 @@ static constexpr OptionEnumValueElement g_script_option_enumeration[] = { "Commands are in the Python language.", }, { + eScriptLanguageLua, + "lua", + "Commands are in the Python language.", + }, + { eSortOrderByName, "default-script", "Commands are in the default scripting language.", @@ -240,7 +243,6 @@ are no syntax errors may indicate that a function was declared but never called. m_interpreter.GetLLDBCommandsFromIOHandler( "> ", // Prompt *this, // IOHandlerDelegate - true, // Run IOHandler in async mode wp_options); // Baton for the "io_handler" that will be passed back into // our IOHandlerDelegate functions } @@ -333,8 +335,16 @@ are no syntax errors may indicate that a function was declared but never called. option_arg, GetDefinitions()[option_idx].enum_values, eScriptLanguageNone, error); - m_use_script_language = (m_script_language == eScriptLanguagePython || - m_script_language == eScriptLanguageDefault); + switch (m_script_language) { + case eScriptLanguagePython: + case eScriptLanguageLua: + m_use_script_language = true; + break; + case eScriptLanguageNone: + case eScriptLanguageUnknown: + m_use_script_language = false; + break; + } break; case 'e': { @@ -349,7 +359,6 @@ are no syntax errors may indicate that a function was declared but never called. case 'F': m_use_one_liner = false; - m_use_script_language = true; m_function_name.assign(option_arg); break; @@ -400,12 +409,11 @@ protected: return false; } - if (!m_options.m_use_script_language && - !m_options.m_function_name.empty()) { - result.AppendError("need to enable scripting to have a function run as a " - "watchpoint command"); - result.SetStatus(eReturnStatusFailed); - return false; + if (!m_options.m_function_name.empty()) { + if (!m_options.m_use_script_language) { + m_options.m_script_language = GetDebugger().GetScriptLanguage(); + m_options.m_use_script_language = true; + } } std::vector<uint32_t> valid_wp_ids; @@ -435,9 +443,11 @@ protected: // to set or collect command callback. Otherwise, call the methods // associated with this object. if (m_options.m_use_script_language) { + ScriptInterpreter *script_interp = GetDebugger().GetScriptInterpreter( + /*can_create=*/true, m_options.m_script_language); // Special handling for one-liner specified inline. if (m_options.m_use_one_liner) { - GetDebugger().GetScriptInterpreter()->SetWatchpointCommandCallback( + script_interp->SetWatchpointCommandCallback( wp_options, m_options.m_one_liner.c_str()); } // Special handling for using a Python function by name instead of @@ -447,12 +457,11 @@ protected: else if (!m_options.m_function_name.empty()) { std::string oneliner(m_options.m_function_name); oneliner += "(frame, wp, internal_dict)"; - GetDebugger().GetScriptInterpreter()->SetWatchpointCommandCallback( + script_interp->SetWatchpointCommandCallback( wp_options, oneliner.c_str()); } else { - GetDebugger() - .GetScriptInterpreter() - ->CollectDataForWatchpointCommandCallback(wp_options, result); + script_interp->CollectDataForWatchpointCommandCallback(wp_options, + result); } } else { // Special handling for one-liner specified inline. @@ -611,10 +620,10 @@ protected: const Baton *baton = wp_options->GetBaton(); if (baton) { result.GetOutputStream().Printf("Watchpoint %u:\n", cur_wp_id); - result.GetOutputStream().IndentMore(); - baton->GetDescription(&result.GetOutputStream(), - eDescriptionLevelFull); - result.GetOutputStream().IndentLess(); + baton->GetDescription(result.GetOutputStream().AsRawOstream(), + eDescriptionLevelFull, + result.GetOutputStream().GetIndentLevel() + + 2); } else { result.AppendMessageWithFormat( "Watchpoint %u does not have an associated command.\n", diff --git a/lldb/source/Commands/CommandObjectWatchpointCommand.h b/lldb/source/Commands/CommandObjectWatchpointCommand.h index f2f15ef50b0f..6fbc9c741617 100644 --- a/lldb/source/Commands/CommandObjectWatchpointCommand.h +++ b/lldb/source/Commands/CommandObjectWatchpointCommand.h @@ -9,11 +9,7 @@ #ifndef liblldb_CommandObjectWatchpointCommand_h_ #define liblldb_CommandObjectWatchpointCommand_h_ - - #include "lldb/Interpreter/CommandObjectMultiword.h" -#include "lldb/Interpreter/Options.h" -#include "lldb/lldb-types.h" namespace lldb_private { diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td index 87f5506c305f..850df133a429 100644 --- a/lldb/source/Commands/Options.td +++ b/lldb/source/Commands/Options.td @@ -4,6 +4,8 @@ let Command = "target modules dump symtab" in { def tm_sort : Option<"sort", "s">, Group<1>, Desc<"Supply a sort order when dumping the symbol table.">, EnumArg<"SortOrder", "OptionEnumValues(g_sort_option_enumeration)">; + def tm_smn : Option<"show-mangled-names", "m">, Group<1>, + Desc<"Do not demangle symbol names before showing them.">; } let Command = "help" in { @@ -268,10 +270,6 @@ let Command = "breakpoint command add" in { EnumArg<"None", "ScriptOptionEnum()">, Desc<"Specify the language for the commands - if none is specified, the " "lldb command interpreter will be used.">; - def breakpoint_add_python_function : Option<"python-function", "F">, - Group<2>, Arg<"PythonFunction">, - Desc<"Give the name of a Python function to run as command for this " - "breakpoint. Be sure to give a module name if appropriate.">; def breakpoint_add_dummy_breakpoints : Option<"dummy-breakpoints", "D">, Desc<"Sets Dummy breakpoints - i.e. breakpoints set before a file is " "provided, which prime new targets.">; @@ -431,7 +429,7 @@ let Command = "log" in { Desc<"Prepend the names of files and function that generate the logs.">; } -let Command = "reproducer" in { +let Command = "reproducer dump" in { def reproducer_provider : Option<"provider", "p">, Group<1>, EnumArg<"None", "ReproducerProviderType()">, Required, Desc<"The reproducer provider to dump.">; @@ -440,6 +438,12 @@ let Command = "reproducer" in { "provided, that reproducer is dumped.">; } +let Command = "reproducer xcrash" in { + def reproducer_signal : Option<"signal", "s">, Group<1>, + EnumArg<"None", "ReproducerSignalType()">, + Required, Desc<"The signal to crash the debugger.">; +} + let Command = "memory read" in { def memory_read_num_per_line : Option<"num-per-line", "l">, Group<1>, Arg<"NumberPerLine">, Desc<"The number of items per line to display.">; @@ -907,9 +911,6 @@ let Command = "thread step scope" in { def thread_step_scope_step_in_target : Option<"step-in-target", "t">, Group<1>, Arg<"FunctionName">, Desc<"The name of the directly called " "function step in should stop at when stepping into.">; - def thread_step_scope_python_class : Option<"python-class", "C">, Group<2>, - Arg<"PythonClass">, Desc<"The name of the class that will manage this step " - "- only supported for Scripted Step.">; } let Command = "thread until" in { @@ -1125,3 +1126,8 @@ let Command = "watchpoint command add" in { "to run as command for this watchpoint. Be sure to give a module name if " "appropriate.">; } + +let Command = "watchpoint delete" in { + def watchpoint_delete_force : Option<"force", "f">, Group<1>, + Desc<"Delete all watchpoints without querying for confirmation.">; +} |