blob: 005a1a03e80810e8f41fba46a1ed139473965eb5 [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{
357 // If the section was NULL, only load address is going to work.
Greg Claytone72dfb32012-02-24 01:59:29 +0000358 SectionSP section_sp (GetSection());
359 if (!section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000360 style = DumpStyleLoadAddress;
361
Greg Claytond9e416c2012-02-18 05:35:26 +0000362 ExecutionContext exe_ctx (exe_scope);
363 Target *target = exe_ctx.GetTargetPtr();
Greg Claytondda4f7b2010-06-30 23:03:03 +0000364 // If addr_byte_size is UINT32_MAX, then determine the correct address
365 // byte size for the process or default to the size of addr_t
366 if (addr_size == UINT32_MAX)
367 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000368 if (target)
Greg Clayton514487e2011-02-15 21:59:32 +0000369 addr_size = target->GetArchitecture().GetAddressByteSize ();
Greg Claytondda4f7b2010-06-30 23:03:03 +0000370 else
371 addr_size = sizeof(addr_t);
372 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373
Greg Claytonc9800662010-09-10 01:30:46 +0000374 Address so_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375 switch (style)
376 {
Greg Claytonc982c762010-07-09 20:39:50 +0000377 case DumpStyleInvalid:
378 return false;
379
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380 case DumpStyleSectionNameOffset:
Greg Claytone72dfb32012-02-24 01:59:29 +0000381 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000382 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000383 section_sp->DumpName(s);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384 s->Printf (" + %llu", m_offset);
385 }
386 else
387 {
Greg Claytondda4f7b2010-06-30 23:03:03 +0000388 s->Address(m_offset, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000389 }
390 break;
391
392 case DumpStyleSectionPointerOffset:
Greg Claytone72dfb32012-02-24 01:59:29 +0000393 s->Printf("(Section *)%p + ", section_sp.get());
Greg Claytondda4f7b2010-06-30 23:03:03 +0000394 s->Address(m_offset, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000395 break;
396
397 case DumpStyleModuleWithFileAddress:
Greg Claytone72dfb32012-02-24 01:59:29 +0000398 if (section_sp)
399 s->Printf("%s[", section_sp->GetModule()->GetFileSpec().GetFilename().AsCString());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400 // Fall through
401 case DumpStyleFileAddress:
402 {
403 addr_t file_addr = GetFileAddress();
404 if (file_addr == LLDB_INVALID_ADDRESS)
405 {
406 if (fallback_style != DumpStyleInvalid)
Greg Claytondda4f7b2010-06-30 23:03:03 +0000407 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408 return false;
409 }
410 s->Address (file_addr, addr_size);
Greg Claytone72dfb32012-02-24 01:59:29 +0000411 if (style == DumpStyleModuleWithFileAddress && section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412 s->PutChar(']');
413 }
414 break;
415
416 case DumpStyleLoadAddress:
417 {
Greg Claytonf5e56de2010-09-14 23:36:40 +0000418 addr_t load_addr = GetLoadAddress (target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000419 if (load_addr == LLDB_INVALID_ADDRESS)
420 {
421 if (fallback_style != DumpStyleInvalid)
Greg Claytondda4f7b2010-06-30 23:03:03 +0000422 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423 return false;
424 }
425 s->Address (load_addr, addr_size);
426 }
427 break;
428
429 case DumpStyleResolvedDescription:
Greg Clayton54b8b8c2010-07-01 01:26:43 +0000430 case DumpStyleResolvedDescriptionNoModule:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000431 if (IsSectionOffset())
432 {
Greg Claytone0d378b2011-03-24 21:19:54 +0000433 AddressType addr_type = eAddressTypeLoad;
Greg Claytonf5e56de2010-09-14 23:36:40 +0000434 addr_t addr = GetLoadAddress (target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435 if (addr == LLDB_INVALID_ADDRESS)
436 {
437 addr = GetFileAddress();
438 addr_type = eAddressTypeFile;
439 }
440
441 uint32_t pointer_size = 4;
Greg Claytone72dfb32012-02-24 01:59:29 +0000442 ModuleSP module_sp (GetModule());
Greg Clayton514487e2011-02-15 21:59:32 +0000443 if (target)
444 pointer_size = target->GetArchitecture().GetAddressByteSize();
Greg Claytone72dfb32012-02-24 01:59:29 +0000445 else if (module_sp)
446 pointer_size = module_sp->GetArchitecture().GetAddressByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000447
448 bool showed_info = false;
Greg Claytone72dfb32012-02-24 01:59:29 +0000449 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000451 SectionType sect_type = section_sp->GetType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452 switch (sect_type)
453 {
Greg Clayton89411422010-10-08 00:21:05 +0000454 case eSectionTypeData:
Greg Claytone72dfb32012-02-24 01:59:29 +0000455 if (module_sp)
Greg Clayton89411422010-10-08 00:21:05 +0000456 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000457 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton89411422010-10-08 00:21:05 +0000458 if (objfile)
459 {
460 Symtab *symtab = objfile->GetSymtab();
461 if (symtab)
462 {
463 const addr_t file_Addr = GetFileAddress();
464 Symbol *symbol = symtab->FindSymbolContainingFileAddress (file_Addr);
465 if (symbol)
466 {
467 const char *symbol_name = symbol->GetName().AsCString();
468 if (symbol_name)
469 {
470 s->PutCString(symbol_name);
Greg Claytone7612132012-03-07 21:03:09 +0000471 addr_t delta = file_Addr - symbol->GetAddress().GetFileAddress();
Greg Clayton89411422010-10-08 00:21:05 +0000472 if (delta)
473 s->Printf(" + %llu", delta);
474 showed_info = true;
475 }
476 }
477 }
478 }
479 }
480 break;
481
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000482 case eSectionTypeDataCString:
483 // Read the C string from memory and display it
484 showed_info = true;
485 ReadCStringFromMemory (exe_scope, *this, s);
486 break;
487
488 case eSectionTypeDataCStringPointers:
489 {
490 if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
491 {
492#if VERBOSE_OUTPUT
493 s->PutCString("(char *)");
494 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
495 s->PutCString(": ");
496#endif
497 showed_info = true;
498 ReadCStringFromMemory (exe_scope, so_addr, s);
499 }
500 }
501 break;
502
503 case eSectionTypeDataObjCMessageRefs:
504 {
505 if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
506 {
Greg Clayton54b8b8c2010-07-01 01:26:43 +0000507 if (target && so_addr.IsSectionOffset())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000508 {
Greg Claytonc9800662010-09-10 01:30:46 +0000509 SymbolContext func_sc;
Greg Clayton54b8b8c2010-07-01 01:26:43 +0000510 target->GetImages().ResolveSymbolContextForAddress (so_addr,
Greg Claytond9e416c2012-02-18 05:35:26 +0000511 eSymbolContextEverything,
512 func_sc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000513 if (func_sc.function || func_sc.symbol)
514 {
515 showed_info = true;
516#if VERBOSE_OUTPUT
517 s->PutCString ("(objc_msgref *) -> { (func*)");
518 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
519#else
520 s->PutCString ("{ ");
521#endif
522 Address cstr_addr(*this);
523 cstr_addr.SetOffset(cstr_addr.GetOffset() + pointer_size);
Greg Clayton6dadd502010-09-02 21:44:10 +0000524 func_sc.DumpStopContext(s, exe_scope, so_addr, true, true, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000525 if (ReadAddress (exe_scope, cstr_addr, pointer_size, so_addr))
526 {
527#if VERBOSE_OUTPUT
528 s->PutCString("), (char *)");
529 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
530 s->PutCString(" (");
531#else
532 s->PutCString(", ");
533#endif
534 ReadCStringFromMemory (exe_scope, so_addr, s);
535 }
536#if VERBOSE_OUTPUT
537 s->PutCString(") }");
538#else
539 s->PutCString(" }");
540#endif
541 }
542 }
543 }
544 }
545 break;
546
547 case eSectionTypeDataObjCCFStrings:
548 {
549 Address cfstring_data_addr(*this);
550 cfstring_data_addr.SetOffset(cfstring_data_addr.GetOffset() + (2 * pointer_size));
551 if (ReadAddress (exe_scope, cfstring_data_addr, pointer_size, so_addr))
552 {
553#if VERBOSE_OUTPUT
554 s->PutCString("(CFString *) ");
555 cfstring_data_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
556 s->PutCString(" -> @");
557#else
558 s->PutChar('@');
559#endif
560 if (so_addr.Dump(s, exe_scope, DumpStyleResolvedDescription))
561 showed_info = true;
562 }
563 }
564 break;
565
566 case eSectionTypeData4:
567 // Read the 4 byte data and display it
568 showed_info = true;
569 s->PutCString("(uint32_t) ");
570 DumpUInt (exe_scope, *this, 4, s);
571 break;
572
573 case eSectionTypeData8:
574 // Read the 8 byte data and display it
575 showed_info = true;
576 s->PutCString("(uint64_t) ");
577 DumpUInt (exe_scope, *this, 8, s);
578 break;
579
580 case eSectionTypeData16:
581 // Read the 16 byte data and display it
582 showed_info = true;
583 s->PutCString("(uint128_t) ");
584 DumpUInt (exe_scope, *this, 16, s);
585 break;
586
587 case eSectionTypeDataPointers:
588 // Read the pointer data and display it
589 {
590 if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
591 {
592 s->PutCString ("(void *)");
593 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
594
595 showed_info = true;
596 if (so_addr.IsSectionOffset())
597 {
Greg Claytonc9800662010-09-10 01:30:46 +0000598 SymbolContext pointer_sc;
Greg Claytondda4f7b2010-06-30 23:03:03 +0000599 if (target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000600 {
Greg Claytondda4f7b2010-06-30 23:03:03 +0000601 target->GetImages().ResolveSymbolContextForAddress (so_addr,
Greg Claytond9e416c2012-02-18 05:35:26 +0000602 eSymbolContextEverything,
603 pointer_sc);
Greg Claytondda4f7b2010-06-30 23:03:03 +0000604 if (pointer_sc.function || pointer_sc.symbol)
605 {
606 s->PutCString(": ");
Greg Clayton6dadd502010-09-02 21:44:10 +0000607 pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, false);
Greg Claytondda4f7b2010-06-30 23:03:03 +0000608 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000609 }
610 }
611 }
612 }
613 break;
Greg Claytonc982c762010-07-09 20:39:50 +0000614
615 default:
616 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000617 }
618 }
619
620 if (!showed_info)
621 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000622 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000623 {
Greg Claytonc9800662010-09-10 01:30:46 +0000624 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000625 module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000626 if (sc.function || sc.symbol)
627 {
628 bool show_stop_context = true;
Greg Clayton8dc0a982010-09-07 21:56:53 +0000629 const bool show_module = (style == DumpStyleResolvedDescription);
630 const bool show_fullpaths = false;
Greg Clayton513c26c2011-01-29 07:10:55 +0000631 const bool show_inlined_frames = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000632 if (sc.function == NULL && sc.symbol != NULL)
633 {
634 // If we have just a symbol make sure it is in the right section
Greg Claytone7612132012-03-07 21:03:09 +0000635 if (sc.symbol->ValueIsAddress())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000636 {
Greg Claytone7612132012-03-07 21:03:09 +0000637 if (sc.symbol->GetAddress().GetSection() != GetSection())
Greg Clayton54b8b8c2010-07-01 01:26:43 +0000638 {
639 // don't show the module if the symbol is a trampoline symbol
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000640 show_stop_context = false;
Greg Clayton54b8b8c2010-07-01 01:26:43 +0000641 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000642 }
643 }
644 if (show_stop_context)
645 {
646 // We have a function or a symbol from the same
647 // sections as this address.
Greg Clayton8dc0a982010-09-07 21:56:53 +0000648 sc.DumpStopContext (s,
649 exe_scope,
650 *this,
651 show_fullpaths,
652 show_module,
653 show_inlined_frames);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000654 }
655 else
656 {
657 // We found a symbol but it was in a different
658 // section so it isn't the symbol we should be
659 // showing, just show the section name + offset
660 Dump (s, exe_scope, DumpStyleSectionNameOffset);
661 }
662 }
663 }
664 }
665 }
666 else
667 {
668 if (fallback_style != DumpStyleInvalid)
Greg Claytondda4f7b2010-06-30 23:03:03 +0000669 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000670 return false;
671 }
672 break;
Greg Claytondda4f7b2010-06-30 23:03:03 +0000673
674 case DumpStyleDetailedSymbolContext:
675 if (IsSectionOffset())
676 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000677 ModuleSP module_sp (GetModule());
678 if (module_sp)
Greg Claytondda4f7b2010-06-30 23:03:03 +0000679 {
Greg Claytonc9800662010-09-10 01:30:46 +0000680 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000681 module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc);
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000682 if (sc.symbol)
Greg Claytondda4f7b2010-06-30 23:03:03 +0000683 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000684 // If we have just a symbol make sure it is in the same section
685 // as our address. If it isn't, then we might have just found
686 // the last symbol that came before the address that we are
687 // looking up that has nothing to do with our address lookup.
Greg Claytone7612132012-03-07 21:03:09 +0000688 if (sc.symbol->ValueIsAddress() && sc.symbol->GetAddress().GetSection() != GetSection())
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000689 sc.symbol = NULL;
Greg Claytondda4f7b2010-06-30 23:03:03 +0000690 }
Greg Claytonf5e56de2010-09-14 23:36:40 +0000691 sc.GetDescription(s, eDescriptionLevelBrief, target);
Greg Claytonc749eb82011-07-11 05:12:02 +0000692
693 if (sc.block)
694 {
695 bool can_create = true;
696 bool get_parent_variables = true;
697 bool stop_if_block_is_inlined_function = false;
698 VariableList variable_list;
699 sc.block->AppendVariables (can_create,
700 get_parent_variables,
701 stop_if_block_is_inlined_function,
702 &variable_list);
703
704 uint32_t num_variables = variable_list.GetSize();
705 for (uint32_t var_idx = 0; var_idx < num_variables; ++var_idx)
706 {
707 Variable *var = variable_list.GetVariableAtIndex (var_idx).get();
708 if (var && var->LocationIsValidForAddress (*this))
709 {
Greg Clayton81c22f62011-10-19 18:09:39 +0000710 s->Printf (" Variable: id = {0x%8.8llx}, name = \"%s\", type= \"%s\", location =",
Greg Claytonc749eb82011-07-11 05:12:02 +0000711 var->GetID(),
712 var->GetName().GetCString(),
713 var->GetType()->GetName().GetCString());
714 var->DumpLocationForAddress(s, *this);
715 s->PutCString(", decl = ");
716 var->GetDeclaration().DumpStopContext(s, false);
717 s->EOL();
718 }
719 }
720 }
Greg Claytondda4f7b2010-06-30 23:03:03 +0000721 }
722 }
Greg Claytonc749eb82011-07-11 05:12:02 +0000723 else
724 {
725 if (fallback_style != DumpStyleInvalid)
726 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
727 return false;
728 }
Greg Claytondda4f7b2010-06-30 23:03:03 +0000729 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000730 }
731
732 return true;
733}
734
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000735uint32_t
Greg Clayton6f6bf262011-12-10 21:05:26 +0000736Address::CalculateSymbolContext (SymbolContext *sc, uint32_t resolve_scope) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000737{
738 sc->Clear();
739 // Absolute addresses don't have enough information to reconstruct even their target.
Greg Claytone72dfb32012-02-24 01:59:29 +0000740
741 SectionSP section_sp (GetSection());
742 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000743 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000744 ModuleSP module_sp (section_sp->GetModule());
745 if (module_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000746 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000747 sc->module_sp = module_sp;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000748 if (sc->module_sp)
749 return sc->module_sp->ResolveSymbolContextForAddress (*this, resolve_scope, *sc);
750 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000751 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000752 return 0;
753}
754
Greg Claytone72dfb32012-02-24 01:59:29 +0000755ModuleSP
Greg Clayton6f6bf262011-12-10 21:05:26 +0000756Address::CalculateSymbolContextModule () const
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000757{
Greg Claytone72dfb32012-02-24 01:59:29 +0000758 SectionSP section_sp (GetSection());
759 if (section_sp)
760 return section_sp->GetModule();
761 return ModuleSP();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000762}
763
764CompileUnit *
Greg Clayton6f6bf262011-12-10 21:05:26 +0000765Address::CalculateSymbolContextCompileUnit () const
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000766{
Greg Claytone72dfb32012-02-24 01:59:29 +0000767 SectionSP section_sp (GetSection());
768 if (section_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000769 {
770 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000771 sc.module_sp = section_sp->GetModule();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000772 if (sc.module_sp)
773 {
774 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextCompUnit, sc);
775 return sc.comp_unit;
776 }
777 }
778 return NULL;
779}
780
781Function *
Greg Clayton6f6bf262011-12-10 21:05:26 +0000782Address::CalculateSymbolContextFunction () const
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000783{
Greg Claytone72dfb32012-02-24 01:59:29 +0000784 SectionSP section_sp (GetSection());
785 if (section_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000786 {
787 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000788 sc.module_sp = section_sp->GetModule();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000789 if (sc.module_sp)
790 {
791 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextFunction, sc);
792 return sc.function;
793 }
794 }
795 return NULL;
796}
797
798Block *
Greg Clayton6f6bf262011-12-10 21:05:26 +0000799Address::CalculateSymbolContextBlock () const
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000800{
Greg Claytone72dfb32012-02-24 01:59:29 +0000801 SectionSP section_sp (GetSection());
802 if (section_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000803 {
804 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000805 sc.module_sp = section_sp->GetModule();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000806 if (sc.module_sp)
807 {
808 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextBlock, sc);
809 return sc.block;
810 }
811 }
812 return NULL;
813}
814
815Symbol *
Greg Clayton6f6bf262011-12-10 21:05:26 +0000816Address::CalculateSymbolContextSymbol () const
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000817{
Greg Claytone72dfb32012-02-24 01:59:29 +0000818 SectionSP section_sp (GetSection());
819 if (section_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000820 {
821 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000822 sc.module_sp = section_sp->GetModule();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000823 if (sc.module_sp)
824 {
825 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextSymbol, sc);
826 return sc.symbol;
827 }
828 }
829 return NULL;
830}
831
832bool
Greg Clayton6f6bf262011-12-10 21:05:26 +0000833Address::CalculateSymbolContextLineEntry (LineEntry &line_entry) const
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000834{
Greg Claytone72dfb32012-02-24 01:59:29 +0000835 SectionSP section_sp (GetSection());
836 if (section_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000837 {
838 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000839 sc.module_sp = section_sp->GetModule();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000840 if (sc.module_sp)
841 {
842 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextLineEntry, sc);
843 if (sc.line_entry.IsValid())
844 {
845 line_entry = sc.line_entry;
846 return true;
847 }
848 }
849 }
850 line_entry.Clear();
851 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000852}
853
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854int
855Address::CompareFileAddress (const Address& a, const Address& b)
856{
857 addr_t a_file_addr = a.GetFileAddress();
858 addr_t b_file_addr = b.GetFileAddress();
859 if (a_file_addr < b_file_addr)
860 return -1;
861 if (a_file_addr > b_file_addr)
862 return +1;
863 return 0;
864}
865
866
867int
Greg Claytonf5e56de2010-09-14 23:36:40 +0000868Address::CompareLoadAddress (const Address& a, const Address& b, Target *target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000869{
Greg Claytonf5e56de2010-09-14 23:36:40 +0000870 assert (target != NULL);
871 addr_t a_load_addr = a.GetLoadAddress (target);
872 addr_t b_load_addr = b.GetLoadAddress (target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000873 if (a_load_addr < b_load_addr)
874 return -1;
875 if (a_load_addr > b_load_addr)
876 return +1;
877 return 0;
878}
879
880int
881Address::CompareModulePointerAndOffset (const Address& a, const Address& b)
882{
Greg Claytone72dfb32012-02-24 01:59:29 +0000883 ModuleSP a_module_sp (a.GetModule());
884 ModuleSP b_module_sp (b.GetModule());
885 Module *a_module = a_module_sp.get();
886 Module *b_module = b_module_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000887 if (a_module < b_module)
888 return -1;
889 if (a_module > b_module)
890 return +1;
891 // Modules are the same, just compare the file address since they should
892 // be unique
893 addr_t a_file_addr = a.GetFileAddress();
894 addr_t b_file_addr = b.GetFileAddress();
895 if (a_file_addr < b_file_addr)
896 return -1;
897 if (a_file_addr > b_file_addr)
898 return +1;
899 return 0;
900}
901
902
903size_t
904Address::MemorySize () const
905{
906 // Noting special for the memory size of a single Address object,
907 // it is just the size of itself.
908 return sizeof(Address);
909}
910
911
Greg Claytonb0848c52011-01-08 00:05:12 +0000912//----------------------------------------------------------------------
913// NOTE: Be careful using this operator. It can correctly compare two
914// addresses from the same Module correctly. It can't compare two
915// addresses from different modules in any meaningful way, but it will
916// compare the module pointers.
917//
918// To sum things up:
919// - works great for addresses within the same module
920// - it works for addresses across multiple modules, but don't expect the
921// address results to make much sense
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000922//
Greg Claytonb0848c52011-01-08 00:05:12 +0000923// This basically lets Address objects be used in ordered collection
924// classes.
925//----------------------------------------------------------------------
926
927bool
928lldb_private::operator< (const Address& lhs, const Address& rhs)
929{
Greg Claytone72dfb32012-02-24 01:59:29 +0000930 ModuleSP lhs_module_sp (lhs.GetModule());
931 ModuleSP rhs_module_sp (rhs.GetModule());
932 Module *lhs_module = lhs_module_sp.get();
933 Module *rhs_module = rhs_module_sp.get();
Greg Claytonb0848c52011-01-08 00:05:12 +0000934 if (lhs_module == rhs_module)
935 {
936 // Addresses are in the same module, just compare the file addresses
937 return lhs.GetFileAddress() < rhs.GetFileAddress();
938 }
939 else
940 {
941 // The addresses are from different modules, just use the module
942 // pointer value to get consistent ordering
943 return lhs_module < rhs_module;
944 }
945}
946
947bool
948lldb_private::operator> (const Address& lhs, const Address& rhs)
949{
Greg Claytone72dfb32012-02-24 01:59:29 +0000950 ModuleSP lhs_module_sp (lhs.GetModule());
951 ModuleSP rhs_module_sp (rhs.GetModule());
952 Module *lhs_module = lhs_module_sp.get();
953 Module *rhs_module = rhs_module_sp.get();
Greg Claytonb0848c52011-01-08 00:05:12 +0000954 if (lhs_module == rhs_module)
955 {
956 // Addresses are in the same module, just compare the file addresses
957 return lhs.GetFileAddress() > rhs.GetFileAddress();
958 }
959 else
960 {
961 // The addresses are from different modules, just use the module
962 // pointer value to get consistent ordering
963 return lhs_module > rhs_module;
964 }
965}
966
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000967
968// The operator == checks for exact equality only (same section, same offset)
969bool
970lldb_private::operator== (const Address& a, const Address& rhs)
971{
972 return a.GetSection() == rhs.GetSection() &&
973 a.GetOffset() == rhs.GetOffset();
974}
975// The operator != checks for exact inequality only (differing section, or
976// different offset)
977bool
978lldb_private::operator!= (const Address& a, const Address& rhs)
979{
980 return a.GetSection() != rhs.GetSection() ||
981 a.GetOffset() != rhs.GetOffset();
982}
983
984bool
985Address::IsLinkedAddress () const
986{
Greg Claytone72dfb32012-02-24 01:59:29 +0000987 SectionSP section_sp (GetSection());
988 return section_sp && section_sp->GetLinkedSection();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000989}
990
991
992void
993Address::ResolveLinkedAddress ()
994{
Greg Claytone72dfb32012-02-24 01:59:29 +0000995 SectionSP section_sp (GetSection());
996 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000997 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000998 SectionSP linked_section_sp (section_sp->GetLinkedSection());
999 if (linked_section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001000 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001001 m_offset += section_sp->GetLinkedOffset();
1002 m_section_wp = linked_section_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001003 }
1004 }
1005}
Greg Claytonded470d2011-03-19 01:12:21 +00001006
Greg Claytone0d378b2011-03-24 21:19:54 +00001007AddressClass
Greg Claytonded470d2011-03-19 01:12:21 +00001008Address::GetAddressClass () const
1009{
Greg Claytone72dfb32012-02-24 01:59:29 +00001010 ModuleSP module_sp (GetModule());
1011 if (module_sp)
Greg Claytonded470d2011-03-19 01:12:21 +00001012 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001013 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Claytonded470d2011-03-19 01:12:21 +00001014 if (obj_file)
1015 return obj_file->GetAddressClass (GetFileAddress());
1016 }
1017 return eAddressClassUnknown;
1018}
Greg Claytoncd482e32011-05-18 01:58:14 +00001019
1020bool
1021Address::SetLoadAddress (lldb::addr_t load_addr, Target *target)
1022{
1023 if (target && target->GetSectionLoadList().ResolveLoadAddress(load_addr, *this))
1024 return true;
Greg Claytone72dfb32012-02-24 01:59:29 +00001025 m_section_wp.reset();
Greg Claytoncd482e32011-05-18 01:58:14 +00001026 m_offset = load_addr;
1027 return false;
1028}
1029