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