2014-03-24 23:10:19 +00:00
|
|
|
//===-- ObjectFileJIT.cpp ---------------------------------------*- C++ -*-===//
|
|
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-03-24 23:10:19 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
|
|
|
|
|
|
#include "ObjectFileJIT.h"
|
|
|
|
|
#include "lldb/Core/Debugger.h"
|
|
|
|
|
#include "lldb/Core/FileSpecList.h"
|
|
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
|
#include "lldb/Core/ModuleSpec.h"
|
|
|
|
|
#include "lldb/Core/PluginManager.h"
|
|
|
|
|
#include "lldb/Core/Section.h"
|
|
|
|
|
#include "lldb/Core/StreamFile.h"
|
|
|
|
|
#include "lldb/Host/Host.h"
|
|
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
|
|
|
|
#include "lldb/Target/Platform.h"
|
|
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
|
#include "lldb/Target/SectionLoadList.h"
|
|
|
|
|
#include "lldb/Target/Target.h"
|
2017-11-13 16:16:33 +00:00
|
|
|
#include "lldb/Utility/ArchSpec.h"
|
2017-03-04 01:30:05 +00:00
|
|
|
#include "lldb/Utility/DataBuffer.h"
|
|
|
|
|
#include "lldb/Utility/DataBufferHeap.h"
|
2017-03-22 18:40:07 +00:00
|
|
|
#include "lldb/Utility/FileSpec.h"
|
2017-03-03 20:56:28 +00:00
|
|
|
#include "lldb/Utility/Log.h"
|
Move RangeMap.h into Utility
Summary:
This file implements some general purpose data structures, and so it
belongs to the Utility module.
Reviewers: zturner, jingham, JDevlieghere, clayborg, espindola
Subscribers: emaste, mgorny, javed.absar, arichardson, MaskRay, lldb-commits
Differential Revision: https://reviews.llvm.org/D58970
llvm-svn: 355509
2019-03-06 14:41:43 +00:00
|
|
|
#include "lldb/Utility/RangeMap.h"
|
2017-02-02 21:39:50 +00:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2017-06-29 14:32:17 +00:00
|
|
|
#include "lldb/Utility/Timer.h"
|
2017-03-04 01:30:05 +00:00
|
|
|
#include "lldb/Utility/UUID.h"
|
2014-03-24 23:10:19 +00:00
|
|
|
|
|
|
|
|
#ifndef __APPLE__
|
|
|
|
|
#include "Utility/UuidCompatibility.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
Add llvm-style RTTI to ObjectFile hierarchy
Summary:
On the heels of D62934, this patch uses the same approach to introduce
llvm RTTI support to the ObjectFile hierarchy. It also replaces the
existing uses of GetPluginName doing run-time type checks with
llvm::dyn_cast and friends.
This formally introduces new dependencies from some other plugins to
ObjectFile plugins. However, I believe this is fine because:
- these dependencies were already kind of there, and the only reason
we could get away with not modeling them explicitly was because the
code was relying on magically knowing what will GetPluginName() return
for a particular kind of object files.
- the dependencies themselves are logical (it makes sense for
SymbolVendorELF to depend on ObjectFileELF), or at least don't
actively get in the way (the JitLoaderGDB->MachO thing).
- they don't introduce any new dependency loops as ObjectFile plugins
don't depend on any other plugins
Reviewers: xiaobai, JDevlieghere, espindola
Subscribers: emaste, mgorny, arichardson, MaskRay, lldb-commits
Differential Revision: https://reviews.llvm.org/D65450
llvm-svn: 367413
2019-07-31 11:57:34 +00:00
|
|
|
char ObjectFileJIT::ID;
|
|
|
|
|
|
2014-03-24 23:10:19 +00:00
|
|
|
void ObjectFileJIT::Initialize() {
|
|
|
|
|
PluginManager::RegisterPlugin(GetPluginNameStatic(),
|
|
|
|
|
GetPluginDescriptionStatic(), CreateInstance,
|
|
|
|
|
CreateMemoryInstance, GetModuleSpecifications);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ObjectFileJIT::Terminate() {
|
|
|
|
|
PluginManager::UnregisterPlugin(CreateInstance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lldb_private::ConstString ObjectFileJIT::GetPluginNameStatic() {
|
|
|
|
|
static ConstString g_name("jit");
|
|
|
|
|
return g_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *ObjectFileJIT::GetPluginDescriptionStatic() {
|
|
|
|
|
return "JIT code object file";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ObjectFile *ObjectFileJIT::CreateInstance(const lldb::ModuleSP &module_sp,
|
|
|
|
|
DataBufferSP &data_sp,
|
|
|
|
|
lldb::offset_t data_offset,
|
|
|
|
|
const FileSpec *file,
|
|
|
|
|
lldb::offset_t file_offset,
|
|
|
|
|
lldb::offset_t length) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// JIT'ed object file is backed by the ObjectFileJITDelegate, never read from
|
|
|
|
|
// a file
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 11:14:47 +00:00
|
|
|
return nullptr;
|
2014-03-24 23:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ObjectFile *ObjectFileJIT::CreateMemoryInstance(const lldb::ModuleSP &module_sp,
|
|
|
|
|
DataBufferSP &data_sp,
|
|
|
|
|
const ProcessSP &process_sp,
|
|
|
|
|
lldb::addr_t header_addr) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// JIT'ed object file is backed by the ObjectFileJITDelegate, never read from
|
|
|
|
|
// memory
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 11:14:47 +00:00
|
|
|
return nullptr;
|
2014-03-24 23:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t ObjectFileJIT::GetModuleSpecifications(
|
|
|
|
|
const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
|
|
|
|
|
lldb::offset_t data_offset, lldb::offset_t file_offset,
|
|
|
|
|
lldb::offset_t length, lldb_private::ModuleSpecList &specs) {
|
|
|
|
|
// JIT'ed object file can't be read from a file on disk
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ObjectFileJIT::ObjectFileJIT(const lldb::ModuleSP &module_sp,
|
|
|
|
|
const ObjectFileJITDelegateSP &delegate_sp)
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 11:14:47 +00:00
|
|
|
: ObjectFile(module_sp, nullptr, 0, 0, DataBufferSP(), 0), m_delegate_wp() {
|
2014-03-24 23:10:19 +00:00
|
|
|
if (delegate_sp) {
|
|
|
|
|
m_delegate_wp = delegate_sp;
|
|
|
|
|
m_data.SetByteOrder(delegate_sp->GetByteOrder());
|
|
|
|
|
m_data.SetAddressByteSize(delegate_sp->GetAddressByteSize());
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2014-03-24 23:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ObjectFileJIT::~ObjectFileJIT() {}
|
|
|
|
|
|
|
|
|
|
bool ObjectFileJIT::ParseHeader() {
|
|
|
|
|
// JIT code is never in a file, nor is it required to have any header
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ByteOrder ObjectFileJIT::GetByteOrder() const { return m_data.GetByteOrder(); }
|
|
|
|
|
|
|
|
|
|
bool ObjectFileJIT::IsExecutable() const { return false; }
|
|
|
|
|
|
|
|
|
|
uint32_t ObjectFileJIT::GetAddressByteSize() const {
|
|
|
|
|
return m_data.GetAddressByteSize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Symtab *ObjectFileJIT::GetSymtab() {
|
|
|
|
|
ModuleSP module_sp(GetModule());
|
|
|
|
|
if (module_sp) {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 11:14:47 +00:00
|
|
|
if (m_symtab_up == nullptr) {
|
2019-02-13 06:25:41 +00:00
|
|
|
m_symtab_up.reset(new Symtab(this));
|
2016-05-19 05:13:57 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> symtab_guard(
|
2019-02-13 06:25:41 +00:00
|
|
|
m_symtab_up->GetMutex());
|
2014-03-24 23:10:19 +00:00
|
|
|
ObjectFileJITDelegateSP delegate_sp(m_delegate_wp.lock());
|
|
|
|
|
if (delegate_sp)
|
2019-02-13 06:25:41 +00:00
|
|
|
delegate_sp->PopulateSymtab(this, *m_symtab_up);
|
2014-03-24 23:10:19 +00:00
|
|
|
// TODO: get symbols from delegate
|
2019-02-13 06:25:41 +00:00
|
|
|
m_symtab_up->Finalize();
|
2014-03-24 23:10:19 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2019-02-13 06:25:41 +00:00
|
|
|
return m_symtab_up.get();
|
2014-03-24 23:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ObjectFileJIT::IsStripped() {
|
|
|
|
|
return false; // JIT code that is in a module is never stripped
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ObjectFileJIT::CreateSections(SectionList &unified_section_list) {
|
2019-02-13 06:25:41 +00:00
|
|
|
if (!m_sections_up) {
|
|
|
|
|
m_sections_up.reset(new SectionList());
|
2014-03-24 23:10:19 +00:00
|
|
|
ObjectFileJITDelegateSP delegate_sp(m_delegate_wp.lock());
|
|
|
|
|
if (delegate_sp) {
|
2019-02-13 06:25:41 +00:00
|
|
|
delegate_sp->PopulateSectionList(this, *m_sections_up);
|
|
|
|
|
unified_section_list = *m_sections_up;
|
2014-03-24 23:10:19 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2014-03-24 23:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ObjectFileJIT::Dump(Stream *s) {
|
|
|
|
|
ModuleSP module_sp(GetModule());
|
|
|
|
|
if (module_sp) {
|
2016-05-18 01:59:10 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
|
2014-04-04 04:06:10 +00:00
|
|
|
s->Printf("%p: ", static_cast<void *>(this));
|
2014-03-24 23:10:19 +00:00
|
|
|
s->Indent();
|
|
|
|
|
s->PutCString("ObjectFileJIT");
|
|
|
|
|
|
2019-01-03 10:37:19 +00:00
|
|
|
if (ArchSpec arch = GetArchitecture())
|
2014-03-24 23:10:19 +00:00
|
|
|
*s << ", arch = " << arch.GetArchitectureName();
|
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
s->EOL();
|
2014-03-24 23:10:19 +00:00
|
|
|
|
|
|
|
|
SectionList *sections = GetSectionList();
|
|
|
|
|
if (sections)
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 11:14:47 +00:00
|
|
|
sections->Dump(s, nullptr, true, UINT32_MAX);
|
2014-03-24 23:10:19 +00:00
|
|
|
|
2019-02-13 06:25:41 +00:00
|
|
|
if (m_symtab_up)
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 11:14:47 +00:00
|
|
|
m_symtab_up->Dump(s, nullptr, eSortOrderNone);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2014-03-24 23:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
2019-02-11 16:14:02 +00:00
|
|
|
UUID ObjectFileJIT::GetUUID() {
|
2014-03-24 23:10:19 +00:00
|
|
|
// TODO: maybe get from delegate, not needed for first pass
|
2019-02-11 16:14:02 +00:00
|
|
|
return UUID();
|
2014-03-24 23:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t ObjectFileJIT::GetDependentModules(FileSpecList &files) {
|
|
|
|
|
// JIT modules don't have dependencies, but they could
|
|
|
|
|
// if external functions are called and we know where they are
|
|
|
|
|
files.Clear();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lldb_private::Address ObjectFileJIT::GetEntryPointAddress() {
|
|
|
|
|
return Address();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-11 15:21:15 +00:00
|
|
|
lldb_private::Address ObjectFileJIT::GetBaseAddress() { return Address(); }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-03-24 23:10:19 +00:00
|
|
|
ObjectFile::Type ObjectFileJIT::CalculateType() { return eTypeJIT; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-03-24 23:10:19 +00:00
|
|
|
ObjectFile::Strata ObjectFileJIT::CalculateStrata() { return eStrataJIT; }
|
|
|
|
|
|
2019-01-03 10:37:19 +00:00
|
|
|
ArchSpec ObjectFileJIT::GetArchitecture() {
|
|
|
|
|
if (ObjectFileJITDelegateSP delegate_sp = m_delegate_wp.lock())
|
|
|
|
|
return delegate_sp->GetArchitecture();
|
|
|
|
|
return ArchSpec();
|
2014-03-24 23:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PluginInterface protocol
|
|
|
|
|
lldb_private::ConstString ObjectFileJIT::GetPluginName() {
|
|
|
|
|
return GetPluginNameStatic();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t ObjectFileJIT::GetPluginVersion() { return 1; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-03-24 23:10:19 +00:00
|
|
|
bool ObjectFileJIT::SetLoadAddress(Target &target, lldb::addr_t value,
|
|
|
|
|
bool value_is_offset) {
|
|
|
|
|
size_t num_loaded_sections = 0;
|
|
|
|
|
SectionList *section_list = GetSectionList();
|
|
|
|
|
if (section_list) {
|
|
|
|
|
const size_t num_sections = section_list->GetSize();
|
|
|
|
|
// "value" is an offset to apply to each top level segment
|
|
|
|
|
for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// Iterate through the object file sections to find all of the sections
|
|
|
|
|
// that size on disk (to avoid __PAGEZERO) and load them
|
2014-03-24 23:10:19 +00:00
|
|
|
SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
|
|
|
|
|
if (section_sp && section_sp->GetFileSize() > 0 &&
|
2018-12-15 00:15:33 +00:00
|
|
|
!section_sp->IsThreadSpecific()) {
|
2014-03-24 23:10:19 +00:00
|
|
|
if (target.GetSectionLoadList().SetSectionLoadAddress(
|
|
|
|
|
section_sp, section_sp->GetFileAddress() + value))
|
|
|
|
|
++num_loaded_sections;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2014-03-24 23:10:19 +00:00
|
|
|
return num_loaded_sections > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-02 14:35:07 +00:00
|
|
|
size_t ObjectFileJIT::ReadSectionData(lldb_private::Section *section,
|
2014-07-02 17:24:07 +00:00
|
|
|
lldb::offset_t section_offset, void *dst,
|
2017-10-02 14:35:07 +00:00
|
|
|
size_t dst_len) {
|
2014-03-24 23:10:19 +00:00
|
|
|
lldb::offset_t file_size = section->GetFileSize();
|
2014-07-02 17:24:07 +00:00
|
|
|
if (section_offset < file_size) {
|
|
|
|
|
size_t src_len = file_size - section_offset;
|
2014-03-24 23:10:19 +00:00
|
|
|
if (src_len > dst_len)
|
|
|
|
|
src_len = dst_len;
|
|
|
|
|
const uint8_t *src =
|
|
|
|
|
((uint8_t *)(uintptr_t)section->GetFileOffset()) + section_offset;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-03-24 23:10:19 +00:00
|
|
|
memcpy(dst, src, src_len);
|
|
|
|
|
return src_len;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2014-07-02 17:24:07 +00:00
|
|
|
|
2014-03-24 23:10:19 +00:00
|
|
|
size_t ObjectFileJIT::ReadSectionData(
|
2017-10-02 14:35:07 +00:00
|
|
|
lldb_private::Section *section,
|
|
|
|
|
lldb_private::DataExtractor §ion_data) {
|
2014-03-24 23:10:19 +00:00
|
|
|
if (section->GetFileSize()) {
|
|
|
|
|
const void *src = (void *)(uintptr_t)section->GetFileOffset();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-07-01 11:09:15 +00:00
|
|
|
DataBufferSP data_sp =
|
|
|
|
|
std::make_shared<DataBufferHeap>(src, section->GetFileSize());
|
|
|
|
|
section_data.SetData(data_sp, 0, data_sp->GetByteSize());
|
|
|
|
|
section_data.SetByteOrder(GetByteOrder());
|
|
|
|
|
section_data.SetAddressByteSize(GetAddressByteSize());
|
|
|
|
|
return section_data.GetByteSize();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2014-03-24 23:10:19 +00:00
|
|
|
section_data.Clear();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|