Skip to content

Commit 6029238

Browse files
Alexander Yermolovichkusmour
authored andcommitted
[LLDB] Add API to set section as ignored.
Summary: This API can be used by custom JIT to set section section as ignored. For example for code cache. This will force resolveAddress to use JITLoader. Test Plan: ninja check-lldb Rollback Plan: Reviewers: gclayton, jpporto, #lldb_team Reviewed By: gclayton Differential Revision: https://phabricator.intern.facebook.com/D77954663 Tasks: T230278908
1 parent 7b7f31d commit 6029238

File tree

6 files changed

+52
-9
lines changed

6 files changed

+52
-9
lines changed

lldb/include/lldb/API/SBSection.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ class LLDB_API SBSection {
8888

8989
bool GetDescription(lldb::SBStream &description);
9090

91+
/// Ignore this section when resolving addresses. Some JIT solutions
92+
/// will create a large section in the main binary that will get code JIT'ed
93+
/// into. Address lookups need to ignore this section and resolve the
94+
/// address in another module that gets loaded.
95+
void SetIsIgnored(bool ignore);
96+
9197
private:
9298
friend class SBAddress;
9399
friend class SBModule;

lldb/include/lldb/Core/Section.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,18 @@ class Section : public std::enable_shared_from_this<Section>,
266266

267267
void SetIsRelocated(bool b) { m_relocated = b; }
268268

269+
/// Check if this section is ignored for address resolution.
270+
/// \return
271+
/// Returns \b true if this section is ignored for address resolution, and
272+
/// falls back to JIT Loader resolution.
273+
bool IsIgnored() const { return m_ignore; }
274+
275+
/// Ignore this section when resolving addresses. Some JIT solutions
276+
/// will create a large section in the main binary that will get code JIT'ed
277+
/// into. Address lookups need to ignore this section and resolve the
278+
/// address in another module that gets loaded.
279+
void SetIsIgnored(bool b) { m_ignore = b; }
280+
269281
/// Returns true if this section contains debug information. Symbol tables
270282
/// are not considered debug information since some symbols might contain
271283
/// debug information (STABS, COFF) but not all symbols do, so to keep this
@@ -300,7 +312,9 @@ class Section : public std::enable_shared_from_this<Section>,
300312
m_readable : 1, // If this section has read permissions
301313
m_writable : 1, // If this section has write permissions
302314
m_executable : 1, // If this section has executable permissions
303-
m_relocated : 1; // If this section has had relocations applied
315+
m_relocated : 1, // If this section has had relocations applied
316+
m_ignore : 1; // If this section is ignored for address
317+
// resolution.
304318
uint32_t m_target_byte_size; // Some architectures have non-8-bit byte size.
305319
// This is specified as
306320
// as a multiple number of a host bytes

lldb/source/API/SBSection.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,11 @@ bool SBSection::GetDescription(SBStream &description) {
261261

262262
return true;
263263
}
264+
265+
void SBSection::SetIsIgnored(bool is_gnore_resolution) {
266+
LLDB_INSTRUMENT_VA(this);
267+
268+
SectionSP section_sp(GetSP());
269+
if (section_sp.get())
270+
section_sp->SetIsIgnored(is_gnore_resolution);
271+
}

lldb/source/Core/Section.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Section::Section(const ModuleSP &module_sp, ObjectFile *obj_file,
170170
m_file_offset(file_offset), m_file_size(file_size),
171171
m_log2align(log2align), m_children(), m_fake(false), m_encrypted(false),
172172
m_thread_specific(false), m_readable(false), m_writable(false),
173-
m_executable(false), m_relocated(false),
173+
m_executable(false), m_relocated(false), m_ignore(false),
174174
m_target_byte_size(target_byte_size) {}
175175

176176
Section::Section(const lldb::SectionSP &parent_section_sp,
@@ -185,7 +185,7 @@ Section::Section(const lldb::SectionSP &parent_section_sp,
185185
m_file_offset(file_offset), m_file_size(file_size),
186186
m_log2align(log2align), m_children(), m_fake(false), m_encrypted(false),
187187
m_thread_specific(false), m_readable(false), m_writable(false),
188-
m_executable(false), m_relocated(false),
188+
m_executable(false), m_relocated(false), m_ignore(false),
189189
m_target_byte_size(target_byte_size) {
190190
if (parent_section_sp)
191191
m_parent_wp = parent_section_sp;

lldb/source/Target/SectionLoadList.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ bool SectionLoadList::ResolveLoadAddress(addr_t load_addr, Address &so_addr,
220220
bool allow_section_end) const {
221221
// First find the top level section that this load address exists in
222222
std::lock_guard<std::recursive_mutex> guard(m_mutex);
223+
bool result = false;
223224
if (!m_addr_to_sect.empty()) {
224225
addr_to_sect_collection::const_iterator pos =
225226
m_addr_to_sect.lower_bound(load_addr);
@@ -232,8 +233,8 @@ bool SectionLoadList::ResolveLoadAddress(addr_t load_addr, Address &so_addr,
232233
if (offset < pos->second->GetByteSize() + (allow_section_end ? 1 : 0)) {
233234
// We have found the top level section, now we need to find the
234235
// deepest child section.
235-
return pos->second->ResolveContainedAddress(offset, so_addr,
236-
allow_section_end);
236+
result = pos->second->ResolveContainedAddress(offset, so_addr,
237+
allow_section_end);
237238
}
238239
}
239240
} else {
@@ -247,12 +248,19 @@ bool SectionLoadList::ResolveLoadAddress(addr_t load_addr, Address &so_addr,
247248
rpos->second->GetByteSize() + (allow_section_end ? 1 : 0)) {
248249
// We have found the top level section, now we need to find the
249250
// deepest child section.
250-
return rpos->second->ResolveContainedAddress(offset, so_addr,
251-
allow_section_end);
251+
result = rpos->second->ResolveContainedAddress(offset, so_addr,
252+
allow_section_end);
252253
}
253254
}
254255
}
255256
}
257+
258+
if (result) {
259+
SectionSP section_sp = so_addr.GetSection();
260+
if (section_sp && !section_sp->IsIgnored())
261+
return true;
262+
}
263+
256264
so_addr.Clear();
257265
return false;
258266
}

lldb/source/Target/Target.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "lldb/Target/ABI.h"
4848
#include "lldb/Target/JITLoaderList.h"
4949
#include "lldb/Target/ExecutionContext.h"
50+
#include "lldb/Target/JITLoaderList.h"
5051
#include "lldb/Target/Language.h"
5152
#include "lldb/Target/LanguageRuntime.h"
5253
#include "lldb/Target/Process.h"
@@ -3249,8 +3250,14 @@ Status Target::Install(ProcessLaunchInfo *launch_info) {
32493250

32503251
bool Target::ResolveLoadAddress(addr_t load_addr, Address &so_addr,
32513252
uint32_t stop_id, bool allow_section_end) {
3252-
return m_section_load_history.ResolveLoadAddress(stop_id, load_addr, so_addr,
3253-
allow_section_end);
3253+
if (m_section_load_history.ResolveLoadAddress(stop_id, load_addr, so_addr,
3254+
allow_section_end))
3255+
return true;
3256+
3257+
ProcessSP process_sp(GetProcessSP());
3258+
if (!process_sp)
3259+
return false;
3260+
return process_sp->GetJITLoaders().ResolveLoadAddress(load_addr, so_addr);
32543261
}
32553262

32563263
bool Target::ResolveFileAddress(lldb::addr_t file_addr,

0 commit comments

Comments
 (0)