summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/lldb/source/Commands/CommandObjectTarget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/tools/lldb/source/Commands/CommandObjectTarget.cpp')
-rw-r--r--contrib/llvm/tools/lldb/source/Commands/CommandObjectTarget.cpp107
1 files changed, 81 insertions, 26 deletions
diff --git a/contrib/llvm/tools/lldb/source/Commands/CommandObjectTarget.cpp b/contrib/llvm/tools/lldb/source/Commands/CommandObjectTarget.cpp
index d2e53aa..a80acf1 100644
--- a/contrib/llvm/tools/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/contrib/llvm/tools/lldb/source/Commands/CommandObjectTarget.cpp
@@ -16,9 +16,9 @@
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/Section.h"
#include "lldb/Core/State.h"
-#include "lldb/Core/Timer.h"
#include "lldb/Core/ValueObjectVariable.h"
#include "lldb/DataFormatters/ValueObjectPrinter.h"
+#include "lldb/Host/OptionParser.h"
#include "lldb/Host/StringConvert.h"
#include "lldb/Host/Symbols.h"
#include "lldb/Interpreter/Args.h"
@@ -49,6 +49,9 @@
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadSpec.h"
+#include "lldb/Utility/Timer.h"
+
+#include "llvm/Support/FileSystem.h"
// C Includes
// C++ Includes
@@ -266,8 +269,8 @@ protected:
}
const char *file_path = command.GetArgumentAtIndex(0);
- Timer scoped_timer(LLVM_PRETTY_FUNCTION, "(lldb) target create '%s'",
- file_path);
+ static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
+ Timer scoped_timer(func_cat, "(lldb) target create '%s'", file_path);
FileSpec file_spec;
if (file_path)
@@ -281,7 +284,7 @@ protected:
llvm::StringRef arch_cstr = m_arch_option.GetArchitectureName();
const bool get_dependent_files =
m_add_dependents.GetOptionValue().GetCurrentValue();
- Error error(debugger.GetTargetList().CreateTarget(
+ Status error(debugger.GetTargetList().CreateTarget(
debugger, file_path, arch_cstr, get_dependent_files, nullptr,
target_sp));
@@ -300,7 +303,7 @@ protected:
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);
+ Status err = platform_sp->PutFile(file_spec, remote_file);
if (err.Fail()) {
result.AppendError(err.AsCString());
result.SetStatus(eReturnStatusFailed);
@@ -321,7 +324,7 @@ protected:
}
if (file_path) {
// copy the remote file to the local file
- Error err = platform_sp->GetFile(remote_file, file_spec);
+ Status err = platform_sp->GetFile(remote_file, file_spec);
if (err.Fail()) {
result.AppendError(err.AsCString());
result.SetStatus(eReturnStatusFailed);
@@ -836,7 +839,7 @@ protected:
matches = target->GetImages().FindGlobalVariables(
regex, true, UINT32_MAX, variable_list);
} else {
- Error error(Variable::GetValuesForVariableExpressionPath(
+ Status error(Variable::GetValuesForVariableExpressionPath(
arg, m_exe_ctx.GetBestExecutionContextScope(),
GetVariableCallback, target, variable_list, valobj_list));
matches = variable_list.GetSize();
@@ -1990,9 +1993,9 @@ public:
~CommandOptions() override = default;
- Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
- ExecutionContext *execution_context) override {
- Error error;
+ Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+ ExecutionContext *execution_context) override {
+ Status error;
const int short_option = m_getopt_table[option_idx].val;
switch (short_option) {
@@ -2512,7 +2515,7 @@ protected:
m_symbol_file.GetOptionValue().GetCurrentValue();
if (!module_spec.GetArchitecture().IsValid())
module_spec.GetArchitecture() = target->GetArchitecture();
- Error error;
+ Status error;
ModuleSP module_sp(target->GetSharedModule(module_spec, &error));
if (!module_sp) {
const char *error_cstr = error.AsCString();
@@ -2567,6 +2570,12 @@ public:
m_option_group(),
m_file_option(LLDB_OPT_SET_1, false, "file", 'f', 0, eArgTypeName,
"Fullpath or basename for module to load.", ""),
+ m_load_option(LLDB_OPT_SET_1, false, "load", 'l',
+ "Write file contents to the memory.", false, true),
+ m_pc_option(LLDB_OPT_SET_1, false, "--set-pc-to-entry", 'p',
+ "Set PC to the entry point."
+ " Only applicable with '--load' option.",
+ false, true),
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.",
@@ -2574,6 +2583,8 @@ public:
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_load_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Append(&m_pc_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();
}
@@ -2585,6 +2596,8 @@ public:
protected:
bool DoExecute(Args &args, CommandReturnObject &result) override {
Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+ const bool load = m_load_option.GetOptionValue().GetCurrentValue();
+ const bool set_pc = m_pc_option.GetOptionValue().GetCurrentValue();
if (target == nullptr) {
result.AppendError("invalid target, create a debug target using the "
"'target create' command");
@@ -2594,6 +2607,21 @@ protected:
const size_t argc = args.GetArgumentCount();
ModuleSpec module_spec;
bool search_using_module_spec = false;
+
+ // Allow "load" option to work without --file or --uuid
+ // option.
+ if (load) {
+ if (!m_file_option.GetOptionValue().OptionWasSet() &&
+ !m_uuid_option_group.GetOptionValue().OptionWasSet()) {
+ ModuleList &module_list = target->GetImages();
+ if (module_list.GetSize() == 1) {
+ search_using_module_spec = true;
+ module_spec.GetFileSpec() =
+ module_list.GetModuleAtIndex(0)->GetFileSpec();
+ }
+ }
+ }
+
if (m_file_option.GetOptionValue().OptionWasSet()) {
search_using_module_spec = true;
const char *arg_cstr = m_file_option.GetOptionValue().GetCurrentValue();
@@ -2721,6 +2749,13 @@ protected:
if (process)
process->Flush();
}
+ if (load) {
+ Status error = module->LoadInMemory(*target, set_pc);
+ if (error.Fail()) {
+ result.AppendError(error.AsCString());
+ return false;
+ }
+ }
} else {
module->GetFileSpec().GetPath(path, sizeof(path));
result.AppendErrorWithFormat(
@@ -2783,6 +2818,8 @@ protected:
OptionGroupOptions m_option_group;
OptionGroupUUID m_uuid_option_group;
OptionGroupString m_file_option;
+ OptionGroupBoolean m_load_option;
+ OptionGroupBoolean m_pc_option;
OptionGroupUInt64 m_slide_option;
};
@@ -2820,9 +2857,9 @@ public:
~CommandOptions() override = default;
- Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
- ExecutionContext *execution_context) override {
- Error error;
+ Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+ ExecutionContext *execution_context) override {
+ Status error;
const int short_option = m_getopt_table[option_idx].val;
if (short_option == 'g') {
@@ -3183,9 +3220,9 @@ public:
~CommandOptions() override = default;
- Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
- ExecutionContext *execution_context) override {
- Error error;
+ Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+ ExecutionContext *execution_context) override {
+ Status error;
const int short_option = m_getopt_table[option_idx].val;
@@ -3389,6 +3426,23 @@ protected:
result.GetOutputStream().Printf("\n");
}
+ if (UnwindPlanSP plan_sp =
+ func_unwinders_sp->GetDebugFrameUnwindPlan(*target, 0)) {
+ result.GetOutputStream().Printf("debug_frame UnwindPlan:\n");
+ plan_sp->Dump(result.GetOutputStream(), thread.get(),
+ LLDB_INVALID_ADDRESS);
+ result.GetOutputStream().Printf("\n");
+ }
+
+ if (UnwindPlanSP plan_sp =
+ func_unwinders_sp->GetDebugFrameAugmentedUnwindPlan(*target,
+ *thread, 0)) {
+ result.GetOutputStream().Printf("debug_frame augmented UnwindPlan:\n");
+ plan_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) {
@@ -3483,9 +3537,9 @@ public:
~CommandOptions() override = default;
- Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
- ExecutionContext *execution_context) override {
- Error error;
+ Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+ ExecutionContext *execution_context) override {
+ Status error;
const int short_option = m_getopt_table[option_idx].val;
@@ -4077,7 +4131,7 @@ protected:
// Make sure we load any scripting resources that may be embedded
// in the debug info files in case the platform supports that.
- Error error;
+ Status error;
StreamString feedback_stream;
module_sp->LoadScriptingResourceInTarget(target, error,
&feedback_stream);
@@ -4102,20 +4156,21 @@ protected:
module_sp->SetSymbolFileFileSpec(FileSpec());
}
+ namespace fs = llvm::sys::fs;
if (module_spec.GetUUID().IsValid()) {
StreamString ss_symfile_uuid;
module_spec.GetUUID().Dump(&ss_symfile_uuid);
result.AppendErrorWithFormat(
"symbol file '%s' (%s) does not match any existing module%s\n",
symfile_path, ss_symfile_uuid.GetData(),
- (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular)
+ !fs::is_regular_file(symbol_fspec.GetPath())
? "\n please specify the full path to the symbol file"
: "");
} else {
result.AppendErrorWithFormat(
"symbol file '%s' does not match any existing module%s\n",
symfile_path,
- (symbol_fspec.GetFileType() != FileSpec::eFileTypeRegular)
+ !fs::is_regular_file(symbol_fspec.GetPath())
? "\n please specify the full path to the symbol file"
: "");
}
@@ -4360,9 +4415,9 @@ public:
return llvm::makeArrayRef(g_target_stop_hook_add_options);
}
- Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
- ExecutionContext *execution_context) override {
- Error error;
+ Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
+ ExecutionContext *execution_context) override {
+ Status error;
const int short_option = m_getopt_table[option_idx].val;
switch (short_option) {
OpenPOWER on IntegriCloud