Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ValueObject.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/Core/ValueObject.h" |
| 11 | |
| 12 | // C Includes |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 13 | #include <stdlib.h> |
| 14 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | // C++ Includes |
| 16 | // Other libraries and framework includes |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "llvm/Support/raw_ostream.h" |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 18 | #include "clang/AST/Type.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | |
| 20 | // Project includes |
| 21 | #include "lldb/Core/DataBufferHeap.h" |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 22 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Core/StreamString.h" |
| 24 | #include "lldb/Core/ValueObjectChild.h" |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 25 | #include "lldb/Core/ValueObjectConstResult.h" |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 26 | #include "lldb/Core/ValueObjectDynamicValue.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | #include "lldb/Core/ValueObjectList.h" |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 28 | #include "lldb/Core/ValueObjectMemory.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | |
Greg Clayton | 7fb56d0 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 30 | #include "lldb/Host/Endian.h" |
| 31 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 32 | #include "lldb/Symbol/ClangASTType.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | #include "lldb/Symbol/ClangASTContext.h" |
| 34 | #include "lldb/Symbol/Type.h" |
| 35 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 36 | #include "lldb/Target/ExecutionContext.h" |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 37 | #include "lldb/Target/LanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | #include "lldb/Target/Process.h" |
| 39 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 40 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | #include "lldb/Target/Thread.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | |
| 43 | using namespace lldb; |
| 44 | using namespace lldb_private; |
| 45 | |
| 46 | static lldb::user_id_t g_value_obj_uid = 0; |
| 47 | |
| 48 | //---------------------------------------------------------------------- |
| 49 | // ValueObject constructor |
| 50 | //---------------------------------------------------------------------- |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 51 | ValueObject::ValueObject (ValueObject &parent) : |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | UserID (++g_value_obj_uid), // Unique identifier for every value object |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 53 | m_parent (&parent), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 54 | m_update_point (parent.GetUpdatePoint ()), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 55 | m_name (), |
| 56 | m_data (), |
| 57 | m_value (), |
| 58 | m_error (), |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 59 | m_value_str (), |
| 60 | m_old_value_str (), |
| 61 | m_location_str (), |
| 62 | m_summary_str (), |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 63 | m_object_desc_str (), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 64 | m_manager(parent.GetManager()), |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 65 | m_children (), |
| 66 | m_synthetic_children (), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 67 | m_dynamic_value (NULL), |
| 68 | m_deref_valobj(NULL), |
Greg Clayton | 32c4085 | 2010-10-06 03:09:11 +0000 | [diff] [blame] | 69 | m_format (eFormatDefault), |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 70 | m_value_is_valid (false), |
| 71 | m_value_did_change (false), |
| 72 | m_children_count_valid (false), |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 73 | m_old_value_valid (false), |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 74 | m_pointers_point_to_load_addrs (false), |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 75 | m_is_deref_of_parent (false), |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 76 | m_is_array_item_for_pointer(false), |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 77 | m_is_bitfield_for_scalar(false), |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 78 | m_last_format_mgr_revision(0), |
| 79 | m_last_summary_format(), |
| 80 | m_last_value_format() |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 81 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 82 | m_manager->ManageObject(this); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | //---------------------------------------------------------------------- |
| 86 | // ValueObject constructor |
| 87 | //---------------------------------------------------------------------- |
| 88 | ValueObject::ValueObject (ExecutionContextScope *exe_scope) : |
| 89 | UserID (++g_value_obj_uid), // Unique identifier for every value object |
| 90 | m_parent (NULL), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 91 | m_update_point (exe_scope), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 92 | m_name (), |
| 93 | m_data (), |
| 94 | m_value (), |
| 95 | m_error (), |
| 96 | m_value_str (), |
| 97 | m_old_value_str (), |
| 98 | m_location_str (), |
| 99 | m_summary_str (), |
| 100 | m_object_desc_str (), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 101 | m_manager(), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 102 | m_children (), |
| 103 | m_synthetic_children (), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 104 | m_dynamic_value (NULL), |
| 105 | m_deref_valobj(NULL), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 106 | m_format (eFormatDefault), |
| 107 | m_value_is_valid (false), |
| 108 | m_value_did_change (false), |
| 109 | m_children_count_valid (false), |
| 110 | m_old_value_valid (false), |
| 111 | m_pointers_point_to_load_addrs (false), |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 112 | m_is_deref_of_parent (false), |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 113 | m_is_array_item_for_pointer(false), |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 114 | m_is_bitfield_for_scalar(false), |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 115 | m_last_format_mgr_revision(0), |
| 116 | m_last_summary_format(), |
| 117 | m_last_value_format() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 118 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 119 | m_manager = new ValueObjectManager(); |
| 120 | m_manager->ManageObject (this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | //---------------------------------------------------------------------- |
| 124 | // Destructor |
| 125 | //---------------------------------------------------------------------- |
| 126 | ValueObject::~ValueObject () |
| 127 | { |
| 128 | } |
| 129 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 130 | bool |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 131 | ValueObject::UpdateValueIfNeeded (bool update_format) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 132 | { |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 133 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 134 | if (update_format) |
| 135 | UpdateFormatsIfNeeded(); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 136 | |
Greg Clayton | b71f384 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 137 | // If this is a constant value, then our success is predicated on whether |
| 138 | // we have an error or not |
| 139 | if (GetIsConstant()) |
| 140 | return m_error.Success(); |
| 141 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 142 | bool first_update = m_update_point.IsFirstEvaluation(); |
| 143 | |
| 144 | if (m_update_point.NeedsUpdating()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 146 | m_update_point.SetUpdated(); |
| 147 | |
| 148 | // Save the old value using swap to avoid a string copy which |
| 149 | // also will clear our m_value_str |
| 150 | if (m_value_str.empty()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 151 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 152 | m_old_value_valid = false; |
| 153 | } |
| 154 | else |
| 155 | { |
| 156 | m_old_value_valid = true; |
| 157 | m_old_value_str.swap (m_value_str); |
| 158 | m_value_str.clear(); |
| 159 | } |
| 160 | m_location_str.clear(); |
| 161 | m_summary_str.clear(); |
| 162 | m_object_desc_str.clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 163 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 164 | const bool value_was_valid = GetValueIsValid(); |
| 165 | SetValueDidChange (false); |
Greg Clayton | 73b953b | 2010-08-28 00:08:07 +0000 | [diff] [blame] | 166 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 167 | m_error.Clear(); |
Greg Clayton | 73b953b | 2010-08-28 00:08:07 +0000 | [diff] [blame] | 168 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 169 | // Call the pure virtual function to update the value |
| 170 | bool success = UpdateValue (); |
| 171 | |
| 172 | SetValueIsValid (success); |
| 173 | |
| 174 | if (first_update) |
| 175 | SetValueDidChange (false); |
| 176 | else if (!m_value_did_change && success == false) |
| 177 | { |
| 178 | // The value wasn't gotten successfully, so we mark this |
| 179 | // as changed if the value used to be valid and now isn't |
| 180 | SetValueDidChange (value_was_valid); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | return m_error.Success(); |
| 184 | } |
| 185 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 186 | void |
| 187 | ValueObject::UpdateFormatsIfNeeded() |
| 188 | { |
| 189 | /*printf("CHECKING FOR UPDATES. I am at revision %d, while the format manager is at revision %d\n", |
| 190 | m_last_format_mgr_revision, |
| 191 | Debugger::ValueFormats::GetCurrentRevision());*/ |
| 192 | if (m_last_format_mgr_revision != Debugger::ValueFormats::GetCurrentRevision()) |
| 193 | { |
| 194 | if (m_last_summary_format.get()) |
| 195 | m_last_summary_format.reset((SummaryFormat*)NULL); |
| 196 | if (m_last_value_format.get()) |
| 197 | m_last_value_format.reset((ValueFormat*)NULL); |
| 198 | Debugger::ValueFormats::Get(*this, m_last_value_format); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 199 | if (!Debugger::SummaryFormats::Get(*this, m_last_summary_format)) |
| 200 | Debugger::RegexSummaryFormats::Get(*this, m_last_summary_format); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 201 | m_last_format_mgr_revision = Debugger::ValueFormats::GetCurrentRevision(); |
| 202 | m_value_str.clear(); |
| 203 | m_summary_str.clear(); |
| 204 | } |
| 205 | } |
| 206 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 207 | DataExtractor & |
| 208 | ValueObject::GetDataExtractor () |
| 209 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 210 | UpdateValueIfNeeded(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 211 | return m_data; |
| 212 | } |
| 213 | |
| 214 | const Error & |
Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame] | 215 | ValueObject::GetError() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 216 | { |
Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame] | 217 | UpdateValueIfNeeded(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 218 | return m_error; |
| 219 | } |
| 220 | |
| 221 | const ConstString & |
| 222 | ValueObject::GetName() const |
| 223 | { |
| 224 | return m_name; |
| 225 | } |
| 226 | |
| 227 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 228 | ValueObject::GetLocationAsCString () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 229 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 230 | if (UpdateValueIfNeeded()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 231 | { |
| 232 | if (m_location_str.empty()) |
| 233 | { |
| 234 | StreamString sstr; |
| 235 | |
| 236 | switch (m_value.GetValueType()) |
| 237 | { |
| 238 | default: |
| 239 | break; |
| 240 | |
| 241 | case Value::eValueTypeScalar: |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 242 | if (m_value.GetContextType() == Value::eContextTypeRegisterInfo) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 243 | { |
| 244 | RegisterInfo *reg_info = m_value.GetRegisterInfo(); |
| 245 | if (reg_info) |
| 246 | { |
| 247 | if (reg_info->name) |
| 248 | m_location_str = reg_info->name; |
| 249 | else if (reg_info->alt_name) |
| 250 | m_location_str = reg_info->alt_name; |
| 251 | break; |
| 252 | } |
| 253 | } |
| 254 | m_location_str = "scalar"; |
| 255 | break; |
| 256 | |
| 257 | case Value::eValueTypeLoadAddress: |
| 258 | case Value::eValueTypeFileAddress: |
| 259 | case Value::eValueTypeHostAddress: |
| 260 | { |
| 261 | uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2; |
| 262 | sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS)); |
| 263 | m_location_str.swap(sstr.GetString()); |
| 264 | } |
| 265 | break; |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | return m_location_str.c_str(); |
| 270 | } |
| 271 | |
| 272 | Value & |
| 273 | ValueObject::GetValue() |
| 274 | { |
| 275 | return m_value; |
| 276 | } |
| 277 | |
| 278 | const Value & |
| 279 | ValueObject::GetValue() const |
| 280 | { |
| 281 | return m_value; |
| 282 | } |
| 283 | |
| 284 | bool |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 285 | ValueObject::ResolveValue (Scalar &scalar) |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 286 | { |
| 287 | ExecutionContext exe_ctx; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 288 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 289 | if (exe_scope) |
| 290 | exe_scope->CalculateExecutionContext(exe_ctx); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 291 | scalar = m_value.ResolveValue(&exe_ctx, GetClangAST ()); |
| 292 | return scalar.IsValid(); |
| 293 | } |
| 294 | |
| 295 | bool |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 296 | ValueObject::GetValueIsValid () const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 297 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 298 | return m_value_is_valid; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | |
| 302 | void |
| 303 | ValueObject::SetValueIsValid (bool b) |
| 304 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 305 | m_value_is_valid = b; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | bool |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 309 | ValueObject::GetValueDidChange () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 310 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 311 | GetValueAsCString (); |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 312 | return m_value_did_change; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void |
| 316 | ValueObject::SetValueDidChange (bool value_changed) |
| 317 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 318 | m_value_did_change = value_changed; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | ValueObjectSP |
| 322 | ValueObject::GetChildAtIndex (uint32_t idx, bool can_create) |
| 323 | { |
| 324 | ValueObjectSP child_sp; |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 325 | // We may need to update our value if we are dynamic |
| 326 | if (IsPossibleDynamicType ()) |
| 327 | UpdateValueIfNeeded(); |
| 328 | if (idx < GetNumChildren()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 329 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 330 | // Check if we have already made the child value object? |
| 331 | if (can_create && m_children[idx] == NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 332 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 333 | // No we haven't created the child at this index, so lets have our |
| 334 | // subclass do it and cache the result for quick future access. |
| 335 | m_children[idx] = CreateChildAtIndex (idx, false, 0); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 336 | } |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 337 | |
| 338 | if (m_children[idx] != NULL) |
| 339 | return m_children[idx]->GetSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 340 | } |
| 341 | return child_sp; |
| 342 | } |
| 343 | |
| 344 | uint32_t |
| 345 | ValueObject::GetIndexOfChildWithName (const ConstString &name) |
| 346 | { |
| 347 | bool omit_empty_base_classes = true; |
| 348 | return ClangASTContext::GetIndexOfChildWithName (GetClangAST(), |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 349 | GetClangType(), |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 350 | name.GetCString(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 351 | omit_empty_base_classes); |
| 352 | } |
| 353 | |
| 354 | ValueObjectSP |
| 355 | ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create) |
| 356 | { |
Greg Clayton | 710dd5a | 2011-01-08 20:28:42 +0000 | [diff] [blame] | 357 | // when getting a child by name, it could be buried inside some base |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 358 | // classes (which really aren't part of the expression path), so we |
| 359 | // need a vector of indexes that can get us down to the correct child |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 360 | ValueObjectSP child_sp; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 361 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 362 | // We may need to update our value if we are dynamic |
| 363 | if (IsPossibleDynamicType ()) |
| 364 | UpdateValueIfNeeded(); |
| 365 | |
| 366 | std::vector<uint32_t> child_indexes; |
| 367 | clang::ASTContext *clang_ast = GetClangAST(); |
| 368 | void *clang_type = GetClangType(); |
| 369 | bool omit_empty_base_classes = true; |
| 370 | const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast, |
| 371 | clang_type, |
| 372 | name.GetCString(), |
| 373 | omit_empty_base_classes, |
| 374 | child_indexes); |
| 375 | if (num_child_indexes > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 376 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 377 | std::vector<uint32_t>::const_iterator pos = child_indexes.begin (); |
| 378 | std::vector<uint32_t>::const_iterator end = child_indexes.end (); |
| 379 | |
| 380 | child_sp = GetChildAtIndex(*pos, can_create); |
| 381 | for (++pos; pos != end; ++pos) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 382 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 383 | if (child_sp) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 384 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 385 | ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create)); |
| 386 | child_sp = new_child_sp; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 387 | } |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 388 | else |
| 389 | { |
| 390 | child_sp.reset(); |
| 391 | } |
| 392 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | return child_sp; |
| 396 | } |
| 397 | |
| 398 | |
| 399 | uint32_t |
| 400 | ValueObject::GetNumChildren () |
| 401 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 402 | if (!m_children_count_valid) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 403 | { |
| 404 | SetNumChildren (CalculateNumChildren()); |
| 405 | } |
| 406 | return m_children.size(); |
| 407 | } |
| 408 | void |
| 409 | ValueObject::SetNumChildren (uint32_t num_children) |
| 410 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 411 | m_children_count_valid = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 412 | m_children.resize(num_children); |
| 413 | } |
| 414 | |
| 415 | void |
| 416 | ValueObject::SetName (const char *name) |
| 417 | { |
| 418 | m_name.SetCString(name); |
| 419 | } |
| 420 | |
| 421 | void |
| 422 | ValueObject::SetName (const ConstString &name) |
| 423 | { |
| 424 | m_name = name; |
| 425 | } |
| 426 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 427 | ValueObject * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 428 | ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index) |
| 429 | { |
Jim Ingham | 2eec487 | 2011-05-07 00:10:58 +0000 | [diff] [blame] | 430 | ValueObject *valobj = NULL; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 431 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 432 | bool omit_empty_base_classes = true; |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame^] | 433 | bool ignore_array_bounds = synthetic_array_member; |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 434 | std::string child_name_str; |
| 435 | uint32_t child_byte_size = 0; |
| 436 | int32_t child_byte_offset = 0; |
| 437 | uint32_t child_bitfield_bit_size = 0; |
| 438 | uint32_t child_bitfield_bit_offset = 0; |
| 439 | bool child_is_base_class = false; |
| 440 | bool child_is_deref_of_parent = false; |
| 441 | |
| 442 | const bool transparent_pointers = synthetic_array_member == false; |
| 443 | clang::ASTContext *clang_ast = GetClangAST(); |
| 444 | clang_type_t clang_type = GetClangType(); |
| 445 | clang_type_t child_clang_type; |
| 446 | |
| 447 | ExecutionContext exe_ctx; |
| 448 | GetExecutionContextScope()->CalculateExecutionContext (exe_ctx); |
| 449 | |
| 450 | child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx, |
| 451 | clang_ast, |
| 452 | GetName().GetCString(), |
| 453 | clang_type, |
| 454 | idx, |
| 455 | transparent_pointers, |
| 456 | omit_empty_base_classes, |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame^] | 457 | ignore_array_bounds, |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 458 | child_name_str, |
| 459 | child_byte_size, |
| 460 | child_byte_offset, |
| 461 | child_bitfield_bit_size, |
| 462 | child_bitfield_bit_offset, |
| 463 | child_is_base_class, |
| 464 | child_is_deref_of_parent); |
| 465 | if (child_clang_type && child_byte_size) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 466 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 467 | if (synthetic_index) |
| 468 | child_byte_offset += child_byte_size * synthetic_index; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 469 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 470 | ConstString child_name; |
| 471 | if (!child_name_str.empty()) |
| 472 | child_name.SetCString (child_name_str.c_str()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 473 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 474 | valobj = new ValueObjectChild (*this, |
| 475 | clang_ast, |
| 476 | child_clang_type, |
| 477 | child_name, |
| 478 | child_byte_size, |
| 479 | child_byte_offset, |
| 480 | child_bitfield_bit_size, |
| 481 | child_bitfield_bit_offset, |
| 482 | child_is_base_class, |
| 483 | child_is_deref_of_parent); |
| 484 | if (m_pointers_point_to_load_addrs) |
| 485 | valobj->SetPointersPointToLoadAddrs (m_pointers_point_to_load_addrs); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 486 | } |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 487 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 488 | return valobj; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 492 | ValueObject::GetSummaryAsCString () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 493 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 494 | if (UpdateValueIfNeeded ()) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 495 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 496 | if (m_summary_str.empty()) |
| 497 | { |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 498 | if (m_last_summary_format.get()) |
| 499 | { |
| 500 | StreamString s; |
| 501 | ExecutionContext exe_ctx; |
| 502 | this->GetExecutionContextScope()->CalculateExecutionContext(exe_ctx); |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame^] | 503 | SymbolContext sc; |
| 504 | if (exe_ctx.frame) |
| 505 | sc = exe_ctx.frame->GetSymbolContext(eSymbolContextEverything); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 506 | |
| 507 | if (m_last_summary_format->m_show_members_oneliner) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 508 | { |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 509 | const uint32_t num_children = GetNumChildren(); |
| 510 | if (num_children) |
| 511 | { |
| 512 | |
| 513 | s.PutChar('('); |
| 514 | |
| 515 | for (uint32_t idx=0; idx<num_children; ++idx) |
| 516 | { |
| 517 | ValueObjectSP child_sp(GetChildAtIndex(idx, true)); |
| 518 | if (child_sp.get()) |
| 519 | { |
| 520 | if (idx) |
| 521 | s.PutCString(", "); |
| 522 | s.PutCString(child_sp.get()->GetName().AsCString()); |
| 523 | s.PutChar('='); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 524 | s.PutCString(child_sp.get()->GetPrintableRepresentation()); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | |
| 528 | s.PutChar(')'); |
| 529 | |
| 530 | m_summary_str.swap(s.GetString()); |
| 531 | return m_summary_str.c_str(); |
| 532 | } |
| 533 | else |
| 534 | return "()"; |
| 535 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 536 | } |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 537 | else |
| 538 | { |
| 539 | if (Debugger::FormatPrompt(m_last_summary_format->m_format.c_str(), &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, NULL, this)) |
| 540 | { |
| 541 | m_summary_str.swap(s.GetString()); |
| 542 | return m_summary_str.c_str(); |
| 543 | } |
| 544 | else |
| 545 | return NULL; |
| 546 | } |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 547 | } |
| 548 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 549 | clang_type_t clang_type = GetClangType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 550 | |
| 551 | // See if this is a pointer to a C string? |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 552 | if (clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 553 | { |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 554 | StreamString sstr; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 555 | clang_type_t elem_or_pointee_clang_type; |
| 556 | const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 557 | GetClangAST(), |
| 558 | &elem_or_pointee_clang_type)); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 559 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 560 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 561 | if (exe_scope) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 562 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 563 | if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) && |
| 564 | ClangASTContext::IsCharType (elem_or_pointee_clang_type)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 565 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 566 | Process *process = exe_scope->CalculateProcess(); |
| 567 | if (process != NULL) |
| 568 | { |
| 569 | lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS; |
| 570 | AddressType cstr_address_type = eAddressTypeInvalid; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 571 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 572 | size_t cstr_len = 0; |
Greg Clayton | 5707d22 | 2011-07-09 17:17:07 +0000 | [diff] [blame] | 573 | bool capped_data = false; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 574 | if (type_flags.Test (ClangASTContext::eTypeIsArray)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 575 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 576 | // We have an array |
| 577 | cstr_len = ClangASTContext::GetArraySize (clang_type); |
Greg Clayton | 5707d22 | 2011-07-09 17:17:07 +0000 | [diff] [blame] | 578 | if (cstr_len > 512) // TODO: make cap a setting |
| 579 | { |
| 580 | cstr_len = ClangASTContext::GetArraySize (clang_type); |
| 581 | if (cstr_len > 512) // TODO: make cap a setting |
| 582 | { |
| 583 | capped_data = true; |
| 584 | cstr_len = 512; |
| 585 | } |
| 586 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 587 | cstr_address = GetAddressOf (cstr_address_type, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 588 | } |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 589 | else |
| 590 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 591 | // We have a pointer |
| 592 | cstr_address = GetPointerValue (cstr_address_type, true); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 593 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 594 | if (cstr_address != LLDB_INVALID_ADDRESS) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 595 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 596 | DataExtractor data; |
| 597 | size_t bytes_read = 0; |
| 598 | std::vector<char> data_buffer; |
| 599 | Error error; |
| 600 | if (cstr_len > 0) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 601 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 602 | data_buffer.resize(cstr_len); |
| 603 | data.SetData (&data_buffer.front(), data_buffer.size(), lldb::endian::InlHostByteOrder()); |
| 604 | bytes_read = process->ReadMemory (cstr_address, &data_buffer.front(), cstr_len, error); |
| 605 | if (bytes_read > 0) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 606 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 607 | sstr << '"'; |
| 608 | data.Dump (&sstr, |
| 609 | 0, // Start offset in "data" |
Greg Clayton | 4e4294b | 2011-06-17 23:50:44 +0000 | [diff] [blame] | 610 | eFormatCharArray, // Print as characters |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 611 | 1, // Size of item (1 byte for a char!) |
| 612 | bytes_read, // How many bytes to print? |
| 613 | UINT32_MAX, // num per line |
| 614 | LLDB_INVALID_ADDRESS,// base address |
| 615 | 0, // bitfield bit size |
| 616 | 0); // bitfield bit offset |
Greg Clayton | 5707d22 | 2011-07-09 17:17:07 +0000 | [diff] [blame] | 617 | if (capped_data) |
| 618 | sstr << "..."; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 619 | sstr << '"'; |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 620 | } |
| 621 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 622 | else |
| 623 | { |
| 624 | const size_t k_max_buf_size = 256; |
| 625 | data_buffer.resize (k_max_buf_size + 1); |
| 626 | // NULL terminate in case we don't get the entire C string |
| 627 | data_buffer.back() = '\0'; |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 628 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 629 | sstr << '"'; |
| 630 | |
| 631 | data.SetData (&data_buffer.front(), data_buffer.size(), endian::InlHostByteOrder()); |
| 632 | while ((bytes_read = process->ReadMemory (cstr_address, &data_buffer.front(), k_max_buf_size, error)) > 0) |
| 633 | { |
| 634 | size_t len = strlen(&data_buffer.front()); |
| 635 | if (len == 0) |
| 636 | break; |
| 637 | if (len > bytes_read) |
| 638 | len = bytes_read; |
| 639 | |
| 640 | data.Dump (&sstr, |
| 641 | 0, // Start offset in "data" |
Greg Clayton | 4e4294b | 2011-06-17 23:50:44 +0000 | [diff] [blame] | 642 | eFormatCharArray, // Print as characters |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 643 | 1, // Size of item (1 byte for a char!) |
| 644 | len, // How many bytes to print? |
| 645 | UINT32_MAX, // num per line |
| 646 | LLDB_INVALID_ADDRESS,// base address |
| 647 | 0, // bitfield bit size |
| 648 | 0); // bitfield bit offset |
| 649 | |
| 650 | if (len < k_max_buf_size) |
| 651 | break; |
| 652 | cstr_address += k_max_buf_size; |
| 653 | } |
| 654 | sstr << '"'; |
| 655 | } |
| 656 | } |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 657 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 658 | |
| 659 | if (sstr.GetSize() > 0) |
| 660 | m_summary_str.assign (sstr.GetData(), sstr.GetSize()); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 661 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 662 | else if (ClangASTContext::IsFunctionPointerType (clang_type)) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 663 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 664 | AddressType func_ptr_address_type = eAddressTypeInvalid; |
| 665 | lldb::addr_t func_ptr_address = GetPointerValue (func_ptr_address_type, true); |
| 666 | |
| 667 | if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS) |
| 668 | { |
| 669 | switch (func_ptr_address_type) |
| 670 | { |
| 671 | case eAddressTypeInvalid: |
| 672 | case eAddressTypeFile: |
| 673 | break; |
| 674 | |
| 675 | case eAddressTypeLoad: |
| 676 | { |
| 677 | Address so_addr; |
| 678 | Target *target = exe_scope->CalculateTarget(); |
| 679 | if (target && target->GetSectionLoadList().IsEmpty() == false) |
| 680 | { |
| 681 | if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr)) |
| 682 | { |
| 683 | so_addr.Dump (&sstr, |
| 684 | exe_scope, |
| 685 | Address::DumpStyleResolvedDescription, |
| 686 | Address::DumpStyleSectionNameOffset); |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | break; |
| 691 | |
| 692 | case eAddressTypeHost: |
| 693 | break; |
| 694 | } |
| 695 | } |
| 696 | if (sstr.GetSize() > 0) |
| 697 | { |
| 698 | m_summary_str.assign (1, '('); |
| 699 | m_summary_str.append (sstr.GetData(), sstr.GetSize()); |
| 700 | m_summary_str.append (1, ')'); |
| 701 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | if (m_summary_str.empty()) |
| 708 | return NULL; |
| 709 | return m_summary_str.c_str(); |
| 710 | } |
| 711 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 712 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 713 | ValueObject::GetObjectDescription () |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 714 | { |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 715 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 716 | if (!UpdateValueIfNeeded ()) |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 717 | return NULL; |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 718 | |
| 719 | if (!m_object_desc_str.empty()) |
| 720 | return m_object_desc_str.c_str(); |
| 721 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 722 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 723 | if (exe_scope == NULL) |
| 724 | return NULL; |
| 725 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 726 | Process *process = exe_scope->CalculateProcess(); |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 727 | if (process == NULL) |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 728 | return NULL; |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 729 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 730 | StreamString s; |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 731 | |
| 732 | lldb::LanguageType language = GetObjectRuntimeLanguage(); |
| 733 | LanguageRuntime *runtime = process->GetLanguageRuntime(language); |
| 734 | |
Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 735 | if (runtime == NULL) |
| 736 | { |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 737 | // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway... |
Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 738 | clang_type_t opaque_qual_type = GetClangType(); |
| 739 | if (opaque_qual_type != NULL) |
| 740 | { |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 741 | bool is_signed; |
| 742 | if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed) |
| 743 | || ClangASTContext::IsPointerType (opaque_qual_type)) |
| 744 | { |
Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 745 | runtime = process->GetLanguageRuntime(lldb::eLanguageTypeObjC); |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 746 | } |
Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
Jim Ingham | 8d543de | 2011-03-31 23:01:21 +0000 | [diff] [blame] | 750 | if (runtime && runtime->GetObjectDescription(s, *this)) |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 751 | { |
| 752 | m_object_desc_str.append (s.GetData()); |
| 753 | } |
Sean Callanan | 672ad94 | 2010-10-23 00:18:49 +0000 | [diff] [blame] | 754 | |
| 755 | if (m_object_desc_str.empty()) |
| 756 | return NULL; |
| 757 | else |
| 758 | return m_object_desc_str.c_str(); |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 759 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 760 | |
| 761 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 762 | ValueObject::GetValueAsCString () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 763 | { |
| 764 | // If our byte size is zero this is an aggregate type that has children |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 765 | if (ClangASTContext::IsAggregateType (GetClangType()) == false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 766 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 767 | if (UpdateValueIfNeeded()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 768 | { |
| 769 | if (m_value_str.empty()) |
| 770 | { |
| 771 | const Value::ContextType context_type = m_value.GetContextType(); |
| 772 | |
| 773 | switch (context_type) |
| 774 | { |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 775 | case Value::eContextTypeClangType: |
| 776 | case Value::eContextTypeLLDBType: |
| 777 | case Value::eContextTypeVariable: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 778 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 779 | clang_type_t clang_type = GetClangType (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 780 | if (clang_type) |
| 781 | { |
| 782 | StreamString sstr; |
Greg Clayton | 68ebae6 | 2011-04-28 20:55:26 +0000 | [diff] [blame] | 783 | Format format = GetFormat(); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 784 | if (format == eFormatDefault) |
| 785 | { |
| 786 | if (m_last_value_format) |
| 787 | format = m_last_value_format->m_format; |
| 788 | else |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 789 | // force the system into using unsigned integers for bitfields |
| 790 | format = (m_is_bitfield_for_scalar ? eFormatUnsigned : |
| 791 | ClangASTType::GetFormat(clang_type)); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 792 | } |
Greg Clayton | 32c4085 | 2010-10-06 03:09:11 +0000 | [diff] [blame] | 793 | |
| 794 | if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST |
| 795 | clang_type, // The clang type to display |
| 796 | &sstr, |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 797 | format, // Format to display this type with |
Greg Clayton | 32c4085 | 2010-10-06 03:09:11 +0000 | [diff] [blame] | 798 | m_data, // Data to extract from |
| 799 | 0, // Byte offset into "m_data" |
| 800 | GetByteSize(), // Byte size of item in "m_data" |
| 801 | GetBitfieldBitSize(), // Bitfield bit size |
| 802 | GetBitfieldBitOffset())) // Bitfield bit offset |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 803 | m_value_str.swap(sstr.GetString()); |
| 804 | else |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 805 | { |
| 806 | m_error.SetErrorStringWithFormat ("unsufficient data for value (only %u of %u bytes available)", |
| 807 | m_data.GetByteSize(), |
| 808 | GetByteSize()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 809 | m_value_str.clear(); |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 810 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | break; |
| 814 | |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 815 | case Value::eContextTypeRegisterInfo: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 816 | { |
| 817 | const RegisterInfo *reg_info = m_value.GetRegisterInfo(); |
| 818 | if (reg_info) |
| 819 | { |
| 820 | StreamString reg_sstr; |
| 821 | m_data.Dump(®_sstr, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0); |
| 822 | m_value_str.swap(reg_sstr.GetString()); |
| 823 | } |
| 824 | } |
| 825 | break; |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 826 | |
| 827 | default: |
| 828 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 829 | } |
| 830 | } |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 831 | |
| 832 | if (!m_value_did_change && m_old_value_valid) |
| 833 | { |
| 834 | // The value was gotten successfully, so we consider the |
| 835 | // value as changed if the value string differs |
| 836 | SetValueDidChange (m_old_value_str != m_value_str); |
| 837 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | if (m_value_str.empty()) |
| 841 | return NULL; |
| 842 | return m_value_str.c_str(); |
| 843 | } |
| 844 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 845 | const char * |
| 846 | ValueObject::GetPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display, |
| 847 | lldb::Format custom_format) |
| 848 | { |
| 849 | if(custom_format != lldb::eFormatInvalid) |
| 850 | SetFormat(custom_format); |
| 851 | |
| 852 | const char * return_value; |
| 853 | |
| 854 | switch(val_obj_display) |
| 855 | { |
| 856 | case eDisplayValue: |
| 857 | return_value = GetValueAsCString(); |
| 858 | break; |
| 859 | case eDisplaySummary: |
| 860 | return_value = GetSummaryAsCString(); |
| 861 | break; |
| 862 | case eDisplayLanguageSpecific: |
| 863 | return_value = GetObjectDescription(); |
| 864 | break; |
| 865 | } |
| 866 | |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 867 | if (!return_value) |
| 868 | { |
| 869 | // try to pick the other choice |
| 870 | if (val_obj_display == eDisplayValue) |
| 871 | return_value = GetSummaryAsCString(); |
| 872 | else if (val_obj_display == eDisplaySummary) |
| 873 | return_value = GetValueAsCString(); |
| 874 | else |
| 875 | return_value = ""; |
| 876 | } |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 877 | |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 878 | return (return_value ? return_value : ""); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 879 | |
| 880 | } |
| 881 | |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 882 | bool |
| 883 | ValueObject::DumpPrintableRepresentation(Stream& s, |
| 884 | ValueObjectRepresentationStyle val_obj_display, |
| 885 | lldb::Format custom_format) |
| 886 | { |
| 887 | const char *targetvalue = GetPrintableRepresentation(val_obj_display, custom_format); |
| 888 | if(targetvalue) |
| 889 | s.PutCString(targetvalue); |
| 890 | bool var_success = (targetvalue != NULL); |
| 891 | if(custom_format != eFormatInvalid) |
| 892 | SetFormat(eFormatDefault); |
| 893 | return var_success; |
| 894 | } |
| 895 | |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 896 | addr_t |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 897 | ValueObject::GetAddressOf (AddressType &address_type, bool scalar_is_load_address) |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 898 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 899 | if (!UpdateValueIfNeeded()) |
| 900 | return LLDB_INVALID_ADDRESS; |
| 901 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 902 | switch (m_value.GetValueType()) |
| 903 | { |
| 904 | case Value::eValueTypeScalar: |
| 905 | if (scalar_is_load_address) |
| 906 | { |
| 907 | address_type = eAddressTypeLoad; |
| 908 | return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 909 | } |
| 910 | break; |
| 911 | |
| 912 | case Value::eValueTypeLoadAddress: |
| 913 | case Value::eValueTypeFileAddress: |
| 914 | case Value::eValueTypeHostAddress: |
| 915 | { |
| 916 | address_type = m_value.GetValueAddressType (); |
| 917 | return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 918 | } |
| 919 | break; |
| 920 | } |
| 921 | address_type = eAddressTypeInvalid; |
| 922 | return LLDB_INVALID_ADDRESS; |
| 923 | } |
| 924 | |
| 925 | addr_t |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 926 | ValueObject::GetPointerValue (AddressType &address_type, bool scalar_is_load_address) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 927 | { |
| 928 | lldb::addr_t address = LLDB_INVALID_ADDRESS; |
| 929 | address_type = eAddressTypeInvalid; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 930 | |
| 931 | if (!UpdateValueIfNeeded()) |
| 932 | return address; |
| 933 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 934 | switch (m_value.GetValueType()) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 935 | { |
| 936 | case Value::eValueTypeScalar: |
| 937 | if (scalar_is_load_address) |
| 938 | { |
| 939 | address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 940 | address_type = eAddressTypeLoad; |
| 941 | } |
| 942 | break; |
| 943 | |
| 944 | case Value::eValueTypeLoadAddress: |
| 945 | case Value::eValueTypeFileAddress: |
| 946 | case Value::eValueTypeHostAddress: |
| 947 | { |
| 948 | uint32_t data_offset = 0; |
| 949 | address = m_data.GetPointer(&data_offset); |
| 950 | address_type = m_value.GetValueAddressType(); |
| 951 | if (address_type == eAddressTypeInvalid) |
| 952 | address_type = eAddressTypeLoad; |
| 953 | } |
| 954 | break; |
| 955 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 956 | |
| 957 | if (m_pointers_point_to_load_addrs) |
| 958 | address_type = eAddressTypeLoad; |
| 959 | |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 960 | return address; |
| 961 | } |
| 962 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 963 | bool |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 964 | ValueObject::SetValueFromCString (const char *value_str) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 965 | { |
| 966 | // Make sure our value is up to date first so that our location and location |
| 967 | // type is valid. |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 968 | if (!UpdateValueIfNeeded()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 969 | return false; |
| 970 | |
| 971 | uint32_t count = 0; |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 972 | lldb::Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 973 | |
| 974 | char *end = NULL; |
Greg Clayton | b132097 | 2010-07-14 00:18:15 +0000 | [diff] [blame] | 975 | const size_t byte_size = GetByteSize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 976 | switch (encoding) |
| 977 | { |
| 978 | case eEncodingInvalid: |
| 979 | return false; |
| 980 | |
| 981 | case eEncodingUint: |
| 982 | if (byte_size > sizeof(unsigned long long)) |
| 983 | { |
| 984 | return false; |
| 985 | } |
| 986 | else |
| 987 | { |
| 988 | unsigned long long ull_val = strtoull(value_str, &end, 0); |
| 989 | if (end && *end != '\0') |
| 990 | return false; |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 991 | m_value.GetScalar() = ull_val; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 992 | // Limit the bytes in our m_data appropriately. |
| 993 | m_value.GetScalar().GetData (m_data, byte_size); |
| 994 | } |
| 995 | break; |
| 996 | |
| 997 | case eEncodingSint: |
| 998 | if (byte_size > sizeof(long long)) |
| 999 | { |
| 1000 | return false; |
| 1001 | } |
| 1002 | else |
| 1003 | { |
| 1004 | long long sll_val = strtoll(value_str, &end, 0); |
| 1005 | if (end && *end != '\0') |
| 1006 | return false; |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 1007 | m_value.GetScalar() = sll_val; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1008 | // Limit the bytes in our m_data appropriately. |
| 1009 | m_value.GetScalar().GetData (m_data, byte_size); |
| 1010 | } |
| 1011 | break; |
| 1012 | |
| 1013 | case eEncodingIEEE754: |
| 1014 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1015 | const off_t byte_offset = GetByteOffset(); |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1016 | uint8_t *dst = const_cast<uint8_t *>(m_data.PeekData(byte_offset, byte_size)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1017 | if (dst != NULL) |
| 1018 | { |
| 1019 | // We are decoding a float into host byte order below, so make |
| 1020 | // sure m_data knows what it contains. |
Greg Clayton | 7fb56d0 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 1021 | m_data.SetByteOrder(lldb::endian::InlHostByteOrder()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1022 | const size_t converted_byte_size = ClangASTContext::ConvertStringToFloatValue ( |
| 1023 | GetClangAST(), |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1024 | GetClangType(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1025 | value_str, |
| 1026 | dst, |
| 1027 | byte_size); |
| 1028 | |
| 1029 | if (converted_byte_size == byte_size) |
| 1030 | { |
| 1031 | } |
| 1032 | } |
| 1033 | } |
| 1034 | break; |
| 1035 | |
| 1036 | case eEncodingVector: |
| 1037 | return false; |
| 1038 | |
| 1039 | default: |
| 1040 | return false; |
| 1041 | } |
| 1042 | |
| 1043 | // If we have made it here the value is in m_data and we should write it |
| 1044 | // out to the target |
| 1045 | return Write (); |
| 1046 | } |
| 1047 | |
| 1048 | bool |
| 1049 | ValueObject::Write () |
| 1050 | { |
| 1051 | // Clear the update ID so the next time we try and read the value |
| 1052 | // we try and read it again. |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1053 | m_update_point.SetNeedsUpdate(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1054 | |
| 1055 | // TODO: when Value has a method to write a value back, call it from here. |
| 1056 | return false; |
| 1057 | |
| 1058 | } |
| 1059 | |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1060 | lldb::LanguageType |
| 1061 | ValueObject::GetObjectRuntimeLanguage () |
| 1062 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1063 | clang_type_t opaque_qual_type = GetClangType(); |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1064 | if (opaque_qual_type == NULL) |
| 1065 | return lldb::eLanguageTypeC; |
| 1066 | |
| 1067 | // If the type is a reference, then resolve it to what it refers to first: |
| 1068 | clang::QualType qual_type (clang::QualType::getFromOpaquePtr(opaque_qual_type).getNonReferenceType()); |
| 1069 | if (qual_type->isAnyPointerType()) |
| 1070 | { |
| 1071 | if (qual_type->isObjCObjectPointerType()) |
| 1072 | return lldb::eLanguageTypeObjC; |
| 1073 | |
| 1074 | clang::QualType pointee_type (qual_type->getPointeeType()); |
| 1075 | if (pointee_type->getCXXRecordDeclForPointerType() != NULL) |
| 1076 | return lldb::eLanguageTypeC_plus_plus; |
| 1077 | if (pointee_type->isObjCObjectOrInterfaceType()) |
| 1078 | return lldb::eLanguageTypeObjC; |
| 1079 | if (pointee_type->isObjCClassType()) |
| 1080 | return lldb::eLanguageTypeObjC; |
| 1081 | } |
| 1082 | else |
| 1083 | { |
| 1084 | if (ClangASTContext::IsObjCClassType (opaque_qual_type)) |
| 1085 | return lldb::eLanguageTypeObjC; |
Johnny Chen | d440bcc | 2010-09-28 16:10:54 +0000 | [diff] [blame] | 1086 | if (ClangASTContext::IsCXXClassType (opaque_qual_type)) |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1087 | return lldb::eLanguageTypeC_plus_plus; |
| 1088 | } |
| 1089 | |
| 1090 | return lldb::eLanguageTypeC; |
| 1091 | } |
| 1092 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1093 | void |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1094 | ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1095 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1096 | m_synthetic_children[key] = valobj; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | ValueObjectSP |
| 1100 | ValueObject::GetSyntheticChild (const ConstString &key) const |
| 1101 | { |
| 1102 | ValueObjectSP synthetic_child_sp; |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1103 | std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1104 | if (pos != m_synthetic_children.end()) |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1105 | synthetic_child_sp = pos->second->GetSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1106 | return synthetic_child_sp; |
| 1107 | } |
| 1108 | |
| 1109 | bool |
| 1110 | ValueObject::IsPointerType () |
| 1111 | { |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1112 | return ClangASTContext::IsPointerType (GetClangType()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 1115 | bool |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame^] | 1116 | ValueObject::IsArrayType () |
| 1117 | { |
| 1118 | return ClangASTContext::IsArrayType (GetClangType()); |
| 1119 | } |
| 1120 | |
| 1121 | bool |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1122 | ValueObject::IsScalarType () |
| 1123 | { |
| 1124 | return ClangASTContext::IsScalarType (GetClangType()); |
| 1125 | } |
| 1126 | |
| 1127 | bool |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 1128 | ValueObject::IsIntegerType (bool &is_signed) |
| 1129 | { |
| 1130 | return ClangASTContext::IsIntegerType (GetClangType(), is_signed); |
| 1131 | } |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1132 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1133 | bool |
| 1134 | ValueObject::IsPointerOrReferenceType () |
| 1135 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 1136 | return ClangASTContext::IsPointerOrReferenceType (GetClangType()); |
| 1137 | } |
| 1138 | |
| 1139 | bool |
| 1140 | ValueObject::IsPossibleCPlusPlusDynamicType () |
| 1141 | { |
| 1142 | return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 1145 | bool |
| 1146 | ValueObject::IsPossibleDynamicType () |
| 1147 | { |
| 1148 | return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType()); |
| 1149 | } |
| 1150 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1151 | ValueObjectSP |
| 1152 | ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create) |
| 1153 | { |
| 1154 | ValueObjectSP synthetic_child_sp; |
| 1155 | if (IsPointerType ()) |
| 1156 | { |
| 1157 | char index_str[64]; |
| 1158 | snprintf(index_str, sizeof(index_str), "[%i]", index); |
| 1159 | ConstString index_const_str(index_str); |
| 1160 | // Check if we have already created a synthetic array member in this |
| 1161 | // valid object. If we have we will re-use it. |
| 1162 | synthetic_child_sp = GetSyntheticChild (index_const_str); |
| 1163 | if (!synthetic_child_sp) |
| 1164 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1165 | ValueObject *synthetic_child; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1166 | // We haven't made a synthetic array member for INDEX yet, so |
| 1167 | // lets make one and cache it for any future reference. |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1168 | synthetic_child = CreateChildAtIndex(0, true, index); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1169 | |
| 1170 | // Cache the value if we got one back... |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1171 | if (synthetic_child) |
| 1172 | { |
| 1173 | AddSyntheticChild(index_const_str, synthetic_child); |
| 1174 | synthetic_child_sp = synthetic_child->GetSP(); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1175 | synthetic_child_sp->SetName(index_str); |
| 1176 | synthetic_child_sp->m_is_array_item_for_pointer = true; |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1177 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1178 | } |
| 1179 | } |
| 1180 | return synthetic_child_sp; |
| 1181 | } |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1182 | |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame^] | 1183 | // This allows you to create an array member using and index |
| 1184 | // that doesn't not fall in the normal bounds of the array. |
| 1185 | // Many times structure can be defined as: |
| 1186 | // struct Collection |
| 1187 | // { |
| 1188 | // uint32_t item_count; |
| 1189 | // Item item_array[0]; |
| 1190 | // }; |
| 1191 | // The size of the "item_array" is 1, but many times in practice |
| 1192 | // there are more items in "item_array". |
| 1193 | |
| 1194 | ValueObjectSP |
| 1195 | ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create) |
| 1196 | { |
| 1197 | ValueObjectSP synthetic_child_sp; |
| 1198 | if (IsArrayType ()) |
| 1199 | { |
| 1200 | char index_str[64]; |
| 1201 | snprintf(index_str, sizeof(index_str), "[%i]", index); |
| 1202 | ConstString index_const_str(index_str); |
| 1203 | // Check if we have already created a synthetic array member in this |
| 1204 | // valid object. If we have we will re-use it. |
| 1205 | synthetic_child_sp = GetSyntheticChild (index_const_str); |
| 1206 | if (!synthetic_child_sp) |
| 1207 | { |
| 1208 | ValueObject *synthetic_child; |
| 1209 | // We haven't made a synthetic array member for INDEX yet, so |
| 1210 | // lets make one and cache it for any future reference. |
| 1211 | synthetic_child = CreateChildAtIndex(0, true, index); |
| 1212 | |
| 1213 | // Cache the value if we got one back... |
| 1214 | if (synthetic_child) |
| 1215 | { |
| 1216 | AddSyntheticChild(index_const_str, synthetic_child); |
| 1217 | synthetic_child_sp = synthetic_child->GetSP(); |
| 1218 | synthetic_child_sp->SetName(index_str); |
| 1219 | synthetic_child_sp->m_is_array_item_for_pointer = true; |
| 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | return synthetic_child_sp; |
| 1224 | } |
| 1225 | |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1226 | ValueObjectSP |
| 1227 | ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create) |
| 1228 | { |
| 1229 | ValueObjectSP synthetic_child_sp; |
| 1230 | if (IsScalarType ()) |
| 1231 | { |
| 1232 | char index_str[64]; |
| 1233 | snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to); |
| 1234 | ConstString index_const_str(index_str); |
| 1235 | // Check if we have already created a synthetic array member in this |
| 1236 | // valid object. If we have we will re-use it. |
| 1237 | synthetic_child_sp = GetSyntheticChild (index_const_str); |
| 1238 | if (!synthetic_child_sp) |
| 1239 | { |
| 1240 | ValueObjectChild *synthetic_child; |
| 1241 | // We haven't made a synthetic array member for INDEX yet, so |
| 1242 | // lets make one and cache it for any future reference. |
| 1243 | synthetic_child = new ValueObjectChild(*this, |
| 1244 | GetClangAST(), |
| 1245 | GetClangType(), |
| 1246 | index_const_str, |
| 1247 | GetByteSize(), |
| 1248 | 0, |
| 1249 | to-from+1, |
| 1250 | from, |
| 1251 | false, |
| 1252 | false); |
| 1253 | |
| 1254 | // Cache the value if we got one back... |
| 1255 | if (synthetic_child) |
| 1256 | { |
| 1257 | AddSyntheticChild(index_const_str, synthetic_child); |
| 1258 | synthetic_child_sp = synthetic_child->GetSP(); |
| 1259 | synthetic_child_sp->SetName(index_str); |
| 1260 | synthetic_child_sp->m_is_bitfield_for_scalar = true; |
| 1261 | } |
| 1262 | } |
| 1263 | } |
| 1264 | return synthetic_child_sp; |
| 1265 | } |
| 1266 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1267 | void |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1268 | ValueObject::CalculateDynamicValue (lldb::DynamicValueType use_dynamic) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1269 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1270 | if (use_dynamic == lldb::eNoDynamicValues) |
| 1271 | return; |
| 1272 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1273 | if (!m_dynamic_value && !IsDynamic()) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1274 | { |
| 1275 | Process *process = m_update_point.GetProcess(); |
| 1276 | bool worth_having_dynamic_value = false; |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1277 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1278 | |
| 1279 | // FIXME: Process should have some kind of "map over Runtimes" so we don't have to |
| 1280 | // hard code this everywhere. |
| 1281 | lldb::LanguageType known_type = GetObjectRuntimeLanguage(); |
| 1282 | if (known_type != lldb::eLanguageTypeUnknown && known_type != lldb::eLanguageTypeC) |
| 1283 | { |
| 1284 | LanguageRuntime *runtime = process->GetLanguageRuntime (known_type); |
| 1285 | if (runtime) |
| 1286 | worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this); |
| 1287 | } |
| 1288 | else |
| 1289 | { |
| 1290 | LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeC_plus_plus); |
| 1291 | if (cpp_runtime) |
| 1292 | worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this); |
| 1293 | |
| 1294 | if (!worth_having_dynamic_value) |
| 1295 | { |
| 1296 | LanguageRuntime *objc_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeObjC); |
| 1297 | if (objc_runtime) |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1298 | worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | if (worth_having_dynamic_value) |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1303 | m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1304 | |
| 1305 | // if (worth_having_dynamic_value) |
| 1306 | // printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager); |
| 1307 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1308 | } |
| 1309 | } |
| 1310 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1311 | ValueObjectSP |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1312 | ValueObject::GetDynamicValue (DynamicValueType use_dynamic) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1313 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1314 | if (use_dynamic == lldb::eNoDynamicValues) |
| 1315 | return ValueObjectSP(); |
| 1316 | |
| 1317 | if (!IsDynamic() && m_dynamic_value == NULL) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1318 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1319 | CalculateDynamicValue(use_dynamic); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1320 | } |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1321 | if (m_dynamic_value) |
| 1322 | return m_dynamic_value->GetSP(); |
| 1323 | else |
| 1324 | return ValueObjectSP(); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1325 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1326 | |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1327 | bool |
| 1328 | ValueObject::GetBaseClassPath (Stream &s) |
| 1329 | { |
| 1330 | if (IsBaseClass()) |
| 1331 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1332 | bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1333 | clang_type_t clang_type = GetClangType(); |
| 1334 | std::string cxx_class_name; |
| 1335 | bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name); |
| 1336 | if (this_had_base_class) |
| 1337 | { |
| 1338 | if (parent_had_base_class) |
| 1339 | s.PutCString("::"); |
| 1340 | s.PutCString(cxx_class_name.c_str()); |
| 1341 | } |
| 1342 | return parent_had_base_class || this_had_base_class; |
| 1343 | } |
| 1344 | return false; |
| 1345 | } |
| 1346 | |
| 1347 | |
| 1348 | ValueObject * |
| 1349 | ValueObject::GetNonBaseClassParent() |
| 1350 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1351 | if (GetParent()) |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1352 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1353 | if (GetParent()->IsBaseClass()) |
| 1354 | return GetParent()->GetNonBaseClassParent(); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1355 | else |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1356 | return GetParent(); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1357 | } |
| 1358 | return NULL; |
| 1359 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1360 | |
| 1361 | void |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1362 | ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1363 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1364 | const bool is_deref_of_parent = IsDereferenceOfParent (); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1365 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1366 | if(is_deref_of_parent && epformat == eDereferencePointers) { |
| 1367 | // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely |
| 1368 | // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName. |
| 1369 | // the eHonorPointers mode is meant to produce strings in this latter format |
| 1370 | s.PutCString("*("); |
| 1371 | } |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1372 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1373 | ValueObject* parent = GetParent(); |
| 1374 | |
| 1375 | if (parent) |
| 1376 | parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1377 | |
| 1378 | // if we are a deref_of_parent just because we are synthetic array |
| 1379 | // members made up to allow ptr[%d] syntax to work in variable |
| 1380 | // printing, then add our name ([%d]) to the expression path |
| 1381 | if(m_is_array_item_for_pointer && epformat == eHonorPointers) |
| 1382 | s.PutCString(m_name.AsCString()); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1383 | |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1384 | if (!IsBaseClass()) |
| 1385 | { |
| 1386 | if (!is_deref_of_parent) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1387 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1388 | ValueObject *non_base_class_parent = GetNonBaseClassParent(); |
| 1389 | if (non_base_class_parent) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1390 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1391 | clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType(); |
| 1392 | if (non_base_class_parent_clang_type) |
| 1393 | { |
| 1394 | const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL); |
| 1395 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1396 | if(parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers) |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1397 | { |
| 1398 | s.PutCString("->"); |
| 1399 | } |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1400 | else |
| 1401 | { |
| 1402 | if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer) |
| 1403 | { |
| 1404 | s.PutCString("->"); |
| 1405 | } |
| 1406 | else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) && |
| 1407 | !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray)) |
| 1408 | { |
| 1409 | s.PutChar('.'); |
| 1410 | } |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1411 | } |
| 1412 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1413 | } |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1414 | |
| 1415 | const char *name = GetName().GetCString(); |
| 1416 | if (name) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1417 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1418 | if (qualify_cxx_base_classes) |
| 1419 | { |
| 1420 | if (GetBaseClassPath (s)) |
| 1421 | s.PutCString("::"); |
| 1422 | } |
| 1423 | s.PutCString(name); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1424 | } |
| 1425 | } |
| 1426 | } |
| 1427 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1428 | if (is_deref_of_parent && epformat == eDereferencePointers) { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1429 | s.PutChar(')'); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1430 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1433 | lldb::ValueObjectSP |
| 1434 | ValueObject::GetValueForExpressionPath(const char* expression, |
| 1435 | const char** first_unparsed, |
| 1436 | ExpressionPathScanEndReason* reason_to_stop, |
| 1437 | ExpressionPathEndResultType* final_value_type, |
| 1438 | const GetValueForExpressionPathOptions& options, |
| 1439 | ExpressionPathAftermath* final_task_on_target) |
| 1440 | { |
| 1441 | |
| 1442 | const char* dummy_first_unparsed; |
| 1443 | ExpressionPathScanEndReason dummy_reason_to_stop; |
| 1444 | ExpressionPathEndResultType dummy_final_value_type; |
| 1445 | ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing; |
| 1446 | |
| 1447 | ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression, |
| 1448 | first_unparsed ? first_unparsed : &dummy_first_unparsed, |
| 1449 | reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, |
| 1450 | final_value_type ? final_value_type : &dummy_final_value_type, |
| 1451 | options, |
| 1452 | final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); |
| 1453 | |
| 1454 | if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing) |
| 1455 | { |
| 1456 | return ret_val; |
| 1457 | } |
| 1458 | if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects |
| 1459 | { |
| 1460 | if (*final_task_on_target == ValueObject::eDereference) |
| 1461 | { |
| 1462 | Error error; |
| 1463 | ValueObjectSP final_value = ret_val->Dereference(error); |
| 1464 | if (error.Fail() || !final_value.get()) |
| 1465 | { |
| 1466 | *reason_to_stop = ValueObject::eDereferencingFailed; |
| 1467 | *final_value_type = ValueObject::eInvalid; |
| 1468 | return ValueObjectSP(); |
| 1469 | } |
| 1470 | else |
| 1471 | { |
| 1472 | *final_task_on_target = ValueObject::eNothing; |
| 1473 | return final_value; |
| 1474 | } |
| 1475 | } |
| 1476 | if (*final_task_on_target == ValueObject::eTakeAddress) |
| 1477 | { |
| 1478 | Error error; |
| 1479 | ValueObjectSP final_value = ret_val->AddressOf(error); |
| 1480 | if (error.Fail() || !final_value.get()) |
| 1481 | { |
| 1482 | *reason_to_stop = ValueObject::eTakingAddressFailed; |
| 1483 | *final_value_type = ValueObject::eInvalid; |
| 1484 | return ValueObjectSP(); |
| 1485 | } |
| 1486 | else |
| 1487 | { |
| 1488 | *final_task_on_target = ValueObject::eNothing; |
| 1489 | return final_value; |
| 1490 | } |
| 1491 | } |
| 1492 | } |
| 1493 | return ret_val; // final_task_on_target will still have its original value, so you know I did not do it |
| 1494 | } |
| 1495 | |
| 1496 | lldb::ValueObjectSP |
| 1497 | ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr, |
| 1498 | const char** first_unparsed, |
| 1499 | ExpressionPathScanEndReason* reason_to_stop, |
| 1500 | ExpressionPathEndResultType* final_result, |
| 1501 | const GetValueForExpressionPathOptions& options, |
| 1502 | ExpressionPathAftermath* what_next) |
| 1503 | { |
| 1504 | ValueObjectSP root = GetSP(); |
| 1505 | |
| 1506 | if (!root.get()) |
| 1507 | return ValueObjectSP(); |
| 1508 | |
| 1509 | *first_unparsed = expression_cstr; |
| 1510 | |
| 1511 | while (true) |
| 1512 | { |
| 1513 | |
| 1514 | const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr |
| 1515 | |
| 1516 | lldb::clang_type_t root_clang_type = root->GetClangType(); |
| 1517 | |
| 1518 | if (!expression_cstr || *expression_cstr == '\0') |
| 1519 | { |
| 1520 | *reason_to_stop = ValueObject::eEndOfString; |
| 1521 | return root; |
| 1522 | } |
| 1523 | |
| 1524 | switch (*expression_cstr) |
| 1525 | { |
| 1526 | case '-': |
| 1527 | { |
| 1528 | if (options.m_check_dot_vs_arrow_syntax && |
| 1529 | !ClangASTContext::IsPointerType(root_clang_type)) // if you are trying to use -> on a non-pointer and I must catch the error |
| 1530 | { |
| 1531 | *first_unparsed = expression_cstr; |
| 1532 | *reason_to_stop = ValueObject::eArrowInsteadOfDot; |
| 1533 | *final_result = ValueObject::eInvalid; |
| 1534 | return ValueObjectSP(); |
| 1535 | } |
| 1536 | const uint32_t pointer_type_flags = ClangASTContext::GetTypeInfo (root_clang_type, NULL, NULL); |
| 1537 | if ((pointer_type_flags & ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden |
| 1538 | (pointer_type_flags & ClangASTContext::eTypeIsPointer) && |
| 1539 | options.m_no_fragile_ivar) |
| 1540 | { |
| 1541 | *first_unparsed = expression_cstr; |
| 1542 | *reason_to_stop = ValueObject::eFragileIVarNotAllowed; |
| 1543 | *final_result = ValueObject::eInvalid; |
| 1544 | return ValueObjectSP(); |
| 1545 | } |
| 1546 | if (expression_cstr[1] != '>') |
| 1547 | { |
| 1548 | *first_unparsed = expression_cstr; |
| 1549 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 1550 | *final_result = ValueObject::eInvalid; |
| 1551 | return ValueObjectSP(); |
| 1552 | } |
| 1553 | expression_cstr++; // skip the - |
| 1554 | } |
| 1555 | case '.': // or fallthrough from -> |
| 1556 | { |
| 1557 | if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' && |
| 1558 | ClangASTContext::IsPointerType(root_clang_type)) // if you are trying to use . on a pointer and I must catch the error |
| 1559 | { |
| 1560 | *first_unparsed = expression_cstr; |
| 1561 | *reason_to_stop = ValueObject::eDotInsteadOfArrow; |
| 1562 | *final_result = ValueObject::eInvalid; |
| 1563 | return ValueObjectSP(); |
| 1564 | } |
| 1565 | expression_cstr++; // skip . |
| 1566 | const char *next_separator = strpbrk(expression_cstr+1,"-.["); |
| 1567 | ConstString child_name; |
| 1568 | if (!next_separator) // if no other separator just expand this last layer |
| 1569 | { |
| 1570 | child_name.SetCString (expression_cstr); |
| 1571 | root = root->GetChildMemberWithName(child_name, true); |
| 1572 | if (root.get()) // we know we are done, so just return |
| 1573 | { |
| 1574 | *first_unparsed = '\0'; |
| 1575 | *reason_to_stop = ValueObject::eEndOfString; |
| 1576 | *final_result = ValueObject::ePlain; |
| 1577 | return root; |
| 1578 | } |
| 1579 | else |
| 1580 | { |
| 1581 | *first_unparsed = expression_cstr; |
| 1582 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 1583 | *final_result = ValueObject::eInvalid; |
| 1584 | return ValueObjectSP(); |
| 1585 | } |
| 1586 | } |
| 1587 | else // other layers do expand |
| 1588 | { |
| 1589 | child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr); |
| 1590 | root = root->GetChildMemberWithName(child_name, true); |
| 1591 | if (root.get()) // store the new root and move on |
| 1592 | { |
| 1593 | *first_unparsed = next_separator; |
| 1594 | *final_result = ValueObject::ePlain; |
| 1595 | continue; |
| 1596 | } |
| 1597 | else |
| 1598 | { |
| 1599 | *first_unparsed = expression_cstr; |
| 1600 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 1601 | *final_result = ValueObject::eInvalid; |
| 1602 | return ValueObjectSP(); |
| 1603 | } |
| 1604 | } |
| 1605 | break; |
| 1606 | } |
| 1607 | case '[': |
| 1608 | { |
| 1609 | if (!ClangASTContext::IsArrayType(root_clang_type) && !ClangASTContext::IsPointerType(root_clang_type)) // if this is not a T[] nor a T* |
| 1610 | { |
| 1611 | if (!ClangASTContext::IsScalarType(root_clang_type)) // if this is not even a scalar, this syntax is just plain wrong! |
| 1612 | { |
| 1613 | *first_unparsed = expression_cstr; |
| 1614 | *reason_to_stop = ValueObject::eRangeOperatorInvalid; |
| 1615 | *final_result = ValueObject::eInvalid; |
| 1616 | return ValueObjectSP(); |
| 1617 | } |
| 1618 | else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields |
| 1619 | { |
| 1620 | *first_unparsed = expression_cstr; |
| 1621 | *reason_to_stop = ValueObject::eRangeOperatorNotAllowed; |
| 1622 | *final_result = ValueObject::eInvalid; |
| 1623 | return ValueObjectSP(); |
| 1624 | } |
| 1625 | } |
| 1626 | if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays |
| 1627 | { |
| 1628 | if (!ClangASTContext::IsArrayType(root_clang_type)) |
| 1629 | { |
| 1630 | *first_unparsed = expression_cstr; |
| 1631 | *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; |
| 1632 | *final_result = ValueObject::eInvalid; |
| 1633 | return ValueObjectSP(); |
| 1634 | } |
| 1635 | else // even if something follows, we cannot expand unbounded ranges, just let the caller do it |
| 1636 | { |
| 1637 | *first_unparsed = expression_cstr+2; |
| 1638 | *reason_to_stop = ValueObject::eArrayRangeOperatorMet; |
| 1639 | *final_result = ValueObject::eUnboundedRange; |
| 1640 | return root; |
| 1641 | } |
| 1642 | } |
| 1643 | const char *separator_position = ::strchr(expression_cstr+1,'-'); |
| 1644 | const char *close_bracket_position = ::strchr(expression_cstr+1,']'); |
| 1645 | if (!close_bracket_position) // if there is no ], this is a syntax error |
| 1646 | { |
| 1647 | *first_unparsed = expression_cstr; |
| 1648 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 1649 | *final_result = ValueObject::eInvalid; |
| 1650 | return ValueObjectSP(); |
| 1651 | } |
| 1652 | if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N] |
| 1653 | { |
| 1654 | char *end = NULL; |
| 1655 | unsigned long index = ::strtoul (expression_cstr+1, &end, 0); |
| 1656 | if (!end || end != close_bracket_position) // if something weird is in our way return an error |
| 1657 | { |
| 1658 | *first_unparsed = expression_cstr; |
| 1659 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 1660 | *final_result = ValueObject::eInvalid; |
| 1661 | return ValueObjectSP(); |
| 1662 | } |
| 1663 | if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays |
| 1664 | { |
| 1665 | if (ClangASTContext::IsArrayType(root_clang_type)) |
| 1666 | { |
| 1667 | *first_unparsed = expression_cstr+2; |
| 1668 | *reason_to_stop = ValueObject::eArrayRangeOperatorMet; |
| 1669 | *final_result = ValueObject::eUnboundedRange; |
| 1670 | return root; |
| 1671 | } |
| 1672 | else |
| 1673 | { |
| 1674 | *first_unparsed = expression_cstr; |
| 1675 | *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; |
| 1676 | *final_result = ValueObject::eInvalid; |
| 1677 | return ValueObjectSP(); |
| 1678 | } |
| 1679 | } |
| 1680 | // from here on we do have a valid index |
| 1681 | if (ClangASTContext::IsArrayType(root_clang_type)) |
| 1682 | { |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame^] | 1683 | ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true); |
| 1684 | if (!child_valobj_sp) |
| 1685 | child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true); |
| 1686 | if (child_valobj_sp) |
| 1687 | { |
| 1688 | root = child_valobj_sp; |
| 1689 | *first_unparsed = end+1; // skip ] |
| 1690 | *final_result = ValueObject::ePlain; |
| 1691 | continue; |
| 1692 | } |
| 1693 | else |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1694 | { |
| 1695 | *first_unparsed = expression_cstr; |
| 1696 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 1697 | *final_result = ValueObject::eInvalid; |
| 1698 | return ValueObjectSP(); |
| 1699 | } |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1700 | } |
| 1701 | else if (ClangASTContext::IsPointerType(root_clang_type)) |
| 1702 | { |
| 1703 | if (*what_next == ValueObject::eDereference && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield |
| 1704 | ClangASTContext::IsScalarType(clang::QualType::getFromOpaquePtr(root_clang_type).getTypePtr()->getPointeeType().getAsOpaquePtr())) |
| 1705 | { |
| 1706 | Error error; |
| 1707 | root = root->Dereference(error); |
| 1708 | if (error.Fail() || !root.get()) |
| 1709 | { |
| 1710 | *first_unparsed = expression_cstr; |
| 1711 | *reason_to_stop = ValueObject::eDereferencingFailed; |
| 1712 | *final_result = ValueObject::eInvalid; |
| 1713 | return ValueObjectSP(); |
| 1714 | } |
| 1715 | else |
| 1716 | { |
| 1717 | *what_next = eNothing; |
| 1718 | continue; |
| 1719 | } |
| 1720 | } |
| 1721 | else |
| 1722 | { |
| 1723 | root = root->GetSyntheticArrayMemberFromPointer(index, true); |
| 1724 | if (!root.get()) |
| 1725 | { |
| 1726 | *first_unparsed = expression_cstr; |
| 1727 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 1728 | *final_result = ValueObject::eInvalid; |
| 1729 | return ValueObjectSP(); |
| 1730 | } |
| 1731 | else |
| 1732 | { |
| 1733 | *first_unparsed = end+1; // skip ] |
| 1734 | *final_result = ValueObject::ePlain; |
| 1735 | continue; |
| 1736 | } |
| 1737 | } |
| 1738 | } |
| 1739 | else /*if (ClangASTContext::IsScalarType(root_clang_type))*/ |
| 1740 | { |
| 1741 | root = root->GetSyntheticBitFieldChild(index, index, true); |
| 1742 | if (!root.get()) |
| 1743 | { |
| 1744 | *first_unparsed = expression_cstr; |
| 1745 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 1746 | *final_result = ValueObject::eInvalid; |
| 1747 | return ValueObjectSP(); |
| 1748 | } |
| 1749 | else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing |
| 1750 | { |
| 1751 | *first_unparsed = end+1; // skip ] |
| 1752 | *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet; |
| 1753 | *final_result = ValueObject::eBitfield; |
| 1754 | return root; |
| 1755 | } |
| 1756 | } |
| 1757 | } |
| 1758 | else // we have a low and a high index |
| 1759 | { |
| 1760 | char *end = NULL; |
| 1761 | unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0); |
| 1762 | if (!end || end != separator_position) // if something weird is in our way return an error |
| 1763 | { |
| 1764 | *first_unparsed = expression_cstr; |
| 1765 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 1766 | *final_result = ValueObject::eInvalid; |
| 1767 | return ValueObjectSP(); |
| 1768 | } |
| 1769 | unsigned long index_higher = ::strtoul (separator_position+1, &end, 0); |
| 1770 | if (!end || end != close_bracket_position) // if something weird is in our way return an error |
| 1771 | { |
| 1772 | *first_unparsed = expression_cstr; |
| 1773 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 1774 | *final_result = ValueObject::eInvalid; |
| 1775 | return ValueObjectSP(); |
| 1776 | } |
| 1777 | if (index_lower > index_higher) // swap indices if required |
| 1778 | { |
| 1779 | unsigned long temp = index_lower; |
| 1780 | index_lower = index_higher; |
| 1781 | index_higher = temp; |
| 1782 | } |
| 1783 | if (ClangASTContext::IsScalarType(root_clang_type)) // expansion only works for scalars |
| 1784 | { |
| 1785 | root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true); |
| 1786 | if (!root.get()) |
| 1787 | { |
| 1788 | *first_unparsed = expression_cstr; |
| 1789 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 1790 | *final_result = ValueObject::eInvalid; |
| 1791 | return ValueObjectSP(); |
| 1792 | } |
| 1793 | else |
| 1794 | { |
| 1795 | *first_unparsed = end+1; // skip ] |
| 1796 | *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet; |
| 1797 | *final_result = ValueObject::eBitfield; |
| 1798 | return root; |
| 1799 | } |
| 1800 | } |
| 1801 | else if (ClangASTContext::IsPointerType(root_clang_type) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield |
| 1802 | *what_next == ValueObject::eDereference && |
| 1803 | ClangASTContext::IsScalarType(clang::QualType::getFromOpaquePtr(root_clang_type).getTypePtr()->getPointeeType().getAsOpaquePtr())) |
| 1804 | { |
| 1805 | Error error; |
| 1806 | root = root->Dereference(error); |
| 1807 | if (error.Fail() || !root.get()) |
| 1808 | { |
| 1809 | *first_unparsed = expression_cstr; |
| 1810 | *reason_to_stop = ValueObject::eDereferencingFailed; |
| 1811 | *final_result = ValueObject::eInvalid; |
| 1812 | return ValueObjectSP(); |
| 1813 | } |
| 1814 | else |
| 1815 | { |
| 1816 | *what_next = ValueObject::eNothing; |
| 1817 | continue; |
| 1818 | } |
| 1819 | } |
| 1820 | else |
| 1821 | { |
| 1822 | *first_unparsed = expression_cstr; |
| 1823 | *reason_to_stop = ValueObject::eArrayRangeOperatorMet; |
| 1824 | *final_result = ValueObject::eBoundedRange; |
| 1825 | return root; |
| 1826 | } |
| 1827 | } |
| 1828 | break; |
| 1829 | } |
| 1830 | default: // some non-separator is in the way |
| 1831 | { |
| 1832 | *first_unparsed = expression_cstr; |
| 1833 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 1834 | *final_result = ValueObject::eInvalid; |
| 1835 | return ValueObjectSP(); |
| 1836 | break; |
| 1837 | } |
| 1838 | } |
| 1839 | } |
| 1840 | } |
| 1841 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1842 | void |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1843 | ValueObject::DumpValueObject |
| 1844 | ( |
| 1845 | Stream &s, |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1846 | ValueObject *valobj, |
| 1847 | const char *root_valobj_name, |
| 1848 | uint32_t ptr_depth, |
| 1849 | uint32_t curr_depth, |
| 1850 | uint32_t max_depth, |
| 1851 | bool show_types, |
| 1852 | bool show_location, |
| 1853 | bool use_objc, |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1854 | lldb::DynamicValueType use_dynamic, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1855 | bool scope_already_checked, |
| 1856 | bool flat_output |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1857 | ) |
| 1858 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 1859 | if (valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1860 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 1861 | bool update_success = valobj->UpdateValueIfNeeded (); |
| 1862 | |
| 1863 | if (update_success && use_dynamic != lldb::eNoDynamicValues) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1864 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1865 | ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1866 | if (dynamic_value) |
| 1867 | valobj = dynamic_value; |
| 1868 | } |
| 1869 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1870 | clang_type_t clang_type = valobj->GetClangType(); |
| 1871 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1872 | const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL)); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1873 | const char *err_cstr = NULL; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1874 | const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren); |
| 1875 | const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1876 | |
| 1877 | const bool print_valobj = flat_output == false || has_value; |
| 1878 | |
| 1879 | if (print_valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1880 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1881 | if (show_location) |
| 1882 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1883 | s.Printf("%s: ", valobj->GetLocationAsCString()); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1884 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1885 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1886 | s.Indent(); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1887 | |
Greg Clayton | 7c8a966 | 2010-11-02 01:50:16 +0000 | [diff] [blame] | 1888 | // Always show the type for the top level items. |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1889 | if (show_types || (curr_depth == 0 && !flat_output)) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1890 | s.Printf("(%s) ", valobj->GetTypeName().AsCString("<invalid type>")); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1891 | |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1892 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1893 | if (flat_output) |
| 1894 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1895 | // If we are showing types, also qualify the C++ base classes |
| 1896 | const bool qualify_cxx_base_classes = show_types; |
| 1897 | valobj->GetExpressionPath(s, qualify_cxx_base_classes); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1898 | s.PutCString(" ="); |
| 1899 | } |
| 1900 | else |
| 1901 | { |
| 1902 | const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString(""); |
| 1903 | s.Printf ("%s =", name_cstr); |
| 1904 | } |
| 1905 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1906 | if (!scope_already_checked && !valobj->IsInScope()) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1907 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 1908 | err_cstr = "out of scope"; |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1909 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1910 | } |
| 1911 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1912 | const char *val_cstr = NULL; |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1913 | const char *sum_cstr = NULL; |
| 1914 | SummaryFormat* entry = valobj->m_last_summary_format.get(); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1915 | |
| 1916 | if (err_cstr == NULL) |
| 1917 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1918 | val_cstr = valobj->GetValueAsCString(); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1919 | err_cstr = valobj->GetError().AsCString(); |
| 1920 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1921 | |
| 1922 | if (err_cstr) |
| 1923 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 1924 | s.Printf (" <%s>\n", err_cstr); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1925 | } |
| 1926 | else |
| 1927 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1928 | const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1929 | if (print_valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1930 | { |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1931 | |
| 1932 | sum_cstr = valobj->GetSummaryAsCString(); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1933 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1934 | // We must calculate this value in realtime because entry might alter this variable's value |
| 1935 | // (e.g. by saying ${var%fmt}) and render precached values useless |
| 1936 | if (val_cstr && (!entry || entry->DoesPrintValue() || !sum_cstr)) |
| 1937 | s.Printf(" %s", valobj->GetValueAsCString()); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1938 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1939 | if(sum_cstr) |
| 1940 | { |
| 1941 | // for some reason, using %@ (ObjC description) in a summary string, makes |
| 1942 | // us believe we need to reset ourselves, thus invalidating the content of |
| 1943 | // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty |
| 1944 | // let us recalculate it! |
| 1945 | if (sum_cstr[0] == '\0') |
| 1946 | s.Printf(" %s", valobj->GetSummaryAsCString()); |
| 1947 | else |
| 1948 | s.Printf(" %s", sum_cstr); |
| 1949 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1950 | |
| 1951 | if (use_objc) |
| 1952 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1953 | const char *object_desc = valobj->GetObjectDescription(); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1954 | if (object_desc) |
| 1955 | s.Printf(" %s\n", object_desc); |
| 1956 | else |
Sean Callanan | 672ad94 | 2010-10-23 00:18:49 +0000 | [diff] [blame] | 1957 | s.Printf (" [no Objective-C description available]\n"); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1958 | return; |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1959 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1960 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1961 | |
| 1962 | if (curr_depth < max_depth) |
| 1963 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1964 | // We will show children for all concrete types. We won't show |
| 1965 | // pointer contents unless a pointer depth has been specified. |
| 1966 | // We won't reference contents unless the reference is the |
| 1967 | // root object (depth of zero). |
| 1968 | bool print_children = true; |
| 1969 | |
| 1970 | // Use a new temporary pointer depth in case we override the |
| 1971 | // current pointer depth below... |
| 1972 | uint32_t curr_ptr_depth = ptr_depth; |
| 1973 | |
| 1974 | const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer); |
| 1975 | if (is_ptr || is_ref) |
| 1976 | { |
| 1977 | // We have a pointer or reference whose value is an address. |
| 1978 | // Make sure that address is not NULL |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1979 | AddressType ptr_address_type; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1980 | if (valobj->GetPointerValue (ptr_address_type, true) == 0) |
| 1981 | print_children = false; |
| 1982 | |
| 1983 | else if (is_ref && curr_depth == 0) |
| 1984 | { |
| 1985 | // If this is the root object (depth is zero) that we are showing |
| 1986 | // and it is a reference, and no pointer depth has been supplied |
| 1987 | // print out what it references. Don't do this at deeper depths |
| 1988 | // otherwise we can end up with infinite recursion... |
| 1989 | curr_ptr_depth = 1; |
| 1990 | } |
| 1991 | |
| 1992 | if (curr_ptr_depth == 0) |
| 1993 | print_children = false; |
| 1994 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1995 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1996 | if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr)) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1997 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1998 | const uint32_t num_children = valobj->GetNumChildren(); |
| 1999 | if (num_children) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2000 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2001 | if (flat_output) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2002 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2003 | if (print_valobj) |
| 2004 | s.EOL(); |
| 2005 | } |
| 2006 | else |
| 2007 | { |
| 2008 | if (print_valobj) |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 2009 | s.PutCString(is_ref ? ": {\n" : " {\n"); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2010 | s.IndentMore(); |
| 2011 | } |
| 2012 | |
| 2013 | for (uint32_t idx=0; idx<num_children; ++idx) |
| 2014 | { |
| 2015 | ValueObjectSP child_sp(valobj->GetChildAtIndex(idx, true)); |
| 2016 | if (child_sp.get()) |
| 2017 | { |
| 2018 | DumpValueObject (s, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2019 | child_sp.get(), |
| 2020 | NULL, |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2021 | (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2022 | curr_depth + 1, |
| 2023 | max_depth, |
| 2024 | show_types, |
| 2025 | show_location, |
| 2026 | false, |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2027 | use_dynamic, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2028 | true, |
| 2029 | flat_output); |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | if (!flat_output) |
| 2034 | { |
| 2035 | s.IndentLess(); |
| 2036 | s.Indent("}\n"); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2037 | } |
| 2038 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2039 | else if (has_children) |
| 2040 | { |
| 2041 | // Aggregate, no children... |
| 2042 | if (print_valobj) |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2043 | s.PutCString(" {}\n"); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2044 | } |
| 2045 | else |
| 2046 | { |
| 2047 | if (print_valobj) |
| 2048 | s.EOL(); |
| 2049 | } |
| 2050 | |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2051 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2052 | else |
| 2053 | { |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2054 | s.EOL(); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2055 | } |
| 2056 | } |
| 2057 | else |
| 2058 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2059 | if (has_children && print_valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2060 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2061 | s.PutCString("{...}\n"); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2062 | } |
| 2063 | } |
| 2064 | } |
| 2065 | } |
| 2066 | } |
| 2067 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2068 | |
| 2069 | ValueObjectSP |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2070 | ValueObject::CreateConstantValue (const ConstString &name) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2071 | { |
| 2072 | ValueObjectSP valobj_sp; |
| 2073 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2074 | if (UpdateValueIfNeeded() && m_error.Success()) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2075 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2076 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 2077 | if (exe_scope) |
| 2078 | { |
| 2079 | ExecutionContext exe_ctx; |
| 2080 | exe_scope->CalculateExecutionContext(exe_ctx); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2081 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2082 | clang::ASTContext *ast = GetClangAST (); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2083 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2084 | DataExtractor data; |
| 2085 | data.SetByteOrder (m_data.GetByteOrder()); |
| 2086 | data.SetAddressByteSize(m_data.GetAddressByteSize()); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2087 | |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 2088 | m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule()); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2089 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2090 | valobj_sp = ValueObjectConstResult::Create (exe_scope, |
| 2091 | ast, |
| 2092 | GetClangType(), |
| 2093 | name, |
| 2094 | data); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2095 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2096 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2097 | |
| 2098 | if (!valobj_sp) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2099 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2100 | valobj_sp = ValueObjectConstResult::Create (NULL, m_error); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2101 | } |
| 2102 | return valobj_sp; |
| 2103 | } |
| 2104 | |
| 2105 | lldb::ValueObjectSP |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 2106 | ValueObject::Dereference (Error &error) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2107 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2108 | if (m_deref_valobj) |
| 2109 | return m_deref_valobj->GetSP(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2110 | |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2111 | const bool is_pointer_type = IsPointerType(); |
| 2112 | if (is_pointer_type) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2113 | { |
| 2114 | bool omit_empty_base_classes = true; |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame^] | 2115 | bool ignore_array_bounds = false; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2116 | |
| 2117 | std::string child_name_str; |
| 2118 | uint32_t child_byte_size = 0; |
| 2119 | int32_t child_byte_offset = 0; |
| 2120 | uint32_t child_bitfield_bit_size = 0; |
| 2121 | uint32_t child_bitfield_bit_offset = 0; |
| 2122 | bool child_is_base_class = false; |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2123 | bool child_is_deref_of_parent = false; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2124 | const bool transparent_pointers = false; |
| 2125 | clang::ASTContext *clang_ast = GetClangAST(); |
| 2126 | clang_type_t clang_type = GetClangType(); |
| 2127 | clang_type_t child_clang_type; |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 2128 | |
| 2129 | ExecutionContext exe_ctx; |
| 2130 | GetExecutionContextScope()->CalculateExecutionContext (exe_ctx); |
| 2131 | |
| 2132 | child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx, |
| 2133 | clang_ast, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2134 | GetName().GetCString(), |
| 2135 | clang_type, |
| 2136 | 0, |
| 2137 | transparent_pointers, |
| 2138 | omit_empty_base_classes, |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame^] | 2139 | ignore_array_bounds, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2140 | child_name_str, |
| 2141 | child_byte_size, |
| 2142 | child_byte_offset, |
| 2143 | child_bitfield_bit_size, |
| 2144 | child_bitfield_bit_offset, |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2145 | child_is_base_class, |
| 2146 | child_is_deref_of_parent); |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 2147 | if (child_clang_type && child_byte_size) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2148 | { |
| 2149 | ConstString child_name; |
| 2150 | if (!child_name_str.empty()) |
| 2151 | child_name.SetCString (child_name_str.c_str()); |
| 2152 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2153 | m_deref_valobj = new ValueObjectChild (*this, |
| 2154 | clang_ast, |
| 2155 | child_clang_type, |
| 2156 | child_name, |
| 2157 | child_byte_size, |
| 2158 | child_byte_offset, |
| 2159 | child_bitfield_bit_size, |
| 2160 | child_bitfield_bit_offset, |
| 2161 | child_is_base_class, |
| 2162 | child_is_deref_of_parent); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2163 | } |
| 2164 | } |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2165 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2166 | if (m_deref_valobj) |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2167 | { |
| 2168 | error.Clear(); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2169 | return m_deref_valobj->GetSP(); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2170 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2171 | else |
| 2172 | { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2173 | StreamString strm; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2174 | GetExpressionPath(strm, true); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2175 | |
| 2176 | if (is_pointer_type) |
| 2177 | error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str()); |
| 2178 | else |
| 2179 | error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str()); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2180 | return ValueObjectSP(); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2181 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2184 | lldb::ValueObjectSP |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2185 | ValueObject::AddressOf (Error &error) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2186 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2187 | if (m_addr_of_valobj_sp) |
| 2188 | return m_addr_of_valobj_sp; |
| 2189 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 2190 | AddressType address_type = eAddressTypeInvalid; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2191 | const bool scalar_is_load_address = false; |
| 2192 | lldb::addr_t addr = GetAddressOf (address_type, scalar_is_load_address); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2193 | error.Clear(); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2194 | if (addr != LLDB_INVALID_ADDRESS) |
| 2195 | { |
| 2196 | switch (address_type) |
| 2197 | { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2198 | default: |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2199 | case eAddressTypeInvalid: |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2200 | { |
| 2201 | StreamString expr_path_strm; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2202 | GetExpressionPath(expr_path_strm, true); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2203 | error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str()); |
| 2204 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2205 | break; |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2206 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2207 | case eAddressTypeFile: |
| 2208 | case eAddressTypeLoad: |
| 2209 | case eAddressTypeHost: |
| 2210 | { |
| 2211 | clang::ASTContext *ast = GetClangAST(); |
| 2212 | clang_type_t clang_type = GetClangType(); |
| 2213 | if (ast && clang_type) |
| 2214 | { |
| 2215 | std::string name (1, '&'); |
| 2216 | name.append (m_name.AsCString("")); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2217 | m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(), |
| 2218 | ast, |
| 2219 | ClangASTContext::CreatePointerType (ast, clang_type), |
| 2220 | ConstString (name.c_str()), |
| 2221 | addr, |
| 2222 | eAddressTypeInvalid, |
| 2223 | m_data.GetAddressByteSize()); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2224 | } |
| 2225 | } |
| 2226 | break; |
| 2227 | } |
| 2228 | } |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2229 | return m_addr_of_valobj_sp; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2230 | } |
| 2231 | |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 2232 | |
| 2233 | lldb::ValueObjectSP |
| 2234 | ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type) |
| 2235 | { |
| 2236 | lldb::ValueObjectSP valobj_sp; |
| 2237 | AddressType address_type; |
| 2238 | const bool scalar_is_load_address = true; |
| 2239 | lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address); |
| 2240 | |
| 2241 | if (ptr_value != LLDB_INVALID_ADDRESS) |
| 2242 | { |
| 2243 | Address ptr_addr (NULL, ptr_value); |
| 2244 | |
| 2245 | valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(), |
| 2246 | name, |
| 2247 | ptr_addr, |
| 2248 | clang_ast_type); |
| 2249 | } |
| 2250 | return valobj_sp; |
| 2251 | } |
| 2252 | |
| 2253 | lldb::ValueObjectSP |
| 2254 | ValueObject::CastPointerType (const char *name, TypeSP &type_sp) |
| 2255 | { |
| 2256 | lldb::ValueObjectSP valobj_sp; |
| 2257 | AddressType address_type; |
| 2258 | const bool scalar_is_load_address = true; |
| 2259 | lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address); |
| 2260 | |
| 2261 | if (ptr_value != LLDB_INVALID_ADDRESS) |
| 2262 | { |
| 2263 | Address ptr_addr (NULL, ptr_value); |
| 2264 | |
| 2265 | valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(), |
| 2266 | name, |
| 2267 | ptr_addr, |
| 2268 | type_sp); |
| 2269 | } |
| 2270 | return valobj_sp; |
| 2271 | } |
| 2272 | |
| 2273 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2274 | ValueObject::EvaluationPoint::EvaluationPoint () : |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 2275 | m_thread_id (LLDB_INVALID_UID), |
| 2276 | m_stop_id (0) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2277 | { |
| 2278 | } |
| 2279 | |
| 2280 | ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected): |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2281 | m_needs_update (true), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 2282 | m_first_update (true), |
Jim Ingham | 89b6109 | 2011-07-06 17:42:14 +0000 | [diff] [blame] | 2283 | m_thread_id (LLDB_INVALID_THREAD_ID), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 2284 | m_stop_id (0) |
| 2285 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2286 | { |
| 2287 | ExecutionContext exe_ctx; |
| 2288 | ExecutionContextScope *computed_exe_scope = exe_scope; // If use_selected is true, we may find a better scope, |
| 2289 | // and if so we want to cache that not the original. |
| 2290 | if (exe_scope) |
| 2291 | exe_scope->CalculateExecutionContext(exe_ctx); |
| 2292 | if (exe_ctx.target != NULL) |
| 2293 | { |
| 2294 | m_target_sp = exe_ctx.target->GetSP(); |
| 2295 | |
| 2296 | if (exe_ctx.process == NULL) |
| 2297 | m_process_sp = exe_ctx.target->GetProcessSP(); |
| 2298 | else |
| 2299 | m_process_sp = exe_ctx.process->GetSP(); |
| 2300 | |
| 2301 | if (m_process_sp != NULL) |
| 2302 | { |
| 2303 | m_stop_id = m_process_sp->GetStopID(); |
| 2304 | Thread *thread = NULL; |
| 2305 | |
| 2306 | if (exe_ctx.thread == NULL) |
| 2307 | { |
| 2308 | if (use_selected) |
| 2309 | { |
| 2310 | thread = m_process_sp->GetThreadList().GetSelectedThread().get(); |
| 2311 | if (thread) |
| 2312 | computed_exe_scope = thread; |
| 2313 | } |
| 2314 | } |
| 2315 | else |
| 2316 | thread = exe_ctx.thread; |
| 2317 | |
| 2318 | if (thread != NULL) |
| 2319 | { |
| 2320 | m_thread_id = thread->GetIndexID(); |
| 2321 | if (exe_ctx.frame == NULL) |
| 2322 | { |
| 2323 | if (use_selected) |
| 2324 | { |
| 2325 | StackFrame *frame = exe_ctx.thread->GetSelectedFrame().get(); |
| 2326 | if (frame) |
| 2327 | { |
| 2328 | m_stack_id = frame->GetStackID(); |
| 2329 | computed_exe_scope = frame; |
| 2330 | } |
| 2331 | } |
| 2332 | } |
| 2333 | else |
| 2334 | m_stack_id = exe_ctx.frame->GetStackID(); |
| 2335 | } |
| 2336 | } |
| 2337 | } |
| 2338 | m_exe_scope = computed_exe_scope; |
| 2339 | } |
| 2340 | |
| 2341 | ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) : |
| 2342 | m_exe_scope (rhs.m_exe_scope), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 2343 | m_needs_update(true), |
| 2344 | m_first_update(true), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2345 | m_target_sp (rhs.m_target_sp), |
| 2346 | m_process_sp (rhs.m_process_sp), |
| 2347 | m_thread_id (rhs.m_thread_id), |
| 2348 | m_stack_id (rhs.m_stack_id), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2349 | m_stop_id (0) |
| 2350 | { |
| 2351 | } |
| 2352 | |
| 2353 | ValueObject::EvaluationPoint::~EvaluationPoint () |
| 2354 | { |
| 2355 | } |
| 2356 | |
| 2357 | ExecutionContextScope * |
| 2358 | ValueObject::EvaluationPoint::GetExecutionContextScope () |
| 2359 | { |
| 2360 | // We have to update before giving out the scope, or we could be handing out stale pointers. |
| 2361 | SyncWithProcessState(); |
| 2362 | |
| 2363 | return m_exe_scope; |
| 2364 | } |
| 2365 | |
| 2366 | // This function checks the EvaluationPoint against the current process state. If the current |
| 2367 | // state matches the evaluation point, or the evaluation point is already invalid, then we return |
| 2368 | // false, meaning "no change". If the current state is different, we update our state, and return |
| 2369 | // true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so |
| 2370 | // future calls to NeedsUpdate will return true. |
| 2371 | |
| 2372 | bool |
| 2373 | ValueObject::EvaluationPoint::SyncWithProcessState() |
| 2374 | { |
| 2375 | // If we're already invalid, we don't need to do anything, and nothing has changed: |
| 2376 | if (m_stop_id == LLDB_INVALID_UID) |
| 2377 | { |
| 2378 | // Can't update with an invalid state. |
| 2379 | m_needs_update = false; |
| 2380 | return false; |
| 2381 | } |
| 2382 | |
| 2383 | // If we don't have a process nothing can change. |
| 2384 | if (!m_process_sp) |
| 2385 | return false; |
| 2386 | |
| 2387 | // If our stop id is the current stop ID, nothing has changed: |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2388 | uint32_t cur_stop_id = m_process_sp->GetStopID(); |
| 2389 | if (m_stop_id == cur_stop_id) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2390 | return false; |
| 2391 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2392 | // If the current stop id is 0, either we haven't run yet, or the process state has been cleared. |
| 2393 | // In either case, we aren't going to be able to sync with the process state. |
| 2394 | if (cur_stop_id == 0) |
| 2395 | return false; |
| 2396 | |
| 2397 | m_stop_id = cur_stop_id; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2398 | m_needs_update = true; |
| 2399 | m_exe_scope = m_process_sp.get(); |
| 2400 | |
| 2401 | // Something has changed, so we will return true. Now make sure the thread & frame still exist, and if either |
| 2402 | // doesn't, mark ourselves as invalid. |
| 2403 | |
| 2404 | if (m_thread_id != LLDB_INVALID_THREAD_ID) |
| 2405 | { |
| 2406 | Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get(); |
| 2407 | if (our_thread == NULL) |
Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame] | 2408 | { |
Jim Ingham | 89b6109 | 2011-07-06 17:42:14 +0000 | [diff] [blame] | 2409 | SetInvalid(); |
Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame] | 2410 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2411 | else |
| 2412 | { |
| 2413 | m_exe_scope = our_thread; |
| 2414 | |
| 2415 | if (m_stack_id.IsValid()) |
| 2416 | { |
| 2417 | StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get(); |
| 2418 | if (our_frame == NULL) |
| 2419 | SetInvalid(); |
| 2420 | else |
| 2421 | m_exe_scope = our_frame; |
| 2422 | } |
| 2423 | } |
| 2424 | } |
| 2425 | return true; |
| 2426 | } |
| 2427 | |
Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 2428 | void |
| 2429 | ValueObject::EvaluationPoint::SetUpdated () |
| 2430 | { |
| 2431 | m_first_update = false; |
| 2432 | m_needs_update = false; |
| 2433 | if (m_process_sp) |
| 2434 | m_stop_id = m_process_sp->GetStopID(); |
| 2435 | } |
| 2436 | |
| 2437 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2438 | bool |
| 2439 | ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope) |
| 2440 | { |
| 2441 | if (!IsValid()) |
| 2442 | return false; |
| 2443 | |
| 2444 | bool needs_update = false; |
| 2445 | m_exe_scope = NULL; |
| 2446 | |
| 2447 | // The target has to be non-null, and the |
| 2448 | Target *target = exe_scope->CalculateTarget(); |
| 2449 | if (target != NULL) |
| 2450 | { |
| 2451 | Target *old_target = m_target_sp.get(); |
| 2452 | assert (target == old_target); |
| 2453 | Process *process = exe_scope->CalculateProcess(); |
| 2454 | if (process != NULL) |
| 2455 | { |
| 2456 | // FOR NOW - assume you can't update variable objects across process boundaries. |
| 2457 | Process *old_process = m_process_sp.get(); |
| 2458 | assert (process == old_process); |
| 2459 | |
| 2460 | lldb::user_id_t stop_id = process->GetStopID(); |
| 2461 | if (stop_id != m_stop_id) |
| 2462 | { |
| 2463 | needs_update = true; |
| 2464 | m_stop_id = stop_id; |
| 2465 | } |
| 2466 | // See if we're switching the thread or stack context. If no thread is given, this is |
| 2467 | // being evaluated in a global context. |
| 2468 | Thread *thread = exe_scope->CalculateThread(); |
| 2469 | if (thread != NULL) |
| 2470 | { |
| 2471 | lldb::user_id_t new_thread_index = thread->GetIndexID(); |
| 2472 | if (new_thread_index != m_thread_id) |
| 2473 | { |
| 2474 | needs_update = true; |
| 2475 | m_thread_id = new_thread_index; |
| 2476 | m_stack_id.Clear(); |
| 2477 | } |
| 2478 | |
| 2479 | StackFrame *new_frame = exe_scope->CalculateStackFrame(); |
| 2480 | if (new_frame != NULL) |
| 2481 | { |
| 2482 | if (new_frame->GetStackID() != m_stack_id) |
| 2483 | { |
| 2484 | needs_update = true; |
| 2485 | m_stack_id = new_frame->GetStackID(); |
| 2486 | } |
| 2487 | } |
| 2488 | else |
| 2489 | { |
| 2490 | m_stack_id.Clear(); |
| 2491 | needs_update = true; |
| 2492 | } |
| 2493 | } |
| 2494 | else |
| 2495 | { |
| 2496 | // If this had been given a thread, and now there is none, we should update. |
| 2497 | // Otherwise we don't have to do anything. |
| 2498 | if (m_thread_id != LLDB_INVALID_UID) |
| 2499 | { |
| 2500 | m_thread_id = LLDB_INVALID_UID; |
| 2501 | m_stack_id.Clear(); |
| 2502 | needs_update = true; |
| 2503 | } |
| 2504 | } |
| 2505 | } |
| 2506 | else |
| 2507 | { |
| 2508 | // If there is no process, then we don't need to update anything. |
| 2509 | // But if we're switching from having a process to not, we should try to update. |
| 2510 | if (m_process_sp.get() != NULL) |
| 2511 | { |
| 2512 | needs_update = true; |
| 2513 | m_process_sp.reset(); |
| 2514 | m_thread_id = LLDB_INVALID_UID; |
| 2515 | m_stack_id.Clear(); |
| 2516 | } |
| 2517 | } |
| 2518 | } |
| 2519 | else |
| 2520 | { |
| 2521 | // If there's no target, nothing can change so we don't need to update anything. |
| 2522 | // But if we're switching from having a target to not, we should try to update. |
| 2523 | if (m_target_sp.get() != NULL) |
| 2524 | { |
| 2525 | needs_update = true; |
| 2526 | m_target_sp.reset(); |
| 2527 | m_process_sp.reset(); |
| 2528 | m_thread_id = LLDB_INVALID_UID; |
| 2529 | m_stack_id.Clear(); |
| 2530 | } |
| 2531 | } |
| 2532 | if (!m_needs_update) |
| 2533 | m_needs_update = needs_update; |
| 2534 | |
| 2535 | return needs_update; |
| 2536 | } |