[Lldb-commits] [lldb] r280751 - *** This commit represents a complete reformatting of the LLDB source code
Kate Stone via lldb-commits
lldb-commits at lists.llvm.org
Tue Sep 6 13:58:36 PDT 2016
Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Tue Sep 6 15:57:50 2016
@@ -15,7 +15,6 @@
// Other libraries and framework includes
// Project includes
-#include "lldb/Interpreter/Args.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/IOHandler.h"
#include "lldb/Core/Module.h"
@@ -27,19 +26,20 @@
#include "lldb/DataFormatters/ValueObjectPrinter.h"
#include "lldb/Host/StringConvert.h"
#include "lldb/Host/Symbols.h"
+#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
-#include "lldb/Interpreter/Options.h"
#include "lldb/Interpreter/OptionGroupArchitecture.h"
#include "lldb/Interpreter/OptionGroupBoolean.h"
#include "lldb/Interpreter/OptionGroupFile.h"
#include "lldb/Interpreter/OptionGroupFormat.h"
-#include "lldb/Interpreter/OptionGroupVariable.h"
#include "lldb/Interpreter/OptionGroupPlatform.h"
+#include "lldb/Interpreter/OptionGroupString.h"
#include "lldb/Interpreter/OptionGroupUInt64.h"
#include "lldb/Interpreter/OptionGroupUUID.h"
-#include "lldb/Interpreter/OptionGroupString.h"
#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
+#include "lldb/Interpreter/OptionGroupVariable.h"
+#include "lldb/Interpreter/Options.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/FuncUnwinders.h"
#include "lldb/Symbol/LineTable.h"
@@ -58,89 +58,78 @@
using namespace lldb;
using namespace lldb_private;
-static void
-DumpTargetInfo (uint32_t target_idx, Target *target, const char *prefix_cstr, bool show_stopped_process_status, Stream &strm)
-{
- const ArchSpec &target_arch = target->GetArchitecture();
-
- Module *exe_module = target->GetExecutableModulePointer();
- char exe_path[PATH_MAX];
- bool exe_valid = false;
- if (exe_module)
- exe_valid = exe_module->GetFileSpec().GetPath (exe_path, sizeof(exe_path));
-
- if (!exe_valid)
- ::strcpy (exe_path, "<none>");
-
- strm.Printf ("%starget #%u: %s", prefix_cstr ? prefix_cstr : "", target_idx, exe_path);
-
- uint32_t properties = 0;
- if (target_arch.IsValid())
- {
- strm.Printf ("%sarch=", properties++ > 0 ? ", " : " ( ");
- target_arch.DumpTriple (strm);
- properties++;
- }
- PlatformSP platform_sp (target->GetPlatform());
- if (platform_sp)
- strm.Printf ("%splatform=%s", properties++ > 0 ? ", " : " ( ", platform_sp->GetName().GetCString());
-
- ProcessSP process_sp (target->GetProcessSP());
- bool show_process_status = false;
- if (process_sp)
- {
- lldb::pid_t pid = process_sp->GetID();
- StateType state = process_sp->GetState();
- if (show_stopped_process_status)
- show_process_status = StateIsStoppedState(state, true);
- const char *state_cstr = StateAsCString (state);
- if (pid != LLDB_INVALID_PROCESS_ID)
- strm.Printf ("%spid=%" PRIu64, properties++ > 0 ? ", " : " ( ", pid);
- strm.Printf ("%sstate=%s", properties++ > 0 ? ", " : " ( ", state_cstr);
- }
- if (properties > 0)
- strm.PutCString (" )\n");
- else
- strm.EOL();
- if (show_process_status)
- {
- const bool only_threads_with_stop_reason = true;
- const uint32_t start_frame = 0;
- const uint32_t num_frames = 1;
- const uint32_t num_frames_with_source = 1;
- process_sp->GetStatus (strm);
- process_sp->GetThreadStatus (strm,
- only_threads_with_stop_reason,
- start_frame,
- num_frames,
- num_frames_with_source);
-
- }
+static void DumpTargetInfo(uint32_t target_idx, Target *target,
+ const char *prefix_cstr,
+ bool show_stopped_process_status, Stream &strm) {
+ const ArchSpec &target_arch = target->GetArchitecture();
+
+ Module *exe_module = target->GetExecutableModulePointer();
+ char exe_path[PATH_MAX];
+ bool exe_valid = false;
+ if (exe_module)
+ exe_valid = exe_module->GetFileSpec().GetPath(exe_path, sizeof(exe_path));
+
+ if (!exe_valid)
+ ::strcpy(exe_path, "<none>");
+
+ strm.Printf("%starget #%u: %s", prefix_cstr ? prefix_cstr : "", target_idx,
+ exe_path);
+
+ uint32_t properties = 0;
+ if (target_arch.IsValid()) {
+ strm.Printf("%sarch=", properties++ > 0 ? ", " : " ( ");
+ target_arch.DumpTriple(strm);
+ properties++;
+ }
+ PlatformSP platform_sp(target->GetPlatform());
+ if (platform_sp)
+ strm.Printf("%splatform=%s", properties++ > 0 ? ", " : " ( ",
+ platform_sp->GetName().GetCString());
+
+ ProcessSP process_sp(target->GetProcessSP());
+ bool show_process_status = false;
+ if (process_sp) {
+ lldb::pid_t pid = process_sp->GetID();
+ StateType state = process_sp->GetState();
+ if (show_stopped_process_status)
+ show_process_status = StateIsStoppedState(state, true);
+ const char *state_cstr = StateAsCString(state);
+ if (pid != LLDB_INVALID_PROCESS_ID)
+ strm.Printf("%spid=%" PRIu64, properties++ > 0 ? ", " : " ( ", pid);
+ strm.Printf("%sstate=%s", properties++ > 0 ? ", " : " ( ", state_cstr);
+ }
+ if (properties > 0)
+ strm.PutCString(" )\n");
+ else
+ strm.EOL();
+ if (show_process_status) {
+ const bool only_threads_with_stop_reason = true;
+ const uint32_t start_frame = 0;
+ const uint32_t num_frames = 1;
+ const uint32_t num_frames_with_source = 1;
+ process_sp->GetStatus(strm);
+ process_sp->GetThreadStatus(strm, only_threads_with_stop_reason,
+ start_frame, num_frames,
+ num_frames_with_source);
+ }
}
-static uint32_t
-DumpTargetList (TargetList &target_list, bool show_stopped_process_status, Stream &strm)
-{
- const uint32_t num_targets = target_list.GetNumTargets();
- if (num_targets)
- {
- TargetSP selected_target_sp (target_list.GetSelectedTarget());
- strm.PutCString ("Current targets:\n");
- for (uint32_t i = 0; i < num_targets; ++i)
- {
- TargetSP target_sp (target_list.GetTargetAtIndex (i));
- if (target_sp)
- {
- bool is_selected = target_sp.get() == selected_target_sp.get();
- DumpTargetInfo (i,
- target_sp.get(),
- is_selected ? "* " : " ",
- show_stopped_process_status,
- strm);
- }
- }
+static uint32_t DumpTargetList(TargetList &target_list,
+ bool show_stopped_process_status, Stream &strm) {
+ const uint32_t num_targets = target_list.GetNumTargets();
+ if (num_targets) {
+ TargetSP selected_target_sp(target_list.GetSelectedTarget());
+ strm.PutCString("Current targets:\n");
+ for (uint32_t i = 0; i < num_targets; ++i) {
+ TargetSP target_sp(target_list.GetTargetAtIndex(i));
+ if (target_sp) {
+ bool is_selected = target_sp.get() == selected_target_sp.get();
+ DumpTargetInfo(i, target_sp.get(), is_selected ? "* " : " ",
+ show_stopped_process_status, strm);
+ }
}
- return num_targets;
+ }
+ return num_targets;
}
#pragma mark CommandObjectTargetCreate
@@ -149,312 +138,283 @@ DumpTargetList (TargetList &target_list,
// "target create"
//-------------------------------------------------------------------------
-class CommandObjectTargetCreate : public CommandObjectParsed
-{
+class CommandObjectTargetCreate : public CommandObjectParsed {
public:
- CommandObjectTargetCreate(CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "target create",
- "Create a target using the argument as the main executable.",
- nullptr),
- m_option_group (),
- m_arch_option (),
- m_core_file (LLDB_OPT_SET_1, false, "core", 'c', 0, eArgTypeFilename, "Fullpath to a core file to use for this target."),
- m_platform_path (LLDB_OPT_SET_1, false, "platform-path", 'P', 0, eArgTypePath, "Path to the remote file to use for this target."),
- m_symbol_file (LLDB_OPT_SET_1, false, "symfile", 's', 0, eArgTypeFilename, "Fullpath to a stand alone debug symbols file for when debug symbols are not in the executable."),
- m_remote_file (LLDB_OPT_SET_1, false, "remote-file", 'r', 0, eArgTypeFilename, "Fullpath to the file on the remote host if debugging remotely."),
- m_add_dependents (LLDB_OPT_SET_1, false, "no-dependents", 'd', "Don't load dependent files when creating the target, just add the specified executable.", true, true)
- {
- CommandArgumentEntry arg;
- CommandArgumentData file_arg;
-
- // Define the first (and only) variant of this arg.
- file_arg.arg_type = eArgTypeFilename;
- file_arg.arg_repetition = eArgRepeatPlain;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (file_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
-
- m_option_group.Append (&m_arch_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Append (&m_core_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Append (&m_platform_path, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Append (&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Append (&m_remote_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Append (&m_add_dependents, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Finalize();
- }
-
- ~CommandObjectTargetCreate() override = default;
-
- Options *
- GetOptions () override
- {
- return &m_option_group;
- }
-
- int
- HandleArgumentCompletion (Args &input,
- int &cursor_index,
- int &cursor_char_position,
- OptionElementVector &opt_element_vector,
- int match_start_point,
- int max_return_elements,
- bool &word_complete,
- StringList &matches) override
- {
- std::string completion_str (input.GetArgumentAtIndex(cursor_index));
- completion_str.erase (cursor_char_position);
-
- CommandCompletions::InvokeCommonCompletionCallbacks(GetCommandInterpreter(),
- CommandCompletions::eDiskFileCompletion,
- completion_str.c_str(),
- match_start_point,
- max_return_elements,
- nullptr,
- word_complete,
- matches);
- return matches.GetSize();
- }
+ CommandObjectTargetCreate(CommandInterpreter &interpreter)
+ : CommandObjectParsed(
+ interpreter, "target create",
+ "Create a target using the argument as the main executable.",
+ nullptr),
+ m_option_group(), m_arch_option(),
+ m_core_file(LLDB_OPT_SET_1, false, "core", 'c', 0, eArgTypeFilename,
+ "Fullpath to a core file to use for this target."),
+ m_platform_path(LLDB_OPT_SET_1, false, "platform-path", 'P', 0,
+ eArgTypePath,
+ "Path to the remote file to use for this target."),
+ m_symbol_file(LLDB_OPT_SET_1, false, "symfile", 's', 0,
+ eArgTypeFilename, "Fullpath to a stand alone debug "
+ "symbols file for when debug symbols "
+ "are not in the executable."),
+ m_remote_file(
+ LLDB_OPT_SET_1, false, "remote-file", 'r', 0, eArgTypeFilename,
+ "Fullpath to the file on the remote host if debugging remotely."),
+ m_add_dependents(LLDB_OPT_SET_1, false, "no-dependents", 'd',
+ "Don't load dependent files when creating the target, "
+ "just add the specified executable.",
+ true, true) {
+ CommandArgumentEntry arg;
+ CommandArgumentData file_arg;
+
+ // Define the first (and only) variant of this arg.
+ file_arg.arg_type = eArgTypeFilename;
+ file_arg.arg_repetition = eArgRepeatPlain;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(file_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+
+ m_option_group.Append(&m_arch_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Append(&m_core_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Append(&m_platform_path, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Append(&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Append(&m_remote_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Append(&m_add_dependents, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Finalize();
+ }
+
+ ~CommandObjectTargetCreate() override = default;
+
+ Options *GetOptions() override { return &m_option_group; }
+
+ int HandleArgumentCompletion(Args &input, int &cursor_index,
+ int &cursor_char_position,
+ OptionElementVector &opt_element_vector,
+ int match_start_point, int max_return_elements,
+ bool &word_complete,
+ StringList &matches) override {
+ std::string completion_str(input.GetArgumentAtIndex(cursor_index));
+ completion_str.erase(cursor_char_position);
+
+ CommandCompletions::InvokeCommonCompletionCallbacks(
+ GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
+ completion_str.c_str(), match_start_point, max_return_elements, nullptr,
+ word_complete, matches);
+ return matches.GetSize();
+ }
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- const size_t argc = command.GetArgumentCount();
- FileSpec core_file (m_core_file.GetOptionValue().GetCurrentValue());
- FileSpec remote_file (m_remote_file.GetOptionValue().GetCurrentValue());
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ const size_t argc = command.GetArgumentCount();
+ FileSpec core_file(m_core_file.GetOptionValue().GetCurrentValue());
+ FileSpec remote_file(m_remote_file.GetOptionValue().GetCurrentValue());
+
+ if (core_file) {
+ if (!core_file.Exists()) {
+ result.AppendErrorWithFormat("core file '%s' doesn't exist",
+ core_file.GetPath().c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ if (!core_file.Readable()) {
+ result.AppendErrorWithFormat("core file '%s' is not readable",
+ core_file.GetPath().c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
- if (core_file)
- {
- if (!core_file.Exists())
- {
- result.AppendErrorWithFormat("core file '%s' doesn't exist", core_file.GetPath().c_str());
- result.SetStatus (eReturnStatusFailed);
+ if (argc == 1 || core_file || remote_file) {
+ FileSpec symfile(m_symbol_file.GetOptionValue().GetCurrentValue());
+ if (symfile) {
+ if (symfile.Exists()) {
+ if (!symfile.Readable()) {
+ result.AppendErrorWithFormat("symbol file '%s' is not readable",
+ symfile.GetPath().c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ } else {
+ char symfile_path[PATH_MAX];
+ symfile.GetPath(symfile_path, sizeof(symfile_path));
+ result.AppendErrorWithFormat("invalid symbol file path '%s'",
+ symfile_path);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+
+ const char *file_path = command.GetArgumentAtIndex(0);
+ Timer scoped_timer(LLVM_PRETTY_FUNCTION, "(lldb) target create '%s'",
+ file_path);
+ FileSpec file_spec;
+
+ if (file_path)
+ file_spec.SetFile(file_path, true);
+
+ bool must_set_platform_path = false;
+
+ Debugger &debugger = m_interpreter.GetDebugger();
+
+ TargetSP target_sp;
+ const char *arch_cstr = m_arch_option.GetArchitectureName();
+ const bool get_dependent_files =
+ m_add_dependents.GetOptionValue().GetCurrentValue();
+ Error error(debugger.GetTargetList().CreateTarget(
+ debugger, file_path, arch_cstr, get_dependent_files, nullptr,
+ target_sp));
+
+ if (target_sp) {
+ // Only get the platform after we create the target because we might
+ // have
+ // switched platforms depending on what the arguments were to
+ // CreateTarget()
+ // we can't rely on the selected platform.
+
+ PlatformSP platform_sp = target_sp->GetPlatform();
+
+ if (remote_file) {
+ if (platform_sp) {
+ // I have a remote file.. two possible cases
+ if (file_spec && file_spec.Exists()) {
+ // if the remote file does not exist, push it there
+ if (!platform_sp->GetFileExists(remote_file)) {
+ Error err = platform_sp->PutFile(file_spec, remote_file);
+ if (err.Fail()) {
+ result.AppendError(err.AsCString());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+ } else {
+ // there is no local file and we need one
+ // in order to make the remote ---> local transfer we need a
+ // platform
+ // TODO: if the user has passed in a --platform argument, use it
+ // to fetch the right platform
+ if (!platform_sp) {
+ result.AppendError(
+ "unable to perform remote debugging without a platform");
+ result.SetStatus(eReturnStatusFailed);
return false;
-
- }
- if (!core_file.Readable())
- {
- result.AppendErrorWithFormat("core file '%s' is not readable", core_file.GetPath().c_str());
- result.SetStatus (eReturnStatusFailed);
+ }
+ if (file_path) {
+ // copy the remote file to the local file
+ Error err = platform_sp->GetFile(remote_file, file_spec);
+ if (err.Fail()) {
+ result.AppendError(err.AsCString());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ } else {
+ // make up a local file
+ result.AppendError("remote --> local transfer without local "
+ "path is not implemented yet");
+ result.SetStatus(eReturnStatusFailed);
return false;
+ }
}
+ } else {
+ result.AppendError("no platform found for target");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
}
- if (argc == 1 || core_file || remote_file)
- {
- FileSpec symfile (m_symbol_file.GetOptionValue().GetCurrentValue());
+ if (symfile || remote_file) {
+ ModuleSP module_sp(target_sp->GetExecutableModule());
+ if (module_sp) {
if (symfile)
- {
- if (symfile.Exists())
- {
- if (!symfile.Readable())
- {
- result.AppendErrorWithFormat("symbol file '%s' is not readable", symfile.GetPath().c_str());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- else
- {
- char symfile_path[PATH_MAX];
- symfile.GetPath(symfile_path, sizeof(symfile_path));
- result.AppendErrorWithFormat("invalid symbol file path '%s'", symfile_path);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
-
- const char *file_path = command.GetArgumentAtIndex(0);
- Timer scoped_timer(LLVM_PRETTY_FUNCTION, "(lldb) target create '%s'", file_path);
- FileSpec file_spec;
-
- if (file_path)
- file_spec.SetFile (file_path, true);
-
- bool must_set_platform_path = false;
-
- Debugger &debugger = m_interpreter.GetDebugger();
-
- TargetSP target_sp;
- const char *arch_cstr = m_arch_option.GetArchitectureName();
- const bool get_dependent_files = m_add_dependents.GetOptionValue().GetCurrentValue();
- Error error(debugger.GetTargetList().CreateTarget(debugger,
- file_path,
- arch_cstr,
- get_dependent_files,
- nullptr,
- target_sp));
-
- if (target_sp)
- {
- // Only get the platform after we create the target because we might have
- // switched platforms depending on what the arguments were to CreateTarget()
- // we can't rely on the selected platform.
-
- PlatformSP platform_sp = target_sp->GetPlatform();
-
- if (remote_file)
- {
- if (platform_sp)
- {
- // I have a remote file.. two possible cases
- if (file_spec && file_spec.Exists())
- {
- // if the remote file does not exist, push it there
- if (!platform_sp->GetFileExists (remote_file))
- {
- Error err = platform_sp->PutFile(file_spec, remote_file);
- if (err.Fail())
- {
- result.AppendError(err.AsCString());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- }
- else
- {
- // there is no local file and we need one
- // in order to make the remote ---> local transfer we need a platform
- // TODO: if the user has passed in a --platform argument, use it to fetch the right platform
- if (!platform_sp)
- {
- result.AppendError("unable to perform remote debugging without a platform");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- if (file_path)
- {
- // copy the remote file to the local file
- Error err = platform_sp->GetFile(remote_file, file_spec);
- if (err.Fail())
- {
- result.AppendError(err.AsCString());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- else
- {
- // make up a local file
- result.AppendError("remote --> local transfer without local path is not implemented yet");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- }
- else
- {
- result.AppendError("no platform found for target");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
-
- if (symfile || remote_file)
- {
- ModuleSP module_sp (target_sp->GetExecutableModule());
- if (module_sp)
- {
- if (symfile)
- module_sp->SetSymbolFileFileSpec(symfile);
- if (remote_file)
- {
- std::string remote_path = remote_file.GetPath();
- target_sp->SetArg0(remote_path.c_str());
- module_sp->SetPlatformFileSpec(remote_file);
- }
- }
- }
-
- debugger.GetTargetList().SetSelectedTarget(target_sp.get());
- if (must_set_platform_path)
- {
- ModuleSpec main_module_spec(file_spec);
- ModuleSP module_sp = target_sp->GetSharedModule(main_module_spec);
- if (module_sp)
- module_sp->SetPlatformFileSpec(remote_file);
- }
- if (core_file)
- {
- char core_path[PATH_MAX];
- core_file.GetPath(core_path, sizeof(core_path));
- if (core_file.Exists())
- {
- if (!core_file.Readable())
- {
- result.AppendMessageWithFormat ("Core file '%s' is not readable.\n", core_path);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- FileSpec core_file_dir;
- core_file_dir.GetDirectory() = core_file.GetDirectory();
- target_sp->GetExecutableSearchPaths ().Append (core_file_dir);
-
- ProcessSP process_sp(target_sp->CreateProcess(m_interpreter.GetDebugger().GetListener(), nullptr, &core_file));
-
- if (process_sp)
- {
- // Seems weird that we Launch a core file, but that is
- // what we do!
- error = process_sp->LoadCore();
-
- if (error.Fail())
- {
- result.AppendError(error.AsCString("can't find plug-in for core file"));
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- else
- {
- result.AppendMessageWithFormat ("Core file '%s' (%s) was loaded.\n", core_path, target_sp->GetArchitecture().GetArchitectureName());
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- }
- else
- {
- result.AppendErrorWithFormat ("Unable to find process plug-in for core file '%s'\n", core_path);
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- result.AppendErrorWithFormat ("Core file '%s' does not exist\n", core_path);
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- result.AppendMessageWithFormat ("Current executable set to '%s' (%s).\n", file_path, target_sp->GetArchitecture().GetArchitectureName());
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- }
- else
- {
- result.AppendError(error.AsCString());
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- result.AppendErrorWithFormat("'%s' takes exactly one executable path argument, or use the --core option.\n", m_cmd_name.c_str());
- result.SetStatus (eReturnStatusFailed);
- }
- return result.Succeeded();
+ module_sp->SetSymbolFileFileSpec(symfile);
+ if (remote_file) {
+ std::string remote_path = remote_file.GetPath();
+ target_sp->SetArg0(remote_path.c_str());
+ module_sp->SetPlatformFileSpec(remote_file);
+ }
+ }
+ }
+
+ debugger.GetTargetList().SetSelectedTarget(target_sp.get());
+ if (must_set_platform_path) {
+ ModuleSpec main_module_spec(file_spec);
+ ModuleSP module_sp = target_sp->GetSharedModule(main_module_spec);
+ if (module_sp)
+ module_sp->SetPlatformFileSpec(remote_file);
+ }
+ if (core_file) {
+ char core_path[PATH_MAX];
+ core_file.GetPath(core_path, sizeof(core_path));
+ if (core_file.Exists()) {
+ if (!core_file.Readable()) {
+ result.AppendMessageWithFormat(
+ "Core file '%s' is not readable.\n", core_path);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ FileSpec core_file_dir;
+ core_file_dir.GetDirectory() = core_file.GetDirectory();
+ target_sp->GetExecutableSearchPaths().Append(core_file_dir);
+
+ ProcessSP process_sp(target_sp->CreateProcess(
+ m_interpreter.GetDebugger().GetListener(), nullptr,
+ &core_file));
+
+ if (process_sp) {
+ // Seems weird that we Launch a core file, but that is
+ // what we do!
+ error = process_sp->LoadCore();
+
+ if (error.Fail()) {
+ result.AppendError(
+ error.AsCString("can't find plug-in for core file"));
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ } else {
+ result.AppendMessageWithFormat(
+ "Core file '%s' (%s) was loaded.\n", core_path,
+ target_sp->GetArchitecture().GetArchitectureName());
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ }
+ } else {
+ result.AppendErrorWithFormat(
+ "Unable to find process plug-in for core file '%s'\n",
+ core_path);
+ result.SetStatus(eReturnStatusFailed);
+ }
+ } else {
+ result.AppendErrorWithFormat("Core file '%s' does not exist\n",
+ core_path);
+ result.SetStatus(eReturnStatusFailed);
+ }
+ } else {
+ result.AppendMessageWithFormat(
+ "Current executable set to '%s' (%s).\n", file_path,
+ target_sp->GetArchitecture().GetArchitectureName());
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ }
+ } else {
+ result.AppendError(error.AsCString());
+ result.SetStatus(eReturnStatusFailed);
+ }
+ } else {
+ result.AppendErrorWithFormat("'%s' takes exactly one executable path "
+ "argument, or use the --core option.\n",
+ m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
}
+ return result.Succeeded();
+ }
private:
- OptionGroupOptions m_option_group;
- OptionGroupArchitecture m_arch_option;
- OptionGroupFile m_core_file;
- OptionGroupFile m_platform_path;
- OptionGroupFile m_symbol_file;
- OptionGroupFile m_remote_file;
- OptionGroupBoolean m_add_dependents;
+ OptionGroupOptions m_option_group;
+ OptionGroupArchitecture m_arch_option;
+ OptionGroupFile m_core_file;
+ OptionGroupFile m_platform_path;
+ OptionGroupFile m_symbol_file;
+ OptionGroupFile m_remote_file;
+ OptionGroupBoolean m_add_dependents;
};
#pragma mark CommandObjectTargetList
@@ -463,41 +423,33 @@ private:
// "target list"
//----------------------------------------------------------------------
-class CommandObjectTargetList : public CommandObjectParsed
-{
+class CommandObjectTargetList : public CommandObjectParsed {
public:
- CommandObjectTargetList (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "target list",
- "List all current targets in the current debug session.",
- nullptr)
- {
- }
+ CommandObjectTargetList(CommandInterpreter &interpreter)
+ : CommandObjectParsed(
+ interpreter, "target list",
+ "List all current targets in the current debug session.", nullptr) {
+ }
- ~CommandObjectTargetList() override = default;
+ ~CommandObjectTargetList() override = default;
protected:
- bool
- DoExecute (Args& args, CommandReturnObject &result) override
- {
- if (args.GetArgumentCount() == 0)
- {
- Stream &strm = result.GetOutputStream();
-
- bool show_stopped_process_status = false;
- if (DumpTargetList (m_interpreter.GetDebugger().GetTargetList(), show_stopped_process_status, strm) == 0)
- {
- strm.PutCString ("No targets.\n");
- }
- result.SetStatus (eReturnStatusSuccessFinishResult);
- }
- else
- {
- result.AppendError ("the 'target list' command takes no arguments\n");
- result.SetStatus (eReturnStatusFailed);
- }
- return result.Succeeded();
+ bool DoExecute(Args &args, CommandReturnObject &result) override {
+ if (args.GetArgumentCount() == 0) {
+ Stream &strm = result.GetOutputStream();
+
+ bool show_stopped_process_status = false;
+ if (DumpTargetList(m_interpreter.GetDebugger().GetTargetList(),
+ show_stopped_process_status, strm) == 0) {
+ strm.PutCString("No targets.\n");
+ }
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ } else {
+ result.AppendError("the 'target list' command takes no arguments\n");
+ result.SetStatus(eReturnStatusFailed);
}
+ return result.Succeeded();
+ }
};
#pragma mark CommandObjectTargetSelect
@@ -506,78 +458,63 @@ protected:
// "target select"
//----------------------------------------------------------------------
-class CommandObjectTargetSelect : public CommandObjectParsed
-{
+class CommandObjectTargetSelect : public CommandObjectParsed {
public:
- CommandObjectTargetSelect (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "target select",
- "Select a target as the current target by target index.",
- nullptr)
- {
- }
+ CommandObjectTargetSelect(CommandInterpreter &interpreter)
+ : CommandObjectParsed(
+ interpreter, "target select",
+ "Select a target as the current target by target index.", nullptr) {
+ }
- ~CommandObjectTargetSelect() override = default;
+ ~CommandObjectTargetSelect() override = default;
protected:
- bool
- DoExecute (Args& args, CommandReturnObject &result) override
- {
- if (args.GetArgumentCount() == 1)
- {
- bool success = false;
- const char *target_idx_arg = args.GetArgumentAtIndex(0);
- uint32_t target_idx = StringConvert::ToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
- if (success)
- {
- TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
- const uint32_t num_targets = target_list.GetNumTargets();
- if (target_idx < num_targets)
- {
- TargetSP target_sp (target_list.GetTargetAtIndex (target_idx));
- if (target_sp)
- {
- Stream &strm = result.GetOutputStream();
- target_list.SetSelectedTarget (target_sp.get());
- bool show_stopped_process_status = false;
- DumpTargetList (target_list, show_stopped_process_status, strm);
- result.SetStatus (eReturnStatusSuccessFinishResult);
- }
- else
- {
- result.AppendErrorWithFormat ("target #%u is NULL in target list\n", target_idx);
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- if (num_targets > 0)
- {
- result.AppendErrorWithFormat ("index %u is out of range, valid target indexes are 0 - %u\n",
- target_idx,
- num_targets - 1);
- }
- else
- {
- result.AppendErrorWithFormat ("index %u is out of range since there are no active targets\n",
- target_idx);
- }
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- result.AppendErrorWithFormat("invalid index string value '%s'\n", target_idx_arg);
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- result.AppendError ("'target select' takes a single argument: a target index\n");
- result.SetStatus (eReturnStatusFailed);
- }
- return result.Succeeded();
+ bool DoExecute(Args &args, CommandReturnObject &result) override {
+ if (args.GetArgumentCount() == 1) {
+ bool success = false;
+ const char *target_idx_arg = args.GetArgumentAtIndex(0);
+ uint32_t target_idx =
+ StringConvert::ToUInt32(target_idx_arg, UINT32_MAX, 0, &success);
+ if (success) {
+ TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
+ const uint32_t num_targets = target_list.GetNumTargets();
+ if (target_idx < num_targets) {
+ TargetSP target_sp(target_list.GetTargetAtIndex(target_idx));
+ if (target_sp) {
+ Stream &strm = result.GetOutputStream();
+ target_list.SetSelectedTarget(target_sp.get());
+ bool show_stopped_process_status = false;
+ DumpTargetList(target_list, show_stopped_process_status, strm);
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ } else {
+ result.AppendErrorWithFormat("target #%u is NULL in target list\n",
+ target_idx);
+ result.SetStatus(eReturnStatusFailed);
+ }
+ } else {
+ if (num_targets > 0) {
+ result.AppendErrorWithFormat(
+ "index %u is out of range, valid target indexes are 0 - %u\n",
+ target_idx, num_targets - 1);
+ } else {
+ result.AppendErrorWithFormat(
+ "index %u is out of range since there are no active targets\n",
+ target_idx);
+ }
+ result.SetStatus(eReturnStatusFailed);
+ }
+ } else {
+ result.AppendErrorWithFormat("invalid index string value '%s'\n",
+ target_idx_arg);
+ result.SetStatus(eReturnStatusFailed);
+ }
+ } else {
+ result.AppendError(
+ "'target select' takes a single argument: a target index\n");
+ result.SetStatus(eReturnStatusFailed);
}
+ return result.Succeeded();
+ }
};
#pragma mark CommandObjectTargetSelect
@@ -586,130 +523,114 @@ protected:
// "target delete"
//----------------------------------------------------------------------
-class CommandObjectTargetDelete : public CommandObjectParsed
-{
+class CommandObjectTargetDelete : public CommandObjectParsed {
public:
- CommandObjectTargetDelete (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "target delete",
+ CommandObjectTargetDelete(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "target delete",
"Delete one or more targets by target index.",
nullptr),
- m_option_group(),
- m_all_option(LLDB_OPT_SET_1, false, "all", 'a', "Delete all targets.", false, true),
+ m_option_group(), m_all_option(LLDB_OPT_SET_1, false, "all", 'a',
+ "Delete all targets.", false, true),
m_cleanup_option(
- LLDB_OPT_SET_1,
- false,
- "clean", 'c',
- "Perform extra cleanup to minimize memory consumption after deleting the target. "
- "By default, LLDB will keep in memory any modules previously loaded by the target as well "
- "as all of its debug info. Specifying --clean will unload all of these shared modules and "
+ LLDB_OPT_SET_1, false, "clean", 'c',
+ "Perform extra cleanup to minimize memory consumption after "
+ "deleting the target. "
+ "By default, LLDB will keep in memory any modules previously "
+ "loaded by the target as well "
+ "as all of its debug info. Specifying --clean will unload all of "
+ "these shared modules and "
"cause them to be reparsed again the next time the target is run",
- false, true)
- {
- m_option_group.Append(&m_all_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Append(&m_cleanup_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Finalize();
- }
-
- ~CommandObjectTargetDelete() override = default;
-
- Options *
- GetOptions () override
- {
- return &m_option_group;
- }
+ false, true) {
+ m_option_group.Append(&m_all_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Append(&m_cleanup_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Finalize();
+ }
-protected:
- bool
- DoExecute (Args& args, CommandReturnObject &result) override
- {
- const size_t argc = args.GetArgumentCount();
- std::vector<TargetSP> delete_target_list;
- TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
- TargetSP target_sp;
+ ~CommandObjectTargetDelete() override = default;
- if (m_all_option.GetOptionValue())
- {
- for (int i = 0; i < target_list.GetNumTargets(); ++i)
- delete_target_list.push_back(target_list.GetTargetAtIndex(i));
- }
- else if (argc > 0)
- {
- const uint32_t num_targets = target_list.GetNumTargets();
- // Bail out if don't have any targets.
- if (num_targets == 0) {
- result.AppendError("no targets to delete");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
+ Options *GetOptions() override { return &m_option_group; }
- for (uint32_t arg_idx = 0; arg_idx < argc; ++arg_idx)
- {
- const char *target_idx_arg = args.GetArgumentAtIndex(arg_idx);
- bool success = false;
- uint32_t target_idx = StringConvert::ToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
- if (!success)
- {
- result.AppendErrorWithFormat("invalid target index '%s'\n", target_idx_arg);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- if (target_idx < num_targets)
- {
- target_sp = target_list.GetTargetAtIndex (target_idx);
- if (target_sp)
- {
- delete_target_list.push_back (target_sp);
- continue;
- }
- }
- if (num_targets > 1)
- result.AppendErrorWithFormat ("target index %u is out of range, valid target indexes are 0 - %u\n",
- target_idx,
- num_targets - 1);
- else
- result.AppendErrorWithFormat("target index %u is out of range, the only valid index is 0\n",
- target_idx);
+protected:
+ bool DoExecute(Args &args, CommandReturnObject &result) override {
+ const size_t argc = args.GetArgumentCount();
+ std::vector<TargetSP> delete_target_list;
+ TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
+ TargetSP target_sp;
+
+ if (m_all_option.GetOptionValue()) {
+ for (int i = 0; i < target_list.GetNumTargets(); ++i)
+ delete_target_list.push_back(target_list.GetTargetAtIndex(i));
+ } else if (argc > 0) {
+ const uint32_t num_targets = target_list.GetNumTargets();
+ // Bail out if don't have any targets.
+ if (num_targets == 0) {
+ result.AppendError("no targets to delete");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
+ for (uint32_t arg_idx = 0; arg_idx < argc; ++arg_idx) {
+ const char *target_idx_arg = args.GetArgumentAtIndex(arg_idx);
+ bool success = false;
+ uint32_t target_idx =
+ StringConvert::ToUInt32(target_idx_arg, UINT32_MAX, 0, &success);
+ if (!success) {
+ result.AppendErrorWithFormat("invalid target index '%s'\n",
+ target_idx_arg);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ if (target_idx < num_targets) {
+ target_sp = target_list.GetTargetAtIndex(target_idx);
+ if (target_sp) {
+ delete_target_list.push_back(target_sp);
+ continue;
+ }
+ }
+ if (num_targets > 1)
+ result.AppendErrorWithFormat("target index %u is out of range, valid "
+ "target indexes are 0 - %u\n",
+ target_idx, num_targets - 1);
else
- {
- target_sp = target_list.GetSelectedTarget();
- if (!target_sp)
- {
- result.AppendErrorWithFormat("no target is currently selected\n");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- delete_target_list.push_back (target_sp);
- }
-
- const size_t num_targets_to_delete = delete_target_list.size();
- for (size_t idx = 0; idx < num_targets_to_delete; ++idx)
- {
- target_sp = delete_target_list[idx];
- target_list.DeleteTarget(target_sp);
- target_sp->Destroy();
- }
- // If "--clean" was specified, prune any orphaned shared modules from
- // the global shared module list
- if (m_cleanup_option.GetOptionValue ())
- {
- const bool mandatory = true;
- ModuleList::RemoveOrphanSharedModules(mandatory);
- }
- result.GetOutputStream().Printf("%u targets deleted.\n", (uint32_t)num_targets_to_delete);
- result.SetStatus(eReturnStatusSuccessFinishResult);
+ result.AppendErrorWithFormat(
+ "target index %u is out of range, the only valid index is 0\n",
+ target_idx);
- return true;
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ } else {
+ target_sp = target_list.GetSelectedTarget();
+ if (!target_sp) {
+ result.AppendErrorWithFormat("no target is currently selected\n");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ delete_target_list.push_back(target_sp);
}
- OptionGroupOptions m_option_group;
- OptionGroupBoolean m_all_option;
- OptionGroupBoolean m_cleanup_option;
+ const size_t num_targets_to_delete = delete_target_list.size();
+ for (size_t idx = 0; idx < num_targets_to_delete; ++idx) {
+ target_sp = delete_target_list[idx];
+ target_list.DeleteTarget(target_sp);
+ target_sp->Destroy();
+ }
+ // If "--clean" was specified, prune any orphaned shared modules from
+ // the global shared module list
+ if (m_cleanup_option.GetOptionValue()) {
+ const bool mandatory = true;
+ ModuleList::RemoveOrphanSharedModules(mandatory);
+ }
+ result.GetOutputStream().Printf("%u targets deleted.\n",
+ (uint32_t)num_targets_to_delete);
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+
+ return true;
+ }
+
+ OptionGroupOptions m_option_group;
+ OptionGroupBoolean m_all_option;
+ OptionGroupBoolean m_cleanup_option;
};
#pragma mark CommandObjectTargetVariable
@@ -718,1308 +639,1138 @@ protected:
// "target variable"
//----------------------------------------------------------------------
-class CommandObjectTargetVariable : public CommandObjectParsed
-{
- static const uint32_t SHORT_OPTION_FILE = 0x66696c65; // 'file'
- static const uint32_t SHORT_OPTION_SHLB = 0x73686c62; // 'shlb'
+class CommandObjectTargetVariable : public CommandObjectParsed {
+ static const uint32_t SHORT_OPTION_FILE = 0x66696c65; // 'file'
+ static const uint32_t SHORT_OPTION_SHLB = 0x73686c62; // 'shlb'
public:
- CommandObjectTargetVariable(CommandInterpreter &interpreter)
- : CommandObjectParsed(interpreter, "target variable",
- "Read global variables for the current target, before or while running a process.",
- nullptr, eCommandRequiresTarget),
- m_option_group(),
- m_option_variable(false), // Don't include frame options
- m_option_format(eFormatDefault),
- m_option_compile_units(LLDB_OPT_SET_1, false, "file", SHORT_OPTION_FILE, 0, eArgTypeFilename,
- "A basename or fullpath to a file that contains global variables. This option can be "
- "specified multiple times."),
- m_option_shared_libraries(LLDB_OPT_SET_1, false, "shlib", SHORT_OPTION_SHLB, 0, eArgTypeFilename,
- "A basename or fullpath to a shared library to use in the search for global "
- "variables. This option can be specified multiple times."),
- m_varobj_options()
- {
- CommandArgumentEntry arg;
- CommandArgumentData var_name_arg;
-
- // Define the first (and only) variant of this arg.
- var_name_arg.arg_type = eArgTypeVarName;
- var_name_arg.arg_repetition = eArgRepeatPlus;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (var_name_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
-
- m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Append (&m_option_format, OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_GDB_FMT, LLDB_OPT_SET_1);
- m_option_group.Append (&m_option_compile_units, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Append (&m_option_shared_libraries, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Finalize();
- }
-
- ~CommandObjectTargetVariable() override = default;
-
- void
- DumpValueObject (Stream &s, VariableSP &var_sp, ValueObjectSP &valobj_sp, const char *root_name)
- {
- DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions());
-
- if (!valobj_sp->GetTargetSP()->GetDisplayRuntimeSupportValues() &&
- valobj_sp->IsRuntimeSupportValue())
- return;
-
- switch (var_sp->GetScope())
- {
- case eValueTypeVariableGlobal:
- if (m_option_variable.show_scope)
- s.PutCString("GLOBAL: ");
- break;
-
- case eValueTypeVariableStatic:
- if (m_option_variable.show_scope)
- s.PutCString("STATIC: ");
- break;
-
- case eValueTypeVariableArgument:
- if (m_option_variable.show_scope)
- s.PutCString(" ARG: ");
- break;
-
- case eValueTypeVariableLocal:
- if (m_option_variable.show_scope)
- s.PutCString(" LOCAL: ");
- break;
+ CommandObjectTargetVariable(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "target variable",
+ "Read global variables for the current target, "
+ "before or while running a process.",
+ nullptr, eCommandRequiresTarget),
+ m_option_group(),
+ m_option_variable(false), // Don't include frame options
+ m_option_format(eFormatDefault),
+ m_option_compile_units(LLDB_OPT_SET_1, false, "file", SHORT_OPTION_FILE,
+ 0, eArgTypeFilename,
+ "A basename or fullpath to a file that contains "
+ "global variables. This option can be "
+ "specified multiple times."),
+ m_option_shared_libraries(
+ LLDB_OPT_SET_1, false, "shlib", SHORT_OPTION_SHLB, 0,
+ eArgTypeFilename,
+ "A basename or fullpath to a shared library to use in the search "
+ "for global "
+ "variables. This option can be specified multiple times."),
+ m_varobj_options() {
+ CommandArgumentEntry arg;
+ CommandArgumentData var_name_arg;
+
+ // Define the first (and only) variant of this arg.
+ var_name_arg.arg_type = eArgTypeVarName;
+ var_name_arg.arg_repetition = eArgRepeatPlus;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(var_name_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+
+ m_option_group.Append(&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Append(&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Append(&m_option_format,
+ OptionGroupFormat::OPTION_GROUP_FORMAT |
+ OptionGroupFormat::OPTION_GROUP_GDB_FMT,
+ LLDB_OPT_SET_1);
+ m_option_group.Append(&m_option_compile_units, LLDB_OPT_SET_ALL,
+ LLDB_OPT_SET_1);
+ m_option_group.Append(&m_option_shared_libraries, LLDB_OPT_SET_ALL,
+ LLDB_OPT_SET_1);
+ m_option_group.Finalize();
+ }
+
+ ~CommandObjectTargetVariable() override = default;
+
+ void DumpValueObject(Stream &s, VariableSP &var_sp, ValueObjectSP &valobj_sp,
+ const char *root_name) {
+ DumpValueObjectOptions options(m_varobj_options.GetAsDumpOptions());
+
+ if (!valobj_sp->GetTargetSP()->GetDisplayRuntimeSupportValues() &&
+ valobj_sp->IsRuntimeSupportValue())
+ return;
+
+ switch (var_sp->GetScope()) {
+ case eValueTypeVariableGlobal:
+ if (m_option_variable.show_scope)
+ s.PutCString("GLOBAL: ");
+ break;
+
+ case eValueTypeVariableStatic:
+ if (m_option_variable.show_scope)
+ s.PutCString("STATIC: ");
+ break;
+
+ case eValueTypeVariableArgument:
+ if (m_option_variable.show_scope)
+ s.PutCString(" ARG: ");
+ break;
+
+ case eValueTypeVariableLocal:
+ if (m_option_variable.show_scope)
+ s.PutCString(" LOCAL: ");
+ break;
+
+ case eValueTypeVariableThreadLocal:
+ if (m_option_variable.show_scope)
+ s.PutCString("THREAD: ");
+ break;
+
+ default:
+ break;
+ }
+
+ if (m_option_variable.show_decl) {
+ bool show_fullpaths = false;
+ bool show_module = true;
+ if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
+ s.PutCString(": ");
+ }
+
+ const Format format = m_option_format.GetFormat();
+ if (format != eFormatDefault)
+ options.SetFormat(format);
+
+ options.SetRootValueObjectName(root_name);
+
+ valobj_sp->Dump(s, options);
+ }
+
+ static size_t GetVariableCallback(void *baton, const char *name,
+ VariableList &variable_list) {
+ Target *target = static_cast<Target *>(baton);
+ if (target) {
+ return target->GetImages().FindGlobalVariables(ConstString(name), true,
+ UINT32_MAX, variable_list);
+ }
+ return 0;
+ }
- case eValueTypeVariableThreadLocal:
- if (m_option_variable.show_scope)
- s.PutCString("THREAD: ");
- break;
+ Options *GetOptions() override { return &m_option_group; }
- default:
- break;
+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());
+ }
+
+ 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));
+
+ if (valobj_sp)
+ DumpValueObject(s, var_sp, valobj_sp,
+ var_sp->GetName().GetCString());
+ }
+ }
+ }
+ }
+
+ bool DoExecute(Args &args, CommandReturnObject &result) override {
+ Target *target = m_exe_ctx.GetTargetPtr();
+ const size_t argc = args.GetArgumentCount();
+ Stream &s = result.GetOutputStream();
+
+ if (argc > 0) {
+
+ for (size_t idx = 0; idx < argc; ++idx) {
+ VariableList variable_list;
+ ValueObjectList valobj_list;
+
+ const char *arg = args.GetArgumentAtIndex(idx);
+ size_t matches = 0;
+ bool use_var_name = false;
+ if (m_option_variable.use_regex) {
+ RegularExpression regex(arg);
+ if (!regex.IsValid()) {
+ result.GetErrorStream().Printf(
+ "error: invalid regular expression: '%s'\n", arg);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ use_var_name = true;
+ matches = target->GetImages().FindGlobalVariables(
+ regex, true, UINT32_MAX, variable_list);
+ } else {
+ Error error(Variable::GetValuesForVariableExpressionPath(
+ arg, m_exe_ctx.GetBestExecutionContextScope(),
+ GetVariableCallback, target, variable_list, valobj_list));
+ matches = variable_list.GetSize();
+ }
+
+ if (matches == 0) {
+ result.GetErrorStream().Printf(
+ "error: can't find global variable '%s'\n", arg);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ } else {
+ for (uint32_t global_idx = 0; global_idx < matches; ++global_idx) {
+ VariableSP var_sp(variable_list.GetVariableAtIndex(global_idx));
+ if (var_sp) {
+ ValueObjectSP valobj_sp(
+ valobj_list.GetValueObjectAtIndex(global_idx));
+ if (!valobj_sp)
+ valobj_sp = ValueObjectVariable::Create(
+ m_exe_ctx.GetBestExecutionContextScope(), var_sp);
+
+ if (valobj_sp)
+ DumpValueObject(s, var_sp, valobj_sp,
+ use_var_name ? var_sp->GetName().GetCString()
+ : arg);
+ }
+ }
+ }
+ }
+ } else {
+ const FileSpecList &compile_units =
+ m_option_compile_units.GetOptionValue().GetCurrentValue();
+ const FileSpecList &shlibs =
+ m_option_shared_libraries.GetOptionValue().GetCurrentValue();
+ SymbolContextList sc_list;
+ const size_t num_compile_units = compile_units.GetSize();
+ const size_t num_shlibs = shlibs.GetSize();
+ if (num_compile_units == 0 && num_shlibs == 0) {
+ bool success = false;
+ StackFrame *frame = m_exe_ctx.GetFramePtr();
+ CompileUnit *comp_unit = nullptr;
+ if (frame) {
+ SymbolContext sc = frame->GetSymbolContext(eSymbolContextCompUnit);
+ if (sc.comp_unit) {
+ const bool can_create = true;
+ VariableListSP comp_unit_varlist_sp(
+ sc.comp_unit->GetVariableList(can_create));
+ if (comp_unit_varlist_sp) {
+ size_t count = comp_unit_varlist_sp->GetSize();
+ if (count > 0) {
+ DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp, s);
+ success = true;
+ }
+ }
+ }
+ }
+ if (!success) {
+ if (frame) {
+ if (comp_unit)
+ result.AppendErrorWithFormat(
+ "no global variables in current compile unit: %s\n",
+ comp_unit->GetPath().c_str());
+ else
+ result.AppendErrorWithFormat(
+ "no debug information for frame %u\n",
+ frame->GetFrameIndex());
+ } else
+ result.AppendError("'target variable' takes one or more global "
+ "variable names as arguments\n");
+ result.SetStatus(eReturnStatusFailed);
}
-
- if (m_option_variable.show_decl)
- {
- bool show_fullpaths = false;
- bool show_module = true;
- if (var_sp->DumpDeclaration(&s, show_fullpaths, show_module))
- s.PutCString (": ");
+ } else {
+ SymbolContextList sc_list;
+ const bool append = true;
+ // We have one or more compile unit or shlib
+ if (num_shlibs > 0) {
+ for (size_t shlib_idx = 0; shlib_idx < num_shlibs; ++shlib_idx) {
+ const FileSpec module_file(shlibs.GetFileSpecAtIndex(shlib_idx));
+ ModuleSpec module_spec(module_file);
+
+ ModuleSP module_sp(
+ target->GetImages().FindFirstModule(module_spec));
+ if (module_sp) {
+ if (num_compile_units > 0) {
+ for (size_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
+ module_sp->FindCompileUnits(
+ compile_units.GetFileSpecAtIndex(cu_idx), append,
+ sc_list);
+ } else {
+ SymbolContext sc;
+ sc.module_sp = module_sp;
+ sc_list.Append(sc);
+ }
+ } else {
+ // Didn't find matching shlib/module in target...
+ result.AppendErrorWithFormat(
+ "target doesn't contain the specified shared library: %s\n",
+ module_file.GetPath().c_str());
+ }
+ }
+ } else {
+ // No shared libraries, we just want to find globals for the compile
+ // units files that were specified
+ for (size_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
+ target->GetImages().FindCompileUnits(
+ compile_units.GetFileSpecAtIndex(cu_idx), append, sc_list);
+ }
+
+ const uint32_t num_scs = sc_list.GetSize();
+ if (num_scs > 0) {
+ SymbolContext sc;
+ for (uint32_t sc_idx = 0; sc_idx < num_scs; ++sc_idx) {
+ if (sc_list.GetContextAtIndex(sc_idx, sc)) {
+ if (sc.comp_unit) {
+ const bool can_create = true;
+ VariableListSP comp_unit_varlist_sp(
+ sc.comp_unit->GetVariableList(can_create));
+ if (comp_unit_varlist_sp)
+ DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp,
+ s);
+ } else if (sc.module_sp) {
+ // Get all global variables for this module
+ lldb_private::RegularExpression all_globals_regex(
+ "."); // Any global with at least one character
+ VariableList variable_list;
+ sc.module_sp->FindGlobalVariables(all_globals_regex, append,
+ UINT32_MAX, variable_list);
+ DumpGlobalVariableList(m_exe_ctx, sc, variable_list, s);
+ }
+ }
+ }
}
-
- const Format format = m_option_format.GetFormat();
- if (format != eFormatDefault)
- options.SetFormat(format);
-
- options.SetRootValueObjectName(root_name);
-
- valobj_sp->Dump(s,options);
+ }
}
- static size_t GetVariableCallback (void *baton,
- const char *name,
- VariableList &variable_list)
- {
- Target *target = static_cast<Target *>(baton);
- if (target)
- {
- return target->GetImages().FindGlobalVariables (ConstString(name),
- true,
- UINT32_MAX,
- variable_list);
- }
- return 0;
- }
-
- Options *
- GetOptions () override
- {
- return &m_option_group;
+ if (m_interpreter.TruncationWarningNecessary()) {
+ result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
+ m_cmd_name.c_str());
+ m_interpreter.TruncationWarningGiven();
}
-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());
- }
-
- 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));
+ return result.Succeeded();
+ }
- if (valobj_sp)
- DumpValueObject (s, var_sp, valobj_sp, var_sp->GetName().GetCString());
- }
- }
- }
- }
+ OptionGroupOptions m_option_group;
+ OptionGroupVariable m_option_variable;
+ OptionGroupFormat m_option_format;
+ OptionGroupFileList m_option_compile_units;
+ OptionGroupFileList m_option_shared_libraries;
+ OptionGroupValueObjectDisplay m_varobj_options;
+};
- bool
- DoExecute (Args& args, CommandReturnObject &result) override
- {
- Target *target = m_exe_ctx.GetTargetPtr();
- const size_t argc = args.GetArgumentCount();
- Stream &s = result.GetOutputStream();
+#pragma mark CommandObjectTargetModulesSearchPathsAdd
- if (argc > 0)
- {
+class CommandObjectTargetModulesSearchPathsAdd : public CommandObjectParsed {
+public:
+ CommandObjectTargetModulesSearchPathsAdd(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "target modules search-paths add",
+ "Add new image search paths substitution pairs to "
+ "the current target.",
+ nullptr) {
+ CommandArgumentEntry arg;
+ CommandArgumentData old_prefix_arg;
+ CommandArgumentData new_prefix_arg;
+
+ // Define the first variant of this arg pair.
+ old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
+ old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
+
+ // Define the first variant of this arg pair.
+ new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
+ new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
+
+ // There are two required arguments that must always occur together, i.e. an
+ // argument "pair". Because they
+ // must always occur together, they are treated as two variants of one
+ // argument rather than two independent
+ // arguments. Push them both into the first argument position for
+ // m_arguments...
- for (size_t idx = 0; idx < argc; ++idx)
- {
- VariableList variable_list;
- ValueObjectList valobj_list;
+ arg.push_back(old_prefix_arg);
+ arg.push_back(new_prefix_arg);
- const char *arg = args.GetArgumentAtIndex(idx);
- size_t matches = 0;
- bool use_var_name = false;
- if (m_option_variable.use_regex)
- {
- RegularExpression regex(arg);
- if (!regex.IsValid ())
- {
- result.GetErrorStream().Printf ("error: invalid regular expression: '%s'\n", arg);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- use_var_name = true;
- matches = target->GetImages().FindGlobalVariables (regex,
- true,
- UINT32_MAX,
- variable_list);
- }
- else
- {
- Error error (Variable::GetValuesForVariableExpressionPath (arg,
- m_exe_ctx.GetBestExecutionContextScope(),
- GetVariableCallback,
- target,
- variable_list,
- valobj_list));
- matches = variable_list.GetSize();
- }
+ m_arguments.push_back(arg);
+ }
- if (matches == 0)
- {
- result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", arg);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- else
- {
- for (uint32_t global_idx=0; global_idx<matches; ++global_idx)
- {
- VariableSP var_sp (variable_list.GetVariableAtIndex(global_idx));
- if (var_sp)
- {
- ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(global_idx));
- if (!valobj_sp)
- valobj_sp = ValueObjectVariable::Create (m_exe_ctx.GetBestExecutionContextScope(), var_sp);
+ ~CommandObjectTargetModulesSearchPathsAdd() override = default;
- if (valobj_sp)
- DumpValueObject (s, var_sp, valobj_sp, use_var_name ? var_sp->GetName().GetCString() : arg);
- }
- }
- }
- }
- }
- else
- {
- const FileSpecList &compile_units = m_option_compile_units.GetOptionValue().GetCurrentValue();
- const FileSpecList &shlibs = m_option_shared_libraries.GetOptionValue().GetCurrentValue();
- SymbolContextList sc_list;
- const size_t num_compile_units = compile_units.GetSize();
- const size_t num_shlibs = shlibs.GetSize();
- if (num_compile_units == 0 && num_shlibs == 0)
- {
- bool success = false;
- StackFrame *frame = m_exe_ctx.GetFramePtr();
- CompileUnit *comp_unit = nullptr;
- if (frame)
- {
- SymbolContext sc = frame->GetSymbolContext (eSymbolContextCompUnit);
- if (sc.comp_unit)
- {
- const bool can_create = true;
- VariableListSP comp_unit_varlist_sp (sc.comp_unit->GetVariableList(can_create));
- if (comp_unit_varlist_sp)
- {
- size_t count = comp_unit_varlist_sp->GetSize();
- if (count > 0)
- {
- DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp, s);
- success = true;
- }
- }
- }
- }
- if (!success)
- {
- if (frame)
- {
- if (comp_unit)
- result.AppendErrorWithFormat ("no global variables in current compile unit: %s\n",
- comp_unit->GetPath().c_str());
- else
- result.AppendErrorWithFormat ("no debug information for frame %u\n", frame->GetFrameIndex());
- }
- else
- result.AppendError ("'target variable' takes one or more global variable names as arguments\n");
- result.SetStatus (eReturnStatusFailed);
- }
- }
+protected:
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target) {
+ const size_t argc = command.GetArgumentCount();
+ if (argc & 1) {
+ result.AppendError("add requires an even number of arguments\n");
+ result.SetStatus(eReturnStatusFailed);
+ } else {
+ for (size_t i = 0; i < argc; i += 2) {
+ const char *from = command.GetArgumentAtIndex(i);
+ const char *to = command.GetArgumentAtIndex(i + 1);
+
+ if (from[0] && to[0]) {
+ Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
+ if (log) {
+ log->Printf("target modules search path adding ImageSearchPath "
+ "pair: '%s' -> '%s'",
+ from, to);
+ }
+ bool last_pair = ((argc - i) == 2);
+ target->GetImageSearchPathList().Append(
+ ConstString(from), ConstString(to),
+ last_pair); // Notify if this is the last pair
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ } else {
+ if (from[0])
+ result.AppendError("<path-prefix> can't be empty\n");
else
- {
- SymbolContextList sc_list;
- const bool append = true;
- // We have one or more compile unit or shlib
- if (num_shlibs > 0)
- {
- for (size_t shlib_idx=0; shlib_idx<num_shlibs; ++shlib_idx)
- {
- const FileSpec module_file(shlibs.GetFileSpecAtIndex(shlib_idx));
- ModuleSpec module_spec (module_file);
-
- ModuleSP module_sp (target->GetImages().FindFirstModule(module_spec));
- if (module_sp)
- {
- if (num_compile_units > 0)
- {
- for (size_t cu_idx=0; cu_idx<num_compile_units; ++cu_idx)
- module_sp->FindCompileUnits(compile_units.GetFileSpecAtIndex(cu_idx), append, sc_list);
- }
- else
- {
- SymbolContext sc;
- sc.module_sp = module_sp;
- sc_list.Append(sc);
- }
- }
- else
- {
- // Didn't find matching shlib/module in target...
- result.AppendErrorWithFormat ("target doesn't contain the specified shared library: %s\n",
- module_file.GetPath().c_str());
- }
- }
- }
- else
- {
- // No shared libraries, we just want to find globals for the compile units files that were specified
- for (size_t cu_idx=0; cu_idx<num_compile_units; ++cu_idx)
- target->GetImages().FindCompileUnits(compile_units.GetFileSpecAtIndex(cu_idx), append, sc_list);
- }
-
- const uint32_t num_scs = sc_list.GetSize();
- if (num_scs > 0)
- {
- SymbolContext sc;
- for (uint32_t sc_idx=0; sc_idx<num_scs; ++sc_idx)
- {
- if (sc_list.GetContextAtIndex(sc_idx, sc))
- {
- if (sc.comp_unit)
- {
- const bool can_create = true;
- VariableListSP comp_unit_varlist_sp (sc.comp_unit->GetVariableList(can_create));
- if (comp_unit_varlist_sp)
- DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp, s);
- }
- else if (sc.module_sp)
- {
- // Get all global variables for this module
- lldb_private::RegularExpression all_globals_regex("."); // Any global with at least one character
- VariableList variable_list;
- sc.module_sp->FindGlobalVariables(all_globals_regex, append, UINT32_MAX, variable_list);
- DumpGlobalVariableList(m_exe_ctx, sc, variable_list, s);
- }
- }
- }
- }
- }
- }
-
- if (m_interpreter.TruncationWarningNecessary())
- {
- result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
- m_cmd_name.c_str());
- m_interpreter.TruncationWarningGiven();
+ result.AppendError("<new-path-prefix> can't be empty\n");
+ result.SetStatus(eReturnStatusFailed);
+ }
}
-
- return result.Succeeded();
+ }
+ } else {
+ result.AppendError("invalid target\n");
+ result.SetStatus(eReturnStatusFailed);
}
-
- OptionGroupOptions m_option_group;
- OptionGroupVariable m_option_variable;
- OptionGroupFormat m_option_format;
- OptionGroupFileList m_option_compile_units;
- OptionGroupFileList m_option_shared_libraries;
- OptionGroupValueObjectDisplay m_varobj_options;
+ return result.Succeeded();
+ }
};
-#pragma mark CommandObjectTargetModulesSearchPathsAdd
+#pragma mark CommandObjectTargetModulesSearchPathsClear
-class CommandObjectTargetModulesSearchPathsAdd : public CommandObjectParsed
-{
+class CommandObjectTargetModulesSearchPathsClear : public CommandObjectParsed {
public:
- CommandObjectTargetModulesSearchPathsAdd (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "target modules search-paths add",
- "Add new image search paths substitution pairs to the current target.",
- nullptr)
- {
- CommandArgumentEntry arg;
- CommandArgumentData old_prefix_arg;
- CommandArgumentData new_prefix_arg;
-
- // Define the first variant of this arg pair.
- old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
- old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
-
- // Define the first variant of this arg pair.
- new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
- new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
-
- // There are two required arguments that must always occur together, i.e. an argument "pair". Because they
- // must always occur together, they are treated as two variants of one argument rather than two independent
- // arguments. Push them both into the first argument position for m_arguments...
+ CommandObjectTargetModulesSearchPathsClear(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "target modules search-paths clear",
+ "Clear all current image search path substitution "
+ "pairs from the current target.",
+ "target modules search-paths clear") {}
- arg.push_back (old_prefix_arg);
- arg.push_back (new_prefix_arg);
+ ~CommandObjectTargetModulesSearchPathsClear() override = default;
- m_arguments.push_back (arg);
+protected:
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target) {
+ bool notify = true;
+ target->GetImageSearchPathList().Clear(notify);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ } else {
+ result.AppendError("invalid target\n");
+ result.SetStatus(eReturnStatusFailed);
}
+ return result.Succeeded();
+ }
+};
- ~CommandObjectTargetModulesSearchPathsAdd() override = default;
+#pragma mark CommandObjectTargetModulesSearchPathsInsert
+
+class CommandObjectTargetModulesSearchPathsInsert : public CommandObjectParsed {
+public:
+ CommandObjectTargetModulesSearchPathsInsert(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "target modules search-paths insert",
+ "Insert a new image search path substitution pair "
+ "into the current target at the specified index.",
+ nullptr) {
+ CommandArgumentEntry arg1;
+ CommandArgumentEntry arg2;
+ CommandArgumentData index_arg;
+ CommandArgumentData old_prefix_arg;
+ CommandArgumentData new_prefix_arg;
+
+ // Define the first and only variant of this arg.
+ index_arg.arg_type = eArgTypeIndex;
+ index_arg.arg_repetition = eArgRepeatPlain;
+
+ // Put the one and only variant into the first arg for m_arguments:
+ arg1.push_back(index_arg);
+
+ // Define the first variant of this arg pair.
+ old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
+ old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
+
+ // Define the first variant of this arg pair.
+ new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
+ new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
+
+ // There are two required arguments that must always occur together, i.e. an
+ // argument "pair". Because they
+ // must always occur together, they are treated as two variants of one
+ // argument rather than two independent
+ // arguments. Push them both into the same argument position for
+ // m_arguments...
+
+ arg2.push_back(old_prefix_arg);
+ arg2.push_back(new_prefix_arg);
+
+ // Add arguments to m_arguments.
+ m_arguments.push_back(arg1);
+ m_arguments.push_back(arg2);
+ }
+
+ ~CommandObjectTargetModulesSearchPathsInsert() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (target)
- {
- const size_t argc = command.GetArgumentCount();
- if (argc & 1)
- {
- result.AppendError ("add requires an even number of arguments\n");
- result.SetStatus (eReturnStatusFailed);
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target) {
+ size_t argc = command.GetArgumentCount();
+ // check for at least 3 arguments and an odd number of parameters
+ if (argc >= 3 && argc & 1) {
+ bool success = false;
+
+ uint32_t insert_idx = StringConvert::ToUInt32(
+ command.GetArgumentAtIndex(0), UINT32_MAX, 0, &success);
+
+ if (!success) {
+ result.AppendErrorWithFormat(
+ "<index> parameter is not an integer: '%s'.\n",
+ command.GetArgumentAtIndex(0));
+ result.SetStatus(eReturnStatusFailed);
+ return result.Succeeded();
+ }
+
+ // shift off the index
+ command.Shift();
+ argc = command.GetArgumentCount();
+
+ for (uint32_t i = 0; i < argc; i += 2, ++insert_idx) {
+ const char *from = command.GetArgumentAtIndex(i);
+ const char *to = command.GetArgumentAtIndex(i + 1);
+
+ if (from[0] && to[0]) {
+ bool last_pair = ((argc - i) == 2);
+ target->GetImageSearchPathList().Insert(
+ ConstString(from), ConstString(to), insert_idx, last_pair);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ } else {
+ if (from[0])
+ result.AppendError("<path-prefix> can't be empty\n");
else
- {
- for (size_t i = 0; i < argc; i+=2)
- {
- const char *from = command.GetArgumentAtIndex(i);
- const char *to = command.GetArgumentAtIndex(i+1);
-
- if (from[0] && to[0])
- {
- Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
- if (log)
- {
- log->Printf ("target modules search path adding ImageSearchPath pair: '%s' -> '%s'",
- from, to);
- }
- bool last_pair = ((argc - i) == 2);
- target->GetImageSearchPathList().Append (ConstString(from),
- ConstString(to),
- last_pair); // Notify if this is the last pair
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- if (from[0])
- result.AppendError ("<path-prefix> can't be empty\n");
- else
- result.AppendError ("<new-path-prefix> can't be empty\n");
- result.SetStatus (eReturnStatusFailed);
- }
- }
- }
- }
- else
- {
- result.AppendError ("invalid target\n");
- result.SetStatus (eReturnStatusFailed);
+ result.AppendError("<new-path-prefix> can't be empty\n");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
}
+ } else {
+ result.AppendError("insert requires at least three arguments\n");
+ result.SetStatus(eReturnStatusFailed);
return result.Succeeded();
+ }
+
+ } else {
+ result.AppendError("invalid target\n");
+ result.SetStatus(eReturnStatusFailed);
}
+ return result.Succeeded();
+ }
};
-#pragma mark CommandObjectTargetModulesSearchPathsClear
+#pragma mark CommandObjectTargetModulesSearchPathsList
-class CommandObjectTargetModulesSearchPathsClear : public CommandObjectParsed
-{
+class CommandObjectTargetModulesSearchPathsList : public CommandObjectParsed {
public:
- CommandObjectTargetModulesSearchPathsClear (CommandInterpreter &interpreter) :
- CommandObjectParsed (interpreter,
- "target modules search-paths clear",
- "Clear all current image search path substitution pairs from the current target.",
- "target modules search-paths clear")
- {
- }
+ CommandObjectTargetModulesSearchPathsList(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "target modules search-paths list",
+ "List all current image search path substitution "
+ "pairs in the current target.",
+ "target modules search-paths list") {}
- ~CommandObjectTargetModulesSearchPathsClear() override = default;
+ ~CommandObjectTargetModulesSearchPathsList() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (target)
- {
- bool notify = true;
- target->GetImageSearchPathList().Clear(notify);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- result.AppendError ("invalid target\n");
- result.SetStatus (eReturnStatusFailed);
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target) {
+ if (command.GetArgumentCount() != 0) {
+ result.AppendError("list takes no arguments\n");
+ result.SetStatus(eReturnStatusFailed);
return result.Succeeded();
+ }
+
+ target->GetImageSearchPathList().Dump(&result.GetOutputStream());
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ } else {
+ result.AppendError("invalid target\n");
+ result.SetStatus(eReturnStatusFailed);
}
+ return result.Succeeded();
+ }
};
-#pragma mark CommandObjectTargetModulesSearchPathsInsert
+#pragma mark CommandObjectTargetModulesSearchPathsQuery
-class CommandObjectTargetModulesSearchPathsInsert : public CommandObjectParsed
-{
+class CommandObjectTargetModulesSearchPathsQuery : public CommandObjectParsed {
public:
- CommandObjectTargetModulesSearchPathsInsert (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "target modules search-paths insert",
- "Insert a new image search path substitution pair into the current target at the specified index.",
- nullptr)
- {
- CommandArgumentEntry arg1;
- CommandArgumentEntry arg2;
- CommandArgumentData index_arg;
- CommandArgumentData old_prefix_arg;
- CommandArgumentData new_prefix_arg;
-
- // Define the first and only variant of this arg.
- index_arg.arg_type = eArgTypeIndex;
- index_arg.arg_repetition = eArgRepeatPlain;
-
- // Put the one and only variant into the first arg for m_arguments:
- arg1.push_back (index_arg);
-
- // Define the first variant of this arg pair.
- old_prefix_arg.arg_type = eArgTypeOldPathPrefix;
- old_prefix_arg.arg_repetition = eArgRepeatPairPlus;
-
- // Define the first variant of this arg pair.
- new_prefix_arg.arg_type = eArgTypeNewPathPrefix;
- new_prefix_arg.arg_repetition = eArgRepeatPairPlus;
-
- // There are two required arguments that must always occur together, i.e. an argument "pair". Because they
- // must always occur together, they are treated as two variants of one argument rather than two independent
- // arguments. Push them both into the same argument position for m_arguments...
-
- arg2.push_back (old_prefix_arg);
- arg2.push_back (new_prefix_arg);
-
- // Add arguments to m_arguments.
- m_arguments.push_back (arg1);
- m_arguments.push_back (arg2);
- }
-
- ~CommandObjectTargetModulesSearchPathsInsert() override = default;
-
-protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (target)
- {
- size_t argc = command.GetArgumentCount();
- // check for at least 3 arguments and an odd number of parameters
- if (argc >= 3 && argc & 1)
- {
- bool success = false;
-
- uint32_t insert_idx = StringConvert::ToUInt32(command.GetArgumentAtIndex(0), UINT32_MAX, 0, &success);
-
- if (!success)
- {
- result.AppendErrorWithFormat("<index> parameter is not an integer: '%s'.\n", command.GetArgumentAtIndex(0));
- result.SetStatus (eReturnStatusFailed);
- return result.Succeeded();
- }
-
- // shift off the index
- command.Shift();
- argc = command.GetArgumentCount();
-
- for (uint32_t i = 0; i < argc; i += 2, ++insert_idx)
- {
- const char *from = command.GetArgumentAtIndex(i);
- const char *to = command.GetArgumentAtIndex(i+1);
-
- if (from[0] && to[0])
- {
- bool last_pair = ((argc - i) == 2);
- target->GetImageSearchPathList().Insert (ConstString(from),
- ConstString(to),
- insert_idx,
- last_pair);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- if (from[0])
- result.AppendError ("<path-prefix> can't be empty\n");
- else
- result.AppendError ("<new-path-prefix> can't be empty\n");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- }
- else
- {
- result.AppendError ("insert requires at least three arguments\n");
- result.SetStatus (eReturnStatusFailed);
- return result.Succeeded();
- }
-
- }
- else
- {
- result.AppendError ("invalid target\n");
- result.SetStatus (eReturnStatusFailed);
- }
- return result.Succeeded();
- }
-};
-
-#pragma mark CommandObjectTargetModulesSearchPathsList
-
-class CommandObjectTargetModulesSearchPathsList : public CommandObjectParsed
-{
-public:
- CommandObjectTargetModulesSearchPathsList (CommandInterpreter &interpreter) :
- CommandObjectParsed (interpreter,
- "target modules search-paths list",
- "List all current image search path substitution pairs in the current target.",
- "target modules search-paths list")
- {
- }
+ CommandObjectTargetModulesSearchPathsQuery(CommandInterpreter &interpreter)
+ : CommandObjectParsed(
+ interpreter, "target modules search-paths query",
+ "Transform a path using the first applicable image search path.",
+ nullptr) {
+ CommandArgumentEntry arg;
+ CommandArgumentData path_arg;
+
+ // Define the first (and only) variant of this arg.
+ path_arg.arg_type = eArgTypeDirectoryName;
+ path_arg.arg_repetition = eArgRepeatPlain;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(path_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+ }
- ~CommandObjectTargetModulesSearchPathsList() override = default;
+ ~CommandObjectTargetModulesSearchPathsQuery() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (target)
- {
- if (command.GetArgumentCount() != 0)
- {
- result.AppendError ("list takes no arguments\n");
- result.SetStatus (eReturnStatusFailed);
- return result.Succeeded();
- }
-
- target->GetImageSearchPathList().Dump(&result.GetOutputStream());
- result.SetStatus (eReturnStatusSuccessFinishResult);
- }
- else
- {
- result.AppendError ("invalid target\n");
- result.SetStatus (eReturnStatusFailed);
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target) {
+ if (command.GetArgumentCount() != 1) {
+ result.AppendError("query requires one argument\n");
+ result.SetStatus(eReturnStatusFailed);
return result.Succeeded();
- }
-};
-
-#pragma mark CommandObjectTargetModulesSearchPathsQuery
-
-class CommandObjectTargetModulesSearchPathsQuery : public CommandObjectParsed
-{
-public:
- CommandObjectTargetModulesSearchPathsQuery (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "target modules search-paths query",
- "Transform a path using the first applicable image search path.",
- nullptr)
- {
- CommandArgumentEntry arg;
- CommandArgumentData path_arg;
-
- // Define the first (and only) variant of this arg.
- path_arg.arg_type = eArgTypeDirectoryName;
- path_arg.arg_repetition = eArgRepeatPlain;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (path_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
- }
-
- ~CommandObjectTargetModulesSearchPathsQuery() override = default;
-
-protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (target)
- {
- if (command.GetArgumentCount() != 1)
- {
- result.AppendError ("query requires one argument\n");
- result.SetStatus (eReturnStatusFailed);
- return result.Succeeded();
- }
-
- ConstString orig(command.GetArgumentAtIndex(0));
- ConstString transformed;
- if (target->GetImageSearchPathList().RemapPath(orig, transformed))
- result.GetOutputStream().Printf("%s\n", transformed.GetCString());
- else
- result.GetOutputStream().Printf("%s\n", orig.GetCString());
+ }
- result.SetStatus (eReturnStatusSuccessFinishResult);
- }
- else
- {
- result.AppendError ("invalid target\n");
- result.SetStatus (eReturnStatusFailed);
- }
- return result.Succeeded();
+ ConstString orig(command.GetArgumentAtIndex(0));
+ ConstString transformed;
+ if (target->GetImageSearchPathList().RemapPath(orig, transformed))
+ result.GetOutputStream().Printf("%s\n", transformed.GetCString());
+ else
+ result.GetOutputStream().Printf("%s\n", orig.GetCString());
+
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ } else {
+ result.AppendError("invalid target\n");
+ result.SetStatus(eReturnStatusFailed);
}
+ return result.Succeeded();
+ }
};
//----------------------------------------------------------------------
// Static Helper functions
//----------------------------------------------------------------------
-static void
-DumpModuleArchitecture (Stream &strm, Module *module, bool full_triple, uint32_t width)
-{
- if (module)
- {
- StreamString arch_strm;
+static void DumpModuleArchitecture(Stream &strm, Module *module,
+ bool full_triple, uint32_t width) {
+ if (module) {
+ StreamString arch_strm;
- if (full_triple)
- module->GetArchitecture().DumpTriple(arch_strm);
- else
- arch_strm.PutCString(module->GetArchitecture().GetArchitectureName());
- std::string arch_str = arch_strm.GetString();
-
- if (width)
- strm.Printf("%-*s", width, arch_str.c_str());
- else
- strm.PutCString(arch_str.c_str());
- }
-}
+ if (full_triple)
+ module->GetArchitecture().DumpTriple(arch_strm);
+ else
+ arch_strm.PutCString(module->GetArchitecture().GetArchitectureName());
+ std::string arch_str = arch_strm.GetString();
-static void
-DumpModuleUUID (Stream &strm, Module *module)
-{
- if (module && module->GetUUID().IsValid())
- module->GetUUID().Dump (&strm);
+ if (width)
+ strm.Printf("%-*s", width, arch_str.c_str());
else
- strm.PutCString(" ");
+ strm.PutCString(arch_str.c_str());
+ }
}
-static uint32_t
-DumpCompileUnitLineTable (CommandInterpreter &interpreter,
- Stream &strm,
- Module *module,
- const FileSpec &file_spec,
- bool load_addresses)
-{
- uint32_t num_matches = 0;
- if (module)
- {
- SymbolContextList sc_list;
- num_matches = module->ResolveSymbolContextsForFileSpec (file_spec,
- 0,
- false,
- eSymbolContextCompUnit,
- sc_list);
-
- for (uint32_t i = 0; i < num_matches; ++i)
- {
- SymbolContext sc;
- if (sc_list.GetContextAtIndex(i, sc))
- {
- if (i > 0)
- strm << "\n\n";
-
- strm << "Line table for " << *static_cast<FileSpec*> (sc.comp_unit) << " in `"
- << module->GetFileSpec().GetFilename() << "\n";
- LineTable *line_table = sc.comp_unit->GetLineTable();
- if (line_table)
- line_table->GetDescription (&strm,
- interpreter.GetExecutionContext().GetTargetPtr(),
- lldb::eDescriptionLevelBrief);
- else
- strm << "No line table";
- }
- }
- }
- return num_matches;
+static void DumpModuleUUID(Stream &strm, Module *module) {
+ if (module && module->GetUUID().IsValid())
+ module->GetUUID().Dump(&strm);
+ else
+ strm.PutCString(" ");
}
-static void
-DumpFullpath (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
-{
- if (file_spec_ptr)
- {
- if (width > 0)
- {
- std::string fullpath = file_spec_ptr->GetPath();
- strm.Printf("%-*s", width, fullpath.c_str());
- return;
- }
+static uint32_t DumpCompileUnitLineTable(CommandInterpreter &interpreter,
+ Stream &strm, Module *module,
+ const FileSpec &file_spec,
+ bool load_addresses) {
+ uint32_t num_matches = 0;
+ if (module) {
+ SymbolContextList sc_list;
+ num_matches = module->ResolveSymbolContextsForFileSpec(
+ file_spec, 0, false, eSymbolContextCompUnit, sc_list);
+
+ for (uint32_t i = 0; i < num_matches; ++i) {
+ SymbolContext sc;
+ if (sc_list.GetContextAtIndex(i, sc)) {
+ if (i > 0)
+ strm << "\n\n";
+
+ strm << "Line table for " << *static_cast<FileSpec *>(sc.comp_unit)
+ << " in `" << module->GetFileSpec().GetFilename() << "\n";
+ LineTable *line_table = sc.comp_unit->GetLineTable();
+ if (line_table)
+ line_table->GetDescription(
+ &strm, interpreter.GetExecutionContext().GetTargetPtr(),
+ lldb::eDescriptionLevelBrief);
else
- {
- file_spec_ptr->Dump(&strm);
- return;
- }
+ strm << "No line table";
+ }
}
- // Keep the width spacing correct if things go wrong...
- if (width > 0)
- strm.Printf("%-*s", width, "");
+ }
+ return num_matches;
}
-static void
-DumpDirectory (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
-{
- if (file_spec_ptr)
- {
- if (width > 0)
- strm.Printf("%-*s", width, file_spec_ptr->GetDirectory().AsCString(""));
- else
- file_spec_ptr->GetDirectory().Dump(&strm);
- return;
- }
- // Keep the width spacing correct if things go wrong...
- if (width > 0)
- strm.Printf("%-*s", width, "");
+static void DumpFullpath(Stream &strm, const FileSpec *file_spec_ptr,
+ uint32_t width) {
+ if (file_spec_ptr) {
+ if (width > 0) {
+ std::string fullpath = file_spec_ptr->GetPath();
+ strm.Printf("%-*s", width, fullpath.c_str());
+ return;
+ } else {
+ file_spec_ptr->Dump(&strm);
+ return;
+ }
+ }
+ // Keep the width spacing correct if things go wrong...
+ if (width > 0)
+ strm.Printf("%-*s", width, "");
}
-static void
-DumpBasename (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width)
-{
- if (file_spec_ptr)
- {
- if (width > 0)
- strm.Printf("%-*s", width, file_spec_ptr->GetFilename().AsCString(""));
- else
- file_spec_ptr->GetFilename().Dump(&strm);
- return;
- }
- // Keep the width spacing correct if things go wrong...
+static void DumpDirectory(Stream &strm, const FileSpec *file_spec_ptr,
+ uint32_t width) {
+ if (file_spec_ptr) {
if (width > 0)
- strm.Printf("%-*s", width, "");
+ strm.Printf("%-*s", width, file_spec_ptr->GetDirectory().AsCString(""));
+ else
+ file_spec_ptr->GetDirectory().Dump(&strm);
+ return;
+ }
+ // Keep the width spacing correct if things go wrong...
+ if (width > 0)
+ strm.Printf("%-*s", width, "");
}
-static size_t
-DumpModuleObjfileHeaders(Stream &strm, ModuleList &module_list)
-{
- size_t num_dumped = 0;
- std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
- const size_t num_modules = module_list.GetSize();
- if (num_modules > 0)
- {
- strm.Printf("Dumping headers for %" PRIu64 " module(s).\n", static_cast<uint64_t>(num_modules));
- strm.IndentMore();
- for (size_t image_idx = 0; image_idx < num_modules; ++image_idx)
- {
- Module *module = module_list.GetModulePointerAtIndexUnlocked(image_idx);
- if (module)
- {
- if (num_dumped++ > 0)
- {
- strm.EOL();
- strm.EOL();
- }
- ObjectFile *objfile = module->GetObjectFile();
- objfile->Dump(&strm);
- }
- }
- strm.IndentLess();
- }
- return num_dumped;
+static void DumpBasename(Stream &strm, const FileSpec *file_spec_ptr,
+ uint32_t width) {
+ if (file_spec_ptr) {
+ if (width > 0)
+ strm.Printf("%-*s", width, file_spec_ptr->GetFilename().AsCString(""));
+ else
+ file_spec_ptr->GetFilename().Dump(&strm);
+ return;
+ }
+ // Keep the width spacing correct if things go wrong...
+ if (width > 0)
+ strm.Printf("%-*s", width, "");
}
-static void
-DumpModuleSymtab (CommandInterpreter &interpreter, Stream &strm, Module *module, SortOrder sort_order)
-{
- if (module)
- {
- SymbolVendor *sym_vendor = module->GetSymbolVendor ();
- if (sym_vendor)
- {
- Symtab *symtab = sym_vendor->GetSymtab();
- if (symtab)
- symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), sort_order);
- }
+static size_t DumpModuleObjfileHeaders(Stream &strm, ModuleList &module_list) {
+ size_t num_dumped = 0;
+ std::lock_guard<std::recursive_mutex> guard(module_list.GetMutex());
+ const size_t num_modules = module_list.GetSize();
+ if (num_modules > 0) {
+ strm.Printf("Dumping headers for %" PRIu64 " module(s).\n",
+ static_cast<uint64_t>(num_modules));
+ strm.IndentMore();
+ for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
+ Module *module = module_list.GetModulePointerAtIndexUnlocked(image_idx);
+ if (module) {
+ if (num_dumped++ > 0) {
+ strm.EOL();
+ strm.EOL();
+ }
+ ObjectFile *objfile = module->GetObjectFile();
+ objfile->Dump(&strm);
+ }
}
+ strm.IndentLess();
+ }
+ return num_dumped;
}
-static void
-DumpModuleSections (CommandInterpreter &interpreter, Stream &strm, Module *module)
-{
- if (module)
- {
- SectionList *section_list = module->GetSectionList();
- if (section_list)
- {
- strm.Printf ("Sections for '%s' (%s):\n",
- module->GetSpecificationDescription().c_str(),
- module->GetArchitecture().GetArchitectureName());
- strm.IndentMore();
- section_list->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(), true, UINT32_MAX);
- strm.IndentLess();
- }
+static void DumpModuleSymtab(CommandInterpreter &interpreter, Stream &strm,
+ Module *module, SortOrder sort_order) {
+ if (module) {
+ SymbolVendor *sym_vendor = module->GetSymbolVendor();
+ if (sym_vendor) {
+ Symtab *symtab = sym_vendor->GetSymtab();
+ if (symtab)
+ symtab->Dump(&strm, interpreter.GetExecutionContext().GetTargetPtr(),
+ sort_order);
}
+ }
}
-static bool
-DumpModuleSymbolVendor (Stream &strm, Module *module)
-{
- if (module)
- {
- SymbolVendor *symbol_vendor = module->GetSymbolVendor(true);
- if (symbol_vendor)
- {
- symbol_vendor->Dump(&strm);
- return true;
- }
+static void DumpModuleSections(CommandInterpreter &interpreter, Stream &strm,
+ Module *module) {
+ if (module) {
+ SectionList *section_list = module->GetSectionList();
+ if (section_list) {
+ strm.Printf("Sections for '%s' (%s):\n",
+ module->GetSpecificationDescription().c_str(),
+ module->GetArchitecture().GetArchitectureName());
+ strm.IndentMore();
+ section_list->Dump(&strm,
+ interpreter.GetExecutionContext().GetTargetPtr(), true,
+ UINT32_MAX);
+ strm.IndentLess();
}
- return false;
+ }
}
-static void
-DumpAddress (ExecutionContextScope *exe_scope, const Address &so_addr, bool verbose, Stream &strm)
-{
- strm.IndentMore();
- strm.Indent (" Address: ");
- so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
- strm.PutCString (" (");
- so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
- strm.PutCString (")\n");
- strm.Indent (" Summary: ");
- const uint32_t save_indent = strm.GetIndentLevel ();
- strm.SetIndentLevel (save_indent + 13);
- so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
- strm.SetIndentLevel (save_indent);
- // Print out detailed address information when verbose is enabled
- if (verbose)
- {
- strm.EOL();
- so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
+static bool DumpModuleSymbolVendor(Stream &strm, Module *module) {
+ if (module) {
+ SymbolVendor *symbol_vendor = module->GetSymbolVendor(true);
+ if (symbol_vendor) {
+ symbol_vendor->Dump(&strm);
+ return true;
}
- strm.IndentLess();
+ }
+ return false;
}
-static bool
-LookupAddressInModule (CommandInterpreter &interpreter,
- Stream &strm,
- Module *module,
- uint32_t resolve_mask,
- lldb::addr_t raw_addr,
- lldb::addr_t offset,
- bool verbose)
-{
- if (module)
- {
- lldb::addr_t addr = raw_addr - offset;
- Address so_addr;
- SymbolContext sc;
- Target *target = interpreter.GetExecutionContext().GetTargetPtr();
- if (target && !target->GetSectionLoadList().IsEmpty())
- {
- if (!target->GetSectionLoadList().ResolveLoadAddress (addr, so_addr))
- return false;
- else if (so_addr.GetModule().get() != module)
- return false;
- }
- else
- {
- if (!module->ResolveFileAddress (addr, so_addr))
- return false;
- }
+static void DumpAddress(ExecutionContextScope *exe_scope,
+ const Address &so_addr, bool verbose, Stream &strm) {
+ strm.IndentMore();
+ strm.Indent(" Address: ");
+ so_addr.Dump(&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
+ strm.PutCString(" (");
+ so_addr.Dump(&strm, exe_scope, Address::DumpStyleSectionNameOffset);
+ strm.PutCString(")\n");
+ strm.Indent(" Summary: ");
+ const uint32_t save_indent = strm.GetIndentLevel();
+ strm.SetIndentLevel(save_indent + 13);
+ so_addr.Dump(&strm, exe_scope, Address::DumpStyleResolvedDescription);
+ strm.SetIndentLevel(save_indent);
+ // Print out detailed address information when verbose is enabled
+ if (verbose) {
+ strm.EOL();
+ so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
+ }
+ strm.IndentLess();
+}
- ExecutionContextScope *exe_scope = interpreter.GetExecutionContext().GetBestExecutionContextScope();
- DumpAddress (exe_scope, so_addr, verbose, strm);
-// strm.IndentMore();
-// strm.Indent (" Address: ");
-// so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
-// strm.PutCString (" (");
-// so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
-// strm.PutCString (")\n");
-// strm.Indent (" Summary: ");
-// const uint32_t save_indent = strm.GetIndentLevel ();
-// strm.SetIndentLevel (save_indent + 13);
-// so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
-// strm.SetIndentLevel (save_indent);
-// // Print out detailed address information when verbose is enabled
-// if (verbose)
-// {
-// strm.EOL();
-// so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
-// }
-// strm.IndentLess();
- return true;
+static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
+ Module *module, uint32_t resolve_mask,
+ lldb::addr_t raw_addr, lldb::addr_t offset,
+ bool verbose) {
+ if (module) {
+ lldb::addr_t addr = raw_addr - offset;
+ Address so_addr;
+ SymbolContext sc;
+ Target *target = interpreter.GetExecutionContext().GetTargetPtr();
+ if (target && !target->GetSectionLoadList().IsEmpty()) {
+ if (!target->GetSectionLoadList().ResolveLoadAddress(addr, so_addr))
+ return false;
+ else if (so_addr.GetModule().get() != module)
+ return false;
+ } else {
+ if (!module->ResolveFileAddress(addr, so_addr))
+ return false;
}
- return false;
-}
-
-static uint32_t
-LookupSymbolInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex, bool verbose)
-{
- if (module)
- {
- SymbolContext sc;
+ ExecutionContextScope *exe_scope =
+ interpreter.GetExecutionContext().GetBestExecutionContextScope();
+ DumpAddress(exe_scope, so_addr, verbose, strm);
+ // strm.IndentMore();
+ // strm.Indent (" Address: ");
+ // so_addr.Dump (&strm, exe_scope,
+ // Address::DumpStyleModuleWithFileAddress);
+ // strm.PutCString (" (");
+ // so_addr.Dump (&strm, exe_scope,
+ // Address::DumpStyleSectionNameOffset);
+ // strm.PutCString (")\n");
+ // strm.Indent (" Summary: ");
+ // const uint32_t save_indent = strm.GetIndentLevel ();
+ // strm.SetIndentLevel (save_indent + 13);
+ // so_addr.Dump (&strm, exe_scope,
+ // Address::DumpStyleResolvedDescription);
+ // strm.SetIndentLevel (save_indent);
+ // // Print out detailed address information when verbose is enabled
+ // if (verbose)
+ // {
+ // strm.EOL();
+ // so_addr.Dump (&strm, exe_scope,
+ // Address::DumpStyleDetailedSymbolContext);
+ // }
+ // strm.IndentLess();
+ return true;
+ }
- SymbolVendor *sym_vendor = module->GetSymbolVendor ();
- if (sym_vendor)
- {
- Symtab *symtab = sym_vendor->GetSymtab();
- if (symtab)
- {
- std::vector<uint32_t> match_indexes;
- ConstString symbol_name (name);
- uint32_t num_matches = 0;
- if (name_is_regex)
- {
- RegularExpression name_regexp(name);
- num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType (name_regexp,
- eSymbolTypeAny,
- match_indexes);
- }
- else
- {
- num_matches = symtab->AppendSymbolIndexesWithName (symbol_name, match_indexes);
- }
+ return false;
+}
- if (num_matches > 0)
- {
- strm.Indent ();
- strm.Printf("%u symbols match %s'%s' in ", num_matches,
- name_is_regex ? "the regular expression " : "", name);
- DumpFullpath (strm, &module->GetFileSpec(), 0);
- strm.PutCString(":\n");
- strm.IndentMore ();
- for (uint32_t i = 0; i < num_matches; ++i)
- {
- Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]);
- if (symbol && symbol->ValueIsAddress())
- {
- DumpAddress (interpreter.GetExecutionContext().GetBestExecutionContextScope(),
- symbol->GetAddressRef(),
- verbose,
- strm);
- }
- }
- strm.IndentLess ();
- return num_matches;
- }
- }
+static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
+ Stream &strm, Module *module,
+ const char *name, bool name_is_regex,
+ bool verbose) {
+ if (module) {
+ SymbolContext sc;
+
+ SymbolVendor *sym_vendor = module->GetSymbolVendor();
+ if (sym_vendor) {
+ Symtab *symtab = sym_vendor->GetSymtab();
+ if (symtab) {
+ std::vector<uint32_t> match_indexes;
+ ConstString symbol_name(name);
+ uint32_t num_matches = 0;
+ if (name_is_regex) {
+ RegularExpression name_regexp(name);
+ num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType(
+ name_regexp, eSymbolTypeAny, match_indexes);
+ } else {
+ num_matches =
+ symtab->AppendSymbolIndexesWithName(symbol_name, match_indexes);
+ }
+
+ if (num_matches > 0) {
+ strm.Indent();
+ strm.Printf("%u symbols match %s'%s' in ", num_matches,
+ name_is_regex ? "the regular expression " : "", name);
+ DumpFullpath(strm, &module->GetFileSpec(), 0);
+ strm.PutCString(":\n");
+ strm.IndentMore();
+ for (uint32_t i = 0; i < num_matches; ++i) {
+ Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]);
+ if (symbol && symbol->ValueIsAddress()) {
+ DumpAddress(interpreter.GetExecutionContext()
+ .GetBestExecutionContextScope(),
+ symbol->GetAddressRef(), verbose, strm);
+ }
+ }
+ strm.IndentLess();
+ return num_matches;
}
+ }
}
- return 0;
+ }
+ return 0;
}
-static void
-DumpSymbolContextList (ExecutionContextScope *exe_scope, Stream &strm, SymbolContextList &sc_list, bool verbose)
-{
- strm.IndentMore ();
-
- const uint32_t num_matches = sc_list.GetSize();
-
- for (uint32_t i = 0; i < num_matches; ++i)
- {
- SymbolContext sc;
- if (sc_list.GetContextAtIndex(i, sc))
- {
- AddressRange range;
+static void DumpSymbolContextList(ExecutionContextScope *exe_scope,
+ Stream &strm, SymbolContextList &sc_list,
+ bool verbose) {
+ strm.IndentMore();
- sc.GetAddressRange(eSymbolContextEverything,
- 0,
- true,
- range);
+ const uint32_t num_matches = sc_list.GetSize();
- DumpAddress (exe_scope, range.GetBaseAddress(), verbose, strm);
- }
- }
- strm.IndentLess ();
-}
+ for (uint32_t i = 0; i < num_matches; ++i) {
+ SymbolContext sc;
+ if (sc_list.GetContextAtIndex(i, sc)) {
+ AddressRange range;
-static size_t
-LookupFunctionInModule (CommandInterpreter &interpreter,
- Stream &strm,
- Module *module,
- const char *name,
- bool name_is_regex,
- bool include_inlines,
- bool include_symbols,
- bool verbose)
-{
- if (module && name && name[0])
- {
- SymbolContextList sc_list;
- const bool append = true;
- size_t num_matches = 0;
- if (name_is_regex)
- {
- RegularExpression function_name_regex (name);
- num_matches = module->FindFunctions (function_name_regex,
- include_symbols,
- include_inlines,
- append,
- sc_list);
- }
- else
- {
- ConstString function_name (name);
- num_matches = module->FindFunctions(function_name,
- nullptr,
- eFunctionNameTypeAuto,
- include_symbols,
- include_inlines,
- append,
- sc_list);
- }
+ sc.GetAddressRange(eSymbolContextEverything, 0, true, range);
- if (num_matches)
- {
- strm.Indent ();
- strm.Printf("%" PRIu64 " match%s found in ", (uint64_t)num_matches, num_matches > 1 ? "es" : "");
- DumpFullpath (strm, &module->GetFileSpec(), 0);
- strm.PutCString(":\n");
- DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose);
- }
- return num_matches;
+ DumpAddress(exe_scope, range.GetBaseAddress(), verbose, strm);
}
- return 0;
+ }
+ strm.IndentLess();
}
-static size_t
-LookupTypeInModule (CommandInterpreter &interpreter,
- Stream &strm,
- Module *module,
- const char *name_cstr,
- bool name_is_regex)
-{
- if (module && name_cstr && name_cstr[0])
- {
- TypeList type_list;
- const uint32_t max_num_matches = UINT32_MAX;
- size_t num_matches = 0;
- bool name_is_fully_qualified = false;
- SymbolContext sc;
-
- ConstString name(name_cstr);
- llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
- num_matches = module->FindTypes(sc, name, name_is_fully_qualified, max_num_matches, searched_symbol_files, type_list);
-
- if (num_matches)
- {
- strm.Indent ();
- strm.Printf("%" PRIu64 " match%s found in ", (uint64_t)num_matches, num_matches > 1 ? "es" : "");
- DumpFullpath (strm, &module->GetFileSpec(), 0);
- strm.PutCString(":\n");
- for (TypeSP type_sp : type_list.Types())
- {
- if (type_sp)
- {
- // Resolve the clang type so that any forward references
- // to types that haven't yet been parsed will get parsed.
- type_sp->GetFullCompilerType ();
- type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
- // Print all typedef chains
- TypeSP typedef_type_sp (type_sp);
- TypeSP typedefed_type_sp (typedef_type_sp->GetTypedefType());
- while (typedefed_type_sp)
- {
- strm.EOL();
- strm.Printf(" typedef '%s': ", typedef_type_sp->GetName().GetCString());
- typedefed_type_sp->GetFullCompilerType ();
- typedefed_type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
- typedef_type_sp = typedefed_type_sp;
- typedefed_type_sp = typedef_type_sp->GetTypedefType();
- }
- }
- strm.EOL();
- }
- }
- return num_matches;
+static size_t LookupFunctionInModule(CommandInterpreter &interpreter,
+ Stream &strm, Module *module,
+ const char *name, bool name_is_regex,
+ bool include_inlines, bool include_symbols,
+ bool verbose) {
+ if (module && name && name[0]) {
+ SymbolContextList sc_list;
+ const bool append = true;
+ size_t num_matches = 0;
+ if (name_is_regex) {
+ RegularExpression function_name_regex(name);
+ num_matches = module->FindFunctions(function_name_regex, include_symbols,
+ include_inlines, append, sc_list);
+ } else {
+ ConstString function_name(name);
+ num_matches = module->FindFunctions(
+ function_name, nullptr, eFunctionNameTypeAuto, include_symbols,
+ include_inlines, append, sc_list);
+ }
+
+ if (num_matches) {
+ strm.Indent();
+ strm.Printf("%" PRIu64 " match%s found in ", (uint64_t)num_matches,
+ num_matches > 1 ? "es" : "");
+ DumpFullpath(strm, &module->GetFileSpec(), 0);
+ strm.PutCString(":\n");
+ DumpSymbolContextList(
+ interpreter.GetExecutionContext().GetBestExecutionContextScope(),
+ strm, sc_list, verbose);
}
- return 0;
+ return num_matches;
+ }
+ return 0;
}
-static size_t
-LookupTypeHere (CommandInterpreter &interpreter,
- Stream &strm,
- const SymbolContext &sym_ctx,
- const char *name_cstr,
- bool name_is_regex)
-{
- if (!sym_ctx.module_sp)
- return 0;
-
+static size_t LookupTypeInModule(CommandInterpreter &interpreter, Stream &strm,
+ Module *module, const char *name_cstr,
+ bool name_is_regex) {
+ if (module && name_cstr && name_cstr[0]) {
TypeList type_list;
const uint32_t max_num_matches = UINT32_MAX;
- size_t num_matches = 1;
+ size_t num_matches = 0;
bool name_is_fully_qualified = false;
+ SymbolContext sc;
ConstString name(name_cstr);
- llvm::DenseSet<SymbolFile *> searched_symbol_files;
- num_matches = sym_ctx.module_sp->FindTypes(sym_ctx, name, name_is_fully_qualified, max_num_matches, searched_symbol_files, type_list);
-
- if (num_matches)
- {
- strm.Indent ();
- strm.PutCString("Best match found in ");
- DumpFullpath (strm, &sym_ctx.module_sp->GetFileSpec(), 0);
- strm.PutCString(":\n");
-
- TypeSP type_sp (type_list.GetTypeAtIndex(0));
- if (type_sp)
- {
- // Resolve the clang type so that any forward references
- // to types that haven't yet been parsed will get parsed.
- type_sp->GetFullCompilerType ();
- type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
- // Print all typedef chains
- TypeSP typedef_type_sp (type_sp);
- TypeSP typedefed_type_sp (typedef_type_sp->GetTypedefType());
- while (typedefed_type_sp)
- {
- strm.EOL();
- strm.Printf(" typedef '%s': ", typedef_type_sp->GetName().GetCString());
- typedefed_type_sp->GetFullCompilerType ();
- typedefed_type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
- typedef_type_sp = typedefed_type_sp;
- typedefed_type_sp = typedef_type_sp->GetTypedefType();
- }
+ llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
+ num_matches =
+ module->FindTypes(sc, name, name_is_fully_qualified, max_num_matches,
+ searched_symbol_files, type_list);
+
+ if (num_matches) {
+ strm.Indent();
+ strm.Printf("%" PRIu64 " match%s found in ", (uint64_t)num_matches,
+ num_matches > 1 ? "es" : "");
+ DumpFullpath(strm, &module->GetFileSpec(), 0);
+ strm.PutCString(":\n");
+ for (TypeSP type_sp : type_list.Types()) {
+ if (type_sp) {
+ // Resolve the clang type so that any forward references
+ // to types that haven't yet been parsed will get parsed.
+ type_sp->GetFullCompilerType();
+ type_sp->GetDescription(&strm, eDescriptionLevelFull, true);
+ // Print all typedef chains
+ TypeSP typedef_type_sp(type_sp);
+ TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType());
+ while (typedefed_type_sp) {
+ strm.EOL();
+ strm.Printf(" typedef '%s': ",
+ typedef_type_sp->GetName().GetCString());
+ typedefed_type_sp->GetFullCompilerType();
+ typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull,
+ true);
+ typedef_type_sp = typedefed_type_sp;
+ typedefed_type_sp = typedef_type_sp->GetTypedefType();
+ }
}
strm.EOL();
+ }
}
return num_matches;
+ }
+ return 0;
}
-static uint32_t
-LookupFileAndLineInModule (CommandInterpreter &interpreter,
- Stream &strm,
- Module *module,
- const FileSpec &file_spec,
- uint32_t line,
- bool check_inlines,
- bool verbose)
-{
- if (module && file_spec)
- {
- SymbolContextList sc_list;
- const uint32_t num_matches = module->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
- eSymbolContextEverything, sc_list);
- if (num_matches > 0)
- {
- strm.Indent ();
- strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
- strm << file_spec;
- if (line > 0)
- strm.Printf (":%u", line);
- strm << " in ";
- DumpFullpath (strm, &module->GetFileSpec(), 0);
- strm.PutCString(":\n");
- DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose);
- return num_matches;
- }
- }
+static size_t LookupTypeHere(CommandInterpreter &interpreter, Stream &strm,
+ const SymbolContext &sym_ctx,
+ const char *name_cstr, bool name_is_regex) {
+ if (!sym_ctx.module_sp)
return 0;
-}
-static size_t
-FindModulesByName (Target *target,
- const char *module_name,
- ModuleList &module_list,
- bool check_global_list)
-{
- FileSpec module_file_spec(module_name, false);
- ModuleSpec module_spec (module_file_spec);
-
- const size_t initial_size = module_list.GetSize ();
-
- if (check_global_list)
- {
- // Check the global list
- std::lock_guard<std::recursive_mutex> guard(Module::GetAllocationModuleCollectionMutex());
- const size_t num_modules = Module::GetNumberAllocatedModules();
- ModuleSP module_sp;
- for (size_t image_idx = 0; image_idx<num_modules; ++image_idx)
- {
- Module *module = Module::GetAllocatedModuleAtIndex(image_idx);
+ TypeList type_list;
+ const uint32_t max_num_matches = UINT32_MAX;
+ size_t num_matches = 1;
+ bool name_is_fully_qualified = false;
+
+ ConstString name(name_cstr);
+ llvm::DenseSet<SymbolFile *> searched_symbol_files;
+ num_matches = sym_ctx.module_sp->FindTypes(
+ sym_ctx, name, name_is_fully_qualified, max_num_matches,
+ searched_symbol_files, type_list);
+
+ if (num_matches) {
+ strm.Indent();
+ strm.PutCString("Best match found in ");
+ DumpFullpath(strm, &sym_ctx.module_sp->GetFileSpec(), 0);
+ strm.PutCString(":\n");
+
+ TypeSP type_sp(type_list.GetTypeAtIndex(0));
+ if (type_sp) {
+ // Resolve the clang type so that any forward references
+ // to types that haven't yet been parsed will get parsed.
+ type_sp->GetFullCompilerType();
+ type_sp->GetDescription(&strm, eDescriptionLevelFull, true);
+ // Print all typedef chains
+ TypeSP typedef_type_sp(type_sp);
+ TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType());
+ while (typedefed_type_sp) {
+ strm.EOL();
+ strm.Printf(" typedef '%s': ",
+ typedef_type_sp->GetName().GetCString());
+ typedefed_type_sp->GetFullCompilerType();
+ typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull, true);
+ typedef_type_sp = typedefed_type_sp;
+ typedefed_type_sp = typedef_type_sp->GetTypedefType();
+ }
+ }
+ strm.EOL();
+ }
+ return num_matches;
+}
- if (module)
- {
- if (module->MatchesModuleSpec (module_spec))
- {
- module_sp = module->shared_from_this();
- module_list.AppendIfNeeded(module_sp);
- }
- }
- }
+static uint32_t LookupFileAndLineInModule(CommandInterpreter &interpreter,
+ Stream &strm, Module *module,
+ const FileSpec &file_spec,
+ uint32_t line, bool check_inlines,
+ bool verbose) {
+ if (module && file_spec) {
+ SymbolContextList sc_list;
+ const uint32_t num_matches = module->ResolveSymbolContextsForFileSpec(
+ file_spec, line, check_inlines, eSymbolContextEverything, sc_list);
+ if (num_matches > 0) {
+ strm.Indent();
+ strm.Printf("%u match%s found in ", num_matches,
+ num_matches > 1 ? "es" : "");
+ strm << file_spec;
+ if (line > 0)
+ strm.Printf(":%u", line);
+ strm << " in ";
+ DumpFullpath(strm, &module->GetFileSpec(), 0);
+ strm.PutCString(":\n");
+ DumpSymbolContextList(
+ interpreter.GetExecutionContext().GetBestExecutionContextScope(),
+ strm, sc_list, verbose);
+ return num_matches;
}
- else
- {
- if (target)
- {
- const size_t num_matches = target->GetImages().FindModules (module_spec, module_list);
+ }
+ return 0;
+}
- // Not found in our module list for our target, check the main
- // shared module list in case it is a extra file used somewhere
- // else
- if (num_matches == 0)
- {
- module_spec.GetArchitecture() = target->GetArchitecture();
- ModuleList::FindSharedModules (module_spec, module_list);
- }
- }
- else
- {
- ModuleList::FindSharedModules (module_spec,module_list);
- }
+static size_t FindModulesByName(Target *target, const char *module_name,
+ ModuleList &module_list,
+ bool check_global_list) {
+ FileSpec module_file_spec(module_name, false);
+ ModuleSpec module_spec(module_file_spec);
+
+ const size_t initial_size = module_list.GetSize();
+
+ if (check_global_list) {
+ // Check the global list
+ std::lock_guard<std::recursive_mutex> guard(
+ Module::GetAllocationModuleCollectionMutex());
+ const size_t num_modules = Module::GetNumberAllocatedModules();
+ ModuleSP module_sp;
+ for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
+ Module *module = Module::GetAllocatedModuleAtIndex(image_idx);
+
+ if (module) {
+ if (module->MatchesModuleSpec(module_spec)) {
+ module_sp = module->shared_from_this();
+ module_list.AppendIfNeeded(module_sp);
+ }
+ }
+ }
+ } else {
+ if (target) {
+ const size_t num_matches =
+ target->GetImages().FindModules(module_spec, module_list);
+
+ // Not found in our module list for our target, check the main
+ // shared module list in case it is a extra file used somewhere
+ // else
+ if (num_matches == 0) {
+ module_spec.GetArchitecture() = target->GetArchitecture();
+ ModuleList::FindSharedModules(module_spec, module_list);
+ }
+ } else {
+ ModuleList::FindSharedModules(module_spec, module_list);
}
+ }
- return module_list.GetSize () - initial_size;
+ return module_list.GetSize() - initial_size;
}
#pragma mark CommandObjectTargetModulesModuleAutoComplete
@@ -2029,55 +1780,47 @@ FindModulesByName (Target *target,
// paths
//----------------------------------------------------------------------
-class CommandObjectTargetModulesModuleAutoComplete : public CommandObjectParsed
-{
+class CommandObjectTargetModulesModuleAutoComplete
+ : public CommandObjectParsed {
public:
- CommandObjectTargetModulesModuleAutoComplete (CommandInterpreter &interpreter,
- const char *name,
- const char *help,
- const char *syntax) :
- CommandObjectParsed (interpreter, name, help, syntax)
- {
- CommandArgumentEntry arg;
- CommandArgumentData file_arg;
-
- // Define the first (and only) variant of this arg.
- file_arg.arg_type = eArgTypeFilename;
- file_arg.arg_repetition = eArgRepeatStar;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (file_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
- }
-
- ~CommandObjectTargetModulesModuleAutoComplete() override = default;
-
- int
- HandleArgumentCompletion (Args &input,
- int &cursor_index,
- int &cursor_char_position,
- OptionElementVector &opt_element_vector,
- int match_start_point,
- int max_return_elements,
- bool &word_complete,
- StringList &matches) override
- {
- // Arguments are the standard module completer.
- std::string completion_str (input.GetArgumentAtIndex(cursor_index));
- completion_str.erase (cursor_char_position);
-
- CommandCompletions::InvokeCommonCompletionCallbacks(GetCommandInterpreter(),
- CommandCompletions::eModuleCompletion,
- completion_str.c_str(),
- match_start_point,
- max_return_elements,
- nullptr,
- word_complete,
- matches);
- return matches.GetSize();
- }
+ CommandObjectTargetModulesModuleAutoComplete(CommandInterpreter &interpreter,
+ const char *name,
+ const char *help,
+ const char *syntax)
+ : CommandObjectParsed(interpreter, name, help, syntax) {
+ CommandArgumentEntry arg;
+ CommandArgumentData file_arg;
+
+ // Define the first (and only) variant of this arg.
+ file_arg.arg_type = eArgTypeFilename;
+ file_arg.arg_repetition = eArgRepeatStar;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(file_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+ }
+
+ ~CommandObjectTargetModulesModuleAutoComplete() override = default;
+
+ int HandleArgumentCompletion(Args &input, int &cursor_index,
+ int &cursor_char_position,
+ OptionElementVector &opt_element_vector,
+ int match_start_point, int max_return_elements,
+ bool &word_complete,
+ StringList &matches) override {
+ // Arguments are the standard module completer.
+ std::string completion_str(input.GetArgumentAtIndex(cursor_index));
+ completion_str.erase(cursor_char_position);
+
+ CommandCompletions::InvokeCommonCompletionCallbacks(
+ GetCommandInterpreter(), CommandCompletions::eModuleCompletion,
+ completion_str.c_str(), match_start_point, max_return_elements, nullptr,
+ word_complete, matches);
+ return matches.GetSize();
+ }
};
#pragma mark CommandObjectTargetModulesSourceFileAutoComplete
@@ -2087,311 +1830,260 @@ public:
// file paths
//----------------------------------------------------------------------
-class CommandObjectTargetModulesSourceFileAutoComplete : public CommandObjectParsed
-{
+class CommandObjectTargetModulesSourceFileAutoComplete
+ : public CommandObjectParsed {
public:
- CommandObjectTargetModulesSourceFileAutoComplete (CommandInterpreter &interpreter,
- const char *name,
- const char *help,
- const char *syntax,
- uint32_t flags) :
- CommandObjectParsed (interpreter, name, help, syntax, flags)
- {
- CommandArgumentEntry arg;
- CommandArgumentData source_file_arg;
-
- // Define the first (and only) variant of this arg.
- source_file_arg.arg_type = eArgTypeSourceFile;
- source_file_arg.arg_repetition = eArgRepeatPlus;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (source_file_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
- }
-
- ~CommandObjectTargetModulesSourceFileAutoComplete() override = default;
-
- int
- HandleArgumentCompletion (Args &input,
- int &cursor_index,
- int &cursor_char_position,
- OptionElementVector &opt_element_vector,
- int match_start_point,
- int max_return_elements,
- bool &word_complete,
- StringList &matches) override
- {
- // Arguments are the standard source file completer.
- std::string completion_str (input.GetArgumentAtIndex(cursor_index));
- completion_str.erase (cursor_char_position);
-
- CommandCompletions::InvokeCommonCompletionCallbacks(GetCommandInterpreter(),
- CommandCompletions::eSourceFileCompletion,
- completion_str.c_str(),
- match_start_point,
- max_return_elements,
- nullptr,
- word_complete,
- matches);
- return matches.GetSize();
- }
+ CommandObjectTargetModulesSourceFileAutoComplete(
+ CommandInterpreter &interpreter, const char *name, const char *help,
+ const char *syntax, uint32_t flags)
+ : CommandObjectParsed(interpreter, name, help, syntax, flags) {
+ CommandArgumentEntry arg;
+ CommandArgumentData source_file_arg;
+
+ // Define the first (and only) variant of this arg.
+ source_file_arg.arg_type = eArgTypeSourceFile;
+ source_file_arg.arg_repetition = eArgRepeatPlus;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(source_file_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+ }
+
+ ~CommandObjectTargetModulesSourceFileAutoComplete() override = default;
+
+ int HandleArgumentCompletion(Args &input, int &cursor_index,
+ int &cursor_char_position,
+ OptionElementVector &opt_element_vector,
+ int match_start_point, int max_return_elements,
+ bool &word_complete,
+ StringList &matches) override {
+ // Arguments are the standard source file completer.
+ std::string completion_str(input.GetArgumentAtIndex(cursor_index));
+ completion_str.erase(cursor_char_position);
+
+ CommandCompletions::InvokeCommonCompletionCallbacks(
+ GetCommandInterpreter(), CommandCompletions::eSourceFileCompletion,
+ completion_str.c_str(), match_start_point, max_return_elements, nullptr,
+ word_complete, matches);
+ return matches.GetSize();
+ }
};
#pragma mark CommandObjectTargetModulesDumpObjfile
-class CommandObjectTargetModulesDumpObjfile : public CommandObjectTargetModulesModuleAutoComplete
-{
+class CommandObjectTargetModulesDumpObjfile
+ : public CommandObjectTargetModulesModuleAutoComplete {
public:
- CommandObjectTargetModulesDumpObjfile(CommandInterpreter &interpreter)
- : CommandObjectTargetModulesModuleAutoComplete(interpreter, "target modules dump objfile",
- "Dump the object file headers from one or more target modules.",
- nullptr)
- {
- }
+ CommandObjectTargetModulesDumpObjfile(CommandInterpreter &interpreter)
+ : CommandObjectTargetModulesModuleAutoComplete(
+ interpreter, "target modules dump objfile",
+ "Dump the object file headers from one or more target modules.",
+ nullptr) {}
- ~CommandObjectTargetModulesDumpObjfile() override = default;
+ ~CommandObjectTargetModulesDumpObjfile() override = default;
protected:
- bool
- DoExecute(Args &command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (target == nullptr)
- {
- result.AppendError("invalid target, create a debug target using the 'target create' command");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
- result.GetOutputStream().SetAddressByteSize(addr_byte_size);
- result.GetErrorStream().SetAddressByteSize(addr_byte_size);
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target == nullptr) {
+ result.AppendError("invalid target, create a debug target using the "
+ "'target create' command");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
- size_t num_dumped = 0;
- if (command.GetArgumentCount() == 0)
- {
- // Dump all headers for all modules images
- num_dumped = DumpModuleObjfileHeaders(result.GetOutputStream(), target->GetImages());
- if (num_dumped == 0)
- {
- result.AppendError("the target has no associated executable images");
- result.SetStatus(eReturnStatusFailed);
- }
- }
- else
- {
- // Find the modules that match the basename or full path.
- ModuleList module_list;
- const char *arg_cstr;
- for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr; ++arg_idx)
- {
- size_t num_matched = FindModulesByName(target, arg_cstr, module_list, true);
- if (num_matched == 0)
- {
- result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
- }
- }
- // Dump all the modules we found.
- num_dumped = DumpModuleObjfileHeaders(result.GetOutputStream(), module_list);
- }
+ uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
+ result.GetOutputStream().SetAddressByteSize(addr_byte_size);
+ result.GetErrorStream().SetAddressByteSize(addr_byte_size);
- if (num_dumped > 0)
- {
- result.SetStatus(eReturnStatusSuccessFinishResult);
- }
- else
- {
- result.AppendError("no matching executable images found");
- result.SetStatus(eReturnStatusFailed);
- }
- return result.Succeeded();
+ size_t num_dumped = 0;
+ if (command.GetArgumentCount() == 0) {
+ // Dump all headers for all modules images
+ num_dumped = DumpModuleObjfileHeaders(result.GetOutputStream(),
+ target->GetImages());
+ if (num_dumped == 0) {
+ result.AppendError("the target has no associated executable images");
+ result.SetStatus(eReturnStatusFailed);
+ }
+ } else {
+ // Find the modules that match the basename or full path.
+ ModuleList module_list;
+ const char *arg_cstr;
+ for (int arg_idx = 0;
+ (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
+ ++arg_idx) {
+ size_t num_matched =
+ FindModulesByName(target, arg_cstr, module_list, true);
+ if (num_matched == 0) {
+ result.AppendWarningWithFormat(
+ "Unable to find an image that matches '%s'.\n", arg_cstr);
+ }
+ }
+ // Dump all the modules we found.
+ num_dumped =
+ DumpModuleObjfileHeaders(result.GetOutputStream(), module_list);
+ }
+
+ if (num_dumped > 0) {
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ } else {
+ result.AppendError("no matching executable images found");
+ result.SetStatus(eReturnStatusFailed);
}
+ return result.Succeeded();
+ }
};
#pragma mark CommandObjectTargetModulesDumpSymtab
-class CommandObjectTargetModulesDumpSymtab : public CommandObjectTargetModulesModuleAutoComplete
-{
+class CommandObjectTargetModulesDumpSymtab
+ : public CommandObjectTargetModulesModuleAutoComplete {
public:
- CommandObjectTargetModulesDumpSymtab (CommandInterpreter &interpreter) :
- CommandObjectTargetModulesModuleAutoComplete(interpreter,
- "target modules dump symtab",
- "Dump the symbol table from one or more target modules.",
- nullptr),
- m_options()
- {
- }
-
- ~CommandObjectTargetModulesDumpSymtab() override = default;
-
- Options *
- GetOptions () override
- {
- return &m_options;
- }
-
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options(),
- m_sort_order(eSortOrderNone)
- {
- }
+ CommandObjectTargetModulesDumpSymtab(CommandInterpreter &interpreter)
+ : CommandObjectTargetModulesModuleAutoComplete(
+ interpreter, "target modules dump symtab",
+ "Dump the symbol table from one or more target modules.", nullptr),
+ m_options() {}
- ~CommandOptions() override = default;
+ ~CommandObjectTargetModulesDumpSymtab() override = default;
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
+ Options *GetOptions() override { return &m_options; }
- switch (short_option)
- {
- case 's':
- m_sort_order = (SortOrder) Args::StringToOptionEnum (option_arg,
- g_option_table[option_idx].enum_values,
- eSortOrderNone,
- error);
- break;
-
- default:
- error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
- break;
- }
- return error;
- }
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options(), m_sort_order(eSortOrderNone) {}
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_sort_order = eSortOrderNone;
- }
+ ~CommandOptions() override = default;
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
- // Options table: Required for subclasses of Options.
- static OptionDefinition g_option_table[];
+ switch (short_option) {
+ case 's':
+ m_sort_order = (SortOrder)Args::StringToOptionEnum(
+ option_arg, g_option_table[option_idx].enum_values, eSortOrderNone,
+ error);
+ break;
- SortOrder m_sort_order;
- };
+ default:
+ error.SetErrorStringWithFormat("invalid short option character '%c'",
+ short_option);
+ break;
+ }
+ return error;
+ }
-protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (target == nullptr)
- {
- result.AppendError ("invalid target, create a debug target using the 'target create' command");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- else
- {
- uint32_t num_dumped = 0;
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_sort_order = eSortOrderNone;
+ }
- uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
- result.GetOutputStream().SetAddressByteSize(addr_byte_size);
- result.GetErrorStream().SetAddressByteSize(addr_byte_size);
-
- if (command.GetArgumentCount() == 0)
- {
- // Dump all sections for all modules images
- std::lock_guard<std::recursive_mutex> guard(target->GetImages().GetMutex());
- const size_t num_modules = target->GetImages().GetSize();
- if (num_modules > 0)
- {
- result.GetOutputStream().Printf("Dumping symbol table for %" PRIu64 " modules.\n", (uint64_t)num_modules);
- for (size_t image_idx = 0; image_idx<num_modules; ++image_idx)
- {
- if (num_dumped > 0)
- {
- result.GetOutputStream().EOL();
- result.GetOutputStream().EOL();
- }
- num_dumped++;
- DumpModuleSymtab (m_interpreter,
- result.GetOutputStream(),
- target->GetImages().GetModulePointerAtIndexUnlocked(image_idx),
- m_options.m_sort_order);
- }
- }
- else
- {
- result.AppendError ("the target has no associated executable images");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- else
- {
- // Dump specified images (by basename or fullpath)
- const char *arg_cstr;
- for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr; ++arg_idx)
- {
- ModuleList module_list;
- const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
- if (num_matches > 0)
- {
- for (size_t i = 0; i < num_matches; ++i)
- {
- Module *module = module_list.GetModulePointerAtIndex(i);
- if (module)
- {
- if (num_dumped > 0)
- {
- result.GetOutputStream().EOL();
- result.GetOutputStream().EOL();
- }
- num_dumped++;
- DumpModuleSymtab (m_interpreter, result.GetOutputStream(), module, m_options.m_sort_order);
- }
- }
- }
- else
- result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
- }
- }
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
- if (num_dumped > 0)
- result.SetStatus (eReturnStatusSuccessFinishResult);
- else
- {
- result.AppendError ("no matching executable images found");
- result.SetStatus (eReturnStatusFailed);
- }
+ // Options table: Required for subclasses of Options.
+ static OptionDefinition g_option_table[];
+
+ SortOrder m_sort_order;
+ };
+
+protected:
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target == nullptr) {
+ result.AppendError("invalid target, create a debug target using the "
+ "'target create' command");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ } else {
+ uint32_t num_dumped = 0;
+
+ uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
+ result.GetOutputStream().SetAddressByteSize(addr_byte_size);
+ result.GetErrorStream().SetAddressByteSize(addr_byte_size);
+
+ if (command.GetArgumentCount() == 0) {
+ // Dump all sections for all modules images
+ std::lock_guard<std::recursive_mutex> guard(
+ target->GetImages().GetMutex());
+ const size_t num_modules = target->GetImages().GetSize();
+ if (num_modules > 0) {
+ result.GetOutputStream().Printf("Dumping symbol table for %" PRIu64
+ " modules.\n",
+ (uint64_t)num_modules);
+ for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
+ if (num_dumped > 0) {
+ result.GetOutputStream().EOL();
+ result.GetOutputStream().EOL();
+ }
+ num_dumped++;
+ DumpModuleSymtab(
+ m_interpreter, result.GetOutputStream(),
+ target->GetImages().GetModulePointerAtIndexUnlocked(image_idx),
+ m_options.m_sort_order);
+ }
+ } else {
+ result.AppendError("the target has no associated executable images");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ } else {
+ // Dump specified images (by basename or fullpath)
+ const char *arg_cstr;
+ for (int arg_idx = 0;
+ (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
+ ++arg_idx) {
+ ModuleList module_list;
+ const size_t num_matches =
+ FindModulesByName(target, arg_cstr, module_list, true);
+ if (num_matches > 0) {
+ for (size_t i = 0; i < num_matches; ++i) {
+ Module *module = module_list.GetModulePointerAtIndex(i);
+ if (module) {
+ if (num_dumped > 0) {
+ result.GetOutputStream().EOL();
+ result.GetOutputStream().EOL();
+ }
+ num_dumped++;
+ DumpModuleSymtab(m_interpreter, result.GetOutputStream(),
+ module, m_options.m_sort_order);
+ }
+ }
+ } else
+ result.AppendWarningWithFormat(
+ "Unable to find an image that matches '%s'.\n", arg_cstr);
}
- return result.Succeeded();
+ }
+
+ if (num_dumped > 0)
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ else {
+ result.AppendError("no matching executable images found");
+ result.SetStatus(eReturnStatusFailed);
+ }
}
+ return result.Succeeded();
+ }
- CommandOptions m_options;
+ CommandOptions m_options;
};
-static OptionEnumValueElement
-g_sort_option_enumeration[4] =
-{
- { eSortOrderNone, "none", "No sorting, use the original symbol table order."},
- { eSortOrderByAddress, "address", "Sort output by symbol address."},
- { eSortOrderByName, "name", "Sort output by symbol name."},
- { 0, nullptr, nullptr }
-};
+static OptionEnumValueElement g_sort_option_enumeration[4] = {
+ {eSortOrderNone, "none",
+ "No sorting, use the original symbol table order."},
+ {eSortOrderByAddress, "address", "Sort output by symbol address."},
+ {eSortOrderByName, "name", "Sort output by symbol name."},
+ {0, nullptr, nullptr}};
OptionDefinition
-CommandObjectTargetModulesDumpSymtab::CommandOptions::g_option_table[] =
-{
- // clang-format off
+ CommandObjectTargetModulesDumpSymtab::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_1, false, "sort", 's', OptionParser::eRequiredArgument, nullptr, g_sort_option_enumeration, 0, eArgTypeSortOrder, "Supply a sort order when dumping the symbol table."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
#pragma mark CommandObjectTargetModulesDumpSections
@@ -2400,99 +2092,89 @@ CommandObjectTargetModulesDumpSymtab::Co
// Image section dumping command
//----------------------------------------------------------------------
-class CommandObjectTargetModulesDumpSections : public CommandObjectTargetModulesModuleAutoComplete
-{
+class CommandObjectTargetModulesDumpSections
+ : public CommandObjectTargetModulesModuleAutoComplete {
public:
- CommandObjectTargetModulesDumpSections (CommandInterpreter &interpreter) :
- CommandObjectTargetModulesModuleAutoComplete(interpreter,
- "target modules dump sections",
- "Dump the sections from one or more target modules.",
- //"target modules dump sections [<file1> ...]")
- nullptr)
- {
- }
+ CommandObjectTargetModulesDumpSections(CommandInterpreter &interpreter)
+ : CommandObjectTargetModulesModuleAutoComplete(
+ interpreter, "target modules dump sections",
+ "Dump the sections from one or more target modules.",
+ //"target modules dump sections [<file1> ...]")
+ nullptr) {}
- ~CommandObjectTargetModulesDumpSections() override = default;
+ ~CommandObjectTargetModulesDumpSections() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (target == nullptr)
- {
- result.AppendError ("invalid target, create a debug target using the 'target create' command");
- result.SetStatus (eReturnStatusFailed);
- return false;
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target == nullptr) {
+ result.AppendError("invalid target, create a debug target using the "
+ "'target create' command");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ } else {
+ uint32_t num_dumped = 0;
+
+ uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
+ result.GetOutputStream().SetAddressByteSize(addr_byte_size);
+ result.GetErrorStream().SetAddressByteSize(addr_byte_size);
+
+ if (command.GetArgumentCount() == 0) {
+ // Dump all sections for all modules images
+ const size_t num_modules = target->GetImages().GetSize();
+ if (num_modules > 0) {
+ result.GetOutputStream().Printf("Dumping sections for %" PRIu64
+ " modules.\n",
+ (uint64_t)num_modules);
+ for (size_t image_idx = 0; image_idx < num_modules; ++image_idx) {
+ num_dumped++;
+ DumpModuleSections(
+ m_interpreter, result.GetOutputStream(),
+ target->GetImages().GetModulePointerAtIndex(image_idx));
+ }
+ } else {
+ result.AppendError("the target has no associated executable images");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ } else {
+ // Dump specified images (by basename or fullpath)
+ const char *arg_cstr;
+ for (int arg_idx = 0;
+ (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
+ ++arg_idx) {
+ ModuleList module_list;
+ const size_t num_matches =
+ FindModulesByName(target, arg_cstr, module_list, true);
+ if (num_matches > 0) {
+ for (size_t i = 0; i < num_matches; ++i) {
+ Module *module = module_list.GetModulePointerAtIndex(i);
+ if (module) {
+ num_dumped++;
+ DumpModuleSections(m_interpreter, result.GetOutputStream(),
+ module);
+ }
+ }
+ } else {
+ // Check the global list
+ std::lock_guard<std::recursive_mutex> guard(
+ Module::GetAllocationModuleCollectionMutex());
+
+ result.AppendWarningWithFormat(
+ "Unable to find an image that matches '%s'.\n", arg_cstr);
+ }
}
- else
- {
- uint32_t num_dumped = 0;
+ }
- uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
- result.GetOutputStream().SetAddressByteSize(addr_byte_size);
- result.GetErrorStream().SetAddressByteSize(addr_byte_size);
-
- if (command.GetArgumentCount() == 0)
- {
- // Dump all sections for all modules images
- const size_t num_modules = target->GetImages().GetSize();
- if (num_modules > 0)
- {
- result.GetOutputStream().Printf("Dumping sections for %" PRIu64 " modules.\n", (uint64_t)num_modules);
- for (size_t image_idx = 0; image_idx<num_modules; ++image_idx)
- {
- num_dumped++;
- DumpModuleSections (m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx));
- }
- }
- else
- {
- result.AppendError ("the target has no associated executable images");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- else
- {
- // Dump specified images (by basename or fullpath)
- const char *arg_cstr;
- for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr; ++arg_idx)
- {
- ModuleList module_list;
- const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
- if (num_matches > 0)
- {
- for (size_t i = 0; i < num_matches; ++i)
- {
- Module *module = module_list.GetModulePointerAtIndex(i);
- if (module)
- {
- num_dumped++;
- DumpModuleSections (m_interpreter, result.GetOutputStream(), module);
- }
- }
- }
- else
- {
- // Check the global list
- std::lock_guard<std::recursive_mutex> guard(Module::GetAllocationModuleCollectionMutex());
-
- result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
- }
- }
- }
-
- if (num_dumped > 0)
- result.SetStatus (eReturnStatusSuccessFinishResult);
- else
- {
- result.AppendError ("no matching executable images found");
- result.SetStatus (eReturnStatusFailed);
- }
- }
- return result.Succeeded();
+ if (num_dumped > 0)
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ else {
+ result.AppendError("no matching executable images found");
+ result.SetStatus(eReturnStatusFailed);
+ }
}
+ return result.Succeeded();
+ }
};
#pragma mark CommandObjectTargetModulesDumpSymfile
@@ -2501,96 +2183,85 @@ protected:
// Image debug symbol dumping command
//----------------------------------------------------------------------
-class CommandObjectTargetModulesDumpSymfile : public CommandObjectTargetModulesModuleAutoComplete
-{
+class CommandObjectTargetModulesDumpSymfile
+ : public CommandObjectTargetModulesModuleAutoComplete {
public:
- CommandObjectTargetModulesDumpSymfile (CommandInterpreter &interpreter) :
- CommandObjectTargetModulesModuleAutoComplete(interpreter,
- "target modules dump symfile",
- "Dump the debug symbol file for one or more target modules.",
- //"target modules dump symfile [<file1> ...]")
- nullptr)
- {
- }
+ CommandObjectTargetModulesDumpSymfile(CommandInterpreter &interpreter)
+ : CommandObjectTargetModulesModuleAutoComplete(
+ interpreter, "target modules dump symfile",
+ "Dump the debug symbol file for one or more target modules.",
+ //"target modules dump symfile [<file1> ...]")
+ nullptr) {}
- ~CommandObjectTargetModulesDumpSymfile() override = default;
+ ~CommandObjectTargetModulesDumpSymfile() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (target == nullptr)
- {
- result.AppendError ("invalid target, create a debug target using the 'target create' command");
- result.SetStatus (eReturnStatusFailed);
- return false;
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target == nullptr) {
+ result.AppendError("invalid target, create a debug target using the "
+ "'target create' command");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ } else {
+ uint32_t num_dumped = 0;
+
+ uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
+ result.GetOutputStream().SetAddressByteSize(addr_byte_size);
+ result.GetErrorStream().SetAddressByteSize(addr_byte_size);
+
+ if (command.GetArgumentCount() == 0) {
+ // Dump all sections for all modules images
+ const ModuleList &target_modules = target->GetImages();
+ std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
+ const size_t num_modules = target_modules.GetSize();
+ if (num_modules > 0) {
+ result.GetOutputStream().Printf("Dumping debug symbols for %" PRIu64
+ " modules.\n",
+ (uint64_t)num_modules);
+ for (uint32_t image_idx = 0; image_idx < num_modules; ++image_idx) {
+ if (DumpModuleSymbolVendor(
+ result.GetOutputStream(),
+ target_modules.GetModulePointerAtIndexUnlocked(image_idx)))
+ num_dumped++;
+ }
+ } else {
+ result.AppendError("the target has no associated executable images");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ } else {
+ // Dump specified images (by basename or fullpath)
+ const char *arg_cstr;
+ for (int arg_idx = 0;
+ (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
+ ++arg_idx) {
+ ModuleList module_list;
+ const size_t num_matches =
+ FindModulesByName(target, arg_cstr, module_list, true);
+ if (num_matches > 0) {
+ for (size_t i = 0; i < num_matches; ++i) {
+ Module *module = module_list.GetModulePointerAtIndex(i);
+ if (module) {
+ if (DumpModuleSymbolVendor(result.GetOutputStream(), module))
+ num_dumped++;
+ }
+ }
+ } else
+ result.AppendWarningWithFormat(
+ "Unable to find an image that matches '%s'.\n", arg_cstr);
}
- else
- {
- uint32_t num_dumped = 0;
+ }
- uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
- result.GetOutputStream().SetAddressByteSize(addr_byte_size);
- result.GetErrorStream().SetAddressByteSize(addr_byte_size);
-
- if (command.GetArgumentCount() == 0)
- {
- // Dump all sections for all modules images
- const ModuleList &target_modules = target->GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
- const size_t num_modules = target_modules.GetSize();
- if (num_modules > 0)
- {
- result.GetOutputStream().Printf("Dumping debug symbols for %" PRIu64 " modules.\n", (uint64_t)num_modules);
- for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
- {
- if (DumpModuleSymbolVendor (result.GetOutputStream(), target_modules.GetModulePointerAtIndexUnlocked(image_idx)))
- num_dumped++;
- }
- }
- else
- {
- result.AppendError ("the target has no associated executable images");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- else
- {
- // Dump specified images (by basename or fullpath)
- const char *arg_cstr;
- for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr; ++arg_idx)
- {
- ModuleList module_list;
- const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, true);
- if (num_matches > 0)
- {
- for (size_t i = 0; i < num_matches; ++i)
- {
- Module *module = module_list.GetModulePointerAtIndex(i);
- if (module)
- {
- if (DumpModuleSymbolVendor (result.GetOutputStream(), module))
- num_dumped++;
- }
- }
- }
- else
- result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
- }
- }
-
- if (num_dumped > 0)
- result.SetStatus (eReturnStatusSuccessFinishResult);
- else
- {
- result.AppendError ("no matching executable images found");
- result.SetStatus (eReturnStatusFailed);
- }
- }
- return result.Succeeded();
+ if (num_dumped > 0)
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ else {
+ result.AppendError("no matching executable images found");
+ result.SetStatus(eReturnStatusFailed);
+ }
}
+ return result.Succeeded();
+ }
};
#pragma mark CommandObjectTargetModulesDumpLineTable
@@ -2599,77 +2270,68 @@ protected:
// Image debug line table dumping command
//----------------------------------------------------------------------
-class CommandObjectTargetModulesDumpLineTable : public CommandObjectTargetModulesSourceFileAutoComplete
-{
+class CommandObjectTargetModulesDumpLineTable
+ : public CommandObjectTargetModulesSourceFileAutoComplete {
public:
- CommandObjectTargetModulesDumpLineTable (CommandInterpreter &interpreter) :
- CommandObjectTargetModulesSourceFileAutoComplete(interpreter,
- "target modules dump line-table",
- "Dump the line table for one or more compilation units.",
- nullptr,
- eCommandRequiresTarget)
- {
- }
+ CommandObjectTargetModulesDumpLineTable(CommandInterpreter &interpreter)
+ : CommandObjectTargetModulesSourceFileAutoComplete(
+ interpreter, "target modules dump line-table",
+ "Dump the line table for one or more compilation units.", nullptr,
+ eCommandRequiresTarget) {}
- ~CommandObjectTargetModulesDumpLineTable() override = default;
+ ~CommandObjectTargetModulesDumpLineTable() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_exe_ctx.GetTargetPtr();
- uint32_t total_num_dumped = 0;
-
- uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
- result.GetOutputStream().SetAddressByteSize(addr_byte_size);
- result.GetErrorStream().SetAddressByteSize(addr_byte_size);
-
- if (command.GetArgumentCount() == 0)
- {
- result.AppendError ("file option must be specified.");
- result.SetStatus (eReturnStatusFailed);
- return result.Succeeded();
- }
- else
- {
- // Dump specified images (by basename or fullpath)
- const char *arg_cstr;
- for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr; ++arg_idx)
- {
- FileSpec file_spec(arg_cstr, false);
-
- const ModuleList &target_modules = target->GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
- const size_t num_modules = target_modules.GetSize();
- if (num_modules > 0)
- {
- uint32_t num_dumped = 0;
- for (uint32_t i = 0; i<num_modules; ++i)
- {
- if (DumpCompileUnitLineTable (m_interpreter,
- result.GetOutputStream(),
- target_modules.GetModulePointerAtIndexUnlocked(i),
- file_spec,
- m_exe_ctx.GetProcessPtr() && m_exe_ctx.GetProcessRef().IsAlive()))
- num_dumped++;
- }
- if (num_dumped == 0)
- result.AppendWarningWithFormat ("No source filenames matched '%s'.\n", arg_cstr);
- else
- total_num_dumped += num_dumped;
- }
- }
- }
-
- if (total_num_dumped > 0)
- result.SetStatus (eReturnStatusSuccessFinishResult);
- else
- {
- result.AppendError ("no source filenames matched any command arguments");
- result.SetStatus (eReturnStatusFailed);
- }
- return result.Succeeded();
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_exe_ctx.GetTargetPtr();
+ uint32_t total_num_dumped = 0;
+
+ uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
+ result.GetOutputStream().SetAddressByteSize(addr_byte_size);
+ result.GetErrorStream().SetAddressByteSize(addr_byte_size);
+
+ if (command.GetArgumentCount() == 0) {
+ result.AppendError("file option must be specified.");
+ result.SetStatus(eReturnStatusFailed);
+ return result.Succeeded();
+ } else {
+ // Dump specified images (by basename or fullpath)
+ const char *arg_cstr;
+ for (int arg_idx = 0;
+ (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != nullptr;
+ ++arg_idx) {
+ FileSpec file_spec(arg_cstr, false);
+
+ const ModuleList &target_modules = target->GetImages();
+ std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
+ const size_t num_modules = target_modules.GetSize();
+ if (num_modules > 0) {
+ uint32_t num_dumped = 0;
+ for (uint32_t i = 0; i < num_modules; ++i) {
+ if (DumpCompileUnitLineTable(
+ m_interpreter, result.GetOutputStream(),
+ target_modules.GetModulePointerAtIndexUnlocked(i),
+ file_spec, m_exe_ctx.GetProcessPtr() &&
+ m_exe_ctx.GetProcessRef().IsAlive()))
+ num_dumped++;
+ }
+ if (num_dumped == 0)
+ result.AppendWarningWithFormat(
+ "No source filenames matched '%s'.\n", arg_cstr);
+ else
+ total_num_dumped += num_dumped;
+ }
+ }
+ }
+
+ if (total_num_dumped > 0)
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ else {
+ result.AppendError("no source filenames matched any command arguments");
+ result.SetStatus(eReturnStatusFailed);
}
+ return result.Succeeded();
+ }
};
#pragma mark CommandObjectTargetModulesDump
@@ -2678,889 +2340,784 @@ protected:
// Dump multi-word command for target modules
//----------------------------------------------------------------------
-class CommandObjectTargetModulesDump : public CommandObjectMultiword
-{
+class CommandObjectTargetModulesDump : public CommandObjectMultiword {
public:
- //------------------------------------------------------------------
- // Constructors and Destructors
- //------------------------------------------------------------------
- CommandObjectTargetModulesDump(CommandInterpreter &interpreter)
- : CommandObjectMultiword(
- interpreter, "target modules dump", "Commands for dumping information about one or more target modules.",
- "target modules dump [headers|symtab|sections|symfile|line-table] [<file1> <file2> ...]")
- {
- LoadSubCommand("objfile", CommandObjectSP(new CommandObjectTargetModulesDumpObjfile(interpreter)));
- LoadSubCommand ("symtab", CommandObjectSP (new CommandObjectTargetModulesDumpSymtab (interpreter)));
- LoadSubCommand ("sections", CommandObjectSP (new CommandObjectTargetModulesDumpSections (interpreter)));
- LoadSubCommand ("symfile", CommandObjectSP (new CommandObjectTargetModulesDumpSymfile (interpreter)));
- LoadSubCommand ("line-table", CommandObjectSP (new CommandObjectTargetModulesDumpLineTable (interpreter)));
- }
+ //------------------------------------------------------------------
+ // Constructors and Destructors
+ //------------------------------------------------------------------
+ CommandObjectTargetModulesDump(CommandInterpreter &interpreter)
+ : CommandObjectMultiword(interpreter, "target modules dump",
+ "Commands for dumping information about one or "
+ "more target modules.",
+ "target modules dump "
+ "[headers|symtab|sections|symfile|line-table] "
+ "[<file1> <file2> ...]") {
+ LoadSubCommand("objfile",
+ CommandObjectSP(
+ new CommandObjectTargetModulesDumpObjfile(interpreter)));
+ LoadSubCommand(
+ "symtab",
+ CommandObjectSP(new CommandObjectTargetModulesDumpSymtab(interpreter)));
+ LoadSubCommand("sections",
+ CommandObjectSP(new CommandObjectTargetModulesDumpSections(
+ interpreter)));
+ LoadSubCommand("symfile",
+ CommandObjectSP(
+ new CommandObjectTargetModulesDumpSymfile(interpreter)));
+ LoadSubCommand("line-table",
+ CommandObjectSP(new CommandObjectTargetModulesDumpLineTable(
+ interpreter)));
+ }
- ~CommandObjectTargetModulesDump() override = default;
+ ~CommandObjectTargetModulesDump() override = default;
};
-class CommandObjectTargetModulesAdd : public CommandObjectParsed
-{
+class CommandObjectTargetModulesAdd : public CommandObjectParsed {
public:
- CommandObjectTargetModulesAdd (CommandInterpreter &interpreter) :
- CommandObjectParsed (interpreter,
- "target modules add",
- "Add a new module to the current target's modules.",
- "target modules add [<module>]"),
+ CommandObjectTargetModulesAdd(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "target modules add",
+ "Add a new module to the current target's modules.",
+ "target modules add [<module>]"),
m_option_group(),
- m_symbol_file (LLDB_OPT_SET_1, false, "symfile", 's', 0, eArgTypeFilename, "Fullpath to a stand alone debug symbols file for when debug symbols are not in the executable.")
- {
- m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Append (&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Finalize();
- }
-
- ~CommandObjectTargetModulesAdd() override = default;
-
- Options *
- GetOptions () override
- {
- return &m_option_group;
- }
-
- int
- HandleArgumentCompletion (Args &input,
- int &cursor_index,
- int &cursor_char_position,
- OptionElementVector &opt_element_vector,
- int match_start_point,
- int max_return_elements,
- bool &word_complete,
- StringList &matches) override
- {
- std::string completion_str (input.GetArgumentAtIndex(cursor_index));
- completion_str.erase (cursor_char_position);
-
- CommandCompletions::InvokeCommonCompletionCallbacks(GetCommandInterpreter(),
- CommandCompletions::eDiskFileCompletion,
- completion_str.c_str(),
- match_start_point,
- max_return_elements,
- nullptr,
- word_complete,
- matches);
- return matches.GetSize();
- }
+ m_symbol_file(LLDB_OPT_SET_1, false, "symfile", 's', 0,
+ eArgTypeFilename, "Fullpath to a stand alone debug "
+ "symbols file for when debug symbols "
+ "are not in the executable.") {
+ m_option_group.Append(&m_uuid_option_group, LLDB_OPT_SET_ALL,
+ LLDB_OPT_SET_1);
+ m_option_group.Append(&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Finalize();
+ }
+
+ ~CommandObjectTargetModulesAdd() override = default;
+
+ Options *GetOptions() override { return &m_option_group; }
+
+ int HandleArgumentCompletion(Args &input, int &cursor_index,
+ int &cursor_char_position,
+ OptionElementVector &opt_element_vector,
+ int match_start_point, int max_return_elements,
+ bool &word_complete,
+ StringList &matches) override {
+ std::string completion_str(input.GetArgumentAtIndex(cursor_index));
+ completion_str.erase(cursor_char_position);
+
+ CommandCompletions::InvokeCommonCompletionCallbacks(
+ GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
+ completion_str.c_str(), match_start_point, max_return_elements, nullptr,
+ word_complete, matches);
+ return matches.GetSize();
+ }
protected:
- OptionGroupOptions m_option_group;
- OptionGroupUUID m_uuid_option_group;
- OptionGroupFile m_symbol_file;
-
- bool
- DoExecute (Args& args, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (target == nullptr)
- {
- result.AppendError ("invalid target, create a debug target using the 'target create' command");
- result.SetStatus (eReturnStatusFailed);
+ OptionGroupOptions m_option_group;
+ OptionGroupUUID m_uuid_option_group;
+ OptionGroupFile m_symbol_file;
+
+ bool DoExecute(Args &args, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target == nullptr) {
+ result.AppendError("invalid target, create a debug target using the "
+ "'target create' command");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ } else {
+ bool flush = false;
+
+ const size_t argc = args.GetArgumentCount();
+ if (argc == 0) {
+ if (m_uuid_option_group.GetOptionValue().OptionWasSet()) {
+ // We are given a UUID only, go locate the file
+ ModuleSpec module_spec;
+ module_spec.GetUUID() =
+ m_uuid_option_group.GetOptionValue().GetCurrentValue();
+ if (m_symbol_file.GetOptionValue().OptionWasSet())
+ module_spec.GetSymbolFileSpec() =
+ m_symbol_file.GetOptionValue().GetCurrentValue();
+ if (Symbols::DownloadObjectAndSymbolFile(module_spec)) {
+ ModuleSP module_sp(target->GetSharedModule(module_spec));
+ if (module_sp) {
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return true;
+ } else {
+ StreamString strm;
+ module_spec.GetUUID().Dump(&strm);
+ if (module_spec.GetFileSpec()) {
+ if (module_spec.GetSymbolFileSpec()) {
+ result.AppendErrorWithFormat(
+ "Unable to create the executable or symbol file with "
+ "UUID %s with path %s and symbol file %s",
+ strm.GetString().c_str(),
+ module_spec.GetFileSpec().GetPath().c_str(),
+ module_spec.GetSymbolFileSpec().GetPath().c_str());
+ } else {
+ result.AppendErrorWithFormat(
+ "Unable to create the executable or symbol file with "
+ "UUID %s with path %s",
+ strm.GetString().c_str(),
+ module_spec.GetFileSpec().GetPath().c_str());
+ }
+ } else {
+ result.AppendErrorWithFormat("Unable to create the executable "
+ "or symbol file with UUID %s",
+ strm.GetString().c_str());
+ }
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ } else {
+ StreamString strm;
+ module_spec.GetUUID().Dump(&strm);
+ result.AppendErrorWithFormat(
+ "Unable to locate the executable or symbol file with UUID %s",
+ strm.GetString().c_str());
+ result.SetStatus(eReturnStatusFailed);
return false;
- }
- else
- {
- bool flush = false;
-
- const size_t argc = args.GetArgumentCount();
- if (argc == 0)
- {
- if (m_uuid_option_group.GetOptionValue ().OptionWasSet())
- {
- // We are given a UUID only, go locate the file
- ModuleSpec module_spec;
- module_spec.GetUUID() = m_uuid_option_group.GetOptionValue ().GetCurrentValue();
- if (m_symbol_file.GetOptionValue().OptionWasSet())
- module_spec.GetSymbolFileSpec() = m_symbol_file.GetOptionValue().GetCurrentValue();
- if (Symbols::DownloadObjectAndSymbolFile (module_spec))
- {
- ModuleSP module_sp (target->GetSharedModule (module_spec));
- if (module_sp)
- {
- result.SetStatus (eReturnStatusSuccessFinishResult);
- return true;
- }
- else
- {
- StreamString strm;
- module_spec.GetUUID().Dump (&strm);
- if (module_spec.GetFileSpec())
- {
- if (module_spec.GetSymbolFileSpec())
- {
- result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s with path %s and symbol file %s",
- strm.GetString().c_str(),
- module_spec.GetFileSpec().GetPath().c_str(),
- module_spec.GetSymbolFileSpec().GetPath().c_str());
- }
- else
- {
- result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s with path %s",
- strm.GetString().c_str(),
- module_spec.GetFileSpec().GetPath().c_str());
- }
- }
- else
- {
- result.AppendErrorWithFormat ("Unable to create the executable or symbol file with UUID %s",
- strm.GetString().c_str());
- }
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- else
- {
- StreamString strm;
- module_spec.GetUUID().Dump (&strm);
- result.AppendErrorWithFormat ("Unable to locate the executable or symbol file with UUID %s", strm.GetString().c_str());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
+ }
+ } else {
+ result.AppendError(
+ "one or more executable image paths must be specified");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ } else {
+ for (size_t i = 0; i < argc; ++i) {
+ const char *path = args.GetArgumentAtIndex(i);
+ if (path) {
+ FileSpec file_spec(path, true);
+ if (file_spec.Exists()) {
+ ModuleSpec module_spec(file_spec);
+ if (m_uuid_option_group.GetOptionValue().OptionWasSet())
+ module_spec.GetUUID() =
+ m_uuid_option_group.GetOptionValue().GetCurrentValue();
+ if (m_symbol_file.GetOptionValue().OptionWasSet())
+ module_spec.GetSymbolFileSpec() =
+ m_symbol_file.GetOptionValue().GetCurrentValue();
+ if (!module_spec.GetArchitecture().IsValid())
+ module_spec.GetArchitecture() = target->GetArchitecture();
+ Error error;
+ ModuleSP module_sp(target->GetSharedModule(module_spec, &error));
+ if (!module_sp) {
+ const char *error_cstr = error.AsCString();
+ if (error_cstr)
+ result.AppendError(error_cstr);
else
- {
- result.AppendError ("one or more executable image paths must be specified");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- else
- {
- for (size_t i = 0; i < argc; ++i)
- {
- const char *path = args.GetArgumentAtIndex(i);
- if (path)
- {
- FileSpec file_spec(path, true);
- if (file_spec.Exists())
- {
- ModuleSpec module_spec (file_spec);
- if (m_uuid_option_group.GetOptionValue ().OptionWasSet())
- module_spec.GetUUID() = m_uuid_option_group.GetOptionValue ().GetCurrentValue();
- if (m_symbol_file.GetOptionValue().OptionWasSet())
- module_spec.GetSymbolFileSpec() = m_symbol_file.GetOptionValue().GetCurrentValue();
- if (!module_spec.GetArchitecture().IsValid())
- module_spec.GetArchitecture() = target->GetArchitecture();
- Error error;
- ModuleSP module_sp (target->GetSharedModule (module_spec, &error));
- if (!module_sp)
- {
- const char *error_cstr = error.AsCString();
- if (error_cstr)
- result.AppendError (error_cstr);
- else
- result.AppendErrorWithFormat ("unsupported module: %s", path);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- else
- {
- flush = true;
- }
- result.SetStatus (eReturnStatusSuccessFinishResult);
- }
- else
- {
- char resolved_path[PATH_MAX];
- result.SetStatus (eReturnStatusFailed);
- if (file_spec.GetPath (resolved_path, sizeof(resolved_path)))
- {
- if (strcmp (resolved_path, path) != 0)
- {
- result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", path, resolved_path);
- break;
- }
- }
- result.AppendErrorWithFormat ("invalid module path '%s'\n", path);
- break;
- }
- }
- }
- }
-
- if (flush)
- {
- ProcessSP process = target->GetProcessSP();
- if (process)
- process->Flush();
+ result.AppendErrorWithFormat("unsupported module: %s", path);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ } else {
+ flush = true;
+ }
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ } else {
+ char resolved_path[PATH_MAX];
+ result.SetStatus(eReturnStatusFailed);
+ if (file_spec.GetPath(resolved_path, sizeof(resolved_path))) {
+ if (strcmp(resolved_path, path) != 0) {
+ result.AppendErrorWithFormat(
+ "invalid module path '%s' with resolved path '%s'\n",
+ path, resolved_path);
+ break;
+ }
+ }
+ result.AppendErrorWithFormat("invalid module path '%s'\n", path);
+ break;
}
+ }
}
+ }
- return result.Succeeded();
+ if (flush) {
+ ProcessSP process = target->GetProcessSP();
+ if (process)
+ process->Flush();
+ }
}
+
+ return result.Succeeded();
+ }
};
-class CommandObjectTargetModulesLoad : public CommandObjectTargetModulesModuleAutoComplete
-{
+class CommandObjectTargetModulesLoad
+ : public CommandObjectTargetModulesModuleAutoComplete {
public:
- CommandObjectTargetModulesLoad (CommandInterpreter &interpreter) :
- CommandObjectTargetModulesModuleAutoComplete (interpreter,
- "target modules load",
- "Set the load addresses for one or more sections in a target module.",
- "target modules load [--file <module> --uuid <uuid>] <sect-name> <address> [<sect-name> <address> ....]"),
+ CommandObjectTargetModulesLoad(CommandInterpreter &interpreter)
+ : CommandObjectTargetModulesModuleAutoComplete(
+ interpreter, "target modules load", "Set the load addresses for "
+ "one or more sections in a "
+ "target module.",
+ "target modules load [--file <module> --uuid <uuid>] <sect-name> "
+ "<address> [<sect-name> <address> ....]"),
m_option_group(),
- m_file_option (LLDB_OPT_SET_1, false, "file", 'f', 0, eArgTypeName, "Fullpath or basename for module to load.", ""),
- m_slide_option(LLDB_OPT_SET_1, false, "slide", 's', 0, eArgTypeOffset, "Set the load address for all sections to be the virtual address in the file plus the offset.", 0)
- {
- m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Append (&m_slide_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Finalize();
- }
+ m_file_option(LLDB_OPT_SET_1, false, "file", 'f', 0, eArgTypeName,
+ "Fullpath or basename for module to load.", ""),
+ m_slide_option(LLDB_OPT_SET_1, false, "slide", 's', 0, eArgTypeOffset,
+ "Set the load address for all sections to be the "
+ "virtual address in the file plus the offset.",
+ 0) {
+ m_option_group.Append(&m_uuid_option_group, LLDB_OPT_SET_ALL,
+ LLDB_OPT_SET_1);
+ m_option_group.Append(&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Append(&m_slide_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Finalize();
+ }
- ~CommandObjectTargetModulesLoad() override = default;
-
- Options *
- GetOptions () override
- {
- return &m_option_group;
- }
-
-protected:
- bool
- DoExecute (Args& args, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (target == nullptr)
- {
- result.AppendError ("invalid target, create a debug target using the 'target create' command");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- else
- {
- const size_t argc = args.GetArgumentCount();
- ModuleSpec module_spec;
- bool search_using_module_spec = false;
- if (m_file_option.GetOptionValue().OptionWasSet())
- {
- search_using_module_spec = true;
- const char *arg_cstr = m_file_option.GetOptionValue().GetCurrentValue();
- const bool use_global_module_list = true;
- ModuleList module_list;
- const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, use_global_module_list);
- if (num_matches == 1)
- {
- module_spec.GetFileSpec() = module_list.GetModuleAtIndex(0)->GetFileSpec();
- }
- else if (num_matches > 1 )
- {
- search_using_module_spec = false;
- result.AppendErrorWithFormat ("more than 1 module matched by name '%s'\n", arg_cstr);
- result.SetStatus (eReturnStatusFailed);
- }
- else
- {
- search_using_module_spec = false;
- result.AppendErrorWithFormat ("no object file for module '%s'\n", arg_cstr);
- result.SetStatus (eReturnStatusFailed);
- }
- }
+ ~CommandObjectTargetModulesLoad() override = default;
- if (m_uuid_option_group.GetOptionValue().OptionWasSet())
- {
- search_using_module_spec = true;
- module_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue();
- }
+ Options *GetOptions() override { return &m_option_group; }
- if (search_using_module_spec)
- {
- ModuleList matching_modules;
- const size_t num_matches = target->GetImages().FindModules (module_spec, matching_modules);
-
- char path[PATH_MAX];
- if (num_matches == 1)
- {
- Module *module = matching_modules.GetModulePointerAtIndex(0);
- if (module)
- {
- ObjectFile *objfile = module->GetObjectFile();
- if (objfile)
- {
- SectionList *section_list = module->GetSectionList();
- if (section_list)
- {
- bool changed = false;
- if (argc == 0)
- {
- if (m_slide_option.GetOptionValue().OptionWasSet())
- {
- const addr_t slide = m_slide_option.GetOptionValue().GetCurrentValue();
- const bool slide_is_offset = true;
- module->SetLoadAddress (*target, slide, slide_is_offset, changed);
- }
- else
- {
- result.AppendError ("one or more section name + load address pair must be specified");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- else
- {
- if (m_slide_option.GetOptionValue().OptionWasSet())
- {
- result.AppendError ("The \"--slide <offset>\" option can't be used in conjunction with setting section load addresses.\n");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- for (size_t i = 0; i < argc; i += 2)
- {
- const char *sect_name = args.GetArgumentAtIndex(i);
- const char *load_addr_cstr = args.GetArgumentAtIndex(i+1);
- if (sect_name && load_addr_cstr)
- {
- ConstString const_sect_name(sect_name);
- bool success = false;
- addr_t load_addr = StringConvert::ToUInt64(load_addr_cstr, LLDB_INVALID_ADDRESS, 0, &success);
- if (success)
- {
- SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
- if (section_sp)
- {
- if (section_sp->IsThreadSpecific())
- {
- result.AppendErrorWithFormat ("thread specific sections are not yet supported (section '%s')\n", sect_name);
- result.SetStatus (eReturnStatusFailed);
- break;
- }
- else
- {
- if (target->GetSectionLoadList().SetSectionLoadAddress (section_sp, load_addr))
- changed = true;
- result.AppendMessageWithFormat("section '%s' loaded at 0x%" PRIx64 "\n", sect_name, load_addr);
- }
- }
- else
- {
- result.AppendErrorWithFormat ("no section found that matches the section name '%s'\n", sect_name);
- result.SetStatus (eReturnStatusFailed);
- break;
- }
- }
- else
- {
- result.AppendErrorWithFormat ("invalid load address string '%s'\n", load_addr_cstr);
- result.SetStatus (eReturnStatusFailed);
- break;
- }
- }
- else
- {
- if (sect_name)
- result.AppendError ("section names must be followed by a load address.\n");
- else
- result.AppendError ("one or more section name + load address pair must be specified.\n");
- result.SetStatus (eReturnStatusFailed);
- break;
- }
- }
- }
-
- if (changed)
- {
- target->ModulesDidLoad (matching_modules);
- Process *process = m_exe_ctx.GetProcessPtr();
- if (process)
- process->Flush();
- }
- }
- else
- {
- module->GetFileSpec().GetPath (path, sizeof(path));
- result.AppendErrorWithFormat ("no sections in object file '%s'\n", path);
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- module->GetFileSpec().GetPath (path, sizeof(path));
- result.AppendErrorWithFormat ("no object file for module '%s'\n", path);
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- FileSpec *module_spec_file = module_spec.GetFileSpecPtr();
- if (module_spec_file)
- {
- module_spec_file->GetPath (path, sizeof(path));
- result.AppendErrorWithFormat ("invalid module '%s'.\n", path);
- }
- else
- result.AppendError ("no module spec");
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- std::string uuid_str;
+protected:
+ bool DoExecute(Args &args, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target == nullptr) {
+ result.AppendError("invalid target, create a debug target using the "
+ "'target create' command");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ } else {
+ const size_t argc = args.GetArgumentCount();
+ ModuleSpec module_spec;
+ bool search_using_module_spec = false;
+ if (m_file_option.GetOptionValue().OptionWasSet()) {
+ search_using_module_spec = true;
+ const char *arg_cstr = m_file_option.GetOptionValue().GetCurrentValue();
+ const bool use_global_module_list = true;
+ ModuleList module_list;
+ const size_t num_matches = FindModulesByName(
+ target, arg_cstr, module_list, use_global_module_list);
+ if (num_matches == 1) {
+ module_spec.GetFileSpec() =
+ module_list.GetModuleAtIndex(0)->GetFileSpec();
+ } else if (num_matches > 1) {
+ search_using_module_spec = false;
+ result.AppendErrorWithFormat(
+ "more than 1 module matched by name '%s'\n", arg_cstr);
+ result.SetStatus(eReturnStatusFailed);
+ } else {
+ search_using_module_spec = false;
+ result.AppendErrorWithFormat("no object file for module '%s'\n",
+ arg_cstr);
+ result.SetStatus(eReturnStatusFailed);
+ }
+ }
+
+ if (m_uuid_option_group.GetOptionValue().OptionWasSet()) {
+ search_using_module_spec = true;
+ module_spec.GetUUID() =
+ m_uuid_option_group.GetOptionValue().GetCurrentValue();
+ }
+
+ if (search_using_module_spec) {
+ ModuleList matching_modules;
+ const size_t num_matches =
+ target->GetImages().FindModules(module_spec, matching_modules);
+
+ char path[PATH_MAX];
+ if (num_matches == 1) {
+ Module *module = matching_modules.GetModulePointerAtIndex(0);
+ if (module) {
+ ObjectFile *objfile = module->GetObjectFile();
+ if (objfile) {
+ SectionList *section_list = module->GetSectionList();
+ if (section_list) {
+ bool changed = false;
+ if (argc == 0) {
+ if (m_slide_option.GetOptionValue().OptionWasSet()) {
+ const addr_t slide =
+ m_slide_option.GetOptionValue().GetCurrentValue();
+ const bool slide_is_offset = true;
+ module->SetLoadAddress(*target, slide, slide_is_offset,
+ changed);
+ } else {
+ result.AppendError("one or more section name + load "
+ "address pair must be specified");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ } else {
+ if (m_slide_option.GetOptionValue().OptionWasSet()) {
+ result.AppendError("The \"--slide <offset>\" option can't "
+ "be used in conjunction with setting "
+ "section load addresses.\n");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
- if (module_spec.GetFileSpec())
- module_spec.GetFileSpec().GetPath (path, sizeof(path));
- else
- path[0] = '\0';
-
- if (module_spec.GetUUIDPtr())
- uuid_str = module_spec.GetUUID().GetAsString();
- if (num_matches > 1)
- {
- result.AppendErrorWithFormat ("multiple modules match%s%s%s%s:\n",
- path[0] ? " file=" : "",
- path,
- !uuid_str.empty() ? " uuid=" : "",
- uuid_str.c_str());
- for (size_t i = 0; i < num_matches; ++i)
- {
- if (matching_modules.GetModulePointerAtIndex(i)->GetFileSpec().GetPath (path, sizeof(path)))
- result.AppendMessageWithFormat("%s\n", path);
- }
- }
- else
- {
- result.AppendErrorWithFormat ("no modules were found that match%s%s%s%s.\n",
- path[0] ? " file=" : "",
- path,
- !uuid_str.empty() ? " uuid=" : "",
- uuid_str.c_str());
- }
- result.SetStatus (eReturnStatusFailed);
+ for (size_t i = 0; i < argc; i += 2) {
+ const char *sect_name = args.GetArgumentAtIndex(i);
+ const char *load_addr_cstr = args.GetArgumentAtIndex(i + 1);
+ if (sect_name && load_addr_cstr) {
+ ConstString const_sect_name(sect_name);
+ bool success = false;
+ addr_t load_addr = StringConvert::ToUInt64(
+ load_addr_cstr, LLDB_INVALID_ADDRESS, 0, &success);
+ if (success) {
+ SectionSP section_sp(
+ section_list->FindSectionByName(const_sect_name));
+ if (section_sp) {
+ if (section_sp->IsThreadSpecific()) {
+ result.AppendErrorWithFormat(
+ "thread specific sections are not yet "
+ "supported (section '%s')\n",
+ sect_name);
+ result.SetStatus(eReturnStatusFailed);
+ break;
+ } else {
+ if (target->GetSectionLoadList()
+ .SetSectionLoadAddress(section_sp,
+ load_addr))
+ changed = true;
+ result.AppendMessageWithFormat(
+ "section '%s' loaded at 0x%" PRIx64 "\n",
+ sect_name, load_addr);
+ }
+ } else {
+ result.AppendErrorWithFormat("no section found that "
+ "matches the section "
+ "name '%s'\n",
+ sect_name);
+ result.SetStatus(eReturnStatusFailed);
+ break;
+ }
+ } else {
+ result.AppendErrorWithFormat(
+ "invalid load address string '%s'\n",
+ load_addr_cstr);
+ result.SetStatus(eReturnStatusFailed);
+ break;
+ }
+ } else {
+ if (sect_name)
+ result.AppendError("section names must be followed by "
+ "a load address.\n");
+ else
+ result.AppendError("one or more section name + load "
+ "address pair must be specified.\n");
+ result.SetStatus(eReturnStatusFailed);
+ break;
+ }
+ }
+ }
+
+ if (changed) {
+ target->ModulesDidLoad(matching_modules);
+ Process *process = m_exe_ctx.GetProcessPtr();
+ if (process)
+ process->Flush();
}
- }
- else
- {
- result.AppendError ("either the \"--file <module>\" or the \"--uuid <uuid>\" option must be specified.\n");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- return result.Succeeded();
+ } else {
+ module->GetFileSpec().GetPath(path, sizeof(path));
+ result.AppendErrorWithFormat(
+ "no sections in object file '%s'\n", path);
+ result.SetStatus(eReturnStatusFailed);
+ }
+ } else {
+ module->GetFileSpec().GetPath(path, sizeof(path));
+ result.AppendErrorWithFormat("no object file for module '%s'\n",
+ path);
+ result.SetStatus(eReturnStatusFailed);
+ }
+ } else {
+ FileSpec *module_spec_file = module_spec.GetFileSpecPtr();
+ if (module_spec_file) {
+ module_spec_file->GetPath(path, sizeof(path));
+ result.AppendErrorWithFormat("invalid module '%s'.\n", path);
+ } else
+ result.AppendError("no module spec");
+ result.SetStatus(eReturnStatusFailed);
+ }
+ } else {
+ std::string uuid_str;
+
+ if (module_spec.GetFileSpec())
+ module_spec.GetFileSpec().GetPath(path, sizeof(path));
+ else
+ path[0] = '\0';
+
+ if (module_spec.GetUUIDPtr())
+ uuid_str = module_spec.GetUUID().GetAsString();
+ if (num_matches > 1) {
+ result.AppendErrorWithFormat(
+ "multiple modules match%s%s%s%s:\n", path[0] ? " file=" : "",
+ path, !uuid_str.empty() ? " uuid=" : "", uuid_str.c_str());
+ for (size_t i = 0; i < num_matches; ++i) {
+ if (matching_modules.GetModulePointerAtIndex(i)
+ ->GetFileSpec()
+ .GetPath(path, sizeof(path)))
+ result.AppendMessageWithFormat("%s\n", path);
+ }
+ } else {
+ result.AppendErrorWithFormat(
+ "no modules were found that match%s%s%s%s.\n",
+ path[0] ? " file=" : "", path,
+ !uuid_str.empty() ? " uuid=" : "", uuid_str.c_str());
+ }
+ result.SetStatus(eReturnStatusFailed);
+ }
+ } else {
+ result.AppendError("either the \"--file <module>\" or the \"--uuid "
+ "<uuid>\" option must be specified.\n");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
}
+ return result.Succeeded();
+ }
- OptionGroupOptions m_option_group;
- OptionGroupUUID m_uuid_option_group;
- OptionGroupString m_file_option;
- OptionGroupUInt64 m_slide_option;
+ OptionGroupOptions m_option_group;
+ OptionGroupUUID m_uuid_option_group;
+ OptionGroupString m_file_option;
+ OptionGroupUInt64 m_slide_option;
};
//----------------------------------------------------------------------
// List images with associated information
//----------------------------------------------------------------------
-class CommandObjectTargetModulesList : public CommandObjectParsed
-{
+class CommandObjectTargetModulesList : public CommandObjectParsed {
public:
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options(),
- m_format_array(),
- m_use_global_module_list (false),
- m_module_addr (LLDB_INVALID_ADDRESS)
- {
- }
-
- ~CommandOptions() override = default;
-
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
-
- const int short_option = m_getopt_table[option_idx].val;
- if (short_option == 'g')
- {
- m_use_global_module_list = true;
- }
- else if (short_option == 'a')
- {
- m_module_addr = Args::StringToAddress(execution_context,
- option_arg,
- LLDB_INVALID_ADDRESS,
- &error);
- }
- else
- {
- unsigned long width = 0;
- if (option_arg)
- width = strtoul(option_arg, nullptr, 0);
- m_format_array.push_back(std::make_pair(short_option, width));
- }
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_format_array.clear();
- m_use_global_module_list = false;
- m_module_addr = LLDB_INVALID_ADDRESS;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- // Options table: Required for subclasses of Options.
+ class CommandOptions : public Options {
+ public:
+ CommandOptions()
+ : Options(), m_format_array(), m_use_global_module_list(false),
+ m_module_addr(LLDB_INVALID_ADDRESS) {}
+
+ ~CommandOptions() override = default;
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+
+ const int short_option = m_getopt_table[option_idx].val;
+ if (short_option == 'g') {
+ m_use_global_module_list = true;
+ } else if (short_option == 'a') {
+ m_module_addr = Args::StringToAddress(execution_context, option_arg,
+ LLDB_INVALID_ADDRESS, &error);
+ } else {
+ unsigned long width = 0;
+ if (option_arg)
+ width = strtoul(option_arg, nullptr, 0);
+ m_format_array.push_back(std::make_pair(short_option, width));
+ }
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_format_array.clear();
+ m_use_global_module_list = false;
+ m_module_addr = LLDB_INVALID_ADDRESS;
+ }
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+ typedef std::vector<std::pair<char, uint32_t>> FormatWidthCollection;
+ FormatWidthCollection m_format_array;
+ bool m_use_global_module_list;
+ lldb::addr_t m_module_addr;
+ };
+
+ CommandObjectTargetModulesList(CommandInterpreter &interpreter)
+ : CommandObjectParsed(
+ interpreter, "target modules list",
+ "List current executable and dependent shared library images.",
+ "target modules list [<cmd-options>]"),
+ m_options() {}
- static OptionDefinition g_option_table[];
+ ~CommandObjectTargetModulesList() override = default;
- // Instance variables to hold the values for command options.
- typedef std::vector< std::pair<char, uint32_t> > FormatWidthCollection;
- FormatWidthCollection m_format_array;
- bool m_use_global_module_list;
- lldb::addr_t m_module_addr;
- };
-
- CommandObjectTargetModulesList (CommandInterpreter &interpreter) :
- CommandObjectParsed (interpreter,
- "target modules list",
- "List current executable and dependent shared library images.",
- "target modules list [<cmd-options>]"),
- m_options()
- {
- }
-
- ~CommandObjectTargetModulesList() override = default;
-
- Options *
- GetOptions () override
- {
- return &m_options;
- }
+ Options *GetOptions() override { return &m_options; }
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- const bool use_global_module_list = m_options.m_use_global_module_list;
- // Define a local module list here to ensure it lives longer than any "locker"
- // object which might lock its contents below (through the "module_list_ptr"
- // variable).
- ModuleList module_list;
- if (target == nullptr && !use_global_module_list)
- {
- result.AppendError ("invalid target, create a debug target using the 'target create' command");
- result.SetStatus (eReturnStatusFailed);
- return false;
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ const bool use_global_module_list = m_options.m_use_global_module_list;
+ // Define a local module list here to ensure it lives longer than any
+ // "locker"
+ // object which might lock its contents below (through the "module_list_ptr"
+ // variable).
+ ModuleList module_list;
+ if (target == nullptr && !use_global_module_list) {
+ result.AppendError("invalid target, create a debug target using the "
+ "'target create' command");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ } else {
+ if (target) {
+ uint32_t addr_byte_size =
+ target->GetArchitecture().GetAddressByteSize();
+ result.GetOutputStream().SetAddressByteSize(addr_byte_size);
+ result.GetErrorStream().SetAddressByteSize(addr_byte_size);
+ }
+ // Dump all sections for all modules images
+ Stream &strm = result.GetOutputStream();
+
+ if (m_options.m_module_addr != LLDB_INVALID_ADDRESS) {
+ if (target) {
+ Address module_address;
+ if (module_address.SetLoadAddress(m_options.m_module_addr, target)) {
+ ModuleSP module_sp(module_address.GetModule());
+ if (module_sp) {
+ PrintModule(target, module_sp.get(), 0, strm);
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ } else {
+ result.AppendErrorWithFormat(
+ "Couldn't find module matching address: 0x%" PRIx64 ".",
+ m_options.m_module_addr);
+ result.SetStatus(eReturnStatusFailed);
+ }
+ } else {
+ result.AppendErrorWithFormat(
+ "Couldn't find module containing address: 0x%" PRIx64 ".",
+ m_options.m_module_addr);
+ result.SetStatus(eReturnStatusFailed);
+ }
+ } else {
+ result.AppendError(
+ "Can only look up modules by address with a valid target.");
+ result.SetStatus(eReturnStatusFailed);
}
- else
- {
- if (target)
- {
- uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
- result.GetOutputStream().SetAddressByteSize(addr_byte_size);
- result.GetErrorStream().SetAddressByteSize(addr_byte_size);
- }
- // Dump all sections for all modules images
- Stream &strm = result.GetOutputStream();
-
- if (m_options.m_module_addr != LLDB_INVALID_ADDRESS)
- {
- if (target)
- {
- Address module_address;
- if (module_address.SetLoadAddress(m_options.m_module_addr, target))
- {
- ModuleSP module_sp (module_address.GetModule());
- if (module_sp)
- {
- PrintModule (target, module_sp.get(), 0, strm);
- result.SetStatus (eReturnStatusSuccessFinishResult);
- }
- else
- {
- result.AppendErrorWithFormat ("Couldn't find module matching address: 0x%" PRIx64 ".", m_options.m_module_addr);
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- result.AppendErrorWithFormat ("Couldn't find module containing address: 0x%" PRIx64 ".", m_options.m_module_addr);
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- result.AppendError ("Can only look up modules by address with a valid target.");
- result.SetStatus (eReturnStatusFailed);
- }
- return result.Succeeded();
- }
-
- size_t num_modules = 0;
-
- // This locker will be locked on the mutex in module_list_ptr if it is non-nullptr.
- // Otherwise it will lock the AllocationModuleCollectionMutex when accessing
- // the global module list directly.
- std::unique_lock<std::recursive_mutex> guard(Module::GetAllocationModuleCollectionMutex(), std::defer_lock);
-
- const ModuleList *module_list_ptr = nullptr;
- const size_t argc = command.GetArgumentCount();
- if (argc == 0)
- {
- if (use_global_module_list)
- {
- guard.lock();
- num_modules = Module::GetNumberAllocatedModules();
- }
- else
- {
- module_list_ptr = &target->GetImages();
- }
- }
- else
- {
- for (size_t i = 0; i < argc; ++i)
- {
- // Dump specified images (by basename or fullpath)
- const char *arg_cstr = command.GetArgumentAtIndex(i);
- const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, use_global_module_list);
- if (num_matches == 0)
- {
- if (argc == 1)
- {
- result.AppendErrorWithFormat ("no modules found that match '%s'", arg_cstr);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- }
-
- module_list_ptr = &module_list;
- }
-
- std::unique_lock<std::recursive_mutex> lock;
- if (module_list_ptr != nullptr)
- {
- lock = std::unique_lock<std::recursive_mutex>(module_list_ptr->GetMutex());
-
- num_modules = module_list_ptr->GetSize();
- }
+ return result.Succeeded();
+ }
- if (num_modules > 0)
- {
- for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
- {
- ModuleSP module_sp;
- Module *module;
- if (module_list_ptr)
- {
- module_sp = module_list_ptr->GetModuleAtIndexUnlocked(image_idx);
- module = module_sp.get();
- }
- else
- {
- module = Module::GetAllocatedModuleAtIndex(image_idx);
- module_sp = module->shared_from_this();
- }
+ size_t num_modules = 0;
- const size_t indent = strm.Printf("[%3u] ", image_idx);
- PrintModule (target, module, indent, strm);
+ // This locker will be locked on the mutex in module_list_ptr if it is
+ // non-nullptr.
+ // Otherwise it will lock the AllocationModuleCollectionMutex when
+ // accessing
+ // the global module list directly.
+ std::unique_lock<std::recursive_mutex> guard(
+ Module::GetAllocationModuleCollectionMutex(), std::defer_lock);
+
+ const ModuleList *module_list_ptr = nullptr;
+ const size_t argc = command.GetArgumentCount();
+ if (argc == 0) {
+ if (use_global_module_list) {
+ guard.lock();
+ num_modules = Module::GetNumberAllocatedModules();
+ } else {
+ module_list_ptr = &target->GetImages();
+ }
+ } else {
+ for (size_t i = 0; i < argc; ++i) {
+ // Dump specified images (by basename or fullpath)
+ const char *arg_cstr = command.GetArgumentAtIndex(i);
+ const size_t num_matches = FindModulesByName(
+ target, arg_cstr, module_list, use_global_module_list);
+ if (num_matches == 0) {
+ if (argc == 1) {
+ result.AppendErrorWithFormat("no modules found that match '%s'",
+ arg_cstr);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+ }
+
+ module_list_ptr = &module_list;
+ }
+
+ std::unique_lock<std::recursive_mutex> lock;
+ if (module_list_ptr != nullptr) {
+ lock =
+ std::unique_lock<std::recursive_mutex>(module_list_ptr->GetMutex());
+
+ num_modules = module_list_ptr->GetSize();
+ }
+
+ if (num_modules > 0) {
+ for (uint32_t image_idx = 0; image_idx < num_modules; ++image_idx) {
+ ModuleSP module_sp;
+ Module *module;
+ if (module_list_ptr) {
+ module_sp = module_list_ptr->GetModuleAtIndexUnlocked(image_idx);
+ module = module_sp.get();
+ } else {
+ module = Module::GetAllocatedModuleAtIndex(image_idx);
+ module_sp = module->shared_from_this();
+ }
- }
- result.SetStatus (eReturnStatusSuccessFinishResult);
- }
- else
- {
- if (argc)
- {
- if (use_global_module_list)
- result.AppendError ("the global module list has no matching modules");
- else
- result.AppendError ("the target has no matching modules");
- }
- else
- {
- if (use_global_module_list)
- result.AppendError ("the global module list is empty");
- else
- result.AppendError ("the target has no associated executable images");
- }
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
+ const size_t indent = strm.Printf("[%3u] ", image_idx);
+ PrintModule(target, module, indent, strm);
}
- return result.Succeeded();
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ } else {
+ if (argc) {
+ if (use_global_module_list)
+ result.AppendError(
+ "the global module list has no matching modules");
+ else
+ result.AppendError("the target has no matching modules");
+ } else {
+ if (use_global_module_list)
+ result.AppendError("the global module list is empty");
+ else
+ result.AppendError(
+ "the target has no associated executable images");
+ }
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
}
+ return result.Succeeded();
+ }
- void
- PrintModule (Target *target, Module *module, int indent, Stream &strm)
- {
- if (module == nullptr)
- {
- strm.PutCString("Null module");
- return;
+ void PrintModule(Target *target, Module *module, int indent, Stream &strm) {
+ if (module == nullptr) {
+ strm.PutCString("Null module");
+ return;
+ }
+
+ bool dump_object_name = false;
+ if (m_options.m_format_array.empty()) {
+ m_options.m_format_array.push_back(std::make_pair('u', 0));
+ m_options.m_format_array.push_back(std::make_pair('h', 0));
+ m_options.m_format_array.push_back(std::make_pair('f', 0));
+ m_options.m_format_array.push_back(std::make_pair('S', 0));
+ }
+ const size_t num_entries = m_options.m_format_array.size();
+ bool print_space = false;
+ for (size_t i = 0; i < num_entries; ++i) {
+ if (print_space)
+ strm.PutChar(' ');
+ print_space = true;
+ const char format_char = m_options.m_format_array[i].first;
+ uint32_t width = m_options.m_format_array[i].second;
+ switch (format_char) {
+ case 'A':
+ DumpModuleArchitecture(strm, module, false, width);
+ break;
+
+ case 't':
+ DumpModuleArchitecture(strm, module, true, width);
+ break;
+
+ case 'f':
+ DumpFullpath(strm, &module->GetFileSpec(), width);
+ dump_object_name = true;
+ break;
+
+ case 'd':
+ DumpDirectory(strm, &module->GetFileSpec(), width);
+ break;
+
+ case 'b':
+ DumpBasename(strm, &module->GetFileSpec(), width);
+ dump_object_name = true;
+ break;
+
+ case 'h':
+ case 'o':
+ // Image header address
+ {
+ uint32_t addr_nibble_width =
+ target ? (target->GetArchitecture().GetAddressByteSize() * 2)
+ : 16;
+
+ ObjectFile *objfile = module->GetObjectFile();
+ if (objfile) {
+ Address header_addr(objfile->GetHeaderAddress());
+ if (header_addr.IsValid()) {
+ if (target && !target->GetSectionLoadList().IsEmpty()) {
+ lldb::addr_t header_load_addr =
+ header_addr.GetLoadAddress(target);
+ if (header_load_addr == LLDB_INVALID_ADDRESS) {
+ header_addr.Dump(&strm, target,
+ 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,
+ header_load_addr - header_addr.GetFileAddress());
+ } else {
+ // Show the load address of the image
+ strm.Printf("0x%*.*" PRIx64, addr_nibble_width,
+ addr_nibble_width, header_load_addr);
+ }
+ }
+ break;
+ }
+ // The address was valid, but the image isn't loaded, output the
+ // address in an appropriate format
+ header_addr.Dump(&strm, target, Address::DumpStyleFileAddress);
+ break;
+ }
+ }
+ strm.Printf("%*s", addr_nibble_width + 2, "");
+ }
+ break;
+
+ case 'r': {
+ size_t ref_count = 0;
+ ModuleSP module_sp(module->shared_from_this());
+ if (module_sp) {
+ // Take one away to make sure we don't count our local "module_sp"
+ ref_count = module_sp.use_count() - 1;
}
+ if (width)
+ strm.Printf("{%*" PRIu64 "}", width, (uint64_t)ref_count);
+ else
+ strm.Printf("{%" PRIu64 "}", (uint64_t)ref_count);
+ } break;
- bool dump_object_name = false;
- if (m_options.m_format_array.empty())
- {
- m_options.m_format_array.push_back(std::make_pair('u', 0));
- m_options.m_format_array.push_back(std::make_pair('h', 0));
- m_options.m_format_array.push_back(std::make_pair('f', 0));
- m_options.m_format_array.push_back(std::make_pair('S', 0));
- }
- const size_t num_entries = m_options.m_format_array.size();
- bool print_space = false;
- for (size_t i = 0; i < num_entries; ++i)
- {
- if (print_space)
- strm.PutChar(' ');
- print_space = true;
- const char format_char = m_options.m_format_array[i].first;
- uint32_t width = m_options.m_format_array[i].second;
- switch (format_char)
- {
- case 'A':
- DumpModuleArchitecture (strm, module, false, width);
- break;
-
- case 't':
- DumpModuleArchitecture (strm, module, true, width);
- break;
-
- case 'f':
- DumpFullpath (strm, &module->GetFileSpec(), width);
- dump_object_name = true;
- break;
-
- case 'd':
- DumpDirectory (strm, &module->GetFileSpec(), width);
- break;
-
- case 'b':
- DumpBasename (strm, &module->GetFileSpec(), width);
- dump_object_name = true;
- break;
-
- case 'h':
- case 'o':
- // Image header address
- {
- uint32_t addr_nibble_width = target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16;
-
- ObjectFile *objfile = module->GetObjectFile ();
- if (objfile)
- {
- Address header_addr(objfile->GetHeaderAddress());
- if (header_addr.IsValid())
- {
- if (target && !target->GetSectionLoadList().IsEmpty())
- {
- lldb::addr_t header_load_addr = header_addr.GetLoadAddress (target);
- if (header_load_addr == LLDB_INVALID_ADDRESS)
- {
- header_addr.Dump (&strm, target, 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, header_load_addr - header_addr.GetFileAddress());
- }
- else
- {
- // Show the load address of the image
- strm.Printf ("0x%*.*" PRIx64, addr_nibble_width, addr_nibble_width, header_load_addr);
- }
- }
- break;
- }
- // The address was valid, but the image isn't loaded, output the address in an appropriate format
- header_addr.Dump (&strm, target, Address::DumpStyleFileAddress);
- break;
- }
- }
- strm.Printf ("%*s", addr_nibble_width + 2, "");
- }
- break;
-
- case 'r':
- {
- size_t ref_count = 0;
- ModuleSP module_sp (module->shared_from_this());
- if (module_sp)
- {
- // Take one away to make sure we don't count our local "module_sp"
- ref_count = module_sp.use_count() - 1;
- }
- if (width)
- strm.Printf("{%*" PRIu64 "}", width, (uint64_t)ref_count);
- else
- strm.Printf("{%" PRIu64 "}", (uint64_t)ref_count);
- }
- break;
-
- case 's':
- case 'S':
- {
- const SymbolVendor *symbol_vendor = module->GetSymbolVendor();
- if (symbol_vendor)
- {
- const FileSpec symfile_spec = symbol_vendor->GetMainFileSpec();
- if (format_char == 'S')
- {
- // Dump symbol file only if different from module file
- if (!symfile_spec || symfile_spec == module->GetFileSpec())
- {
- print_space = false;
- break;
- }
- // Add a newline and indent past the index
- strm.Printf ("\n%*s", indent, "");
- }
- DumpFullpath (strm, &symfile_spec, width);
- dump_object_name = true;
- break;
- }
- strm.Printf("%.*s", width, "<NONE>");
- }
- break;
-
- case 'm':
- module->GetModificationTime().Dump(&strm, width);
- break;
-
- case 'p':
- strm.Printf("%p", static_cast<void*>(module));
- break;
-
- case 'u':
- DumpModuleUUID(strm, module);
- break;
-
- default:
- break;
- }
- }
- if (dump_object_name)
- {
- const char *object_name = module->GetObjectName().GetCString();
- if (object_name)
- strm.Printf ("(%s)", object_name);
- }
- strm.EOL();
+ case 's':
+ case 'S': {
+ const SymbolVendor *symbol_vendor = module->GetSymbolVendor();
+ if (symbol_vendor) {
+ const FileSpec symfile_spec = symbol_vendor->GetMainFileSpec();
+ if (format_char == 'S') {
+ // Dump symbol file only if different from module file
+ if (!symfile_spec || symfile_spec == module->GetFileSpec()) {
+ print_space = false;
+ break;
+ }
+ // Add a newline and indent past the index
+ strm.Printf("\n%*s", indent, "");
+ }
+ DumpFullpath(strm, &symfile_spec, width);
+ dump_object_name = true;
+ break;
+ }
+ strm.Printf("%.*s", width, "<NONE>");
+ } break;
+
+ case 'm':
+ module->GetModificationTime().Dump(&strm, width);
+ break;
+
+ case 'p':
+ strm.Printf("%p", static_cast<void *>(module));
+ break;
+
+ case 'u':
+ DumpModuleUUID(strm, module);
+ break;
+
+ default:
+ break;
+ }
+ }
+ if (dump_object_name) {
+ const char *object_name = module->GetObjectName().GetCString();
+ if (object_name)
+ strm.Printf("(%s)", object_name);
}
+ strm.EOL();
+ }
- CommandOptions m_options;
+ CommandOptions m_options;
};
OptionDefinition
-CommandObjectTargetModulesList::CommandOptions::g_option_table[] =
-{
- // clang-format off
+ CommandObjectTargetModulesList::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_1, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Display the image at this address."},
{LLDB_OPT_SET_1, false, "arch", 'A', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the architecture when listing images."},
{LLDB_OPT_SET_1, false, "triple", 't', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeWidth, "Display the triple when listing images."},
@@ -3577,7 +3134,7 @@ CommandObjectTargetModulesList::CommandO
{LLDB_OPT_SET_1, false, "pointer", 'p', OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the module pointer."},
{LLDB_OPT_SET_1, false, "global", 'g', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the modules from the global module list, not just the current target."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
#pragma mark CommandObjectTargetModulesShowUnwind
@@ -3586,746 +3143,668 @@ CommandObjectTargetModulesList::CommandO
// Lookup unwind information in images
//----------------------------------------------------------------------
-class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed
-{
+class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed {
public:
- enum
- {
- eLookupTypeInvalid = -1,
- eLookupTypeAddress = 0,
- eLookupTypeSymbol,
- eLookupTypeFunction,
- eLookupTypeFunctionOrSymbol,
- kNumLookupTypes
- };
-
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options(),
- m_type(eLookupTypeInvalid),
- m_str(),
- m_addr(LLDB_INVALID_ADDRESS)
- {
- }
+ enum {
+ eLookupTypeInvalid = -1,
+ eLookupTypeAddress = 0,
+ eLookupTypeSymbol,
+ eLookupTypeFunction,
+ eLookupTypeFunctionOrSymbol,
+ kNumLookupTypes
+ };
+
+ class CommandOptions : public Options {
+ public:
+ CommandOptions()
+ : Options(), m_type(eLookupTypeInvalid), m_str(),
+ m_addr(LLDB_INVALID_ADDRESS) {}
+
+ ~CommandOptions() override = default;
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option) {
+ case 'a': {
+ m_str = option_arg;
+ m_type = eLookupTypeAddress;
+ m_addr = Args::StringToAddress(execution_context, option_arg,
+ LLDB_INVALID_ADDRESS, &error);
+ if (m_addr == LLDB_INVALID_ADDRESS)
+ error.SetErrorStringWithFormat("invalid address string '%s'",
+ option_arg);
+ break;
+ }
+
+ case 'n':
+ m_str = option_arg;
+ m_type = eLookupTypeFunctionOrSymbol;
+ break;
+
+ default:
+ error.SetErrorStringWithFormat("unrecognized option %c.", short_option);
+ break;
+ }
+
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_type = eLookupTypeInvalid;
+ m_str.clear();
+ m_addr = LLDB_INVALID_ADDRESS;
+ }
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+
+ int m_type; // Should be a eLookupTypeXXX enum after parsing options
+ std::string m_str; // Holds name lookup
+ lldb::addr_t m_addr; // Holds the address to lookup
+ };
+
+ CommandObjectTargetModulesShowUnwind(CommandInterpreter &interpreter)
+ : CommandObjectParsed(
+ interpreter, "target modules show-unwind",
+ "Show synthesized unwind instructions for a function.", nullptr,
+ eCommandRequiresTarget | eCommandRequiresProcess |
+ eCommandProcessMustBeLaunched | eCommandProcessMustBePaused),
+ m_options() {}
- ~CommandOptions() override = default;
+ ~CommandObjectTargetModulesShowUnwind() override = default;
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
-
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'a':
- {
- m_str = option_arg;
- m_type = eLookupTypeAddress;
- m_addr = Args::StringToAddress(execution_context,
- option_arg,
- LLDB_INVALID_ADDRESS,
- &error);
- if (m_addr == LLDB_INVALID_ADDRESS)
- error.SetErrorStringWithFormat ("invalid address string '%s'", option_arg);
- break;
- }
-
- case 'n':
- m_str = option_arg;
- m_type = eLookupTypeFunctionOrSymbol;
- break;
-
- default:
- error.SetErrorStringWithFormat ("unrecognized option %c.", short_option);
- break;
- }
-
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_type = eLookupTypeInvalid;
- m_str.clear();
- m_addr = LLDB_INVALID_ADDRESS;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
-
- int m_type; // Should be a eLookupTypeXXX enum after parsing options
- std::string m_str; // Holds name lookup
- lldb::addr_t m_addr; // Holds the address to lookup
- };
-
- CommandObjectTargetModulesShowUnwind (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "target modules show-unwind",
- "Show synthesized unwind instructions for a function.",
- nullptr,
- eCommandRequiresTarget |
- eCommandRequiresProcess |
- eCommandProcessMustBeLaunched |
- eCommandProcessMustBePaused ),
- m_options()
- {
- }
-
- ~CommandObjectTargetModulesShowUnwind() override = default;
-
- Options *
- GetOptions () override
- {
- return &m_options;
- }
+ Options *GetOptions() override { return &m_options; }
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_exe_ctx.GetTargetPtr();
- Process *process = m_exe_ctx.GetProcessPtr();
- ABI *abi = nullptr;
- if (process)
- abi = process->GetABI().get();
-
- if (process == nullptr)
- {
- result.AppendError ("You must have a process running to use this command.");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- ThreadList threads(process->GetThreadList());
- if (threads.GetSize() == 0)
- {
- result.AppendError ("The process must be paused to use this command.");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- ThreadSP thread(threads.GetThreadAtIndex(0));
- if (!thread)
- {
- result.AppendError ("The process must be paused to use this command.");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- SymbolContextList sc_list;
-
- if (m_options.m_type == eLookupTypeFunctionOrSymbol)
- {
- ConstString function_name (m_options.m_str.c_str());
- target->GetImages().FindFunctions (function_name, eFunctionNameTypeAuto, true, false, true, sc_list);
- }
- else if (m_options.m_type == eLookupTypeAddress && target)
- {
- Address addr;
- if (target->GetSectionLoadList().ResolveLoadAddress (m_options.m_addr, addr))
- {
- SymbolContext sc;
- ModuleSP module_sp (addr.GetModule());
- module_sp->ResolveSymbolContextForAddress (addr, eSymbolContextEverything, sc);
- if (sc.function || sc.symbol)
- {
- sc_list.Append(sc);
- }
- }
- }
- else
- {
- result.AppendError ("address-expression or function name option must be specified.");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- size_t num_matches = sc_list.GetSize();
- if (num_matches == 0)
- {
- result.AppendErrorWithFormat ("no unwind data found that matches '%s'.", m_options.m_str.c_str());
- result.SetStatus (eReturnStatusFailed);
- return false;
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_exe_ctx.GetTargetPtr();
+ Process *process = m_exe_ctx.GetProcessPtr();
+ ABI *abi = nullptr;
+ if (process)
+ abi = process->GetABI().get();
+
+ if (process == nullptr) {
+ result.AppendError(
+ "You must have a process running to use this command.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ ThreadList threads(process->GetThreadList());
+ if (threads.GetSize() == 0) {
+ result.AppendError("The process must be paused to use this command.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ ThreadSP thread(threads.GetThreadAtIndex(0));
+ if (!thread) {
+ result.AppendError("The process must be paused to use this command.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ SymbolContextList sc_list;
+
+ if (m_options.m_type == eLookupTypeFunctionOrSymbol) {
+ ConstString function_name(m_options.m_str.c_str());
+ target->GetImages().FindFunctions(function_name, eFunctionNameTypeAuto,
+ true, false, true, sc_list);
+ } else if (m_options.m_type == eLookupTypeAddress && target) {
+ Address addr;
+ if (target->GetSectionLoadList().ResolveLoadAddress(m_options.m_addr,
+ addr)) {
+ SymbolContext sc;
+ ModuleSP module_sp(addr.GetModule());
+ module_sp->ResolveSymbolContextForAddress(addr,
+ eSymbolContextEverything, sc);
+ if (sc.function || sc.symbol) {
+ sc_list.Append(sc);
+ }
+ }
+ } else {
+ result.AppendError(
+ "address-expression or function name option must be specified.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ size_t num_matches = sc_list.GetSize();
+ if (num_matches == 0) {
+ result.AppendErrorWithFormat("no unwind data found that matches '%s'.",
+ m_options.m_str.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ for (uint32_t idx = 0; idx < num_matches; idx++) {
+ SymbolContext sc;
+ sc_list.GetContextAtIndex(idx, sc);
+ if (sc.symbol == nullptr && sc.function == nullptr)
+ continue;
+ if (!sc.module_sp || sc.module_sp->GetObjectFile() == nullptr)
+ continue;
+ AddressRange range;
+ if (!sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0,
+ false, range))
+ continue;
+ if (!range.GetBaseAddress().IsValid())
+ continue;
+ ConstString funcname(sc.GetFunctionName());
+ if (funcname.IsEmpty())
+ continue;
+ addr_t start_addr = range.GetBaseAddress().GetLoadAddress(target);
+ if (abi)
+ start_addr = abi->FixCodeAddress(start_addr);
+
+ FuncUnwindersSP func_unwinders_sp(
+ sc.module_sp->GetObjectFile()
+ ->GetUnwindTable()
+ .GetUncachedFuncUnwindersContainingAddress(start_addr, sc));
+ if (!func_unwinders_sp)
+ continue;
+
+ result.GetOutputStream().Printf(
+ "UNWIND PLANS for %s`%s (start addr 0x%" PRIx64 ")\n\n",
+ sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(),
+ funcname.AsCString(), start_addr);
+
+ UnwindPlanSP non_callsite_unwind_plan =
+ func_unwinders_sp->GetUnwindPlanAtNonCallSite(*target, *thread, -1);
+ if (non_callsite_unwind_plan) {
+ result.GetOutputStream().Printf(
+ "Asynchronous (not restricted to call-sites) UnwindPlan is '%s'\n",
+ non_callsite_unwind_plan->GetSourceName().AsCString());
+ }
+ UnwindPlanSP callsite_unwind_plan =
+ func_unwinders_sp->GetUnwindPlanAtCallSite(*target, -1);
+ if (callsite_unwind_plan) {
+ result.GetOutputStream().Printf(
+ "Synchronous (restricted to call-sites) UnwindPlan is '%s'\n",
+ callsite_unwind_plan->GetSourceName().AsCString());
+ }
+ UnwindPlanSP fast_unwind_plan =
+ func_unwinders_sp->GetUnwindPlanFastUnwind(*target, *thread);
+ if (fast_unwind_plan) {
+ result.GetOutputStream().Printf(
+ "Fast UnwindPlan is '%s'\n",
+ fast_unwind_plan->GetSourceName().AsCString());
+ }
+
+ result.GetOutputStream().Printf("\n");
+
+ UnwindPlanSP assembly_sp =
+ func_unwinders_sp->GetAssemblyUnwindPlan(*target, *thread, 0);
+ if (assembly_sp) {
+ result.GetOutputStream().Printf(
+ "Assembly language inspection UnwindPlan:\n");
+ assembly_sp->Dump(result.GetOutputStream(), thread.get(),
+ LLDB_INVALID_ADDRESS);
+ result.GetOutputStream().Printf("\n");
+ }
+
+ UnwindPlanSP ehframe_sp =
+ func_unwinders_sp->GetEHFrameUnwindPlan(*target, 0);
+ if (ehframe_sp) {
+ result.GetOutputStream().Printf("eh_frame UnwindPlan:\n");
+ ehframe_sp->Dump(result.GetOutputStream(), thread.get(),
+ LLDB_INVALID_ADDRESS);
+ result.GetOutputStream().Printf("\n");
+ }
+
+ UnwindPlanSP ehframe_augmented_sp =
+ func_unwinders_sp->GetEHFrameAugmentedUnwindPlan(*target, *thread, 0);
+ if (ehframe_augmented_sp) {
+ result.GetOutputStream().Printf("eh_frame augmented UnwindPlan:\n");
+ ehframe_augmented_sp->Dump(result.GetOutputStream(), thread.get(),
+ LLDB_INVALID_ADDRESS);
+ result.GetOutputStream().Printf("\n");
+ }
+
+ UnwindPlanSP arm_unwind_sp =
+ func_unwinders_sp->GetArmUnwindUnwindPlan(*target, 0);
+ if (arm_unwind_sp) {
+ result.GetOutputStream().Printf("ARM.exidx unwind UnwindPlan:\n");
+ arm_unwind_sp->Dump(result.GetOutputStream(), thread.get(),
+ LLDB_INVALID_ADDRESS);
+ result.GetOutputStream().Printf("\n");
+ }
+
+ UnwindPlanSP compact_unwind_sp =
+ func_unwinders_sp->GetCompactUnwindUnwindPlan(*target, 0);
+ if (compact_unwind_sp) {
+ result.GetOutputStream().Printf("Compact unwind UnwindPlan:\n");
+ compact_unwind_sp->Dump(result.GetOutputStream(), thread.get(),
+ LLDB_INVALID_ADDRESS);
+ result.GetOutputStream().Printf("\n");
+ }
+
+ if (fast_unwind_plan) {
+ result.GetOutputStream().Printf("Fast UnwindPlan:\n");
+ fast_unwind_plan->Dump(result.GetOutputStream(), thread.get(),
+ LLDB_INVALID_ADDRESS);
+ result.GetOutputStream().Printf("\n");
+ }
+
+ ABISP abi_sp = process->GetABI();
+ if (abi_sp) {
+ UnwindPlan arch_default(lldb::eRegisterKindGeneric);
+ if (abi_sp->CreateDefaultUnwindPlan(arch_default)) {
+ result.GetOutputStream().Printf("Arch default UnwindPlan:\n");
+ arch_default.Dump(result.GetOutputStream(), thread.get(),
+ LLDB_INVALID_ADDRESS);
+ result.GetOutputStream().Printf("\n");
+ }
+
+ UnwindPlan arch_entry(lldb::eRegisterKindGeneric);
+ if (abi_sp->CreateFunctionEntryUnwindPlan(arch_entry)) {
+ result.GetOutputStream().Printf(
+ "Arch default at entry point UnwindPlan:\n");
+ arch_entry.Dump(result.GetOutputStream(), thread.get(),
+ LLDB_INVALID_ADDRESS);
+ result.GetOutputStream().Printf("\n");
}
+ }
- for (uint32_t idx = 0; idx < num_matches; idx++)
- {
- SymbolContext sc;
- sc_list.GetContextAtIndex(idx, sc);
- if (sc.symbol == nullptr && sc.function == nullptr)
- continue;
- if (!sc.module_sp || sc.module_sp->GetObjectFile() == nullptr)
- continue;
- AddressRange range;
- if (!sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, range))
- continue;
- if (!range.GetBaseAddress().IsValid())
- continue;
- ConstString funcname(sc.GetFunctionName());
- if (funcname.IsEmpty())
- continue;
- addr_t start_addr = range.GetBaseAddress().GetLoadAddress(target);
- if (abi)
- start_addr = abi->FixCodeAddress(start_addr);
-
- FuncUnwindersSP func_unwinders_sp (sc.module_sp->GetObjectFile()->GetUnwindTable().GetUncachedFuncUnwindersContainingAddress(start_addr, sc));
- if (!func_unwinders_sp)
- continue;
-
- result.GetOutputStream().Printf("UNWIND PLANS for %s`%s (start addr 0x%" PRIx64 ")\n\n", sc.module_sp->GetPlatformFileSpec().GetFilename().AsCString(), funcname.AsCString(), start_addr);
-
- UnwindPlanSP non_callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtNonCallSite(*target, *thread, -1);
- if (non_callsite_unwind_plan)
- {
- result.GetOutputStream().Printf("Asynchronous (not restricted to call-sites) UnwindPlan is '%s'\n", non_callsite_unwind_plan->GetSourceName().AsCString());
- }
- UnwindPlanSP callsite_unwind_plan = func_unwinders_sp->GetUnwindPlanAtCallSite(*target, -1);
- if (callsite_unwind_plan)
- {
- result.GetOutputStream().Printf("Synchronous (restricted to call-sites) UnwindPlan is '%s'\n", callsite_unwind_plan->GetSourceName().AsCString());
- }
- UnwindPlanSP fast_unwind_plan = func_unwinders_sp->GetUnwindPlanFastUnwind(*target, *thread);
- if (fast_unwind_plan)
- {
- result.GetOutputStream().Printf("Fast UnwindPlan is '%s'\n", fast_unwind_plan->GetSourceName().AsCString());
- }
-
- result.GetOutputStream().Printf("\n");
-
- UnwindPlanSP assembly_sp = func_unwinders_sp->GetAssemblyUnwindPlan(*target, *thread, 0);
- if (assembly_sp)
- {
- result.GetOutputStream().Printf("Assembly language inspection UnwindPlan:\n");
- assembly_sp->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
- result.GetOutputStream().Printf("\n");
- }
-
- UnwindPlanSP ehframe_sp = func_unwinders_sp->GetEHFrameUnwindPlan(*target, 0);
- if (ehframe_sp)
- {
- result.GetOutputStream().Printf("eh_frame UnwindPlan:\n");
- ehframe_sp->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
- result.GetOutputStream().Printf("\n");
- }
-
- UnwindPlanSP ehframe_augmented_sp = func_unwinders_sp->GetEHFrameAugmentedUnwindPlan(*target, *thread, 0);
- if (ehframe_augmented_sp)
- {
- result.GetOutputStream().Printf("eh_frame augmented UnwindPlan:\n");
- ehframe_augmented_sp->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
- result.GetOutputStream().Printf("\n");
- }
-
- UnwindPlanSP arm_unwind_sp = func_unwinders_sp->GetArmUnwindUnwindPlan(*target, 0);
- if (arm_unwind_sp)
- {
- result.GetOutputStream().Printf("ARM.exidx unwind UnwindPlan:\n");
- arm_unwind_sp->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
- result.GetOutputStream().Printf("\n");
- }
-
- UnwindPlanSP compact_unwind_sp = func_unwinders_sp->GetCompactUnwindUnwindPlan(*target, 0);
- if (compact_unwind_sp)
- {
- result.GetOutputStream().Printf("Compact unwind UnwindPlan:\n");
- compact_unwind_sp->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
- result.GetOutputStream().Printf("\n");
- }
-
- if (fast_unwind_plan)
- {
- result.GetOutputStream().Printf("Fast UnwindPlan:\n");
- fast_unwind_plan->Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
- result.GetOutputStream().Printf("\n");
- }
-
- ABISP abi_sp = process->GetABI();
- if (abi_sp)
- {
- UnwindPlan arch_default(lldb::eRegisterKindGeneric);
- if (abi_sp->CreateDefaultUnwindPlan (arch_default))
- {
- result.GetOutputStream().Printf("Arch default UnwindPlan:\n");
- arch_default.Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
- result.GetOutputStream().Printf("\n");
- }
-
- UnwindPlan arch_entry(lldb::eRegisterKindGeneric);
- if (abi_sp->CreateFunctionEntryUnwindPlan (arch_entry))
- {
- result.GetOutputStream().Printf("Arch default at entry point UnwindPlan:\n");
- arch_entry.Dump(result.GetOutputStream(), thread.get(), LLDB_INVALID_ADDRESS);
- result.GetOutputStream().Printf("\n");
- }
- }
-
- result.GetOutputStream().Printf ("\n");
- }
- return result.Succeeded();
+ result.GetOutputStream().Printf("\n");
}
+ return result.Succeeded();
+ }
- CommandOptions m_options;
+ CommandOptions m_options;
};
OptionDefinition
-CommandObjectTargetModulesShowUnwind::CommandOptions::g_option_table[] =
-{
- // clang-format off
+ CommandObjectTargetModulesShowUnwind::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_1, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFunctionName, "Show unwind instructions for a function or symbol name."},
- {LLDB_OPT_SET_2, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Show unwind instructions for a function or symbol containing an address"},
- {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
-};
-
-//----------------------------------------------------------------------
-// Lookup information in images
-//----------------------------------------------------------------------
-class CommandObjectTargetModulesLookup : public CommandObjectParsed
-{
-public:
- enum
- {
- eLookupTypeInvalid = -1,
- eLookupTypeAddress = 0,
- eLookupTypeSymbol,
- eLookupTypeFileLine, // Line is optional
- eLookupTypeFunction,
- eLookupTypeFunctionOrSymbol,
- eLookupTypeType,
- kNumLookupTypes
- };
-
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options()
- {
- OptionParsingStarting(nullptr);
- }
-
- ~CommandOptions() override = default;
-
- Error
- SetOptionValue (uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
-
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'a':
- {
- m_type = eLookupTypeAddress;
- m_addr = Args::StringToAddress(execution_context,
- option_arg,
- LLDB_INVALID_ADDRESS,
- &error);
- }
- break;
-
- case 'o':
- m_offset = StringConvert::ToUInt64(option_arg, LLDB_INVALID_ADDRESS);
- if (m_offset == LLDB_INVALID_ADDRESS)
- error.SetErrorStringWithFormat ("invalid offset string '%s'", option_arg);
- break;
-
- case 's':
- m_str = option_arg;
- m_type = eLookupTypeSymbol;
- break;
-
- case 'f':
- m_file.SetFile (option_arg, false);
- m_type = eLookupTypeFileLine;
- break;
-
- case 'i':
- m_include_inlines = false;
- break;
-
- case 'l':
- m_line_number = StringConvert::ToUInt32(option_arg, UINT32_MAX);
- if (m_line_number == UINT32_MAX)
- error.SetErrorStringWithFormat ("invalid line number string '%s'", option_arg);
- else if (m_line_number == 0)
- error.SetErrorString ("zero is an invalid line number");
- m_type = eLookupTypeFileLine;
- break;
-
- case 'F':
- m_str = option_arg;
- m_type = eLookupTypeFunction;
- break;
-
- case 'n':
- m_str = option_arg;
- m_type = eLookupTypeFunctionOrSymbol;
- break;
-
- case 't':
- m_str = option_arg;
- m_type = eLookupTypeType;
- break;
-
- case 'v':
- m_verbose = 1;
- break;
-
- case 'A':
- m_print_all = true;
- break;
-
- case 'r':
- m_use_regex = true;
- break;
- }
-
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_type = eLookupTypeInvalid;
- m_str.clear();
- m_file.Clear();
- m_addr = LLDB_INVALID_ADDRESS;
- m_offset = 0;
- m_line_number = 0;
- m_use_regex = false;
- m_include_inlines = true;
- m_verbose = false;
- m_print_all = false;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
- int m_type; // Should be a eLookupTypeXXX enum after parsing options
- std::string m_str; // Holds name lookup
- FileSpec m_file; // Files for file lookups
- lldb::addr_t m_addr; // Holds the address to lookup
- lldb::addr_t m_offset; // Subtract this offset from m_addr before doing lookups.
- uint32_t m_line_number; // Line number for file+line lookups
- bool m_use_regex; // Name lookups in m_str are regular expressions.
- bool m_include_inlines;// Check for inline entries when looking up by file/line.
- bool m_verbose; // Enable verbose lookup info
- bool m_print_all; // Print all matches, even in cases where there's a best match.
- };
-
- CommandObjectTargetModulesLookup (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "target modules lookup",
- "Look up information within executable and dependent shared library images.",
- nullptr,
- eCommandRequiresTarget),
- m_options()
- {
- CommandArgumentEntry arg;
- CommandArgumentData file_arg;
-
- // Define the first (and only) variant of this arg.
- file_arg.arg_type = eArgTypeFilename;
- file_arg.arg_repetition = eArgRepeatStar;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (file_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
- }
-
- ~CommandObjectTargetModulesLookup() override = default;
-
- Options *
- GetOptions () override
- {
- return &m_options;
- }
-
- bool
- LookupHere (CommandInterpreter &interpreter, CommandReturnObject &result, bool &syntax_error)
- {
- switch (m_options.m_type)
- {
- case eLookupTypeAddress:
- case eLookupTypeFileLine:
- case eLookupTypeFunction:
- case eLookupTypeFunctionOrSymbol:
- case eLookupTypeSymbol:
- default:
- return false;
- case eLookupTypeType:
- break;
- }
-
- StackFrameSP frame = m_exe_ctx.GetFrameSP();
-
- if (!frame)
- return false;
-
- const SymbolContext &sym_ctx(frame->GetSymbolContext(eSymbolContextModule));
-
- if (!sym_ctx.module_sp)
- return false;
-
- switch (m_options.m_type)
- {
- default:
- return false;
- case eLookupTypeType:
- if (!m_options.m_str.empty())
- {
- if (LookupTypeHere (m_interpreter,
- result.GetOutputStream(),
- sym_ctx,
- m_options.m_str.c_str(),
- m_options.m_use_regex))
- {
- result.SetStatus(eReturnStatusSuccessFinishResult);
- return true;
- }
- }
- break;
- }
+ {LLDB_OPT_SET_2, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Show unwind instructions for a function or symbol containing an address"},
+ {0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
+ // clang-format on
+};
- return true;
+//----------------------------------------------------------------------
+// Lookup information in images
+//----------------------------------------------------------------------
+class CommandObjectTargetModulesLookup : public CommandObjectParsed {
+public:
+ enum {
+ eLookupTypeInvalid = -1,
+ eLookupTypeAddress = 0,
+ eLookupTypeSymbol,
+ eLookupTypeFileLine, // Line is optional
+ eLookupTypeFunction,
+ eLookupTypeFunctionOrSymbol,
+ eLookupTypeType,
+ kNumLookupTypes
+ };
+
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options() { OptionParsingStarting(nullptr); }
+
+ ~CommandOptions() override = default;
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option) {
+ case 'a': {
+ m_type = eLookupTypeAddress;
+ m_addr = Args::StringToAddress(execution_context, option_arg,
+ LLDB_INVALID_ADDRESS, &error);
+ } break;
+
+ case 'o':
+ m_offset = StringConvert::ToUInt64(option_arg, LLDB_INVALID_ADDRESS);
+ if (m_offset == LLDB_INVALID_ADDRESS)
+ error.SetErrorStringWithFormat("invalid offset string '%s'",
+ option_arg);
+ break;
+
+ case 's':
+ m_str = option_arg;
+ m_type = eLookupTypeSymbol;
+ break;
+
+ case 'f':
+ m_file.SetFile(option_arg, false);
+ m_type = eLookupTypeFileLine;
+ break;
+
+ case 'i':
+ m_include_inlines = false;
+ break;
+
+ case 'l':
+ m_line_number = StringConvert::ToUInt32(option_arg, UINT32_MAX);
+ if (m_line_number == UINT32_MAX)
+ error.SetErrorStringWithFormat("invalid line number string '%s'",
+ option_arg);
+ else if (m_line_number == 0)
+ error.SetErrorString("zero is an invalid line number");
+ m_type = eLookupTypeFileLine;
+ break;
+
+ case 'F':
+ m_str = option_arg;
+ m_type = eLookupTypeFunction;
+ break;
+
+ case 'n':
+ m_str = option_arg;
+ m_type = eLookupTypeFunctionOrSymbol;
+ break;
+
+ case 't':
+ m_str = option_arg;
+ m_type = eLookupTypeType;
+ break;
+
+ case 'v':
+ m_verbose = 1;
+ break;
+
+ case 'A':
+ m_print_all = true;
+ break;
+
+ case 'r':
+ m_use_regex = true;
+ break;
+ }
+
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_type = eLookupTypeInvalid;
+ m_str.clear();
+ m_file.Clear();
+ m_addr = LLDB_INVALID_ADDRESS;
+ m_offset = 0;
+ m_line_number = 0;
+ m_use_regex = false;
+ m_include_inlines = true;
+ m_verbose = false;
+ m_print_all = false;
+ }
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+ int m_type; // Should be a eLookupTypeXXX enum after parsing options
+ std::string m_str; // Holds name lookup
+ FileSpec m_file; // Files for file lookups
+ lldb::addr_t m_addr; // Holds the address to lookup
+ lldb::addr_t
+ m_offset; // Subtract this offset from m_addr before doing lookups.
+ uint32_t m_line_number; // Line number for file+line lookups
+ bool m_use_regex; // Name lookups in m_str are regular expressions.
+ bool m_include_inlines; // Check for inline entries when looking up by
+ // file/line.
+ bool m_verbose; // Enable verbose lookup info
+ bool m_print_all; // Print all matches, even in cases where there's a best
+ // match.
+ };
+
+ CommandObjectTargetModulesLookup(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "target modules lookup",
+ "Look up information within executable and "
+ "dependent shared library images.",
+ nullptr, eCommandRequiresTarget),
+ m_options() {
+ CommandArgumentEntry arg;
+ CommandArgumentData file_arg;
+
+ // Define the first (and only) variant of this arg.
+ file_arg.arg_type = eArgTypeFilename;
+ file_arg.arg_repetition = eArgRepeatStar;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(file_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+ }
+
+ ~CommandObjectTargetModulesLookup() override = default;
+
+ Options *GetOptions() override { return &m_options; }
+
+ bool LookupHere(CommandInterpreter &interpreter, CommandReturnObject &result,
+ bool &syntax_error) {
+ switch (m_options.m_type) {
+ case eLookupTypeAddress:
+ case eLookupTypeFileLine:
+ case eLookupTypeFunction:
+ case eLookupTypeFunctionOrSymbol:
+ case eLookupTypeSymbol:
+ default:
+ return false;
+ case eLookupTypeType:
+ break;
}
- bool
- LookupInModule (CommandInterpreter &interpreter, Module *module, CommandReturnObject &result, bool &syntax_error)
- {
- switch (m_options.m_type)
- {
- case eLookupTypeAddress:
- if (m_options.m_addr != LLDB_INVALID_ADDRESS)
- {
- if (LookupAddressInModule (m_interpreter,
- result.GetOutputStream(),
- module,
- eSymbolContextEverything | (m_options.m_verbose ? static_cast<int>(eSymbolContextVariable) : 0),
- m_options.m_addr,
- m_options.m_offset,
- m_options.m_verbose))
- {
- result.SetStatus(eReturnStatusSuccessFinishResult);
- return true;
- }
- }
- break;
-
- case eLookupTypeSymbol:
- if (!m_options.m_str.empty())
- {
- if (LookupSymbolInModule (m_interpreter,
- result.GetOutputStream(),
- module,
- m_options.m_str.c_str(),
- m_options.m_use_regex,
- m_options.m_verbose))
- {
- result.SetStatus(eReturnStatusSuccessFinishResult);
- return true;
- }
- }
- break;
-
- case eLookupTypeFileLine:
- if (m_options.m_file)
- {
- if (LookupFileAndLineInModule (m_interpreter,
- result.GetOutputStream(),
- module,
- m_options.m_file,
- m_options.m_line_number,
- m_options.m_include_inlines,
- m_options.m_verbose))
- {
- result.SetStatus(eReturnStatusSuccessFinishResult);
- return true;
- }
- }
- break;
+ StackFrameSP frame = m_exe_ctx.GetFrameSP();
- case eLookupTypeFunctionOrSymbol:
- case eLookupTypeFunction:
- if (!m_options.m_str.empty())
- {
- if (LookupFunctionInModule (m_interpreter,
- result.GetOutputStream(),
- module,
- m_options.m_str.c_str(),
- m_options.m_use_regex,
- m_options.m_include_inlines,
- m_options.m_type == eLookupTypeFunctionOrSymbol, // include symbols
- m_options.m_verbose))
- {
- result.SetStatus(eReturnStatusSuccessFinishResult);
- return true;
- }
- }
- break;
+ if (!frame)
+ return false;
- case eLookupTypeType:
- if (!m_options.m_str.empty())
- {
- if (LookupTypeInModule (m_interpreter,
- result.GetOutputStream(),
- module,
- m_options.m_str.c_str(),
- m_options.m_use_regex))
- {
- result.SetStatus(eReturnStatusSuccessFinishResult);
- return true;
- }
- }
- break;
+ const SymbolContext &sym_ctx(frame->GetSymbolContext(eSymbolContextModule));
- default:
- m_options.GenerateOptionUsage(result.GetErrorStream(), this,
- GetCommandInterpreter()
- .GetDebugger()
- .GetTerminalWidth());
- syntax_error = true;
- break;
- }
+ if (!sym_ctx.module_sp)
+ return false;
- result.SetStatus (eReturnStatusFailed);
- return false;
+ switch (m_options.m_type) {
+ default:
+ return false;
+ case eLookupTypeType:
+ if (!m_options.m_str.empty()) {
+ if (LookupTypeHere(m_interpreter, result.GetOutputStream(), sym_ctx,
+ m_options.m_str.c_str(), m_options.m_use_regex)) {
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return true;
+ }
+ }
+ break;
+ }
+
+ return true;
+ }
+
+ bool LookupInModule(CommandInterpreter &interpreter, Module *module,
+ CommandReturnObject &result, bool &syntax_error) {
+ switch (m_options.m_type) {
+ case eLookupTypeAddress:
+ if (m_options.m_addr != LLDB_INVALID_ADDRESS) {
+ if (LookupAddressInModule(
+ m_interpreter, result.GetOutputStream(), module,
+ eSymbolContextEverything |
+ (m_options.m_verbose
+ ? static_cast<int>(eSymbolContextVariable)
+ : 0),
+ m_options.m_addr, m_options.m_offset, m_options.m_verbose)) {
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return true;
+ }
+ }
+ break;
+
+ case eLookupTypeSymbol:
+ if (!m_options.m_str.empty()) {
+ if (LookupSymbolInModule(m_interpreter, result.GetOutputStream(),
+ module, m_options.m_str.c_str(),
+ m_options.m_use_regex, m_options.m_verbose)) {
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return true;
+ }
+ }
+ break;
+
+ case eLookupTypeFileLine:
+ if (m_options.m_file) {
+ if (LookupFileAndLineInModule(
+ m_interpreter, result.GetOutputStream(), module,
+ m_options.m_file, m_options.m_line_number,
+ m_options.m_include_inlines, m_options.m_verbose)) {
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return true;
+ }
+ }
+ break;
+
+ case eLookupTypeFunctionOrSymbol:
+ case eLookupTypeFunction:
+ if (!m_options.m_str.empty()) {
+ if (LookupFunctionInModule(
+ m_interpreter, result.GetOutputStream(), module,
+ m_options.m_str.c_str(), m_options.m_use_regex,
+ m_options.m_include_inlines,
+ m_options.m_type ==
+ eLookupTypeFunctionOrSymbol, // include symbols
+ m_options.m_verbose)) {
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return true;
+ }
+ }
+ break;
+
+ case eLookupTypeType:
+ if (!m_options.m_str.empty()) {
+ if (LookupTypeInModule(m_interpreter, result.GetOutputStream(), module,
+ m_options.m_str.c_str(),
+ m_options.m_use_regex)) {
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return true;
+ }
+ }
+ break;
+
+ default:
+ m_options.GenerateOptionUsage(
+ result.GetErrorStream(), this,
+ GetCommandInterpreter().GetDebugger().GetTerminalWidth());
+ syntax_error = true;
+ break;
}
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (target == nullptr)
- {
- result.AppendError ("invalid target, create a debug target using the 'target create' command");
- result.SetStatus (eReturnStatusFailed);
- return false;
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target == nullptr) {
+ result.AppendError("invalid target, create a debug target using the "
+ "'target create' command");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ } else {
+ bool syntax_error = false;
+ uint32_t i;
+ uint32_t num_successful_lookups = 0;
+ uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
+ result.GetOutputStream().SetAddressByteSize(addr_byte_size);
+ result.GetErrorStream().SetAddressByteSize(addr_byte_size);
+ // Dump all sections for all modules images
+
+ if (command.GetArgumentCount() == 0) {
+ ModuleSP current_module;
+
+ // Where it is possible to look in the current symbol context
+ // first, try that. If this search was successful and --all
+ // was not passed, don't print anything else.
+ if (LookupHere(m_interpreter, result, syntax_error)) {
+ result.GetOutputStream().EOL();
+ num_successful_lookups++;
+ if (!m_options.m_print_all) {
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return result.Succeeded();
+ }
}
- else
- {
- bool syntax_error = false;
- uint32_t i;
- uint32_t num_successful_lookups = 0;
- uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
- result.GetOutputStream().SetAddressByteSize(addr_byte_size);
- result.GetErrorStream().SetAddressByteSize(addr_byte_size);
- // Dump all sections for all modules images
-
- if (command.GetArgumentCount() == 0)
- {
- ModuleSP current_module;
-
- // Where it is possible to look in the current symbol context
- // first, try that. If this search was successful and --all
- // was not passed, don't print anything else.
- if (LookupHere (m_interpreter, result, syntax_error))
- {
- result.GetOutputStream().EOL();
- num_successful_lookups++;
- if (!m_options.m_print_all)
- {
- result.SetStatus (eReturnStatusSuccessFinishResult);
- return result.Succeeded();
- }
- }
- // Dump all sections for all other modules
-
- const ModuleList &target_modules = target->GetImages();
- std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
- const size_t num_modules = target_modules.GetSize();
- if (num_modules > 0)
- {
- for (i = 0; i < num_modules && !syntax_error; ++i)
- {
- Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked(i);
-
- if (module_pointer != current_module.get() &&
- LookupInModule (m_interpreter, target_modules.GetModulePointerAtIndexUnlocked(i), result, syntax_error))
- {
- result.GetOutputStream().EOL();
- num_successful_lookups++;
- }
- }
- }
- else
- {
- result.AppendError ("the target has no associated executable images");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- else
- {
- // Dump specified images (by basename or fullpath)
- const char *arg_cstr;
- for (i = 0; (arg_cstr = command.GetArgumentAtIndex(i)) != nullptr && !syntax_error; ++i)
- {
- ModuleList module_list;
- const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, false);
- if (num_matches > 0)
- {
- for (size_t j=0; j<num_matches; ++j)
- {
- Module *module = module_list.GetModulePointerAtIndex(j);
- if (module)
- {
- if (LookupInModule (m_interpreter, module, result, syntax_error))
- {
- result.GetOutputStream().EOL();
- num_successful_lookups++;
- }
- }
- }
- }
- else
- result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
- }
- }
+ // Dump all sections for all other modules
- if (num_successful_lookups > 0)
- result.SetStatus (eReturnStatusSuccessFinishResult);
- else
- result.SetStatus (eReturnStatusFailed);
+ const ModuleList &target_modules = target->GetImages();
+ std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
+ const size_t num_modules = target_modules.GetSize();
+ if (num_modules > 0) {
+ for (i = 0; i < num_modules && !syntax_error; ++i) {
+ Module *module_pointer =
+ target_modules.GetModulePointerAtIndexUnlocked(i);
+
+ if (module_pointer != current_module.get() &&
+ LookupInModule(
+ m_interpreter,
+ target_modules.GetModulePointerAtIndexUnlocked(i), result,
+ syntax_error)) {
+ result.GetOutputStream().EOL();
+ num_successful_lookups++;
+ }
+ }
+ } else {
+ result.AppendError("the target has no associated executable images");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ } else {
+ // Dump specified images (by basename or fullpath)
+ const char *arg_cstr;
+ for (i = 0; (arg_cstr = command.GetArgumentAtIndex(i)) != nullptr &&
+ !syntax_error;
+ ++i) {
+ ModuleList module_list;
+ const size_t num_matches =
+ FindModulesByName(target, arg_cstr, module_list, false);
+ if (num_matches > 0) {
+ for (size_t j = 0; j < num_matches; ++j) {
+ Module *module = module_list.GetModulePointerAtIndex(j);
+ if (module) {
+ if (LookupInModule(m_interpreter, module, result,
+ syntax_error)) {
+ result.GetOutputStream().EOL();
+ num_successful_lookups++;
+ }
+ }
+ }
+ } else
+ result.AppendWarningWithFormat(
+ "Unable to find an image that matches '%s'.\n", arg_cstr);
}
- return result.Succeeded();
+ }
+
+ if (num_successful_lookups > 0)
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ else
+ result.SetStatus(eReturnStatusFailed);
}
+ return result.Succeeded();
+ }
- CommandOptions m_options;
+ CommandOptions m_options;
};
OptionDefinition
-CommandObjectTargetModulesLookup::CommandOptions::g_option_table[] =
-{
- // clang-format off
+ CommandObjectTargetModulesLookup::CommandOptions::g_option_table[] =
+ {
+ // clang-format off
{LLDB_OPT_SET_1, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Lookup an address in one or more target modules."},
{LLDB_OPT_SET_1, false, "offset", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOffset, "When looking up an address subtract <offset> from any addresses before doing the lookup."},
/* FIXME: re-enable regex for types when the LookupTypeInModule actually uses the regex option: | LLDB_OPT_SET_6 */
@@ -4340,7 +3819,7 @@ CommandObjectTargetModulesLookup::Comman
{LLDB_OPT_SET_ALL, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Enable verbose lookup information."},
{LLDB_OPT_SET_ALL, false, "all", 'A', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Print all matches, not just the best match, if a best match is available."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
#pragma mark CommandObjectMultiwordImageSearchPaths
@@ -4349,22 +3828,33 @@ CommandObjectTargetModulesLookup::Comman
// CommandObjectMultiwordImageSearchPaths
//-------------------------------------------------------------------------
-class CommandObjectTargetModulesImageSearchPaths : public CommandObjectMultiword
-{
+class CommandObjectTargetModulesImageSearchPaths
+ : public CommandObjectMultiword {
public:
- CommandObjectTargetModulesImageSearchPaths(CommandInterpreter &interpreter)
- : CommandObjectMultiword(interpreter, "target modules search-paths",
- "Commands for managing module search paths for a target.",
- "target modules search-paths <subcommand> [<subcommand-options>]")
- {
- LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesSearchPathsAdd (interpreter)));
- LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTargetModulesSearchPathsClear (interpreter)));
- LoadSubCommand ("insert", CommandObjectSP (new CommandObjectTargetModulesSearchPathsInsert (interpreter)));
- LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesSearchPathsList (interpreter)));
- LoadSubCommand ("query", CommandObjectSP (new CommandObjectTargetModulesSearchPathsQuery (interpreter)));
- }
+ CommandObjectTargetModulesImageSearchPaths(CommandInterpreter &interpreter)
+ : CommandObjectMultiword(
+ interpreter, "target modules search-paths",
+ "Commands for managing module search paths for a target.",
+ "target modules search-paths <subcommand> [<subcommand-options>]") {
+ LoadSubCommand(
+ "add", CommandObjectSP(
+ new CommandObjectTargetModulesSearchPathsAdd(interpreter)));
+ LoadSubCommand(
+ "clear", CommandObjectSP(new CommandObjectTargetModulesSearchPathsClear(
+ interpreter)));
+ LoadSubCommand(
+ "insert",
+ CommandObjectSP(
+ new CommandObjectTargetModulesSearchPathsInsert(interpreter)));
+ LoadSubCommand(
+ "list", CommandObjectSP(new CommandObjectTargetModulesSearchPathsList(
+ interpreter)));
+ LoadSubCommand(
+ "query", CommandObjectSP(new CommandObjectTargetModulesSearchPathsQuery(
+ interpreter)));
+ }
- ~CommandObjectTargetModulesImageSearchPaths() override = default;
+ ~CommandObjectTargetModulesImageSearchPaths() override = default;
};
#pragma mark CommandObjectTargetModules
@@ -4373,455 +3863,431 @@ public:
// CommandObjectTargetModules
//-------------------------------------------------------------------------
-class CommandObjectTargetModules : public CommandObjectMultiword
-{
+class CommandObjectTargetModules : public CommandObjectMultiword {
public:
- //------------------------------------------------------------------
- // Constructors and Destructors
- //------------------------------------------------------------------
- CommandObjectTargetModules(CommandInterpreter &interpreter)
- : CommandObjectMultiword(interpreter, "target modules",
- "Commands for accessing information for one or more target modules.",
- "target modules <sub-command> ...")
- {
- LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetModulesAdd (interpreter)));
- LoadSubCommand ("load", CommandObjectSP (new CommandObjectTargetModulesLoad (interpreter)));
- LoadSubCommand ("dump", CommandObjectSP (new CommandObjectTargetModulesDump (interpreter)));
- LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetModulesList (interpreter)));
- LoadSubCommand ("lookup", CommandObjectSP (new CommandObjectTargetModulesLookup (interpreter)));
- LoadSubCommand ("search-paths", CommandObjectSP (new CommandObjectTargetModulesImageSearchPaths (interpreter)));
- LoadSubCommand ("show-unwind", CommandObjectSP (new CommandObjectTargetModulesShowUnwind (interpreter)));
-
- }
+ //------------------------------------------------------------------
+ // Constructors and Destructors
+ //------------------------------------------------------------------
+ CommandObjectTargetModules(CommandInterpreter &interpreter)
+ : CommandObjectMultiword(interpreter, "target modules",
+ "Commands for accessing information for one or "
+ "more target modules.",
+ "target modules <sub-command> ...") {
+ LoadSubCommand(
+ "add", CommandObjectSP(new CommandObjectTargetModulesAdd(interpreter)));
+ LoadSubCommand("load", CommandObjectSP(new CommandObjectTargetModulesLoad(
+ interpreter)));
+ LoadSubCommand("dump", CommandObjectSP(new CommandObjectTargetModulesDump(
+ interpreter)));
+ LoadSubCommand("list", CommandObjectSP(new CommandObjectTargetModulesList(
+ interpreter)));
+ LoadSubCommand(
+ "lookup",
+ CommandObjectSP(new CommandObjectTargetModulesLookup(interpreter)));
+ LoadSubCommand(
+ "search-paths",
+ CommandObjectSP(
+ new CommandObjectTargetModulesImageSearchPaths(interpreter)));
+ LoadSubCommand(
+ "show-unwind",
+ CommandObjectSP(new CommandObjectTargetModulesShowUnwind(interpreter)));
+ }
- ~CommandObjectTargetModules() override = default;
+ ~CommandObjectTargetModules() override = default;
private:
- //------------------------------------------------------------------
- // For CommandObjectTargetModules only
- //------------------------------------------------------------------
- DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetModules);
+ //------------------------------------------------------------------
+ // For CommandObjectTargetModules only
+ //------------------------------------------------------------------
+ DISALLOW_COPY_AND_ASSIGN(CommandObjectTargetModules);
};
-class CommandObjectTargetSymbolsAdd : public CommandObjectParsed
-{
+class CommandObjectTargetSymbolsAdd : public CommandObjectParsed {
public:
- CommandObjectTargetSymbolsAdd (CommandInterpreter &interpreter) :
- CommandObjectParsed (interpreter,
- "target symbols add",
- "Add a debug symbol file to one of the target's current modules by specifying a path to a debug symbols file, or using the options to specify a module to download symbols for.",
- "target symbols add [<symfile>]", eCommandRequiresTarget),
+ CommandObjectTargetSymbolsAdd(CommandInterpreter &interpreter)
+ : CommandObjectParsed(
+ interpreter, "target symbols add",
+ "Add a debug symbol file to one of the target's current modules by "
+ "specifying a path to a debug symbols file, or using the options "
+ "to specify a module to download symbols for.",
+ "target symbols add [<symfile>]", eCommandRequiresTarget),
m_option_group(),
- m_file_option (LLDB_OPT_SET_1, false, "shlib", 's', CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Fullpath or basename for module to find debug symbols for."),
- m_current_frame_option (LLDB_OPT_SET_2, false, "frame", 'F', "Locate the debug symbols the currently selected frame.", false, true)
+ m_file_option(
+ LLDB_OPT_SET_1, false, "shlib", 's',
+ CommandCompletions::eModuleCompletion, eArgTypeShlibName,
+ "Fullpath or basename for module to find debug symbols for."),
+ m_current_frame_option(
+ LLDB_OPT_SET_2, false, "frame", 'F',
+ "Locate the debug symbols the currently selected frame.", false,
+ true)
+
+ {
+ m_option_group.Append(&m_uuid_option_group, LLDB_OPT_SET_ALL,
+ LLDB_OPT_SET_1);
+ m_option_group.Append(&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Append(&m_current_frame_option, LLDB_OPT_SET_2,
+ LLDB_OPT_SET_2);
+ m_option_group.Finalize();
+ }
+
+ ~CommandObjectTargetSymbolsAdd() override = default;
+
+ int HandleArgumentCompletion(Args &input, int &cursor_index,
+ int &cursor_char_position,
+ OptionElementVector &opt_element_vector,
+ int match_start_point, int max_return_elements,
+ bool &word_complete,
+ StringList &matches) override {
+ std::string completion_str(input.GetArgumentAtIndex(cursor_index));
+ completion_str.erase(cursor_char_position);
+
+ CommandCompletions::InvokeCommonCompletionCallbacks(
+ GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion,
+ completion_str.c_str(), match_start_point, max_return_elements, nullptr,
+ word_complete, matches);
+ return matches.GetSize();
+ }
- {
- m_option_group.Append (&m_uuid_option_group, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Append (&m_file_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Append (&m_current_frame_option, LLDB_OPT_SET_2, LLDB_OPT_SET_2);
- m_option_group.Finalize();
- }
-
- ~CommandObjectTargetSymbolsAdd() override = default;
-
- int
- HandleArgumentCompletion (Args &input,
- int &cursor_index,
- int &cursor_char_position,
- OptionElementVector &opt_element_vector,
- int match_start_point,
- int max_return_elements,
- bool &word_complete,
- StringList &matches) override
- {
- std::string completion_str (input.GetArgumentAtIndex(cursor_index));
- completion_str.erase (cursor_char_position);
-
- CommandCompletions::InvokeCommonCompletionCallbacks(GetCommandInterpreter(),
- CommandCompletions::eDiskFileCompletion,
- completion_str.c_str(),
- match_start_point,
- max_return_elements,
- nullptr,
- word_complete,
- matches);
- return matches.GetSize();
- }
-
- Options *
- GetOptions () override
- {
- return &m_option_group;
- }
+ Options *GetOptions() override { return &m_option_group; }
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 (!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();
- num_matches = target->GetImages().FindModules (symfile_uuid_module_spec, matching_module_list);
- }
- }
-
- 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();
- num_matches = target->GetImages().FindModules (symfile_uuid_module_spec, matching_module_list);
- }
- }
- }
- }
- }
-
- // Just try to match up the file by basename if we have no matches at this point
- if (num_matches == 0)
- num_matches = target->GetImages().FindModules (module_spec, matching_module_list);
-
- while (num_matches == 0)
- {
- ConstString filename_no_extension(module_spec.GetFileSpec().GetFileNameStrippingExtension());
- // Empty string returned, lets 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;
-
- // Replace basename with one less extension
- module_spec.GetFileSpec().GetFilename() = filename_no_extension;
-
- num_matches = target->GetImages().FindModules (module_spec, matching_module_list);
- }
-
- 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);
-
- SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(true, &result.GetErrorStream());
- if (symbol_vendor)
- {
- SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
-
- 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.
- Error 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());
- }
-
- 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(),
- (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular)
- ? "\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,
- (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular)
- ? "\n please specify the full path to the symbol file"
- : "");
- }
- }
- else
- {
- result.AppendError ("one or more executable image paths must be specified");
- }
- result.SetStatus (eReturnStatusFailed);
- return false;
+ 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 (!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();
+ num_matches = target->GetImages().FindModules(
+ symfile_uuid_module_spec, matching_module_list);
+ }
+ }
+
+ 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();
+ num_matches = target->GetImages().FindModules(
+ symfile_uuid_module_spec, matching_module_list);
+ }
+ }
+ }
+ }
+ }
+
+ // Just try to match up the file by basename if we have no matches at this
+ // point
+ if (num_matches == 0)
+ num_matches =
+ target->GetImages().FindModules(module_spec, matching_module_list);
+
+ while (num_matches == 0) {
+ ConstString filename_no_extension(
+ module_spec.GetFileSpec().GetFileNameStrippingExtension());
+ // Empty string returned, lets 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;
+
+ // Replace basename with one less extension
+ module_spec.GetFileSpec().GetFilename() = filename_no_extension;
+
+ num_matches =
+ target->GetImages().FindModules(module_spec, matching_module_list);
+ }
+
+ 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);
+
+ SymbolVendor *symbol_vendor =
+ module_sp->GetSymbolVendor(true, &result.GetErrorStream());
+ if (symbol_vendor) {
+ SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
+
+ 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.
+ Error 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());
+ }
+
+ 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(),
+ (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular)
+ ? "\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,
+ (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular)
+ ? "\n please specify the full path to the symbol file"
+ : "");
+ }
+ } else {
+ result.AppendError(
+ "one or more executable image paths must be specified");
}
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
- bool
- DoExecute (Args& args, CommandReturnObject &result) override
- {
- Target *target = m_exe_ctx.GetTargetPtr();
- result.SetStatus (eReturnStatusFailed);
- bool flush = false;
- ModuleSpec module_spec;
- const bool uuid_option_set = m_uuid_option_group.GetOptionValue().OptionWasSet();
- const bool file_option_set = m_file_option.GetOptionValue().OptionWasSet();
- const bool frame_option_set = m_current_frame_option.GetOptionValue().OptionWasSet();
- const size_t argc = args.GetArgumentCount();
-
- if (argc == 0)
- {
- if (uuid_option_set || file_option_set || frame_option_set)
- {
- bool success = false;
- bool error_set = false;
- if (frame_option_set)
- {
- Process *process = m_exe_ctx.GetProcessPtr();
- if (process)
- {
- const StateType process_state = process->GetState();
- if (StateIsStoppedState (process_state, true))
- {
- StackFrame *frame = m_exe_ctx.GetFramePtr();
- if (frame)
- {
- ModuleSP frame_module_sp (frame->GetSymbolContext(eSymbolContextModule).module_sp);
- if (frame_module_sp)
- {
- if (frame_module_sp->GetPlatformFileSpec().Exists())
- {
- module_spec.GetArchitecture() = frame_module_sp->GetArchitecture();
- module_spec.GetFileSpec() = frame_module_sp->GetPlatformFileSpec();
- }
- module_spec.GetUUID() = frame_module_sp->GetUUID();
- success = module_spec.GetUUID().IsValid() || module_spec.GetFileSpec();
- }
- else
- {
- result.AppendError ("frame has no module");
- error_set = true;
- }
- }
- else
- {
- result.AppendError ("invalid current frame");
- error_set = true;
- }
- }
- else
- {
- result.AppendErrorWithFormat ("process is not stopped: %s", StateAsCString(process_state));
- error_set = true;
- }
- }
- else
- {
- result.AppendError ("a process must exist in order to use the --frame option");
- error_set = true;
- }
- }
- else
- {
- if (uuid_option_set)
- {
- module_spec.GetUUID() = m_uuid_option_group.GetOptionValue().GetCurrentValue();
- success |= module_spec.GetUUID().IsValid();
- }
- else if (file_option_set)
- {
- module_spec.GetFileSpec() = m_file_option.GetOptionValue().GetCurrentValue();
- ModuleSP module_sp (target->GetImages().FindFirstModule(module_spec));
- if (module_sp)
- {
- module_spec.GetFileSpec() = module_sp->GetFileSpec();
- module_spec.GetPlatformFileSpec() = module_sp->GetPlatformFileSpec();
- module_spec.GetUUID() = module_sp->GetUUID();
- module_spec.GetArchitecture() = module_sp->GetArchitecture();
- }
- else
- {
- module_spec.GetArchitecture() = target->GetArchitecture();
- }
- success |= module_spec.GetUUID().IsValid() || module_spec.GetFileSpec().Exists();
- }
- }
-
- if (success)
- {
- if (Symbols::DownloadObjectAndSymbolFile (module_spec))
- {
- if (module_spec.GetSymbolFileSpec())
- success = AddModuleSymbols (target, module_spec, flush, result);
- }
- }
-
- if (!success && !error_set)
- {
- StreamString error_strm;
- if (uuid_option_set)
- {
- error_strm.PutCString("unable to find debug symbols for UUID ");
- module_spec.GetUUID().Dump (&error_strm);
- }
- else if (file_option_set)
- {
- error_strm.PutCString("unable to find debug symbols for the executable file ");
- error_strm << module_spec.GetFileSpec();
- }
- else if (frame_option_set)
- {
- error_strm.PutCString("unable to find debug symbols for the current frame");
- }
- result.AppendError (error_strm.GetData());
- }
- }
- else
- {
- result.AppendError ("one or more symbol file paths must be specified, or options must be specified");
- }
- }
- else
- {
- if (uuid_option_set)
- {
- result.AppendError ("specify either one or more paths to symbol files or use the --uuid option without arguments");
- }
- else if (file_option_set)
- {
- result.AppendError ("specify either one or more paths to symbol files or use the --file option without arguments");
- }
- else if (frame_option_set)
- {
- result.AppendError ("specify either one or more paths to symbol files or use the --frame option without arguments");
- }
- else
- {
- PlatformSP platform_sp (target->GetPlatform());
-
- for (size_t i = 0; i < argc; ++i)
- {
- const char *symfile_path = args.GetArgumentAtIndex(i);
- if (symfile_path)
- {
- module_spec.GetSymbolFileSpec().SetFile(symfile_path, true);
- if (platform_sp)
- {
- FileSpec symfile_spec;
- if (platform_sp->ResolveSymbolFile(*target, module_spec, symfile_spec).Success())
- module_spec.GetSymbolFileSpec() = symfile_spec;
- }
-
- ArchSpec arch;
- bool symfile_exists = module_spec.GetSymbolFileSpec().Exists();
-
- if (symfile_exists)
- {
- if (!AddModuleSymbols (target, module_spec, flush, result))
- break;
- }
- else
- {
- char resolved_symfile_path[PATH_MAX];
- if (module_spec.GetSymbolFileSpec().GetPath (resolved_symfile_path, sizeof(resolved_symfile_path)))
- {
- if (strcmp (resolved_symfile_path, symfile_path) != 0)
- {
- result.AppendErrorWithFormat ("invalid module path '%s' with resolved path '%s'\n", symfile_path, resolved_symfile_path);
- break;
- }
- }
- result.AppendErrorWithFormat ("invalid module path '%s'\n", symfile_path);
- break;
- }
- }
- }
+ bool DoExecute(Args &args, CommandReturnObject &result) override {
+ Target *target = m_exe_ctx.GetTargetPtr();
+ result.SetStatus(eReturnStatusFailed);
+ bool flush = false;
+ ModuleSpec module_spec;
+ const bool uuid_option_set =
+ m_uuid_option_group.GetOptionValue().OptionWasSet();
+ const bool file_option_set = m_file_option.GetOptionValue().OptionWasSet();
+ const bool frame_option_set =
+ m_current_frame_option.GetOptionValue().OptionWasSet();
+ const size_t argc = args.GetArgumentCount();
+
+ if (argc == 0) {
+ if (uuid_option_set || file_option_set || frame_option_set) {
+ bool success = false;
+ bool error_set = false;
+ if (frame_option_set) {
+ Process *process = m_exe_ctx.GetProcessPtr();
+ if (process) {
+ const StateType process_state = process->GetState();
+ if (StateIsStoppedState(process_state, true)) {
+ StackFrame *frame = m_exe_ctx.GetFramePtr();
+ if (frame) {
+ ModuleSP frame_module_sp(
+ frame->GetSymbolContext(eSymbolContextModule).module_sp);
+ if (frame_module_sp) {
+ if (frame_module_sp->GetPlatformFileSpec().Exists()) {
+ module_spec.GetArchitecture() =
+ frame_module_sp->GetArchitecture();
+ module_spec.GetFileSpec() =
+ frame_module_sp->GetPlatformFileSpec();
+ }
+ module_spec.GetUUID() = frame_module_sp->GetUUID();
+ success = module_spec.GetUUID().IsValid() ||
+ module_spec.GetFileSpec();
+ } else {
+ result.AppendError("frame has no module");
+ error_set = true;
+ }
+ } else {
+ result.AppendError("invalid current frame");
+ error_set = true;
+ }
+ } else {
+ result.AppendErrorWithFormat("process is not stopped: %s",
+ StateAsCString(process_state));
+ error_set = true;
+ }
+ } else {
+ result.AppendError(
+ "a process must exist in order to use the --frame option");
+ error_set = true;
+ }
+ } else {
+ if (uuid_option_set) {
+ module_spec.GetUUID() =
+ m_uuid_option_group.GetOptionValue().GetCurrentValue();
+ success |= module_spec.GetUUID().IsValid();
+ } else if (file_option_set) {
+ module_spec.GetFileSpec() =
+ m_file_option.GetOptionValue().GetCurrentValue();
+ ModuleSP module_sp(
+ target->GetImages().FindFirstModule(module_spec));
+ if (module_sp) {
+ module_spec.GetFileSpec() = module_sp->GetFileSpec();
+ module_spec.GetPlatformFileSpec() =
+ module_sp->GetPlatformFileSpec();
+ module_spec.GetUUID() = module_sp->GetUUID();
+ module_spec.GetArchitecture() = module_sp->GetArchitecture();
+ } else {
+ module_spec.GetArchitecture() = target->GetArchitecture();
+ }
+ success |= module_spec.GetUUID().IsValid() ||
+ module_spec.GetFileSpec().Exists();
+ }
+ }
+
+ if (success) {
+ if (Symbols::DownloadObjectAndSymbolFile(module_spec)) {
+ if (module_spec.GetSymbolFileSpec())
+ success = AddModuleSymbols(target, module_spec, flush, result);
+ }
+ }
+
+ if (!success && !error_set) {
+ StreamString error_strm;
+ if (uuid_option_set) {
+ error_strm.PutCString("unable to find debug symbols for UUID ");
+ module_spec.GetUUID().Dump(&error_strm);
+ } else if (file_option_set) {
+ error_strm.PutCString(
+ "unable to find debug symbols for the executable file ");
+ error_strm << module_spec.GetFileSpec();
+ } else if (frame_option_set) {
+ error_strm.PutCString(
+ "unable to find debug symbols for the current frame");
+ }
+ result.AppendError(error_strm.GetData());
+ }
+ } else {
+ result.AppendError("one or more symbol file paths must be specified, "
+ "or options must be specified");
+ }
+ } else {
+ if (uuid_option_set) {
+ result.AppendError("specify either one or more paths to symbol files "
+ "or use the --uuid option without arguments");
+ } else if (file_option_set) {
+ result.AppendError("specify either one or more paths to symbol files "
+ "or use the --file option without arguments");
+ } else if (frame_option_set) {
+ result.AppendError("specify either one or more paths to symbol files "
+ "or use the --frame option without arguments");
+ } else {
+ PlatformSP platform_sp(target->GetPlatform());
+
+ for (size_t i = 0; i < argc; ++i) {
+ const char *symfile_path = args.GetArgumentAtIndex(i);
+ if (symfile_path) {
+ module_spec.GetSymbolFileSpec().SetFile(symfile_path, true);
+ if (platform_sp) {
+ FileSpec symfile_spec;
+ if (platform_sp
+ ->ResolveSymbolFile(*target, module_spec, symfile_spec)
+ .Success())
+ module_spec.GetSymbolFileSpec() = symfile_spec;
}
- }
- if (flush)
- {
- Process *process = m_exe_ctx.GetProcessPtr();
- if (process)
- process->Flush();
- }
- return result.Succeeded();
- }
+ ArchSpec arch;
+ bool symfile_exists = module_spec.GetSymbolFileSpec().Exists();
- OptionGroupOptions m_option_group;
- OptionGroupUUID m_uuid_option_group;
- OptionGroupFile m_file_option;
- OptionGroupBoolean m_current_frame_option;
+ if (symfile_exists) {
+ if (!AddModuleSymbols(target, module_spec, flush, result))
+ break;
+ } else {
+ char resolved_symfile_path[PATH_MAX];
+ if (module_spec.GetSymbolFileSpec().GetPath(
+ resolved_symfile_path, sizeof(resolved_symfile_path))) {
+ if (strcmp(resolved_symfile_path, symfile_path) != 0) {
+ result.AppendErrorWithFormat(
+ "invalid module path '%s' with resolved path '%s'\n",
+ symfile_path, resolved_symfile_path);
+ break;
+ }
+ }
+ result.AppendErrorWithFormat("invalid module path '%s'\n",
+ symfile_path);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if (flush) {
+ Process *process = m_exe_ctx.GetProcessPtr();
+ if (process)
+ process->Flush();
+ }
+ return result.Succeeded();
+ }
+
+ OptionGroupOptions m_option_group;
+ OptionGroupUUID m_uuid_option_group;
+ OptionGroupFile m_file_option;
+ OptionGroupBoolean m_current_frame_option;
};
#pragma mark CommandObjectTargetSymbols
@@ -4830,26 +4296,27 @@ protected:
// CommandObjectTargetSymbols
//-------------------------------------------------------------------------
-class CommandObjectTargetSymbols : public CommandObjectMultiword
-{
+class CommandObjectTargetSymbols : public CommandObjectMultiword {
public:
- //------------------------------------------------------------------
- // Constructors and Destructors
- //------------------------------------------------------------------
- CommandObjectTargetSymbols(CommandInterpreter &interpreter)
- : CommandObjectMultiword(interpreter, "target symbols", "Commands for adding and managing debug symbol files.",
- "target symbols <sub-command> ...")
- {
- LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetSymbolsAdd (interpreter)));
- }
+ //------------------------------------------------------------------
+ // Constructors and Destructors
+ //------------------------------------------------------------------
+ CommandObjectTargetSymbols(CommandInterpreter &interpreter)
+ : CommandObjectMultiword(
+ interpreter, "target symbols",
+ "Commands for adding and managing debug symbol files.",
+ "target symbols <sub-command> ...") {
+ LoadSubCommand(
+ "add", CommandObjectSP(new CommandObjectTargetSymbolsAdd(interpreter)));
+ }
- ~CommandObjectTargetSymbols() override = default;
+ ~CommandObjectTargetSymbols() override = default;
private:
- //------------------------------------------------------------------
- // For CommandObjectTargetModules only
- //------------------------------------------------------------------
- DISALLOW_COPY_AND_ASSIGN (CommandObjectTargetSymbols);
+ //------------------------------------------------------------------
+ // For CommandObjectTargetModules only
+ //------------------------------------------------------------------
+ DISALLOW_COPY_AND_ASSIGN(CommandObjectTargetSymbols);
};
#pragma mark CommandObjectTargetStopHookAdd
@@ -4858,339 +4325,308 @@ private:
// CommandObjectTargetStopHookAdd
//-------------------------------------------------------------------------
-class CommandObjectTargetStopHookAdd :
- public CommandObjectParsed,
- public IOHandlerDelegateMultiline
-{
+class CommandObjectTargetStopHookAdd : public CommandObjectParsed,
+ public IOHandlerDelegateMultiline {
public:
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options(),
- m_line_start(0),
- m_line_end (UINT_MAX),
- m_func_name_type_mask (eFunctionNameTypeAuto),
- m_sym_ctx_specified (false),
- m_thread_specified (false),
- m_use_one_liner (false),
- m_one_liner()
- {
- }
-
- ~CommandOptions() override = default;
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
- bool success;
-
- switch (short_option)
- {
- case 'c':
- m_class_name = option_arg;
- m_sym_ctx_specified = true;
- break;
-
- case 'e':
- m_line_end = StringConvert::ToUInt32 (option_arg, UINT_MAX, 0, &success);
- if (!success)
- {
- error.SetErrorStringWithFormat ("invalid end line number: \"%s\"", option_arg);
- break;
- }
- m_sym_ctx_specified = true;
- break;
-
- case 'l':
- m_line_start = StringConvert::ToUInt32 (option_arg, 0, 0, &success);
- if (!success)
- {
- error.SetErrorStringWithFormat ("invalid start line number: \"%s\"", option_arg);
- break;
- }
- m_sym_ctx_specified = true;
- break;
+ class CommandOptions : public Options {
+ public:
+ CommandOptions()
+ : Options(), m_line_start(0), m_line_end(UINT_MAX),
+ m_func_name_type_mask(eFunctionNameTypeAuto),
+ m_sym_ctx_specified(false), m_thread_specified(false),
+ m_use_one_liner(false), m_one_liner() {}
+
+ ~CommandOptions() override = default;
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+ bool success;
+
+ switch (short_option) {
+ case 'c':
+ m_class_name = option_arg;
+ m_sym_ctx_specified = true;
+ break;
+
+ case 'e':
+ m_line_end = StringConvert::ToUInt32(option_arg, UINT_MAX, 0, &success);
+ if (!success) {
+ error.SetErrorStringWithFormat("invalid end line number: \"%s\"",
+ option_arg);
+ break;
+ }
+ m_sym_ctx_specified = true;
+ break;
+
+ case 'l':
+ m_line_start = StringConvert::ToUInt32(option_arg, 0, 0, &success);
+ if (!success) {
+ error.SetErrorStringWithFormat("invalid start line number: \"%s\"",
+ option_arg);
+ break;
+ }
+ m_sym_ctx_specified = true;
+ break;
+
+ case 'i':
+ m_no_inlines = true;
+ break;
+
+ case 'n':
+ m_function_name = option_arg;
+ m_func_name_type_mask |= eFunctionNameTypeAuto;
+ m_sym_ctx_specified = true;
+ break;
+
+ case 'f':
+ m_file_name = option_arg;
+ m_sym_ctx_specified = true;
+ break;
+
+ case 's':
+ m_module_name = option_arg;
+ m_sym_ctx_specified = true;
+ break;
+
+ case 't':
+ m_thread_id =
+ StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
+ if (m_thread_id == LLDB_INVALID_THREAD_ID)
+ error.SetErrorStringWithFormat("invalid thread id string '%s'",
+ option_arg);
+ m_thread_specified = true;
+ break;
+
+ case 'T':
+ m_thread_name = option_arg;
+ m_thread_specified = true;
+ break;
+
+ case 'q':
+ m_queue_name = option_arg;
+ m_thread_specified = true;
+ break;
+
+ case 'x':
+ m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
+ if (m_thread_id == UINT32_MAX)
+ error.SetErrorStringWithFormat("invalid thread index string '%s'",
+ option_arg);
+ m_thread_specified = true;
+ break;
+
+ case 'o':
+ m_use_one_liner = true;
+ m_one_liner = option_arg;
+ break;
+
+ default:
+ error.SetErrorStringWithFormat("unrecognized option %c.", short_option);
+ break;
+ }
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_class_name.clear();
+ m_function_name.clear();
+ m_line_start = 0;
+ m_line_end = UINT_MAX;
+ m_file_name.clear();
+ m_module_name.clear();
+ m_func_name_type_mask = eFunctionNameTypeAuto;
+ m_thread_id = LLDB_INVALID_THREAD_ID;
+ m_thread_index = UINT32_MAX;
+ m_thread_name.clear();
+ m_queue_name.clear();
+
+ m_no_inlines = false;
+ m_sym_ctx_specified = false;
+ m_thread_specified = false;
+
+ m_use_one_liner = false;
+ m_one_liner.clear();
+ }
+
+ static OptionDefinition g_option_table[];
+
+ std::string m_class_name;
+ std::string m_function_name;
+ uint32_t m_line_start;
+ uint32_t m_line_end;
+ std::string m_file_name;
+ std::string m_module_name;
+ uint32_t m_func_name_type_mask; // A pick from lldb::FunctionNameType.
+ lldb::tid_t m_thread_id;
+ uint32_t m_thread_index;
+ std::string m_thread_name;
+ std::string m_queue_name;
+ bool m_sym_ctx_specified;
+ bool m_no_inlines;
+ bool m_thread_specified;
+ // Instance variables to hold the values for one_liner options.
+ bool m_use_one_liner;
+ std::string m_one_liner;
+ };
+
+ CommandObjectTargetStopHookAdd(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "target stop-hook add",
+ "Add a hook to be executed when the target stops.",
+ "target stop-hook add"),
+ IOHandlerDelegateMultiline("DONE",
+ IOHandlerDelegate::Completion::LLDBCommand),
+ m_options() {}
- case 'i':
- m_no_inlines = true;
- break;
-
- case 'n':
- m_function_name = option_arg;
- m_func_name_type_mask |= eFunctionNameTypeAuto;
- m_sym_ctx_specified = true;
- break;
-
- case 'f':
- m_file_name = option_arg;
- m_sym_ctx_specified = true;
- break;
-
- case 's':
- m_module_name = option_arg;
- m_sym_ctx_specified = true;
- break;
-
- case 't' :
- m_thread_id = StringConvert::ToUInt64(option_arg, LLDB_INVALID_THREAD_ID, 0);
- if (m_thread_id == LLDB_INVALID_THREAD_ID)
- error.SetErrorStringWithFormat ("invalid thread id string '%s'", option_arg);
- m_thread_specified = true;
- break;
-
- case 'T':
- m_thread_name = option_arg;
- m_thread_specified = true;
- break;
-
- case 'q':
- m_queue_name = option_arg;
- m_thread_specified = true;
- break;
-
- case 'x':
- m_thread_index = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
- if (m_thread_id == UINT32_MAX)
- error.SetErrorStringWithFormat ("invalid thread index string '%s'", option_arg);
- m_thread_specified = true;
- break;
-
- case 'o':
- m_use_one_liner = true;
- m_one_liner = option_arg;
- break;
-
- default:
- error.SetErrorStringWithFormat ("unrecognized option %c.", short_option);
- break;
- }
- return error;
- }
+ ~CommandObjectTargetStopHookAdd() override = default;
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_class_name.clear();
- m_function_name.clear();
- m_line_start = 0;
- m_line_end = UINT_MAX;
- m_file_name.clear();
- m_module_name.clear();
- m_func_name_type_mask = eFunctionNameTypeAuto;
- m_thread_id = LLDB_INVALID_THREAD_ID;
- m_thread_index = UINT32_MAX;
- m_thread_name.clear();
- m_queue_name.clear();
-
- m_no_inlines = false;
- m_sym_ctx_specified = false;
- m_thread_specified = false;
-
- m_use_one_liner = false;
- m_one_liner.clear();
- }
-
- static OptionDefinition g_option_table[];
-
- std::string m_class_name;
- std::string m_function_name;
- uint32_t m_line_start;
- uint32_t m_line_end;
- std::string m_file_name;
- std::string m_module_name;
- uint32_t m_func_name_type_mask; // A pick from lldb::FunctionNameType.
- lldb::tid_t m_thread_id;
- uint32_t m_thread_index;
- std::string m_thread_name;
- std::string m_queue_name;
- bool m_sym_ctx_specified;
- bool m_no_inlines;
- bool m_thread_specified;
- // Instance variables to hold the values for one_liner options.
- bool m_use_one_liner;
- std::string m_one_liner;
- };
-
- CommandObjectTargetStopHookAdd (CommandInterpreter &interpreter) :
- CommandObjectParsed (interpreter,
- "target stop-hook add",
- "Add a hook to be executed when the target stops.",
- "target stop-hook add"),
- IOHandlerDelegateMultiline ("DONE", IOHandlerDelegate::Completion::LLDBCommand),
- m_options()
- {
- }
-
- ~CommandObjectTargetStopHookAdd() override = default;
-
- Options *
- GetOptions () override
- {
- return &m_options;
- }
+ Options *GetOptions() override { return &m_options; }
protected:
- void
- IOHandlerActivated (IOHandler &io_handler) override
- {
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
- if (output_sp)
- {
- output_sp->PutCString("Enter your stop hook command(s). Type 'DONE' to end.\n");
- output_sp->Flush();
+ void IOHandlerActivated(IOHandler &io_handler) override {
+ StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ if (output_sp) {
+ output_sp->PutCString(
+ "Enter your stop hook command(s). Type 'DONE' to end.\n");
+ output_sp->Flush();
+ }
+ }
+
+ void IOHandlerInputComplete(IOHandler &io_handler,
+ std::string &line) override {
+ if (m_stop_hook_sp) {
+ if (line.empty()) {
+ StreamFileSP error_sp(io_handler.GetErrorStreamFile());
+ if (error_sp) {
+ error_sp->Printf("error: stop hook #%" PRIu64
+ " aborted, no commands.\n",
+ m_stop_hook_sp->GetID());
+ error_sp->Flush();
}
- }
-
- void
- IOHandlerInputComplete (IOHandler &io_handler, std::string &line) override
- {
- if (m_stop_hook_sp)
- {
- if (line.empty())
- {
- StreamFileSP error_sp(io_handler.GetErrorStreamFile());
- if (error_sp)
- {
- error_sp->Printf("error: stop hook #%" PRIu64 " aborted, no commands.\n", m_stop_hook_sp->GetID());
- error_sp->Flush();
- }
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (target)
- target->RemoveStopHookByID(m_stop_hook_sp->GetID());
- }
- else
- {
- m_stop_hook_sp->GetCommandPointer()->SplitIntoLines(line);
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
- if (output_sp)
- {
- output_sp->Printf("Stop hook #%" PRIu64 " added.\n", m_stop_hook_sp->GetID());
- output_sp->Flush();
- }
- }
- m_stop_hook_sp.reset();
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target)
+ target->RemoveStopHookByID(m_stop_hook_sp->GetID());
+ } else {
+ m_stop_hook_sp->GetCommandPointer()->SplitIntoLines(line);
+ StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ if (output_sp) {
+ output_sp->Printf("Stop hook #%" PRIu64 " added.\n",
+ m_stop_hook_sp->GetID());
+ output_sp->Flush();
}
- io_handler.SetIsDone(true);
+ }
+ m_stop_hook_sp.reset();
}
+ io_handler.SetIsDone(true);
+ }
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- m_stop_hook_sp.reset();
-
- Target *target = GetSelectedOrDummyTarget();
- if (target)
- {
- Target::StopHookSP new_hook_sp = target->CreateStopHook();
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ m_stop_hook_sp.reset();
- // First step, make the specifier.
- std::unique_ptr<SymbolContextSpecifier> specifier_ap;
- if (m_options.m_sym_ctx_specified)
- {
- specifier_ap.reset(new SymbolContextSpecifier(m_interpreter.GetDebugger().GetSelectedTarget()));
-
- if (!m_options.m_module_name.empty())
- {
- specifier_ap->AddSpecification (m_options.m_module_name.c_str(), SymbolContextSpecifier::eModuleSpecified);
- }
+ Target *target = GetSelectedOrDummyTarget();
+ if (target) {
+ Target::StopHookSP new_hook_sp = target->CreateStopHook();
- if (!m_options.m_class_name.empty())
- {
- specifier_ap->AddSpecification (m_options.m_class_name.c_str(), SymbolContextSpecifier::eClassOrNamespaceSpecified);
- }
+ // First step, make the specifier.
+ std::unique_ptr<SymbolContextSpecifier> specifier_ap;
+ if (m_options.m_sym_ctx_specified) {
+ specifier_ap.reset(new SymbolContextSpecifier(
+ m_interpreter.GetDebugger().GetSelectedTarget()));
- if (!m_options.m_file_name.empty())
- {
- specifier_ap->AddSpecification (m_options.m_file_name.c_str(), SymbolContextSpecifier::eFileSpecified);
- }
+ if (!m_options.m_module_name.empty()) {
+ specifier_ap->AddSpecification(
+ m_options.m_module_name.c_str(),
+ SymbolContextSpecifier::eModuleSpecified);
+ }
- if (m_options.m_line_start != 0)
- {
- specifier_ap->AddLineSpecification (m_options.m_line_start, SymbolContextSpecifier::eLineStartSpecified);
- }
+ if (!m_options.m_class_name.empty()) {
+ specifier_ap->AddSpecification(
+ m_options.m_class_name.c_str(),
+ SymbolContextSpecifier::eClassOrNamespaceSpecified);
+ }
- if (m_options.m_line_end != UINT_MAX)
- {
- specifier_ap->AddLineSpecification (m_options.m_line_end, SymbolContextSpecifier::eLineEndSpecified);
- }
+ if (!m_options.m_file_name.empty()) {
+ specifier_ap->AddSpecification(
+ m_options.m_file_name.c_str(),
+ SymbolContextSpecifier::eFileSpecified);
+ }
- if (!m_options.m_function_name.empty())
- {
- specifier_ap->AddSpecification (m_options.m_function_name.c_str(), SymbolContextSpecifier::eFunctionSpecified);
- }
- }
+ if (m_options.m_line_start != 0) {
+ specifier_ap->AddLineSpecification(
+ m_options.m_line_start,
+ SymbolContextSpecifier::eLineStartSpecified);
+ }
- if (specifier_ap)
- new_hook_sp->SetSpecifier (specifier_ap.release());
+ if (m_options.m_line_end != UINT_MAX) {
+ specifier_ap->AddLineSpecification(
+ m_options.m_line_end, SymbolContextSpecifier::eLineEndSpecified);
+ }
- // Next see if any of the thread options have been entered:
+ if (!m_options.m_function_name.empty()) {
+ specifier_ap->AddSpecification(
+ m_options.m_function_name.c_str(),
+ SymbolContextSpecifier::eFunctionSpecified);
+ }
+ }
- 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 (specifier_ap)
+ new_hook_sp->SetSpecifier(specifier_ap.release());
- if (m_options.m_thread_index != UINT32_MAX)
- thread_spec->SetIndex (m_options.m_thread_index);
+ // Next see if any of the thread options have been entered:
- if (!m_options.m_thread_name.empty())
- thread_spec->SetName (m_options.m_thread_name.c_str());
+ if (m_options.m_thread_specified) {
+ ThreadSpec *thread_spec = new ThreadSpec();
- if (!m_options.m_queue_name.empty())
- thread_spec->SetQueueName (m_options.m_queue_name.c_str());
+ if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID) {
+ thread_spec->SetTID(m_options.m_thread_id);
+ }
- new_hook_sp->SetThreadSpecifier (thread_spec);
+ if (m_options.m_thread_index != UINT32_MAX)
+ thread_spec->SetIndex(m_options.m_thread_index);
- }
- if (m_options.m_use_one_liner)
- {
- // Use one-liner.
- new_hook_sp->GetCommandPointer()->AppendString (m_options.m_one_liner.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
+ if (!m_options.m_thread_name.empty())
+ thread_spec->SetName(m_options.m_thread_name.c_str());
- }
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- result.AppendError ("invalid target\n");
- result.SetStatus (eReturnStatusFailed);
- }
+ if (!m_options.m_queue_name.empty())
+ thread_spec->SetQueueName(m_options.m_queue_name.c_str());
- return result.Succeeded();
+ new_hook_sp->SetThreadSpecifier(thread_spec);
+ }
+ if (m_options.m_use_one_liner) {
+ // Use one-liner.
+ new_hook_sp->GetCommandPointer()->AppendString(
+ m_options.m_one_liner.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);
+ } else {
+ result.AppendError("invalid target\n");
+ result.SetStatus(eReturnStatusFailed);
}
+ return result.Succeeded();
+ }
+
private:
- CommandOptions m_options;
- Target::StopHookSP m_stop_hook_sp;
+ CommandOptions m_options;
+ Target::StopHookSP m_stop_hook_sp;
};
OptionDefinition
-CommandObjectTargetStopHookAdd::CommandOptions::g_option_table[] =
-{
- // clang-format off
+ CommandObjectTargetStopHookAdd::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_ALL, false, "one-liner", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOneLiner, "Specify a one-line breakpoint command inline. Be sure to surround it with quotes."},
{LLDB_OPT_SET_ALL, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Set the module within which the stop-hook is to be run."},
{LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "The stop hook is run only for the thread whose index matches this argument."},
@@ -5203,7 +4639,7 @@ CommandObjectTargetStopHookAdd::CommandO
{LLDB_OPT_SET_2, false, "classname", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeClassName, "Specify the class within which the stop-hook is to be run."},
{LLDB_OPT_SET_3, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the function name within which the stop hook will be run."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
- // clang-format on
+ // clang-format on
};
#pragma mark CommandObjectTargetStopHookDelete
@@ -5212,71 +4648,56 @@ CommandObjectTargetStopHookAdd::CommandO
// CommandObjectTargetStopHookDelete
//-------------------------------------------------------------------------
-class CommandObjectTargetStopHookDelete : public CommandObjectParsed
-{
+class CommandObjectTargetStopHookDelete : public CommandObjectParsed {
public:
- CommandObjectTargetStopHookDelete (CommandInterpreter &interpreter) :
- CommandObjectParsed (interpreter,
- "target stop-hook delete",
- "Delete a stop-hook.",
- "target stop-hook delete [<idx>]")
- {
- }
+ CommandObjectTargetStopHookDelete(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "target stop-hook delete",
+ "Delete a stop-hook.",
+ "target stop-hook delete [<idx>]") {}
- ~CommandObjectTargetStopHookDelete() override = default;
+ ~CommandObjectTargetStopHookDelete() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = GetSelectedOrDummyTarget();
- if (target)
- {
- // FIXME: see if we can use the breakpoint id style parser?
- size_t num_args = command.GetArgumentCount();
- if (num_args == 0)
- {
- if (!m_interpreter.Confirm ("Delete all stop hooks?", true))
- {
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- else
- {
- target->RemoveAllStopHooks();
- }
- }
- else
- {
- bool success;
- for (size_t i = 0; i < num_args; i++)
- {
- lldb::user_id_t user_id = StringConvert::ToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
- if (!success)
- {
- result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- success = target->RemoveStopHookByID (user_id);
- if (!success)
- {
- result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
- }
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- result.AppendError ("invalid target\n");
- result.SetStatus (eReturnStatusFailed);
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = GetSelectedOrDummyTarget();
+ if (target) {
+ // FIXME: see if we can use the breakpoint id style parser?
+ size_t num_args = command.GetArgumentCount();
+ if (num_args == 0) {
+ if (!m_interpreter.Confirm("Delete all stop hooks?", true)) {
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ } else {
+ target->RemoveAllStopHooks();
+ }
+ } else {
+ bool success;
+ for (size_t i = 0; i < num_args; i++) {
+ lldb::user_id_t user_id = StringConvert::ToUInt32(
+ command.GetArgumentAtIndex(i), 0, 0, &success);
+ if (!success) {
+ result.AppendErrorWithFormat("invalid stop hook id: \"%s\".\n",
+ command.GetArgumentAtIndex(i));
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ success = target->RemoveStopHookByID(user_id);
+ if (!success) {
+ result.AppendErrorWithFormat("unknown stop hook id: \"%s\".\n",
+ command.GetArgumentAtIndex(i));
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
}
-
- return result.Succeeded();
+ }
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ } else {
+ result.AppendError("invalid target\n");
+ result.SetStatus(eReturnStatusFailed);
}
+
+ return result.Succeeded();
+ }
};
#pragma mark CommandObjectTargetStopHookEnableDisable
@@ -5285,66 +4706,55 @@ protected:
// CommandObjectTargetStopHookEnableDisable
//-------------------------------------------------------------------------
-class CommandObjectTargetStopHookEnableDisable : public CommandObjectParsed
-{
+class CommandObjectTargetStopHookEnableDisable : public CommandObjectParsed {
public:
- CommandObjectTargetStopHookEnableDisable (CommandInterpreter &interpreter, bool enable, const char *name, const char *help, const char *syntax) :
- CommandObjectParsed (interpreter,
- name,
- help,
- syntax),
- m_enable (enable)
- {
- }
+ CommandObjectTargetStopHookEnableDisable(CommandInterpreter &interpreter,
+ bool enable, const char *name,
+ const char *help, const char *syntax)
+ : CommandObjectParsed(interpreter, name, help, syntax), m_enable(enable) {
+ }
- ~CommandObjectTargetStopHookEnableDisable() override = default;
+ ~CommandObjectTargetStopHookEnableDisable() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = GetSelectedOrDummyTarget();
- if (target)
- {
- // FIXME: see if we can use the breakpoint id style parser?
- size_t num_args = command.GetArgumentCount();
- bool success;
-
- if (num_args == 0)
- {
- target->SetAllStopHooksActiveState (m_enable);
- }
- else
- {
- for (size_t i = 0; i < num_args; i++)
- {
- lldb::user_id_t user_id = StringConvert::ToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
- if (!success)
- {
- result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- success = target->SetStopHookActiveStateByID (user_id, m_enable);
- if (!success)
- {
- result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
- }
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- result.AppendError ("invalid target\n");
- result.SetStatus (eReturnStatusFailed);
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = GetSelectedOrDummyTarget();
+ if (target) {
+ // FIXME: see if we can use the breakpoint id style parser?
+ size_t num_args = command.GetArgumentCount();
+ bool success;
+
+ if (num_args == 0) {
+ target->SetAllStopHooksActiveState(m_enable);
+ } else {
+ for (size_t i = 0; i < num_args; i++) {
+ lldb::user_id_t user_id = StringConvert::ToUInt32(
+ command.GetArgumentAtIndex(i), 0, 0, &success);
+ if (!success) {
+ result.AppendErrorWithFormat("invalid stop hook id: \"%s\".\n",
+ command.GetArgumentAtIndex(i));
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ success = target->SetStopHookActiveStateByID(user_id, m_enable);
+ if (!success) {
+ result.AppendErrorWithFormat("unknown stop hook id: \"%s\".\n",
+ command.GetArgumentAtIndex(i));
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
}
- return result.Succeeded();
+ }
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ } else {
+ result.AppendError("invalid target\n");
+ result.SetStatus(eReturnStatusFailed);
}
+ return result.Succeeded();
+ }
+
private:
- bool m_enable;
+ bool m_enable;
};
#pragma mark CommandObjectTargetStopHookList
@@ -5353,49 +4763,39 @@ private:
// CommandObjectTargetStopHookList
//-------------------------------------------------------------------------
-class CommandObjectTargetStopHookList : public CommandObjectParsed
-{
+class CommandObjectTargetStopHookList : public CommandObjectParsed {
public:
- CommandObjectTargetStopHookList (CommandInterpreter &interpreter) :
- CommandObjectParsed (interpreter,
- "target stop-hook list",
- "List all stop-hooks.",
- "target stop-hook list [<type>]")
- {
- }
+ CommandObjectTargetStopHookList(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "target stop-hook list",
+ "List all stop-hooks.",
+ "target stop-hook list [<type>]") {}
- ~CommandObjectTargetStopHookList() override = default;
+ ~CommandObjectTargetStopHookList() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = GetSelectedOrDummyTarget();
- if (!target)
- {
- result.AppendError ("invalid target\n");
- result.SetStatus (eReturnStatusFailed);
- return result.Succeeded();
- }
-
- size_t num_hooks = target->GetNumStopHooks ();
- if (num_hooks == 0)
- {
- result.GetOutputStream().PutCString ("No stop hooks.\n");
- }
- else
- {
- for (size_t i = 0; i < num_hooks; i++)
- {
- Target::StopHookSP this_hook = target->GetStopHookAtIndex (i);
- if (i > 0)
- result.GetOutputStream().PutCString ("\n");
- this_hook->GetDescription (&(result.GetOutputStream()), eDescriptionLevelFull);
- }
- }
- result.SetStatus (eReturnStatusSuccessFinishResult);
- return result.Succeeded();
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = GetSelectedOrDummyTarget();
+ if (!target) {
+ result.AppendError("invalid target\n");
+ result.SetStatus(eReturnStatusFailed);
+ return result.Succeeded();
+ }
+
+ size_t num_hooks = target->GetNumStopHooks();
+ if (num_hooks == 0) {
+ result.GetOutputStream().PutCString("No stop hooks.\n");
+ } else {
+ for (size_t i = 0; i < num_hooks; i++) {
+ Target::StopHookSP this_hook = target->GetStopHookAtIndex(i);
+ if (i > 0)
+ result.GetOutputStream().PutCString("\n");
+ this_hook->GetDescription(&(result.GetOutputStream()),
+ eDescriptionLevelFull);
+ }
+ }
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return result.Succeeded();
+ }
};
#pragma mark CommandObjectMultiwordTargetStopHooks
@@ -5404,30 +4804,31 @@ protected:
// CommandObjectMultiwordTargetStopHooks
//-------------------------------------------------------------------------
-class CommandObjectMultiwordTargetStopHooks : public CommandObjectMultiword
-{
+class CommandObjectMultiwordTargetStopHooks : public CommandObjectMultiword {
public:
- CommandObjectMultiwordTargetStopHooks(CommandInterpreter &interpreter)
- : CommandObjectMultiword(interpreter, "target stop-hook",
- "Commands for operating on debugger target stop-hooks.",
- "target stop-hook <subcommand> [<subcommand-options>]")
- {
- LoadSubCommand ("add", CommandObjectSP (new CommandObjectTargetStopHookAdd (interpreter)));
- LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetStopHookDelete (interpreter)));
- LoadSubCommand ("disable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
- false,
- "target stop-hook disable [<id>]",
- "Disable a stop-hook.",
- "target stop-hook disable")));
- LoadSubCommand ("enable", CommandObjectSP (new CommandObjectTargetStopHookEnableDisable (interpreter,
- true,
- "target stop-hook enable [<id>]",
- "Enable a stop-hook.",
- "target stop-hook enable")));
- LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetStopHookList (interpreter)));
- }
+ CommandObjectMultiwordTargetStopHooks(CommandInterpreter &interpreter)
+ : CommandObjectMultiword(
+ interpreter, "target stop-hook",
+ "Commands for operating on debugger target stop-hooks.",
+ "target stop-hook <subcommand> [<subcommand-options>]") {
+ LoadSubCommand("add", CommandObjectSP(
+ new CommandObjectTargetStopHookAdd(interpreter)));
+ LoadSubCommand(
+ "delete",
+ CommandObjectSP(new CommandObjectTargetStopHookDelete(interpreter)));
+ LoadSubCommand("disable",
+ CommandObjectSP(new CommandObjectTargetStopHookEnableDisable(
+ interpreter, false, "target stop-hook disable [<id>]",
+ "Disable a stop-hook.", "target stop-hook disable")));
+ LoadSubCommand("enable",
+ CommandObjectSP(new CommandObjectTargetStopHookEnableDisable(
+ interpreter, true, "target stop-hook enable [<id>]",
+ "Enable a stop-hook.", "target stop-hook enable")));
+ LoadSubCommand("list", CommandObjectSP(new CommandObjectTargetStopHookList(
+ interpreter)));
+ }
- ~CommandObjectMultiwordTargetStopHooks() override = default;
+ ~CommandObjectMultiwordTargetStopHooks() override = default;
};
#pragma mark CommandObjectMultiwordTarget
@@ -5436,18 +4837,28 @@ public:
// CommandObjectMultiwordTarget
//-------------------------------------------------------------------------
-CommandObjectMultiwordTarget::CommandObjectMultiwordTarget(CommandInterpreter &interpreter)
- : CommandObjectMultiword(interpreter, "target", "Commands for operating on debugger targets.",
- "target <subcommand> [<subcommand-options>]")
-{
- LoadSubCommand ("create", CommandObjectSP (new CommandObjectTargetCreate (interpreter)));
- LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetDelete (interpreter)));
- LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetList (interpreter)));
- LoadSubCommand ("select", CommandObjectSP (new CommandObjectTargetSelect (interpreter)));
- LoadSubCommand ("stop-hook", CommandObjectSP (new CommandObjectMultiwordTargetStopHooks (interpreter)));
- LoadSubCommand ("modules", CommandObjectSP (new CommandObjectTargetModules (interpreter)));
- LoadSubCommand ("symbols", CommandObjectSP (new CommandObjectTargetSymbols (interpreter)));
- LoadSubCommand ("variable", CommandObjectSP (new CommandObjectTargetVariable (interpreter)));
+CommandObjectMultiwordTarget::CommandObjectMultiwordTarget(
+ CommandInterpreter &interpreter)
+ : CommandObjectMultiword(interpreter, "target",
+ "Commands for operating on debugger targets.",
+ "target <subcommand> [<subcommand-options>]") {
+ LoadSubCommand("create",
+ CommandObjectSP(new CommandObjectTargetCreate(interpreter)));
+ LoadSubCommand("delete",
+ CommandObjectSP(new CommandObjectTargetDelete(interpreter)));
+ LoadSubCommand("list",
+ CommandObjectSP(new CommandObjectTargetList(interpreter)));
+ LoadSubCommand("select",
+ CommandObjectSP(new CommandObjectTargetSelect(interpreter)));
+ LoadSubCommand(
+ "stop-hook",
+ CommandObjectSP(new CommandObjectMultiwordTargetStopHooks(interpreter)));
+ LoadSubCommand("modules",
+ CommandObjectSP(new CommandObjectTargetModules(interpreter)));
+ LoadSubCommand("symbols",
+ CommandObjectSP(new CommandObjectTargetSymbols(interpreter)));
+ LoadSubCommand("variable",
+ CommandObjectSP(new CommandObjectTargetVariable(interpreter)));
}
CommandObjectMultiwordTarget::~CommandObjectMultiwordTarget() = default;
Modified: lldb/trunk/source/Commands/CommandObjectTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.h (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.h Tue Sep 6 15:57:50 2016
@@ -14,9 +14,9 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
-#include "lldb/Interpreter/Options.h"
#include "lldb/Core/ArchSpec.h"
#include "lldb/Interpreter/CommandObjectMultiword.h"
+#include "lldb/Interpreter/Options.h"
namespace lldb_private {
@@ -24,13 +24,11 @@ namespace lldb_private {
// CommandObjectMultiwordTarget
//-------------------------------------------------------------------------
-class CommandObjectMultiwordTarget : public CommandObjectMultiword
-{
+class CommandObjectMultiwordTarget : public CommandObjectMultiword {
public:
+ CommandObjectMultiwordTarget(CommandInterpreter &interpreter);
- CommandObjectMultiwordTarget (CommandInterpreter &interpreter);
-
- ~CommandObjectMultiwordTarget() override;
+ ~CommandObjectMultiwordTarget() override;
};
} // namespace lldb_private
Modified: lldb/trunk/source/Commands/CommandObjectThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectThread.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectThread.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectThread.cpp Tue Sep 6 15:57:50 2016
@@ -13,9 +13,8 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
-#include "lldb/lldb-private.h"
-#include "lldb/Core/State.h"
#include "lldb/Core/SourceManager.h"
+#include "lldb/Core/State.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/StringConvert.h"
@@ -24,18 +23,19 @@
#include "lldb/Interpreter/Options.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/Function.h"
-#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/LineEntry.h"
+#include "lldb/Symbol/LineTable.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/SystemRuntime.h"
#include "lldb/Target/Target.h"
#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/Target/ThreadPlanStepInRange.h"
+#include "lldb/lldb-private.h"
using namespace lldb;
using namespace lldb_private;
@@ -44,750 +44,663 @@ using namespace lldb_private;
// CommandObjectThreadBacktrace
//-------------------------------------------------------------------------
-class CommandObjectIterateOverThreads : public CommandObjectParsed
-{
+class CommandObjectIterateOverThreads : public CommandObjectParsed {
public:
- CommandObjectIterateOverThreads (CommandInterpreter &interpreter,
- const char *name,
- const char *help,
- const char *syntax,
- uint32_t flags) :
- CommandObjectParsed (interpreter, name, help, syntax, flags)
- {
- }
+ CommandObjectIterateOverThreads(CommandInterpreter &interpreter,
+ const char *name, const char *help,
+ const char *syntax, uint32_t flags)
+ : CommandObjectParsed(interpreter, name, help, syntax, flags) {}
+
+ ~CommandObjectIterateOverThreads() override = default;
+
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ result.SetStatus(m_success_return);
+
+ if (command.GetArgumentCount() == 0) {
+ Thread *thread = m_exe_ctx.GetThreadPtr();
+ if (!HandleOneThread(thread->GetID(), result))
+ return false;
+ return result.Succeeded();
+ }
+
+ // Use tids instead of ThreadSPs to prevent deadlocking problems which
+ // result from JIT-ing
+ // code while iterating over the (locked) ThreadSP list.
+ std::vector<lldb::tid_t> tids;
+
+ if (command.GetArgumentCount() == 1 &&
+ ::strcmp(command.GetArgumentAtIndex(0), "all") == 0) {
+ Process *process = m_exe_ctx.GetProcessPtr();
+
+ for (ThreadSP thread_sp : process->Threads())
+ tids.push_back(thread_sp->GetID());
+ } else {
+ const size_t num_args = command.GetArgumentCount();
+ Process *process = m_exe_ctx.GetProcessPtr();
- ~CommandObjectIterateOverThreads() override = default;
+ std::lock_guard<std::recursive_mutex> guard(
+ process->GetThreadList().GetMutex());
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- result.SetStatus (m_success_return);
-
- if (command.GetArgumentCount() == 0)
- {
- Thread *thread = m_exe_ctx.GetThreadPtr();
- if (!HandleOneThread (thread->GetID(), result))
- return false;
- return result.Succeeded();
- }
-
- // Use tids instead of ThreadSPs to prevent deadlocking problems which result from JIT-ing
- // code while iterating over the (locked) ThreadSP list.
- std::vector<lldb::tid_t> tids;
-
- if (command.GetArgumentCount() == 1 && ::strcmp (command.GetArgumentAtIndex(0), "all") == 0)
- {
- Process *process = m_exe_ctx.GetProcessPtr();
+ for (size_t i = 0; i < num_args; i++) {
+ bool success;
- for (ThreadSP thread_sp : process->Threads())
- tids.push_back(thread_sp->GetID());
+ uint32_t thread_idx = StringConvert::ToUInt32(
+ command.GetArgumentAtIndex(i), 0, 0, &success);
+ if (!success) {
+ result.AppendErrorWithFormat("invalid thread specification: \"%s\"\n",
+ command.GetArgumentAtIndex(i));
+ result.SetStatus(eReturnStatusFailed);
+ return false;
}
- else
- {
- const size_t num_args = command.GetArgumentCount();
- Process *process = m_exe_ctx.GetProcessPtr();
-
- std::lock_guard<std::recursive_mutex> guard(process->GetThreadList().GetMutex());
-
- for (size_t i = 0; i < num_args; i++)
- {
- bool success;
-
- uint32_t thread_idx = StringConvert::ToUInt32(command.GetArgumentAtIndex(i), 0, 0, &success);
- if (!success)
- {
- result.AppendErrorWithFormat ("invalid thread specification: \"%s\"\n", command.GetArgumentAtIndex(i));
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- ThreadSP thread = process->GetThreadList().FindThreadByIndexID(thread_idx);
-
- if (!thread)
- {
- result.AppendErrorWithFormat ("no thread with index: \"%s\"\n", command.GetArgumentAtIndex(i));
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- tids.push_back(thread->GetID());
- }
+ ThreadSP thread =
+ process->GetThreadList().FindThreadByIndexID(thread_idx);
+
+ if (!thread) {
+ result.AppendErrorWithFormat("no thread with index: \"%s\"\n",
+ command.GetArgumentAtIndex(i));
+ result.SetStatus(eReturnStatusFailed);
+ return false;
}
- uint32_t idx = 0;
- for (const lldb::tid_t &tid : tids)
- {
- if (idx != 0 && m_add_return)
- result.AppendMessage("");
+ tids.push_back(thread->GetID());
+ }
+ }
+
+ uint32_t idx = 0;
+ for (const lldb::tid_t &tid : tids) {
+ if (idx != 0 && m_add_return)
+ result.AppendMessage("");
- if (!HandleOneThread (tid, result))
- return false;
+ if (!HandleOneThread(tid, result))
+ return false;
- ++idx;
- }
- return result.Succeeded();
+ ++idx;
}
+ return result.Succeeded();
+ }
protected:
- // Override this to do whatever you need to do for one thread.
- //
- // If you return false, the iteration will stop, otherwise it will proceed.
- // The result is set to m_success_return (defaults to eReturnStatusSuccessFinishResult) before the iteration,
- // so you only need to set the return status in HandleOneThread if you want to indicate an error.
- // If m_add_return is true, a blank line will be inserted between each of the listings (except the last one.)
+ // Override this to do whatever you need to do for one thread.
+ //
+ // If you return false, the iteration will stop, otherwise it will proceed.
+ // The result is set to m_success_return (defaults to
+ // eReturnStatusSuccessFinishResult) before the iteration,
+ // so you only need to set the return status in HandleOneThread if you want to
+ // indicate an error.
+ // If m_add_return is true, a blank line will be inserted between each of the
+ // listings (except the last one.)
- virtual bool
- HandleOneThread (lldb::tid_t, CommandReturnObject &result) = 0;
+ virtual bool HandleOneThread(lldb::tid_t, CommandReturnObject &result) = 0;
- ReturnStatus m_success_return = eReturnStatusSuccessFinishResult;
- bool m_add_return = true;
+ ReturnStatus m_success_return = eReturnStatusSuccessFinishResult;
+ bool m_add_return = true;
};
//-------------------------------------------------------------------------
// CommandObjectThreadBacktrace
//-------------------------------------------------------------------------
-class CommandObjectThreadBacktrace : public CommandObjectIterateOverThreads
-{
+class CommandObjectThreadBacktrace : public CommandObjectIterateOverThreads {
public:
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options()
- {
- // Keep default values of all options in one place: OptionParsingStarting ()
- OptionParsingStarting(nullptr);
- }
-
- ~CommandOptions() override = default;
-
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'c':
- {
- bool success;
- int32_t input_count = StringConvert::ToSInt32 (option_arg, -1, 0, &success);
- if (!success)
- error.SetErrorStringWithFormat("invalid integer value for option '%c'", short_option);
- if (input_count < -1)
- m_count = UINT32_MAX;
- else
- m_count = input_count;
- }
- break;
- case 's':
- {
- bool success;
- m_start = StringConvert::ToUInt32 (option_arg, 0, 0, &success);
- if (!success)
- error.SetErrorStringWithFormat("invalid integer value for option '%c'", short_option);
- }
- break;
- case 'e':
- {
- bool success;
- m_extended_backtrace = Args::StringToBoolean (option_arg, false, &success);
- if (!success)
- error.SetErrorStringWithFormat("invalid boolean value for option '%c'", short_option);
- }
- break;
- default:
- error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
- break;
- }
- return error;
- }
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options() {
+ // Keep default values of all options in one place: OptionParsingStarting
+ // ()
+ OptionParsingStarting(nullptr);
+ }
+
+ ~CommandOptions() override = default;
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_count = UINT32_MAX;
- m_start = 0;
- m_extended_backtrace = false;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
- uint32_t m_count;
- uint32_t m_start;
- bool m_extended_backtrace;
- };
-
- CommandObjectThreadBacktrace(CommandInterpreter &interpreter)
- : CommandObjectIterateOverThreads(
- interpreter, "thread backtrace", "Show thread call stacks. Defaults to the current thread, thread "
- "indexes can be specified as arguments. Use the thread-index \"all\" "
- "to see all threads.",
- nullptr, eCommandRequiresProcess | eCommandRequiresThread | eCommandTryTargetAPILock |
- eCommandProcessMustBeLaunched | eCommandProcessMustBePaused),
- m_options()
- {
- }
+ switch (short_option) {
+ case 'c': {
+ bool success;
+ int32_t input_count =
+ StringConvert::ToSInt32(option_arg, -1, 0, &success);
+ if (!success)
+ error.SetErrorStringWithFormat(
+ "invalid integer value for option '%c'", short_option);
+ if (input_count < -1)
+ m_count = UINT32_MAX;
+ else
+ m_count = input_count;
+ } break;
+ case 's': {
+ bool success;
+ m_start = StringConvert::ToUInt32(option_arg, 0, 0, &success);
+ if (!success)
+ error.SetErrorStringWithFormat(
+ "invalid integer value for option '%c'", short_option);
+ } break;
+ case 'e': {
+ bool success;
+ m_extended_backtrace =
+ Args::StringToBoolean(option_arg, false, &success);
+ if (!success)
+ error.SetErrorStringWithFormat(
+ "invalid boolean value for option '%c'", short_option);
+ } break;
+ default:
+ error.SetErrorStringWithFormat("invalid short option character '%c'",
+ short_option);
+ break;
+ }
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_count = UINT32_MAX;
+ m_start = 0;
+ m_extended_backtrace = false;
+ }
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+ uint32_t m_count;
+ uint32_t m_start;
+ bool m_extended_backtrace;
+ };
+
+ CommandObjectThreadBacktrace(CommandInterpreter &interpreter)
+ : CommandObjectIterateOverThreads(
+ interpreter, "thread backtrace",
+ "Show thread call stacks. Defaults to the current thread, thread "
+ "indexes can be specified as arguments. Use the thread-index "
+ "\"all\" "
+ "to see all threads.",
+ nullptr,
+ eCommandRequiresProcess | eCommandRequiresThread |
+ eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
+ eCommandProcessMustBePaused),
+ m_options() {}
- ~CommandObjectThreadBacktrace() override = default;
+ ~CommandObjectThreadBacktrace() override = default;
- Options *
- GetOptions () override
- {
- return &m_options;
- }
+ Options *GetOptions() override { return &m_options; }
protected:
- void
- DoExtendedBacktrace (Thread *thread, CommandReturnObject &result)
- {
- SystemRuntime *runtime = thread->GetProcess()->GetSystemRuntime();
- if (runtime)
- {
- Stream &strm = result.GetOutputStream();
- const std::vector<ConstString> &types = runtime->GetExtendedBacktraceTypes();
- for (auto type : types)
- {
- ThreadSP ext_thread_sp = runtime->GetExtendedBacktraceThread (thread->shared_from_this(), type);
- if (ext_thread_sp && ext_thread_sp->IsValid ())
- {
- const uint32_t num_frames_with_source = 0;
- if (ext_thread_sp->GetStatus (strm,
- m_options.m_start,
- m_options.m_count,
- num_frames_with_source))
- {
- DoExtendedBacktrace (ext_thread_sp.get(), result);
- }
- }
- }
- }
+ void DoExtendedBacktrace(Thread *thread, CommandReturnObject &result) {
+ SystemRuntime *runtime = thread->GetProcess()->GetSystemRuntime();
+ if (runtime) {
+ Stream &strm = result.GetOutputStream();
+ const std::vector<ConstString> &types =
+ runtime->GetExtendedBacktraceTypes();
+ for (auto type : types) {
+ ThreadSP ext_thread_sp = runtime->GetExtendedBacktraceThread(
+ thread->shared_from_this(), type);
+ if (ext_thread_sp && ext_thread_sp->IsValid()) {
+ const uint32_t num_frames_with_source = 0;
+ if (ext_thread_sp->GetStatus(strm, m_options.m_start,
+ m_options.m_count,
+ num_frames_with_source)) {
+ DoExtendedBacktrace(ext_thread_sp.get(), result);
+ }
+ }
+ }
+ }
+ }
+
+ bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
+ ThreadSP thread_sp =
+ m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
+ if (!thread_sp) {
+ result.AppendErrorWithFormat(
+ "thread disappeared while computing backtraces: 0x%" PRIx64 "\n",
+ tid);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ Thread *thread = thread_sp.get();
+
+ Stream &strm = result.GetOutputStream();
+
+ // Don't show source context when doing backtraces.
+ const uint32_t num_frames_with_source = 0;
+
+ if (!thread->GetStatus(strm, m_options.m_start, m_options.m_count,
+ num_frames_with_source)) {
+ result.AppendErrorWithFormat(
+ "error displaying backtrace for thread: \"0x%4.4x\"\n",
+ thread->GetIndexID());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
}
-
- bool
- HandleOneThread (lldb::tid_t tid, CommandReturnObject &result) override
- {
- ThreadSP thread_sp = m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
- if (!thread_sp)
- {
- result.AppendErrorWithFormat ("thread disappeared while computing backtraces: 0x%" PRIx64 "\n", tid);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- Thread *thread = thread_sp.get();
-
- Stream &strm = result.GetOutputStream();
-
- // Don't show source context when doing backtraces.
- const uint32_t num_frames_with_source = 0;
-
- if (!thread->GetStatus (strm,
- m_options.m_start,
- m_options.m_count,
- num_frames_with_source))
- {
- result.AppendErrorWithFormat ("error displaying backtrace for thread: \"0x%4.4x\"\n", thread->GetIndexID());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- if (m_options.m_extended_backtrace)
- {
- DoExtendedBacktrace (thread, result);
- }
-
- return true;
+ if (m_options.m_extended_backtrace) {
+ DoExtendedBacktrace(thread, result);
}
- CommandOptions m_options;
+ return true;
+ }
+
+ CommandOptions m_options;
};
OptionDefinition
-CommandObjectThreadBacktrace::CommandOptions::g_option_table[] =
-{
- // clang-format off
+ CommandObjectThreadBacktrace::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "How many frames to display (-1 for all)"},
{LLDB_OPT_SET_1, false, "start", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFrameIndex, "Frame in which to start the backtrace"},
{LLDB_OPT_SET_1, false, "extended", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Show the extended backtrace, if available"},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
-enum StepScope
-{
- eStepScopeSource,
- eStepScopeInstruction
-};
+enum StepScope { eStepScopeSource, eStepScopeInstruction };
-class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed
-{
+class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed {
public:
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options()
- {
- // Keep default values of all options in one place: OptionParsingStarting ()
- OptionParsingStarting(nullptr);
- }
-
- ~CommandOptions() override = default;
-
- Error
- SetOptionValue (uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'a':
- {
- bool success;
- bool avoid_no_debug = Args::StringToBoolean (option_arg, true, &success);
- if (!success)
- error.SetErrorStringWithFormat("invalid boolean value for option '%c'", short_option);
- else
- {
- m_step_in_avoid_no_debug = avoid_no_debug ? eLazyBoolYes : eLazyBoolNo;
- }
- }
- break;
-
- case 'A':
- {
- bool success;
- bool avoid_no_debug = Args::StringToBoolean (option_arg, true, &success);
- if (!success)
- error.SetErrorStringWithFormat("invalid boolean value for option '%c'", short_option);
- else
- {
- m_step_out_avoid_no_debug = avoid_no_debug ? eLazyBoolYes : eLazyBoolNo;
- }
- }
- break;
-
- case 'c':
- m_step_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
- if (m_step_count == UINT32_MAX)
- error.SetErrorStringWithFormat ("invalid step count '%s'", option_arg);
- break;
-
- case 'C':
- m_class_name.clear();
- m_class_name.assign(option_arg);
- break;
-
- case 'm':
- {
- OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values;
- m_run_mode = (lldb::RunMode) Args::StringToOptionEnum(option_arg, enum_values, eOnlyDuringStepping, error);
- }
- break;
-
- case 'e':
- {
- if (strcmp(option_arg, "block") == 0)
- {
- m_end_line_is_block_end = 1;
- break;
- }
- uint32_t tmp_end_line = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
- if (tmp_end_line == UINT32_MAX)
- error.SetErrorStringWithFormat ("invalid end line number '%s'", option_arg);
- else
- m_end_line = tmp_end_line;
- break;
- }
- break;
-
- case 'r':
- m_avoid_regexp.clear();
- m_avoid_regexp.assign(option_arg);
- break;
-
- case 't':
- m_step_in_target.clear();
- m_step_in_target.assign(option_arg);
- break;
-
- default:
- error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
- break;
- }
- return error;
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options() {
+ // Keep default values of all options in one place: OptionParsingStarting
+ // ()
+ OptionParsingStarting(nullptr);
+ }
+
+ ~CommandOptions() override = default;
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option) {
+ case 'a': {
+ bool success;
+ bool avoid_no_debug = Args::StringToBoolean(option_arg, true, &success);
+ if (!success)
+ error.SetErrorStringWithFormat(
+ "invalid boolean value for option '%c'", short_option);
+ else {
+ m_step_in_avoid_no_debug =
+ avoid_no_debug ? eLazyBoolYes : eLazyBoolNo;
}
+ } break;
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_step_in_avoid_no_debug = eLazyBoolCalculate;
- m_step_out_avoid_no_debug = eLazyBoolCalculate;
- m_run_mode = eOnlyDuringStepping;
-
- // Check if we are in Non-Stop mode
- TargetSP target_sp =
- execution_context ? execution_context->GetTargetSP() :
- TargetSP();
- if (target_sp && target_sp->GetNonStopModeEnabled())
- m_run_mode = eOnlyThisThread;
-
- m_avoid_regexp.clear();
- m_step_in_target.clear();
- m_class_name.clear();
- m_step_count = 1;
- m_end_line = LLDB_INVALID_LINE_NUMBER;
- m_end_line_is_block_end = false;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
- LazyBool m_step_in_avoid_no_debug;
- LazyBool m_step_out_avoid_no_debug;
- RunMode m_run_mode;
- std::string m_avoid_regexp;
- std::string m_step_in_target;
- std::string m_class_name;
- uint32_t m_step_count;
- uint32_t m_end_line;
- bool m_end_line_is_block_end;
- };
-
- CommandObjectThreadStepWithTypeAndScope (CommandInterpreter &interpreter,
- const char *name,
- const char *help,
- const char *syntax,
- StepType step_type,
- StepScope step_scope) :
- CommandObjectParsed (interpreter, name, help, syntax,
- eCommandRequiresProcess |
- eCommandRequiresThread |
- eCommandTryTargetAPILock |
- eCommandProcessMustBeLaunched |
- eCommandProcessMustBePaused ),
- m_step_type (step_type),
- m_step_scope (step_scope),
- m_options()
- {
- CommandArgumentEntry arg;
- CommandArgumentData thread_id_arg;
-
- // Define the first (and only) variant of this arg.
- thread_id_arg.arg_type = eArgTypeThreadID;
- thread_id_arg.arg_repetition = eArgRepeatOptional;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (thread_id_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
- }
+ case 'A': {
+ bool success;
+ bool avoid_no_debug = Args::StringToBoolean(option_arg, true, &success);
+ if (!success)
+ error.SetErrorStringWithFormat(
+ "invalid boolean value for option '%c'", short_option);
+ else {
+ m_step_out_avoid_no_debug =
+ avoid_no_debug ? eLazyBoolYes : eLazyBoolNo;
+ }
+ } break;
+
+ case 'c':
+ m_step_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
+ if (m_step_count == UINT32_MAX)
+ error.SetErrorStringWithFormat("invalid step count '%s'", option_arg);
+ break;
+
+ case 'C':
+ m_class_name.clear();
+ m_class_name.assign(option_arg);
+ break;
+
+ case 'm': {
+ OptionEnumValueElement *enum_values =
+ g_option_table[option_idx].enum_values;
+ m_run_mode = (lldb::RunMode)Args::StringToOptionEnum(
+ option_arg, enum_values, eOnlyDuringStepping, error);
+ } break;
+
+ case 'e': {
+ if (strcmp(option_arg, "block") == 0) {
+ m_end_line_is_block_end = 1;
+ break;
+ }
+ uint32_t tmp_end_line =
+ StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
+ if (tmp_end_line == UINT32_MAX)
+ error.SetErrorStringWithFormat("invalid end line number '%s'",
+ option_arg);
+ else
+ m_end_line = tmp_end_line;
+ break;
+ } break;
+
+ case 'r':
+ m_avoid_regexp.clear();
+ m_avoid_regexp.assign(option_arg);
+ break;
+
+ case 't':
+ m_step_in_target.clear();
+ m_step_in_target.assign(option_arg);
+ break;
+
+ default:
+ error.SetErrorStringWithFormat("invalid short option character '%c'",
+ short_option);
+ break;
+ }
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_step_in_avoid_no_debug = eLazyBoolCalculate;
+ m_step_out_avoid_no_debug = eLazyBoolCalculate;
+ m_run_mode = eOnlyDuringStepping;
+
+ // Check if we are in Non-Stop mode
+ TargetSP target_sp =
+ execution_context ? execution_context->GetTargetSP() : TargetSP();
+ if (target_sp && target_sp->GetNonStopModeEnabled())
+ m_run_mode = eOnlyThisThread;
+
+ m_avoid_regexp.clear();
+ m_step_in_target.clear();
+ m_class_name.clear();
+ m_step_count = 1;
+ m_end_line = LLDB_INVALID_LINE_NUMBER;
+ m_end_line_is_block_end = false;
+ }
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+ LazyBool m_step_in_avoid_no_debug;
+ LazyBool m_step_out_avoid_no_debug;
+ RunMode m_run_mode;
+ std::string m_avoid_regexp;
+ std::string m_step_in_target;
+ std::string m_class_name;
+ uint32_t m_step_count;
+ uint32_t m_end_line;
+ bool m_end_line_is_block_end;
+ };
+
+ CommandObjectThreadStepWithTypeAndScope(CommandInterpreter &interpreter,
+ const char *name, const char *help,
+ const char *syntax,
+ StepType step_type,
+ StepScope step_scope)
+ : CommandObjectParsed(interpreter, name, help, syntax,
+ eCommandRequiresProcess | eCommandRequiresThread |
+ eCommandTryTargetAPILock |
+ eCommandProcessMustBeLaunched |
+ eCommandProcessMustBePaused),
+ m_step_type(step_type), m_step_scope(step_scope), m_options() {
+ CommandArgumentEntry arg;
+ CommandArgumentData thread_id_arg;
+
+ // Define the first (and only) variant of this arg.
+ thread_id_arg.arg_type = eArgTypeThreadID;
+ thread_id_arg.arg_repetition = eArgRepeatOptional;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(thread_id_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+ }
- ~CommandObjectThreadStepWithTypeAndScope() override = default;
+ ~CommandObjectThreadStepWithTypeAndScope() override = default;
- Options *
- GetOptions () override
- {
- return &m_options;
- }
+ Options *GetOptions() override { return &m_options; }
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Process *process = m_exe_ctx.GetProcessPtr();
- bool synchronous_execution = m_interpreter.GetSynchronous();
-
- const uint32_t num_threads = process->GetThreadList().GetSize();
- Thread *thread = nullptr;
-
- if (command.GetArgumentCount() == 0)
- {
- thread = GetDefaultThread();
-
- if (thread == nullptr)
- {
- result.AppendError ("no selected thread in process");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- else
- {
- const char *thread_idx_cstr = command.GetArgumentAtIndex(0);
- uint32_t step_thread_idx = StringConvert::ToUInt32 (thread_idx_cstr, LLDB_INVALID_INDEX32);
- if (step_thread_idx == LLDB_INVALID_INDEX32)
- {
- result.AppendErrorWithFormat ("invalid thread index '%s'.\n", thread_idx_cstr);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- thread = process->GetThreadList().FindThreadByIndexID(step_thread_idx).get();
- if (thread == nullptr)
- {
- result.AppendErrorWithFormat ("Thread index %u is out of range (valid values are 0 - %u).\n",
- step_thread_idx, num_threads);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
-
- if (m_step_type == eStepTypeScripted)
- {
- if (m_options.m_class_name.empty())
- {
- result.AppendErrorWithFormat ("empty class name for scripted step.");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- else if (!m_interpreter.GetScriptInterpreter()->CheckObjectExists(m_options.m_class_name.c_str()))
- {
- result.AppendErrorWithFormat ("class for scripted step: \"%s\" does not exist.", m_options.m_class_name.c_str());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
-
- if (m_options.m_end_line != LLDB_INVALID_LINE_NUMBER
- && m_step_type != eStepTypeInto)
- {
- result.AppendErrorWithFormat("end line option is only valid for step into");
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Process *process = m_exe_ctx.GetProcessPtr();
+ bool synchronous_execution = m_interpreter.GetSynchronous();
+
+ const uint32_t num_threads = process->GetThreadList().GetSize();
+ Thread *thread = nullptr;
+
+ if (command.GetArgumentCount() == 0) {
+ thread = GetDefaultThread();
+
+ if (thread == nullptr) {
+ result.AppendError("no selected thread in process");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ } else {
+ const char *thread_idx_cstr = command.GetArgumentAtIndex(0);
+ uint32_t step_thread_idx =
+ StringConvert::ToUInt32(thread_idx_cstr, LLDB_INVALID_INDEX32);
+ if (step_thread_idx == LLDB_INVALID_INDEX32) {
+ result.AppendErrorWithFormat("invalid thread index '%s'.\n",
+ thread_idx_cstr);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ thread =
+ process->GetThreadList().FindThreadByIndexID(step_thread_idx).get();
+ if (thread == nullptr) {
+ result.AppendErrorWithFormat(
+ "Thread index %u is out of range (valid values are 0 - %u).\n",
+ step_thread_idx, num_threads);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+
+ if (m_step_type == eStepTypeScripted) {
+ if (m_options.m_class_name.empty()) {
+ result.AppendErrorWithFormat("empty class name for scripted step.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ } else if (!m_interpreter.GetScriptInterpreter()->CheckObjectExists(
+ m_options.m_class_name.c_str())) {
+ result.AppendErrorWithFormat(
+ "class for scripted step: \"%s\" does not exist.",
+ m_options.m_class_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+
+ if (m_options.m_end_line != LLDB_INVALID_LINE_NUMBER &&
+ m_step_type != eStepTypeInto) {
+ result.AppendErrorWithFormat(
+ "end line option is only valid for step into");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ const bool abort_other_plans = false;
+ const lldb::RunMode stop_other_threads = m_options.m_run_mode;
+
+ // This is a bit unfortunate, but not all the commands in this command
+ // object support
+ // only while stepping, so I use the bool for them.
+ bool bool_stop_other_threads;
+ if (m_options.m_run_mode == eAllThreads)
+ bool_stop_other_threads = false;
+ else if (m_options.m_run_mode == eOnlyDuringStepping)
+ bool_stop_other_threads =
+ (m_step_type != eStepTypeOut && m_step_type != eStepTypeScripted);
+ else
+ bool_stop_other_threads = true;
+
+ ThreadPlanSP new_plan_sp;
+
+ if (m_step_type == eStepTypeInto) {
+ StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
+ assert(frame != nullptr);
+
+ if (frame->HasDebugInformation()) {
+ AddressRange range;
+ SymbolContext sc = frame->GetSymbolContext(eSymbolContextEverything);
+ if (m_options.m_end_line != LLDB_INVALID_LINE_NUMBER) {
+ Error error;
+ if (!sc.GetAddressRangeFromHereToEndLine(m_options.m_end_line, range,
+ error)) {
+ result.AppendErrorWithFormat("invalid end-line option: %s.",
+ error.AsCString());
result.SetStatus(eReturnStatusFailed);
return false;
- }
-
- const bool abort_other_plans = false;
- const lldb::RunMode stop_other_threads = m_options.m_run_mode;
-
- // This is a bit unfortunate, but not all the commands in this command object support
- // only while stepping, so I use the bool for them.
- bool bool_stop_other_threads;
- if (m_options.m_run_mode == eAllThreads)
- bool_stop_other_threads = false;
- else if (m_options.m_run_mode == eOnlyDuringStepping)
- bool_stop_other_threads = (m_step_type != eStepTypeOut && m_step_type != eStepTypeScripted);
- else
- bool_stop_other_threads = true;
-
- ThreadPlanSP new_plan_sp;
-
- if (m_step_type == eStepTypeInto)
- {
- StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
- assert(frame != nullptr);
-
- if (frame->HasDebugInformation ())
- {
- AddressRange range;
- SymbolContext sc = frame->GetSymbolContext(eSymbolContextEverything);
- if (m_options.m_end_line != LLDB_INVALID_LINE_NUMBER)
- {
- Error error;
- if (!sc.GetAddressRangeFromHereToEndLine(m_options.m_end_line, range, error))
- {
- result.AppendErrorWithFormat("invalid end-line option: %s.", error.AsCString());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
- else if (m_options.m_end_line_is_block_end)
- {
- Error error;
- Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
- if (!block)
- {
- result.AppendErrorWithFormat("Could not find the current block.");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- AddressRange block_range;
- Address pc_address = frame->GetFrameCodeAddress();
- block->GetRangeContainingAddress(pc_address, block_range);
- if (!block_range.GetBaseAddress().IsValid())
- {
- result.AppendErrorWithFormat("Could not find the current block address.");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- lldb::addr_t pc_offset_in_block = pc_address.GetFileAddress() - block_range.GetBaseAddress().GetFileAddress();
- lldb::addr_t range_length = block_range.GetByteSize() - pc_offset_in_block;
- range = AddressRange(pc_address, range_length);
- }
- else
- {
- range = sc.line_entry.range;
- }
-
- new_plan_sp = thread->QueueThreadPlanForStepInRange (abort_other_plans,
- range,
- frame->GetSymbolContext(eSymbolContextEverything),
- m_options.m_step_in_target.c_str(),
- stop_other_threads,
- m_options.m_step_in_avoid_no_debug,
- m_options.m_step_out_avoid_no_debug);
-
- if (new_plan_sp && !m_options.m_avoid_regexp.empty())
- {
- ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (new_plan_sp.get());
- step_in_range_plan->SetAvoidRegexp(m_options.m_avoid_regexp.c_str());
- }
- }
- else
- new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (false, abort_other_plans, bool_stop_other_threads);
- }
- else if (m_step_type == eStepTypeOver)
- {
- StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
-
- if (frame->HasDebugInformation())
- new_plan_sp = thread->QueueThreadPlanForStepOverRange (abort_other_plans,
- frame->GetSymbolContext(eSymbolContextEverything).line_entry,
- frame->GetSymbolContext(eSymbolContextEverything),
- stop_other_threads,
- m_options.m_step_out_avoid_no_debug);
- else
- new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (true,
- abort_other_plans,
- bool_stop_other_threads);
- }
- else if (m_step_type == eStepTypeTrace)
- {
- new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (false, abort_other_plans, bool_stop_other_threads);
- }
- else if (m_step_type == eStepTypeTraceOver)
- {
- new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (true, abort_other_plans, bool_stop_other_threads);
- }
- else if (m_step_type == eStepTypeOut)
- {
- new_plan_sp = thread->QueueThreadPlanForStepOut(abort_other_plans,
- nullptr,
- false,
- bool_stop_other_threads,
- eVoteYes,
- eVoteNoOpinion,
- thread->GetSelectedFrameIndex(),
- m_options.m_step_out_avoid_no_debug);
- }
- else if (m_step_type == eStepTypeScripted)
- {
- new_plan_sp = thread->QueueThreadPlanForStepScripted (abort_other_plans,
- m_options.m_class_name.c_str(),
- bool_stop_other_threads);
- }
- else
- {
- result.AppendError ("step type is not supported");
- result.SetStatus (eReturnStatusFailed);
+ }
+ } else if (m_options.m_end_line_is_block_end) {
+ Error error;
+ Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
+ if (!block) {
+ result.AppendErrorWithFormat("Could not find the current block.");
+ result.SetStatus(eReturnStatusFailed);
return false;
- }
-
- // If we got a new plan, then set it to be a master plan (User level Plans should be master plans
- // so that they can be interruptible). Then resume the process.
-
- if (new_plan_sp)
- {
- new_plan_sp->SetIsMasterPlan (true);
- new_plan_sp->SetOkayToDiscard (false);
-
- if (m_options.m_step_count > 1)
- {
- if (new_plan_sp->SetIterationCount(m_options.m_step_count))
- {
- result.AppendWarning ("step operation does not support iteration count.");
- }
- }
-
- process->GetThreadList().SetSelectedThreadByID (thread->GetID());
-
- const uint32_t iohandler_id = process->GetIOHandlerID();
+ }
- StreamString stream;
- Error error;
- if (synchronous_execution)
- error = process->ResumeSynchronous (&stream);
- else
- error = process->Resume ();
-
- // There is a race condition where this thread will return up the call stack to the main command handler
- // and show an (lldb) prompt before HandlePrivateEvent (from PrivateStateThread) has
- // a chance to call PushProcessIOHandler().
- process->SyncIOHandler(iohandler_id, 2000);
-
- if (synchronous_execution)
- {
- // If any state changed events had anything to say, add that to the result
- if (stream.GetData())
- result.AppendMessage(stream.GetData());
-
- process->GetThreadList().SetSelectedThreadByID (thread->GetID());
- result.SetDidChangeProcessState (true);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- result.SetStatus (eReturnStatusSuccessContinuingNoResult);
- }
- }
- else
- {
- result.AppendError ("Couldn't find thread plan to implement step type.");
- result.SetStatus (eReturnStatusFailed);
- }
- return result.Succeeded();
+ AddressRange block_range;
+ Address pc_address = frame->GetFrameCodeAddress();
+ block->GetRangeContainingAddress(pc_address, block_range);
+ if (!block_range.GetBaseAddress().IsValid()) {
+ result.AppendErrorWithFormat(
+ "Could not find the current block address.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ lldb::addr_t pc_offset_in_block =
+ pc_address.GetFileAddress() -
+ block_range.GetBaseAddress().GetFileAddress();
+ lldb::addr_t range_length =
+ block_range.GetByteSize() - pc_offset_in_block;
+ range = AddressRange(pc_address, range_length);
+ } else {
+ range = sc.line_entry.range;
+ }
+
+ new_plan_sp = thread->QueueThreadPlanForStepInRange(
+ abort_other_plans, range,
+ frame->GetSymbolContext(eSymbolContextEverything),
+ m_options.m_step_in_target.c_str(), stop_other_threads,
+ m_options.m_step_in_avoid_no_debug,
+ m_options.m_step_out_avoid_no_debug);
+
+ if (new_plan_sp && !m_options.m_avoid_regexp.empty()) {
+ ThreadPlanStepInRange *step_in_range_plan =
+ static_cast<ThreadPlanStepInRange *>(new_plan_sp.get());
+ step_in_range_plan->SetAvoidRegexp(m_options.m_avoid_regexp.c_str());
+ }
+ } else
+ new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
+ false, abort_other_plans, bool_stop_other_threads);
+ } else if (m_step_type == eStepTypeOver) {
+ StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
+
+ if (frame->HasDebugInformation())
+ new_plan_sp = thread->QueueThreadPlanForStepOverRange(
+ abort_other_plans,
+ frame->GetSymbolContext(eSymbolContextEverything).line_entry,
+ frame->GetSymbolContext(eSymbolContextEverything),
+ stop_other_threads, m_options.m_step_out_avoid_no_debug);
+ else
+ new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
+ true, abort_other_plans, bool_stop_other_threads);
+ } else if (m_step_type == eStepTypeTrace) {
+ new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
+ false, abort_other_plans, bool_stop_other_threads);
+ } else if (m_step_type == eStepTypeTraceOver) {
+ new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
+ true, abort_other_plans, bool_stop_other_threads);
+ } else if (m_step_type == eStepTypeOut) {
+ new_plan_sp = thread->QueueThreadPlanForStepOut(
+ abort_other_plans, nullptr, false, bool_stop_other_threads, eVoteYes,
+ eVoteNoOpinion, thread->GetSelectedFrameIndex(),
+ m_options.m_step_out_avoid_no_debug);
+ } else if (m_step_type == eStepTypeScripted) {
+ new_plan_sp = thread->QueueThreadPlanForStepScripted(
+ abort_other_plans, m_options.m_class_name.c_str(),
+ bool_stop_other_threads);
+ } else {
+ result.AppendError("step type is not supported");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ // If we got a new plan, then set it to be a master plan (User level Plans
+ // should be master plans
+ // so that they can be interruptible). Then resume the process.
+
+ if (new_plan_sp) {
+ new_plan_sp->SetIsMasterPlan(true);
+ new_plan_sp->SetOkayToDiscard(false);
+
+ if (m_options.m_step_count > 1) {
+ if (new_plan_sp->SetIterationCount(m_options.m_step_count)) {
+ result.AppendWarning(
+ "step operation does not support iteration count.");
+ }
+ }
+
+ process->GetThreadList().SetSelectedThreadByID(thread->GetID());
+
+ const uint32_t iohandler_id = process->GetIOHandlerID();
+
+ StreamString stream;
+ Error error;
+ if (synchronous_execution)
+ error = process->ResumeSynchronous(&stream);
+ else
+ error = process->Resume();
+
+ // There is a race condition where this thread will return up the call
+ // stack to the main command handler
+ // and show an (lldb) prompt before HandlePrivateEvent (from
+ // PrivateStateThread) has
+ // a chance to call PushProcessIOHandler().
+ process->SyncIOHandler(iohandler_id, 2000);
+
+ if (synchronous_execution) {
+ // If any state changed events had anything to say, add that to the
+ // result
+ if (stream.GetData())
+ result.AppendMessage(stream.GetData());
+
+ process->GetThreadList().SetSelectedThreadByID(thread->GetID());
+ result.SetDidChangeProcessState(true);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ } else {
+ result.SetStatus(eReturnStatusSuccessContinuingNoResult);
+ }
+ } else {
+ result.AppendError("Couldn't find thread plan to implement step type.");
+ result.SetStatus(eReturnStatusFailed);
}
+ return result.Succeeded();
+ }
protected:
- StepType m_step_type;
- StepScope m_step_scope;
- CommandOptions m_options;
-};
-
-static 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"},
-{ 0, nullptr, nullptr }
-};
-
-static OptionEnumValueElement
-g_duo_running_mode[] =
-{
-{ eOnlyThisThread, "this-thread", "Run only this thread"},
-{ eAllThreads, "all-threads", "Run all threads"},
-{ 0, nullptr, nullptr }
-};
-
-OptionDefinition
-CommandObjectThreadStepWithTypeAndScope::CommandOptions::g_option_table[] =
-{
- // clang-format off
+ StepType m_step_type;
+ StepScope m_step_scope;
+ CommandOptions m_options;
+};
+
+static 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"},
+ {0, nullptr, nullptr}};
+
+static OptionEnumValueElement g_duo_running_mode[] = {
+ {eOnlyThisThread, "this-thread", "Run only this thread"},
+ {eAllThreads, "all-threads", "Run all threads"},
+ {0, nullptr, nullptr}};
+
+OptionDefinition CommandObjectThreadStepWithTypeAndScope::CommandOptions::
+ g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_1, false, "step-in-avoids-no-debug", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "A boolean value that sets whether stepping into functions will step over functions with no debug information."},
{LLDB_OPT_SET_1, false, "step-out-avoids-no-debug", 'A', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "A boolean value, if true stepping out of functions will continue to step out till it hits a function with debug information."},
{LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 1, eArgTypeCount, "How many times to perform the stepping operation - currently only supported for step-inst and next-inst."},
@@ -797,1167 +710,1045 @@ CommandObjectThreadStepWithTypeAndScope:
{LLDB_OPT_SET_1, false, "step-in-target", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFunctionName, "The name of the directly called function step in should stop at when stepping into."},
{LLDB_OPT_SET_2, false, "python-class", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonClass, "The name of the class that will manage this step - only supported for Scripted Step."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
//-------------------------------------------------------------------------
// CommandObjectThreadContinue
//-------------------------------------------------------------------------
-class CommandObjectThreadContinue : public CommandObjectParsed
-{
+class CommandObjectThreadContinue : public CommandObjectParsed {
public:
- CommandObjectThreadContinue(CommandInterpreter &interpreter)
- : CommandObjectParsed(interpreter, "thread continue", "Continue execution of the current target process. One "
- "or more threads may be specified, by default all "
- "threads continue.",
- nullptr, eCommandRequiresThread | eCommandTryTargetAPILock |
- eCommandProcessMustBeLaunched | eCommandProcessMustBePaused)
- {
- CommandArgumentEntry arg;
- CommandArgumentData thread_idx_arg;
-
- // Define the first (and only) variant of this arg.
- thread_idx_arg.arg_type = eArgTypeThreadIndex;
- thread_idx_arg.arg_repetition = eArgRepeatPlus;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (thread_idx_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
- }
-
- ~CommandObjectThreadContinue() override = default;
-
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- bool synchronous_execution = m_interpreter.GetSynchronous ();
-
- if (!m_interpreter.GetDebugger().GetSelectedTarget())
- {
- result.AppendError ("invalid target, create a debug target using the 'target create' command");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- Process *process = m_exe_ctx.GetProcessPtr();
- if (process == nullptr)
- {
- result.AppendError ("no process exists. Cannot continue");
- result.SetStatus (eReturnStatusFailed);
+ CommandObjectThreadContinue(CommandInterpreter &interpreter)
+ : CommandObjectParsed(
+ interpreter, "thread continue",
+ "Continue execution of the current target process. One "
+ "or more threads may be specified, by default all "
+ "threads continue.",
+ nullptr,
+ eCommandRequiresThread | eCommandTryTargetAPILock |
+ eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
+ CommandArgumentEntry arg;
+ CommandArgumentData thread_idx_arg;
+
+ // Define the first (and only) variant of this arg.
+ thread_idx_arg.arg_type = eArgTypeThreadIndex;
+ thread_idx_arg.arg_repetition = eArgRepeatPlus;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(thread_idx_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+ }
+
+ ~CommandObjectThreadContinue() override = default;
+
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ bool synchronous_execution = m_interpreter.GetSynchronous();
+
+ if (!m_interpreter.GetDebugger().GetSelectedTarget()) {
+ result.AppendError("invalid target, create a debug target using the "
+ "'target create' command");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ Process *process = m_exe_ctx.GetProcessPtr();
+ if (process == nullptr) {
+ result.AppendError("no process exists. Cannot continue");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ StateType state = process->GetState();
+ if ((state == eStateCrashed) || (state == eStateStopped) ||
+ (state == eStateSuspended)) {
+ const size_t argc = command.GetArgumentCount();
+ if (argc > 0) {
+ // These two lines appear at the beginning of both blocks in
+ // this if..else, but that is because we need to release the
+ // lock before calling process->Resume below.
+ std::lock_guard<std::recursive_mutex> guard(
+ process->GetThreadList().GetMutex());
+ const uint32_t num_threads = process->GetThreadList().GetSize();
+ std::vector<Thread *> resume_threads;
+ for (uint32_t i = 0; i < argc; ++i) {
+ bool success;
+ const int base = 0;
+ uint32_t thread_idx =
+ StringConvert::ToUInt32(command.GetArgumentAtIndex(i),
+ LLDB_INVALID_INDEX32, base, &success);
+ if (success) {
+ Thread *thread =
+ process->GetThreadList().FindThreadByIndexID(thread_idx).get();
+
+ if (thread) {
+ resume_threads.push_back(thread);
+ } else {
+ result.AppendErrorWithFormat("invalid thread index %u.\n",
+ thread_idx);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ } else {
+ result.AppendErrorWithFormat(
+ "invalid thread index argument: \"%s\".\n",
+ command.GetArgumentAtIndex(i));
+ result.SetStatus(eReturnStatusFailed);
return false;
+ }
}
- StateType state = process->GetState();
- if ((state == eStateCrashed) || (state == eStateStopped) || (state == eStateSuspended))
- {
- const size_t argc = command.GetArgumentCount();
- if (argc > 0)
- {
- // These two lines appear at the beginning of both blocks in
- // this if..else, but that is because we need to release the
- // lock before calling process->Resume below.
- std::lock_guard<std::recursive_mutex> guard(process->GetThreadList().GetMutex());
- const uint32_t num_threads = process->GetThreadList().GetSize();
- std::vector<Thread *> resume_threads;
- for (uint32_t i = 0; i < argc; ++i)
- {
- bool success;
- const int base = 0;
- uint32_t thread_idx = StringConvert::ToUInt32 (command.GetArgumentAtIndex(i), LLDB_INVALID_INDEX32, base, &success);
- if (success)
- {
- Thread *thread = process->GetThreadList().FindThreadByIndexID(thread_idx).get();
-
- if (thread)
- {
- resume_threads.push_back(thread);
- }
- else
- {
- result.AppendErrorWithFormat("invalid thread index %u.\n", thread_idx);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- else
- {
- result.AppendErrorWithFormat ("invalid thread index argument: \"%s\".\n", command.GetArgumentAtIndex(i));
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
-
- if (resume_threads.empty())
- {
- result.AppendError ("no valid thread indexes were specified");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- else
- {
- if (resume_threads.size() == 1)
- result.AppendMessageWithFormat ("Resuming thread: ");
- else
- result.AppendMessageWithFormat ("Resuming threads: ");
-
- for (uint32_t idx = 0; idx < num_threads; ++idx)
- {
- Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get();
- std::vector<Thread *>::iterator this_thread_pos = find(resume_threads.begin(), resume_threads.end(), thread);
-
- if (this_thread_pos != resume_threads.end())
- {
- resume_threads.erase(this_thread_pos);
- if (!resume_threads.empty())
- result.AppendMessageWithFormat ("%u, ", thread->GetIndexID());
- else
- result.AppendMessageWithFormat ("%u ", thread->GetIndexID());
-
- const bool override_suspend = true;
- thread->SetResumeState (eStateRunning, override_suspend);
- }
- else
- {
- thread->SetResumeState (eStateSuspended);
- }
- }
- result.AppendMessageWithFormat ("in process %" PRIu64 "\n", process->GetID());
- }
- }
- else
- {
- // These two lines appear at the beginning of both blocks in
- // this if..else, but that is because we need to release the
- // lock before calling process->Resume below.
- std::lock_guard<std::recursive_mutex> guard(process->GetThreadList().GetMutex());
- const uint32_t num_threads = process->GetThreadList().GetSize();
- Thread *current_thread = GetDefaultThread();
- if (current_thread == nullptr)
- {
- result.AppendError ("the process doesn't have a current thread");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- // Set the actions that the threads should each take when resuming
- for (uint32_t idx = 0; idx < num_threads; ++idx)
- {
- Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get();
- if (thread == current_thread)
- {
- result.AppendMessageWithFormat ("Resuming thread 0x%4.4" PRIx64 " in process %" PRIu64 "\n", thread->GetID(), process->GetID());
- const bool override_suspend = true;
- thread->SetResumeState (eStateRunning, override_suspend);
- }
- else
- {
- thread->SetResumeState (eStateSuspended);
- }
- }
- }
-
- StreamString stream;
- Error error;
- if (synchronous_execution)
- error = process->ResumeSynchronous (&stream);
- else
- error = process->Resume ();
-
- // We should not be holding the thread list lock when we do this.
- if (error.Success())
- {
- result.AppendMessageWithFormat ("Process %" PRIu64 " resuming\n", process->GetID());
- if (synchronous_execution)
- {
- // If any state changed events had anything to say, add that to the result
- if (stream.GetData())
- result.AppendMessage(stream.GetData());
-
- result.SetDidChangeProcessState (true);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- result.SetStatus (eReturnStatusSuccessContinuingNoResult);
- }
- }
- else
- {
- result.AppendErrorWithFormat("Failed to resume process: %s\n", error.AsCString());
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- result.AppendErrorWithFormat ("Process cannot be continued from its current state (%s).\n",
- StateAsCString(state));
- result.SetStatus (eReturnStatusFailed);
- }
-
- return result.Succeeded();
+ if (resume_threads.empty()) {
+ result.AppendError("no valid thread indexes were specified");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ } else {
+ if (resume_threads.size() == 1)
+ result.AppendMessageWithFormat("Resuming thread: ");
+ else
+ result.AppendMessageWithFormat("Resuming threads: ");
+
+ for (uint32_t idx = 0; idx < num_threads; ++idx) {
+ Thread *thread =
+ process->GetThreadList().GetThreadAtIndex(idx).get();
+ std::vector<Thread *>::iterator this_thread_pos =
+ find(resume_threads.begin(), resume_threads.end(), thread);
+
+ if (this_thread_pos != resume_threads.end()) {
+ resume_threads.erase(this_thread_pos);
+ if (!resume_threads.empty())
+ result.AppendMessageWithFormat("%u, ", thread->GetIndexID());
+ else
+ result.AppendMessageWithFormat("%u ", thread->GetIndexID());
+
+ const bool override_suspend = true;
+ thread->SetResumeState(eStateRunning, override_suspend);
+ } else {
+ thread->SetResumeState(eStateSuspended);
+ }
+ }
+ result.AppendMessageWithFormat("in process %" PRIu64 "\n",
+ process->GetID());
+ }
+ } else {
+ // These two lines appear at the beginning of both blocks in
+ // this if..else, but that is because we need to release the
+ // lock before calling process->Resume below.
+ std::lock_guard<std::recursive_mutex> guard(
+ process->GetThreadList().GetMutex());
+ const uint32_t num_threads = process->GetThreadList().GetSize();
+ Thread *current_thread = GetDefaultThread();
+ if (current_thread == nullptr) {
+ result.AppendError("the process doesn't have a current thread");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ // Set the actions that the threads should each take when resuming
+ for (uint32_t idx = 0; idx < num_threads; ++idx) {
+ Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get();
+ if (thread == current_thread) {
+ result.AppendMessageWithFormat("Resuming thread 0x%4.4" PRIx64
+ " in process %" PRIu64 "\n",
+ thread->GetID(), process->GetID());
+ const bool override_suspend = true;
+ thread->SetResumeState(eStateRunning, override_suspend);
+ } else {
+ thread->SetResumeState(eStateSuspended);
+ }
+ }
+ }
+
+ StreamString stream;
+ Error error;
+ if (synchronous_execution)
+ error = process->ResumeSynchronous(&stream);
+ else
+ error = process->Resume();
+
+ // We should not be holding the thread list lock when we do this.
+ if (error.Success()) {
+ result.AppendMessageWithFormat("Process %" PRIu64 " resuming\n",
+ process->GetID());
+ if (synchronous_execution) {
+ // If any state changed events had anything to say, add that to the
+ // result
+ if (stream.GetData())
+ result.AppendMessage(stream.GetData());
+
+ result.SetDidChangeProcessState(true);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ } else {
+ result.SetStatus(eReturnStatusSuccessContinuingNoResult);
+ }
+ } else {
+ result.AppendErrorWithFormat("Failed to resume process: %s\n",
+ error.AsCString());
+ result.SetStatus(eReturnStatusFailed);
+ }
+ } else {
+ result.AppendErrorWithFormat(
+ "Process cannot be continued from its current state (%s).\n",
+ StateAsCString(state));
+ result.SetStatus(eReturnStatusFailed);
}
+
+ return result.Succeeded();
+ }
};
//-------------------------------------------------------------------------
// CommandObjectThreadUntil
//-------------------------------------------------------------------------
-class CommandObjectThreadUntil : public CommandObjectParsed
-{
+class CommandObjectThreadUntil : public CommandObjectParsed {
public:
- class CommandOptions : public Options
- {
- public:
- uint32_t m_thread_idx;
- uint32_t m_frame_idx;
-
- CommandOptions() :
- Options(),
- m_thread_idx(LLDB_INVALID_THREAD_ID),
- m_frame_idx(LLDB_INVALID_FRAME_ID)
- {
- // Keep default values of all options in one place: OptionParsingStarting ()
- OptionParsingStarting(nullptr);
- }
-
- ~CommandOptions() override = default;
-
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'a':
- {
- lldb::addr_t tmp_addr =
- Args::StringToAddress(execution_context, option_arg,
- LLDB_INVALID_ADDRESS, &error);
- if (error.Success())
- m_until_addrs.push_back(tmp_addr);
- }
- break;
- case 't':
- m_thread_idx = StringConvert::ToUInt32 (option_arg, LLDB_INVALID_INDEX32);
- if (m_thread_idx == LLDB_INVALID_INDEX32)
- {
- error.SetErrorStringWithFormat ("invalid thread index '%s'", option_arg);
- }
- break;
- case 'f':
- m_frame_idx = StringConvert::ToUInt32 (option_arg, LLDB_INVALID_FRAME_ID);
- if (m_frame_idx == LLDB_INVALID_FRAME_ID)
- {
- error.SetErrorStringWithFormat ("invalid frame index '%s'", option_arg);
- }
- break;
- case 'm':
- {
- OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values;
- lldb::RunMode run_mode = (lldb::RunMode) Args::StringToOptionEnum(option_arg, enum_values, eOnlyDuringStepping, error);
-
- if (error.Success())
- {
- if (run_mode == eAllThreads)
- m_stop_others = false;
- else
- m_stop_others = true;
- }
- }
- break;
- default:
- error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
- break;
- }
- return error;
- }
+ class CommandOptions : public Options {
+ public:
+ uint32_t m_thread_idx;
+ uint32_t m_frame_idx;
+
+ CommandOptions()
+ : Options(), m_thread_idx(LLDB_INVALID_THREAD_ID),
+ m_frame_idx(LLDB_INVALID_FRAME_ID) {
+ // Keep default values of all options in one place: OptionParsingStarting
+ // ()
+ OptionParsingStarting(nullptr);
+ }
+
+ ~CommandOptions() override = default;
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option) {
+ case 'a': {
+ lldb::addr_t tmp_addr = Args::StringToAddress(
+ execution_context, option_arg, LLDB_INVALID_ADDRESS, &error);
+ if (error.Success())
+ m_until_addrs.push_back(tmp_addr);
+ } break;
+ case 't':
+ m_thread_idx =
+ StringConvert::ToUInt32(option_arg, LLDB_INVALID_INDEX32);
+ if (m_thread_idx == LLDB_INVALID_INDEX32) {
+ error.SetErrorStringWithFormat("invalid thread index '%s'",
+ option_arg);
+ }
+ break;
+ case 'f':
+ m_frame_idx =
+ StringConvert::ToUInt32(option_arg, LLDB_INVALID_FRAME_ID);
+ if (m_frame_idx == LLDB_INVALID_FRAME_ID) {
+ error.SetErrorStringWithFormat("invalid frame index '%s'",
+ option_arg);
+ }
+ break;
+ case 'm': {
+ OptionEnumValueElement *enum_values =
+ g_option_table[option_idx].enum_values;
+ lldb::RunMode run_mode = (lldb::RunMode)Args::StringToOptionEnum(
+ option_arg, enum_values, eOnlyDuringStepping, error);
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_thread_idx = LLDB_INVALID_THREAD_ID;
- m_frame_idx = 0;
+ if (error.Success()) {
+ if (run_mode == eAllThreads)
m_stop_others = false;
- m_until_addrs.clear();
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
+ else
+ m_stop_others = true;
}
+ } break;
+ default:
+ error.SetErrorStringWithFormat("invalid short option character '%c'",
+ short_option);
+ break;
+ }
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_thread_idx = LLDB_INVALID_THREAD_ID;
+ m_frame_idx = 0;
+ m_stop_others = false;
+ m_until_addrs.clear();
+ }
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ uint32_t m_step_thread_idx;
+ bool m_stop_others;
+ std::vector<lldb::addr_t> m_until_addrs;
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+ };
+
+ CommandObjectThreadUntil(CommandInterpreter &interpreter)
+ : CommandObjectParsed(
+ interpreter, "thread until",
+ "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.",
+ nullptr,
+ eCommandRequiresThread | eCommandTryTargetAPILock |
+ eCommandProcessMustBeLaunched | eCommandProcessMustBePaused),
+ m_options() {
+ CommandArgumentEntry arg;
+ CommandArgumentData line_num_arg;
+
+ // Define the first (and only) variant of this arg.
+ line_num_arg.arg_type = eArgTypeLineNum;
+ line_num_arg.arg_repetition = eArgRepeatPlain;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(line_num_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+ }
- uint32_t m_step_thread_idx;
- bool m_stop_others;
- std::vector<lldb::addr_t> m_until_addrs;
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
+ ~CommandObjectThreadUntil() override = default;
- // Instance variables to hold the values for command options.
- };
-
- CommandObjectThreadUntil(CommandInterpreter &interpreter)
- : CommandObjectParsed(interpreter, "thread until", "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.",
- nullptr, eCommandRequiresThread | eCommandTryTargetAPILock |
- eCommandProcessMustBeLaunched | eCommandProcessMustBePaused),
- m_options()
- {
- CommandArgumentEntry arg;
- CommandArgumentData line_num_arg;
-
- // Define the first (and only) variant of this arg.
- line_num_arg.arg_type = eArgTypeLineNum;
- line_num_arg.arg_repetition = eArgRepeatPlain;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (line_num_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
- }
-
- ~CommandObjectThreadUntil() override = default;
-
- Options *
- GetOptions () override
- {
- return &m_options;
- }
+ Options *GetOptions() override { return &m_options; }
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- bool synchronous_execution = m_interpreter.GetSynchronous ();
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ bool synchronous_execution = m_interpreter.GetSynchronous();
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (target == nullptr)
- {
- result.AppendError ("invalid target, create a debug target using the 'target create' command");
- result.SetStatus (eReturnStatusFailed);
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target == nullptr) {
+ result.AppendError("invalid target, create a debug target using the "
+ "'target create' command");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ Process *process = m_exe_ctx.GetProcessPtr();
+ if (process == nullptr) {
+ result.AppendError("need a valid process to step");
+ result.SetStatus(eReturnStatusFailed);
+ } else {
+ Thread *thread = nullptr;
+ std::vector<uint32_t> line_numbers;
+
+ if (command.GetArgumentCount() >= 1) {
+ size_t num_args = command.GetArgumentCount();
+ for (size_t i = 0; i < num_args; i++) {
+ uint32_t line_number;
+ line_number = StringConvert::ToUInt32(command.GetArgumentAtIndex(0),
+ UINT32_MAX);
+ if (line_number == UINT32_MAX) {
+ result.AppendErrorWithFormat("invalid line number: '%s'.\n",
+ command.GetArgumentAtIndex(0));
+ result.SetStatus(eReturnStatusFailed);
return false;
+ } else
+ line_numbers.push_back(line_number);
}
+ } else if (m_options.m_until_addrs.empty()) {
+ result.AppendErrorWithFormat("No line number or address provided:\n%s",
+ GetSyntax());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (m_options.m_thread_idx == LLDB_INVALID_THREAD_ID) {
+ thread = GetDefaultThread();
+ } else {
+ thread = process->GetThreadList()
+ .FindThreadByIndexID(m_options.m_thread_idx)
+ .get();
+ }
- Process *process = m_exe_ctx.GetProcessPtr();
- if (process == nullptr)
- {
- result.AppendError ("need a valid process to step");
- result.SetStatus (eReturnStatusFailed);
- }
- else
- {
- Thread *thread = nullptr;
- std::vector<uint32_t> line_numbers;
-
- if (command.GetArgumentCount() >= 1)
- {
- size_t num_args = command.GetArgumentCount();
- for (size_t i = 0; i < num_args; i++)
- {
- uint32_t line_number;
- line_number = StringConvert::ToUInt32 (command.GetArgumentAtIndex(0), UINT32_MAX);
- if (line_number == UINT32_MAX)
- {
- result.AppendErrorWithFormat ("invalid line number: '%s'.\n", command.GetArgumentAtIndex(0));
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- else
- line_numbers.push_back(line_number);
- }
- }
- else if (m_options.m_until_addrs.empty())
- {
- result.AppendErrorWithFormat ("No line number or address provided:\n%s", GetSyntax());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- if (m_options.m_thread_idx == LLDB_INVALID_THREAD_ID)
- {
- thread = GetDefaultThread();
- }
- else
- {
- thread = process->GetThreadList().FindThreadByIndexID(m_options.m_thread_idx).get();
- }
-
- if (thread == nullptr)
- {
- const uint32_t num_threads = process->GetThreadList().GetSize();
- result.AppendErrorWithFormat ("Thread index %u is out of range (valid values are 0 - %u).\n",
- m_options.m_thread_idx,
- num_threads);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- const bool abort_other_plans = false;
-
- StackFrame *frame = thread->GetStackFrameAtIndex(m_options.m_frame_idx).get();
- if (frame == nullptr)
- {
- result.AppendErrorWithFormat ("Frame index %u is out of range for thread %u.\n",
- m_options.m_frame_idx,
- m_options.m_thread_idx);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- ThreadPlanSP new_plan_sp;
-
- if (frame->HasDebugInformation ())
- {
- // Finally we got here... Translate the given line number to a bunch of addresses:
- SymbolContext sc(frame->GetSymbolContext (eSymbolContextCompUnit));
- LineTable *line_table = nullptr;
- if (sc.comp_unit)
- line_table = sc.comp_unit->GetLineTable();
-
- if (line_table == nullptr)
- {
- result.AppendErrorWithFormat ("Failed to resolve the line table for frame %u of thread index %u.\n",
- m_options.m_frame_idx, m_options.m_thread_idx);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- LineEntry function_start;
- uint32_t index_ptr = 0, end_ptr;
- std::vector<addr_t> address_list;
-
- // Find the beginning & end index of the
- AddressRange fun_addr_range = sc.function->GetAddressRange();
- Address fun_start_addr = fun_addr_range.GetBaseAddress();
- line_table->FindLineEntryByAddress (fun_start_addr, function_start, &index_ptr);
-
- Address fun_end_addr(fun_start_addr.GetSection(),
- fun_start_addr.GetOffset() + fun_addr_range.GetByteSize());
-
- bool all_in_function = true;
-
- line_table->FindLineEntryByAddress (fun_end_addr, function_start, &end_ptr);
-
- for (uint32_t line_number : line_numbers)
- {
- uint32_t start_idx_ptr = index_ptr;
- while (start_idx_ptr <= end_ptr)
- {
- 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);
- if (start_idx_ptr == UINT32_MAX)
- break;
-
- addr_t address = line_entry.range.GetBaseAddress().GetLoadAddress(target);
- if (address != LLDB_INVALID_ADDRESS)
- {
- if (fun_addr_range.ContainsLoadAddress (address, target))
- address_list.push_back (address);
- else
- all_in_function = false;
- }
- start_idx_ptr++;
- }
- }
-
- for (lldb::addr_t address : m_options.m_until_addrs)
- {
- if (fun_addr_range.ContainsLoadAddress (address, target))
- address_list.push_back (address);
- else
- all_in_function = false;
- }
-
- if (address_list.empty())
- {
- if (all_in_function)
- result.AppendErrorWithFormat ("No line entries matching until target.\n");
- else
- result.AppendErrorWithFormat ("Until target outside of the current function.\n");
-
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- new_plan_sp = thread->QueueThreadPlanForStepUntil (abort_other_plans,
- &address_list.front(),
- address_list.size(),
- m_options.m_stop_others,
- m_options.m_frame_idx);
- // User level plans should be master plans so they can be interrupted (e.g. by hitting a breakpoint)
- // and other plans executed by the user (stepping around the breakpoint) and then a "continue"
- // will resume the original plan.
- new_plan_sp->SetIsMasterPlan (true);
- new_plan_sp->SetOkayToDiscard(false);
- }
- else
- {
- result.AppendErrorWithFormat ("Frame index %u of thread %u has no debug information.\n",
- m_options.m_frame_idx,
- m_options.m_thread_idx);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- process->GetThreadList().SetSelectedThreadByID (m_options.m_thread_idx);
-
- StreamString stream;
- Error error;
- if (synchronous_execution)
- error = process->ResumeSynchronous (&stream);
- else
- error = process->Resume ();
-
- if (error.Success())
- {
- result.AppendMessageWithFormat ("Process %" PRIu64 " resuming\n", process->GetID());
- if (synchronous_execution)
- {
- // If any state changed events had anything to say, add that to the result
- if (stream.GetData())
- result.AppendMessage(stream.GetData());
-
- result.SetDidChangeProcessState (true);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- result.SetStatus (eReturnStatusSuccessContinuingNoResult);
- }
- }
- else
- {
- result.AppendErrorWithFormat("Failed to resume process: %s.\n", error.AsCString());
- result.SetStatus (eReturnStatusFailed);
- }
-
- }
- return result.Succeeded();
+ if (thread == nullptr) {
+ const uint32_t num_threads = process->GetThreadList().GetSize();
+ result.AppendErrorWithFormat(
+ "Thread index %u is out of range (valid values are 0 - %u).\n",
+ m_options.m_thread_idx, num_threads);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ const bool abort_other_plans = false;
+
+ StackFrame *frame =
+ thread->GetStackFrameAtIndex(m_options.m_frame_idx).get();
+ if (frame == nullptr) {
+ result.AppendErrorWithFormat(
+ "Frame index %u is out of range for thread %u.\n",
+ m_options.m_frame_idx, m_options.m_thread_idx);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ ThreadPlanSP new_plan_sp;
+
+ if (frame->HasDebugInformation()) {
+ // Finally we got here... Translate the given line number to a bunch of
+ // addresses:
+ SymbolContext sc(frame->GetSymbolContext(eSymbolContextCompUnit));
+ LineTable *line_table = nullptr;
+ if (sc.comp_unit)
+ line_table = sc.comp_unit->GetLineTable();
+
+ if (line_table == nullptr) {
+ result.AppendErrorWithFormat("Failed to resolve the line table for "
+ "frame %u of thread index %u.\n",
+ m_options.m_frame_idx,
+ m_options.m_thread_idx);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ LineEntry function_start;
+ uint32_t index_ptr = 0, end_ptr;
+ std::vector<addr_t> address_list;
+
+ // Find the beginning & end index of the
+ AddressRange fun_addr_range = sc.function->GetAddressRange();
+ Address fun_start_addr = fun_addr_range.GetBaseAddress();
+ line_table->FindLineEntryByAddress(fun_start_addr, function_start,
+ &index_ptr);
+
+ Address fun_end_addr(fun_start_addr.GetSection(),
+ fun_start_addr.GetOffset() +
+ fun_addr_range.GetByteSize());
+
+ bool all_in_function = true;
+
+ line_table->FindLineEntryByAddress(fun_end_addr, function_start,
+ &end_ptr);
+
+ for (uint32_t line_number : line_numbers) {
+ uint32_t start_idx_ptr = index_ptr;
+ while (start_idx_ptr <= end_ptr) {
+ 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);
+ if (start_idx_ptr == UINT32_MAX)
+ break;
+
+ addr_t address =
+ line_entry.range.GetBaseAddress().GetLoadAddress(target);
+ if (address != LLDB_INVALID_ADDRESS) {
+ if (fun_addr_range.ContainsLoadAddress(address, target))
+ address_list.push_back(address);
+ else
+ all_in_function = false;
+ }
+ start_idx_ptr++;
+ }
+ }
+
+ for (lldb::addr_t address : m_options.m_until_addrs) {
+ if (fun_addr_range.ContainsLoadAddress(address, target))
+ address_list.push_back(address);
+ else
+ all_in_function = false;
+ }
+
+ if (address_list.empty()) {
+ if (all_in_function)
+ result.AppendErrorWithFormat(
+ "No line entries matching until target.\n");
+ else
+ result.AppendErrorWithFormat(
+ "Until target outside of the current function.\n");
+
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ new_plan_sp = thread->QueueThreadPlanForStepUntil(
+ abort_other_plans, &address_list.front(), address_list.size(),
+ m_options.m_stop_others, m_options.m_frame_idx);
+ // User level plans should be master plans so they can be interrupted
+ // (e.g. by hitting a breakpoint)
+ // and other plans executed by the user (stepping around the breakpoint)
+ // and then a "continue"
+ // will resume the original plan.
+ new_plan_sp->SetIsMasterPlan(true);
+ new_plan_sp->SetOkayToDiscard(false);
+ } else {
+ result.AppendErrorWithFormat(
+ "Frame index %u of thread %u has no debug information.\n",
+ m_options.m_frame_idx, m_options.m_thread_idx);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ process->GetThreadList().SetSelectedThreadByID(m_options.m_thread_idx);
+
+ StreamString stream;
+ Error error;
+ if (synchronous_execution)
+ error = process->ResumeSynchronous(&stream);
+ else
+ error = process->Resume();
+
+ if (error.Success()) {
+ result.AppendMessageWithFormat("Process %" PRIu64 " resuming\n",
+ process->GetID());
+ if (synchronous_execution) {
+ // If any state changed events had anything to say, add that to the
+ // result
+ if (stream.GetData())
+ result.AppendMessage(stream.GetData());
+
+ result.SetDidChangeProcessState(true);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ } else {
+ result.SetStatus(eReturnStatusSuccessContinuingNoResult);
+ }
+ } else {
+ result.AppendErrorWithFormat("Failed to resume process: %s.\n",
+ error.AsCString());
+ result.SetStatus(eReturnStatusFailed);
+ }
}
+ return result.Succeeded();
+ }
- CommandOptions m_options;
+ CommandOptions m_options;
};
-OptionDefinition
-CommandObjectThreadUntil::CommandOptions::g_option_table[] =
-{
- // clang-format off
+OptionDefinition CommandObjectThreadUntil::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_1, false, "frame", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeFrameIndex, "Frame index for until operation - defaults to 0"},
{LLDB_OPT_SET_1, false, "thread", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeThreadIndex, "Thread index for the thread for until operation"},
{LLDB_OPT_SET_1, false, "run-mode",'m', OptionParser::eRequiredArgument, nullptr, g_duo_running_mode, 0, eArgTypeRunMode, "Determine how to run other threads while stepping this one"},
{LLDB_OPT_SET_1, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Run until we reach the specified address, or leave the function - can be specified multiple times."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
//-------------------------------------------------------------------------
// CommandObjectThreadSelect
//-------------------------------------------------------------------------
-class CommandObjectThreadSelect : public CommandObjectParsed
-{
+class CommandObjectThreadSelect : public CommandObjectParsed {
public:
- CommandObjectThreadSelect(CommandInterpreter &interpreter)
- : CommandObjectParsed(interpreter, "thread select", "Change the currently selected thread.", nullptr,
- eCommandRequiresProcess | eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
- eCommandProcessMustBePaused)
- {
- CommandArgumentEntry arg;
- CommandArgumentData thread_idx_arg;
-
- // Define the first (and only) variant of this arg.
- thread_idx_arg.arg_type = eArgTypeThreadIndex;
- thread_idx_arg.arg_repetition = eArgRepeatPlain;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (thread_idx_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
- }
+ CommandObjectThreadSelect(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "thread select",
+ "Change the currently selected thread.", nullptr,
+ eCommandRequiresProcess | eCommandTryTargetAPILock |
+ eCommandProcessMustBeLaunched |
+ eCommandProcessMustBePaused) {
+ CommandArgumentEntry arg;
+ CommandArgumentData thread_idx_arg;
+
+ // Define the first (and only) variant of this arg.
+ thread_idx_arg.arg_type = eArgTypeThreadIndex;
+ thread_idx_arg.arg_repetition = eArgRepeatPlain;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(thread_idx_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+ }
- ~CommandObjectThreadSelect() override = default;
+ ~CommandObjectThreadSelect() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Process *process = m_exe_ctx.GetProcessPtr();
- if (process == nullptr)
- {
- result.AppendError ("no process");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- else if (command.GetArgumentCount() != 1)
- {
- result.AppendErrorWithFormat("'%s' takes exactly one thread index argument:\nUsage: %s\n", m_cmd_name.c_str(), m_cmd_syntax.c_str());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- uint32_t index_id = StringConvert::ToUInt32(command.GetArgumentAtIndex(0), 0, 0);
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Process *process = m_exe_ctx.GetProcessPtr();
+ if (process == nullptr) {
+ result.AppendError("no process");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ } else if (command.GetArgumentCount() != 1) {
+ result.AppendErrorWithFormat(
+ "'%s' takes exactly one thread index argument:\nUsage: %s\n",
+ m_cmd_name.c_str(), m_cmd_syntax.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ uint32_t index_id =
+ StringConvert::ToUInt32(command.GetArgumentAtIndex(0), 0, 0);
+
+ Thread *new_thread =
+ process->GetThreadList().FindThreadByIndexID(index_id).get();
+ if (new_thread == nullptr) {
+ result.AppendErrorWithFormat("invalid thread #%s.\n",
+ command.GetArgumentAtIndex(0));
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
- Thread *new_thread = process->GetThreadList().FindThreadByIndexID(index_id).get();
- if (new_thread == nullptr)
- {
- result.AppendErrorWithFormat ("invalid thread #%s.\n", command.GetArgumentAtIndex(0));
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
+ process->GetThreadList().SetSelectedThreadByID(new_thread->GetID(), true);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
- process->GetThreadList().SetSelectedThreadByID(new_thread->GetID(), true);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
-
- return result.Succeeded();
- }
+ return result.Succeeded();
+ }
};
//-------------------------------------------------------------------------
// CommandObjectThreadList
//-------------------------------------------------------------------------
-class CommandObjectThreadList : public CommandObjectParsed
-{
+class CommandObjectThreadList : public CommandObjectParsed {
public:
- CommandObjectThreadList(CommandInterpreter &interpreter)
- : CommandObjectParsed(interpreter, "thread list",
- "Show a summary of each thread in the current target process.", "thread list",
- eCommandRequiresProcess | eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
- eCommandProcessMustBePaused)
- {
- }
+ CommandObjectThreadList(CommandInterpreter &interpreter)
+ : CommandObjectParsed(
+ interpreter, "thread list",
+ "Show a summary of each thread in the current target process.",
+ "thread list",
+ eCommandRequiresProcess | eCommandTryTargetAPILock |
+ eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
- ~CommandObjectThreadList() override = default;
+ ~CommandObjectThreadList() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Stream &strm = result.GetOutputStream();
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- Process *process = m_exe_ctx.GetProcessPtr();
- const bool only_threads_with_stop_reason = false;
- const uint32_t start_frame = 0;
- const uint32_t num_frames = 0;
- const uint32_t num_frames_with_source = 0;
- process->GetStatus(strm);
- process->GetThreadStatus (strm,
- only_threads_with_stop_reason,
- start_frame,
- num_frames,
- num_frames_with_source);
- return result.Succeeded();
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Stream &strm = result.GetOutputStream();
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ Process *process = m_exe_ctx.GetProcessPtr();
+ const bool only_threads_with_stop_reason = false;
+ const uint32_t start_frame = 0;
+ const uint32_t num_frames = 0;
+ const uint32_t num_frames_with_source = 0;
+ process->GetStatus(strm);
+ process->GetThreadStatus(strm, only_threads_with_stop_reason, start_frame,
+ num_frames, num_frames_with_source);
+ return result.Succeeded();
+ }
};
//-------------------------------------------------------------------------
// CommandObjectThreadInfo
//-------------------------------------------------------------------------
-class CommandObjectThreadInfo : public CommandObjectIterateOverThreads
-{
+class CommandObjectThreadInfo : public CommandObjectIterateOverThreads {
public:
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options()
- {
- OptionParsingStarting(nullptr);
- }
-
- ~CommandOptions() override = default;
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_json_thread = false;
- m_json_stopinfo = false;
- }
-
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- const int short_option = m_getopt_table[option_idx].val;
- Error error;
-
- switch (short_option)
- {
- case 'j':
- m_json_thread = true;
- break;
-
- case 's':
- m_json_stopinfo = true;
- break;
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options() { OptionParsingStarting(nullptr); }
- default:
- return Error("invalid short option character '%c'", short_option);
- }
- return error;
- }
+ ~CommandOptions() override = default;
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_json_thread = false;
+ m_json_stopinfo = false;
+ }
- bool m_json_thread;
- bool m_json_stopinfo;
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ const int short_option = m_getopt_table[option_idx].val;
+ Error error;
- static OptionDefinition g_option_table[];
- };
+ switch (short_option) {
+ case 'j':
+ m_json_thread = true;
+ break;
- CommandObjectThreadInfo(CommandInterpreter &interpreter)
- : CommandObjectIterateOverThreads(
- interpreter, "thread info",
- "Show an extended summary of one or more threads. Defaults to the current thread.", "thread info",
- eCommandRequiresProcess | eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
- eCommandProcessMustBePaused),
- m_options()
- {
- m_add_return = false;
+ case 's':
+ m_json_stopinfo = true;
+ break;
+
+ default:
+ return Error("invalid short option character '%c'", short_option);
+ }
+ return error;
}
- ~CommandObjectThreadInfo() override = default;
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
- Options *
- GetOptions () override
- {
- return &m_options;
- }
+ bool m_json_thread;
+ bool m_json_stopinfo;
- bool
- HandleOneThread (lldb::tid_t tid, CommandReturnObject &result) override
- {
- ThreadSP thread_sp = m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
- if (!thread_sp)
- {
- result.AppendErrorWithFormat ("thread no longer exists: 0x%" PRIx64 "\n", tid);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
+ static OptionDefinition g_option_table[];
+ };
- Thread *thread = thread_sp.get();
+ CommandObjectThreadInfo(CommandInterpreter &interpreter)
+ : CommandObjectIterateOverThreads(
+ interpreter, "thread info", "Show an extended summary of one or "
+ "more threads. Defaults to the "
+ "current thread.",
+ "thread info",
+ eCommandRequiresProcess | eCommandTryTargetAPILock |
+ eCommandProcessMustBeLaunched | eCommandProcessMustBePaused),
+ m_options() {
+ m_add_return = false;
+ }
- Stream &strm = result.GetOutputStream();
- if (!thread->GetDescription (strm, eDescriptionLevelFull, m_options.m_json_thread, m_options.m_json_stopinfo))
- {
- result.AppendErrorWithFormat ("error displaying info for thread: \"%d\"\n", thread->GetIndexID());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- return true;
+ ~CommandObjectThreadInfo() override = default;
+
+ Options *GetOptions() override { return &m_options; }
+
+ bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
+ ThreadSP thread_sp =
+ m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
+ if (!thread_sp) {
+ result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64 "\n",
+ tid);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ Thread *thread = thread_sp.get();
+
+ Stream &strm = result.GetOutputStream();
+ if (!thread->GetDescription(strm, eDescriptionLevelFull,
+ m_options.m_json_thread,
+ m_options.m_json_stopinfo)) {
+ result.AppendErrorWithFormat("error displaying info for thread: \"%d\"\n",
+ thread->GetIndexID());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
}
+ return true;
+ }
- CommandOptions m_options;
+ CommandOptions m_options;
};
-OptionDefinition
-CommandObjectThreadInfo::CommandOptions::g_option_table[] =
-{
- // clang-format off
+OptionDefinition CommandObjectThreadInfo::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_ALL, false, "json", 'j', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the thread info in JSON format."},
{LLDB_OPT_SET_ALL, false, "stop-info", 's', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display the extended stop info in JSON format."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
//-------------------------------------------------------------------------
// CommandObjectThreadReturn
//-------------------------------------------------------------------------
-class CommandObjectThreadReturn : public CommandObjectRaw
-{
+class CommandObjectThreadReturn : public CommandObjectRaw {
public:
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options(),
- m_from_expression(false)
- {
- // Keep default values of all options in one place: OptionParsingStarting ()
- OptionParsingStarting(nullptr);
- }
-
- ~CommandOptions() override = default;
-
- Error
- SetOptionValue (uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'x':
- {
- bool success;
- bool tmp_value = Args::StringToBoolean (option_arg, false, &success);
- if (success)
- m_from_expression = tmp_value;
- else
- {
- error.SetErrorStringWithFormat ("invalid boolean value '%s' for 'x' option", option_arg);
- }
- }
- break;
- default:
- error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
- break;
- }
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_from_expression = false;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options(), m_from_expression(false) {
+ // Keep default values of all options in one place: OptionParsingStarting
+ // ()
+ OptionParsingStarting(nullptr);
+ }
+
+ ~CommandOptions() override = default;
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
- bool m_from_expression;
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
- };
-
- CommandObjectThreadReturn(CommandInterpreter &interpreter)
- : CommandObjectRaw(interpreter, "thread return",
- "Prematurely return from a stack frame, short-circuiting execution of newer frames "
- "and optionally yielding a specified value. Defaults to the exiting the current stack "
- "frame.",
- "thread return", eCommandRequiresFrame | eCommandTryTargetAPILock |
- eCommandProcessMustBeLaunched | eCommandProcessMustBePaused),
- m_options()
- {
- CommandArgumentEntry arg;
- CommandArgumentData expression_arg;
-
- // Define the first (and only) variant of this arg.
- expression_arg.arg_type = eArgTypeExpression;
- expression_arg.arg_repetition = eArgRepeatOptional;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (expression_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
- }
+ switch (short_option) {
+ case 'x': {
+ bool success;
+ bool tmp_value = Args::StringToBoolean(option_arg, false, &success);
+ if (success)
+ m_from_expression = tmp_value;
+ else {
+ error.SetErrorStringWithFormat(
+ "invalid boolean value '%s' for 'x' option", option_arg);
+ }
+ } break;
+ default:
+ error.SetErrorStringWithFormat("invalid short option character '%c'",
+ short_option);
+ break;
+ }
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_from_expression = false;
+ }
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ bool m_from_expression;
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+ };
+
+ CommandObjectThreadReturn(CommandInterpreter &interpreter)
+ : CommandObjectRaw(interpreter, "thread return",
+ "Prematurely return from a stack frame, "
+ "short-circuiting execution of newer frames "
+ "and optionally yielding a specified value. Defaults "
+ "to the exiting the current stack "
+ "frame.",
+ "thread return",
+ eCommandRequiresFrame | eCommandTryTargetAPILock |
+ eCommandProcessMustBeLaunched |
+ eCommandProcessMustBePaused),
+ m_options() {
+ CommandArgumentEntry arg;
+ CommandArgumentData expression_arg;
+
+ // Define the first (and only) variant of this arg.
+ expression_arg.arg_type = eArgTypeExpression;
+ expression_arg.arg_repetition = eArgRepeatOptional;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(expression_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+ }
- ~CommandObjectThreadReturn() override = default;
+ ~CommandObjectThreadReturn() override = default;
- Options *
- GetOptions() override
- {
- return &m_options;
- }
+ Options *GetOptions() override { return &m_options; }
protected:
- bool
- DoExecute (const char *command, CommandReturnObject &result) override
- {
- // I am going to handle this by hand, because I don't want you to have to say:
- // "thread return -- -5".
- if (command[0] == '-' && command[1] == 'x')
- {
- if (command && command[2] != '\0')
- result.AppendWarning("Return values ignored when returning from user called expressions");
-
- Thread *thread = m_exe_ctx.GetThreadPtr();
- Error error;
- error = thread->UnwindInnermostExpression();
- if (!error.Success())
- {
- result.AppendErrorWithFormat ("Unwinding expression failed - %s.", error.AsCString());
- result.SetStatus (eReturnStatusFailed);
- }
- else
- {
- bool success = thread->SetSelectedFrameByIndexNoisily (0, result.GetOutputStream());
- if (success)
- {
- m_exe_ctx.SetFrameSP(thread->GetSelectedFrame ());
- result.SetStatus (eReturnStatusSuccessFinishResult);
- }
- else
- {
- result.AppendErrorWithFormat ("Could not select 0th frame after unwinding expression.");
- result.SetStatus (eReturnStatusFailed);
- }
- }
- return result.Succeeded();
- }
-
- ValueObjectSP return_valobj_sp;
-
- StackFrameSP frame_sp = m_exe_ctx.GetFrameSP();
- uint32_t frame_idx = frame_sp->GetFrameIndex();
-
- if (frame_sp->IsInlined())
- {
- result.AppendError("Don't know how to return from inlined frames.");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- if (command && command[0] != '\0')
- {
- Target *target = m_exe_ctx.GetTargetPtr();
- EvaluateExpressionOptions options;
-
- options.SetUnwindOnError(true);
- options.SetUseDynamic(eNoDynamicValues);
-
- ExpressionResults exe_results = eExpressionSetupError;
- exe_results = target->EvaluateExpression (command,
- frame_sp.get(),
- return_valobj_sp,
- options);
- if (exe_results != eExpressionCompleted)
- {
- if (return_valobj_sp)
- result.AppendErrorWithFormat("Error evaluating result expression: %s", return_valobj_sp->GetError().AsCString());
- else
- result.AppendErrorWithFormat("Unknown error evaluating result expression.");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
-
- Error error;
- ThreadSP thread_sp = m_exe_ctx.GetThreadSP();
- const bool broadcast = true;
- error = thread_sp->ReturnFromFrame (frame_sp, return_valobj_sp, broadcast);
- if (!error.Success())
- {
- result.AppendErrorWithFormat("Error returning from frame %d of thread %d: %s.", frame_idx, thread_sp->GetIndexID(), error.AsCString());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
+ bool DoExecute(const char *command, CommandReturnObject &result) override {
+ // I am going to handle this by hand, because I don't want you to have to
+ // say:
+ // "thread return -- -5".
+ if (command[0] == '-' && command[1] == 'x') {
+ if (command && command[2] != '\0')
+ result.AppendWarning("Return values ignored when returning from user "
+ "called expressions");
+
+ Thread *thread = m_exe_ctx.GetThreadPtr();
+ Error error;
+ error = thread->UnwindInnermostExpression();
+ if (!error.Success()) {
+ result.AppendErrorWithFormat("Unwinding expression failed - %s.",
+ error.AsCString());
+ result.SetStatus(eReturnStatusFailed);
+ } else {
+ bool success =
+ thread->SetSelectedFrameByIndexNoisily(0, result.GetOutputStream());
+ if (success) {
+ m_exe_ctx.SetFrameSP(thread->GetSelectedFrame());
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ } else {
+ result.AppendErrorWithFormat(
+ "Could not select 0th frame after unwinding expression.");
+ result.SetStatus(eReturnStatusFailed);
+ }
+ }
+ return result.Succeeded();
+ }
+
+ ValueObjectSP return_valobj_sp;
+
+ StackFrameSP frame_sp = m_exe_ctx.GetFrameSP();
+ uint32_t frame_idx = frame_sp->GetFrameIndex();
+
+ if (frame_sp->IsInlined()) {
+ result.AppendError("Don't know how to return from inlined frames.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (command && command[0] != '\0') {
+ Target *target = m_exe_ctx.GetTargetPtr();
+ EvaluateExpressionOptions options;
+
+ options.SetUnwindOnError(true);
+ options.SetUseDynamic(eNoDynamicValues);
+
+ ExpressionResults exe_results = eExpressionSetupError;
+ exe_results = target->EvaluateExpression(command, frame_sp.get(),
+ return_valobj_sp, options);
+ if (exe_results != eExpressionCompleted) {
+ if (return_valobj_sp)
+ result.AppendErrorWithFormat(
+ "Error evaluating result expression: %s",
+ return_valobj_sp->GetError().AsCString());
+ else
+ result.AppendErrorWithFormat(
+ "Unknown error evaluating result expression.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+
+ Error error;
+ ThreadSP thread_sp = m_exe_ctx.GetThreadSP();
+ const bool broadcast = true;
+ error = thread_sp->ReturnFromFrame(frame_sp, return_valobj_sp, broadcast);
+ if (!error.Success()) {
+ result.AppendErrorWithFormat(
+ "Error returning from frame %d of thread %d: %s.", frame_idx,
+ thread_sp->GetIndexID(), error.AsCString());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return true;
+ }
- result.SetStatus (eReturnStatusSuccessFinishResult);
- return true;
- }
-
- CommandOptions m_options;
+ CommandOptions m_options;
};
-OptionDefinition
-CommandObjectThreadReturn::CommandOptions::g_option_table[] =
-{
- // clang-format off
+OptionDefinition CommandObjectThreadReturn::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_ALL, false, "from-expression", 'x', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Return from the innermost expression evaluation."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
- // clang-format on
+ // clang-format on
};
//-------------------------------------------------------------------------
// CommandObjectThreadJump
//-------------------------------------------------------------------------
-class CommandObjectThreadJump : public CommandObjectParsed
-{
+class CommandObjectThreadJump : public CommandObjectParsed {
public:
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options()
- {
- OptionParsingStarting(nullptr);
- }
-
- ~CommandOptions() override = default;
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_filenames.Clear();
- m_line_num = 0;
- m_line_offset = 0;
- m_load_addr = LLDB_INVALID_ADDRESS;
- m_force = false;
- }
-
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- bool success;
- const int short_option = m_getopt_table[option_idx].val;
- Error error;
-
- switch (short_option)
- {
- case 'f':
- m_filenames.AppendIfUnique (FileSpec(option_arg, false));
- if (m_filenames.GetSize() > 1)
- return Error("only one source file expected.");
- break;
- case 'l':
- m_line_num = StringConvert::ToUInt32 (option_arg, 0, 0, &success);
- if (!success || m_line_num == 0)
- return Error("invalid line number: '%s'.", option_arg);
- break;
- case 'b':
- m_line_offset = StringConvert::ToSInt32 (option_arg, 0, 0, &success);
- if (!success)
- return Error("invalid line offset: '%s'.", option_arg);
- break;
- case 'a':
- m_load_addr = Args::StringToAddress(execution_context,
- option_arg,
- LLDB_INVALID_ADDRESS,
- &error);
- break;
- case 'r':
- m_force = true;
- break;
- default:
- return Error("invalid short option character '%c'", short_option);
- }
- return error;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- FileSpecList m_filenames;
- uint32_t m_line_num;
- int32_t m_line_offset;
- lldb::addr_t m_load_addr;
- bool m_force;
-
- static OptionDefinition g_option_table[];
- };
-
- CommandObjectThreadJump (CommandInterpreter &interpreter) :
- CommandObjectParsed (interpreter,
- "thread jump",
- "Sets the program counter to a new address.",
- "thread jump",
- eCommandRequiresFrame |
- eCommandTryTargetAPILock |
- eCommandProcessMustBeLaunched |
- eCommandProcessMustBePaused ),
- m_options()
- {
- }
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options() { OptionParsingStarting(nullptr); }
+
+ ~CommandOptions() override = default;
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_filenames.Clear();
+ m_line_num = 0;
+ m_line_offset = 0;
+ m_load_addr = LLDB_INVALID_ADDRESS;
+ m_force = false;
+ }
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ bool success;
+ const int short_option = m_getopt_table[option_idx].val;
+ Error error;
+
+ switch (short_option) {
+ case 'f':
+ m_filenames.AppendIfUnique(FileSpec(option_arg, false));
+ if (m_filenames.GetSize() > 1)
+ return Error("only one source file expected.");
+ break;
+ case 'l':
+ m_line_num = StringConvert::ToUInt32(option_arg, 0, 0, &success);
+ if (!success || m_line_num == 0)
+ return Error("invalid line number: '%s'.", option_arg);
+ break;
+ case 'b':
+ m_line_offset = StringConvert::ToSInt32(option_arg, 0, 0, &success);
+ if (!success)
+ return Error("invalid line offset: '%s'.", option_arg);
+ break;
+ case 'a':
+ m_load_addr = Args::StringToAddress(execution_context, option_arg,
+ LLDB_INVALID_ADDRESS, &error);
+ break;
+ case 'r':
+ m_force = true;
+ break;
+ default:
+ return Error("invalid short option character '%c'", short_option);
+ }
+ return error;
+ }
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ FileSpecList m_filenames;
+ uint32_t m_line_num;
+ int32_t m_line_offset;
+ lldb::addr_t m_load_addr;
+ bool m_force;
+
+ static OptionDefinition g_option_table[];
+ };
+
+ CommandObjectThreadJump(CommandInterpreter &interpreter)
+ : CommandObjectParsed(
+ interpreter, "thread jump",
+ "Sets the program counter to a new address.", "thread jump",
+ eCommandRequiresFrame | eCommandTryTargetAPILock |
+ eCommandProcessMustBeLaunched | eCommandProcessMustBePaused),
+ m_options() {}
- ~CommandObjectThreadJump() override = default;
+ ~CommandObjectThreadJump() override = default;
- Options *
- GetOptions() override
- {
- return &m_options;
- }
+ Options *GetOptions() override { return &m_options; }
protected:
- bool DoExecute (Args& args, CommandReturnObject &result) override
- {
- RegisterContext *reg_ctx = m_exe_ctx.GetRegisterContext();
- StackFrame *frame = m_exe_ctx.GetFramePtr();
- Thread *thread = m_exe_ctx.GetThreadPtr();
- Target *target = m_exe_ctx.GetTargetPtr();
- const SymbolContext &sym_ctx = frame->GetSymbolContext (eSymbolContextLineEntry);
-
- if (m_options.m_load_addr != LLDB_INVALID_ADDRESS)
- {
- // Use this address directly.
- Address dest = Address(m_options.m_load_addr);
-
- lldb::addr_t callAddr = dest.GetCallableLoadAddress (target);
- if (callAddr == LLDB_INVALID_ADDRESS)
- {
- result.AppendErrorWithFormat ("Invalid destination address.");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- if (!reg_ctx->SetPC (callAddr))
- {
- result.AppendErrorWithFormat ("Error changing PC value for thread %d.", thread->GetIndexID());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- else
- {
- // Pick either the absolute line, or work out a relative one.
- int32_t line = (int32_t)m_options.m_line_num;
- if (line == 0)
- line = sym_ctx.line_entry.line + m_options.m_line_offset;
-
- // Try the current file, but override if asked.
- FileSpec file = sym_ctx.line_entry.file;
- if (m_options.m_filenames.GetSize() == 1)
- file = m_options.m_filenames.GetFileSpecAtIndex(0);
-
- if (!file)
- {
- result.AppendErrorWithFormat ("No source file available for the current location.");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- std::string warnings;
- Error err = thread->JumpToLine (file, line, m_options.m_force, &warnings);
-
- if (err.Fail())
- {
- result.SetError (err);
- return false;
- }
-
- if (!warnings.empty())
- result.AppendWarning (warnings.c_str());
- }
-
- result.SetStatus (eReturnStatusSuccessFinishResult);
- return true;
- }
+ bool DoExecute(Args &args, CommandReturnObject &result) override {
+ RegisterContext *reg_ctx = m_exe_ctx.GetRegisterContext();
+ StackFrame *frame = m_exe_ctx.GetFramePtr();
+ Thread *thread = m_exe_ctx.GetThreadPtr();
+ Target *target = m_exe_ctx.GetTargetPtr();
+ const SymbolContext &sym_ctx =
+ frame->GetSymbolContext(eSymbolContextLineEntry);
+
+ if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) {
+ // Use this address directly.
+ Address dest = Address(m_options.m_load_addr);
+
+ lldb::addr_t callAddr = dest.GetCallableLoadAddress(target);
+ if (callAddr == LLDB_INVALID_ADDRESS) {
+ result.AppendErrorWithFormat("Invalid destination address.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (!reg_ctx->SetPC(callAddr)) {
+ result.AppendErrorWithFormat("Error changing PC value for thread %d.",
+ thread->GetIndexID());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ } else {
+ // Pick either the absolute line, or work out a relative one.
+ int32_t line = (int32_t)m_options.m_line_num;
+ if (line == 0)
+ line = sym_ctx.line_entry.line + m_options.m_line_offset;
+
+ // Try the current file, but override if asked.
+ FileSpec file = sym_ctx.line_entry.file;
+ if (m_options.m_filenames.GetSize() == 1)
+ file = m_options.m_filenames.GetFileSpecAtIndex(0);
+
+ if (!file) {
+ result.AppendErrorWithFormat(
+ "No source file available for the current location.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ std::string warnings;
+ Error err = thread->JumpToLine(file, line, m_options.m_force, &warnings);
+
+ if (err.Fail()) {
+ result.SetError(err);
+ return false;
+ }
+
+ if (!warnings.empty())
+ result.AppendWarning(warnings.c_str());
+ }
+
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return true;
+ }
- CommandOptions m_options;
+ CommandOptions m_options;
};
-OptionDefinition
-CommandObjectThreadJump::CommandOptions::g_option_table[] =
-{
- // clang-format off
+OptionDefinition CommandObjectThreadJump::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specifies the source file to jump to."},
{LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLineNum, "Specifies the line number to jump to."},
{LLDB_OPT_SET_2, true, "by", 'b', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOffset, "Jumps by a relative line offset from the current line."},
{LLDB_OPT_SET_3, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeAddressOrExpression, "Jumps to a specific address."},
{LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "force", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allows the PC to leave the current function."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
//-------------------------------------------------------------------------
@@ -1968,267 +1759,265 @@ CommandObjectThreadJump::CommandOptions:
// CommandObjectThreadPlanList
//-------------------------------------------------------------------------
-class CommandObjectThreadPlanList : public CommandObjectIterateOverThreads
-{
+class CommandObjectThreadPlanList : public CommandObjectIterateOverThreads {
public:
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options()
- {
- // Keep default values of all options in one place: OptionParsingStarting ()
- OptionParsingStarting(nullptr);
- }
-
- ~CommandOptions() override = default;
-
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'i':
- m_internal = true;
- break;
- case 'v':
- m_verbose = true;
- break;
- default:
- error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
- break;
- }
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_verbose = false;
- m_internal = false;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options() {
+ // Keep default values of all options in one place: OptionParsingStarting
+ // ()
+ OptionParsingStarting(nullptr);
+ }
+
+ ~CommandOptions() override = default;
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option) {
+ case 'i':
+ m_internal = true;
+ break;
+ case 'v':
+ m_verbose = true;
+ break;
+ default:
+ error.SetErrorStringWithFormat("invalid short option character '%c'",
+ short_option);
+ break;
+ }
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_verbose = false;
+ m_internal = false;
+ }
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+ bool m_verbose;
+ bool m_internal;
+ };
+
+ CommandObjectThreadPlanList(CommandInterpreter &interpreter)
+ : CommandObjectIterateOverThreads(
+ interpreter, "thread plan list",
+ "Show thread plans for one or more threads. If no threads are "
+ "specified, show the "
+ "current thread. Use the thread-index \"all\" to see all threads.",
+ nullptr,
+ eCommandRequiresProcess | eCommandRequiresThread |
+ eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
+ eCommandProcessMustBePaused),
+ m_options() {}
- // Instance variables to hold the values for command options.
- bool m_verbose;
- bool m_internal;
- };
+ ~CommandObjectThreadPlanList() override = default;
- CommandObjectThreadPlanList(CommandInterpreter &interpreter)
- : CommandObjectIterateOverThreads(
- interpreter, "thread plan list",
- "Show thread plans for one or more threads. If no threads are specified, show the "
- "current thread. Use the thread-index \"all\" to see all threads.",
- nullptr, eCommandRequiresProcess | eCommandRequiresThread | eCommandTryTargetAPILock |
- eCommandProcessMustBeLaunched | eCommandProcessMustBePaused),
- m_options()
- {
- }
-
- ~CommandObjectThreadPlanList() override = default;
-
- Options *
- GetOptions () override
- {
- return &m_options;
- }
+ Options *GetOptions() override { return &m_options; }
protected:
- bool
- HandleOneThread (lldb::tid_t tid, CommandReturnObject &result) override
- {
- ThreadSP thread_sp = m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
- if (!thread_sp)
- {
- result.AppendErrorWithFormat ("thread no longer exists: 0x%" PRIx64 "\n", tid);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
+ bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
+ ThreadSP thread_sp =
+ m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
+ if (!thread_sp) {
+ result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64 "\n",
+ tid);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
- Thread *thread = thread_sp.get();
+ Thread *thread = thread_sp.get();
- Stream &strm = result.GetOutputStream();
- DescriptionLevel desc_level = eDescriptionLevelFull;
- if (m_options.m_verbose)
- desc_level = eDescriptionLevelVerbose;
+ Stream &strm = result.GetOutputStream();
+ DescriptionLevel desc_level = eDescriptionLevelFull;
+ if (m_options.m_verbose)
+ desc_level = eDescriptionLevelVerbose;
- thread->DumpThreadPlans (&strm, desc_level, m_options.m_internal, true);
- return true;
- }
+ thread->DumpThreadPlans(&strm, desc_level, m_options.m_internal, true);
+ return true;
+ }
- CommandOptions m_options;
+ CommandOptions m_options;
};
-OptionDefinition
-CommandObjectThreadPlanList::CommandOptions::g_option_table[] =
-{
- // clang-format off
+OptionDefinition CommandObjectThreadPlanList::CommandOptions::g_option_table[] =
+ {
+ // clang-format off
{LLDB_OPT_SET_1, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display more information about the thread plans"},
{LLDB_OPT_SET_1, false, "internal", 'i', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display internal as well as user thread plans"},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
-class CommandObjectThreadPlanDiscard : public CommandObjectParsed
-{
+class CommandObjectThreadPlanDiscard : public CommandObjectParsed {
public:
- CommandObjectThreadPlanDiscard(CommandInterpreter &interpreter)
- : CommandObjectParsed(
- interpreter, "thread plan discard",
- "Discards thread plans up to and including the specified index (see 'thread plan list'.) "
- "Only user visible plans can be discarded.",
- nullptr, eCommandRequiresProcess | eCommandRequiresThread | eCommandTryTargetAPILock |
- eCommandProcessMustBeLaunched | eCommandProcessMustBePaused)
- {
- CommandArgumentEntry arg;
- CommandArgumentData plan_index_arg;
-
- // Define the first (and only) variant of this arg.
- plan_index_arg.arg_type = eArgTypeUnsignedInteger;
- plan_index_arg.arg_repetition = eArgRepeatPlain;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (plan_index_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
- }
-
- ~CommandObjectThreadPlanDiscard() override = default;
-
- bool
- DoExecute (Args& args, CommandReturnObject &result) override
- {
- Thread *thread = m_exe_ctx.GetThreadPtr();
- if (args.GetArgumentCount() != 1)
- {
- result.AppendErrorWithFormat("Too many arguments, expected one - the thread plan index - but got %zu.",
- args.GetArgumentCount());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- bool success;
- uint32_t thread_plan_idx = StringConvert::ToUInt32(args.GetArgumentAtIndex(0), 0, 0, &success);
- if (!success)
- {
- result.AppendErrorWithFormat("Invalid thread index: \"%s\" - should be unsigned int.",
- args.GetArgumentAtIndex(0));
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- if (thread_plan_idx == 0)
- {
- result.AppendErrorWithFormat("You wouldn't really want me to discard the base thread plan.");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- if (thread->DiscardUserThreadPlansUpToIndex(thread_plan_idx))
- {
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- return true;
- }
- else
- {
- result.AppendErrorWithFormat("Could not find User thread plan with index %s.",
- args.GetArgumentAtIndex(0));
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
+ CommandObjectThreadPlanDiscard(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "thread plan discard",
+ "Discards thread plans up to and including the "
+ "specified index (see 'thread plan list'.) "
+ "Only user visible plans can be discarded.",
+ nullptr,
+ eCommandRequiresProcess | eCommandRequiresThread |
+ eCommandTryTargetAPILock |
+ eCommandProcessMustBeLaunched |
+ eCommandProcessMustBePaused) {
+ CommandArgumentEntry arg;
+ CommandArgumentData plan_index_arg;
+
+ // Define the first (and only) variant of this arg.
+ plan_index_arg.arg_type = eArgTypeUnsignedInteger;
+ plan_index_arg.arg_repetition = eArgRepeatPlain;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(plan_index_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+ }
+
+ ~CommandObjectThreadPlanDiscard() override = default;
+
+ bool DoExecute(Args &args, CommandReturnObject &result) override {
+ Thread *thread = m_exe_ctx.GetThreadPtr();
+ if (args.GetArgumentCount() != 1) {
+ result.AppendErrorWithFormat("Too many arguments, expected one - the "
+ "thread plan index - but got %zu.",
+ args.GetArgumentCount());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ bool success;
+ uint32_t thread_plan_idx =
+ StringConvert::ToUInt32(args.GetArgumentAtIndex(0), 0, 0, &success);
+ if (!success) {
+ result.AppendErrorWithFormat(
+ "Invalid thread index: \"%s\" - should be unsigned int.",
+ args.GetArgumentAtIndex(0));
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (thread_plan_idx == 0) {
+ result.AppendErrorWithFormat(
+ "You wouldn't really want me to discard the base thread plan.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (thread->DiscardUserThreadPlansUpToIndex(thread_plan_idx)) {
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ return true;
+ } else {
+ result.AppendErrorWithFormat(
+ "Could not find User thread plan with index %s.",
+ args.GetArgumentAtIndex(0));
+ result.SetStatus(eReturnStatusFailed);
+ return false;
}
+ }
};
//-------------------------------------------------------------------------
// CommandObjectMultiwordThreadPlan
//-------------------------------------------------------------------------
-class CommandObjectMultiwordThreadPlan : public CommandObjectMultiword
-{
+class CommandObjectMultiwordThreadPlan : public CommandObjectMultiword {
public:
- CommandObjectMultiwordThreadPlan(CommandInterpreter &interpreter)
- : CommandObjectMultiword(interpreter, "plan", "Commands for managing thread plans that control execution.",
- "thread plan <subcommand> [<subcommand objects]")
- {
- LoadSubCommand ("list", CommandObjectSP (new CommandObjectThreadPlanList (interpreter)));
- LoadSubCommand ("discard", CommandObjectSP (new CommandObjectThreadPlanDiscard (interpreter)));
- }
+ CommandObjectMultiwordThreadPlan(CommandInterpreter &interpreter)
+ : CommandObjectMultiword(
+ interpreter, "plan",
+ "Commands for managing thread plans that control execution.",
+ "thread plan <subcommand> [<subcommand objects]") {
+ LoadSubCommand(
+ "list", CommandObjectSP(new CommandObjectThreadPlanList(interpreter)));
+ LoadSubCommand(
+ "discard",
+ CommandObjectSP(new CommandObjectThreadPlanDiscard(interpreter)));
+ }
- ~CommandObjectMultiwordThreadPlan() override = default;
+ ~CommandObjectMultiwordThreadPlan() override = default;
};
//-------------------------------------------------------------------------
// CommandObjectMultiwordThread
//-------------------------------------------------------------------------
-CommandObjectMultiwordThread::CommandObjectMultiwordThread(CommandInterpreter &interpreter)
- : 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)));
- LoadSubCommand ("continue", CommandObjectSP (new CommandObjectThreadContinue (interpreter)));
- LoadSubCommand ("list", CommandObjectSP (new CommandObjectThreadList (interpreter)));
- LoadSubCommand ("return", CommandObjectSP (new CommandObjectThreadReturn (interpreter)));
- LoadSubCommand ("jump", CommandObjectSP (new CommandObjectThreadJump (interpreter)));
- LoadSubCommand ("select", CommandObjectSP (new CommandObjectThreadSelect (interpreter)));
- LoadSubCommand ("until", CommandObjectSP (new CommandObjectThreadUntil (interpreter)));
- LoadSubCommand ("info", CommandObjectSP (new CommandObjectThreadInfo (interpreter)));
- LoadSubCommand("step-in",
- CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
- interpreter, "thread step-in",
- "Source level single step, stepping into calls. Defaults to current thread unless specified.",
- nullptr, eStepTypeInto, eStepScopeSource)));
-
- LoadSubCommand("step-out",
- CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
- interpreter, "thread step-out", "Finish executing the current stack frame and stop after "
- "returning. Defaults to current thread unless specified.",
- nullptr, eStepTypeOut, eStepScopeSource)));
-
- LoadSubCommand("step-over",
- CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
- interpreter, "thread step-over",
- "Source level single step, stepping over calls. Defaults to current thread unless specified.",
- nullptr, eStepTypeOver, eStepScopeSource)));
-
- LoadSubCommand(
- "step-inst",
- CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
- interpreter, "thread step-inst",
- "Instruction level single step, stepping into calls. Defaults to current thread unless specified.",
- nullptr, eStepTypeTrace, eStepScopeInstruction)));
-
- LoadSubCommand(
- "step-inst-over",
- CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
- interpreter, "thread step-inst-over",
- "Instruction level single step, stepping over calls. Defaults to current thread unless specified.",
- nullptr, eStepTypeTraceOver, eStepScopeInstruction)));
-
- LoadSubCommand ("step-scripted", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope (
- interpreter,
- "thread step-scripted",
- "Step as instructed by the script class passed in the -C option.",
- nullptr,
- eStepTypeScripted,
- eStepScopeSource)));
+CommandObjectMultiwordThread::CommandObjectMultiwordThread(
+ CommandInterpreter &interpreter)
+ : 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)));
+ LoadSubCommand("continue",
+ CommandObjectSP(new CommandObjectThreadContinue(interpreter)));
+ LoadSubCommand("list",
+ CommandObjectSP(new CommandObjectThreadList(interpreter)));
+ LoadSubCommand("return",
+ CommandObjectSP(new CommandObjectThreadReturn(interpreter)));
+ LoadSubCommand("jump",
+ CommandObjectSP(new CommandObjectThreadJump(interpreter)));
+ LoadSubCommand("select",
+ CommandObjectSP(new CommandObjectThreadSelect(interpreter)));
+ LoadSubCommand("until",
+ CommandObjectSP(new CommandObjectThreadUntil(interpreter)));
+ LoadSubCommand("info",
+ CommandObjectSP(new CommandObjectThreadInfo(interpreter)));
+ LoadSubCommand("step-in",
+ CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
+ interpreter, "thread step-in",
+ "Source level single step, stepping into calls. Defaults "
+ "to current thread unless specified.",
+ nullptr, eStepTypeInto, eStepScopeSource)));
+
+ LoadSubCommand("step-out",
+ CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
+ interpreter, "thread step-out",
+ "Finish executing the current stack frame and stop after "
+ "returning. Defaults to current thread unless specified.",
+ nullptr, eStepTypeOut, eStepScopeSource)));
+
+ LoadSubCommand("step-over",
+ CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
+ interpreter, "thread step-over",
+ "Source level single step, stepping over calls. Defaults "
+ "to current thread unless specified.",
+ nullptr, eStepTypeOver, eStepScopeSource)));
+
+ LoadSubCommand("step-inst",
+ CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
+ interpreter, "thread step-inst",
+ "Instruction level single step, stepping into calls. "
+ "Defaults to current thread unless specified.",
+ nullptr, eStepTypeTrace, eStepScopeInstruction)));
+
+ LoadSubCommand("step-inst-over",
+ CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
+ interpreter, "thread step-inst-over",
+ "Instruction level single step, stepping over calls. "
+ "Defaults to current thread unless specified.",
+ nullptr, eStepTypeTraceOver, eStepScopeInstruction)));
+
+ LoadSubCommand(
+ "step-scripted",
+ CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
+ interpreter, "thread step-scripted",
+ "Step as instructed by the script class passed in the -C option.",
+ nullptr, eStepTypeScripted, eStepScopeSource)));
- LoadSubCommand ("plan", CommandObjectSP (new CommandObjectMultiwordThreadPlan(interpreter)));
+ LoadSubCommand("plan", CommandObjectSP(new CommandObjectMultiwordThreadPlan(
+ interpreter)));
}
CommandObjectMultiwordThread::~CommandObjectMultiwordThread() = default;
Modified: lldb/trunk/source/Commands/CommandObjectThread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectThread.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectThread.h (original)
+++ lldb/trunk/source/Commands/CommandObjectThread.h Tue Sep 6 15:57:50 2016
@@ -18,13 +18,11 @@
namespace lldb_private {
-class CommandObjectMultiwordThread : public CommandObjectMultiword
-{
+class CommandObjectMultiwordThread : public CommandObjectMultiword {
public:
+ CommandObjectMultiwordThread(CommandInterpreter &interpreter);
- CommandObjectMultiwordThread (CommandInterpreter &interpreter);
-
- ~CommandObjectMultiwordThread() override;
+ ~CommandObjectMultiwordThread() override;
};
} // namespace lldb_private
Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Tue Sep 6 15:57:50 2016
@@ -29,11 +29,11 @@
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandObject.h"
#include "lldb/Interpreter/CommandReturnObject.h"
-#include "lldb/Interpreter/Options.h"
#include "lldb/Interpreter/OptionGroupFormat.h"
#include "lldb/Interpreter/OptionValueBoolean.h"
#include "lldb/Interpreter/OptionValueLanguage.h"
#include "lldb/Interpreter/OptionValueString.h"
+#include "lldb/Interpreter/Options.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Target/Language.h"
#include "lldb/Target/Process.h"
@@ -45,697 +45,558 @@
using namespace lldb;
using namespace lldb_private;
-class ScriptAddOptions
-{
+class ScriptAddOptions {
public:
+ TypeSummaryImpl::Flags m_flags;
+ StringList m_target_types;
+ bool m_regex;
+ ConstString m_name;
+ std::string m_category;
+
+ ScriptAddOptions(const TypeSummaryImpl::Flags &flags, bool regx,
+ const ConstString &name, std::string catg)
+ : m_flags(flags), m_regex(regx), m_name(name), m_category(catg) {}
+
+ typedef std::shared_ptr<ScriptAddOptions> SharedPointer;
+};
+
+class SynthAddOptions {
+public:
+ bool m_skip_pointers;
+ bool m_skip_references;
+ bool m_cascade;
+ bool m_regex;
+ StringList m_target_types;
+ std::string m_category;
+
+ SynthAddOptions(bool sptr, bool sref, bool casc, bool regx, std::string catg)
+ : m_skip_pointers(sptr), m_skip_references(sref), m_cascade(casc),
+ m_regex(regx), m_target_types(), m_category(catg) {}
+
+ typedef std::shared_ptr<SynthAddOptions> SharedPointer;
+};
+
+static bool WarnOnPotentialUnquotedUnsignedType(Args &command,
+ CommandReturnObject &result) {
+ for (unsigned idx = 0; idx < command.GetArgumentCount(); idx++) {
+ const char *arg = command.GetArgumentAtIndex(idx);
+ if (idx + 1 < command.GetArgumentCount()) {
+ if (arg && 0 == strcmp(arg, "unsigned")) {
+ const char *next = command.GetArgumentAtIndex(idx + 1);
+ if (next && (0 == strcmp(next, "int") || 0 == strcmp(next, "short") ||
+ 0 == strcmp(next, "char") || 0 == strcmp(next, "long"))) {
+ result.AppendWarningWithFormat("%s %s being treated as two types. if "
+ "you meant the combined type name use "
+ "quotes, as in \"%s %s\"\n",
+ arg, next, arg, next);
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+class CommandObjectTypeSummaryAdd : public CommandObjectParsed,
+ public IOHandlerDelegateMultiline {
+private:
+ class CommandOptions : public Options {
+ public:
+ CommandOptions(CommandInterpreter &interpreter) : Options() {}
+
+ ~CommandOptions() override = default;
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override;
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override;
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+
TypeSummaryImpl::Flags m_flags;
- StringList m_target_types;
bool m_regex;
+ std::string m_format_string;
ConstString m_name;
+ std::string m_python_script;
+ std::string m_python_function;
+ bool m_is_add_script;
std::string m_category;
-
- ScriptAddOptions(const TypeSummaryImpl::Flags& flags,
- bool regx,
- const ConstString& name,
- std::string catg) :
- m_flags(flags),
- m_regex(regx),
- m_name(name),
- m_category(catg)
- {
- }
-
- typedef std::shared_ptr<ScriptAddOptions> SharedPointer;
-};
+ };
-class SynthAddOptions
-{
-public:
- bool m_skip_pointers;
- bool m_skip_references;
- bool m_cascade;
- bool m_regex;
- StringList m_target_types;
- std::string m_category;
-
- SynthAddOptions(bool sptr,
- bool sref,
- bool casc,
- bool regx,
- std::string catg) :
- m_skip_pointers(sptr),
- m_skip_references(sref),
- m_cascade(casc),
- m_regex(regx),
- m_target_types(),
- m_category(catg)
- {
- }
-
- typedef std::shared_ptr<SynthAddOptions> SharedPointer;
-};
+ CommandOptions m_options;
-static bool
-WarnOnPotentialUnquotedUnsignedType (Args& command, CommandReturnObject &result)
-{
- for (unsigned idx = 0; idx < command.GetArgumentCount(); idx++)
- {
- const char* arg = command.GetArgumentAtIndex(idx);
- if (idx+1 < command.GetArgumentCount())
- {
- if (arg && 0 == strcmp(arg,"unsigned"))
- {
- const char* next = command.GetArgumentAtIndex(idx+1);
- if (next &&
- (0 == strcmp(next, "int") ||
- 0 == strcmp(next, "short") ||
- 0 == strcmp(next, "char") ||
- 0 == strcmp(next, "long")))
- {
- result.AppendWarningWithFormat("%s %s being treated as two types. if you meant the combined type name use quotes, as in \"%s %s\"\n",
- arg,next,arg,next);
- return true;
- }
- }
- }
- }
- return false;
-}
+ Options *GetOptions() override { return &m_options; }
-class CommandObjectTypeSummaryAdd :
- public CommandObjectParsed,
- public IOHandlerDelegateMultiline
-{
-private:
- class CommandOptions : public Options
- {
- public:
- CommandOptions (CommandInterpreter &interpreter) :
- Options()
- {
- }
+ bool Execute_ScriptSummary(Args &command, CommandReturnObject &result);
- ~CommandOptions() override = default;
+ bool Execute_StringSummary(Args &command, CommandReturnObject &result);
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override;
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override;
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
-
- TypeSummaryImpl::Flags m_flags;
- bool m_regex;
- std::string m_format_string;
- ConstString m_name;
- std::string m_python_script;
- std::string m_python_function;
- bool m_is_add_script;
- std::string m_category;
- };
-
- CommandOptions m_options;
-
- Options *
- GetOptions () override
- {
- return &m_options;
- }
-
- bool
- Execute_ScriptSummary (Args& command, CommandReturnObject &result);
-
- bool
- Execute_StringSummary (Args& command, CommandReturnObject &result);
-
public:
- enum SummaryFormatType
- {
- eRegularSummary,
- eRegexSummary,
- eNamedSummary
- };
-
- CommandObjectTypeSummaryAdd (CommandInterpreter &interpreter);
+ enum SummaryFormatType { eRegularSummary, eRegexSummary, eNamedSummary };
- ~CommandObjectTypeSummaryAdd() override = default;
+ CommandObjectTypeSummaryAdd(CommandInterpreter &interpreter);
- void
- IOHandlerActivated (IOHandler &io_handler) override
- {
- static const char *g_summary_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
+ ~CommandObjectTypeSummaryAdd() override = default;
+
+ void IOHandlerActivated(IOHandler &io_handler) override {
+ static const char *g_summary_addreader_instructions =
+ "Enter your Python command(s). Type 'DONE' to end.\n"
"def function (valobj,internal_dict):\n"
- " \"\"\"valobj: an SBValue which you want to provide a summary for\n"
+ " \"\"\"valobj: an SBValue which you want to provide a summary "
+ "for\n"
" internal_dict: an LLDB support object not to be used\"\"\"\n";
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
- if (output_sp)
- {
- output_sp->PutCString(g_summary_addreader_instructions);
- output_sp->Flush();
- }
- }
+ StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ if (output_sp) {
+ output_sp->PutCString(g_summary_addreader_instructions);
+ output_sp->Flush();
+ }
+ }
+
+ void IOHandlerInputComplete(IOHandler &io_handler,
+ std::string &data) override {
+ StreamFileSP error_sp = io_handler.GetErrorStreamFile();
- void
- IOHandlerInputComplete (IOHandler &io_handler, std::string &data) override
- {
- StreamFileSP error_sp = io_handler.GetErrorStreamFile();
-
#ifndef LLDB_DISABLE_PYTHON
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
- if (interpreter)
- {
- StringList lines;
- lines.SplitIntoLines(data);
- if (lines.GetSize() > 0)
- {
- ScriptAddOptions *options_ptr = ((ScriptAddOptions*)io_handler.GetUserData());
- if (options_ptr)
- {
- ScriptAddOptions::SharedPointer options(options_ptr); // this will ensure that we get rid of the pointer when going out of scope
-
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
- if (interpreter)
- {
- std::string funct_name_str;
- if (interpreter->GenerateTypeScriptFunction (lines, funct_name_str))
- {
- if (funct_name_str.empty())
- {
- error_sp->Printf ("unable to obtain a valid function name from the script interpreter.\n");
- error_sp->Flush();
- }
- else
- {
- // now I have a valid function name, let's add this as script for every type in the list
-
- TypeSummaryImplSP script_format;
- script_format.reset(new ScriptSummaryFormat(options->m_flags,
- funct_name_str.c_str(),
- lines.CopyList(" ").c_str()));
-
- Error error;
-
- for (size_t i = 0; i < options->m_target_types.GetSize(); i++)
- {
- const char *type_name = options->m_target_types.GetStringAtIndex(i);
- CommandObjectTypeSummaryAdd::AddSummary(ConstString(type_name),
- script_format,
- (options->m_regex ? CommandObjectTypeSummaryAdd::eRegexSummary : CommandObjectTypeSummaryAdd::eRegularSummary),
- options->m_category,
- &error);
- if (error.Fail())
- {
- error_sp->Printf ("error: %s", error.AsCString());
- error_sp->Flush();
- }
- }
-
- if (options->m_name)
- {
- CommandObjectTypeSummaryAdd::AddSummary (options->m_name,
- script_format,
- CommandObjectTypeSummaryAdd::eNamedSummary,
- options->m_category,
- &error);
- if (error.Fail())
- {
- CommandObjectTypeSummaryAdd::AddSummary (options->m_name,
- script_format,
- CommandObjectTypeSummaryAdd::eNamedSummary,
- options->m_category,
- &error);
- if (error.Fail())
- {
- error_sp->Printf ("error: %s", error.AsCString());
- error_sp->Flush();
- }
- }
- else
- {
- error_sp->Printf ("error: %s", error.AsCString());
- error_sp->Flush();
- }
- }
- else
- {
- if (error.AsCString())
- {
- error_sp->Printf ("error: %s", error.AsCString());
- error_sp->Flush();
- }
- }
- }
- }
- else
- {
- error_sp->Printf ("error: unable to generate a function.\n");
- error_sp->Flush();
- }
- }
- else
- {
- error_sp->Printf ("error: no script interpreter.\n");
- error_sp->Flush();
- }
+ ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ if (interpreter) {
+ StringList lines;
+ lines.SplitIntoLines(data);
+ if (lines.GetSize() > 0) {
+ ScriptAddOptions *options_ptr =
+ ((ScriptAddOptions *)io_handler.GetUserData());
+ if (options_ptr) {
+ ScriptAddOptions::SharedPointer options(
+ options_ptr); // this will ensure that we get rid of the pointer
+ // when going out of scope
+
+ ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ if (interpreter) {
+ std::string funct_name_str;
+ if (interpreter->GenerateTypeScriptFunction(lines,
+ funct_name_str)) {
+ if (funct_name_str.empty()) {
+ error_sp->Printf("unable to obtain a valid function name from "
+ "the script interpreter.\n");
+ error_sp->Flush();
+ } else {
+ // now I have a valid function name, let's add this as script
+ // for every type in the list
+
+ TypeSummaryImplSP script_format;
+ script_format.reset(new ScriptSummaryFormat(
+ options->m_flags, funct_name_str.c_str(),
+ lines.CopyList(" ").c_str()));
+
+ Error error;
+
+ for (size_t i = 0; i < options->m_target_types.GetSize(); i++) {
+ const char *type_name =
+ options->m_target_types.GetStringAtIndex(i);
+ CommandObjectTypeSummaryAdd::AddSummary(
+ ConstString(type_name), script_format,
+ (options->m_regex
+ ? CommandObjectTypeSummaryAdd::eRegexSummary
+ : CommandObjectTypeSummaryAdd::eRegularSummary),
+ options->m_category, &error);
+ if (error.Fail()) {
+ error_sp->Printf("error: %s", error.AsCString());
+ error_sp->Flush();
+ }
}
- else
- {
- error_sp->Printf ("error: internal synchronization information missing or invalid.\n");
+
+ if (options->m_name) {
+ CommandObjectTypeSummaryAdd::AddSummary(
+ options->m_name, script_format,
+ CommandObjectTypeSummaryAdd::eNamedSummary,
+ options->m_category, &error);
+ if (error.Fail()) {
+ CommandObjectTypeSummaryAdd::AddSummary(
+ options->m_name, script_format,
+ CommandObjectTypeSummaryAdd::eNamedSummary,
+ options->m_category, &error);
+ if (error.Fail()) {
+ error_sp->Printf("error: %s", error.AsCString());
+ error_sp->Flush();
+ }
+ } else {
+ error_sp->Printf("error: %s", error.AsCString());
+ error_sp->Flush();
+ }
+ } else {
+ if (error.AsCString()) {
+ error_sp->Printf("error: %s", error.AsCString());
error_sp->Flush();
+ }
}
+ }
+ } else {
+ error_sp->Printf("error: unable to generate a function.\n");
+ error_sp->Flush();
}
- else
- {
- error_sp->Printf ("error: empty function, didn't add python command.\n");
- error_sp->Flush();
- }
- }
- else
- {
- error_sp->Printf ("error: script interpreter missing, didn't add python command.\n");
+ } else {
+ error_sp->Printf("error: no script interpreter.\n");
error_sp->Flush();
- }
-#endif // LLDB_DISABLE_PYTHON
- io_handler.SetIsDone(true);
+ }
+ } else {
+ error_sp->Printf("error: internal synchronization information "
+ "missing or invalid.\n");
+ error_sp->Flush();
+ }
+ } else {
+ error_sp->Printf("error: empty function, didn't add python command.\n");
+ error_sp->Flush();
+ }
+ } else {
+ error_sp->Printf(
+ "error: script interpreter missing, didn't add python command.\n");
+ error_sp->Flush();
}
-
- static bool
- AddSummary(ConstString type_name,
- lldb::TypeSummaryImplSP entry,
- SummaryFormatType type,
- std::string category,
- Error* error = nullptr);
+#endif // LLDB_DISABLE_PYTHON
+ io_handler.SetIsDone(true);
+ }
+
+ static bool AddSummary(ConstString type_name, lldb::TypeSummaryImplSP entry,
+ SummaryFormatType type, std::string category,
+ Error *error = nullptr);
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override;
+ bool DoExecute(Args &command, CommandReturnObject &result) override;
};
-static const char *g_synth_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
-"You must define a Python class with these methods:\n"
-" def __init__(self, valobj, dict):\n"
-" def num_children(self):\n"
-" def get_child_at_index(self, index):\n"
-" def get_child_index(self, name):\n"
-" def update(self):\n"
-" '''Optional'''\n"
-"class synthProvider:\n";
-
-class CommandObjectTypeSynthAdd :
- public CommandObjectParsed,
- public IOHandlerDelegateMultiline
-{
+static const char *g_synth_addreader_instructions =
+ "Enter your Python command(s). Type 'DONE' to end.\n"
+ "You must define a Python class with these methods:\n"
+ " def __init__(self, valobj, dict):\n"
+ " def num_children(self):\n"
+ " def get_child_at_index(self, index):\n"
+ " def get_child_index(self, name):\n"
+ " def update(self):\n"
+ " '''Optional'''\n"
+ "class synthProvider:\n";
+
+class CommandObjectTypeSynthAdd : public CommandObjectParsed,
+ public IOHandlerDelegateMultiline {
private:
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options()
- {
- }
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options() {}
+
+ ~CommandOptions() override = default;
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+ bool success;
+
+ switch (short_option) {
+ case 'C':
+ m_cascade = Args::StringToBoolean(option_arg, true, &success);
+ if (!success)
+ error.SetErrorStringWithFormat("invalid value for cascade: %s",
+ option_arg);
+ break;
+ case 'P':
+ handwrite_python = true;
+ break;
+ case 'l':
+ m_class_name = std::string(option_arg);
+ is_class_based = true;
+ break;
+ case 'p':
+ m_skip_pointers = true;
+ break;
+ case 'r':
+ m_skip_references = true;
+ break;
+ case 'w':
+ m_category = std::string(option_arg);
+ break;
+ case 'x':
+ m_regex = true;
+ break;
+ default:
+ error.SetErrorStringWithFormat("unrecognized option '%c'",
+ short_option);
+ break;
+ }
+
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_cascade = true;
+ m_class_name = "";
+ m_skip_pointers = false;
+ m_skip_references = false;
+ m_category = "default";
+ is_class_based = false;
+ handwrite_python = false;
+ m_regex = false;
+ }
- ~CommandOptions() override = default;
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+
+ bool m_cascade;
+ bool m_skip_references;
+ bool m_skip_pointers;
+ std::string m_class_name;
+ bool m_input_python;
+ std::string m_category;
+ bool is_class_based;
+ bool handwrite_python;
+ bool m_regex;
+ };
+
+ CommandOptions m_options;
+
+ Options *GetOptions() override { return &m_options; }
+
+ bool Execute_HandwritePython(Args &command, CommandReturnObject &result);
+
+ bool Execute_PythonClass(Args &command, CommandReturnObject &result);
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
- bool success;
-
- switch (short_option)
- {
- case 'C':
- m_cascade = Args::StringToBoolean(option_arg, true, &success);
- if (!success)
- error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg);
- break;
- case 'P':
- handwrite_python = true;
- break;
- case 'l':
- m_class_name = std::string(option_arg);
- is_class_based = true;
- break;
- case 'p':
- m_skip_pointers = true;
- break;
- case 'r':
- m_skip_references = true;
- break;
- case 'w':
- m_category = std::string(option_arg);
- break;
- case 'x':
- m_regex = true;
- break;
- default:
- error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
- break;
- }
-
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_cascade = true;
- m_class_name = "";
- m_skip_pointers = false;
- m_skip_references = false;
- m_category = "default";
- is_class_based = false;
- handwrite_python = false;
- m_regex = false;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
-
- bool m_cascade;
- bool m_skip_references;
- bool m_skip_pointers;
- std::string m_class_name;
- bool m_input_python;
- std::string m_category;
- bool is_class_based;
- bool handwrite_python;
- bool m_regex;
- };
-
- CommandOptions m_options;
-
- Options *
- GetOptions () override
- {
- return &m_options;
- }
-
- bool
- Execute_HandwritePython (Args& command, CommandReturnObject &result);
-
- bool
- Execute_PythonClass (Args& command, CommandReturnObject &result);
-
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- WarnOnPotentialUnquotedUnsignedType(command, result);
-
- if (m_options.handwrite_python)
- return Execute_HandwritePython(command, result);
- else if (m_options.is_class_based)
- return Execute_PythonClass(command, result);
- else
- {
- result.AppendError("must either provide a children list, a Python class name, or use -P and type a Python class line-by-line");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
-
- void
- IOHandlerActivated (IOHandler &io_handler) override
- {
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
- if (output_sp)
- {
- output_sp->PutCString(g_synth_addreader_instructions);
- output_sp->Flush();
- }
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ WarnOnPotentialUnquotedUnsignedType(command, result);
+
+ if (m_options.handwrite_python)
+ return Execute_HandwritePython(command, result);
+ else if (m_options.is_class_based)
+ return Execute_PythonClass(command, result);
+ else {
+ result.AppendError("must either provide a children list, a Python class "
+ "name, or use -P and type a Python class "
+ "line-by-line");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+
+ void IOHandlerActivated(IOHandler &io_handler) override {
+ StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ if (output_sp) {
+ output_sp->PutCString(g_synth_addreader_instructions);
+ output_sp->Flush();
+ }
+ }
+
+ void IOHandlerInputComplete(IOHandler &io_handler,
+ std::string &data) override {
+ StreamFileSP error_sp = io_handler.GetErrorStreamFile();
- void
- IOHandlerInputComplete (IOHandler &io_handler, std::string &data) override
- {
- StreamFileSP error_sp = io_handler.GetErrorStreamFile();
-
#ifndef LLDB_DISABLE_PYTHON
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
- if (interpreter)
- {
- StringList lines;
- lines.SplitIntoLines(data);
- if (lines.GetSize() > 0)
- {
- SynthAddOptions *options_ptr = ((SynthAddOptions*)io_handler.GetUserData());
- if (options_ptr)
- {
- SynthAddOptions::SharedPointer options(options_ptr); // this will ensure that we get rid of the pointer when going out of scope
-
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
- if (interpreter)
- {
- std::string class_name_str;
- if (interpreter->GenerateTypeSynthClass (lines, class_name_str))
- {
- if (class_name_str.empty())
- {
- error_sp->Printf ("error: unable to obtain a proper name for the class.\n");
- error_sp->Flush();
- }
- else
- {
- // everything should be fine now, let's add the synth provider class
-
- SyntheticChildrenSP synth_provider;
- synth_provider.reset(new ScriptedSyntheticChildren(SyntheticChildren::Flags().SetCascades(options->m_cascade).
- SetSkipPointers(options->m_skip_pointers).
- SetSkipReferences(options->m_skip_references),
- class_name_str.c_str()));
-
-
- lldb::TypeCategoryImplSP category;
- DataVisualization::Categories::GetCategory(ConstString(options->m_category.c_str()), category);
-
- Error error;
-
- for (size_t i = 0; i < options->m_target_types.GetSize(); i++)
- {
- const char *type_name = options->m_target_types.GetStringAtIndex(i);
- ConstString const_type_name(type_name);
- if (const_type_name)
- {
- if (!CommandObjectTypeSynthAdd::AddSynth(const_type_name,
- synth_provider,
- options->m_regex ? CommandObjectTypeSynthAdd::eRegexSynth : CommandObjectTypeSynthAdd::eRegularSynth,
- options->m_category,
- &error))
- {
- error_sp->Printf("error: %s\n", error.AsCString());
- error_sp->Flush();
- break;
- }
- }
- else
- {
- error_sp->Printf ("error: invalid type name.\n");
- error_sp->Flush();
- break;
- }
- }
- }
- }
- else
- {
- error_sp->Printf ("error: unable to generate a class.\n");
- error_sp->Flush();
- }
- }
- else
- {
- error_sp->Printf ("error: no script interpreter.\n");
- error_sp->Flush();
+ ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ if (interpreter) {
+ StringList lines;
+ lines.SplitIntoLines(data);
+ if (lines.GetSize() > 0) {
+ SynthAddOptions *options_ptr =
+ ((SynthAddOptions *)io_handler.GetUserData());
+ if (options_ptr) {
+ SynthAddOptions::SharedPointer options(
+ options_ptr); // this will ensure that we get rid of the pointer
+ // when going out of scope
+
+ ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ if (interpreter) {
+ std::string class_name_str;
+ if (interpreter->GenerateTypeSynthClass(lines, class_name_str)) {
+ if (class_name_str.empty()) {
+ error_sp->Printf(
+ "error: unable to obtain a proper name for the class.\n");
+ error_sp->Flush();
+ } else {
+ // everything should be fine now, let's add the synth provider
+ // class
+
+ SyntheticChildrenSP synth_provider;
+ synth_provider.reset(new ScriptedSyntheticChildren(
+ SyntheticChildren::Flags()
+ .SetCascades(options->m_cascade)
+ .SetSkipPointers(options->m_skip_pointers)
+ .SetSkipReferences(options->m_skip_references),
+ class_name_str.c_str()));
+
+ lldb::TypeCategoryImplSP category;
+ DataVisualization::Categories::GetCategory(
+ ConstString(options->m_category.c_str()), category);
+
+ Error error;
+
+ for (size_t i = 0; i < options->m_target_types.GetSize(); i++) {
+ const char *type_name =
+ options->m_target_types.GetStringAtIndex(i);
+ ConstString const_type_name(type_name);
+ if (const_type_name) {
+ if (!CommandObjectTypeSynthAdd::AddSynth(
+ const_type_name, synth_provider,
+ options->m_regex
+ ? CommandObjectTypeSynthAdd::eRegexSynth
+ : CommandObjectTypeSynthAdd::eRegularSynth,
+ options->m_category, &error)) {
+ error_sp->Printf("error: %s\n", error.AsCString());
+ error_sp->Flush();
+ break;
}
- }
- else
- {
- error_sp->Printf ("error: internal synchronization data missing.\n");
+ } else {
+ error_sp->Printf("error: invalid type name.\n");
error_sp->Flush();
+ break;
+ }
}
+ }
+ } else {
+ error_sp->Printf("error: unable to generate a class.\n");
+ error_sp->Flush();
}
- else
- {
- error_sp->Printf ("error: empty function, didn't add python command.\n");
- error_sp->Flush();
- }
- }
- else
- {
- error_sp->Printf ("error: script interpreter missing, didn't add python command.\n");
+ } else {
+ error_sp->Printf("error: no script interpreter.\n");
error_sp->Flush();
- }
-
-#endif // LLDB_DISABLE_PYTHON
- io_handler.SetIsDone(true);
+ }
+ } else {
+ error_sp->Printf("error: internal synchronization data missing.\n");
+ error_sp->Flush();
+ }
+ } else {
+ error_sp->Printf("error: empty function, didn't add python command.\n");
+ error_sp->Flush();
+ }
+ } else {
+ error_sp->Printf(
+ "error: script interpreter missing, didn't add python command.\n");
+ error_sp->Flush();
}
+#endif // LLDB_DISABLE_PYTHON
+ io_handler.SetIsDone(true);
+ }
+
public:
- enum SynthFormatType
- {
- eRegularSynth,
- eRegexSynth
- };
-
- CommandObjectTypeSynthAdd (CommandInterpreter &interpreter);
+ enum SynthFormatType { eRegularSynth, eRegexSynth };
+
+ CommandObjectTypeSynthAdd(CommandInterpreter &interpreter);
- ~CommandObjectTypeSynthAdd() override = default;
+ ~CommandObjectTypeSynthAdd() override = default;
- static bool
- AddSynth(ConstString type_name,
- lldb::SyntheticChildrenSP entry,
- SynthFormatType type,
- std::string category_name,
- Error* error);
+ static bool AddSynth(ConstString type_name, lldb::SyntheticChildrenSP entry,
+ SynthFormatType type, std::string category_name,
+ Error *error);
};
//-------------------------------------------------------------------------
// CommandObjectTypeFormatAdd
//-------------------------------------------------------------------------
-class CommandObjectTypeFormatAdd : public CommandObjectParsed
-{
+class CommandObjectTypeFormatAdd : public CommandObjectParsed {
private:
- class CommandOptions : public OptionGroup
- {
- public:
- CommandOptions () :
- OptionGroup()
- {
- }
+ class CommandOptions : public OptionGroup {
+ public:
+ CommandOptions() : OptionGroup() {}
+
+ ~CommandOptions() override = default;
+
+ uint32_t GetNumDefinitions() override;
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_cascade = true;
+ m_skip_pointers = false;
+ m_skip_references = false;
+ m_regex = false;
+ m_category.assign("default");
+ m_custom_type_name.clear();
+ }
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_value,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = g_option_table[option_idx].short_option;
+ bool success;
+
+ switch (short_option) {
+ case 'C':
+ m_cascade = Args::StringToBoolean(option_value, true, &success);
+ if (!success)
+ error.SetErrorStringWithFormat("invalid value for cascade: %s",
+ option_value);
+ break;
+ case 'p':
+ m_skip_pointers = true;
+ break;
+ case 'w':
+ m_category.assign(option_value);
+ break;
+ case 'r':
+ m_skip_references = true;
+ break;
+ case 'x':
+ m_regex = true;
+ break;
+ case 't':
+ m_custom_type_name.assign(option_value);
+ break;
+ default:
+ error.SetErrorStringWithFormat("unrecognized option '%c'",
+ short_option);
+ break;
+ }
- ~CommandOptions() override = default;
+ return error;
+ }
- uint32_t
- GetNumDefinitions () override;
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_cascade = true;
- m_skip_pointers = false;
- m_skip_references = false;
- m_regex = false;
- m_category.assign("default");
- m_custom_type_name.clear();
- }
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+
+ bool m_cascade;
+ bool m_skip_references;
+ bool m_skip_pointers;
+ bool m_regex;
+ std::string m_category;
+ std::string m_custom_type_name;
+ };
+
+ OptionGroupOptions m_option_group;
+ OptionGroupFormat m_format_options;
+ CommandOptions m_command_options;
+
+ Options *GetOptions() override { return &m_option_group; }
- Error
- SetOptionValue(uint32_t option_idx,
- const char *option_value,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = g_option_table[option_idx].short_option;
- bool success;
-
- switch (short_option)
- {
- case 'C':
- m_cascade = Args::StringToBoolean(option_value, true, &success);
- if (!success)
- error.SetErrorStringWithFormat("invalid value for cascade: %s", option_value);
- break;
- case 'p':
- m_skip_pointers = true;
- break;
- case 'w':
- m_category.assign(option_value);
- break;
- case 'r':
- m_skip_references = true;
- break;
- case 'x':
- m_regex = true;
- break;
- case 't':
- m_custom_type_name.assign(option_value);
- break;
- default:
- error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
- break;
- }
-
- return error;
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
-
- bool m_cascade;
- bool m_skip_references;
- bool m_skip_pointers;
- bool m_regex;
- std::string m_category;
- std::string m_custom_type_name;
- };
-
- OptionGroupOptions m_option_group;
- OptionGroupFormat m_format_options;
- CommandOptions m_command_options;
-
- Options *
- GetOptions () override
- {
- return &m_option_group;
- }
-
public:
- CommandObjectTypeFormatAdd (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "type format add",
- "Add a new formatting style for a type.",
- nullptr),
- m_option_group(),
- m_format_options(eFormatInvalid),
- m_command_options()
- {
- CommandArgumentEntry type_arg;
- CommandArgumentData type_style_arg;
-
- type_style_arg.arg_type = eArgTypeName;
- type_style_arg.arg_repetition = eArgRepeatPlus;
-
- type_arg.push_back (type_style_arg);
-
- m_arguments.push_back (type_arg);
-
- SetHelpLong(
-R"(
+ CommandObjectTypeFormatAdd(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "type format add",
+ "Add a new formatting style for a type.", nullptr),
+ m_option_group(), m_format_options(eFormatInvalid),
+ m_command_options() {
+ CommandArgumentEntry type_arg;
+ CommandArgumentData type_style_arg;
+
+ type_style_arg.arg_type = eArgTypeName;
+ type_style_arg.arg_repetition = eArgRepeatPlus;
+
+ type_arg.push_back(type_style_arg);
+
+ m_arguments.push_back(type_arg);
+
+ SetHelpLong(
+ R"(
The following examples of 'type format add' refer to this code snippet for context:
typedef int Aint;
@@ -754,8 +615,10 @@ Adding default formatting:
(lldb) type format add -f hex AInt
(lldb) frame variable iy
-)" " Produces hexadecimal display of iy, because no formatter is available for Bint and \
-the one for Aint is used instead." R"(
+)"
+ " Produces hexadecimal display of iy, because no formatter is available for Bint and \
+the one for Aint is used instead."
+ R"(
To prevent this use the cascade option '-C no' to prevent evaluation of typedef chains:
@@ -766,99 +629,97 @@ Similar reasoning applies to this:
(lldb) type format add -f hex -C no float -p
-)" " All float values and float references are now formatted as hexadecimal, but not \
-pointers to floats. Nor will it change the default display for Afloat and Bfloat objects."
- );
-
- // Add the "--format" to all options groups
- m_option_group.Append (&m_format_options, OptionGroupFormat::OPTION_GROUP_FORMAT, LLDB_OPT_SET_1);
- m_option_group.Append (&m_command_options);
- m_option_group.Finalize();
- }
+)"
+ " All float values and float references are now formatted as hexadecimal, but not \
+pointers to floats. Nor will it change the default display for Afloat and Bfloat objects.");
+
+ // Add the "--format" to all options groups
+ m_option_group.Append(&m_format_options,
+ OptionGroupFormat::OPTION_GROUP_FORMAT,
+ LLDB_OPT_SET_1);
+ m_option_group.Append(&m_command_options);
+ m_option_group.Finalize();
+ }
- ~CommandObjectTypeFormatAdd() override = default;
+ ~CommandObjectTypeFormatAdd() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- const size_t argc = command.GetArgumentCount();
-
- if (argc < 1)
- {
- result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- const Format format = m_format_options.GetFormat();
- if (format == eFormatInvalid && m_command_options.m_custom_type_name.empty())
- {
- result.AppendErrorWithFormat ("%s needs a valid format.\n", m_cmd_name.c_str());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- TypeFormatImplSP entry;
-
- if (m_command_options.m_custom_type_name.empty())
- entry.reset(new TypeFormatImpl_Format(format,
- TypeFormatImpl::Flags().SetCascades(m_command_options.m_cascade).
- SetSkipPointers(m_command_options.m_skip_pointers).
- SetSkipReferences(m_command_options.m_skip_references)));
- else
- entry.reset(new TypeFormatImpl_EnumType(ConstString(m_command_options.m_custom_type_name.c_str()),
- TypeFormatImpl::Flags().SetCascades(m_command_options.m_cascade).
- SetSkipPointers(m_command_options.m_skip_pointers).
- SetSkipReferences(m_command_options.m_skip_references)));
-
- // now I have a valid format, let's add it to every type
-
- TypeCategoryImplSP category_sp;
- DataVisualization::Categories::GetCategory(ConstString(m_command_options.m_category), category_sp);
- if (!category_sp)
- return false;
-
- WarnOnPotentialUnquotedUnsignedType(command, result);
-
- for (size_t i = 0; i < argc; i++)
- {
- const char* typeA = command.GetArgumentAtIndex(i);
- ConstString typeCS(typeA);
- if (typeCS)
- {
- if (m_command_options.m_regex)
- {
- RegularExpressionSP typeRX(new RegularExpression());
- if (!typeRX->Compile(typeCS.GetCString()))
- {
- result.AppendError("regex format error (maybe this is not really a regex?)");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- category_sp->GetRegexTypeSummariesContainer()->Delete(typeCS);
- category_sp->GetRegexTypeFormatsContainer()->Add(typeRX, entry);
- }
- else
- category_sp->GetTypeFormatsContainer()->Add(typeCS, entry);
- }
- else
- {
- result.AppendError("empty typenames not allowed");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
-
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- return result.Succeeded();
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ const size_t argc = command.GetArgumentCount();
+
+ if (argc < 1) {
+ result.AppendErrorWithFormat("%s takes one or more args.\n",
+ m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ const Format format = m_format_options.GetFormat();
+ if (format == eFormatInvalid &&
+ m_command_options.m_custom_type_name.empty()) {
+ result.AppendErrorWithFormat("%s needs a valid format.\n",
+ m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ TypeFormatImplSP entry;
+
+ if (m_command_options.m_custom_type_name.empty())
+ entry.reset(new TypeFormatImpl_Format(
+ format, TypeFormatImpl::Flags()
+ .SetCascades(m_command_options.m_cascade)
+ .SetSkipPointers(m_command_options.m_skip_pointers)
+ .SetSkipReferences(m_command_options.m_skip_references)));
+ else
+ entry.reset(new TypeFormatImpl_EnumType(
+ ConstString(m_command_options.m_custom_type_name.c_str()),
+ TypeFormatImpl::Flags()
+ .SetCascades(m_command_options.m_cascade)
+ .SetSkipPointers(m_command_options.m_skip_pointers)
+ .SetSkipReferences(m_command_options.m_skip_references)));
+
+ // now I have a valid format, let's add it to every type
+
+ TypeCategoryImplSP category_sp;
+ DataVisualization::Categories::GetCategory(
+ ConstString(m_command_options.m_category), category_sp);
+ if (!category_sp)
+ return false;
+
+ WarnOnPotentialUnquotedUnsignedType(command, result);
+
+ for (size_t i = 0; i < argc; i++) {
+ const char *typeA = command.GetArgumentAtIndex(i);
+ ConstString typeCS(typeA);
+ if (typeCS) {
+ if (m_command_options.m_regex) {
+ RegularExpressionSP typeRX(new RegularExpression());
+ if (!typeRX->Compile(typeCS.GetCString())) {
+ result.AppendError(
+ "regex format error (maybe this is not really a regex?)");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ category_sp->GetRegexTypeSummariesContainer()->Delete(typeCS);
+ category_sp->GetRegexTypeFormatsContainer()->Add(typeRX, entry);
+ } else
+ category_sp->GetTypeFormatsContainer()->Add(typeCS, entry);
+ } else {
+ result.AppendError("empty typenames not allowed");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
}
+
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ return result.Succeeded();
+ }
};
-OptionDefinition
-CommandObjectTypeFormatAdd::CommandOptions::g_option_table[] =
-{
- // clang-format off
+OptionDefinition CommandObjectTypeFormatAdd::CommandOptions::g_option_table[] =
+ {
+ // clang-format off
{LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Add this to the given category instead of the default one."},
{LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
{LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
@@ -866,615 +727,506 @@ CommandObjectTypeFormatAdd::CommandOptio
{LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Type names are actually regular expressions."},
{LLDB_OPT_SET_2, false, "type", 't', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Format variables as if they were of this type."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
-uint32_t
-CommandObjectTypeFormatAdd::CommandOptions::GetNumDefinitions ()
-{
- return sizeof(g_option_table) / sizeof (OptionDefinition);
+uint32_t CommandObjectTypeFormatAdd::CommandOptions::GetNumDefinitions() {
+ return sizeof(g_option_table) / sizeof(OptionDefinition);
}
-class CommandObjectTypeFormatterDelete : public CommandObjectParsed
-{
+class CommandObjectTypeFormatterDelete : public CommandObjectParsed {
protected:
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options()
- {
- }
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options() {}
- ~CommandOptions() override = default;
+ ~CommandOptions() override = default;
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'a':
- m_delete_all = true;
- break;
- case 'w':
- m_category = std::string(option_arg);
- break;
- case 'l':
- m_language = Language::GetLanguageTypeFromString(option_arg);
- break;
- default:
- error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
- break;
- }
-
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_delete_all = false;
- m_category = "default";
- m_language = lldb::eLanguageTypeUnknown;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
-
- bool m_delete_all;
- std::string m_category;
- lldb::LanguageType m_language;
- };
-
- CommandOptions m_options;
- uint32_t m_formatter_kind_mask;
-
- Options *
- GetOptions () override
- {
- return &m_options;
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option) {
+ case 'a':
+ m_delete_all = true;
+ break;
+ case 'w':
+ m_category = std::string(option_arg);
+ break;
+ case 'l':
+ m_language = Language::GetLanguageTypeFromString(option_arg);
+ break;
+ default:
+ error.SetErrorStringWithFormat("unrecognized option '%c'",
+ short_option);
+ break;
+ }
+
+ return error;
}
-
-public:
- CommandObjectTypeFormatterDelete (CommandInterpreter &interpreter,
- uint32_t formatter_kind_mask,
- const char* name,
- const char* help) :
- CommandObjectParsed(interpreter,
- name,
- help,
- nullptr),
- m_options(),
- m_formatter_kind_mask(formatter_kind_mask)
- {
- CommandArgumentEntry type_arg;
- CommandArgumentData type_style_arg;
-
- type_style_arg.arg_type = eArgTypeName;
- type_style_arg.arg_repetition = eArgRepeatPlain;
-
- type_arg.push_back (type_style_arg);
-
- m_arguments.push_back (type_arg);
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_delete_all = false;
+ m_category = "default";
+ m_language = lldb::eLanguageTypeUnknown;
}
- ~CommandObjectTypeFormatterDelete() override = default;
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+
+ bool m_delete_all;
+ std::string m_category;
+ lldb::LanguageType m_language;
+ };
+
+ CommandOptions m_options;
+ uint32_t m_formatter_kind_mask;
+
+ Options *GetOptions() override { return &m_options; }
+
+public:
+ CommandObjectTypeFormatterDelete(CommandInterpreter &interpreter,
+ uint32_t formatter_kind_mask,
+ const char *name, const char *help)
+ : CommandObjectParsed(interpreter, name, help, nullptr), m_options(),
+ m_formatter_kind_mask(formatter_kind_mask) {
+ CommandArgumentEntry type_arg;
+ CommandArgumentData type_style_arg;
+
+ type_style_arg.arg_type = eArgTypeName;
+ type_style_arg.arg_repetition = eArgRepeatPlain;
+
+ type_arg.push_back(type_style_arg);
+
+ m_arguments.push_back(type_arg);
+ }
+
+ ~CommandObjectTypeFormatterDelete() override = default;
protected:
- virtual bool
- FormatterSpecificDeletion (ConstString typeCS)
- {
- return false;
+ virtual bool FormatterSpecificDeletion(ConstString typeCS) { return false; }
+
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ const size_t argc = command.GetArgumentCount();
+
+ if (argc != 1) {
+ result.AppendErrorWithFormat("%s takes 1 arg.\n", m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
}
-
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- const size_t argc = command.GetArgumentCount();
-
- if (argc != 1)
- {
- result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- const char* typeA = command.GetArgumentAtIndex(0);
- ConstString typeCS(typeA);
-
- if (!typeCS)
- {
- result.AppendError("empty typenames not allowed");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- if (m_options.m_delete_all)
- {
- DataVisualization::Categories::ForEach( [this, typeCS] (const lldb::TypeCategoryImplSP& category_sp) -> bool {
- category_sp->Delete(typeCS, m_formatter_kind_mask);
- return true;
- });
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- return result.Succeeded();
- }
-
- bool delete_category = false;
- bool extra_deletion = false;
-
- if (m_options.m_language != lldb::eLanguageTypeUnknown)
- {
- lldb::TypeCategoryImplSP category;
- DataVisualization::Categories::GetCategory(m_options.m_language, category);
- if (category)
- delete_category = category->Delete(typeCS, m_formatter_kind_mask);
- extra_deletion = FormatterSpecificDeletion(typeCS);
- }
- else
- {
- lldb::TypeCategoryImplSP category;
- DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
- if (category)
- delete_category = category->Delete(typeCS, m_formatter_kind_mask);
- extra_deletion = FormatterSpecificDeletion(typeCS);
- }
-
- if (delete_category || extra_deletion)
- {
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- return result.Succeeded();
- }
- else
- {
- result.AppendErrorWithFormat ("no custom formatter for %s.\n", typeA);
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
+
+ const char *typeA = command.GetArgumentAtIndex(0);
+ ConstString typeCS(typeA);
+
+ if (!typeCS) {
+ result.AppendError("empty typenames not allowed");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
}
+
+ if (m_options.m_delete_all) {
+ DataVisualization::Categories::ForEach(
+ [this, typeCS](const lldb::TypeCategoryImplSP &category_sp) -> bool {
+ category_sp->Delete(typeCS, m_formatter_kind_mask);
+ return true;
+ });
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ return result.Succeeded();
+ }
+
+ bool delete_category = false;
+ bool extra_deletion = false;
+
+ if (m_options.m_language != lldb::eLanguageTypeUnknown) {
+ lldb::TypeCategoryImplSP category;
+ DataVisualization::Categories::GetCategory(m_options.m_language,
+ category);
+ if (category)
+ delete_category = category->Delete(typeCS, m_formatter_kind_mask);
+ extra_deletion = FormatterSpecificDeletion(typeCS);
+ } else {
+ lldb::TypeCategoryImplSP category;
+ DataVisualization::Categories::GetCategory(
+ ConstString(m_options.m_category.c_str()), category);
+ if (category)
+ delete_category = category->Delete(typeCS, m_formatter_kind_mask);
+ extra_deletion = FormatterSpecificDeletion(typeCS);
+ }
+
+ if (delete_category || extra_deletion) {
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ return result.Succeeded();
+ } else {
+ result.AppendErrorWithFormat("no custom formatter for %s.\n", typeA);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
};
OptionDefinition
-CommandObjectTypeFormatterDelete::CommandOptions::g_option_table[] =
-{
- // clang-format off
+ CommandObjectTypeFormatterDelete::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Delete from every category."},
{LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Delete from given category."},
{LLDB_OPT_SET_3, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Delete from given language's category."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
-class CommandObjectTypeFormatterClear : public CommandObjectParsed
-{
+class CommandObjectTypeFormatterClear : public CommandObjectParsed {
private:
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options()
- {
- }
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options() {}
- ~CommandOptions() override = default;
+ ~CommandOptions() override = default;
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'a':
- m_delete_all = true;
- break;
- default:
- error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
- break;
- }
-
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_delete_all = false;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
- bool m_delete_all;
- };
-
- CommandOptions m_options;
- uint32_t m_formatter_kind_mask;
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
- Options *
- GetOptions () override
- {
- return &m_options;
+ switch (short_option) {
+ case 'a':
+ m_delete_all = true;
+ break;
+ default:
+ error.SetErrorStringWithFormat("unrecognized option '%c'",
+ short_option);
+ break;
+ }
+
+ return error;
}
-
-public:
- CommandObjectTypeFormatterClear (CommandInterpreter &interpreter,
- uint32_t formatter_kind_mask,
- const char* name,
- const char* help) :
- CommandObjectParsed(interpreter,
- name,
- help,
- nullptr),
- m_options(),
- m_formatter_kind_mask(formatter_kind_mask)
- {
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_delete_all = false;
}
- ~CommandObjectTypeFormatterClear() override = default;
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+ bool m_delete_all;
+ };
+
+ CommandOptions m_options;
+ uint32_t m_formatter_kind_mask;
+
+ Options *GetOptions() override { return &m_options; }
+
+public:
+ CommandObjectTypeFormatterClear(CommandInterpreter &interpreter,
+ uint32_t formatter_kind_mask,
+ const char *name, const char *help)
+ : CommandObjectParsed(interpreter, name, help, nullptr), m_options(),
+ m_formatter_kind_mask(formatter_kind_mask) {}
+
+ ~CommandObjectTypeFormatterClear() override = default;
protected:
- virtual void
- FormatterSpecificDeletion ()
- {
- }
-
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- if (m_options.m_delete_all)
- {
- DataVisualization::Categories::ForEach( [this] (const TypeCategoryImplSP& category_sp) -> bool {
- category_sp->Clear(m_formatter_kind_mask);
- return true;
- });
- }
- else
- {
- lldb::TypeCategoryImplSP category;
- if (command.GetArgumentCount() > 0)
- {
- const char* cat_name = command.GetArgumentAtIndex(0);
- ConstString cat_nameCS(cat_name);
- DataVisualization::Categories::GetCategory(cat_nameCS, category);
- }
- else
- {
- DataVisualization::Categories::GetCategory(ConstString(nullptr), category);
- }
- category->Clear(m_formatter_kind_mask);
- }
-
- FormatterSpecificDeletion();
-
- result.SetStatus(eReturnStatusSuccessFinishResult);
- return result.Succeeded();
+ virtual void FormatterSpecificDeletion() {}
+
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ if (m_options.m_delete_all) {
+ DataVisualization::Categories::ForEach(
+ [this](const TypeCategoryImplSP &category_sp) -> bool {
+ category_sp->Clear(m_formatter_kind_mask);
+ return true;
+ });
+ } else {
+ lldb::TypeCategoryImplSP category;
+ if (command.GetArgumentCount() > 0) {
+ const char *cat_name = command.GetArgumentAtIndex(0);
+ ConstString cat_nameCS(cat_name);
+ DataVisualization::Categories::GetCategory(cat_nameCS, category);
+ } else {
+ DataVisualization::Categories::GetCategory(ConstString(nullptr),
+ category);
+ }
+ category->Clear(m_formatter_kind_mask);
}
+
+ FormatterSpecificDeletion();
+
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return result.Succeeded();
+ }
};
OptionDefinition
-CommandObjectTypeFormatterClear::CommandOptions::g_option_table[] =
-{
- // clang-format off
+ CommandObjectTypeFormatterClear::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_ALL, false, "all", 'a', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Clear every category."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
//-------------------------------------------------------------------------
// CommandObjectTypeFormatDelete
//-------------------------------------------------------------------------
-class CommandObjectTypeFormatDelete : public CommandObjectTypeFormatterDelete
-{
+class CommandObjectTypeFormatDelete : public CommandObjectTypeFormatterDelete {
public:
- CommandObjectTypeFormatDelete (CommandInterpreter &interpreter) :
- CommandObjectTypeFormatterDelete (interpreter,
- eFormatCategoryItemValue | eFormatCategoryItemRegexValue,
- "type format delete",
- "Delete an existing formatting style for a type.")
- {
- }
+ CommandObjectTypeFormatDelete(CommandInterpreter &interpreter)
+ : CommandObjectTypeFormatterDelete(
+ interpreter,
+ eFormatCategoryItemValue | eFormatCategoryItemRegexValue,
+ "type format delete",
+ "Delete an existing formatting style for a type.") {}
- ~CommandObjectTypeFormatDelete() override = default;
+ ~CommandObjectTypeFormatDelete() override = default;
};
//-------------------------------------------------------------------------
// CommandObjectTypeFormatClear
//-------------------------------------------------------------------------
-class CommandObjectTypeFormatClear : public CommandObjectTypeFormatterClear
-{
+class CommandObjectTypeFormatClear : public CommandObjectTypeFormatterClear {
public:
- CommandObjectTypeFormatClear (CommandInterpreter &interpreter) :
- CommandObjectTypeFormatterClear (interpreter,
- eFormatCategoryItemValue | eFormatCategoryItemRegexValue,
- "type format clear",
- "Delete all existing format styles.")
- {
- }
+ CommandObjectTypeFormatClear(CommandInterpreter &interpreter)
+ : CommandObjectTypeFormatterClear(
+ interpreter,
+ eFormatCategoryItemValue | eFormatCategoryItemRegexValue,
+ "type format clear", "Delete all existing format styles.") {}
};
template <typename FormatterType>
-class CommandObjectTypeFormatterList : public CommandObjectParsed
-{
- typedef typename FormatterType::SharedPointer FormatterSharedPointer;
+class CommandObjectTypeFormatterList : public CommandObjectParsed {
+ typedef typename FormatterType::SharedPointer FormatterSharedPointer;
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options(),
- m_category_regex("",""),
- m_category_language(lldb::eLanguageTypeUnknown, lldb::eLanguageTypeUnknown)
- {
- }
-
- ~CommandOptions() override = default;
-
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'w':
- m_category_regex.SetCurrentValue(option_arg);
- m_category_regex.SetOptionWasSet();
- break;
- case 'l':
- error = m_category_language.SetValueFromString(option_arg);
- if (error.Success())
- m_category_language.SetOptionWasSet();
- break;
- default:
- error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
- break;
- }
-
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_category_regex.Clear();
- m_category_language.Clear();
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- static OptionDefinition g_option_table[] =
- {
- // clang-format off
+ class CommandOptions : public Options {
+ public:
+ CommandOptions()
+ : Options(), m_category_regex("", ""),
+ m_category_language(lldb::eLanguageTypeUnknown,
+ lldb::eLanguageTypeUnknown) {}
+
+ ~CommandOptions() override = default;
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option) {
+ case 'w':
+ m_category_regex.SetCurrentValue(option_arg);
+ m_category_regex.SetOptionWasSet();
+ break;
+ case 'l':
+ error = m_category_language.SetValueFromString(option_arg);
+ if (error.Success())
+ m_category_language.SetOptionWasSet();
+ break;
+ default:
+ error.SetErrorStringWithFormat("unrecognized option '%c'",
+ short_option);
+ break;
+ }
+
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_category_regex.Clear();
+ m_category_language.Clear();
+ }
+
+ const OptionDefinition *GetDefinitions() override {
+ static OptionDefinition g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_1, false, "category-regex", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Only show categories matching this filter."},
{LLDB_OPT_SET_2, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Only show the category for a specific language."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
- };
+ // clang-format on
+ };
- return g_option_table;
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
-
- OptionValueString m_category_regex;
- OptionValueLanguage m_category_language;
- };
-
- CommandOptions m_options;
-
- Options *
- GetOptions () override
- {
- return &m_options;
+ return g_option_table;
}
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+
+ OptionValueString m_category_regex;
+ OptionValueLanguage m_category_language;
+ };
+
+ CommandOptions m_options;
+
+ Options *GetOptions() override { return &m_options; }
+
public:
- CommandObjectTypeFormatterList (CommandInterpreter &interpreter,
- const char* name,
- const char* help) :
- CommandObjectParsed(interpreter,
- name,
- help,
- nullptr),
- m_options()
- {
- CommandArgumentEntry type_arg;
- CommandArgumentData type_style_arg;
-
- type_style_arg.arg_type = eArgTypeName;
- type_style_arg.arg_repetition = eArgRepeatOptional;
-
- type_arg.push_back (type_style_arg);
-
- m_arguments.push_back (type_arg);
- }
+ CommandObjectTypeFormatterList(CommandInterpreter &interpreter,
+ const char *name, const char *help)
+ : CommandObjectParsed(interpreter, name, help, nullptr), m_options() {
+ CommandArgumentEntry type_arg;
+ CommandArgumentData type_style_arg;
- ~CommandObjectTypeFormatterList() override = default;
+ type_style_arg.arg_type = eArgTypeName;
+ type_style_arg.arg_repetition = eArgRepeatOptional;
+
+ type_arg.push_back(type_style_arg);
+
+ m_arguments.push_back(type_arg);
+ }
+
+ ~CommandObjectTypeFormatterList() override = default;
protected:
- virtual bool
- FormatterSpecificList (CommandReturnObject &result)
- {
+ virtual bool FormatterSpecificList(CommandReturnObject &result) {
+ return false;
+ }
+
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ const size_t argc = command.GetArgumentCount();
+
+ std::unique_ptr<RegularExpression> category_regex;
+ std::unique_ptr<RegularExpression> formatter_regex;
+
+ if (m_options.m_category_regex.OptionWasSet()) {
+ category_regex.reset(new RegularExpression());
+ if (!category_regex->Compile(
+ m_options.m_category_regex.GetCurrentValue())) {
+ result.AppendErrorWithFormat(
+ "syntax error in category regular expression '%s'",
+ m_options.m_category_regex.GetCurrentValue());
+ result.SetStatus(eReturnStatusFailed);
return false;
+ }
}
-
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- const size_t argc = command.GetArgumentCount();
-
- std::unique_ptr<RegularExpression> category_regex;
- std::unique_ptr<RegularExpression> formatter_regex;
-
- if (m_options.m_category_regex.OptionWasSet())
- {
- category_regex.reset(new RegularExpression());
- if (!category_regex->Compile(m_options.m_category_regex.GetCurrentValue()))
- {
- result.AppendErrorWithFormat("syntax error in category regular expression '%s'", m_options.m_category_regex.GetCurrentValue());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
-
- if (argc == 1)
- {
- const char* arg = command.GetArgumentAtIndex(0);
- formatter_regex.reset(new RegularExpression());
- if (!formatter_regex->Compile(arg))
- {
- result.AppendErrorWithFormat("syntax error in regular expression '%s'", arg);
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
-
- bool any_printed = false;
-
- 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)");
-
- TypeCategoryImpl::ForEachCallbacks<FormatterType> foreach;
- foreach.SetExact([&result, &formatter_regex, &any_printed] (ConstString name, const FormatterSharedPointer& format_sp) -> bool {
- if (formatter_regex)
- {
- bool escape = true;
- if (0 == strcmp(name.AsCString(), formatter_regex->GetText()))
- {
- escape = false;
- }
- else if (formatter_regex->Execute(name.AsCString()))
- {
- escape = false;
- }
-
- if (escape)
- return true;
- }
- any_printed = true;
- result.GetOutputStream().Printf ("%s: %s\n", name.AsCString(), format_sp->GetDescription().c_str());
- return true;
- });
-
- foreach.SetWithRegex([&result, &formatter_regex, &any_printed] (RegularExpressionSP regex_sp, const FormatterSharedPointer& format_sp) -> bool {
- if (formatter_regex)
- {
- bool escape = true;
- if (0 == strcmp(regex_sp->GetText(), formatter_regex->GetText()))
- {
- escape = false;
- }
- else if (formatter_regex->Execute(regex_sp->GetText()))
- {
- escape = false;
- }
-
- if (escape)
- return true;
- }
-
- any_printed = true;
- result.GetOutputStream().Printf ("%s: %s\n", regex_sp->GetText(), format_sp->GetDescription().c_str());
- return true;
- });
-
- category->ForEach(foreach);
- };
-
- if (m_options.m_category_language.OptionWasSet())
- {
- lldb::TypeCategoryImplSP category_sp;
- DataVisualization::Categories::GetCategory(m_options.m_category_language.GetCurrentValue(), category_sp);
- if (category_sp)
- category_closure(category_sp);
- }
- else
- {
- DataVisualization::Categories::ForEach( [this, &command, &result, &category_regex, &formatter_regex, &category_closure] (const lldb::TypeCategoryImplSP& category) -> bool {
- if (category_regex)
- {
- bool escape = true;
- if (0 == strcmp(category->GetName(), category_regex->GetText()))
- {
- escape = false;
- }
- else if (category_regex->Execute(category->GetName()))
- {
- escape = false;
- }
-
- if (escape)
- return true;
- }
-
- category_closure(category);
-
+ if (argc == 1) {
+ const char *arg = command.GetArgumentAtIndex(0);
+ formatter_regex.reset(new RegularExpression());
+ if (!formatter_regex->Compile(arg)) {
+ result.AppendErrorWithFormat("syntax error in regular expression '%s'",
+ arg);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+
+ bool any_printed = false;
+
+ 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)");
+
+ TypeCategoryImpl::ForEachCallbacks<FormatterType> foreach;
+ foreach
+ .SetExact([&result, &formatter_regex, &any_printed](
+ ConstString name,
+ const FormatterSharedPointer &format_sp) -> bool {
+ if (formatter_regex) {
+ bool escape = true;
+ if (0 == strcmp(name.AsCString(), formatter_regex->GetText())) {
+ escape = false;
+ } else if (formatter_regex->Execute(name.AsCString())) {
+ escape = false;
+ }
+
+ if (escape)
+ return true;
+ }
+
+ any_printed = true;
+ result.GetOutputStream().Printf("%s: %s\n", name.AsCString(),
+ format_sp->GetDescription().c_str());
+ return true;
+ });
+
+ foreach
+ .SetWithRegex([&result, &formatter_regex, &any_printed](
+ RegularExpressionSP regex_sp,
+ const FormatterSharedPointer &format_sp) -> bool {
+ if (formatter_regex) {
+ bool escape = true;
+ if (0 == strcmp(regex_sp->GetText(), formatter_regex->GetText())) {
+ escape = false;
+ } else if (formatter_regex->Execute(regex_sp->GetText())) {
+ escape = false;
+ }
+
+ if (escape)
+ return true;
+ }
+
+ any_printed = true;
+ result.GetOutputStream().Printf("%s: %s\n", regex_sp->GetText(),
+ format_sp->GetDescription().c_str());
+ return true;
+ });
+
+ category->ForEach(foreach);
+ };
+
+ if (m_options.m_category_language.OptionWasSet()) {
+ lldb::TypeCategoryImplSP category_sp;
+ DataVisualization::Categories::GetCategory(
+ m_options.m_category_language.GetCurrentValue(), category_sp);
+ if (category_sp)
+ category_closure(category_sp);
+ } else {
+ DataVisualization::Categories::ForEach(
+ [this, &command, &result, &category_regex, &formatter_regex,
+ &category_closure](
+ const lldb::TypeCategoryImplSP &category) -> bool {
+ if (category_regex) {
+ bool escape = true;
+ if (0 == strcmp(category->GetName(), category_regex->GetText())) {
+ escape = false;
+ } else if (category_regex->Execute(category->GetName())) {
+ escape = false;
+ }
+
+ if (escape)
return true;
- });
-
- any_printed = FormatterSpecificList(result) | any_printed;
- }
-
- if (any_printed)
- result.SetStatus(eReturnStatusSuccessFinishResult);
- else
- {
- result.GetOutputStream().PutCString("no matching results found.\n");
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- }
- return result.Succeeded();
+ }
+
+ category_closure(category);
+
+ return true;
+ });
+
+ any_printed = FormatterSpecificList(result) | any_printed;
}
+
+ if (any_printed)
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ else {
+ result.GetOutputStream().PutCString("no matching results found.\n");
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ }
+ return result.Succeeded();
+ }
};
//-------------------------------------------------------------------------
// CommandObjectTypeFormatList
//-------------------------------------------------------------------------
-class CommandObjectTypeFormatList : public CommandObjectTypeFormatterList<TypeFormatImpl>
-{
+class CommandObjectTypeFormatList
+ : public CommandObjectTypeFormatterList<TypeFormatImpl> {
public:
-
- CommandObjectTypeFormatList (CommandInterpreter &interpreter) :
- CommandObjectTypeFormatterList(interpreter,
- "type format list",
- "Show a list of current formats.")
- {
- }
+ CommandObjectTypeFormatList(CommandInterpreter &interpreter)
+ : CommandObjectTypeFormatterList(interpreter, "type format list",
+ "Show a list of current formats.") {}
};
#ifndef LLDB_DISABLE_PYTHON
@@ -1485,338 +1237,316 @@ public:
#endif // LLDB_DISABLE_PYTHON
-Error
-CommandObjectTypeSummaryAdd::CommandOptions::SetOptionValue(uint32_t option_idx,
- const char
- *option_arg,
- ExecutionContext
- *execution_context)
-{
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
- bool success;
-
- switch (short_option)
- {
- case 'C':
- m_flags.SetCascades(Args::StringToBoolean(option_arg, true, &success));
- if (!success)
- error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg);
- break;
- case 'e':
- m_flags.SetDontShowChildren(false);
- break;
- case 'h':
- m_flags.SetHideEmptyAggregates(true);
- break;
- case 'v':
- m_flags.SetDontShowValue(true);
- break;
- case 'c':
- m_flags.SetShowMembersOneLiner(true);
- break;
- case 's':
- m_format_string = std::string(option_arg);
- break;
- case 'p':
- m_flags.SetSkipPointers(true);
- break;
- case 'r':
- m_flags.SetSkipReferences(true);
- break;
- case 'x':
- m_regex = true;
- break;
- case 'n':
- m_name.SetCString(option_arg);
- break;
- case 'o':
- m_python_script = std::string(option_arg);
- m_is_add_script = true;
- break;
- case 'F':
- m_python_function = std::string(option_arg);
- m_is_add_script = true;
- break;
- case 'P':
- m_is_add_script = true;
- break;
- case 'w':
- m_category = std::string(option_arg);
- break;
- case 'O':
- m_flags.SetHideItemNames(true);
- break;
- default:
- error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
- break;
- }
-
- return error;
+Error CommandObjectTypeSummaryAdd::CommandOptions::SetOptionValue(
+ uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+ bool success;
+
+ switch (short_option) {
+ case 'C':
+ m_flags.SetCascades(Args::StringToBoolean(option_arg, true, &success));
+ if (!success)
+ error.SetErrorStringWithFormat("invalid value for cascade: %s",
+ option_arg);
+ break;
+ case 'e':
+ m_flags.SetDontShowChildren(false);
+ break;
+ case 'h':
+ m_flags.SetHideEmptyAggregates(true);
+ break;
+ case 'v':
+ m_flags.SetDontShowValue(true);
+ break;
+ case 'c':
+ m_flags.SetShowMembersOneLiner(true);
+ break;
+ case 's':
+ m_format_string = std::string(option_arg);
+ break;
+ case 'p':
+ m_flags.SetSkipPointers(true);
+ break;
+ case 'r':
+ m_flags.SetSkipReferences(true);
+ break;
+ case 'x':
+ m_regex = true;
+ break;
+ case 'n':
+ m_name.SetCString(option_arg);
+ break;
+ case 'o':
+ m_python_script = std::string(option_arg);
+ m_is_add_script = true;
+ break;
+ case 'F':
+ m_python_function = std::string(option_arg);
+ m_is_add_script = true;
+ break;
+ case 'P':
+ m_is_add_script = true;
+ break;
+ case 'w':
+ m_category = std::string(option_arg);
+ break;
+ case 'O':
+ m_flags.SetHideItemNames(true);
+ break;
+ default:
+ error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
+ break;
+ }
+
+ return error;
}
-void
-CommandObjectTypeSummaryAdd::CommandOptions::OptionParsingStarting(
- ExecutionContext *execution_context)
-{
- m_flags.Clear().SetCascades().SetDontShowChildren().SetDontShowValue(false);
- m_flags.SetShowMembersOneLiner(false).SetSkipPointers(false).SetSkipReferences(false).SetHideItemNames(false);
-
- m_regex = false;
- m_name.Clear();
- m_python_script = "";
- m_python_function = "";
- m_format_string = "";
- m_is_add_script = false;
- m_category = "default";
+void CommandObjectTypeSummaryAdd::CommandOptions::OptionParsingStarting(
+ ExecutionContext *execution_context) {
+ m_flags.Clear().SetCascades().SetDontShowChildren().SetDontShowValue(false);
+ m_flags.SetShowMembersOneLiner(false)
+ .SetSkipPointers(false)
+ .SetSkipReferences(false)
+ .SetHideItemNames(false);
+
+ m_regex = false;
+ m_name.Clear();
+ m_python_script = "";
+ m_python_function = "";
+ m_format_string = "";
+ m_is_add_script = false;
+ m_category = "default";
}
#ifndef LLDB_DISABLE_PYTHON
-bool
-CommandObjectTypeSummaryAdd::Execute_ScriptSummary (Args& command, CommandReturnObject &result)
-{
- const size_t argc = command.GetArgumentCount();
-
- if (argc < 1 && !m_options.m_name)
- {
- result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
+bool CommandObjectTypeSummaryAdd::Execute_ScriptSummary(
+ Args &command, CommandReturnObject &result) {
+ const size_t argc = command.GetArgumentCount();
+
+ if (argc < 1 && !m_options.m_name) {
+ result.AppendErrorWithFormat("%s takes one or more args.\n",
+ m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ TypeSummaryImplSP script_format;
+
+ if (!m_options.m_python_function
+ .empty()) // we have a Python function ready to use
+ {
+ const char *funct_name = m_options.m_python_function.c_str();
+ if (!funct_name || !funct_name[0]) {
+ result.AppendError("function name empty.\n");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ std::string code =
+ (" " + m_options.m_python_function + "(valobj,internal_dict)");
+
+ script_format.reset(
+ new ScriptSummaryFormat(m_options.m_flags, funct_name, code.c_str()));
+
+ ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+
+ if (interpreter && !interpreter->CheckObjectExists(funct_name))
+ result.AppendWarningWithFormat(
+ "The provided function \"%s\" does not exist - "
+ "please define it before attempting to use this summary.\n",
+ funct_name);
+ } else if (!m_options.m_python_script
+ .empty()) // we have a quick 1-line script, just use it
+ {
+ ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+ if (!interpreter) {
+ result.AppendError("script interpreter missing - unable to generate "
+ "function wrapper.\n");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ StringList funct_sl;
+ funct_sl << m_options.m_python_script.c_str();
+ std::string funct_name_str;
+ if (!interpreter->GenerateTypeScriptFunction(funct_sl, funct_name_str)) {
+ result.AppendError("unable to generate function wrapper.\n");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ if (funct_name_str.empty()) {
+ result.AppendError(
+ "script interpreter failed to generate a valid function name.\n");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ std::string code = " " + m_options.m_python_script;
+
+ script_format.reset(new ScriptSummaryFormat(
+ m_options.m_flags, funct_name_str.c_str(), code.c_str()));
+ } else {
+ // Use an IOHandler to grab Python code from the user
+ ScriptAddOptions *options =
+ new ScriptAddOptions(m_options.m_flags, m_options.m_regex,
+ m_options.m_name, m_options.m_category);
+
+ for (size_t i = 0; i < argc; i++) {
+ const char *typeA = command.GetArgumentAtIndex(i);
+ if (typeA && *typeA)
+ options->m_target_types << typeA;
+ else {
+ result.AppendError("empty typenames not allowed");
result.SetStatus(eReturnStatusFailed);
return false;
+ }
}
-
- TypeSummaryImplSP script_format;
-
- if (!m_options.m_python_function.empty()) // we have a Python function ready to use
- {
- const char *funct_name = m_options.m_python_function.c_str();
- if (!funct_name || !funct_name[0])
- {
- result.AppendError ("function name empty.\n");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- std::string code = (" " + m_options.m_python_function + "(valobj,internal_dict)");
-
- script_format.reset(new ScriptSummaryFormat(m_options.m_flags,
- funct_name,
- code.c_str()));
-
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
-
- if (interpreter && !interpreter->CheckObjectExists(funct_name))
- result.AppendWarningWithFormat("The provided function \"%s\" does not exist - "
- "please define it before attempting to use this summary.\n",
- funct_name);
- }
- else if (!m_options.m_python_script.empty()) // we have a quick 1-line script, just use it
- {
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
- if (!interpreter)
- {
- result.AppendError ("script interpreter missing - unable to generate function wrapper.\n");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- StringList funct_sl;
- funct_sl << m_options.m_python_script.c_str();
- std::string funct_name_str;
- if (!interpreter->GenerateTypeScriptFunction (funct_sl,
- funct_name_str))
- {
- result.AppendError ("unable to generate function wrapper.\n");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- if (funct_name_str.empty())
- {
- result.AppendError ("script interpreter failed to generate a valid function name.\n");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- std::string code = " " + m_options.m_python_script;
-
- script_format.reset(new ScriptSummaryFormat(m_options.m_flags,
- funct_name_str.c_str(),
- code.c_str()));
- }
- else
- {
- // Use an IOHandler to grab Python code from the user
- ScriptAddOptions *options = new ScriptAddOptions(m_options.m_flags,
- m_options.m_regex,
- m_options.m_name,
- m_options.m_category);
-
- for (size_t i = 0; i < argc; i++)
- {
- const char* typeA = command.GetArgumentAtIndex(i);
- if (typeA && *typeA)
- options->m_target_types << typeA;
- else
- {
- result.AppendError("empty typenames not allowed");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
-
- 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);
-
- return result.Succeeded();
- }
-
- // if I am here, script_format must point to something good, so I can add that
- // as a script summary to all interested parties
-
- Error error;
-
- for (size_t i = 0; i < command.GetArgumentCount(); i++)
- {
- const char *type_name = command.GetArgumentAtIndex(i);
- CommandObjectTypeSummaryAdd::AddSummary(ConstString(type_name),
- script_format,
- (m_options.m_regex ? eRegexSummary : eRegularSummary),
- m_options.m_category,
- &error);
- if (error.Fail())
- {
- result.AppendError(error.AsCString());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
-
- if (m_options.m_name)
- {
- AddSummary(m_options.m_name, script_format, eNamedSummary, m_options.m_category, &error);
- if (error.Fail())
- {
- result.AppendError(error.AsCString());
- result.AppendError("added to types, but not given a name");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
-
+
+ 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);
+
return result.Succeeded();
+ }
+
+ // if I am here, script_format must point to something good, so I can add that
+ // as a script summary to all interested parties
+
+ Error error;
+
+ for (size_t i = 0; i < command.GetArgumentCount(); i++) {
+ const char *type_name = command.GetArgumentAtIndex(i);
+ CommandObjectTypeSummaryAdd::AddSummary(
+ ConstString(type_name), script_format,
+ (m_options.m_regex ? eRegexSummary : eRegularSummary),
+ m_options.m_category, &error);
+ if (error.Fail()) {
+ result.AppendError(error.AsCString());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+
+ if (m_options.m_name) {
+ AddSummary(m_options.m_name, script_format, eNamedSummary,
+ m_options.m_category, &error);
+ if (error.Fail()) {
+ result.AppendError(error.AsCString());
+ result.AppendError("added to types, but not given a name");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+
+ return result.Succeeded();
}
#endif // LLDB_DISABLE_PYTHON
-bool
-CommandObjectTypeSummaryAdd::Execute_StringSummary (Args& command, CommandReturnObject &result)
-{
- const size_t argc = command.GetArgumentCount();
-
- if (argc < 1 && !m_options.m_name)
- {
- result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- if (!m_options.m_flags.GetShowMembersOneLiner() && m_options.m_format_string.empty())
- {
- result.AppendError("empty summary strings not allowed");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- const char* format_cstr = (m_options.m_flags.GetShowMembersOneLiner() ? "" : m_options.m_format_string.c_str());
-
- // ${var%S} is an endless recursion, prevent it
- if (strcmp(format_cstr, "${var%S}") == 0)
- {
- result.AppendError("recursive summary not allowed");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- std::unique_ptr<StringSummaryFormat> string_format(new StringSummaryFormat(m_options.m_flags, format_cstr));
- if (!string_format)
- {
- result.AppendError("summary creation failed");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- if (string_format->m_error.Fail())
- {
- result.AppendErrorWithFormat("syntax error: %s", string_format->m_error.AsCString("<unknown>"));
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- lldb::TypeSummaryImplSP entry(string_format.release());
-
- // now I have a valid format, let's add it to every type
- Error error;
- for (size_t i = 0; i < argc; i++)
- {
- const char* typeA = command.GetArgumentAtIndex(i);
- if (!typeA || typeA[0] == '\0')
- {
- result.AppendError("empty typenames not allowed");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- ConstString typeCS(typeA);
-
- AddSummary(typeCS,
- entry,
- (m_options.m_regex ? eRegexSummary : eRegularSummary),
- m_options.m_category,
- &error);
-
- if (error.Fail())
- {
- result.AppendError(error.AsCString());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
-
- if (m_options.m_name)
- {
- AddSummary(m_options.m_name, entry, eNamedSummary, m_options.m_category, &error);
- if (error.Fail())
- {
- result.AppendError(error.AsCString());
- result.AppendError("added to types, but not given a name");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
+bool CommandObjectTypeSummaryAdd::Execute_StringSummary(
+ Args &command, CommandReturnObject &result) {
+ const size_t argc = command.GetArgumentCount();
+
+ if (argc < 1 && !m_options.m_name) {
+ result.AppendErrorWithFormat("%s takes one or more args.\n",
+ m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (!m_options.m_flags.GetShowMembersOneLiner() &&
+ m_options.m_format_string.empty()) {
+ result.AppendError("empty summary strings not allowed");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ const char *format_cstr = (m_options.m_flags.GetShowMembersOneLiner()
+ ? ""
+ : m_options.m_format_string.c_str());
+
+ // ${var%S} is an endless recursion, prevent it
+ if (strcmp(format_cstr, "${var%S}") == 0) {
+ result.AppendError("recursive summary not allowed");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ std::unique_ptr<StringSummaryFormat> string_format(
+ new StringSummaryFormat(m_options.m_flags, format_cstr));
+ if (!string_format) {
+ result.AppendError("summary creation failed");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ if (string_format->m_error.Fail()) {
+ result.AppendErrorWithFormat("syntax error: %s",
+ string_format->m_error.AsCString("<unknown>"));
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ lldb::TypeSummaryImplSP entry(string_format.release());
+
+ // now I have a valid format, let's add it to every type
+ Error error;
+ for (size_t i = 0; i < argc; i++) {
+ const char *typeA = command.GetArgumentAtIndex(i);
+ if (!typeA || typeA[0] == '\0') {
+ result.AppendError("empty typenames not allowed");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ ConstString typeCS(typeA);
+
+ AddSummary(typeCS, entry,
+ (m_options.m_regex ? eRegexSummary : eRegularSummary),
+ m_options.m_category, &error);
+
+ if (error.Fail()) {
+ result.AppendError(error.AsCString());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+
+ if (m_options.m_name) {
+ AddSummary(m_options.m_name, entry, eNamedSummary, m_options.m_category,
+ &error);
+ if (error.Fail()) {
+ result.AppendError(error.AsCString());
+ result.AppendError("added to types, but not given a name");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
}
-
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- return result.Succeeded();
+ }
+
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ return result.Succeeded();
}
-CommandObjectTypeSummaryAdd::CommandObjectTypeSummaryAdd (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "type summary add",
- "Add a new summary style for a type.",
- nullptr),
- IOHandlerDelegateMultiline ("DONE"),
- m_options (interpreter)
-{
- CommandArgumentEntry type_arg;
- CommandArgumentData type_style_arg;
-
- type_style_arg.arg_type = eArgTypeName;
- type_style_arg.arg_repetition = eArgRepeatPlus;
-
- type_arg.push_back (type_style_arg);
-
- m_arguments.push_back (type_arg);
-
- SetHelpLong(
-R"(
+CommandObjectTypeSummaryAdd::CommandObjectTypeSummaryAdd(
+ CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "type summary add",
+ "Add a new summary style for a type.", nullptr),
+ IOHandlerDelegateMultiline("DONE"), m_options(interpreter) {
+ CommandArgumentEntry type_arg;
+ CommandArgumentData type_style_arg;
+
+ type_style_arg.arg_type = eArgTypeName;
+ type_style_arg.arg_repetition = eArgRepeatPlus;
+
+ type_arg.push_back(type_style_arg);
+
+ m_arguments.push_back(type_arg);
+
+ SetHelpLong(
+ R"(
The following examples of 'type summary add' refer to this code snippet for context:
struct JustADemo
@@ -1838,51 +1568,65 @@ The following examples of 'type summary
Subsequently displaying demo_instance with 'frame variable' or 'expression' will display "the answer is 42 and the question is 3.14"
-)" "Alternatively, you could define formatting for all pointers to integers and \
-rely on that when formatting JustADemo to obtain the same result:" R"(
+)"
+ "Alternatively, you could define formatting for all pointers to integers and \
+rely on that when formatting JustADemo to obtain the same result:"
+ R"(
(lldb) type summary add --summary-string "${var%V} -> ${*var}" "int *"
(lldb) type summary add --summary-string "the answer is ${var.ptr}, and the question is ${var.value}" JustADemo
-)" "Type summaries are automatically applied to derived typedefs, so the examples \
+)"
+ "Type summaries are automatically applied to derived typedefs, so the examples \
above apply to both JustADemo and NewDemo. The cascade option can be used to \
-suppress this behavior:" R"(
+suppress this behavior:"
+ R"(
(lldb) type summary add --summary-string "${var.ptr}, ${var.value},{${var.byte}}" JustADemo -C no
The summary will now be used for values of JustADemo but not NewDemo.
-)" "By default summaries are shown for pointers and references to values of the \
+)"
+ "By default summaries are shown for pointers and references to values of the \
specified type. To suppress formatting for pointers use the -p option, or apply \
-the corresponding -r option to suppress formatting for references:" R"(
+the corresponding -r option to suppress formatting for references:"
+ R"(
(lldb) type summary add -p -r --summary-string "${var.ptr}, ${var.value},{${var.byte}}" JustADemo
-)" "One-line summaries including all fields in a type can be inferred without supplying an \
-explicit summary string by passing the -c option:" R"(
+)"
+ "One-line summaries including all fields in a type can be inferred without supplying an \
+explicit summary string by passing the -c option:"
+ R"(
(lldb) type summary add -c JustADemo
(lldb) frame variable demo_instance
(ptr=<address>, value=3.14)
-)" "Type summaries normally suppress the nested display of individual fields. To \
-supply a summary to supplement the default structure add the -e option:" R"(
+)"
+ "Type summaries normally suppress the nested display of individual fields. To \
+supply a summary to supplement the default structure add the -e option:"
+ R"(
(lldb) type summary add -e --summary-string "*ptr = ${*var.ptr}" JustADemo
-)" "Now when displaying JustADemo values the int* is displayed, followed by the \
-standard LLDB sequence of children, one per line:" R"(
+)"
+ "Now when displaying JustADemo values the int* is displayed, followed by the \
+standard LLDB sequence of children, one per line:"
+ R"(
*ptr = 42 {
ptr = <address>
value = 3.14
}
-)" "You can also add summaries written in Python. These scripts use lldb public API to \
+)"
+ "You can also add summaries written in Python. These scripts use lldb public API to \
gather information from your variables and produce a meaningful summary. To start a \
multi-line script use the -P option. The function declaration will be displayed along with \
a comment describing the two arguments. End your script with the word 'DONE' on a line by \
-itself:" R"(
+itself:"
+ R"(
(lldb) type summary add JustADemo -P
def function (valobj,internal_dict):
@@ -1894,96 +1638,82 @@ internal_dict: an LLDB support object no
Alternatively, the -o option can be used when providing a simple one-line Python script:
-(lldb) type summary add JustADemo -o "value = valobj.GetChildMemberWithName('value'); return 'My value is ' + value.GetValue();")"
- );
+(lldb) type summary add JustADemo -o "value = valobj.GetChildMemberWithName('value'); return 'My value is ' + value.GetValue();")");
}
-bool
-CommandObjectTypeSummaryAdd::DoExecute (Args& command, CommandReturnObject &result)
-{
- WarnOnPotentialUnquotedUnsignedType(command, result);
+bool CommandObjectTypeSummaryAdd::DoExecute(Args &command,
+ CommandReturnObject &result) {
+ WarnOnPotentialUnquotedUnsignedType(command, result);
- if (m_options.m_is_add_script)
- {
+ if (m_options.m_is_add_script) {
#ifndef LLDB_DISABLE_PYTHON
- return Execute_ScriptSummary(command, result);
+ return Execute_ScriptSummary(command, result);
#else
- result.AppendError ("python is disabled");
- result.SetStatus(eReturnStatusFailed);
- return false;
+ result.AppendError("python is disabled");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
#endif // LLDB_DISABLE_PYTHON
- }
-
- return Execute_StringSummary(command, result);
-}
+ }
-static bool
-FixArrayTypeNameWithRegex (ConstString &type_name)
-{
- llvm::StringRef type_name_ref(type_name.GetStringRef());
-
- if (type_name_ref.endswith("[]"))
- {
- std::string type_name_str(type_name.GetCString());
- type_name_str.resize(type_name_str.length()-2);
- if (type_name_str.back() != ' ')
- type_name_str.append(" \\[[0-9]+\\]");
- else
- type_name_str.append("\\[[0-9]+\\]");
- type_name.SetCString(type_name_str.c_str());
- return true;
- }
- return false;
+ return Execute_StringSummary(command, result);
}
-bool
-CommandObjectTypeSummaryAdd::AddSummary(ConstString type_name,
- TypeSummaryImplSP entry,
- SummaryFormatType type,
- std::string category_name,
- Error* error)
-{
- lldb::TypeCategoryImplSP category;
- DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
-
- if (type == eRegularSummary)
- {
- if (FixArrayTypeNameWithRegex (type_name))
- type = eRegexSummary;
- }
-
- if (type == eRegexSummary)
- {
- RegularExpressionSP typeRX(new RegularExpression());
- if (!typeRX->Compile(type_name.GetCString()))
- {
- if (error)
- error->SetErrorString("regex format error (maybe this is not really a regex?)");
- return false;
- }
-
- category->GetRegexTypeSummariesContainer()->Delete(type_name);
- category->GetRegexTypeSummariesContainer()->Add(typeRX, entry);
-
- return true;
- }
- else if (type == eNamedSummary)
- {
- // system named summaries do not exist (yet?)
- DataVisualization::NamedSummaryFormats::Add(type_name,entry);
- return true;
- }
+static bool FixArrayTypeNameWithRegex(ConstString &type_name) {
+ llvm::StringRef type_name_ref(type_name.GetStringRef());
+
+ if (type_name_ref.endswith("[]")) {
+ std::string type_name_str(type_name.GetCString());
+ type_name_str.resize(type_name_str.length() - 2);
+ if (type_name_str.back() != ' ')
+ type_name_str.append(" \\[[0-9]+\\]");
else
- {
- category->GetTypeSummariesContainer()->Add(type_name, entry);
- return true;
- }
-}
+ type_name_str.append("\\[[0-9]+\\]");
+ type_name.SetCString(type_name_str.c_str());
+ return true;
+ }
+ return false;
+}
-OptionDefinition
-CommandObjectTypeSummaryAdd::CommandOptions::g_option_table[] =
-{
- // clang-format off
+bool CommandObjectTypeSummaryAdd::AddSummary(ConstString type_name,
+ TypeSummaryImplSP entry,
+ SummaryFormatType type,
+ std::string category_name,
+ Error *error) {
+ lldb::TypeCategoryImplSP category;
+ DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()),
+ category);
+
+ if (type == eRegularSummary) {
+ if (FixArrayTypeNameWithRegex(type_name))
+ type = eRegexSummary;
+ }
+
+ if (type == eRegexSummary) {
+ RegularExpressionSP typeRX(new RegularExpression());
+ if (!typeRX->Compile(type_name.GetCString())) {
+ if (error)
+ error->SetErrorString(
+ "regex format error (maybe this is not really a regex?)");
+ return false;
+ }
+
+ category->GetRegexTypeSummariesContainer()->Delete(type_name);
+ category->GetRegexTypeSummariesContainer()->Add(typeRX, entry);
+
+ return true;
+ } else if (type == eNamedSummary) {
+ // system named summaries do not exist (yet?)
+ DataVisualization::NamedSummaryFormats::Add(type_name, entry);
+ return true;
+ } else {
+ category->GetTypeSummariesContainer()->Add(type_name, entry);
+ return true;
+ }
+}
+
+OptionDefinition CommandObjectTypeSummaryAdd::CommandOptions::g_option_table[] =
+ {
+ // clang-format off
{LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "Add this to the given category instead of the default one."},
{LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
{LLDB_OPT_SET_ALL, false, "no-value", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't show the value, just show the summary, for this type."},
@@ -2000,678 +1730,563 @@ CommandObjectTypeSummaryAdd::CommandOpti
{LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "hide-empty", 'h', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Do not expand aggregate data types with no children."},
{LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, "A name for this summary string."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
//-------------------------------------------------------------------------
// CommandObjectTypeSummaryDelete
//-------------------------------------------------------------------------
-class CommandObjectTypeSummaryDelete : public CommandObjectTypeFormatterDelete
-{
+class CommandObjectTypeSummaryDelete : public CommandObjectTypeFormatterDelete {
public:
- CommandObjectTypeSummaryDelete (CommandInterpreter &interpreter) :
- CommandObjectTypeFormatterDelete (interpreter,
- eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary,
- "type summary delete",
- "Delete an existing summary for a type.")
- {
- }
+ CommandObjectTypeSummaryDelete(CommandInterpreter &interpreter)
+ : CommandObjectTypeFormatterDelete(
+ interpreter,
+ eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary,
+ "type summary delete", "Delete an existing summary for a type.") {}
- ~CommandObjectTypeSummaryDelete() override = default;
+ ~CommandObjectTypeSummaryDelete() override = default;
protected:
- bool
- FormatterSpecificDeletion (ConstString typeCS) override
- {
- if (m_options.m_language != lldb::eLanguageTypeUnknown)
- return false;
- return DataVisualization::NamedSummaryFormats::Delete(typeCS);
- }
+ bool FormatterSpecificDeletion(ConstString typeCS) override {
+ if (m_options.m_language != lldb::eLanguageTypeUnknown)
+ return false;
+ return DataVisualization::NamedSummaryFormats::Delete(typeCS);
+ }
};
-class CommandObjectTypeSummaryClear : public CommandObjectTypeFormatterClear
-{
-public:
- CommandObjectTypeSummaryClear (CommandInterpreter &interpreter) :
- CommandObjectTypeFormatterClear (interpreter,
- eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary,
- "type summary clear",
- "Delete all existing summaries.")
- {
- }
-
+class CommandObjectTypeSummaryClear : public CommandObjectTypeFormatterClear {
+public:
+ CommandObjectTypeSummaryClear(CommandInterpreter &interpreter)
+ : CommandObjectTypeFormatterClear(
+ interpreter,
+ eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary,
+ "type summary clear", "Delete all existing summaries.") {}
+
protected:
- void
- FormatterSpecificDeletion () override
- {
- DataVisualization::NamedSummaryFormats::Clear();
- }
+ void FormatterSpecificDeletion() override {
+ DataVisualization::NamedSummaryFormats::Clear();
+ }
};
//-------------------------------------------------------------------------
// CommandObjectTypeSummaryList
//-------------------------------------------------------------------------
-class CommandObjectTypeSummaryList : public CommandObjectTypeFormatterList<TypeSummaryImpl>
-{
+class CommandObjectTypeSummaryList
+ : public CommandObjectTypeFormatterList<TypeSummaryImpl> {
public:
- CommandObjectTypeSummaryList (CommandInterpreter &interpreter) :
- CommandObjectTypeFormatterList(interpreter,
- "type summary list",
- "Show a list of current summaries.")
- {
- }
-
+ CommandObjectTypeSummaryList(CommandInterpreter &interpreter)
+ : CommandObjectTypeFormatterList(interpreter, "type summary list",
+ "Show a list of current summaries.") {}
+
protected:
- bool
- FormatterSpecificList (CommandReturnObject &result) override
- {
- if (DataVisualization::NamedSummaryFormats::GetCount() > 0)
- {
- result.GetOutputStream().Printf("Named summaries:\n");
- DataVisualization::NamedSummaryFormats::ForEach( [&result] (ConstString name, const TypeSummaryImplSP& summary_sp) -> bool {
- result.GetOutputStream().Printf ("%s: %s\n", name.AsCString(), summary_sp->GetDescription().c_str());
- return true;
- });
+ bool FormatterSpecificList(CommandReturnObject &result) override {
+ if (DataVisualization::NamedSummaryFormats::GetCount() > 0) {
+ result.GetOutputStream().Printf("Named summaries:\n");
+ DataVisualization::NamedSummaryFormats::ForEach(
+ [&result](ConstString name,
+ const TypeSummaryImplSP &summary_sp) -> bool {
+ result.GetOutputStream().Printf(
+ "%s: %s\n", name.AsCString(),
+ summary_sp->GetDescription().c_str());
return true;
- }
- return false;
+ });
+ return true;
}
+ return false;
+ }
};
//-------------------------------------------------------------------------
// CommandObjectTypeCategoryDefine
//-------------------------------------------------------------------------
-class CommandObjectTypeCategoryDefine : public CommandObjectParsed
-{
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options(),
- m_define_enabled(false,false),
- m_cate_language(eLanguageTypeUnknown,eLanguageTypeUnknown)
- {
- }
+class CommandObjectTypeCategoryDefine : public CommandObjectParsed {
+ class CommandOptions : public Options {
+ public:
+ CommandOptions()
+ : Options(), m_define_enabled(false, false),
+ m_cate_language(eLanguageTypeUnknown, eLanguageTypeUnknown) {}
- ~CommandOptions() override = default;
+ ~CommandOptions() override = default;
- Error
- SetOptionValue (uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'e':
- m_define_enabled.SetValueFromString("true");
- break;
- case 'l':
- error = m_cate_language.SetValueFromString(option_arg);
- break;
- default:
- error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
- break;
- }
-
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_define_enabled.Clear();
- m_cate_language.Clear();
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
-
- OptionValueBoolean m_define_enabled;
- OptionValueLanguage m_cate_language;
- };
-
- CommandOptions m_options;
-
- Options *
- GetOptions () override
- {
- return &m_options;
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option) {
+ case 'e':
+ m_define_enabled.SetValueFromString("true");
+ break;
+ case 'l':
+ error = m_cate_language.SetValueFromString(option_arg);
+ break;
+ default:
+ error.SetErrorStringWithFormat("unrecognized option '%c'",
+ short_option);
+ break;
+ }
+
+ return error;
}
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_define_enabled.Clear();
+ m_cate_language.Clear();
+ }
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+
+ OptionValueBoolean m_define_enabled;
+ OptionValueLanguage m_cate_language;
+ };
+
+ CommandOptions m_options;
+
+ Options *GetOptions() override { return &m_options; }
+
public:
- CommandObjectTypeCategoryDefine (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "type category define",
+ CommandObjectTypeCategoryDefine(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "type category define",
"Define a new category as a source of formatters.",
nullptr),
- m_options()
- {
- CommandArgumentEntry type_arg;
- CommandArgumentData type_style_arg;
-
- type_style_arg.arg_type = eArgTypeName;
- type_style_arg.arg_repetition = eArgRepeatPlus;
-
- type_arg.push_back (type_style_arg);
-
- m_arguments.push_back (type_arg);
- }
+ m_options() {
+ CommandArgumentEntry type_arg;
+ CommandArgumentData type_style_arg;
+
+ type_style_arg.arg_type = eArgTypeName;
+ type_style_arg.arg_repetition = eArgRepeatPlus;
- ~CommandObjectTypeCategoryDefine() override = default;
+ type_arg.push_back(type_style_arg);
+
+ m_arguments.push_back(type_arg);
+ }
+
+ ~CommandObjectTypeCategoryDefine() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- const size_t argc = command.GetArgumentCount();
-
- if (argc < 1)
- {
- result.AppendErrorWithFormat ("%s takes 1 or more args.\n", m_cmd_name.c_str());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- for (size_t i = 0; i < argc; i++)
- {
- const char* cateName = command.GetArgumentAtIndex(i);
- TypeCategoryImplSP category_sp;
- if (DataVisualization::Categories::GetCategory(ConstString(cateName), category_sp) && category_sp)
- {
- category_sp->AddLanguage(m_options.m_cate_language.GetCurrentValue());
- if (m_options.m_define_enabled.GetCurrentValue())
- DataVisualization::Categories::Enable(category_sp, TypeCategoryMap::Default);
- }
- }
-
- result.SetStatus(eReturnStatusSuccessFinishResult);
- return result.Succeeded();
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ const size_t argc = command.GetArgumentCount();
+
+ if (argc < 1) {
+ result.AppendErrorWithFormat("%s takes 1 or more args.\n",
+ m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ for (size_t i = 0; i < argc; i++) {
+ const char *cateName = command.GetArgumentAtIndex(i);
+ TypeCategoryImplSP category_sp;
+ if (DataVisualization::Categories::GetCategory(ConstString(cateName),
+ category_sp) &&
+ category_sp) {
+ category_sp->AddLanguage(m_options.m_cate_language.GetCurrentValue());
+ if (m_options.m_define_enabled.GetCurrentValue())
+ DataVisualization::Categories::Enable(category_sp,
+ TypeCategoryMap::Default);
+ }
}
+
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return result.Succeeded();
+ }
};
OptionDefinition
-CommandObjectTypeCategoryDefine::CommandOptions::g_option_table[] =
-{
- // clang-format off
+ CommandObjectTypeCategoryDefine::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_ALL, false, "enabled", 'e', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "If specified, this category will be created enabled."},
{LLDB_OPT_SET_ALL, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Specify the language that this category is supported for."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
//-------------------------------------------------------------------------
// CommandObjectTypeCategoryEnable
//-------------------------------------------------------------------------
-class CommandObjectTypeCategoryEnable : public CommandObjectParsed
-{
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options()
- {
- }
+class CommandObjectTypeCategoryEnable : public CommandObjectParsed {
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options() {}
- ~CommandOptions() override = default;
+ ~CommandOptions() override = default;
- Error
- SetOptionValue (uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'l':
- if (option_arg)
- {
- m_language = Language::GetLanguageTypeFromString(option_arg);
- if (m_language == lldb::eLanguageTypeUnknown)
- error.SetErrorStringWithFormat ("unrecognized language '%s'", option_arg);
- }
- break;
- default:
- error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
- break;
- }
-
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_language = lldb::eLanguageTypeUnknown;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option) {
+ case 'l':
+ if (option_arg) {
+ m_language = Language::GetLanguageTypeFromString(option_arg);
+ if (m_language == lldb::eLanguageTypeUnknown)
+ error.SetErrorStringWithFormat("unrecognized language '%s'",
+ option_arg);
}
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
-
- lldb::LanguageType m_language;
-
- };
-
- CommandOptions m_options;
-
- Options *
- GetOptions () override
- {
- return &m_options;
+ break;
+ default:
+ error.SetErrorStringWithFormat("unrecognized option '%c'",
+ short_option);
+ break;
+ }
+
+ return error;
}
-
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_language = lldb::eLanguageTypeUnknown;
+ }
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+
+ lldb::LanguageType m_language;
+ };
+
+ CommandOptions m_options;
+
+ Options *GetOptions() override { return &m_options; }
+
public:
- CommandObjectTypeCategoryEnable (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "type category enable",
+ CommandObjectTypeCategoryEnable(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "type category enable",
"Enable a category as a source of formatters.",
nullptr),
- m_options()
- {
- CommandArgumentEntry type_arg;
- CommandArgumentData type_style_arg;
-
- type_style_arg.arg_type = eArgTypeName;
- type_style_arg.arg_repetition = eArgRepeatPlus;
-
- type_arg.push_back (type_style_arg);
-
- m_arguments.push_back (type_arg);
-
- }
+ m_options() {
+ CommandArgumentEntry type_arg;
+ CommandArgumentData type_style_arg;
+
+ type_style_arg.arg_type = eArgTypeName;
+ type_style_arg.arg_repetition = eArgRepeatPlus;
+
+ type_arg.push_back(type_style_arg);
- ~CommandObjectTypeCategoryEnable() override = default;
+ m_arguments.push_back(type_arg);
+ }
+
+ ~CommandObjectTypeCategoryEnable() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- const size_t argc = command.GetArgumentCount();
-
- if (argc < 1 &&
- m_options.m_language == lldb::eLanguageTypeUnknown)
- {
- result.AppendErrorWithFormat ("%s takes arguments and/or a language", m_cmd_name.c_str());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- if (argc == 1 && strcmp(command.GetArgumentAtIndex(0),"*") == 0)
- {
- DataVisualization::Categories::EnableStar();
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ const size_t argc = command.GetArgumentCount();
+
+ if (argc < 1 && m_options.m_language == lldb::eLanguageTypeUnknown) {
+ result.AppendErrorWithFormat("%s takes arguments and/or a language",
+ m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (argc == 1 && strcmp(command.GetArgumentAtIndex(0), "*") == 0) {
+ DataVisualization::Categories::EnableStar();
+ } else if (argc > 0) {
+ for (int i = argc - 1; i >= 0; i--) {
+ const char *typeA = command.GetArgumentAtIndex(i);
+ ConstString typeCS(typeA);
+
+ if (!typeCS) {
+ result.AppendError("empty category name not allowed");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
}
- else if (argc > 0)
- {
- for (int i = argc - 1; i >= 0; i--)
- {
- const char* typeA = command.GetArgumentAtIndex(i);
- ConstString typeCS(typeA);
-
- if (!typeCS)
- {
- result.AppendError("empty category name not allowed");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- DataVisualization::Categories::Enable(typeCS);
- lldb::TypeCategoryImplSP cate;
- if (DataVisualization::Categories::GetCategory(typeCS, cate) && cate)
- {
- if (cate->GetCount() == 0)
- {
- result.AppendWarning("empty category enabled (typo?)");
- }
- }
- }
+ DataVisualization::Categories::Enable(typeCS);
+ lldb::TypeCategoryImplSP cate;
+ if (DataVisualization::Categories::GetCategory(typeCS, cate) && cate) {
+ if (cate->GetCount() == 0) {
+ result.AppendWarning("empty category enabled (typo?)");
+ }
}
-
- if (m_options.m_language != lldb::eLanguageTypeUnknown)
- DataVisualization::Categories::Enable(m_options.m_language);
-
- result.SetStatus(eReturnStatusSuccessFinishResult);
- return result.Succeeded();
+ }
}
+
+ if (m_options.m_language != lldb::eLanguageTypeUnknown)
+ DataVisualization::Categories::Enable(m_options.m_language);
+
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return result.Succeeded();
+ }
};
OptionDefinition
-CommandObjectTypeCategoryEnable::CommandOptions::g_option_table[] =
-{
- // clang-format off
+ CommandObjectTypeCategoryEnable::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_ALL, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Enable the category for this language."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
//-------------------------------------------------------------------------
// CommandObjectTypeCategoryDelete
//-------------------------------------------------------------------------
-class CommandObjectTypeCategoryDelete : public CommandObjectParsed
-{
+class CommandObjectTypeCategoryDelete : public CommandObjectParsed {
public:
- CommandObjectTypeCategoryDelete (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "type category delete",
+ CommandObjectTypeCategoryDelete(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "type category delete",
"Delete a category and all associated formatters.",
- nullptr)
- {
- CommandArgumentEntry type_arg;
- CommandArgumentData type_style_arg;
-
- type_style_arg.arg_type = eArgTypeName;
- type_style_arg.arg_repetition = eArgRepeatPlus;
-
- type_arg.push_back (type_style_arg);
-
- m_arguments.push_back (type_arg);
- }
+ nullptr) {
+ CommandArgumentEntry type_arg;
+ CommandArgumentData type_style_arg;
+
+ type_style_arg.arg_type = eArgTypeName;
+ type_style_arg.arg_repetition = eArgRepeatPlus;
+
+ type_arg.push_back(type_style_arg);
- ~CommandObjectTypeCategoryDelete() override = default;
+ m_arguments.push_back(type_arg);
+ }
+
+ ~CommandObjectTypeCategoryDelete() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- const size_t argc = command.GetArgumentCount();
-
- if (argc < 1)
- {
- result.AppendErrorWithFormat ("%s takes 1 or more arg.\n", m_cmd_name.c_str());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- bool success = true;
-
- // the order is not relevant here
- for (int i = argc - 1; i >= 0; i--)
- {
- const char* typeA = command.GetArgumentAtIndex(i);
- ConstString typeCS(typeA);
-
- if (!typeCS)
- {
- result.AppendError("empty category name not allowed");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- if (!DataVisualization::Categories::Delete(typeCS))
- success = false; // keep deleting even if we hit an error
- }
- if (success)
- {
- result.SetStatus(eReturnStatusSuccessFinishResult);
- return result.Succeeded();
- }
- else
- {
- result.AppendError("cannot delete one or more categories\n");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ const size_t argc = command.GetArgumentCount();
+
+ if (argc < 1) {
+ result.AppendErrorWithFormat("%s takes 1 or more arg.\n",
+ m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ bool success = true;
+
+ // the order is not relevant here
+ for (int i = argc - 1; i >= 0; i--) {
+ const char *typeA = command.GetArgumentAtIndex(i);
+ ConstString typeCS(typeA);
+
+ if (!typeCS) {
+ result.AppendError("empty category name not allowed");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ if (!DataVisualization::Categories::Delete(typeCS))
+ success = false; // keep deleting even if we hit an error
+ }
+ if (success) {
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return result.Succeeded();
+ } else {
+ result.AppendError("cannot delete one or more categories\n");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
}
+ }
};
//-------------------------------------------------------------------------
// CommandObjectTypeCategoryDisable
//-------------------------------------------------------------------------
-class CommandObjectTypeCategoryDisable : public CommandObjectParsed
-{
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options()
- {
- }
+class CommandObjectTypeCategoryDisable : public CommandObjectParsed {
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options() {}
- ~CommandOptions() override = default;
+ ~CommandOptions() override = default;
- Error
- SetOptionValue (uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'l':
- if (option_arg)
- {
- m_language = Language::GetLanguageTypeFromString(option_arg);
- if (m_language == lldb::eLanguageTypeUnknown)
- error.SetErrorStringWithFormat ("unrecognized language '%s'", option_arg);
- }
- break;
- default:
- error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
- break;
- }
-
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_language = lldb::eLanguageTypeUnknown;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option) {
+ case 'l':
+ if (option_arg) {
+ m_language = Language::GetLanguageTypeFromString(option_arg);
+ if (m_language == lldb::eLanguageTypeUnknown)
+ error.SetErrorStringWithFormat("unrecognized language '%s'",
+ option_arg);
}
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
-
- lldb::LanguageType m_language;
- };
-
- CommandOptions m_options;
-
- Options *
- GetOptions () override
- {
- return &m_options;
+ break;
+ default:
+ error.SetErrorStringWithFormat("unrecognized option '%c'",
+ short_option);
+ break;
+ }
+
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_language = lldb::eLanguageTypeUnknown;
}
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+
+ lldb::LanguageType m_language;
+ };
+
+ CommandOptions m_options;
+
+ Options *GetOptions() override { return &m_options; }
+
public:
- CommandObjectTypeCategoryDisable (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "type category disable",
+ CommandObjectTypeCategoryDisable(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "type category disable",
"Disable a category as a source of formatters.",
nullptr),
- m_options()
- {
- CommandArgumentEntry type_arg;
- CommandArgumentData type_style_arg;
-
- type_style_arg.arg_type = eArgTypeName;
- type_style_arg.arg_repetition = eArgRepeatPlus;
-
- type_arg.push_back (type_style_arg);
-
- m_arguments.push_back (type_arg);
- }
+ m_options() {
+ CommandArgumentEntry type_arg;
+ CommandArgumentData type_style_arg;
+
+ type_style_arg.arg_type = eArgTypeName;
+ type_style_arg.arg_repetition = eArgRepeatPlus;
+
+ type_arg.push_back(type_style_arg);
- ~CommandObjectTypeCategoryDisable() override = default;
+ m_arguments.push_back(type_arg);
+ }
+
+ ~CommandObjectTypeCategoryDisable() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- const size_t argc = command.GetArgumentCount();
-
- if (argc < 1 &&
- m_options.m_language == lldb::eLanguageTypeUnknown)
- {
- result.AppendErrorWithFormat ("%s takes arguments and/or a language", m_cmd_name.c_str());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- if (argc == 1 && strcmp(command.GetArgumentAtIndex(0),"*") == 0)
- {
- DataVisualization::Categories::DisableStar();
- }
- else if (argc > 0)
- {
- // the order is not relevant here
- for (int i = argc - 1; i >= 0; i--)
- {
- const char* typeA = command.GetArgumentAtIndex(i);
- ConstString typeCS(typeA);
-
- if (!typeCS)
- {
- result.AppendError("empty category name not allowed");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- DataVisualization::Categories::Disable(typeCS);
- }
- }
-
- if (m_options.m_language != lldb::eLanguageTypeUnknown)
- DataVisualization::Categories::Disable(m_options.m_language);
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ const size_t argc = command.GetArgumentCount();
- result.SetStatus(eReturnStatusSuccessFinishResult);
- return result.Succeeded();
+ if (argc < 1 && m_options.m_language == lldb::eLanguageTypeUnknown) {
+ result.AppendErrorWithFormat("%s takes arguments and/or a language",
+ m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
}
+
+ if (argc == 1 && strcmp(command.GetArgumentAtIndex(0), "*") == 0) {
+ DataVisualization::Categories::DisableStar();
+ } else if (argc > 0) {
+ // the order is not relevant here
+ for (int i = argc - 1; i >= 0; i--) {
+ const char *typeA = command.GetArgumentAtIndex(i);
+ ConstString typeCS(typeA);
+
+ if (!typeCS) {
+ result.AppendError("empty category name not allowed");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ DataVisualization::Categories::Disable(typeCS);
+ }
+ }
+
+ if (m_options.m_language != lldb::eLanguageTypeUnknown)
+ DataVisualization::Categories::Disable(m_options.m_language);
+
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return result.Succeeded();
+ }
};
OptionDefinition
-CommandObjectTypeCategoryDisable::CommandOptions::g_option_table[] =
-{
- // clang-format off
+ CommandObjectTypeCategoryDisable::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_ALL, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Enable the category for this language."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
//-------------------------------------------------------------------------
// CommandObjectTypeCategoryList
//-------------------------------------------------------------------------
-class CommandObjectTypeCategoryList : public CommandObjectParsed
-{
+class CommandObjectTypeCategoryList : public CommandObjectParsed {
public:
- CommandObjectTypeCategoryList (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "type category list",
+ CommandObjectTypeCategoryList(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "type category list",
"Provide a list of all existing categories.",
- nullptr)
- {
- CommandArgumentEntry type_arg;
- CommandArgumentData type_style_arg;
-
- type_style_arg.arg_type = eArgTypeName;
- type_style_arg.arg_repetition = eArgRepeatOptional;
-
- type_arg.push_back (type_style_arg);
-
- m_arguments.push_back (type_arg);
- }
+ nullptr) {
+ CommandArgumentEntry type_arg;
+ CommandArgumentData type_style_arg;
+
+ type_style_arg.arg_type = eArgTypeName;
+ type_style_arg.arg_repetition = eArgRepeatOptional;
+
+ type_arg.push_back(type_style_arg);
+
+ m_arguments.push_back(type_arg);
+ }
- ~CommandObjectTypeCategoryList() override = default;
+ ~CommandObjectTypeCategoryList() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- const size_t argc = command.GetArgumentCount();
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ const size_t argc = command.GetArgumentCount();
- std::unique_ptr<RegularExpression> regex;
-
- if (argc == 1)
- {
- regex.reset(new RegularExpression());
- const char* arg = command.GetArgumentAtIndex(0);
- if (!regex->Compile(arg))
- {
- result.AppendErrorWithFormat("syntax error in category regular expression '%s'", arg);
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
- else if (argc != 0)
- {
- result.AppendErrorWithFormat ("%s takes 0 or one arg.\n", m_cmd_name.c_str());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- DataVisualization::Categories::ForEach( [®ex, &result] (const lldb::TypeCategoryImplSP& category_sp) -> bool {
- if (regex)
- {
- bool escape = true;
- if (0 == strcmp(category_sp->GetName(), regex->GetText()))
- {
- escape = false;
- }
- else if (regex->Execute(category_sp->GetName()))
- {
- escape = false;
- }
-
- if (escape)
- return true;
- }
-
- result.GetOutputStream().Printf("Category: %s\n", category_sp->GetDescription().c_str());
-
- return true;
+ std::unique_ptr<RegularExpression> regex;
+
+ if (argc == 1) {
+ regex.reset(new RegularExpression());
+ const char *arg = command.GetArgumentAtIndex(0);
+ if (!regex->Compile(arg)) {
+ result.AppendErrorWithFormat(
+ "syntax error in category regular expression '%s'", arg);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ } else if (argc != 0) {
+ result.AppendErrorWithFormat("%s takes 0 or one arg.\n",
+ m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ DataVisualization::Categories::ForEach(
+ [®ex, &result](const lldb::TypeCategoryImplSP &category_sp) -> bool {
+ if (regex) {
+ bool escape = true;
+ if (0 == strcmp(category_sp->GetName(), regex->GetText())) {
+ escape = false;
+ } else if (regex->Execute(category_sp->GetName())) {
+ escape = false;
+ }
+
+ if (escape)
+ return true;
+ }
+
+ result.GetOutputStream().Printf(
+ "Category: %s\n", category_sp->GetDescription().c_str());
+
+ return true;
});
-
- result.SetStatus(eReturnStatusSuccessFinishResult);
- return result.Succeeded();
- }
+
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return result.Succeeded();
+ }
};
//-------------------------------------------------------------------------
// CommandObjectTypeFilterList
//-------------------------------------------------------------------------
-class CommandObjectTypeFilterList : public CommandObjectTypeFormatterList<TypeFilterImpl>
-{
+class CommandObjectTypeFilterList
+ : public CommandObjectTypeFormatterList<TypeFilterImpl> {
public:
- CommandObjectTypeFilterList (CommandInterpreter &interpreter) :
- CommandObjectTypeFormatterList(interpreter,
- "type filter list",
- "Show a list of current filters.")
- {
- }
+ CommandObjectTypeFilterList(CommandInterpreter &interpreter)
+ : CommandObjectTypeFormatterList(interpreter, "type filter list",
+ "Show a list of current filters.") {}
};
#ifndef LLDB_DISABLE_PYTHON
@@ -2680,15 +2295,13 @@ public:
// CommandObjectTypeSynthList
//-------------------------------------------------------------------------
-class CommandObjectTypeSynthList : public CommandObjectTypeFormatterList<SyntheticChildren>
-{
+class CommandObjectTypeSynthList
+ : public CommandObjectTypeFormatterList<SyntheticChildren> {
public:
- CommandObjectTypeSynthList (CommandInterpreter &interpreter) :
- CommandObjectTypeFormatterList(interpreter,
- "type synthetic list",
- "Show a list of current synthetic providers.")
- {
- }
+ CommandObjectTypeSynthList(CommandInterpreter &interpreter)
+ : CommandObjectTypeFormatterList(
+ interpreter, "type synthetic list",
+ "Show a list of current synthetic providers.") {}
};
#endif // LLDB_DISABLE_PYTHON
@@ -2697,18 +2310,15 @@ public:
// CommandObjectTypeFilterDelete
//-------------------------------------------------------------------------
-class CommandObjectTypeFilterDelete : public CommandObjectTypeFormatterDelete
-{
+class CommandObjectTypeFilterDelete : public CommandObjectTypeFormatterDelete {
public:
- CommandObjectTypeFilterDelete (CommandInterpreter &interpreter) :
- CommandObjectTypeFormatterDelete (interpreter,
- eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter,
- "type filter delete",
- "Delete an existing filter for a type.")
- {
- }
+ CommandObjectTypeFilterDelete(CommandInterpreter &interpreter)
+ : CommandObjectTypeFormatterDelete(
+ interpreter,
+ eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter,
+ "type filter delete", "Delete an existing filter for a type.") {}
- ~CommandObjectTypeFilterDelete() override = default;
+ ~CommandObjectTypeFilterDelete() override = default;
};
#ifndef LLDB_DISABLE_PYTHON
@@ -2717,18 +2327,16 @@ public:
// CommandObjectTypeSynthDelete
//-------------------------------------------------------------------------
-class CommandObjectTypeSynthDelete : public CommandObjectTypeFormatterDelete
-{
+class CommandObjectTypeSynthDelete : public CommandObjectTypeFormatterDelete {
public:
- CommandObjectTypeSynthDelete (CommandInterpreter &interpreter) :
- CommandObjectTypeFormatterDelete (interpreter,
- eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth,
- "type synthetic delete",
- "Delete an existing synthetic provider for a type.")
- {
- }
+ CommandObjectTypeSynthDelete(CommandInterpreter &interpreter)
+ : CommandObjectTypeFormatterDelete(
+ interpreter,
+ eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth,
+ "type synthetic delete",
+ "Delete an existing synthetic provider for a type.") {}
- ~CommandObjectTypeSynthDelete() override = default;
+ ~CommandObjectTypeSynthDelete() override = default;
};
#endif // LLDB_DISABLE_PYTHON
@@ -2737,16 +2345,13 @@ public:
// CommandObjectTypeFilterClear
//-------------------------------------------------------------------------
-class CommandObjectTypeFilterClear : public CommandObjectTypeFormatterClear
-{
+class CommandObjectTypeFilterClear : public CommandObjectTypeFormatterClear {
public:
- CommandObjectTypeFilterClear (CommandInterpreter &interpreter) :
- CommandObjectTypeFormatterClear (interpreter,
- eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter,
- "type filter clear",
- "Delete all existing filter.")
- {
- }
+ CommandObjectTypeFilterClear(CommandInterpreter &interpreter)
+ : CommandObjectTypeFormatterClear(
+ interpreter,
+ eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter,
+ "type filter clear", "Delete all existing filter.") {}
};
#ifndef LLDB_DISABLE_PYTHON
@@ -2754,190 +2359,173 @@ public:
// CommandObjectTypeSynthClear
//-------------------------------------------------------------------------
-class CommandObjectTypeSynthClear : public CommandObjectTypeFormatterClear
-{
+class CommandObjectTypeSynthClear : public CommandObjectTypeFormatterClear {
public:
- CommandObjectTypeSynthClear (CommandInterpreter &interpreter) :
- CommandObjectTypeFormatterClear (interpreter,
- eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth,
- "type synthetic clear",
- "Delete all existing synthetic providers.")
- {
- }
-};
-
-bool
-CommandObjectTypeSynthAdd::Execute_HandwritePython (Args& command, CommandReturnObject &result)
-{
- SynthAddOptions *options = new SynthAddOptions ( m_options.m_skip_pointers,
- m_options.m_skip_references,
- m_options.m_cascade,
- m_options.m_regex,
- m_options.m_category);
-
- const size_t argc = command.GetArgumentCount();
-
- for (size_t i = 0; i < argc; i++)
- {
- const char* typeA = command.GetArgumentAtIndex(i);
- if (typeA && *typeA)
- options->m_target_types << typeA;
- else
- {
- result.AppendError("empty typenames not allowed");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
-
- 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);
- return result.Succeeded();
+ CommandObjectTypeSynthClear(CommandInterpreter &interpreter)
+ : CommandObjectTypeFormatterClear(
+ interpreter,
+ eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth,
+ "type synthetic clear",
+ "Delete all existing synthetic providers.") {}
+};
+
+bool CommandObjectTypeSynthAdd::Execute_HandwritePython(
+ Args &command, CommandReturnObject &result) {
+ SynthAddOptions *options = new SynthAddOptions(
+ m_options.m_skip_pointers, m_options.m_skip_references,
+ m_options.m_cascade, m_options.m_regex, m_options.m_category);
+
+ const size_t argc = command.GetArgumentCount();
+
+ for (size_t i = 0; i < argc; i++) {
+ const char *typeA = command.GetArgumentAtIndex(i);
+ if (typeA && *typeA)
+ options->m_target_types << typeA;
+ else {
+ result.AppendError("empty typenames not allowed");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+
+ 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);
+ return result.Succeeded();
}
-bool
-CommandObjectTypeSynthAdd::Execute_PythonClass (Args& command, CommandReturnObject &result)
-{
- const size_t argc = command.GetArgumentCount();
-
- if (argc < 1)
- {
- result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- if (m_options.m_class_name.empty() && !m_options.m_input_python)
- {
- result.AppendErrorWithFormat ("%s needs either a Python class name or -P to directly input Python code.\n", m_cmd_name.c_str());
+bool CommandObjectTypeSynthAdd::Execute_PythonClass(
+ Args &command, CommandReturnObject &result) {
+ const size_t argc = command.GetArgumentCount();
+
+ if (argc < 1) {
+ result.AppendErrorWithFormat("%s takes one or more args.\n",
+ m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (m_options.m_class_name.empty() && !m_options.m_input_python) {
+ result.AppendErrorWithFormat("%s needs either a Python class name or -P to "
+ "directly input Python code.\n",
+ m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ SyntheticChildrenSP entry;
+
+ ScriptedSyntheticChildren *impl = new ScriptedSyntheticChildren(
+ SyntheticChildren::Flags()
+ .SetCascades(m_options.m_cascade)
+ .SetSkipPointers(m_options.m_skip_pointers)
+ .SetSkipReferences(m_options.m_skip_references),
+ m_options.m_class_name.c_str());
+
+ entry.reset(impl);
+
+ ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
+
+ if (interpreter &&
+ !interpreter->CheckObjectExists(impl->GetPythonClassName()))
+ result.AppendWarning("The provided class does not exist - please define it "
+ "before attempting to use this synthetic provider");
+
+ // now I have a valid provider, let's add it to every type
+
+ lldb::TypeCategoryImplSP category;
+ DataVisualization::Categories::GetCategory(
+ ConstString(m_options.m_category.c_str()), category);
+
+ Error error;
+
+ for (size_t i = 0; i < argc; i++) {
+ const char *typeA = command.GetArgumentAtIndex(i);
+ ConstString typeCS(typeA);
+ if (typeCS) {
+ if (!AddSynth(typeCS, entry,
+ m_options.m_regex ? eRegexSynth : eRegularSynth,
+ m_options.m_category, &error)) {
+ result.AppendError(error.AsCString());
result.SetStatus(eReturnStatusFailed);
return false;
+ }
+ } else {
+ result.AppendError("empty typenames not allowed");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
}
-
- SyntheticChildrenSP entry;
-
- ScriptedSyntheticChildren* impl = new ScriptedSyntheticChildren(SyntheticChildren::Flags().
- SetCascades(m_options.m_cascade).
- SetSkipPointers(m_options.m_skip_pointers).
- SetSkipReferences(m_options.m_skip_references),
- m_options.m_class_name.c_str());
-
- entry.reset(impl);
-
- ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
-
- if (interpreter && !interpreter->CheckObjectExists(impl->GetPythonClassName()))
- result.AppendWarning("The provided class does not exist - please define it before attempting to use this synthetic provider");
-
- // now I have a valid provider, let's add it to every type
-
- lldb::TypeCategoryImplSP category;
- DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
-
- Error error;
-
- for (size_t i = 0; i < argc; i++)
- {
- const char* typeA = command.GetArgumentAtIndex(i);
- ConstString typeCS(typeA);
- if (typeCS)
- {
- if (!AddSynth(typeCS,
- entry,
- m_options.m_regex ? eRegexSynth : eRegularSynth,
- m_options.m_category,
- &error))
- {
- result.AppendError(error.AsCString());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
- else
- {
- result.AppendError("empty typenames not allowed");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
-
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- return result.Succeeded();
+ }
+
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ return result.Succeeded();
}
-
-CommandObjectTypeSynthAdd::CommandObjectTypeSynthAdd (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "type synthetic add",
- "Add a new synthetic provider for a type.",
- nullptr),
- IOHandlerDelegateMultiline ("DONE"),
- m_options()
-{
- CommandArgumentEntry type_arg;
- CommandArgumentData type_style_arg;
-
- type_style_arg.arg_type = eArgTypeName;
- type_style_arg.arg_repetition = eArgRepeatPlus;
-
- type_arg.push_back (type_style_arg);
-
- m_arguments.push_back (type_arg);
+
+CommandObjectTypeSynthAdd::CommandObjectTypeSynthAdd(
+ CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "type synthetic add",
+ "Add a new synthetic provider for a type.", nullptr),
+ IOHandlerDelegateMultiline("DONE"), m_options() {
+ CommandArgumentEntry type_arg;
+ CommandArgumentData type_style_arg;
+
+ type_style_arg.arg_type = eArgTypeName;
+ type_style_arg.arg_repetition = eArgRepeatPlus;
+
+ type_arg.push_back(type_style_arg);
+
+ m_arguments.push_back(type_arg);
}
-bool
-CommandObjectTypeSynthAdd::AddSynth(ConstString type_name,
- SyntheticChildrenSP entry,
- SynthFormatType type,
- std::string category_name,
- Error* error)
-{
- lldb::TypeCategoryImplSP category;
- DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
-
- if (type == eRegularSynth)
- {
- if (FixArrayTypeNameWithRegex (type_name))
- type = eRegexSynth;
- }
-
- 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!", type_name.AsCString());
- return false;
- }
-
- if (type == eRegexSynth)
- {
- RegularExpressionSP typeRX(new RegularExpression());
- if (!typeRX->Compile(type_name.GetCString()))
- {
- if (error)
- error->SetErrorString("regex format error (maybe this is not really a regex?)");
- return false;
- }
-
- category->GetRegexTypeSyntheticsContainer()->Delete(type_name);
- category->GetRegexTypeSyntheticsContainer()->Add(typeRX, entry);
-
- return true;
- }
- else
- {
- category->GetTypeSyntheticsContainer()->Add(type_name, entry);
- return true;
- }
+bool CommandObjectTypeSynthAdd::AddSynth(ConstString type_name,
+ SyntheticChildrenSP entry,
+ SynthFormatType type,
+ std::string category_name,
+ Error *error) {
+ lldb::TypeCategoryImplSP category;
+ DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()),
+ category);
+
+ if (type == eRegularSynth) {
+ if (FixArrayTypeNameWithRegex(type_name))
+ type = eRegexSynth;
+ }
+
+ 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!",
+ type_name.AsCString());
+ return false;
+ }
+
+ if (type == eRegexSynth) {
+ RegularExpressionSP typeRX(new RegularExpression());
+ if (!typeRX->Compile(type_name.GetCString())) {
+ if (error)
+ error->SetErrorString(
+ "regex format error (maybe this is not really a regex?)");
+ return false;
+ }
+
+ category->GetRegexTypeSyntheticsContainer()->Delete(type_name);
+ category->GetRegexTypeSyntheticsContainer()->Add(typeRX, entry);
+
+ return true;
+ } else {
+ category->GetTypeSyntheticsContainer()->Add(type_name, entry);
+ return true;
+ }
}
-OptionDefinition
-CommandObjectTypeSynthAdd::CommandOptions::g_option_table[] =
-{
- // clang-format off
+OptionDefinition CommandObjectTypeSynthAdd::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
{LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
{LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
@@ -2946,182 +2534,154 @@ CommandObjectTypeSynthAdd::CommandOption
{LLDB_OPT_SET_3, false, "input-python", 'P', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Type Python code to generate a class that provides synthetic children."},
{LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Type names are actually regular expressions."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
#endif // LLDB_DISABLE_PYTHON
-class CommandObjectTypeFilterAdd : public CommandObjectParsed
-{
+class CommandObjectTypeFilterAdd : public CommandObjectParsed {
private:
- class CommandOptions : public Options
- {
- typedef std::vector<std::string> option_vector;
+ class CommandOptions : public Options {
+ typedef std::vector<std::string> option_vector;
- public:
- CommandOptions() :
- Options()
- {
- }
+ public:
+ CommandOptions() : Options() {}
- ~CommandOptions() override = default;
+ ~CommandOptions() override = default;
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
- bool success;
-
- switch (short_option)
- {
- case 'C':
- m_cascade = Args::StringToBoolean(option_arg, true, &success);
- if (!success)
- error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg);
- break;
- case 'c':
- m_expr_paths.push_back(option_arg);
- has_child_list = true;
- break;
- case 'p':
- m_skip_pointers = true;
- break;
- case 'r':
- m_skip_references = true;
- break;
- case 'w':
- m_category = std::string(option_arg);
- break;
- case 'x':
- m_regex = true;
- break;
- default:
- error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
- break;
- }
-
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_cascade = true;
- m_skip_pointers = false;
- m_skip_references = false;
- m_category = "default";
- m_expr_paths.clear();
- has_child_list = false;
- m_regex = false;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
-
- bool m_cascade;
- bool m_skip_references;
- bool m_skip_pointers;
- bool m_input_python;
- option_vector m_expr_paths;
- std::string m_category;
- bool has_child_list;
- bool m_regex;
-
- typedef option_vector::iterator ExpressionPathsIterator;
- };
-
- CommandOptions m_options;
-
- Options *
- GetOptions () override
- {
- return &m_options;
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+ bool success;
+
+ switch (short_option) {
+ case 'C':
+ m_cascade = Args::StringToBoolean(option_arg, true, &success);
+ if (!success)
+ error.SetErrorStringWithFormat("invalid value for cascade: %s",
+ option_arg);
+ break;
+ case 'c':
+ m_expr_paths.push_back(option_arg);
+ has_child_list = true;
+ break;
+ case 'p':
+ m_skip_pointers = true;
+ break;
+ case 'r':
+ m_skip_references = true;
+ break;
+ case 'w':
+ m_category = std::string(option_arg);
+ break;
+ case 'x':
+ m_regex = true;
+ break;
+ default:
+ error.SetErrorStringWithFormat("unrecognized option '%c'",
+ short_option);
+ break;
+ }
+
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_cascade = true;
+ m_skip_pointers = false;
+ m_skip_references = false;
+ m_category = "default";
+ m_expr_paths.clear();
+ has_child_list = false;
+ m_regex = false;
}
-
- enum FilterFormatType
- {
- eRegularFilter,
- eRegexFilter
- };
-
- bool
- AddFilter(ConstString type_name,
- TypeFilterImplSP entry,
- FilterFormatType type,
- std::string category_name,
- Error* error)
- {
- lldb::TypeCategoryImplSP category;
- DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
-
- if (type == eRegularFilter)
- {
- if (FixArrayTypeNameWithRegex (type_name))
- type = eRegexFilter;
- }
-
- if (category->AnyMatches(type_name,
- eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth,
- false))
- {
- if (error)
- error->SetErrorStringWithFormat("cannot add filter for type %s when synthetic is defined in same category!", type_name.AsCString());
- return false;
- }
-
- if (type == eRegexFilter)
- {
- RegularExpressionSP typeRX(new RegularExpression());
- if (!typeRX->Compile(type_name.GetCString()))
- {
- if (error)
- error->SetErrorString("regex format error (maybe this is not really a regex?)");
- return false;
- }
-
- category->GetRegexTypeFiltersContainer()->Delete(type_name);
- category->GetRegexTypeFiltersContainer()->Add(typeRX, entry);
-
- return true;
- }
- else
- {
- category->GetTypeFiltersContainer()->Add(type_name, entry);
- return true;
- }
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+
+ bool m_cascade;
+ bool m_skip_references;
+ bool m_skip_pointers;
+ bool m_input_python;
+ option_vector m_expr_paths;
+ std::string m_category;
+ bool has_child_list;
+ bool m_regex;
+
+ typedef option_vector::iterator ExpressionPathsIterator;
+ };
+
+ CommandOptions m_options;
+
+ Options *GetOptions() override { return &m_options; }
+
+ enum FilterFormatType { eRegularFilter, eRegexFilter };
+
+ bool AddFilter(ConstString type_name, TypeFilterImplSP entry,
+ FilterFormatType type, std::string category_name,
+ Error *error) {
+ lldb::TypeCategoryImplSP category;
+ DataVisualization::Categories::GetCategory(
+ ConstString(category_name.c_str()), category);
+
+ if (type == eRegularFilter) {
+ if (FixArrayTypeNameWithRegex(type_name))
+ type = eRegexFilter;
+ }
+
+ if (category->AnyMatches(type_name, eFormatCategoryItemSynth |
+ eFormatCategoryItemRegexSynth,
+ false)) {
+ if (error)
+ error->SetErrorStringWithFormat("cannot add filter for type %s when "
+ "synthetic is defined in same "
+ "category!",
+ type_name.AsCString());
+ return false;
+ }
+
+ if (type == eRegexFilter) {
+ RegularExpressionSP typeRX(new RegularExpression());
+ if (!typeRX->Compile(type_name.GetCString())) {
+ if (error)
+ error->SetErrorString(
+ "regex format error (maybe this is not really a regex?)");
+ return false;
+ }
+
+ category->GetRegexTypeFiltersContainer()->Delete(type_name);
+ category->GetRegexTypeFiltersContainer()->Add(typeRX, entry);
+
+ return true;
+ } else {
+ category->GetTypeFiltersContainer()->Add(type_name, entry);
+ return true;
}
+ }
public:
- CommandObjectTypeFilterAdd (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "type filter add",
- "Add a new filter for a type.",
- nullptr),
- m_options()
- {
- CommandArgumentEntry type_arg;
- CommandArgumentData type_style_arg;
-
- type_style_arg.arg_type = eArgTypeName;
- type_style_arg.arg_repetition = eArgRepeatPlus;
-
- type_arg.push_back (type_style_arg);
-
- m_arguments.push_back (type_arg);
-
- SetHelpLong(
-R"(
+ CommandObjectTypeFilterAdd(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "type filter add",
+ "Add a new filter for a type.", nullptr),
+ m_options() {
+ CommandArgumentEntry type_arg;
+ CommandArgumentData type_style_arg;
+
+ type_style_arg.arg_type = eArgTypeName;
+ type_style_arg.arg_repetition = eArgRepeatPlus;
+
+ type_arg.push_back(type_style_arg);
+
+ m_arguments.push_back(type_arg);
+
+ SetHelpLong(
+ R"(
The following examples of 'type filter add' refer to this code snippet for context:
class Foo {
@@ -3142,94 +2702,90 @@ Adding a simple filter:
(lldb) type filter add --child a --child g Foo
(lldb) frame variable my_foo
-)" "Produces output where only a and g are displayed. Other children of my_foo \
-(b, c, d, e, f, h and i) are available by asking for them explicitly:" R"(
+)"
+ "Produces output where only a and g are displayed. Other children of my_foo \
+(b, c, d, e, f, h and i) are available by asking for them explicitly:"
+ R"(
(lldb) frame variable my_foo.b my_foo.c my_foo.i
-)" "The formatting option --raw on frame variable bypasses the filter, showing \
-all children of my_foo as if no filter was defined:" R"(
+)"
+ "The formatting option --raw on frame variable bypasses the filter, showing \
+all children of my_foo as if no filter was defined:"
+ R"(
-(lldb) frame variable my_foo --raw)"
- );
- }
+(lldb) frame variable my_foo --raw)");
+ }
- ~CommandObjectTypeFilterAdd() override = default;
+ ~CommandObjectTypeFilterAdd() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- const size_t argc = command.GetArgumentCount();
-
- if (argc < 1)
- {
- result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- if (m_options.m_expr_paths.empty())
- {
- result.AppendErrorWithFormat ("%s needs one or more children.\n", m_cmd_name.c_str());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- TypeFilterImplSP entry(new TypeFilterImpl(SyntheticChildren::Flags().SetCascades(m_options.m_cascade).
- SetSkipPointers(m_options.m_skip_pointers).
- SetSkipReferences(m_options.m_skip_references)));
-
- // go through the expression paths
- CommandOptions::ExpressionPathsIterator begin, end = m_options.m_expr_paths.end();
-
- for (begin = m_options.m_expr_paths.begin(); begin != end; begin++)
- entry->AddExpressionPath(*begin);
-
-
- // now I have a valid provider, let's add it to every type
-
- lldb::TypeCategoryImplSP category;
- DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
-
- Error error;
-
- WarnOnPotentialUnquotedUnsignedType(command, result);
-
- for (size_t i = 0; i < argc; i++)
- {
- const char* typeA = command.GetArgumentAtIndex(i);
- ConstString typeCS(typeA);
- if (typeCS)
- {
- if (!AddFilter(typeCS,
- entry,
- m_options.m_regex ? eRegexFilter : eRegularFilter,
- m_options.m_category,
- &error))
- {
- result.AppendError(error.AsCString());
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
- }
- else
- {
- result.AppendError("empty typenames not allowed");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ const size_t argc = command.GetArgumentCount();
+
+ if (argc < 1) {
+ result.AppendErrorWithFormat("%s takes one or more args.\n",
+ m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (m_options.m_expr_paths.empty()) {
+ result.AppendErrorWithFormat("%s needs one or more children.\n",
+ m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ TypeFilterImplSP entry(new TypeFilterImpl(
+ SyntheticChildren::Flags()
+ .SetCascades(m_options.m_cascade)
+ .SetSkipPointers(m_options.m_skip_pointers)
+ .SetSkipReferences(m_options.m_skip_references)));
+
+ // go through the expression paths
+ CommandOptions::ExpressionPathsIterator begin,
+ end = m_options.m_expr_paths.end();
+
+ for (begin = m_options.m_expr_paths.begin(); begin != end; begin++)
+ entry->AddExpressionPath(*begin);
+
+ // now I have a valid provider, let's add it to every type
+
+ lldb::TypeCategoryImplSP category;
+ DataVisualization::Categories::GetCategory(
+ ConstString(m_options.m_category.c_str()), category);
+
+ Error error;
+
+ WarnOnPotentialUnquotedUnsignedType(command, result);
+
+ for (size_t i = 0; i < argc; i++) {
+ const char *typeA = command.GetArgumentAtIndex(i);
+ ConstString typeCS(typeA);
+ if (typeCS) {
+ if (!AddFilter(typeCS, entry,
+ m_options.m_regex ? eRegexFilter : eRegularFilter,
+ m_options.m_category, &error)) {
+ result.AppendError(error.AsCString());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
}
-
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- return result.Succeeded();
+ } else {
+ result.AppendError("empty typenames not allowed");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
}
+
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ return result.Succeeded();
+ }
};
-OptionDefinition
-CommandObjectTypeFilterAdd::CommandOptions::g_option_table[] =
-{
- // clang-format off
+OptionDefinition CommandObjectTypeFilterAdd::CommandOptions::g_option_table[] =
+ {
+ // clang-format off
{LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
{LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
{LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
@@ -3237,484 +2793,466 @@ CommandObjectTypeFilterAdd::CommandOptio
{LLDB_OPT_SET_ALL, false, "child", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpressionPath, "Include this expression path in the synthetic view."},
{LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Type names are actually regular expressions."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
//----------------------------------------------------------------------
// "type lookup"
//----------------------------------------------------------------------
-class CommandObjectTypeLookup : public CommandObjectRaw
-{
+class CommandObjectTypeLookup : public CommandObjectRaw {
protected:
- // this function is allowed to do a more aggressive job at guessing languages than the expression parser
- // is comfortable with - so leave the original call alone and add one that is specific to type lookup
- lldb::LanguageType
- GuessLanguage (StackFrame *frame)
- {
- lldb::LanguageType lang_type = lldb::eLanguageTypeUnknown;
+ // this function is allowed to do a more aggressive job at guessing languages
+ // than the expression parser
+ // is comfortable with - so leave the original call alone and add one that is
+ // specific to type lookup
+ lldb::LanguageType GuessLanguage(StackFrame *frame) {
+ lldb::LanguageType lang_type = lldb::eLanguageTypeUnknown;
+
+ if (!frame)
+ return lang_type;
+
+ lang_type = frame->GuessLanguage();
+ if (lang_type != lldb::eLanguageTypeUnknown)
+ return lang_type;
+
+ Symbol *s = frame->GetSymbolContext(eSymbolContextSymbol).symbol;
+ if (s)
+ lang_type = s->GetMangled().GuessLanguage();
+
+ return lang_type;
+ }
+
+ class CommandOptions : public OptionGroup {
+ public:
+ CommandOptions()
+ : OptionGroup(), m_show_help(false), m_language(eLanguageTypeUnknown) {}
+
+ ~CommandOptions() override = default;
+
+ uint32_t GetNumDefinitions() override { return 3; }
- if (!frame)
- return lang_type;
-
- lang_type = frame->GuessLanguage();
- if (lang_type != lldb::eLanguageTypeUnknown)
- return lang_type;
-
- Symbol *s = frame->GetSymbolContext(eSymbolContextSymbol).symbol;
- if (s)
- lang_type = s->GetMangled().GuessLanguage();
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
- return lang_type;
+ Error SetOptionValue(uint32_t option_idx, const char *option_value,
+ ExecutionContext *execution_context) override {
+ Error error;
+
+ const int short_option = g_option_table[option_idx].short_option;
+
+ switch (short_option) {
+ case 'h':
+ m_show_help = true;
+ break;
+
+ case 'l':
+ m_language = Language::GetLanguageTypeFromString(option_value);
+ break;
+
+ default:
+ error.SetErrorStringWithFormat("invalid short option character '%c'",
+ short_option);
+ break;
+ }
+
+ return error;
}
-
- class CommandOptions : public OptionGroup
- {
- public:
- CommandOptions () :
- OptionGroup(),
- m_show_help(false),
- m_language(eLanguageTypeUnknown)
- {}
-
- ~CommandOptions() override = default;
-
- uint32_t
- GetNumDefinitions () override
- {
- return 3;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- Error
- SetOptionValue (uint32_t option_idx,
- const char *option_value,
- ExecutionContext *execution_context) override
- {
- Error error;
-
- const int short_option = g_option_table[option_idx].short_option;
-
- switch (short_option)
- {
- case 'h':
- m_show_help = true;
- break;
-
- case 'l':
- m_language = Language::GetLanguageTypeFromString(option_value);
- break;
-
- default:
- error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
- break;
- }
-
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_show_help = false;
- m_language = eLanguageTypeUnknown;
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
- bool m_show_help;
- lldb::LanguageType m_language;
- };
-
- OptionGroupOptions m_option_group;
- CommandOptions m_command_options;
-
-public:
- CommandObjectTypeLookup (CommandInterpreter &interpreter) :
- CommandObjectRaw (interpreter,
- "type lookup",
- "Lookup types and declarations in the current target, following language-specific naming conventions.",
- "type lookup <type-specifier>",
- eCommandRequiresTarget),
- m_option_group(),
- m_command_options()
- {
- m_option_group.Append(&m_command_options);
- m_option_group.Finalize();
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_show_help = false;
+ m_language = eLanguageTypeUnknown;
}
- ~CommandObjectTypeLookup() override = default;
+ // Options table: Required for subclasses of Options.
- Options *
- GetOptions () override
- {
- return &m_option_group;
- }
-
- const char*
- GetHelpLong () override
- {
- if (m_cmd_help_long.empty())
- {
- StreamString stream;
- // FIXME: hardcoding languages is not good
- lldb::LanguageType languages[] = {eLanguageTypeObjC,eLanguageTypeC_plus_plus};
-
- for(const auto lang_type : languages)
- {
- if (auto language = Language::FindPlugin(lang_type))
- {
- if (const char* help = language->GetLanguageSpecificTypeLookupHelp())
- {
- stream.Printf("%s\n", help);
- }
- }
- }
-
- if (stream.GetData())
- m_cmd_help_long.assign(stream.GetString());
+ static OptionDefinition g_option_table[];
+ bool m_show_help;
+ lldb::LanguageType m_language;
+ };
+
+ OptionGroupOptions m_option_group;
+ CommandOptions m_command_options;
+
+public:
+ CommandObjectTypeLookup(CommandInterpreter &interpreter)
+ : CommandObjectRaw(interpreter, "type lookup",
+ "Lookup types and declarations in the current target, "
+ "following language-specific naming conventions.",
+ "type lookup <type-specifier>",
+ eCommandRequiresTarget),
+ m_option_group(), m_command_options() {
+ m_option_group.Append(&m_command_options);
+ m_option_group.Finalize();
+ }
+
+ ~CommandObjectTypeLookup() override = default;
+
+ Options *GetOptions() override { return &m_option_group; }
+
+ const char *GetHelpLong() override {
+ if (m_cmd_help_long.empty()) {
+ StreamString stream;
+ // FIXME: hardcoding languages is not good
+ lldb::LanguageType languages[] = {eLanguageTypeObjC,
+ eLanguageTypeC_plus_plus};
+
+ for (const auto lang_type : languages) {
+ if (auto language = Language::FindPlugin(lang_type)) {
+ if (const char *help =
+ language->GetLanguageSpecificTypeLookupHelp()) {
+ stream.Printf("%s\n", help);
+ }
}
- return this->CommandObject::GetHelpLong();
+ }
+
+ if (stream.GetData())
+ m_cmd_help_long.assign(stream.GetString());
}
-
- bool
- DoExecute (const char *raw_command_line, CommandReturnObject &result) override
- {
- if (!raw_command_line || !raw_command_line[0])
- {
- result.SetError("type lookup cannot be invoked without a type name as argument");
- return false;
- }
+ return this->CommandObject::GetHelpLong();
+ }
- auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
- m_option_group.NotifyOptionParsingStarting(&exe_ctx);
-
- const char * name_of_type = nullptr;
-
- if (raw_command_line[0] == '-')
- {
- // We have some options and these options MUST end with --.
- const char *end_options = nullptr;
- const char *s = raw_command_line;
- while (s && s[0])
- {
- end_options = ::strstr (s, "--");
- if (end_options)
- {
- end_options += 2; // Get past the "--"
- if (::isspace (end_options[0]))
- {
- name_of_type = end_options;
- while (::isspace (*name_of_type))
- ++name_of_type;
- break;
- }
- }
- s = end_options;
- }
-
- if (end_options)
- {
- Args args (llvm::StringRef(raw_command_line, end_options - raw_command_line));
- if (!ParseOptions (args, result))
- return false;
-
- Error error(m_option_group.NotifyOptionParsingFinished(
- &exe_ctx));
- if (error.Fail())
- {
- result.AppendError (error.AsCString());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- }
- if (nullptr == name_of_type)
- name_of_type = raw_command_line;
-
- // TargetSP target_sp(GetCommandInterpreter().GetDebugger().GetSelectedTarget());
- // const bool fill_all_in = true;
- // ExecutionContext exe_ctx(target_sp.get(), fill_all_in);
- ExecutionContextScope *best_scope = exe_ctx.GetBestExecutionContextScope();
-
- bool any_found = false;
-
- std::vector<Language*> languages;
-
- bool is_global_search = false;
- LanguageType guessed_language = lldb::eLanguageTypeUnknown;
-
- if ( (is_global_search = (m_command_options.m_language == eLanguageTypeUnknown)) )
- {
- // FIXME: hardcoding languages is not good
- languages.push_back(Language::FindPlugin(eLanguageTypeObjC));
- languages.push_back(Language::FindPlugin(eLanguageTypeC_plus_plus));
- }
- else
- {
- languages.push_back(Language::FindPlugin(m_command_options.m_language));
- }
-
- // This is not the most efficient way to do this, but we support very few languages
- // so the cost of the sort is going to be dwarfed by the actual lookup anyway
- if (StackFrame* frame = m_exe_ctx.GetFramePtr())
- {
- guessed_language = GuessLanguage(frame);
- if (guessed_language != eLanguageTypeUnknown)
- {
- std::sort(languages.begin(),
- languages.end(),
- [guessed_language] (Language* lang1,
- Language* lang2) -> bool {
- if (!lang1 || !lang2) return false;
- LanguageType lt1 = lang1->GetLanguageType();
- LanguageType lt2 = lang2->GetLanguageType();
- if (lt1 == guessed_language) return true; // make the selected frame's language come first
- if (lt2 == guessed_language) return false; // make the selected frame's language come first
- return (lt1 < lt2); // normal comparison otherwise
- });
- }
- }
-
- bool is_first_language = true;
-
- for (Language* language : languages)
- {
- if (!language)
- continue;
-
- if (auto scavenger = language->GetTypeScavenger())
- {
- Language::TypeScavenger::ResultSet search_results;
- if (scavenger->Find(best_scope, name_of_type, search_results) > 0)
- {
- for (const auto& search_result : search_results)
- {
- if (search_result && search_result->IsValid())
- {
- any_found = true;
- search_result->DumpToStream(result.GetOutputStream(), this->m_command_options.m_show_help);
- }
- }
- }
- }
- // this is "type lookup SomeName" and we did find a match, so get out
- if (any_found && is_global_search)
- break;
- else if (is_first_language && is_global_search && guessed_language != lldb::eLanguageTypeUnknown)
- {
- is_first_language = false;
- result.GetOutputStream().Printf("no type was found in the current language %s matching '%s'; performing a global search across all languages\n",
- Language::GetNameForLanguageType(guessed_language),
- name_of_type);
- }
+ bool DoExecute(const char *raw_command_line,
+ CommandReturnObject &result) override {
+ if (!raw_command_line || !raw_command_line[0]) {
+ result.SetError(
+ "type lookup cannot be invoked without a type name as argument");
+ return false;
+ }
+
+ auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
+ m_option_group.NotifyOptionParsingStarting(&exe_ctx);
+
+ const char *name_of_type = nullptr;
+
+ if (raw_command_line[0] == '-') {
+ // We have some options and these options MUST end with --.
+ const char *end_options = nullptr;
+ const char *s = raw_command_line;
+ while (s && s[0]) {
+ end_options = ::strstr(s, "--");
+ if (end_options) {
+ end_options += 2; // Get past the "--"
+ if (::isspace(end_options[0])) {
+ name_of_type = end_options;
+ while (::isspace(*name_of_type))
+ ++name_of_type;
+ break;
+ }
}
-
- if (!any_found)
- result.AppendMessageWithFormat("no type was found matching '%s'\n", name_of_type);
-
- result.SetStatus (any_found ? lldb::eReturnStatusSuccessFinishResult : lldb::eReturnStatusSuccessFinishNoResult);
- return true;
+ s = end_options;
+ }
+
+ if (end_options) {
+ Args args(
+ llvm::StringRef(raw_command_line, end_options - raw_command_line));
+ if (!ParseOptions(args, result))
+ return false;
+
+ Error error(m_option_group.NotifyOptionParsingFinished(&exe_ctx));
+ if (error.Fail()) {
+ result.AppendError(error.AsCString());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+ }
+ if (nullptr == name_of_type)
+ name_of_type = raw_command_line;
+
+ // TargetSP
+ // target_sp(GetCommandInterpreter().GetDebugger().GetSelectedTarget());
+ // const bool fill_all_in = true;
+ // ExecutionContext exe_ctx(target_sp.get(), fill_all_in);
+ ExecutionContextScope *best_scope = exe_ctx.GetBestExecutionContextScope();
+
+ bool any_found = false;
+
+ std::vector<Language *> languages;
+
+ bool is_global_search = false;
+ LanguageType guessed_language = lldb::eLanguageTypeUnknown;
+
+ if ((is_global_search =
+ (m_command_options.m_language == eLanguageTypeUnknown))) {
+ // FIXME: hardcoding languages is not good
+ languages.push_back(Language::FindPlugin(eLanguageTypeObjC));
+ languages.push_back(Language::FindPlugin(eLanguageTypeC_plus_plus));
+ } else {
+ languages.push_back(Language::FindPlugin(m_command_options.m_language));
+ }
+
+ // This is not the most efficient way to do this, but we support very few
+ // languages
+ // so the cost of the sort is going to be dwarfed by the actual lookup
+ // anyway
+ if (StackFrame *frame = m_exe_ctx.GetFramePtr()) {
+ guessed_language = GuessLanguage(frame);
+ if (guessed_language != eLanguageTypeUnknown) {
+ std::sort(
+ languages.begin(), languages.end(),
+ [guessed_language](Language *lang1, Language *lang2) -> bool {
+ if (!lang1 || !lang2)
+ return false;
+ LanguageType lt1 = lang1->GetLanguageType();
+ LanguageType lt2 = lang2->GetLanguageType();
+ if (lt1 == guessed_language)
+ return true; // make the selected frame's language come first
+ if (lt2 == guessed_language)
+ return false; // make the selected frame's language come first
+ return (lt1 < lt2); // normal comparison otherwise
+ });
+ }
}
+
+ bool is_first_language = true;
+
+ for (Language *language : languages) {
+ if (!language)
+ continue;
+
+ if (auto scavenger = language->GetTypeScavenger()) {
+ Language::TypeScavenger::ResultSet search_results;
+ if (scavenger->Find(best_scope, name_of_type, search_results) > 0) {
+ for (const auto &search_result : search_results) {
+ if (search_result && search_result->IsValid()) {
+ any_found = true;
+ search_result->DumpToStream(result.GetOutputStream(),
+ this->m_command_options.m_show_help);
+ }
+ }
+ }
+ }
+ // this is "type lookup SomeName" and we did find a match, so get out
+ if (any_found && is_global_search)
+ break;
+ else if (is_first_language && is_global_search &&
+ guessed_language != lldb::eLanguageTypeUnknown) {
+ is_first_language = false;
+ result.GetOutputStream().Printf(
+ "no type was found in the current language %s matching '%s'; "
+ "performing a global search across all languages\n",
+ Language::GetNameForLanguageType(guessed_language), name_of_type);
+ }
+ }
+
+ if (!any_found)
+ result.AppendMessageWithFormat("no type was found matching '%s'\n",
+ name_of_type);
+
+ result.SetStatus(any_found ? lldb::eReturnStatusSuccessFinishResult
+ : lldb::eReturnStatusSuccessFinishNoResult);
+ return true;
+ }
};
-OptionDefinition
-CommandObjectTypeLookup::CommandOptions::g_option_table[] =
-{
- // clang-format off
+OptionDefinition CommandObjectTypeLookup::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_ALL, false, "show-help", 'h', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Display available help for types"},
{LLDB_OPT_SET_ALL, false, "language", 'l', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeLanguage, "Which language's types should the search scope be"},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
- // clang-format on
+ // clang-format on
};
template <typename FormatterType>
-class CommandObjectFormatterInfo : public CommandObjectRaw
-{
+class CommandObjectFormatterInfo : public CommandObjectRaw {
public:
- typedef std::function<typename FormatterType::SharedPointer(ValueObject&)> DiscoveryFunction;
- CommandObjectFormatterInfo (CommandInterpreter &interpreter,
- const char* formatter_name,
- DiscoveryFunction discovery_func) :
- CommandObjectRaw(interpreter,
- nullptr,
- nullptr,
- nullptr,
- eCommandRequiresFrame),
- m_formatter_name(formatter_name ? formatter_name : ""),
- m_discovery_function(discovery_func)
- {
- StreamString name;
- name.Printf("type %s info", formatter_name);
- SetCommandName(name.GetData());
- StreamString help;
- help.Printf("This command evaluates the provided expression and shows which %s is applied to the resulting value (if any).", formatter_name);
- SetHelp(help.GetData());
- StreamString syntax;
- syntax.Printf("type %s info <expr>", formatter_name);
- SetSyntax(syntax.GetData());
- }
+ typedef std::function<typename FormatterType::SharedPointer(ValueObject &)>
+ DiscoveryFunction;
+ CommandObjectFormatterInfo(CommandInterpreter &interpreter,
+ const char *formatter_name,
+ DiscoveryFunction discovery_func)
+ : CommandObjectRaw(interpreter, nullptr, nullptr, nullptr,
+ eCommandRequiresFrame),
+ m_formatter_name(formatter_name ? formatter_name : ""),
+ m_discovery_function(discovery_func) {
+ StreamString name;
+ name.Printf("type %s info", formatter_name);
+ SetCommandName(name.GetData());
+ StreamString help;
+ help.Printf("This command evaluates the provided expression and shows "
+ "which %s is applied to the resulting value (if any).",
+ formatter_name);
+ SetHelp(help.GetData());
+ StreamString syntax;
+ syntax.Printf("type %s info <expr>", formatter_name);
+ SetSyntax(syntax.GetData());
+ }
- ~CommandObjectFormatterInfo() override = default;
+ ~CommandObjectFormatterInfo() override = default;
protected:
- bool
- DoExecute (const char *command, CommandReturnObject &result) override
- {
- TargetSP target_sp = m_interpreter.GetDebugger().GetSelectedTarget();
- Thread *thread = GetDefaultThread();
- if (!thread)
- {
- result.AppendError("no default thread");
- result.SetStatus(lldb::eReturnStatusFailed);
- return false;
- }
-
- StackFrameSP frame_sp = thread->GetSelectedFrame();
- ValueObjectSP result_valobj_sp;
- EvaluateExpressionOptions options;
- lldb::ExpressionResults expr_result = target_sp->EvaluateExpression(command, frame_sp.get(), result_valobj_sp, options);
- if (expr_result == eExpressionCompleted && result_valobj_sp)
- {
- result_valobj_sp = result_valobj_sp->GetQualifiedRepresentationIfAvailable(target_sp->GetPreferDynamicValue(), target_sp->GetEnableSyntheticValue());
- typename FormatterType::SharedPointer formatter_sp = m_discovery_function(*result_valobj_sp);
- if (formatter_sp)
- {
- std::string description(formatter_sp->GetDescription());
- result.AppendMessageWithFormat("%s applied to (%s) %s is: %s\n",
- m_formatter_name.c_str(),
- result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>"),
- command,
- description.c_str());
- result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
- }
- else
- {
- result.AppendMessageWithFormat("no %s applies to (%s) %s\n",
- m_formatter_name.c_str(),
- result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>"),
- command);
- result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult);
- }
- return true;
- }
- else
- {
- result.AppendError("failed to evaluate expression");
- result.SetStatus(lldb::eReturnStatusFailed);
- return false;
- }
+ bool DoExecute(const char *command, CommandReturnObject &result) override {
+ TargetSP target_sp = m_interpreter.GetDebugger().GetSelectedTarget();
+ Thread *thread = GetDefaultThread();
+ if (!thread) {
+ result.AppendError("no default thread");
+ result.SetStatus(lldb::eReturnStatusFailed);
+ return false;
+ }
+
+ StackFrameSP frame_sp = thread->GetSelectedFrame();
+ ValueObjectSP result_valobj_sp;
+ EvaluateExpressionOptions options;
+ lldb::ExpressionResults expr_result = target_sp->EvaluateExpression(
+ command, frame_sp.get(), result_valobj_sp, options);
+ if (expr_result == eExpressionCompleted && result_valobj_sp) {
+ result_valobj_sp =
+ result_valobj_sp->GetQualifiedRepresentationIfAvailable(
+ target_sp->GetPreferDynamicValue(),
+ target_sp->GetEnableSyntheticValue());
+ typename FormatterType::SharedPointer formatter_sp =
+ m_discovery_function(*result_valobj_sp);
+ if (formatter_sp) {
+ std::string description(formatter_sp->GetDescription());
+ result.AppendMessageWithFormat(
+ "%s applied to (%s) %s is: %s\n", m_formatter_name.c_str(),
+ result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>"),
+ command, description.c_str());
+ result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
+ } else {
+ result.AppendMessageWithFormat(
+ "no %s applies to (%s) %s\n", m_formatter_name.c_str(),
+ result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>"),
+ command);
+ result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult);
+ }
+ return true;
+ } else {
+ result.AppendError("failed to evaluate expression");
+ result.SetStatus(lldb::eReturnStatusFailed);
+ return false;
}
+ }
private:
- std::string m_formatter_name;
- DiscoveryFunction m_discovery_function;
+ std::string m_formatter_name;
+ DiscoveryFunction m_discovery_function;
};
-class CommandObjectTypeFormat : public CommandObjectMultiword
-{
+class CommandObjectTypeFormat : public CommandObjectMultiword {
public:
- CommandObjectTypeFormat(CommandInterpreter &interpreter)
- : CommandObjectMultiword(interpreter, "type format", "Commands for customizing value display formats.",
- "type format [<sub-command-options>] ")
- {
- LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeFormatAdd (interpreter)));
- LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeFormatClear (interpreter)));
- LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeFormatDelete (interpreter)));
- LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeFormatList (interpreter)));
- LoadSubCommand ("info", CommandObjectSP (new CommandObjectFormatterInfo<TypeFormatImpl>(interpreter,
- "format",
- [](ValueObject& valobj) -> TypeFormatImpl::SharedPointer {
- return valobj.GetValueFormat();
- })));
- }
+ CommandObjectTypeFormat(CommandInterpreter &interpreter)
+ : CommandObjectMultiword(
+ interpreter, "type format",
+ "Commands for customizing value display formats.",
+ "type format [<sub-command-options>] ") {
+ LoadSubCommand(
+ "add", CommandObjectSP(new CommandObjectTypeFormatAdd(interpreter)));
+ LoadSubCommand("clear", CommandObjectSP(
+ new CommandObjectTypeFormatClear(interpreter)));
+ LoadSubCommand("delete", CommandObjectSP(new CommandObjectTypeFormatDelete(
+ interpreter)));
+ LoadSubCommand(
+ "list", CommandObjectSP(new CommandObjectTypeFormatList(interpreter)));
+ LoadSubCommand(
+ "info", CommandObjectSP(new CommandObjectFormatterInfo<TypeFormatImpl>(
+ interpreter, "format",
+ [](ValueObject &valobj) -> TypeFormatImpl::SharedPointer {
+ return valobj.GetValueFormat();
+ })));
+ }
- ~CommandObjectTypeFormat() override = default;
+ ~CommandObjectTypeFormat() override = default;
};
#ifndef LLDB_DISABLE_PYTHON
-class CommandObjectTypeSynth : public CommandObjectMultiword
-{
+class CommandObjectTypeSynth : public CommandObjectMultiword {
public:
- CommandObjectTypeSynth(CommandInterpreter &interpreter)
- : CommandObjectMultiword(interpreter, "type synthetic",
- "Commands for operating on synthetic type representations.",
- "type synthetic [<sub-command-options>] ")
- {
- LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeSynthAdd (interpreter)));
- LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeSynthClear (interpreter)));
- LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeSynthDelete (interpreter)));
- LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeSynthList (interpreter)));
- LoadSubCommand ("info", CommandObjectSP (new CommandObjectFormatterInfo<SyntheticChildren>(interpreter,
- "synthetic",
- [](ValueObject& valobj) -> SyntheticChildren::SharedPointer {
- return valobj.GetSyntheticChildren();
- })));
- }
+ CommandObjectTypeSynth(CommandInterpreter &interpreter)
+ : CommandObjectMultiword(
+ interpreter, "type synthetic",
+ "Commands for operating on synthetic type representations.",
+ "type synthetic [<sub-command-options>] ") {
+ LoadSubCommand("add",
+ CommandObjectSP(new CommandObjectTypeSynthAdd(interpreter)));
+ LoadSubCommand(
+ "clear", CommandObjectSP(new CommandObjectTypeSynthClear(interpreter)));
+ LoadSubCommand("delete", CommandObjectSP(new CommandObjectTypeSynthDelete(
+ interpreter)));
+ LoadSubCommand(
+ "list", CommandObjectSP(new CommandObjectTypeSynthList(interpreter)));
+ LoadSubCommand(
+ "info",
+ CommandObjectSP(new CommandObjectFormatterInfo<SyntheticChildren>(
+ interpreter, "synthetic",
+ [](ValueObject &valobj) -> SyntheticChildren::SharedPointer {
+ return valobj.GetSyntheticChildren();
+ })));
+ }
- ~CommandObjectTypeSynth() override = default;
+ ~CommandObjectTypeSynth() override = default;
};
#endif // LLDB_DISABLE_PYTHON
-class CommandObjectTypeFilter : public CommandObjectMultiword
-{
-public:
- CommandObjectTypeFilter(CommandInterpreter &interpreter)
- : CommandObjectMultiword(interpreter, "type filter", "Commands for operating on type filters.",
- "type synthetic [<sub-command-options>] ")
- {
- LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeFilterAdd (interpreter)));
- LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeFilterClear (interpreter)));
- LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeFilterDelete (interpreter)));
- LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeFilterList (interpreter)));
- }
-
- ~CommandObjectTypeFilter() override = default;
-};
-
-class CommandObjectTypeCategory : public CommandObjectMultiword
-{
+class CommandObjectTypeFilter : public CommandObjectMultiword {
public:
- CommandObjectTypeCategory(CommandInterpreter &interpreter)
- : CommandObjectMultiword(interpreter, "type category", "Commands for operating on type categories.",
- "type category [<sub-command-options>] ")
- {
- LoadSubCommand ("define", CommandObjectSP (new CommandObjectTypeCategoryDefine (interpreter)));
- LoadSubCommand ("enable", CommandObjectSP (new CommandObjectTypeCategoryEnable (interpreter)));
- LoadSubCommand ("disable", CommandObjectSP (new CommandObjectTypeCategoryDisable (interpreter)));
- LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeCategoryDelete (interpreter)));
- LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeCategoryList (interpreter)));
- }
-
- ~CommandObjectTypeCategory() override = default;
-};
-
-class CommandObjectTypeSummary : public CommandObjectMultiword
-{
-public:
- CommandObjectTypeSummary(CommandInterpreter &interpreter)
- : CommandObjectMultiword(interpreter, "type summary", "Commands for editing variable summary display options.",
- "type summary [<sub-command-options>] ")
- {
- LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeSummaryAdd (interpreter)));
- LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeSummaryClear (interpreter)));
- LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeSummaryDelete (interpreter)));
- LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeSummaryList (interpreter)));
- LoadSubCommand ("info", CommandObjectSP (new CommandObjectFormatterInfo<TypeSummaryImpl>(interpreter,
- "summary",
- [](ValueObject& valobj) -> TypeSummaryImpl::SharedPointer {
- return valobj.GetSummaryFormat();
- })));
- }
+ CommandObjectTypeFilter(CommandInterpreter &interpreter)
+ : CommandObjectMultiword(interpreter, "type filter",
+ "Commands for operating on type filters.",
+ "type synthetic [<sub-command-options>] ") {
+ LoadSubCommand(
+ "add", CommandObjectSP(new CommandObjectTypeFilterAdd(interpreter)));
+ LoadSubCommand("clear", CommandObjectSP(
+ new CommandObjectTypeFilterClear(interpreter)));
+ LoadSubCommand("delete", CommandObjectSP(new CommandObjectTypeFilterDelete(
+ interpreter)));
+ LoadSubCommand(
+ "list", CommandObjectSP(new CommandObjectTypeFilterList(interpreter)));
+ }
+
+ ~CommandObjectTypeFilter() override = default;
+};
+
+class CommandObjectTypeCategory : public CommandObjectMultiword {
+public:
+ CommandObjectTypeCategory(CommandInterpreter &interpreter)
+ : CommandObjectMultiword(interpreter, "type category",
+ "Commands for operating on type categories.",
+ "type category [<sub-command-options>] ") {
+ LoadSubCommand(
+ "define",
+ CommandObjectSP(new CommandObjectTypeCategoryDefine(interpreter)));
+ LoadSubCommand(
+ "enable",
+ CommandObjectSP(new CommandObjectTypeCategoryEnable(interpreter)));
+ LoadSubCommand(
+ "disable",
+ CommandObjectSP(new CommandObjectTypeCategoryDisable(interpreter)));
+ LoadSubCommand(
+ "delete",
+ CommandObjectSP(new CommandObjectTypeCategoryDelete(interpreter)));
+ LoadSubCommand("list", CommandObjectSP(
+ new CommandObjectTypeCategoryList(interpreter)));
+ }
+
+ ~CommandObjectTypeCategory() override = default;
+};
+
+class CommandObjectTypeSummary : public CommandObjectMultiword {
+public:
+ CommandObjectTypeSummary(CommandInterpreter &interpreter)
+ : CommandObjectMultiword(
+ interpreter, "type summary",
+ "Commands for editing variable summary display options.",
+ "type summary [<sub-command-options>] ") {
+ LoadSubCommand(
+ "add", CommandObjectSP(new CommandObjectTypeSummaryAdd(interpreter)));
+ LoadSubCommand("clear", CommandObjectSP(new CommandObjectTypeSummaryClear(
+ interpreter)));
+ LoadSubCommand("delete", CommandObjectSP(new CommandObjectTypeSummaryDelete(
+ interpreter)));
+ LoadSubCommand(
+ "list", CommandObjectSP(new CommandObjectTypeSummaryList(interpreter)));
+ LoadSubCommand(
+ "info", CommandObjectSP(new CommandObjectFormatterInfo<TypeSummaryImpl>(
+ interpreter, "summary",
+ [](ValueObject &valobj) -> TypeSummaryImpl::SharedPointer {
+ return valobj.GetSummaryFormat();
+ })));
+ }
- ~CommandObjectTypeSummary() override = default;
+ ~CommandObjectTypeSummary() override = default;
};
//-------------------------------------------------------------------------
@@ -3722,17 +3260,23 @@ public:
//-------------------------------------------------------------------------
CommandObjectType::CommandObjectType(CommandInterpreter &interpreter)
- : CommandObjectMultiword(interpreter, "type", "Commands for operating on the type system.",
- "type [<sub-command-options>]")
-{
- LoadSubCommand ("category", CommandObjectSP (new CommandObjectTypeCategory (interpreter)));
- LoadSubCommand ("filter", CommandObjectSP (new CommandObjectTypeFilter (interpreter)));
- LoadSubCommand ("format", CommandObjectSP (new CommandObjectTypeFormat (interpreter)));
- LoadSubCommand ("summary", CommandObjectSP (new CommandObjectTypeSummary (interpreter)));
+ : CommandObjectMultiword(interpreter, "type",
+ "Commands for operating on the type system.",
+ "type [<sub-command-options>]") {
+ LoadSubCommand("category",
+ CommandObjectSP(new CommandObjectTypeCategory(interpreter)));
+ LoadSubCommand("filter",
+ CommandObjectSP(new CommandObjectTypeFilter(interpreter)));
+ LoadSubCommand("format",
+ CommandObjectSP(new CommandObjectTypeFormat(interpreter)));
+ LoadSubCommand("summary",
+ CommandObjectSP(new CommandObjectTypeSummary(interpreter)));
#ifndef LLDB_DISABLE_PYTHON
- LoadSubCommand ("synthetic", CommandObjectSP (new CommandObjectTypeSynth (interpreter)));
+ LoadSubCommand("synthetic",
+ CommandObjectSP(new CommandObjectTypeSynth(interpreter)));
#endif // LLDB_DISABLE_PYTHON
- LoadSubCommand ("lookup", CommandObjectSP (new CommandObjectTypeLookup (interpreter)));
+ LoadSubCommand("lookup",
+ CommandObjectSP(new CommandObjectTypeLookup(interpreter)));
}
CommandObjectType::~CommandObjectType() = default;
Modified: lldb/trunk/source/Commands/CommandObjectType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.h (original)
+++ lldb/trunk/source/Commands/CommandObjectType.h Tue Sep 6 15:57:50 2016
@@ -16,18 +16,17 @@
// Other libraries and framework includes
// Project includes
-#include "lldb/lldb-types.h"
#include "lldb/Interpreter/CommandObjectMultiword.h"
#include "lldb/Interpreter/Options.h"
+#include "lldb/lldb-types.h"
namespace lldb_private {
-class CommandObjectType : public CommandObjectMultiword
-{
+class CommandObjectType : public CommandObjectMultiword {
public:
- CommandObjectType (CommandInterpreter &interpreter);
+ CommandObjectType(CommandInterpreter &interpreter);
- ~CommandObjectType() override;
+ ~CommandObjectType() override;
};
} // namespace lldb_private
Modified: lldb/trunk/source/Commands/CommandObjectVersion.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectVersion.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectVersion.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectVersion.cpp Tue Sep 6 15:57:50 2016
@@ -13,9 +13,9 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
-#include "lldb/lldb-private.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/lldb-private.h"
using namespace lldb;
using namespace lldb_private;
@@ -25,27 +25,18 @@ using namespace lldb_private;
//-------------------------------------------------------------------------
CommandObjectVersion::CommandObjectVersion(CommandInterpreter &interpreter)
- : CommandObjectParsed(interpreter, "version", "Show the LLDB debugger version.", "version")
-{
-}
+ : CommandObjectParsed(interpreter, "version",
+ "Show the LLDB debugger version.", "version") {}
-CommandObjectVersion::~CommandObjectVersion ()
-{
-}
+CommandObjectVersion::~CommandObjectVersion() {}
-bool
-CommandObjectVersion::DoExecute (Args& args, CommandReturnObject &result)
-{
- if (args.GetArgumentCount() == 0)
- {
- result.AppendMessageWithFormat ("%s\n", lldb_private::GetVersion());
- result.SetStatus (eReturnStatusSuccessFinishResult);
- }
- else
- {
- result.AppendError("the version command takes no arguments.");
- result.SetStatus (eReturnStatusFailed);
- }
- return true;
+bool CommandObjectVersion::DoExecute(Args &args, CommandReturnObject &result) {
+ if (args.GetArgumentCount() == 0) {
+ result.AppendMessageWithFormat("%s\n", lldb_private::GetVersion());
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ } else {
+ result.AppendError("the version command takes no arguments.");
+ result.SetStatus(eReturnStatusFailed);
+ }
+ return true;
}
-
Modified: lldb/trunk/source/Commands/CommandObjectVersion.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectVersion.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectVersion.h (original)
+++ lldb/trunk/source/Commands/CommandObjectVersion.h Tue Sep 6 15:57:50 2016
@@ -22,18 +22,14 @@ namespace lldb_private {
// CommandObjectVersion
//-------------------------------------------------------------------------
-class CommandObjectVersion : public CommandObjectParsed
-{
+class CommandObjectVersion : public CommandObjectParsed {
public:
+ CommandObjectVersion(CommandInterpreter &interpreter);
- CommandObjectVersion (CommandInterpreter &interpreter);
-
- ~CommandObjectVersion() override;
+ ~CommandObjectVersion() override;
protected:
- bool
- DoExecute(Args& args,
- CommandReturnObject &result) override;
+ bool DoExecute(Args &args, CommandReturnObject &result) override;
};
} // namespace lldb_private
Modified: lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp Tue Sep 6 15:57:50 2016
@@ -24,9 +24,9 @@
#include "lldb/Core/ValueObject.h"
#include "lldb/Core/ValueObjectVariable.h"
#include "lldb/Host/StringConvert.h"
+#include "lldb/Interpreter/CommandCompletions.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
-#include "lldb/Interpreter/CommandCompletions.h"
#include "lldb/Symbol/Variable.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/StackFrame.h"
@@ -35,126 +35,118 @@
using namespace lldb;
using namespace lldb_private;
-static void
-AddWatchpointDescription(Stream *s, Watchpoint *wp, lldb::DescriptionLevel level)
-{
- s->IndentMore();
- wp->GetDescription(s, level);
- s->IndentLess();
- s->EOL();
+static void AddWatchpointDescription(Stream *s, Watchpoint *wp,
+ lldb::DescriptionLevel level) {
+ s->IndentMore();
+ wp->GetDescription(s, level);
+ s->IndentLess();
+ s->EOL();
}
-static bool
-CheckTargetForWatchpointOperations(Target *target, CommandReturnObject &result)
-{
- if (target == nullptr)
- {
- result.AppendError ("Invalid target. No existing target or watchpoints.");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- bool process_is_valid = target->GetProcessSP() && target->GetProcessSP()->IsAlive();
- if (!process_is_valid)
- {
- result.AppendError ("Thre's no process or it is not alive.");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- // Target passes our checks, return true.
- return true;
+static bool CheckTargetForWatchpointOperations(Target *target,
+ CommandReturnObject &result) {
+ if (target == nullptr) {
+ result.AppendError("Invalid target. No existing target or watchpoints.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ bool process_is_valid =
+ target->GetProcessSP() && target->GetProcessSP()->IsAlive();
+ if (!process_is_valid) {
+ result.AppendError("Thre's no process or it is not alive.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ // Target passes our checks, return true.
+ return true;
}
// Equivalent class: {"-", "to", "To", "TO"} of range specifier array.
-static const char* RSA[4] = { "-", "to", "To", "TO" };
+static const char *RSA[4] = {"-", "to", "To", "TO"};
// Return the index to RSA if found; otherwise -1 is returned.
-static int32_t
-WithRSAIndex(llvm::StringRef &Arg)
-{
-
- uint32_t i;
- for (i = 0; i < 4; ++i)
- if (Arg.find(RSA[i]) != llvm::StringRef::npos)
- return i;
- return -1;
+static int32_t WithRSAIndex(llvm::StringRef &Arg) {
+
+ uint32_t i;
+ for (i = 0; i < 4; ++i)
+ if (Arg.find(RSA[i]) != llvm::StringRef::npos)
+ return i;
+ return -1;
}
// Return true if wp_ids is successfully populated with the watch ids.
// False otherwise.
-bool
-CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(Target *target, Args &args, std::vector<uint32_t> &wp_ids)
-{
- // Pre-condition: args.GetArgumentCount() > 0.
- if (args.GetArgumentCount() == 0)
- {
- if (target == nullptr)
- return false;
- WatchpointSP watch_sp = target->GetLastCreatedWatchpoint();
- if (watch_sp)
- {
- wp_ids.push_back(watch_sp->GetID());
- return true;
- }
- else
- return false;
- }
-
- llvm::StringRef Minus("-");
- std::vector<llvm::StringRef> StrRefArgs;
- std::pair<llvm::StringRef, llvm::StringRef> Pair;
- size_t i;
- int32_t idx;
- // Go through the arguments and make a canonical form of arg list containing
- // only numbers with possible "-" in between.
- for (i = 0; i < args.GetArgumentCount(); ++i) {
- llvm::StringRef Arg(args.GetArgumentAtIndex(i));
- if ((idx = WithRSAIndex(Arg)) == -1) {
- StrRefArgs.push_back(Arg);
- continue;
- }
- // The Arg contains the range specifier, split it, then.
- Pair = Arg.split(RSA[idx]);
- if (!Pair.first.empty())
- StrRefArgs.push_back(Pair.first);
- StrRefArgs.push_back(Minus);
- if (!Pair.second.empty())
- StrRefArgs.push_back(Pair.second);
- }
- // Now process the canonical list and fill in the vector of uint32_t's.
- // If there is any error, return false and the client should ignore wp_ids.
- uint32_t beg, end, id;
- size_t size = StrRefArgs.size();
- bool in_range = false;
- for (i = 0; i < size; ++i) {
- llvm::StringRef Arg = StrRefArgs[i];
- if (in_range) {
- // Look for the 'end' of the range. Note StringRef::getAsInteger()
- // returns true to signify error while parsing.
- if (Arg.getAsInteger(0, end))
- return false;
- // Found a range! Now append the elements.
- for (id = beg; id <= end; ++id)
- wp_ids.push_back(id);
- in_range = false;
- continue;
- }
- if (i < (size - 1) && StrRefArgs[i+1] == Minus) {
- if (Arg.getAsInteger(0, beg))
- return false;
- // Turn on the in_range flag, we are looking for end of range next.
- ++i; in_range = true;
- continue;
- }
- // Otherwise, we have a simple ID. Just append it.
- if (Arg.getAsInteger(0, beg))
- return false;
- wp_ids.push_back(beg);
+bool CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(
+ Target *target, Args &args, std::vector<uint32_t> &wp_ids) {
+ // Pre-condition: args.GetArgumentCount() > 0.
+ if (args.GetArgumentCount() == 0) {
+ if (target == nullptr)
+ return false;
+ WatchpointSP watch_sp = target->GetLastCreatedWatchpoint();
+ if (watch_sp) {
+ wp_ids.push_back(watch_sp->GetID());
+ return true;
+ } else
+ return false;
+ }
+
+ llvm::StringRef Minus("-");
+ std::vector<llvm::StringRef> StrRefArgs;
+ std::pair<llvm::StringRef, llvm::StringRef> Pair;
+ size_t i;
+ int32_t idx;
+ // Go through the arguments and make a canonical form of arg list containing
+ // only numbers with possible "-" in between.
+ for (i = 0; i < args.GetArgumentCount(); ++i) {
+ llvm::StringRef Arg(args.GetArgumentAtIndex(i));
+ if ((idx = WithRSAIndex(Arg)) == -1) {
+ StrRefArgs.push_back(Arg);
+ continue;
+ }
+ // The Arg contains the range specifier, split it, then.
+ Pair = Arg.split(RSA[idx]);
+ if (!Pair.first.empty())
+ StrRefArgs.push_back(Pair.first);
+ StrRefArgs.push_back(Minus);
+ if (!Pair.second.empty())
+ StrRefArgs.push_back(Pair.second);
+ }
+ // Now process the canonical list and fill in the vector of uint32_t's.
+ // If there is any error, return false and the client should ignore wp_ids.
+ uint32_t beg, end, id;
+ size_t size = StrRefArgs.size();
+ bool in_range = false;
+ for (i = 0; i < size; ++i) {
+ llvm::StringRef Arg = StrRefArgs[i];
+ if (in_range) {
+ // Look for the 'end' of the range. Note StringRef::getAsInteger()
+ // returns true to signify error while parsing.
+ if (Arg.getAsInteger(0, end))
+ return false;
+ // Found a range! Now append the elements.
+ for (id = beg; id <= end; ++id)
+ wp_ids.push_back(id);
+ in_range = false;
+ continue;
}
- // It is an error if after the loop, we're still in_range.
- if (in_range)
+ if (i < (size - 1) && StrRefArgs[i + 1] == Minus) {
+ if (Arg.getAsInteger(0, beg))
return false;
+ // Turn on the in_range flag, we are looking for end of range next.
+ ++i;
+ in_range = true;
+ continue;
+ }
+ // Otherwise, we have a simple ID. Just append it.
+ if (Arg.getAsInteger(0, beg))
+ return false;
+ wp_ids.push_back(beg);
+ }
+ // It is an error if after the loop, we're still in_range.
+ if (in_range)
+ return false;
- return true; // Success!
+ return true; // Success!
}
//-------------------------------------------------------------------------
@@ -162,162 +154,140 @@ CommandObjectMultiwordWatchpoint::Verify
//-------------------------------------------------------------------------
#pragma mark List
-class CommandObjectWatchpointList : public CommandObjectParsed
-{
+class CommandObjectWatchpointList : public CommandObjectParsed {
public:
- CommandObjectWatchpointList (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "watchpoint list",
- "List all watchpoints at configurable levels of detail.",
- nullptr),
- m_options()
- {
- CommandArgumentEntry arg;
- CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange);
- // Add the entry for the first argument for this command to the object's arguments vector.
- m_arguments.push_back(arg);
- }
-
- ~CommandObjectWatchpointList() override = default;
-
- Options *
- GetOptions () override
- {
- return &m_options;
- }
-
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options(),
- m_level(lldb::eDescriptionLevelBrief) // Watchpoint List defaults to brief descriptions
- {
- }
-
- ~CommandOptions() override = default;
-
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'b':
- m_level = lldb::eDescriptionLevelBrief;
- break;
- case 'f':
- m_level = lldb::eDescriptionLevelFull;
- break;
- case 'v':
- m_level = lldb::eDescriptionLevelVerbose;
- break;
- default:
- error.SetErrorStringWithFormat("unrecognized option '%c'", short_option);
- break;
- }
-
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_level = lldb::eDescriptionLevelFull;
- }
+ CommandObjectWatchpointList(CommandInterpreter &interpreter)
+ : CommandObjectParsed(
+ interpreter, "watchpoint list",
+ "List all watchpoints at configurable levels of detail.", nullptr),
+ m_options() {
+ CommandArgumentEntry arg;
+ CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID,
+ eArgTypeWatchpointIDRange);
+ // Add the entry for the first argument for this command to the object's
+ // arguments vector.
+ m_arguments.push_back(arg);
+ }
+
+ ~CommandObjectWatchpointList() override = default;
+
+ Options *GetOptions() override { return &m_options; }
+
+ class CommandOptions : public Options {
+ public:
+ CommandOptions()
+ : Options(),
+ m_level(lldb::eDescriptionLevelBrief) // Watchpoint List defaults to
+ // brief descriptions
+ {}
+
+ ~CommandOptions() override = default;
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option) {
+ case 'b':
+ m_level = lldb::eDescriptionLevelBrief;
+ break;
+ case 'f':
+ m_level = lldb::eDescriptionLevelFull;
+ break;
+ case 'v':
+ m_level = lldb::eDescriptionLevelVerbose;
+ break;
+ default:
+ error.SetErrorStringWithFormat("unrecognized option '%c'",
+ short_option);
+ break;
+ }
+
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_level = lldb::eDescriptionLevelFull;
+ }
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
- const OptionDefinition *
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- // Options table: Required for subclasses of Options.
+ // Options table: Required for subclasses of Options.
- static OptionDefinition g_option_table[];
+ static OptionDefinition g_option_table[];
- // Instance variables to hold the values for command options.
+ // Instance variables to hold the values for command options.
- lldb::DescriptionLevel m_level;
- };
+ lldb::DescriptionLevel m_level;
+ };
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (target == nullptr)
- {
- result.AppendError ("Invalid target. No current target or watchpoints.");
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- return true;
- }
-
- if (target->GetProcessSP() && target->GetProcessSP()->IsAlive())
- {
- uint32_t num_supported_hardware_watchpoints;
- Error error = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints);
- if (error.Success())
- result.AppendMessageWithFormat("Number of supported hardware watchpoints: %u\n",
- num_supported_hardware_watchpoints);
- }
-
- const WatchpointList &watchpoints = target->GetWatchpointList();
-
- std::unique_lock<std::recursive_mutex> lock;
- target->GetWatchpointList().GetListMutex(lock);
-
- size_t num_watchpoints = watchpoints.GetSize();
-
- if (num_watchpoints == 0)
- {
- result.AppendMessage("No watchpoints currently set.");
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- return true;
- }
-
- Stream &output_stream = result.GetOutputStream();
-
- if (command.GetArgumentCount() == 0)
- {
- // No watchpoint selected; show info about all currently set watchpoints.
- result.AppendMessage ("Current watchpoints:");
- for (size_t i = 0; i < num_watchpoints; ++i)
- {
- Watchpoint *wp = watchpoints.GetByIndex(i).get();
- AddWatchpointDescription(&output_stream, wp, m_options.m_level);
- }
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- // Particular watchpoints selected; enable them.
- std::vector<uint32_t> wp_ids;
- if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, wp_ids))
- {
- result.AppendError("Invalid watchpoints specification.");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- const size_t size = wp_ids.size();
- for (size_t i = 0; i < size; ++i)
- {
- Watchpoint *wp = watchpoints.FindByID(wp_ids[i]).get();
- if (wp)
- AddWatchpointDescription(&output_stream, wp, m_options.m_level);
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- }
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (target == nullptr) {
+ result.AppendError("Invalid target. No current target or watchpoints.");
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ return true;
+ }
+
+ if (target->GetProcessSP() && target->GetProcessSP()->IsAlive()) {
+ uint32_t num_supported_hardware_watchpoints;
+ Error error = target->GetProcessSP()->GetWatchpointSupportInfo(
+ num_supported_hardware_watchpoints);
+ if (error.Success())
+ result.AppendMessageWithFormat(
+ "Number of supported hardware watchpoints: %u\n",
+ num_supported_hardware_watchpoints);
+ }
+
+ const WatchpointList &watchpoints = target->GetWatchpointList();
+
+ std::unique_lock<std::recursive_mutex> lock;
+ target->GetWatchpointList().GetListMutex(lock);
+
+ size_t num_watchpoints = watchpoints.GetSize();
+
+ if (num_watchpoints == 0) {
+ result.AppendMessage("No watchpoints currently set.");
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ return true;
+ }
+
+ Stream &output_stream = result.GetOutputStream();
+
+ if (command.GetArgumentCount() == 0) {
+ // No watchpoint selected; show info about all currently set watchpoints.
+ result.AppendMessage("Current watchpoints:");
+ for (size_t i = 0; i < num_watchpoints; ++i) {
+ Watchpoint *wp = watchpoints.GetByIndex(i).get();
+ AddWatchpointDescription(&output_stream, wp, m_options.m_level);
+ }
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ } else {
+ // Particular watchpoints selected; enable 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();
+ const size_t size = wp_ids.size();
+ for (size_t i = 0; i < size; ++i) {
+ Watchpoint *wp = watchpoints.FindByID(wp_ids[i]).get();
+ if (wp)
+ AddWatchpointDescription(&output_stream, wp, m_options.m_level);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ }
}
+ return result.Succeeded();
+ }
+
private:
- CommandOptions m_options;
+ CommandOptions m_options;
};
//-------------------------------------------------------------------------
@@ -325,15 +295,14 @@ private:
//-------------------------------------------------------------------------
#pragma mark List::CommandOptions
-OptionDefinition
-CommandObjectWatchpointList::CommandOptions::g_option_table[] =
-{
- // clang-format off
+OptionDefinition CommandObjectWatchpointList::CommandOptions::g_option_table[] =
+ {
+ // clang-format off
{LLDB_OPT_SET_1, false, "brief", 'b', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a brief description of the watchpoint (no location info)."},
{LLDB_OPT_SET_2, false, "full", 'f', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Give a full description of the watchpoint and its locations."},
{LLDB_OPT_SET_3, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Explain everything we know about the watchpoint (for debugging debugger bugs)."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
//-------------------------------------------------------------------------
@@ -341,75 +310,70 @@ CommandObjectWatchpointList::CommandOpti
//-------------------------------------------------------------------------
#pragma mark Enable
-class CommandObjectWatchpointEnable : public CommandObjectParsed
-{
+class CommandObjectWatchpointEnable : public CommandObjectParsed {
public:
- CommandObjectWatchpointEnable (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "enable",
- "Enable the specified disabled watchpoint(s). If no watchpoints are specified, enable all of them.",
- nullptr)
- {
- CommandArgumentEntry arg;
- CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange);
- // Add the entry for the first argument for this command to the object's arguments vector.
- m_arguments.push_back(arg);
- }
+ CommandObjectWatchpointEnable(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "enable",
+ "Enable the specified disabled watchpoint(s). If "
+ "no watchpoints are specified, enable all of them.",
+ nullptr) {
+ CommandArgumentEntry arg;
+ CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID,
+ eArgTypeWatchpointIDRange);
+ // Add the entry for the first argument for this command to the object's
+ // arguments vector.
+ m_arguments.push_back(arg);
+ }
- ~CommandObjectWatchpointEnable() override = default;
+ ~CommandObjectWatchpointEnable() override = default;
protected:
- bool
- DoExecute (Args& command,
- CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (!CheckTargetForWatchpointOperations(target, result))
- return false;
-
- std::unique_lock<std::recursive_mutex> lock;
- target->GetWatchpointList().GetListMutex(lock);
-
- const WatchpointList &watchpoints = target->GetWatchpointList();
-
- size_t num_watchpoints = watchpoints.GetSize();
-
- if (num_watchpoints == 0)
- {
- result.AppendError("No watchpoints exist to be enabled.");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- if (command.GetArgumentCount() == 0)
- {
- // No watchpoint selected; enable all currently set watchpoints.
- target->EnableAllWatchpoints();
- result.AppendMessageWithFormat("All watchpoints enabled. (%" PRIu64 " watchpoints)\n", (uint64_t)num_watchpoints);
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- // Particular watchpoints selected; enable 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->EnableWatchpointByID(wp_ids[i]))
- ++count;
- result.AppendMessageWithFormat("%d watchpoints enabled.\n", count);
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (!CheckTargetForWatchpointOperations(target, result))
+ return false;
+
+ std::unique_lock<std::recursive_mutex> lock;
+ target->GetWatchpointList().GetListMutex(lock);
+
+ const WatchpointList &watchpoints = target->GetWatchpointList();
+
+ size_t num_watchpoints = watchpoints.GetSize();
+
+ if (num_watchpoints == 0) {
+ result.AppendError("No watchpoints exist to be enabled.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (command.GetArgumentCount() == 0) {
+ // No watchpoint selected; enable all currently set watchpoints.
+ target->EnableAllWatchpoints();
+ result.AppendMessageWithFormat("All watchpoints enabled. (%" PRIu64
+ " watchpoints)\n",
+ (uint64_t)num_watchpoints);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ } else {
+ // Particular watchpoints selected; enable 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->EnableWatchpointByID(wp_ids[i]))
+ ++count;
+ result.AppendMessageWithFormat("%d watchpoints enabled.\n", count);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
+
+ return result.Succeeded();
+ }
};
//-------------------------------------------------------------------------
@@ -417,80 +381,74 @@ protected:
//-------------------------------------------------------------------------
#pragma mark Disable
-class CommandObjectWatchpointDisable : public CommandObjectParsed
-{
+class CommandObjectWatchpointDisable : public CommandObjectParsed {
public:
- CommandObjectWatchpointDisable (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "watchpoint disable",
- "Disable the specified watchpoint(s) without removing it/them. If no watchpoints are specified, disable them all.",
- nullptr)
- {
- CommandArgumentEntry arg;
- CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange);
- // Add the entry for the first argument for this command to the object's arguments vector.
- m_arguments.push_back(arg);
- }
+ CommandObjectWatchpointDisable(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "watchpoint disable",
+ "Disable the specified watchpoint(s) without "
+ "removing it/them. If no watchpoints are "
+ "specified, disable them all.",
+ nullptr) {
+ CommandArgumentEntry arg;
+ CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID,
+ eArgTypeWatchpointIDRange);
+ // Add the entry for the first argument for this command to the object's
+ // arguments vector.
+ m_arguments.push_back(arg);
+ }
- ~CommandObjectWatchpointDisable() override = default;
+ ~CommandObjectWatchpointDisable() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (!CheckTargetForWatchpointOperations(target, result))
- return false;
-
- std::unique_lock<std::recursive_mutex> lock;
- target->GetWatchpointList().GetListMutex(lock);
-
- const WatchpointList &watchpoints = target->GetWatchpointList();
- size_t num_watchpoints = watchpoints.GetSize();
-
- if (num_watchpoints == 0)
- {
- result.AppendError("No watchpoints exist to be disabled.");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- if (command.GetArgumentCount() == 0)
- {
- // No watchpoint selected; disable all currently set watchpoints.
- if (target->DisableAllWatchpoints())
- {
- result.AppendMessageWithFormat("All watchpoints disabled. (%" PRIu64 " watchpoints)\n", (uint64_t)num_watchpoints);
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- result.AppendError("Disable all watchpoints failed\n");
- result.SetStatus(eReturnStatusFailed);
- }
- }
- else
- {
- // Particular watchpoints selected; disable 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->DisableWatchpointByID(wp_ids[i]))
- ++count;
- result.AppendMessageWithFormat("%d watchpoints disabled.\n", count);
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (!CheckTargetForWatchpointOperations(target, result))
+ return false;
+
+ std::unique_lock<std::recursive_mutex> lock;
+ target->GetWatchpointList().GetListMutex(lock);
+
+ const WatchpointList &watchpoints = target->GetWatchpointList();
+ size_t num_watchpoints = watchpoints.GetSize();
+
+ if (num_watchpoints == 0) {
+ result.AppendError("No watchpoints exist to be disabled.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (command.GetArgumentCount() == 0) {
+ // No watchpoint selected; disable all currently set watchpoints.
+ if (target->DisableAllWatchpoints()) {
+ result.AppendMessageWithFormat("All watchpoints disabled. (%" PRIu64
+ " watchpoints)\n",
+ (uint64_t)num_watchpoints);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ } else {
+ result.AppendError("Disable all watchpoints failed\n");
+ result.SetStatus(eReturnStatusFailed);
+ }
+ } else {
+ // Particular watchpoints selected; disable 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->DisableWatchpointByID(wp_ids[i]))
+ ++count;
+ result.AppendMessageWithFormat("%d watchpoints disabled.\n", count);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
+
+ return result.Succeeded();
+ }
};
//-------------------------------------------------------------------------
@@ -498,229 +456,202 @@ protected:
//-------------------------------------------------------------------------
#pragma mark Delete
-class CommandObjectWatchpointDelete : public CommandObjectParsed
-{
+class CommandObjectWatchpointDelete : public CommandObjectParsed {
public:
- CommandObjectWatchpointDelete (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "watchpoint delete",
- "Delete the specified watchpoint(s). If no watchpoints are specified, delete them all.",
- nullptr)
- {
- CommandArgumentEntry arg;
- CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange);
- // Add the entry for the first argument for this command to the object's arguments vector.
- m_arguments.push_back(arg);
- }
+ CommandObjectWatchpointDelete(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "watchpoint delete",
+ "Delete the specified watchpoint(s). If no "
+ "watchpoints are specified, delete them all.",
+ nullptr) {
+ CommandArgumentEntry arg;
+ CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID,
+ eArgTypeWatchpointIDRange);
+ // Add the entry for the first argument for this command to the object's
+ // arguments vector.
+ m_arguments.push_back(arg);
+ }
- ~CommandObjectWatchpointDelete() override = default;
+ ~CommandObjectWatchpointDelete() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (!CheckTargetForWatchpointOperations(target, result))
- return false;
-
- std::unique_lock<std::recursive_mutex> lock;
- target->GetWatchpointList().GetListMutex(lock);
-
- const WatchpointList &watchpoints = target->GetWatchpointList();
-
- size_t num_watchpoints = watchpoints.GetSize();
-
- if (num_watchpoints == 0)
- {
- result.AppendError("No watchpoints exist to be deleted.");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- if (command.GetArgumentCount() == 0)
- {
- if (!m_interpreter.Confirm("About to delete all watchpoints, do you want to do that?", true))
- {
- result.AppendMessage("Operation cancelled...");
- }
- else
- {
- target->RemoveAllWatchpoints();
- result.AppendMessageWithFormat("All watchpoints removed. (%" PRIu64 " watchpoints)\n", (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;
- }
-
- 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);
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (!CheckTargetForWatchpointOperations(target, result))
+ return false;
+
+ std::unique_lock<std::recursive_mutex> lock;
+ target->GetWatchpointList().GetListMutex(lock);
+
+ const WatchpointList &watchpoints = target->GetWatchpointList();
+
+ size_t num_watchpoints = watchpoints.GetSize();
+
+ if (num_watchpoints == 0) {
+ result.AppendError("No watchpoints exist to be deleted.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (command.GetArgumentCount() == 0) {
+ if (!m_interpreter.Confirm(
+ "About to delete all watchpoints, do you want to do that?",
+ true)) {
+ result.AppendMessage("Operation cancelled...");
+ } else {
+ target->RemoveAllWatchpoints();
+ result.AppendMessageWithFormat("All watchpoints removed. (%" PRIu64
+ " watchpoints)\n",
+ (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);
}
+
+ return result.Succeeded();
+ }
};
//-------------------------------------------------------------------------
// CommandObjectWatchpointIgnore
//-------------------------------------------------------------------------
-class CommandObjectWatchpointIgnore : public CommandObjectParsed
-{
+class CommandObjectWatchpointIgnore : public CommandObjectParsed {
public:
- CommandObjectWatchpointIgnore (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "watchpoint ignore",
- "Set ignore count on the specified watchpoint(s). If no watchpoints are specified, set them all.",
+ CommandObjectWatchpointIgnore(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "watchpoint ignore",
+ "Set ignore count on the specified watchpoint(s). "
+ "If no watchpoints are specified, set them all.",
nullptr),
- m_options()
- {
- CommandArgumentEntry arg;
- CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange);
- // Add the entry for the first argument for this command to the object's arguments vector.
- m_arguments.push_back(arg);
- }
+ m_options() {
+ CommandArgumentEntry arg;
+ CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID,
+ eArgTypeWatchpointIDRange);
+ // Add the entry for the first argument for this command to the object's
+ // arguments vector.
+ m_arguments.push_back(arg);
+ }
- ~CommandObjectWatchpointIgnore() override = default;
+ ~CommandObjectWatchpointIgnore() override = default;
- Options *
- GetOptions () override
- {
- return &m_options;
- }
+ Options *GetOptions() override { return &m_options; }
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options(),
- m_ignore_count (0)
- {
- }
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options(), m_ignore_count(0) {}
- ~CommandOptions() override = default;
+ ~CommandOptions() override = default;
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'i':
- m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
- if (m_ignore_count == UINT32_MAX)
- error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg);
- break;
- default:
- error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
- break;
- }
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
- return error;
- }
+ switch (short_option) {
+ case 'i':
+ m_ignore_count = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);
+ if (m_ignore_count == UINT32_MAX)
+ error.SetErrorStringWithFormat("invalid ignore count '%s'",
+ option_arg);
+ break;
+ default:
+ error.SetErrorStringWithFormat("unrecognized option '%c'",
+ short_option);
+ break;
+ }
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_ignore_count = 0;
- }
+ return error;
+ }
- const OptionDefinition *
- GetDefinitions () override
- {
- return g_option_table;
- }
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_ignore_count = 0;
+ }
- // Options table: Required for subclasses of Options.
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
- static OptionDefinition g_option_table[];
+ // Options table: Required for subclasses of Options.
- // Instance variables to hold the values for command options.
+ static OptionDefinition g_option_table[];
- uint32_t m_ignore_count;
- };
+ // Instance variables to hold the values for command options.
-protected:
- bool
- DoExecute (Args& command,
- CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (!CheckTargetForWatchpointOperations(target, result))
- return false;
-
- std::unique_lock<std::recursive_mutex> lock;
- target->GetWatchpointList().GetListMutex(lock);
-
- const WatchpointList &watchpoints = target->GetWatchpointList();
-
- size_t num_watchpoints = watchpoints.GetSize();
-
- if (num_watchpoints == 0)
- {
- result.AppendError("No watchpoints exist to be ignored.");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
+ uint32_t m_ignore_count;
+ };
- if (command.GetArgumentCount() == 0)
- {
- target->IgnoreAllWatchpoints(m_options.m_ignore_count);
- result.AppendMessageWithFormat("All watchpoints ignored. (%" PRIu64 " watchpoints)\n", (uint64_t)num_watchpoints);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- // Particular watchpoints selected; ignore 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->IgnoreWatchpointByID(wp_ids[i], m_options.m_ignore_count))
- ++count;
- result.AppendMessageWithFormat("%d watchpoints ignored.\n",count);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
+protected:
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (!CheckTargetForWatchpointOperations(target, result))
+ return false;
+
+ std::unique_lock<std::recursive_mutex> lock;
+ target->GetWatchpointList().GetListMutex(lock);
+
+ const WatchpointList &watchpoints = target->GetWatchpointList();
+
+ size_t num_watchpoints = watchpoints.GetSize();
+
+ if (num_watchpoints == 0) {
+ result.AppendError("No watchpoints exist to be ignored.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (command.GetArgumentCount() == 0) {
+ target->IgnoreAllWatchpoints(m_options.m_ignore_count);
+ result.AppendMessageWithFormat("All watchpoints ignored. (%" PRIu64
+ " watchpoints)\n",
+ (uint64_t)num_watchpoints);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ } else {
+ // Particular watchpoints selected; ignore 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->IgnoreWatchpointByID(wp_ids[i], m_options.m_ignore_count))
+ ++count;
+ result.AppendMessageWithFormat("%d watchpoints ignored.\n", count);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
+ return result.Succeeded();
+ }
+
private:
- CommandOptions m_options;
+ CommandOptions m_options;
};
#pragma mark Ignore::CommandOptions
OptionDefinition
-CommandObjectWatchpointIgnore::CommandOptions::g_option_table[] =
-{
- // clang-format off
+ CommandObjectWatchpointIgnore::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_ALL, true, "ignore-count", 'i', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, "Set the number of times this watchpoint is skipped before stopping."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
//-------------------------------------------------------------------------
@@ -728,161 +659,136 @@ CommandObjectWatchpointIgnore::CommandOp
//-------------------------------------------------------------------------
#pragma mark Modify
-class CommandObjectWatchpointModify : public CommandObjectParsed
-{
+class CommandObjectWatchpointModify : public CommandObjectParsed {
public:
- CommandObjectWatchpointModify (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "watchpoint modify",
- "Modify the options on a watchpoint or set of watchpoints in the executable. "
- "If no watchpoint is specified, act on the last created watchpoint. "
- "Passing an empty argument clears the modification.",
- nullptr),
- m_options()
- {
- CommandArgumentEntry arg;
- CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID, eArgTypeWatchpointIDRange);
- // Add the entry for the first argument for this command to the object's arguments vector.
- m_arguments.push_back (arg);
- }
-
- ~CommandObjectWatchpointModify() override = default;
+ CommandObjectWatchpointModify(CommandInterpreter &interpreter)
+ : CommandObjectParsed(
+ interpreter, "watchpoint modify",
+ "Modify the options on a watchpoint or set of watchpoints in the "
+ "executable. "
+ "If no watchpoint is specified, act on the last created "
+ "watchpoint. "
+ "Passing an empty argument clears the modification.",
+ nullptr),
+ m_options() {
+ CommandArgumentEntry arg;
+ CommandObject::AddIDsArgumentData(arg, eArgTypeWatchpointID,
+ eArgTypeWatchpointIDRange);
+ // Add the entry for the first argument for this command to the object's
+ // arguments vector.
+ m_arguments.push_back(arg);
+ }
+
+ ~CommandObjectWatchpointModify() override = default;
+
+ Options *GetOptions() override { return &m_options; }
+
+ class CommandOptions : public Options {
+ public:
+ CommandOptions() : Options(), m_condition(), m_condition_passed(false) {}
+
+ ~CommandOptions() override = default;
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option) {
+ case 'c':
+ if (option_arg != nullptr)
+ m_condition.assign(option_arg);
+ else
+ m_condition.clear();
+ m_condition_passed = true;
+ break;
+ default:
+ error.SetErrorStringWithFormat("unrecognized option '%c'",
+ short_option);
+ break;
+ }
- Options *
- GetOptions () override
- {
- return &m_options;
+ return error;
}
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options(),
- m_condition (),
- m_condition_passed (false)
- {
- }
-
- ~CommandOptions() override = default;
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_condition.clear();
+ m_condition_passed = false;
+ }
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'c':
- if (option_arg != nullptr)
- m_condition.assign (option_arg);
- else
- m_condition.clear();
- m_condition_passed = true;
- break;
- default:
- error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
- break;
- }
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
- return error;
- }
+ // Options table: Required for subclasses of Options.
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_condition.clear();
- m_condition_passed = false;
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
+ static OptionDefinition g_option_table[];
- // Options table: Required for subclasses of Options.
+ // Instance variables to hold the values for command options.
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
-
- std::string m_condition;
- bool m_condition_passed;
- };
+ std::string m_condition;
+ bool m_condition_passed;
+ };
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (!CheckTargetForWatchpointOperations(target, result))
- return false;
-
- std::unique_lock<std::recursive_mutex> lock;
- target->GetWatchpointList().GetListMutex(lock);
-
- const WatchpointList &watchpoints = target->GetWatchpointList();
-
- size_t num_watchpoints = watchpoints.GetSize();
-
- if (num_watchpoints == 0)
- {
- result.AppendError("No watchpoints exist to be modified.");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- if (command.GetArgumentCount() == 0)
- {
- WatchpointSP wp_sp = target->GetLastCreatedWatchpoint();
- wp_sp->SetCondition(m_options.m_condition.c_str());
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- // Particular watchpoints selected; set condition on 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)
- {
- WatchpointSP wp_sp = watchpoints.FindByID(wp_ids[i]);
- if (wp_sp)
- {
- wp_sp->SetCondition(m_options.m_condition.c_str());
- ++count;
- }
- }
- result.AppendMessageWithFormat("%d watchpoints modified.\n",count);
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ if (!CheckTargetForWatchpointOperations(target, result))
+ return false;
+
+ std::unique_lock<std::recursive_mutex> lock;
+ target->GetWatchpointList().GetListMutex(lock);
+
+ const WatchpointList &watchpoints = target->GetWatchpointList();
+
+ size_t num_watchpoints = watchpoints.GetSize();
+
+ if (num_watchpoints == 0) {
+ result.AppendError("No watchpoints exist to be modified.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (command.GetArgumentCount() == 0) {
+ WatchpointSP wp_sp = target->GetLastCreatedWatchpoint();
+ wp_sp->SetCondition(m_options.m_condition.c_str());
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ } else {
+ // Particular watchpoints selected; set condition on 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) {
+ WatchpointSP wp_sp = watchpoints.FindByID(wp_ids[i]);
+ if (wp_sp) {
+ wp_sp->SetCondition(m_options.m_condition.c_str());
+ ++count;
+ }
+ }
+ result.AppendMessageWithFormat("%d watchpoints modified.\n", count);
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
}
+ return result.Succeeded();
+ }
+
private:
- CommandOptions m_options;
+ CommandOptions m_options;
};
#pragma mark Modify::CommandOptions
OptionDefinition
-CommandObjectWatchpointModify::CommandOptions::g_option_table[] =
-{
- // clang-format off
+ CommandObjectWatchpointModify::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_ALL, false, "condition", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeExpression, "The watchpoint stops only if this condition expression evaluates to true."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr}
- // clang-format on
+ // clang-format on
};
//-------------------------------------------------------------------------
@@ -890,208 +796,189 @@ CommandObjectWatchpointModify::CommandOp
//-------------------------------------------------------------------------
#pragma mark SetVariable
-class CommandObjectWatchpointSetVariable : public CommandObjectParsed
-{
+class CommandObjectWatchpointSetVariable : public CommandObjectParsed {
public:
- CommandObjectWatchpointSetVariable (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "watchpoint set variable",
- "Set a watchpoint on a variable. "
- "Use the '-w' option to specify the type of watchpoint and "
- "the '-s' option to specify the byte size to watch for. "
- "If no '-w' option is specified, it defaults to write. "
- "If no '-s' option is specified, it defaults to the variable's "
- "byte size. "
- "Note that there are limited hardware resources for watchpoints. "
- "If watchpoint setting fails, consider disable/delete existing ones "
- "to free up resources.",
- nullptr,
- eCommandRequiresFrame |
- eCommandTryTargetAPILock |
- eCommandProcessMustBeLaunched |
- eCommandProcessMustBePaused ),
- m_option_group(),
- m_option_watchpoint ()
- {
- SetHelpLong(
-R"(
+ CommandObjectWatchpointSetVariable(CommandInterpreter &interpreter)
+ : CommandObjectParsed(
+ interpreter, "watchpoint set variable",
+ "Set a watchpoint on a variable. "
+ "Use the '-w' option to specify the type of watchpoint and "
+ "the '-s' option to specify the byte size to watch for. "
+ "If no '-w' option is specified, it defaults to write. "
+ "If no '-s' option is specified, it defaults to the variable's "
+ "byte size. "
+ "Note that there are limited hardware resources for watchpoints. "
+ "If watchpoint setting fails, consider disable/delete existing "
+ "ones "
+ "to free up resources.",
+ nullptr,
+ eCommandRequiresFrame | eCommandTryTargetAPILock |
+ eCommandProcessMustBeLaunched | eCommandProcessMustBePaused),
+ m_option_group(), m_option_watchpoint() {
+ SetHelpLong(
+ R"(
Examples:
(lldb) watchpoint set variable -w read_write my_global_var
-)" " Watches my_global_var for read/write access, with the region to watch \
-corresponding to the byte size of the data type."
- );
-
- CommandArgumentEntry arg;
- CommandArgumentData var_name_arg;
-
- // Define the only variant of this arg.
- var_name_arg.arg_type = eArgTypeVarName;
- var_name_arg.arg_repetition = eArgRepeatPlain;
-
- // Push the variant into the argument entry.
- arg.push_back (var_name_arg);
-
- // Push the data for the only argument into the m_arguments vector.
- m_arguments.push_back (arg);
-
- // Absorb the '-w' and '-s' options into our option group.
- m_option_group.Append (&m_option_watchpoint, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Finalize();
- }
+)"
+ " Watches my_global_var for read/write access, with the region to watch \
+corresponding to the byte size of the data type.");
- ~CommandObjectWatchpointSetVariable() override = default;
+ CommandArgumentEntry arg;
+ CommandArgumentData var_name_arg;
- Options *
- GetOptions () override
- {
- return &m_option_group;
- }
+ // Define the only variant of this arg.
+ var_name_arg.arg_type = eArgTypeVarName;
+ var_name_arg.arg_repetition = eArgRepeatPlain;
-protected:
- static size_t GetVariableCallback (void *baton,
- const char *name,
- VariableList &variable_list)
- {
- Target *target = static_cast<Target *>(baton);
- if (target)
- {
- return target->GetImages().FindGlobalVariables (ConstString(name),
- true,
- UINT32_MAX,
- variable_list);
- }
- return 0;
- }
-
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- StackFrame *frame = m_exe_ctx.GetFramePtr();
-
- // If no argument is present, issue an error message. There's no way to set a watchpoint.
- if (command.GetArgumentCount() <= 0)
- {
- result.GetErrorStream().Printf("error: required argument missing; specify your program variable to watch for\n");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
+ // Push the variant into the argument entry.
+ arg.push_back(var_name_arg);
- // If no '-w' is specified, default to '-w write'.
- if (!m_option_watchpoint.watch_type_specified)
- {
- m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchWrite;
- }
+ // Push the data for the only argument into the m_arguments vector.
+ m_arguments.push_back(arg);
- // We passed the sanity check for the command.
- // Proceed to set the watchpoint now.
- lldb::addr_t addr = 0;
- size_t size = 0;
-
- VariableSP var_sp;
- ValueObjectSP valobj_sp;
- Stream &output_stream = result.GetOutputStream();
-
- // A simple watch variable gesture allows only one argument.
- if (command.GetArgumentCount() != 1)
- {
- result.GetErrorStream().Printf("error: specify exactly one variable to watch for\n");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
+ // Absorb the '-w' and '-s' options into our option group.
+ m_option_group.Append(&m_option_watchpoint, LLDB_OPT_SET_ALL,
+ LLDB_OPT_SET_1);
+ m_option_group.Finalize();
+ }
- // Things have checked out ok...
- Error error;
- uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
- StackFrame::eExpressionPathOptionsAllowDirectIVarAccess;
- valobj_sp = frame->GetValueForVariableExpressionPath (command.GetArgumentAtIndex(0),
- eNoDynamicValues,
- expr_path_options,
- var_sp,
- error);
-
- if (!valobj_sp)
- {
- // Not in the frame; let's check the globals.
-
- VariableList variable_list;
- ValueObjectList valobj_list;
-
- Error error (Variable::GetValuesForVariableExpressionPath (command.GetArgumentAtIndex(0),
- m_exe_ctx.GetBestExecutionContextScope(),
- GetVariableCallback,
- target,
- variable_list,
- valobj_list));
-
- if (valobj_list.GetSize())
- valobj_sp = valobj_list.GetValueObjectAtIndex(0);
- }
-
- CompilerType compiler_type;
-
- if (valobj_sp)
- {
- AddressType addr_type;
- addr = valobj_sp->GetAddressOf(false, &addr_type);
- if (addr_type == eAddressTypeLoad)
- {
- // We're in business.
- // Find out the size of this variable.
- size = m_option_watchpoint.watch_size == 0 ? valobj_sp->GetByteSize()
- : m_option_watchpoint.watch_size;
- }
- compiler_type = valobj_sp->GetCompilerType();
- }
- else
- {
- const char *error_cstr = error.AsCString(nullptr);
- if (error_cstr)
- result.GetErrorStream().Printf("error: %s\n", error_cstr);
- else
- result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n",
- command.GetArgumentAtIndex(0));
- return false;
- }
+ ~CommandObjectWatchpointSetVariable() override = default;
- // Now it's time to create the watchpoint.
- uint32_t watch_type = m_option_watchpoint.watch_type;
-
- error.Clear();
- Watchpoint *wp = target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error).get();
- if (wp)
- {
- wp->SetWatchSpec(command.GetArgumentAtIndex(0));
- wp->SetWatchVariable(true);
- if (var_sp && var_sp->GetDeclaration().GetFile())
- {
- StreamString ss;
- // True to show fullpath for declaration file.
- var_sp->GetDeclaration().DumpStopContext(&ss, true);
- wp->SetDeclInfo(ss.GetString());
- }
- output_stream.Printf("Watchpoint created: ");
- wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull);
- output_stream.EOL();
- result.SetStatus(eReturnStatusSuccessFinishResult);
- }
- else
- {
- result.AppendErrorWithFormat("Watchpoint creation failed (addr=0x%" PRIx64 ", size=%" PRIu64 ", variable expression='%s').\n",
- addr, (uint64_t)size, command.GetArgumentAtIndex(0));
- if (error.AsCString(nullptr))
- result.AppendError(error.AsCString());
- result.SetStatus(eReturnStatusFailed);
- }
+ Options *GetOptions() override { return &m_option_group; }
- return result.Succeeded();
+protected:
+ static size_t GetVariableCallback(void *baton, const char *name,
+ VariableList &variable_list) {
+ Target *target = static_cast<Target *>(baton);
+ if (target) {
+ return target->GetImages().FindGlobalVariables(ConstString(name), true,
+ UINT32_MAX, variable_list);
+ }
+ return 0;
+ }
+
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ StackFrame *frame = m_exe_ctx.GetFramePtr();
+
+ // If no argument is present, issue an error message. There's no way to set
+ // a watchpoint.
+ if (command.GetArgumentCount() <= 0) {
+ result.GetErrorStream().Printf("error: required argument missing; "
+ "specify your program variable to watch "
+ "for\n");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ // If no '-w' is specified, default to '-w write'.
+ if (!m_option_watchpoint.watch_type_specified) {
+ m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchWrite;
+ }
+
+ // We passed the sanity check for the command.
+ // Proceed to set the watchpoint now.
+ lldb::addr_t addr = 0;
+ size_t size = 0;
+
+ VariableSP var_sp;
+ ValueObjectSP valobj_sp;
+ Stream &output_stream = result.GetOutputStream();
+
+ // A simple watch variable gesture allows only one argument.
+ if (command.GetArgumentCount() != 1) {
+ result.GetErrorStream().Printf(
+ "error: specify exactly one variable to watch for\n");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ // Things have checked out ok...
+ Error error;
+ uint32_t expr_path_options =
+ StackFrame::eExpressionPathOptionCheckPtrVsMember |
+ StackFrame::eExpressionPathOptionsAllowDirectIVarAccess;
+ valobj_sp = frame->GetValueForVariableExpressionPath(
+ command.GetArgumentAtIndex(0), eNoDynamicValues, expr_path_options,
+ var_sp, error);
+
+ if (!valobj_sp) {
+ // Not in the frame; let's check the globals.
+
+ VariableList variable_list;
+ ValueObjectList valobj_list;
+
+ Error error(Variable::GetValuesForVariableExpressionPath(
+ command.GetArgumentAtIndex(0),
+ m_exe_ctx.GetBestExecutionContextScope(), GetVariableCallback, target,
+ variable_list, valobj_list));
+
+ if (valobj_list.GetSize())
+ valobj_sp = valobj_list.GetValueObjectAtIndex(0);
+ }
+
+ CompilerType compiler_type;
+
+ if (valobj_sp) {
+ AddressType addr_type;
+ addr = valobj_sp->GetAddressOf(false, &addr_type);
+ if (addr_type == eAddressTypeLoad) {
+ // We're in business.
+ // Find out the size of this variable.
+ size = m_option_watchpoint.watch_size == 0
+ ? valobj_sp->GetByteSize()
+ : m_option_watchpoint.watch_size;
+ }
+ compiler_type = valobj_sp->GetCompilerType();
+ } else {
+ const char *error_cstr = error.AsCString(nullptr);
+ if (error_cstr)
+ result.GetErrorStream().Printf("error: %s\n", error_cstr);
+ else
+ result.GetErrorStream().Printf("error: unable to find any variable "
+ "expression path that matches '%s'\n",
+ command.GetArgumentAtIndex(0));
+ return false;
+ }
+
+ // Now it's time to create the watchpoint.
+ uint32_t watch_type = m_option_watchpoint.watch_type;
+
+ error.Clear();
+ Watchpoint *wp =
+ target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error)
+ .get();
+ if (wp) {
+ wp->SetWatchSpec(command.GetArgumentAtIndex(0));
+ wp->SetWatchVariable(true);
+ if (var_sp && var_sp->GetDeclaration().GetFile()) {
+ StreamString ss;
+ // True to show fullpath for declaration file.
+ var_sp->GetDeclaration().DumpStopContext(&ss, true);
+ wp->SetDeclInfo(ss.GetString());
+ }
+ output_stream.Printf("Watchpoint created: ");
+ wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull);
+ output_stream.EOL();
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ } else {
+ result.AppendErrorWithFormat(
+ "Watchpoint creation failed (addr=0x%" PRIx64 ", size=%" PRIu64
+ ", variable expression='%s').\n",
+ addr, (uint64_t)size, command.GetArgumentAtIndex(0));
+ if (error.AsCString(nullptr))
+ result.AppendError(error.AsCString());
+ result.SetStatus(eReturnStatusFailed);
}
+ return result.Succeeded();
+ }
+
private:
- OptionGroupOptions m_option_group;
- OptionGroupWatchpoint m_option_watchpoint;
+ OptionGroupOptions m_option_group;
+ OptionGroupWatchpoint m_option_watchpoint;
};
//-------------------------------------------------------------------------
@@ -1099,210 +986,195 @@ private:
//-------------------------------------------------------------------------
#pragma mark Set
-class CommandObjectWatchpointSetExpression : public CommandObjectRaw
-{
+class CommandObjectWatchpointSetExpression : public CommandObjectRaw {
public:
- CommandObjectWatchpointSetExpression (CommandInterpreter &interpreter) :
- CommandObjectRaw(interpreter,
- "watchpoint set expression",
- "Set a watchpoint on an address by supplying an expression. "
- "Use the '-w' option to specify the type of watchpoint and "
- "the '-s' option to specify the byte size to watch for. "
- "If no '-w' option is specified, it defaults to write. "
- "If no '-s' option is specified, it defaults to the target's "
- "pointer byte size. "
- "Note that there are limited hardware resources for watchpoints. "
- "If watchpoint setting fails, consider disable/delete existing ones "
- "to free up resources.",
- nullptr,
- eCommandRequiresFrame |
- eCommandTryTargetAPILock |
- eCommandProcessMustBeLaunched |
- eCommandProcessMustBePaused ),
- m_option_group(),
- m_option_watchpoint ()
- {
- SetHelpLong(
-R"(
+ CommandObjectWatchpointSetExpression(CommandInterpreter &interpreter)
+ : CommandObjectRaw(
+ interpreter, "watchpoint set expression",
+ "Set a watchpoint on an address by supplying an expression. "
+ "Use the '-w' option to specify the type of watchpoint and "
+ "the '-s' option to specify the byte size to watch for. "
+ "If no '-w' option is specified, it defaults to write. "
+ "If no '-s' option is specified, it defaults to the target's "
+ "pointer byte size. "
+ "Note that there are limited hardware resources for watchpoints. "
+ "If watchpoint setting fails, consider disable/delete existing "
+ "ones "
+ "to free up resources.",
+ nullptr,
+ eCommandRequiresFrame | eCommandTryTargetAPILock |
+ eCommandProcessMustBeLaunched | eCommandProcessMustBePaused),
+ m_option_group(), m_option_watchpoint() {
+ SetHelpLong(
+ R"(
Examples:
(lldb) watchpoint set expression -w write -s 1 -- foo + 32
- Watches write access for the 1-byte region pointed to by the address 'foo + 32')"
- );
+ Watches write access for the 1-byte region pointed to by the address 'foo + 32')");
- CommandArgumentEntry arg;
- CommandArgumentData expression_arg;
-
- // Define the only variant of this arg.
- expression_arg.arg_type = eArgTypeExpression;
- expression_arg.arg_repetition = eArgRepeatPlain;
-
- // Push the only variant into the argument entry.
- arg.push_back (expression_arg);
-
- // Push the data for the only argument into the m_arguments vector.
- m_arguments.push_back (arg);
-
- // Absorb the '-w' and '-s' options into our option group.
- m_option_group.Append (&m_option_watchpoint, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Finalize();
- }
-
- ~CommandObjectWatchpointSetExpression() override = default;
-
- // Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
- bool
- WantsCompletion() override { return true; }
+ CommandArgumentEntry arg;
+ CommandArgumentData expression_arg;
- Options *
- GetOptions () override
- {
- return &m_option_group;
- }
+ // Define the only variant of this arg.
+ expression_arg.arg_type = eArgTypeExpression;
+ expression_arg.arg_repetition = eArgRepeatPlain;
-protected:
- bool
- DoExecute (const char *raw_command, CommandReturnObject &result) override
- {
- auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
- m_option_group.NotifyOptionParsingStarting(&exe_ctx); // This is a raw command, so notify the option group
-
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- StackFrame *frame = m_exe_ctx.GetFramePtr();
-
- Args command(raw_command);
- const char *expr = nullptr;
- if (raw_command[0] == '-')
- {
- // We have some options and these options MUST end with --.
- const char *end_options = nullptr;
- const char *s = raw_command;
- while (s && s[0])
- {
- end_options = ::strstr (s, "--");
- if (end_options)
- {
- end_options += 2; // Get past the "--"
- if (::isspace (end_options[0]))
- {
- expr = end_options;
- while (::isspace (*expr))
- ++expr;
- break;
- }
- }
- s = end_options;
- }
-
- if (end_options)
- {
- Args args (llvm::StringRef(raw_command, end_options - raw_command));
- if (!ParseOptions (args, result))
- return false;
-
- Error error(m_option_group.NotifyOptionParsingFinished(
- &exe_ctx));
- if (error.Fail())
- {
- result.AppendError (error.AsCString());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- }
+ // Push the only variant into the argument entry.
+ arg.push_back(expression_arg);
- if (expr == nullptr)
- expr = raw_command;
+ // Push the data for the only argument into the m_arguments vector.
+ m_arguments.push_back(arg);
- // If no argument is present, issue an error message. There's no way to set a watchpoint.
- if (command.GetArgumentCount() == 0)
- {
- result.GetErrorStream().Printf("error: required argument missing; specify an expression to evaulate into the address to watch for\n");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
+ // Absorb the '-w' and '-s' options into our option group.
+ m_option_group.Append(&m_option_watchpoint, LLDB_OPT_SET_ALL,
+ LLDB_OPT_SET_1);
+ m_option_group.Finalize();
+ }
- // If no '-w' is specified, default to '-w write'.
- if (!m_option_watchpoint.watch_type_specified)
- {
- m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchWrite;
- }
+ ~CommandObjectWatchpointSetExpression() override = default;
- // We passed the sanity check for the command.
- // Proceed to set the watchpoint now.
- lldb::addr_t addr = 0;
- size_t size = 0;
-
- ValueObjectSP valobj_sp;
-
- // Use expression evaluation to arrive at the address to watch.
- EvaluateExpressionOptions options;
- options.SetCoerceToId(false);
- options.SetUnwindOnError(true);
- options.SetKeepInMemory(false);
- options.SetTryAllThreads(true);
- options.SetTimeoutUsec(0);
-
- ExpressionResults expr_result = target->EvaluateExpression (expr,
- frame,
- valobj_sp,
- options);
- if (expr_result != eExpressionCompleted)
- {
- result.GetErrorStream().Printf("error: expression evaluation of address to watch failed\n");
- result.GetErrorStream().Printf("expression evaluated: %s\n", expr);
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
+ // Overrides base class's behavior where WantsCompletion =
+ // !WantsRawCommandString.
+ bool WantsCompletion() override { return true; }
- // Get the address to watch.
- bool success = false;
- addr = valobj_sp->GetValueAsUnsigned(0, &success);
- if (!success)
- {
- result.GetErrorStream().Printf("error: expression did not evaluate to an address\n");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- if (m_option_watchpoint.watch_size != 0)
- size = m_option_watchpoint.watch_size;
- else
- size = target->GetArchitecture().GetAddressByteSize();
-
- // Now it's time to create the watchpoint.
- uint32_t watch_type = m_option_watchpoint.watch_type;
-
- // Fetch the type from the value object, the type of the watched object is the pointee type
- /// of the expression, so convert to that if we found a valid type.
- CompilerType compiler_type(valobj_sp->GetCompilerType());
-
- Error error;
- Watchpoint *wp = target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error).get();
- if (wp)
- {
- Stream &output_stream = result.GetOutputStream();
- output_stream.Printf("Watchpoint created: ");
- wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull);
- output_stream.EOL();
- result.SetStatus(eReturnStatusSuccessFinishResult);
- }
- else
- {
- result.AppendErrorWithFormat("Watchpoint creation failed (addr=0x%" PRIx64 ", size=%" PRIu64 ").\n",
- addr, (uint64_t)size);
- if (error.AsCString(nullptr))
- result.AppendError(error.AsCString());
- result.SetStatus(eReturnStatusFailed);
- }
+ Options *GetOptions() override { return &m_option_group; }
- return result.Succeeded();
+protected:
+ bool DoExecute(const char *raw_command,
+ CommandReturnObject &result) override {
+ auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
+ m_option_group.NotifyOptionParsingStarting(
+ &exe_ctx); // This is a raw command, so notify the option group
+
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ StackFrame *frame = m_exe_ctx.GetFramePtr();
+
+ Args command(raw_command);
+ const char *expr = nullptr;
+ if (raw_command[0] == '-') {
+ // We have some options and these options MUST end with --.
+ const char *end_options = nullptr;
+ const char *s = raw_command;
+ while (s && s[0]) {
+ end_options = ::strstr(s, "--");
+ if (end_options) {
+ end_options += 2; // Get past the "--"
+ if (::isspace(end_options[0])) {
+ expr = end_options;
+ while (::isspace(*expr))
+ ++expr;
+ break;
+ }
+ }
+ s = end_options;
+ }
+
+ if (end_options) {
+ Args args(llvm::StringRef(raw_command, end_options - raw_command));
+ if (!ParseOptions(args, result))
+ return false;
+
+ Error error(m_option_group.NotifyOptionParsingFinished(&exe_ctx));
+ if (error.Fail()) {
+ result.AppendError(error.AsCString());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+ }
+ }
+
+ if (expr == nullptr)
+ expr = raw_command;
+
+ // If no argument is present, issue an error message. There's no way to set
+ // a watchpoint.
+ if (command.GetArgumentCount() == 0) {
+ result.GetErrorStream().Printf("error: required argument missing; "
+ "specify an expression to evaulate into "
+ "the address to watch for\n");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ // If no '-w' is specified, default to '-w write'.
+ if (!m_option_watchpoint.watch_type_specified) {
+ m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchWrite;
+ }
+
+ // We passed the sanity check for the command.
+ // Proceed to set the watchpoint now.
+ lldb::addr_t addr = 0;
+ size_t size = 0;
+
+ ValueObjectSP valobj_sp;
+
+ // Use expression evaluation to arrive at the address to watch.
+ EvaluateExpressionOptions options;
+ options.SetCoerceToId(false);
+ options.SetUnwindOnError(true);
+ options.SetKeepInMemory(false);
+ options.SetTryAllThreads(true);
+ options.SetTimeoutUsec(0);
+
+ ExpressionResults expr_result =
+ target->EvaluateExpression(expr, frame, valobj_sp, options);
+ if (expr_result != eExpressionCompleted) {
+ result.GetErrorStream().Printf(
+ "error: expression evaluation of address to watch failed\n");
+ result.GetErrorStream().Printf("expression evaluated: %s\n", expr);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ // Get the address to watch.
+ bool success = false;
+ addr = valobj_sp->GetValueAsUnsigned(0, &success);
+ if (!success) {
+ result.GetErrorStream().Printf(
+ "error: expression did not evaluate to an address\n");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (m_option_watchpoint.watch_size != 0)
+ size = m_option_watchpoint.watch_size;
+ else
+ size = target->GetArchitecture().GetAddressByteSize();
+
+ // Now it's time to create the watchpoint.
+ uint32_t watch_type = m_option_watchpoint.watch_type;
+
+ // Fetch the type from the value object, the type of the watched object is
+ // the pointee type
+ /// of the expression, so convert to that if we found a valid type.
+ CompilerType compiler_type(valobj_sp->GetCompilerType());
+
+ Error error;
+ Watchpoint *wp =
+ target->CreateWatchpoint(addr, size, &compiler_type, watch_type, error)
+ .get();
+ if (wp) {
+ Stream &output_stream = result.GetOutputStream();
+ output_stream.Printf("Watchpoint created: ");
+ wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull);
+ output_stream.EOL();
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ } else {
+ result.AppendErrorWithFormat("Watchpoint creation failed (addr=0x%" PRIx64
+ ", size=%" PRIu64 ").\n",
+ addr, (uint64_t)size);
+ if (error.AsCString(nullptr))
+ result.AppendError(error.AsCString());
+ result.SetStatus(eReturnStatusFailed);
}
+ return result.Succeeded();
+ }
+
private:
- OptionGroupOptions m_option_group;
- OptionGroupWatchpoint m_option_watchpoint;
+ OptionGroupOptions m_option_group;
+ OptionGroupWatchpoint m_option_watchpoint;
};
//-------------------------------------------------------------------------
@@ -1310,19 +1182,22 @@ private:
//-------------------------------------------------------------------------
#pragma mark Set
-class CommandObjectWatchpointSet : public CommandObjectMultiword
-{
+class CommandObjectWatchpointSet : public CommandObjectMultiword {
public:
- CommandObjectWatchpointSet(CommandInterpreter &interpreter)
- : CommandObjectMultiword(interpreter, "watchpoint set", "Commands for setting a watchpoint.",
- "watchpoint set <subcommand> [<subcommand-options>]")
- {
-
- LoadSubCommand ("variable", CommandObjectSP (new CommandObjectWatchpointSetVariable (interpreter)));
- LoadSubCommand ("expression", CommandObjectSP (new CommandObjectWatchpointSetExpression (interpreter)));
- }
+ CommandObjectWatchpointSet(CommandInterpreter &interpreter)
+ : CommandObjectMultiword(
+ interpreter, "watchpoint set", "Commands for setting a watchpoint.",
+ "watchpoint set <subcommand> [<subcommand-options>]") {
+
+ LoadSubCommand(
+ "variable",
+ CommandObjectSP(new CommandObjectWatchpointSetVariable(interpreter)));
+ LoadSubCommand(
+ "expression",
+ CommandObjectSP(new CommandObjectWatchpointSetExpression(interpreter)));
+ }
- ~CommandObjectWatchpointSet() override = default;
+ ~CommandObjectWatchpointSet() override = default;
};
//-------------------------------------------------------------------------
@@ -1330,36 +1205,45 @@ public:
//-------------------------------------------------------------------------
#pragma mark MultiwordWatchpoint
-CommandObjectMultiwordWatchpoint::CommandObjectMultiwordWatchpoint(CommandInterpreter &interpreter)
- : CommandObjectMultiword(interpreter, "watchpoint", "Commands for operating on watchpoints.",
- "watchpoint <subcommand> [<command-options>]")
-{
- CommandObjectSP list_command_object (new CommandObjectWatchpointList (interpreter));
- CommandObjectSP enable_command_object (new CommandObjectWatchpointEnable (interpreter));
- CommandObjectSP disable_command_object (new CommandObjectWatchpointDisable (interpreter));
- CommandObjectSP delete_command_object (new CommandObjectWatchpointDelete (interpreter));
- CommandObjectSP ignore_command_object (new CommandObjectWatchpointIgnore (interpreter));
- CommandObjectSP command_command_object (new CommandObjectWatchpointCommand (interpreter));
- CommandObjectSP modify_command_object (new CommandObjectWatchpointModify (interpreter));
- CommandObjectSP set_command_object (new CommandObjectWatchpointSet (interpreter));
-
- list_command_object->SetCommandName ("watchpoint list");
- enable_command_object->SetCommandName("watchpoint enable");
- disable_command_object->SetCommandName("watchpoint disable");
- delete_command_object->SetCommandName("watchpoint delete");
- ignore_command_object->SetCommandName("watchpoint ignore");
- command_command_object->SetCommandName ("watchpoint command");
- modify_command_object->SetCommandName("watchpoint modify");
- set_command_object->SetCommandName("watchpoint set");
-
- LoadSubCommand ("list", list_command_object);
- LoadSubCommand ("enable", enable_command_object);
- LoadSubCommand ("disable", disable_command_object);
- LoadSubCommand ("delete", delete_command_object);
- LoadSubCommand ("ignore", ignore_command_object);
- LoadSubCommand ("command", command_command_object);
- LoadSubCommand ("modify", modify_command_object);
- LoadSubCommand ("set", set_command_object);
+CommandObjectMultiwordWatchpoint::CommandObjectMultiwordWatchpoint(
+ CommandInterpreter &interpreter)
+ : CommandObjectMultiword(interpreter, "watchpoint",
+ "Commands for operating on watchpoints.",
+ "watchpoint <subcommand> [<command-options>]") {
+ CommandObjectSP list_command_object(
+ new CommandObjectWatchpointList(interpreter));
+ CommandObjectSP enable_command_object(
+ new CommandObjectWatchpointEnable(interpreter));
+ CommandObjectSP disable_command_object(
+ new CommandObjectWatchpointDisable(interpreter));
+ CommandObjectSP delete_command_object(
+ new CommandObjectWatchpointDelete(interpreter));
+ CommandObjectSP ignore_command_object(
+ new CommandObjectWatchpointIgnore(interpreter));
+ CommandObjectSP command_command_object(
+ new CommandObjectWatchpointCommand(interpreter));
+ CommandObjectSP modify_command_object(
+ new CommandObjectWatchpointModify(interpreter));
+ CommandObjectSP set_command_object(
+ new CommandObjectWatchpointSet(interpreter));
+
+ list_command_object->SetCommandName("watchpoint list");
+ enable_command_object->SetCommandName("watchpoint enable");
+ disable_command_object->SetCommandName("watchpoint disable");
+ delete_command_object->SetCommandName("watchpoint delete");
+ ignore_command_object->SetCommandName("watchpoint ignore");
+ command_command_object->SetCommandName("watchpoint command");
+ modify_command_object->SetCommandName("watchpoint modify");
+ set_command_object->SetCommandName("watchpoint set");
+
+ LoadSubCommand("list", list_command_object);
+ LoadSubCommand("enable", enable_command_object);
+ LoadSubCommand("disable", disable_command_object);
+ LoadSubCommand("delete", delete_command_object);
+ LoadSubCommand("ignore", ignore_command_object);
+ LoadSubCommand("command", command_command_object);
+ LoadSubCommand("modify", modify_command_object);
+ LoadSubCommand("set", set_command_object);
}
CommandObjectMultiwordWatchpoint::~CommandObjectMultiwordWatchpoint() = default;
Modified: lldb/trunk/source/Commands/CommandObjectWatchpoint.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpoint.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectWatchpoint.h (original)
+++ lldb/trunk/source/Commands/CommandObjectWatchpoint.h Tue Sep 6 15:57:50 2016
@@ -16,8 +16,8 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Interpreter/CommandObjectMultiword.h"
-#include "lldb/Interpreter/Options.h"
#include "lldb/Interpreter/OptionGroupWatchpoint.h"
+#include "lldb/Interpreter/Options.h"
namespace lldb_private {
@@ -25,15 +25,14 @@ namespace lldb_private {
// CommandObjectMultiwordWatchpoint
//-------------------------------------------------------------------------
-class CommandObjectMultiwordWatchpoint : public CommandObjectMultiword
-{
+class CommandObjectMultiwordWatchpoint : public CommandObjectMultiword {
public:
- CommandObjectMultiwordWatchpoint (CommandInterpreter &interpreter);
+ CommandObjectMultiwordWatchpoint(CommandInterpreter &interpreter);
- ~CommandObjectMultiwordWatchpoint() override;
+ ~CommandObjectMultiwordWatchpoint() override;
- static bool
- VerifyWatchpointIDs(Target *target, Args &args, std::vector<uint32_t> &wp_ids);
+ static bool VerifyWatchpointIDs(Target *target, Args &args,
+ std::vector<uint32_t> &wp_ids);
};
} // namespace lldb_private
Modified: lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectWatchpointCommand.cpp Tue Sep 6 15:57:50 2016
@@ -13,16 +13,16 @@
// Other libraries and framework includes
// Project includes
-#include "CommandObjectWatchpointCommand.h"
#include "CommandObjectWatchpoint.h"
+#include "CommandObjectWatchpointCommand.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Breakpoint/Watchpoint.h"
#include "lldb/Core/IOHandler.h"
+#include "lldb/Core/State.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
-#include "lldb/Breakpoint/Watchpoint.h"
-#include "lldb/Breakpoint/StoppointCallbackContext.h"
-#include "lldb/Core/State.h"
using namespace lldb;
using namespace lldb_private;
@@ -31,43 +31,50 @@ using namespace lldb_private;
// CommandObjectWatchpointCommandAdd
//-------------------------------------------------------------------------
-class CommandObjectWatchpointCommandAdd :
- public CommandObjectParsed,
- public IOHandlerDelegateMultiline
-{
+class CommandObjectWatchpointCommandAdd : public CommandObjectParsed,
+ public IOHandlerDelegateMultiline {
public:
- CommandObjectWatchpointCommandAdd(CommandInterpreter &interpreter)
- : CommandObjectParsed(
- interpreter, "add",
- "Add a set of LLDB commands to a watchpoint, to be executed whenever the watchpoint is hit.", nullptr),
- IOHandlerDelegateMultiline("DONE", IOHandlerDelegate::Completion::LLDBCommand),
- m_options()
- {
- SetHelpLong (
-R"(
+ CommandObjectWatchpointCommandAdd(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "add",
+ "Add a set of LLDB commands to a watchpoint, to be "
+ "executed whenever the watchpoint is hit.",
+ nullptr),
+ IOHandlerDelegateMultiline("DONE",
+ IOHandlerDelegate::Completion::LLDBCommand),
+ m_options() {
+ SetHelpLong(
+ R"(
General information about entering watchpoint commands
------------------------------------------------------
-)" "This command will prompt for commands to be executed when the specified \
+)"
+ "This command will prompt for commands to be executed when the specified \
watchpoint is hit. Each command is typed on its own line following the '> ' \
-prompt until 'DONE' is entered." R"(
+prompt until 'DONE' is entered."
+ R"(
-)" "Syntactic errors may not be detected when initially entered, and many \
+)"
+ "Syntactic errors may not be detected when initially entered, and many \
malformed commands can silently fail when executed. If your watchpoint commands \
-do not appear to be executing, double-check the command syntax." R"(
+do not appear to be executing, double-check the command syntax."
+ R"(
-)" "Note: You may enter any debugger command exactly as you would at the debugger \
+)"
+ "Note: You may enter any debugger command exactly as you would at the debugger \
prompt. There is no limit to the number of commands supplied, but do NOT enter \
-more than one command per line." R"(
+more than one command per line."
+ R"(
Special information about PYTHON watchpoint commands
----------------------------------------------------
-)" "You may enter either one or more lines of Python, including function \
+)"
+ "You may enter either one or more lines of Python, including function \
definitions or calls to functions that will have been imported by the time \
the code executes. Single line watchpoint commands will be interpreted 'as is' \
when the watchpoint is hit. Multiple lines of Python will be wrapped in a \
-generated function, and a call to the function will be attached to the watchpoint." R"(
+generated function, and a call to the function will be attached to the watchpoint."
+ R"(
This auto-generated function is passed in three arguments:
@@ -75,8 +82,10 @@ This auto-generated function is passed i
wp: the watchpoint that was hit.
-)" "When specifying a python function with the --python-function option, you need \
-to supply the function name prepended by the module name:" R"(
+)"
+ "When specifying a python function with the --python-function option, you need \
+to supply the function name prepended by the module name:"
+ R"(
--python-function myutils.watchpoint_callback
@@ -85,16 +94,20 @@ The function itself must have the follow
def watchpoint_callback(frame, wp):
# Your code goes here
-)" "The arguments are the same as the arguments passed to generated functions as \
+)"
+ "The arguments are the same as the arguments passed to generated functions as \
described above. Note that the global variable 'lldb.frame' will NOT be updated when \
this function is called, so be sure to use the 'frame' argument. The 'frame' argument \
can get you to the thread via frame.GetThread(), the thread can get you to the \
process via thread.GetProcess(), and the process can get you back to the target \
-via process.GetTarget()." R"(
+via process.GetTarget()."
+ R"(
-)" "Important Note: As Python code gets collected into functions, access to global \
+)"
+ "Important Note: As Python code gets collected into functions, access to global \
variables requires explicit scoping using the 'global' keyword. Be sure to use correct \
-Python syntax, including indentation, when entering Python watchpoint commands." R"(
+Python syntax, including indentation, when entering Python watchpoint commands."
+ R"(
Example Python one-line watchpoint command:
@@ -139,585 +152,540 @@ Enter your Python command(s). Type 'DONE
> print "Hit this watchpoint " + repr(wp_count) + " times!"
> DONE
-)" "In this case, since there is a reference to a global variable, \
+)"
+ "In this case, since there is a reference to a global variable, \
'wp_count', you will also need to make sure 'wp_count' exists and is \
-initialized:" R"(
+initialized:"
+ R"(
(lldb) script
>>> wp_count = 0
>>> quit()
-)" "Final Note: A warning that no watchpoint command was generated when there \
-are no syntax errors may indicate that a function was declared but never called."
- );
-
- CommandArgumentEntry arg;
- CommandArgumentData wp_id_arg;
-
- // Define the first (and only) variant of this arg.
- wp_id_arg.arg_type = eArgTypeWatchpointID;
- wp_id_arg.arg_repetition = eArgRepeatPlain;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (wp_id_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
- }
-
- ~CommandObjectWatchpointCommandAdd() override = default;
-
- Options *
- GetOptions () override
- {
- return &m_options;
- }
-
- void
- IOHandlerActivated (IOHandler &io_handler) override
- {
- StreamFileSP output_sp(io_handler.GetOutputStreamFile());
- if (output_sp)
- {
- output_sp->PutCString("Enter your debugger command(s). Type 'DONE' to end.\n");
- output_sp->Flush();
- }
- }
-
- void
- IOHandlerInputComplete (IOHandler &io_handler, std::string &line) override
- {
- io_handler.SetIsDone(true);
-
- // The WatchpointOptions object is owned by the watchpoint or watchpoint location
- WatchpointOptions *wp_options = (WatchpointOptions *) io_handler.GetUserData();
- if (wp_options)
- {
- std::unique_ptr<WatchpointOptions::CommandData> data_ap(new WatchpointOptions::CommandData());
- if (data_ap)
- {
- data_ap->user_source.SplitIntoLines(line);
- BatonSP baton_sp (new WatchpointOptions::CommandBaton (data_ap.release()));
- wp_options->SetCallback (WatchpointOptionsCallbackFunction, baton_sp);
- }
- }
- }
-
- void
- CollectDataForWatchpointCommandCallback (WatchpointOptions *wp_options,
- CommandReturnObject &result)
- {
- 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
- }
-
- /// Set a one-liner as the callback for the watchpoint.
- void
- SetWatchpointCommandCallback (WatchpointOptions *wp_options,
- const char *oneliner)
- {
- std::unique_ptr<WatchpointOptions::CommandData> data_ap(new WatchpointOptions::CommandData());
-
- // It's necessary to set both user_source and script_source to the oneliner.
- // The former is used to generate callback description (as in watchpoint command list)
- // while the latter is used for Python to interpret during the actual callback.
- data_ap->user_source.AppendString (oneliner);
- data_ap->script_source.assign (oneliner);
- data_ap->stop_on_error = m_options.m_stop_on_error;
-
- BatonSP baton_sp (new WatchpointOptions::CommandBaton (data_ap.release()));
- wp_options->SetCallback (WatchpointOptionsCallbackFunction, baton_sp);
- }
-
- static bool
- WatchpointOptionsCallbackFunction (void *baton,
- StoppointCallbackContext *context,
- lldb::user_id_t watch_id)
- {
- bool ret_value = true;
- if (baton == nullptr)
- return true;
-
- WatchpointOptions::CommandData *data = (WatchpointOptions::CommandData *) baton;
- StringList &commands = data->user_source;
-
- if (commands.GetSize() > 0)
- {
- ExecutionContext exe_ctx (context->exe_ctx_ref);
- Target *target = exe_ctx.GetTargetPtr();
- if (target)
- {
- CommandReturnObject result;
- Debugger &debugger = target->GetDebugger();
- // Rig up the results secondary output stream to the debugger's, so the output will come out synchronously
- // if the debugger is set up that way.
-
- StreamSP output_stream (debugger.GetAsyncOutputStream());
- StreamSP error_stream (debugger.GetAsyncErrorStream());
- result.SetImmediateOutputStream (output_stream);
- result.SetImmediateErrorStream (error_stream);
-
- CommandInterpreterRunOptions options;
- options.SetStopOnContinue (true);
- options.SetStopOnError (data->stop_on_error);
- options.SetEchoCommands (false);
- options.SetPrintResults (true);
- options.SetAddToHistory (false);
-
- debugger.GetCommandInterpreter().HandleCommands (commands,
- &exe_ctx,
- options,
- result);
- result.GetImmediateOutputStream()->Flush();
- result.GetImmediateErrorStream()->Flush();
- }
- }
- return ret_value;
- }
-
- class CommandOptions : public Options
- {
- public:
- CommandOptions() :
- Options(),
- m_use_commands (false),
- m_use_script_language (false),
- m_script_language (eScriptLanguageNone),
- m_use_one_liner (false),
- m_one_liner(),
- m_function_name()
- {
- }
-
- ~CommandOptions() override = default;
-
- Error
- SetOptionValue(uint32_t option_idx, const char *option_arg,
- ExecutionContext *execution_context) override
- {
- Error error;
- const int short_option = m_getopt_table[option_idx].val;
-
- switch (short_option)
- {
- case 'o':
- m_use_one_liner = true;
- m_one_liner = option_arg;
- break;
-
- case 's':
- m_script_language = (lldb::ScriptLanguage) Args::StringToOptionEnum (option_arg,
- g_option_table[option_idx].enum_values,
- eScriptLanguageNone,
- error);
-
- m_use_script_language =
- (m_script_language == eScriptLanguagePython || m_script_language == eScriptLanguageDefault);
- break;
-
- case 'e':
- {
- bool success = false;
- m_stop_on_error = Args::StringToBoolean(option_arg, false, &success);
- if (!success)
- error.SetErrorStringWithFormat("invalid value for stop-on-error: \"%s\"", option_arg);
- }
- break;
-
- case 'F':
- m_use_one_liner = false;
- m_use_script_language = true;
- m_function_name.assign(option_arg);
- break;
-
- default:
- break;
- }
- return error;
- }
-
- void
- OptionParsingStarting(ExecutionContext *execution_context) override
- {
- m_use_commands = true;
- m_use_script_language = false;
- m_script_language = eScriptLanguageNone;
-
- m_use_one_liner = false;
- m_stop_on_error = true;
- m_one_liner.clear();
- m_function_name.clear();
- }
-
- const OptionDefinition*
- GetDefinitions () override
- {
- return g_option_table;
- }
-
- // Options table: Required for subclasses of Options.
-
- static OptionDefinition g_option_table[];
-
- // Instance variables to hold the values for command options.
-
- bool m_use_commands;
- bool m_use_script_language;
- lldb::ScriptLanguage m_script_language;
-
- // Instance variables to hold the values for one_liner options.
- bool m_use_one_liner;
- std::string m_one_liner;
- bool m_stop_on_error;
- std::string m_function_name;
- };
+)"
+ "Final Note: A warning that no watchpoint command was generated when there \
+are no syntax errors may indicate that a function was declared but never called.");
+
+ CommandArgumentEntry arg;
+ CommandArgumentData wp_id_arg;
+
+ // Define the first (and only) variant of this arg.
+ wp_id_arg.arg_type = eArgTypeWatchpointID;
+ wp_id_arg.arg_repetition = eArgRepeatPlain;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(wp_id_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+ }
+
+ ~CommandObjectWatchpointCommandAdd() override = default;
+
+ Options *GetOptions() override { return &m_options; }
+
+ void IOHandlerActivated(IOHandler &io_handler) override {
+ StreamFileSP output_sp(io_handler.GetOutputStreamFile());
+ if (output_sp) {
+ output_sp->PutCString(
+ "Enter your debugger command(s). Type 'DONE' to end.\n");
+ output_sp->Flush();
+ }
+ }
+
+ void IOHandlerInputComplete(IOHandler &io_handler,
+ std::string &line) override {
+ io_handler.SetIsDone(true);
+
+ // The WatchpointOptions object is owned by the watchpoint or watchpoint
+ // location
+ WatchpointOptions *wp_options =
+ (WatchpointOptions *)io_handler.GetUserData();
+ if (wp_options) {
+ std::unique_ptr<WatchpointOptions::CommandData> data_ap(
+ new WatchpointOptions::CommandData());
+ if (data_ap) {
+ data_ap->user_source.SplitIntoLines(line);
+ BatonSP baton_sp(
+ new WatchpointOptions::CommandBaton(data_ap.release()));
+ wp_options->SetCallback(WatchpointOptionsCallbackFunction, baton_sp);
+ }
+ }
+ }
+
+ void CollectDataForWatchpointCommandCallback(WatchpointOptions *wp_options,
+ CommandReturnObject &result) {
+ 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
+ }
+
+ /// Set a one-liner as the callback for the watchpoint.
+ void SetWatchpointCommandCallback(WatchpointOptions *wp_options,
+ const char *oneliner) {
+ std::unique_ptr<WatchpointOptions::CommandData> data_ap(
+ new WatchpointOptions::CommandData());
+
+ // It's necessary to set both user_source and script_source to the oneliner.
+ // The former is used to generate callback description (as in watchpoint
+ // command list)
+ // while the latter is used for Python to interpret during the actual
+ // callback.
+ data_ap->user_source.AppendString(oneliner);
+ data_ap->script_source.assign(oneliner);
+ data_ap->stop_on_error = m_options.m_stop_on_error;
+
+ BatonSP baton_sp(new WatchpointOptions::CommandBaton(data_ap.release()));
+ wp_options->SetCallback(WatchpointOptionsCallbackFunction, baton_sp);
+ }
+
+ static bool
+ WatchpointOptionsCallbackFunction(void *baton,
+ StoppointCallbackContext *context,
+ lldb::user_id_t watch_id) {
+ bool ret_value = true;
+ if (baton == nullptr)
+ return true;
+
+ WatchpointOptions::CommandData *data =
+ (WatchpointOptions::CommandData *)baton;
+ StringList &commands = data->user_source;
+
+ if (commands.GetSize() > 0) {
+ ExecutionContext exe_ctx(context->exe_ctx_ref);
+ Target *target = exe_ctx.GetTargetPtr();
+ if (target) {
+ CommandReturnObject result;
+ Debugger &debugger = target->GetDebugger();
+ // Rig up the results secondary output stream to the debugger's, so the
+ // output will come out synchronously
+ // if the debugger is set up that way.
+
+ StreamSP output_stream(debugger.GetAsyncOutputStream());
+ StreamSP error_stream(debugger.GetAsyncErrorStream());
+ result.SetImmediateOutputStream(output_stream);
+ result.SetImmediateErrorStream(error_stream);
+
+ CommandInterpreterRunOptions options;
+ options.SetStopOnContinue(true);
+ options.SetStopOnError(data->stop_on_error);
+ options.SetEchoCommands(false);
+ options.SetPrintResults(true);
+ options.SetAddToHistory(false);
+
+ debugger.GetCommandInterpreter().HandleCommands(commands, &exe_ctx,
+ options, result);
+ result.GetImmediateOutputStream()->Flush();
+ result.GetImmediateErrorStream()->Flush();
+ }
+ }
+ return ret_value;
+ }
+
+ class CommandOptions : public Options {
+ public:
+ CommandOptions()
+ : Options(), m_use_commands(false), m_use_script_language(false),
+ m_script_language(eScriptLanguageNone), m_use_one_liner(false),
+ m_one_liner(), m_function_name() {}
+
+ ~CommandOptions() override = default;
+
+ Error SetOptionValue(uint32_t option_idx, const char *option_arg,
+ ExecutionContext *execution_context) override {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option) {
+ case 'o':
+ m_use_one_liner = true;
+ m_one_liner = option_arg;
+ break;
+
+ case 's':
+ m_script_language = (lldb::ScriptLanguage)Args::StringToOptionEnum(
+ option_arg, g_option_table[option_idx].enum_values,
+ eScriptLanguageNone, error);
+
+ m_use_script_language = (m_script_language == eScriptLanguagePython ||
+ m_script_language == eScriptLanguageDefault);
+ break;
+
+ case 'e': {
+ bool success = false;
+ m_stop_on_error = Args::StringToBoolean(option_arg, false, &success);
+ if (!success)
+ error.SetErrorStringWithFormat(
+ "invalid value for stop-on-error: \"%s\"", option_arg);
+ } break;
+
+ case 'F':
+ m_use_one_liner = false;
+ m_use_script_language = true;
+ m_function_name.assign(option_arg);
+ break;
+
+ default:
+ break;
+ }
+ return error;
+ }
+
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_use_commands = true;
+ m_use_script_language = false;
+ m_script_language = eScriptLanguageNone;
+
+ m_use_one_liner = false;
+ m_stop_on_error = true;
+ m_one_liner.clear();
+ m_function_name.clear();
+ }
+
+ const OptionDefinition *GetDefinitions() override { return g_option_table; }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+
+ bool m_use_commands;
+ bool m_use_script_language;
+ lldb::ScriptLanguage m_script_language;
+
+ // Instance variables to hold the values for one_liner options.
+ bool m_use_one_liner;
+ std::string m_one_liner;
+ bool m_stop_on_error;
+ std::string m_function_name;
+ };
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
-
- if (target == nullptr)
- {
- result.AppendError ("There is not a current executable; there are no watchpoints to which to add commands");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- const WatchpointList &watchpoints = target->GetWatchpointList();
- size_t num_watchpoints = watchpoints.GetSize();
-
- if (num_watchpoints == 0)
- {
- result.AppendError ("No watchpoints exist to have commands added");
- result.SetStatus (eReturnStatusFailed);
- 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;
- }
-
- std::vector<uint32_t> valid_wp_ids;
- if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, valid_wp_ids))
- {
- result.AppendError("Invalid watchpoints specification.");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- const size_t count = valid_wp_ids.size();
- for (size_t i = 0; i < count; ++i)
- {
- uint32_t cur_wp_id = valid_wp_ids.at (i);
- if (cur_wp_id != LLDB_INVALID_WATCH_ID)
- {
- Watchpoint *wp = target->GetWatchpointList().FindByID (cur_wp_id).get();
- // Sanity check wp first.
- if (wp == nullptr) continue;
-
- WatchpointOptions *wp_options = wp->GetOptions();
- // Skip this watchpoint if wp_options is not good.
- if (wp_options == nullptr) continue;
-
- // If we are using script language, get the script interpreter
- // in order to set or collect command callback. Otherwise, call
- // the methods associated with this object.
- if (m_options.m_use_script_language)
- {
- // Special handling for one-liner specified inline.
- if (m_options.m_use_one_liner)
- {
- m_interpreter.GetScriptInterpreter()->SetWatchpointCommandCallback (wp_options,
- m_options.m_one_liner.c_str());
- }
- // Special handling for using a Python function by name
- // instead of extending the watchpoint callback data structures, we just automatize
- // what the user would do manually: make their watchpoint command be a function call
- else if (!m_options.m_function_name.empty())
- {
- std::string oneliner(m_options.m_function_name);
- oneliner += "(frame, wp, internal_dict)";
- m_interpreter.GetScriptInterpreter()->SetWatchpointCommandCallback (wp_options,
- oneliner.c_str());
- }
- else
- {
- m_interpreter.GetScriptInterpreter()->CollectDataForWatchpointCommandCallback (wp_options,
- result);
- }
- }
- else
- {
- // Special handling for one-liner specified inline.
- if (m_options.m_use_one_liner)
- SetWatchpointCommandCallback (wp_options,
- m_options.m_one_liner.c_str());
- else
- CollectDataForWatchpointCommandCallback (wp_options,
- result);
- }
- }
+ if (target == nullptr) {
+ result.AppendError("There is not a current executable; there are no "
+ "watchpoints to which to add commands");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ const WatchpointList &watchpoints = target->GetWatchpointList();
+ size_t num_watchpoints = watchpoints.GetSize();
+
+ if (num_watchpoints == 0) {
+ result.AppendError("No watchpoints exist to have commands added");
+ result.SetStatus(eReturnStatusFailed);
+ 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;
+ }
+
+ std::vector<uint32_t> valid_wp_ids;
+ if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command,
+ valid_wp_ids)) {
+ result.AppendError("Invalid watchpoints specification.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ const size_t count = valid_wp_ids.size();
+ for (size_t i = 0; i < count; ++i) {
+ uint32_t cur_wp_id = valid_wp_ids.at(i);
+ if (cur_wp_id != LLDB_INVALID_WATCH_ID) {
+ Watchpoint *wp = target->GetWatchpointList().FindByID(cur_wp_id).get();
+ // Sanity check wp first.
+ if (wp == nullptr)
+ continue;
+
+ WatchpointOptions *wp_options = wp->GetOptions();
+ // Skip this watchpoint if wp_options is not good.
+ if (wp_options == nullptr)
+ continue;
+
+ // If we are using script language, get the script interpreter
+ // in order to set or collect command callback. Otherwise, call
+ // the methods associated with this object.
+ if (m_options.m_use_script_language) {
+ // Special handling for one-liner specified inline.
+ if (m_options.m_use_one_liner) {
+ m_interpreter.GetScriptInterpreter()->SetWatchpointCommandCallback(
+ wp_options, m_options.m_one_liner.c_str());
+ }
+ // Special handling for using a Python function by name
+ // instead of extending the watchpoint callback data structures, we
+ // just automatize
+ // what the user would do manually: make their watchpoint command be a
+ // function call
+ else if (!m_options.m_function_name.empty()) {
+ std::string oneliner(m_options.m_function_name);
+ oneliner += "(frame, wp, internal_dict)";
+ m_interpreter.GetScriptInterpreter()->SetWatchpointCommandCallback(
+ wp_options, oneliner.c_str());
+ } else {
+ m_interpreter.GetScriptInterpreter()
+ ->CollectDataForWatchpointCommandCallback(wp_options, result);
+ }
+ } else {
+ // Special handling for one-liner specified inline.
+ if (m_options.m_use_one_liner)
+ SetWatchpointCommandCallback(wp_options,
+ m_options.m_one_liner.c_str());
+ else
+ CollectDataForWatchpointCommandCallback(wp_options, result);
}
-
- return result.Succeeded();
+ }
}
+ return result.Succeeded();
+ }
+
private:
- CommandOptions m_options;
+ CommandOptions m_options;
};
-// FIXME: "script-type" needs to have its contents determined dynamically, so somebody can add a new scripting
-// language to lldb and have it pickable here without having to change this enumeration by hand and rebuild lldb proper.
-
-static OptionEnumValueElement
-g_script_option_enumeration[4] =
-{
- { eScriptLanguageNone, "command", "Commands are in the lldb command interpreter language"},
- { eScriptLanguagePython, "python", "Commands are in the Python language."},
- { eSortOrderByName, "default-script", "Commands are in the default scripting language."},
- { 0, nullptr, nullptr }
-};
+// FIXME: "script-type" needs to have its contents determined dynamically, so
+// somebody can add a new scripting
+// language to lldb and have it pickable here without having to change this
+// enumeration by hand and rebuild lldb proper.
+
+static OptionEnumValueElement g_script_option_enumeration[4] = {
+ {eScriptLanguageNone, "command",
+ "Commands are in the lldb command interpreter language"},
+ {eScriptLanguagePython, "python", "Commands are in the Python language."},
+ {eSortOrderByName, "default-script",
+ "Commands are in the default scripting language."},
+ {0, nullptr, nullptr}};
OptionDefinition
-CommandObjectWatchpointCommandAdd::CommandOptions::g_option_table[] =
-{
- // clang-format off
+ CommandObjectWatchpointCommandAdd::CommandOptions::g_option_table[] = {
+ // clang-format off
{LLDB_OPT_SET_1, false, "one-liner", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeOneLiner, "Specify a one-line watchpoint command inline. Be sure to surround it with quotes."},
{LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Specify whether watchpoint command execution should terminate on error."},
{LLDB_OPT_SET_ALL, false, "script-type", 's', OptionParser::eRequiredArgument, nullptr, g_script_option_enumeration, 0, eArgTypeNone, "Specify the language for the commands - if none is specified, the lldb command interpreter will be used."},
{LLDB_OPT_SET_2, false, "python-function", 'F', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonFunction, "Give the name of a Python function to run as command for this watchpoint. Be sure to give a module name if appropriate."},
{0, false, nullptr, 0, 0, nullptr, nullptr, 0, eArgTypeNone, nullptr }
- // clang-format on
+ // clang-format on
};
//-------------------------------------------------------------------------
// CommandObjectWatchpointCommandDelete
//-------------------------------------------------------------------------
-class CommandObjectWatchpointCommandDelete : public CommandObjectParsed
-{
+class CommandObjectWatchpointCommandDelete : public CommandObjectParsed {
public:
- CommandObjectWatchpointCommandDelete (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "delete",
+ CommandObjectWatchpointCommandDelete(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "delete",
"Delete the set of commands from a watchpoint.",
- nullptr)
- {
- CommandArgumentEntry arg;
- CommandArgumentData wp_id_arg;
-
- // Define the first (and only) variant of this arg.
- wp_id_arg.arg_type = eArgTypeWatchpointID;
- wp_id_arg.arg_repetition = eArgRepeatPlain;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (wp_id_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
- }
+ nullptr) {
+ CommandArgumentEntry arg;
+ CommandArgumentData wp_id_arg;
+
+ // Define the first (and only) variant of this arg.
+ wp_id_arg.arg_type = eArgTypeWatchpointID;
+ wp_id_arg.arg_repetition = eArgRepeatPlain;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(wp_id_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+ }
- ~CommandObjectWatchpointCommandDelete() override = default;
+ ~CommandObjectWatchpointCommandDelete() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
-
- if (target == nullptr)
- {
- result.AppendError ("There is not a current executable; there are no watchpoints from which to delete commands");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- const WatchpointList &watchpoints = target->GetWatchpointList();
- size_t num_watchpoints = watchpoints.GetSize();
-
- if (num_watchpoints == 0)
- {
- result.AppendError ("No watchpoints exist to have commands deleted");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- if (command.GetArgumentCount() == 0)
- {
- result.AppendError ("No watchpoint specified from which to delete the commands");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- std::vector<uint32_t> valid_wp_ids;
- if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, valid_wp_ids))
- {
- result.AppendError("Invalid watchpoints specification.");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
-
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- const size_t count = valid_wp_ids.size();
- for (size_t i = 0; i < count; ++i)
- {
- uint32_t cur_wp_id = valid_wp_ids.at (i);
- if (cur_wp_id != LLDB_INVALID_WATCH_ID)
- {
- Watchpoint *wp = target->GetWatchpointList().FindByID (cur_wp_id).get();
- if (wp)
- wp->ClearCallback();
- }
- else
- {
- result.AppendErrorWithFormat("Invalid watchpoint ID: %u.\n",
- cur_wp_id);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- return result.Succeeded();
+ if (target == nullptr) {
+ result.AppendError("There is not a current executable; there are no "
+ "watchpoints from which to delete commands");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ const WatchpointList &watchpoints = target->GetWatchpointList();
+ size_t num_watchpoints = watchpoints.GetSize();
+
+ if (num_watchpoints == 0) {
+ result.AppendError("No watchpoints exist to have commands deleted");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (command.GetArgumentCount() == 0) {
+ result.AppendError(
+ "No watchpoint specified from which to delete the commands");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ std::vector<uint32_t> valid_wp_ids;
+ if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command,
+ valid_wp_ids)) {
+ result.AppendError("Invalid watchpoints specification.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ const size_t count = valid_wp_ids.size();
+ for (size_t i = 0; i < count; ++i) {
+ uint32_t cur_wp_id = valid_wp_ids.at(i);
+ if (cur_wp_id != LLDB_INVALID_WATCH_ID) {
+ Watchpoint *wp = target->GetWatchpointList().FindByID(cur_wp_id).get();
+ if (wp)
+ wp->ClearCallback();
+ } else {
+ result.AppendErrorWithFormat("Invalid watchpoint ID: %u.\n", cur_wp_id);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
}
+ return result.Succeeded();
+ }
};
//-------------------------------------------------------------------------
// CommandObjectWatchpointCommandList
//-------------------------------------------------------------------------
-class CommandObjectWatchpointCommandList : public CommandObjectParsed
-{
+class CommandObjectWatchpointCommandList : public CommandObjectParsed {
public:
- CommandObjectWatchpointCommandList (CommandInterpreter &interpreter) :
- CommandObjectParsed(interpreter,
- "list",
- "List the script or set of commands to be executed when the watchpoint is hit.",
- nullptr)
- {
- CommandArgumentEntry arg;
- CommandArgumentData wp_id_arg;
-
- // Define the first (and only) variant of this arg.
- wp_id_arg.arg_type = eArgTypeWatchpointID;
- wp_id_arg.arg_repetition = eArgRepeatPlain;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (wp_id_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
- }
+ CommandObjectWatchpointCommandList(CommandInterpreter &interpreter)
+ : CommandObjectParsed(interpreter, "list", "List the script or set of "
+ "commands to be executed when "
+ "the watchpoint is hit.",
+ nullptr) {
+ CommandArgumentEntry arg;
+ CommandArgumentData wp_id_arg;
+
+ // Define the first (and only) variant of this arg.
+ wp_id_arg.arg_type = eArgTypeWatchpointID;
+ wp_id_arg.arg_repetition = eArgRepeatPlain;
+
+ // There is only one variant this argument could be; put it into the
+ // argument entry.
+ arg.push_back(wp_id_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back(arg);
+ }
- ~CommandObjectWatchpointCommandList() override = default;
+ ~CommandObjectWatchpointCommandList() override = default;
protected:
- bool
- DoExecute (Args& command, CommandReturnObject &result) override
- {
- Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
-
- if (target == nullptr)
- {
- result.AppendError ("There is not a current executable; there are no watchpoints for which to list commands");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- const WatchpointList &watchpoints = target->GetWatchpointList();
- size_t num_watchpoints = watchpoints.GetSize();
-
- if (num_watchpoints == 0)
- {
- result.AppendError ("No watchpoints exist for which to list commands");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- if (command.GetArgumentCount() == 0)
- {
- result.AppendError ("No watchpoint specified for which to list the commands");
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- std::vector<uint32_t> valid_wp_ids;
- if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command, valid_wp_ids))
- {
- result.AppendError("Invalid watchpoints specification.");
- result.SetStatus(eReturnStatusFailed);
- return false;
- }
+ bool DoExecute(Args &command, CommandReturnObject &result) override {
+ Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
- result.SetStatus(eReturnStatusSuccessFinishNoResult);
- const size_t count = valid_wp_ids.size();
- for (size_t i = 0; i < count; ++i)
- {
- uint32_t cur_wp_id = valid_wp_ids.at (i);
- if (cur_wp_id != LLDB_INVALID_WATCH_ID)
- {
- Watchpoint *wp = target->GetWatchpointList().FindByID (cur_wp_id).get();
-
- if (wp)
- {
- const WatchpointOptions *wp_options = wp->GetOptions();
- if (wp_options)
- {
- // Get the callback baton associated with the current watchpoint.
- 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 ();
- }
- else
- {
- result.AppendMessageWithFormat ("Watchpoint %u does not have an associated command.\n",
- cur_wp_id);
- }
- }
- result.SetStatus (eReturnStatusSuccessFinishResult);
- }
- else
- {
- result.AppendErrorWithFormat("Invalid watchpoint ID: %u.\n", cur_wp_id);
- result.SetStatus (eReturnStatusFailed);
- }
+ if (target == nullptr) {
+ result.AppendError("There is not a current executable; there are no "
+ "watchpoints for which to list commands");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ const WatchpointList &watchpoints = target->GetWatchpointList();
+ size_t num_watchpoints = watchpoints.GetSize();
+
+ if (num_watchpoints == 0) {
+ result.AppendError("No watchpoints exist for which to list commands");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ if (command.GetArgumentCount() == 0) {
+ result.AppendError(
+ "No watchpoint specified for which to list the commands");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ std::vector<uint32_t> valid_wp_ids;
+ if (!CommandObjectMultiwordWatchpoint::VerifyWatchpointIDs(target, command,
+ valid_wp_ids)) {
+ result.AppendError("Invalid watchpoints specification.");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ result.SetStatus(eReturnStatusSuccessFinishNoResult);
+ const size_t count = valid_wp_ids.size();
+ for (size_t i = 0; i < count; ++i) {
+ uint32_t cur_wp_id = valid_wp_ids.at(i);
+ if (cur_wp_id != LLDB_INVALID_WATCH_ID) {
+ Watchpoint *wp = target->GetWatchpointList().FindByID(cur_wp_id).get();
+
+ if (wp) {
+ const WatchpointOptions *wp_options = wp->GetOptions();
+ if (wp_options) {
+ // Get the callback baton associated with the current watchpoint.
+ 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();
+ } else {
+ result.AppendMessageWithFormat(
+ "Watchpoint %u does not have an associated command.\n",
+ cur_wp_id);
}
+ }
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ } else {
+ result.AppendErrorWithFormat("Invalid watchpoint ID: %u.\n",
+ cur_wp_id);
+ result.SetStatus(eReturnStatusFailed);
}
-
- return result.Succeeded();
+ }
}
+
+ return result.Succeeded();
+ }
};
//-------------------------------------------------------------------------
// CommandObjectWatchpointCommand
//-------------------------------------------------------------------------
-CommandObjectWatchpointCommand::CommandObjectWatchpointCommand(CommandInterpreter &interpreter)
- : CommandObjectMultiword(interpreter, "command", "Commands for adding, removing and examining LLDB commands "
- "executed when the watchpoint is hit (watchpoint 'commmands').",
- "command <sub-command> [<sub-command-options>] <watchpoint-id>")
-{
- CommandObjectSP add_command_object (new CommandObjectWatchpointCommandAdd (interpreter));
- CommandObjectSP delete_command_object (new CommandObjectWatchpointCommandDelete (interpreter));
- CommandObjectSP list_command_object (new CommandObjectWatchpointCommandList (interpreter));
-
- add_command_object->SetCommandName ("watchpoint command add");
- delete_command_object->SetCommandName ("watchpoint command delete");
- list_command_object->SetCommandName ("watchpoint command list");
-
- LoadSubCommand ("add", add_command_object);
- LoadSubCommand ("delete", delete_command_object);
- LoadSubCommand ("list", list_command_object);
+CommandObjectWatchpointCommand::CommandObjectWatchpointCommand(
+ CommandInterpreter &interpreter)
+ : CommandObjectMultiword(
+ interpreter, "command",
+ "Commands for adding, removing and examining LLDB commands "
+ "executed when the watchpoint is hit (watchpoint 'commmands').",
+ "command <sub-command> [<sub-command-options>] <watchpoint-id>") {
+ CommandObjectSP add_command_object(
+ new CommandObjectWatchpointCommandAdd(interpreter));
+ CommandObjectSP delete_command_object(
+ new CommandObjectWatchpointCommandDelete(interpreter));
+ CommandObjectSP list_command_object(
+ new CommandObjectWatchpointCommandList(interpreter));
+
+ add_command_object->SetCommandName("watchpoint command add");
+ delete_command_object->SetCommandName("watchpoint command delete");
+ list_command_object->SetCommandName("watchpoint command list");
+
+ LoadSubCommand("add", add_command_object);
+ LoadSubCommand("delete", delete_command_object);
+ LoadSubCommand("list", list_command_object);
}
CommandObjectWatchpointCommand::~CommandObjectWatchpointCommand() = default;
Modified: lldb/trunk/source/Commands/CommandObjectWatchpointCommand.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpointCommand.h?rev=280751&r1=280750&r2=280751&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectWatchpointCommand.h (original)
+++ lldb/trunk/source/Commands/CommandObjectWatchpointCommand.h Tue Sep 6 15:57:50 2016
@@ -16,10 +16,9 @@
// Other libraries and framework includes
// Project includes
-#include "lldb/lldb-types.h"
-#include "lldb/Interpreter/Options.h"
#include "lldb/Interpreter/CommandObjectMultiword.h"
-
+#include "lldb/Interpreter/Options.h"
+#include "lldb/lldb-types.h"
namespace lldb_private {
@@ -27,12 +26,11 @@ namespace lldb_private {
// CommandObjectMultiwordWatchpoint
//-------------------------------------------------------------------------
-class CommandObjectWatchpointCommand : public CommandObjectMultiword
-{
+class CommandObjectWatchpointCommand : public CommandObjectMultiword {
public:
- CommandObjectWatchpointCommand (CommandInterpreter &interpreter);
+ CommandObjectWatchpointCommand(CommandInterpreter &interpreter);
- ~CommandObjectWatchpointCommand() override;
+ ~CommandObjectWatchpointCommand() override;
};
} // namespace lldb_private
More information about the lldb-commits
mailing list