blob: 4d8610fb2228c02215a370f1aa9bf1be43369e1c [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)
Enrico Granata86cc9822012-03-19 22:58:49 +0000182 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
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);
Enrico Granata86cc9822012-03-19 22:58:49 +0000202 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000203 }
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));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000253#ifndef LLDB_DISABLE_PYTHON
Enrico Granata78d06382011-09-09 23:33:14 +0000254 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, use_dynamic));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000255#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000256
Enrico Granata85933ed2011-08-18 16:38:26 +0000257 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000258 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granata855cd902011-09-06 22:59:55 +0000259
260 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000261 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000262
263 return any_change;
264
Enrico Granata4becb372011-06-29 22:27:15 +0000265}
266
Jim Ingham16e0c682011-08-12 23:34:31 +0000267void
268ValueObject::SetNeedsUpdate ()
269{
270 m_update_point.SetNeedsUpdate();
271 // We have to clear the value string here so ConstResult children will notice if their values are
272 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000273 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000274}
275
Sean Callanan72772842012-02-22 23:57:45 +0000276ClangASTType
277ValueObject::MaybeCalculateCompleteType ()
278{
279 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000280
Sean Callanan72772842012-02-22 23:57:45 +0000281 if (m_did_calculate_complete_objc_class_type)
282 {
283 if (m_override_type.IsValid())
284 return m_override_type;
285 else
286 return ret;
287 }
288
289 clang_type_t ast_type(GetClangTypeImpl());
290 clang_type_t class_type;
291 bool is_pointer_type;
292
293 if (ClangASTContext::IsObjCObjectPointerType(ast_type, &class_type))
294 {
295 is_pointer_type = true;
296 }
297 else if (ClangASTContext::IsObjCClassType(ast_type))
298 {
299 is_pointer_type = false;
300 class_type = ast_type;
301 }
302 else
303 {
304 return ret;
305 }
306
307 m_did_calculate_complete_objc_class_type = true;
308
309 if (!class_type)
310 return ret;
311
312 std::string class_name;
313
314 if (!ClangASTContext::GetObjCClassName(class_type, class_name))
315 return ret;
316
317 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
318
319 if (!process_sp)
320 return ret;
321
322 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
323
324 if (!objc_language_runtime)
325 return ret;
326
327 ConstString class_name_cs(class_name.c_str());
328
329 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name_cs);
330
331 if (!complete_objc_class_type_sp)
332 return ret;
333
334 ClangASTType complete_class(complete_objc_class_type_sp->GetClangAST(),
335 complete_objc_class_type_sp->GetClangFullType());
336
337 if (!ClangASTContext::GetCompleteType(complete_class.GetASTContext(),
338 complete_class.GetOpaqueQualType()))
339 return ret;
340
341 if (is_pointer_type)
342 {
343 clang_type_t pointer_type = ClangASTContext::CreatePointerType(complete_class.GetASTContext(),
344 complete_class.GetOpaqueQualType());
345
346 m_override_type = ClangASTType(complete_class.GetASTContext(),
347 pointer_type);
348 }
349 else
350 {
351 m_override_type = complete_class;
352 }
353
Sean Callanan356e17c2012-03-30 02:04:38 +0000354 if (m_override_type.IsValid())
355 return m_override_type;
356 else
357 return ret;
Sean Callanan72772842012-02-22 23:57:45 +0000358}
359
360clang::ASTContext *
361ValueObject::GetClangAST ()
362{
363 ClangASTType type = MaybeCalculateCompleteType();
364
365 return type.GetASTContext();
366}
367
368lldb::clang_type_t
369ValueObject::GetClangType ()
370{
371 ClangASTType type = MaybeCalculateCompleteType();
372
373 return type.GetOpaqueQualType();
374}
375
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000376DataExtractor &
377ValueObject::GetDataExtractor ()
378{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000379 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380 return m_data;
381}
382
383const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000384ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000386 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000387 return m_error;
388}
389
390const ConstString &
391ValueObject::GetName() const
392{
393 return m_name;
394}
395
396const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000397ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000398{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000399 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400 {
401 if (m_location_str.empty())
402 {
403 StreamString sstr;
404
405 switch (m_value.GetValueType())
406 {
407 default:
408 break;
409
410 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000411 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412 {
413 RegisterInfo *reg_info = m_value.GetRegisterInfo();
414 if (reg_info)
415 {
416 if (reg_info->name)
417 m_location_str = reg_info->name;
418 else if (reg_info->alt_name)
419 m_location_str = reg_info->alt_name;
420 break;
421 }
422 }
423 m_location_str = "scalar";
424 break;
425
426 case Value::eValueTypeLoadAddress:
427 case Value::eValueTypeFileAddress:
428 case Value::eValueTypeHostAddress:
429 {
430 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
431 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
432 m_location_str.swap(sstr.GetString());
433 }
434 break;
435 }
436 }
437 }
438 return m_location_str.c_str();
439}
440
441Value &
442ValueObject::GetValue()
443{
444 return m_value;
445}
446
447const Value &
448ValueObject::GetValue() const
449{
450 return m_value;
451}
452
453bool
Jim Ingham6035b672011-03-31 00:19:25 +0000454ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000455{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000456 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
457 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000458 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000459 Value tmp_value(m_value);
460 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000461 if (scalar.IsValid())
462 {
463 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
464 if (bitfield_bit_size)
465 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
466 return true;
467 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000468 }
Greg Claytondcad5022011-12-29 01:26:56 +0000469 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000470}
471
472bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000473ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000474{
Greg Clayton288bdf92010-09-02 02:59:18 +0000475 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476}
477
478
479void
480ValueObject::SetValueIsValid (bool b)
481{
Greg Clayton288bdf92010-09-02 02:59:18 +0000482 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483}
484
485bool
Jim Ingham6035b672011-03-31 00:19:25 +0000486ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487{
Jim Ingham6035b672011-03-31 00:19:25 +0000488 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000489 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490}
491
492void
493ValueObject::SetValueDidChange (bool value_changed)
494{
Greg Clayton288bdf92010-09-02 02:59:18 +0000495 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496}
497
498ValueObjectSP
499ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
500{
501 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000502 // We may need to update our value if we are dynamic
503 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000504 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000505 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000506 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000507 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000508 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000509 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000510 // No we haven't created the child at this index, so lets have our
511 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000512 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000513 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000514
Enrico Granata9d60f602012-03-09 03:09:58 +0000515 ValueObject* child = m_children.GetChildAtIndex(idx);
516 if (child != NULL)
517 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000518 }
519 return child_sp;
520}
521
522uint32_t
523ValueObject::GetIndexOfChildWithName (const ConstString &name)
524{
525 bool omit_empty_base_classes = true;
526 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000527 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000528 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000529 omit_empty_base_classes);
530}
531
532ValueObjectSP
533ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
534{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000535 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000536 // classes (which really aren't part of the expression path), so we
537 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000539
Greg Claytondea8cb42011-06-29 22:09:02 +0000540 // We may need to update our value if we are dynamic
541 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000542 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000543
544 std::vector<uint32_t> child_indexes;
545 clang::ASTContext *clang_ast = GetClangAST();
546 void *clang_type = GetClangType();
547 bool omit_empty_base_classes = true;
548 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
549 clang_type,
550 name.GetCString(),
551 omit_empty_base_classes,
552 child_indexes);
553 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000554 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000555 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
556 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
557
558 child_sp = GetChildAtIndex(*pos, can_create);
559 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000560 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000561 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000562 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000563 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
564 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000565 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000566 else
567 {
568 child_sp.reset();
569 }
570
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000571 }
572 }
573 return child_sp;
574}
575
576
577uint32_t
578ValueObject::GetNumChildren ()
579{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000580 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000581 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000582 {
583 SetNumChildren (CalculateNumChildren());
584 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000585 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586}
587void
588ValueObject::SetNumChildren (uint32_t num_children)
589{
Greg Clayton288bdf92010-09-02 02:59:18 +0000590 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000591 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000592}
593
594void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000595ValueObject::SetName (const ConstString &name)
596{
597 m_name = name;
598}
599
Jim Ingham58b59f92011-04-22 23:53:53 +0000600ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000601ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
602{
Jim Ingham2eec4872011-05-07 00:10:58 +0000603 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000604
Greg Claytondea8cb42011-06-29 22:09:02 +0000605 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000606 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000607 std::string child_name_str;
608 uint32_t child_byte_size = 0;
609 int32_t child_byte_offset = 0;
610 uint32_t child_bitfield_bit_size = 0;
611 uint32_t child_bitfield_bit_offset = 0;
612 bool child_is_base_class = false;
613 bool child_is_deref_of_parent = false;
614
615 const bool transparent_pointers = synthetic_array_member == false;
616 clang::ASTContext *clang_ast = GetClangAST();
617 clang_type_t clang_type = GetClangType();
618 clang_type_t child_clang_type;
619
Greg Claytoncc4d0142012-02-17 07:49:44 +0000620 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000621
622 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
623 clang_ast,
624 GetName().GetCString(),
625 clang_type,
626 idx,
627 transparent_pointers,
628 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000629 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000630 child_name_str,
631 child_byte_size,
632 child_byte_offset,
633 child_bitfield_bit_size,
634 child_bitfield_bit_offset,
635 child_is_base_class,
636 child_is_deref_of_parent);
637 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000638 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000639 if (synthetic_index)
640 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000641
Greg Claytondea8cb42011-06-29 22:09:02 +0000642 ConstString child_name;
643 if (!child_name_str.empty())
644 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000645
Greg Claytondea8cb42011-06-29 22:09:02 +0000646 valobj = new ValueObjectChild (*this,
647 clang_ast,
648 child_clang_type,
649 child_name,
650 child_byte_size,
651 child_byte_offset,
652 child_bitfield_bit_size,
653 child_bitfield_bit_offset,
654 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000655 child_is_deref_of_parent,
656 eAddressTypeInvalid);
657 //if (valobj)
658 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
659 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000660
Jim Ingham58b59f92011-04-22 23:53:53 +0000661 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000662}
663
Enrico Granata0c489f52012-03-01 04:24:26 +0000664bool
665ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
666 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000667{
Enrico Granata0c489f52012-03-01 04:24:26 +0000668 destination.clear();
669
670 // ideally we would like to bail out if passing NULL, but if we do so
671 // we end up not providing the summary for function pointers anymore
672 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
673 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000674
675 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000676
677 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
678 // information that we might care to see in a crash log. might be useful in very specific situations though.
679 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
680 GetTypeName().GetCString(),
681 GetName().GetCString(),
682 summary_ptr->GetDescription().c_str());*/
683
Enrico Granata0c489f52012-03-01 04:24:26 +0000684 if (UpdateValueIfNeeded (false))
685 {
686 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000688 if (HasSyntheticValue())
689 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
690 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000691 }
692 else
693 {
694 clang_type_t clang_type = GetClangType();
695
696 // Do some default printout for function pointers
697 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000698 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000699 StreamString sstr;
700 clang_type_t elem_or_pointee_clang_type;
701 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
702 GetClangAST(),
703 &elem_or_pointee_clang_type));
704
705 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000706 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000707 AddressType func_ptr_address_type = eAddressTypeInvalid;
708 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
709 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000710 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000711 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000712 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000713 case eAddressTypeInvalid:
714 case eAddressTypeFile:
715 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000716
Greg Claytoncc4d0142012-02-17 07:49:44 +0000717 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000718 {
719 ExecutionContext exe_ctx (GetExecutionContextRef());
720
721 Address so_addr;
722 Target *target = exe_ctx.GetTargetPtr();
723 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000724 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000725 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000726 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000727 so_addr.Dump (&sstr,
728 exe_ctx.GetBestExecutionContextScope(),
729 Address::DumpStyleResolvedDescription,
730 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000731 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000732 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000733 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000734 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000735
Greg Claytoncc4d0142012-02-17 07:49:44 +0000736 case eAddressTypeHost:
737 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000738 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000739 }
740 if (sstr.GetSize() > 0)
741 {
742 destination.assign (1, '(');
743 destination.append (sstr.GetData(), sstr.GetSize());
744 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000745 }
746 }
747 }
748 }
749 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000750 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000751 return !destination.empty();
752}
753
754const char *
755ValueObject::GetSummaryAsCString ()
756{
757 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
758 {
759 GetSummaryAsCString(GetSummaryFormat().get(),
760 m_summary_str);
761 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000762 if (m_summary_str.empty())
763 return NULL;
764 return m_summary_str.c_str();
765}
766
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000767bool
768ValueObject::IsCStringContainer(bool check_pointer)
769{
770 clang_type_t elem_or_pointee_clang_type;
771 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
772 GetClangAST(),
773 &elem_or_pointee_clang_type));
774 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
775 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
776 if (!is_char_arr_ptr)
777 return false;
778 if (!check_pointer)
779 return true;
780 if (type_flags.Test(ClangASTContext::eTypeIsArray))
781 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000782 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000783 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000784 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000785 return (cstr_address != LLDB_INVALID_ADDRESS);
786}
787
Enrico Granata9128ee22011-09-06 19:20:51 +0000788size_t
789ValueObject::GetPointeeData (DataExtractor& data,
790 uint32_t item_idx,
791 uint32_t item_count)
792{
793 if (!IsPointerType() && !IsArrayType())
794 return 0;
795
796 if (item_count == 0)
797 return 0;
798
799 uint32_t stride = 0;
800
801 ClangASTType type(GetClangAST(),
802 GetClangType());
803
804 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
805 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
806
807 const uint64_t bytes = item_count * item_type_size;
808
809 const uint64_t offset = item_idx * item_type_size;
810
811 if (item_idx == 0 && item_count == 1) // simply a deref
812 {
813 if (IsPointerType())
814 {
815 Error error;
816 ValueObjectSP pointee_sp = Dereference(error);
817 if (error.Fail() || pointee_sp.get() == NULL)
818 return 0;
819 return pointee_sp->GetDataExtractor().Copy(data);
820 }
821 else
822 {
823 ValueObjectSP child_sp = GetChildAtIndex(0, true);
824 if (child_sp.get() == NULL)
825 return 0;
826 return child_sp->GetDataExtractor().Copy(data);
827 }
828 return true;
829 }
830 else /* (items > 1) */
831 {
832 Error error;
833 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
834 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
835
836 AddressType addr_type;
837 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
838
Enrico Granata9128ee22011-09-06 19:20:51 +0000839 switch (addr_type)
840 {
841 case eAddressTypeFile:
842 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000843 ModuleSP module_sp (GetModule());
844 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000845 {
846 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000847 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000848 ExecutionContext exe_ctx (GetExecutionContextRef());
849 Target* target = exe_ctx.GetTargetPtr();
850 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000851 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000852 heap_buf_ptr->SetByteSize(bytes);
853 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
854 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000855 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000856 data.SetData(data_sp);
857 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000858 }
859 }
860 }
861 }
862 break;
863 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000864 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000865 ExecutionContext exe_ctx (GetExecutionContextRef());
866 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000867 if (process)
868 {
869 heap_buf_ptr->SetByteSize(bytes);
870 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
871 if (error.Success())
872 {
873 data.SetData(data_sp);
874 return bytes_read;
875 }
876 }
877 }
878 break;
879 case eAddressTypeHost:
880 {
881 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
882 data.SetData(data_sp);
883 return bytes;
884 }
885 break;
886 case eAddressTypeInvalid:
887 default:
888 break;
889 }
890 }
891 return 0;
892}
893
894size_t
895ValueObject::GetData (DataExtractor& data)
896{
897 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000898 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +0000899 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000900 if (error.Fail())
901 return 0;
902 data.SetAddressByteSize(m_data.GetAddressByteSize());
903 data.SetByteOrder(m_data.GetByteOrder());
904 return data.GetByteSize();
905}
906
907// will compute strlen(str), but without consuming more than
908// maxlen bytes out of str (this serves the purpose of reading
909// chunks of a string without having to worry about
910// missing NULL terminators in the chunk)
911// of course, if strlen(str) > maxlen, the function will return
912// maxlen_value (which should be != maxlen, because that allows you
913// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
914static uint32_t
915strlen_or_inf (const char* str,
916 uint32_t maxlen,
917 uint32_t maxlen_value)
918{
919 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000920 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000921 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000922 while(*str)
923 {
924 len++;str++;
925 if (len > maxlen)
926 return maxlen_value;
927 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000928 }
929 return len;
930}
931
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000932void
Greg Claytoncc4d0142012-02-17 07:49:44 +0000933ValueObject::ReadPointedString (Stream& s,
934 Error& error,
935 uint32_t max_length,
936 bool honor_array,
937 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000938{
Greg Claytoncc4d0142012-02-17 07:49:44 +0000939 ExecutionContext exe_ctx (GetExecutionContextRef());
940 Target* target = exe_ctx.GetTargetPtr();
941
942 if (target && max_length == 0)
943 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000944
945 clang_type_t clang_type = GetClangType();
946 clang_type_t elem_or_pointee_clang_type;
947 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
948 GetClangAST(),
949 &elem_or_pointee_clang_type));
950 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
951 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
952 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000953 if (target == NULL)
954 {
955 s << "<no target to read from>";
956 }
957 else
958 {
959 addr_t cstr_address = LLDB_INVALID_ADDRESS;
960 AddressType cstr_address_type = eAddressTypeInvalid;
961
962 size_t cstr_len = 0;
963 bool capped_data = false;
964 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000965 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000966 // We have an array
967 cstr_len = ClangASTContext::GetArraySize (clang_type);
968 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000969 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000970 capped_data = true;
971 cstr_len = max_length;
972 }
973 cstr_address = GetAddressOf (true, &cstr_address_type);
974 }
975 else
976 {
977 // We have a pointer
978 cstr_address = GetPointerValue (&cstr_address_type);
979 }
980 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
981 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000982 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000983 DataExtractor data;
984 size_t bytes_read = 0;
985 if (cstr_len > 0 && honor_array)
986 {
987 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
988 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
989 GetPointeeData(data, 0, cstr_len);
990
991 if ((bytes_read = data.GetByteSize()) > 0)
992 {
993 s << '"';
994 data.Dump (&s,
995 0, // Start offset in "data"
996 item_format,
997 1, // Size of item (1 byte for a char!)
998 bytes_read, // How many bytes to print?
999 UINT32_MAX, // num per line
1000 LLDB_INVALID_ADDRESS,// base address
1001 0, // bitfield bit size
1002 0); // bitfield bit offset
1003 if (capped_data)
1004 s << "...";
1005 s << '"';
1006 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001007 }
1008 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001009 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001010 cstr_len = max_length;
1011 const size_t k_max_buf_size = 64;
1012
1013 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001014
Greg Claytoncc4d0142012-02-17 07:49:44 +00001015 int cstr_len_displayed = -1;
1016 bool capped_cstr = false;
1017 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1018 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1019 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001020 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001021 const char *cstr = data.PeekCStr(0);
1022 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1023 if (len > k_max_buf_size)
1024 len = k_max_buf_size;
1025 if (cstr && cstr_len_displayed < 0)
1026 s << '"';
1027
1028 if (cstr_len_displayed < 0)
1029 cstr_len_displayed = len;
1030
1031 if (len == 0)
1032 break;
1033 cstr_len_displayed += len;
1034 if (len > bytes_read)
1035 len = bytes_read;
1036 if (len > cstr_len)
1037 len = cstr_len;
1038
1039 data.Dump (&s,
1040 0, // Start offset in "data"
1041 item_format,
1042 1, // Size of item (1 byte for a char!)
1043 len, // How many bytes to print?
1044 UINT32_MAX, // num per line
1045 LLDB_INVALID_ADDRESS,// base address
1046 0, // bitfield bit size
1047 0); // bitfield bit offset
1048
1049 if (len < k_max_buf_size)
1050 break;
1051
1052 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001053 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001054 capped_cstr = true;
1055 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001056 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001057
1058 cstr_len -= len;
1059 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001060 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001061
1062 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001063 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001064 s << '"';
1065 if (capped_cstr)
1066 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001067 }
1068 }
1069 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001070 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001071 }
1072 else
1073 {
1074 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001075 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001076 }
1077}
1078
Jim Ingham53c47f12010-09-10 23:12:17 +00001079const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001080ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001081{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001082
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001083 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001084 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001085
1086 if (!m_object_desc_str.empty())
1087 return m_object_desc_str.c_str();
1088
Greg Claytoncc4d0142012-02-17 07:49:44 +00001089 ExecutionContext exe_ctx (GetExecutionContextRef());
1090 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001091 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001092 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001093
Jim Ingham53c47f12010-09-10 23:12:17 +00001094 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001095
Greg Claytonafacd142011-09-02 01:15:17 +00001096 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001097 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1098
Jim Inghama2cf2632010-12-23 02:29:54 +00001099 if (runtime == NULL)
1100 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001101 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001102 clang_type_t opaque_qual_type = GetClangType();
1103 if (opaque_qual_type != NULL)
1104 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001105 bool is_signed;
1106 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1107 || ClangASTContext::IsPointerType (opaque_qual_type))
1108 {
Greg Claytonafacd142011-09-02 01:15:17 +00001109 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001110 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001111 }
1112 }
1113
Jim Ingham8d543de2011-03-31 23:01:21 +00001114 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001115 {
1116 m_object_desc_str.append (s.GetData());
1117 }
Sean Callanan672ad942010-10-23 00:18:49 +00001118
1119 if (m_object_desc_str.empty())
1120 return NULL;
1121 else
1122 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001123}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001124
Enrico Granata0c489f52012-03-01 04:24:26 +00001125bool
1126ValueObject::GetValueAsCString (lldb::Format format,
1127 std::string& destination)
1128{
1129 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1130 UpdateValueIfNeeded(false))
1131 {
1132 const Value::ContextType context_type = m_value.GetContextType();
1133
1134 switch (context_type)
1135 {
1136 case Value::eContextTypeClangType:
1137 case Value::eContextTypeLLDBType:
1138 case Value::eContextTypeVariable:
1139 {
1140 clang_type_t clang_type = GetClangType ();
1141 if (clang_type)
1142 {
1143 StreamString sstr;
1144 ExecutionContext exe_ctx (GetExecutionContextRef());
1145 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1146 clang_type, // The clang type to display
1147 &sstr,
1148 format, // Format to display this type with
1149 m_data, // Data to extract from
1150 0, // Byte offset into "m_data"
1151 GetByteSize(), // Byte size of item in "m_data"
1152 GetBitfieldBitSize(), // Bitfield bit size
1153 GetBitfieldBitOffset(), // Bitfield bit offset
1154 exe_ctx.GetBestExecutionContextScope());
1155 // Don't set the m_error to anything here otherwise
1156 // we won't be able to re-format as anything else. The
1157 // code for ClangASTType::DumpTypeValue() should always
1158 // return something, even if that something contains
1159 // an error messsage. "m_error" is used to detect errors
1160 // when reading the valid object, not for formatting errors.
1161 if (sstr.GetString().empty())
1162 destination.clear();
1163 else
1164 destination.swap(sstr.GetString());
1165 }
1166 }
1167 break;
1168
1169 case Value::eContextTypeRegisterInfo:
1170 {
1171 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1172 if (reg_info)
1173 {
1174 ExecutionContext exe_ctx (GetExecutionContextRef());
1175
1176 StreamString reg_sstr;
1177 m_data.Dump (&reg_sstr,
1178 0,
1179 format,
1180 reg_info->byte_size,
1181 1,
1182 UINT32_MAX,
1183 LLDB_INVALID_ADDRESS,
1184 0,
1185 0,
1186 exe_ctx.GetBestExecutionContextScope());
1187 destination.swap(reg_sstr.GetString());
1188 }
1189 }
1190 break;
1191
1192 default:
1193 break;
1194 }
1195 return !destination.empty();
1196 }
1197 else
1198 return false;
1199}
1200
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001201const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001202ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001203{
Enrico Granata0c489f52012-03-01 04:24:26 +00001204 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001205 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001206 lldb::Format my_format = GetFormat();
1207 if (m_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001208 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001209 if (m_type_format_sp)
1210 my_format = m_type_format_sp->GetFormat();
1211 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001213 if (m_is_bitfield_for_scalar)
1214 my_format = eFormatUnsigned;
1215 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001216 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001217 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001218 {
1219 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1220 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001221 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001222 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001223 else
1224 {
1225 clang_type_t clang_type = GetClangType ();
1226 my_format = ClangASTType::GetFormat(clang_type);
1227 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001228 }
1229 }
1230 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001231 if (GetValueAsCString(my_format, m_value_str))
1232 {
1233 if (!m_value_did_change && m_old_value_valid)
1234 {
1235 // The value was gotten successfully, so we consider the
1236 // value as changed if the value string differs
1237 SetValueDidChange (m_old_value_str != m_value_str);
1238 }
1239 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001240 }
1241 if (m_value_str.empty())
1242 return NULL;
1243 return m_value_str.c_str();
1244}
1245
Enrico Granatac3e320a2011-08-02 17:27:39 +00001246// if > 8bytes, 0 is returned. this method should mostly be used
1247// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001248uint64_t
1249ValueObject::GetValueAsUnsigned (uint64_t fail_value)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001250{
1251 // If our byte size is zero this is an aggregate type that has children
1252 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1253 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001254 Scalar scalar;
1255 if (ResolveValue (scalar))
1256 return scalar.GetRawBits64(fail_value);
Enrico Granatac3e320a2011-08-02 17:27:39 +00001257 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001258 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001259}
1260
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001261// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1262// this call up to date by returning true for your new special cases. We will eventually move
1263// to checking this call result before trying to display special cases
1264bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001265ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1266 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001267{
1268 clang_type_t elem_or_pointee_type;
1269 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1270
1271 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001272 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001273 {
1274 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001275 (custom_format == eFormatCString ||
1276 custom_format == eFormatCharArray ||
1277 custom_format == eFormatChar ||
1278 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001279 return true;
1280
1281 if (flags.Test(ClangASTContext::eTypeIsArray))
1282 {
Greg Claytonafacd142011-09-02 01:15:17 +00001283 if ((custom_format == eFormatBytes) ||
1284 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001285 return true;
1286
Greg Claytonafacd142011-09-02 01:15:17 +00001287 if ((custom_format == eFormatVectorOfChar) ||
1288 (custom_format == eFormatVectorOfFloat32) ||
1289 (custom_format == eFormatVectorOfFloat64) ||
1290 (custom_format == eFormatVectorOfSInt16) ||
1291 (custom_format == eFormatVectorOfSInt32) ||
1292 (custom_format == eFormatVectorOfSInt64) ||
1293 (custom_format == eFormatVectorOfSInt8) ||
1294 (custom_format == eFormatVectorOfUInt128) ||
1295 (custom_format == eFormatVectorOfUInt16) ||
1296 (custom_format == eFormatVectorOfUInt32) ||
1297 (custom_format == eFormatVectorOfUInt64) ||
1298 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001299 return true;
1300 }
1301 }
1302 return false;
1303}
1304
Enrico Granata9fc19442011-07-06 02:13:41 +00001305bool
1306ValueObject::DumpPrintableRepresentation(Stream& s,
1307 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001308 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001309 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001310{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001311
1312 clang_type_t elem_or_pointee_type;
1313 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001314
Enrico Granata86cc9822012-03-19 22:58:49 +00001315 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1316 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1317
1318 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001319 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001320 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1321 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001322 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001323 // when being asked to get a printable display an array or pointer type directly,
1324 // try to "do the right thing"
1325
1326 if (IsCStringContainer(true) &&
1327 (custom_format == eFormatCString ||
1328 custom_format == eFormatCharArray ||
1329 custom_format == eFormatChar ||
1330 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001331 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001332 Error error;
1333 ReadPointedString(s,
1334 error,
1335 0,
1336 (custom_format == eFormatVectorOfChar) ||
1337 (custom_format == eFormatCharArray));
1338 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001339 }
1340
Enrico Granata86cc9822012-03-19 22:58:49 +00001341 if (custom_format == eFormatEnum)
1342 return false;
1343
1344 // this only works for arrays, because I have no way to know when
1345 // the pointed memory ends, and no special \0 end of data marker
1346 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001347 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001348 if ((custom_format == eFormatBytes) ||
1349 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001350 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001351 uint32_t count = GetNumChildren();
1352
1353 s << '[';
1354 for (uint32_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001355 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001356
1357 if (low)
1358 s << ',';
1359
1360 ValueObjectSP child = GetChildAtIndex(low,true);
1361 if (!child.get())
1362 {
1363 s << "<invalid child>";
1364 continue;
1365 }
1366 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1367 }
1368
1369 s << ']';
1370
1371 return true;
1372 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001373
Enrico Granata86cc9822012-03-19 22:58:49 +00001374 if ((custom_format == eFormatVectorOfChar) ||
1375 (custom_format == eFormatVectorOfFloat32) ||
1376 (custom_format == eFormatVectorOfFloat64) ||
1377 (custom_format == eFormatVectorOfSInt16) ||
1378 (custom_format == eFormatVectorOfSInt32) ||
1379 (custom_format == eFormatVectorOfSInt64) ||
1380 (custom_format == eFormatVectorOfSInt8) ||
1381 (custom_format == eFormatVectorOfUInt128) ||
1382 (custom_format == eFormatVectorOfUInt16) ||
1383 (custom_format == eFormatVectorOfUInt32) ||
1384 (custom_format == eFormatVectorOfUInt64) ||
1385 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1386 {
1387 uint32_t count = GetNumChildren();
1388
1389 Format format = FormatManager::GetSingleItemFormat(custom_format);
1390
1391 s << '[';
1392 for (uint32_t low = 0; low < count; low++)
1393 {
1394
1395 if (low)
1396 s << ',';
1397
1398 ValueObjectSP child = GetChildAtIndex(low,true);
1399 if (!child.get())
1400 {
1401 s << "<invalid child>";
1402 continue;
1403 }
1404 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1405 }
1406
1407 s << ']';
1408
1409 return true;
1410 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001411 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001412
1413 if ((custom_format == eFormatBoolean) ||
1414 (custom_format == eFormatBinary) ||
1415 (custom_format == eFormatChar) ||
1416 (custom_format == eFormatCharPrintable) ||
1417 (custom_format == eFormatComplexFloat) ||
1418 (custom_format == eFormatDecimal) ||
1419 (custom_format == eFormatHex) ||
1420 (custom_format == eFormatFloat) ||
1421 (custom_format == eFormatOctal) ||
1422 (custom_format == eFormatOSType) ||
1423 (custom_format == eFormatUnicode16) ||
1424 (custom_format == eFormatUnicode32) ||
1425 (custom_format == eFormatUnsigned) ||
1426 (custom_format == eFormatPointer) ||
1427 (custom_format == eFormatComplexInteger) ||
1428 (custom_format == eFormatComplex) ||
1429 (custom_format == eFormatDefault)) // use the [] operator
1430 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001431 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001432 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001433
1434 if (only_special)
1435 return false;
1436
Enrico Granata86cc9822012-03-19 22:58:49 +00001437 bool var_success = false;
1438
1439 {
1440 const char * return_value;
1441 std::string alloc_mem;
1442
1443 if (custom_format != eFormatInvalid)
1444 SetFormat(custom_format);
1445
1446 switch(val_obj_display)
1447 {
1448 case eValueObjectRepresentationStyleValue:
1449 return_value = GetValueAsCString();
1450 break;
1451
1452 case eValueObjectRepresentationStyleSummary:
1453 return_value = GetSummaryAsCString();
1454 break;
1455
1456 case eValueObjectRepresentationStyleLanguageSpecific:
1457 return_value = GetObjectDescription();
1458 break;
1459
1460 case eValueObjectRepresentationStyleLocation:
1461 return_value = GetLocationAsCString();
1462 break;
1463
1464 case eValueObjectRepresentationStyleChildrenCount:
1465 {
1466 alloc_mem.resize(512);
1467 return_value = &alloc_mem[0];
1468 int count = GetNumChildren();
1469 snprintf((char*)return_value, 512, "%d", count);
1470 }
1471 break;
1472
1473 case eValueObjectRepresentationStyleType:
1474 return_value = GetTypeName().AsCString();
1475 break;
1476
1477 default:
1478 break;
1479 }
1480
1481 if (!return_value)
1482 {
1483 if (val_obj_display == eValueObjectRepresentationStyleValue)
1484 return_value = GetSummaryAsCString();
1485 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1486 {
1487 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1488 {
1489 // this thing has no value, and it seems to have no summary
1490 // some combination of unitialized data and other factors can also
1491 // raise this condition, so let's print a nice generic description
1492 {
1493 alloc_mem.resize(684);
1494 return_value = &alloc_mem[0];
1495 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1496 }
1497 }
1498 else
1499 return_value = GetValueAsCString();
1500 }
1501 }
1502
1503 if (return_value)
1504 s.PutCString(return_value);
1505 else
1506 {
1507 if (m_error.Fail())
1508 s.Printf("<%s>", m_error.AsCString());
1509 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1510 s.PutCString("<no summary available>");
1511 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1512 s.PutCString("<no value available>");
1513 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1514 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1515 else
1516 s.PutCString("<no printable representation>");
1517 }
1518
1519 // we should only return false here if we could not do *anything*
1520 // even if we have an error message as output, that's a success
1521 // from our callers' perspective, so return true
1522 var_success = true;
1523
1524 if (custom_format != eFormatInvalid)
1525 SetFormat(eFormatDefault);
1526 }
1527
Enrico Granataf4efecd2011-07-12 22:56:10 +00001528 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001529}
1530
Greg Clayton737b9322010-09-13 03:32:57 +00001531addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001532ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001533{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001534 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001535 return LLDB_INVALID_ADDRESS;
1536
Greg Clayton73b472d2010-10-27 03:32:59 +00001537 switch (m_value.GetValueType())
1538 {
1539 case Value::eValueTypeScalar:
1540 if (scalar_is_load_address)
1541 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001542 if(address_type)
1543 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001544 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1545 }
1546 break;
1547
1548 case Value::eValueTypeLoadAddress:
1549 case Value::eValueTypeFileAddress:
1550 case Value::eValueTypeHostAddress:
1551 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001552 if(address_type)
1553 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001554 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1555 }
1556 break;
1557 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001558 if (address_type)
1559 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001560 return LLDB_INVALID_ADDRESS;
1561}
1562
1563addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001564ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001565{
Greg Claytonafacd142011-09-02 01:15:17 +00001566 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001567 if(address_type)
1568 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001569
Enrico Granatac3e320a2011-08-02 17:27:39 +00001570 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001571 return address;
1572
Greg Clayton73b472d2010-10-27 03:32:59 +00001573 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001574 {
1575 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001576 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001577 break;
1578
Enrico Granata9128ee22011-09-06 19:20:51 +00001579 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001580 case Value::eValueTypeLoadAddress:
1581 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001582 {
1583 uint32_t data_offset = 0;
1584 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001585 }
1586 break;
1587 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001588
Enrico Granata9128ee22011-09-06 19:20:51 +00001589 if (address_type)
1590 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001591
Greg Clayton737b9322010-09-13 03:32:57 +00001592 return address;
1593}
1594
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001595bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001596ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001597{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001598 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001599 // Make sure our value is up to date first so that our location and location
1600 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001601 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001602 {
1603 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001604 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001605 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001606
1607 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001608 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001609
Greg Claytonb1320972010-07-14 00:18:15 +00001610 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001611
Jim Ingham16e0c682011-08-12 23:34:31 +00001612 Value::ValueType value_type = m_value.GetValueType();
1613
1614 if (value_type == Value::eValueTypeScalar)
1615 {
1616 // If the value is already a scalar, then let the scalar change itself:
1617 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1618 }
1619 else if (byte_size <= Scalar::GetMaxByteSize())
1620 {
1621 // If the value fits in a scalar, then make a new scalar and again let the
1622 // scalar code do the conversion, then figure out where to put the new value.
1623 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001624 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1625 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001626 {
Jim Ingham4b536182011-08-09 02:12:22 +00001627 switch (value_type)
1628 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001629 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001630 {
1631 // If it is a load address, then the scalar value is the storage location
1632 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001633 ExecutionContext exe_ctx (GetExecutionContextRef());
1634 Process *process = exe_ctx.GetProcessPtr();
1635 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001636 {
Greg Claytonafacd142011-09-02 01:15:17 +00001637 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001638 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1639 new_scalar,
1640 byte_size,
1641 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001642 if (!error.Success())
1643 return false;
1644 if (bytes_written != byte_size)
1645 {
1646 error.SetErrorString("unable to write value to memory");
1647 return false;
1648 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001649 }
1650 }
Jim Ingham4b536182011-08-09 02:12:22 +00001651 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001652 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001653 {
1654 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1655 DataExtractor new_data;
1656 new_data.SetByteOrder (m_data.GetByteOrder());
1657
1658 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1659 m_data.SetData(buffer_sp, 0);
1660 bool success = new_scalar.GetData(new_data);
1661 if (success)
1662 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001663 new_data.CopyByteOrderedData (0,
1664 byte_size,
1665 const_cast<uint8_t *>(m_data.GetDataStart()),
1666 byte_size,
1667 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001668 }
1669 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1670
1671 }
Jim Ingham4b536182011-08-09 02:12:22 +00001672 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001673 case Value::eValueTypeFileAddress:
1674 case Value::eValueTypeScalar:
Jim Ingham16e0c682011-08-12 23:34:31 +00001675 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001676 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001677 }
1678 else
1679 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001680 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001681 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001682 }
1683 else
1684 {
1685 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001686 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001687 return false;
1688 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001689
1690 // If we have reached this point, then we have successfully changed the value.
1691 SetNeedsUpdate();
1692 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001693}
1694
Greg Clayton81e871e2012-02-04 02:27:34 +00001695bool
1696ValueObject::GetDeclaration (Declaration &decl)
1697{
1698 decl.Clear();
1699 return false;
1700}
1701
Greg Clayton84db9102012-03-26 23:03:23 +00001702ConstString
1703ValueObject::GetTypeName()
1704{
1705 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1706}
1707
1708ConstString
1709ValueObject::GetQualifiedTypeName()
1710{
1711 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1712}
1713
1714
Greg Claytonafacd142011-09-02 01:15:17 +00001715LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001716ValueObject::GetObjectRuntimeLanguage ()
1717{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001718 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1719 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001720}
1721
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001722void
Jim Ingham58b59f92011-04-22 23:53:53 +00001723ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001724{
Jim Ingham58b59f92011-04-22 23:53:53 +00001725 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001726}
1727
1728ValueObjectSP
1729ValueObject::GetSyntheticChild (const ConstString &key) const
1730{
1731 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001732 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001733 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001734 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001735 return synthetic_child_sp;
1736}
1737
1738bool
1739ValueObject::IsPointerType ()
1740{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001741 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001742}
1743
Jim Inghamb7603bb2011-03-18 00:05:18 +00001744bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001745ValueObject::IsArrayType ()
1746{
1747 return ClangASTContext::IsArrayType (GetClangType());
1748}
1749
1750bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001751ValueObject::IsScalarType ()
1752{
1753 return ClangASTContext::IsScalarType (GetClangType());
1754}
1755
1756bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001757ValueObject::IsIntegerType (bool &is_signed)
1758{
1759 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1760}
Greg Clayton73b472d2010-10-27 03:32:59 +00001761
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001762bool
1763ValueObject::IsPointerOrReferenceType ()
1764{
Greg Clayton007d5be2011-05-30 00:49:24 +00001765 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1766}
1767
1768bool
1769ValueObject::IsPossibleCPlusPlusDynamicType ()
1770{
1771 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001772}
1773
Greg Claytondea8cb42011-06-29 22:09:02 +00001774bool
1775ValueObject::IsPossibleDynamicType ()
1776{
1777 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1778}
1779
Greg Claytonafacd142011-09-02 01:15:17 +00001780ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001781ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1782{
1783 if (IsArrayType())
1784 return GetSyntheticArrayMemberFromArray(index, can_create);
1785
1786 if (IsPointerType())
1787 return GetSyntheticArrayMemberFromPointer(index, can_create);
1788
1789 return ValueObjectSP();
1790
1791}
1792
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001793ValueObjectSP
1794ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1795{
1796 ValueObjectSP synthetic_child_sp;
1797 if (IsPointerType ())
1798 {
1799 char index_str[64];
1800 snprintf(index_str, sizeof(index_str), "[%i]", index);
1801 ConstString index_const_str(index_str);
1802 // Check if we have already created a synthetic array member in this
1803 // valid object. If we have we will re-use it.
1804 synthetic_child_sp = GetSyntheticChild (index_const_str);
1805 if (!synthetic_child_sp)
1806 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001807 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001808 // We haven't made a synthetic array member for INDEX yet, so
1809 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001810 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001811
1812 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001813 if (synthetic_child)
1814 {
1815 AddSyntheticChild(index_const_str, synthetic_child);
1816 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001817 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001818 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001819 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001820 }
1821 }
1822 return synthetic_child_sp;
1823}
Jim Ingham22777012010-09-23 02:01:19 +00001824
Greg Claytondaf515f2011-07-09 20:12:33 +00001825// This allows you to create an array member using and index
1826// that doesn't not fall in the normal bounds of the array.
1827// Many times structure can be defined as:
1828// struct Collection
1829// {
1830// uint32_t item_count;
1831// Item item_array[0];
1832// };
1833// The size of the "item_array" is 1, but many times in practice
1834// there are more items in "item_array".
1835
1836ValueObjectSP
1837ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1838{
1839 ValueObjectSP synthetic_child_sp;
1840 if (IsArrayType ())
1841 {
1842 char index_str[64];
1843 snprintf(index_str, sizeof(index_str), "[%i]", index);
1844 ConstString index_const_str(index_str);
1845 // Check if we have already created a synthetic array member in this
1846 // valid object. If we have we will re-use it.
1847 synthetic_child_sp = GetSyntheticChild (index_const_str);
1848 if (!synthetic_child_sp)
1849 {
1850 ValueObject *synthetic_child;
1851 // We haven't made a synthetic array member for INDEX yet, so
1852 // lets make one and cache it for any future reference.
1853 synthetic_child = CreateChildAtIndex(0, true, index);
1854
1855 // Cache the value if we got one back...
1856 if (synthetic_child)
1857 {
1858 AddSyntheticChild(index_const_str, synthetic_child);
1859 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001860 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001861 synthetic_child_sp->m_is_array_item_for_pointer = true;
1862 }
1863 }
1864 }
1865 return synthetic_child_sp;
1866}
1867
Enrico Granata9fc19442011-07-06 02:13:41 +00001868ValueObjectSP
1869ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1870{
1871 ValueObjectSP synthetic_child_sp;
1872 if (IsScalarType ())
1873 {
1874 char index_str[64];
1875 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1876 ConstString index_const_str(index_str);
1877 // Check if we have already created a synthetic array member in this
1878 // valid object. If we have we will re-use it.
1879 synthetic_child_sp = GetSyntheticChild (index_const_str);
1880 if (!synthetic_child_sp)
1881 {
1882 ValueObjectChild *synthetic_child;
1883 // We haven't made a synthetic array member for INDEX yet, so
1884 // lets make one and cache it for any future reference.
1885 synthetic_child = new ValueObjectChild(*this,
1886 GetClangAST(),
1887 GetClangType(),
1888 index_const_str,
1889 GetByteSize(),
1890 0,
1891 to-from+1,
1892 from,
1893 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001894 false,
1895 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001896
1897 // Cache the value if we got one back...
1898 if (synthetic_child)
1899 {
1900 AddSyntheticChild(index_const_str, synthetic_child);
1901 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001902 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001903 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1904 }
1905 }
1906 }
1907 return synthetic_child_sp;
1908}
1909
Greg Claytonafacd142011-09-02 01:15:17 +00001910ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001911ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1912{
1913 ValueObjectSP synthetic_child_sp;
1914 if (IsArrayType () || IsPointerType ())
1915 {
1916 char index_str[64];
1917 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1918 ConstString index_const_str(index_str);
1919 // Check if we have already created a synthetic array member in this
1920 // valid object. If we have we will re-use it.
1921 synthetic_child_sp = GetSyntheticChild (index_const_str);
1922 if (!synthetic_child_sp)
1923 {
1924 ValueObjectSynthetic *synthetic_child;
1925
1926 // We haven't made a synthetic array member for INDEX yet, so
1927 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001928 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001929 view->AddRange(from,to);
1930 SyntheticChildrenSP view_sp(view);
1931 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1932
1933 // Cache the value if we got one back...
1934 if (synthetic_child)
1935 {
1936 AddSyntheticChild(index_const_str, synthetic_child);
1937 synthetic_child_sp = synthetic_child->GetSP();
1938 synthetic_child_sp->SetName(ConstString(index_str));
1939 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1940 }
1941 }
1942 }
1943 return synthetic_child_sp;
1944}
1945
Greg Claytonafacd142011-09-02 01:15:17 +00001946ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001947ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1948{
1949
1950 ValueObjectSP synthetic_child_sp;
1951
1952 char name_str[64];
1953 snprintf(name_str, sizeof(name_str), "@%i", offset);
1954 ConstString name_const_str(name_str);
1955
1956 // Check if we have already created a synthetic array member in this
1957 // valid object. If we have we will re-use it.
1958 synthetic_child_sp = GetSyntheticChild (name_const_str);
1959
1960 if (synthetic_child_sp.get())
1961 return synthetic_child_sp;
1962
1963 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001964 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001965
1966 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1967 type.GetASTContext(),
1968 type.GetOpaqueQualType(),
1969 name_const_str,
1970 type.GetTypeByteSize(),
1971 offset,
1972 0,
1973 0,
1974 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001975 false,
1976 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001977 if (synthetic_child)
1978 {
1979 AddSyntheticChild(name_const_str, synthetic_child);
1980 synthetic_child_sp = synthetic_child->GetSP();
1981 synthetic_child_sp->SetName(name_const_str);
1982 synthetic_child_sp->m_is_child_at_offset = true;
1983 }
1984 return synthetic_child_sp;
1985}
1986
Enrico Granatad55546b2011-07-22 00:16:08 +00001987// your expression path needs to have a leading . or ->
1988// (unless it somehow "looks like" an array, in which case it has
1989// a leading [ symbol). while the [ is meaningful and should be shown
1990// to the user, . and -> are just parser design, but by no means
1991// added information for the user.. strip them off
1992static const char*
1993SkipLeadingExpressionPathSeparators(const char* expression)
1994{
1995 if (!expression || !expression[0])
1996 return expression;
1997 if (expression[0] == '.')
1998 return expression+1;
1999 if (expression[0] == '-' && expression[1] == '>')
2000 return expression+2;
2001 return expression;
2002}
2003
Greg Claytonafacd142011-09-02 01:15:17 +00002004ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002005ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2006{
2007 ValueObjectSP synthetic_child_sp;
2008 ConstString name_const_string(expression);
2009 // Check if we have already created a synthetic array member in this
2010 // valid object. If we have we will re-use it.
2011 synthetic_child_sp = GetSyntheticChild (name_const_string);
2012 if (!synthetic_child_sp)
2013 {
2014 // We haven't made a synthetic array member for expression yet, so
2015 // lets make one and cache it for any future reference.
2016 synthetic_child_sp = GetValueForExpressionPath(expression);
2017
2018 // Cache the value if we got one back...
2019 if (synthetic_child_sp.get())
2020 {
2021 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002022 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002023 synthetic_child_sp->m_is_expression_path_child = true;
2024 }
2025 }
2026 return synthetic_child_sp;
2027}
2028
2029void
Enrico Granata86cc9822012-03-19 22:58:49 +00002030ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002031{
Enrico Granata86cc9822012-03-19 22:58:49 +00002032 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002033 return;
2034
Enrico Granatac5bc4122012-03-27 02:35:13 +00002035 TargetSP target_sp(GetTargetSP());
2036 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2037 {
2038 m_synthetic_value = NULL;
2039 return;
2040 }
2041
Enrico Granata86cc9822012-03-19 22:58:49 +00002042 if (!UpdateFormatsIfNeeded(m_last_format_mgr_dynamic) && m_synthetic_value)
2043 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002044
Enrico Granata0c489f52012-03-01 04:24:26 +00002045 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002046 return;
2047
Enrico Granata86cc9822012-03-19 22:58:49 +00002048 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002049}
2050
Jim Ingham78a685a2011-04-16 00:01:13 +00002051void
Greg Claytonafacd142011-09-02 01:15:17 +00002052ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002053{
Greg Claytonafacd142011-09-02 01:15:17 +00002054 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002055 return;
2056
Jim Ingham58b59f92011-04-22 23:53:53 +00002057 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002058 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002059 ExecutionContext exe_ctx (GetExecutionContextRef());
2060 Process *process = exe_ctx.GetProcessPtr();
2061 if (process)
Jim Ingham78a685a2011-04-16 00:01:13 +00002062 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002063 bool worth_having_dynamic_value = false;
Jim Ingham78a685a2011-04-16 00:01:13 +00002064
Greg Claytoncc4d0142012-02-17 07:49:44 +00002065
2066 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
2067 // hard code this everywhere.
2068 LanguageType known_type = GetObjectRuntimeLanguage();
2069 if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
Jim Ingham78a685a2011-04-16 00:01:13 +00002070 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002071 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
2072 if (runtime)
2073 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00002074 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00002075 else
2076 {
2077 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus);
2078 if (cpp_runtime)
2079 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
2080
2081 if (!worth_having_dynamic_value)
2082 {
2083 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC);
2084 if (objc_runtime)
2085 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
2086 }
2087 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002088
Greg Claytoncc4d0142012-02-17 07:49:44 +00002089 if (worth_having_dynamic_value)
2090 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
2091 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002092 }
2093}
2094
Jim Ingham58b59f92011-04-22 23:53:53 +00002095ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002096ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002097{
Greg Claytonafacd142011-09-02 01:15:17 +00002098 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002099 return ValueObjectSP();
2100
2101 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002102 {
Jim Ingham2837b762011-05-04 03:43:18 +00002103 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002104 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002105 if (m_dynamic_value)
2106 return m_dynamic_value->GetSP();
2107 else
2108 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002109}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002110
Jim Ingham60dbabb2011-12-08 19:44:08 +00002111ValueObjectSP
2112ValueObject::GetStaticValue()
2113{
2114 return GetSP();
2115}
2116
Enrico Granata886147f2012-05-08 18:47:08 +00002117lldb::ValueObjectSP
2118ValueObject::GetNonSyntheticValue ()
2119{
2120 return GetSP();
2121}
2122
Enrico Granatad55546b2011-07-22 00:16:08 +00002123ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002124ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002125{
Enrico Granata86cc9822012-03-19 22:58:49 +00002126 if (use_synthetic == false)
2127 return ValueObjectSP();
2128
Enrico Granatad55546b2011-07-22 00:16:08 +00002129 CalculateSyntheticValue(use_synthetic);
2130
2131 if (m_synthetic_value)
2132 return m_synthetic_value->GetSP();
2133 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002134 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002135}
2136
Greg Claytone221f822011-01-21 01:59:00 +00002137bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002138ValueObject::HasSyntheticValue()
2139{
2140 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2141
Enrico Granata0c489f52012-03-01 04:24:26 +00002142 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002143 return false;
2144
Enrico Granata86cc9822012-03-19 22:58:49 +00002145 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002146
2147 if (m_synthetic_value)
2148 return true;
2149 else
2150 return false;
2151}
2152
2153bool
Greg Claytone221f822011-01-21 01:59:00 +00002154ValueObject::GetBaseClassPath (Stream &s)
2155{
2156 if (IsBaseClass())
2157 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002158 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002159 clang_type_t clang_type = GetClangType();
2160 std::string cxx_class_name;
2161 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2162 if (this_had_base_class)
2163 {
2164 if (parent_had_base_class)
2165 s.PutCString("::");
2166 s.PutCString(cxx_class_name.c_str());
2167 }
2168 return parent_had_base_class || this_had_base_class;
2169 }
2170 return false;
2171}
2172
2173
2174ValueObject *
2175ValueObject::GetNonBaseClassParent()
2176{
Jim Ingham78a685a2011-04-16 00:01:13 +00002177 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002178 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002179 if (GetParent()->IsBaseClass())
2180 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002181 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002182 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002183 }
2184 return NULL;
2185}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002186
2187void
Enrico Granata4becb372011-06-29 22:27:15 +00002188ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002189{
Greg Claytone221f822011-01-21 01:59:00 +00002190 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002191
Enrico Granata86cc9822012-03-19 22:58:49 +00002192 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002193 {
Enrico Granata4becb372011-06-29 22:27:15 +00002194 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2195 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2196 // the eHonorPointers mode is meant to produce strings in this latter format
2197 s.PutCString("*(");
2198 }
Greg Claytone221f822011-01-21 01:59:00 +00002199
Enrico Granata4becb372011-06-29 22:27:15 +00002200 ValueObject* parent = GetParent();
2201
2202 if (parent)
2203 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002204
2205 // if we are a deref_of_parent just because we are synthetic array
2206 // members made up to allow ptr[%d] syntax to work in variable
2207 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002208 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002209 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002210
Greg Claytone221f822011-01-21 01:59:00 +00002211 if (!IsBaseClass())
2212 {
2213 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002214 {
Greg Claytone221f822011-01-21 01:59:00 +00002215 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2216 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002217 {
Greg Claytone221f822011-01-21 01:59:00 +00002218 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2219 if (non_base_class_parent_clang_type)
2220 {
2221 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2222
Enrico Granata86cc9822012-03-19 22:58:49 +00002223 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002224 {
2225 s.PutCString("->");
2226 }
Enrico Granata4becb372011-06-29 22:27:15 +00002227 else
2228 {
2229 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2230 {
2231 s.PutCString("->");
2232 }
2233 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2234 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2235 {
2236 s.PutChar('.');
2237 }
Greg Claytone221f822011-01-21 01:59:00 +00002238 }
2239 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002240 }
Greg Claytone221f822011-01-21 01:59:00 +00002241
2242 const char *name = GetName().GetCString();
2243 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002244 {
Greg Claytone221f822011-01-21 01:59:00 +00002245 if (qualify_cxx_base_classes)
2246 {
2247 if (GetBaseClassPath (s))
2248 s.PutCString("::");
2249 }
2250 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002251 }
2252 }
2253 }
2254
Enrico Granata86cc9822012-03-19 22:58:49 +00002255 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002256 {
Greg Claytone221f822011-01-21 01:59:00 +00002257 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002258 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002259}
2260
Greg Claytonafacd142011-09-02 01:15:17 +00002261ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002262ValueObject::GetValueForExpressionPath(const char* expression,
2263 const char** first_unparsed,
2264 ExpressionPathScanEndReason* reason_to_stop,
2265 ExpressionPathEndResultType* final_value_type,
2266 const GetValueForExpressionPathOptions& options,
2267 ExpressionPathAftermath* final_task_on_target)
2268{
2269
2270 const char* dummy_first_unparsed;
2271 ExpressionPathScanEndReason dummy_reason_to_stop;
2272 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002273 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002274
2275 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2276 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2277 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2278 final_value_type ? final_value_type : &dummy_final_value_type,
2279 options,
2280 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2281
Enrico Granata86cc9822012-03-19 22:58:49 +00002282 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002283 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002284
Enrico Granata86cc9822012-03-19 22:58:49 +00002285 if (ret_val.get() && ((final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress of plain objects
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002286 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002287 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002288 {
2289 Error error;
2290 ValueObjectSP final_value = ret_val->Dereference(error);
2291 if (error.Fail() || !final_value.get())
2292 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002293 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002294 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002295 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002296 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002297 return ValueObjectSP();
2298 }
2299 else
2300 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002301 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002302 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002303 return final_value;
2304 }
2305 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002306 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002307 {
2308 Error error;
2309 ValueObjectSP final_value = ret_val->AddressOf(error);
2310 if (error.Fail() || !final_value.get())
2311 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002312 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002313 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002314 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002315 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002316 return ValueObjectSP();
2317 }
2318 else
2319 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002320 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002321 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002322 return final_value;
2323 }
2324 }
2325 }
2326 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2327}
2328
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002329int
2330ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002331 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002332 const char** first_unparsed,
2333 ExpressionPathScanEndReason* reason_to_stop,
2334 ExpressionPathEndResultType* final_value_type,
2335 const GetValueForExpressionPathOptions& options,
2336 ExpressionPathAftermath* final_task_on_target)
2337{
2338 const char* dummy_first_unparsed;
2339 ExpressionPathScanEndReason dummy_reason_to_stop;
2340 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002341 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002342
2343 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2344 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2345 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2346 final_value_type ? final_value_type : &dummy_final_value_type,
2347 options,
2348 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2349
2350 if (!ret_val.get()) // if there are errors, I add nothing to the list
2351 return 0;
2352
Enrico Granata86ea8d82012-03-29 01:34:34 +00002353 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002354 {
2355 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002356 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002357 {
2358 list->Append(ret_val);
2359 return 1;
2360 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002361 if (ret_val.get() && (final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain) // I can only deref and takeaddress of plain objects
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002362 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002363 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002364 {
2365 Error error;
2366 ValueObjectSP final_value = ret_val->Dereference(error);
2367 if (error.Fail() || !final_value.get())
2368 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002369 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2370 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002371 return 0;
2372 }
2373 else
2374 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002375 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002376 list->Append(final_value);
2377 return 1;
2378 }
2379 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002380 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002381 {
2382 Error error;
2383 ValueObjectSP final_value = ret_val->AddressOf(error);
2384 if (error.Fail() || !final_value.get())
2385 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002386 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2387 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002388 return 0;
2389 }
2390 else
2391 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002392 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002393 list->Append(final_value);
2394 return 1;
2395 }
2396 }
2397 }
2398 }
2399 else
2400 {
2401 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2402 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2403 ret_val,
2404 list,
2405 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2406 final_value_type ? final_value_type : &dummy_final_value_type,
2407 options,
2408 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2409 }
2410 // in any non-covered case, just do the obviously right thing
2411 list->Append(ret_val);
2412 return 1;
2413}
2414
Greg Claytonafacd142011-09-02 01:15:17 +00002415ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002416ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2417 const char** first_unparsed,
2418 ExpressionPathScanEndReason* reason_to_stop,
2419 ExpressionPathEndResultType* final_result,
2420 const GetValueForExpressionPathOptions& options,
2421 ExpressionPathAftermath* what_next)
2422{
2423 ValueObjectSP root = GetSP();
2424
2425 if (!root.get())
2426 return ValueObjectSP();
2427
2428 *first_unparsed = expression_cstr;
2429
2430 while (true)
2431 {
2432
2433 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2434
Greg Claytonafacd142011-09-02 01:15:17 +00002435 clang_type_t root_clang_type = root->GetClangType();
2436 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002437 Flags root_clang_type_info,pointee_clang_type_info;
2438
2439 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2440 if (pointee_clang_type)
2441 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002442
2443 if (!expression_cstr || *expression_cstr == '\0')
2444 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002445 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002446 return root;
2447 }
2448
2449 switch (*expression_cstr)
2450 {
2451 case '-':
2452 {
2453 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002454 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 +00002455 {
2456 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002457 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2458 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002459 return ValueObjectSP();
2460 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002461 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2462 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002463 options.m_no_fragile_ivar)
2464 {
2465 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002466 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2467 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002468 return ValueObjectSP();
2469 }
2470 if (expression_cstr[1] != '>')
2471 {
2472 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002473 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2474 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002475 return ValueObjectSP();
2476 }
2477 expression_cstr++; // skip the -
2478 }
2479 case '.': // or fallthrough from ->
2480 {
2481 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002482 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 +00002483 {
2484 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002485 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2486 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002487 return ValueObjectSP();
2488 }
2489 expression_cstr++; // skip .
2490 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2491 ConstString child_name;
2492 if (!next_separator) // if no other separator just expand this last layer
2493 {
2494 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002495 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2496
2497 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002498 {
2499 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002500 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2501 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002502 return child_valobj_sp;
2503 }
2504 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2505 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002506 if (root->IsSynthetic())
2507 child_valobj_sp = root;
2508 else
2509 child_valobj_sp = root->GetSyntheticValue();
2510
2511 if (child_valobj_sp.get())
2512 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002513 }
2514
2515 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2516 // so we hit the "else" branch, and return an error
2517 if(child_valobj_sp.get()) // if it worked, just return
2518 {
2519 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002520 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2521 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002522 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002523 }
2524 else
2525 {
2526 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002527 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2528 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002529 return ValueObjectSP();
2530 }
2531 }
2532 else // other layers do expand
2533 {
2534 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002535 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2536 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002537 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002538 root = child_valobj_sp;
2539 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002540 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002541 continue;
2542 }
2543 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2544 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002545 child_valobj_sp = root->GetSyntheticValue(true);
2546 if (child_valobj_sp)
2547 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002548 }
2549
2550 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2551 // so we hit the "else" branch, and return an error
2552 if(child_valobj_sp.get()) // if it worked, move on
2553 {
2554 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002555 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002556 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002557 continue;
2558 }
2559 else
2560 {
2561 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002562 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2563 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002564 return ValueObjectSP();
2565 }
2566 }
2567 break;
2568 }
2569 case '[':
2570 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002571 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 +00002572 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002573 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002574 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002575 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2576 {
2577 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002578 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2579 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002580 return ValueObjectSP();
2581 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002582 }
2583 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2584 {
2585 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002586 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2587 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002588 return ValueObjectSP();
2589 }
2590 }
2591 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2592 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002593 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002594 {
2595 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002596 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2597 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002598 return ValueObjectSP();
2599 }
2600 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2601 {
2602 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002603 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2604 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002605 return root;
2606 }
2607 }
2608 const char *separator_position = ::strchr(expression_cstr+1,'-');
2609 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2610 if (!close_bracket_position) // if there is no ], this is a syntax error
2611 {
2612 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002613 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2614 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002615 return ValueObjectSP();
2616 }
2617 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2618 {
2619 char *end = NULL;
2620 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2621 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2622 {
2623 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002624 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2625 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002626 return ValueObjectSP();
2627 }
2628 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2629 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002630 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002631 {
2632 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002633 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2634 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002635 return root;
2636 }
2637 else
2638 {
2639 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002640 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2641 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002642 return ValueObjectSP();
2643 }
2644 }
2645 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002646 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002647 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002648 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2649 if (!child_valobj_sp)
2650 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002651 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002652 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2653 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002654 if (child_valobj_sp)
2655 {
2656 root = child_valobj_sp;
2657 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002658 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002659 continue;
2660 }
2661 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002662 {
2663 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002664 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2665 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002666 return ValueObjectSP();
2667 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002668 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002669 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002670 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002671 if (*what_next == ValueObject::eExpressionPathAftermathDereference && // 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 +00002672 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002673 {
2674 Error error;
2675 root = root->Dereference(error);
2676 if (error.Fail() || !root.get())
2677 {
2678 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002679 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2680 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002681 return ValueObjectSP();
2682 }
2683 else
2684 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002685 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002686 continue;
2687 }
2688 }
2689 else
2690 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002691 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002692 root->GetClangType()) == eLanguageTypeObjC
2693 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2694 && root->HasSyntheticValue()
2695 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002696 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002697 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002698 }
2699 else
2700 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002701 if (!root.get())
2702 {
2703 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002704 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2705 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002706 return ValueObjectSP();
2707 }
2708 else
2709 {
2710 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002711 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002712 continue;
2713 }
2714 }
2715 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002716 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002717 {
2718 root = root->GetSyntheticBitFieldChild(index, index, true);
2719 if (!root.get())
2720 {
2721 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002722 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2723 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002724 return ValueObjectSP();
2725 }
2726 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2727 {
2728 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002729 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2730 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002731 return root;
2732 }
2733 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002734 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002735 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002736 if (root->HasSyntheticValue())
2737 root = root->GetSyntheticValue();
2738 else if (!root->IsSynthetic())
2739 {
2740 *first_unparsed = expression_cstr;
2741 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2742 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2743 return ValueObjectSP();
2744 }
2745 // if we are here, then root itself is a synthetic VO.. should be good to go
2746
Enrico Granata27b625e2011-08-09 01:04:56 +00002747 if (!root.get())
2748 {
2749 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002750 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2751 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2752 return ValueObjectSP();
2753 }
2754 root = root->GetChildAtIndex(index, true);
2755 if (!root.get())
2756 {
2757 *first_unparsed = expression_cstr;
2758 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2759 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002760 return ValueObjectSP();
2761 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002762 else
2763 {
2764 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002765 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002766 continue;
2767 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002768 }
2769 else
2770 {
2771 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002772 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2773 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002774 return ValueObjectSP();
2775 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002776 }
2777 else // we have a low and a high index
2778 {
2779 char *end = NULL;
2780 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2781 if (!end || end != separator_position) // if something weird is in our way return an error
2782 {
2783 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002784 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2785 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002786 return ValueObjectSP();
2787 }
2788 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2789 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2790 {
2791 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002792 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2793 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002794 return ValueObjectSP();
2795 }
2796 if (index_lower > index_higher) // swap indices if required
2797 {
2798 unsigned long temp = index_lower;
2799 index_lower = index_higher;
2800 index_higher = temp;
2801 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002802 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002803 {
2804 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2805 if (!root.get())
2806 {
2807 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002808 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2809 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002810 return ValueObjectSP();
2811 }
2812 else
2813 {
2814 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002815 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2816 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002817 return root;
2818 }
2819 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002820 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 Granata86cc9822012-03-19 22:58:49 +00002821 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002822 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002823 {
2824 Error error;
2825 root = root->Dereference(error);
2826 if (error.Fail() || !root.get())
2827 {
2828 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002829 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2830 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002831 return ValueObjectSP();
2832 }
2833 else
2834 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002835 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002836 continue;
2837 }
2838 }
2839 else
2840 {
2841 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002842 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2843 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002844 return root;
2845 }
2846 }
2847 break;
2848 }
2849 default: // some non-separator is in the way
2850 {
2851 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002852 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2853 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002854 return ValueObjectSP();
2855 break;
2856 }
2857 }
2858 }
2859}
2860
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002861int
2862ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2863 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002864 ValueObjectSP root,
2865 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002866 ExpressionPathScanEndReason* reason_to_stop,
2867 ExpressionPathEndResultType* final_result,
2868 const GetValueForExpressionPathOptions& options,
2869 ExpressionPathAftermath* what_next)
2870{
2871 if (!root.get())
2872 return 0;
2873
2874 *first_unparsed = expression_cstr;
2875
2876 while (true)
2877 {
2878
2879 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2880
Greg Claytonafacd142011-09-02 01:15:17 +00002881 clang_type_t root_clang_type = root->GetClangType();
2882 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002883 Flags root_clang_type_info,pointee_clang_type_info;
2884
2885 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2886 if (pointee_clang_type)
2887 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2888
2889 if (!expression_cstr || *expression_cstr == '\0')
2890 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002891 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002892 list->Append(root);
2893 return 1;
2894 }
2895
2896 switch (*expression_cstr)
2897 {
2898 case '[':
2899 {
2900 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2901 {
2902 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2903 {
2904 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002905 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2906 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002907 return 0;
2908 }
2909 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2910 {
2911 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002912 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2913 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002914 return 0;
2915 }
2916 }
2917 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2918 {
2919 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2920 {
2921 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002922 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2923 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002924 return 0;
2925 }
2926 else // expand this into list
2927 {
2928 int max_index = root->GetNumChildren() - 1;
2929 for (int index = 0; index < max_index; index++)
2930 {
2931 ValueObjectSP child =
2932 root->GetChildAtIndex(index, true);
2933 list->Append(child);
2934 }
2935 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002936 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2937 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002938 return max_index; // tell me number of items I added to the VOList
2939 }
2940 }
2941 const char *separator_position = ::strchr(expression_cstr+1,'-');
2942 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2943 if (!close_bracket_position) // if there is no ], this is a syntax error
2944 {
2945 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002946 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2947 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002948 return 0;
2949 }
2950 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2951 {
2952 char *end = NULL;
2953 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2954 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2955 {
2956 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002957 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2958 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002959 return 0;
2960 }
2961 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2962 {
2963 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2964 {
2965 int max_index = root->GetNumChildren() - 1;
2966 for (int index = 0; index < max_index; index++)
2967 {
2968 ValueObjectSP child =
2969 root->GetChildAtIndex(index, true);
2970 list->Append(child);
2971 }
2972 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002973 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2974 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002975 return max_index; // tell me number of items I added to the VOList
2976 }
2977 else
2978 {
2979 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002980 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2981 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002982 return 0;
2983 }
2984 }
2985 // from here on we do have a valid index
2986 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2987 {
2988 root = root->GetChildAtIndex(index, true);
2989 if (!root.get())
2990 {
2991 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002992 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2993 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002994 return 0;
2995 }
2996 else
2997 {
2998 list->Append(root);
2999 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003000 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3001 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003002 return 1;
3003 }
3004 }
3005 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3006 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003007 if (*what_next == ValueObject::eExpressionPathAftermathDereference && // 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 +00003008 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3009 {
3010 Error error;
3011 root = root->Dereference(error);
3012 if (error.Fail() || !root.get())
3013 {
3014 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003015 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3016 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003017 return 0;
3018 }
3019 else
3020 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003021 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003022 continue;
3023 }
3024 }
3025 else
3026 {
3027 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3028 if (!root.get())
3029 {
3030 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003031 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3032 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003033 return 0;
3034 }
3035 else
3036 {
3037 list->Append(root);
3038 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003039 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3040 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003041 return 1;
3042 }
3043 }
3044 }
3045 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3046 {
3047 root = root->GetSyntheticBitFieldChild(index, index, true);
3048 if (!root.get())
3049 {
3050 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003051 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3052 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003053 return 0;
3054 }
3055 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3056 {
3057 list->Append(root);
3058 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003059 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3060 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003061 return 1;
3062 }
3063 }
3064 }
3065 else // we have a low and a high index
3066 {
3067 char *end = NULL;
3068 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3069 if (!end || end != separator_position) // if something weird is in our way return an error
3070 {
3071 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003072 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3073 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003074 return 0;
3075 }
3076 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3077 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3078 {
3079 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003080 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3081 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003082 return 0;
3083 }
3084 if (index_lower > index_higher) // swap indices if required
3085 {
3086 unsigned long temp = index_lower;
3087 index_lower = index_higher;
3088 index_higher = temp;
3089 }
3090 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3091 {
3092 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3093 if (!root.get())
3094 {
3095 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003096 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3097 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003098 return 0;
3099 }
3100 else
3101 {
3102 list->Append(root);
3103 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003104 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3105 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003106 return 1;
3107 }
3108 }
3109 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 Granata86cc9822012-03-19 22:58:49 +00003110 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003111 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3112 {
3113 Error error;
3114 root = root->Dereference(error);
3115 if (error.Fail() || !root.get())
3116 {
3117 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003118 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3119 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003120 return 0;
3121 }
3122 else
3123 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003124 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003125 continue;
3126 }
3127 }
3128 else
3129 {
Johnny Chen44805302011-07-19 19:48:13 +00003130 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003131 index <= index_higher; index++)
3132 {
3133 ValueObjectSP child =
3134 root->GetChildAtIndex(index, true);
3135 list->Append(child);
3136 }
3137 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003138 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3139 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003140 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3141 }
3142 }
3143 break;
3144 }
3145 default: // some non-[ separator, or something entirely wrong, is in the way
3146 {
3147 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003148 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3149 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003150 return 0;
3151 break;
3152 }
3153 }
3154 }
3155}
3156
Enrico Granata0c489f52012-03-01 04:24:26 +00003157static void
3158DumpValueObject_Impl (Stream &s,
3159 ValueObject *valobj,
3160 const ValueObject::DumpValueObjectOptions& options,
3161 uint32_t ptr_depth,
3162 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003163{
Greg Clayton007d5be2011-05-30 00:49:24 +00003164 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003165 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003166 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003167
Enrico Granata0c489f52012-03-01 04:24:26 +00003168 const char *root_valobj_name =
3169 options.m_root_valobj_name.empty() ?
3170 valobj->GetName().AsCString() :
3171 options.m_root_valobj_name.c_str();
3172
3173 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003174 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003175 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003176 if (dynamic_value)
3177 valobj = dynamic_value;
3178 }
3179
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003180 clang_type_t clang_type = valobj->GetClangType();
3181
Greg Clayton73b472d2010-10-27 03:32:59 +00003182 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003183 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003184 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3185 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003186
Enrico Granata0c489f52012-03-01 04:24:26 +00003187 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003188
3189 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003190 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003191 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003192 {
Jim Ingham6035b672011-03-31 00:19:25 +00003193 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003194 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003195
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003196 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003197
Greg Clayton7c8a9662010-11-02 01:50:16 +00003198 // Always show the type for the top level items.
Enrico Granata0c489f52012-03-01 04:24:26 +00003199 if (options.m_show_types || (curr_depth == 0 && !options.m_flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003200 {
Greg Clayton84db9102012-03-26 23:03:23 +00003201 const char* typeName = valobj->GetQualifiedTypeName().AsCString("<invalid type>");
3202 //const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
Enrico Granata9910bc82011-08-03 02:18:51 +00003203 s.Printf("(%s", typeName);
3204 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003205 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003206 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003207 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003208 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003209 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3210 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003211 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003212 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003213 else
3214 {
3215 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3216 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003217 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003218 else
3219 {
3220 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3221 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003222 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003223 else
3224 s.Printf(", dynamic type: %s) ",
3225 runtime->GetActualTypeName(isa).GetCString());
3226 }
3227 }
3228 }
3229 else
3230 s.Printf(") ");
3231 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003232
Greg Clayton1d3afba2010-10-05 00:00:42 +00003233
Enrico Granata0c489f52012-03-01 04:24:26 +00003234 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003235 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003236 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003237 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003238 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003239 s.PutCString(" =");
3240 }
3241 else
3242 {
3243 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3244 s.Printf ("%s =", name_cstr);
3245 }
3246
Enrico Granata0c489f52012-03-01 04:24:26 +00003247 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003248 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003249 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003250 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003251 }
3252
Enrico Granata0c489f52012-03-01 04:24:26 +00003253 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003254 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003255 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003256 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003257 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003258
Enrico Granata0c489f52012-03-01 04:24:26 +00003259 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003260 entry = NULL;
3261
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003262 if (err_cstr == NULL)
3263 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003264 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003265 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003266 valobj->GetValueAsCString(options.m_format,
3267 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003268 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003269 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003270 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003271 val_cstr = valobj->GetValueAsCString();
3272 if (val_cstr)
3273 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003274 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003275 err_cstr = valobj->GetError().AsCString();
3276 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003277
3278 if (err_cstr)
3279 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003280 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003281 }
3282 else
3283 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003284 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003285 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003286 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003287 if (options.m_omit_summary_depth == 0)
3288 {
3289 if (options.m_summary_sp)
3290 {
3291 valobj->GetSummaryAsCString(entry, summary_str);
3292 sum_cstr = summary_str.c_str();
3293 }
3294 else
3295 sum_cstr = valobj->GetSummaryAsCString();
3296 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003297
Greg Clayton6efba4f2012-01-26 21:08:30 +00003298 // Make sure we have a value and make sure the summary didn't
3299 // specify that the value should not be printed
3300 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3301 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003302
Enrico Granata9dd75c82011-07-15 23:30:15 +00003303 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003304 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003305
Enrico Granata0c489f52012-03-01 04:24:26 +00003306 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003307 {
Jim Ingham6035b672011-03-31 00:19:25 +00003308 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003309 if (object_desc)
3310 s.Printf(" %s\n", object_desc);
3311 else
Sean Callanan672ad942010-10-23 00:18:49 +00003312 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003313 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003314 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003315 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003316
Enrico Granata0c489f52012-03-01 04:24:26 +00003317 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003318 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003319 // We will show children for all concrete types. We won't show
3320 // pointer contents unless a pointer depth has been specified.
3321 // We won't reference contents unless the reference is the
3322 // root object (depth of zero).
3323 bool print_children = true;
3324
3325 // Use a new temporary pointer depth in case we override the
3326 // current pointer depth below...
3327 uint32_t curr_ptr_depth = ptr_depth;
3328
3329 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3330 if (is_ptr || is_ref)
3331 {
3332 // We have a pointer or reference whose value is an address.
3333 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003334 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003335 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003336 print_children = false;
3337
3338 else if (is_ref && curr_depth == 0)
3339 {
3340 // If this is the root object (depth is zero) that we are showing
3341 // and it is a reference, and no pointer depth has been supplied
3342 // print out what it references. Don't do this at deeper depths
3343 // otherwise we can end up with infinite recursion...
3344 curr_ptr_depth = 1;
3345 }
3346
3347 if (curr_ptr_depth == 0)
3348 print_children = false;
3349 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003350
Enrico Granata0a3958e2011-07-02 00:25:22 +00003351 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003352 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003353 ValueObject* synth_valobj;
3354 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3355 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003356
Enrico Granatac482a192011-08-17 22:13:59 +00003357 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003358 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003359 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003360 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003361 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003362 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003363 if (print_valobj)
3364 s.EOL();
3365 }
3366 else
3367 {
3368 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003369 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003370 s.IndentMore();
3371 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003372
Greg Claytoncc4d0142012-02-17 07:49:44 +00003373 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003374
Enrico Granata0c489f52012-03-01 04:24:26 +00003375 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003376 {
3377 num_children = max_num_children;
3378 print_dotdotdot = true;
3379 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003380
Enrico Granata0c489f52012-03-01 04:24:26 +00003381 ValueObject::DumpValueObjectOptions child_options(options);
3382 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3383 child_options.SetScopeChecked(true)
3384 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003385 for (uint32_t idx=0; idx<num_children; ++idx)
3386 {
Enrico Granatac482a192011-08-17 22:13:59 +00003387 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003388 if (child_sp.get())
3389 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003390 DumpValueObject_Impl (s,
3391 child_sp.get(),
3392 child_options,
3393 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3394 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003395 }
3396 }
3397
Enrico Granata0c489f52012-03-01 04:24:26 +00003398 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003399 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003400 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003401 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003402 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3403 Target *target = exe_ctx.GetTargetPtr();
3404 if (target)
3405 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003406 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003407 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003408 s.IndentLess();
3409 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003410 }
3411 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003412 else if (has_children)
3413 {
3414 // Aggregate, no children...
3415 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003416 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003417 }
3418 else
3419 {
3420 if (print_valobj)
3421 s.EOL();
3422 }
3423
Greg Clayton1d3afba2010-10-05 00:00:42 +00003424 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003425 else
3426 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003427 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003428 }
3429 }
3430 else
3431 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003432 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003433 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003434 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003435 }
3436 }
3437 }
3438 }
3439}
3440
Enrico Granata0c489f52012-03-01 04:24:26 +00003441void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003442ValueObject::LogValueObject (Log *log,
3443 ValueObject *valobj)
3444{
3445 if (log && valobj)
3446 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3447}
3448
3449void
3450ValueObject::LogValueObject (Log *log,
3451 ValueObject *valobj,
3452 const DumpValueObjectOptions& options)
3453{
3454 if (log && valobj)
3455 {
3456 StreamString s;
3457 ValueObject::DumpValueObject (s, valobj, options);
3458 if (s.GetSize())
3459 log->PutCString(s.GetData());
3460 }
3461}
3462
3463void
Enrico Granata0c489f52012-03-01 04:24:26 +00003464ValueObject::DumpValueObject (Stream &s,
3465 ValueObject *valobj)
3466{
3467
3468 if (!valobj)
3469 return;
3470
3471 DumpValueObject_Impl(s,
3472 valobj,
3473 DumpValueObjectOptions::DefaultOptions(),
3474 0,
3475 0);
3476}
3477
3478void
3479ValueObject::DumpValueObject (Stream &s,
3480 ValueObject *valobj,
3481 const DumpValueObjectOptions& options)
3482{
3483 DumpValueObject_Impl(s,
3484 valobj,
3485 options,
3486 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3487 0 // current object depth is 0 since we are just starting
3488 );
3489}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003490
3491ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003492ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003493{
3494 ValueObjectSP valobj_sp;
3495
Enrico Granatac3e320a2011-08-02 17:27:39 +00003496 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003497 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003498 ExecutionContext exe_ctx (GetExecutionContextRef());
3499 clang::ASTContext *ast = GetClangAST ();
3500
3501 DataExtractor data;
3502 data.SetByteOrder (m_data.GetByteOrder());
3503 data.SetAddressByteSize(m_data.GetAddressByteSize());
3504
Enrico Granata9f1e2042012-04-24 22:15:37 +00003505 if (IsBitfield())
3506 {
3507 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3508 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3509 }
3510 else
3511 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003512
3513 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3514 ast,
3515 GetClangType(),
3516 name,
3517 data,
3518 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003519 }
Jim Ingham6035b672011-03-31 00:19:25 +00003520
3521 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003522 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003523 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003524 }
3525 return valobj_sp;
3526}
3527
Greg Claytonafacd142011-09-02 01:15:17 +00003528ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003529ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003530{
Jim Ingham58b59f92011-04-22 23:53:53 +00003531 if (m_deref_valobj)
3532 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003533
Greg Clayton54979cd2010-12-15 05:08:08 +00003534 const bool is_pointer_type = IsPointerType();
3535 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003536 {
3537 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003538 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003539
3540 std::string child_name_str;
3541 uint32_t child_byte_size = 0;
3542 int32_t child_byte_offset = 0;
3543 uint32_t child_bitfield_bit_size = 0;
3544 uint32_t child_bitfield_bit_offset = 0;
3545 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003546 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003547 const bool transparent_pointers = false;
3548 clang::ASTContext *clang_ast = GetClangAST();
3549 clang_type_t clang_type = GetClangType();
3550 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003551
Greg Claytoncc4d0142012-02-17 07:49:44 +00003552 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003553
3554 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3555 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003556 GetName().GetCString(),
3557 clang_type,
3558 0,
3559 transparent_pointers,
3560 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003561 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003562 child_name_str,
3563 child_byte_size,
3564 child_byte_offset,
3565 child_bitfield_bit_size,
3566 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003567 child_is_base_class,
3568 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003569 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003570 {
3571 ConstString child_name;
3572 if (!child_name_str.empty())
3573 child_name.SetCString (child_name_str.c_str());
3574
Jim Ingham58b59f92011-04-22 23:53:53 +00003575 m_deref_valobj = new ValueObjectChild (*this,
3576 clang_ast,
3577 child_clang_type,
3578 child_name,
3579 child_byte_size,
3580 child_byte_offset,
3581 child_bitfield_bit_size,
3582 child_bitfield_bit_offset,
3583 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003584 child_is_deref_of_parent,
3585 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003586 }
3587 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003588
Jim Ingham58b59f92011-04-22 23:53:53 +00003589 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003590 {
3591 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003592 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003593 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003594 else
3595 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003596 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003597 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003598
3599 if (is_pointer_type)
3600 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3601 else
3602 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003603 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003604 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003605}
3606
Greg Claytonafacd142011-09-02 01:15:17 +00003607ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003608ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003609{
Jim Ingham78a685a2011-04-16 00:01:13 +00003610 if (m_addr_of_valobj_sp)
3611 return m_addr_of_valobj_sp;
3612
Greg Claytone0d378b2011-03-24 21:19:54 +00003613 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003614 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003615 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003616 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003617 if (addr != LLDB_INVALID_ADDRESS)
3618 {
3619 switch (address_type)
3620 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003621 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003622 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003623 {
3624 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003625 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003626 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3627 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003628 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003629
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003630 case eAddressTypeFile:
3631 case eAddressTypeLoad:
3632 case eAddressTypeHost:
3633 {
3634 clang::ASTContext *ast = GetClangAST();
3635 clang_type_t clang_type = GetClangType();
3636 if (ast && clang_type)
3637 {
3638 std::string name (1, '&');
3639 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003640 ExecutionContext exe_ctx (GetExecutionContextRef());
3641 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003642 ast,
3643 ClangASTContext::CreatePointerType (ast, clang_type),
3644 ConstString (name.c_str()),
3645 addr,
3646 eAddressTypeInvalid,
3647 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003648 }
3649 }
3650 break;
3651 }
3652 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003653 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003654}
3655
Greg Clayton9a142cf2012-02-03 05:34:10 +00003656ValueObjectSP
3657ValueObject::Cast (const ClangASTType &clang_ast_type)
3658{
Greg Clayton81e871e2012-02-04 02:27:34 +00003659 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003660}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003661
Greg Claytonafacd142011-09-02 01:15:17 +00003662ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003663ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3664{
Greg Claytonafacd142011-09-02 01:15:17 +00003665 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003666 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003667 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003668
3669 if (ptr_value != LLDB_INVALID_ADDRESS)
3670 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003671 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003672 ExecutionContext exe_ctx (GetExecutionContextRef());
3673 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003674 name,
3675 ptr_addr,
3676 clang_ast_type);
3677 }
3678 return valobj_sp;
3679}
3680
Greg Claytonafacd142011-09-02 01:15:17 +00003681ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003682ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3683{
Greg Claytonafacd142011-09-02 01:15:17 +00003684 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003685 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003686 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003687
3688 if (ptr_value != LLDB_INVALID_ADDRESS)
3689 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003690 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003691 ExecutionContext exe_ctx (GetExecutionContextRef());
3692 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003693 name,
3694 ptr_addr,
3695 type_sp);
3696 }
3697 return valobj_sp;
3698}
3699
Jim Ingham6035b672011-03-31 00:19:25 +00003700ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003701 m_mod_id(),
3702 m_exe_ctx_ref(),
3703 m_needs_update (true),
3704 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003705{
3706}
3707
3708ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003709 m_mod_id(),
3710 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003711 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003712 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003713{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003714 ExecutionContext exe_ctx(exe_scope);
3715 TargetSP target_sp (exe_ctx.GetTargetSP());
3716 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003717 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003718 m_exe_ctx_ref.SetTargetSP (target_sp);
3719 ProcessSP process_sp (exe_ctx.GetProcessSP());
3720 if (!process_sp)
3721 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003722
Greg Claytoncc4d0142012-02-17 07:49:44 +00003723 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003724 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003725 m_mod_id = process_sp->GetModID();
3726 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003727
Greg Claytoncc4d0142012-02-17 07:49:44 +00003728 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003729
Greg Claytoncc4d0142012-02-17 07:49:44 +00003730 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003731 {
3732 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003733 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003734 }
Jim Ingham6035b672011-03-31 00:19:25 +00003735
Greg Claytoncc4d0142012-02-17 07:49:44 +00003736 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003737 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003738 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003739
Greg Claytoncc4d0142012-02-17 07:49:44 +00003740 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3741 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003742 {
3743 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003744 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003745 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003746 if (frame_sp)
3747 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003748 }
3749 }
3750 }
Jim Ingham6035b672011-03-31 00:19:25 +00003751}
3752
3753ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003754 m_mod_id(),
3755 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3756 m_needs_update (true),
3757 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003758{
3759}
3760
3761ValueObject::EvaluationPoint::~EvaluationPoint ()
3762{
3763}
3764
Jim Ingham6035b672011-03-31 00:19:25 +00003765// This function checks the EvaluationPoint against the current process state. If the current
3766// state matches the evaluation point, or the evaluation point is already invalid, then we return
3767// false, meaning "no change". If the current state is different, we update our state, and return
3768// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3769// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003770// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003771
3772bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003773ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003774{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003775
3776 // 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 +00003777 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003778
Greg Claytoncc4d0142012-02-17 07:49:44 +00003779 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003780 return false;
3781
Jim Ingham6035b672011-03-31 00:19:25 +00003782 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003783 Process *process = exe_ctx.GetProcessPtr();
3784 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003785 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003786
Jim Ingham6035b672011-03-31 00:19:25 +00003787 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003788 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003789
Jim Ingham78a685a2011-04-16 00:01:13 +00003790 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3791 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003792 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003793 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003794
3795 bool changed;
3796
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003797 if (m_mod_id.IsValid())
3798 {
3799 if (m_mod_id == current_mod_id)
3800 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003801 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003802 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003803 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003804 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003805 else
3806 {
3807 m_mod_id = current_mod_id;
3808 m_needs_update = true;
3809 changed = true;
3810 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003811 }
Jim Ingham6035b672011-03-31 00:19:25 +00003812
Jim Ingham73ca05a2011-12-17 01:35:57 +00003813 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3814 // That way we'll be sure to return a valid exe_scope.
3815 // 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 +00003816
Greg Claytoncc4d0142012-02-17 07:49:44 +00003817 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003818 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003819 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3820 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003821 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003822 if (m_exe_ctx_ref.HasFrameRef())
3823 {
3824 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3825 if (!frame_sp)
3826 {
3827 // We used to have a frame, but now it is gone
3828 SetInvalid();
3829 }
3830 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003831 }
Jim Ingham6035b672011-03-31 00:19:25 +00003832 else
3833 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003834 // We used to have a thread, but now it is gone
3835 SetInvalid();
Jim Ingham6035b672011-03-31 00:19:25 +00003836 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003837
Jim Ingham6035b672011-03-31 00:19:25 +00003838 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003839 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003840}
3841
Jim Ingham61be0902011-05-02 18:13:59 +00003842void
3843ValueObject::EvaluationPoint::SetUpdated ()
3844{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003845 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3846 if (process_sp)
3847 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003848 m_first_update = false;
3849 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003850}
3851
3852
Greg Claytoncc4d0142012-02-17 07:49:44 +00003853//bool
3854//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3855//{
3856// if (!IsValid())
3857// return false;
3858//
3859// bool needs_update = false;
3860//
3861// // The target has to be non-null, and the
3862// Target *target = exe_scope->CalculateTarget();
3863// if (target != NULL)
3864// {
3865// Target *old_target = m_target_sp.get();
3866// assert (target == old_target);
3867// Process *process = exe_scope->CalculateProcess();
3868// if (process != NULL)
3869// {
3870// // FOR NOW - assume you can't update variable objects across process boundaries.
3871// Process *old_process = m_process_sp.get();
3872// assert (process == old_process);
3873// ProcessModID current_mod_id = process->GetModID();
3874// if (m_mod_id != current_mod_id)
3875// {
3876// needs_update = true;
3877// m_mod_id = current_mod_id;
3878// }
3879// // See if we're switching the thread or stack context. If no thread is given, this is
3880// // being evaluated in a global context.
3881// Thread *thread = exe_scope->CalculateThread();
3882// if (thread != NULL)
3883// {
3884// user_id_t new_thread_index = thread->GetIndexID();
3885// if (new_thread_index != m_thread_id)
3886// {
3887// needs_update = true;
3888// m_thread_id = new_thread_index;
3889// m_stack_id.Clear();
3890// }
3891//
3892// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3893// if (new_frame != NULL)
3894// {
3895// if (new_frame->GetStackID() != m_stack_id)
3896// {
3897// needs_update = true;
3898// m_stack_id = new_frame->GetStackID();
3899// }
3900// }
3901// else
3902// {
3903// m_stack_id.Clear();
3904// needs_update = true;
3905// }
3906// }
3907// else
3908// {
3909// // If this had been given a thread, and now there is none, we should update.
3910// // Otherwise we don't have to do anything.
3911// if (m_thread_id != LLDB_INVALID_UID)
3912// {
3913// m_thread_id = LLDB_INVALID_UID;
3914// m_stack_id.Clear();
3915// needs_update = true;
3916// }
3917// }
3918// }
3919// else
3920// {
3921// // If there is no process, then we don't need to update anything.
3922// // But if we're switching from having a process to not, we should try to update.
3923// if (m_process_sp.get() != NULL)
3924// {
3925// needs_update = true;
3926// m_process_sp.reset();
3927// m_thread_id = LLDB_INVALID_UID;
3928// m_stack_id.Clear();
3929// }
3930// }
3931// }
3932// else
3933// {
3934// // If there's no target, nothing can change so we don't need to update anything.
3935// // But if we're switching from having a target to not, we should try to update.
3936// if (m_target_sp.get() != NULL)
3937// {
3938// needs_update = true;
3939// m_target_sp.reset();
3940// m_process_sp.reset();
3941// m_thread_id = LLDB_INVALID_UID;
3942// m_stack_id.Clear();
3943// }
3944// }
3945// if (!m_needs_update)
3946// m_needs_update = needs_update;
3947//
3948// return needs_update;
3949//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003950
3951void
Enrico Granata86cc9822012-03-19 22:58:49 +00003952ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00003953{
Enrico Granata86cc9822012-03-19 22:58:49 +00003954 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3955 m_value_str.clear();
3956
3957 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3958 m_location_str.clear();
3959
3960 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3961 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003962 m_summary_str.clear();
3963 }
3964
3965 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3966 m_object_desc_str.clear();
3967
3968 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3969 {
3970 if (m_synthetic_value)
3971 m_synthetic_value = NULL;
3972 }
Johnny Chen44805302011-07-19 19:48:13 +00003973}
Enrico Granata9128ee22011-09-06 19:20:51 +00003974
3975SymbolContextScope *
3976ValueObject::GetSymbolContextScope()
3977{
3978 if (m_parent)
3979 {
3980 if (!m_parent->IsPointerOrReferenceType())
3981 return m_parent->GetSymbolContextScope();
3982 }
3983 return NULL;
3984}