blob: 7c8cd7f62edda5e53c2679cf5edcb01b7bc2ba44 [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 Granata9df29e32011-07-19 20:57:44 +000083 m_last_summary_format(),
84 m_forced_summary_format(),
85 m_last_value_format(),
Enrico Granatad55546b2011-07-22 00:16:08 +000086 m_last_synthetic_filter(),
Jim Ingham4b536182011-08-09 02:12:22 +000087 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000088 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000089 m_value_is_valid (false),
90 m_value_did_change (false),
91 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000092 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000093 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000094 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000095 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +000096 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000097 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +000098 m_is_getting_summary(false),
99 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +0000100{
Jim Ingham58b59f92011-04-22 23:53:53 +0000101 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000102}
103
104//----------------------------------------------------------------------
105// ValueObject constructor
106//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000107ValueObject::ValueObject (ExecutionContextScope *exe_scope,
108 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000109 UserID (++g_value_obj_uid), // Unique identifier for every value object
110 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000111 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000112 m_name (),
113 m_data (),
114 m_value (),
115 m_error (),
116 m_value_str (),
117 m_old_value_str (),
118 m_location_str (),
119 m_summary_str (),
120 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000121 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000122 m_children (),
123 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000124 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000125 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000126 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000127 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000128 m_last_format_mgr_revision(0),
Greg Claytonafacd142011-09-02 01:15:17 +0000129 m_last_format_mgr_dynamic(eNoDynamicValues),
Enrico Granata9df29e32011-07-19 20:57:44 +0000130 m_last_summary_format(),
131 m_forced_summary_format(),
132 m_last_value_format(),
Enrico Granatad55546b2011-07-22 00:16:08 +0000133 m_last_synthetic_filter(),
Jim Ingham4b536182011-08-09 02:12:22 +0000134 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000135 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000136 m_value_is_valid (false),
137 m_value_did_change (false),
138 m_children_count_valid (false),
139 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000140 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000141 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000142 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000143 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000144 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000145 m_is_getting_summary(false),
146 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147{
Jim Ingham58b59f92011-04-22 23:53:53 +0000148 m_manager = new ValueObjectManager();
149 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000150}
151
152//----------------------------------------------------------------------
153// Destructor
154//----------------------------------------------------------------------
155ValueObject::~ValueObject ()
156{
157}
158
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000160ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000162 return UpdateValueIfNeeded(m_last_format_mgr_dynamic, update_format);
163}
164
165bool
Greg Claytonafacd142011-09-02 01:15:17 +0000166ValueObject::UpdateValueIfNeeded (DynamicValueType use_dynamic, bool update_format)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000167{
Enrico Granata4becb372011-06-29 22:27:15 +0000168
Enrico Granata9128ee22011-09-06 19:20:51 +0000169 bool did_change_formats = false;
170
Enrico Granata0a3958e2011-07-02 00:25:22 +0000171 if (update_format)
Enrico Granata9128ee22011-09-06 19:20:51 +0000172 did_change_formats = UpdateFormatsIfNeeded(use_dynamic);
Enrico Granata4becb372011-06-29 22:27:15 +0000173
Greg Claytonb71f3842010-10-05 03:13:51 +0000174 // If this is a constant value, then our success is predicated on whether
175 // we have an error or not
176 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000177 {
178 // if you were asked to update your formatters, but did not get a chance to do it
179 // clear your own values (this serves the purpose of faking a stop-id for frozen
180 // objects (which are regarded as constant, but could have changes behind their backs
181 // because of the frozen-pointer depth limit)
182 // TODO: decouple summary from value and then remove this code and only force-clear the summary
183 if (update_format && !did_change_formats)
184 m_summary_str.clear();
Greg Claytonb71f3842010-10-05 03:13:51 +0000185 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000186 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000187
Jim Ingham6035b672011-03-31 00:19:25 +0000188 bool first_update = m_update_point.IsFirstEvaluation();
189
190 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000191 {
Jim Ingham6035b672011-03-31 00:19:25 +0000192 m_update_point.SetUpdated();
193
194 // Save the old value using swap to avoid a string copy which
195 // also will clear our m_value_str
196 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000197 {
Jim Ingham6035b672011-03-31 00:19:25 +0000198 m_old_value_valid = false;
199 }
200 else
201 {
202 m_old_value_valid = true;
203 m_old_value_str.swap (m_value_str);
204 m_value_str.clear();
205 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000206
Enrico Granataf2bbf712011-07-15 02:26:42 +0000207 ClearUserVisibleData();
208
Jim Ingham6035b672011-03-31 00:19:25 +0000209 const bool value_was_valid = GetValueIsValid();
210 SetValueDidChange (false);
Greg Clayton73b953b2010-08-28 00:08:07 +0000211
Jim Ingham6035b672011-03-31 00:19:25 +0000212 m_error.Clear();
Greg Clayton73b953b2010-08-28 00:08:07 +0000213
Jim Ingham6035b672011-03-31 00:19:25 +0000214 // 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);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000226 }
227 }
228 return m_error.Success();
229}
230
Enrico Granata9128ee22011-09-06 19:20:51 +0000231bool
Greg Claytonafacd142011-09-02 01:15:17 +0000232ValueObject::UpdateFormatsIfNeeded(DynamicValueType use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000233{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000234 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
235 if (log)
236 log->Printf("checking for FormatManager revisions. VO named %s is at revision %d, while the format manager is at revision %d",
237 GetName().GetCString(),
Enrico Granata4becb372011-06-29 22:27:15 +0000238 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000239 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000240
241 bool any_change = false;
242
Jim Ingham4b536182011-08-09 02:12:22 +0000243 if (HasCustomSummaryFormat() && m_update_point.GetModID() != m_user_id_of_forced_summary)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000244 {
245 ClearCustomSummaryFormat();
Enrico Granata855cd902011-09-06 22:59:55 +0000246
Enrico Granata9128ee22011-09-06 19:20:51 +0000247 any_change = true;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000248 }
Enrico Granata855cd902011-09-06 22:59:55 +0000249
Enrico Granata85933ed2011-08-18 16:38:26 +0000250 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) ||
Enrico Granatac3e320a2011-08-02 17:27:39 +0000251 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000252 {
Enrico Granata78d06382011-09-09 23:33:14 +0000253 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
254 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, use_dynamic));
255 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, use_dynamic));
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).
273 m_value_str.clear();
274}
275
Sean Callanan72772842012-02-22 23:57:45 +0000276ClangASTType
277ValueObject::MaybeCalculateCompleteType ()
278{
279 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
280
281 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
354 return m_override_type;
355}
356
357clang::ASTContext *
358ValueObject::GetClangAST ()
359{
360 ClangASTType type = MaybeCalculateCompleteType();
361
362 return type.GetASTContext();
363}
364
365lldb::clang_type_t
366ValueObject::GetClangType ()
367{
368 ClangASTType type = MaybeCalculateCompleteType();
369
370 return type.GetOpaqueQualType();
371}
372
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373DataExtractor &
374ValueObject::GetDataExtractor ()
375{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000376 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000377 return m_data;
378}
379
380const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000381ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000382{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000383 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384 return m_error;
385}
386
387const ConstString &
388ValueObject::GetName() const
389{
390 return m_name;
391}
392
393const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000394ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000395{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000396 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000397 {
398 if (m_location_str.empty())
399 {
400 StreamString sstr;
401
402 switch (m_value.GetValueType())
403 {
404 default:
405 break;
406
407 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000408 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000409 {
410 RegisterInfo *reg_info = m_value.GetRegisterInfo();
411 if (reg_info)
412 {
413 if (reg_info->name)
414 m_location_str = reg_info->name;
415 else if (reg_info->alt_name)
416 m_location_str = reg_info->alt_name;
417 break;
418 }
419 }
420 m_location_str = "scalar";
421 break;
422
423 case Value::eValueTypeLoadAddress:
424 case Value::eValueTypeFileAddress:
425 case Value::eValueTypeHostAddress:
426 {
427 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
428 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
429 m_location_str.swap(sstr.GetString());
430 }
431 break;
432 }
433 }
434 }
435 return m_location_str.c_str();
436}
437
438Value &
439ValueObject::GetValue()
440{
441 return m_value;
442}
443
444const Value &
445ValueObject::GetValue() const
446{
447 return m_value;
448}
449
450bool
Jim Ingham6035b672011-03-31 00:19:25 +0000451ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000452{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000453 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
454 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000455 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000456 Value tmp_value(m_value);
457 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000458 if (scalar.IsValid())
459 {
460 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
461 if (bitfield_bit_size)
462 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
463 return true;
464 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000465 }
Greg Claytondcad5022011-12-29 01:26:56 +0000466 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000467}
468
469bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000470ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471{
Greg Clayton288bdf92010-09-02 02:59:18 +0000472 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000473}
474
475
476void
477ValueObject::SetValueIsValid (bool b)
478{
Greg Clayton288bdf92010-09-02 02:59:18 +0000479 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480}
481
482bool
Jim Ingham6035b672011-03-31 00:19:25 +0000483ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484{
Jim Ingham6035b672011-03-31 00:19:25 +0000485 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000486 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487}
488
489void
490ValueObject::SetValueDidChange (bool value_changed)
491{
Greg Clayton288bdf92010-09-02 02:59:18 +0000492 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000493}
494
495ValueObjectSP
496ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
497{
498 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000499 // We may need to update our value if we are dynamic
500 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000501 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000502 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000504 // Check if we have already made the child value object?
505 if (can_create && m_children[idx] == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000506 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000507 // No we haven't created the child at this index, so lets have our
508 // subclass do it and cache the result for quick future access.
509 m_children[idx] = CreateChildAtIndex (idx, false, 0);
Jim Ingham78a685a2011-04-16 00:01:13 +0000510 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000511
512 if (m_children[idx] != NULL)
513 return m_children[idx]->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000514 }
515 return child_sp;
516}
517
518uint32_t
519ValueObject::GetIndexOfChildWithName (const ConstString &name)
520{
521 bool omit_empty_base_classes = true;
522 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000523 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000524 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000525 omit_empty_base_classes);
526}
527
528ValueObjectSP
529ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
530{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000531 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000532 // classes (which really aren't part of the expression path), so we
533 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000535
Greg Claytondea8cb42011-06-29 22:09:02 +0000536 // We may need to update our value if we are dynamic
537 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000538 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000539
540 std::vector<uint32_t> child_indexes;
541 clang::ASTContext *clang_ast = GetClangAST();
542 void *clang_type = GetClangType();
543 bool omit_empty_base_classes = true;
544 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
545 clang_type,
546 name.GetCString(),
547 omit_empty_base_classes,
548 child_indexes);
549 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000550 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000551 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
552 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
553
554 child_sp = GetChildAtIndex(*pos, can_create);
555 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000556 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000557 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000558 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000559 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
560 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000561 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000562 else
563 {
564 child_sp.reset();
565 }
566
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000567 }
568 }
569 return child_sp;
570}
571
572
573uint32_t
574ValueObject::GetNumChildren ()
575{
Greg Clayton288bdf92010-09-02 02:59:18 +0000576 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000577 {
578 SetNumChildren (CalculateNumChildren());
579 }
580 return m_children.size();
581}
582void
583ValueObject::SetNumChildren (uint32_t num_children)
584{
Greg Clayton288bdf92010-09-02 02:59:18 +0000585 m_children_count_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586 m_children.resize(num_children);
587}
588
589void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000590ValueObject::SetName (const ConstString &name)
591{
592 m_name = name;
593}
594
Jim Ingham58b59f92011-04-22 23:53:53 +0000595ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000596ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
597{
Jim Ingham2eec4872011-05-07 00:10:58 +0000598 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000599
Greg Claytondea8cb42011-06-29 22:09:02 +0000600 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000601 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000602 std::string child_name_str;
603 uint32_t child_byte_size = 0;
604 int32_t child_byte_offset = 0;
605 uint32_t child_bitfield_bit_size = 0;
606 uint32_t child_bitfield_bit_offset = 0;
607 bool child_is_base_class = false;
608 bool child_is_deref_of_parent = false;
609
610 const bool transparent_pointers = synthetic_array_member == false;
611 clang::ASTContext *clang_ast = GetClangAST();
612 clang_type_t clang_type = GetClangType();
613 clang_type_t child_clang_type;
614
Greg Claytoncc4d0142012-02-17 07:49:44 +0000615 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000616
617 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
618 clang_ast,
619 GetName().GetCString(),
620 clang_type,
621 idx,
622 transparent_pointers,
623 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000624 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000625 child_name_str,
626 child_byte_size,
627 child_byte_offset,
628 child_bitfield_bit_size,
629 child_bitfield_bit_offset,
630 child_is_base_class,
631 child_is_deref_of_parent);
632 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000633 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000634 if (synthetic_index)
635 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000636
Greg Claytondea8cb42011-06-29 22:09:02 +0000637 ConstString child_name;
638 if (!child_name_str.empty())
639 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000640
Greg Claytondea8cb42011-06-29 22:09:02 +0000641 valobj = new ValueObjectChild (*this,
642 clang_ast,
643 child_clang_type,
644 child_name,
645 child_byte_size,
646 child_byte_offset,
647 child_bitfield_bit_size,
648 child_bitfield_bit_offset,
649 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000650 child_is_deref_of_parent,
651 eAddressTypeInvalid);
652 //if (valobj)
653 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
654 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000655
Jim Ingham58b59f92011-04-22 23:53:53 +0000656 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000657}
658
659const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000660ValueObject::GetSummaryAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000661{
Greg Clayton48ca8b82012-01-07 20:58:07 +0000662 // Watch for recursion which can happen with summary strings and other
663 // variable formatting options.
664 if (m_is_getting_summary)
665 return NULL;
666
667 m_is_getting_summary = true;
668
Enrico Granatad8b5fce2011-08-02 23:12:24 +0000669 if (UpdateValueIfNeeded (true))
Enrico Granata4becb372011-06-29 22:27:15 +0000670 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000671 if (m_summary_str.empty())
672 {
Enrico Granata061858c2012-02-15 02:34:21 +0000673 TypeSummaryImpl *summary_format = GetSummaryFormat().get();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000674
675 if (summary_format)
Enrico Granata4becb372011-06-29 22:27:15 +0000676 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000677 m_summary_str = summary_format->FormatObject(GetSP());
Enrico Granata4becb372011-06-29 22:27:15 +0000678 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000679 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000680 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000681 clang_type_t clang_type = GetClangType();
Greg Clayton737b9322010-09-13 03:32:57 +0000682
Enrico Granata9dd75c82011-07-15 23:30:15 +0000683 // Do some default printout for function pointers
Enrico Granataf2bbf712011-07-15 02:26:42 +0000684 if (clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000685 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000686 StreamString sstr;
687 clang_type_t elem_or_pointee_clang_type;
688 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
689 GetClangAST(),
690 &elem_or_pointee_clang_type));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691
Greg Claytoncc4d0142012-02-17 07:49:44 +0000692 if (ClangASTContext::IsFunctionPointerType (clang_type))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000693 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000694 AddressType func_ptr_address_type = eAddressTypeInvalid;
695 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
696 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Jim Ingham6035b672011-03-31 00:19:25 +0000697 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000698 switch (func_ptr_address_type)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000699 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000700 case eAddressTypeInvalid:
701 case eAddressTypeFile:
702 break;
Enrico Granataf2bbf712011-07-15 02:26:42 +0000703
Greg Claytoncc4d0142012-02-17 07:49:44 +0000704 case eAddressTypeLoad:
705 {
706 ExecutionContext exe_ctx (GetExecutionContextRef());
707
708 Address so_addr;
709 Target *target = exe_ctx.GetTargetPtr();
710 if (target && target->GetSectionLoadList().IsEmpty() == false)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000711 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000712 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000713 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000714 so_addr.Dump (&sstr,
715 exe_ctx.GetBestExecutionContextScope(),
716 Address::DumpStyleResolvedDescription,
717 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000718 }
719 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000720 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000721 break;
722
723 case eAddressTypeHost:
724 break;
Enrico Granataf2bbf712011-07-15 02:26:42 +0000725 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000726 }
727 if (sstr.GetSize() > 0)
728 {
729 m_summary_str.assign (1, '(');
730 m_summary_str.append (sstr.GetData(), sstr.GetSize());
731 m_summary_str.append (1, ')');
Jim Ingham6035b672011-03-31 00:19:25 +0000732 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000733 }
734 }
735 }
736 }
737 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000738 m_is_getting_summary = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000739 if (m_summary_str.empty())
740 return NULL;
741 return m_summary_str.c_str();
742}
743
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000744bool
745ValueObject::IsCStringContainer(bool check_pointer)
746{
747 clang_type_t elem_or_pointee_clang_type;
748 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
749 GetClangAST(),
750 &elem_or_pointee_clang_type));
751 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
752 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
753 if (!is_char_arr_ptr)
754 return false;
755 if (!check_pointer)
756 return true;
757 if (type_flags.Test(ClangASTContext::eTypeIsArray))
758 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000759 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000760 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000761 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000762 return (cstr_address != LLDB_INVALID_ADDRESS);
763}
764
Enrico Granata9128ee22011-09-06 19:20:51 +0000765size_t
766ValueObject::GetPointeeData (DataExtractor& data,
767 uint32_t item_idx,
768 uint32_t item_count)
769{
770 if (!IsPointerType() && !IsArrayType())
771 return 0;
772
773 if (item_count == 0)
774 return 0;
775
776 uint32_t stride = 0;
777
778 ClangASTType type(GetClangAST(),
779 GetClangType());
780
781 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
782 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
783
784 const uint64_t bytes = item_count * item_type_size;
785
786 const uint64_t offset = item_idx * item_type_size;
787
788 if (item_idx == 0 && item_count == 1) // simply a deref
789 {
790 if (IsPointerType())
791 {
792 Error error;
793 ValueObjectSP pointee_sp = Dereference(error);
794 if (error.Fail() || pointee_sp.get() == NULL)
795 return 0;
796 return pointee_sp->GetDataExtractor().Copy(data);
797 }
798 else
799 {
800 ValueObjectSP child_sp = GetChildAtIndex(0, true);
801 if (child_sp.get() == NULL)
802 return 0;
803 return child_sp->GetDataExtractor().Copy(data);
804 }
805 return true;
806 }
807 else /* (items > 1) */
808 {
809 Error error;
810 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
811 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
812
813 AddressType addr_type;
814 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
815
Enrico Granata9128ee22011-09-06 19:20:51 +0000816 switch (addr_type)
817 {
818 case eAddressTypeFile:
819 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000820 ModuleSP module_sp (GetModule());
821 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000822 {
823 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000824 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000825 ExecutionContext exe_ctx (GetExecutionContextRef());
826 Target* target = exe_ctx.GetTargetPtr();
827 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000828 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000829 heap_buf_ptr->SetByteSize(bytes);
830 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
831 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000832 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000833 data.SetData(data_sp);
834 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000835 }
836 }
837 }
838 }
839 break;
840 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000841 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000842 ExecutionContext exe_ctx (GetExecutionContextRef());
843 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000844 if (process)
845 {
846 heap_buf_ptr->SetByteSize(bytes);
847 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
848 if (error.Success())
849 {
850 data.SetData(data_sp);
851 return bytes_read;
852 }
853 }
854 }
855 break;
856 case eAddressTypeHost:
857 {
858 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
859 data.SetData(data_sp);
860 return bytes;
861 }
862 break;
863 case eAddressTypeInvalid:
864 default:
865 break;
866 }
867 }
868 return 0;
869}
870
871size_t
872ValueObject::GetData (DataExtractor& data)
873{
874 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000875 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +0000876 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000877 if (error.Fail())
878 return 0;
879 data.SetAddressByteSize(m_data.GetAddressByteSize());
880 data.SetByteOrder(m_data.GetByteOrder());
881 return data.GetByteSize();
882}
883
884// will compute strlen(str), but without consuming more than
885// maxlen bytes out of str (this serves the purpose of reading
886// chunks of a string without having to worry about
887// missing NULL terminators in the chunk)
888// of course, if strlen(str) > maxlen, the function will return
889// maxlen_value (which should be != maxlen, because that allows you
890// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
891static uint32_t
892strlen_or_inf (const char* str,
893 uint32_t maxlen,
894 uint32_t maxlen_value)
895{
896 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000897 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000898 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000899 while(*str)
900 {
901 len++;str++;
902 if (len > maxlen)
903 return maxlen_value;
904 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000905 }
906 return len;
907}
908
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000909void
Greg Claytoncc4d0142012-02-17 07:49:44 +0000910ValueObject::ReadPointedString (Stream& s,
911 Error& error,
912 uint32_t max_length,
913 bool honor_array,
914 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000915{
Greg Claytoncc4d0142012-02-17 07:49:44 +0000916 ExecutionContext exe_ctx (GetExecutionContextRef());
917 Target* target = exe_ctx.GetTargetPtr();
918
919 if (target && max_length == 0)
920 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000921
922 clang_type_t clang_type = GetClangType();
923 clang_type_t elem_or_pointee_clang_type;
924 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
925 GetClangAST(),
926 &elem_or_pointee_clang_type));
927 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
928 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
929 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000930 if (target == NULL)
931 {
932 s << "<no target to read from>";
933 }
934 else
935 {
936 addr_t cstr_address = LLDB_INVALID_ADDRESS;
937 AddressType cstr_address_type = eAddressTypeInvalid;
938
939 size_t cstr_len = 0;
940 bool capped_data = false;
941 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000942 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000943 // We have an array
944 cstr_len = ClangASTContext::GetArraySize (clang_type);
945 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000946 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000947 capped_data = true;
948 cstr_len = max_length;
949 }
950 cstr_address = GetAddressOf (true, &cstr_address_type);
951 }
952 else
953 {
954 // We have a pointer
955 cstr_address = GetPointerValue (&cstr_address_type);
956 }
957 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
958 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000959 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000960 DataExtractor data;
961 size_t bytes_read = 0;
962 if (cstr_len > 0 && honor_array)
963 {
964 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
965 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
966 GetPointeeData(data, 0, cstr_len);
967
968 if ((bytes_read = data.GetByteSize()) > 0)
969 {
970 s << '"';
971 data.Dump (&s,
972 0, // Start offset in "data"
973 item_format,
974 1, // Size of item (1 byte for a char!)
975 bytes_read, // How many bytes to print?
976 UINT32_MAX, // num per line
977 LLDB_INVALID_ADDRESS,// base address
978 0, // bitfield bit size
979 0); // bitfield bit offset
980 if (capped_data)
981 s << "...";
982 s << '"';
983 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000984 }
985 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000986 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000987 cstr_len = max_length;
988 const size_t k_max_buf_size = 64;
989
990 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000991
Greg Claytoncc4d0142012-02-17 07:49:44 +0000992 int cstr_len_displayed = -1;
993 bool capped_cstr = false;
994 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
995 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
996 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000997 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000998 const char *cstr = data.PeekCStr(0);
999 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1000 if (len > k_max_buf_size)
1001 len = k_max_buf_size;
1002 if (cstr && cstr_len_displayed < 0)
1003 s << '"';
1004
1005 if (cstr_len_displayed < 0)
1006 cstr_len_displayed = len;
1007
1008 if (len == 0)
1009 break;
1010 cstr_len_displayed += len;
1011 if (len > bytes_read)
1012 len = bytes_read;
1013 if (len > cstr_len)
1014 len = cstr_len;
1015
1016 data.Dump (&s,
1017 0, // Start offset in "data"
1018 item_format,
1019 1, // Size of item (1 byte for a char!)
1020 len, // How many bytes to print?
1021 UINT32_MAX, // num per line
1022 LLDB_INVALID_ADDRESS,// base address
1023 0, // bitfield bit size
1024 0); // bitfield bit offset
1025
1026 if (len < k_max_buf_size)
1027 break;
1028
1029 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001030 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001031 capped_cstr = true;
1032 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001033 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001034
1035 cstr_len -= len;
1036 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001037 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001038
1039 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001040 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001041 s << '"';
1042 if (capped_cstr)
1043 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001044 }
1045 }
1046 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001047 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001048 }
1049 else
1050 {
1051 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001052 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001053 }
1054}
1055
Jim Ingham53c47f12010-09-10 23:12:17 +00001056const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001057ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001058{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001059
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001060 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001061 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001062
1063 if (!m_object_desc_str.empty())
1064 return m_object_desc_str.c_str();
1065
Greg Claytoncc4d0142012-02-17 07:49:44 +00001066 ExecutionContext exe_ctx (GetExecutionContextRef());
1067 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001068 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001069 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001070
Jim Ingham53c47f12010-09-10 23:12:17 +00001071 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001072
Greg Claytonafacd142011-09-02 01:15:17 +00001073 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001074 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1075
Jim Inghama2cf2632010-12-23 02:29:54 +00001076 if (runtime == NULL)
1077 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001078 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001079 clang_type_t opaque_qual_type = GetClangType();
1080 if (opaque_qual_type != NULL)
1081 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001082 bool is_signed;
1083 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1084 || ClangASTContext::IsPointerType (opaque_qual_type))
1085 {
Greg Claytonafacd142011-09-02 01:15:17 +00001086 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001087 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001088 }
1089 }
1090
Jim Ingham8d543de2011-03-31 23:01:21 +00001091 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001092 {
1093 m_object_desc_str.append (s.GetData());
1094 }
Sean Callanan672ad942010-10-23 00:18:49 +00001095
1096 if (m_object_desc_str.empty())
1097 return NULL;
1098 else
1099 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001100}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001101
1102const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001103ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001104{
1105 // If our byte size is zero this is an aggregate type that has children
Greg Clayton1be10fc2010-09-29 01:12:09 +00001106 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001107 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00001108 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001109 {
1110 if (m_value_str.empty())
1111 {
1112 const Value::ContextType context_type = m_value.GetContextType();
1113
1114 switch (context_type)
1115 {
Greg Clayton526e5af2010-11-13 03:52:47 +00001116 case Value::eContextTypeClangType:
1117 case Value::eContextTypeLLDBType:
1118 case Value::eContextTypeVariable:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001119 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001120 lldb::Format my_format = GetFormat();
Greg Clayton73b472d2010-10-27 03:32:59 +00001121 clang_type_t clang_type = GetClangType ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001122 if (clang_type)
1123 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001124 if (m_format == lldb::eFormatDefault)
Enrico Granata4becb372011-06-29 22:27:15 +00001125 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001126 if (m_last_value_format)
1127 my_format = m_last_value_format->GetFormat();
Enrico Granataf2bbf712011-07-15 02:26:42 +00001128 else
1129 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001130 if (m_is_bitfield_for_scalar)
1131 my_format = eFormatUnsigned;
1132 else
1133 my_format = ClangASTType::GetFormat(clang_type);
Enrico Granataf2bbf712011-07-15 02:26:42 +00001134 }
Greg Clayton007d5be2011-05-30 00:49:24 +00001135 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001136 StreamString sstr;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001137 ExecutionContext exe_ctx (GetExecutionContextRef());
Enrico Granata9128ee22011-09-06 19:20:51 +00001138 if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1139 clang_type, // The clang type to display
1140 &sstr,
1141 my_format, // Format to display this type with
1142 m_data, // Data to extract from
1143 0, // Byte offset into "m_data"
1144 GetByteSize(), // Byte size of item in "m_data"
1145 GetBitfieldBitSize(), // Bitfield bit size
Greg Clayton5009f9d2011-10-27 17:55:14 +00001146 GetBitfieldBitOffset(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00001147 exe_ctx.GetBestExecutionContextScope())) // Bitfield bit offset
Enrico Granata9128ee22011-09-06 19:20:51 +00001148 m_value_str.swap(sstr.GetString());
1149 else
1150 {
Jason Molenda7e589a62011-09-20 00:26:08 +00001151 m_error.SetErrorStringWithFormat ("unsufficient data for value (only %lu of %lu bytes available)",
Enrico Granata9128ee22011-09-06 19:20:51 +00001152 m_data.GetByteSize(),
1153 GetByteSize());
1154 m_value_str.clear();
1155 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001156 }
1157 }
1158 break;
1159
Greg Clayton526e5af2010-11-13 03:52:47 +00001160 case Value::eContextTypeRegisterInfo:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001161 {
1162 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1163 if (reg_info)
1164 {
Jim Ingham6657d092012-01-19 21:10:56 +00001165 lldb::Format my_format = GetFormat();
1166 if (m_format == lldb::eFormatDefault)
1167 {
1168 if (m_last_value_format)
1169 my_format = m_last_value_format->GetFormat();
1170 else
1171 my_format = reg_info->format;
1172 }
1173
Greg Claytoncc4d0142012-02-17 07:49:44 +00001174 ExecutionContext exe_ctx (GetExecutionContextRef());
1175
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001176 StreamString reg_sstr;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001177 m_data.Dump (&reg_sstr,
1178 0,
1179 my_format,
1180 reg_info->byte_size,
1181 1,
1182 UINT32_MAX,
1183 LLDB_INVALID_ADDRESS,
1184 0,
1185 0,
1186 exe_ctx.GetBestExecutionContextScope());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001187 m_value_str.swap(reg_sstr.GetString());
1188 }
1189 }
1190 break;
Greg Claytonc982c762010-07-09 20:39:50 +00001191
1192 default:
1193 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001194 }
1195 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001196
1197 if (!m_value_did_change && m_old_value_valid)
1198 {
1199 // The value was gotten successfully, so we consider the
1200 // value as changed if the value string differs
1201 SetValueDidChange (m_old_value_str != m_value_str);
1202 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001203 }
1204 }
1205 if (m_value_str.empty())
1206 return NULL;
1207 return m_value_str.c_str();
1208}
1209
Enrico Granatac3e320a2011-08-02 17:27:39 +00001210// if > 8bytes, 0 is returned. this method should mostly be used
1211// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001212uint64_t
1213ValueObject::GetValueAsUnsigned (uint64_t fail_value)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001214{
1215 // If our byte size is zero this is an aggregate type that has children
1216 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1217 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001218 Scalar scalar;
1219 if (ResolveValue (scalar))
1220 return scalar.GetRawBits64(fail_value);
Enrico Granatac3e320a2011-08-02 17:27:39 +00001221 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001222 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001223}
1224
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001225bool
1226ValueObject::GetPrintableRepresentation(Stream& s,
1227 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001228 Format custom_format)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001229{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001230
Greg Claytonafacd142011-09-02 01:15:17 +00001231 if (custom_format != eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001232 SetFormat(custom_format);
1233
1234 const char * return_value;
Enrico Granatacd1c0232011-08-04 23:37:18 +00001235 std::string alloc_mem;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001236
1237 switch(val_obj_display)
1238 {
1239 case eDisplayValue:
1240 return_value = GetValueAsCString();
1241 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001242
Enrico Granata0a3958e2011-07-02 00:25:22 +00001243 case eDisplaySummary:
Greg Clayton48ca8b82012-01-07 20:58:07 +00001244 return_value = GetSummaryAsCString();
1245 break;
1246
Enrico Granata0a3958e2011-07-02 00:25:22 +00001247 case eDisplayLanguageSpecific:
1248 return_value = GetObjectDescription();
1249 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001250
Enrico Granataf2bbf712011-07-15 02:26:42 +00001251 case eDisplayLocation:
1252 return_value = GetLocationAsCString();
1253 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001254
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001255 case eDisplayChildrenCount:
Greg Clayton48ca8b82012-01-07 20:58:07 +00001256 {
1257 alloc_mem.resize(512);
1258 return_value = &alloc_mem[0];
1259 int count = GetNumChildren();
1260 snprintf((char*)return_value, 512, "%d", count);
1261 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001262 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001263
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001264 case eDisplayType:
1265 return_value = GetTypeName().AsCString();
1266 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001267
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001268 default:
1269 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001270 }
1271
Enrico Granata855cd902011-09-06 22:59:55 +00001272 if (!return_value)
Enrico Granata9fc19442011-07-06 02:13:41 +00001273 {
Enrico Granata9fc19442011-07-06 02:13:41 +00001274 if (val_obj_display == eDisplayValue)
Enrico Granata855cd902011-09-06 22:59:55 +00001275 return_value = GetSummaryAsCString();
Enrico Granata9fc19442011-07-06 02:13:41 +00001276 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +00001277 {
1278 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1279 {
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001280 // this thing has no value, and it seems to have no summary
1281 // some combination of unitialized data and other factors can also
Enrico Granata855cd902011-09-06 22:59:55 +00001282 // raise this condition, so let's print a nice generic description
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001283 {
1284 alloc_mem.resize(684);
1285 return_value = &alloc_mem[0];
1286 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1287 }
Enrico Granatae992a082011-07-22 17:03:19 +00001288 }
1289 else
1290 return_value = GetValueAsCString();
1291 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001292 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001293
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001294 if (return_value)
1295 s.PutCString(return_value);
1296 else
Enrico Granata88da35f2011-08-23 21:26:09 +00001297 {
1298 if (m_error.Fail())
1299 s.Printf("<%s>", m_error.AsCString());
1300 else if (val_obj_display == eDisplaySummary)
1301 s.PutCString("<no summary available>");
1302 else if (val_obj_display == eDisplayValue)
1303 s.PutCString("<no value available>");
1304 else if (val_obj_display == eDisplayLanguageSpecific)
1305 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1306 else
1307 s.PutCString("<no printable representation>");
1308 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001309
1310 // we should only return false here if we could not do *anything*
1311 // even if we have an error message as output, that's a success
1312 // from our callers' perspective, so return true
1313 return true;
1314
Enrico Granata0a3958e2011-07-02 00:25:22 +00001315}
1316
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001317// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1318// this call up to date by returning true for your new special cases. We will eventually move
1319// to checking this call result before trying to display special cases
1320bool
1321ValueObject::HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001322 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001323{
1324 clang_type_t elem_or_pointee_type;
1325 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1326
1327 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1328 && val_obj_display == ValueObject::eDisplayValue)
1329 {
1330 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001331 (custom_format == eFormatCString ||
1332 custom_format == eFormatCharArray ||
1333 custom_format == eFormatChar ||
1334 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001335 return true;
1336
1337 if (flags.Test(ClangASTContext::eTypeIsArray))
1338 {
Greg Claytonafacd142011-09-02 01:15:17 +00001339 if ((custom_format == eFormatBytes) ||
1340 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001341 return true;
1342
Greg Claytonafacd142011-09-02 01:15:17 +00001343 if ((custom_format == eFormatVectorOfChar) ||
1344 (custom_format == eFormatVectorOfFloat32) ||
1345 (custom_format == eFormatVectorOfFloat64) ||
1346 (custom_format == eFormatVectorOfSInt16) ||
1347 (custom_format == eFormatVectorOfSInt32) ||
1348 (custom_format == eFormatVectorOfSInt64) ||
1349 (custom_format == eFormatVectorOfSInt8) ||
1350 (custom_format == eFormatVectorOfUInt128) ||
1351 (custom_format == eFormatVectorOfUInt16) ||
1352 (custom_format == eFormatVectorOfUInt32) ||
1353 (custom_format == eFormatVectorOfUInt64) ||
1354 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001355 return true;
1356 }
1357 }
1358 return false;
1359}
1360
Enrico Granata9fc19442011-07-06 02:13:41 +00001361bool
1362ValueObject::DumpPrintableRepresentation(Stream& s,
1363 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001364 Format custom_format,
Enrico Granata85933ed2011-08-18 16:38:26 +00001365 bool only_special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001366{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001367
1368 clang_type_t elem_or_pointee_type;
1369 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001370
Enrico Granataf4efecd2011-07-12 22:56:10 +00001371 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1372 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001373 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001374 // when being asked to get a printable display an array or pointer type directly,
1375 // try to "do the right thing"
1376
1377 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001378 (custom_format == eFormatCString ||
1379 custom_format == eFormatCharArray ||
1380 custom_format == eFormatChar ||
1381 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001382 {
1383 Error error;
1384 ReadPointedString(s,
1385 error,
1386 0,
Greg Claytonafacd142011-09-02 01:15:17 +00001387 (custom_format == eFormatVectorOfChar) ||
1388 (custom_format == eFormatCharArray));
Enrico Granataf4efecd2011-07-12 22:56:10 +00001389 return !error.Fail();
1390 }
1391
Greg Claytonafacd142011-09-02 01:15:17 +00001392 if (custom_format == eFormatEnum)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001393 return false;
1394
1395 // this only works for arrays, because I have no way to know when
1396 // the pointed memory ends, and no special \0 end of data marker
1397 if (flags.Test(ClangASTContext::eTypeIsArray))
1398 {
Greg Claytonafacd142011-09-02 01:15:17 +00001399 if ((custom_format == eFormatBytes) ||
1400 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001401 {
1402 uint32_t count = GetNumChildren();
1403
1404 s << '[';
1405 for (uint32_t low = 0; low < count; low++)
1406 {
1407
1408 if (low)
1409 s << ',';
1410
1411 ValueObjectSP child = GetChildAtIndex(low,true);
1412 if (!child.get())
1413 {
Enrico Granatae992a082011-07-22 17:03:19 +00001414 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001415 continue;
1416 }
1417 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1418 }
1419
1420 s << ']';
1421
1422 return true;
1423 }
1424
Greg Claytonafacd142011-09-02 01:15:17 +00001425 if ((custom_format == eFormatVectorOfChar) ||
1426 (custom_format == eFormatVectorOfFloat32) ||
1427 (custom_format == eFormatVectorOfFloat64) ||
1428 (custom_format == eFormatVectorOfSInt16) ||
1429 (custom_format == eFormatVectorOfSInt32) ||
1430 (custom_format == eFormatVectorOfSInt64) ||
1431 (custom_format == eFormatVectorOfSInt8) ||
1432 (custom_format == eFormatVectorOfUInt128) ||
1433 (custom_format == eFormatVectorOfUInt16) ||
1434 (custom_format == eFormatVectorOfUInt32) ||
1435 (custom_format == eFormatVectorOfUInt64) ||
1436 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001437 {
1438 uint32_t count = GetNumChildren();
1439
Greg Claytonafacd142011-09-02 01:15:17 +00001440 Format format = FormatManager::GetSingleItemFormat(custom_format);
Enrico Granataf4efecd2011-07-12 22:56:10 +00001441
1442 s << '[';
1443 for (uint32_t low = 0; low < count; low++)
1444 {
1445
1446 if (low)
1447 s << ',';
1448
1449 ValueObjectSP child = GetChildAtIndex(low,true);
1450 if (!child.get())
1451 {
Enrico Granatae992a082011-07-22 17:03:19 +00001452 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001453 continue;
1454 }
1455 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1456 }
1457
1458 s << ']';
1459
1460 return true;
1461 }
1462 }
1463
Greg Claytonafacd142011-09-02 01:15:17 +00001464 if ((custom_format == eFormatBoolean) ||
1465 (custom_format == eFormatBinary) ||
1466 (custom_format == eFormatChar) ||
1467 (custom_format == eFormatCharPrintable) ||
1468 (custom_format == eFormatComplexFloat) ||
1469 (custom_format == eFormatDecimal) ||
1470 (custom_format == eFormatHex) ||
1471 (custom_format == eFormatFloat) ||
1472 (custom_format == eFormatOctal) ||
1473 (custom_format == eFormatOSType) ||
1474 (custom_format == eFormatUnicode16) ||
1475 (custom_format == eFormatUnicode32) ||
1476 (custom_format == eFormatUnsigned) ||
1477 (custom_format == eFormatPointer) ||
1478 (custom_format == eFormatComplexInteger) ||
1479 (custom_format == eFormatComplex) ||
1480 (custom_format == eFormatDefault)) // use the [] operator
Enrico Granataf4efecd2011-07-12 22:56:10 +00001481 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001482 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001483
1484 if (only_special)
1485 return false;
1486
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001487 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001488 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001489 SetFormat(eFormatDefault);
1490 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001491}
1492
Greg Clayton737b9322010-09-13 03:32:57 +00001493addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001494ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001495{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001496 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001497 return LLDB_INVALID_ADDRESS;
1498
Greg Clayton73b472d2010-10-27 03:32:59 +00001499 switch (m_value.GetValueType())
1500 {
1501 case Value::eValueTypeScalar:
1502 if (scalar_is_load_address)
1503 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001504 if(address_type)
1505 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001506 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1507 }
1508 break;
1509
1510 case Value::eValueTypeLoadAddress:
1511 case Value::eValueTypeFileAddress:
1512 case Value::eValueTypeHostAddress:
1513 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001514 if(address_type)
1515 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001516 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1517 }
1518 break;
1519 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001520 if (address_type)
1521 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001522 return LLDB_INVALID_ADDRESS;
1523}
1524
1525addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001526ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001527{
Greg Claytonafacd142011-09-02 01:15:17 +00001528 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001529 if(address_type)
1530 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001531
Enrico Granatac3e320a2011-08-02 17:27:39 +00001532 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001533 return address;
1534
Greg Clayton73b472d2010-10-27 03:32:59 +00001535 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001536 {
1537 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001538 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001539 break;
1540
Enrico Granata9128ee22011-09-06 19:20:51 +00001541 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001542 case Value::eValueTypeLoadAddress:
1543 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001544 {
1545 uint32_t data_offset = 0;
1546 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001547 }
1548 break;
1549 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001550
Enrico Granata9128ee22011-09-06 19:20:51 +00001551 if (address_type)
1552 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001553
Greg Clayton737b9322010-09-13 03:32:57 +00001554 return address;
1555}
1556
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001557bool
Jim Ingham6035b672011-03-31 00:19:25 +00001558ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001559{
1560 // Make sure our value is up to date first so that our location and location
1561 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001562 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001563 return false;
1564
1565 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001566 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001567
Greg Claytonb1320972010-07-14 00:18:15 +00001568 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001569
Jim Ingham16e0c682011-08-12 23:34:31 +00001570 Value::ValueType value_type = m_value.GetValueType();
1571
1572 if (value_type == Value::eValueTypeScalar)
1573 {
1574 // If the value is already a scalar, then let the scalar change itself:
1575 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1576 }
1577 else if (byte_size <= Scalar::GetMaxByteSize())
1578 {
1579 // If the value fits in a scalar, then make a new scalar and again let the
1580 // scalar code do the conversion, then figure out where to put the new value.
1581 Scalar new_scalar;
1582 Error error;
1583 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1584 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001585 {
Jim Ingham4b536182011-08-09 02:12:22 +00001586 switch (value_type)
1587 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001588 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001589 {
1590 // If it is a load address, then the scalar value is the storage location
1591 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001592 ExecutionContext exe_ctx (GetExecutionContextRef());
1593 Process *process = exe_ctx.GetProcessPtr();
1594 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001595 {
Greg Claytonafacd142011-09-02 01:15:17 +00001596 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001597 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1598 new_scalar,
1599 byte_size,
1600 error);
Jim Ingham16e0c682011-08-12 23:34:31 +00001601 if (!error.Success() || bytes_written != byte_size)
1602 return false;
1603 }
1604 }
Jim Ingham4b536182011-08-09 02:12:22 +00001605 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001606 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001607 {
1608 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1609 DataExtractor new_data;
1610 new_data.SetByteOrder (m_data.GetByteOrder());
1611
1612 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1613 m_data.SetData(buffer_sp, 0);
1614 bool success = new_scalar.GetData(new_data);
1615 if (success)
1616 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001617 new_data.CopyByteOrderedData (0,
1618 byte_size,
1619 const_cast<uint8_t *>(m_data.GetDataStart()),
1620 byte_size,
1621 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001622 }
1623 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1624
1625 }
Jim Ingham4b536182011-08-09 02:12:22 +00001626 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001627 case Value::eValueTypeFileAddress:
1628 case Value::eValueTypeScalar:
Jim Ingham16e0c682011-08-12 23:34:31 +00001629 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001630 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001631 }
1632 else
1633 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001634 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001635 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001636 }
1637 else
1638 {
1639 // We don't support setting things bigger than a scalar at present.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001640 return false;
1641 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001642
1643 // If we have reached this point, then we have successfully changed the value.
1644 SetNeedsUpdate();
1645 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001646}
1647
Greg Clayton81e871e2012-02-04 02:27:34 +00001648bool
1649ValueObject::GetDeclaration (Declaration &decl)
1650{
1651 decl.Clear();
1652 return false;
1653}
1654
Greg Claytonafacd142011-09-02 01:15:17 +00001655LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001656ValueObject::GetObjectRuntimeLanguage ()
1657{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001658 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1659 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001660}
1661
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001662void
Jim Ingham58b59f92011-04-22 23:53:53 +00001663ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001664{
Jim Ingham58b59f92011-04-22 23:53:53 +00001665 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001666}
1667
1668ValueObjectSP
1669ValueObject::GetSyntheticChild (const ConstString &key) const
1670{
1671 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001672 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001673 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001674 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001675 return synthetic_child_sp;
1676}
1677
1678bool
1679ValueObject::IsPointerType ()
1680{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001681 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001682}
1683
Jim Inghamb7603bb2011-03-18 00:05:18 +00001684bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001685ValueObject::IsArrayType ()
1686{
1687 return ClangASTContext::IsArrayType (GetClangType());
1688}
1689
1690bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001691ValueObject::IsScalarType ()
1692{
1693 return ClangASTContext::IsScalarType (GetClangType());
1694}
1695
1696bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001697ValueObject::IsIntegerType (bool &is_signed)
1698{
1699 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1700}
Greg Clayton73b472d2010-10-27 03:32:59 +00001701
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001702bool
1703ValueObject::IsPointerOrReferenceType ()
1704{
Greg Clayton007d5be2011-05-30 00:49:24 +00001705 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1706}
1707
1708bool
1709ValueObject::IsPossibleCPlusPlusDynamicType ()
1710{
1711 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001712}
1713
Greg Claytondea8cb42011-06-29 22:09:02 +00001714bool
1715ValueObject::IsPossibleDynamicType ()
1716{
1717 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1718}
1719
Greg Claytonafacd142011-09-02 01:15:17 +00001720ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001721ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1722{
1723 if (IsArrayType())
1724 return GetSyntheticArrayMemberFromArray(index, can_create);
1725
1726 if (IsPointerType())
1727 return GetSyntheticArrayMemberFromPointer(index, can_create);
1728
1729 return ValueObjectSP();
1730
1731}
1732
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001733ValueObjectSP
1734ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1735{
1736 ValueObjectSP synthetic_child_sp;
1737 if (IsPointerType ())
1738 {
1739 char index_str[64];
1740 snprintf(index_str, sizeof(index_str), "[%i]", index);
1741 ConstString index_const_str(index_str);
1742 // Check if we have already created a synthetic array member in this
1743 // valid object. If we have we will re-use it.
1744 synthetic_child_sp = GetSyntheticChild (index_const_str);
1745 if (!synthetic_child_sp)
1746 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001747 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001748 // We haven't made a synthetic array member for INDEX yet, so
1749 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001750 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001751
1752 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001753 if (synthetic_child)
1754 {
1755 AddSyntheticChild(index_const_str, synthetic_child);
1756 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001757 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001758 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001759 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001760 }
1761 }
1762 return synthetic_child_sp;
1763}
Jim Ingham22777012010-09-23 02:01:19 +00001764
Greg Claytondaf515f2011-07-09 20:12:33 +00001765// This allows you to create an array member using and index
1766// that doesn't not fall in the normal bounds of the array.
1767// Many times structure can be defined as:
1768// struct Collection
1769// {
1770// uint32_t item_count;
1771// Item item_array[0];
1772// };
1773// The size of the "item_array" is 1, but many times in practice
1774// there are more items in "item_array".
1775
1776ValueObjectSP
1777ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1778{
1779 ValueObjectSP synthetic_child_sp;
1780 if (IsArrayType ())
1781 {
1782 char index_str[64];
1783 snprintf(index_str, sizeof(index_str), "[%i]", index);
1784 ConstString index_const_str(index_str);
1785 // Check if we have already created a synthetic array member in this
1786 // valid object. If we have we will re-use it.
1787 synthetic_child_sp = GetSyntheticChild (index_const_str);
1788 if (!synthetic_child_sp)
1789 {
1790 ValueObject *synthetic_child;
1791 // We haven't made a synthetic array member for INDEX yet, so
1792 // lets make one and cache it for any future reference.
1793 synthetic_child = CreateChildAtIndex(0, true, index);
1794
1795 // Cache the value if we got one back...
1796 if (synthetic_child)
1797 {
1798 AddSyntheticChild(index_const_str, synthetic_child);
1799 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001800 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001801 synthetic_child_sp->m_is_array_item_for_pointer = true;
1802 }
1803 }
1804 }
1805 return synthetic_child_sp;
1806}
1807
Enrico Granata9fc19442011-07-06 02:13:41 +00001808ValueObjectSP
1809ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1810{
1811 ValueObjectSP synthetic_child_sp;
1812 if (IsScalarType ())
1813 {
1814 char index_str[64];
1815 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1816 ConstString index_const_str(index_str);
1817 // Check if we have already created a synthetic array member in this
1818 // valid object. If we have we will re-use it.
1819 synthetic_child_sp = GetSyntheticChild (index_const_str);
1820 if (!synthetic_child_sp)
1821 {
1822 ValueObjectChild *synthetic_child;
1823 // We haven't made a synthetic array member for INDEX yet, so
1824 // lets make one and cache it for any future reference.
1825 synthetic_child = new ValueObjectChild(*this,
1826 GetClangAST(),
1827 GetClangType(),
1828 index_const_str,
1829 GetByteSize(),
1830 0,
1831 to-from+1,
1832 from,
1833 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001834 false,
1835 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001836
1837 // Cache the value if we got one back...
1838 if (synthetic_child)
1839 {
1840 AddSyntheticChild(index_const_str, synthetic_child);
1841 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001842 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001843 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1844 }
1845 }
1846 }
1847 return synthetic_child_sp;
1848}
1849
Greg Claytonafacd142011-09-02 01:15:17 +00001850ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001851ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1852{
1853 ValueObjectSP synthetic_child_sp;
1854 if (IsArrayType () || IsPointerType ())
1855 {
1856 char index_str[64];
1857 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1858 ConstString index_const_str(index_str);
1859 // Check if we have already created a synthetic array member in this
1860 // valid object. If we have we will re-use it.
1861 synthetic_child_sp = GetSyntheticChild (index_const_str);
1862 if (!synthetic_child_sp)
1863 {
1864 ValueObjectSynthetic *synthetic_child;
1865
1866 // We haven't made a synthetic array member for INDEX yet, so
1867 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001868 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001869 view->AddRange(from,to);
1870 SyntheticChildrenSP view_sp(view);
1871 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1872
1873 // Cache the value if we got one back...
1874 if (synthetic_child)
1875 {
1876 AddSyntheticChild(index_const_str, synthetic_child);
1877 synthetic_child_sp = synthetic_child->GetSP();
1878 synthetic_child_sp->SetName(ConstString(index_str));
1879 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1880 }
1881 }
1882 }
1883 return synthetic_child_sp;
1884}
1885
Greg Claytonafacd142011-09-02 01:15:17 +00001886ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001887ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1888{
1889
1890 ValueObjectSP synthetic_child_sp;
1891
1892 char name_str[64];
1893 snprintf(name_str, sizeof(name_str), "@%i", offset);
1894 ConstString name_const_str(name_str);
1895
1896 // Check if we have already created a synthetic array member in this
1897 // valid object. If we have we will re-use it.
1898 synthetic_child_sp = GetSyntheticChild (name_const_str);
1899
1900 if (synthetic_child_sp.get())
1901 return synthetic_child_sp;
1902
1903 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001904 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001905
1906 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1907 type.GetASTContext(),
1908 type.GetOpaqueQualType(),
1909 name_const_str,
1910 type.GetTypeByteSize(),
1911 offset,
1912 0,
1913 0,
1914 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001915 false,
1916 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001917 if (synthetic_child)
1918 {
1919 AddSyntheticChild(name_const_str, synthetic_child);
1920 synthetic_child_sp = synthetic_child->GetSP();
1921 synthetic_child_sp->SetName(name_const_str);
1922 synthetic_child_sp->m_is_child_at_offset = true;
1923 }
1924 return synthetic_child_sp;
1925}
1926
Enrico Granatad55546b2011-07-22 00:16:08 +00001927// your expression path needs to have a leading . or ->
1928// (unless it somehow "looks like" an array, in which case it has
1929// a leading [ symbol). while the [ is meaningful and should be shown
1930// to the user, . and -> are just parser design, but by no means
1931// added information for the user.. strip them off
1932static const char*
1933SkipLeadingExpressionPathSeparators(const char* expression)
1934{
1935 if (!expression || !expression[0])
1936 return expression;
1937 if (expression[0] == '.')
1938 return expression+1;
1939 if (expression[0] == '-' && expression[1] == '>')
1940 return expression+2;
1941 return expression;
1942}
1943
Greg Claytonafacd142011-09-02 01:15:17 +00001944ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00001945ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1946{
1947 ValueObjectSP synthetic_child_sp;
1948 ConstString name_const_string(expression);
1949 // Check if we have already created a synthetic array member in this
1950 // valid object. If we have we will re-use it.
1951 synthetic_child_sp = GetSyntheticChild (name_const_string);
1952 if (!synthetic_child_sp)
1953 {
1954 // We haven't made a synthetic array member for expression yet, so
1955 // lets make one and cache it for any future reference.
1956 synthetic_child_sp = GetValueForExpressionPath(expression);
1957
1958 // Cache the value if we got one back...
1959 if (synthetic_child_sp.get())
1960 {
1961 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001962 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001963 synthetic_child_sp->m_is_expression_path_child = true;
1964 }
1965 }
1966 return synthetic_child_sp;
1967}
1968
1969void
Greg Claytonafacd142011-09-02 01:15:17 +00001970ValueObject::CalculateSyntheticValue (SyntheticValueType use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00001971{
Greg Claytonafacd142011-09-02 01:15:17 +00001972 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001973 return;
1974
Enrico Granatac3e320a2011-08-02 17:27:39 +00001975 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001976
1977 if (m_last_synthetic_filter.get() == NULL)
1978 return;
1979
Enrico Granataa37a0652011-07-24 00:14:56 +00001980 if (m_synthetic_value == NULL)
1981 m_synthetic_value = new ValueObjectSynthetic(*this, m_last_synthetic_filter);
Enrico Granatad55546b2011-07-22 00:16:08 +00001982
1983}
1984
Jim Ingham78a685a2011-04-16 00:01:13 +00001985void
Greg Claytonafacd142011-09-02 01:15:17 +00001986ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00001987{
Greg Claytonafacd142011-09-02 01:15:17 +00001988 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00001989 return;
1990
Jim Ingham58b59f92011-04-22 23:53:53 +00001991 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00001992 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001993 ExecutionContext exe_ctx (GetExecutionContextRef());
1994 Process *process = exe_ctx.GetProcessPtr();
1995 if (process)
Jim Ingham78a685a2011-04-16 00:01:13 +00001996 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001997 bool worth_having_dynamic_value = false;
Jim Ingham78a685a2011-04-16 00:01:13 +00001998
Greg Claytoncc4d0142012-02-17 07:49:44 +00001999
2000 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
2001 // hard code this everywhere.
2002 LanguageType known_type = GetObjectRuntimeLanguage();
2003 if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
Jim Ingham78a685a2011-04-16 00:01:13 +00002004 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002005 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
2006 if (runtime)
2007 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00002008 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00002009 else
2010 {
2011 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus);
2012 if (cpp_runtime)
2013 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
2014
2015 if (!worth_having_dynamic_value)
2016 {
2017 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC);
2018 if (objc_runtime)
2019 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
2020 }
2021 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002022
Greg Claytoncc4d0142012-02-17 07:49:44 +00002023 if (worth_having_dynamic_value)
2024 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
2025 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002026 }
2027}
2028
Jim Ingham58b59f92011-04-22 23:53:53 +00002029ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002030ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002031{
Greg Claytonafacd142011-09-02 01:15:17 +00002032 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002033 return ValueObjectSP();
2034
2035 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002036 {
Jim Ingham2837b762011-05-04 03:43:18 +00002037 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002038 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002039 if (m_dynamic_value)
2040 return m_dynamic_value->GetSP();
2041 else
2042 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002043}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002044
Jim Ingham60dbabb2011-12-08 19:44:08 +00002045ValueObjectSP
2046ValueObject::GetStaticValue()
2047{
2048 return GetSP();
2049}
2050
Enrico Granatad55546b2011-07-22 00:16:08 +00002051// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
2052// or we do not really want a dynamic VO. this method instead returns this object
2053// itself when making it synthetic has no meaning. this makes it much simpler
2054// to replace the SyntheticValue for the ValueObject
2055ValueObjectSP
2056ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
2057{
Greg Claytonafacd142011-09-02 01:15:17 +00002058 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00002059 return GetSP();
2060
Enrico Granatac3e320a2011-08-02 17:27:39 +00002061 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00002062
2063 if (m_last_synthetic_filter.get() == NULL)
2064 return GetSP();
2065
2066 CalculateSyntheticValue(use_synthetic);
2067
2068 if (m_synthetic_value)
2069 return m_synthetic_value->GetSP();
2070 else
2071 return GetSP();
2072}
2073
Greg Claytone221f822011-01-21 01:59:00 +00002074bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002075ValueObject::HasSyntheticValue()
2076{
2077 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2078
2079 if (m_last_synthetic_filter.get() == NULL)
2080 return false;
2081
Greg Claytonafacd142011-09-02 01:15:17 +00002082 CalculateSyntheticValue(eUseSyntheticFilter);
Enrico Granata27b625e2011-08-09 01:04:56 +00002083
2084 if (m_synthetic_value)
2085 return true;
2086 else
2087 return false;
2088}
2089
2090bool
Greg Claytone221f822011-01-21 01:59:00 +00002091ValueObject::GetBaseClassPath (Stream &s)
2092{
2093 if (IsBaseClass())
2094 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002095 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002096 clang_type_t clang_type = GetClangType();
2097 std::string cxx_class_name;
2098 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2099 if (this_had_base_class)
2100 {
2101 if (parent_had_base_class)
2102 s.PutCString("::");
2103 s.PutCString(cxx_class_name.c_str());
2104 }
2105 return parent_had_base_class || this_had_base_class;
2106 }
2107 return false;
2108}
2109
2110
2111ValueObject *
2112ValueObject::GetNonBaseClassParent()
2113{
Jim Ingham78a685a2011-04-16 00:01:13 +00002114 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002115 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002116 if (GetParent()->IsBaseClass())
2117 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002118 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002119 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002120 }
2121 return NULL;
2122}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002123
2124void
Enrico Granata4becb372011-06-29 22:27:15 +00002125ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002126{
Greg Claytone221f822011-01-21 01:59:00 +00002127 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002128
Enrico Granata85933ed2011-08-18 16:38:26 +00002129 if (is_deref_of_parent && epformat == eDereferencePointers)
2130 {
Enrico Granata4becb372011-06-29 22:27:15 +00002131 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2132 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2133 // the eHonorPointers mode is meant to produce strings in this latter format
2134 s.PutCString("*(");
2135 }
Greg Claytone221f822011-01-21 01:59:00 +00002136
Enrico Granata4becb372011-06-29 22:27:15 +00002137 ValueObject* parent = GetParent();
2138
2139 if (parent)
2140 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002141
2142 // if we are a deref_of_parent just because we are synthetic array
2143 // members made up to allow ptr[%d] syntax to work in variable
2144 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00002145 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002146 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002147
Greg Claytone221f822011-01-21 01:59:00 +00002148 if (!IsBaseClass())
2149 {
2150 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002151 {
Greg Claytone221f822011-01-21 01:59:00 +00002152 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2153 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002154 {
Greg Claytone221f822011-01-21 01:59:00 +00002155 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2156 if (non_base_class_parent_clang_type)
2157 {
2158 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2159
Enrico Granata9dd75c82011-07-15 23:30:15 +00002160 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002161 {
2162 s.PutCString("->");
2163 }
Enrico Granata4becb372011-06-29 22:27:15 +00002164 else
2165 {
2166 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2167 {
2168 s.PutCString("->");
2169 }
2170 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2171 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2172 {
2173 s.PutChar('.');
2174 }
Greg Claytone221f822011-01-21 01:59:00 +00002175 }
2176 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002177 }
Greg Claytone221f822011-01-21 01:59:00 +00002178
2179 const char *name = GetName().GetCString();
2180 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002181 {
Greg Claytone221f822011-01-21 01:59:00 +00002182 if (qualify_cxx_base_classes)
2183 {
2184 if (GetBaseClassPath (s))
2185 s.PutCString("::");
2186 }
2187 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002188 }
2189 }
2190 }
2191
Enrico Granata85933ed2011-08-18 16:38:26 +00002192 if (is_deref_of_parent && epformat == eDereferencePointers)
2193 {
Greg Claytone221f822011-01-21 01:59:00 +00002194 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002195 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002196}
2197
Greg Claytonafacd142011-09-02 01:15:17 +00002198ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002199ValueObject::GetValueForExpressionPath(const char* expression,
2200 const char** first_unparsed,
2201 ExpressionPathScanEndReason* reason_to_stop,
2202 ExpressionPathEndResultType* final_value_type,
2203 const GetValueForExpressionPathOptions& options,
2204 ExpressionPathAftermath* final_task_on_target)
2205{
2206
2207 const char* dummy_first_unparsed;
2208 ExpressionPathScanEndReason dummy_reason_to_stop;
2209 ExpressionPathEndResultType dummy_final_value_type;
2210 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2211
2212 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2213 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2214 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2215 final_value_type ? final_value_type : &dummy_final_value_type,
2216 options,
2217 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2218
2219 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2220 {
2221 return ret_val;
2222 }
2223 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2224 {
2225 if (*final_task_on_target == ValueObject::eDereference)
2226 {
2227 Error error;
2228 ValueObjectSP final_value = ret_val->Dereference(error);
2229 if (error.Fail() || !final_value.get())
2230 {
2231 *reason_to_stop = ValueObject::eDereferencingFailed;
2232 *final_value_type = ValueObject::eInvalid;
2233 return ValueObjectSP();
2234 }
2235 else
2236 {
2237 *final_task_on_target = ValueObject::eNothing;
2238 return final_value;
2239 }
2240 }
2241 if (*final_task_on_target == ValueObject::eTakeAddress)
2242 {
2243 Error error;
2244 ValueObjectSP final_value = ret_val->AddressOf(error);
2245 if (error.Fail() || !final_value.get())
2246 {
2247 *reason_to_stop = ValueObject::eTakingAddressFailed;
2248 *final_value_type = ValueObject::eInvalid;
2249 return ValueObjectSP();
2250 }
2251 else
2252 {
2253 *final_task_on_target = ValueObject::eNothing;
2254 return final_value;
2255 }
2256 }
2257 }
2258 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2259}
2260
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002261int
2262ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002263 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002264 const char** first_unparsed,
2265 ExpressionPathScanEndReason* reason_to_stop,
2266 ExpressionPathEndResultType* final_value_type,
2267 const GetValueForExpressionPathOptions& options,
2268 ExpressionPathAftermath* final_task_on_target)
2269{
2270 const char* dummy_first_unparsed;
2271 ExpressionPathScanEndReason dummy_reason_to_stop;
2272 ExpressionPathEndResultType dummy_final_value_type;
2273 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2274
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
2282 if (!ret_val.get()) // if there are errors, I add nothing to the list
2283 return 0;
2284
2285 if (*reason_to_stop != eArrayRangeOperatorMet)
2286 {
2287 // I need not expand a range, just post-process the final value and return
2288 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2289 {
2290 list->Append(ret_val);
2291 return 1;
2292 }
2293 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2294 {
2295 if (*final_task_on_target == ValueObject::eDereference)
2296 {
2297 Error error;
2298 ValueObjectSP final_value = ret_val->Dereference(error);
2299 if (error.Fail() || !final_value.get())
2300 {
2301 *reason_to_stop = ValueObject::eDereferencingFailed;
2302 *final_value_type = ValueObject::eInvalid;
2303 return 0;
2304 }
2305 else
2306 {
2307 *final_task_on_target = ValueObject::eNothing;
2308 list->Append(final_value);
2309 return 1;
2310 }
2311 }
2312 if (*final_task_on_target == ValueObject::eTakeAddress)
2313 {
2314 Error error;
2315 ValueObjectSP final_value = ret_val->AddressOf(error);
2316 if (error.Fail() || !final_value.get())
2317 {
2318 *reason_to_stop = ValueObject::eTakingAddressFailed;
2319 *final_value_type = ValueObject::eInvalid;
2320 return 0;
2321 }
2322 else
2323 {
2324 *final_task_on_target = ValueObject::eNothing;
2325 list->Append(final_value);
2326 return 1;
2327 }
2328 }
2329 }
2330 }
2331 else
2332 {
2333 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2334 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2335 ret_val,
2336 list,
2337 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2338 final_value_type ? final_value_type : &dummy_final_value_type,
2339 options,
2340 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2341 }
2342 // in any non-covered case, just do the obviously right thing
2343 list->Append(ret_val);
2344 return 1;
2345}
2346
Greg Claytonafacd142011-09-02 01:15:17 +00002347ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002348ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2349 const char** first_unparsed,
2350 ExpressionPathScanEndReason* reason_to_stop,
2351 ExpressionPathEndResultType* final_result,
2352 const GetValueForExpressionPathOptions& options,
2353 ExpressionPathAftermath* what_next)
2354{
2355 ValueObjectSP root = GetSP();
2356
2357 if (!root.get())
2358 return ValueObjectSP();
2359
2360 *first_unparsed = expression_cstr;
2361
2362 while (true)
2363 {
2364
2365 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2366
Greg Claytonafacd142011-09-02 01:15:17 +00002367 clang_type_t root_clang_type = root->GetClangType();
2368 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002369 Flags root_clang_type_info,pointee_clang_type_info;
2370
2371 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2372 if (pointee_clang_type)
2373 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002374
2375 if (!expression_cstr || *expression_cstr == '\0')
2376 {
2377 *reason_to_stop = ValueObject::eEndOfString;
2378 return root;
2379 }
2380
2381 switch (*expression_cstr)
2382 {
2383 case '-':
2384 {
2385 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002386 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 +00002387 {
2388 *first_unparsed = expression_cstr;
2389 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
2390 *final_result = ValueObject::eInvalid;
2391 return ValueObjectSP();
2392 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002393 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2394 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002395 options.m_no_fragile_ivar)
2396 {
2397 *first_unparsed = expression_cstr;
2398 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
2399 *final_result = ValueObject::eInvalid;
2400 return ValueObjectSP();
2401 }
2402 if (expression_cstr[1] != '>')
2403 {
2404 *first_unparsed = expression_cstr;
2405 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2406 *final_result = ValueObject::eInvalid;
2407 return ValueObjectSP();
2408 }
2409 expression_cstr++; // skip the -
2410 }
2411 case '.': // or fallthrough from ->
2412 {
2413 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002414 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 +00002415 {
2416 *first_unparsed = expression_cstr;
2417 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
2418 *final_result = ValueObject::eInvalid;
2419 return ValueObjectSP();
2420 }
2421 expression_cstr++; // skip .
2422 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2423 ConstString child_name;
2424 if (!next_separator) // if no other separator just expand this last layer
2425 {
2426 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002427 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2428
2429 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002430 {
2431 *first_unparsed = '\0';
2432 *reason_to_stop = ValueObject::eEndOfString;
2433 *final_result = ValueObject::ePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002434 return child_valobj_sp;
2435 }
2436 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2437 {
Greg Clayton4c3b8fb2011-12-02 22:48:25 +00002438 child_valobj_sp = root->GetSyntheticValue(eNoSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002439 }
2440
2441 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2442 // so we hit the "else" branch, and return an error
2443 if(child_valobj_sp.get()) // if it worked, just return
2444 {
2445 *first_unparsed = '\0';
2446 *reason_to_stop = ValueObject::eEndOfString;
2447 *final_result = ValueObject::ePlain;
2448 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002449 }
2450 else
2451 {
2452 *first_unparsed = expression_cstr;
2453 *reason_to_stop = ValueObject::eNoSuchChild;
2454 *final_result = ValueObject::eInvalid;
2455 return ValueObjectSP();
2456 }
2457 }
2458 else // other layers do expand
2459 {
2460 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002461 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2462 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002463 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002464 root = child_valobj_sp;
2465 *first_unparsed = next_separator;
2466 *final_result = ValueObject::ePlain;
2467 continue;
2468 }
2469 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2470 {
Greg Claytonafacd142011-09-02 01:15:17 +00002471 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002472 }
2473
2474 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2475 // so we hit the "else" branch, and return an error
2476 if(child_valobj_sp.get()) // if it worked, move on
2477 {
2478 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002479 *first_unparsed = next_separator;
2480 *final_result = ValueObject::ePlain;
2481 continue;
2482 }
2483 else
2484 {
2485 *first_unparsed = expression_cstr;
2486 *reason_to_stop = ValueObject::eNoSuchChild;
2487 *final_result = ValueObject::eInvalid;
2488 return ValueObjectSP();
2489 }
2490 }
2491 break;
2492 }
2493 case '[':
2494 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002495 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 +00002496 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002497 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002498 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002499 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2500 {
2501 *first_unparsed = expression_cstr;
2502 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2503 *final_result = ValueObject::eInvalid;
2504 return ValueObjectSP();
2505 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002506 }
2507 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2508 {
2509 *first_unparsed = expression_cstr;
2510 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2511 *final_result = ValueObject::eInvalid;
2512 return ValueObjectSP();
2513 }
2514 }
2515 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2516 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002517 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002518 {
2519 *first_unparsed = expression_cstr;
2520 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2521 *final_result = ValueObject::eInvalid;
2522 return ValueObjectSP();
2523 }
2524 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2525 {
2526 *first_unparsed = expression_cstr+2;
2527 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2528 *final_result = ValueObject::eUnboundedRange;
2529 return root;
2530 }
2531 }
2532 const char *separator_position = ::strchr(expression_cstr+1,'-');
2533 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2534 if (!close_bracket_position) // if there is no ], this is a syntax error
2535 {
2536 *first_unparsed = expression_cstr;
2537 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2538 *final_result = ValueObject::eInvalid;
2539 return ValueObjectSP();
2540 }
2541 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2542 {
2543 char *end = NULL;
2544 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2545 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2546 {
2547 *first_unparsed = expression_cstr;
2548 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2549 *final_result = ValueObject::eInvalid;
2550 return ValueObjectSP();
2551 }
2552 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2553 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002554 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002555 {
2556 *first_unparsed = expression_cstr+2;
2557 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2558 *final_result = ValueObject::eUnboundedRange;
2559 return root;
2560 }
2561 else
2562 {
2563 *first_unparsed = expression_cstr;
2564 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2565 *final_result = ValueObject::eInvalid;
2566 return ValueObjectSP();
2567 }
2568 }
2569 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002570 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002571 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002572 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2573 if (!child_valobj_sp)
2574 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002575 if (!child_valobj_sp)
Greg Claytonafacd142011-09-02 01:15:17 +00002576 if (root->HasSyntheticValue() && root->GetSyntheticValue(eUseSyntheticFilter)->GetNumChildren() > index)
2577 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002578 if (child_valobj_sp)
2579 {
2580 root = child_valobj_sp;
2581 *first_unparsed = end+1; // skip ]
2582 *final_result = ValueObject::ePlain;
2583 continue;
2584 }
2585 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002586 {
2587 *first_unparsed = expression_cstr;
2588 *reason_to_stop = ValueObject::eNoSuchChild;
2589 *final_result = ValueObject::eInvalid;
2590 return ValueObjectSP();
2591 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002592 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002593 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002594 {
2595 if (*what_next == ValueObject::eDereference && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002596 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002597 {
2598 Error error;
2599 root = root->Dereference(error);
2600 if (error.Fail() || !root.get())
2601 {
2602 *first_unparsed = expression_cstr;
2603 *reason_to_stop = ValueObject::eDereferencingFailed;
2604 *final_result = ValueObject::eInvalid;
2605 return ValueObjectSP();
2606 }
2607 else
2608 {
2609 *what_next = eNothing;
2610 continue;
2611 }
2612 }
2613 else
2614 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002615 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Claytonafacd142011-09-02 01:15:17 +00002616 root->GetClangType()) == eLanguageTypeObjC
Enrico Granata27b625e2011-08-09 01:04:56 +00002617 &&
2618 ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2619 &&
2620 root->HasSyntheticValue()
2621 &&
2622 options.m_no_synthetic_children == false)
2623 {
Greg Claytonafacd142011-09-02 01:15:17 +00002624 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002625 }
2626 else
2627 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002628 if (!root.get())
2629 {
2630 *first_unparsed = expression_cstr;
2631 *reason_to_stop = ValueObject::eNoSuchChild;
2632 *final_result = ValueObject::eInvalid;
2633 return ValueObjectSP();
2634 }
2635 else
2636 {
2637 *first_unparsed = end+1; // skip ]
2638 *final_result = ValueObject::ePlain;
2639 continue;
2640 }
2641 }
2642 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002643 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002644 {
2645 root = root->GetSyntheticBitFieldChild(index, index, true);
2646 if (!root.get())
2647 {
2648 *first_unparsed = expression_cstr;
2649 *reason_to_stop = ValueObject::eNoSuchChild;
2650 *final_result = ValueObject::eInvalid;
2651 return ValueObjectSP();
2652 }
2653 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2654 {
2655 *first_unparsed = end+1; // skip ]
2656 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2657 *final_result = ValueObject::eBitfield;
2658 return root;
2659 }
2660 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002661 else if (root->HasSyntheticValue() && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002662 {
Greg Claytonafacd142011-09-02 01:15:17 +00002663 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002664 if (!root.get())
2665 {
2666 *first_unparsed = expression_cstr;
2667 *reason_to_stop = ValueObject::eNoSuchChild;
2668 *final_result = ValueObject::eInvalid;
2669 return ValueObjectSP();
2670 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002671 else
2672 {
2673 *first_unparsed = end+1; // skip ]
2674 *final_result = ValueObject::ePlain;
2675 continue;
2676 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002677 }
2678 else
2679 {
2680 *first_unparsed = expression_cstr;
2681 *reason_to_stop = ValueObject::eNoSuchChild;
2682 *final_result = ValueObject::eInvalid;
2683 return ValueObjectSP();
2684 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002685 }
2686 else // we have a low and a high index
2687 {
2688 char *end = NULL;
2689 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2690 if (!end || end != separator_position) // if something weird is in our way return an error
2691 {
2692 *first_unparsed = expression_cstr;
2693 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2694 *final_result = ValueObject::eInvalid;
2695 return ValueObjectSP();
2696 }
2697 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2698 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2699 {
2700 *first_unparsed = expression_cstr;
2701 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2702 *final_result = ValueObject::eInvalid;
2703 return ValueObjectSP();
2704 }
2705 if (index_lower > index_higher) // swap indices if required
2706 {
2707 unsigned long temp = index_lower;
2708 index_lower = index_higher;
2709 index_higher = temp;
2710 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002711 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002712 {
2713 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2714 if (!root.get())
2715 {
2716 *first_unparsed = expression_cstr;
2717 *reason_to_stop = ValueObject::eNoSuchChild;
2718 *final_result = ValueObject::eInvalid;
2719 return ValueObjectSP();
2720 }
2721 else
2722 {
2723 *first_unparsed = end+1; // skip ]
2724 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2725 *final_result = ValueObject::eBitfield;
2726 return root;
2727 }
2728 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002729 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002730 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002731 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002732 {
2733 Error error;
2734 root = root->Dereference(error);
2735 if (error.Fail() || !root.get())
2736 {
2737 *first_unparsed = expression_cstr;
2738 *reason_to_stop = ValueObject::eDereferencingFailed;
2739 *final_result = ValueObject::eInvalid;
2740 return ValueObjectSP();
2741 }
2742 else
2743 {
2744 *what_next = ValueObject::eNothing;
2745 continue;
2746 }
2747 }
2748 else
2749 {
2750 *first_unparsed = expression_cstr;
2751 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2752 *final_result = ValueObject::eBoundedRange;
2753 return root;
2754 }
2755 }
2756 break;
2757 }
2758 default: // some non-separator is in the way
2759 {
2760 *first_unparsed = expression_cstr;
2761 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2762 *final_result = ValueObject::eInvalid;
2763 return ValueObjectSP();
2764 break;
2765 }
2766 }
2767 }
2768}
2769
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002770int
2771ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2772 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002773 ValueObjectSP root,
2774 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002775 ExpressionPathScanEndReason* reason_to_stop,
2776 ExpressionPathEndResultType* final_result,
2777 const GetValueForExpressionPathOptions& options,
2778 ExpressionPathAftermath* what_next)
2779{
2780 if (!root.get())
2781 return 0;
2782
2783 *first_unparsed = expression_cstr;
2784
2785 while (true)
2786 {
2787
2788 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2789
Greg Claytonafacd142011-09-02 01:15:17 +00002790 clang_type_t root_clang_type = root->GetClangType();
2791 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002792 Flags root_clang_type_info,pointee_clang_type_info;
2793
2794 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2795 if (pointee_clang_type)
2796 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2797
2798 if (!expression_cstr || *expression_cstr == '\0')
2799 {
2800 *reason_to_stop = ValueObject::eEndOfString;
2801 list->Append(root);
2802 return 1;
2803 }
2804
2805 switch (*expression_cstr)
2806 {
2807 case '[':
2808 {
2809 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2810 {
2811 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2812 {
2813 *first_unparsed = expression_cstr;
2814 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2815 *final_result = ValueObject::eInvalid;
2816 return 0;
2817 }
2818 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2819 {
2820 *first_unparsed = expression_cstr;
2821 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2822 *final_result = ValueObject::eInvalid;
2823 return 0;
2824 }
2825 }
2826 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2827 {
2828 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2829 {
2830 *first_unparsed = expression_cstr;
2831 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2832 *final_result = ValueObject::eInvalid;
2833 return 0;
2834 }
2835 else // expand this into list
2836 {
2837 int max_index = root->GetNumChildren() - 1;
2838 for (int index = 0; index < max_index; index++)
2839 {
2840 ValueObjectSP child =
2841 root->GetChildAtIndex(index, true);
2842 list->Append(child);
2843 }
2844 *first_unparsed = expression_cstr+2;
2845 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2846 *final_result = ValueObject::eValueObjectList;
2847 return max_index; // tell me number of items I added to the VOList
2848 }
2849 }
2850 const char *separator_position = ::strchr(expression_cstr+1,'-');
2851 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2852 if (!close_bracket_position) // if there is no ], this is a syntax error
2853 {
2854 *first_unparsed = expression_cstr;
2855 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2856 *final_result = ValueObject::eInvalid;
2857 return 0;
2858 }
2859 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2860 {
2861 char *end = NULL;
2862 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2863 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2864 {
2865 *first_unparsed = expression_cstr;
2866 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2867 *final_result = ValueObject::eInvalid;
2868 return 0;
2869 }
2870 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2871 {
2872 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2873 {
2874 int max_index = root->GetNumChildren() - 1;
2875 for (int index = 0; index < max_index; index++)
2876 {
2877 ValueObjectSP child =
2878 root->GetChildAtIndex(index, true);
2879 list->Append(child);
2880 }
2881 *first_unparsed = expression_cstr+2;
2882 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2883 *final_result = ValueObject::eValueObjectList;
2884 return max_index; // tell me number of items I added to the VOList
2885 }
2886 else
2887 {
2888 *first_unparsed = expression_cstr;
2889 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2890 *final_result = ValueObject::eInvalid;
2891 return 0;
2892 }
2893 }
2894 // from here on we do have a valid index
2895 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2896 {
2897 root = root->GetChildAtIndex(index, true);
2898 if (!root.get())
2899 {
2900 *first_unparsed = expression_cstr;
2901 *reason_to_stop = ValueObject::eNoSuchChild;
2902 *final_result = ValueObject::eInvalid;
2903 return 0;
2904 }
2905 else
2906 {
2907 list->Append(root);
2908 *first_unparsed = end+1; // skip ]
2909 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2910 *final_result = ValueObject::eValueObjectList;
2911 return 1;
2912 }
2913 }
2914 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2915 {
2916 if (*what_next == ValueObject::eDereference && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
2917 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2918 {
2919 Error error;
2920 root = root->Dereference(error);
2921 if (error.Fail() || !root.get())
2922 {
2923 *first_unparsed = expression_cstr;
2924 *reason_to_stop = ValueObject::eDereferencingFailed;
2925 *final_result = ValueObject::eInvalid;
2926 return 0;
2927 }
2928 else
2929 {
2930 *what_next = eNothing;
2931 continue;
2932 }
2933 }
2934 else
2935 {
2936 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2937 if (!root.get())
2938 {
2939 *first_unparsed = expression_cstr;
2940 *reason_to_stop = ValueObject::eNoSuchChild;
2941 *final_result = ValueObject::eInvalid;
2942 return 0;
2943 }
2944 else
2945 {
2946 list->Append(root);
2947 *first_unparsed = end+1; // skip ]
2948 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2949 *final_result = ValueObject::eValueObjectList;
2950 return 1;
2951 }
2952 }
2953 }
2954 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2955 {
2956 root = root->GetSyntheticBitFieldChild(index, index, true);
2957 if (!root.get())
2958 {
2959 *first_unparsed = expression_cstr;
2960 *reason_to_stop = ValueObject::eNoSuchChild;
2961 *final_result = ValueObject::eInvalid;
2962 return 0;
2963 }
2964 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2965 {
2966 list->Append(root);
2967 *first_unparsed = end+1; // skip ]
2968 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2969 *final_result = ValueObject::eValueObjectList;
2970 return 1;
2971 }
2972 }
2973 }
2974 else // we have a low and a high index
2975 {
2976 char *end = NULL;
2977 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2978 if (!end || end != separator_position) // if something weird is in our way return an error
2979 {
2980 *first_unparsed = expression_cstr;
2981 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2982 *final_result = ValueObject::eInvalid;
2983 return 0;
2984 }
2985 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2986 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2987 {
2988 *first_unparsed = expression_cstr;
2989 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2990 *final_result = ValueObject::eInvalid;
2991 return 0;
2992 }
2993 if (index_lower > index_higher) // swap indices if required
2994 {
2995 unsigned long temp = index_lower;
2996 index_lower = index_higher;
2997 index_higher = temp;
2998 }
2999 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3000 {
3001 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3002 if (!root.get())
3003 {
3004 *first_unparsed = expression_cstr;
3005 *reason_to_stop = ValueObject::eNoSuchChild;
3006 *final_result = ValueObject::eInvalid;
3007 return 0;
3008 }
3009 else
3010 {
3011 list->Append(root);
3012 *first_unparsed = end+1; // skip ]
3013 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
3014 *final_result = ValueObject::eValueObjectList;
3015 return 1;
3016 }
3017 }
3018 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
3019 *what_next == ValueObject::eDereference &&
3020 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3021 {
3022 Error error;
3023 root = root->Dereference(error);
3024 if (error.Fail() || !root.get())
3025 {
3026 *first_unparsed = expression_cstr;
3027 *reason_to_stop = ValueObject::eDereferencingFailed;
3028 *final_result = ValueObject::eInvalid;
3029 return 0;
3030 }
3031 else
3032 {
3033 *what_next = ValueObject::eNothing;
3034 continue;
3035 }
3036 }
3037 else
3038 {
Johnny Chen44805302011-07-19 19:48:13 +00003039 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003040 index <= index_higher; index++)
3041 {
3042 ValueObjectSP child =
3043 root->GetChildAtIndex(index, true);
3044 list->Append(child);
3045 }
3046 *first_unparsed = end+1;
3047 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
3048 *final_result = ValueObject::eValueObjectList;
3049 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3050 }
3051 }
3052 break;
3053 }
3054 default: // some non-[ separator, or something entirely wrong, is in the way
3055 {
3056 *first_unparsed = expression_cstr;
3057 *reason_to_stop = ValueObject::eUnexpectedSymbol;
3058 *final_result = ValueObject::eInvalid;
3059 return 0;
3060 break;
3061 }
3062 }
3063 }
3064}
3065
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003066void
Greg Clayton1d3afba2010-10-05 00:00:42 +00003067ValueObject::DumpValueObject
3068(
3069 Stream &s,
Greg Clayton1d3afba2010-10-05 00:00:42 +00003070 ValueObject *valobj,
3071 const char *root_valobj_name,
3072 uint32_t ptr_depth,
3073 uint32_t curr_depth,
3074 uint32_t max_depth,
3075 bool show_types,
3076 bool show_location,
3077 bool use_objc,
Greg Claytonafacd142011-09-02 01:15:17 +00003078 DynamicValueType use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00003079 bool use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003080 bool scope_already_checked,
Enrico Granata0c5ef692011-07-16 01:22:04 +00003081 bool flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00003082 uint32_t omit_summary_depth,
Greg Clayton6efba4f2012-01-26 21:08:30 +00003083 bool ignore_cap,
3084 Format format_override // Normally the format is in the valobj, but we might want to override this
Greg Clayton1d3afba2010-10-05 00:00:42 +00003085)
3086{
Greg Clayton007d5be2011-05-30 00:49:24 +00003087 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003088 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00003089 bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003090
Greg Claytonafacd142011-09-02 01:15:17 +00003091 if (update_success && use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003092 {
Jim Ingham2837b762011-05-04 03:43:18 +00003093 ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003094 if (dynamic_value)
3095 valobj = dynamic_value;
3096 }
3097
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003098 clang_type_t clang_type = valobj->GetClangType();
3099
Greg Clayton73b472d2010-10-27 03:32:59 +00003100 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003101 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003102 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3103 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003104
3105 const bool print_valobj = flat_output == false || has_value;
3106
3107 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003108 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003109 if (show_location)
3110 {
Jim Ingham6035b672011-03-31 00:19:25 +00003111 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003112 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003113
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003114 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003115
Greg Clayton7c8a9662010-11-02 01:50:16 +00003116 // Always show the type for the top level items.
Greg Claytone221f822011-01-21 01:59:00 +00003117 if (show_types || (curr_depth == 0 && !flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003118 {
Enrico Granata9910bc82011-08-03 02:18:51 +00003119 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
3120 s.Printf("(%s", typeName);
3121 // only show dynamic types if the user really wants to see types
Greg Claytonafacd142011-09-02 01:15:17 +00003122 if (show_types && use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003123 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003124 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003125 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003126 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3127 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003128 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003129 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003130 else
3131 {
3132 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3133 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003134 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003135 else
3136 {
3137 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3138 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003139 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003140 else
3141 s.Printf(", dynamic type: %s) ",
3142 runtime->GetActualTypeName(isa).GetCString());
3143 }
3144 }
3145 }
3146 else
3147 s.Printf(") ");
3148 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003149
Greg Clayton1d3afba2010-10-05 00:00:42 +00003150
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003151 if (flat_output)
3152 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003153 // If we are showing types, also qualify the C++ base classes
3154 const bool qualify_cxx_base_classes = show_types;
3155 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003156 s.PutCString(" =");
3157 }
3158 else
3159 {
3160 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3161 s.Printf ("%s =", name_cstr);
3162 }
3163
Jim Ingham6035b672011-03-31 00:19:25 +00003164 if (!scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003165 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003166 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003167 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003168 }
3169
Greg Clayton6efba4f2012-01-26 21:08:30 +00003170 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003171 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003172 const char *sum_cstr = NULL;
Enrico Granata061858c2012-02-15 02:34:21 +00003173 TypeSummaryImpl* entry = valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003174
Enrico Granata0c5ef692011-07-16 01:22:04 +00003175 if (omit_summary_depth > 0)
3176 entry = NULL;
3177
Greg Clayton6efba4f2012-01-26 21:08:30 +00003178 Format orig_format = kNumFormats;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003179 if (err_cstr == NULL)
3180 {
Greg Clayton6efba4f2012-01-26 21:08:30 +00003181 if (format_override != eFormatDefault)
3182 {
3183 orig_format = valobj->GetFormat();
3184 valobj->SetFormat (format_override);
3185 }
Jim Ingham6035b672011-03-31 00:19:25 +00003186 val_cstr = valobj->GetValueAsCString();
Greg Clayton6efba4f2012-01-26 21:08:30 +00003187 if (val_cstr)
3188 {
3189 // Cache the value in our own storage as running summaries might
3190 // change our value from underneath us
3191 value_str = val_cstr;
3192 }
3193 if (orig_format != kNumFormats && orig_format != format_override)
3194 {
3195 valobj->SetFormat (orig_format);
3196 orig_format = kNumFormats;
3197 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003198 err_cstr = valobj->GetError().AsCString();
3199 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003200
3201 if (err_cstr)
3202 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003203 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003204 }
3205 else
3206 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003207 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003208 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003209 {
Greg Clayton6efba4f2012-01-26 21:08:30 +00003210 if (omit_summary_depth == 0)
3211 sum_cstr = valobj->GetSummaryAsCString();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003212
Greg Clayton6efba4f2012-01-26 21:08:30 +00003213 // Make sure we have a value and make sure the summary didn't
3214 // specify that the value should not be printed
3215 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3216 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003217
Enrico Granata9dd75c82011-07-15 23:30:15 +00003218 if (sum_cstr)
Enrico Granata0a3958e2011-07-02 00:25:22 +00003219 {
3220 // for some reason, using %@ (ObjC description) in a summary string, makes
3221 // us believe we need to reset ourselves, thus invalidating the content of
3222 // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty
3223 // let us recalculate it!
3224 if (sum_cstr[0] == '\0')
3225 s.Printf(" %s", valobj->GetSummaryAsCString());
3226 else
3227 s.Printf(" %s", sum_cstr);
3228 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003229
3230 if (use_objc)
3231 {
Jim Ingham6035b672011-03-31 00:19:25 +00003232 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003233 if (object_desc)
3234 s.Printf(" %s\n", object_desc);
3235 else
Sean Callanan672ad942010-10-23 00:18:49 +00003236 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003237 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003238 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003239 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003240
3241 if (curr_depth < max_depth)
3242 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003243 // We will show children for all concrete types. We won't show
3244 // pointer contents unless a pointer depth has been specified.
3245 // We won't reference contents unless the reference is the
3246 // root object (depth of zero).
3247 bool print_children = true;
3248
3249 // Use a new temporary pointer depth in case we override the
3250 // current pointer depth below...
3251 uint32_t curr_ptr_depth = ptr_depth;
3252
3253 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3254 if (is_ptr || is_ref)
3255 {
3256 // We have a pointer or reference whose value is an address.
3257 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003258 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003259 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003260 print_children = false;
3261
3262 else if (is_ref && curr_depth == 0)
3263 {
3264 // If this is the root object (depth is zero) that we are showing
3265 // and it is a reference, and no pointer depth has been supplied
3266 // print out what it references. Don't do this at deeper depths
3267 // otherwise we can end up with infinite recursion...
3268 curr_ptr_depth = 1;
3269 }
3270
3271 if (curr_ptr_depth == 0)
3272 print_children = false;
3273 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003274
Enrico Granata0a3958e2011-07-02 00:25:22 +00003275 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003276 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003277 ValueObjectSP synth_valobj = valobj->GetSyntheticValue (use_synth ?
3278 eUseSyntheticFilter :
3279 eNoSyntheticFilter);
Enrico Granatac482a192011-08-17 22:13:59 +00003280 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003281 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003282 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003283 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003284 if (flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003285 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003286 if (print_valobj)
3287 s.EOL();
3288 }
3289 else
3290 {
3291 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003292 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003293 s.IndentMore();
3294 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003295
Greg Claytoncc4d0142012-02-17 07:49:44 +00003296 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003297
3298 if (num_children > max_num_children && !ignore_cap)
3299 {
3300 num_children = max_num_children;
3301 print_dotdotdot = true;
3302 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003303
3304 for (uint32_t idx=0; idx<num_children; ++idx)
3305 {
Enrico Granatac482a192011-08-17 22:13:59 +00003306 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003307 if (child_sp.get())
3308 {
3309 DumpValueObject (s,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003310 child_sp.get(),
3311 NULL,
Greg Clayton73b472d2010-10-27 03:32:59 +00003312 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003313 curr_depth + 1,
3314 max_depth,
3315 show_types,
3316 show_location,
3317 false,
Jim Ingham78a685a2011-04-16 00:01:13 +00003318 use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00003319 use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003320 true,
Enrico Granata0c5ef692011-07-16 01:22:04 +00003321 flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00003322 omit_summary_depth > 1 ? omit_summary_depth - 1 : 0,
Greg Clayton6efba4f2012-01-26 21:08:30 +00003323 ignore_cap,
3324 format_override);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003325 }
3326 }
3327
3328 if (!flat_output)
3329 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003330 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003331 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003332 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3333 Target *target = exe_ctx.GetTargetPtr();
3334 if (target)
3335 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003336 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003337 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003338 s.IndentLess();
3339 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003340 }
3341 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003342 else if (has_children)
3343 {
3344 // Aggregate, no children...
3345 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003346 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003347 }
3348 else
3349 {
3350 if (print_valobj)
3351 s.EOL();
3352 }
3353
Greg Clayton1d3afba2010-10-05 00:00:42 +00003354 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003355 else
3356 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003357 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003358 }
3359 }
3360 else
3361 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003362 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003363 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003364 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003365 }
3366 }
3367 }
3368 }
3369}
3370
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003371
3372ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003373ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003374{
3375 ValueObjectSP valobj_sp;
3376
Enrico Granatac3e320a2011-08-02 17:27:39 +00003377 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003378 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003379 ExecutionContext exe_ctx (GetExecutionContextRef());
3380 clang::ASTContext *ast = GetClangAST ();
3381
3382 DataExtractor data;
3383 data.SetByteOrder (m_data.GetByteOrder());
3384 data.SetAddressByteSize(m_data.GetAddressByteSize());
3385
Greg Claytone72dfb32012-02-24 01:59:29 +00003386 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003387
3388 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3389 ast,
3390 GetClangType(),
3391 name,
3392 data,
3393 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003394 }
Jim Ingham6035b672011-03-31 00:19:25 +00003395
3396 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003397 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003398 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003399 }
3400 return valobj_sp;
3401}
3402
Greg Claytonafacd142011-09-02 01:15:17 +00003403ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003404ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003405{
Jim Ingham58b59f92011-04-22 23:53:53 +00003406 if (m_deref_valobj)
3407 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003408
Greg Clayton54979cd2010-12-15 05:08:08 +00003409 const bool is_pointer_type = IsPointerType();
3410 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003411 {
3412 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003413 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003414
3415 std::string child_name_str;
3416 uint32_t child_byte_size = 0;
3417 int32_t child_byte_offset = 0;
3418 uint32_t child_bitfield_bit_size = 0;
3419 uint32_t child_bitfield_bit_offset = 0;
3420 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003421 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003422 const bool transparent_pointers = false;
3423 clang::ASTContext *clang_ast = GetClangAST();
3424 clang_type_t clang_type = GetClangType();
3425 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003426
Greg Claytoncc4d0142012-02-17 07:49:44 +00003427 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003428
3429 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3430 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003431 GetName().GetCString(),
3432 clang_type,
3433 0,
3434 transparent_pointers,
3435 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003436 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003437 child_name_str,
3438 child_byte_size,
3439 child_byte_offset,
3440 child_bitfield_bit_size,
3441 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003442 child_is_base_class,
3443 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003444 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003445 {
3446 ConstString child_name;
3447 if (!child_name_str.empty())
3448 child_name.SetCString (child_name_str.c_str());
3449
Jim Ingham58b59f92011-04-22 23:53:53 +00003450 m_deref_valobj = new ValueObjectChild (*this,
3451 clang_ast,
3452 child_clang_type,
3453 child_name,
3454 child_byte_size,
3455 child_byte_offset,
3456 child_bitfield_bit_size,
3457 child_bitfield_bit_offset,
3458 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003459 child_is_deref_of_parent,
3460 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003461 }
3462 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003463
Jim Ingham58b59f92011-04-22 23:53:53 +00003464 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003465 {
3466 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003467 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003468 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003469 else
3470 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003471 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003472 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003473
3474 if (is_pointer_type)
3475 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3476 else
3477 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003478 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003479 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003480}
3481
Greg Claytonafacd142011-09-02 01:15:17 +00003482ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003483ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003484{
Jim Ingham78a685a2011-04-16 00:01:13 +00003485 if (m_addr_of_valobj_sp)
3486 return m_addr_of_valobj_sp;
3487
Greg Claytone0d378b2011-03-24 21:19:54 +00003488 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003489 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003490 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003491 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003492 if (addr != LLDB_INVALID_ADDRESS)
3493 {
3494 switch (address_type)
3495 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003496 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003497 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003498 {
3499 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003500 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003501 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3502 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003503 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003504
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003505 case eAddressTypeFile:
3506 case eAddressTypeLoad:
3507 case eAddressTypeHost:
3508 {
3509 clang::ASTContext *ast = GetClangAST();
3510 clang_type_t clang_type = GetClangType();
3511 if (ast && clang_type)
3512 {
3513 std::string name (1, '&');
3514 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003515 ExecutionContext exe_ctx (GetExecutionContextRef());
3516 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003517 ast,
3518 ClangASTContext::CreatePointerType (ast, clang_type),
3519 ConstString (name.c_str()),
3520 addr,
3521 eAddressTypeInvalid,
3522 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003523 }
3524 }
3525 break;
3526 }
3527 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003528 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003529}
3530
Greg Clayton9a142cf2012-02-03 05:34:10 +00003531ValueObjectSP
3532ValueObject::Cast (const ClangASTType &clang_ast_type)
3533{
Greg Clayton81e871e2012-02-04 02:27:34 +00003534 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003535}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003536
Greg Claytonafacd142011-09-02 01:15:17 +00003537ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003538ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3539{
Greg Claytonafacd142011-09-02 01:15:17 +00003540 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003541 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003542 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003543
3544 if (ptr_value != LLDB_INVALID_ADDRESS)
3545 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003546 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003547 ExecutionContext exe_ctx (GetExecutionContextRef());
3548 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003549 name,
3550 ptr_addr,
3551 clang_ast_type);
3552 }
3553 return valobj_sp;
3554}
3555
Greg Claytonafacd142011-09-02 01:15:17 +00003556ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003557ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3558{
Greg Claytonafacd142011-09-02 01:15:17 +00003559 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003560 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003561 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003562
3563 if (ptr_value != LLDB_INVALID_ADDRESS)
3564 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003565 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003566 ExecutionContext exe_ctx (GetExecutionContextRef());
3567 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003568 name,
3569 ptr_addr,
3570 type_sp);
3571 }
3572 return valobj_sp;
3573}
3574
Jim Ingham6035b672011-03-31 00:19:25 +00003575ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003576 m_mod_id(),
3577 m_exe_ctx_ref(),
3578 m_needs_update (true),
3579 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003580{
3581}
3582
3583ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003584 m_mod_id(),
3585 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003586 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003587 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003588{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003589 ExecutionContext exe_ctx(exe_scope);
3590 TargetSP target_sp (exe_ctx.GetTargetSP());
3591 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003592 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003593 m_exe_ctx_ref.SetTargetSP (target_sp);
3594 ProcessSP process_sp (exe_ctx.GetProcessSP());
3595 if (!process_sp)
3596 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003597
Greg Claytoncc4d0142012-02-17 07:49:44 +00003598 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003599 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003600 m_mod_id = process_sp->GetModID();
3601 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003602
Greg Claytoncc4d0142012-02-17 07:49:44 +00003603 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003604
Greg Claytoncc4d0142012-02-17 07:49:44 +00003605 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003606 {
3607 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003608 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003609 }
Jim Ingham6035b672011-03-31 00:19:25 +00003610
Greg Claytoncc4d0142012-02-17 07:49:44 +00003611 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003612 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003613 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003614
Greg Claytoncc4d0142012-02-17 07:49:44 +00003615 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3616 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003617 {
3618 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003619 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003620 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003621 if (frame_sp)
3622 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003623 }
3624 }
3625 }
Jim Ingham6035b672011-03-31 00:19:25 +00003626}
3627
3628ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003629 m_mod_id(),
3630 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3631 m_needs_update (true),
3632 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003633{
3634}
3635
3636ValueObject::EvaluationPoint::~EvaluationPoint ()
3637{
3638}
3639
Jim Ingham6035b672011-03-31 00:19:25 +00003640// This function checks the EvaluationPoint against the current process state. If the current
3641// state matches the evaluation point, or the evaluation point is already invalid, then we return
3642// false, meaning "no change". If the current state is different, we update our state, and return
3643// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3644// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003645// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003646
3647bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003648ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003649{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003650
3651 // 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 +00003652 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003653
Greg Claytoncc4d0142012-02-17 07:49:44 +00003654 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003655 return false;
3656
Jim Ingham6035b672011-03-31 00:19:25 +00003657 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003658 Process *process = exe_ctx.GetProcessPtr();
3659 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003660 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003661
Jim Ingham6035b672011-03-31 00:19:25 +00003662 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003663 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003664
Jim Ingham78a685a2011-04-16 00:01:13 +00003665 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3666 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003667 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003668 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003669
3670 bool changed;
3671
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003672 if (m_mod_id.IsValid())
3673 {
3674 if (m_mod_id == current_mod_id)
3675 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003676 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003677 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003678 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003679 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003680 else
3681 {
3682 m_mod_id = current_mod_id;
3683 m_needs_update = true;
3684 changed = true;
3685 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003686 }
Jim Ingham6035b672011-03-31 00:19:25 +00003687
Jim Ingham73ca05a2011-12-17 01:35:57 +00003688 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3689 // That way we'll be sure to return a valid exe_scope.
3690 // 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 +00003691
Greg Claytoncc4d0142012-02-17 07:49:44 +00003692 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003693 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003694 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3695 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003696 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003697 if (m_exe_ctx_ref.HasFrameRef())
3698 {
3699 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3700 if (!frame_sp)
3701 {
3702 // We used to have a frame, but now it is gone
3703 SetInvalid();
3704 }
3705 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003706 }
Jim Ingham6035b672011-03-31 00:19:25 +00003707 else
3708 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003709 // We used to have a thread, but now it is gone
3710 SetInvalid();
Jim Ingham6035b672011-03-31 00:19:25 +00003711 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003712
Jim Ingham6035b672011-03-31 00:19:25 +00003713 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003714 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003715}
3716
Jim Ingham61be0902011-05-02 18:13:59 +00003717void
3718ValueObject::EvaluationPoint::SetUpdated ()
3719{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003720 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3721 if (process_sp)
3722 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003723 m_first_update = false;
3724 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003725}
3726
3727
Greg Claytoncc4d0142012-02-17 07:49:44 +00003728//bool
3729//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3730//{
3731// if (!IsValid())
3732// return false;
3733//
3734// bool needs_update = false;
3735//
3736// // The target has to be non-null, and the
3737// Target *target = exe_scope->CalculateTarget();
3738// if (target != NULL)
3739// {
3740// Target *old_target = m_target_sp.get();
3741// assert (target == old_target);
3742// Process *process = exe_scope->CalculateProcess();
3743// if (process != NULL)
3744// {
3745// // FOR NOW - assume you can't update variable objects across process boundaries.
3746// Process *old_process = m_process_sp.get();
3747// assert (process == old_process);
3748// ProcessModID current_mod_id = process->GetModID();
3749// if (m_mod_id != current_mod_id)
3750// {
3751// needs_update = true;
3752// m_mod_id = current_mod_id;
3753// }
3754// // See if we're switching the thread or stack context. If no thread is given, this is
3755// // being evaluated in a global context.
3756// Thread *thread = exe_scope->CalculateThread();
3757// if (thread != NULL)
3758// {
3759// user_id_t new_thread_index = thread->GetIndexID();
3760// if (new_thread_index != m_thread_id)
3761// {
3762// needs_update = true;
3763// m_thread_id = new_thread_index;
3764// m_stack_id.Clear();
3765// }
3766//
3767// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3768// if (new_frame != NULL)
3769// {
3770// if (new_frame->GetStackID() != m_stack_id)
3771// {
3772// needs_update = true;
3773// m_stack_id = new_frame->GetStackID();
3774// }
3775// }
3776// else
3777// {
3778// m_stack_id.Clear();
3779// needs_update = true;
3780// }
3781// }
3782// else
3783// {
3784// // If this had been given a thread, and now there is none, we should update.
3785// // Otherwise we don't have to do anything.
3786// if (m_thread_id != LLDB_INVALID_UID)
3787// {
3788// m_thread_id = LLDB_INVALID_UID;
3789// m_stack_id.Clear();
3790// needs_update = true;
3791// }
3792// }
3793// }
3794// else
3795// {
3796// // If there is no process, then we don't need to update anything.
3797// // But if we're switching from having a process to not, we should try to update.
3798// if (m_process_sp.get() != NULL)
3799// {
3800// needs_update = true;
3801// m_process_sp.reset();
3802// m_thread_id = LLDB_INVALID_UID;
3803// m_stack_id.Clear();
3804// }
3805// }
3806// }
3807// else
3808// {
3809// // If there's no target, nothing can change so we don't need to update anything.
3810// // But if we're switching from having a target to not, we should try to update.
3811// if (m_target_sp.get() != NULL)
3812// {
3813// needs_update = true;
3814// m_target_sp.reset();
3815// m_process_sp.reset();
3816// m_thread_id = LLDB_INVALID_UID;
3817// m_stack_id.Clear();
3818// }
3819// }
3820// if (!m_needs_update)
3821// m_needs_update = needs_update;
3822//
3823// return needs_update;
3824//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003825
3826void
3827ValueObject::ClearUserVisibleData()
3828{
3829 m_location_str.clear();
3830 m_value_str.clear();
3831 m_summary_str.clear();
3832 m_object_desc_str.clear();
Greg Clayton48ca8b82012-01-07 20:58:07 +00003833 m_is_getting_summary = false;
Johnny Chen44805302011-07-19 19:48:13 +00003834}
Enrico Granata9128ee22011-09-06 19:20:51 +00003835
3836SymbolContextScope *
3837ValueObject::GetSymbolContextScope()
3838{
3839 if (m_parent)
3840 {
3841 if (!m_parent->IsPointerOrReferenceType())
3842 return m_parent->GetSymbolContextScope();
3843 }
3844 return NULL;
3845}