diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2024-07-31 09:57:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-31 09:57:10 -0700 |
commit | 8398ad9cb21736dc57ee4dd766bd0859ef9bd000 (patch) | |
tree | 928489616eb403b4328eb66656664c83ff9f1241 /lldb/source/Commands/CommandObjectTarget.cpp | |
parent | faf3333510e0c2c3f319af40456e10c471e11ce8 (diff) | |
download | llvm-8398ad9cb21736dc57ee4dd766bd0859ef9bd000.zip llvm-8398ad9cb21736dc57ee4dd766bd0859ef9bd000.tar.gz llvm-8398ad9cb21736dc57ee4dd766bd0859ef9bd000.tar.bz2 |
[lldb] Unify the way we get the Target in CommandObject (#101208)
Currently, CommandObjects are obtaining a target in a variety of ways.
Often the command incorrectly operates on the selected target. As an
example, when a breakpoint command is running, the current target is
passed into the command but the target that hit the breakpoint is not
the selected target. In other places we use the CommandObject's
execution context, which is frozen during the execution of the command,
and comes with its own limitations. Finally, we often want to fall back
to the dummy target if no real target is available.
Instead of having to guess how to get the target, this patch introduces
one helper function in CommandObject to get the most relevant target. In
order of priority, that's the target from the command object's execution
context, from the interpreter's execution context, the selected target
or the dummy target.
rdar://110846511
Diffstat (limited to 'lldb/source/Commands/CommandObjectTarget.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectTarget.cpp | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index eb57f37..60a8482 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -1027,7 +1027,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + Target *target = &GetTarget(); const size_t argc = command.GetArgumentCount(); if (argc & 1) { result.AppendError("add requires an even number of arguments\n"); @@ -1074,7 +1074,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + Target *target = &GetTarget(); bool notify = true; target->GetImageSearchPathList().Clear(notify); result.SetStatus(eReturnStatusSuccessFinishNoResult); @@ -1148,7 +1148,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + Target *target = &GetTarget(); size_t argc = command.GetArgumentCount(); // check for at least 3 arguments and an odd number of parameters if (argc >= 3 && argc & 1) { @@ -1203,7 +1203,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + Target *target = &GetTarget(); target->GetImageSearchPathList().Dump(&result.GetOutputStream()); result.SetStatus(eReturnStatusSuccessFinishResult); @@ -1226,7 +1226,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + Target *target = &GetTarget(); if (command.GetArgumentCount() != 1) { result.AppendError("query requires one argument\n"); return; @@ -1898,7 +1898,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + Target *target = &GetTarget(); uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); result.GetOutputStream().SetAddressByteSize(addr_byte_size); @@ -1999,7 +1999,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + Target *target = &GetTarget(); uint32_t num_dumped = 0; Mangled::NamePreference name_preference = (m_options.m_prefer_mangled ? Mangled::ePreferMangled @@ -2097,7 +2097,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + Target *target = &GetTarget(); uint32_t num_dumped = 0; uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); @@ -2238,7 +2238,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + Target *target = &GetTarget(); const ModuleList &module_list = target->GetImages(); const size_t num_modules = module_list.GetSize(); @@ -2309,7 +2309,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + Target *target = &GetTarget(); uint32_t num_dumped = 0; uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); @@ -2533,7 +2533,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target &target = GetSelectedTarget(); + Target &target = GetTarget(); uint32_t num_dumped = 0; uint32_t addr_byte_size = target.GetArchitecture().GetAddressByteSize(); @@ -2726,7 +2726,7 @@ protected: OptionGroupFile m_symbol_file; void DoExecute(Args &args, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + Target *target = &GetTarget(); bool flush = false; const size_t argc = args.GetArgumentCount(); @@ -2876,7 +2876,7 @@ public: protected: void DoExecute(Args &args, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + Target *target = &GetTarget(); const bool load = m_load_option.GetOptionValue().GetCurrentValue(); const bool set_pc = m_pc_option.GetOptionValue().GetCurrentValue(); @@ -3166,7 +3166,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = GetDebugger().GetSelectedTarget().get(); + Target *target = &GetTarget(); 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 @@ -3969,7 +3969,7 @@ public: return false; case eLookupTypeType: if (!m_options.m_str.empty()) { - if (LookupTypeHere(&GetSelectedTarget(), m_interpreter, + if (LookupTypeHere(&GetTarget(), m_interpreter, result.GetOutputStream(), *sym_ctx.module_sp, m_options.m_str.c_str(), m_options.m_use_regex)) { result.SetStatus(eReturnStatusSuccessFinishResult); @@ -4048,8 +4048,8 @@ public: case eLookupTypeType: if (!m_options.m_str.empty()) { if (LookupTypeInModule( - &GetSelectedTarget(), m_interpreter, result.GetOutputStream(), - module, m_options.m_str.c_str(), m_options.m_use_regex)) { + &GetTarget(), m_interpreter, result.GetOutputStream(), module, + m_options.m_str.c_str(), m_options.m_use_regex)) { result.SetStatus(eReturnStatusSuccessFinishResult); return true; } @@ -4070,7 +4070,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target *target = &GetSelectedTarget(); + Target *target = &GetTarget(); bool syntax_error = false; uint32_t i; uint32_t num_successful_lookups = 0; @@ -4937,7 +4937,7 @@ protected: m_stop_hook_sp->GetID()); error_sp->Flush(); } - Target *target = GetDebugger().GetSelectedTarget().get(); + Target *target = &GetTarget(); if (target) { target->UndoCreateStopHook(m_stop_hook_sp->GetID()); } @@ -4962,7 +4962,7 @@ protected: void DoExecute(Args &command, CommandReturnObject &result) override { m_stop_hook_sp.reset(); - Target &target = GetSelectedOrDummyTarget(); + Target &target = GetTarget(); Target::StopHookSP new_hook_sp = target.CreateStopHook(m_python_class_options.GetName().empty() ? Target::StopHook::StopHookKind::CommandBased @@ -5099,7 +5099,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target &target = GetSelectedOrDummyTarget(); + Target &target = GetTarget(); // FIXME: see if we can use the breakpoint id style parser? size_t num_args = command.GetArgumentCount(); if (num_args == 0) { @@ -5153,7 +5153,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target &target = GetSelectedOrDummyTarget(); + Target &target = GetTarget(); // FIXME: see if we can use the breakpoint id style parser? size_t num_args = command.GetArgumentCount(); bool success; @@ -5197,7 +5197,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target &target = GetSelectedOrDummyTarget(); + Target &target = GetTarget(); size_t num_hooks = target.GetNumStopHooks(); if (num_hooks == 0) { @@ -5263,7 +5263,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { // Go over every scratch TypeSystem and dump to the command output. - for (lldb::TypeSystemSP ts : GetSelectedTarget().GetScratchTypeSystems()) + for (lldb::TypeSystemSP ts : GetTarget().GetScratchTypeSystems()) if (ts) ts->Dump(result.GetOutputStream().AsRawOstream()); @@ -5287,7 +5287,7 @@ public: protected: void DoExecute(Args &command, CommandReturnObject &result) override { - Target &target = GetSelectedTarget(); + Target &target = GetTarget(); target.GetSectionLoadList().Dump(result.GetOutputStream(), &target); result.SetStatus(eReturnStatusSuccessFinishResult); } |