1 //===-- DWARFLocationDescription.cpp ----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "DWARFLocationDescription.h"
11 #include "DWARFDefines.h"
12 #include "lldb/lldb-private.h"
13 #include "lldb/Core/Stream.h"
16 using namespace lldb_private;
18 static int print_dwarf_exp_op (Stream &s, const DataExtractor& data, lldb::offset_t *offset_ptr, int address_size, int dwarf_ref_size);
21 print_dwarf_expression (Stream &s,
22 const DataExtractor& data,
25 bool location_expression)
28 lldb::offset_t offset = 0;
29 while (data.ValidOffset(offset))
31 if (location_expression && op_count > 0)
33 // err (baton, "Dwarf location expressions may only have one operand!");
40 if (print_dwarf_exp_op (s, data, &offset, address_size, dwarf_ref_size) == 1)
49 print_dwarf_exp_op (Stream &s,
50 const DataExtractor& data,
51 lldb::offset_t *offset_ptr,
55 uint8_t opcode = data.GetU8(offset_ptr);
56 DRC_class opcode_class;
62 opcode_class = DW_OP_value_to_class (opcode) & (~DRC_DWARFv3);
64 s.Printf("%s ", DW_OP_value_to_name (opcode));
66 /* Does this take zero parameters? If so we can shortcut this function. */
67 if (opcode_class == DRC_ZEROOPERANDS)
70 if (opcode_class == DRC_TWOOPERANDS && opcode == DW_OP_bregx)
72 uint = data.GetULEB128(offset_ptr);
73 sint = data.GetSLEB128(offset_ptr);
74 s.Printf("%" PRIu64 " %" PRIi64, uint, sint);
77 if (opcode_class != DRC_ONEOPERAND)
79 s.Printf("UNKNOWN OP %u", opcode);
85 case DW_OP_addr: size = address_size; break;
86 case DW_OP_const1u: size = 1; break;
87 case DW_OP_const1s: size = -1; break;
88 case DW_OP_const2u: size = 2; break;
89 case DW_OP_const2s: size = -2; break;
90 case DW_OP_const4u: size = 4; break;
91 case DW_OP_const4s: size = -4; break;
92 case DW_OP_const8u: size = 8; break;
93 case DW_OP_const8s: size = -8; break;
94 case DW_OP_constu: size = 128; break;
95 case DW_OP_consts: size = -128; break;
96 case DW_OP_fbreg: size = -128; break;
132 case DW_OP_deref_size:
134 case DW_OP_xderef_size:
136 case DW_OP_plus_uconst:
147 size = dwarf_ref_size; break;
153 s.Printf("UNKNOWN ONE-OPERAND OPCODE, #%u", opcode);
159 case -1: sint = (int8_t) data.GetU8(offset_ptr); s.Printf("%+" PRIi64, sint); break;
160 case -2: sint = (int16_t) data.GetU16(offset_ptr); s.Printf("%+" PRIi64, sint); break;
161 case -4: sint = (int32_t) data.GetU32(offset_ptr); s.Printf("%+" PRIi64, sint); break;
162 case -8: sint = (int64_t) data.GetU64(offset_ptr); s.Printf("%+" PRIi64, sint); break;
163 case -128: sint = data.GetSLEB128(offset_ptr); s.Printf("%+" PRIi64, sint); break;
164 case 1: uint = data.GetU8(offset_ptr); s.Printf("0x%2.2" PRIx64, uint); break;
165 case 2: uint = data.GetU16(offset_ptr); s.Printf("0x%4.4" PRIx64, uint); break;
166 case 4: uint = data.GetU32(offset_ptr); s.Printf("0x%8.8" PRIx64, uint); break;
167 case 8: uint = data.GetU64(offset_ptr); s.Printf("0x%16.16" PRIx64, uint); break;
168 case 128: uint = data.GetULEB128(offset_ptr); s.Printf("0x%" PRIx64, uint); break;