blob: 9d4d8706c5a061dcb7b438a0532b026886b9c6c2 [file] [log] [blame]
Chris Lattner24943d22010-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"
Greg Clayton49ce8962012-08-29 21:13:06 +000013#include "lldb/Symbol/Block.h"
Chris Lattner24943d22010-06-08 16:52:24 +000014#include "lldb/Symbol/ObjectFile.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000015#include "lldb/Symbol/Type.h"
Greg Clayton9b82f862011-07-11 05:12:02 +000016#include "lldb/Symbol/Variable.h"
17#include "lldb/Symbol/VariableList.h"
Greg Claytoneea26402010-09-14 23:36:40 +000018#include "lldb/Target/ExecutionContext.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019#include "lldb/Target/Process.h"
20#include "lldb/Target/Target.h"
21
Greg Claytonda7af842011-05-18 22:01:49 +000022#include "llvm/ADT/Triple.h"
23
Chris Lattner24943d22010-06-08 16:52:24 +000024using namespace lldb;
25using namespace lldb_private;
26
27static size_t
28ReadBytes (ExecutionContextScope *exe_scope, const Address &address, void *dst, size_t dst_len)
29{
30 if (exe_scope == NULL)
31 return 0;
32
Greg Clayton289afcb2012-02-18 05:35:26 +000033 TargetSP target_sp (exe_scope->CalculateTarget());
34 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000035 {
36 Error error;
Greg Clayton26100dc2011-01-07 01:57:07 +000037 bool prefer_file_cache = false;
Greg Clayton289afcb2012-02-18 05:35:26 +000038 return target_sp->ReadMemory (address, prefer_file_cache, dst, dst_len, error);
Chris Lattner24943d22010-06-08 16:52:24 +000039 }
40 return 0;
41}
42
43static bool
44GetByteOrderAndAddressSize (ExecutionContextScope *exe_scope, const Address &address, ByteOrder& byte_order, uint32_t& addr_size)
45{
46 byte_order = eByteOrderInvalid;
47 addr_size = 0;
48 if (exe_scope == NULL)
49 return false;
50
Greg Clayton289afcb2012-02-18 05:35:26 +000051 TargetSP target_sp (exe_scope->CalculateTarget());
52 if (target_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000053 {
Greg Clayton289afcb2012-02-18 05:35:26 +000054 byte_order = target_sp->GetArchitecture().GetByteOrder();
55 addr_size = target_sp->GetArchitecture().GetAddressByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +000056 }
57
58 if (byte_order == eByteOrderInvalid || addr_size == 0)
59 {
Greg Clayton3508c382012-02-24 01:59:29 +000060 ModuleSP module_sp (address.GetModule());
61 if (module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000062 {
Greg Clayton3508c382012-02-24 01:59:29 +000063 byte_order = module_sp->GetArchitecture().GetByteOrder();
64 addr_size = module_sp->GetArchitecture().GetAddressByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +000065 }
66 }
67 return byte_order != eByteOrderInvalid && addr_size != 0;
68}
69
70static uint64_t
71ReadUIntMax64 (ExecutionContextScope *exe_scope, const Address &address, uint32_t byte_size, bool &success)
72{
73 uint64_t uval64 = 0;
74 if (exe_scope == NULL || byte_size > sizeof(uint64_t))
75 {
76 success = false;
77 return 0;
78 }
Johnny Chen451d02b2011-08-25 17:40:39 +000079 uint64_t buf = 0;
Chris Lattner24943d22010-06-08 16:52:24 +000080
81 success = ReadBytes (exe_scope, address, &buf, byte_size) == byte_size;
82 if (success)
83 {
84 ByteOrder byte_order = eByteOrderInvalid;
85 uint32_t addr_size = 0;
86 if (GetByteOrderAndAddressSize (exe_scope, address, byte_order, addr_size))
87 {
88 DataExtractor data (&buf, sizeof(buf), byte_order, addr_size);
89 uint32_t offset = 0;
90 uval64 = data.GetU64(&offset);
91 }
92 else
93 success = false;
94 }
95 return uval64;
96}
97
98static bool
99ReadAddress (ExecutionContextScope *exe_scope, const Address &address, uint32_t pointer_size, Address &deref_so_addr)
100{
101 if (exe_scope == NULL)
102 return false;
103
104
105 bool success = false;
106 addr_t deref_addr = ReadUIntMax64 (exe_scope, address, pointer_size, success);
107 if (success)
108 {
Greg Claytoneea26402010-09-14 23:36:40 +0000109 ExecutionContext exe_ctx;
Greg Claytona830adb2010-10-04 01:05:56 +0000110 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Claytoneea26402010-09-14 23:36:40 +0000111 // If we have any sections that are loaded, try and resolve using the
112 // section load list
Greg Clayton567e7f32011-09-22 04:58:26 +0000113 Target *target = exe_ctx.GetTargetPtr();
114 if (target && !target->GetSectionLoadList().IsEmpty())
Chris Lattner24943d22010-06-08 16:52:24 +0000115 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000116 if (target->GetSectionLoadList().ResolveLoadAddress (deref_addr, deref_so_addr))
Greg Claytoneea26402010-09-14 23:36:40 +0000117 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000118 }
119 else
120 {
Greg Claytoneea26402010-09-14 23:36:40 +0000121 // If we were not running, yet able to read an integer, we must
122 // have a module
Greg Clayton3508c382012-02-24 01:59:29 +0000123 ModuleSP module_sp (address.GetModule());
124
125 assert (module_sp);
126 if (module_sp->ResolveFileAddress(deref_addr, deref_so_addr))
Greg Claytoneea26402010-09-14 23:36:40 +0000127 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000128 }
Greg Claytoneea26402010-09-14 23:36:40 +0000129
130 // We couldn't make "deref_addr" into a section offset value, but we were
131 // able to read the address, so we return a section offset address with
132 // no section and "deref_addr" as the offset (address).
Greg Clayton3508c382012-02-24 01:59:29 +0000133 deref_so_addr.SetRawAddress(deref_addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000134 return true;
135 }
136 return false;
137}
138
139static bool
140DumpUInt (ExecutionContextScope *exe_scope, const Address &address, uint32_t byte_size, Stream* strm)
141{
Greg Clayton53d68e72010-07-20 22:52:08 +0000142 if (exe_scope == NULL || byte_size == 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000143 return 0;
144 std::vector<uint8_t> buf(byte_size, 0);
145
146 if (ReadBytes (exe_scope, address, &buf[0], buf.size()) == buf.size())
147 {
148 ByteOrder byte_order = eByteOrderInvalid;
149 uint32_t addr_size = 0;
150 if (GetByteOrderAndAddressSize (exe_scope, address, byte_order, addr_size))
151 {
Greg Clayton53d68e72010-07-20 22:52:08 +0000152 DataExtractor data (&buf.front(), buf.size(), byte_order, addr_size);
Chris Lattner24943d22010-06-08 16:52:24 +0000153
154 data.Dump (strm,
155 0, // Start offset in "data"
156 eFormatHex, // Print as characters
157 buf.size(), // Size of item
158 1, // Items count
159 UINT32_MAX, // num per line
160 LLDB_INVALID_ADDRESS,// base address
161 0, // bitfield bit size
162 0); // bitfield bit offset
163
164 return true;
165 }
166 }
167 return false;
168}
169
170
171static size_t
172ReadCStringFromMemory (ExecutionContextScope *exe_scope, const Address &address, Stream *strm)
173{
174 if (exe_scope == NULL)
175 return 0;
176 const size_t k_buf_len = 256;
177 char buf[k_buf_len+1];
178 buf[k_buf_len] = '\0'; // NULL terminate
179
Greg Clayton5d187e52011-01-08 20:28:42 +0000180 // Byte order and address size don't matter for C string dumping..
Greg Claytoncd548032011-02-01 01:31:41 +0000181 DataExtractor data (buf, sizeof(buf), lldb::endian::InlHostByteOrder(), 4);
Chris Lattner24943d22010-06-08 16:52:24 +0000182 size_t total_len = 0;
183 size_t bytes_read;
184 Address curr_address(address);
185 strm->PutChar ('"');
186 while ((bytes_read = ReadBytes (exe_scope, curr_address, buf, k_buf_len)) > 0)
187 {
188 size_t len = strlen(buf);
189 if (len == 0)
190 break;
191 if (len > bytes_read)
192 len = bytes_read;
193
194 data.Dump (strm,
195 0, // Start offset in "data"
196 eFormatChar, // Print as characters
197 1, // Size of item (1 byte for a char!)
198 len, // How many bytes to print?
199 UINT32_MAX, // num per line
200 LLDB_INVALID_ADDRESS,// base address
201 0, // bitfield bit size
202
203 0); // bitfield bit offset
204
205 total_len += bytes_read;
206
207 if (len < k_buf_len)
208 break;
209 curr_address.SetOffset (curr_address.GetOffset() + bytes_read);
210 }
211 strm->PutChar ('"');
212 return total_len;
213}
214
Greg Clayton3508c382012-02-24 01:59:29 +0000215Address::Address (lldb::addr_t abs_addr) :
216 m_section_wp (),
217 m_offset (abs_addr)
218{
219}
220
221Address::Address (addr_t address, const SectionList *section_list) :
222 m_section_wp (),
Chris Lattner24943d22010-06-08 16:52:24 +0000223 m_offset (LLDB_INVALID_ADDRESS)
224{
Greg Clayton3508c382012-02-24 01:59:29 +0000225 ResolveAddressUsingFileSections(address, section_list);
Chris Lattner24943d22010-06-08 16:52:24 +0000226}
227
Chris Lattner24943d22010-06-08 16:52:24 +0000228const Address&
229Address::operator= (const Address& rhs)
230{
231 if (this != &rhs)
232 {
Greg Clayton3508c382012-02-24 01:59:29 +0000233 m_section_wp = rhs.m_section_wp;
Chris Lattner24943d22010-06-08 16:52:24 +0000234 m_offset = rhs.m_offset;
235 }
236 return *this;
237}
238
239bool
Greg Clayton3508c382012-02-24 01:59:29 +0000240Address::ResolveAddressUsingFileSections (addr_t file_addr, const SectionList *section_list)
Chris Lattner24943d22010-06-08 16:52:24 +0000241{
Greg Clayton3508c382012-02-24 01:59:29 +0000242 if (section_list)
Chris Lattner24943d22010-06-08 16:52:24 +0000243 {
Greg Clayton3508c382012-02-24 01:59:29 +0000244 SectionSP section_sp (section_list->FindSectionContainingFileAddress(file_addr));
245 m_section_wp = section_sp;
246 if (section_sp)
247 {
248 assert( section_sp->ContainsFileAddress(file_addr) );
249 m_offset = file_addr - section_sp->GetFileAddress();
250 return true; // Successfully transformed addr into a section offset address
251 }
Chris Lattner24943d22010-06-08 16:52:24 +0000252 }
Greg Clayton3508c382012-02-24 01:59:29 +0000253 m_offset = file_addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000254 return false; // Failed to resolve this address to a section offset value
255}
256
Greg Clayton13d24fb2012-01-29 20:56:30 +0000257ModuleSP
Greg Clayton3508c382012-02-24 01:59:29 +0000258Address::GetModule () const
Greg Clayton13d24fb2012-01-29 20:56:30 +0000259{
260 lldb::ModuleSP module_sp;
Greg Clayton3508c382012-02-24 01:59:29 +0000261 SectionSP section_sp (GetSection());
262 if (section_sp)
263 module_sp = section_sp->GetModule();
Greg Clayton13d24fb2012-01-29 20:56:30 +0000264 return module_sp;
265}
266
Chris Lattner24943d22010-06-08 16:52:24 +0000267addr_t
268Address::GetFileAddress () const
269{
Greg Clayton3508c382012-02-24 01:59:29 +0000270 SectionSP section_sp (GetSection());
271 if (section_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000272 {
Greg Clayton3508c382012-02-24 01:59:29 +0000273 addr_t sect_file_addr = section_sp->GetFileAddress();
Chris Lattner24943d22010-06-08 16:52:24 +0000274 if (sect_file_addr == LLDB_INVALID_ADDRESS)
275 {
276 // Section isn't resolved, we can't return a valid file address
277 return LLDB_INVALID_ADDRESS;
278 }
279 // We have a valid file range, so we can return the file based
280 // address by adding the file base address to our offset
281 return sect_file_addr + m_offset;
282 }
283 // No section, we just return the offset since it is the value in this case
284 return m_offset;
285}
286
287addr_t
Greg Claytoneea26402010-09-14 23:36:40 +0000288Address::GetLoadAddress (Target *target) const
Chris Lattner24943d22010-06-08 16:52:24 +0000289{
Greg Clayton3508c382012-02-24 01:59:29 +0000290 SectionSP section_sp (GetSection());
291 if (!section_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000292 {
Greg Claytoneea26402010-09-14 23:36:40 +0000293 // No section, we just return the offset since it is the value in this case
294 return m_offset;
Chris Lattner24943d22010-06-08 16:52:24 +0000295 }
Greg Claytoneea26402010-09-14 23:36:40 +0000296
297 if (target)
298 {
Greg Clayton3508c382012-02-24 01:59:29 +0000299 addr_t sect_load_addr = section_sp->GetLoadBaseAddress (target);
Greg Claytoneea26402010-09-14 23:36:40 +0000300
301 if (sect_load_addr != LLDB_INVALID_ADDRESS)
302 {
303 // We have a valid file range, so we can return the file based
304 // address by adding the file base address to our offset
305 return sect_load_addr + m_offset;
306 }
307 }
308 // The section isn't resolved or no process was supplied so we can't
309 // return a valid file address.
310 return LLDB_INVALID_ADDRESS;
Chris Lattner24943d22010-06-08 16:52:24 +0000311}
312
Greg Claytonda7af842011-05-18 22:01:49 +0000313addr_t
314Address::GetCallableLoadAddress (Target *target) const
315{
316 addr_t code_addr = GetLoadAddress (target);
Greg Claytonc0fa5332011-05-22 22:46:53 +0000317
318 if (target)
319 return target->GetCallableLoadAddress (code_addr, GetAddressClass());
Greg Claytonda7af842011-05-18 22:01:49 +0000320 return code_addr;
321}
322
Greg Clayton5a269102011-05-22 04:32:55 +0000323bool
324Address::SetCallableLoadAddress (lldb::addr_t load_addr, Target *target)
325{
326 if (SetLoadAddress (load_addr, target))
327 {
Greg Claytonc0fa5332011-05-22 22:46:53 +0000328 if (target)
329 m_offset = target->GetCallableLoadAddress(m_offset, GetAddressClass());
Greg Clayton5a269102011-05-22 04:32:55 +0000330 return true;
331 }
332 return false;
333}
334
Greg Clayton265ab332011-05-19 18:17:41 +0000335addr_t
336Address::GetOpcodeLoadAddress (Target *target) const
337{
338 addr_t code_addr = GetLoadAddress (target);
Greg Clayton265ab332011-05-19 18:17:41 +0000339 if (code_addr != LLDB_INVALID_ADDRESS)
Greg Claytonc0fa5332011-05-22 22:46:53 +0000340 code_addr = target->GetOpcodeLoadAddress (code_addr, GetAddressClass());
Greg Clayton265ab332011-05-19 18:17:41 +0000341 return code_addr;
342}
343
Chris Lattner24943d22010-06-08 16:52:24 +0000344bool
Greg Clayton5a269102011-05-22 04:32:55 +0000345Address::SetOpcodeLoadAddress (lldb::addr_t load_addr, Target *target)
346{
347 if (SetLoadAddress (load_addr, target))
348 {
Greg Claytonc0fa5332011-05-22 22:46:53 +0000349 if (target)
350 m_offset = target->GetOpcodeLoadAddress (m_offset, GetAddressClass());
Greg Clayton5a269102011-05-22 04:32:55 +0000351 return true;
352 }
353 return false;
354}
355
356bool
Greg Clayton70436352010-06-30 23:03:03 +0000357Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style, uint32_t addr_size) const
Chris Lattner24943d22010-06-08 16:52:24 +0000358{
Greg Clayton941f5da2012-07-11 22:18:24 +0000359 // If the section was NULL, only load address is going to work unless we are
360 // trying to deref a pointer
Greg Clayton3508c382012-02-24 01:59:29 +0000361 SectionSP section_sp (GetSection());
Greg Clayton941f5da2012-07-11 22:18:24 +0000362 if (!section_sp && style != DumpStyleResolvedPointerDescription)
Chris Lattner24943d22010-06-08 16:52:24 +0000363 style = DumpStyleLoadAddress;
364
Greg Clayton289afcb2012-02-18 05:35:26 +0000365 ExecutionContext exe_ctx (exe_scope);
366 Target *target = exe_ctx.GetTargetPtr();
Greg Clayton70436352010-06-30 23:03:03 +0000367 // If addr_byte_size is UINT32_MAX, then determine the correct address
368 // byte size for the process or default to the size of addr_t
369 if (addr_size == UINT32_MAX)
370 {
Greg Clayton289afcb2012-02-18 05:35:26 +0000371 if (target)
Greg Clayton395fc332011-02-15 21:59:32 +0000372 addr_size = target->GetArchitecture().GetAddressByteSize ();
Greg Clayton70436352010-06-30 23:03:03 +0000373 else
374 addr_size = sizeof(addr_t);
375 }
Chris Lattner24943d22010-06-08 16:52:24 +0000376
Greg Claytonc67b7d12010-09-10 01:30:46 +0000377 Address so_addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000378 switch (style)
379 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000380 case DumpStyleInvalid:
381 return false;
382
Chris Lattner24943d22010-06-08 16:52:24 +0000383 case DumpStyleSectionNameOffset:
Greg Clayton3508c382012-02-24 01:59:29 +0000384 if (section_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000385 {
Greg Clayton3508c382012-02-24 01:59:29 +0000386 section_sp->DumpName(s);
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000387 s->Printf (" + %" PRIu64, m_offset);
Chris Lattner24943d22010-06-08 16:52:24 +0000388 }
389 else
390 {
Greg Clayton70436352010-06-30 23:03:03 +0000391 s->Address(m_offset, addr_size);
Chris Lattner24943d22010-06-08 16:52:24 +0000392 }
393 break;
394
395 case DumpStyleSectionPointerOffset:
Greg Clayton3508c382012-02-24 01:59:29 +0000396 s->Printf("(Section *)%p + ", section_sp.get());
Greg Clayton70436352010-06-30 23:03:03 +0000397 s->Address(m_offset, addr_size);
Chris Lattner24943d22010-06-08 16:52:24 +0000398 break;
399
400 case DumpStyleModuleWithFileAddress:
Greg Clayton3508c382012-02-24 01:59:29 +0000401 if (section_sp)
402 s->Printf("%s[", section_sp->GetModule()->GetFileSpec().GetFilename().AsCString());
Chris Lattner24943d22010-06-08 16:52:24 +0000403 // Fall through
404 case DumpStyleFileAddress:
405 {
406 addr_t file_addr = GetFileAddress();
407 if (file_addr == LLDB_INVALID_ADDRESS)
408 {
409 if (fallback_style != DumpStyleInvalid)
Greg Clayton70436352010-06-30 23:03:03 +0000410 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
Chris Lattner24943d22010-06-08 16:52:24 +0000411 return false;
412 }
413 s->Address (file_addr, addr_size);
Greg Clayton3508c382012-02-24 01:59:29 +0000414 if (style == DumpStyleModuleWithFileAddress && section_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000415 s->PutChar(']');
416 }
417 break;
418
419 case DumpStyleLoadAddress:
420 {
Greg Claytoneea26402010-09-14 23:36:40 +0000421 addr_t load_addr = GetLoadAddress (target);
Chris Lattner24943d22010-06-08 16:52:24 +0000422 if (load_addr == LLDB_INVALID_ADDRESS)
423 {
424 if (fallback_style != DumpStyleInvalid)
Greg Clayton70436352010-06-30 23:03:03 +0000425 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
Chris Lattner24943d22010-06-08 16:52:24 +0000426 return false;
427 }
428 s->Address (load_addr, addr_size);
429 }
430 break;
431
432 case DumpStyleResolvedDescription:
Greg Claytoncf7f1ad2010-07-01 01:26:43 +0000433 case DumpStyleResolvedDescriptionNoModule:
Chris Lattner24943d22010-06-08 16:52:24 +0000434 if (IsSectionOffset())
435 {
Chris Lattner24943d22010-06-08 16:52:24 +0000436 uint32_t pointer_size = 4;
Greg Clayton3508c382012-02-24 01:59:29 +0000437 ModuleSP module_sp (GetModule());
Greg Clayton395fc332011-02-15 21:59:32 +0000438 if (target)
439 pointer_size = target->GetArchitecture().GetAddressByteSize();
Greg Clayton3508c382012-02-24 01:59:29 +0000440 else if (module_sp)
441 pointer_size = module_sp->GetArchitecture().GetAddressByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000442
443 bool showed_info = false;
Greg Clayton3508c382012-02-24 01:59:29 +0000444 if (section_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000445 {
Greg Clayton3508c382012-02-24 01:59:29 +0000446 SectionType sect_type = section_sp->GetType();
Chris Lattner24943d22010-06-08 16:52:24 +0000447 switch (sect_type)
448 {
Greg Clayton3fed8b92010-10-08 00:21:05 +0000449 case eSectionTypeData:
Greg Clayton3508c382012-02-24 01:59:29 +0000450 if (module_sp)
Greg Clayton3fed8b92010-10-08 00:21:05 +0000451 {
Greg Clayton3508c382012-02-24 01:59:29 +0000452 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton3fed8b92010-10-08 00:21:05 +0000453 if (objfile)
454 {
455 Symtab *symtab = objfile->GetSymtab();
456 if (symtab)
457 {
458 const addr_t file_Addr = GetFileAddress();
459 Symbol *symbol = symtab->FindSymbolContainingFileAddress (file_Addr);
460 if (symbol)
461 {
462 const char *symbol_name = symbol->GetName().AsCString();
463 if (symbol_name)
464 {
465 s->PutCString(symbol_name);
Greg Clayton0c31d3d2012-03-07 21:03:09 +0000466 addr_t delta = file_Addr - symbol->GetAddress().GetFileAddress();
Greg Clayton3fed8b92010-10-08 00:21:05 +0000467 if (delta)
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000468 s->Printf(" + %" PRIu64, delta);
Greg Clayton3fed8b92010-10-08 00:21:05 +0000469 showed_info = true;
470 }
471 }
472 }
473 }
474 }
475 break;
476
Chris Lattner24943d22010-06-08 16:52:24 +0000477 case eSectionTypeDataCString:
478 // Read the C string from memory and display it
479 showed_info = true;
480 ReadCStringFromMemory (exe_scope, *this, s);
481 break;
482
483 case eSectionTypeDataCStringPointers:
484 {
485 if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
486 {
487#if VERBOSE_OUTPUT
488 s->PutCString("(char *)");
489 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
490 s->PutCString(": ");
491#endif
492 showed_info = true;
493 ReadCStringFromMemory (exe_scope, so_addr, s);
494 }
495 }
496 break;
497
498 case eSectionTypeDataObjCMessageRefs:
499 {
500 if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
501 {
Greg Claytoncf7f1ad2010-07-01 01:26:43 +0000502 if (target && so_addr.IsSectionOffset())
Chris Lattner24943d22010-06-08 16:52:24 +0000503 {
Greg Claytonc67b7d12010-09-10 01:30:46 +0000504 SymbolContext func_sc;
Greg Claytoncf7f1ad2010-07-01 01:26:43 +0000505 target->GetImages().ResolveSymbolContextForAddress (so_addr,
Greg Clayton289afcb2012-02-18 05:35:26 +0000506 eSymbolContextEverything,
507 func_sc);
Chris Lattner24943d22010-06-08 16:52:24 +0000508 if (func_sc.function || func_sc.symbol)
509 {
510 showed_info = true;
511#if VERBOSE_OUTPUT
512 s->PutCString ("(objc_msgref *) -> { (func*)");
513 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
514#else
515 s->PutCString ("{ ");
516#endif
517 Address cstr_addr(*this);
518 cstr_addr.SetOffset(cstr_addr.GetOffset() + pointer_size);
Greg Clayton72b71582010-09-02 21:44:10 +0000519 func_sc.DumpStopContext(s, exe_scope, so_addr, true, true, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000520 if (ReadAddress (exe_scope, cstr_addr, pointer_size, so_addr))
521 {
522#if VERBOSE_OUTPUT
523 s->PutCString("), (char *)");
524 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
525 s->PutCString(" (");
526#else
527 s->PutCString(", ");
528#endif
529 ReadCStringFromMemory (exe_scope, so_addr, s);
530 }
531#if VERBOSE_OUTPUT
532 s->PutCString(") }");
533#else
534 s->PutCString(" }");
535#endif
536 }
537 }
538 }
539 }
540 break;
541
542 case eSectionTypeDataObjCCFStrings:
543 {
544 Address cfstring_data_addr(*this);
545 cfstring_data_addr.SetOffset(cfstring_data_addr.GetOffset() + (2 * pointer_size));
546 if (ReadAddress (exe_scope, cfstring_data_addr, pointer_size, so_addr))
547 {
548#if VERBOSE_OUTPUT
549 s->PutCString("(CFString *) ");
550 cfstring_data_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
551 s->PutCString(" -> @");
552#else
553 s->PutChar('@');
554#endif
555 if (so_addr.Dump(s, exe_scope, DumpStyleResolvedDescription))
556 showed_info = true;
557 }
558 }
559 break;
560
561 case eSectionTypeData4:
562 // Read the 4 byte data and display it
563 showed_info = true;
564 s->PutCString("(uint32_t) ");
565 DumpUInt (exe_scope, *this, 4, s);
566 break;
567
568 case eSectionTypeData8:
569 // Read the 8 byte data and display it
570 showed_info = true;
571 s->PutCString("(uint64_t) ");
572 DumpUInt (exe_scope, *this, 8, s);
573 break;
574
575 case eSectionTypeData16:
576 // Read the 16 byte data and display it
577 showed_info = true;
578 s->PutCString("(uint128_t) ");
579 DumpUInt (exe_scope, *this, 16, s);
580 break;
581
582 case eSectionTypeDataPointers:
583 // Read the pointer data and display it
584 {
585 if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
586 {
587 s->PutCString ("(void *)");
588 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
589
590 showed_info = true;
591 if (so_addr.IsSectionOffset())
592 {
Greg Claytonc67b7d12010-09-10 01:30:46 +0000593 SymbolContext pointer_sc;
Greg Clayton70436352010-06-30 23:03:03 +0000594 if (target)
Chris Lattner24943d22010-06-08 16:52:24 +0000595 {
Greg Clayton70436352010-06-30 23:03:03 +0000596 target->GetImages().ResolveSymbolContextForAddress (so_addr,
Greg Clayton289afcb2012-02-18 05:35:26 +0000597 eSymbolContextEverything,
598 pointer_sc);
Greg Clayton70436352010-06-30 23:03:03 +0000599 if (pointer_sc.function || pointer_sc.symbol)
600 {
601 s->PutCString(": ");
Greg Clayton72b71582010-09-02 21:44:10 +0000602 pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, false);
Greg Clayton70436352010-06-30 23:03:03 +0000603 }
Chris Lattner24943d22010-06-08 16:52:24 +0000604 }
605 }
606 }
607 }
608 break;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000609
610 default:
611 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000612 }
613 }
614
615 if (!showed_info)
616 {
Greg Clayton3508c382012-02-24 01:59:29 +0000617 if (module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000618 {
Greg Claytonc67b7d12010-09-10 01:30:46 +0000619 SymbolContext sc;
Greg Clayton3508c382012-02-24 01:59:29 +0000620 module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc);
Chris Lattner24943d22010-06-08 16:52:24 +0000621 if (sc.function || sc.symbol)
622 {
623 bool show_stop_context = true;
Greg Claytonb47e69e2010-09-07 21:56:53 +0000624 const bool show_module = (style == DumpStyleResolvedDescription);
625 const bool show_fullpaths = false;
Greg Clayton7e2f91c2011-01-29 07:10:55 +0000626 const bool show_inlined_frames = true;
Chris Lattner24943d22010-06-08 16:52:24 +0000627 if (sc.function == NULL && sc.symbol != NULL)
628 {
629 // If we have just a symbol make sure it is in the right section
Greg Clayton0c31d3d2012-03-07 21:03:09 +0000630 if (sc.symbol->ValueIsAddress())
Chris Lattner24943d22010-06-08 16:52:24 +0000631 {
Greg Clayton0c31d3d2012-03-07 21:03:09 +0000632 if (sc.symbol->GetAddress().GetSection() != GetSection())
Greg Claytoncf7f1ad2010-07-01 01:26:43 +0000633 {
634 // don't show the module if the symbol is a trampoline symbol
Chris Lattner24943d22010-06-08 16:52:24 +0000635 show_stop_context = false;
Greg Claytoncf7f1ad2010-07-01 01:26:43 +0000636 }
Chris Lattner24943d22010-06-08 16:52:24 +0000637 }
638 }
639 if (show_stop_context)
640 {
641 // We have a function or a symbol from the same
642 // sections as this address.
Greg Claytonb47e69e2010-09-07 21:56:53 +0000643 sc.DumpStopContext (s,
644 exe_scope,
645 *this,
646 show_fullpaths,
647 show_module,
648 show_inlined_frames);
Chris Lattner24943d22010-06-08 16:52:24 +0000649 }
650 else
651 {
652 // We found a symbol but it was in a different
653 // section so it isn't the symbol we should be
654 // showing, just show the section name + offset
655 Dump (s, exe_scope, DumpStyleSectionNameOffset);
656 }
657 }
658 }
659 }
660 }
661 else
662 {
663 if (fallback_style != DumpStyleInvalid)
Greg Clayton70436352010-06-30 23:03:03 +0000664 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
Chris Lattner24943d22010-06-08 16:52:24 +0000665 return false;
666 }
667 break;
Greg Clayton70436352010-06-30 23:03:03 +0000668
669 case DumpStyleDetailedSymbolContext:
670 if (IsSectionOffset())
671 {
Greg Clayton3508c382012-02-24 01:59:29 +0000672 ModuleSP module_sp (GetModule());
673 if (module_sp)
Greg Clayton70436352010-06-30 23:03:03 +0000674 {
Greg Claytonc67b7d12010-09-10 01:30:46 +0000675 SymbolContext sc;
Greg Clayton3508c382012-02-24 01:59:29 +0000676 module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc);
Greg Clayton960d6a42010-08-03 00:35:52 +0000677 if (sc.symbol)
Greg Clayton70436352010-06-30 23:03:03 +0000678 {
Greg Clayton960d6a42010-08-03 00:35:52 +0000679 // If we have just a symbol make sure it is in the same section
680 // as our address. If it isn't, then we might have just found
681 // the last symbol that came before the address that we are
682 // looking up that has nothing to do with our address lookup.
Greg Clayton0c31d3d2012-03-07 21:03:09 +0000683 if (sc.symbol->ValueIsAddress() && sc.symbol->GetAddress().GetSection() != GetSection())
Greg Clayton960d6a42010-08-03 00:35:52 +0000684 sc.symbol = NULL;
Greg Clayton70436352010-06-30 23:03:03 +0000685 }
Greg Claytoneea26402010-09-14 23:36:40 +0000686 sc.GetDescription(s, eDescriptionLevelBrief, target);
Greg Clayton9b82f862011-07-11 05:12:02 +0000687
688 if (sc.block)
689 {
690 bool can_create = true;
691 bool get_parent_variables = true;
692 bool stop_if_block_is_inlined_function = false;
693 VariableList variable_list;
694 sc.block->AppendVariables (can_create,
695 get_parent_variables,
696 stop_if_block_is_inlined_function,
697 &variable_list);
698
699 uint32_t num_variables = variable_list.GetSize();
700 for (uint32_t var_idx = 0; var_idx < num_variables; ++var_idx)
701 {
702 Variable *var = variable_list.GetVariableAtIndex (var_idx).get();
703 if (var && var->LocationIsValidForAddress (*this))
704 {
Greg Clayton2ad894b2012-05-15 18:43:44 +0000705 s->Indent();
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000706 s->Printf (" Variable: id = {0x%8.8" PRIx64 "}, name = \"%s\", type= \"%s\", location =",
Greg Clayton9b82f862011-07-11 05:12:02 +0000707 var->GetID(),
708 var->GetName().GetCString(),
709 var->GetType()->GetName().GetCString());
710 var->DumpLocationForAddress(s, *this);
711 s->PutCString(", decl = ");
712 var->GetDeclaration().DumpStopContext(s, false);
713 s->EOL();
714 }
715 }
716 }
Greg Clayton70436352010-06-30 23:03:03 +0000717 }
718 }
Greg Clayton9b82f862011-07-11 05:12:02 +0000719 else
720 {
721 if (fallback_style != DumpStyleInvalid)
722 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
723 return false;
724 }
Greg Clayton70436352010-06-30 23:03:03 +0000725 break;
Greg Clayton941f5da2012-07-11 22:18:24 +0000726 case DumpStyleResolvedPointerDescription:
727 {
728 Process *process = exe_ctx.GetProcessPtr();
729 if (process)
730 {
731 addr_t load_addr = GetLoadAddress (target);
732 if (load_addr != LLDB_INVALID_ADDRESS)
733 {
734 Error memory_error;
735 addr_t dereferenced_load_addr = process->ReadPointerFromMemory(load_addr, memory_error);
736 if (dereferenced_load_addr != LLDB_INVALID_ADDRESS)
737 {
738 Address dereferenced_addr;
739 if (dereferenced_addr.SetLoadAddress(dereferenced_load_addr, target))
740 {
741 StreamString strm;
742 if (dereferenced_addr.Dump (&strm, exe_scope, DumpStyleResolvedDescription, DumpStyleInvalid, addr_size))
743 {
744 s->Address (dereferenced_load_addr, addr_size, " -> ", " ");
745 s->Write(strm.GetData(), strm.GetSize());
746 return true;
747 }
748 }
749 }
750 }
751 }
752 if (fallback_style != DumpStyleInvalid)
753 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
754 return false;
755 }
756 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000757 }
758
759 return true;
760}
761
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000762uint32_t
Greg Claytonc5d14e62011-12-10 21:05:26 +0000763Address::CalculateSymbolContext (SymbolContext *sc, uint32_t resolve_scope) const
Chris Lattner24943d22010-06-08 16:52:24 +0000764{
765 sc->Clear();
766 // Absolute addresses don't have enough information to reconstruct even their target.
Greg Clayton3508c382012-02-24 01:59:29 +0000767
768 SectionSP section_sp (GetSection());
769 if (section_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000770 {
Greg Clayton3508c382012-02-24 01:59:29 +0000771 ModuleSP module_sp (section_sp->GetModule());
772 if (module_sp)
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000773 {
Greg Clayton3508c382012-02-24 01:59:29 +0000774 sc->module_sp = module_sp;
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000775 if (sc->module_sp)
776 return sc->module_sp->ResolveSymbolContextForAddress (*this, resolve_scope, *sc);
777 }
Chris Lattner24943d22010-06-08 16:52:24 +0000778 }
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000779 return 0;
780}
781
Greg Clayton3508c382012-02-24 01:59:29 +0000782ModuleSP
Greg Claytonc5d14e62011-12-10 21:05:26 +0000783Address::CalculateSymbolContextModule () const
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000784{
Greg Clayton3508c382012-02-24 01:59:29 +0000785 SectionSP section_sp (GetSection());
786 if (section_sp)
787 return section_sp->GetModule();
788 return ModuleSP();
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000789}
790
791CompileUnit *
Greg Claytonc5d14e62011-12-10 21:05:26 +0000792Address::CalculateSymbolContextCompileUnit () const
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000793{
Greg Clayton3508c382012-02-24 01:59:29 +0000794 SectionSP section_sp (GetSection());
795 if (section_sp)
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000796 {
797 SymbolContext sc;
Greg Clayton3508c382012-02-24 01:59:29 +0000798 sc.module_sp = section_sp->GetModule();
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000799 if (sc.module_sp)
800 {
801 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextCompUnit, sc);
802 return sc.comp_unit;
803 }
804 }
805 return NULL;
806}
807
808Function *
Greg Claytonc5d14e62011-12-10 21:05:26 +0000809Address::CalculateSymbolContextFunction () const
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000810{
Greg Clayton3508c382012-02-24 01:59:29 +0000811 SectionSP section_sp (GetSection());
812 if (section_sp)
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000813 {
814 SymbolContext sc;
Greg Clayton3508c382012-02-24 01:59:29 +0000815 sc.module_sp = section_sp->GetModule();
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000816 if (sc.module_sp)
817 {
818 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextFunction, sc);
819 return sc.function;
820 }
821 }
822 return NULL;
823}
824
825Block *
Greg Claytonc5d14e62011-12-10 21:05:26 +0000826Address::CalculateSymbolContextBlock () const
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000827{
Greg Clayton3508c382012-02-24 01:59:29 +0000828 SectionSP section_sp (GetSection());
829 if (section_sp)
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000830 {
831 SymbolContext sc;
Greg Clayton3508c382012-02-24 01:59:29 +0000832 sc.module_sp = section_sp->GetModule();
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000833 if (sc.module_sp)
834 {
835 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextBlock, sc);
836 return sc.block;
837 }
838 }
839 return NULL;
840}
841
842Symbol *
Greg Claytonc5d14e62011-12-10 21:05:26 +0000843Address::CalculateSymbolContextSymbol () const
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000844{
Greg Clayton3508c382012-02-24 01:59:29 +0000845 SectionSP section_sp (GetSection());
846 if (section_sp)
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000847 {
848 SymbolContext sc;
Greg Clayton3508c382012-02-24 01:59:29 +0000849 sc.module_sp = section_sp->GetModule();
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000850 if (sc.module_sp)
851 {
852 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextSymbol, sc);
853 return sc.symbol;
854 }
855 }
856 return NULL;
857}
858
859bool
Greg Claytonc5d14e62011-12-10 21:05:26 +0000860Address::CalculateSymbolContextLineEntry (LineEntry &line_entry) const
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000861{
Greg Clayton3508c382012-02-24 01:59:29 +0000862 SectionSP section_sp (GetSection());
863 if (section_sp)
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000864 {
865 SymbolContext sc;
Greg Clayton3508c382012-02-24 01:59:29 +0000866 sc.module_sp = section_sp->GetModule();
Greg Claytonc51ffbf2011-08-12 21:40:01 +0000867 if (sc.module_sp)
868 {
869 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextLineEntry, sc);
870 if (sc.line_entry.IsValid())
871 {
872 line_entry = sc.line_entry;
873 return true;
874 }
875 }
876 }
877 line_entry.Clear();
878 return false;
Chris Lattner24943d22010-06-08 16:52:24 +0000879}
880
Chris Lattner24943d22010-06-08 16:52:24 +0000881int
882Address::CompareFileAddress (const Address& a, const Address& b)
883{
884 addr_t a_file_addr = a.GetFileAddress();
885 addr_t b_file_addr = b.GetFileAddress();
886 if (a_file_addr < b_file_addr)
887 return -1;
888 if (a_file_addr > b_file_addr)
889 return +1;
890 return 0;
891}
892
893
894int
Greg Claytoneea26402010-09-14 23:36:40 +0000895Address::CompareLoadAddress (const Address& a, const Address& b, Target *target)
Chris Lattner24943d22010-06-08 16:52:24 +0000896{
Greg Claytoneea26402010-09-14 23:36:40 +0000897 assert (target != NULL);
898 addr_t a_load_addr = a.GetLoadAddress (target);
899 addr_t b_load_addr = b.GetLoadAddress (target);
Chris Lattner24943d22010-06-08 16:52:24 +0000900 if (a_load_addr < b_load_addr)
901 return -1;
902 if (a_load_addr > b_load_addr)
903 return +1;
904 return 0;
905}
906
907int
908Address::CompareModulePointerAndOffset (const Address& a, const Address& b)
909{
Greg Clayton3508c382012-02-24 01:59:29 +0000910 ModuleSP a_module_sp (a.GetModule());
911 ModuleSP b_module_sp (b.GetModule());
912 Module *a_module = a_module_sp.get();
913 Module *b_module = b_module_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000914 if (a_module < b_module)
915 return -1;
916 if (a_module > b_module)
917 return +1;
918 // Modules are the same, just compare the file address since they should
919 // be unique
920 addr_t a_file_addr = a.GetFileAddress();
921 addr_t b_file_addr = b.GetFileAddress();
922 if (a_file_addr < b_file_addr)
923 return -1;
924 if (a_file_addr > b_file_addr)
925 return +1;
926 return 0;
927}
928
929
930size_t
931Address::MemorySize () const
932{
933 // Noting special for the memory size of a single Address object,
934 // it is just the size of itself.
935 return sizeof(Address);
936}
937
938
Greg Claytone2f90642011-01-08 00:05:12 +0000939//----------------------------------------------------------------------
940// NOTE: Be careful using this operator. It can correctly compare two
941// addresses from the same Module correctly. It can't compare two
942// addresses from different modules in any meaningful way, but it will
943// compare the module pointers.
944//
945// To sum things up:
946// - works great for addresses within the same module
947// - it works for addresses across multiple modules, but don't expect the
948// address results to make much sense
Chris Lattner24943d22010-06-08 16:52:24 +0000949//
Greg Claytone2f90642011-01-08 00:05:12 +0000950// This basically lets Address objects be used in ordered collection
951// classes.
952//----------------------------------------------------------------------
953
954bool
955lldb_private::operator< (const Address& lhs, const Address& rhs)
956{
Greg Clayton3508c382012-02-24 01:59:29 +0000957 ModuleSP lhs_module_sp (lhs.GetModule());
958 ModuleSP rhs_module_sp (rhs.GetModule());
959 Module *lhs_module = lhs_module_sp.get();
960 Module *rhs_module = rhs_module_sp.get();
Greg Claytone2f90642011-01-08 00:05:12 +0000961 if (lhs_module == rhs_module)
962 {
963 // Addresses are in the same module, just compare the file addresses
964 return lhs.GetFileAddress() < rhs.GetFileAddress();
965 }
966 else
967 {
968 // The addresses are from different modules, just use the module
969 // pointer value to get consistent ordering
970 return lhs_module < rhs_module;
971 }
972}
973
974bool
975lldb_private::operator> (const Address& lhs, const Address& rhs)
976{
Greg Clayton3508c382012-02-24 01:59:29 +0000977 ModuleSP lhs_module_sp (lhs.GetModule());
978 ModuleSP rhs_module_sp (rhs.GetModule());
979 Module *lhs_module = lhs_module_sp.get();
980 Module *rhs_module = rhs_module_sp.get();
Greg Claytone2f90642011-01-08 00:05:12 +0000981 if (lhs_module == rhs_module)
982 {
983 // Addresses are in the same module, just compare the file addresses
984 return lhs.GetFileAddress() > rhs.GetFileAddress();
985 }
986 else
987 {
988 // The addresses are from different modules, just use the module
989 // pointer value to get consistent ordering
990 return lhs_module > rhs_module;
991 }
992}
993
Chris Lattner24943d22010-06-08 16:52:24 +0000994
995// The operator == checks for exact equality only (same section, same offset)
996bool
997lldb_private::operator== (const Address& a, const Address& rhs)
998{
999 return a.GetSection() == rhs.GetSection() &&
1000 a.GetOffset() == rhs.GetOffset();
1001}
1002// The operator != checks for exact inequality only (differing section, or
1003// different offset)
1004bool
1005lldb_private::operator!= (const Address& a, const Address& rhs)
1006{
1007 return a.GetSection() != rhs.GetSection() ||
1008 a.GetOffset() != rhs.GetOffset();
1009}
1010
1011bool
1012Address::IsLinkedAddress () const
1013{
Greg Clayton3508c382012-02-24 01:59:29 +00001014 SectionSP section_sp (GetSection());
1015 return section_sp && section_sp->GetLinkedSection();
Chris Lattner24943d22010-06-08 16:52:24 +00001016}
1017
1018
1019void
1020Address::ResolveLinkedAddress ()
1021{
Greg Clayton3508c382012-02-24 01:59:29 +00001022 SectionSP section_sp (GetSection());
1023 if (section_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001024 {
Greg Clayton3508c382012-02-24 01:59:29 +00001025 SectionSP linked_section_sp (section_sp->GetLinkedSection());
1026 if (linked_section_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001027 {
Greg Clayton3508c382012-02-24 01:59:29 +00001028 m_offset += section_sp->GetLinkedOffset();
1029 m_section_wp = linked_section_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001030 }
1031 }
1032}
Greg Claytonb1888f22011-03-19 01:12:21 +00001033
Greg Claytonb3448432011-03-24 21:19:54 +00001034AddressClass
Greg Claytonb1888f22011-03-19 01:12:21 +00001035Address::GetAddressClass () const
1036{
Greg Clayton3508c382012-02-24 01:59:29 +00001037 ModuleSP module_sp (GetModule());
1038 if (module_sp)
Greg Claytonb1888f22011-03-19 01:12:21 +00001039 {
Greg Clayton3508c382012-02-24 01:59:29 +00001040 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Claytonb1888f22011-03-19 01:12:21 +00001041 if (obj_file)
1042 return obj_file->GetAddressClass (GetFileAddress());
1043 }
1044 return eAddressClassUnknown;
1045}
Greg Claytonb9e8f6e2011-05-18 01:58:14 +00001046
1047bool
1048Address::SetLoadAddress (lldb::addr_t load_addr, Target *target)
1049{
1050 if (target && target->GetSectionLoadList().ResolveLoadAddress(load_addr, *this))
1051 return true;
Greg Clayton3508c382012-02-24 01:59:29 +00001052 m_section_wp.reset();
Greg Claytonb9e8f6e2011-05-18 01:58:14 +00001053 m_offset = load_addr;
1054 return false;
1055}
1056