SBValue.h revision 533ed2fd6d3763654cd35cdc2379e1bf1049e0dd
1//===-- SBValue.h -----------------------------------------------*- 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#ifndef LLDB_SBValue_h_ 11#define LLDB_SBValue_h_ 12 13#include "lldb/API/SBDefines.h" 14 15#include <stdio.h> 16 17namespace lldb { 18 19#ifdef SWIG 20%feature("docstring", 21"Represents the value of a variable, a register, or an expression. 22 23SBValue supports iteration through its child, which in turn is represented 24as an SBValue. For example, we can get the general purpose registers of a 25frame as an SBValue, and iterate through all the registers, 26 27 registerSet = frame.GetRegisters() # Returns an SBValueList. 28 for regs in registerSet: 29 if 'general purpose registers' in regs.getName().lower(): 30 GPRs = regs 31 break 32 33 print '%s (number of children = %d):' % (GPRs.GetName(), GPRs.GetNumChildren()) 34 for reg in GPRs: 35 print 'Name: ', reg.GetName(), ' Value: ', reg.GetValue() 36 37produces the output: 38 39General Purpose Registers (number of children = 21): 40Name: rax Value: 0x0000000100000c5c 41Name: rbx Value: 0x0000000000000000 42Name: rcx Value: 0x00007fff5fbffec0 43Name: rdx Value: 0x00007fff5fbffeb8 44Name: rdi Value: 0x0000000000000001 45Name: rsi Value: 0x00007fff5fbffea8 46Name: rbp Value: 0x00007fff5fbffe80 47Name: rsp Value: 0x00007fff5fbffe60 48Name: r8 Value: 0x0000000008668682 49Name: r9 Value: 0x0000000000000000 50Name: r10 Value: 0x0000000000001200 51Name: r11 Value: 0x0000000000000206 52Name: r12 Value: 0x0000000000000000 53Name: r13 Value: 0x0000000000000000 54Name: r14 Value: 0x0000000000000000 55Name: r15 Value: 0x0000000000000000 56Name: rip Value: 0x0000000100000dae 57Name: rflags Value: 0x0000000000000206 58Name: cs Value: 0x0000000000000027 59Name: fs Value: 0x0000000000000010 60Name: gs Value: 0x0000000000000048 61" 62 ) SBValue; 63#endif 64class SBValue 65{ 66#ifdef SWIG 67 %feature("autodoc", "1"); 68#endif 69public: 70 SBValue (); 71 72 SBValue (const SBValue &rhs); 73 74#ifndef SWIG 75 const SBValue & 76 operator =(const SBValue &rhs); 77#endif 78 79 ~SBValue (); 80 81 bool 82 IsValid() const; 83 84 SBError 85 GetError(); 86 87 lldb::user_id_t 88 GetID (); 89 90 const char * 91 GetName(); 92 93 const char * 94 GetTypeName (); 95 96 size_t 97 GetByteSize (); 98 99 bool 100 IsInScope (const lldb::SBFrame &frame); // DEPRECATED - SBValues know their own frames. 101 102 bool 103 IsInScope (); 104 105 lldb::Format 106 GetFormat () const; 107 108 void 109 SetFormat (lldb::Format format); 110 111 const char * 112 GetValue (const lldb::SBFrame &frame); // DEPRECATED - SBValues know their own frames. 113 114 const char * 115 GetValue (); 116 117 ValueType 118 GetValueType (); 119 120 bool 121 GetValueDidChange (const lldb::SBFrame &frame); // DEPRECATED - SBValues know their own frames. 122 123 bool 124 GetValueDidChange (); 125 126 const char * 127 GetSummary (const lldb::SBFrame &frame); // DEPRECATED - SBValues know their own frames. 128 129 const char * 130 GetSummary (); 131 132 const char * 133 GetObjectDescription (const lldb::SBFrame &frame); // DEPRECATED - SBValues know their own frames. 134 135 const char * 136 GetObjectDescription (); 137 138 const char * 139 GetLocation (const lldb::SBFrame &frame); // DEPRECATED - SBValues know their own frames. 140 141 const char * 142 GetLocation (); 143 144 bool 145 SetValueFromCString (const lldb::SBFrame &frame, const char *value_str); // DEPRECATED - SBValues know their own frames. 146 147 bool 148 SetValueFromCString (const char *value_str); 149 150 lldb::SBValue 151 GetChildAtIndex (uint32_t idx); 152 153#ifdef SWIG 154 %feature("docstring", " 155#endif 156 //------------------------------------------------------------------ 157 /// Get a child value by index from a value. 158 /// 159 /// Structs, unions, classes, arrays and and pointers have child 160 /// values that can be access by index. 161 /// 162 /// Structs and unions access child members using a zero based index 163 /// for each child member. For 164 /// 165 /// Classes reserve the first indexes for base classes that have 166 /// members (empty base classes are omitted), and all members of the 167 /// current class will then follow the base classes. 168 /// 169 /// Pointers differ depending on what they point to. If the pointer 170 /// points to a simple type, the child at index zero 171 /// is the only child value available, unless \a synthetic_allowed 172 /// is \b true, in which case the pointer will be used as an array 173 /// and can create 'synthetic' child values using positive or 174 /// negative indexes. If the pointer points to an aggregate type 175 /// (an array, class, union, struct), then the pointee is 176 /// transparently skipped and any children are going to be the indexes 177 /// of the child values within the aggregate type. For example if 178 /// we have a 'Point' type and we have a SBValue that contains a 179 /// pointer to a 'Point' type, then the child at index zero will be 180 /// the 'x' member, and the child at index 1 will be the 'y' member 181 /// (the child at index zero won't be a 'Point' instance). 182 /// 183 /// Arrays have a preset number of children that can be accessed by 184 /// index and will returns invalid child values for indexes that are 185 /// out of bounds unless the \a synthetic_allowed is \b true. In this 186 /// case the array can create 'synthetic' child values for indexes 187 /// that aren't in the array bounds using positive or negative 188 /// indexes. 189 /// 190 /// @param[in] idx 191 /// The index of the child value to get 192 /// 193 /// @param[in] use_dynamic 194 /// An enumeration that specifies wether to get dynamic values, 195 /// and also if the target can be run to figure out the dynamic 196 /// type of the child value. 197 /// 198 /// @param[in] synthetic_allowed 199 /// If \b true, then allow child values to be created by index 200 /// for pointers and arrays for indexes that normally wouldn't 201 /// be allowed. 202 /// 203 /// @return 204 /// A new SBValue object that represents the child member value. 205 //------------------------------------------------------------------ 206#ifdef SWIG 207 ") GetChildAtIndex; 208#endif 209 lldb::SBValue 210 GetChildAtIndex (uint32_t idx, 211 lldb::DynamicValueType use_dynamic, 212 bool can_create_synthetic); 213 214 // Matches children of this object only and will match base classes and 215 // member names if this is a clang typed object. 216 uint32_t 217 GetIndexOfChildWithName (const char *name); 218 219 // Matches child members of this object and child members of any base 220 // classes. 221 lldb::SBValue 222 GetChildMemberWithName (const char *name); 223 224 // Matches child members of this object and child members of any base 225 // classes. 226 lldb::SBValue 227 GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic); 228 229 // Expands nested expressions like .a->b[0].c[1]->d 230 lldb::SBValue 231 GetValueForExpressionPath(const char* expr_path); 232 233 uint32_t 234 GetNumChildren (); 235 236 void * 237 GetOpaqueType(); 238 239 240 lldb::SBValue 241 Dereference (); 242 243 bool 244 TypeIsPointerType (); 245 246 bool 247 GetDescription (lldb::SBStream &description); 248 249 bool 250 GetExpressionPath (lldb::SBStream &description); 251 252 bool 253 GetExpressionPath (lldb::SBStream &description, bool qualify_cxx_base_classes); 254 255 SBValue (const lldb::ValueObjectSP &value_sp); 256 257protected: 258 friend class SBValueList; 259 friend class SBFrame; 260 261#ifndef SWIG 262 263 // Mimic shared pointer... 264 lldb_private::ValueObject * 265 get() const; 266 267 lldb_private::ValueObject * 268 operator->() const; 269 270 lldb::ValueObjectSP & 271 operator*(); 272 273 const lldb::ValueObjectSP & 274 operator*() const; 275 276#endif 277 278private: 279 lldb::ValueObjectSP m_opaque_sp; 280}; 281 282} // namespace lldb 283 284#endif // LLDB_SBValue_h_ 285