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/Symbol/ObjectFile.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/Symbol/ObjectFile.cpp')
-rw-r--r-- | lldb/source/Symbol/ObjectFile.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lldb/source/Symbol/ObjectFile.cpp b/lldb/source/Symbol/ObjectFile.cpp index 0b1d6b29983..ecae78e3954 100644 --- a/lldb/source/Symbol/ObjectFile.cpp +++ b/lldb/source/Symbol/ObjectFile.cpp @@ -20,6 +20,9 @@ #include "lldb/Core/Timer.h" #include "lldb/Symbol/ObjectContainer.h" #include "lldb/Symbol/SymbolFile.h" +#include "lldb/Target/Target.h" +#include "lldb/Target/RegisterContext.h" +#include "lldb/Target/SectionLoadList.h" #include "lldb/Target/Process.h" #include "lldb/lldb-private.h" @@ -648,3 +651,31 @@ ConstString ObjectFile::GetNextSyntheticSymbolName() { file_name.GetCString()); return ConstString(ss.GetString()); } + +Error ObjectFile::LoadInMemory(Target &target) { + Error error; + ProcessSP process = target.CalculateProcess(); + if (!process) + return Error("No Process"); + + SectionList *section_list = GetSectionList(); + if (!section_list) + return Error("No section in object file"); + size_t section_count = section_list->GetNumSections(0); + for (size_t i = 0; i < section_count; ++i) { + SectionSP section_sp = section_list->GetSectionAtIndex(i); + addr_t addr = target.GetSectionLoadList().GetSectionLoadAddress(section_sp); + if (addr != LLDB_INVALID_ADDRESS) { + DataExtractor section_data; + // We can skip sections like bss + if (section_sp->GetFileSize() == 0) + continue; + section_sp->GetSectionData(section_data); + lldb::offset_t written = process->WriteMemory( + addr, section_data.GetDataStart(), section_data.GetByteSize(), error); + if (written != section_data.GetByteSize()) + return error; + } + } + return error; +} |