aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-07-04 19:20:19 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-02-08 19:02:26 +0000
commit81ad626541db97eb356e2c1d4a20eb2a26a766ab (patch)
tree311b6a8987c32b1e1dcbab65c54cfac3fdb56175 /contrib/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp
parent5fff09660e06a66bed6482da9c70df328e16bbb6 (diff)
parent145449b1e420787bb99721a429341fa6be3adfb6 (diff)
Diffstat (limited to 'contrib/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp')
-rw-r--r--contrib/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp180
1 files changed, 116 insertions, 64 deletions
diff --git a/contrib/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp b/contrib/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp
index 157065bde10e..2b71f1bc7bc8 100644
--- a/contrib/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/contrib/llvm-project/lldb/source/Commands/CommandObjectTarget.cpp
@@ -47,8 +47,11 @@
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadSpec.h"
#include "lldb/Utility/Args.h"
+#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/State.h"
#include "lldb/Utility/Timer.h"
+#include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-private-enumerations.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/Support/FileSystem.h"
@@ -83,8 +86,8 @@ static void DumpTargetInfo(uint32_t target_idx, Target *target,
}
PlatformSP platform_sp(target->GetPlatform());
if (platform_sp)
- strm.Printf("%splatform=%s", properties++ > 0 ? ", " : " ( ",
- platform_sp->GetName().GetCString());
+ strm.Format("{0}platform={1}", properties++ > 0 ? ", " : " ( ",
+ platform_sp->GetName());
ProcessSP process_sp(target->GetProcessSP());
bool show_process_status = false;
@@ -135,7 +138,7 @@ static uint32_t DumpTargetList(TargetList &target_list,
// Note that the negation in the argument name causes a slightly confusing
// mapping of the enum values.
-static constexpr OptionEnumValueElement g_dependents_enumaration[] = {
+static constexpr OptionEnumValueElement g_dependents_enumeration[] = {
{
eLoadDependentsDefault,
"default",
@@ -296,12 +299,6 @@ protected:
const char *file_path = command.GetArgumentAtIndex(0);
LLDB_SCOPED_TIMERF("(lldb) target create '%s'", file_path);
- FileSpec file_spec;
-
- if (file_path) {
- file_spec.SetFile(file_path, FileSpec::Style::native);
- FileSystem::Instance().Resolve(file_spec);
- }
bool must_set_platform_path = false;
@@ -330,6 +327,18 @@ protected:
PlatformSP platform_sp = target_sp->GetPlatform();
+ FileSpec file_spec;
+ if (file_path) {
+ file_spec.SetFile(file_path, FileSpec::Style::native);
+ FileSystem::Instance().Resolve(file_spec);
+
+ // Try to resolve the exe based on PATH and/or platform-specific
+ // suffixes, but only if using the host platform.
+ if (platform_sp && platform_sp->IsHost() &&
+ !FileSystem::Instance().Exists(file_spec))
+ FileSystem::Instance().ResolveExecutableLocation(file_spec);
+ }
+
if (remote_file) {
if (platform_sp) {
// I have a remote file.. two possible cases
@@ -356,10 +365,29 @@ protected:
return false;
}
} else {
- // make up a local file
- result.AppendError("remote --> local transfer without local "
+ // If the remote file exists, we can debug reading that out of
+ // memory. If the platform is already connected to an lldb-server
+ // then we can at least check the file exists remotely. Otherwise
+ // we'll just have to trust that it will be there when we do
+ // process connect.
+ // I don't do this for the host platform because it seems odd to
+ // support supplying a remote file but no local file for a local
+ // debug session.
+ if (platform_sp->IsHost()) {
+ result.AppendError("Supply a local file, not a remote file, "
+ "when debugging on the host.");
+ return false;
+ }
+ if (platform_sp->IsConnected() && !platform_sp->GetFileExists(remote_file)) {
+ result.AppendError("remote --> local transfer without local "
"path is not implemented yet");
- return false;
+ return false;
+ }
+ // Since there's only a remote file, we need to set the executable
+ // file spec to the remote one.
+ ProcessLaunchInfo launch_info = target_sp->GetProcessLaunchInfo();
+ launch_info.SetExecutableFile(FileSpec(remote_file), true);
+ target_sp->SetProcessLaunchInfo(launch_info);
}
}
} else {
@@ -459,18 +487,14 @@ public:
protected:
bool DoExecute(Args &args, CommandReturnObject &result) override {
- if (args.GetArgumentCount() == 0) {
- Stream &strm = result.GetOutputStream();
+ Stream &strm = result.GetOutputStream();
- bool show_stopped_process_status = false;
- if (DumpTargetList(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");
+ bool show_stopped_process_status = false;
+ if (DumpTargetList(GetDebugger().GetTargetList(),
+ show_stopped_process_status, strm) == 0) {
+ strm.PutCString("No targets.\n");
}
+ result.SetStatus(eReturnStatusSuccessFinishResult);
return result.Succeeded();
}
};
@@ -483,6 +507,8 @@ public:
: CommandObjectParsed(
interpreter, "target select",
"Select a target as the current target by target index.", nullptr) {
+ CommandArgumentData target_arg{eArgTypeTargetID, eArgRepeatPlain};
+ m_arguments.push_back({target_arg});
}
~CommandObjectTargetSelect() override = default;
@@ -547,6 +573,8 @@ public:
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();
+ CommandArgumentData target_arg{eArgTypeTargetID, eArgRepeatStar};
+ m_arguments.push_back({target_arg});
}
~CommandObjectTargetDelete() override = default;
@@ -970,11 +998,8 @@ protected:
}
}
- if (m_interpreter.TruncationWarningNecessary()) {
- result.GetOutputStream().Printf(m_interpreter.TruncationWarningText(),
- m_cmd_name.c_str());
- m_interpreter.TruncationWarningGiven();
- }
+ m_interpreter.PrintWarningsIfNecessary(result.GetOutputStream(),
+ m_cmd_name);
return result.Succeeded();
}
@@ -1034,7 +1059,7 @@ protected:
const char *to = command.GetArgumentAtIndex(i + 1);
if (from[0] && to[0]) {
- Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
+ Log *log = GetLog(LLDBLog::Host);
if (log) {
LLDB_LOGF(log,
"target modules search path adding ImageSearchPath "
@@ -1205,10 +1230,6 @@ public:
protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
Target *target = &GetSelectedTarget();
- if (command.GetArgumentCount() != 0) {
- result.AppendError("list takes no arguments\n");
- return result.Succeeded();
- }
target->GetImageSearchPathList().Dump(&result.GetOutputStream());
result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -1428,7 +1449,8 @@ static bool DumpModuleSymbolFile(Stream &strm, Module *module) {
}
static void DumpAddress(ExecutionContextScope *exe_scope,
- const Address &so_addr, bool verbose, Stream &strm) {
+ const Address &so_addr, bool verbose, bool all_ranges,
+ Stream &strm) {
strm.IndentMore();
strm.Indent(" Address: ");
so_addr.Dump(&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
@@ -1443,7 +1465,8 @@ static void DumpAddress(ExecutionContextScope *exe_scope,
// Print out detailed address information when verbose is enabled
if (verbose) {
strm.EOL();
- so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
+ so_addr.Dump(&strm, exe_scope, Address::DumpStyleDetailedSymbolContext,
+ Address::DumpStyleInvalid, UINT32_MAX, all_ranges);
}
strm.IndentLess();
}
@@ -1451,7 +1474,7 @@ static void DumpAddress(ExecutionContextScope *exe_scope,
static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
Module *module, uint32_t resolve_mask,
lldb::addr_t raw_addr, lldb::addr_t offset,
- bool verbose) {
+ bool verbose, bool all_ranges) {
if (module) {
lldb::addr_t addr = raw_addr - offset;
Address so_addr;
@@ -1469,7 +1492,7 @@ static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
ExecutionContextScope *exe_scope =
interpreter.GetExecutionContext().GetBestExecutionContextScope();
- DumpAddress(exe_scope, so_addr, verbose, strm);
+ DumpAddress(exe_scope, so_addr, verbose, all_ranges, strm);
// strm.IndentMore();
// strm.Indent (" Address: ");
// so_addr.Dump (&strm, exe_scope,
@@ -1501,7 +1524,7 @@ static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
Stream &strm, Module *module,
const char *name, bool name_is_regex,
- bool verbose) {
+ bool verbose, bool all_ranges) {
if (!module)
return 0;
@@ -1534,7 +1557,7 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
if (symbol && symbol->ValueIsAddress()) {
DumpAddress(
interpreter.GetExecutionContext().GetBestExecutionContextScope(),
- symbol->GetAddressRef(), verbose, strm);
+ symbol->GetAddressRef(), verbose, all_ranges, strm);
}
}
strm.IndentLess();
@@ -1544,7 +1567,7 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
static void DumpSymbolContextList(ExecutionContextScope *exe_scope,
Stream &strm, SymbolContextList &sc_list,
- bool verbose) {
+ bool verbose, bool all_ranges) {
strm.IndentMore();
const uint32_t num_matches = sc_list.GetSize();
@@ -1556,7 +1579,7 @@ static void DumpSymbolContextList(ExecutionContextScope *exe_scope,
sc.GetAddressRange(eSymbolContextEverything, 0, true, range);
- DumpAddress(exe_scope, range.GetBaseAddress(), verbose, strm);
+ DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm);
}
}
strm.IndentLess();
@@ -1566,7 +1589,7 @@ static size_t LookupFunctionInModule(CommandInterpreter &interpreter,
Stream &strm, Module *module,
const char *name, bool name_is_regex,
const ModuleFunctionSearchOptions &options,
- bool verbose) {
+ bool verbose, bool all_ranges) {
if (module && name && name[0]) {
SymbolContextList sc_list;
size_t num_matches = 0;
@@ -1587,7 +1610,7 @@ static size_t LookupFunctionInModule(CommandInterpreter &interpreter,
strm.PutCString(":\n");
DumpSymbolContextList(
interpreter.GetExecutionContext().GetBestExecutionContextScope(),
- strm, sc_list, verbose);
+ strm, sc_list, verbose, all_ranges);
}
return num_matches;
}
@@ -1692,7 +1715,7 @@ static uint32_t LookupFileAndLineInModule(CommandInterpreter &interpreter,
Stream &strm, Module *module,
const FileSpec &file_spec,
uint32_t line, bool check_inlines,
- bool verbose) {
+ bool verbose, bool all_ranges) {
if (module && file_spec) {
SymbolContextList sc_list;
const uint32_t num_matches = module->ResolveSymbolContextsForFileSpec(
@@ -1709,7 +1732,7 @@ static uint32_t LookupFileAndLineInModule(CommandInterpreter &interpreter,
strm.PutCString(":\n");
DumpSymbolContextList(
interpreter.GetExecutionContext().GetBestExecutionContextScope(),
- strm, sc_list, verbose);
+ strm, sc_list, verbose, all_ranges);
return num_matches;
}
}
@@ -1932,7 +1955,7 @@ public:
class CommandOptions : public Options {
public:
- CommandOptions() {}
+ CommandOptions() = default;
~CommandOptions() override = default;
@@ -2427,6 +2450,8 @@ public:
LLDB_OPT_SET_1);
m_option_group.Append(&m_symbol_file, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
m_option_group.Finalize();
+ CommandArgumentData module_arg{eArgTypePath, eArgRepeatStar};
+ m_arguments.push_back({module_arg});
}
~CommandObjectTargetModulesAdd() override = default;
@@ -2460,7 +2485,8 @@ protected:
if (m_symbol_file.GetOptionValue().OptionWasSet())
module_spec.GetSymbolFileSpec() =
m_symbol_file.GetOptionValue().GetCurrentValue();
- if (Symbols::DownloadObjectAndSymbolFile(module_spec)) {
+ Status error;
+ if (Symbols::DownloadObjectAndSymbolFile(module_spec, error)) {
ModuleSP module_sp(
target->GetOrCreateModule(module_spec, true /* notify */));
if (module_sp) {
@@ -2496,6 +2522,7 @@ protected:
result.AppendErrorWithFormat(
"Unable to locate the executable or symbol file with UUID %s",
strm.GetData());
+ result.SetError(error);
return false;
}
} else {
@@ -2837,7 +2864,7 @@ class CommandObjectTargetModulesList : public CommandObjectParsed {
public:
class CommandOptions : public Options {
public:
- CommandOptions() {}
+ CommandOptions() = default;
~CommandOptions() override = default;
@@ -2879,8 +2906,10 @@ public:
CommandObjectTargetModulesList(CommandInterpreter &interpreter)
: CommandObjectParsed(
interpreter, "target modules list",
- "List current executable and dependent shared library images.",
- "target modules list [<cmd-options>]") {}
+ "List current executable and dependent shared library images.") {
+ CommandArgumentData module_arg{eArgTypeShlibName, eArgRepeatStar};
+ m_arguments.push_back({module_arg});
+ }
~CommandObjectTargetModulesList() override = default;
@@ -3179,7 +3208,7 @@ public:
class CommandOptions : public Options {
public:
- CommandOptions() {}
+ CommandOptions() = default;
~CommandOptions() override = default;
@@ -3597,6 +3626,10 @@ public:
case 'r':
m_use_regex = true;
break;
+
+ case '\x01':
+ m_all_ranges = true;
+ break;
default:
llvm_unreachable("Unimplemented option");
}
@@ -3613,10 +3646,20 @@ public:
m_line_number = 0;
m_use_regex = false;
m_include_inlines = true;
+ m_all_ranges = false;
m_verbose = false;
m_print_all = false;
}
+ Status OptionParsingFinished(ExecutionContext *execution_context) override {
+ Status status;
+ if (m_all_ranges && !m_verbose) {
+ status.SetErrorString("--show-variable-ranges must be used in "
+ "conjunction with --verbose.");
+ }
+ return status;
+ }
+
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
return llvm::makeArrayRef(g_target_modules_lookup_options);
}
@@ -3631,6 +3674,7 @@ public:
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_all_ranges; // Print all ranges or single range.
bool m_verbose; // Enable verbose lookup info
bool m_print_all; // Print all matches, even in cases where there's a best
// match.
@@ -3713,7 +3757,8 @@ public:
(m_options.m_verbose
? static_cast<int>(eSymbolContextVariable)
: 0),
- m_options.m_addr, m_options.m_offset, m_options.m_verbose)) {
+ m_options.m_addr, m_options.m_offset, m_options.m_verbose,
+ m_options.m_all_ranges)) {
result.SetStatus(eReturnStatusSuccessFinishResult);
return true;
}
@@ -3724,7 +3769,8 @@ public:
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)) {
+ m_options.m_use_regex, m_options.m_verbose,
+ m_options.m_all_ranges)) {
result.SetStatus(eReturnStatusSuccessFinishResult);
return true;
}
@@ -3736,7 +3782,8 @@ public:
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)) {
+ m_options.m_include_inlines, m_options.m_verbose,
+ m_options.m_all_ranges)) {
result.SetStatus(eReturnStatusSuccessFinishResult);
return true;
}
@@ -3754,7 +3801,8 @@ public:
if (LookupFunctionInModule(m_interpreter, result.GetOutputStream(),
module, m_options.m_str.c_str(),
m_options.m_use_regex, function_options,
- m_options.m_verbose)) {
+ m_options.m_verbose,
+ m_options.m_all_ranges)) {
result.SetStatus(eReturnStatusSuccessFinishResult);
return true;
}
@@ -3774,7 +3822,7 @@ public:
default:
m_options.GenerateOptionUsage(
- result.GetErrorStream(), this,
+ result.GetErrorStream(), *this,
GetCommandInterpreter().GetDebugger().GetTerminalWidth());
syntax_error = true;
break;
@@ -3969,6 +4017,8 @@ public:
m_option_group.Append(&m_current_stack_option, LLDB_OPT_SET_2,
LLDB_OPT_SET_2);
m_option_group.Finalize();
+ CommandArgumentData module_arg{eArgTypeShlibName, eArgRepeatPlain};
+ m_arguments.push_back({module_arg});
}
~CommandObjectTargetSymbolsAdd() override = default;
@@ -4142,10 +4192,13 @@ protected:
bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
CommandReturnObject &result, bool &flush) {
- if (Symbols::DownloadObjectAndSymbolFile(module_spec)) {
+ Status error;
+ if (Symbols::DownloadObjectAndSymbolFile(module_spec, error)) {
if (module_spec.GetSymbolFileSpec())
return AddModuleSymbols(m_exe_ctx.GetTargetPtr(), module_spec, flush,
result);
+ } else {
+ result.SetError(error);
}
return false;
}
@@ -4814,7 +4867,10 @@ public:
CommandObjectTargetStopHookDelete(CommandInterpreter &interpreter)
: CommandObjectParsed(interpreter, "target stop-hook delete",
"Delete a stop-hook.",
- "target stop-hook delete [<idx>]") {}
+ "target stop-hook delete [<idx>]") {
+ CommandArgumentData hook_arg{eArgTypeStopHookID, eArgRepeatStar};
+ m_arguments.push_back({hook_arg});
+ }
~CommandObjectTargetStopHookDelete() override = default;
@@ -4868,6 +4924,8 @@ public:
bool enable, const char *name,
const char *help, const char *syntax)
: CommandObjectParsed(interpreter, name, help, syntax), m_enable(enable) {
+ CommandArgumentData hook_arg{eArgTypeStopHookID, eArgRepeatStar};
+ m_arguments.push_back({hook_arg});
}
~CommandObjectTargetStopHookEnableDisable() override = default;
@@ -4923,8 +4981,7 @@ class CommandObjectTargetStopHookList : public CommandObjectParsed {
public:
CommandObjectTargetStopHookList(CommandInterpreter &interpreter)
: CommandObjectParsed(interpreter, "target stop-hook list",
- "List all stop-hooks.",
- "target stop-hook list [<type>]") {}
+ "List all stop-hooks.", "target stop-hook list") {}
~CommandObjectTargetStopHookList() override = default;
@@ -4996,11 +5053,6 @@ public:
protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
- if (!command.empty()) {
- result.AppendError("target dump typesystem doesn't take arguments.");
- return result.Succeeded();
- }
-
// Go over every scratch TypeSystem and dump to the command output.
for (TypeSystem *ts : GetSelectedTarget().GetScratchTypeSystems())
ts->Dump(result.GetOutputStream().AsRawOstream());