diff options
author | Hafiz Abid Qadeer <hafiz_abid@mentor.com> | 2017-01-19 17:32:50 +0000 |
---|---|---|
committer | Hafiz Abid Qadeer <hafiz_abid@mentor.com> | 2017-01-19 17:32:50 +0000 |
commit | 4687db0e09322d5a24f89aaa221ba854199e4333 (patch) | |
tree | ee539395d7d78a94dd17c4c81824d1e3f5b6ef81 /lldb/source/Commands/CommandObjectTarget.cpp | |
parent | bece0cd51294b96c5562d5f769363dc468e5f9bf (diff) | |
download | bcm5719-llvm-4687db0e09322d5a24f89aaa221ba854199e4333.tar.gz bcm5719-llvm-4687db0e09322d5a24f89aaa221ba854199e4333.zip |
Provide a substitute to load command of gdb.
For bare-metal targets, lldb was missing a command like 'load' in gdb
which can be used to create executable image on the target. This was
discussed in
http://lists.llvm.org/pipermail/lldb-dev/2016-December/011752.html
This commits adds an option to "target module load" command to provide
that functionality. It does not set the PC to entry address which will
be done separately.
Reviewed in https://reviews.llvm.org/D28804
llvm-svn: 292499
Diffstat (limited to 'lldb/source/Commands/CommandObjectTarget.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectTarget.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index d2e53aa4a14..61e9e9bcd94 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -2567,6 +2567,9 @@ 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_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 +2577,7 @@ 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_slide_option, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); m_option_group.Finalize(); } @@ -2585,6 +2589,7 @@ public: protected: bool DoExecute(Args &args, CommandReturnObject &result) override { Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + const bool load = m_load_option.GetOptionValue().GetCurrentValue(); if (target == nullptr) { result.AppendError("invalid target, create a debug target using the " "'target create' command"); @@ -2594,6 +2599,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 +2741,13 @@ protected: if (process) process->Flush(); } + if (load) { + Error error = module->LoadInMemory(*target); + if (error.Fail()) { + result.AppendError(error.AsCString()); + return false; + } + } } else { module->GetFileSpec().GetPath(path, sizeof(path)); result.AppendErrorWithFormat( @@ -2783,6 +2810,7 @@ protected: OptionGroupOptions m_option_group; OptionGroupUUID m_uuid_option_group; OptionGroupString m_file_option; + OptionGroupBoolean m_load_option; OptionGroupUInt64 m_slide_option; }; |