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