Chris Lattner | 24943d2 | 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" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 13 | #include "lldb/Symbol/Block.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | #include "lldb/Symbol/ObjectFile.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 15 | #include "lldb/Symbol/Type.h" |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 16 | #include "lldb/Symbol/Variable.h" |
| 17 | #include "lldb/Symbol/VariableList.h" |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 18 | #include "lldb/Target/ExecutionContext.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Target/Process.h" |
| 20 | #include "lldb/Target/Target.h" |
| 21 | |
Greg Clayton | da7af84 | 2011-05-18 22:01:49 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/Triple.h" |
| 23 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | using namespace lldb; |
| 25 | using namespace lldb_private; |
| 26 | |
| 27 | static size_t |
| 28 | ReadBytes (ExecutionContextScope *exe_scope, const Address &address, void *dst, size_t dst_len) |
| 29 | { |
| 30 | if (exe_scope == NULL) |
| 31 | return 0; |
| 32 | |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 33 | TargetSP target_sp (exe_scope->CalculateTarget()); |
| 34 | if (target_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | { |
| 36 | Error error; |
Greg Clayton | 26100dc | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 37 | bool prefer_file_cache = false; |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 38 | return target_sp->ReadMemory (address, prefer_file_cache, dst, dst_len, error); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | } |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static bool |
| 44 | GetByteOrderAndAddressSize (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 Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 51 | TargetSP target_sp (exe_scope->CalculateTarget()); |
| 52 | if (target_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | { |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 54 | byte_order = target_sp->GetArchitecture().GetByteOrder(); |
| 55 | addr_size = target_sp->GetArchitecture().GetAddressByteSize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | if (byte_order == eByteOrderInvalid || addr_size == 0) |
| 59 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 60 | ModuleSP module_sp (address.GetModule()); |
| 61 | if (module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 63 | byte_order = module_sp->GetArchitecture().GetByteOrder(); |
| 64 | addr_size = module_sp->GetArchitecture().GetAddressByteSize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | return byte_order != eByteOrderInvalid && addr_size != 0; |
| 68 | } |
| 69 | |
| 70 | static uint64_t |
| 71 | ReadUIntMax64 (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 Chen | 451d02b | 2011-08-25 17:40:39 +0000 | [diff] [blame] | 79 | uint64_t buf = 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | |
| 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 | |
| 98 | static bool |
| 99 | ReadAddress (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 Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 109 | ExecutionContext exe_ctx; |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 110 | exe_scope->CalculateExecutionContext(exe_ctx); |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 111 | // If we have any sections that are loaded, try and resolve using the |
| 112 | // section load list |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 113 | Target *target = exe_ctx.GetTargetPtr(); |
| 114 | if (target && !target->GetSectionLoadList().IsEmpty()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 116 | if (target->GetSectionLoadList().ResolveLoadAddress (deref_addr, deref_so_addr)) |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 117 | return true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 118 | } |
| 119 | else |
| 120 | { |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 121 | // If we were not running, yet able to read an integer, we must |
| 122 | // have a module |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 123 | ModuleSP module_sp (address.GetModule()); |
| 124 | |
| 125 | assert (module_sp); |
| 126 | if (module_sp->ResolveFileAddress(deref_addr, deref_so_addr)) |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 127 | return true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 128 | } |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 129 | |
| 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 Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 133 | deref_so_addr.SetRawAddress(deref_addr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 134 | return true; |
| 135 | } |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | static bool |
| 140 | DumpUInt (ExecutionContextScope *exe_scope, const Address &address, uint32_t byte_size, Stream* strm) |
| 141 | { |
Greg Clayton | 53d68e7 | 2010-07-20 22:52:08 +0000 | [diff] [blame] | 142 | if (exe_scope == NULL || byte_size == 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 143 | 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 Clayton | 53d68e7 | 2010-07-20 22:52:08 +0000 | [diff] [blame] | 152 | DataExtractor data (&buf.front(), buf.size(), byte_order, addr_size); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 153 | |
| 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 | |
| 171 | static size_t |
| 172 | ReadCStringFromMemory (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 Clayton | 5d187e5 | 2011-01-08 20:28:42 +0000 | [diff] [blame] | 180 | // Byte order and address size don't matter for C string dumping.. |
Greg Clayton | cd54803 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 181 | DataExtractor data (buf, sizeof(buf), lldb::endian::InlHostByteOrder(), 4); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 182 | 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 Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 215 | Address::Address (lldb::addr_t abs_addr) : |
| 216 | m_section_wp (), |
| 217 | m_offset (abs_addr) |
| 218 | { |
| 219 | } |
| 220 | |
| 221 | Address::Address (addr_t address, const SectionList *section_list) : |
| 222 | m_section_wp (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 223 | m_offset (LLDB_INVALID_ADDRESS) |
| 224 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 225 | ResolveAddressUsingFileSections(address, section_list); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 228 | const Address& |
| 229 | Address::operator= (const Address& rhs) |
| 230 | { |
| 231 | if (this != &rhs) |
| 232 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 233 | m_section_wp = rhs.m_section_wp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 234 | m_offset = rhs.m_offset; |
| 235 | } |
| 236 | return *this; |
| 237 | } |
| 238 | |
| 239 | bool |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 240 | Address::ResolveAddressUsingFileSections (addr_t file_addr, const SectionList *section_list) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 241 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 242 | if (section_list) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 243 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 244 | 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 252 | } |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 253 | m_offset = file_addr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 254 | return false; // Failed to resolve this address to a section offset value |
| 255 | } |
| 256 | |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 257 | ModuleSP |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 258 | Address::GetModule () const |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 259 | { |
| 260 | lldb::ModuleSP module_sp; |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 261 | SectionSP section_sp (GetSection()); |
| 262 | if (section_sp) |
| 263 | module_sp = section_sp->GetModule(); |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 264 | return module_sp; |
| 265 | } |
| 266 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 267 | addr_t |
| 268 | Address::GetFileAddress () const |
| 269 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 270 | SectionSP section_sp (GetSection()); |
| 271 | if (section_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 272 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 273 | addr_t sect_file_addr = section_sp->GetFileAddress(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 274 | 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 | |
| 287 | addr_t |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 288 | Address::GetLoadAddress (Target *target) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 289 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 290 | SectionSP section_sp (GetSection()); |
| 291 | if (!section_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 292 | { |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 293 | // No section, we just return the offset since it is the value in this case |
| 294 | return m_offset; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 295 | } |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 296 | |
| 297 | if (target) |
| 298 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 299 | addr_t sect_load_addr = section_sp->GetLoadBaseAddress (target); |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 300 | |
| 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Greg Clayton | da7af84 | 2011-05-18 22:01:49 +0000 | [diff] [blame] | 313 | addr_t |
| 314 | Address::GetCallableLoadAddress (Target *target) const |
| 315 | { |
| 316 | addr_t code_addr = GetLoadAddress (target); |
Greg Clayton | c0fa533 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 317 | |
| 318 | if (target) |
| 319 | return target->GetCallableLoadAddress (code_addr, GetAddressClass()); |
Greg Clayton | da7af84 | 2011-05-18 22:01:49 +0000 | [diff] [blame] | 320 | return code_addr; |
| 321 | } |
| 322 | |
Greg Clayton | 5a26910 | 2011-05-22 04:32:55 +0000 | [diff] [blame] | 323 | bool |
| 324 | Address::SetCallableLoadAddress (lldb::addr_t load_addr, Target *target) |
| 325 | { |
| 326 | if (SetLoadAddress (load_addr, target)) |
| 327 | { |
Greg Clayton | c0fa533 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 328 | if (target) |
| 329 | m_offset = target->GetCallableLoadAddress(m_offset, GetAddressClass()); |
Greg Clayton | 5a26910 | 2011-05-22 04:32:55 +0000 | [diff] [blame] | 330 | return true; |
| 331 | } |
| 332 | return false; |
| 333 | } |
| 334 | |
Greg Clayton | 265ab33 | 2011-05-19 18:17:41 +0000 | [diff] [blame] | 335 | addr_t |
| 336 | Address::GetOpcodeLoadAddress (Target *target) const |
| 337 | { |
| 338 | addr_t code_addr = GetLoadAddress (target); |
Greg Clayton | 265ab33 | 2011-05-19 18:17:41 +0000 | [diff] [blame] | 339 | if (code_addr != LLDB_INVALID_ADDRESS) |
Greg Clayton | c0fa533 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 340 | code_addr = target->GetOpcodeLoadAddress (code_addr, GetAddressClass()); |
Greg Clayton | 265ab33 | 2011-05-19 18:17:41 +0000 | [diff] [blame] | 341 | return code_addr; |
| 342 | } |
| 343 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 344 | bool |
Greg Clayton | 5a26910 | 2011-05-22 04:32:55 +0000 | [diff] [blame] | 345 | Address::SetOpcodeLoadAddress (lldb::addr_t load_addr, Target *target) |
| 346 | { |
| 347 | if (SetLoadAddress (load_addr, target)) |
| 348 | { |
Greg Clayton | c0fa533 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 349 | if (target) |
| 350 | m_offset = target->GetOpcodeLoadAddress (m_offset, GetAddressClass()); |
Greg Clayton | 5a26910 | 2011-05-22 04:32:55 +0000 | [diff] [blame] | 351 | return true; |
| 352 | } |
| 353 | return false; |
| 354 | } |
| 355 | |
| 356 | bool |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 357 | Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style, uint32_t addr_size) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 358 | { |
Greg Clayton | 941f5da | 2012-07-11 22:18:24 +0000 | [diff] [blame] | 359 | // If the section was NULL, only load address is going to work unless we are |
| 360 | // trying to deref a pointer |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 361 | SectionSP section_sp (GetSection()); |
Greg Clayton | 941f5da | 2012-07-11 22:18:24 +0000 | [diff] [blame] | 362 | if (!section_sp && style != DumpStyleResolvedPointerDescription) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 363 | style = DumpStyleLoadAddress; |
| 364 | |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 365 | ExecutionContext exe_ctx (exe_scope); |
| 366 | Target *target = exe_ctx.GetTargetPtr(); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 367 | // 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 Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 371 | if (target) |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 372 | addr_size = target->GetArchitecture().GetAddressByteSize (); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 373 | else |
| 374 | addr_size = sizeof(addr_t); |
| 375 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 376 | |
Greg Clayton | c67b7d1 | 2010-09-10 01:30:46 +0000 | [diff] [blame] | 377 | Address so_addr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 378 | switch (style) |
| 379 | { |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 380 | case DumpStyleInvalid: |
| 381 | return false; |
| 382 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 383 | case DumpStyleSectionNameOffset: |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 384 | if (section_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 385 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 386 | section_sp->DumpName(s); |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 387 | s->Printf (" + %" PRIu64, m_offset); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 388 | } |
| 389 | else |
| 390 | { |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 391 | s->Address(m_offset, addr_size); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 392 | } |
| 393 | break; |
| 394 | |
| 395 | case DumpStyleSectionPointerOffset: |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 396 | s->Printf("(Section *)%p + ", section_sp.get()); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 397 | s->Address(m_offset, addr_size); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 398 | break; |
| 399 | |
| 400 | case DumpStyleModuleWithFileAddress: |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 401 | if (section_sp) |
| 402 | s->Printf("%s[", section_sp->GetModule()->GetFileSpec().GetFilename().AsCString()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 403 | // 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 Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 410 | return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 411 | return false; |
| 412 | } |
| 413 | s->Address (file_addr, addr_size); |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 414 | if (style == DumpStyleModuleWithFileAddress && section_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 415 | s->PutChar(']'); |
| 416 | } |
| 417 | break; |
| 418 | |
| 419 | case DumpStyleLoadAddress: |
| 420 | { |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 421 | addr_t load_addr = GetLoadAddress (target); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 422 | if (load_addr == LLDB_INVALID_ADDRESS) |
| 423 | { |
| 424 | if (fallback_style != DumpStyleInvalid) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 425 | return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 426 | return false; |
| 427 | } |
| 428 | s->Address (load_addr, addr_size); |
| 429 | } |
| 430 | break; |
| 431 | |
| 432 | case DumpStyleResolvedDescription: |
Greg Clayton | cf7f1ad | 2010-07-01 01:26:43 +0000 | [diff] [blame] | 433 | case DumpStyleResolvedDescriptionNoModule: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 434 | if (IsSectionOffset()) |
| 435 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 436 | uint32_t pointer_size = 4; |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 437 | ModuleSP module_sp (GetModule()); |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 438 | if (target) |
| 439 | pointer_size = target->GetArchitecture().GetAddressByteSize(); |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 440 | else if (module_sp) |
| 441 | pointer_size = module_sp->GetArchitecture().GetAddressByteSize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 442 | |
| 443 | bool showed_info = false; |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 444 | if (section_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 445 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 446 | SectionType sect_type = section_sp->GetType(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 447 | switch (sect_type) |
| 448 | { |
Greg Clayton | 3fed8b9 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 449 | case eSectionTypeData: |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 450 | if (module_sp) |
Greg Clayton | 3fed8b9 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 451 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 452 | ObjectFile *objfile = module_sp->GetObjectFile(); |
Greg Clayton | 3fed8b9 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 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); |
Greg Clayton | 0c31d3d | 2012-03-07 21:03:09 +0000 | [diff] [blame] | 466 | addr_t delta = file_Addr - symbol->GetAddress().GetFileAddress(); |
Greg Clayton | 3fed8b9 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 467 | if (delta) |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 468 | s->Printf(" + %" PRIu64, delta); |
Greg Clayton | 3fed8b9 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 469 | showed_info = true; |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | break; |
| 476 | |
Chris Lattner | 24943d2 | 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 | cf7f1ad | 2010-07-01 01:26:43 +0000 | [diff] [blame] | 502 | if (target && so_addr.IsSectionOffset()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 503 | { |
Greg Clayton | c67b7d1 | 2010-09-10 01:30:46 +0000 | [diff] [blame] | 504 | SymbolContext func_sc; |
Greg Clayton | cf7f1ad | 2010-07-01 01:26:43 +0000 | [diff] [blame] | 505 | target->GetImages().ResolveSymbolContextForAddress (so_addr, |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 506 | eSymbolContextEverything, |
| 507 | func_sc); |
Chris Lattner | 24943d2 | 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 | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 519 | func_sc.DumpStopContext(s, exe_scope, so_addr, true, true, false); |
Chris Lattner | 24943d2 | 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 | c67b7d1 | 2010-09-10 01:30:46 +0000 | [diff] [blame] | 593 | SymbolContext pointer_sc; |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 594 | if (target) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 595 | { |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 596 | target->GetImages().ResolveSymbolContextForAddress (so_addr, |
Greg Clayton | 289afcb | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 597 | eSymbolContextEverything, |
| 598 | pointer_sc); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 599 | if (pointer_sc.function || pointer_sc.symbol) |
| 600 | { |
| 601 | s->PutCString(": "); |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 602 | pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, false); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 603 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 604 | } |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | break; |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 609 | |
| 610 | default: |
| 611 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | |
| 615 | if (!showed_info) |
| 616 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 617 | if (module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 618 | { |
Greg Clayton | c67b7d1 | 2010-09-10 01:30:46 +0000 | [diff] [blame] | 619 | SymbolContext sc; |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 620 | module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 621 | if (sc.function || sc.symbol) |
| 622 | { |
| 623 | bool show_stop_context = true; |
Greg Clayton | b47e69e | 2010-09-07 21:56:53 +0000 | [diff] [blame] | 624 | const bool show_module = (style == DumpStyleResolvedDescription); |
| 625 | const bool show_fullpaths = false; |
Greg Clayton | 7e2f91c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 626 | const bool show_inlined_frames = true; |
Chris Lattner | 24943d2 | 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 |
Greg Clayton | 0c31d3d | 2012-03-07 21:03:09 +0000 | [diff] [blame] | 630 | if (sc.symbol->ValueIsAddress()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 631 | { |
Greg Clayton | 0c31d3d | 2012-03-07 21:03:09 +0000 | [diff] [blame] | 632 | if (sc.symbol->GetAddress().GetSection() != GetSection()) |
Greg Clayton | cf7f1ad | 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 | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 635 | show_stop_context = false; |
Greg Clayton | cf7f1ad | 2010-07-01 01:26:43 +0000 | [diff] [blame] | 636 | } |
Chris Lattner | 24943d2 | 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 | b47e69e | 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 | 24943d2 | 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 | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 664 | return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 665 | return false; |
| 666 | } |
| 667 | break; |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 668 | |
| 669 | case DumpStyleDetailedSymbolContext: |
| 670 | if (IsSectionOffset()) |
| 671 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 672 | ModuleSP module_sp (GetModule()); |
| 673 | if (module_sp) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 674 | { |
Greg Clayton | c67b7d1 | 2010-09-10 01:30:46 +0000 | [diff] [blame] | 675 | SymbolContext sc; |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 676 | module_sp->ResolveSymbolContextForAddress(*this, eSymbolContextEverything, sc); |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 677 | if (sc.symbol) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 678 | { |
Greg Clayton | 960d6a4 | 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. |
Greg Clayton | 0c31d3d | 2012-03-07 21:03:09 +0000 | [diff] [blame] | 683 | if (sc.symbol->ValueIsAddress() && sc.symbol->GetAddress().GetSection() != GetSection()) |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 684 | sc.symbol = NULL; |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 685 | } |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 686 | sc.GetDescription(s, eDescriptionLevelBrief, target); |
Greg Clayton | 9b82f86 | 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 | { |
Greg Clayton | 2ad894b | 2012-05-15 18:43:44 +0000 | [diff] [blame] | 705 | s->Indent(); |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 706 | s->Printf (" Variable: id = {0x%8.8" PRIx64 "}, name = \"%s\", type= \"%s\", location =", |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 707 | 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 Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 717 | } |
| 718 | } |
Greg Clayton | 9b82f86 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 719 | else |
| 720 | { |
| 721 | if (fallback_style != DumpStyleInvalid) |
| 722 | return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size); |
| 723 | return false; |
| 724 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 725 | break; |
Greg Clayton | 941f5da | 2012-07-11 22:18:24 +0000 | [diff] [blame] | 726 | 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | return true; |
| 760 | } |
| 761 | |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 762 | uint32_t |
Greg Clayton | c5d14e6 | 2011-12-10 21:05:26 +0000 | [diff] [blame] | 763 | Address::CalculateSymbolContext (SymbolContext *sc, uint32_t resolve_scope) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 764 | { |
| 765 | sc->Clear(); |
| 766 | // Absolute addresses don't have enough information to reconstruct even their target. |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 767 | |
| 768 | SectionSP section_sp (GetSection()); |
| 769 | if (section_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 770 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 771 | ModuleSP module_sp (section_sp->GetModule()); |
| 772 | if (module_sp) |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 773 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 774 | sc->module_sp = module_sp; |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 775 | if (sc->module_sp) |
| 776 | return sc->module_sp->ResolveSymbolContextForAddress (*this, resolve_scope, *sc); |
| 777 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 778 | } |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 779 | return 0; |
| 780 | } |
| 781 | |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 782 | ModuleSP |
Greg Clayton | c5d14e6 | 2011-12-10 21:05:26 +0000 | [diff] [blame] | 783 | Address::CalculateSymbolContextModule () const |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 784 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 785 | SectionSP section_sp (GetSection()); |
| 786 | if (section_sp) |
| 787 | return section_sp->GetModule(); |
| 788 | return ModuleSP(); |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | CompileUnit * |
Greg Clayton | c5d14e6 | 2011-12-10 21:05:26 +0000 | [diff] [blame] | 792 | Address::CalculateSymbolContextCompileUnit () const |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 793 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 794 | SectionSP section_sp (GetSection()); |
| 795 | if (section_sp) |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 796 | { |
| 797 | SymbolContext sc; |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 798 | sc.module_sp = section_sp->GetModule(); |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 799 | 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 | |
| 808 | Function * |
Greg Clayton | c5d14e6 | 2011-12-10 21:05:26 +0000 | [diff] [blame] | 809 | Address::CalculateSymbolContextFunction () const |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 810 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 811 | SectionSP section_sp (GetSection()); |
| 812 | if (section_sp) |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 813 | { |
| 814 | SymbolContext sc; |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 815 | sc.module_sp = section_sp->GetModule(); |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 816 | if (sc.module_sp) |
| 817 | { |
| 818 | sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextFunction, sc); |
| 819 | return sc.function; |
| 820 | } |
| 821 | } |
| 822 | return NULL; |
| 823 | } |
| 824 | |
| 825 | Block * |
Greg Clayton | c5d14e6 | 2011-12-10 21:05:26 +0000 | [diff] [blame] | 826 | Address::CalculateSymbolContextBlock () const |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 827 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 828 | SectionSP section_sp (GetSection()); |
| 829 | if (section_sp) |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 830 | { |
| 831 | SymbolContext sc; |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 832 | sc.module_sp = section_sp->GetModule(); |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 833 | if (sc.module_sp) |
| 834 | { |
| 835 | sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextBlock, sc); |
| 836 | return sc.block; |
| 837 | } |
| 838 | } |
| 839 | return NULL; |
| 840 | } |
| 841 | |
| 842 | Symbol * |
Greg Clayton | c5d14e6 | 2011-12-10 21:05:26 +0000 | [diff] [blame] | 843 | Address::CalculateSymbolContextSymbol () const |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 844 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 845 | SectionSP section_sp (GetSection()); |
| 846 | if (section_sp) |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 847 | { |
| 848 | SymbolContext sc; |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 849 | sc.module_sp = section_sp->GetModule(); |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 850 | if (sc.module_sp) |
| 851 | { |
| 852 | sc.module_sp->ResolveSymbolContextForAddress (*this, eSymbolContextSymbol, sc); |
| 853 | return sc.symbol; |
| 854 | } |
| 855 | } |
| 856 | return NULL; |
| 857 | } |
| 858 | |
| 859 | bool |
Greg Clayton | c5d14e6 | 2011-12-10 21:05:26 +0000 | [diff] [blame] | 860 | Address::CalculateSymbolContextLineEntry (LineEntry &line_entry) const |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 861 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 862 | SectionSP section_sp (GetSection()); |
| 863 | if (section_sp) |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 864 | { |
| 865 | SymbolContext sc; |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 866 | sc.module_sp = section_sp->GetModule(); |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 867 | 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 879 | } |
| 880 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 881 | int |
| 882 | Address::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 | |
| 894 | int |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 895 | Address::CompareLoadAddress (const Address& a, const Address& b, Target *target) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 896 | { |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 897 | assert (target != NULL); |
| 898 | addr_t a_load_addr = a.GetLoadAddress (target); |
| 899 | addr_t b_load_addr = b.GetLoadAddress (target); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 900 | 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 | |
| 907 | int |
| 908 | Address::CompareModulePointerAndOffset (const Address& a, const Address& b) |
| 909 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 910 | 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 914 | 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 | |
| 930 | size_t |
| 931 | Address::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 Clayton | e2f9064 | 2011-01-08 00:05:12 +0000 | [diff] [blame] | 939 | //---------------------------------------------------------------------- |
| 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 949 | // |
Greg Clayton | e2f9064 | 2011-01-08 00:05:12 +0000 | [diff] [blame] | 950 | // This basically lets Address objects be used in ordered collection |
| 951 | // classes. |
| 952 | //---------------------------------------------------------------------- |
| 953 | |
| 954 | bool |
| 955 | lldb_private::operator< (const Address& lhs, const Address& rhs) |
| 956 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 957 | 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 Clayton | e2f9064 | 2011-01-08 00:05:12 +0000 | [diff] [blame] | 961 | 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 | |
| 974 | bool |
| 975 | lldb_private::operator> (const Address& lhs, const Address& rhs) |
| 976 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 977 | 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 Clayton | e2f9064 | 2011-01-08 00:05:12 +0000 | [diff] [blame] | 981 | 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 994 | |
| 995 | // The operator == checks for exact equality only (same section, same offset) |
| 996 | bool |
| 997 | lldb_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) |
| 1004 | bool |
| 1005 | lldb_private::operator!= (const Address& a, const Address& rhs) |
| 1006 | { |
| 1007 | return a.GetSection() != rhs.GetSection() || |
| 1008 | a.GetOffset() != rhs.GetOffset(); |
| 1009 | } |
| 1010 | |
| 1011 | bool |
| 1012 | Address::IsLinkedAddress () const |
| 1013 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1014 | SectionSP section_sp (GetSection()); |
| 1015 | return section_sp && section_sp->GetLinkedSection(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | |
| 1019 | void |
| 1020 | Address::ResolveLinkedAddress () |
| 1021 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1022 | SectionSP section_sp (GetSection()); |
| 1023 | if (section_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1024 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1025 | SectionSP linked_section_sp (section_sp->GetLinkedSection()); |
| 1026 | if (linked_section_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1027 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1028 | m_offset += section_sp->GetLinkedOffset(); |
| 1029 | m_section_wp = linked_section_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1030 | } |
| 1031 | } |
| 1032 | } |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 1033 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1034 | AddressClass |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 1035 | Address::GetAddressClass () const |
| 1036 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1037 | ModuleSP module_sp (GetModule()); |
| 1038 | if (module_sp) |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 1039 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1040 | ObjectFile *obj_file = module_sp->GetObjectFile(); |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 1041 | if (obj_file) |
| 1042 | return obj_file->GetAddressClass (GetFileAddress()); |
| 1043 | } |
| 1044 | return eAddressClassUnknown; |
| 1045 | } |
Greg Clayton | b9e8f6e | 2011-05-18 01:58:14 +0000 | [diff] [blame] | 1046 | |
| 1047 | bool |
| 1048 | Address::SetLoadAddress (lldb::addr_t load_addr, Target *target) |
| 1049 | { |
| 1050 | if (target && target->GetSectionLoadList().ResolveLoadAddress(load_addr, *this)) |
| 1051 | return true; |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1052 | m_section_wp.reset(); |
Greg Clayton | b9e8f6e | 2011-05-18 01:58:14 +0000 | [diff] [blame] | 1053 | m_offset = load_addr; |
| 1054 | return false; |
| 1055 | } |
| 1056 | |