blob: b336d59f79490622407f0bbaf2d2410527e35a6e [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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 Claytonf5e56de2010-09-14 23:36:40 +000013#include <stdlib.h>
14
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015// C++ Includes
16// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000018#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
20// Project includes
21#include "lldb/Core/DataBufferHeap.h"
Enrico Granata0a976142011-08-22 22:03:47 +000022#include "lldb/Core/DataVisualization.h"
Enrico Granata4becb372011-06-29 22:27:15 +000023#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000024#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/StreamString.h"
26#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000027#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000028#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000030#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000031#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Greg Clayton7fb56d02011-02-01 01:31:41 +000033#include "lldb/Host/Endian.h"
34
Enrico Granata61a80ba2011-08-12 16:42:31 +000035#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000036#include "lldb/Interpreter/ScriptInterpreterPython.h"
37
Greg Claytone1a916a2010-07-21 22:12:05 +000038#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Symbol/ClangASTContext.h"
40#include "lldb/Symbol/Type.h"
41
Jim Ingham53c47f12010-09-10 23:12:17 +000042#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000043#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000044#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045#include "lldb/Target/Process.h"
46#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000047#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049
Enrico Granataf4efecd2011-07-12 22:56:10 +000050#include "lldb/Utility/RefCounter.h"
51
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052using namespace lldb;
53using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000054using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055
Greg Claytonafacd142011-09-02 01:15:17 +000056static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057
58//----------------------------------------------------------------------
59// ValueObject constructor
60//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000061ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000063 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000064 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065 m_name (),
66 m_data (),
67 m_value (),
68 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000069 m_value_str (),
70 m_old_value_str (),
71 m_location_str (),
72 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000073 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000074 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000075 m_children (),
76 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000077 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000078 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000079 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000080 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000081 m_last_format_mgr_revision(0),
Enrico Granatad8b5fce2011-08-02 23:12:24 +000082 m_last_format_mgr_dynamic(parent.m_last_format_mgr_dynamic),
Enrico Granata0c489f52012-03-01 04:24:26 +000083 m_type_summary_sp(),
84 m_type_format_sp(),
85 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000086 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000087 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000088 m_value_is_valid (false),
89 m_value_did_change (false),
90 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000091 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000092 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000093 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000094 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +000095 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000096 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +000097 m_is_getting_summary(false),
98 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +000099{
Jim Ingham58b59f92011-04-22 23:53:53 +0000100 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000101}
102
103//----------------------------------------------------------------------
104// ValueObject constructor
105//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000106ValueObject::ValueObject (ExecutionContextScope *exe_scope,
107 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000108 UserID (++g_value_obj_uid), // Unique identifier for every value object
109 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000110 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000111 m_name (),
112 m_data (),
113 m_value (),
114 m_error (),
115 m_value_str (),
116 m_old_value_str (),
117 m_location_str (),
118 m_summary_str (),
119 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000120 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000121 m_children (),
122 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000123 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000124 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000125 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000126 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000127 m_last_format_mgr_revision(0),
Greg Claytonafacd142011-09-02 01:15:17 +0000128 m_last_format_mgr_dynamic(eNoDynamicValues),
Enrico Granata0c489f52012-03-01 04:24:26 +0000129 m_type_summary_sp(),
130 m_type_format_sp(),
131 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000132 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000133 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000134 m_value_is_valid (false),
135 m_value_did_change (false),
136 m_children_count_valid (false),
137 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000138 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000139 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000140 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000141 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000142 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000143 m_is_getting_summary(false),
144 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000145{
Jim Ingham58b59f92011-04-22 23:53:53 +0000146 m_manager = new ValueObjectManager();
147 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148}
149
150//----------------------------------------------------------------------
151// Destructor
152//----------------------------------------------------------------------
153ValueObject::~ValueObject ()
154{
155}
156
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000157bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000158ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000160 return UpdateValueIfNeeded(m_last_format_mgr_dynamic, update_format);
161}
162
163bool
Greg Claytonafacd142011-09-02 01:15:17 +0000164ValueObject::UpdateValueIfNeeded (DynamicValueType use_dynamic, bool update_format)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000165{
Enrico Granata4becb372011-06-29 22:27:15 +0000166
Enrico Granata9128ee22011-09-06 19:20:51 +0000167 bool did_change_formats = false;
168
Enrico Granata0a3958e2011-07-02 00:25:22 +0000169 if (update_format)
Enrico Granata9128ee22011-09-06 19:20:51 +0000170 did_change_formats = UpdateFormatsIfNeeded(use_dynamic);
Enrico Granata4becb372011-06-29 22:27:15 +0000171
Greg Claytonb71f3842010-10-05 03:13:51 +0000172 // If this is a constant value, then our success is predicated on whether
173 // we have an error or not
174 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000175 {
176 // if you were asked to update your formatters, but did not get a chance to do it
177 // clear your own values (this serves the purpose of faking a stop-id for frozen
178 // objects (which are regarded as constant, but could have changes behind their backs
179 // because of the frozen-pointer depth limit)
180 // TODO: decouple summary from value and then remove this code and only force-clear the summary
181 if (update_format && !did_change_formats)
182 m_summary_str.clear();
Greg Claytonb71f3842010-10-05 03:13:51 +0000183 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000184 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000185
Jim Ingham6035b672011-03-31 00:19:25 +0000186 bool first_update = m_update_point.IsFirstEvaluation();
187
188 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189 {
Jim Ingham6035b672011-03-31 00:19:25 +0000190 m_update_point.SetUpdated();
191
192 // Save the old value using swap to avoid a string copy which
193 // also will clear our m_value_str
194 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000195 {
Jim Ingham6035b672011-03-31 00:19:25 +0000196 m_old_value_valid = false;
197 }
198 else
199 {
200 m_old_value_valid = true;
201 m_old_value_str.swap (m_value_str);
202 m_value_str.clear();
203 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000204
Enrico Granataf2bbf712011-07-15 02:26:42 +0000205 ClearUserVisibleData();
206
Jim Ingham6035b672011-03-31 00:19:25 +0000207 const bool value_was_valid = GetValueIsValid();
208 SetValueDidChange (false);
Greg Clayton73b953b2010-08-28 00:08:07 +0000209
Jim Ingham6035b672011-03-31 00:19:25 +0000210 m_error.Clear();
Greg Clayton73b953b2010-08-28 00:08:07 +0000211
Jim Ingham6035b672011-03-31 00:19:25 +0000212 // Call the pure virtual function to update the value
213 bool success = UpdateValue ();
214
215 SetValueIsValid (success);
216
217 if (first_update)
218 SetValueDidChange (false);
219 else if (!m_value_did_change && success == false)
220 {
221 // The value wasn't gotten successfully, so we mark this
222 // as changed if the value used to be valid and now isn't
223 SetValueDidChange (value_was_valid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224 }
225 }
226 return m_error.Success();
227}
228
Enrico Granata9128ee22011-09-06 19:20:51 +0000229bool
Greg Claytonafacd142011-09-02 01:15:17 +0000230ValueObject::UpdateFormatsIfNeeded(DynamicValueType use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000231{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000232 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
233 if (log)
234 log->Printf("checking for FormatManager revisions. VO named %s is at revision %d, while the format manager is at revision %d",
235 GetName().GetCString(),
Enrico Granata4becb372011-06-29 22:27:15 +0000236 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000237 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000238
239 bool any_change = false;
240
Enrico Granata85933ed2011-08-18 16:38:26 +0000241 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) ||
Enrico Granatac3e320a2011-08-02 17:27:39 +0000242 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000243 {
Enrico Granata78d06382011-09-09 23:33:14 +0000244 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
245 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, use_dynamic));
246 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, use_dynamic));
Enrico Granata1490c6f2011-07-19 02:34:21 +0000247
Enrico Granata85933ed2011-08-18 16:38:26 +0000248 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000249 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granata855cd902011-09-06 22:59:55 +0000250
251 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000252 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000253
254 return any_change;
255
Enrico Granata4becb372011-06-29 22:27:15 +0000256}
257
Jim Ingham16e0c682011-08-12 23:34:31 +0000258void
259ValueObject::SetNeedsUpdate ()
260{
261 m_update_point.SetNeedsUpdate();
262 // We have to clear the value string here so ConstResult children will notice if their values are
263 // changed by hand (i.e. with SetValueAsCString).
264 m_value_str.clear();
265}
266
Sean Callanan72772842012-02-22 23:57:45 +0000267ClangASTType
268ValueObject::MaybeCalculateCompleteType ()
269{
270 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
271
272 if (m_did_calculate_complete_objc_class_type)
273 {
274 if (m_override_type.IsValid())
275 return m_override_type;
276 else
277 return ret;
278 }
279
280 clang_type_t ast_type(GetClangTypeImpl());
281 clang_type_t class_type;
282 bool is_pointer_type;
283
284 if (ClangASTContext::IsObjCObjectPointerType(ast_type, &class_type))
285 {
286 is_pointer_type = true;
287 }
288 else if (ClangASTContext::IsObjCClassType(ast_type))
289 {
290 is_pointer_type = false;
291 class_type = ast_type;
292 }
293 else
294 {
295 return ret;
296 }
297
298 m_did_calculate_complete_objc_class_type = true;
299
300 if (!class_type)
301 return ret;
302
303 std::string class_name;
304
305 if (!ClangASTContext::GetObjCClassName(class_type, class_name))
306 return ret;
307
308 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
309
310 if (!process_sp)
311 return ret;
312
313 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
314
315 if (!objc_language_runtime)
316 return ret;
317
318 ConstString class_name_cs(class_name.c_str());
319
320 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name_cs);
321
322 if (!complete_objc_class_type_sp)
323 return ret;
324
325 ClangASTType complete_class(complete_objc_class_type_sp->GetClangAST(),
326 complete_objc_class_type_sp->GetClangFullType());
327
328 if (!ClangASTContext::GetCompleteType(complete_class.GetASTContext(),
329 complete_class.GetOpaqueQualType()))
330 return ret;
331
332 if (is_pointer_type)
333 {
334 clang_type_t pointer_type = ClangASTContext::CreatePointerType(complete_class.GetASTContext(),
335 complete_class.GetOpaqueQualType());
336
337 m_override_type = ClangASTType(complete_class.GetASTContext(),
338 pointer_type);
339 }
340 else
341 {
342 m_override_type = complete_class;
343 }
344
345 return m_override_type;
346}
347
348clang::ASTContext *
349ValueObject::GetClangAST ()
350{
351 ClangASTType type = MaybeCalculateCompleteType();
352
353 return type.GetASTContext();
354}
355
356lldb::clang_type_t
357ValueObject::GetClangType ()
358{
359 ClangASTType type = MaybeCalculateCompleteType();
360
361 return type.GetOpaqueQualType();
362}
363
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000364DataExtractor &
365ValueObject::GetDataExtractor ()
366{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000367 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368 return m_data;
369}
370
371const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000372ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000374 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375 return m_error;
376}
377
378const ConstString &
379ValueObject::GetName() const
380{
381 return m_name;
382}
383
384const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000385ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000386{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000387 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000388 {
389 if (m_location_str.empty())
390 {
391 StreamString sstr;
392
393 switch (m_value.GetValueType())
394 {
395 default:
396 break;
397
398 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000399 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400 {
401 RegisterInfo *reg_info = m_value.GetRegisterInfo();
402 if (reg_info)
403 {
404 if (reg_info->name)
405 m_location_str = reg_info->name;
406 else if (reg_info->alt_name)
407 m_location_str = reg_info->alt_name;
408 break;
409 }
410 }
411 m_location_str = "scalar";
412 break;
413
414 case Value::eValueTypeLoadAddress:
415 case Value::eValueTypeFileAddress:
416 case Value::eValueTypeHostAddress:
417 {
418 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
419 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
420 m_location_str.swap(sstr.GetString());
421 }
422 break;
423 }
424 }
425 }
426 return m_location_str.c_str();
427}
428
429Value &
430ValueObject::GetValue()
431{
432 return m_value;
433}
434
435const Value &
436ValueObject::GetValue() const
437{
438 return m_value;
439}
440
441bool
Jim Ingham6035b672011-03-31 00:19:25 +0000442ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000443{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000444 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
445 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000446 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000447 Value tmp_value(m_value);
448 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000449 if (scalar.IsValid())
450 {
451 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
452 if (bitfield_bit_size)
453 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
454 return true;
455 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000456 }
Greg Claytondcad5022011-12-29 01:26:56 +0000457 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000458}
459
460bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000461ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000462{
Greg Clayton288bdf92010-09-02 02:59:18 +0000463 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464}
465
466
467void
468ValueObject::SetValueIsValid (bool b)
469{
Greg Clayton288bdf92010-09-02 02:59:18 +0000470 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471}
472
473bool
Jim Ingham6035b672011-03-31 00:19:25 +0000474ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000475{
Jim Ingham6035b672011-03-31 00:19:25 +0000476 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000477 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000478}
479
480void
481ValueObject::SetValueDidChange (bool value_changed)
482{
Greg Clayton288bdf92010-09-02 02:59:18 +0000483 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484}
485
486ValueObjectSP
487ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
488{
489 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000490 // We may need to update our value if we are dynamic
491 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000492 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000493 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000494 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000495 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000496 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000497 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000498 // No we haven't created the child at this index, so lets have our
499 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000500 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000501 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000502
Enrico Granata9d60f602012-03-09 03:09:58 +0000503 ValueObject* child = m_children.GetChildAtIndex(idx);
504 if (child != NULL)
505 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000506 }
507 return child_sp;
508}
509
510uint32_t
511ValueObject::GetIndexOfChildWithName (const ConstString &name)
512{
513 bool omit_empty_base_classes = true;
514 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000515 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000516 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000517 omit_empty_base_classes);
518}
519
520ValueObjectSP
521ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
522{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000523 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524 // classes (which really aren't part of the expression path), so we
525 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000527
Greg Claytondea8cb42011-06-29 22:09:02 +0000528 // We may need to update our value if we are dynamic
529 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000530 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000531
532 std::vector<uint32_t> child_indexes;
533 clang::ASTContext *clang_ast = GetClangAST();
534 void *clang_type = GetClangType();
535 bool omit_empty_base_classes = true;
536 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
537 clang_type,
538 name.GetCString(),
539 omit_empty_base_classes,
540 child_indexes);
541 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000543 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
544 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
545
546 child_sp = GetChildAtIndex(*pos, can_create);
547 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000548 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000549 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000550 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000551 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
552 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000553 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000554 else
555 {
556 child_sp.reset();
557 }
558
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000559 }
560 }
561 return child_sp;
562}
563
564
565uint32_t
566ValueObject::GetNumChildren ()
567{
Greg Clayton288bdf92010-09-02 02:59:18 +0000568 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569 {
570 SetNumChildren (CalculateNumChildren());
571 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000572 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573}
574void
575ValueObject::SetNumChildren (uint32_t num_children)
576{
Greg Clayton288bdf92010-09-02 02:59:18 +0000577 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000578 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000579}
580
581void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000582ValueObject::SetName (const ConstString &name)
583{
584 m_name = name;
585}
586
Jim Ingham58b59f92011-04-22 23:53:53 +0000587ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000588ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
589{
Jim Ingham2eec4872011-05-07 00:10:58 +0000590 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000591
Greg Claytondea8cb42011-06-29 22:09:02 +0000592 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000593 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000594 std::string child_name_str;
595 uint32_t child_byte_size = 0;
596 int32_t child_byte_offset = 0;
597 uint32_t child_bitfield_bit_size = 0;
598 uint32_t child_bitfield_bit_offset = 0;
599 bool child_is_base_class = false;
600 bool child_is_deref_of_parent = false;
601
602 const bool transparent_pointers = synthetic_array_member == false;
603 clang::ASTContext *clang_ast = GetClangAST();
604 clang_type_t clang_type = GetClangType();
605 clang_type_t child_clang_type;
606
Greg Claytoncc4d0142012-02-17 07:49:44 +0000607 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000608
609 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
610 clang_ast,
611 GetName().GetCString(),
612 clang_type,
613 idx,
614 transparent_pointers,
615 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000616 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000617 child_name_str,
618 child_byte_size,
619 child_byte_offset,
620 child_bitfield_bit_size,
621 child_bitfield_bit_offset,
622 child_is_base_class,
623 child_is_deref_of_parent);
624 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000625 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000626 if (synthetic_index)
627 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000628
Greg Claytondea8cb42011-06-29 22:09:02 +0000629 ConstString child_name;
630 if (!child_name_str.empty())
631 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000632
Greg Claytondea8cb42011-06-29 22:09:02 +0000633 valobj = new ValueObjectChild (*this,
634 clang_ast,
635 child_clang_type,
636 child_name,
637 child_byte_size,
638 child_byte_offset,
639 child_bitfield_bit_size,
640 child_bitfield_bit_offset,
641 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000642 child_is_deref_of_parent,
643 eAddressTypeInvalid);
644 //if (valobj)
645 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
646 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000647
Jim Ingham58b59f92011-04-22 23:53:53 +0000648 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000649}
650
Enrico Granata0c489f52012-03-01 04:24:26 +0000651bool
652ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
653 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000654{
Enrico Granata0c489f52012-03-01 04:24:26 +0000655 destination.clear();
656
657 // ideally we would like to bail out if passing NULL, but if we do so
658 // we end up not providing the summary for function pointers anymore
659 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
660 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000661
662 m_is_getting_summary = true;
Enrico Granata0c489f52012-03-01 04:24:26 +0000663 if (UpdateValueIfNeeded (false))
664 {
665 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000666 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000667 summary_ptr->FormatObject(GetSP(), destination);
668 }
669 else
670 {
671 clang_type_t clang_type = GetClangType();
672
673 // Do some default printout for function pointers
674 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000675 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000676 StreamString sstr;
677 clang_type_t elem_or_pointee_clang_type;
678 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
679 GetClangAST(),
680 &elem_or_pointee_clang_type));
681
682 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000684 AddressType func_ptr_address_type = eAddressTypeInvalid;
685 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
686 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000687 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000688 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000689 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000690 case eAddressTypeInvalid:
691 case eAddressTypeFile:
692 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000693
Greg Claytoncc4d0142012-02-17 07:49:44 +0000694 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000695 {
696 ExecutionContext exe_ctx (GetExecutionContextRef());
697
698 Address so_addr;
699 Target *target = exe_ctx.GetTargetPtr();
700 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000701 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000702 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000703 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000704 so_addr.Dump (&sstr,
705 exe_ctx.GetBestExecutionContextScope(),
706 Address::DumpStyleResolvedDescription,
707 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000708 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000709 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000710 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000711 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000712
Greg Claytoncc4d0142012-02-17 07:49:44 +0000713 case eAddressTypeHost:
714 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000715 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000716 }
717 if (sstr.GetSize() > 0)
718 {
719 destination.assign (1, '(');
720 destination.append (sstr.GetData(), sstr.GetSize());
721 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000722 }
723 }
724 }
725 }
726 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000727 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000728 return !destination.empty();
729}
730
731const char *
732ValueObject::GetSummaryAsCString ()
733{
734 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
735 {
736 GetSummaryAsCString(GetSummaryFormat().get(),
737 m_summary_str);
738 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000739 if (m_summary_str.empty())
740 return NULL;
741 return m_summary_str.c_str();
742}
743
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000744bool
745ValueObject::IsCStringContainer(bool check_pointer)
746{
747 clang_type_t elem_or_pointee_clang_type;
748 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
749 GetClangAST(),
750 &elem_or_pointee_clang_type));
751 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
752 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
753 if (!is_char_arr_ptr)
754 return false;
755 if (!check_pointer)
756 return true;
757 if (type_flags.Test(ClangASTContext::eTypeIsArray))
758 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000759 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000760 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000761 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000762 return (cstr_address != LLDB_INVALID_ADDRESS);
763}
764
Enrico Granata9128ee22011-09-06 19:20:51 +0000765size_t
766ValueObject::GetPointeeData (DataExtractor& data,
767 uint32_t item_idx,
768 uint32_t item_count)
769{
770 if (!IsPointerType() && !IsArrayType())
771 return 0;
772
773 if (item_count == 0)
774 return 0;
775
776 uint32_t stride = 0;
777
778 ClangASTType type(GetClangAST(),
779 GetClangType());
780
781 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
782 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
783
784 const uint64_t bytes = item_count * item_type_size;
785
786 const uint64_t offset = item_idx * item_type_size;
787
788 if (item_idx == 0 && item_count == 1) // simply a deref
789 {
790 if (IsPointerType())
791 {
792 Error error;
793 ValueObjectSP pointee_sp = Dereference(error);
794 if (error.Fail() || pointee_sp.get() == NULL)
795 return 0;
796 return pointee_sp->GetDataExtractor().Copy(data);
797 }
798 else
799 {
800 ValueObjectSP child_sp = GetChildAtIndex(0, true);
801 if (child_sp.get() == NULL)
802 return 0;
803 return child_sp->GetDataExtractor().Copy(data);
804 }
805 return true;
806 }
807 else /* (items > 1) */
808 {
809 Error error;
810 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
811 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
812
813 AddressType addr_type;
814 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
815
Enrico Granata9128ee22011-09-06 19:20:51 +0000816 switch (addr_type)
817 {
818 case eAddressTypeFile:
819 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000820 ModuleSP module_sp (GetModule());
821 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000822 {
823 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000824 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000825 ExecutionContext exe_ctx (GetExecutionContextRef());
826 Target* target = exe_ctx.GetTargetPtr();
827 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000828 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000829 heap_buf_ptr->SetByteSize(bytes);
830 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
831 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000832 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000833 data.SetData(data_sp);
834 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000835 }
836 }
837 }
838 }
839 break;
840 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000841 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000842 ExecutionContext exe_ctx (GetExecutionContextRef());
843 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000844 if (process)
845 {
846 heap_buf_ptr->SetByteSize(bytes);
847 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
848 if (error.Success())
849 {
850 data.SetData(data_sp);
851 return bytes_read;
852 }
853 }
854 }
855 break;
856 case eAddressTypeHost:
857 {
858 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
859 data.SetData(data_sp);
860 return bytes;
861 }
862 break;
863 case eAddressTypeInvalid:
864 default:
865 break;
866 }
867 }
868 return 0;
869}
870
871size_t
872ValueObject::GetData (DataExtractor& data)
873{
874 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000875 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +0000876 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000877 if (error.Fail())
878 return 0;
879 data.SetAddressByteSize(m_data.GetAddressByteSize());
880 data.SetByteOrder(m_data.GetByteOrder());
881 return data.GetByteSize();
882}
883
884// will compute strlen(str), but without consuming more than
885// maxlen bytes out of str (this serves the purpose of reading
886// chunks of a string without having to worry about
887// missing NULL terminators in the chunk)
888// of course, if strlen(str) > maxlen, the function will return
889// maxlen_value (which should be != maxlen, because that allows you
890// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
891static uint32_t
892strlen_or_inf (const char* str,
893 uint32_t maxlen,
894 uint32_t maxlen_value)
895{
896 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000897 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000898 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000899 while(*str)
900 {
901 len++;str++;
902 if (len > maxlen)
903 return maxlen_value;
904 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000905 }
906 return len;
907}
908
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000909void
Greg Claytoncc4d0142012-02-17 07:49:44 +0000910ValueObject::ReadPointedString (Stream& s,
911 Error& error,
912 uint32_t max_length,
913 bool honor_array,
914 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000915{
Greg Claytoncc4d0142012-02-17 07:49:44 +0000916 ExecutionContext exe_ctx (GetExecutionContextRef());
917 Target* target = exe_ctx.GetTargetPtr();
918
919 if (target && max_length == 0)
920 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000921
922 clang_type_t clang_type = GetClangType();
923 clang_type_t elem_or_pointee_clang_type;
924 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
925 GetClangAST(),
926 &elem_or_pointee_clang_type));
927 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
928 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
929 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000930 if (target == NULL)
931 {
932 s << "<no target to read from>";
933 }
934 else
935 {
936 addr_t cstr_address = LLDB_INVALID_ADDRESS;
937 AddressType cstr_address_type = eAddressTypeInvalid;
938
939 size_t cstr_len = 0;
940 bool capped_data = false;
941 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000942 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000943 // We have an array
944 cstr_len = ClangASTContext::GetArraySize (clang_type);
945 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000946 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000947 capped_data = true;
948 cstr_len = max_length;
949 }
950 cstr_address = GetAddressOf (true, &cstr_address_type);
951 }
952 else
953 {
954 // We have a pointer
955 cstr_address = GetPointerValue (&cstr_address_type);
956 }
957 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
958 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000959 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000960 DataExtractor data;
961 size_t bytes_read = 0;
962 if (cstr_len > 0 && honor_array)
963 {
964 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
965 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
966 GetPointeeData(data, 0, cstr_len);
967
968 if ((bytes_read = data.GetByteSize()) > 0)
969 {
970 s << '"';
971 data.Dump (&s,
972 0, // Start offset in "data"
973 item_format,
974 1, // Size of item (1 byte for a char!)
975 bytes_read, // How many bytes to print?
976 UINT32_MAX, // num per line
977 LLDB_INVALID_ADDRESS,// base address
978 0, // bitfield bit size
979 0); // bitfield bit offset
980 if (capped_data)
981 s << "...";
982 s << '"';
983 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000984 }
985 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000986 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000987 cstr_len = max_length;
988 const size_t k_max_buf_size = 64;
989
990 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000991
Greg Claytoncc4d0142012-02-17 07:49:44 +0000992 int cstr_len_displayed = -1;
993 bool capped_cstr = false;
994 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
995 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
996 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000997 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000998 const char *cstr = data.PeekCStr(0);
999 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1000 if (len > k_max_buf_size)
1001 len = k_max_buf_size;
1002 if (cstr && cstr_len_displayed < 0)
1003 s << '"';
1004
1005 if (cstr_len_displayed < 0)
1006 cstr_len_displayed = len;
1007
1008 if (len == 0)
1009 break;
1010 cstr_len_displayed += len;
1011 if (len > bytes_read)
1012 len = bytes_read;
1013 if (len > cstr_len)
1014 len = cstr_len;
1015
1016 data.Dump (&s,
1017 0, // Start offset in "data"
1018 item_format,
1019 1, // Size of item (1 byte for a char!)
1020 len, // How many bytes to print?
1021 UINT32_MAX, // num per line
1022 LLDB_INVALID_ADDRESS,// base address
1023 0, // bitfield bit size
1024 0); // bitfield bit offset
1025
1026 if (len < k_max_buf_size)
1027 break;
1028
1029 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001030 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001031 capped_cstr = true;
1032 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001033 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001034
1035 cstr_len -= len;
1036 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001037 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001038
1039 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001040 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001041 s << '"';
1042 if (capped_cstr)
1043 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001044 }
1045 }
1046 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001047 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001048 }
1049 else
1050 {
1051 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001052 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001053 }
1054}
1055
Jim Ingham53c47f12010-09-10 23:12:17 +00001056const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001057ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001058{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001059
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001060 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001061 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001062
1063 if (!m_object_desc_str.empty())
1064 return m_object_desc_str.c_str();
1065
Greg Claytoncc4d0142012-02-17 07:49:44 +00001066 ExecutionContext exe_ctx (GetExecutionContextRef());
1067 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001068 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001069 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001070
Jim Ingham53c47f12010-09-10 23:12:17 +00001071 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001072
Greg Claytonafacd142011-09-02 01:15:17 +00001073 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001074 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1075
Jim Inghama2cf2632010-12-23 02:29:54 +00001076 if (runtime == NULL)
1077 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001078 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001079 clang_type_t opaque_qual_type = GetClangType();
1080 if (opaque_qual_type != NULL)
1081 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001082 bool is_signed;
1083 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1084 || ClangASTContext::IsPointerType (opaque_qual_type))
1085 {
Greg Claytonafacd142011-09-02 01:15:17 +00001086 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001087 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001088 }
1089 }
1090
Jim Ingham8d543de2011-03-31 23:01:21 +00001091 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001092 {
1093 m_object_desc_str.append (s.GetData());
1094 }
Sean Callanan672ad942010-10-23 00:18:49 +00001095
1096 if (m_object_desc_str.empty())
1097 return NULL;
1098 else
1099 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001100}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001101
Enrico Granata0c489f52012-03-01 04:24:26 +00001102bool
1103ValueObject::GetValueAsCString (lldb::Format format,
1104 std::string& destination)
1105{
1106 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1107 UpdateValueIfNeeded(false))
1108 {
1109 const Value::ContextType context_type = m_value.GetContextType();
1110
1111 switch (context_type)
1112 {
1113 case Value::eContextTypeClangType:
1114 case Value::eContextTypeLLDBType:
1115 case Value::eContextTypeVariable:
1116 {
1117 clang_type_t clang_type = GetClangType ();
1118 if (clang_type)
1119 {
1120 StreamString sstr;
1121 ExecutionContext exe_ctx (GetExecutionContextRef());
1122 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1123 clang_type, // The clang type to display
1124 &sstr,
1125 format, // Format to display this type with
1126 m_data, // Data to extract from
1127 0, // Byte offset into "m_data"
1128 GetByteSize(), // Byte size of item in "m_data"
1129 GetBitfieldBitSize(), // Bitfield bit size
1130 GetBitfieldBitOffset(), // Bitfield bit offset
1131 exe_ctx.GetBestExecutionContextScope());
1132 // Don't set the m_error to anything here otherwise
1133 // we won't be able to re-format as anything else. The
1134 // code for ClangASTType::DumpTypeValue() should always
1135 // return something, even if that something contains
1136 // an error messsage. "m_error" is used to detect errors
1137 // when reading the valid object, not for formatting errors.
1138 if (sstr.GetString().empty())
1139 destination.clear();
1140 else
1141 destination.swap(sstr.GetString());
1142 }
1143 }
1144 break;
1145
1146 case Value::eContextTypeRegisterInfo:
1147 {
1148 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1149 if (reg_info)
1150 {
1151 ExecutionContext exe_ctx (GetExecutionContextRef());
1152
1153 StreamString reg_sstr;
1154 m_data.Dump (&reg_sstr,
1155 0,
1156 format,
1157 reg_info->byte_size,
1158 1,
1159 UINT32_MAX,
1160 LLDB_INVALID_ADDRESS,
1161 0,
1162 0,
1163 exe_ctx.GetBestExecutionContextScope());
1164 destination.swap(reg_sstr.GetString());
1165 }
1166 }
1167 break;
1168
1169 default:
1170 break;
1171 }
1172 return !destination.empty();
1173 }
1174 else
1175 return false;
1176}
1177
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001178const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001179ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001180{
Enrico Granata0c489f52012-03-01 04:24:26 +00001181 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001182 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001183 lldb::Format my_format = GetFormat();
1184 if (m_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001185 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001186 if (m_type_format_sp)
1187 my_format = m_type_format_sp->GetFormat();
1188 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001189 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001190 if (m_is_bitfield_for_scalar)
1191 my_format = eFormatUnsigned;
1192 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001193 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001194 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001195 {
1196 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1197 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001198 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001199 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001200 else
1201 {
1202 clang_type_t clang_type = GetClangType ();
1203 my_format = ClangASTType::GetFormat(clang_type);
1204 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001205 }
1206 }
1207 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001208 if (GetValueAsCString(my_format, m_value_str))
1209 {
1210 if (!m_value_did_change && m_old_value_valid)
1211 {
1212 // The value was gotten successfully, so we consider the
1213 // value as changed if the value string differs
1214 SetValueDidChange (m_old_value_str != m_value_str);
1215 }
1216 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001217 }
1218 if (m_value_str.empty())
1219 return NULL;
1220 return m_value_str.c_str();
1221}
1222
Enrico Granatac3e320a2011-08-02 17:27:39 +00001223// if > 8bytes, 0 is returned. this method should mostly be used
1224// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001225uint64_t
1226ValueObject::GetValueAsUnsigned (uint64_t fail_value)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001227{
1228 // If our byte size is zero this is an aggregate type that has children
1229 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1230 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001231 Scalar scalar;
1232 if (ResolveValue (scalar))
1233 return scalar.GetRawBits64(fail_value);
Enrico Granatac3e320a2011-08-02 17:27:39 +00001234 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001235 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001236}
1237
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001238bool
1239ValueObject::GetPrintableRepresentation(Stream& s,
1240 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001241 Format custom_format)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001242{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001243
Greg Claytonafacd142011-09-02 01:15:17 +00001244 if (custom_format != eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001245 SetFormat(custom_format);
1246
1247 const char * return_value;
Enrico Granatacd1c0232011-08-04 23:37:18 +00001248 std::string alloc_mem;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001249
1250 switch(val_obj_display)
1251 {
1252 case eDisplayValue:
1253 return_value = GetValueAsCString();
1254 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001255
Enrico Granata0a3958e2011-07-02 00:25:22 +00001256 case eDisplaySummary:
Greg Clayton48ca8b82012-01-07 20:58:07 +00001257 return_value = GetSummaryAsCString();
1258 break;
1259
Enrico Granata0a3958e2011-07-02 00:25:22 +00001260 case eDisplayLanguageSpecific:
1261 return_value = GetObjectDescription();
1262 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001263
Enrico Granataf2bbf712011-07-15 02:26:42 +00001264 case eDisplayLocation:
1265 return_value = GetLocationAsCString();
1266 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001267
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001268 case eDisplayChildrenCount:
Greg Clayton48ca8b82012-01-07 20:58:07 +00001269 {
1270 alloc_mem.resize(512);
1271 return_value = &alloc_mem[0];
1272 int count = GetNumChildren();
1273 snprintf((char*)return_value, 512, "%d", count);
1274 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001275 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001276
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001277 case eDisplayType:
1278 return_value = GetTypeName().AsCString();
1279 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001280
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001281 default:
1282 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001283 }
1284
Enrico Granata855cd902011-09-06 22:59:55 +00001285 if (!return_value)
Enrico Granata9fc19442011-07-06 02:13:41 +00001286 {
Enrico Granata9fc19442011-07-06 02:13:41 +00001287 if (val_obj_display == eDisplayValue)
Enrico Granata855cd902011-09-06 22:59:55 +00001288 return_value = GetSummaryAsCString();
Enrico Granata9fc19442011-07-06 02:13:41 +00001289 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +00001290 {
1291 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1292 {
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001293 // this thing has no value, and it seems to have no summary
1294 // some combination of unitialized data and other factors can also
Enrico Granata855cd902011-09-06 22:59:55 +00001295 // raise this condition, so let's print a nice generic description
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001296 {
1297 alloc_mem.resize(684);
1298 return_value = &alloc_mem[0];
1299 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1300 }
Enrico Granatae992a082011-07-22 17:03:19 +00001301 }
1302 else
1303 return_value = GetValueAsCString();
1304 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001305 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001306
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001307 if (return_value)
1308 s.PutCString(return_value);
1309 else
Enrico Granata88da35f2011-08-23 21:26:09 +00001310 {
1311 if (m_error.Fail())
1312 s.Printf("<%s>", m_error.AsCString());
1313 else if (val_obj_display == eDisplaySummary)
1314 s.PutCString("<no summary available>");
1315 else if (val_obj_display == eDisplayValue)
1316 s.PutCString("<no value available>");
1317 else if (val_obj_display == eDisplayLanguageSpecific)
1318 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1319 else
1320 s.PutCString("<no printable representation>");
1321 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001322
1323 // we should only return false here if we could not do *anything*
1324 // even if we have an error message as output, that's a success
1325 // from our callers' perspective, so return true
1326 return true;
1327
Enrico Granata0a3958e2011-07-02 00:25:22 +00001328}
1329
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001330// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1331// this call up to date by returning true for your new special cases. We will eventually move
1332// to checking this call result before trying to display special cases
1333bool
1334ValueObject::HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001335 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001336{
1337 clang_type_t elem_or_pointee_type;
1338 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1339
1340 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1341 && val_obj_display == ValueObject::eDisplayValue)
1342 {
1343 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001344 (custom_format == eFormatCString ||
1345 custom_format == eFormatCharArray ||
1346 custom_format == eFormatChar ||
1347 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001348 return true;
1349
1350 if (flags.Test(ClangASTContext::eTypeIsArray))
1351 {
Greg Claytonafacd142011-09-02 01:15:17 +00001352 if ((custom_format == eFormatBytes) ||
1353 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001354 return true;
1355
Greg Claytonafacd142011-09-02 01:15:17 +00001356 if ((custom_format == eFormatVectorOfChar) ||
1357 (custom_format == eFormatVectorOfFloat32) ||
1358 (custom_format == eFormatVectorOfFloat64) ||
1359 (custom_format == eFormatVectorOfSInt16) ||
1360 (custom_format == eFormatVectorOfSInt32) ||
1361 (custom_format == eFormatVectorOfSInt64) ||
1362 (custom_format == eFormatVectorOfSInt8) ||
1363 (custom_format == eFormatVectorOfUInt128) ||
1364 (custom_format == eFormatVectorOfUInt16) ||
1365 (custom_format == eFormatVectorOfUInt32) ||
1366 (custom_format == eFormatVectorOfUInt64) ||
1367 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001368 return true;
1369 }
1370 }
1371 return false;
1372}
1373
Enrico Granata9fc19442011-07-06 02:13:41 +00001374bool
1375ValueObject::DumpPrintableRepresentation(Stream& s,
1376 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001377 Format custom_format,
Enrico Granata85933ed2011-08-18 16:38:26 +00001378 bool only_special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001379{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001380
1381 clang_type_t elem_or_pointee_type;
1382 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001383
Enrico Granataf4efecd2011-07-12 22:56:10 +00001384 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1385 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001386 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001387 // when being asked to get a printable display an array or pointer type directly,
1388 // try to "do the right thing"
1389
1390 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001391 (custom_format == eFormatCString ||
1392 custom_format == eFormatCharArray ||
1393 custom_format == eFormatChar ||
1394 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001395 {
1396 Error error;
1397 ReadPointedString(s,
1398 error,
1399 0,
Greg Claytonafacd142011-09-02 01:15:17 +00001400 (custom_format == eFormatVectorOfChar) ||
1401 (custom_format == eFormatCharArray));
Enrico Granataf4efecd2011-07-12 22:56:10 +00001402 return !error.Fail();
1403 }
1404
Greg Claytonafacd142011-09-02 01:15:17 +00001405 if (custom_format == eFormatEnum)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001406 return false;
1407
1408 // this only works for arrays, because I have no way to know when
1409 // the pointed memory ends, and no special \0 end of data marker
1410 if (flags.Test(ClangASTContext::eTypeIsArray))
1411 {
Greg Claytonafacd142011-09-02 01:15:17 +00001412 if ((custom_format == eFormatBytes) ||
1413 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001414 {
1415 uint32_t count = GetNumChildren();
1416
1417 s << '[';
1418 for (uint32_t low = 0; low < count; low++)
1419 {
1420
1421 if (low)
1422 s << ',';
1423
1424 ValueObjectSP child = GetChildAtIndex(low,true);
1425 if (!child.get())
1426 {
Enrico Granatae992a082011-07-22 17:03:19 +00001427 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001428 continue;
1429 }
1430 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1431 }
1432
1433 s << ']';
1434
1435 return true;
1436 }
1437
Greg Claytonafacd142011-09-02 01:15:17 +00001438 if ((custom_format == eFormatVectorOfChar) ||
1439 (custom_format == eFormatVectorOfFloat32) ||
1440 (custom_format == eFormatVectorOfFloat64) ||
1441 (custom_format == eFormatVectorOfSInt16) ||
1442 (custom_format == eFormatVectorOfSInt32) ||
1443 (custom_format == eFormatVectorOfSInt64) ||
1444 (custom_format == eFormatVectorOfSInt8) ||
1445 (custom_format == eFormatVectorOfUInt128) ||
1446 (custom_format == eFormatVectorOfUInt16) ||
1447 (custom_format == eFormatVectorOfUInt32) ||
1448 (custom_format == eFormatVectorOfUInt64) ||
1449 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001450 {
1451 uint32_t count = GetNumChildren();
1452
Greg Claytonafacd142011-09-02 01:15:17 +00001453 Format format = FormatManager::GetSingleItemFormat(custom_format);
Enrico Granataf4efecd2011-07-12 22:56:10 +00001454
1455 s << '[';
1456 for (uint32_t low = 0; low < count; low++)
1457 {
1458
1459 if (low)
1460 s << ',';
1461
1462 ValueObjectSP child = GetChildAtIndex(low,true);
1463 if (!child.get())
1464 {
Enrico Granatae992a082011-07-22 17:03:19 +00001465 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001466 continue;
1467 }
1468 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1469 }
1470
1471 s << ']';
1472
1473 return true;
1474 }
1475 }
1476
Greg Claytonafacd142011-09-02 01:15:17 +00001477 if ((custom_format == eFormatBoolean) ||
1478 (custom_format == eFormatBinary) ||
1479 (custom_format == eFormatChar) ||
1480 (custom_format == eFormatCharPrintable) ||
1481 (custom_format == eFormatComplexFloat) ||
1482 (custom_format == eFormatDecimal) ||
1483 (custom_format == eFormatHex) ||
1484 (custom_format == eFormatFloat) ||
1485 (custom_format == eFormatOctal) ||
1486 (custom_format == eFormatOSType) ||
1487 (custom_format == eFormatUnicode16) ||
1488 (custom_format == eFormatUnicode32) ||
1489 (custom_format == eFormatUnsigned) ||
1490 (custom_format == eFormatPointer) ||
1491 (custom_format == eFormatComplexInteger) ||
1492 (custom_format == eFormatComplex) ||
1493 (custom_format == eFormatDefault)) // use the [] operator
Enrico Granataf4efecd2011-07-12 22:56:10 +00001494 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001495 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001496
1497 if (only_special)
1498 return false;
1499
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001500 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001501 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001502 SetFormat(eFormatDefault);
1503 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001504}
1505
Greg Clayton737b9322010-09-13 03:32:57 +00001506addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001507ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001508{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001509 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001510 return LLDB_INVALID_ADDRESS;
1511
Greg Clayton73b472d2010-10-27 03:32:59 +00001512 switch (m_value.GetValueType())
1513 {
1514 case Value::eValueTypeScalar:
1515 if (scalar_is_load_address)
1516 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001517 if(address_type)
1518 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001519 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1520 }
1521 break;
1522
1523 case Value::eValueTypeLoadAddress:
1524 case Value::eValueTypeFileAddress:
1525 case Value::eValueTypeHostAddress:
1526 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001527 if(address_type)
1528 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001529 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1530 }
1531 break;
1532 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001533 if (address_type)
1534 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001535 return LLDB_INVALID_ADDRESS;
1536}
1537
1538addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001539ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001540{
Greg Claytonafacd142011-09-02 01:15:17 +00001541 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001542 if(address_type)
1543 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001544
Enrico Granatac3e320a2011-08-02 17:27:39 +00001545 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001546 return address;
1547
Greg Clayton73b472d2010-10-27 03:32:59 +00001548 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001549 {
1550 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001551 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001552 break;
1553
Enrico Granata9128ee22011-09-06 19:20:51 +00001554 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001555 case Value::eValueTypeLoadAddress:
1556 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001557 {
1558 uint32_t data_offset = 0;
1559 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001560 }
1561 break;
1562 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001563
Enrico Granata9128ee22011-09-06 19:20:51 +00001564 if (address_type)
1565 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001566
Greg Clayton737b9322010-09-13 03:32:57 +00001567 return address;
1568}
1569
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001570bool
Jim Ingham6035b672011-03-31 00:19:25 +00001571ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001572{
1573 // Make sure our value is up to date first so that our location and location
1574 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001575 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001576 return false;
1577
1578 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001579 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001580
Greg Claytonb1320972010-07-14 00:18:15 +00001581 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001582
Jim Ingham16e0c682011-08-12 23:34:31 +00001583 Value::ValueType value_type = m_value.GetValueType();
1584
1585 if (value_type == Value::eValueTypeScalar)
1586 {
1587 // If the value is already a scalar, then let the scalar change itself:
1588 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1589 }
1590 else if (byte_size <= Scalar::GetMaxByteSize())
1591 {
1592 // If the value fits in a scalar, then make a new scalar and again let the
1593 // scalar code do the conversion, then figure out where to put the new value.
1594 Scalar new_scalar;
1595 Error error;
1596 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1597 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001598 {
Jim Ingham4b536182011-08-09 02:12:22 +00001599 switch (value_type)
1600 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001601 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001602 {
1603 // If it is a load address, then the scalar value is the storage location
1604 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001605 ExecutionContext exe_ctx (GetExecutionContextRef());
1606 Process *process = exe_ctx.GetProcessPtr();
1607 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001608 {
Greg Claytonafacd142011-09-02 01:15:17 +00001609 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001610 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1611 new_scalar,
1612 byte_size,
1613 error);
Jim Ingham16e0c682011-08-12 23:34:31 +00001614 if (!error.Success() || bytes_written != byte_size)
1615 return false;
1616 }
1617 }
Jim Ingham4b536182011-08-09 02:12:22 +00001618 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001619 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001620 {
1621 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1622 DataExtractor new_data;
1623 new_data.SetByteOrder (m_data.GetByteOrder());
1624
1625 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1626 m_data.SetData(buffer_sp, 0);
1627 bool success = new_scalar.GetData(new_data);
1628 if (success)
1629 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001630 new_data.CopyByteOrderedData (0,
1631 byte_size,
1632 const_cast<uint8_t *>(m_data.GetDataStart()),
1633 byte_size,
1634 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001635 }
1636 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1637
1638 }
Jim Ingham4b536182011-08-09 02:12:22 +00001639 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001640 case Value::eValueTypeFileAddress:
1641 case Value::eValueTypeScalar:
Jim Ingham16e0c682011-08-12 23:34:31 +00001642 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001643 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001644 }
1645 else
1646 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001647 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001648 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001649 }
1650 else
1651 {
1652 // We don't support setting things bigger than a scalar at present.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001653 return false;
1654 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001655
1656 // If we have reached this point, then we have successfully changed the value.
1657 SetNeedsUpdate();
1658 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001659}
1660
Greg Clayton81e871e2012-02-04 02:27:34 +00001661bool
1662ValueObject::GetDeclaration (Declaration &decl)
1663{
1664 decl.Clear();
1665 return false;
1666}
1667
Greg Claytonafacd142011-09-02 01:15:17 +00001668LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001669ValueObject::GetObjectRuntimeLanguage ()
1670{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001671 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1672 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001673}
1674
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001675void
Jim Ingham58b59f92011-04-22 23:53:53 +00001676ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001677{
Jim Ingham58b59f92011-04-22 23:53:53 +00001678 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001679}
1680
1681ValueObjectSP
1682ValueObject::GetSyntheticChild (const ConstString &key) const
1683{
1684 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001685 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001686 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001687 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001688 return synthetic_child_sp;
1689}
1690
1691bool
1692ValueObject::IsPointerType ()
1693{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001694 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001695}
1696
Jim Inghamb7603bb2011-03-18 00:05:18 +00001697bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001698ValueObject::IsArrayType ()
1699{
1700 return ClangASTContext::IsArrayType (GetClangType());
1701}
1702
1703bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001704ValueObject::IsScalarType ()
1705{
1706 return ClangASTContext::IsScalarType (GetClangType());
1707}
1708
1709bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001710ValueObject::IsIntegerType (bool &is_signed)
1711{
1712 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1713}
Greg Clayton73b472d2010-10-27 03:32:59 +00001714
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001715bool
1716ValueObject::IsPointerOrReferenceType ()
1717{
Greg Clayton007d5be2011-05-30 00:49:24 +00001718 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1719}
1720
1721bool
1722ValueObject::IsPossibleCPlusPlusDynamicType ()
1723{
1724 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001725}
1726
Greg Claytondea8cb42011-06-29 22:09:02 +00001727bool
1728ValueObject::IsPossibleDynamicType ()
1729{
1730 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1731}
1732
Greg Claytonafacd142011-09-02 01:15:17 +00001733ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001734ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1735{
1736 if (IsArrayType())
1737 return GetSyntheticArrayMemberFromArray(index, can_create);
1738
1739 if (IsPointerType())
1740 return GetSyntheticArrayMemberFromPointer(index, can_create);
1741
1742 return ValueObjectSP();
1743
1744}
1745
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001746ValueObjectSP
1747ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1748{
1749 ValueObjectSP synthetic_child_sp;
1750 if (IsPointerType ())
1751 {
1752 char index_str[64];
1753 snprintf(index_str, sizeof(index_str), "[%i]", index);
1754 ConstString index_const_str(index_str);
1755 // Check if we have already created a synthetic array member in this
1756 // valid object. If we have we will re-use it.
1757 synthetic_child_sp = GetSyntheticChild (index_const_str);
1758 if (!synthetic_child_sp)
1759 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001760 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001761 // We haven't made a synthetic array member for INDEX yet, so
1762 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001763 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001764
1765 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001766 if (synthetic_child)
1767 {
1768 AddSyntheticChild(index_const_str, synthetic_child);
1769 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001770 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001771 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001772 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001773 }
1774 }
1775 return synthetic_child_sp;
1776}
Jim Ingham22777012010-09-23 02:01:19 +00001777
Greg Claytondaf515f2011-07-09 20:12:33 +00001778// This allows you to create an array member using and index
1779// that doesn't not fall in the normal bounds of the array.
1780// Many times structure can be defined as:
1781// struct Collection
1782// {
1783// uint32_t item_count;
1784// Item item_array[0];
1785// };
1786// The size of the "item_array" is 1, but many times in practice
1787// there are more items in "item_array".
1788
1789ValueObjectSP
1790ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1791{
1792 ValueObjectSP synthetic_child_sp;
1793 if (IsArrayType ())
1794 {
1795 char index_str[64];
1796 snprintf(index_str, sizeof(index_str), "[%i]", index);
1797 ConstString index_const_str(index_str);
1798 // Check if we have already created a synthetic array member in this
1799 // valid object. If we have we will re-use it.
1800 synthetic_child_sp = GetSyntheticChild (index_const_str);
1801 if (!synthetic_child_sp)
1802 {
1803 ValueObject *synthetic_child;
1804 // We haven't made a synthetic array member for INDEX yet, so
1805 // lets make one and cache it for any future reference.
1806 synthetic_child = CreateChildAtIndex(0, true, index);
1807
1808 // Cache the value if we got one back...
1809 if (synthetic_child)
1810 {
1811 AddSyntheticChild(index_const_str, synthetic_child);
1812 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001813 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001814 synthetic_child_sp->m_is_array_item_for_pointer = true;
1815 }
1816 }
1817 }
1818 return synthetic_child_sp;
1819}
1820
Enrico Granata9fc19442011-07-06 02:13:41 +00001821ValueObjectSP
1822ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1823{
1824 ValueObjectSP synthetic_child_sp;
1825 if (IsScalarType ())
1826 {
1827 char index_str[64];
1828 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1829 ConstString index_const_str(index_str);
1830 // Check if we have already created a synthetic array member in this
1831 // valid object. If we have we will re-use it.
1832 synthetic_child_sp = GetSyntheticChild (index_const_str);
1833 if (!synthetic_child_sp)
1834 {
1835 ValueObjectChild *synthetic_child;
1836 // We haven't made a synthetic array member for INDEX yet, so
1837 // lets make one and cache it for any future reference.
1838 synthetic_child = new ValueObjectChild(*this,
1839 GetClangAST(),
1840 GetClangType(),
1841 index_const_str,
1842 GetByteSize(),
1843 0,
1844 to-from+1,
1845 from,
1846 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001847 false,
1848 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001849
1850 // Cache the value if we got one back...
1851 if (synthetic_child)
1852 {
1853 AddSyntheticChild(index_const_str, synthetic_child);
1854 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001855 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001856 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1857 }
1858 }
1859 }
1860 return synthetic_child_sp;
1861}
1862
Greg Claytonafacd142011-09-02 01:15:17 +00001863ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001864ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1865{
1866 ValueObjectSP synthetic_child_sp;
1867 if (IsArrayType () || IsPointerType ())
1868 {
1869 char index_str[64];
1870 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1871 ConstString index_const_str(index_str);
1872 // Check if we have already created a synthetic array member in this
1873 // valid object. If we have we will re-use it.
1874 synthetic_child_sp = GetSyntheticChild (index_const_str);
1875 if (!synthetic_child_sp)
1876 {
1877 ValueObjectSynthetic *synthetic_child;
1878
1879 // We haven't made a synthetic array member for INDEX yet, so
1880 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001881 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001882 view->AddRange(from,to);
1883 SyntheticChildrenSP view_sp(view);
1884 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1885
1886 // Cache the value if we got one back...
1887 if (synthetic_child)
1888 {
1889 AddSyntheticChild(index_const_str, synthetic_child);
1890 synthetic_child_sp = synthetic_child->GetSP();
1891 synthetic_child_sp->SetName(ConstString(index_str));
1892 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1893 }
1894 }
1895 }
1896 return synthetic_child_sp;
1897}
1898
Greg Claytonafacd142011-09-02 01:15:17 +00001899ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001900ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1901{
1902
1903 ValueObjectSP synthetic_child_sp;
1904
1905 char name_str[64];
1906 snprintf(name_str, sizeof(name_str), "@%i", offset);
1907 ConstString name_const_str(name_str);
1908
1909 // Check if we have already created a synthetic array member in this
1910 // valid object. If we have we will re-use it.
1911 synthetic_child_sp = GetSyntheticChild (name_const_str);
1912
1913 if (synthetic_child_sp.get())
1914 return synthetic_child_sp;
1915
1916 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001917 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001918
1919 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1920 type.GetASTContext(),
1921 type.GetOpaqueQualType(),
1922 name_const_str,
1923 type.GetTypeByteSize(),
1924 offset,
1925 0,
1926 0,
1927 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001928 false,
1929 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001930 if (synthetic_child)
1931 {
1932 AddSyntheticChild(name_const_str, synthetic_child);
1933 synthetic_child_sp = synthetic_child->GetSP();
1934 synthetic_child_sp->SetName(name_const_str);
1935 synthetic_child_sp->m_is_child_at_offset = true;
1936 }
1937 return synthetic_child_sp;
1938}
1939
Enrico Granatad55546b2011-07-22 00:16:08 +00001940// your expression path needs to have a leading . or ->
1941// (unless it somehow "looks like" an array, in which case it has
1942// a leading [ symbol). while the [ is meaningful and should be shown
1943// to the user, . and -> are just parser design, but by no means
1944// added information for the user.. strip them off
1945static const char*
1946SkipLeadingExpressionPathSeparators(const char* expression)
1947{
1948 if (!expression || !expression[0])
1949 return expression;
1950 if (expression[0] == '.')
1951 return expression+1;
1952 if (expression[0] == '-' && expression[1] == '>')
1953 return expression+2;
1954 return expression;
1955}
1956
Greg Claytonafacd142011-09-02 01:15:17 +00001957ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00001958ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1959{
1960 ValueObjectSP synthetic_child_sp;
1961 ConstString name_const_string(expression);
1962 // Check if we have already created a synthetic array member in this
1963 // valid object. If we have we will re-use it.
1964 synthetic_child_sp = GetSyntheticChild (name_const_string);
1965 if (!synthetic_child_sp)
1966 {
1967 // We haven't made a synthetic array member for expression yet, so
1968 // lets make one and cache it for any future reference.
1969 synthetic_child_sp = GetValueForExpressionPath(expression);
1970
1971 // Cache the value if we got one back...
1972 if (synthetic_child_sp.get())
1973 {
1974 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001975 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001976 synthetic_child_sp->m_is_expression_path_child = true;
1977 }
1978 }
1979 return synthetic_child_sp;
1980}
1981
1982void
Greg Claytonafacd142011-09-02 01:15:17 +00001983ValueObject::CalculateSyntheticValue (SyntheticValueType use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00001984{
Greg Claytonafacd142011-09-02 01:15:17 +00001985 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001986 return;
1987
Enrico Granatac3e320a2011-08-02 17:27:39 +00001988 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001989
Enrico Granata0c489f52012-03-01 04:24:26 +00001990 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00001991 return;
1992
Enrico Granataa37a0652011-07-24 00:14:56 +00001993 if (m_synthetic_value == NULL)
Enrico Granata0c489f52012-03-01 04:24:26 +00001994 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00001995
1996}
1997
Jim Ingham78a685a2011-04-16 00:01:13 +00001998void
Greg Claytonafacd142011-09-02 01:15:17 +00001999ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002000{
Greg Claytonafacd142011-09-02 01:15:17 +00002001 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002002 return;
2003
Jim Ingham58b59f92011-04-22 23:53:53 +00002004 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002005 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002006 ExecutionContext exe_ctx (GetExecutionContextRef());
2007 Process *process = exe_ctx.GetProcessPtr();
2008 if (process)
Jim Ingham78a685a2011-04-16 00:01:13 +00002009 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002010 bool worth_having_dynamic_value = false;
Jim Ingham78a685a2011-04-16 00:01:13 +00002011
Greg Claytoncc4d0142012-02-17 07:49:44 +00002012
2013 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
2014 // hard code this everywhere.
2015 LanguageType known_type = GetObjectRuntimeLanguage();
2016 if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
Jim Ingham78a685a2011-04-16 00:01:13 +00002017 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002018 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
2019 if (runtime)
2020 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00002021 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00002022 else
2023 {
2024 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus);
2025 if (cpp_runtime)
2026 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
2027
2028 if (!worth_having_dynamic_value)
2029 {
2030 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC);
2031 if (objc_runtime)
2032 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
2033 }
2034 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002035
Greg Claytoncc4d0142012-02-17 07:49:44 +00002036 if (worth_having_dynamic_value)
2037 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
2038 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002039 }
2040}
2041
Jim Ingham58b59f92011-04-22 23:53:53 +00002042ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002043ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002044{
Greg Claytonafacd142011-09-02 01:15:17 +00002045 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002046 return ValueObjectSP();
2047
2048 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002049 {
Jim Ingham2837b762011-05-04 03:43:18 +00002050 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002051 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002052 if (m_dynamic_value)
2053 return m_dynamic_value->GetSP();
2054 else
2055 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002056}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002057
Jim Ingham60dbabb2011-12-08 19:44:08 +00002058ValueObjectSP
2059ValueObject::GetStaticValue()
2060{
2061 return GetSP();
2062}
2063
Enrico Granatad55546b2011-07-22 00:16:08 +00002064// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
2065// or we do not really want a dynamic VO. this method instead returns this object
2066// itself when making it synthetic has no meaning. this makes it much simpler
2067// to replace the SyntheticValue for the ValueObject
2068ValueObjectSP
2069ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
2070{
Greg Claytonafacd142011-09-02 01:15:17 +00002071 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00002072 return GetSP();
2073
Enrico Granatac3e320a2011-08-02 17:27:39 +00002074 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00002075
Enrico Granata0c489f52012-03-01 04:24:26 +00002076 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002077 return GetSP();
2078
2079 CalculateSyntheticValue(use_synthetic);
2080
2081 if (m_synthetic_value)
2082 return m_synthetic_value->GetSP();
2083 else
2084 return GetSP();
2085}
2086
Greg Claytone221f822011-01-21 01:59:00 +00002087bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002088ValueObject::HasSyntheticValue()
2089{
2090 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2091
Enrico Granata0c489f52012-03-01 04:24:26 +00002092 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002093 return false;
2094
Greg Claytonafacd142011-09-02 01:15:17 +00002095 CalculateSyntheticValue(eUseSyntheticFilter);
Enrico Granata27b625e2011-08-09 01:04:56 +00002096
2097 if (m_synthetic_value)
2098 return true;
2099 else
2100 return false;
2101}
2102
2103bool
Greg Claytone221f822011-01-21 01:59:00 +00002104ValueObject::GetBaseClassPath (Stream &s)
2105{
2106 if (IsBaseClass())
2107 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002108 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002109 clang_type_t clang_type = GetClangType();
2110 std::string cxx_class_name;
2111 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2112 if (this_had_base_class)
2113 {
2114 if (parent_had_base_class)
2115 s.PutCString("::");
2116 s.PutCString(cxx_class_name.c_str());
2117 }
2118 return parent_had_base_class || this_had_base_class;
2119 }
2120 return false;
2121}
2122
2123
2124ValueObject *
2125ValueObject::GetNonBaseClassParent()
2126{
Jim Ingham78a685a2011-04-16 00:01:13 +00002127 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002128 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002129 if (GetParent()->IsBaseClass())
2130 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002131 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002132 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002133 }
2134 return NULL;
2135}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002136
2137void
Enrico Granata4becb372011-06-29 22:27:15 +00002138ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002139{
Greg Claytone221f822011-01-21 01:59:00 +00002140 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002141
Enrico Granata85933ed2011-08-18 16:38:26 +00002142 if (is_deref_of_parent && epformat == eDereferencePointers)
2143 {
Enrico Granata4becb372011-06-29 22:27:15 +00002144 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2145 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2146 // the eHonorPointers mode is meant to produce strings in this latter format
2147 s.PutCString("*(");
2148 }
Greg Claytone221f822011-01-21 01:59:00 +00002149
Enrico Granata4becb372011-06-29 22:27:15 +00002150 ValueObject* parent = GetParent();
2151
2152 if (parent)
2153 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002154
2155 // if we are a deref_of_parent just because we are synthetic array
2156 // members made up to allow ptr[%d] syntax to work in variable
2157 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00002158 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002159 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002160
Greg Claytone221f822011-01-21 01:59:00 +00002161 if (!IsBaseClass())
2162 {
2163 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002164 {
Greg Claytone221f822011-01-21 01:59:00 +00002165 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2166 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002167 {
Greg Claytone221f822011-01-21 01:59:00 +00002168 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2169 if (non_base_class_parent_clang_type)
2170 {
2171 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2172
Enrico Granata9dd75c82011-07-15 23:30:15 +00002173 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002174 {
2175 s.PutCString("->");
2176 }
Enrico Granata4becb372011-06-29 22:27:15 +00002177 else
2178 {
2179 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2180 {
2181 s.PutCString("->");
2182 }
2183 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2184 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2185 {
2186 s.PutChar('.');
2187 }
Greg Claytone221f822011-01-21 01:59:00 +00002188 }
2189 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002190 }
Greg Claytone221f822011-01-21 01:59:00 +00002191
2192 const char *name = GetName().GetCString();
2193 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002194 {
Greg Claytone221f822011-01-21 01:59:00 +00002195 if (qualify_cxx_base_classes)
2196 {
2197 if (GetBaseClassPath (s))
2198 s.PutCString("::");
2199 }
2200 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002201 }
2202 }
2203 }
2204
Enrico Granata85933ed2011-08-18 16:38:26 +00002205 if (is_deref_of_parent && epformat == eDereferencePointers)
2206 {
Greg Claytone221f822011-01-21 01:59:00 +00002207 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002208 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002209}
2210
Greg Claytonafacd142011-09-02 01:15:17 +00002211ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002212ValueObject::GetValueForExpressionPath(const char* expression,
2213 const char** first_unparsed,
2214 ExpressionPathScanEndReason* reason_to_stop,
2215 ExpressionPathEndResultType* final_value_type,
2216 const GetValueForExpressionPathOptions& options,
2217 ExpressionPathAftermath* final_task_on_target)
2218{
2219
2220 const char* dummy_first_unparsed;
2221 ExpressionPathScanEndReason dummy_reason_to_stop;
2222 ExpressionPathEndResultType dummy_final_value_type;
2223 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2224
2225 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2226 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2227 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2228 final_value_type ? final_value_type : &dummy_final_value_type,
2229 options,
2230 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2231
2232 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002233 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002234
2235 if (ret_val.get() && ((final_value_type ? *final_value_type : dummy_final_value_type) == ePlain)) // I can only deref and takeaddress of plain objects
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002236 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002237 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002238 {
2239 Error error;
2240 ValueObjectSP final_value = ret_val->Dereference(error);
2241 if (error.Fail() || !final_value.get())
2242 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002243 if (reason_to_stop)
2244 *reason_to_stop = ValueObject::eDereferencingFailed;
2245 if (final_value_type)
2246 *final_value_type = ValueObject::eInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002247 return ValueObjectSP();
2248 }
2249 else
2250 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002251 if (final_task_on_target)
2252 *final_task_on_target = ValueObject::eNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002253 return final_value;
2254 }
2255 }
2256 if (*final_task_on_target == ValueObject::eTakeAddress)
2257 {
2258 Error error;
2259 ValueObjectSP final_value = ret_val->AddressOf(error);
2260 if (error.Fail() || !final_value.get())
2261 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002262 if (reason_to_stop)
2263 *reason_to_stop = ValueObject::eTakingAddressFailed;
2264 if (final_value_type)
2265 *final_value_type = ValueObject::eInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002266 return ValueObjectSP();
2267 }
2268 else
2269 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002270 if (final_task_on_target)
2271 *final_task_on_target = ValueObject::eNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002272 return final_value;
2273 }
2274 }
2275 }
2276 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2277}
2278
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002279int
2280ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002281 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002282 const char** first_unparsed,
2283 ExpressionPathScanEndReason* reason_to_stop,
2284 ExpressionPathEndResultType* final_value_type,
2285 const GetValueForExpressionPathOptions& options,
2286 ExpressionPathAftermath* final_task_on_target)
2287{
2288 const char* dummy_first_unparsed;
2289 ExpressionPathScanEndReason dummy_reason_to_stop;
2290 ExpressionPathEndResultType dummy_final_value_type;
2291 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2292
2293 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2294 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2295 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2296 final_value_type ? final_value_type : &dummy_final_value_type,
2297 options,
2298 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2299
2300 if (!ret_val.get()) // if there are errors, I add nothing to the list
2301 return 0;
2302
2303 if (*reason_to_stop != eArrayRangeOperatorMet)
2304 {
2305 // I need not expand a range, just post-process the final value and return
2306 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2307 {
2308 list->Append(ret_val);
2309 return 1;
2310 }
2311 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2312 {
2313 if (*final_task_on_target == ValueObject::eDereference)
2314 {
2315 Error error;
2316 ValueObjectSP final_value = ret_val->Dereference(error);
2317 if (error.Fail() || !final_value.get())
2318 {
2319 *reason_to_stop = ValueObject::eDereferencingFailed;
2320 *final_value_type = ValueObject::eInvalid;
2321 return 0;
2322 }
2323 else
2324 {
2325 *final_task_on_target = ValueObject::eNothing;
2326 list->Append(final_value);
2327 return 1;
2328 }
2329 }
2330 if (*final_task_on_target == ValueObject::eTakeAddress)
2331 {
2332 Error error;
2333 ValueObjectSP final_value = ret_val->AddressOf(error);
2334 if (error.Fail() || !final_value.get())
2335 {
2336 *reason_to_stop = ValueObject::eTakingAddressFailed;
2337 *final_value_type = ValueObject::eInvalid;
2338 return 0;
2339 }
2340 else
2341 {
2342 *final_task_on_target = ValueObject::eNothing;
2343 list->Append(final_value);
2344 return 1;
2345 }
2346 }
2347 }
2348 }
2349 else
2350 {
2351 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2352 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2353 ret_val,
2354 list,
2355 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2356 final_value_type ? final_value_type : &dummy_final_value_type,
2357 options,
2358 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2359 }
2360 // in any non-covered case, just do the obviously right thing
2361 list->Append(ret_val);
2362 return 1;
2363}
2364
Greg Claytonafacd142011-09-02 01:15:17 +00002365ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002366ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2367 const char** first_unparsed,
2368 ExpressionPathScanEndReason* reason_to_stop,
2369 ExpressionPathEndResultType* final_result,
2370 const GetValueForExpressionPathOptions& options,
2371 ExpressionPathAftermath* what_next)
2372{
2373 ValueObjectSP root = GetSP();
2374
2375 if (!root.get())
2376 return ValueObjectSP();
2377
2378 *first_unparsed = expression_cstr;
2379
2380 while (true)
2381 {
2382
2383 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2384
Greg Claytonafacd142011-09-02 01:15:17 +00002385 clang_type_t root_clang_type = root->GetClangType();
2386 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002387 Flags root_clang_type_info,pointee_clang_type_info;
2388
2389 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2390 if (pointee_clang_type)
2391 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002392
2393 if (!expression_cstr || *expression_cstr == '\0')
2394 {
2395 *reason_to_stop = ValueObject::eEndOfString;
2396 return root;
2397 }
2398
2399 switch (*expression_cstr)
2400 {
2401 case '-':
2402 {
2403 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002404 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) ) // if you are trying to use -> on a non-pointer and I must catch the error
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002405 {
2406 *first_unparsed = expression_cstr;
2407 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
2408 *final_result = ValueObject::eInvalid;
2409 return ValueObjectSP();
2410 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002411 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2412 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002413 options.m_no_fragile_ivar)
2414 {
2415 *first_unparsed = expression_cstr;
2416 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
2417 *final_result = ValueObject::eInvalid;
2418 return ValueObjectSP();
2419 }
2420 if (expression_cstr[1] != '>')
2421 {
2422 *first_unparsed = expression_cstr;
2423 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2424 *final_result = ValueObject::eInvalid;
2425 return ValueObjectSP();
2426 }
2427 expression_cstr++; // skip the -
2428 }
2429 case '.': // or fallthrough from ->
2430 {
2431 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002432 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if you are trying to use . on a pointer and I must catch the error
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002433 {
2434 *first_unparsed = expression_cstr;
2435 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
2436 *final_result = ValueObject::eInvalid;
2437 return ValueObjectSP();
2438 }
2439 expression_cstr++; // skip .
2440 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2441 ConstString child_name;
2442 if (!next_separator) // if no other separator just expand this last layer
2443 {
2444 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002445 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2446
2447 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002448 {
2449 *first_unparsed = '\0';
2450 *reason_to_stop = ValueObject::eEndOfString;
2451 *final_result = ValueObject::ePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002452 return child_valobj_sp;
2453 }
2454 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2455 {
Greg Clayton4c3b8fb2011-12-02 22:48:25 +00002456 child_valobj_sp = root->GetSyntheticValue(eNoSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002457 }
2458
2459 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2460 // so we hit the "else" branch, and return an error
2461 if(child_valobj_sp.get()) // if it worked, just return
2462 {
2463 *first_unparsed = '\0';
2464 *reason_to_stop = ValueObject::eEndOfString;
2465 *final_result = ValueObject::ePlain;
2466 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002467 }
2468 else
2469 {
2470 *first_unparsed = expression_cstr;
2471 *reason_to_stop = ValueObject::eNoSuchChild;
2472 *final_result = ValueObject::eInvalid;
2473 return ValueObjectSP();
2474 }
2475 }
2476 else // other layers do expand
2477 {
2478 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002479 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2480 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002481 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002482 root = child_valobj_sp;
2483 *first_unparsed = next_separator;
2484 *final_result = ValueObject::ePlain;
2485 continue;
2486 }
2487 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2488 {
Greg Claytonafacd142011-09-02 01:15:17 +00002489 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002490 }
2491
2492 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2493 // so we hit the "else" branch, and return an error
2494 if(child_valobj_sp.get()) // if it worked, move on
2495 {
2496 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002497 *first_unparsed = next_separator;
2498 *final_result = ValueObject::ePlain;
2499 continue;
2500 }
2501 else
2502 {
2503 *first_unparsed = expression_cstr;
2504 *reason_to_stop = ValueObject::eNoSuchChild;
2505 *final_result = ValueObject::eInvalid;
2506 return ValueObjectSP();
2507 }
2508 }
2509 break;
2510 }
2511 case '[':
2512 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002513 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002514 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002515 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002516 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002517 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2518 {
2519 *first_unparsed = expression_cstr;
2520 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2521 *final_result = ValueObject::eInvalid;
2522 return ValueObjectSP();
2523 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002524 }
2525 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2526 {
2527 *first_unparsed = expression_cstr;
2528 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2529 *final_result = ValueObject::eInvalid;
2530 return ValueObjectSP();
2531 }
2532 }
2533 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2534 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002535 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002536 {
2537 *first_unparsed = expression_cstr;
2538 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2539 *final_result = ValueObject::eInvalid;
2540 return ValueObjectSP();
2541 }
2542 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2543 {
2544 *first_unparsed = expression_cstr+2;
2545 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2546 *final_result = ValueObject::eUnboundedRange;
2547 return root;
2548 }
2549 }
2550 const char *separator_position = ::strchr(expression_cstr+1,'-');
2551 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2552 if (!close_bracket_position) // if there is no ], this is a syntax error
2553 {
2554 *first_unparsed = expression_cstr;
2555 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2556 *final_result = ValueObject::eInvalid;
2557 return ValueObjectSP();
2558 }
2559 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2560 {
2561 char *end = NULL;
2562 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2563 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2564 {
2565 *first_unparsed = expression_cstr;
2566 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2567 *final_result = ValueObject::eInvalid;
2568 return ValueObjectSP();
2569 }
2570 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2571 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002572 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002573 {
2574 *first_unparsed = expression_cstr+2;
2575 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2576 *final_result = ValueObject::eUnboundedRange;
2577 return root;
2578 }
2579 else
2580 {
2581 *first_unparsed = expression_cstr;
2582 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2583 *final_result = ValueObject::eInvalid;
2584 return ValueObjectSP();
2585 }
2586 }
2587 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002588 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002589 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002590 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2591 if (!child_valobj_sp)
2592 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002593 if (!child_valobj_sp)
Greg Claytonafacd142011-09-02 01:15:17 +00002594 if (root->HasSyntheticValue() && root->GetSyntheticValue(eUseSyntheticFilter)->GetNumChildren() > index)
2595 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002596 if (child_valobj_sp)
2597 {
2598 root = child_valobj_sp;
2599 *first_unparsed = end+1; // skip ]
2600 *final_result = ValueObject::ePlain;
2601 continue;
2602 }
2603 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002604 {
2605 *first_unparsed = expression_cstr;
2606 *reason_to_stop = ValueObject::eNoSuchChild;
2607 *final_result = ValueObject::eInvalid;
2608 return ValueObjectSP();
2609 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002610 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002611 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002612 {
2613 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
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002614 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002615 {
2616 Error error;
2617 root = root->Dereference(error);
2618 if (error.Fail() || !root.get())
2619 {
2620 *first_unparsed = expression_cstr;
2621 *reason_to_stop = ValueObject::eDereferencingFailed;
2622 *final_result = ValueObject::eInvalid;
2623 return ValueObjectSP();
2624 }
2625 else
2626 {
2627 *what_next = eNothing;
2628 continue;
2629 }
2630 }
2631 else
2632 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002633 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Claytonafacd142011-09-02 01:15:17 +00002634 root->GetClangType()) == eLanguageTypeObjC
Enrico Granata27b625e2011-08-09 01:04:56 +00002635 &&
2636 ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2637 &&
2638 root->HasSyntheticValue()
2639 &&
2640 options.m_no_synthetic_children == false)
2641 {
Greg Claytonafacd142011-09-02 01:15:17 +00002642 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002643 }
2644 else
2645 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002646 if (!root.get())
2647 {
2648 *first_unparsed = expression_cstr;
2649 *reason_to_stop = ValueObject::eNoSuchChild;
2650 *final_result = ValueObject::eInvalid;
2651 return ValueObjectSP();
2652 }
2653 else
2654 {
2655 *first_unparsed = end+1; // skip ]
2656 *final_result = ValueObject::ePlain;
2657 continue;
2658 }
2659 }
2660 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002661 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002662 {
2663 root = root->GetSyntheticBitFieldChild(index, index, true);
2664 if (!root.get())
2665 {
2666 *first_unparsed = expression_cstr;
2667 *reason_to_stop = ValueObject::eNoSuchChild;
2668 *final_result = ValueObject::eInvalid;
2669 return ValueObjectSP();
2670 }
2671 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2672 {
2673 *first_unparsed = end+1; // skip ]
2674 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2675 *final_result = ValueObject::eBitfield;
2676 return root;
2677 }
2678 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002679 else if (root->HasSyntheticValue() && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002680 {
Greg Claytonafacd142011-09-02 01:15:17 +00002681 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002682 if (!root.get())
2683 {
2684 *first_unparsed = expression_cstr;
2685 *reason_to_stop = ValueObject::eNoSuchChild;
2686 *final_result = ValueObject::eInvalid;
2687 return ValueObjectSP();
2688 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002689 else
2690 {
2691 *first_unparsed = end+1; // skip ]
2692 *final_result = ValueObject::ePlain;
2693 continue;
2694 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002695 }
2696 else
2697 {
2698 *first_unparsed = expression_cstr;
2699 *reason_to_stop = ValueObject::eNoSuchChild;
2700 *final_result = ValueObject::eInvalid;
2701 return ValueObjectSP();
2702 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002703 }
2704 else // we have a low and a high index
2705 {
2706 char *end = NULL;
2707 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2708 if (!end || end != separator_position) // if something weird is in our way return an error
2709 {
2710 *first_unparsed = expression_cstr;
2711 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2712 *final_result = ValueObject::eInvalid;
2713 return ValueObjectSP();
2714 }
2715 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2716 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2717 {
2718 *first_unparsed = expression_cstr;
2719 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2720 *final_result = ValueObject::eInvalid;
2721 return ValueObjectSP();
2722 }
2723 if (index_lower > index_higher) // swap indices if required
2724 {
2725 unsigned long temp = index_lower;
2726 index_lower = index_higher;
2727 index_higher = temp;
2728 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002729 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002730 {
2731 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2732 if (!root.get())
2733 {
2734 *first_unparsed = expression_cstr;
2735 *reason_to_stop = ValueObject::eNoSuchChild;
2736 *final_result = ValueObject::eInvalid;
2737 return ValueObjectSP();
2738 }
2739 else
2740 {
2741 *first_unparsed = end+1; // skip ]
2742 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2743 *final_result = ValueObject::eBitfield;
2744 return root;
2745 }
2746 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002747 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) && // 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
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002748 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002749 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002750 {
2751 Error error;
2752 root = root->Dereference(error);
2753 if (error.Fail() || !root.get())
2754 {
2755 *first_unparsed = expression_cstr;
2756 *reason_to_stop = ValueObject::eDereferencingFailed;
2757 *final_result = ValueObject::eInvalid;
2758 return ValueObjectSP();
2759 }
2760 else
2761 {
2762 *what_next = ValueObject::eNothing;
2763 continue;
2764 }
2765 }
2766 else
2767 {
2768 *first_unparsed = expression_cstr;
2769 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2770 *final_result = ValueObject::eBoundedRange;
2771 return root;
2772 }
2773 }
2774 break;
2775 }
2776 default: // some non-separator is in the way
2777 {
2778 *first_unparsed = expression_cstr;
2779 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2780 *final_result = ValueObject::eInvalid;
2781 return ValueObjectSP();
2782 break;
2783 }
2784 }
2785 }
2786}
2787
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002788int
2789ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2790 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002791 ValueObjectSP root,
2792 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002793 ExpressionPathScanEndReason* reason_to_stop,
2794 ExpressionPathEndResultType* final_result,
2795 const GetValueForExpressionPathOptions& options,
2796 ExpressionPathAftermath* what_next)
2797{
2798 if (!root.get())
2799 return 0;
2800
2801 *first_unparsed = expression_cstr;
2802
2803 while (true)
2804 {
2805
2806 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2807
Greg Claytonafacd142011-09-02 01:15:17 +00002808 clang_type_t root_clang_type = root->GetClangType();
2809 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002810 Flags root_clang_type_info,pointee_clang_type_info;
2811
2812 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2813 if (pointee_clang_type)
2814 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2815
2816 if (!expression_cstr || *expression_cstr == '\0')
2817 {
2818 *reason_to_stop = ValueObject::eEndOfString;
2819 list->Append(root);
2820 return 1;
2821 }
2822
2823 switch (*expression_cstr)
2824 {
2825 case '[':
2826 {
2827 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2828 {
2829 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2830 {
2831 *first_unparsed = expression_cstr;
2832 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2833 *final_result = ValueObject::eInvalid;
2834 return 0;
2835 }
2836 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2837 {
2838 *first_unparsed = expression_cstr;
2839 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2840 *final_result = ValueObject::eInvalid;
2841 return 0;
2842 }
2843 }
2844 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2845 {
2846 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2847 {
2848 *first_unparsed = expression_cstr;
2849 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2850 *final_result = ValueObject::eInvalid;
2851 return 0;
2852 }
2853 else // expand this into list
2854 {
2855 int max_index = root->GetNumChildren() - 1;
2856 for (int index = 0; index < max_index; index++)
2857 {
2858 ValueObjectSP child =
2859 root->GetChildAtIndex(index, true);
2860 list->Append(child);
2861 }
2862 *first_unparsed = expression_cstr+2;
2863 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2864 *final_result = ValueObject::eValueObjectList;
2865 return max_index; // tell me number of items I added to the VOList
2866 }
2867 }
2868 const char *separator_position = ::strchr(expression_cstr+1,'-');
2869 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2870 if (!close_bracket_position) // if there is no ], this is a syntax error
2871 {
2872 *first_unparsed = expression_cstr;
2873 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2874 *final_result = ValueObject::eInvalid;
2875 return 0;
2876 }
2877 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2878 {
2879 char *end = NULL;
2880 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2881 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2882 {
2883 *first_unparsed = expression_cstr;
2884 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2885 *final_result = ValueObject::eInvalid;
2886 return 0;
2887 }
2888 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2889 {
2890 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2891 {
2892 int max_index = root->GetNumChildren() - 1;
2893 for (int index = 0; index < max_index; index++)
2894 {
2895 ValueObjectSP child =
2896 root->GetChildAtIndex(index, true);
2897 list->Append(child);
2898 }
2899 *first_unparsed = expression_cstr+2;
2900 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2901 *final_result = ValueObject::eValueObjectList;
2902 return max_index; // tell me number of items I added to the VOList
2903 }
2904 else
2905 {
2906 *first_unparsed = expression_cstr;
2907 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2908 *final_result = ValueObject::eInvalid;
2909 return 0;
2910 }
2911 }
2912 // from here on we do have a valid index
2913 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2914 {
2915 root = root->GetChildAtIndex(index, true);
2916 if (!root.get())
2917 {
2918 *first_unparsed = expression_cstr;
2919 *reason_to_stop = ValueObject::eNoSuchChild;
2920 *final_result = ValueObject::eInvalid;
2921 return 0;
2922 }
2923 else
2924 {
2925 list->Append(root);
2926 *first_unparsed = end+1; // skip ]
2927 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2928 *final_result = ValueObject::eValueObjectList;
2929 return 1;
2930 }
2931 }
2932 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2933 {
2934 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
2935 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2936 {
2937 Error error;
2938 root = root->Dereference(error);
2939 if (error.Fail() || !root.get())
2940 {
2941 *first_unparsed = expression_cstr;
2942 *reason_to_stop = ValueObject::eDereferencingFailed;
2943 *final_result = ValueObject::eInvalid;
2944 return 0;
2945 }
2946 else
2947 {
2948 *what_next = eNothing;
2949 continue;
2950 }
2951 }
2952 else
2953 {
2954 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2955 if (!root.get())
2956 {
2957 *first_unparsed = expression_cstr;
2958 *reason_to_stop = ValueObject::eNoSuchChild;
2959 *final_result = ValueObject::eInvalid;
2960 return 0;
2961 }
2962 else
2963 {
2964 list->Append(root);
2965 *first_unparsed = end+1; // skip ]
2966 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2967 *final_result = ValueObject::eValueObjectList;
2968 return 1;
2969 }
2970 }
2971 }
2972 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2973 {
2974 root = root->GetSyntheticBitFieldChild(index, index, true);
2975 if (!root.get())
2976 {
2977 *first_unparsed = expression_cstr;
2978 *reason_to_stop = ValueObject::eNoSuchChild;
2979 *final_result = ValueObject::eInvalid;
2980 return 0;
2981 }
2982 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2983 {
2984 list->Append(root);
2985 *first_unparsed = end+1; // skip ]
2986 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2987 *final_result = ValueObject::eValueObjectList;
2988 return 1;
2989 }
2990 }
2991 }
2992 else // we have a low and a high index
2993 {
2994 char *end = NULL;
2995 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2996 if (!end || end != separator_position) // if something weird is in our way return an error
2997 {
2998 *first_unparsed = expression_cstr;
2999 *reason_to_stop = ValueObject::eUnexpectedSymbol;
3000 *final_result = ValueObject::eInvalid;
3001 return 0;
3002 }
3003 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3004 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3005 {
3006 *first_unparsed = expression_cstr;
3007 *reason_to_stop = ValueObject::eUnexpectedSymbol;
3008 *final_result = ValueObject::eInvalid;
3009 return 0;
3010 }
3011 if (index_lower > index_higher) // swap indices if required
3012 {
3013 unsigned long temp = index_lower;
3014 index_lower = index_higher;
3015 index_higher = temp;
3016 }
3017 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3018 {
3019 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3020 if (!root.get())
3021 {
3022 *first_unparsed = expression_cstr;
3023 *reason_to_stop = ValueObject::eNoSuchChild;
3024 *final_result = ValueObject::eInvalid;
3025 return 0;
3026 }
3027 else
3028 {
3029 list->Append(root);
3030 *first_unparsed = end+1; // skip ]
3031 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
3032 *final_result = ValueObject::eValueObjectList;
3033 return 1;
3034 }
3035 }
3036 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) && // 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
3037 *what_next == ValueObject::eDereference &&
3038 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3039 {
3040 Error error;
3041 root = root->Dereference(error);
3042 if (error.Fail() || !root.get())
3043 {
3044 *first_unparsed = expression_cstr;
3045 *reason_to_stop = ValueObject::eDereferencingFailed;
3046 *final_result = ValueObject::eInvalid;
3047 return 0;
3048 }
3049 else
3050 {
3051 *what_next = ValueObject::eNothing;
3052 continue;
3053 }
3054 }
3055 else
3056 {
Johnny Chen44805302011-07-19 19:48:13 +00003057 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003058 index <= index_higher; index++)
3059 {
3060 ValueObjectSP child =
3061 root->GetChildAtIndex(index, true);
3062 list->Append(child);
3063 }
3064 *first_unparsed = end+1;
3065 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
3066 *final_result = ValueObject::eValueObjectList;
3067 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3068 }
3069 }
3070 break;
3071 }
3072 default: // some non-[ separator, or something entirely wrong, is in the way
3073 {
3074 *first_unparsed = expression_cstr;
3075 *reason_to_stop = ValueObject::eUnexpectedSymbol;
3076 *final_result = ValueObject::eInvalid;
3077 return 0;
3078 break;
3079 }
3080 }
3081 }
3082}
3083
Enrico Granata0c489f52012-03-01 04:24:26 +00003084static void
3085DumpValueObject_Impl (Stream &s,
3086 ValueObject *valobj,
3087 const ValueObject::DumpValueObjectOptions& options,
3088 uint32_t ptr_depth,
3089 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003090{
Greg Clayton007d5be2011-05-30 00:49:24 +00003091 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003092 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003093 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003094
Enrico Granata0c489f52012-03-01 04:24:26 +00003095 const char *root_valobj_name =
3096 options.m_root_valobj_name.empty() ?
3097 valobj->GetName().AsCString() :
3098 options.m_root_valobj_name.c_str();
3099
3100 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003101 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003102 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003103 if (dynamic_value)
3104 valobj = dynamic_value;
3105 }
3106
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003107 clang_type_t clang_type = valobj->GetClangType();
3108
Greg Clayton73b472d2010-10-27 03:32:59 +00003109 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003110 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003111 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3112 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003113
Enrico Granata0c489f52012-03-01 04:24:26 +00003114 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003115
3116 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003117 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003118 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003119 {
Jim Ingham6035b672011-03-31 00:19:25 +00003120 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003121 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003122
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003123 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003124
Greg Clayton7c8a9662010-11-02 01:50:16 +00003125 // Always show the type for the top level items.
Enrico Granata0c489f52012-03-01 04:24:26 +00003126 if (options.m_show_types || (curr_depth == 0 && !options.m_flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003127 {
Enrico Granata9910bc82011-08-03 02:18:51 +00003128 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
3129 s.Printf("(%s", typeName);
3130 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003131 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003132 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003133 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003134 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003135 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3136 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003137 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003138 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003139 else
3140 {
3141 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3142 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003143 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003144 else
3145 {
3146 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3147 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003148 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003149 else
3150 s.Printf(", dynamic type: %s) ",
3151 runtime->GetActualTypeName(isa).GetCString());
3152 }
3153 }
3154 }
3155 else
3156 s.Printf(") ");
3157 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003158
Greg Clayton1d3afba2010-10-05 00:00:42 +00003159
Enrico Granata0c489f52012-03-01 04:24:26 +00003160 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003161 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003162 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003163 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003164 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003165 s.PutCString(" =");
3166 }
3167 else
3168 {
3169 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3170 s.Printf ("%s =", name_cstr);
3171 }
3172
Enrico Granata0c489f52012-03-01 04:24:26 +00003173 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003174 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003175 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003176 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003177 }
3178
Enrico Granata0c489f52012-03-01 04:24:26 +00003179 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003180 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003181 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003182 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003183 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003184
Enrico Granata0c489f52012-03-01 04:24:26 +00003185 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003186 entry = NULL;
3187
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003188 if (err_cstr == NULL)
3189 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003190 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003191 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003192 valobj->GetValueAsCString(options.m_format,
3193 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003194 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003195 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003196 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003197 val_cstr = valobj->GetValueAsCString();
3198 if (val_cstr)
3199 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003200 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003201 err_cstr = valobj->GetError().AsCString();
3202 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003203
3204 if (err_cstr)
3205 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003206 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003207 }
3208 else
3209 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003210 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003211 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003212 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003213 if (options.m_omit_summary_depth == 0)
3214 {
3215 if (options.m_summary_sp)
3216 {
3217 valobj->GetSummaryAsCString(entry, summary_str);
3218 sum_cstr = summary_str.c_str();
3219 }
3220 else
3221 sum_cstr = valobj->GetSummaryAsCString();
3222 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003223
Greg Clayton6efba4f2012-01-26 21:08:30 +00003224 // Make sure we have a value and make sure the summary didn't
3225 // specify that the value should not be printed
3226 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3227 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003228
Enrico Granata9dd75c82011-07-15 23:30:15 +00003229 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003230 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003231
Enrico Granata0c489f52012-03-01 04:24:26 +00003232 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003233 {
Jim Ingham6035b672011-03-31 00:19:25 +00003234 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003235 if (object_desc)
3236 s.Printf(" %s\n", object_desc);
3237 else
Sean Callanan672ad942010-10-23 00:18:49 +00003238 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003239 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003240 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003241 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003242
Enrico Granata0c489f52012-03-01 04:24:26 +00003243 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003244 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003245 // We will show children for all concrete types. We won't show
3246 // pointer contents unless a pointer depth has been specified.
3247 // We won't reference contents unless the reference is the
3248 // root object (depth of zero).
3249 bool print_children = true;
3250
3251 // Use a new temporary pointer depth in case we override the
3252 // current pointer depth below...
3253 uint32_t curr_ptr_depth = ptr_depth;
3254
3255 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3256 if (is_ptr || is_ref)
3257 {
3258 // We have a pointer or reference whose value is an address.
3259 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003260 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003261 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003262 print_children = false;
3263
3264 else if (is_ref && curr_depth == 0)
3265 {
3266 // If this is the root object (depth is zero) that we are showing
3267 // and it is a reference, and no pointer depth has been supplied
3268 // print out what it references. Don't do this at deeper depths
3269 // otherwise we can end up with infinite recursion...
3270 curr_ptr_depth = 1;
3271 }
3272
3273 if (curr_ptr_depth == 0)
3274 print_children = false;
3275 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003276
Enrico Granata0a3958e2011-07-02 00:25:22 +00003277 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003278 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003279 ValueObjectSP synth_valobj = valobj->GetSyntheticValue (options.m_use_synthetic ?
Greg Claytoncc4d0142012-02-17 07:49:44 +00003280 eUseSyntheticFilter :
3281 eNoSyntheticFilter);
Enrico Granatac482a192011-08-17 22:13:59 +00003282 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003283 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003284 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003285 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003286 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003287 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003288 if (print_valobj)
3289 s.EOL();
3290 }
3291 else
3292 {
3293 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003294 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003295 s.IndentMore();
3296 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003297
Greg Claytoncc4d0142012-02-17 07:49:44 +00003298 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003299
Enrico Granata0c489f52012-03-01 04:24:26 +00003300 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003301 {
3302 num_children = max_num_children;
3303 print_dotdotdot = true;
3304 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003305
Enrico Granata0c489f52012-03-01 04:24:26 +00003306 ValueObject::DumpValueObjectOptions child_options(options);
3307 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3308 child_options.SetScopeChecked(true)
3309 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003310 for (uint32_t idx=0; idx<num_children; ++idx)
3311 {
Enrico Granatac482a192011-08-17 22:13:59 +00003312 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003313 if (child_sp.get())
3314 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003315 DumpValueObject_Impl (s,
3316 child_sp.get(),
3317 child_options,
3318 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3319 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003320 }
3321 }
3322
Enrico Granata0c489f52012-03-01 04:24:26 +00003323 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003324 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003325 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003326 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003327 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3328 Target *target = exe_ctx.GetTargetPtr();
3329 if (target)
3330 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003331 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003332 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003333 s.IndentLess();
3334 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003335 }
3336 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003337 else if (has_children)
3338 {
3339 // Aggregate, no children...
3340 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003341 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003342 }
3343 else
3344 {
3345 if (print_valobj)
3346 s.EOL();
3347 }
3348
Greg Clayton1d3afba2010-10-05 00:00:42 +00003349 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003350 else
3351 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003352 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003353 }
3354 }
3355 else
3356 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003357 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003358 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003359 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003360 }
3361 }
3362 }
3363 }
3364}
3365
Enrico Granata0c489f52012-03-01 04:24:26 +00003366void
3367ValueObject::DumpValueObject (Stream &s,
3368 ValueObject *valobj)
3369{
3370
3371 if (!valobj)
3372 return;
3373
3374 DumpValueObject_Impl(s,
3375 valobj,
3376 DumpValueObjectOptions::DefaultOptions(),
3377 0,
3378 0);
3379}
3380
3381void
3382ValueObject::DumpValueObject (Stream &s,
3383 ValueObject *valobj,
3384 const DumpValueObjectOptions& options)
3385{
3386 DumpValueObject_Impl(s,
3387 valobj,
3388 options,
3389 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3390 0 // current object depth is 0 since we are just starting
3391 );
3392}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003393
3394ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003395ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003396{
3397 ValueObjectSP valobj_sp;
3398
Enrico Granatac3e320a2011-08-02 17:27:39 +00003399 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003400 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003401 ExecutionContext exe_ctx (GetExecutionContextRef());
3402 clang::ASTContext *ast = GetClangAST ();
3403
3404 DataExtractor data;
3405 data.SetByteOrder (m_data.GetByteOrder());
3406 data.SetAddressByteSize(m_data.GetAddressByteSize());
3407
Greg Claytone72dfb32012-02-24 01:59:29 +00003408 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003409
3410 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3411 ast,
3412 GetClangType(),
3413 name,
3414 data,
3415 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003416 }
Jim Ingham6035b672011-03-31 00:19:25 +00003417
3418 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003419 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003420 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003421 }
3422 return valobj_sp;
3423}
3424
Greg Claytonafacd142011-09-02 01:15:17 +00003425ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003426ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003427{
Jim Ingham58b59f92011-04-22 23:53:53 +00003428 if (m_deref_valobj)
3429 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003430
Greg Clayton54979cd2010-12-15 05:08:08 +00003431 const bool is_pointer_type = IsPointerType();
3432 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003433 {
3434 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003435 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003436
3437 std::string child_name_str;
3438 uint32_t child_byte_size = 0;
3439 int32_t child_byte_offset = 0;
3440 uint32_t child_bitfield_bit_size = 0;
3441 uint32_t child_bitfield_bit_offset = 0;
3442 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003443 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003444 const bool transparent_pointers = false;
3445 clang::ASTContext *clang_ast = GetClangAST();
3446 clang_type_t clang_type = GetClangType();
3447 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003448
Greg Claytoncc4d0142012-02-17 07:49:44 +00003449 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003450
3451 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3452 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003453 GetName().GetCString(),
3454 clang_type,
3455 0,
3456 transparent_pointers,
3457 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003458 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003459 child_name_str,
3460 child_byte_size,
3461 child_byte_offset,
3462 child_bitfield_bit_size,
3463 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003464 child_is_base_class,
3465 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003466 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003467 {
3468 ConstString child_name;
3469 if (!child_name_str.empty())
3470 child_name.SetCString (child_name_str.c_str());
3471
Jim Ingham58b59f92011-04-22 23:53:53 +00003472 m_deref_valobj = new ValueObjectChild (*this,
3473 clang_ast,
3474 child_clang_type,
3475 child_name,
3476 child_byte_size,
3477 child_byte_offset,
3478 child_bitfield_bit_size,
3479 child_bitfield_bit_offset,
3480 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003481 child_is_deref_of_parent,
3482 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003483 }
3484 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003485
Jim Ingham58b59f92011-04-22 23:53:53 +00003486 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003487 {
3488 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003489 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003490 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003491 else
3492 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003493 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003494 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003495
3496 if (is_pointer_type)
3497 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3498 else
3499 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003500 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003501 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003502}
3503
Greg Claytonafacd142011-09-02 01:15:17 +00003504ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003505ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003506{
Jim Ingham78a685a2011-04-16 00:01:13 +00003507 if (m_addr_of_valobj_sp)
3508 return m_addr_of_valobj_sp;
3509
Greg Claytone0d378b2011-03-24 21:19:54 +00003510 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003511 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003512 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003513 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003514 if (addr != LLDB_INVALID_ADDRESS)
3515 {
3516 switch (address_type)
3517 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003518 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003519 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003520 {
3521 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003522 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003523 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3524 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003525 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003526
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003527 case eAddressTypeFile:
3528 case eAddressTypeLoad:
3529 case eAddressTypeHost:
3530 {
3531 clang::ASTContext *ast = GetClangAST();
3532 clang_type_t clang_type = GetClangType();
3533 if (ast && clang_type)
3534 {
3535 std::string name (1, '&');
3536 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003537 ExecutionContext exe_ctx (GetExecutionContextRef());
3538 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003539 ast,
3540 ClangASTContext::CreatePointerType (ast, clang_type),
3541 ConstString (name.c_str()),
3542 addr,
3543 eAddressTypeInvalid,
3544 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003545 }
3546 }
3547 break;
3548 }
3549 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003550 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003551}
3552
Greg Clayton9a142cf2012-02-03 05:34:10 +00003553ValueObjectSP
3554ValueObject::Cast (const ClangASTType &clang_ast_type)
3555{
Greg Clayton81e871e2012-02-04 02:27:34 +00003556 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003557}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003558
Greg Claytonafacd142011-09-02 01:15:17 +00003559ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003560ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3561{
Greg Claytonafacd142011-09-02 01:15:17 +00003562 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003563 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003564 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003565
3566 if (ptr_value != LLDB_INVALID_ADDRESS)
3567 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003568 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003569 ExecutionContext exe_ctx (GetExecutionContextRef());
3570 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003571 name,
3572 ptr_addr,
3573 clang_ast_type);
3574 }
3575 return valobj_sp;
3576}
3577
Greg Claytonafacd142011-09-02 01:15:17 +00003578ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003579ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3580{
Greg Claytonafacd142011-09-02 01:15:17 +00003581 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003582 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003583 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003584
3585 if (ptr_value != LLDB_INVALID_ADDRESS)
3586 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003587 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003588 ExecutionContext exe_ctx (GetExecutionContextRef());
3589 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003590 name,
3591 ptr_addr,
3592 type_sp);
3593 }
3594 return valobj_sp;
3595}
3596
Jim Ingham6035b672011-03-31 00:19:25 +00003597ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003598 m_mod_id(),
3599 m_exe_ctx_ref(),
3600 m_needs_update (true),
3601 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003602{
3603}
3604
3605ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003606 m_mod_id(),
3607 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003608 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003609 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003610{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003611 ExecutionContext exe_ctx(exe_scope);
3612 TargetSP target_sp (exe_ctx.GetTargetSP());
3613 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003614 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003615 m_exe_ctx_ref.SetTargetSP (target_sp);
3616 ProcessSP process_sp (exe_ctx.GetProcessSP());
3617 if (!process_sp)
3618 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003619
Greg Claytoncc4d0142012-02-17 07:49:44 +00003620 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003621 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003622 m_mod_id = process_sp->GetModID();
3623 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003624
Greg Claytoncc4d0142012-02-17 07:49:44 +00003625 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003626
Greg Claytoncc4d0142012-02-17 07:49:44 +00003627 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003628 {
3629 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003630 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003631 }
Jim Ingham6035b672011-03-31 00:19:25 +00003632
Greg Claytoncc4d0142012-02-17 07:49:44 +00003633 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003634 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003635 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003636
Greg Claytoncc4d0142012-02-17 07:49:44 +00003637 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3638 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003639 {
3640 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003641 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003642 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003643 if (frame_sp)
3644 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003645 }
3646 }
3647 }
Jim Ingham6035b672011-03-31 00:19:25 +00003648}
3649
3650ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003651 m_mod_id(),
3652 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3653 m_needs_update (true),
3654 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003655{
3656}
3657
3658ValueObject::EvaluationPoint::~EvaluationPoint ()
3659{
3660}
3661
Jim Ingham6035b672011-03-31 00:19:25 +00003662// This function checks the EvaluationPoint against the current process state. If the current
3663// state matches the evaluation point, or the evaluation point is already invalid, then we return
3664// false, meaning "no change". If the current state is different, we update our state, and return
3665// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3666// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003667// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003668
3669bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003670ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003671{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003672
3673 // Start with the target, if it is NULL, then we're obviously not going to get any further:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003674 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003675
Greg Claytoncc4d0142012-02-17 07:49:44 +00003676 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003677 return false;
3678
Jim Ingham6035b672011-03-31 00:19:25 +00003679 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003680 Process *process = exe_ctx.GetProcessPtr();
3681 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003682 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003683
Jim Ingham6035b672011-03-31 00:19:25 +00003684 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003685 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003686
Jim Ingham78a685a2011-04-16 00:01:13 +00003687 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3688 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003689 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003690 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003691
3692 bool changed;
3693
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003694 if (m_mod_id.IsValid())
3695 {
3696 if (m_mod_id == current_mod_id)
3697 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003698 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003699 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003700 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003701 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003702 else
3703 {
3704 m_mod_id = current_mod_id;
3705 m_needs_update = true;
3706 changed = true;
3707 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003708 }
Jim Ingham6035b672011-03-31 00:19:25 +00003709
Jim Ingham73ca05a2011-12-17 01:35:57 +00003710 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3711 // That way we'll be sure to return a valid exe_scope.
3712 // If we used to have a thread or a frame but can't find it anymore, then mark ourselves as invalid.
Jim Ingham6035b672011-03-31 00:19:25 +00003713
Greg Claytoncc4d0142012-02-17 07:49:44 +00003714 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003715 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003716 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3717 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003718 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003719 if (m_exe_ctx_ref.HasFrameRef())
3720 {
3721 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3722 if (!frame_sp)
3723 {
3724 // We used to have a frame, but now it is gone
3725 SetInvalid();
3726 }
3727 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003728 }
Jim Ingham6035b672011-03-31 00:19:25 +00003729 else
3730 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003731 // We used to have a thread, but now it is gone
3732 SetInvalid();
Jim Ingham6035b672011-03-31 00:19:25 +00003733 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003734
Jim Ingham6035b672011-03-31 00:19:25 +00003735 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003736 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003737}
3738
Jim Ingham61be0902011-05-02 18:13:59 +00003739void
3740ValueObject::EvaluationPoint::SetUpdated ()
3741{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003742 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3743 if (process_sp)
3744 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003745 m_first_update = false;
3746 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003747}
3748
3749
Greg Claytoncc4d0142012-02-17 07:49:44 +00003750//bool
3751//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3752//{
3753// if (!IsValid())
3754// return false;
3755//
3756// bool needs_update = false;
3757//
3758// // The target has to be non-null, and the
3759// Target *target = exe_scope->CalculateTarget();
3760// if (target != NULL)
3761// {
3762// Target *old_target = m_target_sp.get();
3763// assert (target == old_target);
3764// Process *process = exe_scope->CalculateProcess();
3765// if (process != NULL)
3766// {
3767// // FOR NOW - assume you can't update variable objects across process boundaries.
3768// Process *old_process = m_process_sp.get();
3769// assert (process == old_process);
3770// ProcessModID current_mod_id = process->GetModID();
3771// if (m_mod_id != current_mod_id)
3772// {
3773// needs_update = true;
3774// m_mod_id = current_mod_id;
3775// }
3776// // See if we're switching the thread or stack context. If no thread is given, this is
3777// // being evaluated in a global context.
3778// Thread *thread = exe_scope->CalculateThread();
3779// if (thread != NULL)
3780// {
3781// user_id_t new_thread_index = thread->GetIndexID();
3782// if (new_thread_index != m_thread_id)
3783// {
3784// needs_update = true;
3785// m_thread_id = new_thread_index;
3786// m_stack_id.Clear();
3787// }
3788//
3789// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3790// if (new_frame != NULL)
3791// {
3792// if (new_frame->GetStackID() != m_stack_id)
3793// {
3794// needs_update = true;
3795// m_stack_id = new_frame->GetStackID();
3796// }
3797// }
3798// else
3799// {
3800// m_stack_id.Clear();
3801// needs_update = true;
3802// }
3803// }
3804// else
3805// {
3806// // If this had been given a thread, and now there is none, we should update.
3807// // Otherwise we don't have to do anything.
3808// if (m_thread_id != LLDB_INVALID_UID)
3809// {
3810// m_thread_id = LLDB_INVALID_UID;
3811// m_stack_id.Clear();
3812// needs_update = true;
3813// }
3814// }
3815// }
3816// else
3817// {
3818// // If there is no process, then we don't need to update anything.
3819// // But if we're switching from having a process to not, we should try to update.
3820// if (m_process_sp.get() != NULL)
3821// {
3822// needs_update = true;
3823// m_process_sp.reset();
3824// m_thread_id = LLDB_INVALID_UID;
3825// m_stack_id.Clear();
3826// }
3827// }
3828// }
3829// else
3830// {
3831// // If there's no target, nothing can change so we don't need to update anything.
3832// // But if we're switching from having a target to not, we should try to update.
3833// if (m_target_sp.get() != NULL)
3834// {
3835// needs_update = true;
3836// m_target_sp.reset();
3837// m_process_sp.reset();
3838// m_thread_id = LLDB_INVALID_UID;
3839// m_stack_id.Clear();
3840// }
3841// }
3842// if (!m_needs_update)
3843// m_needs_update = needs_update;
3844//
3845// return needs_update;
3846//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003847
3848void
3849ValueObject::ClearUserVisibleData()
3850{
3851 m_location_str.clear();
3852 m_value_str.clear();
3853 m_summary_str.clear();
3854 m_object_desc_str.clear();
Enrico Granata0c489f52012-03-01 04:24:26 +00003855 m_synthetic_value = NULL;
Greg Clayton48ca8b82012-01-07 20:58:07 +00003856 m_is_getting_summary = false;
Johnny Chen44805302011-07-19 19:48:13 +00003857}
Enrico Granata9128ee22011-09-06 19:20:51 +00003858
3859SymbolContextScope *
3860ValueObject::GetSymbolContextScope()
3861{
3862 if (m_parent)
3863 {
3864 if (!m_parent->IsPointerOrReferenceType())
3865 return m_parent->GetSymbolContextScope();
3866 }
3867 return NULL;
3868}