blob: 1a7e3702b83a37005a1190dc8df097bfb879f7c9 [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
Greg Claytonefbc7d22012-03-09 04:23:44 +0000207 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000208 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000209 const bool value_was_valid = GetValueIsValid();
210 SetValueDidChange (false);
211
212 m_error.Clear();
213
214 // Call the pure virtual function to update the value
215 bool success = UpdateValue ();
216
217 SetValueIsValid (success);
218
219 if (first_update)
220 SetValueDidChange (false);
221 else if (!m_value_did_change && success == false)
222 {
223 // The value wasn't gotten successfully, so we mark this
224 // as changed if the value used to be valid and now isn't
225 SetValueDidChange (value_was_valid);
226 }
227 }
228 else
229 {
230 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231 }
232 }
233 return m_error.Success();
234}
235
Enrico Granata9128ee22011-09-06 19:20:51 +0000236bool
Greg Claytonafacd142011-09-02 01:15:17 +0000237ValueObject::UpdateFormatsIfNeeded(DynamicValueType use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000238{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000239 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
240 if (log)
241 log->Printf("checking for FormatManager revisions. VO named %s is at revision %d, while the format manager is at revision %d",
242 GetName().GetCString(),
Enrico Granata4becb372011-06-29 22:27:15 +0000243 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000244 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000245
246 bool any_change = false;
247
Enrico Granata85933ed2011-08-18 16:38:26 +0000248 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) ||
Enrico Granatac3e320a2011-08-02 17:27:39 +0000249 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000250 {
Enrico Granata78d06382011-09-09 23:33:14 +0000251 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
252 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, use_dynamic));
253 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, use_dynamic));
Enrico Granata1490c6f2011-07-19 02:34:21 +0000254
Enrico Granata85933ed2011-08-18 16:38:26 +0000255 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000256 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granata855cd902011-09-06 22:59:55 +0000257
258 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000259 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000260
261 return any_change;
262
Enrico Granata4becb372011-06-29 22:27:15 +0000263}
264
Jim Ingham16e0c682011-08-12 23:34:31 +0000265void
266ValueObject::SetNeedsUpdate ()
267{
268 m_update_point.SetNeedsUpdate();
269 // We have to clear the value string here so ConstResult children will notice if their values are
270 // changed by hand (i.e. with SetValueAsCString).
271 m_value_str.clear();
272}
273
Sean Callanan72772842012-02-22 23:57:45 +0000274ClangASTType
275ValueObject::MaybeCalculateCompleteType ()
276{
277 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
278
279 if (m_did_calculate_complete_objc_class_type)
280 {
281 if (m_override_type.IsValid())
282 return m_override_type;
283 else
284 return ret;
285 }
286
287 clang_type_t ast_type(GetClangTypeImpl());
288 clang_type_t class_type;
289 bool is_pointer_type;
290
291 if (ClangASTContext::IsObjCObjectPointerType(ast_type, &class_type))
292 {
293 is_pointer_type = true;
294 }
295 else if (ClangASTContext::IsObjCClassType(ast_type))
296 {
297 is_pointer_type = false;
298 class_type = ast_type;
299 }
300 else
301 {
302 return ret;
303 }
304
305 m_did_calculate_complete_objc_class_type = true;
306
307 if (!class_type)
308 return ret;
309
310 std::string class_name;
311
312 if (!ClangASTContext::GetObjCClassName(class_type, class_name))
313 return ret;
314
315 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
316
317 if (!process_sp)
318 return ret;
319
320 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
321
322 if (!objc_language_runtime)
323 return ret;
324
325 ConstString class_name_cs(class_name.c_str());
326
327 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name_cs);
328
329 if (!complete_objc_class_type_sp)
330 return ret;
331
332 ClangASTType complete_class(complete_objc_class_type_sp->GetClangAST(),
333 complete_objc_class_type_sp->GetClangFullType());
334
335 if (!ClangASTContext::GetCompleteType(complete_class.GetASTContext(),
336 complete_class.GetOpaqueQualType()))
337 return ret;
338
339 if (is_pointer_type)
340 {
341 clang_type_t pointer_type = ClangASTContext::CreatePointerType(complete_class.GetASTContext(),
342 complete_class.GetOpaqueQualType());
343
344 m_override_type = ClangASTType(complete_class.GetASTContext(),
345 pointer_type);
346 }
347 else
348 {
349 m_override_type = complete_class;
350 }
351
352 return m_override_type;
353}
354
355clang::ASTContext *
356ValueObject::GetClangAST ()
357{
358 ClangASTType type = MaybeCalculateCompleteType();
359
360 return type.GetASTContext();
361}
362
363lldb::clang_type_t
364ValueObject::GetClangType ()
365{
366 ClangASTType type = MaybeCalculateCompleteType();
367
368 return type.GetOpaqueQualType();
369}
370
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000371DataExtractor &
372ValueObject::GetDataExtractor ()
373{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000374 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375 return m_data;
376}
377
378const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000379ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000381 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000382 return m_error;
383}
384
385const ConstString &
386ValueObject::GetName() const
387{
388 return m_name;
389}
390
391const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000392ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000393{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000394 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000395 {
396 if (m_location_str.empty())
397 {
398 StreamString sstr;
399
400 switch (m_value.GetValueType())
401 {
402 default:
403 break;
404
405 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000406 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407 {
408 RegisterInfo *reg_info = m_value.GetRegisterInfo();
409 if (reg_info)
410 {
411 if (reg_info->name)
412 m_location_str = reg_info->name;
413 else if (reg_info->alt_name)
414 m_location_str = reg_info->alt_name;
415 break;
416 }
417 }
418 m_location_str = "scalar";
419 break;
420
421 case Value::eValueTypeLoadAddress:
422 case Value::eValueTypeFileAddress:
423 case Value::eValueTypeHostAddress:
424 {
425 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
426 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
427 m_location_str.swap(sstr.GetString());
428 }
429 break;
430 }
431 }
432 }
433 return m_location_str.c_str();
434}
435
436Value &
437ValueObject::GetValue()
438{
439 return m_value;
440}
441
442const Value &
443ValueObject::GetValue() const
444{
445 return m_value;
446}
447
448bool
Jim Ingham6035b672011-03-31 00:19:25 +0000449ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000450{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000451 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
452 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000453 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000454 Value tmp_value(m_value);
455 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000456 if (scalar.IsValid())
457 {
458 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
459 if (bitfield_bit_size)
460 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
461 return true;
462 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000463 }
Greg Claytondcad5022011-12-29 01:26:56 +0000464 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000465}
466
467bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000468ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000469{
Greg Clayton288bdf92010-09-02 02:59:18 +0000470 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471}
472
473
474void
475ValueObject::SetValueIsValid (bool b)
476{
Greg Clayton288bdf92010-09-02 02:59:18 +0000477 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000478}
479
480bool
Jim Ingham6035b672011-03-31 00:19:25 +0000481ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000482{
Jim Ingham6035b672011-03-31 00:19:25 +0000483 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000484 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000485}
486
487void
488ValueObject::SetValueDidChange (bool value_changed)
489{
Greg Clayton288bdf92010-09-02 02:59:18 +0000490 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491}
492
493ValueObjectSP
494ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
495{
496 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000497 // We may need to update our value if we are dynamic
498 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000499 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000500 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000502 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000503 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000505 // No we haven't created the child at this index, so lets have our
506 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000507 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000508 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000509
Enrico Granata9d60f602012-03-09 03:09:58 +0000510 ValueObject* child = m_children.GetChildAtIndex(idx);
511 if (child != NULL)
512 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000513 }
514 return child_sp;
515}
516
517uint32_t
518ValueObject::GetIndexOfChildWithName (const ConstString &name)
519{
520 bool omit_empty_base_classes = true;
521 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000522 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000523 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524 omit_empty_base_classes);
525}
526
527ValueObjectSP
528ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
529{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000530 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531 // classes (which really aren't part of the expression path), so we
532 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000533 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000534
Greg Claytondea8cb42011-06-29 22:09:02 +0000535 // We may need to update our value if we are dynamic
536 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000537 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000538
539 std::vector<uint32_t> child_indexes;
540 clang::ASTContext *clang_ast = GetClangAST();
541 void *clang_type = GetClangType();
542 bool omit_empty_base_classes = true;
543 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
544 clang_type,
545 name.GetCString(),
546 omit_empty_base_classes,
547 child_indexes);
548 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000550 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
551 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
552
553 child_sp = GetChildAtIndex(*pos, can_create);
554 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000556 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000557 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000558 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
559 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000560 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000561 else
562 {
563 child_sp.reset();
564 }
565
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000566 }
567 }
568 return child_sp;
569}
570
571
572uint32_t
573ValueObject::GetNumChildren ()
574{
Greg Clayton288bdf92010-09-02 02:59:18 +0000575 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000576 {
577 SetNumChildren (CalculateNumChildren());
578 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000579 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580}
581void
582ValueObject::SetNumChildren (uint32_t num_children)
583{
Greg Clayton288bdf92010-09-02 02:59:18 +0000584 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000585 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586}
587
588void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000589ValueObject::SetName (const ConstString &name)
590{
591 m_name = name;
592}
593
Jim Ingham58b59f92011-04-22 23:53:53 +0000594ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000595ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
596{
Jim Ingham2eec4872011-05-07 00:10:58 +0000597 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000598
Greg Claytondea8cb42011-06-29 22:09:02 +0000599 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000600 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000601 std::string child_name_str;
602 uint32_t child_byte_size = 0;
603 int32_t child_byte_offset = 0;
604 uint32_t child_bitfield_bit_size = 0;
605 uint32_t child_bitfield_bit_offset = 0;
606 bool child_is_base_class = false;
607 bool child_is_deref_of_parent = false;
608
609 const bool transparent_pointers = synthetic_array_member == false;
610 clang::ASTContext *clang_ast = GetClangAST();
611 clang_type_t clang_type = GetClangType();
612 clang_type_t child_clang_type;
613
Greg Claytoncc4d0142012-02-17 07:49:44 +0000614 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000615
616 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
617 clang_ast,
618 GetName().GetCString(),
619 clang_type,
620 idx,
621 transparent_pointers,
622 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000623 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000624 child_name_str,
625 child_byte_size,
626 child_byte_offset,
627 child_bitfield_bit_size,
628 child_bitfield_bit_offset,
629 child_is_base_class,
630 child_is_deref_of_parent);
631 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000632 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000633 if (synthetic_index)
634 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000635
Greg Claytondea8cb42011-06-29 22:09:02 +0000636 ConstString child_name;
637 if (!child_name_str.empty())
638 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000639
Greg Claytondea8cb42011-06-29 22:09:02 +0000640 valobj = new ValueObjectChild (*this,
641 clang_ast,
642 child_clang_type,
643 child_name,
644 child_byte_size,
645 child_byte_offset,
646 child_bitfield_bit_size,
647 child_bitfield_bit_offset,
648 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000649 child_is_deref_of_parent,
650 eAddressTypeInvalid);
651 //if (valobj)
652 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
653 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000654
Jim Ingham58b59f92011-04-22 23:53:53 +0000655 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000656}
657
Enrico Granata0c489f52012-03-01 04:24:26 +0000658bool
659ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
660 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000661{
Enrico Granata0c489f52012-03-01 04:24:26 +0000662 destination.clear();
663
664 // ideally we would like to bail out if passing NULL, but if we do so
665 // we end up not providing the summary for function pointers anymore
666 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
667 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000668
669 m_is_getting_summary = true;
Enrico Granata0c489f52012-03-01 04:24:26 +0000670 if (UpdateValueIfNeeded (false))
671 {
672 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000673 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000674 summary_ptr->FormatObject(GetSP(), destination);
675 }
676 else
677 {
678 clang_type_t clang_type = GetClangType();
679
680 // Do some default printout for function pointers
681 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000682 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000683 StreamString sstr;
684 clang_type_t elem_or_pointee_clang_type;
685 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
686 GetClangAST(),
687 &elem_or_pointee_clang_type));
688
689 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000690 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000691 AddressType func_ptr_address_type = eAddressTypeInvalid;
692 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
693 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000694 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000695 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000696 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000697 case eAddressTypeInvalid:
698 case eAddressTypeFile:
699 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000700
Greg Claytoncc4d0142012-02-17 07:49:44 +0000701 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000702 {
703 ExecutionContext exe_ctx (GetExecutionContextRef());
704
705 Address so_addr;
706 Target *target = exe_ctx.GetTargetPtr();
707 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000708 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000709 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000710 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000711 so_addr.Dump (&sstr,
712 exe_ctx.GetBestExecutionContextScope(),
713 Address::DumpStyleResolvedDescription,
714 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000715 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000716 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000717 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000718 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000719
Greg Claytoncc4d0142012-02-17 07:49:44 +0000720 case eAddressTypeHost:
721 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000722 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000723 }
724 if (sstr.GetSize() > 0)
725 {
726 destination.assign (1, '(');
727 destination.append (sstr.GetData(), sstr.GetSize());
728 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000729 }
730 }
731 }
732 }
733 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000734 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000735 return !destination.empty();
736}
737
738const char *
739ValueObject::GetSummaryAsCString ()
740{
741 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
742 {
743 GetSummaryAsCString(GetSummaryFormat().get(),
744 m_summary_str);
745 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000746 if (m_summary_str.empty())
747 return NULL;
748 return m_summary_str.c_str();
749}
750
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000751bool
752ValueObject::IsCStringContainer(bool check_pointer)
753{
754 clang_type_t elem_or_pointee_clang_type;
755 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
756 GetClangAST(),
757 &elem_or_pointee_clang_type));
758 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
759 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
760 if (!is_char_arr_ptr)
761 return false;
762 if (!check_pointer)
763 return true;
764 if (type_flags.Test(ClangASTContext::eTypeIsArray))
765 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000766 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000767 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000768 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000769 return (cstr_address != LLDB_INVALID_ADDRESS);
770}
771
Enrico Granata9128ee22011-09-06 19:20:51 +0000772size_t
773ValueObject::GetPointeeData (DataExtractor& data,
774 uint32_t item_idx,
775 uint32_t item_count)
776{
777 if (!IsPointerType() && !IsArrayType())
778 return 0;
779
780 if (item_count == 0)
781 return 0;
782
783 uint32_t stride = 0;
784
785 ClangASTType type(GetClangAST(),
786 GetClangType());
787
788 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
789 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
790
791 const uint64_t bytes = item_count * item_type_size;
792
793 const uint64_t offset = item_idx * item_type_size;
794
795 if (item_idx == 0 && item_count == 1) // simply a deref
796 {
797 if (IsPointerType())
798 {
799 Error error;
800 ValueObjectSP pointee_sp = Dereference(error);
801 if (error.Fail() || pointee_sp.get() == NULL)
802 return 0;
803 return pointee_sp->GetDataExtractor().Copy(data);
804 }
805 else
806 {
807 ValueObjectSP child_sp = GetChildAtIndex(0, true);
808 if (child_sp.get() == NULL)
809 return 0;
810 return child_sp->GetDataExtractor().Copy(data);
811 }
812 return true;
813 }
814 else /* (items > 1) */
815 {
816 Error error;
817 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
818 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
819
820 AddressType addr_type;
821 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
822
Enrico Granata9128ee22011-09-06 19:20:51 +0000823 switch (addr_type)
824 {
825 case eAddressTypeFile:
826 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000827 ModuleSP module_sp (GetModule());
828 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000829 {
830 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000831 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000832 ExecutionContext exe_ctx (GetExecutionContextRef());
833 Target* target = exe_ctx.GetTargetPtr();
834 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000835 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000836 heap_buf_ptr->SetByteSize(bytes);
837 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
838 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000839 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000840 data.SetData(data_sp);
841 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000842 }
843 }
844 }
845 }
846 break;
847 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000848 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000849 ExecutionContext exe_ctx (GetExecutionContextRef());
850 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000851 if (process)
852 {
853 heap_buf_ptr->SetByteSize(bytes);
854 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
855 if (error.Success())
856 {
857 data.SetData(data_sp);
858 return bytes_read;
859 }
860 }
861 }
862 break;
863 case eAddressTypeHost:
864 {
865 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
866 data.SetData(data_sp);
867 return bytes;
868 }
869 break;
870 case eAddressTypeInvalid:
871 default:
872 break;
873 }
874 }
875 return 0;
876}
877
878size_t
879ValueObject::GetData (DataExtractor& data)
880{
881 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000882 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +0000883 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000884 if (error.Fail())
885 return 0;
886 data.SetAddressByteSize(m_data.GetAddressByteSize());
887 data.SetByteOrder(m_data.GetByteOrder());
888 return data.GetByteSize();
889}
890
891// will compute strlen(str), but without consuming more than
892// maxlen bytes out of str (this serves the purpose of reading
893// chunks of a string without having to worry about
894// missing NULL terminators in the chunk)
895// of course, if strlen(str) > maxlen, the function will return
896// maxlen_value (which should be != maxlen, because that allows you
897// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
898static uint32_t
899strlen_or_inf (const char* str,
900 uint32_t maxlen,
901 uint32_t maxlen_value)
902{
903 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000904 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000905 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000906 while(*str)
907 {
908 len++;str++;
909 if (len > maxlen)
910 return maxlen_value;
911 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000912 }
913 return len;
914}
915
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000916void
Greg Claytoncc4d0142012-02-17 07:49:44 +0000917ValueObject::ReadPointedString (Stream& s,
918 Error& error,
919 uint32_t max_length,
920 bool honor_array,
921 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000922{
Greg Claytoncc4d0142012-02-17 07:49:44 +0000923 ExecutionContext exe_ctx (GetExecutionContextRef());
924 Target* target = exe_ctx.GetTargetPtr();
925
926 if (target && max_length == 0)
927 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000928
929 clang_type_t clang_type = GetClangType();
930 clang_type_t elem_or_pointee_clang_type;
931 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
932 GetClangAST(),
933 &elem_or_pointee_clang_type));
934 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
935 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
936 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000937 if (target == NULL)
938 {
939 s << "<no target to read from>";
940 }
941 else
942 {
943 addr_t cstr_address = LLDB_INVALID_ADDRESS;
944 AddressType cstr_address_type = eAddressTypeInvalid;
945
946 size_t cstr_len = 0;
947 bool capped_data = false;
948 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000949 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000950 // We have an array
951 cstr_len = ClangASTContext::GetArraySize (clang_type);
952 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000953 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000954 capped_data = true;
955 cstr_len = max_length;
956 }
957 cstr_address = GetAddressOf (true, &cstr_address_type);
958 }
959 else
960 {
961 // We have a pointer
962 cstr_address = GetPointerValue (&cstr_address_type);
963 }
964 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
965 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000966 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000967 DataExtractor data;
968 size_t bytes_read = 0;
969 if (cstr_len > 0 && honor_array)
970 {
971 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
972 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
973 GetPointeeData(data, 0, cstr_len);
974
975 if ((bytes_read = data.GetByteSize()) > 0)
976 {
977 s << '"';
978 data.Dump (&s,
979 0, // Start offset in "data"
980 item_format,
981 1, // Size of item (1 byte for a char!)
982 bytes_read, // How many bytes to print?
983 UINT32_MAX, // num per line
984 LLDB_INVALID_ADDRESS,// base address
985 0, // bitfield bit size
986 0); // bitfield bit offset
987 if (capped_data)
988 s << "...";
989 s << '"';
990 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000991 }
992 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000993 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000994 cstr_len = max_length;
995 const size_t k_max_buf_size = 64;
996
997 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000998
Greg Claytoncc4d0142012-02-17 07:49:44 +0000999 int cstr_len_displayed = -1;
1000 bool capped_cstr = false;
1001 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1002 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1003 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001004 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001005 const char *cstr = data.PeekCStr(0);
1006 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1007 if (len > k_max_buf_size)
1008 len = k_max_buf_size;
1009 if (cstr && cstr_len_displayed < 0)
1010 s << '"';
1011
1012 if (cstr_len_displayed < 0)
1013 cstr_len_displayed = len;
1014
1015 if (len == 0)
1016 break;
1017 cstr_len_displayed += len;
1018 if (len > bytes_read)
1019 len = bytes_read;
1020 if (len > cstr_len)
1021 len = cstr_len;
1022
1023 data.Dump (&s,
1024 0, // Start offset in "data"
1025 item_format,
1026 1, // Size of item (1 byte for a char!)
1027 len, // How many bytes to print?
1028 UINT32_MAX, // num per line
1029 LLDB_INVALID_ADDRESS,// base address
1030 0, // bitfield bit size
1031 0); // bitfield bit offset
1032
1033 if (len < k_max_buf_size)
1034 break;
1035
1036 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001037 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001038 capped_cstr = true;
1039 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001040 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001041
1042 cstr_len -= len;
1043 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001044 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001045
1046 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001047 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001048 s << '"';
1049 if (capped_cstr)
1050 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001051 }
1052 }
1053 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001054 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001055 }
1056 else
1057 {
1058 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001059 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001060 }
1061}
1062
Jim Ingham53c47f12010-09-10 23:12:17 +00001063const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001064ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001065{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001066
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001067 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001068 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001069
1070 if (!m_object_desc_str.empty())
1071 return m_object_desc_str.c_str();
1072
Greg Claytoncc4d0142012-02-17 07:49:44 +00001073 ExecutionContext exe_ctx (GetExecutionContextRef());
1074 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001075 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001076 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001077
Jim Ingham53c47f12010-09-10 23:12:17 +00001078 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001079
Greg Claytonafacd142011-09-02 01:15:17 +00001080 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001081 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1082
Jim Inghama2cf2632010-12-23 02:29:54 +00001083 if (runtime == NULL)
1084 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001085 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001086 clang_type_t opaque_qual_type = GetClangType();
1087 if (opaque_qual_type != NULL)
1088 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001089 bool is_signed;
1090 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1091 || ClangASTContext::IsPointerType (opaque_qual_type))
1092 {
Greg Claytonafacd142011-09-02 01:15:17 +00001093 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001094 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001095 }
1096 }
1097
Jim Ingham8d543de2011-03-31 23:01:21 +00001098 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001099 {
1100 m_object_desc_str.append (s.GetData());
1101 }
Sean Callanan672ad942010-10-23 00:18:49 +00001102
1103 if (m_object_desc_str.empty())
1104 return NULL;
1105 else
1106 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001107}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001108
Enrico Granata0c489f52012-03-01 04:24:26 +00001109bool
1110ValueObject::GetValueAsCString (lldb::Format format,
1111 std::string& destination)
1112{
1113 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1114 UpdateValueIfNeeded(false))
1115 {
1116 const Value::ContextType context_type = m_value.GetContextType();
1117
1118 switch (context_type)
1119 {
1120 case Value::eContextTypeClangType:
1121 case Value::eContextTypeLLDBType:
1122 case Value::eContextTypeVariable:
1123 {
1124 clang_type_t clang_type = GetClangType ();
1125 if (clang_type)
1126 {
1127 StreamString sstr;
1128 ExecutionContext exe_ctx (GetExecutionContextRef());
1129 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1130 clang_type, // The clang type to display
1131 &sstr,
1132 format, // Format to display this type with
1133 m_data, // Data to extract from
1134 0, // Byte offset into "m_data"
1135 GetByteSize(), // Byte size of item in "m_data"
1136 GetBitfieldBitSize(), // Bitfield bit size
1137 GetBitfieldBitOffset(), // Bitfield bit offset
1138 exe_ctx.GetBestExecutionContextScope());
1139 // Don't set the m_error to anything here otherwise
1140 // we won't be able to re-format as anything else. The
1141 // code for ClangASTType::DumpTypeValue() should always
1142 // return something, even if that something contains
1143 // an error messsage. "m_error" is used to detect errors
1144 // when reading the valid object, not for formatting errors.
1145 if (sstr.GetString().empty())
1146 destination.clear();
1147 else
1148 destination.swap(sstr.GetString());
1149 }
1150 }
1151 break;
1152
1153 case Value::eContextTypeRegisterInfo:
1154 {
1155 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1156 if (reg_info)
1157 {
1158 ExecutionContext exe_ctx (GetExecutionContextRef());
1159
1160 StreamString reg_sstr;
1161 m_data.Dump (&reg_sstr,
1162 0,
1163 format,
1164 reg_info->byte_size,
1165 1,
1166 UINT32_MAX,
1167 LLDB_INVALID_ADDRESS,
1168 0,
1169 0,
1170 exe_ctx.GetBestExecutionContextScope());
1171 destination.swap(reg_sstr.GetString());
1172 }
1173 }
1174 break;
1175
1176 default:
1177 break;
1178 }
1179 return !destination.empty();
1180 }
1181 else
1182 return false;
1183}
1184
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001185const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001186ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001187{
Enrico Granata0c489f52012-03-01 04:24:26 +00001188 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001189 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001190 lldb::Format my_format = GetFormat();
1191 if (m_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001192 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001193 if (m_type_format_sp)
1194 my_format = m_type_format_sp->GetFormat();
1195 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001196 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001197 if (m_is_bitfield_for_scalar)
1198 my_format = eFormatUnsigned;
1199 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001200 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001201 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001202 {
1203 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1204 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001205 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001206 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001207 else
1208 {
1209 clang_type_t clang_type = GetClangType ();
1210 my_format = ClangASTType::GetFormat(clang_type);
1211 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212 }
1213 }
1214 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001215 if (GetValueAsCString(my_format, m_value_str))
1216 {
1217 if (!m_value_did_change && m_old_value_valid)
1218 {
1219 // The value was gotten successfully, so we consider the
1220 // value as changed if the value string differs
1221 SetValueDidChange (m_old_value_str != m_value_str);
1222 }
1223 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001224 }
1225 if (m_value_str.empty())
1226 return NULL;
1227 return m_value_str.c_str();
1228}
1229
Enrico Granatac3e320a2011-08-02 17:27:39 +00001230// if > 8bytes, 0 is returned. this method should mostly be used
1231// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001232uint64_t
1233ValueObject::GetValueAsUnsigned (uint64_t fail_value)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001234{
1235 // If our byte size is zero this is an aggregate type that has children
1236 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1237 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001238 Scalar scalar;
1239 if (ResolveValue (scalar))
1240 return scalar.GetRawBits64(fail_value);
Enrico Granatac3e320a2011-08-02 17:27:39 +00001241 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001242 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001243}
1244
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001245bool
1246ValueObject::GetPrintableRepresentation(Stream& s,
1247 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001248 Format custom_format)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001249{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001250
Greg Claytonafacd142011-09-02 01:15:17 +00001251 if (custom_format != eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001252 SetFormat(custom_format);
1253
1254 const char * return_value;
Enrico Granatacd1c0232011-08-04 23:37:18 +00001255 std::string alloc_mem;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001256
1257 switch(val_obj_display)
1258 {
1259 case eDisplayValue:
1260 return_value = GetValueAsCString();
1261 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001262
Enrico Granata0a3958e2011-07-02 00:25:22 +00001263 case eDisplaySummary:
Greg Clayton48ca8b82012-01-07 20:58:07 +00001264 return_value = GetSummaryAsCString();
1265 break;
1266
Enrico Granata0a3958e2011-07-02 00:25:22 +00001267 case eDisplayLanguageSpecific:
1268 return_value = GetObjectDescription();
1269 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001270
Enrico Granataf2bbf712011-07-15 02:26:42 +00001271 case eDisplayLocation:
1272 return_value = GetLocationAsCString();
1273 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001274
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001275 case eDisplayChildrenCount:
Greg Clayton48ca8b82012-01-07 20:58:07 +00001276 {
1277 alloc_mem.resize(512);
1278 return_value = &alloc_mem[0];
1279 int count = GetNumChildren();
1280 snprintf((char*)return_value, 512, "%d", count);
1281 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001282 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001283
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001284 case eDisplayType:
1285 return_value = GetTypeName().AsCString();
1286 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001287
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001288 default:
1289 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001290 }
1291
Enrico Granata855cd902011-09-06 22:59:55 +00001292 if (!return_value)
Enrico Granata9fc19442011-07-06 02:13:41 +00001293 {
Enrico Granata9fc19442011-07-06 02:13:41 +00001294 if (val_obj_display == eDisplayValue)
Enrico Granata855cd902011-09-06 22:59:55 +00001295 return_value = GetSummaryAsCString();
Enrico Granata9fc19442011-07-06 02:13:41 +00001296 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +00001297 {
1298 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1299 {
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001300 // this thing has no value, and it seems to have no summary
1301 // some combination of unitialized data and other factors can also
Enrico Granata855cd902011-09-06 22:59:55 +00001302 // raise this condition, so let's print a nice generic description
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001303 {
1304 alloc_mem.resize(684);
1305 return_value = &alloc_mem[0];
1306 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1307 }
Enrico Granatae992a082011-07-22 17:03:19 +00001308 }
1309 else
1310 return_value = GetValueAsCString();
1311 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001312 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001313
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001314 if (return_value)
1315 s.PutCString(return_value);
1316 else
Enrico Granata88da35f2011-08-23 21:26:09 +00001317 {
1318 if (m_error.Fail())
1319 s.Printf("<%s>", m_error.AsCString());
1320 else if (val_obj_display == eDisplaySummary)
1321 s.PutCString("<no summary available>");
1322 else if (val_obj_display == eDisplayValue)
1323 s.PutCString("<no value available>");
1324 else if (val_obj_display == eDisplayLanguageSpecific)
1325 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1326 else
1327 s.PutCString("<no printable representation>");
1328 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001329
1330 // we should only return false here if we could not do *anything*
1331 // even if we have an error message as output, that's a success
1332 // from our callers' perspective, so return true
1333 return true;
1334
Enrico Granata0a3958e2011-07-02 00:25:22 +00001335}
1336
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001337// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1338// this call up to date by returning true for your new special cases. We will eventually move
1339// to checking this call result before trying to display special cases
1340bool
1341ValueObject::HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001342 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001343{
1344 clang_type_t elem_or_pointee_type;
1345 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1346
1347 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1348 && val_obj_display == ValueObject::eDisplayValue)
1349 {
1350 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001351 (custom_format == eFormatCString ||
1352 custom_format == eFormatCharArray ||
1353 custom_format == eFormatChar ||
1354 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001355 return true;
1356
1357 if (flags.Test(ClangASTContext::eTypeIsArray))
1358 {
Greg Claytonafacd142011-09-02 01:15:17 +00001359 if ((custom_format == eFormatBytes) ||
1360 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001361 return true;
1362
Greg Claytonafacd142011-09-02 01:15:17 +00001363 if ((custom_format == eFormatVectorOfChar) ||
1364 (custom_format == eFormatVectorOfFloat32) ||
1365 (custom_format == eFormatVectorOfFloat64) ||
1366 (custom_format == eFormatVectorOfSInt16) ||
1367 (custom_format == eFormatVectorOfSInt32) ||
1368 (custom_format == eFormatVectorOfSInt64) ||
1369 (custom_format == eFormatVectorOfSInt8) ||
1370 (custom_format == eFormatVectorOfUInt128) ||
1371 (custom_format == eFormatVectorOfUInt16) ||
1372 (custom_format == eFormatVectorOfUInt32) ||
1373 (custom_format == eFormatVectorOfUInt64) ||
1374 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001375 return true;
1376 }
1377 }
1378 return false;
1379}
1380
Enrico Granata9fc19442011-07-06 02:13:41 +00001381bool
1382ValueObject::DumpPrintableRepresentation(Stream& s,
1383 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001384 Format custom_format,
Enrico Granata85933ed2011-08-18 16:38:26 +00001385 bool only_special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001386{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001387
1388 clang_type_t elem_or_pointee_type;
1389 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001390
Enrico Granataf4efecd2011-07-12 22:56:10 +00001391 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1392 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001393 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001394 // when being asked to get a printable display an array or pointer type directly,
1395 // try to "do the right thing"
1396
1397 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001398 (custom_format == eFormatCString ||
1399 custom_format == eFormatCharArray ||
1400 custom_format == eFormatChar ||
1401 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001402 {
1403 Error error;
1404 ReadPointedString(s,
1405 error,
1406 0,
Greg Claytonafacd142011-09-02 01:15:17 +00001407 (custom_format == eFormatVectorOfChar) ||
1408 (custom_format == eFormatCharArray));
Enrico Granataf4efecd2011-07-12 22:56:10 +00001409 return !error.Fail();
1410 }
1411
Greg Claytonafacd142011-09-02 01:15:17 +00001412 if (custom_format == eFormatEnum)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001413 return false;
1414
1415 // this only works for arrays, because I have no way to know when
1416 // the pointed memory ends, and no special \0 end of data marker
1417 if (flags.Test(ClangASTContext::eTypeIsArray))
1418 {
Greg Claytonafacd142011-09-02 01:15:17 +00001419 if ((custom_format == eFormatBytes) ||
1420 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001421 {
1422 uint32_t count = GetNumChildren();
1423
1424 s << '[';
1425 for (uint32_t low = 0; low < count; low++)
1426 {
1427
1428 if (low)
1429 s << ',';
1430
1431 ValueObjectSP child = GetChildAtIndex(low,true);
1432 if (!child.get())
1433 {
Enrico Granatae992a082011-07-22 17:03:19 +00001434 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001435 continue;
1436 }
1437 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1438 }
1439
1440 s << ']';
1441
1442 return true;
1443 }
1444
Greg Claytonafacd142011-09-02 01:15:17 +00001445 if ((custom_format == eFormatVectorOfChar) ||
1446 (custom_format == eFormatVectorOfFloat32) ||
1447 (custom_format == eFormatVectorOfFloat64) ||
1448 (custom_format == eFormatVectorOfSInt16) ||
1449 (custom_format == eFormatVectorOfSInt32) ||
1450 (custom_format == eFormatVectorOfSInt64) ||
1451 (custom_format == eFormatVectorOfSInt8) ||
1452 (custom_format == eFormatVectorOfUInt128) ||
1453 (custom_format == eFormatVectorOfUInt16) ||
1454 (custom_format == eFormatVectorOfUInt32) ||
1455 (custom_format == eFormatVectorOfUInt64) ||
1456 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001457 {
1458 uint32_t count = GetNumChildren();
1459
Greg Claytonafacd142011-09-02 01:15:17 +00001460 Format format = FormatManager::GetSingleItemFormat(custom_format);
Enrico Granataf4efecd2011-07-12 22:56:10 +00001461
1462 s << '[';
1463 for (uint32_t low = 0; low < count; low++)
1464 {
1465
1466 if (low)
1467 s << ',';
1468
1469 ValueObjectSP child = GetChildAtIndex(low,true);
1470 if (!child.get())
1471 {
Enrico Granatae992a082011-07-22 17:03:19 +00001472 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001473 continue;
1474 }
1475 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1476 }
1477
1478 s << ']';
1479
1480 return true;
1481 }
1482 }
1483
Greg Claytonafacd142011-09-02 01:15:17 +00001484 if ((custom_format == eFormatBoolean) ||
1485 (custom_format == eFormatBinary) ||
1486 (custom_format == eFormatChar) ||
1487 (custom_format == eFormatCharPrintable) ||
1488 (custom_format == eFormatComplexFloat) ||
1489 (custom_format == eFormatDecimal) ||
1490 (custom_format == eFormatHex) ||
1491 (custom_format == eFormatFloat) ||
1492 (custom_format == eFormatOctal) ||
1493 (custom_format == eFormatOSType) ||
1494 (custom_format == eFormatUnicode16) ||
1495 (custom_format == eFormatUnicode32) ||
1496 (custom_format == eFormatUnsigned) ||
1497 (custom_format == eFormatPointer) ||
1498 (custom_format == eFormatComplexInteger) ||
1499 (custom_format == eFormatComplex) ||
1500 (custom_format == eFormatDefault)) // use the [] operator
Enrico Granataf4efecd2011-07-12 22:56:10 +00001501 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001502 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001503
1504 if (only_special)
1505 return false;
1506
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001507 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001508 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001509 SetFormat(eFormatDefault);
1510 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001511}
1512
Greg Clayton737b9322010-09-13 03:32:57 +00001513addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001514ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001515{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001516 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001517 return LLDB_INVALID_ADDRESS;
1518
Greg Clayton73b472d2010-10-27 03:32:59 +00001519 switch (m_value.GetValueType())
1520 {
1521 case Value::eValueTypeScalar:
1522 if (scalar_is_load_address)
1523 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001524 if(address_type)
1525 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001526 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1527 }
1528 break;
1529
1530 case Value::eValueTypeLoadAddress:
1531 case Value::eValueTypeFileAddress:
1532 case Value::eValueTypeHostAddress:
1533 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001534 if(address_type)
1535 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001536 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1537 }
1538 break;
1539 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001540 if (address_type)
1541 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001542 return LLDB_INVALID_ADDRESS;
1543}
1544
1545addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001546ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001547{
Greg Claytonafacd142011-09-02 01:15:17 +00001548 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001549 if(address_type)
1550 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001551
Enrico Granatac3e320a2011-08-02 17:27:39 +00001552 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001553 return address;
1554
Greg Clayton73b472d2010-10-27 03:32:59 +00001555 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001556 {
1557 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001558 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001559 break;
1560
Enrico Granata9128ee22011-09-06 19:20:51 +00001561 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001562 case Value::eValueTypeLoadAddress:
1563 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001564 {
1565 uint32_t data_offset = 0;
1566 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001567 }
1568 break;
1569 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001570
Enrico Granata9128ee22011-09-06 19:20:51 +00001571 if (address_type)
1572 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001573
Greg Clayton737b9322010-09-13 03:32:57 +00001574 return address;
1575}
1576
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001577bool
Jim Ingham6035b672011-03-31 00:19:25 +00001578ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001579{
1580 // Make sure our value is up to date first so that our location and location
1581 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001582 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001583 return false;
1584
1585 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001586 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001587
Greg Claytonb1320972010-07-14 00:18:15 +00001588 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001589
Jim Ingham16e0c682011-08-12 23:34:31 +00001590 Value::ValueType value_type = m_value.GetValueType();
1591
1592 if (value_type == Value::eValueTypeScalar)
1593 {
1594 // If the value is already a scalar, then let the scalar change itself:
1595 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1596 }
1597 else if (byte_size <= Scalar::GetMaxByteSize())
1598 {
1599 // If the value fits in a scalar, then make a new scalar and again let the
1600 // scalar code do the conversion, then figure out where to put the new value.
1601 Scalar new_scalar;
1602 Error error;
1603 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1604 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001605 {
Jim Ingham4b536182011-08-09 02:12:22 +00001606 switch (value_type)
1607 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001608 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001609 {
1610 // If it is a load address, then the scalar value is the storage location
1611 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001612 ExecutionContext exe_ctx (GetExecutionContextRef());
1613 Process *process = exe_ctx.GetProcessPtr();
1614 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001615 {
Greg Claytonafacd142011-09-02 01:15:17 +00001616 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001617 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1618 new_scalar,
1619 byte_size,
1620 error);
Jim Ingham16e0c682011-08-12 23:34:31 +00001621 if (!error.Success() || bytes_written != byte_size)
1622 return false;
1623 }
1624 }
Jim Ingham4b536182011-08-09 02:12:22 +00001625 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001626 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001627 {
1628 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1629 DataExtractor new_data;
1630 new_data.SetByteOrder (m_data.GetByteOrder());
1631
1632 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1633 m_data.SetData(buffer_sp, 0);
1634 bool success = new_scalar.GetData(new_data);
1635 if (success)
1636 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001637 new_data.CopyByteOrderedData (0,
1638 byte_size,
1639 const_cast<uint8_t *>(m_data.GetDataStart()),
1640 byte_size,
1641 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001642 }
1643 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1644
1645 }
Jim Ingham4b536182011-08-09 02:12:22 +00001646 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001647 case Value::eValueTypeFileAddress:
1648 case Value::eValueTypeScalar:
Jim Ingham16e0c682011-08-12 23:34:31 +00001649 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001650 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001651 }
1652 else
1653 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001654 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001655 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001656 }
1657 else
1658 {
1659 // We don't support setting things bigger than a scalar at present.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001660 return false;
1661 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001662
1663 // If we have reached this point, then we have successfully changed the value.
1664 SetNeedsUpdate();
1665 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001666}
1667
Greg Clayton81e871e2012-02-04 02:27:34 +00001668bool
1669ValueObject::GetDeclaration (Declaration &decl)
1670{
1671 decl.Clear();
1672 return false;
1673}
1674
Greg Claytonafacd142011-09-02 01:15:17 +00001675LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001676ValueObject::GetObjectRuntimeLanguage ()
1677{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001678 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1679 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001680}
1681
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001682void
Jim Ingham58b59f92011-04-22 23:53:53 +00001683ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001684{
Jim Ingham58b59f92011-04-22 23:53:53 +00001685 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001686}
1687
1688ValueObjectSP
1689ValueObject::GetSyntheticChild (const ConstString &key) const
1690{
1691 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001692 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001693 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001694 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001695 return synthetic_child_sp;
1696}
1697
1698bool
1699ValueObject::IsPointerType ()
1700{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001701 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001702}
1703
Jim Inghamb7603bb2011-03-18 00:05:18 +00001704bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001705ValueObject::IsArrayType ()
1706{
1707 return ClangASTContext::IsArrayType (GetClangType());
1708}
1709
1710bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001711ValueObject::IsScalarType ()
1712{
1713 return ClangASTContext::IsScalarType (GetClangType());
1714}
1715
1716bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001717ValueObject::IsIntegerType (bool &is_signed)
1718{
1719 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1720}
Greg Clayton73b472d2010-10-27 03:32:59 +00001721
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001722bool
1723ValueObject::IsPointerOrReferenceType ()
1724{
Greg Clayton007d5be2011-05-30 00:49:24 +00001725 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1726}
1727
1728bool
1729ValueObject::IsPossibleCPlusPlusDynamicType ()
1730{
1731 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001732}
1733
Greg Claytondea8cb42011-06-29 22:09:02 +00001734bool
1735ValueObject::IsPossibleDynamicType ()
1736{
1737 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1738}
1739
Greg Claytonafacd142011-09-02 01:15:17 +00001740ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001741ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1742{
1743 if (IsArrayType())
1744 return GetSyntheticArrayMemberFromArray(index, can_create);
1745
1746 if (IsPointerType())
1747 return GetSyntheticArrayMemberFromPointer(index, can_create);
1748
1749 return ValueObjectSP();
1750
1751}
1752
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001753ValueObjectSP
1754ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1755{
1756 ValueObjectSP synthetic_child_sp;
1757 if (IsPointerType ())
1758 {
1759 char index_str[64];
1760 snprintf(index_str, sizeof(index_str), "[%i]", index);
1761 ConstString index_const_str(index_str);
1762 // Check if we have already created a synthetic array member in this
1763 // valid object. If we have we will re-use it.
1764 synthetic_child_sp = GetSyntheticChild (index_const_str);
1765 if (!synthetic_child_sp)
1766 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001767 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001768 // We haven't made a synthetic array member for INDEX yet, so
1769 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001770 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001771
1772 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001773 if (synthetic_child)
1774 {
1775 AddSyntheticChild(index_const_str, synthetic_child);
1776 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001777 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001778 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001779 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001780 }
1781 }
1782 return synthetic_child_sp;
1783}
Jim Ingham22777012010-09-23 02:01:19 +00001784
Greg Claytondaf515f2011-07-09 20:12:33 +00001785// This allows you to create an array member using and index
1786// that doesn't not fall in the normal bounds of the array.
1787// Many times structure can be defined as:
1788// struct Collection
1789// {
1790// uint32_t item_count;
1791// Item item_array[0];
1792// };
1793// The size of the "item_array" is 1, but many times in practice
1794// there are more items in "item_array".
1795
1796ValueObjectSP
1797ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1798{
1799 ValueObjectSP synthetic_child_sp;
1800 if (IsArrayType ())
1801 {
1802 char index_str[64];
1803 snprintf(index_str, sizeof(index_str), "[%i]", index);
1804 ConstString index_const_str(index_str);
1805 // Check if we have already created a synthetic array member in this
1806 // valid object. If we have we will re-use it.
1807 synthetic_child_sp = GetSyntheticChild (index_const_str);
1808 if (!synthetic_child_sp)
1809 {
1810 ValueObject *synthetic_child;
1811 // We haven't made a synthetic array member for INDEX yet, so
1812 // lets make one and cache it for any future reference.
1813 synthetic_child = CreateChildAtIndex(0, true, index);
1814
1815 // Cache the value if we got one back...
1816 if (synthetic_child)
1817 {
1818 AddSyntheticChild(index_const_str, synthetic_child);
1819 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001820 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001821 synthetic_child_sp->m_is_array_item_for_pointer = true;
1822 }
1823 }
1824 }
1825 return synthetic_child_sp;
1826}
1827
Enrico Granata9fc19442011-07-06 02:13:41 +00001828ValueObjectSP
1829ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1830{
1831 ValueObjectSP synthetic_child_sp;
1832 if (IsScalarType ())
1833 {
1834 char index_str[64];
1835 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1836 ConstString index_const_str(index_str);
1837 // Check if we have already created a synthetic array member in this
1838 // valid object. If we have we will re-use it.
1839 synthetic_child_sp = GetSyntheticChild (index_const_str);
1840 if (!synthetic_child_sp)
1841 {
1842 ValueObjectChild *synthetic_child;
1843 // We haven't made a synthetic array member for INDEX yet, so
1844 // lets make one and cache it for any future reference.
1845 synthetic_child = new ValueObjectChild(*this,
1846 GetClangAST(),
1847 GetClangType(),
1848 index_const_str,
1849 GetByteSize(),
1850 0,
1851 to-from+1,
1852 from,
1853 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001854 false,
1855 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001856
1857 // Cache the value if we got one back...
1858 if (synthetic_child)
1859 {
1860 AddSyntheticChild(index_const_str, synthetic_child);
1861 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001862 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001863 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1864 }
1865 }
1866 }
1867 return synthetic_child_sp;
1868}
1869
Greg Claytonafacd142011-09-02 01:15:17 +00001870ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001871ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1872{
1873 ValueObjectSP synthetic_child_sp;
1874 if (IsArrayType () || IsPointerType ())
1875 {
1876 char index_str[64];
1877 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1878 ConstString index_const_str(index_str);
1879 // Check if we have already created a synthetic array member in this
1880 // valid object. If we have we will re-use it.
1881 synthetic_child_sp = GetSyntheticChild (index_const_str);
1882 if (!synthetic_child_sp)
1883 {
1884 ValueObjectSynthetic *synthetic_child;
1885
1886 // We haven't made a synthetic array member for INDEX yet, so
1887 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001888 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001889 view->AddRange(from,to);
1890 SyntheticChildrenSP view_sp(view);
1891 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1892
1893 // Cache the value if we got one back...
1894 if (synthetic_child)
1895 {
1896 AddSyntheticChild(index_const_str, synthetic_child);
1897 synthetic_child_sp = synthetic_child->GetSP();
1898 synthetic_child_sp->SetName(ConstString(index_str));
1899 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1900 }
1901 }
1902 }
1903 return synthetic_child_sp;
1904}
1905
Greg Claytonafacd142011-09-02 01:15:17 +00001906ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001907ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1908{
1909
1910 ValueObjectSP synthetic_child_sp;
1911
1912 char name_str[64];
1913 snprintf(name_str, sizeof(name_str), "@%i", offset);
1914 ConstString name_const_str(name_str);
1915
1916 // Check if we have already created a synthetic array member in this
1917 // valid object. If we have we will re-use it.
1918 synthetic_child_sp = GetSyntheticChild (name_const_str);
1919
1920 if (synthetic_child_sp.get())
1921 return synthetic_child_sp;
1922
1923 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001924 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001925
1926 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1927 type.GetASTContext(),
1928 type.GetOpaqueQualType(),
1929 name_const_str,
1930 type.GetTypeByteSize(),
1931 offset,
1932 0,
1933 0,
1934 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001935 false,
1936 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001937 if (synthetic_child)
1938 {
1939 AddSyntheticChild(name_const_str, synthetic_child);
1940 synthetic_child_sp = synthetic_child->GetSP();
1941 synthetic_child_sp->SetName(name_const_str);
1942 synthetic_child_sp->m_is_child_at_offset = true;
1943 }
1944 return synthetic_child_sp;
1945}
1946
Enrico Granatad55546b2011-07-22 00:16:08 +00001947// your expression path needs to have a leading . or ->
1948// (unless it somehow "looks like" an array, in which case it has
1949// a leading [ symbol). while the [ is meaningful and should be shown
1950// to the user, . and -> are just parser design, but by no means
1951// added information for the user.. strip them off
1952static const char*
1953SkipLeadingExpressionPathSeparators(const char* expression)
1954{
1955 if (!expression || !expression[0])
1956 return expression;
1957 if (expression[0] == '.')
1958 return expression+1;
1959 if (expression[0] == '-' && expression[1] == '>')
1960 return expression+2;
1961 return expression;
1962}
1963
Greg Claytonafacd142011-09-02 01:15:17 +00001964ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00001965ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1966{
1967 ValueObjectSP synthetic_child_sp;
1968 ConstString name_const_string(expression);
1969 // Check if we have already created a synthetic array member in this
1970 // valid object. If we have we will re-use it.
1971 synthetic_child_sp = GetSyntheticChild (name_const_string);
1972 if (!synthetic_child_sp)
1973 {
1974 // We haven't made a synthetic array member for expression yet, so
1975 // lets make one and cache it for any future reference.
1976 synthetic_child_sp = GetValueForExpressionPath(expression);
1977
1978 // Cache the value if we got one back...
1979 if (synthetic_child_sp.get())
1980 {
1981 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001982 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001983 synthetic_child_sp->m_is_expression_path_child = true;
1984 }
1985 }
1986 return synthetic_child_sp;
1987}
1988
1989void
Greg Claytonafacd142011-09-02 01:15:17 +00001990ValueObject::CalculateSyntheticValue (SyntheticValueType use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00001991{
Greg Claytonafacd142011-09-02 01:15:17 +00001992 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001993 return;
1994
Enrico Granatac3e320a2011-08-02 17:27:39 +00001995 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001996
Enrico Granata0c489f52012-03-01 04:24:26 +00001997 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00001998 return;
1999
Enrico Granataa37a0652011-07-24 00:14:56 +00002000 if (m_synthetic_value == NULL)
Enrico Granata0c489f52012-03-01 04:24:26 +00002001 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002002
2003}
2004
Jim Ingham78a685a2011-04-16 00:01:13 +00002005void
Greg Claytonafacd142011-09-02 01:15:17 +00002006ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002007{
Greg Claytonafacd142011-09-02 01:15:17 +00002008 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002009 return;
2010
Jim Ingham58b59f92011-04-22 23:53:53 +00002011 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002012 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002013 ExecutionContext exe_ctx (GetExecutionContextRef());
2014 Process *process = exe_ctx.GetProcessPtr();
2015 if (process)
Jim Ingham78a685a2011-04-16 00:01:13 +00002016 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002017 bool worth_having_dynamic_value = false;
Jim Ingham78a685a2011-04-16 00:01:13 +00002018
Greg Claytoncc4d0142012-02-17 07:49:44 +00002019
2020 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
2021 // hard code this everywhere.
2022 LanguageType known_type = GetObjectRuntimeLanguage();
2023 if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
Jim Ingham78a685a2011-04-16 00:01:13 +00002024 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002025 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
2026 if (runtime)
2027 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00002028 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00002029 else
2030 {
2031 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus);
2032 if (cpp_runtime)
2033 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
2034
2035 if (!worth_having_dynamic_value)
2036 {
2037 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC);
2038 if (objc_runtime)
2039 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
2040 }
2041 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002042
Greg Claytoncc4d0142012-02-17 07:49:44 +00002043 if (worth_having_dynamic_value)
2044 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
2045 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002046 }
2047}
2048
Jim Ingham58b59f92011-04-22 23:53:53 +00002049ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002050ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002051{
Greg Claytonafacd142011-09-02 01:15:17 +00002052 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002053 return ValueObjectSP();
2054
2055 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002056 {
Jim Ingham2837b762011-05-04 03:43:18 +00002057 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002058 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002059 if (m_dynamic_value)
2060 return m_dynamic_value->GetSP();
2061 else
2062 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002063}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002064
Jim Ingham60dbabb2011-12-08 19:44:08 +00002065ValueObjectSP
2066ValueObject::GetStaticValue()
2067{
2068 return GetSP();
2069}
2070
Enrico Granatad55546b2011-07-22 00:16:08 +00002071// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
2072// or we do not really want a dynamic VO. this method instead returns this object
2073// itself when making it synthetic has no meaning. this makes it much simpler
2074// to replace the SyntheticValue for the ValueObject
2075ValueObjectSP
2076ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
2077{
Greg Claytonafacd142011-09-02 01:15:17 +00002078 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00002079 return GetSP();
2080
Enrico Granatac3e320a2011-08-02 17:27:39 +00002081 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00002082
Enrico Granata0c489f52012-03-01 04:24:26 +00002083 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002084 return GetSP();
2085
2086 CalculateSyntheticValue(use_synthetic);
2087
2088 if (m_synthetic_value)
2089 return m_synthetic_value->GetSP();
2090 else
2091 return GetSP();
2092}
2093
Greg Claytone221f822011-01-21 01:59:00 +00002094bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002095ValueObject::HasSyntheticValue()
2096{
2097 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2098
Enrico Granata0c489f52012-03-01 04:24:26 +00002099 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002100 return false;
2101
Greg Claytonafacd142011-09-02 01:15:17 +00002102 CalculateSyntheticValue(eUseSyntheticFilter);
Enrico Granata27b625e2011-08-09 01:04:56 +00002103
2104 if (m_synthetic_value)
2105 return true;
2106 else
2107 return false;
2108}
2109
2110bool
Greg Claytone221f822011-01-21 01:59:00 +00002111ValueObject::GetBaseClassPath (Stream &s)
2112{
2113 if (IsBaseClass())
2114 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002115 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002116 clang_type_t clang_type = GetClangType();
2117 std::string cxx_class_name;
2118 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2119 if (this_had_base_class)
2120 {
2121 if (parent_had_base_class)
2122 s.PutCString("::");
2123 s.PutCString(cxx_class_name.c_str());
2124 }
2125 return parent_had_base_class || this_had_base_class;
2126 }
2127 return false;
2128}
2129
2130
2131ValueObject *
2132ValueObject::GetNonBaseClassParent()
2133{
Jim Ingham78a685a2011-04-16 00:01:13 +00002134 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002135 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002136 if (GetParent()->IsBaseClass())
2137 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002138 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002139 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002140 }
2141 return NULL;
2142}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002143
2144void
Enrico Granata4becb372011-06-29 22:27:15 +00002145ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002146{
Greg Claytone221f822011-01-21 01:59:00 +00002147 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002148
Enrico Granata85933ed2011-08-18 16:38:26 +00002149 if (is_deref_of_parent && epformat == eDereferencePointers)
2150 {
Enrico Granata4becb372011-06-29 22:27:15 +00002151 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2152 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2153 // the eHonorPointers mode is meant to produce strings in this latter format
2154 s.PutCString("*(");
2155 }
Greg Claytone221f822011-01-21 01:59:00 +00002156
Enrico Granata4becb372011-06-29 22:27:15 +00002157 ValueObject* parent = GetParent();
2158
2159 if (parent)
2160 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002161
2162 // if we are a deref_of_parent just because we are synthetic array
2163 // members made up to allow ptr[%d] syntax to work in variable
2164 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00002165 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002166 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002167
Greg Claytone221f822011-01-21 01:59:00 +00002168 if (!IsBaseClass())
2169 {
2170 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002171 {
Greg Claytone221f822011-01-21 01:59:00 +00002172 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2173 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002174 {
Greg Claytone221f822011-01-21 01:59:00 +00002175 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2176 if (non_base_class_parent_clang_type)
2177 {
2178 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2179
Enrico Granata9dd75c82011-07-15 23:30:15 +00002180 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002181 {
2182 s.PutCString("->");
2183 }
Enrico Granata4becb372011-06-29 22:27:15 +00002184 else
2185 {
2186 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2187 {
2188 s.PutCString("->");
2189 }
2190 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2191 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2192 {
2193 s.PutChar('.');
2194 }
Greg Claytone221f822011-01-21 01:59:00 +00002195 }
2196 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002197 }
Greg Claytone221f822011-01-21 01:59:00 +00002198
2199 const char *name = GetName().GetCString();
2200 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002201 {
Greg Claytone221f822011-01-21 01:59:00 +00002202 if (qualify_cxx_base_classes)
2203 {
2204 if (GetBaseClassPath (s))
2205 s.PutCString("::");
2206 }
2207 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002208 }
2209 }
2210 }
2211
Enrico Granata85933ed2011-08-18 16:38:26 +00002212 if (is_deref_of_parent && epformat == eDereferencePointers)
2213 {
Greg Claytone221f822011-01-21 01:59:00 +00002214 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002215 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002216}
2217
Greg Claytonafacd142011-09-02 01:15:17 +00002218ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002219ValueObject::GetValueForExpressionPath(const char* expression,
2220 const char** first_unparsed,
2221 ExpressionPathScanEndReason* reason_to_stop,
2222 ExpressionPathEndResultType* final_value_type,
2223 const GetValueForExpressionPathOptions& options,
2224 ExpressionPathAftermath* final_task_on_target)
2225{
2226
2227 const char* dummy_first_unparsed;
2228 ExpressionPathScanEndReason dummy_reason_to_stop;
2229 ExpressionPathEndResultType dummy_final_value_type;
2230 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2231
2232 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2233 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2234 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2235 final_value_type ? final_value_type : &dummy_final_value_type,
2236 options,
2237 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2238
2239 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002240 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002241
2242 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 +00002243 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002244 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002245 {
2246 Error error;
2247 ValueObjectSP final_value = ret_val->Dereference(error);
2248 if (error.Fail() || !final_value.get())
2249 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002250 if (reason_to_stop)
2251 *reason_to_stop = ValueObject::eDereferencingFailed;
2252 if (final_value_type)
2253 *final_value_type = ValueObject::eInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002254 return ValueObjectSP();
2255 }
2256 else
2257 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002258 if (final_task_on_target)
2259 *final_task_on_target = ValueObject::eNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002260 return final_value;
2261 }
2262 }
2263 if (*final_task_on_target == ValueObject::eTakeAddress)
2264 {
2265 Error error;
2266 ValueObjectSP final_value = ret_val->AddressOf(error);
2267 if (error.Fail() || !final_value.get())
2268 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002269 if (reason_to_stop)
2270 *reason_to_stop = ValueObject::eTakingAddressFailed;
2271 if (final_value_type)
2272 *final_value_type = ValueObject::eInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002273 return ValueObjectSP();
2274 }
2275 else
2276 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002277 if (final_task_on_target)
2278 *final_task_on_target = ValueObject::eNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002279 return final_value;
2280 }
2281 }
2282 }
2283 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2284}
2285
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002286int
2287ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002288 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002289 const char** first_unparsed,
2290 ExpressionPathScanEndReason* reason_to_stop,
2291 ExpressionPathEndResultType* final_value_type,
2292 const GetValueForExpressionPathOptions& options,
2293 ExpressionPathAftermath* final_task_on_target)
2294{
2295 const char* dummy_first_unparsed;
2296 ExpressionPathScanEndReason dummy_reason_to_stop;
2297 ExpressionPathEndResultType dummy_final_value_type;
2298 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2299
2300 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2301 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2302 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2303 final_value_type ? final_value_type : &dummy_final_value_type,
2304 options,
2305 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2306
2307 if (!ret_val.get()) // if there are errors, I add nothing to the list
2308 return 0;
2309
2310 if (*reason_to_stop != eArrayRangeOperatorMet)
2311 {
2312 // I need not expand a range, just post-process the final value and return
2313 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2314 {
2315 list->Append(ret_val);
2316 return 1;
2317 }
2318 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2319 {
2320 if (*final_task_on_target == ValueObject::eDereference)
2321 {
2322 Error error;
2323 ValueObjectSP final_value = ret_val->Dereference(error);
2324 if (error.Fail() || !final_value.get())
2325 {
2326 *reason_to_stop = ValueObject::eDereferencingFailed;
2327 *final_value_type = ValueObject::eInvalid;
2328 return 0;
2329 }
2330 else
2331 {
2332 *final_task_on_target = ValueObject::eNothing;
2333 list->Append(final_value);
2334 return 1;
2335 }
2336 }
2337 if (*final_task_on_target == ValueObject::eTakeAddress)
2338 {
2339 Error error;
2340 ValueObjectSP final_value = ret_val->AddressOf(error);
2341 if (error.Fail() || !final_value.get())
2342 {
2343 *reason_to_stop = ValueObject::eTakingAddressFailed;
2344 *final_value_type = ValueObject::eInvalid;
2345 return 0;
2346 }
2347 else
2348 {
2349 *final_task_on_target = ValueObject::eNothing;
2350 list->Append(final_value);
2351 return 1;
2352 }
2353 }
2354 }
2355 }
2356 else
2357 {
2358 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2359 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2360 ret_val,
2361 list,
2362 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2363 final_value_type ? final_value_type : &dummy_final_value_type,
2364 options,
2365 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2366 }
2367 // in any non-covered case, just do the obviously right thing
2368 list->Append(ret_val);
2369 return 1;
2370}
2371
Greg Claytonafacd142011-09-02 01:15:17 +00002372ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002373ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2374 const char** first_unparsed,
2375 ExpressionPathScanEndReason* reason_to_stop,
2376 ExpressionPathEndResultType* final_result,
2377 const GetValueForExpressionPathOptions& options,
2378 ExpressionPathAftermath* what_next)
2379{
2380 ValueObjectSP root = GetSP();
2381
2382 if (!root.get())
2383 return ValueObjectSP();
2384
2385 *first_unparsed = expression_cstr;
2386
2387 while (true)
2388 {
2389
2390 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2391
Greg Claytonafacd142011-09-02 01:15:17 +00002392 clang_type_t root_clang_type = root->GetClangType();
2393 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002394 Flags root_clang_type_info,pointee_clang_type_info;
2395
2396 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2397 if (pointee_clang_type)
2398 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002399
2400 if (!expression_cstr || *expression_cstr == '\0')
2401 {
2402 *reason_to_stop = ValueObject::eEndOfString;
2403 return root;
2404 }
2405
2406 switch (*expression_cstr)
2407 {
2408 case '-':
2409 {
2410 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002411 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 +00002412 {
2413 *first_unparsed = expression_cstr;
2414 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
2415 *final_result = ValueObject::eInvalid;
2416 return ValueObjectSP();
2417 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002418 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2419 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002420 options.m_no_fragile_ivar)
2421 {
2422 *first_unparsed = expression_cstr;
2423 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
2424 *final_result = ValueObject::eInvalid;
2425 return ValueObjectSP();
2426 }
2427 if (expression_cstr[1] != '>')
2428 {
2429 *first_unparsed = expression_cstr;
2430 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2431 *final_result = ValueObject::eInvalid;
2432 return ValueObjectSP();
2433 }
2434 expression_cstr++; // skip the -
2435 }
2436 case '.': // or fallthrough from ->
2437 {
2438 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002439 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 +00002440 {
2441 *first_unparsed = expression_cstr;
2442 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
2443 *final_result = ValueObject::eInvalid;
2444 return ValueObjectSP();
2445 }
2446 expression_cstr++; // skip .
2447 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2448 ConstString child_name;
2449 if (!next_separator) // if no other separator just expand this last layer
2450 {
2451 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002452 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2453
2454 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002455 {
2456 *first_unparsed = '\0';
2457 *reason_to_stop = ValueObject::eEndOfString;
2458 *final_result = ValueObject::ePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002459 return child_valobj_sp;
2460 }
2461 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2462 {
Greg Clayton4c3b8fb2011-12-02 22:48:25 +00002463 child_valobj_sp = root->GetSyntheticValue(eNoSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002464 }
2465
2466 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2467 // so we hit the "else" branch, and return an error
2468 if(child_valobj_sp.get()) // if it worked, just return
2469 {
2470 *first_unparsed = '\0';
2471 *reason_to_stop = ValueObject::eEndOfString;
2472 *final_result = ValueObject::ePlain;
2473 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002474 }
2475 else
2476 {
2477 *first_unparsed = expression_cstr;
2478 *reason_to_stop = ValueObject::eNoSuchChild;
2479 *final_result = ValueObject::eInvalid;
2480 return ValueObjectSP();
2481 }
2482 }
2483 else // other layers do expand
2484 {
2485 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002486 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2487 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002488 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002489 root = child_valobj_sp;
2490 *first_unparsed = next_separator;
2491 *final_result = ValueObject::ePlain;
2492 continue;
2493 }
2494 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2495 {
Greg Claytonafacd142011-09-02 01:15:17 +00002496 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002497 }
2498
2499 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2500 // so we hit the "else" branch, and return an error
2501 if(child_valobj_sp.get()) // if it worked, move on
2502 {
2503 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002504 *first_unparsed = next_separator;
2505 *final_result = ValueObject::ePlain;
2506 continue;
2507 }
2508 else
2509 {
2510 *first_unparsed = expression_cstr;
2511 *reason_to_stop = ValueObject::eNoSuchChild;
2512 *final_result = ValueObject::eInvalid;
2513 return ValueObjectSP();
2514 }
2515 }
2516 break;
2517 }
2518 case '[':
2519 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002520 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 +00002521 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002522 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002523 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002524 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2525 {
2526 *first_unparsed = expression_cstr;
2527 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2528 *final_result = ValueObject::eInvalid;
2529 return ValueObjectSP();
2530 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002531 }
2532 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2533 {
2534 *first_unparsed = expression_cstr;
2535 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2536 *final_result = ValueObject::eInvalid;
2537 return ValueObjectSP();
2538 }
2539 }
2540 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2541 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002542 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002543 {
2544 *first_unparsed = expression_cstr;
2545 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2546 *final_result = ValueObject::eInvalid;
2547 return ValueObjectSP();
2548 }
2549 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2550 {
2551 *first_unparsed = expression_cstr+2;
2552 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2553 *final_result = ValueObject::eUnboundedRange;
2554 return root;
2555 }
2556 }
2557 const char *separator_position = ::strchr(expression_cstr+1,'-');
2558 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2559 if (!close_bracket_position) // if there is no ], this is a syntax error
2560 {
2561 *first_unparsed = expression_cstr;
2562 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2563 *final_result = ValueObject::eInvalid;
2564 return ValueObjectSP();
2565 }
2566 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2567 {
2568 char *end = NULL;
2569 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2570 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2571 {
2572 *first_unparsed = expression_cstr;
2573 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2574 *final_result = ValueObject::eInvalid;
2575 return ValueObjectSP();
2576 }
2577 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2578 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002579 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002580 {
2581 *first_unparsed = expression_cstr+2;
2582 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2583 *final_result = ValueObject::eUnboundedRange;
2584 return root;
2585 }
2586 else
2587 {
2588 *first_unparsed = expression_cstr;
2589 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2590 *final_result = ValueObject::eInvalid;
2591 return ValueObjectSP();
2592 }
2593 }
2594 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002595 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002596 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002597 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2598 if (!child_valobj_sp)
2599 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002600 if (!child_valobj_sp)
Greg Claytonafacd142011-09-02 01:15:17 +00002601 if (root->HasSyntheticValue() && root->GetSyntheticValue(eUseSyntheticFilter)->GetNumChildren() > index)
2602 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002603 if (child_valobj_sp)
2604 {
2605 root = child_valobj_sp;
2606 *first_unparsed = end+1; // skip ]
2607 *final_result = ValueObject::ePlain;
2608 continue;
2609 }
2610 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002611 {
2612 *first_unparsed = expression_cstr;
2613 *reason_to_stop = ValueObject::eNoSuchChild;
2614 *final_result = ValueObject::eInvalid;
2615 return ValueObjectSP();
2616 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002617 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002618 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002619 {
2620 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 +00002621 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002622 {
2623 Error error;
2624 root = root->Dereference(error);
2625 if (error.Fail() || !root.get())
2626 {
2627 *first_unparsed = expression_cstr;
2628 *reason_to_stop = ValueObject::eDereferencingFailed;
2629 *final_result = ValueObject::eInvalid;
2630 return ValueObjectSP();
2631 }
2632 else
2633 {
2634 *what_next = eNothing;
2635 continue;
2636 }
2637 }
2638 else
2639 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002640 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Claytonafacd142011-09-02 01:15:17 +00002641 root->GetClangType()) == eLanguageTypeObjC
Enrico Granata27b625e2011-08-09 01:04:56 +00002642 &&
2643 ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2644 &&
2645 root->HasSyntheticValue()
2646 &&
2647 options.m_no_synthetic_children == false)
2648 {
Greg Claytonafacd142011-09-02 01:15:17 +00002649 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002650 }
2651 else
2652 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002653 if (!root.get())
2654 {
2655 *first_unparsed = expression_cstr;
2656 *reason_to_stop = ValueObject::eNoSuchChild;
2657 *final_result = ValueObject::eInvalid;
2658 return ValueObjectSP();
2659 }
2660 else
2661 {
2662 *first_unparsed = end+1; // skip ]
2663 *final_result = ValueObject::ePlain;
2664 continue;
2665 }
2666 }
2667 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002668 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002669 {
2670 root = root->GetSyntheticBitFieldChild(index, index, true);
2671 if (!root.get())
2672 {
2673 *first_unparsed = expression_cstr;
2674 *reason_to_stop = ValueObject::eNoSuchChild;
2675 *final_result = ValueObject::eInvalid;
2676 return ValueObjectSP();
2677 }
2678 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2679 {
2680 *first_unparsed = end+1; // skip ]
2681 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2682 *final_result = ValueObject::eBitfield;
2683 return root;
2684 }
2685 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002686 else if (root->HasSyntheticValue() && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002687 {
Greg Claytonafacd142011-09-02 01:15:17 +00002688 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002689 if (!root.get())
2690 {
2691 *first_unparsed = expression_cstr;
2692 *reason_to_stop = ValueObject::eNoSuchChild;
2693 *final_result = ValueObject::eInvalid;
2694 return ValueObjectSP();
2695 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002696 else
2697 {
2698 *first_unparsed = end+1; // skip ]
2699 *final_result = ValueObject::ePlain;
2700 continue;
2701 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002702 }
2703 else
2704 {
2705 *first_unparsed = expression_cstr;
2706 *reason_to_stop = ValueObject::eNoSuchChild;
2707 *final_result = ValueObject::eInvalid;
2708 return ValueObjectSP();
2709 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002710 }
2711 else // we have a low and a high index
2712 {
2713 char *end = NULL;
2714 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2715 if (!end || end != separator_position) // if something weird is in our way return an error
2716 {
2717 *first_unparsed = expression_cstr;
2718 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2719 *final_result = ValueObject::eInvalid;
2720 return ValueObjectSP();
2721 }
2722 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2723 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2724 {
2725 *first_unparsed = expression_cstr;
2726 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2727 *final_result = ValueObject::eInvalid;
2728 return ValueObjectSP();
2729 }
2730 if (index_lower > index_higher) // swap indices if required
2731 {
2732 unsigned long temp = index_lower;
2733 index_lower = index_higher;
2734 index_higher = temp;
2735 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002736 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002737 {
2738 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2739 if (!root.get())
2740 {
2741 *first_unparsed = expression_cstr;
2742 *reason_to_stop = ValueObject::eNoSuchChild;
2743 *final_result = ValueObject::eInvalid;
2744 return ValueObjectSP();
2745 }
2746 else
2747 {
2748 *first_unparsed = end+1; // skip ]
2749 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2750 *final_result = ValueObject::eBitfield;
2751 return root;
2752 }
2753 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002754 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 +00002755 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002756 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002757 {
2758 Error error;
2759 root = root->Dereference(error);
2760 if (error.Fail() || !root.get())
2761 {
2762 *first_unparsed = expression_cstr;
2763 *reason_to_stop = ValueObject::eDereferencingFailed;
2764 *final_result = ValueObject::eInvalid;
2765 return ValueObjectSP();
2766 }
2767 else
2768 {
2769 *what_next = ValueObject::eNothing;
2770 continue;
2771 }
2772 }
2773 else
2774 {
2775 *first_unparsed = expression_cstr;
2776 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2777 *final_result = ValueObject::eBoundedRange;
2778 return root;
2779 }
2780 }
2781 break;
2782 }
2783 default: // some non-separator is in the way
2784 {
2785 *first_unparsed = expression_cstr;
2786 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2787 *final_result = ValueObject::eInvalid;
2788 return ValueObjectSP();
2789 break;
2790 }
2791 }
2792 }
2793}
2794
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002795int
2796ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2797 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002798 ValueObjectSP root,
2799 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002800 ExpressionPathScanEndReason* reason_to_stop,
2801 ExpressionPathEndResultType* final_result,
2802 const GetValueForExpressionPathOptions& options,
2803 ExpressionPathAftermath* what_next)
2804{
2805 if (!root.get())
2806 return 0;
2807
2808 *first_unparsed = expression_cstr;
2809
2810 while (true)
2811 {
2812
2813 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2814
Greg Claytonafacd142011-09-02 01:15:17 +00002815 clang_type_t root_clang_type = root->GetClangType();
2816 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002817 Flags root_clang_type_info,pointee_clang_type_info;
2818
2819 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2820 if (pointee_clang_type)
2821 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2822
2823 if (!expression_cstr || *expression_cstr == '\0')
2824 {
2825 *reason_to_stop = ValueObject::eEndOfString;
2826 list->Append(root);
2827 return 1;
2828 }
2829
2830 switch (*expression_cstr)
2831 {
2832 case '[':
2833 {
2834 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2835 {
2836 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2837 {
2838 *first_unparsed = expression_cstr;
2839 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2840 *final_result = ValueObject::eInvalid;
2841 return 0;
2842 }
2843 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2844 {
2845 *first_unparsed = expression_cstr;
2846 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2847 *final_result = ValueObject::eInvalid;
2848 return 0;
2849 }
2850 }
2851 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2852 {
2853 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2854 {
2855 *first_unparsed = expression_cstr;
2856 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2857 *final_result = ValueObject::eInvalid;
2858 return 0;
2859 }
2860 else // expand this into list
2861 {
2862 int max_index = root->GetNumChildren() - 1;
2863 for (int index = 0; index < max_index; index++)
2864 {
2865 ValueObjectSP child =
2866 root->GetChildAtIndex(index, true);
2867 list->Append(child);
2868 }
2869 *first_unparsed = expression_cstr+2;
2870 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2871 *final_result = ValueObject::eValueObjectList;
2872 return max_index; // tell me number of items I added to the VOList
2873 }
2874 }
2875 const char *separator_position = ::strchr(expression_cstr+1,'-');
2876 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2877 if (!close_bracket_position) // if there is no ], this is a syntax error
2878 {
2879 *first_unparsed = expression_cstr;
2880 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2881 *final_result = ValueObject::eInvalid;
2882 return 0;
2883 }
2884 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2885 {
2886 char *end = NULL;
2887 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2888 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2889 {
2890 *first_unparsed = expression_cstr;
2891 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2892 *final_result = ValueObject::eInvalid;
2893 return 0;
2894 }
2895 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2896 {
2897 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2898 {
2899 int max_index = root->GetNumChildren() - 1;
2900 for (int index = 0; index < max_index; index++)
2901 {
2902 ValueObjectSP child =
2903 root->GetChildAtIndex(index, true);
2904 list->Append(child);
2905 }
2906 *first_unparsed = expression_cstr+2;
2907 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2908 *final_result = ValueObject::eValueObjectList;
2909 return max_index; // tell me number of items I added to the VOList
2910 }
2911 else
2912 {
2913 *first_unparsed = expression_cstr;
2914 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2915 *final_result = ValueObject::eInvalid;
2916 return 0;
2917 }
2918 }
2919 // from here on we do have a valid index
2920 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2921 {
2922 root = root->GetChildAtIndex(index, true);
2923 if (!root.get())
2924 {
2925 *first_unparsed = expression_cstr;
2926 *reason_to_stop = ValueObject::eNoSuchChild;
2927 *final_result = ValueObject::eInvalid;
2928 return 0;
2929 }
2930 else
2931 {
2932 list->Append(root);
2933 *first_unparsed = end+1; // skip ]
2934 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2935 *final_result = ValueObject::eValueObjectList;
2936 return 1;
2937 }
2938 }
2939 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2940 {
2941 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
2942 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2943 {
2944 Error error;
2945 root = root->Dereference(error);
2946 if (error.Fail() || !root.get())
2947 {
2948 *first_unparsed = expression_cstr;
2949 *reason_to_stop = ValueObject::eDereferencingFailed;
2950 *final_result = ValueObject::eInvalid;
2951 return 0;
2952 }
2953 else
2954 {
2955 *what_next = eNothing;
2956 continue;
2957 }
2958 }
2959 else
2960 {
2961 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2962 if (!root.get())
2963 {
2964 *first_unparsed = expression_cstr;
2965 *reason_to_stop = ValueObject::eNoSuchChild;
2966 *final_result = ValueObject::eInvalid;
2967 return 0;
2968 }
2969 else
2970 {
2971 list->Append(root);
2972 *first_unparsed = end+1; // skip ]
2973 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2974 *final_result = ValueObject::eValueObjectList;
2975 return 1;
2976 }
2977 }
2978 }
2979 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2980 {
2981 root = root->GetSyntheticBitFieldChild(index, index, true);
2982 if (!root.get())
2983 {
2984 *first_unparsed = expression_cstr;
2985 *reason_to_stop = ValueObject::eNoSuchChild;
2986 *final_result = ValueObject::eInvalid;
2987 return 0;
2988 }
2989 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2990 {
2991 list->Append(root);
2992 *first_unparsed = end+1; // skip ]
2993 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2994 *final_result = ValueObject::eValueObjectList;
2995 return 1;
2996 }
2997 }
2998 }
2999 else // we have a low and a high index
3000 {
3001 char *end = NULL;
3002 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3003 if (!end || end != separator_position) // if something weird is in our way return an error
3004 {
3005 *first_unparsed = expression_cstr;
3006 *reason_to_stop = ValueObject::eUnexpectedSymbol;
3007 *final_result = ValueObject::eInvalid;
3008 return 0;
3009 }
3010 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3011 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3012 {
3013 *first_unparsed = expression_cstr;
3014 *reason_to_stop = ValueObject::eUnexpectedSymbol;
3015 *final_result = ValueObject::eInvalid;
3016 return 0;
3017 }
3018 if (index_lower > index_higher) // swap indices if required
3019 {
3020 unsigned long temp = index_lower;
3021 index_lower = index_higher;
3022 index_higher = temp;
3023 }
3024 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3025 {
3026 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3027 if (!root.get())
3028 {
3029 *first_unparsed = expression_cstr;
3030 *reason_to_stop = ValueObject::eNoSuchChild;
3031 *final_result = ValueObject::eInvalid;
3032 return 0;
3033 }
3034 else
3035 {
3036 list->Append(root);
3037 *first_unparsed = end+1; // skip ]
3038 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
3039 *final_result = ValueObject::eValueObjectList;
3040 return 1;
3041 }
3042 }
3043 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
3044 *what_next == ValueObject::eDereference &&
3045 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3046 {
3047 Error error;
3048 root = root->Dereference(error);
3049 if (error.Fail() || !root.get())
3050 {
3051 *first_unparsed = expression_cstr;
3052 *reason_to_stop = ValueObject::eDereferencingFailed;
3053 *final_result = ValueObject::eInvalid;
3054 return 0;
3055 }
3056 else
3057 {
3058 *what_next = ValueObject::eNothing;
3059 continue;
3060 }
3061 }
3062 else
3063 {
Johnny Chen44805302011-07-19 19:48:13 +00003064 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003065 index <= index_higher; index++)
3066 {
3067 ValueObjectSP child =
3068 root->GetChildAtIndex(index, true);
3069 list->Append(child);
3070 }
3071 *first_unparsed = end+1;
3072 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
3073 *final_result = ValueObject::eValueObjectList;
3074 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3075 }
3076 }
3077 break;
3078 }
3079 default: // some non-[ separator, or something entirely wrong, is in the way
3080 {
3081 *first_unparsed = expression_cstr;
3082 *reason_to_stop = ValueObject::eUnexpectedSymbol;
3083 *final_result = ValueObject::eInvalid;
3084 return 0;
3085 break;
3086 }
3087 }
3088 }
3089}
3090
Enrico Granata0c489f52012-03-01 04:24:26 +00003091static void
3092DumpValueObject_Impl (Stream &s,
3093 ValueObject *valobj,
3094 const ValueObject::DumpValueObjectOptions& options,
3095 uint32_t ptr_depth,
3096 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003097{
Greg Clayton007d5be2011-05-30 00:49:24 +00003098 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003099 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003100 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003101
Enrico Granata0c489f52012-03-01 04:24:26 +00003102 const char *root_valobj_name =
3103 options.m_root_valobj_name.empty() ?
3104 valobj->GetName().AsCString() :
3105 options.m_root_valobj_name.c_str();
3106
3107 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003108 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003109 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003110 if (dynamic_value)
3111 valobj = dynamic_value;
3112 }
3113
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003114 clang_type_t clang_type = valobj->GetClangType();
3115
Greg Clayton73b472d2010-10-27 03:32:59 +00003116 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003117 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003118 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3119 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003120
Enrico Granata0c489f52012-03-01 04:24:26 +00003121 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003122
3123 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003124 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003125 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003126 {
Jim Ingham6035b672011-03-31 00:19:25 +00003127 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003128 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003129
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003130 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003131
Greg Clayton7c8a9662010-11-02 01:50:16 +00003132 // Always show the type for the top level items.
Enrico Granata0c489f52012-03-01 04:24:26 +00003133 if (options.m_show_types || (curr_depth == 0 && !options.m_flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003134 {
Enrico Granata9910bc82011-08-03 02:18:51 +00003135 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
3136 s.Printf("(%s", typeName);
3137 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003138 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003139 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003140 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003141 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003142 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3143 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003144 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003145 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003146 else
3147 {
3148 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3149 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003150 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003151 else
3152 {
3153 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3154 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003155 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003156 else
3157 s.Printf(", dynamic type: %s) ",
3158 runtime->GetActualTypeName(isa).GetCString());
3159 }
3160 }
3161 }
3162 else
3163 s.Printf(") ");
3164 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003165
Greg Clayton1d3afba2010-10-05 00:00:42 +00003166
Enrico Granata0c489f52012-03-01 04:24:26 +00003167 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003168 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003169 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003170 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003171 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003172 s.PutCString(" =");
3173 }
3174 else
3175 {
3176 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3177 s.Printf ("%s =", name_cstr);
3178 }
3179
Enrico Granata0c489f52012-03-01 04:24:26 +00003180 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003181 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003182 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003183 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003184 }
3185
Enrico Granata0c489f52012-03-01 04:24:26 +00003186 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003187 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003188 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003189 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003190 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003191
Enrico Granata0c489f52012-03-01 04:24:26 +00003192 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003193 entry = NULL;
3194
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003195 if (err_cstr == NULL)
3196 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003197 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003198 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003199 valobj->GetValueAsCString(options.m_format,
3200 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003201 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003202 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003203 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003204 val_cstr = valobj->GetValueAsCString();
3205 if (val_cstr)
3206 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003207 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003208 err_cstr = valobj->GetError().AsCString();
3209 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003210
3211 if (err_cstr)
3212 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003213 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003214 }
3215 else
3216 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003217 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003218 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003219 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003220 if (options.m_omit_summary_depth == 0)
3221 {
3222 if (options.m_summary_sp)
3223 {
3224 valobj->GetSummaryAsCString(entry, summary_str);
3225 sum_cstr = summary_str.c_str();
3226 }
3227 else
3228 sum_cstr = valobj->GetSummaryAsCString();
3229 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003230
Greg Clayton6efba4f2012-01-26 21:08:30 +00003231 // Make sure we have a value and make sure the summary didn't
3232 // specify that the value should not be printed
3233 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3234 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003235
Enrico Granata9dd75c82011-07-15 23:30:15 +00003236 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003237 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003238
Enrico Granata0c489f52012-03-01 04:24:26 +00003239 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003240 {
Jim Ingham6035b672011-03-31 00:19:25 +00003241 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003242 if (object_desc)
3243 s.Printf(" %s\n", object_desc);
3244 else
Sean Callanan672ad942010-10-23 00:18:49 +00003245 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003246 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003247 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003248 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003249
Enrico Granata0c489f52012-03-01 04:24:26 +00003250 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003251 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003252 // We will show children for all concrete types. We won't show
3253 // pointer contents unless a pointer depth has been specified.
3254 // We won't reference contents unless the reference is the
3255 // root object (depth of zero).
3256 bool print_children = true;
3257
3258 // Use a new temporary pointer depth in case we override the
3259 // current pointer depth below...
3260 uint32_t curr_ptr_depth = ptr_depth;
3261
3262 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3263 if (is_ptr || is_ref)
3264 {
3265 // We have a pointer or reference whose value is an address.
3266 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003267 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003268 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003269 print_children = false;
3270
3271 else if (is_ref && curr_depth == 0)
3272 {
3273 // If this is the root object (depth is zero) that we are showing
3274 // and it is a reference, and no pointer depth has been supplied
3275 // print out what it references. Don't do this at deeper depths
3276 // otherwise we can end up with infinite recursion...
3277 curr_ptr_depth = 1;
3278 }
3279
3280 if (curr_ptr_depth == 0)
3281 print_children = false;
3282 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003283
Enrico Granata0a3958e2011-07-02 00:25:22 +00003284 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003285 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003286 ValueObjectSP synth_valobj = valobj->GetSyntheticValue (options.m_use_synthetic ?
Greg Claytoncc4d0142012-02-17 07:49:44 +00003287 eUseSyntheticFilter :
3288 eNoSyntheticFilter);
Enrico Granatac482a192011-08-17 22:13:59 +00003289 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003290 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003291 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003292 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003293 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003294 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003295 if (print_valobj)
3296 s.EOL();
3297 }
3298 else
3299 {
3300 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003301 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003302 s.IndentMore();
3303 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003304
Greg Claytoncc4d0142012-02-17 07:49:44 +00003305 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003306
Enrico Granata0c489f52012-03-01 04:24:26 +00003307 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003308 {
3309 num_children = max_num_children;
3310 print_dotdotdot = true;
3311 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003312
Enrico Granata0c489f52012-03-01 04:24:26 +00003313 ValueObject::DumpValueObjectOptions child_options(options);
3314 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3315 child_options.SetScopeChecked(true)
3316 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003317 for (uint32_t idx=0; idx<num_children; ++idx)
3318 {
Enrico Granatac482a192011-08-17 22:13:59 +00003319 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003320 if (child_sp.get())
3321 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003322 DumpValueObject_Impl (s,
3323 child_sp.get(),
3324 child_options,
3325 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3326 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003327 }
3328 }
3329
Enrico Granata0c489f52012-03-01 04:24:26 +00003330 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003331 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003332 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003333 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003334 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3335 Target *target = exe_ctx.GetTargetPtr();
3336 if (target)
3337 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003338 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003339 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003340 s.IndentLess();
3341 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003342 }
3343 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003344 else if (has_children)
3345 {
3346 // Aggregate, no children...
3347 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003348 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003349 }
3350 else
3351 {
3352 if (print_valobj)
3353 s.EOL();
3354 }
3355
Greg Clayton1d3afba2010-10-05 00:00:42 +00003356 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003357 else
3358 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003359 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003360 }
3361 }
3362 else
3363 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003364 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003365 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003366 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003367 }
3368 }
3369 }
3370 }
3371}
3372
Enrico Granata0c489f52012-03-01 04:24:26 +00003373void
3374ValueObject::DumpValueObject (Stream &s,
3375 ValueObject *valobj)
3376{
3377
3378 if (!valobj)
3379 return;
3380
3381 DumpValueObject_Impl(s,
3382 valobj,
3383 DumpValueObjectOptions::DefaultOptions(),
3384 0,
3385 0);
3386}
3387
3388void
3389ValueObject::DumpValueObject (Stream &s,
3390 ValueObject *valobj,
3391 const DumpValueObjectOptions& options)
3392{
3393 DumpValueObject_Impl(s,
3394 valobj,
3395 options,
3396 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3397 0 // current object depth is 0 since we are just starting
3398 );
3399}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003400
3401ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003402ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003403{
3404 ValueObjectSP valobj_sp;
3405
Enrico Granatac3e320a2011-08-02 17:27:39 +00003406 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003407 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003408 ExecutionContext exe_ctx (GetExecutionContextRef());
3409 clang::ASTContext *ast = GetClangAST ();
3410
3411 DataExtractor data;
3412 data.SetByteOrder (m_data.GetByteOrder());
3413 data.SetAddressByteSize(m_data.GetAddressByteSize());
3414
Greg Claytone72dfb32012-02-24 01:59:29 +00003415 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003416
3417 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3418 ast,
3419 GetClangType(),
3420 name,
3421 data,
3422 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003423 }
Jim Ingham6035b672011-03-31 00:19:25 +00003424
3425 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003426 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003427 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003428 }
3429 return valobj_sp;
3430}
3431
Greg Claytonafacd142011-09-02 01:15:17 +00003432ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003433ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003434{
Jim Ingham58b59f92011-04-22 23:53:53 +00003435 if (m_deref_valobj)
3436 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003437
Greg Clayton54979cd2010-12-15 05:08:08 +00003438 const bool is_pointer_type = IsPointerType();
3439 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003440 {
3441 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003442 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003443
3444 std::string child_name_str;
3445 uint32_t child_byte_size = 0;
3446 int32_t child_byte_offset = 0;
3447 uint32_t child_bitfield_bit_size = 0;
3448 uint32_t child_bitfield_bit_offset = 0;
3449 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003450 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003451 const bool transparent_pointers = false;
3452 clang::ASTContext *clang_ast = GetClangAST();
3453 clang_type_t clang_type = GetClangType();
3454 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003455
Greg Claytoncc4d0142012-02-17 07:49:44 +00003456 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003457
3458 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3459 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003460 GetName().GetCString(),
3461 clang_type,
3462 0,
3463 transparent_pointers,
3464 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003465 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003466 child_name_str,
3467 child_byte_size,
3468 child_byte_offset,
3469 child_bitfield_bit_size,
3470 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003471 child_is_base_class,
3472 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003473 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003474 {
3475 ConstString child_name;
3476 if (!child_name_str.empty())
3477 child_name.SetCString (child_name_str.c_str());
3478
Jim Ingham58b59f92011-04-22 23:53:53 +00003479 m_deref_valobj = new ValueObjectChild (*this,
3480 clang_ast,
3481 child_clang_type,
3482 child_name,
3483 child_byte_size,
3484 child_byte_offset,
3485 child_bitfield_bit_size,
3486 child_bitfield_bit_offset,
3487 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003488 child_is_deref_of_parent,
3489 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003490 }
3491 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003492
Jim Ingham58b59f92011-04-22 23:53:53 +00003493 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003494 {
3495 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003496 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003497 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003498 else
3499 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003500 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003501 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003502
3503 if (is_pointer_type)
3504 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3505 else
3506 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003507 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003508 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003509}
3510
Greg Claytonafacd142011-09-02 01:15:17 +00003511ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003512ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003513{
Jim Ingham78a685a2011-04-16 00:01:13 +00003514 if (m_addr_of_valobj_sp)
3515 return m_addr_of_valobj_sp;
3516
Greg Claytone0d378b2011-03-24 21:19:54 +00003517 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003518 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003519 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003520 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003521 if (addr != LLDB_INVALID_ADDRESS)
3522 {
3523 switch (address_type)
3524 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003525 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003526 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003527 {
3528 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003529 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003530 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3531 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003532 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003533
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003534 case eAddressTypeFile:
3535 case eAddressTypeLoad:
3536 case eAddressTypeHost:
3537 {
3538 clang::ASTContext *ast = GetClangAST();
3539 clang_type_t clang_type = GetClangType();
3540 if (ast && clang_type)
3541 {
3542 std::string name (1, '&');
3543 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003544 ExecutionContext exe_ctx (GetExecutionContextRef());
3545 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003546 ast,
3547 ClangASTContext::CreatePointerType (ast, clang_type),
3548 ConstString (name.c_str()),
3549 addr,
3550 eAddressTypeInvalid,
3551 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003552 }
3553 }
3554 break;
3555 }
3556 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003557 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003558}
3559
Greg Clayton9a142cf2012-02-03 05:34:10 +00003560ValueObjectSP
3561ValueObject::Cast (const ClangASTType &clang_ast_type)
3562{
Greg Clayton81e871e2012-02-04 02:27:34 +00003563 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003564}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003565
Greg Claytonafacd142011-09-02 01:15:17 +00003566ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003567ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3568{
Greg Claytonafacd142011-09-02 01:15:17 +00003569 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003570 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003571 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003572
3573 if (ptr_value != LLDB_INVALID_ADDRESS)
3574 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003575 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003576 ExecutionContext exe_ctx (GetExecutionContextRef());
3577 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003578 name,
3579 ptr_addr,
3580 clang_ast_type);
3581 }
3582 return valobj_sp;
3583}
3584
Greg Claytonafacd142011-09-02 01:15:17 +00003585ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003586ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3587{
Greg Claytonafacd142011-09-02 01:15:17 +00003588 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003589 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003590 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003591
3592 if (ptr_value != LLDB_INVALID_ADDRESS)
3593 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003594 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003595 ExecutionContext exe_ctx (GetExecutionContextRef());
3596 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003597 name,
3598 ptr_addr,
3599 type_sp);
3600 }
3601 return valobj_sp;
3602}
3603
Jim Ingham6035b672011-03-31 00:19:25 +00003604ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003605 m_mod_id(),
3606 m_exe_ctx_ref(),
3607 m_needs_update (true),
3608 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003609{
3610}
3611
3612ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003613 m_mod_id(),
3614 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003615 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003616 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003617{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003618 ExecutionContext exe_ctx(exe_scope);
3619 TargetSP target_sp (exe_ctx.GetTargetSP());
3620 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003621 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003622 m_exe_ctx_ref.SetTargetSP (target_sp);
3623 ProcessSP process_sp (exe_ctx.GetProcessSP());
3624 if (!process_sp)
3625 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003626
Greg Claytoncc4d0142012-02-17 07:49:44 +00003627 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003628 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003629 m_mod_id = process_sp->GetModID();
3630 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003631
Greg Claytoncc4d0142012-02-17 07:49:44 +00003632 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003633
Greg Claytoncc4d0142012-02-17 07:49:44 +00003634 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003635 {
3636 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003637 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003638 }
Jim Ingham6035b672011-03-31 00:19:25 +00003639
Greg Claytoncc4d0142012-02-17 07:49:44 +00003640 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003641 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003642 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003643
Greg Claytoncc4d0142012-02-17 07:49:44 +00003644 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3645 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003646 {
3647 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003648 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003649 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003650 if (frame_sp)
3651 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003652 }
3653 }
3654 }
Jim Ingham6035b672011-03-31 00:19:25 +00003655}
3656
3657ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003658 m_mod_id(),
3659 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3660 m_needs_update (true),
3661 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003662{
3663}
3664
3665ValueObject::EvaluationPoint::~EvaluationPoint ()
3666{
3667}
3668
Jim Ingham6035b672011-03-31 00:19:25 +00003669// This function checks the EvaluationPoint against the current process state. If the current
3670// state matches the evaluation point, or the evaluation point is already invalid, then we return
3671// false, meaning "no change". If the current state is different, we update our state, and return
3672// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3673// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003674// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003675
3676bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003677ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003678{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003679
3680 // 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 +00003681 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003682
Greg Claytoncc4d0142012-02-17 07:49:44 +00003683 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003684 return false;
3685
Jim Ingham6035b672011-03-31 00:19:25 +00003686 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003687 Process *process = exe_ctx.GetProcessPtr();
3688 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003689 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003690
Jim Ingham6035b672011-03-31 00:19:25 +00003691 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003692 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003693
Jim Ingham78a685a2011-04-16 00:01:13 +00003694 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3695 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003696 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003697 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003698
3699 bool changed;
3700
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003701 if (m_mod_id.IsValid())
3702 {
3703 if (m_mod_id == current_mod_id)
3704 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003705 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003706 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003707 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003708 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003709 else
3710 {
3711 m_mod_id = current_mod_id;
3712 m_needs_update = true;
3713 changed = true;
3714 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003715 }
Jim Ingham6035b672011-03-31 00:19:25 +00003716
Jim Ingham73ca05a2011-12-17 01:35:57 +00003717 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3718 // That way we'll be sure to return a valid exe_scope.
3719 // 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 +00003720
Greg Claytoncc4d0142012-02-17 07:49:44 +00003721 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003722 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003723 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3724 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003725 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003726 if (m_exe_ctx_ref.HasFrameRef())
3727 {
3728 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3729 if (!frame_sp)
3730 {
3731 // We used to have a frame, but now it is gone
3732 SetInvalid();
3733 }
3734 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003735 }
Jim Ingham6035b672011-03-31 00:19:25 +00003736 else
3737 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003738 // We used to have a thread, but now it is gone
3739 SetInvalid();
Jim Ingham6035b672011-03-31 00:19:25 +00003740 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003741
Jim Ingham6035b672011-03-31 00:19:25 +00003742 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003743 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003744}
3745
Jim Ingham61be0902011-05-02 18:13:59 +00003746void
3747ValueObject::EvaluationPoint::SetUpdated ()
3748{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003749 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3750 if (process_sp)
3751 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003752 m_first_update = false;
3753 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003754}
3755
3756
Greg Claytoncc4d0142012-02-17 07:49:44 +00003757//bool
3758//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3759//{
3760// if (!IsValid())
3761// return false;
3762//
3763// bool needs_update = false;
3764//
3765// // The target has to be non-null, and the
3766// Target *target = exe_scope->CalculateTarget();
3767// if (target != NULL)
3768// {
3769// Target *old_target = m_target_sp.get();
3770// assert (target == old_target);
3771// Process *process = exe_scope->CalculateProcess();
3772// if (process != NULL)
3773// {
3774// // FOR NOW - assume you can't update variable objects across process boundaries.
3775// Process *old_process = m_process_sp.get();
3776// assert (process == old_process);
3777// ProcessModID current_mod_id = process->GetModID();
3778// if (m_mod_id != current_mod_id)
3779// {
3780// needs_update = true;
3781// m_mod_id = current_mod_id;
3782// }
3783// // See if we're switching the thread or stack context. If no thread is given, this is
3784// // being evaluated in a global context.
3785// Thread *thread = exe_scope->CalculateThread();
3786// if (thread != NULL)
3787// {
3788// user_id_t new_thread_index = thread->GetIndexID();
3789// if (new_thread_index != m_thread_id)
3790// {
3791// needs_update = true;
3792// m_thread_id = new_thread_index;
3793// m_stack_id.Clear();
3794// }
3795//
3796// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3797// if (new_frame != NULL)
3798// {
3799// if (new_frame->GetStackID() != m_stack_id)
3800// {
3801// needs_update = true;
3802// m_stack_id = new_frame->GetStackID();
3803// }
3804// }
3805// else
3806// {
3807// m_stack_id.Clear();
3808// needs_update = true;
3809// }
3810// }
3811// else
3812// {
3813// // If this had been given a thread, and now there is none, we should update.
3814// // Otherwise we don't have to do anything.
3815// if (m_thread_id != LLDB_INVALID_UID)
3816// {
3817// m_thread_id = LLDB_INVALID_UID;
3818// m_stack_id.Clear();
3819// needs_update = true;
3820// }
3821// }
3822// }
3823// else
3824// {
3825// // If there is no process, then we don't need to update anything.
3826// // But if we're switching from having a process to not, we should try to update.
3827// if (m_process_sp.get() != NULL)
3828// {
3829// needs_update = true;
3830// m_process_sp.reset();
3831// m_thread_id = LLDB_INVALID_UID;
3832// m_stack_id.Clear();
3833// }
3834// }
3835// }
3836// else
3837// {
3838// // If there's no target, nothing can change so we don't need to update anything.
3839// // But if we're switching from having a target to not, we should try to update.
3840// if (m_target_sp.get() != NULL)
3841// {
3842// needs_update = true;
3843// m_target_sp.reset();
3844// m_process_sp.reset();
3845// m_thread_id = LLDB_INVALID_UID;
3846// m_stack_id.Clear();
3847// }
3848// }
3849// if (!m_needs_update)
3850// m_needs_update = needs_update;
3851//
3852// return needs_update;
3853//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003854
3855void
3856ValueObject::ClearUserVisibleData()
3857{
3858 m_location_str.clear();
3859 m_value_str.clear();
3860 m_summary_str.clear();
3861 m_object_desc_str.clear();
Enrico Granata0c489f52012-03-01 04:24:26 +00003862 m_synthetic_value = NULL;
Greg Clayton48ca8b82012-01-07 20:58:07 +00003863 m_is_getting_summary = false;
Johnny Chen44805302011-07-19 19:48:13 +00003864}
Enrico Granata9128ee22011-09-06 19:20:51 +00003865
3866SymbolContextScope *
3867ValueObject::GetSymbolContextScope()
3868{
3869 if (m_parent)
3870 {
3871 if (!m_parent->IsPointerOrReferenceType())
3872 return m_parent->GetSymbolContextScope();
3873 }
3874 return NULL;
3875}