1 //===-- AddressRange.cpp ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/AddressRange.h"
11 #include "lldb/Core/Module.h"
12 #include "lldb/Target/Target.h"
13 #include "lldb/Utility/ConstString.h"
14 #include "lldb/Utility/FileSpec.h"
15 #include "lldb/Utility/Stream.h"
16 #include "lldb/lldb-defines.h"
18 #include "llvm/Support/Compiler.h"
24 namespace lldb_private {
29 using namespace lldb_private;
31 AddressRange::AddressRange() : m_base_addr(), m_byte_size(0) {}
33 AddressRange::AddressRange(addr_t file_addr, addr_t byte_size,
34 const SectionList *section_list)
35 : m_base_addr(file_addr, section_list), m_byte_size(byte_size) {}
37 AddressRange::AddressRange(const lldb::SectionSP §ion, addr_t offset,
39 : m_base_addr(section, offset), m_byte_size(byte_size) {}
41 AddressRange::AddressRange(const Address &so_addr, addr_t byte_size)
42 : m_base_addr(so_addr), m_byte_size(byte_size) {}
44 AddressRange::~AddressRange() {}
47 // AddressRange::Contains (const Address &addr) const
49 // const addr_t byte_size = GetByteSize();
51 // return addr.GetSection() == m_base_addr.GetSection() &&
52 // (addr.GetOffset() - m_base_addr.GetOffset()) < byte_size;
56 // AddressRange::Contains (const Address *addr) const
59 // return Contains (*addr);
63 bool AddressRange::ContainsFileAddress(const Address &addr) const {
64 if (addr.GetSection() == m_base_addr.GetSection())
65 return (addr.GetOffset() - m_base_addr.GetOffset()) < GetByteSize();
66 addr_t file_base_addr = GetBaseAddress().GetFileAddress();
67 if (file_base_addr == LLDB_INVALID_ADDRESS)
70 addr_t file_addr = addr.GetFileAddress();
71 if (file_addr == LLDB_INVALID_ADDRESS)
74 if (file_base_addr <= file_addr)
75 return (file_addr - file_base_addr) < GetByteSize();
80 bool AddressRange::ContainsFileAddress(addr_t file_addr) const {
81 if (file_addr == LLDB_INVALID_ADDRESS)
84 addr_t file_base_addr = GetBaseAddress().GetFileAddress();
85 if (file_base_addr == LLDB_INVALID_ADDRESS)
88 if (file_base_addr <= file_addr)
89 return (file_addr - file_base_addr) < GetByteSize();
94 bool AddressRange::ContainsLoadAddress(const Address &addr,
95 Target *target) const {
96 if (addr.GetSection() == m_base_addr.GetSection())
97 return (addr.GetOffset() - m_base_addr.GetOffset()) < GetByteSize();
98 addr_t load_base_addr = GetBaseAddress().GetLoadAddress(target);
99 if (load_base_addr == LLDB_INVALID_ADDRESS)
102 addr_t load_addr = addr.GetLoadAddress(target);
103 if (load_addr == LLDB_INVALID_ADDRESS)
106 if (load_base_addr <= load_addr)
107 return (load_addr - load_base_addr) < GetByteSize();
112 bool AddressRange::ContainsLoadAddress(addr_t load_addr, Target *target) const {
113 if (load_addr == LLDB_INVALID_ADDRESS)
116 addr_t load_base_addr = GetBaseAddress().GetLoadAddress(target);
117 if (load_base_addr == LLDB_INVALID_ADDRESS)
120 if (load_base_addr <= load_addr)
121 return (load_addr - load_base_addr) < GetByteSize();
126 void AddressRange::Clear() {
131 bool AddressRange::Dump(Stream *s, Target *target, Address::DumpStyle style,
132 Address::DumpStyle fallback_style) const {
133 addr_t vmaddr = LLDB_INVALID_ADDRESS;
134 int addr_size = sizeof(addr_t);
136 addr_size = target->GetArchitecture().GetAddressByteSize();
138 bool show_module = false;
142 case Address::DumpStyleSectionNameOffset:
143 case Address::DumpStyleSectionPointerOffset:
145 m_base_addr.Dump(s, target, style, fallback_style);
147 s->Address(m_base_addr.GetOffset() + GetByteSize(), addr_size);
152 case Address::DumpStyleModuleWithFileAddress:
155 case Address::DumpStyleFileAddress:
156 vmaddr = m_base_addr.GetFileAddress();
159 case Address::DumpStyleLoadAddress:
160 vmaddr = m_base_addr.GetLoadAddress(target);
164 if (vmaddr != LLDB_INVALID_ADDRESS) {
166 ModuleSP module_sp(GetBaseAddress().GetModule());
168 s->Printf("%s", module_sp->GetFileSpec().GetFilename().AsCString(
171 s->AddressRange(vmaddr, vmaddr + GetByteSize(), addr_size);
173 } else if (fallback_style != Address::DumpStyleInvalid) {
174 return Dump(s, target, fallback_style, Address::DumpStyleInvalid);
180 void AddressRange::DumpDebug(Stream *s) const {
181 s->Printf("%p: AddressRange section = %p, offset = 0x%16.16" PRIx64
182 ", byte_size = 0x%16.16" PRIx64 "\n",
183 static_cast<const void *>(this),
184 static_cast<void *>(m_base_addr.GetSection().get()),
185 m_base_addr.GetOffset(), GetByteSize());
189 // lldb::operator== (const AddressRange& lhs, const AddressRange& rhs)
191 // if (lhs.GetBaseAddress() == rhs.GetBaseAddress())
192 // return lhs.GetByteSize() == rhs.GetByteSize();