Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Clayton | c749eb8 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 14 | #include "lldb/Symbol/Variable.h" |
| 15 | #include "lldb/Symbol/VariableList.h" |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 16 | #include "lldb/Target/ExecutionContext.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Target/Process.h" |
| 18 | #include "lldb/Target/Target.h" |
| 19 | |
Greg Clayton | 3f5c08f | 2011-05-18 22:01:49 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/Triple.h" |
| 21 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | using namespace lldb; |
| 23 | using namespace lldb_private; |
| 24 | |
| 25 | static size_t |
| 26 | ReadBytes (ExecutionContextScope *exe_scope, const Address &address, void *dst, size_t dst_len) |
| 27 | { |
| 28 | if (exe_scope == NULL) |
| 29 | return 0; |
| 30 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | Target *target = exe_scope->CalculateTarget(); |
| 32 | if (target) |
| 33 | { |
| 34 | Error error; |
Greg Clayton | db59823 | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 35 | bool prefer_file_cache = false; |
| 36 | return target->ReadMemory (address, prefer_file_cache, dst, dst_len, error); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | } |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | static bool |
| 42 | GetByteOrderAndAddressSize (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 Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 49 | Target *target = exe_scope->CalculateTarget(); |
| 50 | if (target) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | { |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 52 | byte_order = target->GetArchitecture().GetByteOrder(); |
| 53 | addr_size = target->GetArchitecture().GetAddressByteSize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | if (byte_order == eByteOrderInvalid || addr_size == 0) |
| 57 | { |
| 58 | Module *module = address.GetModule(); |
| 59 | if (module) |
| 60 | { |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 61 | byte_order = module->GetArchitecture().GetByteOrder(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | addr_size = module->GetArchitecture().GetAddressByteSize(); |
| 63 | } |
| 64 | } |
| 65 | return byte_order != eByteOrderInvalid && addr_size != 0; |
| 66 | } |
| 67 | |
| 68 | static uint64_t |
| 69 | ReadUIntMax64 (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 | } |
| 77 | uint64_t buf; |
| 78 | |
| 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 | |
| 96 | static bool |
| 97 | ReadAddress (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 Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 107 | ExecutionContext exe_ctx; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 108 | exe_scope->CalculateExecutionContext(exe_ctx); |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 109 | // If we have any sections that are loaded, try and resolve using the |
| 110 | // section load list |
| 111 | if (exe_ctx.target && !exe_ctx.target->GetSectionLoadList().IsEmpty()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 112 | { |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 113 | if (exe_ctx.target->GetSectionLoadList().ResolveLoadAddress (deref_addr, deref_so_addr)) |
| 114 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | } |
| 116 | else |
| 117 | { |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 118 | // If we were not running, yet able to read an integer, we must |
| 119 | // have a module |
| 120 | Module *module = address.GetModule(); |
| 121 | assert (module); |
| 122 | if (module->ResolveFileAddress(deref_addr, deref_so_addr)) |
| 123 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 124 | } |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 125 | |
| 126 | // We couldn't make "deref_addr" into a section offset value, but we were |
| 127 | // able to read the address, so we return a section offset address with |
| 128 | // no section and "deref_addr" as the offset (address). |
| 129 | deref_so_addr.SetSection(NULL); |
| 130 | deref_so_addr.SetOffset(deref_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 131 | return true; |
| 132 | } |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | static bool |
| 137 | DumpUInt (ExecutionContextScope *exe_scope, const Address &address, uint32_t byte_size, Stream* strm) |
| 138 | { |
Greg Clayton | 471b31c | 2010-07-20 22:52:08 +0000 | [diff] [blame] | 139 | if (exe_scope == NULL || byte_size == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 140 | return 0; |
| 141 | std::vector<uint8_t> buf(byte_size, 0); |
| 142 | |
| 143 | if (ReadBytes (exe_scope, address, &buf[0], buf.size()) == buf.size()) |
| 144 | { |
| 145 | ByteOrder byte_order = eByteOrderInvalid; |
| 146 | uint32_t addr_size = 0; |
| 147 | if (GetByteOrderAndAddressSize (exe_scope, address, byte_order, addr_size)) |
| 148 | { |
Greg Clayton | 471b31c | 2010-07-20 22:52:08 +0000 | [diff] [blame] | 149 | DataExtractor data (&buf.front(), buf.size(), byte_order, addr_size); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 150 | |
| 151 | data.Dump (strm, |
| 152 | 0, // Start offset in "data" |
| 153 | eFormatHex, // Print as characters |
| 154 | buf.size(), // Size of item |
| 155 | 1, // Items count |
| 156 | UINT32_MAX, // num per line |
| 157 | LLDB_INVALID_ADDRESS,// base address |
| 158 | 0, // bitfield bit size |
| 159 | 0); // bitfield bit offset |
| 160 | |
| 161 | return true; |
| 162 | } |
| 163 | } |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | |
| 168 | static size_t |
| 169 | ReadCStringFromMemory (ExecutionContextScope *exe_scope, const Address &address, Stream *strm) |
| 170 | { |
| 171 | if (exe_scope == NULL) |
| 172 | return 0; |
| 173 | const size_t k_buf_len = 256; |
| 174 | char buf[k_buf_len+1]; |
| 175 | buf[k_buf_len] = '\0'; // NULL terminate |
| 176 | |
Greg Clayton | 710dd5a | 2011-01-08 20:28:42 +0000 | [diff] [blame] | 177 | // Byte order and address size don't matter for C string dumping.. |
Greg Clayton | 7fb56d0 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 178 | DataExtractor data (buf, sizeof(buf), lldb::endian::InlHostByteOrder(), 4); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 179 | size_t total_len = 0; |
| 180 | size_t bytes_read; |
| 181 | Address curr_address(address); |
| 182 | strm->PutChar ('"'); |
| 183 | while ((bytes_read = ReadBytes (exe_scope, curr_address, buf, k_buf_len)) > 0) |
| 184 | { |
| 185 | size_t len = strlen(buf); |
| 186 | if (len == 0) |
| 187 | break; |
| 188 | if (len > bytes_read) |
| 189 | len = bytes_read; |
| 190 | |
| 191 | data.Dump (strm, |
| 192 | 0, // Start offset in "data" |
| 193 | eFormatChar, // Print as characters |
| 194 | 1, // Size of item (1 byte for a char!) |
| 195 | len, // How many bytes to print? |
| 196 | UINT32_MAX, // num per line |
| 197 | LLDB_INVALID_ADDRESS,// base address |
| 198 | 0, // bitfield bit size |
| 199 | |
| 200 | 0); // bitfield bit offset |
| 201 | |
| 202 | total_len += bytes_read; |
| 203 | |
| 204 | if (len < k_buf_len) |
| 205 | break; |
| 206 | curr_address.SetOffset (curr_address.GetOffset() + bytes_read); |
| 207 | } |
| 208 | strm->PutChar ('"'); |
| 209 | return total_len; |
| 210 | } |
| 211 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 212 | Address::Address (addr_t address, const SectionList * sections) : |
| 213 | m_section (NULL), |
| 214 | m_offset (LLDB_INVALID_ADDRESS) |
| 215 | { |
| 216 | ResolveAddressUsingFileSections(address, sections); |
| 217 | } |
| 218 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 219 | const Address& |
| 220 | Address::operator= (const Address& rhs) |
| 221 | { |
| 222 | if (this != &rhs) |
| 223 | { |
| 224 | m_section = rhs.m_section; |
| 225 | m_offset = rhs.m_offset; |
| 226 | } |
| 227 | return *this; |
| 228 | } |
| 229 | |
| 230 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 231 | Address::ResolveAddressUsingFileSections (addr_t addr, const SectionList *sections) |
| 232 | { |
| 233 | if (sections) |
| 234 | m_section = sections->FindSectionContainingFileAddress(addr).get(); |
| 235 | else |
| 236 | m_section = NULL; |
| 237 | |
| 238 | if (m_section != NULL) |
| 239 | { |
| 240 | assert( m_section->ContainsFileAddress(addr) ); |
| 241 | m_offset = addr - m_section->GetFileAddress(); |
| 242 | return true; // Successfully transformed addr into a section offset address |
| 243 | } |
| 244 | |
| 245 | m_offset = addr; |
| 246 | return false; // Failed to resolve this address to a section offset value |
| 247 | } |
| 248 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 249 | Module * |
| 250 | Address::GetModule () const |
| 251 | { |
| 252 | if (m_section) |
| 253 | return m_section->GetModule(); |
| 254 | return NULL; |
| 255 | } |
| 256 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 257 | addr_t |
| 258 | Address::GetFileAddress () const |
| 259 | { |
| 260 | if (m_section != NULL) |
| 261 | { |
| 262 | addr_t sect_file_addr = m_section->GetFileAddress(); |
| 263 | if (sect_file_addr == LLDB_INVALID_ADDRESS) |
| 264 | { |
| 265 | // Section isn't resolved, we can't return a valid file address |
| 266 | return LLDB_INVALID_ADDRESS; |
| 267 | } |
| 268 | // We have a valid file range, so we can return the file based |
| 269 | // address by adding the file base address to our offset |
| 270 | return sect_file_addr + m_offset; |
| 271 | } |
| 272 | // No section, we just return the offset since it is the value in this case |
| 273 | return m_offset; |
| 274 | } |
| 275 | |
| 276 | addr_t |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 277 | Address::GetLoadAddress (Target *target) const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 278 | { |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 279 | if (m_section == NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 280 | { |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 281 | // No section, we just return the offset since it is the value in this case |
| 282 | return m_offset; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 283 | } |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 284 | |
| 285 | if (target) |
| 286 | { |
| 287 | addr_t sect_load_addr = m_section->GetLoadBaseAddress (target); |
| 288 | |
| 289 | if (sect_load_addr != LLDB_INVALID_ADDRESS) |
| 290 | { |
| 291 | // We have a valid file range, so we can return the file based |
| 292 | // address by adding the file base address to our offset |
| 293 | return sect_load_addr + m_offset; |
| 294 | } |
| 295 | } |
| 296 | // The section isn't resolved or no process was supplied so we can't |
| 297 | // return a valid file address. |
| 298 | return LLDB_INVALID_ADDRESS; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Greg Clayton | 3f5c08f | 2011-05-18 22:01:49 +0000 | [diff] [blame] | 301 | addr_t |
| 302 | Address::GetCallableLoadAddress (Target *target) const |
| 303 | { |
| 304 | addr_t code_addr = GetLoadAddress (target); |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 305 | |
| 306 | if (target) |
| 307 | return target->GetCallableLoadAddress (code_addr, GetAddressClass()); |
Greg Clayton | 3f5c08f | 2011-05-18 22:01:49 +0000 | [diff] [blame] | 308 | return code_addr; |
| 309 | } |
| 310 | |
Greg Clayton | cff851a | 2011-05-22 04:32:55 +0000 | [diff] [blame] | 311 | bool |
| 312 | Address::SetCallableLoadAddress (lldb::addr_t load_addr, Target *target) |
| 313 | { |
| 314 | if (SetLoadAddress (load_addr, target)) |
| 315 | { |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 316 | if (target) |
| 317 | m_offset = target->GetCallableLoadAddress(m_offset, GetAddressClass()); |
Greg Clayton | cff851a | 2011-05-22 04:32:55 +0000 | [diff] [blame] | 318 | return true; |
| 319 | } |
| 320 | return false; |
| 321 | } |
| 322 | |
Greg Clayton | 92bb12c | 2011-05-19 18:17:41 +0000 | [diff] [blame] | 323 | addr_t |
| 324 | Address::GetOpcodeLoadAddress (Target *target) const |
| 325 | { |
| 326 | addr_t code_addr = GetLoadAddress (target); |
Greg Clayton | 92bb12c | 2011-05-19 18:17:41 +0000 | [diff] [blame] | 327 | if (code_addr != LLDB_INVALID_ADDRESS) |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 328 | code_addr = target->GetOpcodeLoadAddress (code_addr, GetAddressClass()); |
Greg Clayton | 92bb12c | 2011-05-19 18:17:41 +0000 | [diff] [blame] | 329 | return code_addr; |
| 330 | } |
| 331 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 332 | bool |
Greg Clayton | cff851a | 2011-05-22 04:32:55 +0000 | [diff] [blame] | 333 | Address::SetOpcodeLoadAddress (lldb::addr_t load_addr, Target *target) |
| 334 | { |
| 335 | if (SetLoadAddress (load_addr, target)) |
| 336 | { |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 337 | if (target) |
| 338 | m_offset = target->GetOpcodeLoadAddress (m_offset, GetAddressClass()); |
Greg Clayton | cff851a | 2011-05-22 04:32:55 +0000 | [diff] [blame] | 339 | return true; |
| 340 | } |
| 341 | return false; |
| 342 | } |
| 343 | |
| 344 | bool |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 345 | Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style, uint32_t addr_size) const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 346 | { |
| 347 | // If the section was NULL, only load address is going to work. |
| 348 | if (m_section == NULL) |
| 349 | style = DumpStyleLoadAddress; |
| 350 | |
Greg Clayton | 54b8b8c | 2010-07-01 01:26:43 +0000 | [diff] [blame] | 351 | Target *target = NULL; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 352 | Process *process = NULL; |
| 353 | if (exe_scope) |
Greg Clayton | 54b8b8c | 2010-07-01 01:26:43 +0000 | [diff] [blame] | 354 | { |
| 355 | target = exe_scope->CalculateTarget(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 356 | process = exe_scope->CalculateProcess(); |
Greg Clayton | 54b8b8c | 2010-07-01 01:26:43 +0000 | [diff] [blame] | 357 | } |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 358 | // If addr_byte_size is UINT32_MAX, then determine the correct address |
| 359 | // byte size for the process or default to the size of addr_t |
| 360 | if (addr_size == UINT32_MAX) |
| 361 | { |
| 362 | if (process) |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 363 | addr_size = target->GetArchitecture().GetAddressByteSize (); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 364 | else |
| 365 | addr_size = sizeof(addr_t); |
| 366 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 367 | |
Greg Clayton | c980066 | 2010-09-10 01:30:46 +0000 | [diff] [blame] | 368 | Address so_addr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 369 | switch (style) |
| 370 | { |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 371 | case DumpStyleInvalid: |
| 372 | return false; |
| 373 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 374 | case DumpStyleSectionNameOffset: |
| 375 | if (m_section != NULL) |
| 376 | { |
| 377 | m_section->DumpName(s); |
| 378 | s->Printf (" + %llu", m_offset); |
| 379 | } |
| 380 | else |
| 381 | { |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 382 | s->Address(m_offset, addr_size); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 383 | } |
| 384 | break; |
| 385 | |
| 386 | case DumpStyleSectionPointerOffset: |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 387 | s->Printf("(Section *)%.*p + ", (int)sizeof(void*) * 2, m_section); |
| 388 | s->Address(m_offset, addr_size); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 389 | break; |
| 390 | |
| 391 | case DumpStyleModuleWithFileAddress: |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 392 | if (m_section) |
| 393 | s->Printf("%s[", m_section->GetModule()->GetFileSpec().GetFilename().AsCString()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 394 | // Fall through |
| 395 | case DumpStyleFileAddress: |
| 396 | { |
| 397 | addr_t file_addr = GetFileAddress(); |
| 398 | if (file_addr == LLDB_INVALID_ADDRESS) |
| 399 | { |
| 400 | if (fallback_style != DumpStyleInvalid) |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 401 | return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 402 | return false; |
| 403 | } |
| 404 | s->Address (file_addr, addr_size); |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 405 | if (style == DumpStyleModuleWithFileAddress && m_section) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 406 | s->PutChar(']'); |
| 407 | } |
| 408 | break; |
| 409 | |
| 410 | case DumpStyleLoadAddress: |
| 411 | { |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 412 | addr_t load_addr = GetLoadAddress (target); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 413 | if (load_addr == LLDB_INVALID_ADDRESS) |
| 414 | { |
| 415 | if (fallback_style != DumpStyleInvalid) |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 416 | return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 417 | return false; |
| 418 | } |
| 419 | s->Address (load_addr, addr_size); |
| 420 | } |
| 421 | break; |
| 422 | |
| 423 | case DumpStyleResolvedDescription: |
Greg Clayton | 54b8b8c | 2010-07-01 01:26:43 +0000 | [diff] [blame] | 424 | case DumpStyleResolvedDescriptionNoModule: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 425 | if (IsSectionOffset()) |
| 426 | { |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 427 | AddressType addr_type = eAddressTypeLoad; |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 428 | addr_t addr = GetLoadAddress (target); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 429 | if (addr == LLDB_INVALID_ADDRESS) |
| 430 | { |
| 431 | addr = GetFileAddress(); |
| 432 | addr_type = eAddressTypeFile; |
| 433 | } |
| 434 | |
| 435 | uint32_t pointer_size = 4; |
Greg Clayton | c980066 | 2010-09-10 01:30:46 +0000 | [diff] [blame] | 436 | Module *module = GetModule(); |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 437 | if (target) |
| 438 | pointer_size = target->GetArchitecture().GetAddressByteSize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 439 | else if (module) |
| 440 | pointer_size = module->GetArchitecture().GetAddressByteSize(); |
| 441 | |
| 442 | bool showed_info = false; |
| 443 | const Section *section = GetSection(); |
| 444 | if (section) |
| 445 | { |
Greg Clayton | 70e33eb | 2010-07-21 21:49:46 +0000 | [diff] [blame] | 446 | SectionType sect_type = section->GetType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 447 | switch (sect_type) |
| 448 | { |
Greg Clayton | 8941142 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 449 | case eSectionTypeData: |
| 450 | if (module) |
| 451 | { |
| 452 | ObjectFile *objfile = module->GetObjectFile(); |
| 453 | 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); |
| 466 | addr_t delta = file_Addr - symbol->GetAddressRangePtr()->GetBaseAddress().GetFileAddress(); |
| 467 | if (delta) |
| 468 | s->Printf(" + %llu", delta); |
| 469 | showed_info = true; |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | break; |
| 476 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 477 | 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 Clayton | 54b8b8c | 2010-07-01 01:26:43 +0000 | [diff] [blame] | 502 | if (target && so_addr.IsSectionOffset()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 503 | { |
Greg Clayton | c980066 | 2010-09-10 01:30:46 +0000 | [diff] [blame] | 504 | SymbolContext func_sc; |
Greg Clayton | 54b8b8c | 2010-07-01 01:26:43 +0000 | [diff] [blame] | 505 | target->GetImages().ResolveSymbolContextForAddress (so_addr, |
| 506 | eSymbolContextEverything, |
| 507 | func_sc); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 508 | 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 Clayton | 6dadd50 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 519 | func_sc.DumpStopContext(s, exe_scope, so_addr, true, true, false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 520 | 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 Clayton | c980066 | 2010-09-10 01:30:46 +0000 | [diff] [blame] | 593 | SymbolContext pointer_sc; |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 594 | if (target) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 595 | { |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 596 | target->GetImages().ResolveSymbolContextForAddress (so_addr, |
| 597 | eSymbolContextEverything, |
| 598 | pointer_sc); |
| 599 | if (pointer_sc.function || pointer_sc.symbol) |
| 600 | { |
| 601 | s->PutCString(": "); |
Greg Clayton | 6dadd50 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 602 | pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, false); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 603 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 604 | } |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | break; |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 609 | |
| 610 | default: |
| 611 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | |
| 615 | if (!showed_info) |
| 616 | { |
| 617 | if (module) |
| 618 | { |
Greg Clayton | c980066 | 2010-09-10 01:30:46 +0000 | [diff] [blame] | 619 | SymbolContext sc; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 620 | module->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc); |
| 621 | if (sc.function || sc.symbol) |
| 622 | { |
| 623 | bool show_stop_context = true; |
Greg Clayton | 8dc0a98 | 2010-09-07 21:56:53 +0000 | [diff] [blame] | 624 | const bool show_module = (style == DumpStyleResolvedDescription); |
| 625 | const bool show_fullpaths = false; |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 626 | const bool show_inlined_frames = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 627 | if (sc.function == NULL && sc.symbol != NULL) |
| 628 | { |
| 629 | // If we have just a symbol make sure it is in the right section |
| 630 | if (sc.symbol->GetAddressRangePtr()) |
| 631 | { |
| 632 | if (sc.symbol->GetAddressRangePtr()->GetBaseAddress().GetSection() != GetSection()) |
Greg Clayton | 54b8b8c | 2010-07-01 01:26:43 +0000 | [diff] [blame] | 633 | { |
| 634 | // don't show the module if the symbol is a trampoline symbol |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 635 | show_stop_context = false; |
Greg Clayton | 54b8b8c | 2010-07-01 01:26:43 +0000 | [diff] [blame] | 636 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 637 | } |
| 638 | } |
| 639 | if (show_stop_context) |
| 640 | { |
| 641 | // We have a function or a symbol from the same |
| 642 | // sections as this address. |
Greg Clayton | 8dc0a98 | 2010-09-07 21:56:53 +0000 | [diff] [blame] | 643 | sc.DumpStopContext (s, |
| 644 | exe_scope, |
| 645 | *this, |
| 646 | show_fullpaths, |
| 647 | show_module, |
| 648 | show_inlined_frames); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 649 | } |
| 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 Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 664 | return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 665 | return false; |
| 666 | } |
| 667 | break; |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 668 | |
| 669 | case DumpStyleDetailedSymbolContext: |
| 670 | if (IsSectionOffset()) |
| 671 | { |
Greg Clayton | c980066 | 2010-09-10 01:30:46 +0000 | [diff] [blame] | 672 | Module *module = GetModule(); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 673 | if (module) |
| 674 | { |
Greg Clayton | c980066 | 2010-09-10 01:30:46 +0000 | [diff] [blame] | 675 | SymbolContext sc; |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 676 | module->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc); |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 677 | if (sc.symbol) |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 678 | { |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 679 | // 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. |
| 683 | if (sc.symbol->GetAddressRangePtr() && sc.symbol->GetAddressRangePtr()->GetBaseAddress().GetSection() != GetSection()) |
| 684 | sc.symbol = NULL; |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 685 | } |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 686 | sc.GetDescription(s, eDescriptionLevelBrief, target); |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 687 | |
| 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 | { |
| 705 | s->Printf (" Variable: id = {0x%8.8x}, name = \"%s\", type= \"%s\", location =", |
| 706 | var->GetID(), |
| 707 | var->GetName().GetCString(), |
| 708 | var->GetType()->GetName().GetCString()); |
| 709 | var->DumpLocationForAddress(s, *this); |
| 710 | s->PutCString(", decl = "); |
| 711 | var->GetDeclaration().DumpStopContext(s, false); |
| 712 | s->EOL(); |
| 713 | } |
| 714 | } |
| 715 | } |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 716 | } |
| 717 | } |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 718 | else |
| 719 | { |
| 720 | if (fallback_style != DumpStyleInvalid) |
| 721 | return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size); |
| 722 | return false; |
| 723 | } |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 724 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | return true; |
| 728 | } |
| 729 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 730 | void |
| 731 | Address::CalculateSymbolContext (SymbolContext *sc) |
| 732 | { |
| 733 | sc->Clear(); |
| 734 | // Absolute addresses don't have enough information to reconstruct even their target. |
| 735 | if (m_section == NULL) |
| 736 | return; |
| 737 | |
| 738 | if (m_section->GetModule()) |
| 739 | { |
| 740 | sc->module_sp = m_section->GetModule()->GetSP(); |
| 741 | if (sc->module_sp) |
| 742 | sc->module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextEverything, *sc); |
| 743 | } |
| 744 | } |
| 745 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 746 | int |
| 747 | Address::CompareFileAddress (const Address& a, const Address& b) |
| 748 | { |
| 749 | addr_t a_file_addr = a.GetFileAddress(); |
| 750 | addr_t b_file_addr = b.GetFileAddress(); |
| 751 | if (a_file_addr < b_file_addr) |
| 752 | return -1; |
| 753 | if (a_file_addr > b_file_addr) |
| 754 | return +1; |
| 755 | return 0; |
| 756 | } |
| 757 | |
| 758 | |
| 759 | int |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 760 | Address::CompareLoadAddress (const Address& a, const Address& b, Target *target) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 761 | { |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 762 | assert (target != NULL); |
| 763 | addr_t a_load_addr = a.GetLoadAddress (target); |
| 764 | addr_t b_load_addr = b.GetLoadAddress (target); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 765 | if (a_load_addr < b_load_addr) |
| 766 | return -1; |
| 767 | if (a_load_addr > b_load_addr) |
| 768 | return +1; |
| 769 | return 0; |
| 770 | } |
| 771 | |
| 772 | int |
| 773 | Address::CompareModulePointerAndOffset (const Address& a, const Address& b) |
| 774 | { |
| 775 | Module *a_module = a.GetModule (); |
| 776 | Module *b_module = b.GetModule (); |
| 777 | if (a_module < b_module) |
| 778 | return -1; |
| 779 | if (a_module > b_module) |
| 780 | return +1; |
| 781 | // Modules are the same, just compare the file address since they should |
| 782 | // be unique |
| 783 | addr_t a_file_addr = a.GetFileAddress(); |
| 784 | addr_t b_file_addr = b.GetFileAddress(); |
| 785 | if (a_file_addr < b_file_addr) |
| 786 | return -1; |
| 787 | if (a_file_addr > b_file_addr) |
| 788 | return +1; |
| 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | |
| 793 | size_t |
| 794 | Address::MemorySize () const |
| 795 | { |
| 796 | // Noting special for the memory size of a single Address object, |
| 797 | // it is just the size of itself. |
| 798 | return sizeof(Address); |
| 799 | } |
| 800 | |
| 801 | |
Greg Clayton | b0848c5 | 2011-01-08 00:05:12 +0000 | [diff] [blame] | 802 | //---------------------------------------------------------------------- |
| 803 | // NOTE: Be careful using this operator. It can correctly compare two |
| 804 | // addresses from the same Module correctly. It can't compare two |
| 805 | // addresses from different modules in any meaningful way, but it will |
| 806 | // compare the module pointers. |
| 807 | // |
| 808 | // To sum things up: |
| 809 | // - works great for addresses within the same module |
| 810 | // - it works for addresses across multiple modules, but don't expect the |
| 811 | // address results to make much sense |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 812 | // |
Greg Clayton | b0848c5 | 2011-01-08 00:05:12 +0000 | [diff] [blame] | 813 | // This basically lets Address objects be used in ordered collection |
| 814 | // classes. |
| 815 | //---------------------------------------------------------------------- |
| 816 | |
| 817 | bool |
| 818 | lldb_private::operator< (const Address& lhs, const Address& rhs) |
| 819 | { |
| 820 | Module *lhs_module = lhs.GetModule(); |
| 821 | Module *rhs_module = rhs.GetModule(); |
| 822 | if (lhs_module == rhs_module) |
| 823 | { |
| 824 | // Addresses are in the same module, just compare the file addresses |
| 825 | return lhs.GetFileAddress() < rhs.GetFileAddress(); |
| 826 | } |
| 827 | else |
| 828 | { |
| 829 | // The addresses are from different modules, just use the module |
| 830 | // pointer value to get consistent ordering |
| 831 | return lhs_module < rhs_module; |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | bool |
| 836 | lldb_private::operator> (const Address& lhs, const Address& rhs) |
| 837 | { |
| 838 | Module *lhs_module = lhs.GetModule(); |
| 839 | Module *rhs_module = rhs.GetModule(); |
| 840 | if (lhs_module == rhs_module) |
| 841 | { |
| 842 | // Addresses are in the same module, just compare the file addresses |
| 843 | return lhs.GetFileAddress() > rhs.GetFileAddress(); |
| 844 | } |
| 845 | else |
| 846 | { |
| 847 | // The addresses are from different modules, just use the module |
| 848 | // pointer value to get consistent ordering |
| 849 | return lhs_module > rhs_module; |
| 850 | } |
| 851 | } |
| 852 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 853 | |
| 854 | // The operator == checks for exact equality only (same section, same offset) |
| 855 | bool |
| 856 | lldb_private::operator== (const Address& a, const Address& rhs) |
| 857 | { |
| 858 | return a.GetSection() == rhs.GetSection() && |
| 859 | a.GetOffset() == rhs.GetOffset(); |
| 860 | } |
| 861 | // The operator != checks for exact inequality only (differing section, or |
| 862 | // different offset) |
| 863 | bool |
| 864 | lldb_private::operator!= (const Address& a, const Address& rhs) |
| 865 | { |
| 866 | return a.GetSection() != rhs.GetSection() || |
| 867 | a.GetOffset() != rhs.GetOffset(); |
| 868 | } |
| 869 | |
| 870 | bool |
| 871 | Address::IsLinkedAddress () const |
| 872 | { |
| 873 | return m_section && m_section->GetLinkedSection(); |
| 874 | } |
| 875 | |
| 876 | |
| 877 | void |
| 878 | Address::ResolveLinkedAddress () |
| 879 | { |
| 880 | if (m_section) |
| 881 | { |
| 882 | const Section *linked_section = m_section->GetLinkedSection(); |
| 883 | if (linked_section) |
| 884 | { |
| 885 | m_offset += m_section->GetLinkedOffset(); |
| 886 | m_section = linked_section; |
| 887 | } |
| 888 | } |
| 889 | } |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 890 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 891 | AddressClass |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 892 | Address::GetAddressClass () const |
| 893 | { |
| 894 | Module *module = GetModule(); |
| 895 | if (module) |
| 896 | { |
| 897 | ObjectFile *obj_file = module->GetObjectFile(); |
| 898 | if (obj_file) |
| 899 | return obj_file->GetAddressClass (GetFileAddress()); |
| 900 | } |
| 901 | return eAddressClassUnknown; |
| 902 | } |
Greg Clayton | cd482e3 | 2011-05-18 01:58:14 +0000 | [diff] [blame] | 903 | |
| 904 | bool |
| 905 | Address::SetLoadAddress (lldb::addr_t load_addr, Target *target) |
| 906 | { |
| 907 | if (target && target->GetSectionLoadList().ResolveLoadAddress(load_addr, *this)) |
| 908 | return true; |
| 909 | m_section = NULL; |
| 910 | m_offset = load_addr; |
| 911 | return false; |
| 912 | } |
| 913 | |