blob: 0308812bc560c38fc527d526dbd2e7f7e8e48f37 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Address.cpp ---------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/Address.h"
11#include "lldb/Core/Module.h"
12#include "lldb/Core/Section.h"
13#include "lldb/Symbol/ObjectFile.h"
Greg Claytonc749eb82011-07-11 05:12:02 +000014#include "lldb/Symbol/Variable.h"
15#include "lldb/Symbol/VariableList.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000016#include "lldb/Target/ExecutionContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/Target/Process.h"
18#include "lldb/Target/Target.h"
19
Greg Clayton3f5c08f2011-05-18 22:01:49 +000020#include "llvm/ADT/Triple.h"
21
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022using namespace lldb;
23using namespace lldb_private;
24
25static size_t
26ReadBytes (ExecutionContextScope *exe_scope, const Address &address, void *dst, size_t dst_len)
27{
28 if (exe_scope == NULL)
29 return 0;
30
Greg Claytond9e416c2012-02-18 05:35:26 +000031 TargetSP target_sp (exe_scope->CalculateTarget());
32 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033 {
34 Error error;
Greg Claytondb598232011-01-07 01:57:07 +000035 bool prefer_file_cache = false;
Greg Claytond9e416c2012-02-18 05:35:26 +000036 return target_sp->ReadMemory (address, prefer_file_cache, dst, dst_len, error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037 }
38 return 0;
39}
40
41static bool
42GetByteOrderAndAddressSize (ExecutionContextScope *exe_scope, const Address &address, ByteOrder& byte_order, uint32_t& addr_size)
43{
44 byte_order = eByteOrderInvalid;
45 addr_size = 0;
46 if (exe_scope == NULL)
47 return false;
48
Greg Claytond9e416c2012-02-18 05:35:26 +000049 TargetSP target_sp (exe_scope->CalculateTarget());
50 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051 {
Greg Claytond9e416c2012-02-18 05:35:26 +000052 byte_order = target_sp->GetArchitecture().GetByteOrder();
53 addr_size = target_sp->GetArchitecture().GetAddressByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054 }
55
56 if (byte_order == eByteOrderInvalid || addr_size == 0)
57 {
Greg Claytone72dfb32012-02-24 01:59:29 +000058 ModuleSP module_sp (address.GetModule());
59 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060 {
Greg Claytone72dfb32012-02-24 01:59:29 +000061 byte_order = module_sp->GetArchitecture().GetByteOrder();
62 addr_size = module_sp->GetArchitecture().GetAddressByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063 }
64 }
65 return byte_order != eByteOrderInvalid && addr_size != 0;
66}
67
68static uint64_t
69ReadUIntMax64 (ExecutionContextScope *exe_scope, const Address &address, uint32_t byte_size, bool &success)
70{
71 uint64_t uval64 = 0;
72 if (exe_scope == NULL || byte_size > sizeof(uint64_t))
73 {
74 success = false;
75 return 0;
76 }
Johnny Chen40e35922011-08-25 17:40:39 +000077 uint64_t buf = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078
79 success = ReadBytes (exe_scope, address, &buf, byte_size) == byte_size;
80 if (success)
81 {
82 ByteOrder byte_order = eByteOrderInvalid;
83 uint32_t addr_size = 0;
84 if (GetByteOrderAndAddressSize (exe_scope, address, byte_order, addr_size))
85 {
86 DataExtractor data (&buf, sizeof(buf), byte_order, addr_size);
87 uint32_t offset = 0;
88 uval64 = data.GetU64(&offset);
89 }
90 else
91 success = false;
92 }
93 return uval64;
94}
95
96static bool
97ReadAddress (ExecutionContextScope *exe_scope, const Address &address, uint32_t pointer_size, Address &deref_so_addr)
98{
99 if (exe_scope == NULL)
100 return false;
101
102
103 bool success = false;
104 addr_t deref_addr = ReadUIntMax64 (exe_scope, address, pointer_size, success);
105 if (success)
106 {
Greg Claytonf5e56de2010-09-14 23:36:40 +0000107 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000108 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Claytonf5e56de2010-09-14 23:36:40 +0000109 // If we have any sections that are loaded, try and resolve using the
110 // section load list
Greg Claytonc14ee322011-09-22 04:58:26 +0000111 Target *target = exe_ctx.GetTargetPtr();
112 if (target && !target->GetSectionLoadList().IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000113 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000114 if (target->GetSectionLoadList().ResolveLoadAddress (deref_addr, deref_so_addr))
Greg Claytonf5e56de2010-09-14 23:36:40 +0000115 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000116 }
117 else
118 {
Greg Claytonf5e56de2010-09-14 23:36:40 +0000119 // If we were not running, yet able to read an integer, we must
120 // have a module
Greg Claytone72dfb32012-02-24 01:59:29 +0000121 ModuleSP module_sp (address.GetModule());
122
123 assert (module_sp);
124 if (module_sp->ResolveFileAddress(deref_addr, deref_so_addr))
Greg Claytonf5e56de2010-09-14 23:36:40 +0000125 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126 }
Greg Claytonf5e56de2010-09-14 23:36:40 +0000127
128 // We couldn't make "deref_addr" into a section offset value, but we were
129 // able to read the address, so we return a section offset address with
130 // no section and "deref_addr" as the offset (address).
Greg Claytone72dfb32012-02-24 01:59:29 +0000131 deref_so_addr.SetRawAddress(deref_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000132 return true;
133 }
134 return false;
135}
136
137static bool
138DumpUInt (ExecutionContextScope *exe_scope, const Address &address, uint32_t byte_size, Stream* strm)
139{
Greg Clayton471b31c2010-07-20 22:52:08 +0000140 if (exe_scope == NULL || byte_size == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000141 return 0;
142 std::vector<uint8_t> buf(byte_size, 0);
143
144 if (ReadBytes (exe_scope, address, &buf[0], buf.size()) == buf.size())
145 {
146 ByteOrder byte_order = eByteOrderInvalid;
147 uint32_t addr_size = 0;
148 if (GetByteOrderAndAddressSize (exe_scope, address, byte_order, addr_size))
149 {
Greg Clayton471b31c2010-07-20 22:52:08 +0000150 DataExtractor data (&buf.front(), buf.size(), byte_order, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000151
152 data.Dump (strm,
153 0, // Start offset in "data"
154 eFormatHex, // Print as characters
155 buf.size(), // Size of item
156 1, // Items count
157 UINT32_MAX, // num per line
158 LLDB_INVALID_ADDRESS,// base address
159 0, // bitfield bit size
160 0); // bitfield bit offset
161
162 return true;
163 }
164 }
165 return false;
166}
167
168
169static size_t
170ReadCStringFromMemory (ExecutionContextScope *exe_scope, const Address &address, Stream *strm)
171{
172 if (exe_scope == NULL)
173 return 0;
174 const size_t k_buf_len = 256;
175 char buf[k_buf_len+1];
176 buf[k_buf_len] = '\0'; // NULL terminate
177
Greg Clayton710dd5a2011-01-08 20:28:42 +0000178 // Byte order and address size don't matter for C string dumping..
Greg Clayton7fb56d02011-02-01 01:31:41 +0000179 DataExtractor data (buf, sizeof(buf), lldb::endian::InlHostByteOrder(), 4);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000180 size_t total_len = 0;
181 size_t bytes_read;
182 Address curr_address(address);
183 strm->PutChar ('"');
184 while ((bytes_read = ReadBytes (exe_scope, curr_address, buf, k_buf_len)) > 0)
185 {
186 size_t len = strlen(buf);
187 if (len == 0)
188 break;
189 if (len > bytes_read)
190 len = bytes_read;
191
192 data.Dump (strm,
193 0, // Start offset in "data"
194 eFormatChar, // Print as characters
195 1, // Size of item (1 byte for a char!)
196 len, // How many bytes to print?
197 UINT32_MAX, // num per line
198 LLDB_INVALID_ADDRESS,// base address
199 0, // bitfield bit size
200
201 0); // bitfield bit offset
202
203 total_len += bytes_read;
204
205 if (len < k_buf_len)
206 break;
207 curr_address.SetOffset (curr_address.GetOffset() + bytes_read);
208 }
209 strm->PutChar ('"');
210 return total_len;
211}
212
Greg Claytone72dfb32012-02-24 01:59:29 +0000213Address::Address (lldb::addr_t abs_addr) :
214 m_section_wp (),
215 m_offset (abs_addr)
216{
217}
218
219Address::Address (addr_t address, const SectionList *section_list) :
220 m_section_wp (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000221 m_offset (LLDB_INVALID_ADDRESS)
222{
Greg Claytone72dfb32012-02-24 01:59:29 +0000223 ResolveAddressUsingFileSections(address, section_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224}
225
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000226const Address&
227Address::operator= (const Address& rhs)
228{
229 if (this != &rhs)
230 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000231 m_section_wp = rhs.m_section_wp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000232 m_offset = rhs.m_offset;
233 }
234 return *this;
235}
236
237bool
Greg Claytone72dfb32012-02-24 01:59:29 +0000238Address::ResolveAddressUsingFileSections (addr_t file_addr, const SectionList *section_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000239{
Greg Claytone72dfb32012-02-24 01:59:29 +0000240 if (section_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000241 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000242 SectionSP section_sp (section_list->FindSectionContainingFileAddress(file_addr));
243 m_section_wp = section_sp;
244 if (section_sp)
245 {
246 assert( section_sp->ContainsFileAddress(file_addr) );
247 m_offset = file_addr - section_sp->GetFileAddress();
248 return true; // Successfully transformed addr into a section offset address
249 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000250 }
Greg Claytone72dfb32012-02-24 01:59:29 +0000251 m_offset = file_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000252 return false; // Failed to resolve this address to a section offset value
253}
254
Greg Claytone1cd1be2012-01-29 20:56:30 +0000255ModuleSP
Greg Claytone72dfb32012-02-24 01:59:29 +0000256Address::GetModule () const
Greg Claytone1cd1be2012-01-29 20:56:30 +0000257{
258 lldb::ModuleSP module_sp;
Greg Claytone72dfb32012-02-24 01:59:29 +0000259 SectionSP section_sp (GetSection());
260 if (section_sp)
261 module_sp = section_sp->GetModule();
Greg Claytone1cd1be2012-01-29 20:56:30 +0000262 return module_sp;
263}
264
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265addr_t
266Address::GetFileAddress () const
267{
Greg Claytone72dfb32012-02-24 01:59:29 +0000268 SectionSP section_sp (GetSection());
269 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000271 addr_t sect_file_addr = section_sp->GetFileAddress();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272 if (sect_file_addr == LLDB_INVALID_ADDRESS)
273 {
274 // Section isn't resolved, we can't return a valid file address
275 return LLDB_INVALID_ADDRESS;
276 }
277 // We have a valid file range, so we can return the file based
278 // address by adding the file base address to our offset
279 return sect_file_addr + m_offset;
280 }
281 // No section, we just return the offset since it is the value in this case
282 return m_offset;
283}
284
285addr_t
Greg Claytonf5e56de2010-09-14 23:36:40 +0000286Address::GetLoadAddress (Target *target) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000287{
Greg Claytone72dfb32012-02-24 01:59:29 +0000288 SectionSP section_sp (GetSection());
289 if (!section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000290 {
Greg Claytonf5e56de2010-09-14 23:36:40 +0000291 // No section, we just return the offset since it is the value in this case
292 return m_offset;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000293 }
Greg Claytonf5e56de2010-09-14 23:36:40 +0000294
295 if (target)
296 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000297 addr_t sect_load_addr = section_sp->GetLoadBaseAddress (target);
Greg Claytonf5e56de2010-09-14 23:36:40 +0000298
299 if (sect_load_addr != LLDB_INVALID_ADDRESS)
300 {
301 // We have a valid file range, so we can return the file based
302 // address by adding the file base address to our offset
303 return sect_load_addr + m_offset;
304 }
305 }
306 // The section isn't resolved or no process was supplied so we can't
307 // return a valid file address.
308 return LLDB_INVALID_ADDRESS;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000309}
310
Greg Clayton3f5c08f2011-05-18 22:01:49 +0000311addr_t
312Address::GetCallableLoadAddress (Target *target) const
313{
314 addr_t code_addr = GetLoadAddress (target);
Greg Claytonf3ef3d22011-05-22 22:46:53 +0000315
316 if (target)
317 return target->GetCallableLoadAddress (code_addr, GetAddressClass());
Greg Clayton3f5c08f2011-05-18 22:01:49 +0000318 return code_addr;
319}
320
Greg Claytoncff851a2011-05-22 04:32:55 +0000321bool
322Address::SetCallableLoadAddress (lldb::addr_t load_addr, Target *target)
323{
324 if (SetLoadAddress (load_addr, target))
325 {
Greg Claytonf3ef3d22011-05-22 22:46:53 +0000326 if (target)
327 m_offset = target->GetCallableLoadAddress(m_offset, GetAddressClass());
Greg Claytoncff851a2011-05-22 04:32:55 +0000328 return true;
329 }
330 return false;
331}
332
Greg Clayton92bb12c2011-05-19 18:17:41 +0000333addr_t
334Address::GetOpcodeLoadAddress (Target *target) const
335{
336 addr_t code_addr = GetLoadAddress (target);
Greg Clayton92bb12c2011-05-19 18:17:41 +0000337 if (code_addr != LLDB_INVALID_ADDRESS)
Greg Claytonf3ef3d22011-05-22 22:46:53 +0000338 code_addr = target->GetOpcodeLoadAddress (code_addr, GetAddressClass());
Greg Clayton92bb12c2011-05-19 18:17:41 +0000339 return code_addr;
340}
341
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000342bool
Greg Claytoncff851a2011-05-22 04:32:55 +0000343Address::SetOpcodeLoadAddress (lldb::addr_t load_addr, Target *target)
344{
345 if (SetLoadAddress (load_addr, target))
346 {
Greg Claytonf3ef3d22011-05-22 22:46:53 +0000347 if (target)
348 m_offset = target->GetOpcodeLoadAddress (m_offset, GetAddressClass());
Greg Claytoncff851a2011-05-22 04:32:55 +0000349 return true;
350 }
351 return false;
352}
353
354bool
Greg Claytondda4f7b2010-06-30 23:03:03 +0000355Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style, uint32_t addr_size) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000356{
Greg Claytonc3a86bf2012-07-11 22:18:24 +0000357 // If the section was NULL, only load address is going to work unless we are
358 // trying to deref a pointer
Greg Claytone72dfb32012-02-24 01:59:29 +0000359 SectionSP section_sp (GetSection());
Greg Claytonc3a86bf2012-07-11 22:18:24 +0000360 if (!section_sp && style != DumpStyleResolvedPointerDescription)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000361 style = DumpStyleLoadAddress;
362
Greg Claytond9e416c2012-02-18 05:35:26 +0000363 ExecutionContext exe_ctx (exe_scope);
364 Target *target = exe_ctx.GetTargetPtr();
Greg Claytondda4f7b2010-06-30 23:03:03 +0000365 // If addr_byte_size is UINT32_MAX, then determine the correct address
366 // byte size for the process or default to the size of addr_t
367 if (addr_size == UINT32_MAX)
368 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000369 if (target)
Greg Clayton514487e2011-02-15 21:59:32 +0000370 addr_size = target->GetArchitecture().GetAddressByteSize ();
Greg Claytondda4f7b2010-06-30 23:03:03 +0000371 else
372 addr_size = sizeof(addr_t);
373 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374
Greg Claytonc9800662010-09-10 01:30:46 +0000375 Address so_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000376 switch (style)
377 {
Greg Claytonc982c762010-07-09 20:39:50 +0000378 case DumpStyleInvalid:
379 return false;
380
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381 case DumpStyleSectionNameOffset:
Greg Claytone72dfb32012-02-24 01:59:29 +0000382 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000384 section_sp->DumpName(s);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385 s->Printf (" + %llu", m_offset);
386 }
387 else
388 {
Greg Claytondda4f7b2010-06-30 23:03:03 +0000389 s->Address(m_offset, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000390 }
391 break;
392
393 case DumpStyleSectionPointerOffset:
Greg Claytone72dfb32012-02-24 01:59:29 +0000394 s->Printf("(Section *)%p + ", section_sp.get());
Greg Claytondda4f7b2010-06-30 23:03:03 +0000395 s->Address(m_offset, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396 break;
397
398 case DumpStyleModuleWithFileAddress:
Greg Claytone72dfb32012-02-24 01:59:29 +0000399 if (section_sp)
400 s->Printf("%s[", section_sp->GetModule()->GetFileSpec().GetFilename().AsCString());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000401 // Fall through
402 case DumpStyleFileAddress:
403 {
404 addr_t file_addr = GetFileAddress();
405 if (file_addr == LLDB_INVALID_ADDRESS)
406 {
407 if (fallback_style != DumpStyleInvalid)
Greg Claytondda4f7b2010-06-30 23:03:03 +0000408 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000409 return false;
410 }
411 s->Address (file_addr, addr_size);
Greg Claytone72dfb32012-02-24 01:59:29 +0000412 if (style == DumpStyleModuleWithFileAddress && section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413 s->PutChar(']');
414 }
415 break;
416
417 case DumpStyleLoadAddress:
418 {
Greg Claytonf5e56de2010-09-14 23:36:40 +0000419 addr_t load_addr = GetLoadAddress (target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420 if (load_addr == LLDB_INVALID_ADDRESS)
421 {
422 if (fallback_style != DumpStyleInvalid)
Greg Claytondda4f7b2010-06-30 23:03:03 +0000423 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424 return false;
425 }
426 s->Address (load_addr, addr_size);
427 }
428 break;
429
430 case DumpStyleResolvedDescription:
Greg Clayton54b8b8c2010-07-01 01:26:43 +0000431 case DumpStyleResolvedDescriptionNoModule:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432 if (IsSectionOffset())
433 {
Greg Claytone0d378b2011-03-24 21:19:54 +0000434 AddressType addr_type = eAddressTypeLoad;
Greg Claytonf5e56de2010-09-14 23:36:40 +0000435 addr_t addr = GetLoadAddress (target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000436 if (addr == LLDB_INVALID_ADDRESS)
437 {
438 addr = GetFileAddress();
439 addr_type = eAddressTypeFile;
440 }
441
442 uint32_t pointer_size = 4;
Greg Claytone72dfb32012-02-24 01:59:29 +0000443 ModuleSP module_sp (GetModule());
Greg Clayton514487e2011-02-15 21:59:32 +0000444 if (target)
445 pointer_size = target->GetArchitecture().GetAddressByteSize();
Greg Claytone72dfb32012-02-24 01:59:29 +0000446 else if (module_sp)
447 pointer_size = module_sp->GetArchitecture().GetAddressByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000448
449 bool showed_info = false;
Greg Claytone72dfb32012-02-24 01:59:29 +0000450 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000451 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000452 SectionType sect_type = section_sp->GetType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 switch (sect_type)
454 {
Greg Clayton89411422010-10-08 00:21:05 +0000455 case eSectionTypeData:
Greg Claytone72dfb32012-02-24 01:59:29 +0000456 if (module_sp)
Greg Clayton89411422010-10-08 00:21:05 +0000457 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000458 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton89411422010-10-08 00:21:05 +0000459 if (objfile)
460 {
461 Symtab *symtab = objfile->GetSymtab();
462 if (symtab)
463 {
464 const addr_t file_Addr = GetFileAddress();
465 Symbol *symbol = symtab->FindSymbolContainingFileAddress (file_Addr);
466 if (symbol)
467 {
468 const char *symbol_name = symbol->GetName().AsCString();
469 if (symbol_name)
470 {
471 s->PutCString(symbol_name);
Greg Claytone7612132012-03-07 21:03:09 +0000472 addr_t delta = file_Addr - symbol->GetAddress().GetFileAddress();
Greg Clayton89411422010-10-08 00:21:05 +0000473 if (delta)
474 s->Printf(" + %llu", delta);
475 showed_info = true;
476 }
477 }
478 }
479 }
480 }
481 break;
482
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483 case eSectionTypeDataCString:
484 // Read the C string from memory and display it
485 showed_info = true;
486 ReadCStringFromMemory (exe_scope, *this, s);
487 break;
488
489 case eSectionTypeDataCStringPointers:
490 {
491 if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
492 {
493#if VERBOSE_OUTPUT
494 s->PutCString("(char *)");
495 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
496 s->PutCString(": ");
497#endif
498 showed_info = true;
499 ReadCStringFromMemory (exe_scope, so_addr, s);
500 }
501 }
502 break;
503
504 case eSectionTypeDataObjCMessageRefs:
505 {
506 if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
507 {
Greg Clayton54b8b8c2010-07-01 01:26:43 +0000508 if (target && so_addr.IsSectionOffset())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000509 {
Greg Claytonc9800662010-09-10 01:30:46 +0000510 SymbolContext func_sc;
Greg Clayton54b8b8c2010-07-01 01:26:43 +0000511 target->GetImages().ResolveSymbolContextForAddress (so_addr,
Greg Claytond9e416c2012-02-18 05:35:26 +0000512 eSymbolContextEverything,
513 func_sc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000514 if (func_sc.function || func_sc.symbol)
515 {
516 showed_info = true;
517#if VERBOSE_OUTPUT
518 s->PutCString ("(objc_msgref *) -> { (func*)");
519 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
520#else
521 s->PutCString ("{ ");
522#endif
523 Address cstr_addr(*this);
524 cstr_addr.SetOffset(cstr_addr.GetOffset() + pointer_size);
Greg Clayton6dadd502010-09-02 21:44:10 +0000525 func_sc.DumpStopContext(s, exe_scope, so_addr, true, true, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526 if (ReadAddress (exe_scope, cstr_addr, pointer_size, so_addr))
527 {
528#if VERBOSE_OUTPUT
529 s->PutCString("), (char *)");
530 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
531 s->PutCString(" (");
532#else
533 s->PutCString(", ");
534#endif
535 ReadCStringFromMemory (exe_scope, so_addr, s);
536 }
537#if VERBOSE_OUTPUT
538 s->PutCString(") }");
539#else
540 s->PutCString(" }");
541#endif
542 }
543 }
544 }
545 }
546 break;
547
548 case eSectionTypeDataObjCCFStrings:
549 {
550 Address cfstring_data_addr(*this);
551 cfstring_data_addr.SetOffset(cfstring_data_addr.GetOffset() + (2 * pointer_size));
552 if (ReadAddress (exe_scope, cfstring_data_addr, pointer_size, so_addr))
553 {
554#if VERBOSE_OUTPUT
555 s->PutCString("(CFString *) ");
556 cfstring_data_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
557 s->PutCString(" -> @");
558#else
559 s->PutChar('@');
560#endif
561 if (so_addr.Dump(s, exe_scope, DumpStyleResolvedDescription))
562 showed_info = true;
563 }
564 }
565 break;
566
567 case eSectionTypeData4:
568 // Read the 4 byte data and display it
569 showed_info = true;
570 s->PutCString("(uint32_t) ");
571 DumpUInt (exe_scope, *this, 4, s);
572 break;
573
574 case eSectionTypeData8:
575 // Read the 8 byte data and display it
576 showed_info = true;
577 s->PutCString("(uint64_t) ");
578 DumpUInt (exe_scope, *this, 8, s);
579 break;
580
581 case eSectionTypeData16:
582 // Read the 16 byte data and display it
583 showed_info = true;
584 s->PutCString("(uint128_t) ");
585 DumpUInt (exe_scope, *this, 16, s);
586 break;
587
588 case eSectionTypeDataPointers:
589 // Read the pointer data and display it
590 {
591 if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
592 {
593 s->PutCString ("(void *)");
594 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
595
596 showed_info = true;
597 if (so_addr.IsSectionOffset())
598 {
Greg Claytonc9800662010-09-10 01:30:46 +0000599 SymbolContext pointer_sc;
Greg Claytondda4f7b2010-06-30 23:03:03 +0000600 if (target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000601 {
Greg Claytondda4f7b2010-06-30 23:03:03 +0000602 target->GetImages().ResolveSymbolContextForAddress (so_addr,
Greg Claytond9e416c2012-02-18 05:35:26 +0000603 eSymbolContextEverything,
604 pointer_sc);
Greg Claytondda4f7b2010-06-30 23:03:03 +0000605 if (pointer_sc.function || pointer_sc.symbol)
606 {
607 s->PutCString(": ");
Greg Clayton6dadd502010-09-02 21:44:10 +0000608 pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, false);
Greg Claytondda4f7b2010-06-30 23:03:03 +0000609 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000610 }
611 }
612 }
613 }
614 break;
Greg Claytonc982c762010-07-09 20:39:50 +0000615
616 default:
617 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000618 }
619 }
620
621 if (!showed_info)
622 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000623 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000624 {
Greg Claytonc9800662010-09-10 01:30:46 +0000625 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000626 module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000627 if (sc.function || sc.symbol)
628 {
629 bool show_stop_context = true;
Greg Clayton8dc0a982010-09-07 21:56:53 +0000630 const bool show_module = (style == DumpStyleResolvedDescription);
631 const bool show_fullpaths = false;
Greg Clayton513c26c2011-01-29 07:10:55 +0000632 const bool show_inlined_frames = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000633 if (sc.function == NULL && sc.symbol != NULL)
634 {
635 // If we have just a symbol make sure it is in the right section
Greg Claytone7612132012-03-07 21:03:09 +0000636 if (sc.symbol->ValueIsAddress())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637 {
Greg Claytone7612132012-03-07 21:03:09 +0000638 if (sc.symbol->GetAddress().GetSection() != GetSection())
Greg Clayton54b8b8c2010-07-01 01:26:43 +0000639 {
640 // don't show the module if the symbol is a trampoline symbol
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000641 show_stop_context = false;
Greg Clayton54b8b8c2010-07-01 01:26:43 +0000642 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000643 }
644 }
645 if (show_stop_context)
646 {
647 // We have a function or a symbol from the same
648 // sections as this address.
Greg Clayton8dc0a982010-09-07 21:56:53 +0000649 sc.DumpStopContext (s,
650 exe_scope,
651 *this,
652 show_fullpaths,
653 show_module,
654 show_inlined_frames);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000655 }
656 else
657 {
658 // We found a symbol but it was in a different
659 // section so it isn't the symbol we should be
660 // showing, just show the section name + offset
661 Dump (s, exe_scope, DumpStyleSectionNameOffset);
662 }
663 }
664 }
665 }
666 }
667 else
668 {
669 if (fallback_style != DumpStyleInvalid)
Greg Claytondda4f7b2010-06-30 23:03:03 +0000670 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000671 return false;
672 }
673 break;
Greg Claytondda4f7b2010-06-30 23:03:03 +0000674
675 case DumpStyleDetailedSymbolContext:
676 if (IsSectionOffset())
677 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000678 ModuleSP module_sp (GetModule());
679 if (module_sp)
Greg Claytondda4f7b2010-06-30 23:03:03 +0000680 {
Greg Claytonc9800662010-09-10 01:30:46 +0000681 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000682 module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc);
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000683 if (sc.symbol)
Greg Claytondda4f7b2010-06-30 23:03:03 +0000684 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000685 // If we have just a symbol make sure it is in the same section
686 // as our address. If it isn't, then we might have just found
687 // the last symbol that came before the address that we are
688 // looking up that has nothing to do with our address lookup.
Greg Claytone7612132012-03-07 21:03:09 +0000689 if (sc.symbol->ValueIsAddress() && sc.symbol->GetAddress().GetSection() != GetSection())
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000690 sc.symbol = NULL;
Greg Claytondda4f7b2010-06-30 23:03:03 +0000691 }
Greg Claytonf5e56de2010-09-14 23:36:40 +0000692 sc.GetDescription(s, eDescriptionLevelBrief, target);
Greg Claytonc749eb82011-07-11 05:12:02 +0000693
694 if (sc.block)
695 {
696 bool can_create = true;
697 bool get_parent_variables = true;
698 bool stop_if_block_is_inlined_function = false;
699 VariableList variable_list;
700 sc.block->AppendVariables (can_create,
701 get_parent_variables,
702 stop_if_block_is_inlined_function,
703 &variable_list);
704
705 uint32_t num_variables = variable_list.GetSize();
706 for (uint32_t var_idx = 0; var_idx < num_variables; ++var_idx)
707 {
708 Variable *var = variable_list.GetVariableAtIndex (var_idx).get();
709 if (var && var->LocationIsValidForAddress (*this))
710 {
Greg Claytonc4a8a762012-05-15 18:43:44 +0000711 s->Indent();
712 s->Printf (" Variable: id = {0x%8.8llx}, name = \"%s\", type= \"%s\", location =",
Greg Claytonc749eb82011-07-11 05:12:02 +0000713 var->GetID(),
714 var->GetName().GetCString(),
715 var->GetType()->GetName().GetCString());
716 var->DumpLocationForAddress(s, *this);
717 s->PutCString(", decl = ");
718 var->GetDeclaration().DumpStopContext(s, false);
719 s->EOL();
720 }
721 }
722 }
Greg Claytondda4f7b2010-06-30 23:03:03 +0000723 }
724 }
Greg Claytonc749eb82011-07-11 05:12:02 +0000725 else
726 {
727 if (fallback_style != DumpStyleInvalid)
728 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
729 return false;
730 }
Greg Claytondda4f7b2010-06-30 23:03:03 +0000731 break;
Greg Claytonc3a86bf2012-07-11 22:18:24 +0000732 case DumpStyleResolvedPointerDescription:
733 {
734 Process *process = exe_ctx.GetProcessPtr();
735 if (process)
736 {
737 addr_t load_addr = GetLoadAddress (target);
738 if (load_addr != LLDB_INVALID_ADDRESS)
739 {
740 Error memory_error;
741 addr_t dereferenced_load_addr = process->ReadPointerFromMemory(load_addr, memory_error);
742 if (dereferenced_load_addr != LLDB_INVALID_ADDRESS)
743 {
744 Address dereferenced_addr;
745 if (dereferenced_addr.SetLoadAddress(dereferenced_load_addr, target))
746 {
747 StreamString strm;
748 if (dereferenced_addr.Dump (&strm, exe_scope, DumpStyleResolvedDescription, DumpStyleInvalid, addr_size))
749 {
750 s->Address (dereferenced_load_addr, addr_size, " -> ", " ");
751 s->Write(strm.GetData(), strm.GetSize());
752 return true;
753 }
754 }
755 }
756 }
757 }
758 if (fallback_style != DumpStyleInvalid)
759 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
760 return false;
761 }
762 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000763 }
764
765 return true;
766}
767
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000768uint32_t
Greg Clayton6f6bf262011-12-10 21:05:26 +0000769Address::CalculateSymbolContext (SymbolContext *sc, uint32_t resolve_scope) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770{
771 sc->Clear();
772 // Absolute addresses don't have enough information to reconstruct even their target.
Greg Claytone72dfb32012-02-24 01:59:29 +0000773
774 SectionSP section_sp (GetSection());
775 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000776 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000777 ModuleSP module_sp (section_sp->GetModule());
778 if (module_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000779 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000780 sc->module_sp = module_sp;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000781 if (sc->module_sp)
782 return sc->module_sp->ResolveSymbolContextForAddress (*this, resolve_scope, *sc);
783 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000785 return 0;
786}
787
Greg Claytone72dfb32012-02-24 01:59:29 +0000788ModuleSP
Greg Clayton6f6bf262011-12-10 21:05:26 +0000789Address::CalculateSymbolContextModule () const
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000790{
Greg Claytone72dfb32012-02-24 01:59:29 +0000791 SectionSP section_sp (GetSection());
792 if (section_sp)
793 return section_sp->GetModule();
794 return ModuleSP();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000795}
796
797CompileUnit *
Greg Clayton6f6bf262011-12-10 21:05:26 +0000798Address::CalculateSymbolContextCompileUnit () const
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000799{
Greg Claytone72dfb32012-02-24 01:59:29 +0000800 SectionSP section_sp (GetSection());
801 if (section_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000802 {
803 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000804 sc.module_sp = section_sp->GetModule();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000805 if (sc.module_sp)
806 {
807 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextCompUnit, sc);
808 return sc.comp_unit;
809 }
810 }
811 return NULL;
812}
813
814Function *
Greg Clayton6f6bf262011-12-10 21:05:26 +0000815Address::CalculateSymbolContextFunction () const
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000816{
Greg Claytone72dfb32012-02-24 01:59:29 +0000817 SectionSP section_sp (GetSection());
818 if (section_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000819 {
820 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000821 sc.module_sp = section_sp->GetModule();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000822 if (sc.module_sp)
823 {
824 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextFunction, sc);
825 return sc.function;
826 }
827 }
828 return NULL;
829}
830
831Block *
Greg Clayton6f6bf262011-12-10 21:05:26 +0000832Address::CalculateSymbolContextBlock () const
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000833{
Greg Claytone72dfb32012-02-24 01:59:29 +0000834 SectionSP section_sp (GetSection());
835 if (section_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000836 {
837 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000838 sc.module_sp = section_sp->GetModule();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000839 if (sc.module_sp)
840 {
841 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextBlock, sc);
842 return sc.block;
843 }
844 }
845 return NULL;
846}
847
848Symbol *
Greg Clayton6f6bf262011-12-10 21:05:26 +0000849Address::CalculateSymbolContextSymbol () const
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000850{
Greg Claytone72dfb32012-02-24 01:59:29 +0000851 SectionSP section_sp (GetSection());
852 if (section_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000853 {
854 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000855 sc.module_sp = section_sp->GetModule();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000856 if (sc.module_sp)
857 {
858 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextSymbol, sc);
859 return sc.symbol;
860 }
861 }
862 return NULL;
863}
864
865bool
Greg Clayton6f6bf262011-12-10 21:05:26 +0000866Address::CalculateSymbolContextLineEntry (LineEntry &line_entry) const
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000867{
Greg Claytone72dfb32012-02-24 01:59:29 +0000868 SectionSP section_sp (GetSection());
869 if (section_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000870 {
871 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000872 sc.module_sp = section_sp->GetModule();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000873 if (sc.module_sp)
874 {
875 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextLineEntry, sc);
876 if (sc.line_entry.IsValid())
877 {
878 line_entry = sc.line_entry;
879 return true;
880 }
881 }
882 }
883 line_entry.Clear();
884 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000885}
886
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000887int
888Address::CompareFileAddress (const Address& a, const Address& b)
889{
890 addr_t a_file_addr = a.GetFileAddress();
891 addr_t b_file_addr = b.GetFileAddress();
892 if (a_file_addr < b_file_addr)
893 return -1;
894 if (a_file_addr > b_file_addr)
895 return +1;
896 return 0;
897}
898
899
900int
Greg Claytonf5e56de2010-09-14 23:36:40 +0000901Address::CompareLoadAddress (const Address& a, const Address& b, Target *target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000902{
Greg Claytonf5e56de2010-09-14 23:36:40 +0000903 assert (target != NULL);
904 addr_t a_load_addr = a.GetLoadAddress (target);
905 addr_t b_load_addr = b.GetLoadAddress (target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000906 if (a_load_addr < b_load_addr)
907 return -1;
908 if (a_load_addr > b_load_addr)
909 return +1;
910 return 0;
911}
912
913int
914Address::CompareModulePointerAndOffset (const Address& a, const Address& b)
915{
Greg Claytone72dfb32012-02-24 01:59:29 +0000916 ModuleSP a_module_sp (a.GetModule());
917 ModuleSP b_module_sp (b.GetModule());
918 Module *a_module = a_module_sp.get();
919 Module *b_module = b_module_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000920 if (a_module < b_module)
921 return -1;
922 if (a_module > b_module)
923 return +1;
924 // Modules are the same, just compare the file address since they should
925 // be unique
926 addr_t a_file_addr = a.GetFileAddress();
927 addr_t b_file_addr = b.GetFileAddress();
928 if (a_file_addr < b_file_addr)
929 return -1;
930 if (a_file_addr > b_file_addr)
931 return +1;
932 return 0;
933}
934
935
936size_t
937Address::MemorySize () const
938{
939 // Noting special for the memory size of a single Address object,
940 // it is just the size of itself.
941 return sizeof(Address);
942}
943
944
Greg Claytonb0848c52011-01-08 00:05:12 +0000945//----------------------------------------------------------------------
946// NOTE: Be careful using this operator. It can correctly compare two
947// addresses from the same Module correctly. It can't compare two
948// addresses from different modules in any meaningful way, but it will
949// compare the module pointers.
950//
951// To sum things up:
952// - works great for addresses within the same module
953// - it works for addresses across multiple modules, but don't expect the
954// address results to make much sense
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000955//
Greg Claytonb0848c52011-01-08 00:05:12 +0000956// This basically lets Address objects be used in ordered collection
957// classes.
958//----------------------------------------------------------------------
959
960bool
961lldb_private::operator< (const Address& lhs, const Address& rhs)
962{
Greg Claytone72dfb32012-02-24 01:59:29 +0000963 ModuleSP lhs_module_sp (lhs.GetModule());
964 ModuleSP rhs_module_sp (rhs.GetModule());
965 Module *lhs_module = lhs_module_sp.get();
966 Module *rhs_module = rhs_module_sp.get();
Greg Claytonb0848c52011-01-08 00:05:12 +0000967 if (lhs_module == rhs_module)
968 {
969 // Addresses are in the same module, just compare the file addresses
970 return lhs.GetFileAddress() < rhs.GetFileAddress();
971 }
972 else
973 {
974 // The addresses are from different modules, just use the module
975 // pointer value to get consistent ordering
976 return lhs_module < rhs_module;
977 }
978}
979
980bool
981lldb_private::operator> (const Address& lhs, const Address& rhs)
982{
Greg Claytone72dfb32012-02-24 01:59:29 +0000983 ModuleSP lhs_module_sp (lhs.GetModule());
984 ModuleSP rhs_module_sp (rhs.GetModule());
985 Module *lhs_module = lhs_module_sp.get();
986 Module *rhs_module = rhs_module_sp.get();
Greg Claytonb0848c52011-01-08 00:05:12 +0000987 if (lhs_module == rhs_module)
988 {
989 // Addresses are in the same module, just compare the file addresses
990 return lhs.GetFileAddress() > rhs.GetFileAddress();
991 }
992 else
993 {
994 // The addresses are from different modules, just use the module
995 // pointer value to get consistent ordering
996 return lhs_module > rhs_module;
997 }
998}
999
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001000
1001// The operator == checks for exact equality only (same section, same offset)
1002bool
1003lldb_private::operator== (const Address& a, const Address& rhs)
1004{
1005 return a.GetSection() == rhs.GetSection() &&
1006 a.GetOffset() == rhs.GetOffset();
1007}
1008// The operator != checks for exact inequality only (differing section, or
1009// different offset)
1010bool
1011lldb_private::operator!= (const Address& a, const Address& rhs)
1012{
1013 return a.GetSection() != rhs.GetSection() ||
1014 a.GetOffset() != rhs.GetOffset();
1015}
1016
1017bool
1018Address::IsLinkedAddress () const
1019{
Greg Claytone72dfb32012-02-24 01:59:29 +00001020 SectionSP section_sp (GetSection());
1021 return section_sp && section_sp->GetLinkedSection();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001022}
1023
1024
1025void
1026Address::ResolveLinkedAddress ()
1027{
Greg Claytone72dfb32012-02-24 01:59:29 +00001028 SectionSP section_sp (GetSection());
1029 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001030 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001031 SectionSP linked_section_sp (section_sp->GetLinkedSection());
1032 if (linked_section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001033 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001034 m_offset += section_sp->GetLinkedOffset();
1035 m_section_wp = linked_section_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001036 }
1037 }
1038}
Greg Claytonded470d2011-03-19 01:12:21 +00001039
Greg Claytone0d378b2011-03-24 21:19:54 +00001040AddressClass
Greg Claytonded470d2011-03-19 01:12:21 +00001041Address::GetAddressClass () const
1042{
Greg Claytone72dfb32012-02-24 01:59:29 +00001043 ModuleSP module_sp (GetModule());
1044 if (module_sp)
Greg Claytonded470d2011-03-19 01:12:21 +00001045 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001046 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Claytonded470d2011-03-19 01:12:21 +00001047 if (obj_file)
1048 return obj_file->GetAddressClass (GetFileAddress());
1049 }
1050 return eAddressClassUnknown;
1051}
Greg Claytoncd482e32011-05-18 01:58:14 +00001052
1053bool
1054Address::SetLoadAddress (lldb::addr_t load_addr, Target *target)
1055{
1056 if (target && target->GetSectionLoadList().ResolveLoadAddress(load_addr, *this))
1057 return true;
Greg Claytone72dfb32012-02-24 01:59:29 +00001058 m_section_wp.reset();
Greg Claytoncd482e32011-05-18 01:58:14 +00001059 m_offset = load_addr;
1060 return false;
1061}
1062