[Lldb-commits] [lldb] Add AddressRange to SB API (PR #92014)
Greg Clayton via lldb-commits
lldb-commits at lists.llvm.org
Mon May 20 15:35:07 PDT 2024
================
@@ -203,3 +208,38 @@ void AddressRange::DumpDebug(Stream *s) const {
static_cast<void *>(m_base_addr.GetSection().get()),
m_base_addr.GetOffset(), GetByteSize());
}
+
+bool AddressRange::GetDescription(Stream *s, Target *target) const {
+ const char *file_name = nullptr;
+ addr_t start_addr = LLDB_INVALID_ADDRESS;
+
+ if (target == nullptr) {
+ const auto section_sp = m_base_addr.GetSection();
+ if (section_sp) {
+ const auto object_file = section_sp->GetObjectFile();
+ if (object_file != nullptr)
+ file_name = object_file->GetFileSpec().GetFilename().AsCString();
+ }
+ start_addr = m_base_addr.GetFileAddress();
+ } else {
+ start_addr = m_base_addr.GetLoadAddress(target);
+ file_name = "";
+ }
+
+ const addr_t end_addr = (start_addr == LLDB_INVALID_ADDRESS)
+ ? LLDB_INVALID_ADDRESS
+ : start_addr + GetByteSize();
----------------
clayborg wrote:
This might be easier to read and reason with if we structure it like:
```
addr_t start_addr = m_base_addr.GetLoadAddress(target);
if (start_addr != LLDB_INVALID_ADDRESS) {
// We have a valid target and the address was resolved, or we have a base address
// with no section. Just print out a raw address range: [<addr>, <addr>)
s->Printf("[0x%" PRIx64 "-0x%" PRIx64 ")", start_addr, start_addr + GetByteSize());
return;
}
// Either no target or the address wasn't resolved, print as <module>[<file-addr>-<file-addr>)
const char *file_name = "";
const auto section_sp = m_base_addr.GetSection();
if (section_sp) {
if (const auto object_file = section_sp->GetObjectFile())
file_name = object_file->GetFileSpec().GetFilename().AsCString();
}
start_addr = m_base_addr.GetFileAddress();
const addr_t end_addr = (start_addr == LLDB_INVALID_ADDRESS)
? LLDB_INVALID_ADDRESS
: start_addr + GetByteSize();
s->Printf("%s[0x%" PRIx64 "-0x%" PRIx64 "]", file_name, start_addr, end_addr);
```
the above `m_base_addr.GetLoadAddress(target)` call knows to check for a NULL target and will return LLDB_INVALID_ADDRESS if that is the case and there is a section.
https://github.com/llvm/llvm-project/pull/92014
More information about the lldb-commits
mailing list