1 //===-- DWARFExpression.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/Expression/DWARFExpression.h" 11 12 // C Includes 13 #include <inttypes.h> 14 15 // C++ Includes 16 #include <vector> 17 18 #include "lldb/Core/DataEncoder.h" 19 #include "lldb/Core/dwarf.h" 20 #include "lldb/Core/Log.h" 21 #include "lldb/Core/RegisterValue.h" 22 #include "lldb/Core/StreamString.h" 23 #include "lldb/Core/Scalar.h" 24 #include "lldb/Core/Value.h" 25 #include "lldb/Core/VMRange.h" 26 27 #include "lldb/Expression/ClangExpressionDeclMap.h" 28 #include "Plugins/ExpressionParser/Clang/ClangExpressionVariable.h" 29 30 #include "lldb/Host/Endian.h" 31 #include "lldb/Host/Host.h" 32 33 #include "lldb/Target/ABI.h" 34 #include "lldb/Target/ExecutionContext.h" 35 #include "lldb/Target/Process.h" 36 #include "lldb/Target/RegisterContext.h" 37 #include "lldb/Target/StackFrame.h" 38 #include "lldb/Target/StackID.h" 39 #include "lldb/Target/Thread.h" 40 41 #include "Plugins/SymbolFile/DWARF/DWARFCompileUnit.h" 42 43 using namespace lldb; 44 using namespace lldb_private; 45 46 // TODO- why is this also defined (in a better way) in DWARFDefines.cpp? 47 const char * 48 DW_OP_value_to_name (uint32_t val) 49 { 50 static char invalid[100]; 51 switch (val) { 52 case 0x03: return "DW_OP_addr"; 53 case 0x06: return "DW_OP_deref"; 54 case 0x08: return "DW_OP_const1u"; 55 case 0x09: return "DW_OP_const1s"; 56 case 0x0a: return "DW_OP_const2u"; 57 case 0x0b: return "DW_OP_const2s"; 58 case 0x0c: return "DW_OP_const4u"; 59 case 0x0d: return "DW_OP_const4s"; 60 case 0x0e: return "DW_OP_const8u"; 61 case 0x0f: return "DW_OP_const8s"; 62 case 0x10: return "DW_OP_constu"; 63 case 0x11: return "DW_OP_consts"; 64 case 0x12: return "DW_OP_dup"; 65 case 0x13: return "DW_OP_drop"; 66 case 0x14: return "DW_OP_over"; 67 case 0x15: return "DW_OP_pick"; 68 case 0x16: return "DW_OP_swap"; 69 case 0x17: return "DW_OP_rot"; 70 case 0x18: return "DW_OP_xderef"; 71 case 0x19: return "DW_OP_abs"; 72 case 0x1a: return "DW_OP_and"; 73 case 0x1b: return "DW_OP_div"; 74 case 0x1c: return "DW_OP_minus"; 75 case 0x1d: return "DW_OP_mod"; 76 case 0x1e: return "DW_OP_mul"; 77 case 0x1f: return "DW_OP_neg"; 78 case 0x20: return "DW_OP_not"; 79 case 0x21: return "DW_OP_or"; 80 case 0x22: return "DW_OP_plus"; 81 case 0x23: return "DW_OP_plus_uconst"; 82 case 0x24: return "DW_OP_shl"; 83 case 0x25: return "DW_OP_shr"; 84 case 0x26: return "DW_OP_shra"; 85 case 0x27: return "DW_OP_xor"; 86 case 0x2f: return "DW_OP_skip"; 87 case 0x28: return "DW_OP_bra"; 88 case 0x29: return "DW_OP_eq"; 89 case 0x2a: return "DW_OP_ge"; 90 case 0x2b: return "DW_OP_gt"; 91 case 0x2c: return "DW_OP_le"; 92 case 0x2d: return "DW_OP_lt"; 93 case 0x2e: return "DW_OP_ne"; 94 case 0x30: return "DW_OP_lit0"; 95 case 0x31: return "DW_OP_lit1"; 96 case 0x32: return "DW_OP_lit2"; 97 case 0x33: return "DW_OP_lit3"; 98 case 0x34: return "DW_OP_lit4"; 99 case 0x35: return "DW_OP_lit5"; 100 case 0x36: return "DW_OP_lit6"; 101 case 0x37: return "DW_OP_lit7"; 102 case 0x38: return "DW_OP_lit8"; 103 case 0x39: return "DW_OP_lit9"; 104 case 0x3a: return "DW_OP_lit10"; 105 case 0x3b: return "DW_OP_lit11"; 106 case 0x3c: return "DW_OP_lit12"; 107 case 0x3d: return "DW_OP_lit13"; 108 case 0x3e: return "DW_OP_lit14"; 109 case 0x3f: return "DW_OP_lit15"; 110 case 0x40: return "DW_OP_lit16"; 111 case 0x41: return "DW_OP_lit17"; 112 case 0x42: return "DW_OP_lit18"; 113 case 0x43: return "DW_OP_lit19"; 114 case 0x44: return "DW_OP_lit20"; 115 case 0x45: return "DW_OP_lit21"; 116 case 0x46: return "DW_OP_lit22"; 117 case 0x47: return "DW_OP_lit23"; 118 case 0x48: return "DW_OP_lit24"; 119 case 0x49: return "DW_OP_lit25"; 120 case 0x4a: return "DW_OP_lit26"; 121 case 0x4b: return "DW_OP_lit27"; 122 case 0x4c: return "DW_OP_lit28"; 123 case 0x4d: return "DW_OP_lit29"; 124 case 0x4e: return "DW_OP_lit30"; 125 case 0x4f: return "DW_OP_lit31"; 126 case 0x50: return "DW_OP_reg0"; 127 case 0x51: return "DW_OP_reg1"; 128 case 0x52: return "DW_OP_reg2"; 129 case 0x53: return "DW_OP_reg3"; 130 case 0x54: return "DW_OP_reg4"; 131 case 0x55: return "DW_OP_reg5"; 132 case 0x56: return "DW_OP_reg6"; 133 case 0x57: return "DW_OP_reg7"; 134 case 0x58: return "DW_OP_reg8"; 135 case 0x59: return "DW_OP_reg9"; 136 case 0x5a: return "DW_OP_reg10"; 137 case 0x5b: return "DW_OP_reg11"; 138 case 0x5c: return "DW_OP_reg12"; 139 case 0x5d: return "DW_OP_reg13"; 140 case 0x5e: return "DW_OP_reg14"; 141 case 0x5f: return "DW_OP_reg15"; 142 case 0x60: return "DW_OP_reg16"; 143 case 0x61: return "DW_OP_reg17"; 144 case 0x62: return "DW_OP_reg18"; 145 case 0x63: return "DW_OP_reg19"; 146 case 0x64: return "DW_OP_reg20"; 147 case 0x65: return "DW_OP_reg21"; 148 case 0x66: return "DW_OP_reg22"; 149 case 0x67: return "DW_OP_reg23"; 150 case 0x68: return "DW_OP_reg24"; 151 case 0x69: return "DW_OP_reg25"; 152 case 0x6a: return "DW_OP_reg26"; 153 case 0x6b: return "DW_OP_reg27"; 154 case 0x6c: return "DW_OP_reg28"; 155 case 0x6d: return "DW_OP_reg29"; 156 case 0x6e: return "DW_OP_reg30"; 157 case 0x6f: return "DW_OP_reg31"; 158 case 0x70: return "DW_OP_breg0"; 159 case 0x71: return "DW_OP_breg1"; 160 case 0x72: return "DW_OP_breg2"; 161 case 0x73: return "DW_OP_breg3"; 162 case 0x74: return "DW_OP_breg4"; 163 case 0x75: return "DW_OP_breg5"; 164 case 0x76: return "DW_OP_breg6"; 165 case 0x77: return "DW_OP_breg7"; 166 case 0x78: return "DW_OP_breg8"; 167 case 0x79: return "DW_OP_breg9"; 168 case 0x7a: return "DW_OP_breg10"; 169 case 0x7b: return "DW_OP_breg11"; 170 case 0x7c: return "DW_OP_breg12"; 171 case 0x7d: return "DW_OP_breg13"; 172 case 0x7e: return "DW_OP_breg14"; 173 case 0x7f: return "DW_OP_breg15"; 174 case 0x80: return "DW_OP_breg16"; 175 case 0x81: return "DW_OP_breg17"; 176 case 0x82: return "DW_OP_breg18"; 177 case 0x83: return "DW_OP_breg19"; 178 case 0x84: return "DW_OP_breg20"; 179 case 0x85: return "DW_OP_breg21"; 180 case 0x86: return "DW_OP_breg22"; 181 case 0x87: return "DW_OP_breg23"; 182 case 0x88: return "DW_OP_breg24"; 183 case 0x89: return "DW_OP_breg25"; 184 case 0x8a: return "DW_OP_breg26"; 185 case 0x8b: return "DW_OP_breg27"; 186 case 0x8c: return "DW_OP_breg28"; 187 case 0x8d: return "DW_OP_breg29"; 188 case 0x8e: return "DW_OP_breg30"; 189 case 0x8f: return "DW_OP_breg31"; 190 case 0x90: return "DW_OP_regx"; 191 case 0x91: return "DW_OP_fbreg"; 192 case 0x92: return "DW_OP_bregx"; 193 case 0x93: return "DW_OP_piece"; 194 case 0x94: return "DW_OP_deref_size"; 195 case 0x95: return "DW_OP_xderef_size"; 196 case 0x96: return "DW_OP_nop"; 197 case 0x97: return "DW_OP_push_object_address"; 198 case 0x98: return "DW_OP_call2"; 199 case 0x99: return "DW_OP_call4"; 200 case 0x9a: return "DW_OP_call_ref"; 201 case 0xfb: return "DW_OP_GNU_addr_index"; 202 // case DW_OP_APPLE_array_ref: return "DW_OP_APPLE_array_ref"; 203 // case DW_OP_APPLE_extern: return "DW_OP_APPLE_extern"; 204 case DW_OP_APPLE_uninit: return "DW_OP_APPLE_uninit"; 205 // case DW_OP_APPLE_assign: return "DW_OP_APPLE_assign"; 206 // case DW_OP_APPLE_address_of: return "DW_OP_APPLE_address_of"; 207 // case DW_OP_APPLE_value_of: return "DW_OP_APPLE_value_of"; 208 // case DW_OP_APPLE_deref_type: return "DW_OP_APPLE_deref_type"; 209 // case DW_OP_APPLE_expr_local: return "DW_OP_APPLE_expr_local"; 210 // case DW_OP_APPLE_constf: return "DW_OP_APPLE_constf"; 211 // case DW_OP_APPLE_scalar_cast: return "DW_OP_APPLE_scalar_cast"; 212 // case DW_OP_APPLE_clang_cast: return "DW_OP_APPLE_clang_cast"; 213 // case DW_OP_APPLE_clear: return "DW_OP_APPLE_clear"; 214 // case DW_OP_APPLE_error: return "DW_OP_APPLE_error"; 215 default: 216 snprintf (invalid, sizeof(invalid), "Unknown DW_OP constant: 0x%x", val); 217 return invalid; 218 } 219 } 220 221 222 //---------------------------------------------------------------------- 223 // DWARFExpression constructor 224 //---------------------------------------------------------------------- 225 DWARFExpression::DWARFExpression(DWARFCompileUnit* dwarf_cu) : 226 m_module_wp(), 227 m_data(), 228 m_dwarf_cu(dwarf_cu), 229 m_reg_kind (eRegisterKindDWARF), 230 m_loclist_slide (LLDB_INVALID_ADDRESS) 231 { 232 } 233 234 DWARFExpression::DWARFExpression(const DWARFExpression& rhs) : 235 m_module_wp(rhs.m_module_wp), 236 m_data(rhs.m_data), 237 m_dwarf_cu(rhs.m_dwarf_cu), 238 m_reg_kind (rhs.m_reg_kind), 239 m_loclist_slide(rhs.m_loclist_slide) 240 { 241 } 242 243 244 DWARFExpression::DWARFExpression(lldb::ModuleSP module_sp, 245 const DataExtractor& data, 246 DWARFCompileUnit* dwarf_cu, 247 lldb::offset_t data_offset, 248 lldb::offset_t data_length) : 249 m_module_wp(), 250 m_data(data, data_offset, data_length), 251 m_dwarf_cu(dwarf_cu), 252 m_reg_kind (eRegisterKindDWARF), 253 m_loclist_slide(LLDB_INVALID_ADDRESS) 254 { 255 if (module_sp) 256 m_module_wp = module_sp; 257 } 258 259 //---------------------------------------------------------------------- 260 // Destructor 261 //---------------------------------------------------------------------- 262 DWARFExpression::~DWARFExpression() 263 { 264 } 265 266 267 bool 268 DWARFExpression::IsValid() const 269 { 270 return m_data.GetByteSize() > 0; 271 } 272 273 void 274 DWARFExpression::SetOpcodeData (const DataExtractor& data) 275 { 276 m_data = data; 277 } 278 279 void 280 DWARFExpression::CopyOpcodeData (lldb::ModuleSP module_sp, const DataExtractor& data, lldb::offset_t data_offset, lldb::offset_t data_length) 281 { 282 const uint8_t *bytes = data.PeekData(data_offset, data_length); 283 if (bytes) 284 { 285 m_module_wp = module_sp; 286 m_data.SetData(DataBufferSP(new DataBufferHeap(bytes, data_length))); 287 m_data.SetByteOrder(data.GetByteOrder()); 288 m_data.SetAddressByteSize(data.GetAddressByteSize()); 289 } 290 } 291 292 void 293 DWARFExpression::CopyOpcodeData (const void *data, 294 lldb::offset_t data_length, 295 ByteOrder byte_order, 296 uint8_t addr_byte_size) 297 { 298 if (data && data_length) 299 { 300 m_data.SetData(DataBufferSP(new DataBufferHeap(data, data_length))); 301 m_data.SetByteOrder(byte_order); 302 m_data.SetAddressByteSize(addr_byte_size); 303 } 304 } 305 306 void 307 DWARFExpression::CopyOpcodeData (uint64_t const_value, 308 lldb::offset_t const_value_byte_size, 309 uint8_t addr_byte_size) 310 { 311 if (const_value_byte_size) 312 { 313 m_data.SetData(DataBufferSP(new DataBufferHeap(&const_value, const_value_byte_size))); 314 m_data.SetByteOrder(endian::InlHostByteOrder()); 315 m_data.SetAddressByteSize(addr_byte_size); 316 } 317 } 318 319 void 320 DWARFExpression::SetOpcodeData (lldb::ModuleSP module_sp, const DataExtractor& data, lldb::offset_t data_offset, lldb::offset_t data_length) 321 { 322 m_module_wp = module_sp; 323 m_data.SetData(data, data_offset, data_length); 324 } 325 326 void 327 DWARFExpression::DumpLocation (Stream *s, lldb::offset_t offset, lldb::offset_t length, lldb::DescriptionLevel level, ABI *abi) const 328 { 329 if (!m_data.ValidOffsetForDataOfSize(offset, length)) 330 return; 331 const lldb::offset_t start_offset = offset; 332 const lldb::offset_t end_offset = offset + length; 333 while (m_data.ValidOffset(offset) && offset < end_offset) 334 { 335 const lldb::offset_t op_offset = offset; 336 const uint8_t op = m_data.GetU8(&offset); 337 338 switch (level) 339 { 340 default: 341 break; 342 343 case lldb::eDescriptionLevelBrief: 344 if (offset > start_offset) 345 s->PutChar(' '); 346 break; 347 348 case lldb::eDescriptionLevelFull: 349 case lldb::eDescriptionLevelVerbose: 350 if (offset > start_offset) 351 s->EOL(); 352 s->Indent(); 353 if (level == lldb::eDescriptionLevelFull) 354 break; 355 // Fall through for verbose and print offset and DW_OP prefix.. 356 s->Printf("0x%8.8" PRIx64 ": %s", op_offset, op >= DW_OP_APPLE_uninit ? "DW_OP_APPLE_" : "DW_OP_"); 357 break; 358 } 359 360 switch (op) 361 { 362 case DW_OP_addr: *s << "DW_OP_addr(" << m_data.GetAddress(&offset) << ") "; break; // 0x03 1 address 363 case DW_OP_deref: *s << "DW_OP_deref"; break; // 0x06 364 case DW_OP_const1u: s->Printf("DW_OP_const1u(0x%2.2x) ", m_data.GetU8(&offset)); break; // 0x08 1 1-byte constant 365 case DW_OP_const1s: s->Printf("DW_OP_const1s(0x%2.2x) ", m_data.GetU8(&offset)); break; // 0x09 1 1-byte constant 366 case DW_OP_const2u: s->Printf("DW_OP_const2u(0x%4.4x) ", m_data.GetU16(&offset)); break; // 0x0a 1 2-byte constant 367 case DW_OP_const2s: s->Printf("DW_OP_const2s(0x%4.4x) ", m_data.GetU16(&offset)); break; // 0x0b 1 2-byte constant 368 case DW_OP_const4u: s->Printf("DW_OP_const4u(0x%8.8x) ", m_data.GetU32(&offset)); break; // 0x0c 1 4-byte constant 369 case DW_OP_const4s: s->Printf("DW_OP_const4s(0x%8.8x) ", m_data.GetU32(&offset)); break; // 0x0d 1 4-byte constant 370 case DW_OP_const8u: s->Printf("DW_OP_const8u(0x%16.16" PRIx64 ") ", m_data.GetU64(&offset)); break; // 0x0e 1 8-byte constant 371 case DW_OP_const8s: s->Printf("DW_OP_const8s(0x%16.16" PRIx64 ") ", m_data.GetU64(&offset)); break; // 0x0f 1 8-byte constant 372 case DW_OP_constu: s->Printf("DW_OP_constu(0x%" PRIx64 ") ", m_data.GetULEB128(&offset)); break; // 0x10 1 ULEB128 constant 373 case DW_OP_consts: s->Printf("DW_OP_consts(0x%" PRId64 ") ", m_data.GetSLEB128(&offset)); break; // 0x11 1 SLEB128 constant 374 case DW_OP_dup: s->PutCString("DW_OP_dup"); break; // 0x12 375 case DW_OP_drop: s->PutCString("DW_OP_drop"); break; // 0x13 376 case DW_OP_over: s->PutCString("DW_OP_over"); break; // 0x14 377 case DW_OP_pick: s->Printf("DW_OP_pick(0x%2.2x) ", m_data.GetU8(&offset)); break; // 0x15 1 1-byte stack index 378 case DW_OP_swap: s->PutCString("DW_OP_swap"); break; // 0x16 379 case DW_OP_rot: s->PutCString("DW_OP_rot"); break; // 0x17 380 case DW_OP_xderef: s->PutCString("DW_OP_xderef"); break; // 0x18 381 case DW_OP_abs: s->PutCString("DW_OP_abs"); break; // 0x19 382 case DW_OP_and: s->PutCString("DW_OP_and"); break; // 0x1a 383 case DW_OP_div: s->PutCString("DW_OP_div"); break; // 0x1b 384 case DW_OP_minus: s->PutCString("DW_OP_minus"); break; // 0x1c 385 case DW_OP_mod: s->PutCString("DW_OP_mod"); break; // 0x1d 386 case DW_OP_mul: s->PutCString("DW_OP_mul"); break; // 0x1e 387 case DW_OP_neg: s->PutCString("DW_OP_neg"); break; // 0x1f 388 case DW_OP_not: s->PutCString("DW_OP_not"); break; // 0x20 389 case DW_OP_or: s->PutCString("DW_OP_or"); break; // 0x21 390 case DW_OP_plus: s->PutCString("DW_OP_plus"); break; // 0x22 391 case DW_OP_plus_uconst: // 0x23 1 ULEB128 addend 392 s->Printf("DW_OP_plus_uconst(0x%" PRIx64 ") ", m_data.GetULEB128(&offset)); 393 break; 394 395 case DW_OP_shl: s->PutCString("DW_OP_shl"); break; // 0x24 396 case DW_OP_shr: s->PutCString("DW_OP_shr"); break; // 0x25 397 case DW_OP_shra: s->PutCString("DW_OP_shra"); break; // 0x26 398 case DW_OP_xor: s->PutCString("DW_OP_xor"); break; // 0x27 399 case DW_OP_skip: s->Printf("DW_OP_skip(0x%4.4x)", m_data.GetU16(&offset)); break; // 0x2f 1 signed 2-byte constant 400 case DW_OP_bra: s->Printf("DW_OP_bra(0x%4.4x)", m_data.GetU16(&offset)); break; // 0x28 1 signed 2-byte constant 401 case DW_OP_eq: s->PutCString("DW_OP_eq"); break; // 0x29 402 case DW_OP_ge: s->PutCString("DW_OP_ge"); break; // 0x2a 403 case DW_OP_gt: s->PutCString("DW_OP_gt"); break; // 0x2b 404 case DW_OP_le: s->PutCString("DW_OP_le"); break; // 0x2c 405 case DW_OP_lt: s->PutCString("DW_OP_lt"); break; // 0x2d 406 case DW_OP_ne: s->PutCString("DW_OP_ne"); break; // 0x2e 407 408 case DW_OP_lit0: // 0x30 409 case DW_OP_lit1: // 0x31 410 case DW_OP_lit2: // 0x32 411 case DW_OP_lit3: // 0x33 412 case DW_OP_lit4: // 0x34 413 case DW_OP_lit5: // 0x35 414 case DW_OP_lit6: // 0x36 415 case DW_OP_lit7: // 0x37 416 case DW_OP_lit8: // 0x38 417 case DW_OP_lit9: // 0x39 418 case DW_OP_lit10: // 0x3A 419 case DW_OP_lit11: // 0x3B 420 case DW_OP_lit12: // 0x3C 421 case DW_OP_lit13: // 0x3D 422 case DW_OP_lit14: // 0x3E 423 case DW_OP_lit15: // 0x3F 424 case DW_OP_lit16: // 0x40 425 case DW_OP_lit17: // 0x41 426 case DW_OP_lit18: // 0x42 427 case DW_OP_lit19: // 0x43 428 case DW_OP_lit20: // 0x44 429 case DW_OP_lit21: // 0x45 430 case DW_OP_lit22: // 0x46 431 case DW_OP_lit23: // 0x47 432 case DW_OP_lit24: // 0x48 433 case DW_OP_lit25: // 0x49 434 case DW_OP_lit26: // 0x4A 435 case DW_OP_lit27: // 0x4B 436 case DW_OP_lit28: // 0x4C 437 case DW_OP_lit29: // 0x4D 438 case DW_OP_lit30: // 0x4E 439 case DW_OP_lit31: s->Printf("DW_OP_lit%i", op - DW_OP_lit0); break; // 0x4f 440 441 case DW_OP_reg0: // 0x50 442 case DW_OP_reg1: // 0x51 443 case DW_OP_reg2: // 0x52 444 case DW_OP_reg3: // 0x53 445 case DW_OP_reg4: // 0x54 446 case DW_OP_reg5: // 0x55 447 case DW_OP_reg6: // 0x56 448 case DW_OP_reg7: // 0x57 449 case DW_OP_reg8: // 0x58 450 case DW_OP_reg9: // 0x59 451 case DW_OP_reg10: // 0x5A 452 case DW_OP_reg11: // 0x5B 453 case DW_OP_reg12: // 0x5C 454 case DW_OP_reg13: // 0x5D 455 case DW_OP_reg14: // 0x5E 456 case DW_OP_reg15: // 0x5F 457 case DW_OP_reg16: // 0x60 458 case DW_OP_reg17: // 0x61 459 case DW_OP_reg18: // 0x62 460 case DW_OP_reg19: // 0x63 461 case DW_OP_reg20: // 0x64 462 case DW_OP_reg21: // 0x65 463 case DW_OP_reg22: // 0x66 464 case DW_OP_reg23: // 0x67 465 case DW_OP_reg24: // 0x68 466 case DW_OP_reg25: // 0x69 467 case DW_OP_reg26: // 0x6A 468 case DW_OP_reg27: // 0x6B 469 case DW_OP_reg28: // 0x6C 470 case DW_OP_reg29: // 0x6D 471 case DW_OP_reg30: // 0x6E 472 case DW_OP_reg31: // 0x6F 473 { 474 uint32_t reg_num = op - DW_OP_reg0; 475 if (abi) 476 { 477 RegisterInfo reg_info; 478 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info)) 479 { 480 if (reg_info.name) 481 { 482 s->PutCString (reg_info.name); 483 break; 484 } 485 else if (reg_info.alt_name) 486 { 487 s->PutCString (reg_info.alt_name); 488 break; 489 } 490 } 491 } 492 s->Printf("DW_OP_reg%u", reg_num); break; 493 } 494 break; 495 496 case DW_OP_breg0: 497 case DW_OP_breg1: 498 case DW_OP_breg2: 499 case DW_OP_breg3: 500 case DW_OP_breg4: 501 case DW_OP_breg5: 502 case DW_OP_breg6: 503 case DW_OP_breg7: 504 case DW_OP_breg8: 505 case DW_OP_breg9: 506 case DW_OP_breg10: 507 case DW_OP_breg11: 508 case DW_OP_breg12: 509 case DW_OP_breg13: 510 case DW_OP_breg14: 511 case DW_OP_breg15: 512 case DW_OP_breg16: 513 case DW_OP_breg17: 514 case DW_OP_breg18: 515 case DW_OP_breg19: 516 case DW_OP_breg20: 517 case DW_OP_breg21: 518 case DW_OP_breg22: 519 case DW_OP_breg23: 520 case DW_OP_breg24: 521 case DW_OP_breg25: 522 case DW_OP_breg26: 523 case DW_OP_breg27: 524 case DW_OP_breg28: 525 case DW_OP_breg29: 526 case DW_OP_breg30: 527 case DW_OP_breg31: 528 { 529 uint32_t reg_num = op - DW_OP_breg0; 530 int64_t reg_offset = m_data.GetSLEB128(&offset); 531 if (abi) 532 { 533 RegisterInfo reg_info; 534 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info)) 535 { 536 if (reg_info.name) 537 { 538 s->Printf("[%s%+" PRIi64 "]", reg_info.name, reg_offset); 539 break; 540 } 541 else if (reg_info.alt_name) 542 { 543 s->Printf("[%s%+" PRIi64 "]", reg_info.alt_name, reg_offset); 544 break; 545 } 546 } 547 } 548 s->Printf("DW_OP_breg%i(0x%" PRIx64 ")", reg_num, reg_offset); 549 } 550 break; 551 552 case DW_OP_regx: // 0x90 1 ULEB128 register 553 { 554 uint32_t reg_num = m_data.GetULEB128(&offset); 555 if (abi) 556 { 557 RegisterInfo reg_info; 558 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info)) 559 { 560 if (reg_info.name) 561 { 562 s->PutCString (reg_info.name); 563 break; 564 } 565 else if (reg_info.alt_name) 566 { 567 s->PutCString (reg_info.alt_name); 568 break; 569 } 570 } 571 } 572 s->Printf("DW_OP_regx(%" PRIu32 ")", reg_num); break; 573 } 574 break; 575 case DW_OP_fbreg: // 0x91 1 SLEB128 offset 576 s->Printf("DW_OP_fbreg(%" PRIi64 ")",m_data.GetSLEB128(&offset)); 577 break; 578 case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset 579 { 580 uint32_t reg_num = m_data.GetULEB128(&offset); 581 int64_t reg_offset = m_data.GetSLEB128(&offset); 582 if (abi) 583 { 584 RegisterInfo reg_info; 585 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info)) 586 { 587 if (reg_info.name) 588 { 589 s->Printf("[%s%+" PRIi64 "]", reg_info.name, reg_offset); 590 break; 591 } 592 else if (reg_info.alt_name) 593 { 594 s->Printf("[%s%+" PRIi64 "]", reg_info.alt_name, reg_offset); 595 break; 596 } 597 } 598 } 599 s->Printf("DW_OP_bregx(reg=%" PRIu32 ",offset=%" PRIi64 ")", reg_num, reg_offset); 600 } 601 break; 602 case DW_OP_piece: // 0x93 1 ULEB128 size of piece addressed 603 s->Printf("DW_OP_piece(0x%" PRIx64 ")", m_data.GetULEB128(&offset)); 604 break; 605 case DW_OP_deref_size: // 0x94 1 1-byte size of data retrieved 606 s->Printf("DW_OP_deref_size(0x%2.2x)", m_data.GetU8(&offset)); 607 break; 608 case DW_OP_xderef_size: // 0x95 1 1-byte size of data retrieved 609 s->Printf("DW_OP_xderef_size(0x%2.2x)", m_data.GetU8(&offset)); 610 break; 611 case DW_OP_nop: s->PutCString("DW_OP_nop"); break; // 0x96 612 case DW_OP_push_object_address: s->PutCString("DW_OP_push_object_address"); break; // 0x97 DWARF3 613 case DW_OP_call2: // 0x98 DWARF3 1 2-byte offset of DIE 614 s->Printf("DW_OP_call2(0x%4.4x)", m_data.GetU16(&offset)); 615 break; 616 case DW_OP_call4: // 0x99 DWARF3 1 4-byte offset of DIE 617 s->Printf("DW_OP_call4(0x%8.8x)", m_data.GetU32(&offset)); 618 break; 619 case DW_OP_call_ref: // 0x9a DWARF3 1 4- or 8-byte offset of DIE 620 s->Printf("DW_OP_call_ref(0x%8.8" PRIx64 ")", m_data.GetAddress(&offset)); 621 break; 622 // case DW_OP_call_frame_cfa: s << "call_frame_cfa"; break; // 0x9c DWARF3 623 // case DW_OP_bit_piece: // 0x9d DWARF3 2 624 // s->Printf("DW_OP_bit_piece(0x%x, 0x%x)", m_data.GetULEB128(&offset), m_data.GetULEB128(&offset)); 625 // break; 626 // case DW_OP_lo_user: s->PutCString("DW_OP_lo_user"); break; // 0xe0 627 // case DW_OP_hi_user: s->PutCString("DW_OP_hi_user"); break; // 0xff 628 // case DW_OP_APPLE_extern: 629 // s->Printf("DW_OP_APPLE_extern(%" PRIu64 ")", m_data.GetULEB128(&offset)); 630 // break; 631 // case DW_OP_APPLE_array_ref: 632 // s->PutCString("DW_OP_APPLE_array_ref"); 633 // break; 634 case DW_OP_form_tls_address: 635 s->PutCString("DW_OP_form_tls_address"); // 0x9b 636 break; 637 case DW_OP_GNU_addr_index: // 0xfb 638 s->Printf("DW_OP_GNU_addr_index(0x%" PRIx64 ")", m_data.GetULEB128(&offset)); 639 break; 640 case DW_OP_GNU_push_tls_address: 641 s->PutCString("DW_OP_GNU_push_tls_address"); // 0xe0 642 break; 643 case DW_OP_APPLE_uninit: 644 s->PutCString("DW_OP_APPLE_uninit"); // 0xF0 645 break; 646 // case DW_OP_APPLE_assign: // 0xF1 - pops value off and assigns it to second item on stack (2nd item must have assignable context) 647 // s->PutCString("DW_OP_APPLE_assign"); 648 // break; 649 // case DW_OP_APPLE_address_of: // 0xF2 - gets the address of the top stack item (top item must be a variable, or have value_type that is an address already) 650 // s->PutCString("DW_OP_APPLE_address_of"); 651 // break; 652 // case DW_OP_APPLE_value_of: // 0xF3 - pops the value off the stack and pushes the value of that object (top item must be a variable, or expression local) 653 // s->PutCString("DW_OP_APPLE_value_of"); 654 // break; 655 // case DW_OP_APPLE_deref_type: // 0xF4 - gets the address of the top stack item (top item must be a variable, or a clang type) 656 // s->PutCString("DW_OP_APPLE_deref_type"); 657 // break; 658 // case DW_OP_APPLE_expr_local: // 0xF5 - ULEB128 expression local index 659 // s->Printf("DW_OP_APPLE_expr_local(%" PRIu64 ")", m_data.GetULEB128(&offset)); 660 // break; 661 // case DW_OP_APPLE_constf: // 0xF6 - 1 byte float size, followed by constant float data 662 // { 663 // uint8_t float_length = m_data.GetU8(&offset); 664 // s->Printf("DW_OP_APPLE_constf(<%u> ", float_length); 665 // m_data.Dump(s, offset, eFormatHex, float_length, 1, UINT32_MAX, DW_INVALID_ADDRESS, 0, 0); 666 // s->PutChar(')'); 667 // // Consume the float data 668 // m_data.GetData(&offset, float_length); 669 // } 670 // break; 671 // case DW_OP_APPLE_scalar_cast: 672 // s->Printf("DW_OP_APPLE_scalar_cast(%s)", Scalar::GetValueTypeAsCString ((Scalar::Type)m_data.GetU8(&offset))); 673 // break; 674 // case DW_OP_APPLE_clang_cast: 675 // { 676 // clang::Type *clang_type = (clang::Type *)m_data.GetMaxU64(&offset, sizeof(void*)); 677 // s->Printf("DW_OP_APPLE_clang_cast(%p)", clang_type); 678 // } 679 // break; 680 // case DW_OP_APPLE_clear: 681 // s->PutCString("DW_OP_APPLE_clear"); 682 // break; 683 // case DW_OP_APPLE_error: // 0xFF - Stops expression evaluation and returns an error (no args) 684 // s->PutCString("DW_OP_APPLE_error"); 685 // break; 686 } 687 } 688 } 689 690 void 691 DWARFExpression::SetLocationListSlide (addr_t slide) 692 { 693 m_loclist_slide = slide; 694 } 695 696 int 697 DWARFExpression::GetRegisterKind () 698 { 699 return m_reg_kind; 700 } 701 702 void 703 DWARFExpression::SetRegisterKind (RegisterKind reg_kind) 704 { 705 m_reg_kind = reg_kind; 706 } 707 708 bool 709 DWARFExpression::IsLocationList() const 710 { 711 return m_loclist_slide != LLDB_INVALID_ADDRESS; 712 } 713 714 void 715 DWARFExpression::GetDescription (Stream *s, lldb::DescriptionLevel level, addr_t location_list_base_addr, ABI *abi) const 716 { 717 if (IsLocationList()) 718 { 719 // We have a location list 720 lldb::offset_t offset = 0; 721 uint32_t count = 0; 722 addr_t curr_base_addr = location_list_base_addr; 723 while (m_data.ValidOffset(offset)) 724 { 725 lldb::addr_t begin_addr_offset = m_data.GetAddress(&offset); 726 lldb::addr_t end_addr_offset = m_data.GetAddress(&offset); 727 if (begin_addr_offset < end_addr_offset) 728 { 729 if (count > 0) 730 s->PutCString(", "); 731 VMRange addr_range(curr_base_addr + begin_addr_offset, curr_base_addr + end_addr_offset); 732 addr_range.Dump(s, 0, 8); 733 s->PutChar('{'); 734 lldb::offset_t location_length = m_data.GetU16(&offset); 735 DumpLocation (s, offset, location_length, level, abi); 736 s->PutChar('}'); 737 offset += location_length; 738 } 739 else if (begin_addr_offset == 0 && end_addr_offset == 0) 740 { 741 // The end of the location list is marked by both the start and end offset being zero 742 break; 743 } 744 else 745 { 746 if ((m_data.GetAddressByteSize() == 4 && (begin_addr_offset == UINT32_MAX)) || 747 (m_data.GetAddressByteSize() == 8 && (begin_addr_offset == UINT64_MAX))) 748 { 749 curr_base_addr = end_addr_offset + location_list_base_addr; 750 // We have a new base address 751 if (count > 0) 752 s->PutCString(", "); 753 *s << "base_addr = " << end_addr_offset; 754 } 755 } 756 757 count++; 758 } 759 } 760 else 761 { 762 // We have a normal location that contains DW_OP location opcodes 763 DumpLocation (s, 0, m_data.GetByteSize(), level, abi); 764 } 765 } 766 767 static bool 768 ReadRegisterValueAsScalar 769 ( 770 RegisterContext *reg_ctx, 771 lldb::RegisterKind reg_kind, 772 uint32_t reg_num, 773 Error *error_ptr, 774 Value &value 775 ) 776 { 777 if (reg_ctx == NULL) 778 { 779 if (error_ptr) 780 error_ptr->SetErrorStringWithFormat("No register context in frame.\n"); 781 } 782 else 783 { 784 uint32_t native_reg = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num); 785 if (native_reg == LLDB_INVALID_REGNUM) 786 { 787 if (error_ptr) 788 error_ptr->SetErrorStringWithFormat("Unable to convert register kind=%u reg_num=%u to a native register number.\n", reg_kind, reg_num); 789 } 790 else 791 { 792 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(native_reg); 793 RegisterValue reg_value; 794 if (reg_ctx->ReadRegister (reg_info, reg_value)) 795 { 796 if (reg_value.GetScalarValue(value.GetScalar())) 797 { 798 value.SetValueType (Value::eValueTypeScalar); 799 value.SetContext (Value::eContextTypeRegisterInfo, 800 const_cast<RegisterInfo *>(reg_info)); 801 if (error_ptr) 802 error_ptr->Clear(); 803 return true; 804 } 805 else 806 { 807 // If we get this error, then we need to implement a value 808 // buffer in the dwarf expression evaluation function... 809 if (error_ptr) 810 error_ptr->SetErrorStringWithFormat ("register %s can't be converted to a scalar value", 811 reg_info->name); 812 } 813 } 814 else 815 { 816 if (error_ptr) 817 error_ptr->SetErrorStringWithFormat("register %s is not available", reg_info->name); 818 } 819 } 820 } 821 return false; 822 } 823 824 //bool 825 //DWARFExpression::LocationListContainsLoadAddress (Process* process, const Address &addr) const 826 //{ 827 // return LocationListContainsLoadAddress(process, addr.GetLoadAddress(process)); 828 //} 829 // 830 //bool 831 //DWARFExpression::LocationListContainsLoadAddress (Process* process, addr_t load_addr) const 832 //{ 833 // if (load_addr == LLDB_INVALID_ADDRESS) 834 // return false; 835 // 836 // if (IsLocationList()) 837 // { 838 // lldb::offset_t offset = 0; 839 // 840 // addr_t loc_list_base_addr = m_loclist_slide.GetLoadAddress(process); 841 // 842 // if (loc_list_base_addr == LLDB_INVALID_ADDRESS) 843 // return false; 844 // 845 // while (m_data.ValidOffset(offset)) 846 // { 847 // // We need to figure out what the value is for the location. 848 // addr_t lo_pc = m_data.GetAddress(&offset); 849 // addr_t hi_pc = m_data.GetAddress(&offset); 850 // if (lo_pc == 0 && hi_pc == 0) 851 // break; 852 // else 853 // { 854 // lo_pc += loc_list_base_addr; 855 // hi_pc += loc_list_base_addr; 856 // 857 // if (lo_pc <= load_addr && load_addr < hi_pc) 858 // return true; 859 // 860 // offset += m_data.GetU16(&offset); 861 // } 862 // } 863 // } 864 // return false; 865 //} 866 867 static offset_t 868 GetOpcodeDataSize (const DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op) 869 { 870 lldb::offset_t offset = data_offset; 871 switch (op) 872 { 873 case DW_OP_addr: 874 case DW_OP_call_ref: // 0x9a 1 address sized offset of DIE (DWARF3) 875 return data.GetAddressByteSize(); 876 877 // Opcodes with no arguments 878 case DW_OP_deref: // 0x06 879 case DW_OP_dup: // 0x12 880 case DW_OP_drop: // 0x13 881 case DW_OP_over: // 0x14 882 case DW_OP_swap: // 0x16 883 case DW_OP_rot: // 0x17 884 case DW_OP_xderef: // 0x18 885 case DW_OP_abs: // 0x19 886 case DW_OP_and: // 0x1a 887 case DW_OP_div: // 0x1b 888 case DW_OP_minus: // 0x1c 889 case DW_OP_mod: // 0x1d 890 case DW_OP_mul: // 0x1e 891 case DW_OP_neg: // 0x1f 892 case DW_OP_not: // 0x20 893 case DW_OP_or: // 0x21 894 case DW_OP_plus: // 0x22 895 case DW_OP_shl: // 0x24 896 case DW_OP_shr: // 0x25 897 case DW_OP_shra: // 0x26 898 case DW_OP_xor: // 0x27 899 case DW_OP_eq: // 0x29 900 case DW_OP_ge: // 0x2a 901 case DW_OP_gt: // 0x2b 902 case DW_OP_le: // 0x2c 903 case DW_OP_lt: // 0x2d 904 case DW_OP_ne: // 0x2e 905 case DW_OP_lit0: // 0x30 906 case DW_OP_lit1: // 0x31 907 case DW_OP_lit2: // 0x32 908 case DW_OP_lit3: // 0x33 909 case DW_OP_lit4: // 0x34 910 case DW_OP_lit5: // 0x35 911 case DW_OP_lit6: // 0x36 912 case DW_OP_lit7: // 0x37 913 case DW_OP_lit8: // 0x38 914 case DW_OP_lit9: // 0x39 915 case DW_OP_lit10: // 0x3A 916 case DW_OP_lit11: // 0x3B 917 case DW_OP_lit12: // 0x3C 918 case DW_OP_lit13: // 0x3D 919 case DW_OP_lit14: // 0x3E 920 case DW_OP_lit15: // 0x3F 921 case DW_OP_lit16: // 0x40 922 case DW_OP_lit17: // 0x41 923 case DW_OP_lit18: // 0x42 924 case DW_OP_lit19: // 0x43 925 case DW_OP_lit20: // 0x44 926 case DW_OP_lit21: // 0x45 927 case DW_OP_lit22: // 0x46 928 case DW_OP_lit23: // 0x47 929 case DW_OP_lit24: // 0x48 930 case DW_OP_lit25: // 0x49 931 case DW_OP_lit26: // 0x4A 932 case DW_OP_lit27: // 0x4B 933 case DW_OP_lit28: // 0x4C 934 case DW_OP_lit29: // 0x4D 935 case DW_OP_lit30: // 0x4E 936 case DW_OP_lit31: // 0x4f 937 case DW_OP_reg0: // 0x50 938 case DW_OP_reg1: // 0x51 939 case DW_OP_reg2: // 0x52 940 case DW_OP_reg3: // 0x53 941 case DW_OP_reg4: // 0x54 942 case DW_OP_reg5: // 0x55 943 case DW_OP_reg6: // 0x56 944 case DW_OP_reg7: // 0x57 945 case DW_OP_reg8: // 0x58 946 case DW_OP_reg9: // 0x59 947 case DW_OP_reg10: // 0x5A 948 case DW_OP_reg11: // 0x5B 949 case DW_OP_reg12: // 0x5C 950 case DW_OP_reg13: // 0x5D 951 case DW_OP_reg14: // 0x5E 952 case DW_OP_reg15: // 0x5F 953 case DW_OP_reg16: // 0x60 954 case DW_OP_reg17: // 0x61 955 case DW_OP_reg18: // 0x62 956 case DW_OP_reg19: // 0x63 957 case DW_OP_reg20: // 0x64 958 case DW_OP_reg21: // 0x65 959 case DW_OP_reg22: // 0x66 960 case DW_OP_reg23: // 0x67 961 case DW_OP_reg24: // 0x68 962 case DW_OP_reg25: // 0x69 963 case DW_OP_reg26: // 0x6A 964 case DW_OP_reg27: // 0x6B 965 case DW_OP_reg28: // 0x6C 966 case DW_OP_reg29: // 0x6D 967 case DW_OP_reg30: // 0x6E 968 case DW_OP_reg31: // 0x6F 969 case DW_OP_nop: // 0x96 970 case DW_OP_push_object_address: // 0x97 DWARF3 971 case DW_OP_form_tls_address: // 0x9b DWARF3 972 case DW_OP_call_frame_cfa: // 0x9c DWARF3 973 case DW_OP_stack_value: // 0x9f DWARF4 974 case DW_OP_GNU_push_tls_address: // 0xe0 GNU extension 975 return 0; 976 977 // Opcodes with a single 1 byte arguments 978 case DW_OP_const1u: // 0x08 1 1-byte constant 979 case DW_OP_const1s: // 0x09 1 1-byte constant 980 case DW_OP_pick: // 0x15 1 1-byte stack index 981 case DW_OP_deref_size: // 0x94 1 1-byte size of data retrieved 982 case DW_OP_xderef_size: // 0x95 1 1-byte size of data retrieved 983 return 1; 984 985 // Opcodes with a single 2 byte arguments 986 case DW_OP_const2u: // 0x0a 1 2-byte constant 987 case DW_OP_const2s: // 0x0b 1 2-byte constant 988 case DW_OP_skip: // 0x2f 1 signed 2-byte constant 989 case DW_OP_bra: // 0x28 1 signed 2-byte constant 990 case DW_OP_call2: // 0x98 1 2-byte offset of DIE (DWARF3) 991 return 2; 992 993 // Opcodes with a single 4 byte arguments 994 case DW_OP_const4u: // 0x0c 1 4-byte constant 995 case DW_OP_const4s: // 0x0d 1 4-byte constant 996 case DW_OP_call4: // 0x99 1 4-byte offset of DIE (DWARF3) 997 return 4; 998 999 // Opcodes with a single 8 byte arguments 1000 case DW_OP_const8u: // 0x0e 1 8-byte constant 1001 case DW_OP_const8s: // 0x0f 1 8-byte constant 1002 return 8; 1003 1004 // All opcodes that have a single ULEB (signed or unsigned) argument 1005 case DW_OP_constu: // 0x10 1 ULEB128 constant 1006 case DW_OP_consts: // 0x11 1 SLEB128 constant 1007 case DW_OP_plus_uconst: // 0x23 1 ULEB128 addend 1008 case DW_OP_breg0: // 0x70 1 ULEB128 register 1009 case DW_OP_breg1: // 0x71 1 ULEB128 register 1010 case DW_OP_breg2: // 0x72 1 ULEB128 register 1011 case DW_OP_breg3: // 0x73 1 ULEB128 register 1012 case DW_OP_breg4: // 0x74 1 ULEB128 register 1013 case DW_OP_breg5: // 0x75 1 ULEB128 register 1014 case DW_OP_breg6: // 0x76 1 ULEB128 register 1015 case DW_OP_breg7: // 0x77 1 ULEB128 register 1016 case DW_OP_breg8: // 0x78 1 ULEB128 register 1017 case DW_OP_breg9: // 0x79 1 ULEB128 register 1018 case DW_OP_breg10: // 0x7a 1 ULEB128 register 1019 case DW_OP_breg11: // 0x7b 1 ULEB128 register 1020 case DW_OP_breg12: // 0x7c 1 ULEB128 register 1021 case DW_OP_breg13: // 0x7d 1 ULEB128 register 1022 case DW_OP_breg14: // 0x7e 1 ULEB128 register 1023 case DW_OP_breg15: // 0x7f 1 ULEB128 register 1024 case DW_OP_breg16: // 0x80 1 ULEB128 register 1025 case DW_OP_breg17: // 0x81 1 ULEB128 register 1026 case DW_OP_breg18: // 0x82 1 ULEB128 register 1027 case DW_OP_breg19: // 0x83 1 ULEB128 register 1028 case DW_OP_breg20: // 0x84 1 ULEB128 register 1029 case DW_OP_breg21: // 0x85 1 ULEB128 register 1030 case DW_OP_breg22: // 0x86 1 ULEB128 register 1031 case DW_OP_breg23: // 0x87 1 ULEB128 register 1032 case DW_OP_breg24: // 0x88 1 ULEB128 register 1033 case DW_OP_breg25: // 0x89 1 ULEB128 register 1034 case DW_OP_breg26: // 0x8a 1 ULEB128 register 1035 case DW_OP_breg27: // 0x8b 1 ULEB128 register 1036 case DW_OP_breg28: // 0x8c 1 ULEB128 register 1037 case DW_OP_breg29: // 0x8d 1 ULEB128 register 1038 case DW_OP_breg30: // 0x8e 1 ULEB128 register 1039 case DW_OP_breg31: // 0x8f 1 ULEB128 register 1040 case DW_OP_regx: // 0x90 1 ULEB128 register 1041 case DW_OP_fbreg: // 0x91 1 SLEB128 offset 1042 case DW_OP_piece: // 0x93 1 ULEB128 size of piece addressed 1043 case DW_OP_GNU_addr_index: // 0xfb 1 ULEB128 index 1044 data.Skip_LEB128(&offset); 1045 return offset - data_offset; 1046 1047 // All opcodes that have a 2 ULEB (signed or unsigned) arguments 1048 case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset 1049 case DW_OP_bit_piece: // 0x9d ULEB128 bit size, ULEB128 bit offset (DWARF3); 1050 data.Skip_LEB128(&offset); 1051 data.Skip_LEB128(&offset); 1052 return offset - data_offset; 1053 1054 case DW_OP_implicit_value: // 0x9e ULEB128 size followed by block of that size (DWARF4) 1055 { 1056 uint64_t block_len = data.Skip_LEB128(&offset); 1057 offset += block_len; 1058 return offset - data_offset; 1059 } 1060 1061 default: 1062 break; 1063 } 1064 return LLDB_INVALID_OFFSET; 1065 } 1066 1067 lldb::addr_t 1068 DWARFExpression::GetLocation_DW_OP_addr (uint32_t op_addr_idx, 1069 bool &error) const 1070 { 1071 error = false; 1072 if (IsLocationList()) 1073 return LLDB_INVALID_ADDRESS; 1074 lldb::offset_t offset = 0; 1075 uint32_t curr_op_addr_idx = 0; 1076 while (m_data.ValidOffset(offset)) 1077 { 1078 const uint8_t op = m_data.GetU8(&offset); 1079 1080 if (op == DW_OP_addr) 1081 { 1082 const lldb::addr_t op_file_addr = m_data.GetAddress(&offset); 1083 if (curr_op_addr_idx == op_addr_idx) 1084 return op_file_addr; 1085 else 1086 ++curr_op_addr_idx; 1087 } 1088 else if (op == DW_OP_GNU_addr_index) 1089 { 1090 uint64_t index = m_data.GetULEB128(&offset); 1091 if (curr_op_addr_idx == op_addr_idx) 1092 { 1093 if (!m_dwarf_cu) 1094 { 1095 error = true; 1096 break; 1097 } 1098 1099 uint32_t index_size = m_dwarf_cu->GetAddressByteSize(); 1100 dw_offset_t addr_base = m_dwarf_cu->GetAddrBase(); 1101 lldb::offset_t offset = addr_base + index * index_size; 1102 return m_dwarf_cu->GetSymbolFileDWARF()->get_debug_addr_data().GetMaxU64(&offset, index_size); 1103 } 1104 else 1105 ++curr_op_addr_idx; 1106 } 1107 else 1108 { 1109 const offset_t op_arg_size = GetOpcodeDataSize (m_data, offset, op); 1110 if (op_arg_size == LLDB_INVALID_OFFSET) 1111 { 1112 error = true; 1113 break; 1114 } 1115 offset += op_arg_size; 1116 } 1117 } 1118 return LLDB_INVALID_ADDRESS; 1119 } 1120 1121 bool 1122 DWARFExpression::Update_DW_OP_addr (lldb::addr_t file_addr) 1123 { 1124 if (IsLocationList()) 1125 return false; 1126 lldb::offset_t offset = 0; 1127 while (m_data.ValidOffset(offset)) 1128 { 1129 const uint8_t op = m_data.GetU8(&offset); 1130 1131 if (op == DW_OP_addr) 1132 { 1133 const uint32_t addr_byte_size = m_data.GetAddressByteSize(); 1134 // We have to make a copy of the data as we don't know if this 1135 // data is from a read only memory mapped buffer, so we duplicate 1136 // all of the data first, then modify it, and if all goes well, 1137 // we then replace the data for this expression 1138 1139 // So first we copy the data into a heap buffer 1140 std::unique_ptr<DataBufferHeap> head_data_ap (new DataBufferHeap (m_data.GetDataStart(), 1141 m_data.GetByteSize())); 1142 1143 // Make en encoder so we can write the address into the buffer using 1144 // the correct byte order (endianness) 1145 DataEncoder encoder (head_data_ap->GetBytes(), 1146 head_data_ap->GetByteSize(), 1147 m_data.GetByteOrder(), 1148 addr_byte_size); 1149 1150 // Replace the address in the new buffer 1151 if (encoder.PutMaxU64 (offset, addr_byte_size, file_addr) == UINT32_MAX) 1152 return false; 1153 1154 // All went well, so now we can reset the data using a shared 1155 // pointer to the heap data so "m_data" will now correctly 1156 // manage the heap data. 1157 m_data.SetData (DataBufferSP (head_data_ap.release())); 1158 return true; 1159 } 1160 else 1161 { 1162 const offset_t op_arg_size = GetOpcodeDataSize (m_data, offset, op); 1163 if (op_arg_size == LLDB_INVALID_OFFSET) 1164 break; 1165 offset += op_arg_size; 1166 } 1167 } 1168 return false; 1169 } 1170 1171 bool 1172 DWARFExpression::LocationListContainsAddress (lldb::addr_t loclist_base_addr, lldb::addr_t addr) const 1173 { 1174 if (addr == LLDB_INVALID_ADDRESS) 1175 return false; 1176 1177 if (IsLocationList()) 1178 { 1179 lldb::offset_t offset = 0; 1180 1181 if (loclist_base_addr == LLDB_INVALID_ADDRESS) 1182 return false; 1183 1184 while (m_data.ValidOffset(offset)) 1185 { 1186 // We need to figure out what the value is for the location. 1187 addr_t lo_pc = m_data.GetAddress(&offset); 1188 addr_t hi_pc = m_data.GetAddress(&offset); 1189 if (lo_pc == 0 && hi_pc == 0) 1190 break; 1191 else 1192 { 1193 lo_pc += loclist_base_addr - m_loclist_slide; 1194 hi_pc += loclist_base_addr - m_loclist_slide; 1195 1196 if (lo_pc <= addr && addr < hi_pc) 1197 return true; 1198 1199 offset += m_data.GetU16(&offset); 1200 } 1201 } 1202 } 1203 return false; 1204 } 1205 1206 bool 1207 DWARFExpression::GetLocation (addr_t base_addr, addr_t pc, lldb::offset_t &offset, lldb::offset_t &length) 1208 { 1209 offset = 0; 1210 if (!IsLocationList()) 1211 { 1212 length = m_data.GetByteSize(); 1213 return true; 1214 } 1215 1216 if (base_addr != LLDB_INVALID_ADDRESS && pc != LLDB_INVALID_ADDRESS) 1217 { 1218 addr_t curr_base_addr = base_addr; 1219 1220 while (m_data.ValidOffset(offset)) 1221 { 1222 // We need to figure out what the value is for the location. 1223 addr_t lo_pc = m_data.GetAddress(&offset); 1224 addr_t hi_pc = m_data.GetAddress(&offset); 1225 if (lo_pc == 0 && hi_pc == 0) 1226 { 1227 break; 1228 } 1229 else 1230 { 1231 lo_pc += curr_base_addr - m_loclist_slide; 1232 hi_pc += curr_base_addr - m_loclist_slide; 1233 1234 length = m_data.GetU16(&offset); 1235 1236 if (length > 0 && lo_pc <= pc && pc < hi_pc) 1237 return true; 1238 1239 offset += length; 1240 } 1241 } 1242 } 1243 offset = LLDB_INVALID_OFFSET; 1244 length = 0; 1245 return false; 1246 } 1247 1248 bool 1249 DWARFExpression::DumpLocationForAddress (Stream *s, 1250 lldb::DescriptionLevel level, 1251 addr_t base_addr, 1252 addr_t address, 1253 ABI *abi) 1254 { 1255 lldb::offset_t offset = 0; 1256 lldb::offset_t length = 0; 1257 1258 if (GetLocation (base_addr, address, offset, length)) 1259 { 1260 if (length > 0) 1261 { 1262 DumpLocation(s, offset, length, level, abi); 1263 return true; 1264 } 1265 } 1266 return false; 1267 } 1268 1269 bool 1270 DWARFExpression::Evaluate 1271 ( 1272 ExecutionContextScope *exe_scope, 1273 ClangExpressionVariableList *expr_locals, 1274 ClangExpressionDeclMap *decl_map, 1275 lldb::addr_t loclist_base_load_addr, 1276 const Value* initial_value_ptr, 1277 Value& result, 1278 Error *error_ptr 1279 ) const 1280 { 1281 ExecutionContext exe_ctx (exe_scope); 1282 return Evaluate(&exe_ctx, expr_locals, decl_map, NULL, loclist_base_load_addr, initial_value_ptr, result, error_ptr); 1283 } 1284 1285 bool 1286 DWARFExpression::Evaluate 1287 ( 1288 ExecutionContext *exe_ctx, 1289 ClangExpressionVariableList *expr_locals, 1290 ClangExpressionDeclMap *decl_map, 1291 RegisterContext *reg_ctx, 1292 lldb::addr_t loclist_base_load_addr, 1293 const Value* initial_value_ptr, 1294 Value& result, 1295 Error *error_ptr 1296 ) const 1297 { 1298 ModuleSP module_sp = m_module_wp.lock(); 1299 1300 if (IsLocationList()) 1301 { 1302 lldb::offset_t offset = 0; 1303 addr_t pc; 1304 StackFrame *frame = NULL; 1305 if (reg_ctx) 1306 pc = reg_ctx->GetPC(); 1307 else 1308 { 1309 frame = exe_ctx->GetFramePtr(); 1310 if (!frame) 1311 return false; 1312 RegisterContextSP reg_ctx_sp = frame->GetRegisterContext(); 1313 if (!reg_ctx_sp) 1314 return false; 1315 pc = reg_ctx_sp->GetPC(); 1316 } 1317 1318 if (loclist_base_load_addr != LLDB_INVALID_ADDRESS) 1319 { 1320 if (pc == LLDB_INVALID_ADDRESS) 1321 { 1322 if (error_ptr) 1323 error_ptr->SetErrorString("Invalid PC in frame."); 1324 return false; 1325 } 1326 1327 addr_t curr_loclist_base_load_addr = loclist_base_load_addr; 1328 1329 while (m_data.ValidOffset(offset)) 1330 { 1331 // We need to figure out what the value is for the location. 1332 addr_t lo_pc = m_data.GetAddress(&offset); 1333 addr_t hi_pc = m_data.GetAddress(&offset); 1334 if (lo_pc == 0 && hi_pc == 0) 1335 { 1336 break; 1337 } 1338 else 1339 { 1340 lo_pc += curr_loclist_base_load_addr - m_loclist_slide; 1341 hi_pc += curr_loclist_base_load_addr - m_loclist_slide; 1342 1343 uint16_t length = m_data.GetU16(&offset); 1344 1345 if (length > 0 && lo_pc <= pc && pc < hi_pc) 1346 { 1347 return DWARFExpression::Evaluate (exe_ctx, 1348 expr_locals, 1349 decl_map, 1350 reg_ctx, 1351 module_sp, 1352 m_data, 1353 m_dwarf_cu, 1354 offset, 1355 length, 1356 m_reg_kind, 1357 initial_value_ptr, 1358 result, 1359 error_ptr); 1360 } 1361 offset += length; 1362 } 1363 } 1364 } 1365 if (error_ptr) 1366 error_ptr->SetErrorString ("variable not available"); 1367 return false; 1368 } 1369 1370 // Not a location list, just a single expression. 1371 return DWARFExpression::Evaluate (exe_ctx, 1372 expr_locals, 1373 decl_map, 1374 reg_ctx, 1375 module_sp, 1376 m_data, 1377 m_dwarf_cu, 1378 0, 1379 m_data.GetByteSize(), 1380 m_reg_kind, 1381 initial_value_ptr, 1382 result, 1383 error_ptr); 1384 } 1385 1386 1387 1388 bool 1389 DWARFExpression::Evaluate 1390 ( 1391 ExecutionContext *exe_ctx, 1392 ClangExpressionVariableList *expr_locals, 1393 ClangExpressionDeclMap *decl_map, 1394 RegisterContext *reg_ctx, 1395 lldb::ModuleSP module_sp, 1396 const DataExtractor& opcodes, 1397 DWARFCompileUnit* dwarf_cu, 1398 const lldb::offset_t opcodes_offset, 1399 const lldb::offset_t opcodes_length, 1400 const lldb::RegisterKind reg_kind, 1401 const Value* initial_value_ptr, 1402 Value& result, 1403 Error *error_ptr 1404 ) 1405 { 1406 1407 if (opcodes_length == 0) 1408 { 1409 if (error_ptr) 1410 error_ptr->SetErrorString ("no location, value may have been optimized out"); 1411 return false; 1412 } 1413 std::vector<Value> stack; 1414 1415 Process *process = NULL; 1416 StackFrame *frame = NULL; 1417 1418 if (exe_ctx) 1419 { 1420 process = exe_ctx->GetProcessPtr(); 1421 frame = exe_ctx->GetFramePtr(); 1422 } 1423 if (reg_ctx == NULL && frame) 1424 reg_ctx = frame->GetRegisterContext().get(); 1425 1426 if (initial_value_ptr) 1427 stack.push_back(*initial_value_ptr); 1428 1429 lldb::offset_t offset = opcodes_offset; 1430 const lldb::offset_t end_offset = opcodes_offset + opcodes_length; 1431 Value tmp; 1432 uint32_t reg_num; 1433 1434 /// Insertion point for evaluating multi-piece expression. 1435 uint64_t op_piece_offset = 0; 1436 Value pieces; // Used for DW_OP_piece 1437 1438 // Make sure all of the data is available in opcodes. 1439 if (!opcodes.ValidOffsetForDataOfSize(opcodes_offset, opcodes_length)) 1440 { 1441 if (error_ptr) 1442 error_ptr->SetErrorString ("invalid offset and/or length for opcodes buffer."); 1443 return false; 1444 } 1445 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); 1446 1447 1448 while (opcodes.ValidOffset(offset) && offset < end_offset) 1449 { 1450 const lldb::offset_t op_offset = offset; 1451 const uint8_t op = opcodes.GetU8(&offset); 1452 1453 if (log && log->GetVerbose()) 1454 { 1455 size_t count = stack.size(); 1456 log->Printf("Stack before operation has %" PRIu64 " values:", (uint64_t)count); 1457 for (size_t i=0; i<count; ++i) 1458 { 1459 StreamString new_value; 1460 new_value.Printf("[%" PRIu64 "]", (uint64_t)i); 1461 stack[i].Dump(&new_value); 1462 log->Printf(" %s", new_value.GetData()); 1463 } 1464 log->Printf("0x%8.8" PRIx64 ": %s", op_offset, DW_OP_value_to_name(op)); 1465 } 1466 switch (op) 1467 { 1468 //---------------------------------------------------------------------- 1469 // The DW_OP_addr operation has a single operand that encodes a machine 1470 // address and whose size is the size of an address on the target machine. 1471 //---------------------------------------------------------------------- 1472 case DW_OP_addr: 1473 stack.push_back(Scalar(opcodes.GetAddress(&offset))); 1474 stack.back().SetValueType (Value::eValueTypeFileAddress); 1475 break; 1476 1477 //---------------------------------------------------------------------- 1478 // The DW_OP_addr_sect_offset4 is used for any location expressions in 1479 // shared libraries that have a location like: 1480 // DW_OP_addr(0x1000) 1481 // If this address resides in a shared library, then this virtual 1482 // address won't make sense when it is evaluated in the context of a 1483 // running process where shared libraries have been slid. To account for 1484 // this, this new address type where we can store the section pointer 1485 // and a 4 byte offset. 1486 //---------------------------------------------------------------------- 1487 // case DW_OP_addr_sect_offset4: 1488 // { 1489 // result_type = eResultTypeFileAddress; 1490 // lldb::Section *sect = (lldb::Section *)opcodes.GetMaxU64(&offset, sizeof(void *)); 1491 // lldb::addr_t sect_offset = opcodes.GetU32(&offset); 1492 // 1493 // Address so_addr (sect, sect_offset); 1494 // lldb::addr_t load_addr = so_addr.GetLoadAddress(); 1495 // if (load_addr != LLDB_INVALID_ADDRESS) 1496 // { 1497 // // We successfully resolve a file address to a load 1498 // // address. 1499 // stack.push_back(load_addr); 1500 // break; 1501 // } 1502 // else 1503 // { 1504 // // We were able 1505 // if (error_ptr) 1506 // error_ptr->SetErrorStringWithFormat ("Section %s in %s is not currently loaded.\n", sect->GetName().AsCString(), sect->GetModule()->GetFileSpec().GetFilename().AsCString()); 1507 // return false; 1508 // } 1509 // } 1510 // break; 1511 1512 //---------------------------------------------------------------------- 1513 // OPCODE: DW_OP_deref 1514 // OPERANDS: none 1515 // DESCRIPTION: Pops the top stack entry and treats it as an address. 1516 // The value retrieved from that address is pushed. The size of the 1517 // data retrieved from the dereferenced address is the size of an 1518 // address on the target machine. 1519 //---------------------------------------------------------------------- 1520 case DW_OP_deref: 1521 { 1522 if (stack.empty()) 1523 { 1524 if (error_ptr) 1525 error_ptr->SetErrorString("Expression stack empty for DW_OP_deref."); 1526 return false; 1527 } 1528 Value::ValueType value_type = stack.back().GetValueType(); 1529 switch (value_type) 1530 { 1531 case Value::eValueTypeHostAddress: 1532 { 1533 void *src = (void *)stack.back().GetScalar().ULongLong(); 1534 intptr_t ptr; 1535 ::memcpy (&ptr, src, sizeof(void *)); 1536 stack.back().GetScalar() = ptr; 1537 stack.back().ClearContext(); 1538 } 1539 break; 1540 case Value::eValueTypeLoadAddress: 1541 if (exe_ctx) 1542 { 1543 if (process) 1544 { 1545 lldb::addr_t pointer_addr = stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1546 Error error; 1547 lldb::addr_t pointer_value = process->ReadPointerFromMemory(pointer_addr, error); 1548 if (pointer_value != LLDB_INVALID_ADDRESS) 1549 { 1550 stack.back().GetScalar() = pointer_value; 1551 stack.back().ClearContext(); 1552 } 1553 else 1554 { 1555 if (error_ptr) 1556 error_ptr->SetErrorStringWithFormat ("Failed to dereference pointer from 0x%" PRIx64 " for DW_OP_deref: %s\n", 1557 pointer_addr, 1558 error.AsCString()); 1559 return false; 1560 } 1561 } 1562 else 1563 { 1564 if (error_ptr) 1565 error_ptr->SetErrorStringWithFormat ("NULL process for DW_OP_deref.\n"); 1566 return false; 1567 } 1568 } 1569 else 1570 { 1571 if (error_ptr) 1572 error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_deref.\n"); 1573 return false; 1574 } 1575 break; 1576 1577 default: 1578 break; 1579 } 1580 1581 } 1582 break; 1583 1584 //---------------------------------------------------------------------- 1585 // OPCODE: DW_OP_deref_size 1586 // OPERANDS: 1 1587 // 1 - uint8_t that specifies the size of the data to dereference. 1588 // DESCRIPTION: Behaves like the DW_OP_deref operation: it pops the top 1589 // stack entry and treats it as an address. The value retrieved from that 1590 // address is pushed. In the DW_OP_deref_size operation, however, the 1591 // size in bytes of the data retrieved from the dereferenced address is 1592 // specified by the single operand. This operand is a 1-byte unsigned 1593 // integral constant whose value may not be larger than the size of an 1594 // address on the target machine. The data retrieved is zero extended 1595 // to the size of an address on the target machine before being pushed 1596 // on the expression stack. 1597 //---------------------------------------------------------------------- 1598 case DW_OP_deref_size: 1599 { 1600 if (stack.empty()) 1601 { 1602 if (error_ptr) 1603 error_ptr->SetErrorString("Expression stack empty for DW_OP_deref_size."); 1604 return false; 1605 } 1606 uint8_t size = opcodes.GetU8(&offset); 1607 Value::ValueType value_type = stack.back().GetValueType(); 1608 switch (value_type) 1609 { 1610 case Value::eValueTypeHostAddress: 1611 { 1612 void *src = (void *)stack.back().GetScalar().ULongLong(); 1613 intptr_t ptr; 1614 ::memcpy (&ptr, src, sizeof(void *)); 1615 // I can't decide whether the size operand should apply to the bytes in their 1616 // lldb-host endianness or the target endianness.. I doubt this'll ever come up 1617 // but I'll opt for assuming big endian regardless. 1618 switch (size) 1619 { 1620 case 1: ptr = ptr & 0xff; break; 1621 case 2: ptr = ptr & 0xffff; break; 1622 case 3: ptr = ptr & 0xffffff; break; 1623 case 4: ptr = ptr & 0xffffffff; break; 1624 // the casts are added to work around the case where intptr_t is a 32 bit quantity; 1625 // presumably we won't hit the 5..7 cases if (void*) is 32-bits in this program. 1626 case 5: ptr = (intptr_t) ptr & 0xffffffffffULL; break; 1627 case 6: ptr = (intptr_t) ptr & 0xffffffffffffULL; break; 1628 case 7: ptr = (intptr_t) ptr & 0xffffffffffffffULL; break; 1629 default: break; 1630 } 1631 stack.back().GetScalar() = ptr; 1632 stack.back().ClearContext(); 1633 } 1634 break; 1635 case Value::eValueTypeLoadAddress: 1636 if (exe_ctx) 1637 { 1638 if (process) 1639 { 1640 lldb::addr_t pointer_addr = stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1641 uint8_t addr_bytes[sizeof(lldb::addr_t)]; 1642 Error error; 1643 if (process->ReadMemory(pointer_addr, &addr_bytes, size, error) == size) 1644 { 1645 DataExtractor addr_data(addr_bytes, sizeof(addr_bytes), process->GetByteOrder(), size); 1646 lldb::offset_t addr_data_offset = 0; 1647 switch (size) 1648 { 1649 case 1: stack.back().GetScalar() = addr_data.GetU8(&addr_data_offset); break; 1650 case 2: stack.back().GetScalar() = addr_data.GetU16(&addr_data_offset); break; 1651 case 4: stack.back().GetScalar() = addr_data.GetU32(&addr_data_offset); break; 1652 case 8: stack.back().GetScalar() = addr_data.GetU64(&addr_data_offset); break; 1653 default: stack.back().GetScalar() = addr_data.GetPointer(&addr_data_offset); 1654 } 1655 stack.back().ClearContext(); 1656 } 1657 else 1658 { 1659 if (error_ptr) 1660 error_ptr->SetErrorStringWithFormat ("Failed to dereference pointer from 0x%" PRIx64 " for DW_OP_deref: %s\n", 1661 pointer_addr, 1662 error.AsCString()); 1663 return false; 1664 } 1665 } 1666 else 1667 { 1668 if (error_ptr) 1669 error_ptr->SetErrorStringWithFormat ("NULL process for DW_OP_deref.\n"); 1670 return false; 1671 } 1672 } 1673 else 1674 { 1675 if (error_ptr) 1676 error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_deref.\n"); 1677 return false; 1678 } 1679 break; 1680 1681 default: 1682 break; 1683 } 1684 1685 } 1686 break; 1687 1688 //---------------------------------------------------------------------- 1689 // OPCODE: DW_OP_xderef_size 1690 // OPERANDS: 1 1691 // 1 - uint8_t that specifies the size of the data to dereference. 1692 // DESCRIPTION: Behaves like the DW_OP_xderef operation: the entry at 1693 // the top of the stack is treated as an address. The second stack 1694 // entry is treated as an "address space identifier" for those 1695 // architectures that support multiple address spaces. The top two 1696 // stack elements are popped, a data item is retrieved through an 1697 // implementation-defined address calculation and pushed as the new 1698 // stack top. In the DW_OP_xderef_size operation, however, the size in 1699 // bytes of the data retrieved from the dereferenced address is 1700 // specified by the single operand. This operand is a 1-byte unsigned 1701 // integral constant whose value may not be larger than the size of an 1702 // address on the target machine. The data retrieved is zero extended 1703 // to the size of an address on the target machine before being pushed 1704 // on the expression stack. 1705 //---------------------------------------------------------------------- 1706 case DW_OP_xderef_size: 1707 if (error_ptr) 1708 error_ptr->SetErrorString("Unimplemented opcode: DW_OP_xderef_size."); 1709 return false; 1710 //---------------------------------------------------------------------- 1711 // OPCODE: DW_OP_xderef 1712 // OPERANDS: none 1713 // DESCRIPTION: Provides an extended dereference mechanism. The entry at 1714 // the top of the stack is treated as an address. The second stack entry 1715 // is treated as an "address space identifier" for those architectures 1716 // that support multiple address spaces. The top two stack elements are 1717 // popped, a data item is retrieved through an implementation-defined 1718 // address calculation and pushed as the new stack top. The size of the 1719 // data retrieved from the dereferenced address is the size of an address 1720 // on the target machine. 1721 //---------------------------------------------------------------------- 1722 case DW_OP_xderef: 1723 if (error_ptr) 1724 error_ptr->SetErrorString("Unimplemented opcode: DW_OP_xderef."); 1725 return false; 1726 1727 //---------------------------------------------------------------------- 1728 // All DW_OP_constXXX opcodes have a single operand as noted below: 1729 // 1730 // Opcode Operand 1 1731 // --------------- ---------------------------------------------------- 1732 // DW_OP_const1u 1-byte unsigned integer constant 1733 // DW_OP_const1s 1-byte signed integer constant 1734 // DW_OP_const2u 2-byte unsigned integer constant 1735 // DW_OP_const2s 2-byte signed integer constant 1736 // DW_OP_const4u 4-byte unsigned integer constant 1737 // DW_OP_const4s 4-byte signed integer constant 1738 // DW_OP_const8u 8-byte unsigned integer constant 1739 // DW_OP_const8s 8-byte signed integer constant 1740 // DW_OP_constu unsigned LEB128 integer constant 1741 // DW_OP_consts signed LEB128 integer constant 1742 //---------------------------------------------------------------------- 1743 case DW_OP_const1u : stack.push_back(Scalar(( uint8_t)opcodes.GetU8 (&offset))); break; 1744 case DW_OP_const1s : stack.push_back(Scalar(( int8_t)opcodes.GetU8 (&offset))); break; 1745 case DW_OP_const2u : stack.push_back(Scalar((uint16_t)opcodes.GetU16 (&offset))); break; 1746 case DW_OP_const2s : stack.push_back(Scalar(( int16_t)opcodes.GetU16 (&offset))); break; 1747 case DW_OP_const4u : stack.push_back(Scalar((uint32_t)opcodes.GetU32 (&offset))); break; 1748 case DW_OP_const4s : stack.push_back(Scalar(( int32_t)opcodes.GetU32 (&offset))); break; 1749 case DW_OP_const8u : stack.push_back(Scalar((uint64_t)opcodes.GetU64 (&offset))); break; 1750 case DW_OP_const8s : stack.push_back(Scalar(( int64_t)opcodes.GetU64 (&offset))); break; 1751 case DW_OP_constu : stack.push_back(Scalar(opcodes.GetULEB128 (&offset))); break; 1752 case DW_OP_consts : stack.push_back(Scalar(opcodes.GetSLEB128 (&offset))); break; 1753 1754 //---------------------------------------------------------------------- 1755 // OPCODE: DW_OP_dup 1756 // OPERANDS: none 1757 // DESCRIPTION: duplicates the value at the top of the stack 1758 //---------------------------------------------------------------------- 1759 case DW_OP_dup: 1760 if (stack.empty()) 1761 { 1762 if (error_ptr) 1763 error_ptr->SetErrorString("Expression stack empty for DW_OP_dup."); 1764 return false; 1765 } 1766 else 1767 stack.push_back(stack.back()); 1768 break; 1769 1770 //---------------------------------------------------------------------- 1771 // OPCODE: DW_OP_drop 1772 // OPERANDS: none 1773 // DESCRIPTION: pops the value at the top of the stack 1774 //---------------------------------------------------------------------- 1775 case DW_OP_drop: 1776 if (stack.empty()) 1777 { 1778 if (error_ptr) 1779 error_ptr->SetErrorString("Expression stack empty for DW_OP_drop."); 1780 return false; 1781 } 1782 else 1783 stack.pop_back(); 1784 break; 1785 1786 //---------------------------------------------------------------------- 1787 // OPCODE: DW_OP_over 1788 // OPERANDS: none 1789 // DESCRIPTION: Duplicates the entry currently second in the stack at 1790 // the top of the stack. 1791 //---------------------------------------------------------------------- 1792 case DW_OP_over: 1793 if (stack.size() < 2) 1794 { 1795 if (error_ptr) 1796 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_over."); 1797 return false; 1798 } 1799 else 1800 stack.push_back(stack[stack.size() - 2]); 1801 break; 1802 1803 1804 //---------------------------------------------------------------------- 1805 // OPCODE: DW_OP_pick 1806 // OPERANDS: uint8_t index into the current stack 1807 // DESCRIPTION: The stack entry with the specified index (0 through 255, 1808 // inclusive) is pushed on the stack 1809 //---------------------------------------------------------------------- 1810 case DW_OP_pick: 1811 { 1812 uint8_t pick_idx = opcodes.GetU8(&offset); 1813 if (pick_idx < stack.size()) 1814 stack.push_back(stack[pick_idx]); 1815 else 1816 { 1817 if (error_ptr) 1818 error_ptr->SetErrorStringWithFormat("Index %u out of range for DW_OP_pick.\n", pick_idx); 1819 return false; 1820 } 1821 } 1822 break; 1823 1824 //---------------------------------------------------------------------- 1825 // OPCODE: DW_OP_swap 1826 // OPERANDS: none 1827 // DESCRIPTION: swaps the top two stack entries. The entry at the top 1828 // of the stack becomes the second stack entry, and the second entry 1829 // becomes the top of the stack 1830 //---------------------------------------------------------------------- 1831 case DW_OP_swap: 1832 if (stack.size() < 2) 1833 { 1834 if (error_ptr) 1835 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_swap."); 1836 return false; 1837 } 1838 else 1839 { 1840 tmp = stack.back(); 1841 stack.back() = stack[stack.size() - 2]; 1842 stack[stack.size() - 2] = tmp; 1843 } 1844 break; 1845 1846 //---------------------------------------------------------------------- 1847 // OPCODE: DW_OP_rot 1848 // OPERANDS: none 1849 // DESCRIPTION: Rotates the first three stack entries. The entry at 1850 // the top of the stack becomes the third stack entry, the second 1851 // entry becomes the top of the stack, and the third entry becomes 1852 // the second entry. 1853 //---------------------------------------------------------------------- 1854 case DW_OP_rot: 1855 if (stack.size() < 3) 1856 { 1857 if (error_ptr) 1858 error_ptr->SetErrorString("Expression stack needs at least 3 items for DW_OP_rot."); 1859 return false; 1860 } 1861 else 1862 { 1863 size_t last_idx = stack.size() - 1; 1864 Value old_top = stack[last_idx]; 1865 stack[last_idx] = stack[last_idx - 1]; 1866 stack[last_idx - 1] = stack[last_idx - 2]; 1867 stack[last_idx - 2] = old_top; 1868 } 1869 break; 1870 1871 //---------------------------------------------------------------------- 1872 // OPCODE: DW_OP_abs 1873 // OPERANDS: none 1874 // DESCRIPTION: pops the top stack entry, interprets it as a signed 1875 // value and pushes its absolute value. If the absolute value can not be 1876 // represented, the result is undefined. 1877 //---------------------------------------------------------------------- 1878 case DW_OP_abs: 1879 if (stack.empty()) 1880 { 1881 if (error_ptr) 1882 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_abs."); 1883 return false; 1884 } 1885 else if (stack.back().ResolveValue(exe_ctx).AbsoluteValue() == false) 1886 { 1887 if (error_ptr) 1888 error_ptr->SetErrorString("Failed to take the absolute value of the first stack item."); 1889 return false; 1890 } 1891 break; 1892 1893 //---------------------------------------------------------------------- 1894 // OPCODE: DW_OP_and 1895 // OPERANDS: none 1896 // DESCRIPTION: pops the top two stack values, performs a bitwise and 1897 // operation on the two, and pushes the result. 1898 //---------------------------------------------------------------------- 1899 case DW_OP_and: 1900 if (stack.size() < 2) 1901 { 1902 if (error_ptr) 1903 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_and."); 1904 return false; 1905 } 1906 else 1907 { 1908 tmp = stack.back(); 1909 stack.pop_back(); 1910 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) & tmp.ResolveValue(exe_ctx); 1911 } 1912 break; 1913 1914 //---------------------------------------------------------------------- 1915 // OPCODE: DW_OP_div 1916 // OPERANDS: none 1917 // DESCRIPTION: pops the top two stack values, divides the former second 1918 // entry by the former top of the stack using signed division, and 1919 // pushes the result. 1920 //---------------------------------------------------------------------- 1921 case DW_OP_div: 1922 if (stack.size() < 2) 1923 { 1924 if (error_ptr) 1925 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_div."); 1926 return false; 1927 } 1928 else 1929 { 1930 tmp = stack.back(); 1931 if (tmp.ResolveValue(exe_ctx).IsZero()) 1932 { 1933 if (error_ptr) 1934 error_ptr->SetErrorString("Divide by zero."); 1935 return false; 1936 } 1937 else 1938 { 1939 stack.pop_back(); 1940 stack.back() = stack.back().ResolveValue(exe_ctx) / tmp.ResolveValue(exe_ctx); 1941 if (!stack.back().ResolveValue(exe_ctx).IsValid()) 1942 { 1943 if (error_ptr) 1944 error_ptr->SetErrorString("Divide failed."); 1945 return false; 1946 } 1947 } 1948 } 1949 break; 1950 1951 //---------------------------------------------------------------------- 1952 // OPCODE: DW_OP_minus 1953 // OPERANDS: none 1954 // DESCRIPTION: pops the top two stack values, subtracts the former top 1955 // of the stack from the former second entry, and pushes the result. 1956 //---------------------------------------------------------------------- 1957 case DW_OP_minus: 1958 if (stack.size() < 2) 1959 { 1960 if (error_ptr) 1961 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_minus."); 1962 return false; 1963 } 1964 else 1965 { 1966 tmp = stack.back(); 1967 stack.pop_back(); 1968 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) - tmp.ResolveValue(exe_ctx); 1969 } 1970 break; 1971 1972 //---------------------------------------------------------------------- 1973 // OPCODE: DW_OP_mod 1974 // OPERANDS: none 1975 // DESCRIPTION: pops the top two stack values and pushes the result of 1976 // the calculation: former second stack entry modulo the former top of 1977 // the stack. 1978 //---------------------------------------------------------------------- 1979 case DW_OP_mod: 1980 if (stack.size() < 2) 1981 { 1982 if (error_ptr) 1983 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_mod."); 1984 return false; 1985 } 1986 else 1987 { 1988 tmp = stack.back(); 1989 stack.pop_back(); 1990 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) % tmp.ResolveValue(exe_ctx); 1991 } 1992 break; 1993 1994 1995 //---------------------------------------------------------------------- 1996 // OPCODE: DW_OP_mul 1997 // OPERANDS: none 1998 // DESCRIPTION: pops the top two stack entries, multiplies them 1999 // together, and pushes the result. 2000 //---------------------------------------------------------------------- 2001 case DW_OP_mul: 2002 if (stack.size() < 2) 2003 { 2004 if (error_ptr) 2005 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_mul."); 2006 return false; 2007 } 2008 else 2009 { 2010 tmp = stack.back(); 2011 stack.pop_back(); 2012 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) * tmp.ResolveValue(exe_ctx); 2013 } 2014 break; 2015 2016 //---------------------------------------------------------------------- 2017 // OPCODE: DW_OP_neg 2018 // OPERANDS: none 2019 // DESCRIPTION: pops the top stack entry, and pushes its negation. 2020 //---------------------------------------------------------------------- 2021 case DW_OP_neg: 2022 if (stack.empty()) 2023 { 2024 if (error_ptr) 2025 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_neg."); 2026 return false; 2027 } 2028 else 2029 { 2030 if (stack.back().ResolveValue(exe_ctx).UnaryNegate() == false) 2031 { 2032 if (error_ptr) 2033 error_ptr->SetErrorString("Unary negate failed."); 2034 return false; 2035 } 2036 } 2037 break; 2038 2039 //---------------------------------------------------------------------- 2040 // OPCODE: DW_OP_not 2041 // OPERANDS: none 2042 // DESCRIPTION: pops the top stack entry, and pushes its bitwise 2043 // complement 2044 //---------------------------------------------------------------------- 2045 case DW_OP_not: 2046 if (stack.empty()) 2047 { 2048 if (error_ptr) 2049 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_not."); 2050 return false; 2051 } 2052 else 2053 { 2054 if (stack.back().ResolveValue(exe_ctx).OnesComplement() == false) 2055 { 2056 if (error_ptr) 2057 error_ptr->SetErrorString("Logical NOT failed."); 2058 return false; 2059 } 2060 } 2061 break; 2062 2063 //---------------------------------------------------------------------- 2064 // OPCODE: DW_OP_or 2065 // OPERANDS: none 2066 // DESCRIPTION: pops the top two stack entries, performs a bitwise or 2067 // operation on the two, and pushes the result. 2068 //---------------------------------------------------------------------- 2069 case DW_OP_or: 2070 if (stack.size() < 2) 2071 { 2072 if (error_ptr) 2073 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_or."); 2074 return false; 2075 } 2076 else 2077 { 2078 tmp = stack.back(); 2079 stack.pop_back(); 2080 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) | tmp.ResolveValue(exe_ctx); 2081 } 2082 break; 2083 2084 //---------------------------------------------------------------------- 2085 // OPCODE: DW_OP_plus 2086 // OPERANDS: none 2087 // DESCRIPTION: pops the top two stack entries, adds them together, and 2088 // pushes the result. 2089 //---------------------------------------------------------------------- 2090 case DW_OP_plus: 2091 if (stack.size() < 2) 2092 { 2093 if (error_ptr) 2094 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_plus."); 2095 return false; 2096 } 2097 else 2098 { 2099 tmp = stack.back(); 2100 stack.pop_back(); 2101 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) + tmp.ResolveValue(exe_ctx); 2102 } 2103 break; 2104 2105 //---------------------------------------------------------------------- 2106 // OPCODE: DW_OP_plus_uconst 2107 // OPERANDS: none 2108 // DESCRIPTION: pops the top stack entry, adds it to the unsigned LEB128 2109 // constant operand and pushes the result. 2110 //---------------------------------------------------------------------- 2111 case DW_OP_plus_uconst: 2112 if (stack.empty()) 2113 { 2114 if (error_ptr) 2115 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_plus_uconst."); 2116 return false; 2117 } 2118 else 2119 { 2120 const uint64_t uconst_value = opcodes.GetULEB128(&offset); 2121 // Implicit conversion from a UINT to a Scalar... 2122 stack.back().ResolveValue(exe_ctx) += uconst_value; 2123 if (!stack.back().ResolveValue(exe_ctx).IsValid()) 2124 { 2125 if (error_ptr) 2126 error_ptr->SetErrorString("DW_OP_plus_uconst failed."); 2127 return false; 2128 } 2129 } 2130 break; 2131 2132 //---------------------------------------------------------------------- 2133 // OPCODE: DW_OP_shl 2134 // OPERANDS: none 2135 // DESCRIPTION: pops the top two stack entries, shifts the former 2136 // second entry left by the number of bits specified by the former top 2137 // of the stack, and pushes the result. 2138 //---------------------------------------------------------------------- 2139 case DW_OP_shl: 2140 if (stack.size() < 2) 2141 { 2142 if (error_ptr) 2143 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_shl."); 2144 return false; 2145 } 2146 else 2147 { 2148 tmp = stack.back(); 2149 stack.pop_back(); 2150 stack.back().ResolveValue(exe_ctx) <<= tmp.ResolveValue(exe_ctx); 2151 } 2152 break; 2153 2154 //---------------------------------------------------------------------- 2155 // OPCODE: DW_OP_shr 2156 // OPERANDS: none 2157 // DESCRIPTION: pops the top two stack entries, shifts the former second 2158 // entry right logically (filling with zero bits) by the number of bits 2159 // specified by the former top of the stack, and pushes the result. 2160 //---------------------------------------------------------------------- 2161 case DW_OP_shr: 2162 if (stack.size() < 2) 2163 { 2164 if (error_ptr) 2165 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_shr."); 2166 return false; 2167 } 2168 else 2169 { 2170 tmp = stack.back(); 2171 stack.pop_back(); 2172 if (stack.back().ResolveValue(exe_ctx).ShiftRightLogical(tmp.ResolveValue(exe_ctx)) == false) 2173 { 2174 if (error_ptr) 2175 error_ptr->SetErrorString("DW_OP_shr failed."); 2176 return false; 2177 } 2178 } 2179 break; 2180 2181 //---------------------------------------------------------------------- 2182 // OPCODE: DW_OP_shra 2183 // OPERANDS: none 2184 // DESCRIPTION: pops the top two stack entries, shifts the former second 2185 // entry right arithmetically (divide the magnitude by 2, keep the same 2186 // sign for the result) by the number of bits specified by the former 2187 // top of the stack, and pushes the result. 2188 //---------------------------------------------------------------------- 2189 case DW_OP_shra: 2190 if (stack.size() < 2) 2191 { 2192 if (error_ptr) 2193 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_shra."); 2194 return false; 2195 } 2196 else 2197 { 2198 tmp = stack.back(); 2199 stack.pop_back(); 2200 stack.back().ResolveValue(exe_ctx) >>= tmp.ResolveValue(exe_ctx); 2201 } 2202 break; 2203 2204 //---------------------------------------------------------------------- 2205 // OPCODE: DW_OP_xor 2206 // OPERANDS: none 2207 // DESCRIPTION: pops the top two stack entries, performs the bitwise 2208 // exclusive-or operation on the two, and pushes the result. 2209 //---------------------------------------------------------------------- 2210 case DW_OP_xor: 2211 if (stack.size() < 2) 2212 { 2213 if (error_ptr) 2214 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_xor."); 2215 return false; 2216 } 2217 else 2218 { 2219 tmp = stack.back(); 2220 stack.pop_back(); 2221 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) ^ tmp.ResolveValue(exe_ctx); 2222 } 2223 break; 2224 2225 2226 //---------------------------------------------------------------------- 2227 // OPCODE: DW_OP_skip 2228 // OPERANDS: int16_t 2229 // DESCRIPTION: An unconditional branch. Its single operand is a 2-byte 2230 // signed integer constant. The 2-byte constant is the number of bytes 2231 // of the DWARF expression to skip forward or backward from the current 2232 // operation, beginning after the 2-byte constant. 2233 //---------------------------------------------------------------------- 2234 case DW_OP_skip: 2235 { 2236 int16_t skip_offset = (int16_t)opcodes.GetU16(&offset); 2237 lldb::offset_t new_offset = offset + skip_offset; 2238 if (new_offset >= opcodes_offset && new_offset < end_offset) 2239 offset = new_offset; 2240 else 2241 { 2242 if (error_ptr) 2243 error_ptr->SetErrorString("Invalid opcode offset in DW_OP_skip."); 2244 return false; 2245 } 2246 } 2247 break; 2248 2249 //---------------------------------------------------------------------- 2250 // OPCODE: DW_OP_bra 2251 // OPERANDS: int16_t 2252 // DESCRIPTION: A conditional branch. Its single operand is a 2-byte 2253 // signed integer constant. This operation pops the top of stack. If 2254 // the value popped is not the constant 0, the 2-byte constant operand 2255 // is the number of bytes of the DWARF expression to skip forward or 2256 // backward from the current operation, beginning after the 2-byte 2257 // constant. 2258 //---------------------------------------------------------------------- 2259 case DW_OP_bra: 2260 if (stack.empty()) 2261 { 2262 if (error_ptr) 2263 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_bra."); 2264 return false; 2265 } 2266 else 2267 { 2268 tmp = stack.back(); 2269 stack.pop_back(); 2270 int16_t bra_offset = (int16_t)opcodes.GetU16(&offset); 2271 Scalar zero(0); 2272 if (tmp.ResolveValue(exe_ctx) != zero) 2273 { 2274 lldb::offset_t new_offset = offset + bra_offset; 2275 if (new_offset >= opcodes_offset && new_offset < end_offset) 2276 offset = new_offset; 2277 else 2278 { 2279 if (error_ptr) 2280 error_ptr->SetErrorString("Invalid opcode offset in DW_OP_bra."); 2281 return false; 2282 } 2283 } 2284 } 2285 break; 2286 2287 //---------------------------------------------------------------------- 2288 // OPCODE: DW_OP_eq 2289 // OPERANDS: none 2290 // DESCRIPTION: pops the top two stack values, compares using the 2291 // equals (==) operator. 2292 // STACK RESULT: push the constant value 1 onto the stack if the result 2293 // of the operation is true or the constant value 0 if the result of the 2294 // operation is false. 2295 //---------------------------------------------------------------------- 2296 case DW_OP_eq: 2297 if (stack.size() < 2) 2298 { 2299 if (error_ptr) 2300 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_eq."); 2301 return false; 2302 } 2303 else 2304 { 2305 tmp = stack.back(); 2306 stack.pop_back(); 2307 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) == tmp.ResolveValue(exe_ctx); 2308 } 2309 break; 2310 2311 //---------------------------------------------------------------------- 2312 // OPCODE: DW_OP_ge 2313 // OPERANDS: none 2314 // DESCRIPTION: pops the top two stack values, compares using the 2315 // greater than or equal to (>=) operator. 2316 // STACK RESULT: push the constant value 1 onto the stack if the result 2317 // of the operation is true or the constant value 0 if the result of the 2318 // operation is false. 2319 //---------------------------------------------------------------------- 2320 case DW_OP_ge: 2321 if (stack.size() < 2) 2322 { 2323 if (error_ptr) 2324 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_ge."); 2325 return false; 2326 } 2327 else 2328 { 2329 tmp = stack.back(); 2330 stack.pop_back(); 2331 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) >= tmp.ResolveValue(exe_ctx); 2332 } 2333 break; 2334 2335 //---------------------------------------------------------------------- 2336 // OPCODE: DW_OP_gt 2337 // OPERANDS: none 2338 // DESCRIPTION: pops the top two stack values, compares using the 2339 // greater than (>) operator. 2340 // STACK RESULT: push the constant value 1 onto the stack if the result 2341 // of the operation is true or the constant value 0 if the result of the 2342 // operation is false. 2343 //---------------------------------------------------------------------- 2344 case DW_OP_gt: 2345 if (stack.size() < 2) 2346 { 2347 if (error_ptr) 2348 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_gt."); 2349 return false; 2350 } 2351 else 2352 { 2353 tmp = stack.back(); 2354 stack.pop_back(); 2355 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) > tmp.ResolveValue(exe_ctx); 2356 } 2357 break; 2358 2359 //---------------------------------------------------------------------- 2360 // OPCODE: DW_OP_le 2361 // OPERANDS: none 2362 // DESCRIPTION: pops the top two stack values, compares using the 2363 // less than or equal to (<=) operator. 2364 // STACK RESULT: push the constant value 1 onto the stack if the result 2365 // of the operation is true or the constant value 0 if the result of the 2366 // operation is false. 2367 //---------------------------------------------------------------------- 2368 case DW_OP_le: 2369 if (stack.size() < 2) 2370 { 2371 if (error_ptr) 2372 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_le."); 2373 return false; 2374 } 2375 else 2376 { 2377 tmp = stack.back(); 2378 stack.pop_back(); 2379 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) <= tmp.ResolveValue(exe_ctx); 2380 } 2381 break; 2382 2383 //---------------------------------------------------------------------- 2384 // OPCODE: DW_OP_lt 2385 // OPERANDS: none 2386 // DESCRIPTION: pops the top two stack values, compares using the 2387 // less than (<) operator. 2388 // STACK RESULT: push the constant value 1 onto the stack if the result 2389 // of the operation is true or the constant value 0 if the result of the 2390 // operation is false. 2391 //---------------------------------------------------------------------- 2392 case DW_OP_lt: 2393 if (stack.size() < 2) 2394 { 2395 if (error_ptr) 2396 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_lt."); 2397 return false; 2398 } 2399 else 2400 { 2401 tmp = stack.back(); 2402 stack.pop_back(); 2403 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) < tmp.ResolveValue(exe_ctx); 2404 } 2405 break; 2406 2407 //---------------------------------------------------------------------- 2408 // OPCODE: DW_OP_ne 2409 // OPERANDS: none 2410 // DESCRIPTION: pops the top two stack values, compares using the 2411 // not equal (!=) operator. 2412 // STACK RESULT: push the constant value 1 onto the stack if the result 2413 // of the operation is true or the constant value 0 if the result of the 2414 // operation is false. 2415 //---------------------------------------------------------------------- 2416 case DW_OP_ne: 2417 if (stack.size() < 2) 2418 { 2419 if (error_ptr) 2420 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_ne."); 2421 return false; 2422 } 2423 else 2424 { 2425 tmp = stack.back(); 2426 stack.pop_back(); 2427 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) != tmp.ResolveValue(exe_ctx); 2428 } 2429 break; 2430 2431 //---------------------------------------------------------------------- 2432 // OPCODE: DW_OP_litn 2433 // OPERANDS: none 2434 // DESCRIPTION: encode the unsigned literal values from 0 through 31. 2435 // STACK RESULT: push the unsigned literal constant value onto the top 2436 // of the stack. 2437 //---------------------------------------------------------------------- 2438 case DW_OP_lit0: 2439 case DW_OP_lit1: 2440 case DW_OP_lit2: 2441 case DW_OP_lit3: 2442 case DW_OP_lit4: 2443 case DW_OP_lit5: 2444 case DW_OP_lit6: 2445 case DW_OP_lit7: 2446 case DW_OP_lit8: 2447 case DW_OP_lit9: 2448 case DW_OP_lit10: 2449 case DW_OP_lit11: 2450 case DW_OP_lit12: 2451 case DW_OP_lit13: 2452 case DW_OP_lit14: 2453 case DW_OP_lit15: 2454 case DW_OP_lit16: 2455 case DW_OP_lit17: 2456 case DW_OP_lit18: 2457 case DW_OP_lit19: 2458 case DW_OP_lit20: 2459 case DW_OP_lit21: 2460 case DW_OP_lit22: 2461 case DW_OP_lit23: 2462 case DW_OP_lit24: 2463 case DW_OP_lit25: 2464 case DW_OP_lit26: 2465 case DW_OP_lit27: 2466 case DW_OP_lit28: 2467 case DW_OP_lit29: 2468 case DW_OP_lit30: 2469 case DW_OP_lit31: 2470 stack.push_back(Scalar(op - DW_OP_lit0)); 2471 break; 2472 2473 //---------------------------------------------------------------------- 2474 // OPCODE: DW_OP_regN 2475 // OPERANDS: none 2476 // DESCRIPTION: Push the value in register n on the top of the stack. 2477 //---------------------------------------------------------------------- 2478 case DW_OP_reg0: 2479 case DW_OP_reg1: 2480 case DW_OP_reg2: 2481 case DW_OP_reg3: 2482 case DW_OP_reg4: 2483 case DW_OP_reg5: 2484 case DW_OP_reg6: 2485 case DW_OP_reg7: 2486 case DW_OP_reg8: 2487 case DW_OP_reg9: 2488 case DW_OP_reg10: 2489 case DW_OP_reg11: 2490 case DW_OP_reg12: 2491 case DW_OP_reg13: 2492 case DW_OP_reg14: 2493 case DW_OP_reg15: 2494 case DW_OP_reg16: 2495 case DW_OP_reg17: 2496 case DW_OP_reg18: 2497 case DW_OP_reg19: 2498 case DW_OP_reg20: 2499 case DW_OP_reg21: 2500 case DW_OP_reg22: 2501 case DW_OP_reg23: 2502 case DW_OP_reg24: 2503 case DW_OP_reg25: 2504 case DW_OP_reg26: 2505 case DW_OP_reg27: 2506 case DW_OP_reg28: 2507 case DW_OP_reg29: 2508 case DW_OP_reg30: 2509 case DW_OP_reg31: 2510 { 2511 reg_num = op - DW_OP_reg0; 2512 2513 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp)) 2514 stack.push_back(tmp); 2515 else 2516 return false; 2517 } 2518 break; 2519 //---------------------------------------------------------------------- 2520 // OPCODE: DW_OP_regx 2521 // OPERANDS: 2522 // ULEB128 literal operand that encodes the register. 2523 // DESCRIPTION: Push the value in register on the top of the stack. 2524 //---------------------------------------------------------------------- 2525 case DW_OP_regx: 2526 { 2527 reg_num = opcodes.GetULEB128(&offset); 2528 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp)) 2529 stack.push_back(tmp); 2530 else 2531 return false; 2532 } 2533 break; 2534 2535 //---------------------------------------------------------------------- 2536 // OPCODE: DW_OP_bregN 2537 // OPERANDS: 2538 // SLEB128 offset from register N 2539 // DESCRIPTION: Value is in memory at the address specified by register 2540 // N plus an offset. 2541 //---------------------------------------------------------------------- 2542 case DW_OP_breg0: 2543 case DW_OP_breg1: 2544 case DW_OP_breg2: 2545 case DW_OP_breg3: 2546 case DW_OP_breg4: 2547 case DW_OP_breg5: 2548 case DW_OP_breg6: 2549 case DW_OP_breg7: 2550 case DW_OP_breg8: 2551 case DW_OP_breg9: 2552 case DW_OP_breg10: 2553 case DW_OP_breg11: 2554 case DW_OP_breg12: 2555 case DW_OP_breg13: 2556 case DW_OP_breg14: 2557 case DW_OP_breg15: 2558 case DW_OP_breg16: 2559 case DW_OP_breg17: 2560 case DW_OP_breg18: 2561 case DW_OP_breg19: 2562 case DW_OP_breg20: 2563 case DW_OP_breg21: 2564 case DW_OP_breg22: 2565 case DW_OP_breg23: 2566 case DW_OP_breg24: 2567 case DW_OP_breg25: 2568 case DW_OP_breg26: 2569 case DW_OP_breg27: 2570 case DW_OP_breg28: 2571 case DW_OP_breg29: 2572 case DW_OP_breg30: 2573 case DW_OP_breg31: 2574 { 2575 reg_num = op - DW_OP_breg0; 2576 2577 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp)) 2578 { 2579 int64_t breg_offset = opcodes.GetSLEB128(&offset); 2580 tmp.ResolveValue(exe_ctx) += (uint64_t)breg_offset; 2581 tmp.ClearContext(); 2582 stack.push_back(tmp); 2583 stack.back().SetValueType (Value::eValueTypeLoadAddress); 2584 } 2585 else 2586 return false; 2587 } 2588 break; 2589 //---------------------------------------------------------------------- 2590 // OPCODE: DW_OP_bregx 2591 // OPERANDS: 2 2592 // ULEB128 literal operand that encodes the register. 2593 // SLEB128 offset from register N 2594 // DESCRIPTION: Value is in memory at the address specified by register 2595 // N plus an offset. 2596 //---------------------------------------------------------------------- 2597 case DW_OP_bregx: 2598 { 2599 reg_num = opcodes.GetULEB128(&offset); 2600 2601 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp)) 2602 { 2603 int64_t breg_offset = opcodes.GetSLEB128(&offset); 2604 tmp.ResolveValue(exe_ctx) += (uint64_t)breg_offset; 2605 tmp.ClearContext(); 2606 stack.push_back(tmp); 2607 stack.back().SetValueType (Value::eValueTypeLoadAddress); 2608 } 2609 else 2610 return false; 2611 } 2612 break; 2613 2614 case DW_OP_fbreg: 2615 if (exe_ctx) 2616 { 2617 if (frame) 2618 { 2619 Scalar value; 2620 if (frame->GetFrameBaseValue(value, error_ptr)) 2621 { 2622 int64_t fbreg_offset = opcodes.GetSLEB128(&offset); 2623 value += fbreg_offset; 2624 stack.push_back(value); 2625 stack.back().SetValueType (Value::eValueTypeLoadAddress); 2626 } 2627 else 2628 return false; 2629 } 2630 else 2631 { 2632 if (error_ptr) 2633 error_ptr->SetErrorString ("Invalid stack frame in context for DW_OP_fbreg opcode."); 2634 return false; 2635 } 2636 } 2637 else 2638 { 2639 if (error_ptr) 2640 error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_fbreg.\n"); 2641 return false; 2642 } 2643 2644 break; 2645 2646 //---------------------------------------------------------------------- 2647 // OPCODE: DW_OP_nop 2648 // OPERANDS: none 2649 // DESCRIPTION: A place holder. It has no effect on the location stack 2650 // or any of its values. 2651 //---------------------------------------------------------------------- 2652 case DW_OP_nop: 2653 break; 2654 2655 //---------------------------------------------------------------------- 2656 // OPCODE: DW_OP_piece 2657 // OPERANDS: 1 2658 // ULEB128: byte size of the piece 2659 // DESCRIPTION: The operand describes the size in bytes of the piece of 2660 // the object referenced by the DWARF expression whose result is at the 2661 // top of the stack. If the piece is located in a register, but does not 2662 // occupy the entire register, the placement of the piece within that 2663 // register is defined by the ABI. 2664 // 2665 // Many compilers store a single variable in sets of registers, or store 2666 // a variable partially in memory and partially in registers. 2667 // DW_OP_piece provides a way of describing how large a part of a 2668 // variable a particular DWARF expression refers to. 2669 //---------------------------------------------------------------------- 2670 case DW_OP_piece: 2671 { 2672 const uint64_t piece_byte_size = opcodes.GetULEB128(&offset); 2673 2674 if (piece_byte_size > 0) 2675 { 2676 Value curr_piece; 2677 2678 if (stack.empty()) 2679 { 2680 // In a multi-piece expression, this means that the current piece is not available. 2681 // Fill with zeros for now by resizing the data and appending it 2682 curr_piece.ResizeData(piece_byte_size); 2683 ::memset (curr_piece.GetBuffer().GetBytes(), 0, piece_byte_size); 2684 pieces.AppendDataToHostBuffer(curr_piece); 2685 } 2686 else 2687 { 2688 Error error; 2689 // Extract the current piece into "curr_piece" 2690 Value curr_piece_source_value(stack.back()); 2691 stack.pop_back(); 2692 2693 const Value::ValueType curr_piece_source_value_type = curr_piece_source_value.GetValueType(); 2694 switch (curr_piece_source_value_type) 2695 { 2696 case Value::eValueTypeLoadAddress: 2697 if (process) 2698 { 2699 if (curr_piece.ResizeData(piece_byte_size) == piece_byte_size) 2700 { 2701 lldb::addr_t load_addr = curr_piece_source_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 2702 if (process->ReadMemory(load_addr, curr_piece.GetBuffer().GetBytes(), piece_byte_size, error) != piece_byte_size) 2703 { 2704 if (error_ptr) 2705 error_ptr->SetErrorStringWithFormat ("failed to read memory DW_OP_piece(%" PRIu64 ") from 0x%" PRIx64, 2706 piece_byte_size, 2707 load_addr); 2708 return false; 2709 } 2710 } 2711 else 2712 { 2713 if (error_ptr) 2714 error_ptr->SetErrorStringWithFormat ("failed to resize the piece memory buffer for DW_OP_piece(%" PRIu64 ")", piece_byte_size); 2715 return false; 2716 } 2717 } 2718 break; 2719 2720 case Value::eValueTypeFileAddress: 2721 case Value::eValueTypeHostAddress: 2722 if (error_ptr) 2723 { 2724 lldb::addr_t addr = curr_piece_source_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 2725 error_ptr->SetErrorStringWithFormat ("failed to read memory DW_OP_piece(%" PRIu64 ") from %s address 0x%" PRIx64, 2726 piece_byte_size, 2727 curr_piece_source_value.GetValueType() == Value::eValueTypeFileAddress ? "file" : "host", 2728 addr); 2729 } 2730 return false; 2731 2732 case Value::eValueTypeScalar: 2733 { 2734 uint32_t bit_size = piece_byte_size * 8; 2735 uint32_t bit_offset = 0; 2736 if (!curr_piece_source_value.GetScalar().ExtractBitfield (bit_size, bit_offset)) 2737 { 2738 if (error_ptr) 2739 error_ptr->SetErrorStringWithFormat("unable to extract %" PRIu64 " bytes from a %" PRIu64 " byte scalar value.", piece_byte_size, (uint64_t)curr_piece_source_value.GetScalar().GetByteSize()); 2740 return false; 2741 } 2742 curr_piece = curr_piece_source_value; 2743 } 2744 break; 2745 2746 case Value::eValueTypeVector: 2747 { 2748 if (curr_piece_source_value.GetVector().length >= piece_byte_size) 2749 curr_piece_source_value.GetVector().length = piece_byte_size; 2750 else 2751 { 2752 if (error_ptr) 2753 error_ptr->SetErrorStringWithFormat("unable to extract %" PRIu64 " bytes from a %" PRIu64 " byte vector value.", piece_byte_size, (uint64_t)curr_piece_source_value.GetVector().length); 2754 return false; 2755 } 2756 } 2757 break; 2758 2759 } 2760 2761 // Check if this is the first piece? 2762 if (op_piece_offset == 0) 2763 { 2764 // This is the first piece, we should push it back onto the stack so subsequent 2765 // pieces will be able to access this piece and add to it 2766 if (pieces.AppendDataToHostBuffer(curr_piece) == 0) 2767 { 2768 if (error_ptr) 2769 error_ptr->SetErrorString("failed to append piece data"); 2770 return false; 2771 } 2772 } 2773 else 2774 { 2775 // If this is the second or later piece there should be a value on the stack 2776 if (pieces.GetBuffer().GetByteSize() != op_piece_offset) 2777 { 2778 if (error_ptr) 2779 error_ptr->SetErrorStringWithFormat ("DW_OP_piece for offset %" PRIu64 " but top of stack is of size %" PRIu64, 2780 op_piece_offset, 2781 pieces.GetBuffer().GetByteSize()); 2782 return false; 2783 } 2784 2785 if (pieces.AppendDataToHostBuffer(curr_piece) == 0) 2786 { 2787 if (error_ptr) 2788 error_ptr->SetErrorString("failed to append piece data"); 2789 return false; 2790 } 2791 } 2792 op_piece_offset += piece_byte_size; 2793 } 2794 } 2795 } 2796 break; 2797 2798 case DW_OP_bit_piece: // 0x9d ULEB128 bit size, ULEB128 bit offset (DWARF3); 2799 if (stack.size() < 1) 2800 { 2801 if (error_ptr) 2802 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_bit_piece."); 2803 return false; 2804 } 2805 else 2806 { 2807 const uint64_t piece_bit_size = opcodes.GetULEB128(&offset); 2808 const uint64_t piece_bit_offset = opcodes.GetULEB128(&offset); 2809 switch (stack.back().GetValueType()) 2810 { 2811 case Value::eValueTypeScalar: 2812 { 2813 if (!stack.back().GetScalar().ExtractBitfield (piece_bit_size, piece_bit_offset)) 2814 { 2815 if (error_ptr) 2816 error_ptr->SetErrorStringWithFormat("unable to extract %" PRIu64 " bit value with %" PRIu64 " bit offset from a %" PRIu64 " bit scalar value.", 2817 piece_bit_size, 2818 piece_bit_offset, 2819 (uint64_t)(stack.back().GetScalar().GetByteSize()*8)); 2820 return false; 2821 } 2822 } 2823 break; 2824 2825 case Value::eValueTypeFileAddress: 2826 case Value::eValueTypeLoadAddress: 2827 case Value::eValueTypeHostAddress: 2828 if (error_ptr) 2829 { 2830 error_ptr->SetErrorStringWithFormat ("unable to extract DW_OP_bit_piece(bit_size = %" PRIu64 ", bit_offset = %" PRIu64 ") from an addresss value.", 2831 piece_bit_size, 2832 piece_bit_offset); 2833 } 2834 return false; 2835 2836 case Value::eValueTypeVector: 2837 if (error_ptr) 2838 { 2839 error_ptr->SetErrorStringWithFormat ("unable to extract DW_OP_bit_piece(bit_size = %" PRIu64 ", bit_offset = %" PRIu64 ") from a vector value.", 2840 piece_bit_size, 2841 piece_bit_offset); 2842 } 2843 return false; 2844 } 2845 } 2846 break; 2847 2848 //---------------------------------------------------------------------- 2849 // OPCODE: DW_OP_push_object_address 2850 // OPERANDS: none 2851 // DESCRIPTION: Pushes the address of the object currently being 2852 // evaluated as part of evaluation of a user presented expression. 2853 // This object may correspond to an independent variable described by 2854 // its own DIE or it may be a component of an array, structure, or class 2855 // whose address has been dynamically determined by an earlier step 2856 // during user expression evaluation. 2857 //---------------------------------------------------------------------- 2858 case DW_OP_push_object_address: 2859 if (error_ptr) 2860 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_push_object_address."); 2861 return false; 2862 2863 //---------------------------------------------------------------------- 2864 // OPCODE: DW_OP_call2 2865 // OPERANDS: 2866 // uint16_t compile unit relative offset of a DIE 2867 // DESCRIPTION: Performs subroutine calls during evaluation 2868 // of a DWARF expression. The operand is the 2-byte unsigned offset 2869 // of a debugging information entry in the current compilation unit. 2870 // 2871 // Operand interpretation is exactly like that for DW_FORM_ref2. 2872 // 2873 // This operation transfers control of DWARF expression evaluation 2874 // to the DW_AT_location attribute of the referenced DIE. If there is 2875 // no such attribute, then there is no effect. Execution of the DWARF 2876 // expression of a DW_AT_location attribute may add to and/or remove from 2877 // values on the stack. Execution returns to the point following the call 2878 // when the end of the attribute is reached. Values on the stack at the 2879 // time of the call may be used as parameters by the called expression 2880 // and values left on the stack by the called expression may be used as 2881 // return values by prior agreement between the calling and called 2882 // expressions. 2883 //---------------------------------------------------------------------- 2884 case DW_OP_call2: 2885 if (error_ptr) 2886 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_call2."); 2887 return false; 2888 //---------------------------------------------------------------------- 2889 // OPCODE: DW_OP_call4 2890 // OPERANDS: 1 2891 // uint32_t compile unit relative offset of a DIE 2892 // DESCRIPTION: Performs a subroutine call during evaluation of a DWARF 2893 // expression. For DW_OP_call4, the operand is a 4-byte unsigned offset 2894 // of a debugging information entry in the current compilation unit. 2895 // 2896 // Operand interpretation DW_OP_call4 is exactly like that for 2897 // DW_FORM_ref4. 2898 // 2899 // This operation transfers control of DWARF expression evaluation 2900 // to the DW_AT_location attribute of the referenced DIE. If there is 2901 // no such attribute, then there is no effect. Execution of the DWARF 2902 // expression of a DW_AT_location attribute may add to and/or remove from 2903 // values on the stack. Execution returns to the point following the call 2904 // when the end of the attribute is reached. Values on the stack at the 2905 // time of the call may be used as parameters by the called expression 2906 // and values left on the stack by the called expression may be used as 2907 // return values by prior agreement between the calling and called 2908 // expressions. 2909 //---------------------------------------------------------------------- 2910 case DW_OP_call4: 2911 if (error_ptr) 2912 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_call4."); 2913 return false; 2914 2915 //---------------------------------------------------------------------- 2916 // OPCODE: DW_OP_stack_value 2917 // OPERANDS: None 2918 // DESCRIPTION: Specifies that the object does not exist in memory but 2919 // rather is a constant value. The value from the top of the stack is 2920 // the value to be used. This is the actual object value and not the 2921 // location. 2922 //---------------------------------------------------------------------- 2923 case DW_OP_stack_value: 2924 stack.back().SetValueType(Value::eValueTypeScalar); 2925 break; 2926 2927 //---------------------------------------------------------------------- 2928 // OPCODE: DW_OP_call_frame_cfa 2929 // OPERANDS: None 2930 // DESCRIPTION: Specifies a DWARF expression that pushes the value of 2931 // the canonical frame address consistent with the call frame information 2932 // located in .debug_frame (or in the FDEs of the eh_frame section). 2933 //---------------------------------------------------------------------- 2934 case DW_OP_call_frame_cfa: 2935 if (frame) 2936 { 2937 // Note that we don't have to parse FDEs because this DWARF expression 2938 // is commonly evaluated with a valid stack frame. 2939 StackID id = frame->GetStackID(); 2940 addr_t cfa = id.GetCallFrameAddress(); 2941 if (cfa != LLDB_INVALID_ADDRESS) 2942 { 2943 stack.push_back(Scalar(cfa)); 2944 stack.back().SetValueType (Value::eValueTypeLoadAddress); 2945 } 2946 else 2947 if (error_ptr) 2948 error_ptr->SetErrorString ("Stack frame does not include a canonical frame address for DW_OP_call_frame_cfa opcode."); 2949 } 2950 else 2951 { 2952 if (error_ptr) 2953 error_ptr->SetErrorString ("Invalid stack frame in context for DW_OP_call_frame_cfa opcode."); 2954 return false; 2955 } 2956 break; 2957 2958 //---------------------------------------------------------------------- 2959 // OPCODE: DW_OP_form_tls_address (or the old pre-DWARFv3 vendor extension opcode, DW_OP_GNU_push_tls_address) 2960 // OPERANDS: none 2961 // DESCRIPTION: Pops a TLS offset from the stack, converts it to 2962 // an address in the current thread's thread-local storage block, 2963 // and pushes it on the stack. 2964 //---------------------------------------------------------------------- 2965 case DW_OP_form_tls_address: 2966 case DW_OP_GNU_push_tls_address: 2967 { 2968 if (stack.size() < 1) 2969 { 2970 if (error_ptr) 2971 { 2972 if (op == DW_OP_form_tls_address) 2973 error_ptr->SetErrorString("DW_OP_form_tls_address needs an argument."); 2974 else 2975 error_ptr->SetErrorString("DW_OP_GNU_push_tls_address needs an argument."); 2976 } 2977 return false; 2978 } 2979 2980 if (!exe_ctx || !module_sp) 2981 { 2982 if (error_ptr) 2983 error_ptr->SetErrorString("No context to evaluate TLS within."); 2984 return false; 2985 } 2986 2987 Thread *thread = exe_ctx->GetThreadPtr(); 2988 if (!thread) 2989 { 2990 if (error_ptr) 2991 error_ptr->SetErrorString("No thread to evaluate TLS within."); 2992 return false; 2993 } 2994 2995 // Lookup the TLS block address for this thread and module. 2996 addr_t tls_addr = thread->GetThreadLocalData (module_sp); 2997 2998 if (tls_addr == LLDB_INVALID_ADDRESS) 2999 { 3000 if (error_ptr) 3001 error_ptr->SetErrorString ("No TLS data currently exists for this thread."); 3002 return false; 3003 } 3004 3005 // Convert the TLS offset into the absolute address. 3006 Scalar tmp = stack.back().ResolveValue(exe_ctx); 3007 stack.back() = tmp + tls_addr; 3008 stack.back().SetValueType (Value::eValueTypeLoadAddress); 3009 } 3010 break; 3011 3012 //---------------------------------------------------------------------- 3013 // OPCODE: DW_OP_GNU_addr_index 3014 // OPERANDS: 1 3015 // ULEB128: index to the .debug_addr section 3016 // DESCRIPTION: Pushes an address to the stack from the .debug_addr 3017 // section with the base address specified by the DW_AT_addr_base 3018 // attribute and the 0 based index is the ULEB128 encoded index. 3019 //---------------------------------------------------------------------- 3020 case DW_OP_GNU_addr_index: 3021 { 3022 if (!dwarf_cu) 3023 { 3024 if (error_ptr) 3025 error_ptr->SetErrorString ("DW_OP_GNU_addr_index found without a compile being specified"); 3026 return false; 3027 } 3028 uint64_t index = opcodes.GetULEB128(&offset); 3029 uint32_t index_size = dwarf_cu->GetAddressByteSize(); 3030 dw_offset_t addr_base = dwarf_cu->GetAddrBase(); 3031 lldb::offset_t offset = addr_base + index * index_size; 3032 uint64_t value = dwarf_cu->GetSymbolFileDWARF()->get_debug_addr_data().GetMaxU64(&offset, index_size); 3033 stack.push_back(Scalar(value)); 3034 stack.back().SetValueType(Value::eValueTypeFileAddress); 3035 } 3036 break; 3037 3038 default: 3039 if (log) 3040 log->Printf("Unhandled opcode %s in DWARFExpression.", DW_OP_value_to_name(op)); 3041 break; 3042 } 3043 } 3044 3045 if (stack.empty()) 3046 { 3047 // Nothing on the stack, check if we created a piece value from DW_OP_piece or DW_OP_bit_piece opcodes 3048 if (pieces.GetBuffer().GetByteSize()) 3049 { 3050 result = pieces; 3051 } 3052 else 3053 { 3054 if (error_ptr) 3055 error_ptr->SetErrorString ("Stack empty after evaluation."); 3056 return false; 3057 } 3058 } 3059 else 3060 { 3061 if (log && log->GetVerbose()) 3062 { 3063 size_t count = stack.size(); 3064 log->Printf("Stack after operation has %" PRIu64 " values:", (uint64_t)count); 3065 for (size_t i=0; i<count; ++i) 3066 { 3067 StreamString new_value; 3068 new_value.Printf("[%" PRIu64 "]", (uint64_t)i); 3069 stack[i].Dump(&new_value); 3070 log->Printf(" %s", new_value.GetData()); 3071 } 3072 } 3073 result = stack.back(); 3074 } 3075 return true; // Return true on success 3076 } 3077 3078