blob: 48a3e215678dbd198b55450347be155f83767669 [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"
Greg Clayton1f746072012-08-29 21:13:06 +000013#include "lldb/Symbol/Block.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014#include "lldb/Symbol/ObjectFile.h"
Greg Clayton1f746072012-08-29 21:13:06 +000015#include "lldb/Symbol/Type.h"
Greg Claytonc749eb82011-07-11 05:12:02 +000016#include "lldb/Symbol/Variable.h"
17#include "lldb/Symbol/VariableList.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000018#include "lldb/Target/ExecutionContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Target/Process.h"
20#include "lldb/Target/Target.h"
21
Greg Clayton3f5c08f2011-05-18 22:01:49 +000022#include "llvm/ADT/Triple.h"
23
Chris Lattner30fdc8d2010-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 Claytond9e416c2012-02-18 05:35:26 +000033 TargetSP target_sp (exe_scope->CalculateTarget());
34 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035 {
36 Error error;
Greg Claytondb598232011-01-07 01:57:07 +000037 bool prefer_file_cache = false;
Greg Claytond9e416c2012-02-18 05:35:26 +000038 return target_sp->ReadMemory (address, prefer_file_cache, dst, dst_len, error);
Chris Lattner30fdc8d2010-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 Claytond9e416c2012-02-18 05:35:26 +000051 TargetSP target_sp (exe_scope->CalculateTarget());
52 if (target_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053 {
Greg Claytond9e416c2012-02-18 05:35:26 +000054 byte_order = target_sp->GetArchitecture().GetByteOrder();
55 addr_size = target_sp->GetArchitecture().GetAddressByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056 }
57
58 if (byte_order == eByteOrderInvalid || addr_size == 0)
59 {
Greg Claytone72dfb32012-02-24 01:59:29 +000060 ModuleSP module_sp (address.GetModule());
61 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062 {
Greg Claytone72dfb32012-02-24 01:59:29 +000063 byte_order = module_sp->GetArchitecture().GetByteOrder();
64 addr_size = module_sp->GetArchitecture().GetAddressByteSize();
Chris Lattner30fdc8d2010-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 Chen40e35922011-08-25 17:40:39 +000079 uint64_t buf = 0;
Chris Lattner30fdc8d2010-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);
Greg Claytonc7bece562013-01-25 18:06:21 +000089 lldb::offset_t offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000090 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 Claytonf5e56de2010-09-14 23:36:40 +0000109 ExecutionContext exe_ctx;
Greg Clayton0603aa92010-10-04 01:05:56 +0000110 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Claytonf5e56de2010-09-14 23:36:40 +0000111 // If we have any sections that are loaded, try and resolve using the
112 // section load list
Greg Claytonc14ee322011-09-22 04:58:26 +0000113 Target *target = exe_ctx.GetTargetPtr();
114 if (target && !target->GetSectionLoadList().IsEmpty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115 {
Greg Claytonc14ee322011-09-22 04:58:26 +0000116 if (target->GetSectionLoadList().ResolveLoadAddress (deref_addr, deref_so_addr))
Greg Claytonf5e56de2010-09-14 23:36:40 +0000117 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118 }
119 else
120 {
Greg Claytonf5e56de2010-09-14 23:36:40 +0000121 // If we were not running, yet able to read an integer, we must
122 // have a module
Greg Claytone72dfb32012-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 Claytonf5e56de2010-09-14 23:36:40 +0000127 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000128 }
Greg Claytonf5e56de2010-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 Claytone72dfb32012-02-24 01:59:29 +0000133 deref_so_addr.SetRawAddress(deref_addr);
Chris Lattner30fdc8d2010-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 Clayton471b31c2010-07-20 22:52:08 +0000142 if (exe_scope == NULL || byte_size == 0)
Chris Lattner30fdc8d2010-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 Clayton471b31c2010-07-20 22:52:08 +0000152 DataExtractor data (&buf.front(), buf.size(), byte_order, addr_size);
Chris Lattner30fdc8d2010-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 Clayton710dd5a2011-01-08 20:28:42 +0000180 // Byte order and address size don't matter for C string dumping..
Greg Clayton7fb56d02011-02-01 01:31:41 +0000181 DataExtractor data (buf, sizeof(buf), lldb::endian::InlHostByteOrder(), 4);
Chris Lattner30fdc8d2010-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 Claytone72dfb32012-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 Lattner30fdc8d2010-06-08 16:52:24 +0000223 m_offset (LLDB_INVALID_ADDRESS)
224{
Greg Claytone72dfb32012-02-24 01:59:29 +0000225 ResolveAddressUsingFileSections(address, section_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000226}
227
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000228const Address&
229Address::operator= (const Address& rhs)
230{
231 if (this != &rhs)
232 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000233 m_section_wp = rhs.m_section_wp;
Daniel Malea48184602013-04-22 20:59:13 +0000234 m_offset = rhs.m_offset.load();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000235 }
236 return *this;
237}
238
239bool
Greg Claytone72dfb32012-02-24 01:59:29 +0000240Address::ResolveAddressUsingFileSections (addr_t file_addr, const SectionList *section_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000241{
Greg Claytone72dfb32012-02-24 01:59:29 +0000242 if (section_list)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000243 {
Greg Claytone72dfb32012-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 Lattner30fdc8d2010-06-08 16:52:24 +0000252 }
Greg Claytone72dfb32012-02-24 01:59:29 +0000253 m_offset = file_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000254 return false; // Failed to resolve this address to a section offset value
255}
256
Greg Claytone1cd1be2012-01-29 20:56:30 +0000257ModuleSP
Greg Claytone72dfb32012-02-24 01:59:29 +0000258Address::GetModule () const
Greg Claytone1cd1be2012-01-29 20:56:30 +0000259{
260 lldb::ModuleSP module_sp;
Greg Claytone72dfb32012-02-24 01:59:29 +0000261 SectionSP section_sp (GetSection());
262 if (section_sp)
263 module_sp = section_sp->GetModule();
Greg Claytone1cd1be2012-01-29 20:56:30 +0000264 return module_sp;
265}
266
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000267addr_t
268Address::GetFileAddress () const
269{
Greg Claytone72dfb32012-02-24 01:59:29 +0000270 SectionSP section_sp (GetSection());
271 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000273 addr_t sect_file_addr = section_sp->GetFileAddress();
Chris Lattner30fdc8d2010-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 Claytonf5e56de2010-09-14 23:36:40 +0000288Address::GetLoadAddress (Target *target) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000289{
Greg Claytone72dfb32012-02-24 01:59:29 +0000290 SectionSP section_sp (GetSection());
291 if (!section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000292 {
Greg Claytonf5e56de2010-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 Lattner30fdc8d2010-06-08 16:52:24 +0000295 }
Greg Claytonf5e56de2010-09-14 23:36:40 +0000296
297 if (target)
298 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000299 addr_t sect_load_addr = section_sp->GetLoadBaseAddress (target);
Greg Claytonf5e56de2010-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 Lattner30fdc8d2010-06-08 16:52:24 +0000311}
312
Greg Clayton3f5c08f2011-05-18 22:01:49 +0000313addr_t
Matt Kopec00049b82013-02-27 20:13:38 +0000314Address::GetCallableLoadAddress (Target *target, bool is_indirect) const
Greg Clayton3f5c08f2011-05-18 22:01:49 +0000315{
Matt Kopec00049b82013-02-27 20:13:38 +0000316 if (is_indirect && target) {
317 ProcessSP processSP = target->GetProcessSP();
318 Error error;
319 if (processSP.get())
320 return processSP->ResolveIndirectFunction(this, error);
321 }
322
Greg Clayton3f5c08f2011-05-18 22:01:49 +0000323 addr_t code_addr = GetLoadAddress (target);
Greg Claytonf3ef3d22011-05-22 22:46:53 +0000324
325 if (target)
326 return target->GetCallableLoadAddress (code_addr, GetAddressClass());
Greg Clayton3f5c08f2011-05-18 22:01:49 +0000327 return code_addr;
328}
329
Greg Claytoncff851a2011-05-22 04:32:55 +0000330bool
331Address::SetCallableLoadAddress (lldb::addr_t load_addr, Target *target)
332{
333 if (SetLoadAddress (load_addr, target))
334 {
Greg Claytonf3ef3d22011-05-22 22:46:53 +0000335 if (target)
336 m_offset = target->GetCallableLoadAddress(m_offset, GetAddressClass());
Greg Claytoncff851a2011-05-22 04:32:55 +0000337 return true;
338 }
339 return false;
340}
341
Greg Clayton92bb12c2011-05-19 18:17:41 +0000342addr_t
343Address::GetOpcodeLoadAddress (Target *target) const
344{
345 addr_t code_addr = GetLoadAddress (target);
Greg Clayton92bb12c2011-05-19 18:17:41 +0000346 if (code_addr != LLDB_INVALID_ADDRESS)
Greg Claytonf3ef3d22011-05-22 22:46:53 +0000347 code_addr = target->GetOpcodeLoadAddress (code_addr, GetAddressClass());
Greg Clayton92bb12c2011-05-19 18:17:41 +0000348 return code_addr;
349}
350
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351bool
Greg Claytoncff851a2011-05-22 04:32:55 +0000352Address::SetOpcodeLoadAddress (lldb::addr_t load_addr, Target *target)
353{
354 if (SetLoadAddress (load_addr, target))
355 {
Greg Claytonf3ef3d22011-05-22 22:46:53 +0000356 if (target)
357 m_offset = target->GetOpcodeLoadAddress (m_offset, GetAddressClass());
Greg Claytoncff851a2011-05-22 04:32:55 +0000358 return true;
359 }
360 return false;
361}
362
363bool
Greg Claytondda4f7b2010-06-30 23:03:03 +0000364Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style, uint32_t addr_size) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000365{
Greg Claytonc3a86bf2012-07-11 22:18:24 +0000366 // If the section was NULL, only load address is going to work unless we are
367 // trying to deref a pointer
Greg Claytone72dfb32012-02-24 01:59:29 +0000368 SectionSP section_sp (GetSection());
Greg Claytonc3a86bf2012-07-11 22:18:24 +0000369 if (!section_sp && style != DumpStyleResolvedPointerDescription)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370 style = DumpStyleLoadAddress;
371
Greg Claytond9e416c2012-02-18 05:35:26 +0000372 ExecutionContext exe_ctx (exe_scope);
373 Target *target = exe_ctx.GetTargetPtr();
Greg Claytondda4f7b2010-06-30 23:03:03 +0000374 // If addr_byte_size is UINT32_MAX, then determine the correct address
375 // byte size for the process or default to the size of addr_t
376 if (addr_size == UINT32_MAX)
377 {
Greg Claytond9e416c2012-02-18 05:35:26 +0000378 if (target)
Greg Clayton514487e2011-02-15 21:59:32 +0000379 addr_size = target->GetArchitecture().GetAddressByteSize ();
Greg Claytondda4f7b2010-06-30 23:03:03 +0000380 else
381 addr_size = sizeof(addr_t);
382 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383
Greg Claytonc9800662010-09-10 01:30:46 +0000384 Address so_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385 switch (style)
386 {
Greg Claytonc982c762010-07-09 20:39:50 +0000387 case DumpStyleInvalid:
388 return false;
389
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000390 case DumpStyleSectionNameOffset:
Greg Claytone72dfb32012-02-24 01:59:29 +0000391 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000393 section_sp->DumpName(s);
Daniel Malea48184602013-04-22 20:59:13 +0000394 s->Printf (" + %" PRIu64, m_offset.load());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000395 }
396 else
397 {
Greg Claytondda4f7b2010-06-30 23:03:03 +0000398 s->Address(m_offset, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000399 }
400 break;
401
402 case DumpStyleSectionPointerOffset:
Greg Claytone72dfb32012-02-24 01:59:29 +0000403 s->Printf("(Section *)%p + ", section_sp.get());
Greg Claytondda4f7b2010-06-30 23:03:03 +0000404 s->Address(m_offset, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405 break;
406
407 case DumpStyleModuleWithFileAddress:
Greg Claytone72dfb32012-02-24 01:59:29 +0000408 if (section_sp)
409 s->Printf("%s[", section_sp->GetModule()->GetFileSpec().GetFilename().AsCString());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410 // Fall through
411 case DumpStyleFileAddress:
412 {
413 addr_t file_addr = GetFileAddress();
414 if (file_addr == LLDB_INVALID_ADDRESS)
415 {
416 if (fallback_style != DumpStyleInvalid)
Greg Claytondda4f7b2010-06-30 23:03:03 +0000417 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000418 return false;
419 }
420 s->Address (file_addr, addr_size);
Greg Claytone72dfb32012-02-24 01:59:29 +0000421 if (style == DumpStyleModuleWithFileAddress && section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422 s->PutChar(']');
423 }
424 break;
425
426 case DumpStyleLoadAddress:
427 {
Greg Claytonf5e56de2010-09-14 23:36:40 +0000428 addr_t load_addr = GetLoadAddress (target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429 if (load_addr == LLDB_INVALID_ADDRESS)
430 {
431 if (fallback_style != DumpStyleInvalid)
Greg Claytondda4f7b2010-06-30 23:03:03 +0000432 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000433 return false;
434 }
435 s->Address (load_addr, addr_size);
436 }
437 break;
438
439 case DumpStyleResolvedDescription:
Greg Clayton54b8b8c2010-07-01 01:26:43 +0000440 case DumpStyleResolvedDescriptionNoModule:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441 if (IsSectionOffset())
442 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000443 uint32_t pointer_size = 4;
Greg Claytone72dfb32012-02-24 01:59:29 +0000444 ModuleSP module_sp (GetModule());
Greg Clayton514487e2011-02-15 21:59:32 +0000445 if (target)
446 pointer_size = target->GetArchitecture().GetAddressByteSize();
Greg Claytone72dfb32012-02-24 01:59:29 +0000447 else if (module_sp)
448 pointer_size = module_sp->GetArchitecture().GetAddressByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000449
450 bool showed_info = false;
Greg Claytone72dfb32012-02-24 01:59:29 +0000451 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000453 SectionType sect_type = section_sp->GetType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454 switch (sect_type)
455 {
Greg Clayton89411422010-10-08 00:21:05 +0000456 case eSectionTypeData:
Greg Claytone72dfb32012-02-24 01:59:29 +0000457 if (module_sp)
Greg Clayton89411422010-10-08 00:21:05 +0000458 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000459 ObjectFile *objfile = module_sp->GetObjectFile();
Greg Clayton89411422010-10-08 00:21:05 +0000460 if (objfile)
461 {
462 Symtab *symtab = objfile->GetSymtab();
463 if (symtab)
464 {
465 const addr_t file_Addr = GetFileAddress();
466 Symbol *symbol = symtab->FindSymbolContainingFileAddress (file_Addr);
467 if (symbol)
468 {
469 const char *symbol_name = symbol->GetName().AsCString();
470 if (symbol_name)
471 {
472 s->PutCString(symbol_name);
Greg Claytone7612132012-03-07 21:03:09 +0000473 addr_t delta = file_Addr - symbol->GetAddress().GetFileAddress();
Greg Clayton89411422010-10-08 00:21:05 +0000474 if (delta)
Daniel Malead01b2952012-11-29 21:49:15 +0000475 s->Printf(" + %" PRIu64, delta);
Greg Clayton89411422010-10-08 00:21:05 +0000476 showed_info = true;
477 }
478 }
479 }
480 }
481 }
482 break;
483
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484 case eSectionTypeDataCString:
485 // Read the C string from memory and display it
486 showed_info = true;
487 ReadCStringFromMemory (exe_scope, *this, s);
488 break;
489
490 case eSectionTypeDataCStringPointers:
491 {
492 if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
493 {
494#if VERBOSE_OUTPUT
495 s->PutCString("(char *)");
496 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
497 s->PutCString(": ");
498#endif
499 showed_info = true;
500 ReadCStringFromMemory (exe_scope, so_addr, s);
501 }
502 }
503 break;
504
505 case eSectionTypeDataObjCMessageRefs:
506 {
507 if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
508 {
Greg Clayton54b8b8c2010-07-01 01:26:43 +0000509 if (target && so_addr.IsSectionOffset())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510 {
Greg Claytonc9800662010-09-10 01:30:46 +0000511 SymbolContext func_sc;
Greg Clayton54b8b8c2010-07-01 01:26:43 +0000512 target->GetImages().ResolveSymbolContextForAddress (so_addr,
Greg Claytond9e416c2012-02-18 05:35:26 +0000513 eSymbolContextEverything,
514 func_sc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000515 if (func_sc.function || func_sc.symbol)
516 {
517 showed_info = true;
518#if VERBOSE_OUTPUT
519 s->PutCString ("(objc_msgref *) -> { (func*)");
520 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
521#else
522 s->PutCString ("{ ");
523#endif
524 Address cstr_addr(*this);
525 cstr_addr.SetOffset(cstr_addr.GetOffset() + pointer_size);
Greg Clayton6dadd502010-09-02 21:44:10 +0000526 func_sc.DumpStopContext(s, exe_scope, so_addr, true, true, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527 if (ReadAddress (exe_scope, cstr_addr, pointer_size, so_addr))
528 {
529#if VERBOSE_OUTPUT
530 s->PutCString("), (char *)");
531 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
532 s->PutCString(" (");
533#else
534 s->PutCString(", ");
535#endif
536 ReadCStringFromMemory (exe_scope, so_addr, s);
537 }
538#if VERBOSE_OUTPUT
539 s->PutCString(") }");
540#else
541 s->PutCString(" }");
542#endif
543 }
544 }
545 }
546 }
547 break;
548
549 case eSectionTypeDataObjCCFStrings:
550 {
551 Address cfstring_data_addr(*this);
552 cfstring_data_addr.SetOffset(cfstring_data_addr.GetOffset() + (2 * pointer_size));
553 if (ReadAddress (exe_scope, cfstring_data_addr, pointer_size, so_addr))
554 {
555#if VERBOSE_OUTPUT
556 s->PutCString("(CFString *) ");
557 cfstring_data_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
558 s->PutCString(" -> @");
559#else
560 s->PutChar('@');
561#endif
562 if (so_addr.Dump(s, exe_scope, DumpStyleResolvedDescription))
563 showed_info = true;
564 }
565 }
566 break;
567
568 case eSectionTypeData4:
569 // Read the 4 byte data and display it
570 showed_info = true;
571 s->PutCString("(uint32_t) ");
572 DumpUInt (exe_scope, *this, 4, s);
573 break;
574
575 case eSectionTypeData8:
576 // Read the 8 byte data and display it
577 showed_info = true;
578 s->PutCString("(uint64_t) ");
579 DumpUInt (exe_scope, *this, 8, s);
580 break;
581
582 case eSectionTypeData16:
583 // Read the 16 byte data and display it
584 showed_info = true;
585 s->PutCString("(uint128_t) ");
586 DumpUInt (exe_scope, *this, 16, s);
587 break;
588
589 case eSectionTypeDataPointers:
590 // Read the pointer data and display it
591 {
592 if (ReadAddress (exe_scope, *this, pointer_size, so_addr))
593 {
594 s->PutCString ("(void *)");
595 so_addr.Dump(s, exe_scope, DumpStyleLoadAddress, DumpStyleFileAddress);
596
597 showed_info = true;
598 if (so_addr.IsSectionOffset())
599 {
Greg Claytonc9800662010-09-10 01:30:46 +0000600 SymbolContext pointer_sc;
Greg Claytondda4f7b2010-06-30 23:03:03 +0000601 if (target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000602 {
Greg Claytondda4f7b2010-06-30 23:03:03 +0000603 target->GetImages().ResolveSymbolContextForAddress (so_addr,
Greg Claytond9e416c2012-02-18 05:35:26 +0000604 eSymbolContextEverything,
605 pointer_sc);
Greg Claytondda4f7b2010-06-30 23:03:03 +0000606 if (pointer_sc.function || pointer_sc.symbol)
607 {
608 s->PutCString(": ");
Greg Clayton6dadd502010-09-02 21:44:10 +0000609 pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, false);
Greg Claytondda4f7b2010-06-30 23:03:03 +0000610 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000611 }
612 }
613 }
614 }
615 break;
Greg Claytonc982c762010-07-09 20:39:50 +0000616
617 default:
618 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000619 }
620 }
621
622 if (!showed_info)
623 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000624 if (module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000625 {
Greg Claytonc9800662010-09-10 01:30:46 +0000626 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000627 module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000628 if (sc.function || sc.symbol)
629 {
630 bool show_stop_context = true;
Greg Clayton8dc0a982010-09-07 21:56:53 +0000631 const bool show_module = (style == DumpStyleResolvedDescription);
632 const bool show_fullpaths = false;
Greg Clayton513c26c2011-01-29 07:10:55 +0000633 const bool show_inlined_frames = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000634 if (sc.function == NULL && sc.symbol != NULL)
635 {
636 // If we have just a symbol make sure it is in the right section
Greg Claytone7612132012-03-07 21:03:09 +0000637 if (sc.symbol->ValueIsAddress())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000638 {
Greg Claytone7612132012-03-07 21:03:09 +0000639 if (sc.symbol->GetAddress().GetSection() != GetSection())
Greg Clayton54b8b8c2010-07-01 01:26:43 +0000640 {
641 // don't show the module if the symbol is a trampoline symbol
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000642 show_stop_context = false;
Greg Clayton54b8b8c2010-07-01 01:26:43 +0000643 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000644 }
645 }
646 if (show_stop_context)
647 {
648 // We have a function or a symbol from the same
649 // sections as this address.
Greg Clayton8dc0a982010-09-07 21:56:53 +0000650 sc.DumpStopContext (s,
651 exe_scope,
652 *this,
653 show_fullpaths,
654 show_module,
655 show_inlined_frames);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000656 }
657 else
658 {
659 // We found a symbol but it was in a different
660 // section so it isn't the symbol we should be
661 // showing, just show the section name + offset
662 Dump (s, exe_scope, DumpStyleSectionNameOffset);
663 }
664 }
665 }
666 }
667 }
668 else
669 {
670 if (fallback_style != DumpStyleInvalid)
Greg Claytondda4f7b2010-06-30 23:03:03 +0000671 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000672 return false;
673 }
674 break;
Greg Claytondda4f7b2010-06-30 23:03:03 +0000675
676 case DumpStyleDetailedSymbolContext:
677 if (IsSectionOffset())
678 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000679 ModuleSP module_sp (GetModule());
680 if (module_sp)
Greg Claytondda4f7b2010-06-30 23:03:03 +0000681 {
Greg Claytonc9800662010-09-10 01:30:46 +0000682 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000683 module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc);
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000684 if (sc.symbol)
Greg Claytondda4f7b2010-06-30 23:03:03 +0000685 {
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000686 // If we have just a symbol make sure it is in the same section
687 // as our address. If it isn't, then we might have just found
688 // the last symbol that came before the address that we are
689 // looking up that has nothing to do with our address lookup.
Greg Claytone7612132012-03-07 21:03:09 +0000690 if (sc.symbol->ValueIsAddress() && sc.symbol->GetAddress().GetSection() != GetSection())
Greg Claytonb0b9fe62010-08-03 00:35:52 +0000691 sc.symbol = NULL;
Greg Claytondda4f7b2010-06-30 23:03:03 +0000692 }
Greg Claytonf5e56de2010-09-14 23:36:40 +0000693 sc.GetDescription(s, eDescriptionLevelBrief, target);
Greg Claytonc749eb82011-07-11 05:12:02 +0000694
695 if (sc.block)
696 {
697 bool can_create = true;
698 bool get_parent_variables = true;
699 bool stop_if_block_is_inlined_function = false;
700 VariableList variable_list;
701 sc.block->AppendVariables (can_create,
702 get_parent_variables,
703 stop_if_block_is_inlined_function,
704 &variable_list);
705
Greg Claytonc7bece562013-01-25 18:06:21 +0000706 const size_t num_variables = variable_list.GetSize();
707 for (size_t var_idx = 0; var_idx < num_variables; ++var_idx)
Greg Claytonc749eb82011-07-11 05:12:02 +0000708 {
709 Variable *var = variable_list.GetVariableAtIndex (var_idx).get();
710 if (var && var->LocationIsValidForAddress (*this))
711 {
Greg Claytonc4a8a762012-05-15 18:43:44 +0000712 s->Indent();
Daniel Malead01b2952012-11-29 21:49:15 +0000713 s->Printf (" Variable: id = {0x%8.8" PRIx64 "}, name = \"%s\", type= \"%s\", location =",
Greg Claytonc749eb82011-07-11 05:12:02 +0000714 var->GetID(),
715 var->GetName().GetCString(),
716 var->GetType()->GetName().GetCString());
717 var->DumpLocationForAddress(s, *this);
718 s->PutCString(", decl = ");
719 var->GetDeclaration().DumpStopContext(s, false);
720 s->EOL();
721 }
722 }
723 }
Greg Claytondda4f7b2010-06-30 23:03:03 +0000724 }
725 }
Greg Claytonc749eb82011-07-11 05:12:02 +0000726 else
727 {
728 if (fallback_style != DumpStyleInvalid)
729 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
730 return false;
731 }
Greg Claytondda4f7b2010-06-30 23:03:03 +0000732 break;
Greg Claytonc3a86bf2012-07-11 22:18:24 +0000733 case DumpStyleResolvedPointerDescription:
734 {
735 Process *process = exe_ctx.GetProcessPtr();
736 if (process)
737 {
738 addr_t load_addr = GetLoadAddress (target);
739 if (load_addr != LLDB_INVALID_ADDRESS)
740 {
741 Error memory_error;
742 addr_t dereferenced_load_addr = process->ReadPointerFromMemory(load_addr, memory_error);
743 if (dereferenced_load_addr != LLDB_INVALID_ADDRESS)
744 {
745 Address dereferenced_addr;
746 if (dereferenced_addr.SetLoadAddress(dereferenced_load_addr, target))
747 {
748 StreamString strm;
749 if (dereferenced_addr.Dump (&strm, exe_scope, DumpStyleResolvedDescription, DumpStyleInvalid, addr_size))
750 {
751 s->Address (dereferenced_load_addr, addr_size, " -> ", " ");
752 s->Write(strm.GetData(), strm.GetSize());
753 return true;
754 }
755 }
756 }
757 }
758 }
759 if (fallback_style != DumpStyleInvalid)
760 return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
761 return false;
762 }
763 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000764 }
765
766 return true;
767}
768
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000769uint32_t
Greg Clayton6f6bf262011-12-10 21:05:26 +0000770Address::CalculateSymbolContext (SymbolContext *sc, uint32_t resolve_scope) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000771{
Greg Clayton72310352013-02-23 04:12:47 +0000772 sc->Clear(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000773 // Absolute addresses don't have enough information to reconstruct even their target.
Greg Claytone72dfb32012-02-24 01:59:29 +0000774
775 SectionSP section_sp (GetSection());
776 if (section_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000777 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000778 ModuleSP module_sp (section_sp->GetModule());
779 if (module_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000780 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000781 sc->module_sp = module_sp;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000782 if (sc->module_sp)
783 return sc->module_sp->ResolveSymbolContextForAddress (*this, resolve_scope, *sc);
784 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000785 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000786 return 0;
787}
788
Greg Claytone72dfb32012-02-24 01:59:29 +0000789ModuleSP
Greg Clayton6f6bf262011-12-10 21:05:26 +0000790Address::CalculateSymbolContextModule () const
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000791{
Greg Claytone72dfb32012-02-24 01:59:29 +0000792 SectionSP section_sp (GetSection());
793 if (section_sp)
794 return section_sp->GetModule();
795 return ModuleSP();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000796}
797
798CompileUnit *
Greg Clayton6f6bf262011-12-10 21:05:26 +0000799Address::CalculateSymbolContextCompileUnit () 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, eSymbolContextCompUnit, sc);
809 return sc.comp_unit;
810 }
811 }
812 return NULL;
813}
814
815Function *
Greg Clayton6f6bf262011-12-10 21:05:26 +0000816Address::CalculateSymbolContextFunction () 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, eSymbolContextFunction, sc);
826 return sc.function;
827 }
828 }
829 return NULL;
830}
831
832Block *
Greg Clayton6f6bf262011-12-10 21:05:26 +0000833Address::CalculateSymbolContextBlock () 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, eSymbolContextBlock, sc);
843 return sc.block;
844 }
845 }
846 return NULL;
847}
848
849Symbol *
Greg Clayton6f6bf262011-12-10 21:05:26 +0000850Address::CalculateSymbolContextSymbol () const
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000851{
Greg Claytone72dfb32012-02-24 01:59:29 +0000852 SectionSP section_sp (GetSection());
853 if (section_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000854 {
855 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000856 sc.module_sp = section_sp->GetModule();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000857 if (sc.module_sp)
858 {
859 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextSymbol, sc);
860 return sc.symbol;
861 }
862 }
863 return NULL;
864}
865
866bool
Greg Clayton6f6bf262011-12-10 21:05:26 +0000867Address::CalculateSymbolContextLineEntry (LineEntry &line_entry) const
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000868{
Greg Claytone72dfb32012-02-24 01:59:29 +0000869 SectionSP section_sp (GetSection());
870 if (section_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000871 {
872 SymbolContext sc;
Greg Claytone72dfb32012-02-24 01:59:29 +0000873 sc.module_sp = section_sp->GetModule();
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000874 if (sc.module_sp)
875 {
876 sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextLineEntry, sc);
877 if (sc.line_entry.IsValid())
878 {
879 line_entry = sc.line_entry;
880 return true;
881 }
882 }
883 }
884 line_entry.Clear();
885 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000886}
887
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000888int
889Address::CompareFileAddress (const Address& a, const Address& b)
890{
891 addr_t a_file_addr = a.GetFileAddress();
892 addr_t b_file_addr = b.GetFileAddress();
893 if (a_file_addr < b_file_addr)
894 return -1;
895 if (a_file_addr > b_file_addr)
896 return +1;
897 return 0;
898}
899
900
901int
Greg Claytonf5e56de2010-09-14 23:36:40 +0000902Address::CompareLoadAddress (const Address& a, const Address& b, Target *target)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000903{
Greg Claytonf5e56de2010-09-14 23:36:40 +0000904 assert (target != NULL);
905 addr_t a_load_addr = a.GetLoadAddress (target);
906 addr_t b_load_addr = b.GetLoadAddress (target);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000907 if (a_load_addr < b_load_addr)
908 return -1;
909 if (a_load_addr > b_load_addr)
910 return +1;
911 return 0;
912}
913
914int
915Address::CompareModulePointerAndOffset (const Address& a, const Address& b)
916{
Greg Claytone72dfb32012-02-24 01:59:29 +0000917 ModuleSP a_module_sp (a.GetModule());
918 ModuleSP b_module_sp (b.GetModule());
919 Module *a_module = a_module_sp.get();
920 Module *b_module = b_module_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000921 if (a_module < b_module)
922 return -1;
923 if (a_module > b_module)
924 return +1;
925 // Modules are the same, just compare the file address since they should
926 // be unique
927 addr_t a_file_addr = a.GetFileAddress();
928 addr_t b_file_addr = b.GetFileAddress();
929 if (a_file_addr < b_file_addr)
930 return -1;
931 if (a_file_addr > b_file_addr)
932 return +1;
933 return 0;
934}
935
936
937size_t
938Address::MemorySize () const
939{
940 // Noting special for the memory size of a single Address object,
941 // it is just the size of itself.
942 return sizeof(Address);
943}
944
945
Greg Claytonb0848c52011-01-08 00:05:12 +0000946//----------------------------------------------------------------------
947// NOTE: Be careful using this operator. It can correctly compare two
948// addresses from the same Module correctly. It can't compare two
949// addresses from different modules in any meaningful way, but it will
950// compare the module pointers.
951//
952// To sum things up:
953// - works great for addresses within the same module
954// - it works for addresses across multiple modules, but don't expect the
955// address results to make much sense
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000956//
Greg Claytonb0848c52011-01-08 00:05:12 +0000957// This basically lets Address objects be used in ordered collection
958// classes.
959//----------------------------------------------------------------------
960
961bool
962lldb_private::operator< (const Address& lhs, const Address& rhs)
963{
Greg Claytone72dfb32012-02-24 01:59:29 +0000964 ModuleSP lhs_module_sp (lhs.GetModule());
965 ModuleSP rhs_module_sp (rhs.GetModule());
966 Module *lhs_module = lhs_module_sp.get();
967 Module *rhs_module = rhs_module_sp.get();
Greg Claytonb0848c52011-01-08 00:05:12 +0000968 if (lhs_module == rhs_module)
969 {
970 // Addresses are in the same module, just compare the file addresses
971 return lhs.GetFileAddress() < rhs.GetFileAddress();
972 }
973 else
974 {
975 // The addresses are from different modules, just use the module
976 // pointer value to get consistent ordering
977 return lhs_module < rhs_module;
978 }
979}
980
981bool
982lldb_private::operator> (const Address& lhs, const Address& rhs)
983{
Greg Claytone72dfb32012-02-24 01:59:29 +0000984 ModuleSP lhs_module_sp (lhs.GetModule());
985 ModuleSP rhs_module_sp (rhs.GetModule());
986 Module *lhs_module = lhs_module_sp.get();
987 Module *rhs_module = rhs_module_sp.get();
Greg Claytonb0848c52011-01-08 00:05:12 +0000988 if (lhs_module == rhs_module)
989 {
990 // Addresses are in the same module, just compare the file addresses
991 return lhs.GetFileAddress() > rhs.GetFileAddress();
992 }
993 else
994 {
995 // The addresses are from different modules, just use the module
996 // pointer value to get consistent ordering
997 return lhs_module > rhs_module;
998 }
999}
1000
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001001
1002// The operator == checks for exact equality only (same section, same offset)
1003bool
1004lldb_private::operator== (const Address& a, const Address& rhs)
1005{
Jim Inghamd3480f52013-06-06 22:16:56 +00001006 return a.GetOffset() == rhs.GetOffset() &&
1007 a.GetSection() == rhs.GetSection();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001008}
1009// The operator != checks for exact inequality only (differing section, or
1010// different offset)
1011bool
1012lldb_private::operator!= (const Address& a, const Address& rhs)
1013{
Jim Inghamd3480f52013-06-06 22:16:56 +00001014 return a.GetOffset() != rhs.GetOffset() ||
1015 a.GetSection() != rhs.GetSection();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001016}
1017
Greg Claytone0d378b2011-03-24 21:19:54 +00001018AddressClass
Greg Claytonded470d2011-03-19 01:12:21 +00001019Address::GetAddressClass () const
1020{
Greg Claytone72dfb32012-02-24 01:59:29 +00001021 ModuleSP module_sp (GetModule());
1022 if (module_sp)
Greg Claytonded470d2011-03-19 01:12:21 +00001023 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001024 ObjectFile *obj_file = module_sp->GetObjectFile();
Greg Claytonded470d2011-03-19 01:12:21 +00001025 if (obj_file)
1026 return obj_file->GetAddressClass (GetFileAddress());
1027 }
1028 return eAddressClassUnknown;
1029}
Greg Claytoncd482e32011-05-18 01:58:14 +00001030
1031bool
1032Address::SetLoadAddress (lldb::addr_t load_addr, Target *target)
1033{
1034 if (target && target->GetSectionLoadList().ResolveLoadAddress(load_addr, *this))
1035 return true;
Greg Claytone72dfb32012-02-24 01:59:29 +00001036 m_section_wp.reset();
Greg Claytoncd482e32011-05-18 01:58:14 +00001037 m_offset = load_addr;
1038 return false;
1039}
1040