blob: aac8e8e99f3a57ca42cc914c75d494eeeb083f49 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/ValueObject.h"
11
12// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000013#include <stdlib.h>
14
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015// C++ Includes
16// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000018#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
20// Project includes
21#include "lldb/Core/DataBufferHeap.h"
Enrico Granata0a976142011-08-22 22:03:47 +000022#include "lldb/Core/DataVisualization.h"
Enrico Granata4becb372011-06-29 22:27:15 +000023#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000024#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/StreamString.h"
26#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000027#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000028#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000030#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000031#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Greg Clayton7fb56d02011-02-01 01:31:41 +000033#include "lldb/Host/Endian.h"
34
Enrico Granata61a80ba2011-08-12 16:42:31 +000035#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000036#include "lldb/Interpreter/ScriptInterpreterPython.h"
37
Greg Claytone1a916a2010-07-21 22:12:05 +000038#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Symbol/ClangASTContext.h"
40#include "lldb/Symbol/Type.h"
41
Jim Ingham53c47f12010-09-10 23:12:17 +000042#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000043#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000044#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045#include "lldb/Target/Process.h"
46#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000047#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049
Enrico Granataf4efecd2011-07-12 22:56:10 +000050#include "lldb/Utility/RefCounter.h"
51
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052using namespace lldb;
53using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000054using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055
Greg Claytonafacd142011-09-02 01:15:17 +000056static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057
58//----------------------------------------------------------------------
59// ValueObject constructor
60//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000061ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000063 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000064 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065 m_name (),
66 m_data (),
67 m_value (),
68 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000069 m_value_str (),
70 m_old_value_str (),
71 m_location_str (),
72 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000073 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000074 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000075 m_children (),
76 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000077 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000078 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000079 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000080 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000081 m_last_format_mgr_revision(0),
Enrico Granatad8b5fce2011-08-02 23:12:24 +000082 m_last_format_mgr_dynamic(parent.m_last_format_mgr_dynamic),
Enrico Granata0c489f52012-03-01 04:24:26 +000083 m_type_summary_sp(),
84 m_type_format_sp(),
85 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000086 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000087 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000088 m_value_is_valid (false),
89 m_value_did_change (false),
90 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000091 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000092 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000093 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000094 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +000095 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000096 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +000097 m_is_getting_summary(false),
98 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +000099{
Jim Ingham58b59f92011-04-22 23:53:53 +0000100 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000101}
102
103//----------------------------------------------------------------------
104// ValueObject constructor
105//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000106ValueObject::ValueObject (ExecutionContextScope *exe_scope,
107 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000108 UserID (++g_value_obj_uid), // Unique identifier for every value object
109 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000110 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000111 m_name (),
112 m_data (),
113 m_value (),
114 m_error (),
115 m_value_str (),
116 m_old_value_str (),
117 m_location_str (),
118 m_summary_str (),
119 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000120 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000121 m_children (),
122 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000123 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000124 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000125 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000126 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000127 m_last_format_mgr_revision(0),
Greg Claytonafacd142011-09-02 01:15:17 +0000128 m_last_format_mgr_dynamic(eNoDynamicValues),
Enrico Granata0c489f52012-03-01 04:24:26 +0000129 m_type_summary_sp(),
130 m_type_format_sp(),
131 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000132 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000133 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000134 m_value_is_valid (false),
135 m_value_did_change (false),
136 m_children_count_valid (false),
137 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000138 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000139 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000140 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000141 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000142 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000143 m_is_getting_summary(false),
144 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000145{
Jim Ingham58b59f92011-04-22 23:53:53 +0000146 m_manager = new ValueObjectManager();
147 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148}
149
150//----------------------------------------------------------------------
151// Destructor
152//----------------------------------------------------------------------
153ValueObject::~ValueObject ()
154{
155}
156
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000157bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000158ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000160 return UpdateValueIfNeeded(m_last_format_mgr_dynamic, update_format);
161}
162
163bool
Greg Claytonafacd142011-09-02 01:15:17 +0000164ValueObject::UpdateValueIfNeeded (DynamicValueType use_dynamic, bool update_format)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000165{
Enrico Granata4becb372011-06-29 22:27:15 +0000166
Enrico Granata9128ee22011-09-06 19:20:51 +0000167 bool did_change_formats = false;
168
Enrico Granata0a3958e2011-07-02 00:25:22 +0000169 if (update_format)
Enrico Granata9128ee22011-09-06 19:20:51 +0000170 did_change_formats = UpdateFormatsIfNeeded(use_dynamic);
Enrico Granata4becb372011-06-29 22:27:15 +0000171
Greg Claytonb71f3842010-10-05 03:13:51 +0000172 // If this is a constant value, then our success is predicated on whether
173 // we have an error or not
174 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000175 {
176 // if you were asked to update your formatters, but did not get a chance to do it
177 // clear your own values (this serves the purpose of faking a stop-id for frozen
178 // objects (which are regarded as constant, but could have changes behind their backs
179 // because of the frozen-pointer depth limit)
180 // TODO: decouple summary from value and then remove this code and only force-clear the summary
181 if (update_format && !did_change_formats)
182 m_summary_str.clear();
Greg Claytonb71f3842010-10-05 03:13:51 +0000183 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000184 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000185
Jim Ingham6035b672011-03-31 00:19:25 +0000186 bool first_update = m_update_point.IsFirstEvaluation();
187
188 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189 {
Jim Ingham6035b672011-03-31 00:19:25 +0000190 m_update_point.SetUpdated();
191
192 // Save the old value using swap to avoid a string copy which
193 // also will clear our m_value_str
194 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000195 {
Jim Ingham6035b672011-03-31 00:19:25 +0000196 m_old_value_valid = false;
197 }
198 else
199 {
200 m_old_value_valid = true;
201 m_old_value_str.swap (m_value_str);
202 m_value_str.clear();
203 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000204
Enrico Granataf2bbf712011-07-15 02:26:42 +0000205 ClearUserVisibleData();
206
Jim Ingham6035b672011-03-31 00:19:25 +0000207 const bool value_was_valid = GetValueIsValid();
208 SetValueDidChange (false);
Greg Clayton73b953b2010-08-28 00:08:07 +0000209
Jim Ingham6035b672011-03-31 00:19:25 +0000210 m_error.Clear();
Greg Clayton73b953b2010-08-28 00:08:07 +0000211
Jim Ingham6035b672011-03-31 00:19:25 +0000212 // Call the pure virtual function to update the value
213 bool success = UpdateValue ();
214
215 SetValueIsValid (success);
216
217 if (first_update)
218 SetValueDidChange (false);
219 else if (!m_value_did_change && success == false)
220 {
221 // The value wasn't gotten successfully, so we mark this
222 // as changed if the value used to be valid and now isn't
223 SetValueDidChange (value_was_valid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224 }
225 }
226 return m_error.Success();
227}
228
Enrico Granata9128ee22011-09-06 19:20:51 +0000229bool
Greg Claytonafacd142011-09-02 01:15:17 +0000230ValueObject::UpdateFormatsIfNeeded(DynamicValueType use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000231{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000232 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
233 if (log)
234 log->Printf("checking for FormatManager revisions. VO named %s is at revision %d, while the format manager is at revision %d",
235 GetName().GetCString(),
Enrico Granata4becb372011-06-29 22:27:15 +0000236 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000237 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000238
239 bool any_change = false;
240
Enrico Granata85933ed2011-08-18 16:38:26 +0000241 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) ||
Enrico Granatac3e320a2011-08-02 17:27:39 +0000242 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000243 {
Enrico Granata78d06382011-09-09 23:33:14 +0000244 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
245 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, use_dynamic));
246 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, use_dynamic));
Enrico Granata1490c6f2011-07-19 02:34:21 +0000247
Enrico Granata85933ed2011-08-18 16:38:26 +0000248 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000249 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granata855cd902011-09-06 22:59:55 +0000250
251 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000252 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000253
254 return any_change;
255
Enrico Granata4becb372011-06-29 22:27:15 +0000256}
257
Jim Ingham16e0c682011-08-12 23:34:31 +0000258void
259ValueObject::SetNeedsUpdate ()
260{
261 m_update_point.SetNeedsUpdate();
262 // We have to clear the value string here so ConstResult children will notice if their values are
263 // changed by hand (i.e. with SetValueAsCString).
264 m_value_str.clear();
265}
266
Sean Callanan72772842012-02-22 23:57:45 +0000267ClangASTType
268ValueObject::MaybeCalculateCompleteType ()
269{
270 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
271
272 if (m_did_calculate_complete_objc_class_type)
273 {
274 if (m_override_type.IsValid())
275 return m_override_type;
276 else
277 return ret;
278 }
279
280 clang_type_t ast_type(GetClangTypeImpl());
281 clang_type_t class_type;
282 bool is_pointer_type;
283
284 if (ClangASTContext::IsObjCObjectPointerType(ast_type, &class_type))
285 {
286 is_pointer_type = true;
287 }
288 else if (ClangASTContext::IsObjCClassType(ast_type))
289 {
290 is_pointer_type = false;
291 class_type = ast_type;
292 }
293 else
294 {
295 return ret;
296 }
297
298 m_did_calculate_complete_objc_class_type = true;
299
300 if (!class_type)
301 return ret;
302
303 std::string class_name;
304
305 if (!ClangASTContext::GetObjCClassName(class_type, class_name))
306 return ret;
307
308 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
309
310 if (!process_sp)
311 return ret;
312
313 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
314
315 if (!objc_language_runtime)
316 return ret;
317
318 ConstString class_name_cs(class_name.c_str());
319
320 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name_cs);
321
322 if (!complete_objc_class_type_sp)
323 return ret;
324
325 ClangASTType complete_class(complete_objc_class_type_sp->GetClangAST(),
326 complete_objc_class_type_sp->GetClangFullType());
327
328 if (!ClangASTContext::GetCompleteType(complete_class.GetASTContext(),
329 complete_class.GetOpaqueQualType()))
330 return ret;
331
332 if (is_pointer_type)
333 {
334 clang_type_t pointer_type = ClangASTContext::CreatePointerType(complete_class.GetASTContext(),
335 complete_class.GetOpaqueQualType());
336
337 m_override_type = ClangASTType(complete_class.GetASTContext(),
338 pointer_type);
339 }
340 else
341 {
342 m_override_type = complete_class;
343 }
344
345 return m_override_type;
346}
347
348clang::ASTContext *
349ValueObject::GetClangAST ()
350{
351 ClangASTType type = MaybeCalculateCompleteType();
352
353 return type.GetASTContext();
354}
355
356lldb::clang_type_t
357ValueObject::GetClangType ()
358{
359 ClangASTType type = MaybeCalculateCompleteType();
360
361 return type.GetOpaqueQualType();
362}
363
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000364DataExtractor &
365ValueObject::GetDataExtractor ()
366{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000367 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368 return m_data;
369}
370
371const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000372ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000374 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375 return m_error;
376}
377
378const ConstString &
379ValueObject::GetName() const
380{
381 return m_name;
382}
383
384const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000385ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000386{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000387 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000388 {
389 if (m_location_str.empty())
390 {
391 StreamString sstr;
392
393 switch (m_value.GetValueType())
394 {
395 default:
396 break;
397
398 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000399 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400 {
401 RegisterInfo *reg_info = m_value.GetRegisterInfo();
402 if (reg_info)
403 {
404 if (reg_info->name)
405 m_location_str = reg_info->name;
406 else if (reg_info->alt_name)
407 m_location_str = reg_info->alt_name;
408 break;
409 }
410 }
411 m_location_str = "scalar";
412 break;
413
414 case Value::eValueTypeLoadAddress:
415 case Value::eValueTypeFileAddress:
416 case Value::eValueTypeHostAddress:
417 {
418 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
419 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
420 m_location_str.swap(sstr.GetString());
421 }
422 break;
423 }
424 }
425 }
426 return m_location_str.c_str();
427}
428
429Value &
430ValueObject::GetValue()
431{
432 return m_value;
433}
434
435const Value &
436ValueObject::GetValue() const
437{
438 return m_value;
439}
440
441bool
Jim Ingham6035b672011-03-31 00:19:25 +0000442ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000443{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000444 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
445 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000446 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000447 Value tmp_value(m_value);
448 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000449 if (scalar.IsValid())
450 {
451 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
452 if (bitfield_bit_size)
453 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
454 return true;
455 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000456 }
Greg Claytondcad5022011-12-29 01:26:56 +0000457 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000458}
459
460bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000461ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000462{
Greg Clayton288bdf92010-09-02 02:59:18 +0000463 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464}
465
466
467void
468ValueObject::SetValueIsValid (bool b)
469{
Greg Clayton288bdf92010-09-02 02:59:18 +0000470 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471}
472
473bool
Jim Ingham6035b672011-03-31 00:19:25 +0000474ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000475{
Jim Ingham6035b672011-03-31 00:19:25 +0000476 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000477 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000478}
479
480void
481ValueObject::SetValueDidChange (bool value_changed)
482{
Greg Clayton288bdf92010-09-02 02:59:18 +0000483 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484}
485
486ValueObjectSP
487ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
488{
489 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000490 // We may need to update our value if we are dynamic
491 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000492 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000493 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000494 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000495 // Check if we have already made the child value object?
496 if (can_create && m_children[idx] == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000497 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000498 // No we haven't created the child at this index, so lets have our
499 // subclass do it and cache the result for quick future access.
500 m_children[idx] = CreateChildAtIndex (idx, false, 0);
Jim Ingham78a685a2011-04-16 00:01:13 +0000501 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000502
503 if (m_children[idx] != NULL)
504 return m_children[idx]->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505 }
506 return child_sp;
507}
508
509uint32_t
510ValueObject::GetIndexOfChildWithName (const ConstString &name)
511{
512 bool omit_empty_base_classes = true;
513 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000514 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000515 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000516 omit_empty_base_classes);
517}
518
519ValueObjectSP
520ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
521{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000522 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523 // classes (which really aren't part of the expression path), so we
524 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000525 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000526
Greg Claytondea8cb42011-06-29 22:09:02 +0000527 // We may need to update our value if we are dynamic
528 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000529 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000530
531 std::vector<uint32_t> child_indexes;
532 clang::ASTContext *clang_ast = GetClangAST();
533 void *clang_type = GetClangType();
534 bool omit_empty_base_classes = true;
535 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
536 clang_type,
537 name.GetCString(),
538 omit_empty_base_classes,
539 child_indexes);
540 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000541 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000542 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
543 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
544
545 child_sp = GetChildAtIndex(*pos, can_create);
546 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000548 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000549 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000550 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
551 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000552 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000553 else
554 {
555 child_sp.reset();
556 }
557
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000558 }
559 }
560 return child_sp;
561}
562
563
564uint32_t
565ValueObject::GetNumChildren ()
566{
Greg Clayton288bdf92010-09-02 02:59:18 +0000567 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000568 {
569 SetNumChildren (CalculateNumChildren());
570 }
571 return m_children.size();
572}
573void
574ValueObject::SetNumChildren (uint32_t num_children)
575{
Greg Clayton288bdf92010-09-02 02:59:18 +0000576 m_children_count_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000577 m_children.resize(num_children);
578}
579
580void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000581ValueObject::SetName (const ConstString &name)
582{
583 m_name = name;
584}
585
Jim Ingham58b59f92011-04-22 23:53:53 +0000586ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000587ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
588{
Jim Ingham2eec4872011-05-07 00:10:58 +0000589 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000590
Greg Claytondea8cb42011-06-29 22:09:02 +0000591 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000592 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000593 std::string child_name_str;
594 uint32_t child_byte_size = 0;
595 int32_t child_byte_offset = 0;
596 uint32_t child_bitfield_bit_size = 0;
597 uint32_t child_bitfield_bit_offset = 0;
598 bool child_is_base_class = false;
599 bool child_is_deref_of_parent = false;
600
601 const bool transparent_pointers = synthetic_array_member == false;
602 clang::ASTContext *clang_ast = GetClangAST();
603 clang_type_t clang_type = GetClangType();
604 clang_type_t child_clang_type;
605
Greg Claytoncc4d0142012-02-17 07:49:44 +0000606 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000607
608 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
609 clang_ast,
610 GetName().GetCString(),
611 clang_type,
612 idx,
613 transparent_pointers,
614 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000615 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000616 child_name_str,
617 child_byte_size,
618 child_byte_offset,
619 child_bitfield_bit_size,
620 child_bitfield_bit_offset,
621 child_is_base_class,
622 child_is_deref_of_parent);
623 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000624 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000625 if (synthetic_index)
626 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000627
Greg Claytondea8cb42011-06-29 22:09:02 +0000628 ConstString child_name;
629 if (!child_name_str.empty())
630 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000631
Greg Claytondea8cb42011-06-29 22:09:02 +0000632 valobj = new ValueObjectChild (*this,
633 clang_ast,
634 child_clang_type,
635 child_name,
636 child_byte_size,
637 child_byte_offset,
638 child_bitfield_bit_size,
639 child_bitfield_bit_offset,
640 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000641 child_is_deref_of_parent,
642 eAddressTypeInvalid);
643 //if (valobj)
644 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
645 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000646
Jim Ingham58b59f92011-04-22 23:53:53 +0000647 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000648}
649
Enrico Granata0c489f52012-03-01 04:24:26 +0000650bool
651ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
652 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000653{
Enrico Granata0c489f52012-03-01 04:24:26 +0000654 destination.clear();
655
656 // ideally we would like to bail out if passing NULL, but if we do so
657 // we end up not providing the summary for function pointers anymore
658 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
659 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000660
661 m_is_getting_summary = true;
Enrico Granata0c489f52012-03-01 04:24:26 +0000662 if (UpdateValueIfNeeded (false))
663 {
664 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000665 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000666 summary_ptr->FormatObject(GetSP(), destination);
667 }
668 else
669 {
670 clang_type_t clang_type = GetClangType();
671
672 // Do some default printout for function pointers
673 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000674 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000675 StreamString sstr;
676 clang_type_t elem_or_pointee_clang_type;
677 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
678 GetClangAST(),
679 &elem_or_pointee_clang_type));
680
681 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000682 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000683 AddressType func_ptr_address_type = eAddressTypeInvalid;
684 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
685 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000686 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000687 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000688 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000689 case eAddressTypeInvalid:
690 case eAddressTypeFile:
691 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000692
Greg Claytoncc4d0142012-02-17 07:49:44 +0000693 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000694 {
695 ExecutionContext exe_ctx (GetExecutionContextRef());
696
697 Address so_addr;
698 Target *target = exe_ctx.GetTargetPtr();
699 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000700 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000701 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000702 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000703 so_addr.Dump (&sstr,
704 exe_ctx.GetBestExecutionContextScope(),
705 Address::DumpStyleResolvedDescription,
706 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000707 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000708 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000709 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000710 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000711
Greg Claytoncc4d0142012-02-17 07:49:44 +0000712 case eAddressTypeHost:
713 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000714 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000715 }
716 if (sstr.GetSize() > 0)
717 {
718 destination.assign (1, '(');
719 destination.append (sstr.GetData(), sstr.GetSize());
720 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000721 }
722 }
723 }
724 }
725 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000726 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000727 return !destination.empty();
728}
729
730const char *
731ValueObject::GetSummaryAsCString ()
732{
733 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
734 {
735 GetSummaryAsCString(GetSummaryFormat().get(),
736 m_summary_str);
737 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000738 if (m_summary_str.empty())
739 return NULL;
740 return m_summary_str.c_str();
741}
742
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000743bool
744ValueObject::IsCStringContainer(bool check_pointer)
745{
746 clang_type_t elem_or_pointee_clang_type;
747 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
748 GetClangAST(),
749 &elem_or_pointee_clang_type));
750 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
751 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
752 if (!is_char_arr_ptr)
753 return false;
754 if (!check_pointer)
755 return true;
756 if (type_flags.Test(ClangASTContext::eTypeIsArray))
757 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000758 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000759 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000760 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000761 return (cstr_address != LLDB_INVALID_ADDRESS);
762}
763
Enrico Granata9128ee22011-09-06 19:20:51 +0000764size_t
765ValueObject::GetPointeeData (DataExtractor& data,
766 uint32_t item_idx,
767 uint32_t item_count)
768{
769 if (!IsPointerType() && !IsArrayType())
770 return 0;
771
772 if (item_count == 0)
773 return 0;
774
775 uint32_t stride = 0;
776
777 ClangASTType type(GetClangAST(),
778 GetClangType());
779
780 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
781 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
782
783 const uint64_t bytes = item_count * item_type_size;
784
785 const uint64_t offset = item_idx * item_type_size;
786
787 if (item_idx == 0 && item_count == 1) // simply a deref
788 {
789 if (IsPointerType())
790 {
791 Error error;
792 ValueObjectSP pointee_sp = Dereference(error);
793 if (error.Fail() || pointee_sp.get() == NULL)
794 return 0;
795 return pointee_sp->GetDataExtractor().Copy(data);
796 }
797 else
798 {
799 ValueObjectSP child_sp = GetChildAtIndex(0, true);
800 if (child_sp.get() == NULL)
801 return 0;
802 return child_sp->GetDataExtractor().Copy(data);
803 }
804 return true;
805 }
806 else /* (items > 1) */
807 {
808 Error error;
809 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
810 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
811
812 AddressType addr_type;
813 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
814
Enrico Granata9128ee22011-09-06 19:20:51 +0000815 switch (addr_type)
816 {
817 case eAddressTypeFile:
818 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000819 ModuleSP module_sp (GetModule());
820 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000821 {
822 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000823 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000824 ExecutionContext exe_ctx (GetExecutionContextRef());
825 Target* target = exe_ctx.GetTargetPtr();
826 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000827 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000828 heap_buf_ptr->SetByteSize(bytes);
829 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
830 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000831 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000832 data.SetData(data_sp);
833 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000834 }
835 }
836 }
837 }
838 break;
839 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000840 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000841 ExecutionContext exe_ctx (GetExecutionContextRef());
842 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000843 if (process)
844 {
845 heap_buf_ptr->SetByteSize(bytes);
846 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
847 if (error.Success())
848 {
849 data.SetData(data_sp);
850 return bytes_read;
851 }
852 }
853 }
854 break;
855 case eAddressTypeHost:
856 {
857 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
858 data.SetData(data_sp);
859 return bytes;
860 }
861 break;
862 case eAddressTypeInvalid:
863 default:
864 break;
865 }
866 }
867 return 0;
868}
869
870size_t
871ValueObject::GetData (DataExtractor& data)
872{
873 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000874 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +0000875 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000876 if (error.Fail())
877 return 0;
878 data.SetAddressByteSize(m_data.GetAddressByteSize());
879 data.SetByteOrder(m_data.GetByteOrder());
880 return data.GetByteSize();
881}
882
883// will compute strlen(str), but without consuming more than
884// maxlen bytes out of str (this serves the purpose of reading
885// chunks of a string without having to worry about
886// missing NULL terminators in the chunk)
887// of course, if strlen(str) > maxlen, the function will return
888// maxlen_value (which should be != maxlen, because that allows you
889// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
890static uint32_t
891strlen_or_inf (const char* str,
892 uint32_t maxlen,
893 uint32_t maxlen_value)
894{
895 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000896 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000897 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000898 while(*str)
899 {
900 len++;str++;
901 if (len > maxlen)
902 return maxlen_value;
903 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000904 }
905 return len;
906}
907
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000908void
Greg Claytoncc4d0142012-02-17 07:49:44 +0000909ValueObject::ReadPointedString (Stream& s,
910 Error& error,
911 uint32_t max_length,
912 bool honor_array,
913 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000914{
Greg Claytoncc4d0142012-02-17 07:49:44 +0000915 ExecutionContext exe_ctx (GetExecutionContextRef());
916 Target* target = exe_ctx.GetTargetPtr();
917
918 if (target && max_length == 0)
919 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000920
921 clang_type_t clang_type = GetClangType();
922 clang_type_t elem_or_pointee_clang_type;
923 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
924 GetClangAST(),
925 &elem_or_pointee_clang_type));
926 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
927 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
928 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000929 if (target == NULL)
930 {
931 s << "<no target to read from>";
932 }
933 else
934 {
935 addr_t cstr_address = LLDB_INVALID_ADDRESS;
936 AddressType cstr_address_type = eAddressTypeInvalid;
937
938 size_t cstr_len = 0;
939 bool capped_data = false;
940 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000941 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000942 // We have an array
943 cstr_len = ClangASTContext::GetArraySize (clang_type);
944 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000945 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000946 capped_data = true;
947 cstr_len = max_length;
948 }
949 cstr_address = GetAddressOf (true, &cstr_address_type);
950 }
951 else
952 {
953 // We have a pointer
954 cstr_address = GetPointerValue (&cstr_address_type);
955 }
956 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
957 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000958 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000959 DataExtractor data;
960 size_t bytes_read = 0;
961 if (cstr_len > 0 && honor_array)
962 {
963 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
964 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
965 GetPointeeData(data, 0, cstr_len);
966
967 if ((bytes_read = data.GetByteSize()) > 0)
968 {
969 s << '"';
970 data.Dump (&s,
971 0, // Start offset in "data"
972 item_format,
973 1, // Size of item (1 byte for a char!)
974 bytes_read, // How many bytes to print?
975 UINT32_MAX, // num per line
976 LLDB_INVALID_ADDRESS,// base address
977 0, // bitfield bit size
978 0); // bitfield bit offset
979 if (capped_data)
980 s << "...";
981 s << '"';
982 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000983 }
984 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000985 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000986 cstr_len = max_length;
987 const size_t k_max_buf_size = 64;
988
989 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000990
Greg Claytoncc4d0142012-02-17 07:49:44 +0000991 int cstr_len_displayed = -1;
992 bool capped_cstr = false;
993 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
994 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
995 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000996 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000997 const char *cstr = data.PeekCStr(0);
998 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
999 if (len > k_max_buf_size)
1000 len = k_max_buf_size;
1001 if (cstr && cstr_len_displayed < 0)
1002 s << '"';
1003
1004 if (cstr_len_displayed < 0)
1005 cstr_len_displayed = len;
1006
1007 if (len == 0)
1008 break;
1009 cstr_len_displayed += len;
1010 if (len > bytes_read)
1011 len = bytes_read;
1012 if (len > cstr_len)
1013 len = cstr_len;
1014
1015 data.Dump (&s,
1016 0, // Start offset in "data"
1017 item_format,
1018 1, // Size of item (1 byte for a char!)
1019 len, // How many bytes to print?
1020 UINT32_MAX, // num per line
1021 LLDB_INVALID_ADDRESS,// base address
1022 0, // bitfield bit size
1023 0); // bitfield bit offset
1024
1025 if (len < k_max_buf_size)
1026 break;
1027
1028 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001029 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001030 capped_cstr = true;
1031 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001032 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001033
1034 cstr_len -= len;
1035 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001036 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001037
1038 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001039 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001040 s << '"';
1041 if (capped_cstr)
1042 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001043 }
1044 }
1045 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001046 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001047 }
1048 else
1049 {
1050 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001051 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001052 }
1053}
1054
Jim Ingham53c47f12010-09-10 23:12:17 +00001055const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001056ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001057{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001058
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001059 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001060 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001061
1062 if (!m_object_desc_str.empty())
1063 return m_object_desc_str.c_str();
1064
Greg Claytoncc4d0142012-02-17 07:49:44 +00001065 ExecutionContext exe_ctx (GetExecutionContextRef());
1066 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001067 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001068 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001069
Jim Ingham53c47f12010-09-10 23:12:17 +00001070 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001071
Greg Claytonafacd142011-09-02 01:15:17 +00001072 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001073 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1074
Jim Inghama2cf2632010-12-23 02:29:54 +00001075 if (runtime == NULL)
1076 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001077 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001078 clang_type_t opaque_qual_type = GetClangType();
1079 if (opaque_qual_type != NULL)
1080 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001081 bool is_signed;
1082 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1083 || ClangASTContext::IsPointerType (opaque_qual_type))
1084 {
Greg Claytonafacd142011-09-02 01:15:17 +00001085 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001086 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001087 }
1088 }
1089
Jim Ingham8d543de2011-03-31 23:01:21 +00001090 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001091 {
1092 m_object_desc_str.append (s.GetData());
1093 }
Sean Callanan672ad942010-10-23 00:18:49 +00001094
1095 if (m_object_desc_str.empty())
1096 return NULL;
1097 else
1098 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001099}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001100
Enrico Granata0c489f52012-03-01 04:24:26 +00001101bool
1102ValueObject::GetValueAsCString (lldb::Format format,
1103 std::string& destination)
1104{
1105 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1106 UpdateValueIfNeeded(false))
1107 {
1108 const Value::ContextType context_type = m_value.GetContextType();
1109
1110 switch (context_type)
1111 {
1112 case Value::eContextTypeClangType:
1113 case Value::eContextTypeLLDBType:
1114 case Value::eContextTypeVariable:
1115 {
1116 clang_type_t clang_type = GetClangType ();
1117 if (clang_type)
1118 {
1119 StreamString sstr;
1120 ExecutionContext exe_ctx (GetExecutionContextRef());
1121 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1122 clang_type, // The clang type to display
1123 &sstr,
1124 format, // Format to display this type with
1125 m_data, // Data to extract from
1126 0, // Byte offset into "m_data"
1127 GetByteSize(), // Byte size of item in "m_data"
1128 GetBitfieldBitSize(), // Bitfield bit size
1129 GetBitfieldBitOffset(), // Bitfield bit offset
1130 exe_ctx.GetBestExecutionContextScope());
1131 // Don't set the m_error to anything here otherwise
1132 // we won't be able to re-format as anything else. The
1133 // code for ClangASTType::DumpTypeValue() should always
1134 // return something, even if that something contains
1135 // an error messsage. "m_error" is used to detect errors
1136 // when reading the valid object, not for formatting errors.
1137 if (sstr.GetString().empty())
1138 destination.clear();
1139 else
1140 destination.swap(sstr.GetString());
1141 }
1142 }
1143 break;
1144
1145 case Value::eContextTypeRegisterInfo:
1146 {
1147 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1148 if (reg_info)
1149 {
1150 ExecutionContext exe_ctx (GetExecutionContextRef());
1151
1152 StreamString reg_sstr;
1153 m_data.Dump (&reg_sstr,
1154 0,
1155 format,
1156 reg_info->byte_size,
1157 1,
1158 UINT32_MAX,
1159 LLDB_INVALID_ADDRESS,
1160 0,
1161 0,
1162 exe_ctx.GetBestExecutionContextScope());
1163 destination.swap(reg_sstr.GetString());
1164 }
1165 }
1166 break;
1167
1168 default:
1169 break;
1170 }
1171 return !destination.empty();
1172 }
1173 else
1174 return false;
1175}
1176
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001177const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001178ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001179{
Enrico Granata0c489f52012-03-01 04:24:26 +00001180 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001181 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001182 lldb::Format my_format = GetFormat();
1183 if (m_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001184 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001185 if (m_type_format_sp)
1186 my_format = m_type_format_sp->GetFormat();
1187 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001188 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001189 if (m_is_bitfield_for_scalar)
1190 my_format = eFormatUnsigned;
1191 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001192 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001193 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001194 {
1195 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1196 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001197 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001198 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001199 else
1200 {
1201 clang_type_t clang_type = GetClangType ();
1202 my_format = ClangASTType::GetFormat(clang_type);
1203 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001204 }
1205 }
1206 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001207 if (GetValueAsCString(my_format, m_value_str))
1208 {
1209 if (!m_value_did_change && m_old_value_valid)
1210 {
1211 // The value was gotten successfully, so we consider the
1212 // value as changed if the value string differs
1213 SetValueDidChange (m_old_value_str != m_value_str);
1214 }
1215 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001216 }
1217 if (m_value_str.empty())
1218 return NULL;
1219 return m_value_str.c_str();
1220}
1221
Enrico Granatac3e320a2011-08-02 17:27:39 +00001222// if > 8bytes, 0 is returned. this method should mostly be used
1223// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001224uint64_t
1225ValueObject::GetValueAsUnsigned (uint64_t fail_value)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001226{
1227 // If our byte size is zero this is an aggregate type that has children
1228 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1229 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001230 Scalar scalar;
1231 if (ResolveValue (scalar))
1232 return scalar.GetRawBits64(fail_value);
Enrico Granatac3e320a2011-08-02 17:27:39 +00001233 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001234 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001235}
1236
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001237bool
1238ValueObject::GetPrintableRepresentation(Stream& s,
1239 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001240 Format custom_format)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001241{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001242
Greg Claytonafacd142011-09-02 01:15:17 +00001243 if (custom_format != eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001244 SetFormat(custom_format);
1245
1246 const char * return_value;
Enrico Granatacd1c0232011-08-04 23:37:18 +00001247 std::string alloc_mem;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001248
1249 switch(val_obj_display)
1250 {
1251 case eDisplayValue:
1252 return_value = GetValueAsCString();
1253 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001254
Enrico Granata0a3958e2011-07-02 00:25:22 +00001255 case eDisplaySummary:
Greg Clayton48ca8b82012-01-07 20:58:07 +00001256 return_value = GetSummaryAsCString();
1257 break;
1258
Enrico Granata0a3958e2011-07-02 00:25:22 +00001259 case eDisplayLanguageSpecific:
1260 return_value = GetObjectDescription();
1261 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001262
Enrico Granataf2bbf712011-07-15 02:26:42 +00001263 case eDisplayLocation:
1264 return_value = GetLocationAsCString();
1265 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001266
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001267 case eDisplayChildrenCount:
Greg Clayton48ca8b82012-01-07 20:58:07 +00001268 {
1269 alloc_mem.resize(512);
1270 return_value = &alloc_mem[0];
1271 int count = GetNumChildren();
1272 snprintf((char*)return_value, 512, "%d", count);
1273 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001274 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001275
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001276 case eDisplayType:
1277 return_value = GetTypeName().AsCString();
1278 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001279
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001280 default:
1281 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001282 }
1283
Enrico Granata855cd902011-09-06 22:59:55 +00001284 if (!return_value)
Enrico Granata9fc19442011-07-06 02:13:41 +00001285 {
Enrico Granata9fc19442011-07-06 02:13:41 +00001286 if (val_obj_display == eDisplayValue)
Enrico Granata855cd902011-09-06 22:59:55 +00001287 return_value = GetSummaryAsCString();
Enrico Granata9fc19442011-07-06 02:13:41 +00001288 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +00001289 {
1290 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1291 {
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001292 // this thing has no value, and it seems to have no summary
1293 // some combination of unitialized data and other factors can also
Enrico Granata855cd902011-09-06 22:59:55 +00001294 // raise this condition, so let's print a nice generic description
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001295 {
1296 alloc_mem.resize(684);
1297 return_value = &alloc_mem[0];
1298 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1299 }
Enrico Granatae992a082011-07-22 17:03:19 +00001300 }
1301 else
1302 return_value = GetValueAsCString();
1303 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001304 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001305
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001306 if (return_value)
1307 s.PutCString(return_value);
1308 else
Enrico Granata88da35f2011-08-23 21:26:09 +00001309 {
1310 if (m_error.Fail())
1311 s.Printf("<%s>", m_error.AsCString());
1312 else if (val_obj_display == eDisplaySummary)
1313 s.PutCString("<no summary available>");
1314 else if (val_obj_display == eDisplayValue)
1315 s.PutCString("<no value available>");
1316 else if (val_obj_display == eDisplayLanguageSpecific)
1317 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1318 else
1319 s.PutCString("<no printable representation>");
1320 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001321
1322 // we should only return false here if we could not do *anything*
1323 // even if we have an error message as output, that's a success
1324 // from our callers' perspective, so return true
1325 return true;
1326
Enrico Granata0a3958e2011-07-02 00:25:22 +00001327}
1328
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001329// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1330// this call up to date by returning true for your new special cases. We will eventually move
1331// to checking this call result before trying to display special cases
1332bool
1333ValueObject::HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001334 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001335{
1336 clang_type_t elem_or_pointee_type;
1337 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1338
1339 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1340 && val_obj_display == ValueObject::eDisplayValue)
1341 {
1342 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001343 (custom_format == eFormatCString ||
1344 custom_format == eFormatCharArray ||
1345 custom_format == eFormatChar ||
1346 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001347 return true;
1348
1349 if (flags.Test(ClangASTContext::eTypeIsArray))
1350 {
Greg Claytonafacd142011-09-02 01:15:17 +00001351 if ((custom_format == eFormatBytes) ||
1352 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001353 return true;
1354
Greg Claytonafacd142011-09-02 01:15:17 +00001355 if ((custom_format == eFormatVectorOfChar) ||
1356 (custom_format == eFormatVectorOfFloat32) ||
1357 (custom_format == eFormatVectorOfFloat64) ||
1358 (custom_format == eFormatVectorOfSInt16) ||
1359 (custom_format == eFormatVectorOfSInt32) ||
1360 (custom_format == eFormatVectorOfSInt64) ||
1361 (custom_format == eFormatVectorOfSInt8) ||
1362 (custom_format == eFormatVectorOfUInt128) ||
1363 (custom_format == eFormatVectorOfUInt16) ||
1364 (custom_format == eFormatVectorOfUInt32) ||
1365 (custom_format == eFormatVectorOfUInt64) ||
1366 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001367 return true;
1368 }
1369 }
1370 return false;
1371}
1372
Enrico Granata9fc19442011-07-06 02:13:41 +00001373bool
1374ValueObject::DumpPrintableRepresentation(Stream& s,
1375 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001376 Format custom_format,
Enrico Granata85933ed2011-08-18 16:38:26 +00001377 bool only_special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001378{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001379
1380 clang_type_t elem_or_pointee_type;
1381 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001382
Enrico Granataf4efecd2011-07-12 22:56:10 +00001383 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1384 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001385 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001386 // when being asked to get a printable display an array or pointer type directly,
1387 // try to "do the right thing"
1388
1389 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001390 (custom_format == eFormatCString ||
1391 custom_format == eFormatCharArray ||
1392 custom_format == eFormatChar ||
1393 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001394 {
1395 Error error;
1396 ReadPointedString(s,
1397 error,
1398 0,
Greg Claytonafacd142011-09-02 01:15:17 +00001399 (custom_format == eFormatVectorOfChar) ||
1400 (custom_format == eFormatCharArray));
Enrico Granataf4efecd2011-07-12 22:56:10 +00001401 return !error.Fail();
1402 }
1403
Greg Claytonafacd142011-09-02 01:15:17 +00001404 if (custom_format == eFormatEnum)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001405 return false;
1406
1407 // this only works for arrays, because I have no way to know when
1408 // the pointed memory ends, and no special \0 end of data marker
1409 if (flags.Test(ClangASTContext::eTypeIsArray))
1410 {
Greg Claytonafacd142011-09-02 01:15:17 +00001411 if ((custom_format == eFormatBytes) ||
1412 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001413 {
1414 uint32_t count = GetNumChildren();
1415
1416 s << '[';
1417 for (uint32_t low = 0; low < count; low++)
1418 {
1419
1420 if (low)
1421 s << ',';
1422
1423 ValueObjectSP child = GetChildAtIndex(low,true);
1424 if (!child.get())
1425 {
Enrico Granatae992a082011-07-22 17:03:19 +00001426 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001427 continue;
1428 }
1429 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1430 }
1431
1432 s << ']';
1433
1434 return true;
1435 }
1436
Greg Claytonafacd142011-09-02 01:15:17 +00001437 if ((custom_format == eFormatVectorOfChar) ||
1438 (custom_format == eFormatVectorOfFloat32) ||
1439 (custom_format == eFormatVectorOfFloat64) ||
1440 (custom_format == eFormatVectorOfSInt16) ||
1441 (custom_format == eFormatVectorOfSInt32) ||
1442 (custom_format == eFormatVectorOfSInt64) ||
1443 (custom_format == eFormatVectorOfSInt8) ||
1444 (custom_format == eFormatVectorOfUInt128) ||
1445 (custom_format == eFormatVectorOfUInt16) ||
1446 (custom_format == eFormatVectorOfUInt32) ||
1447 (custom_format == eFormatVectorOfUInt64) ||
1448 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001449 {
1450 uint32_t count = GetNumChildren();
1451
Greg Claytonafacd142011-09-02 01:15:17 +00001452 Format format = FormatManager::GetSingleItemFormat(custom_format);
Enrico Granataf4efecd2011-07-12 22:56:10 +00001453
1454 s << '[';
1455 for (uint32_t low = 0; low < count; low++)
1456 {
1457
1458 if (low)
1459 s << ',';
1460
1461 ValueObjectSP child = GetChildAtIndex(low,true);
1462 if (!child.get())
1463 {
Enrico Granatae992a082011-07-22 17:03:19 +00001464 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001465 continue;
1466 }
1467 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1468 }
1469
1470 s << ']';
1471
1472 return true;
1473 }
1474 }
1475
Greg Claytonafacd142011-09-02 01:15:17 +00001476 if ((custom_format == eFormatBoolean) ||
1477 (custom_format == eFormatBinary) ||
1478 (custom_format == eFormatChar) ||
1479 (custom_format == eFormatCharPrintable) ||
1480 (custom_format == eFormatComplexFloat) ||
1481 (custom_format == eFormatDecimal) ||
1482 (custom_format == eFormatHex) ||
1483 (custom_format == eFormatFloat) ||
1484 (custom_format == eFormatOctal) ||
1485 (custom_format == eFormatOSType) ||
1486 (custom_format == eFormatUnicode16) ||
1487 (custom_format == eFormatUnicode32) ||
1488 (custom_format == eFormatUnsigned) ||
1489 (custom_format == eFormatPointer) ||
1490 (custom_format == eFormatComplexInteger) ||
1491 (custom_format == eFormatComplex) ||
1492 (custom_format == eFormatDefault)) // use the [] operator
Enrico Granataf4efecd2011-07-12 22:56:10 +00001493 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001494 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001495
1496 if (only_special)
1497 return false;
1498
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001499 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001500 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001501 SetFormat(eFormatDefault);
1502 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001503}
1504
Greg Clayton737b9322010-09-13 03:32:57 +00001505addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001506ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001507{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001508 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001509 return LLDB_INVALID_ADDRESS;
1510
Greg Clayton73b472d2010-10-27 03:32:59 +00001511 switch (m_value.GetValueType())
1512 {
1513 case Value::eValueTypeScalar:
1514 if (scalar_is_load_address)
1515 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001516 if(address_type)
1517 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001518 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1519 }
1520 break;
1521
1522 case Value::eValueTypeLoadAddress:
1523 case Value::eValueTypeFileAddress:
1524 case Value::eValueTypeHostAddress:
1525 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001526 if(address_type)
1527 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001528 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1529 }
1530 break;
1531 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001532 if (address_type)
1533 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001534 return LLDB_INVALID_ADDRESS;
1535}
1536
1537addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001538ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001539{
Greg Claytonafacd142011-09-02 01:15:17 +00001540 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001541 if(address_type)
1542 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001543
Enrico Granatac3e320a2011-08-02 17:27:39 +00001544 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001545 return address;
1546
Greg Clayton73b472d2010-10-27 03:32:59 +00001547 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001548 {
1549 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001550 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001551 break;
1552
Enrico Granata9128ee22011-09-06 19:20:51 +00001553 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001554 case Value::eValueTypeLoadAddress:
1555 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001556 {
1557 uint32_t data_offset = 0;
1558 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001559 }
1560 break;
1561 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001562
Enrico Granata9128ee22011-09-06 19:20:51 +00001563 if (address_type)
1564 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001565
Greg Clayton737b9322010-09-13 03:32:57 +00001566 return address;
1567}
1568
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001569bool
Jim Ingham6035b672011-03-31 00:19:25 +00001570ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001571{
1572 // Make sure our value is up to date first so that our location and location
1573 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001574 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001575 return false;
1576
1577 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001578 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001579
Greg Claytonb1320972010-07-14 00:18:15 +00001580 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001581
Jim Ingham16e0c682011-08-12 23:34:31 +00001582 Value::ValueType value_type = m_value.GetValueType();
1583
1584 if (value_type == Value::eValueTypeScalar)
1585 {
1586 // If the value is already a scalar, then let the scalar change itself:
1587 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1588 }
1589 else if (byte_size <= Scalar::GetMaxByteSize())
1590 {
1591 // If the value fits in a scalar, then make a new scalar and again let the
1592 // scalar code do the conversion, then figure out where to put the new value.
1593 Scalar new_scalar;
1594 Error error;
1595 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1596 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001597 {
Jim Ingham4b536182011-08-09 02:12:22 +00001598 switch (value_type)
1599 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001600 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001601 {
1602 // If it is a load address, then the scalar value is the storage location
1603 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001604 ExecutionContext exe_ctx (GetExecutionContextRef());
1605 Process *process = exe_ctx.GetProcessPtr();
1606 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001607 {
Greg Claytonafacd142011-09-02 01:15:17 +00001608 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001609 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1610 new_scalar,
1611 byte_size,
1612 error);
Jim Ingham16e0c682011-08-12 23:34:31 +00001613 if (!error.Success() || bytes_written != byte_size)
1614 return false;
1615 }
1616 }
Jim Ingham4b536182011-08-09 02:12:22 +00001617 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001618 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001619 {
1620 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1621 DataExtractor new_data;
1622 new_data.SetByteOrder (m_data.GetByteOrder());
1623
1624 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1625 m_data.SetData(buffer_sp, 0);
1626 bool success = new_scalar.GetData(new_data);
1627 if (success)
1628 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001629 new_data.CopyByteOrderedData (0,
1630 byte_size,
1631 const_cast<uint8_t *>(m_data.GetDataStart()),
1632 byte_size,
1633 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001634 }
1635 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1636
1637 }
Jim Ingham4b536182011-08-09 02:12:22 +00001638 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001639 case Value::eValueTypeFileAddress:
1640 case Value::eValueTypeScalar:
Jim Ingham16e0c682011-08-12 23:34:31 +00001641 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001642 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001643 }
1644 else
1645 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001646 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001647 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001648 }
1649 else
1650 {
1651 // We don't support setting things bigger than a scalar at present.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001652 return false;
1653 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001654
1655 // If we have reached this point, then we have successfully changed the value.
1656 SetNeedsUpdate();
1657 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001658}
1659
Greg Clayton81e871e2012-02-04 02:27:34 +00001660bool
1661ValueObject::GetDeclaration (Declaration &decl)
1662{
1663 decl.Clear();
1664 return false;
1665}
1666
Greg Claytonafacd142011-09-02 01:15:17 +00001667LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001668ValueObject::GetObjectRuntimeLanguage ()
1669{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001670 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1671 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001672}
1673
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001674void
Jim Ingham58b59f92011-04-22 23:53:53 +00001675ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001676{
Jim Ingham58b59f92011-04-22 23:53:53 +00001677 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001678}
1679
1680ValueObjectSP
1681ValueObject::GetSyntheticChild (const ConstString &key) const
1682{
1683 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001684 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001685 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001686 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001687 return synthetic_child_sp;
1688}
1689
1690bool
1691ValueObject::IsPointerType ()
1692{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001693 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001694}
1695
Jim Inghamb7603bb2011-03-18 00:05:18 +00001696bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001697ValueObject::IsArrayType ()
1698{
1699 return ClangASTContext::IsArrayType (GetClangType());
1700}
1701
1702bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001703ValueObject::IsScalarType ()
1704{
1705 return ClangASTContext::IsScalarType (GetClangType());
1706}
1707
1708bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001709ValueObject::IsIntegerType (bool &is_signed)
1710{
1711 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1712}
Greg Clayton73b472d2010-10-27 03:32:59 +00001713
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001714bool
1715ValueObject::IsPointerOrReferenceType ()
1716{
Greg Clayton007d5be2011-05-30 00:49:24 +00001717 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1718}
1719
1720bool
1721ValueObject::IsPossibleCPlusPlusDynamicType ()
1722{
1723 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001724}
1725
Greg Claytondea8cb42011-06-29 22:09:02 +00001726bool
1727ValueObject::IsPossibleDynamicType ()
1728{
1729 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1730}
1731
Greg Claytonafacd142011-09-02 01:15:17 +00001732ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001733ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1734{
1735 if (IsArrayType())
1736 return GetSyntheticArrayMemberFromArray(index, can_create);
1737
1738 if (IsPointerType())
1739 return GetSyntheticArrayMemberFromPointer(index, can_create);
1740
1741 return ValueObjectSP();
1742
1743}
1744
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001745ValueObjectSP
1746ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1747{
1748 ValueObjectSP synthetic_child_sp;
1749 if (IsPointerType ())
1750 {
1751 char index_str[64];
1752 snprintf(index_str, sizeof(index_str), "[%i]", index);
1753 ConstString index_const_str(index_str);
1754 // Check if we have already created a synthetic array member in this
1755 // valid object. If we have we will re-use it.
1756 synthetic_child_sp = GetSyntheticChild (index_const_str);
1757 if (!synthetic_child_sp)
1758 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001759 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001760 // We haven't made a synthetic array member for INDEX yet, so
1761 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001762 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001763
1764 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001765 if (synthetic_child)
1766 {
1767 AddSyntheticChild(index_const_str, synthetic_child);
1768 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001769 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001770 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001771 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001772 }
1773 }
1774 return synthetic_child_sp;
1775}
Jim Ingham22777012010-09-23 02:01:19 +00001776
Greg Claytondaf515f2011-07-09 20:12:33 +00001777// This allows you to create an array member using and index
1778// that doesn't not fall in the normal bounds of the array.
1779// Many times structure can be defined as:
1780// struct Collection
1781// {
1782// uint32_t item_count;
1783// Item item_array[0];
1784// };
1785// The size of the "item_array" is 1, but many times in practice
1786// there are more items in "item_array".
1787
1788ValueObjectSP
1789ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1790{
1791 ValueObjectSP synthetic_child_sp;
1792 if (IsArrayType ())
1793 {
1794 char index_str[64];
1795 snprintf(index_str, sizeof(index_str), "[%i]", index);
1796 ConstString index_const_str(index_str);
1797 // Check if we have already created a synthetic array member in this
1798 // valid object. If we have we will re-use it.
1799 synthetic_child_sp = GetSyntheticChild (index_const_str);
1800 if (!synthetic_child_sp)
1801 {
1802 ValueObject *synthetic_child;
1803 // We haven't made a synthetic array member for INDEX yet, so
1804 // lets make one and cache it for any future reference.
1805 synthetic_child = CreateChildAtIndex(0, true, index);
1806
1807 // Cache the value if we got one back...
1808 if (synthetic_child)
1809 {
1810 AddSyntheticChild(index_const_str, synthetic_child);
1811 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001812 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001813 synthetic_child_sp->m_is_array_item_for_pointer = true;
1814 }
1815 }
1816 }
1817 return synthetic_child_sp;
1818}
1819
Enrico Granata9fc19442011-07-06 02:13:41 +00001820ValueObjectSP
1821ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1822{
1823 ValueObjectSP synthetic_child_sp;
1824 if (IsScalarType ())
1825 {
1826 char index_str[64];
1827 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1828 ConstString index_const_str(index_str);
1829 // Check if we have already created a synthetic array member in this
1830 // valid object. If we have we will re-use it.
1831 synthetic_child_sp = GetSyntheticChild (index_const_str);
1832 if (!synthetic_child_sp)
1833 {
1834 ValueObjectChild *synthetic_child;
1835 // We haven't made a synthetic array member for INDEX yet, so
1836 // lets make one and cache it for any future reference.
1837 synthetic_child = new ValueObjectChild(*this,
1838 GetClangAST(),
1839 GetClangType(),
1840 index_const_str,
1841 GetByteSize(),
1842 0,
1843 to-from+1,
1844 from,
1845 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001846 false,
1847 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001848
1849 // Cache the value if we got one back...
1850 if (synthetic_child)
1851 {
1852 AddSyntheticChild(index_const_str, synthetic_child);
1853 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001854 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001855 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1856 }
1857 }
1858 }
1859 return synthetic_child_sp;
1860}
1861
Greg Claytonafacd142011-09-02 01:15:17 +00001862ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001863ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1864{
1865 ValueObjectSP synthetic_child_sp;
1866 if (IsArrayType () || IsPointerType ())
1867 {
1868 char index_str[64];
1869 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1870 ConstString index_const_str(index_str);
1871 // Check if we have already created a synthetic array member in this
1872 // valid object. If we have we will re-use it.
1873 synthetic_child_sp = GetSyntheticChild (index_const_str);
1874 if (!synthetic_child_sp)
1875 {
1876 ValueObjectSynthetic *synthetic_child;
1877
1878 // We haven't made a synthetic array member for INDEX yet, so
1879 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001880 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001881 view->AddRange(from,to);
1882 SyntheticChildrenSP view_sp(view);
1883 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1884
1885 // Cache the value if we got one back...
1886 if (synthetic_child)
1887 {
1888 AddSyntheticChild(index_const_str, synthetic_child);
1889 synthetic_child_sp = synthetic_child->GetSP();
1890 synthetic_child_sp->SetName(ConstString(index_str));
1891 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1892 }
1893 }
1894 }
1895 return synthetic_child_sp;
1896}
1897
Greg Claytonafacd142011-09-02 01:15:17 +00001898ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001899ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1900{
1901
1902 ValueObjectSP synthetic_child_sp;
1903
1904 char name_str[64];
1905 snprintf(name_str, sizeof(name_str), "@%i", offset);
1906 ConstString name_const_str(name_str);
1907
1908 // Check if we have already created a synthetic array member in this
1909 // valid object. If we have we will re-use it.
1910 synthetic_child_sp = GetSyntheticChild (name_const_str);
1911
1912 if (synthetic_child_sp.get())
1913 return synthetic_child_sp;
1914
1915 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001916 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001917
1918 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1919 type.GetASTContext(),
1920 type.GetOpaqueQualType(),
1921 name_const_str,
1922 type.GetTypeByteSize(),
1923 offset,
1924 0,
1925 0,
1926 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001927 false,
1928 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001929 if (synthetic_child)
1930 {
1931 AddSyntheticChild(name_const_str, synthetic_child);
1932 synthetic_child_sp = synthetic_child->GetSP();
1933 synthetic_child_sp->SetName(name_const_str);
1934 synthetic_child_sp->m_is_child_at_offset = true;
1935 }
1936 return synthetic_child_sp;
1937}
1938
Enrico Granatad55546b2011-07-22 00:16:08 +00001939// your expression path needs to have a leading . or ->
1940// (unless it somehow "looks like" an array, in which case it has
1941// a leading [ symbol). while the [ is meaningful and should be shown
1942// to the user, . and -> are just parser design, but by no means
1943// added information for the user.. strip them off
1944static const char*
1945SkipLeadingExpressionPathSeparators(const char* expression)
1946{
1947 if (!expression || !expression[0])
1948 return expression;
1949 if (expression[0] == '.')
1950 return expression+1;
1951 if (expression[0] == '-' && expression[1] == '>')
1952 return expression+2;
1953 return expression;
1954}
1955
Greg Claytonafacd142011-09-02 01:15:17 +00001956ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00001957ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1958{
1959 ValueObjectSP synthetic_child_sp;
1960 ConstString name_const_string(expression);
1961 // Check if we have already created a synthetic array member in this
1962 // valid object. If we have we will re-use it.
1963 synthetic_child_sp = GetSyntheticChild (name_const_string);
1964 if (!synthetic_child_sp)
1965 {
1966 // We haven't made a synthetic array member for expression yet, so
1967 // lets make one and cache it for any future reference.
1968 synthetic_child_sp = GetValueForExpressionPath(expression);
1969
1970 // Cache the value if we got one back...
1971 if (synthetic_child_sp.get())
1972 {
1973 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001974 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001975 synthetic_child_sp->m_is_expression_path_child = true;
1976 }
1977 }
1978 return synthetic_child_sp;
1979}
1980
1981void
Greg Claytonafacd142011-09-02 01:15:17 +00001982ValueObject::CalculateSyntheticValue (SyntheticValueType use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00001983{
Greg Claytonafacd142011-09-02 01:15:17 +00001984 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001985 return;
1986
Enrico Granatac3e320a2011-08-02 17:27:39 +00001987 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001988
Enrico Granata0c489f52012-03-01 04:24:26 +00001989 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00001990 return;
1991
Enrico Granataa37a0652011-07-24 00:14:56 +00001992 if (m_synthetic_value == NULL)
Enrico Granata0c489f52012-03-01 04:24:26 +00001993 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00001994
1995}
1996
Jim Ingham78a685a2011-04-16 00:01:13 +00001997void
Greg Claytonafacd142011-09-02 01:15:17 +00001998ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00001999{
Greg Claytonafacd142011-09-02 01:15:17 +00002000 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002001 return;
2002
Jim Ingham58b59f92011-04-22 23:53:53 +00002003 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002004 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002005 ExecutionContext exe_ctx (GetExecutionContextRef());
2006 Process *process = exe_ctx.GetProcessPtr();
2007 if (process)
Jim Ingham78a685a2011-04-16 00:01:13 +00002008 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002009 bool worth_having_dynamic_value = false;
Jim Ingham78a685a2011-04-16 00:01:13 +00002010
Greg Claytoncc4d0142012-02-17 07:49:44 +00002011
2012 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
2013 // hard code this everywhere.
2014 LanguageType known_type = GetObjectRuntimeLanguage();
2015 if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
Jim Ingham78a685a2011-04-16 00:01:13 +00002016 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002017 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
2018 if (runtime)
2019 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00002020 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00002021 else
2022 {
2023 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus);
2024 if (cpp_runtime)
2025 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
2026
2027 if (!worth_having_dynamic_value)
2028 {
2029 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC);
2030 if (objc_runtime)
2031 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
2032 }
2033 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002034
Greg Claytoncc4d0142012-02-17 07:49:44 +00002035 if (worth_having_dynamic_value)
2036 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
2037 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002038 }
2039}
2040
Jim Ingham58b59f92011-04-22 23:53:53 +00002041ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002042ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002043{
Greg Claytonafacd142011-09-02 01:15:17 +00002044 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002045 return ValueObjectSP();
2046
2047 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002048 {
Jim Ingham2837b762011-05-04 03:43:18 +00002049 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002050 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002051 if (m_dynamic_value)
2052 return m_dynamic_value->GetSP();
2053 else
2054 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002055}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002056
Jim Ingham60dbabb2011-12-08 19:44:08 +00002057ValueObjectSP
2058ValueObject::GetStaticValue()
2059{
2060 return GetSP();
2061}
2062
Enrico Granatad55546b2011-07-22 00:16:08 +00002063// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
2064// or we do not really want a dynamic VO. this method instead returns this object
2065// itself when making it synthetic has no meaning. this makes it much simpler
2066// to replace the SyntheticValue for the ValueObject
2067ValueObjectSP
2068ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
2069{
Greg Claytonafacd142011-09-02 01:15:17 +00002070 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00002071 return GetSP();
2072
Enrico Granatac3e320a2011-08-02 17:27:39 +00002073 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00002074
Enrico Granata0c489f52012-03-01 04:24:26 +00002075 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002076 return GetSP();
2077
2078 CalculateSyntheticValue(use_synthetic);
2079
2080 if (m_synthetic_value)
2081 return m_synthetic_value->GetSP();
2082 else
2083 return GetSP();
2084}
2085
Greg Claytone221f822011-01-21 01:59:00 +00002086bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002087ValueObject::HasSyntheticValue()
2088{
2089 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2090
Enrico Granata0c489f52012-03-01 04:24:26 +00002091 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002092 return false;
2093
Greg Claytonafacd142011-09-02 01:15:17 +00002094 CalculateSyntheticValue(eUseSyntheticFilter);
Enrico Granata27b625e2011-08-09 01:04:56 +00002095
2096 if (m_synthetic_value)
2097 return true;
2098 else
2099 return false;
2100}
2101
2102bool
Greg Claytone221f822011-01-21 01:59:00 +00002103ValueObject::GetBaseClassPath (Stream &s)
2104{
2105 if (IsBaseClass())
2106 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002107 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002108 clang_type_t clang_type = GetClangType();
2109 std::string cxx_class_name;
2110 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2111 if (this_had_base_class)
2112 {
2113 if (parent_had_base_class)
2114 s.PutCString("::");
2115 s.PutCString(cxx_class_name.c_str());
2116 }
2117 return parent_had_base_class || this_had_base_class;
2118 }
2119 return false;
2120}
2121
2122
2123ValueObject *
2124ValueObject::GetNonBaseClassParent()
2125{
Jim Ingham78a685a2011-04-16 00:01:13 +00002126 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002127 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002128 if (GetParent()->IsBaseClass())
2129 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002130 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002131 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002132 }
2133 return NULL;
2134}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002135
2136void
Enrico Granata4becb372011-06-29 22:27:15 +00002137ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002138{
Greg Claytone221f822011-01-21 01:59:00 +00002139 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002140
Enrico Granata85933ed2011-08-18 16:38:26 +00002141 if (is_deref_of_parent && epformat == eDereferencePointers)
2142 {
Enrico Granata4becb372011-06-29 22:27:15 +00002143 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2144 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2145 // the eHonorPointers mode is meant to produce strings in this latter format
2146 s.PutCString("*(");
2147 }
Greg Claytone221f822011-01-21 01:59:00 +00002148
Enrico Granata4becb372011-06-29 22:27:15 +00002149 ValueObject* parent = GetParent();
2150
2151 if (parent)
2152 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002153
2154 // if we are a deref_of_parent just because we are synthetic array
2155 // members made up to allow ptr[%d] syntax to work in variable
2156 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00002157 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002158 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002159
Greg Claytone221f822011-01-21 01:59:00 +00002160 if (!IsBaseClass())
2161 {
2162 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002163 {
Greg Claytone221f822011-01-21 01:59:00 +00002164 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2165 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002166 {
Greg Claytone221f822011-01-21 01:59:00 +00002167 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2168 if (non_base_class_parent_clang_type)
2169 {
2170 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2171
Enrico Granata9dd75c82011-07-15 23:30:15 +00002172 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002173 {
2174 s.PutCString("->");
2175 }
Enrico Granata4becb372011-06-29 22:27:15 +00002176 else
2177 {
2178 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2179 {
2180 s.PutCString("->");
2181 }
2182 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2183 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2184 {
2185 s.PutChar('.');
2186 }
Greg Claytone221f822011-01-21 01:59:00 +00002187 }
2188 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002189 }
Greg Claytone221f822011-01-21 01:59:00 +00002190
2191 const char *name = GetName().GetCString();
2192 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002193 {
Greg Claytone221f822011-01-21 01:59:00 +00002194 if (qualify_cxx_base_classes)
2195 {
2196 if (GetBaseClassPath (s))
2197 s.PutCString("::");
2198 }
2199 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002200 }
2201 }
2202 }
2203
Enrico Granata85933ed2011-08-18 16:38:26 +00002204 if (is_deref_of_parent && epformat == eDereferencePointers)
2205 {
Greg Claytone221f822011-01-21 01:59:00 +00002206 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002207 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002208}
2209
Greg Claytonafacd142011-09-02 01:15:17 +00002210ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002211ValueObject::GetValueForExpressionPath(const char* expression,
2212 const char** first_unparsed,
2213 ExpressionPathScanEndReason* reason_to_stop,
2214 ExpressionPathEndResultType* final_value_type,
2215 const GetValueForExpressionPathOptions& options,
2216 ExpressionPathAftermath* final_task_on_target)
2217{
2218
2219 const char* dummy_first_unparsed;
2220 ExpressionPathScanEndReason dummy_reason_to_stop;
2221 ExpressionPathEndResultType dummy_final_value_type;
2222 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2223
2224 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2225 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2226 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2227 final_value_type ? final_value_type : &dummy_final_value_type,
2228 options,
2229 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2230
2231 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002232 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002233
2234 if (ret_val.get() && ((final_value_type ? *final_value_type : dummy_final_value_type) == ePlain)) // I can only deref and takeaddress of plain objects
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002235 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002236 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002237 {
2238 Error error;
2239 ValueObjectSP final_value = ret_val->Dereference(error);
2240 if (error.Fail() || !final_value.get())
2241 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002242 if (reason_to_stop)
2243 *reason_to_stop = ValueObject::eDereferencingFailed;
2244 if (final_value_type)
2245 *final_value_type = ValueObject::eInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002246 return ValueObjectSP();
2247 }
2248 else
2249 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002250 if (final_task_on_target)
2251 *final_task_on_target = ValueObject::eNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002252 return final_value;
2253 }
2254 }
2255 if (*final_task_on_target == ValueObject::eTakeAddress)
2256 {
2257 Error error;
2258 ValueObjectSP final_value = ret_val->AddressOf(error);
2259 if (error.Fail() || !final_value.get())
2260 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002261 if (reason_to_stop)
2262 *reason_to_stop = ValueObject::eTakingAddressFailed;
2263 if (final_value_type)
2264 *final_value_type = ValueObject::eInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002265 return ValueObjectSP();
2266 }
2267 else
2268 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002269 if (final_task_on_target)
2270 *final_task_on_target = ValueObject::eNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002271 return final_value;
2272 }
2273 }
2274 }
2275 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2276}
2277
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002278int
2279ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002280 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002281 const char** first_unparsed,
2282 ExpressionPathScanEndReason* reason_to_stop,
2283 ExpressionPathEndResultType* final_value_type,
2284 const GetValueForExpressionPathOptions& options,
2285 ExpressionPathAftermath* final_task_on_target)
2286{
2287 const char* dummy_first_unparsed;
2288 ExpressionPathScanEndReason dummy_reason_to_stop;
2289 ExpressionPathEndResultType dummy_final_value_type;
2290 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2291
2292 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2293 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2294 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2295 final_value_type ? final_value_type : &dummy_final_value_type,
2296 options,
2297 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2298
2299 if (!ret_val.get()) // if there are errors, I add nothing to the list
2300 return 0;
2301
2302 if (*reason_to_stop != eArrayRangeOperatorMet)
2303 {
2304 // I need not expand a range, just post-process the final value and return
2305 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2306 {
2307 list->Append(ret_val);
2308 return 1;
2309 }
2310 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2311 {
2312 if (*final_task_on_target == ValueObject::eDereference)
2313 {
2314 Error error;
2315 ValueObjectSP final_value = ret_val->Dereference(error);
2316 if (error.Fail() || !final_value.get())
2317 {
2318 *reason_to_stop = ValueObject::eDereferencingFailed;
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 if (*final_task_on_target == ValueObject::eTakeAddress)
2330 {
2331 Error error;
2332 ValueObjectSP final_value = ret_val->AddressOf(error);
2333 if (error.Fail() || !final_value.get())
2334 {
2335 *reason_to_stop = ValueObject::eTakingAddressFailed;
2336 *final_value_type = ValueObject::eInvalid;
2337 return 0;
2338 }
2339 else
2340 {
2341 *final_task_on_target = ValueObject::eNothing;
2342 list->Append(final_value);
2343 return 1;
2344 }
2345 }
2346 }
2347 }
2348 else
2349 {
2350 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2351 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2352 ret_val,
2353 list,
2354 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2355 final_value_type ? final_value_type : &dummy_final_value_type,
2356 options,
2357 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2358 }
2359 // in any non-covered case, just do the obviously right thing
2360 list->Append(ret_val);
2361 return 1;
2362}
2363
Greg Claytonafacd142011-09-02 01:15:17 +00002364ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002365ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2366 const char** first_unparsed,
2367 ExpressionPathScanEndReason* reason_to_stop,
2368 ExpressionPathEndResultType* final_result,
2369 const GetValueForExpressionPathOptions& options,
2370 ExpressionPathAftermath* what_next)
2371{
2372 ValueObjectSP root = GetSP();
2373
2374 if (!root.get())
2375 return ValueObjectSP();
2376
2377 *first_unparsed = expression_cstr;
2378
2379 while (true)
2380 {
2381
2382 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2383
Greg Claytonafacd142011-09-02 01:15:17 +00002384 clang_type_t root_clang_type = root->GetClangType();
2385 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002386 Flags root_clang_type_info,pointee_clang_type_info;
2387
2388 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2389 if (pointee_clang_type)
2390 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002391
2392 if (!expression_cstr || *expression_cstr == '\0')
2393 {
2394 *reason_to_stop = ValueObject::eEndOfString;
2395 return root;
2396 }
2397
2398 switch (*expression_cstr)
2399 {
2400 case '-':
2401 {
2402 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002403 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 +00002404 {
2405 *first_unparsed = expression_cstr;
2406 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
2407 *final_result = ValueObject::eInvalid;
2408 return ValueObjectSP();
2409 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002410 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2411 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002412 options.m_no_fragile_ivar)
2413 {
2414 *first_unparsed = expression_cstr;
2415 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
2416 *final_result = ValueObject::eInvalid;
2417 return ValueObjectSP();
2418 }
2419 if (expression_cstr[1] != '>')
2420 {
2421 *first_unparsed = expression_cstr;
2422 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2423 *final_result = ValueObject::eInvalid;
2424 return ValueObjectSP();
2425 }
2426 expression_cstr++; // skip the -
2427 }
2428 case '.': // or fallthrough from ->
2429 {
2430 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002431 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 +00002432 {
2433 *first_unparsed = expression_cstr;
2434 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
2435 *final_result = ValueObject::eInvalid;
2436 return ValueObjectSP();
2437 }
2438 expression_cstr++; // skip .
2439 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2440 ConstString child_name;
2441 if (!next_separator) // if no other separator just expand this last layer
2442 {
2443 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002444 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2445
2446 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002447 {
2448 *first_unparsed = '\0';
2449 *reason_to_stop = ValueObject::eEndOfString;
2450 *final_result = ValueObject::ePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002451 return child_valobj_sp;
2452 }
2453 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2454 {
Greg Clayton4c3b8fb2011-12-02 22:48:25 +00002455 child_valobj_sp = root->GetSyntheticValue(eNoSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002456 }
2457
2458 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2459 // so we hit the "else" branch, and return an error
2460 if(child_valobj_sp.get()) // if it worked, just return
2461 {
2462 *first_unparsed = '\0';
2463 *reason_to_stop = ValueObject::eEndOfString;
2464 *final_result = ValueObject::ePlain;
2465 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002466 }
2467 else
2468 {
2469 *first_unparsed = expression_cstr;
2470 *reason_to_stop = ValueObject::eNoSuchChild;
2471 *final_result = ValueObject::eInvalid;
2472 return ValueObjectSP();
2473 }
2474 }
2475 else // other layers do expand
2476 {
2477 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002478 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2479 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002480 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002481 root = child_valobj_sp;
2482 *first_unparsed = next_separator;
2483 *final_result = ValueObject::ePlain;
2484 continue;
2485 }
2486 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2487 {
Greg Claytonafacd142011-09-02 01:15:17 +00002488 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002489 }
2490
2491 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2492 // so we hit the "else" branch, and return an error
2493 if(child_valobj_sp.get()) // if it worked, move on
2494 {
2495 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002496 *first_unparsed = next_separator;
2497 *final_result = ValueObject::ePlain;
2498 continue;
2499 }
2500 else
2501 {
2502 *first_unparsed = expression_cstr;
2503 *reason_to_stop = ValueObject::eNoSuchChild;
2504 *final_result = ValueObject::eInvalid;
2505 return ValueObjectSP();
2506 }
2507 }
2508 break;
2509 }
2510 case '[':
2511 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002512 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 +00002513 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002514 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002515 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002516 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2517 {
2518 *first_unparsed = expression_cstr;
2519 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2520 *final_result = ValueObject::eInvalid;
2521 return ValueObjectSP();
2522 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002523 }
2524 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2525 {
2526 *first_unparsed = expression_cstr;
2527 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2528 *final_result = ValueObject::eInvalid;
2529 return ValueObjectSP();
2530 }
2531 }
2532 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2533 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002534 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002535 {
2536 *first_unparsed = expression_cstr;
2537 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2538 *final_result = ValueObject::eInvalid;
2539 return ValueObjectSP();
2540 }
2541 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2542 {
2543 *first_unparsed = expression_cstr+2;
2544 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2545 *final_result = ValueObject::eUnboundedRange;
2546 return root;
2547 }
2548 }
2549 const char *separator_position = ::strchr(expression_cstr+1,'-');
2550 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2551 if (!close_bracket_position) // if there is no ], this is a syntax error
2552 {
2553 *first_unparsed = expression_cstr;
2554 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2555 *final_result = ValueObject::eInvalid;
2556 return ValueObjectSP();
2557 }
2558 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2559 {
2560 char *end = NULL;
2561 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2562 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2563 {
2564 *first_unparsed = expression_cstr;
2565 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2566 *final_result = ValueObject::eInvalid;
2567 return ValueObjectSP();
2568 }
2569 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2570 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002571 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002572 {
2573 *first_unparsed = expression_cstr+2;
2574 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2575 *final_result = ValueObject::eUnboundedRange;
2576 return root;
2577 }
2578 else
2579 {
2580 *first_unparsed = expression_cstr;
2581 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2582 *final_result = ValueObject::eInvalid;
2583 return ValueObjectSP();
2584 }
2585 }
2586 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002587 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002588 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002589 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2590 if (!child_valobj_sp)
2591 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002592 if (!child_valobj_sp)
Greg Claytonafacd142011-09-02 01:15:17 +00002593 if (root->HasSyntheticValue() && root->GetSyntheticValue(eUseSyntheticFilter)->GetNumChildren() > index)
2594 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002595 if (child_valobj_sp)
2596 {
2597 root = child_valobj_sp;
2598 *first_unparsed = end+1; // skip ]
2599 *final_result = ValueObject::ePlain;
2600 continue;
2601 }
2602 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002603 {
2604 *first_unparsed = expression_cstr;
2605 *reason_to_stop = ValueObject::eNoSuchChild;
2606 *final_result = ValueObject::eInvalid;
2607 return ValueObjectSP();
2608 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002609 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002610 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002611 {
2612 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 +00002613 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002614 {
2615 Error error;
2616 root = root->Dereference(error);
2617 if (error.Fail() || !root.get())
2618 {
2619 *first_unparsed = expression_cstr;
2620 *reason_to_stop = ValueObject::eDereferencingFailed;
2621 *final_result = ValueObject::eInvalid;
2622 return ValueObjectSP();
2623 }
2624 else
2625 {
2626 *what_next = eNothing;
2627 continue;
2628 }
2629 }
2630 else
2631 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002632 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Claytonafacd142011-09-02 01:15:17 +00002633 root->GetClangType()) == eLanguageTypeObjC
Enrico Granata27b625e2011-08-09 01:04:56 +00002634 &&
2635 ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2636 &&
2637 root->HasSyntheticValue()
2638 &&
2639 options.m_no_synthetic_children == false)
2640 {
Greg Claytonafacd142011-09-02 01:15:17 +00002641 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002642 }
2643 else
2644 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002645 if (!root.get())
2646 {
2647 *first_unparsed = expression_cstr;
2648 *reason_to_stop = ValueObject::eNoSuchChild;
2649 *final_result = ValueObject::eInvalid;
2650 return ValueObjectSP();
2651 }
2652 else
2653 {
2654 *first_unparsed = end+1; // skip ]
2655 *final_result = ValueObject::ePlain;
2656 continue;
2657 }
2658 }
2659 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002660 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002661 {
2662 root = root->GetSyntheticBitFieldChild(index, index, true);
2663 if (!root.get())
2664 {
2665 *first_unparsed = expression_cstr;
2666 *reason_to_stop = ValueObject::eNoSuchChild;
2667 *final_result = ValueObject::eInvalid;
2668 return ValueObjectSP();
2669 }
2670 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2671 {
2672 *first_unparsed = end+1; // skip ]
2673 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2674 *final_result = ValueObject::eBitfield;
2675 return root;
2676 }
2677 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002678 else if (root->HasSyntheticValue() && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002679 {
Greg Claytonafacd142011-09-02 01:15:17 +00002680 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002681 if (!root.get())
2682 {
2683 *first_unparsed = expression_cstr;
2684 *reason_to_stop = ValueObject::eNoSuchChild;
2685 *final_result = ValueObject::eInvalid;
2686 return ValueObjectSP();
2687 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002688 else
2689 {
2690 *first_unparsed = end+1; // skip ]
2691 *final_result = ValueObject::ePlain;
2692 continue;
2693 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002694 }
2695 else
2696 {
2697 *first_unparsed = expression_cstr;
2698 *reason_to_stop = ValueObject::eNoSuchChild;
2699 *final_result = ValueObject::eInvalid;
2700 return ValueObjectSP();
2701 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002702 }
2703 else // we have a low and a high index
2704 {
2705 char *end = NULL;
2706 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2707 if (!end || end != separator_position) // if something weird is in our way return an error
2708 {
2709 *first_unparsed = expression_cstr;
2710 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2711 *final_result = ValueObject::eInvalid;
2712 return ValueObjectSP();
2713 }
2714 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2715 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2716 {
2717 *first_unparsed = expression_cstr;
2718 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2719 *final_result = ValueObject::eInvalid;
2720 return ValueObjectSP();
2721 }
2722 if (index_lower > index_higher) // swap indices if required
2723 {
2724 unsigned long temp = index_lower;
2725 index_lower = index_higher;
2726 index_higher = temp;
2727 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002728 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002729 {
2730 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2731 if (!root.get())
2732 {
2733 *first_unparsed = expression_cstr;
2734 *reason_to_stop = ValueObject::eNoSuchChild;
2735 *final_result = ValueObject::eInvalid;
2736 return ValueObjectSP();
2737 }
2738 else
2739 {
2740 *first_unparsed = end+1; // skip ]
2741 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2742 *final_result = ValueObject::eBitfield;
2743 return root;
2744 }
2745 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002746 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 +00002747 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002748 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002749 {
2750 Error error;
2751 root = root->Dereference(error);
2752 if (error.Fail() || !root.get())
2753 {
2754 *first_unparsed = expression_cstr;
2755 *reason_to_stop = ValueObject::eDereferencingFailed;
2756 *final_result = ValueObject::eInvalid;
2757 return ValueObjectSP();
2758 }
2759 else
2760 {
2761 *what_next = ValueObject::eNothing;
2762 continue;
2763 }
2764 }
2765 else
2766 {
2767 *first_unparsed = expression_cstr;
2768 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2769 *final_result = ValueObject::eBoundedRange;
2770 return root;
2771 }
2772 }
2773 break;
2774 }
2775 default: // some non-separator is in the way
2776 {
2777 *first_unparsed = expression_cstr;
2778 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2779 *final_result = ValueObject::eInvalid;
2780 return ValueObjectSP();
2781 break;
2782 }
2783 }
2784 }
2785}
2786
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002787int
2788ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2789 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002790 ValueObjectSP root,
2791 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002792 ExpressionPathScanEndReason* reason_to_stop,
2793 ExpressionPathEndResultType* final_result,
2794 const GetValueForExpressionPathOptions& options,
2795 ExpressionPathAftermath* what_next)
2796{
2797 if (!root.get())
2798 return 0;
2799
2800 *first_unparsed = expression_cstr;
2801
2802 while (true)
2803 {
2804
2805 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2806
Greg Claytonafacd142011-09-02 01:15:17 +00002807 clang_type_t root_clang_type = root->GetClangType();
2808 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002809 Flags root_clang_type_info,pointee_clang_type_info;
2810
2811 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2812 if (pointee_clang_type)
2813 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2814
2815 if (!expression_cstr || *expression_cstr == '\0')
2816 {
2817 *reason_to_stop = ValueObject::eEndOfString;
2818 list->Append(root);
2819 return 1;
2820 }
2821
2822 switch (*expression_cstr)
2823 {
2824 case '[':
2825 {
2826 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2827 {
2828 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2829 {
2830 *first_unparsed = expression_cstr;
2831 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2832 *final_result = ValueObject::eInvalid;
2833 return 0;
2834 }
2835 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2836 {
2837 *first_unparsed = expression_cstr;
2838 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2839 *final_result = ValueObject::eInvalid;
2840 return 0;
2841 }
2842 }
2843 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2844 {
2845 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2846 {
2847 *first_unparsed = expression_cstr;
2848 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2849 *final_result = ValueObject::eInvalid;
2850 return 0;
2851 }
2852 else // expand this into list
2853 {
2854 int max_index = root->GetNumChildren() - 1;
2855 for (int index = 0; index < max_index; index++)
2856 {
2857 ValueObjectSP child =
2858 root->GetChildAtIndex(index, true);
2859 list->Append(child);
2860 }
2861 *first_unparsed = expression_cstr+2;
2862 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2863 *final_result = ValueObject::eValueObjectList;
2864 return max_index; // tell me number of items I added to the VOList
2865 }
2866 }
2867 const char *separator_position = ::strchr(expression_cstr+1,'-');
2868 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2869 if (!close_bracket_position) // if there is no ], this is a syntax error
2870 {
2871 *first_unparsed = expression_cstr;
2872 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2873 *final_result = ValueObject::eInvalid;
2874 return 0;
2875 }
2876 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2877 {
2878 char *end = NULL;
2879 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2880 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2881 {
2882 *first_unparsed = expression_cstr;
2883 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2884 *final_result = ValueObject::eInvalid;
2885 return 0;
2886 }
2887 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2888 {
2889 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2890 {
2891 int max_index = root->GetNumChildren() - 1;
2892 for (int index = 0; index < max_index; index++)
2893 {
2894 ValueObjectSP child =
2895 root->GetChildAtIndex(index, true);
2896 list->Append(child);
2897 }
2898 *first_unparsed = expression_cstr+2;
2899 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2900 *final_result = ValueObject::eValueObjectList;
2901 return max_index; // tell me number of items I added to the VOList
2902 }
2903 else
2904 {
2905 *first_unparsed = expression_cstr;
2906 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2907 *final_result = ValueObject::eInvalid;
2908 return 0;
2909 }
2910 }
2911 // from here on we do have a valid index
2912 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2913 {
2914 root = root->GetChildAtIndex(index, true);
2915 if (!root.get())
2916 {
2917 *first_unparsed = expression_cstr;
2918 *reason_to_stop = ValueObject::eNoSuchChild;
2919 *final_result = ValueObject::eInvalid;
2920 return 0;
2921 }
2922 else
2923 {
2924 list->Append(root);
2925 *first_unparsed = end+1; // skip ]
2926 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2927 *final_result = ValueObject::eValueObjectList;
2928 return 1;
2929 }
2930 }
2931 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2932 {
2933 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
2934 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2935 {
2936 Error error;
2937 root = root->Dereference(error);
2938 if (error.Fail() || !root.get())
2939 {
2940 *first_unparsed = expression_cstr;
2941 *reason_to_stop = ValueObject::eDereferencingFailed;
2942 *final_result = ValueObject::eInvalid;
2943 return 0;
2944 }
2945 else
2946 {
2947 *what_next = eNothing;
2948 continue;
2949 }
2950 }
2951 else
2952 {
2953 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2954 if (!root.get())
2955 {
2956 *first_unparsed = expression_cstr;
2957 *reason_to_stop = ValueObject::eNoSuchChild;
2958 *final_result = ValueObject::eInvalid;
2959 return 0;
2960 }
2961 else
2962 {
2963 list->Append(root);
2964 *first_unparsed = end+1; // skip ]
2965 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2966 *final_result = ValueObject::eValueObjectList;
2967 return 1;
2968 }
2969 }
2970 }
2971 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2972 {
2973 root = root->GetSyntheticBitFieldChild(index, index, true);
2974 if (!root.get())
2975 {
2976 *first_unparsed = expression_cstr;
2977 *reason_to_stop = ValueObject::eNoSuchChild;
2978 *final_result = ValueObject::eInvalid;
2979 return 0;
2980 }
2981 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2982 {
2983 list->Append(root);
2984 *first_unparsed = end+1; // skip ]
2985 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2986 *final_result = ValueObject::eValueObjectList;
2987 return 1;
2988 }
2989 }
2990 }
2991 else // we have a low and a high index
2992 {
2993 char *end = NULL;
2994 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2995 if (!end || end != separator_position) // if something weird is in our way return an error
2996 {
2997 *first_unparsed = expression_cstr;
2998 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2999 *final_result = ValueObject::eInvalid;
3000 return 0;
3001 }
3002 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3003 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3004 {
3005 *first_unparsed = expression_cstr;
3006 *reason_to_stop = ValueObject::eUnexpectedSymbol;
3007 *final_result = ValueObject::eInvalid;
3008 return 0;
3009 }
3010 if (index_lower > index_higher) // swap indices if required
3011 {
3012 unsigned long temp = index_lower;
3013 index_lower = index_higher;
3014 index_higher = temp;
3015 }
3016 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3017 {
3018 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3019 if (!root.get())
3020 {
3021 *first_unparsed = expression_cstr;
3022 *reason_to_stop = ValueObject::eNoSuchChild;
3023 *final_result = ValueObject::eInvalid;
3024 return 0;
3025 }
3026 else
3027 {
3028 list->Append(root);
3029 *first_unparsed = end+1; // skip ]
3030 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
3031 *final_result = ValueObject::eValueObjectList;
3032 return 1;
3033 }
3034 }
3035 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
3036 *what_next == ValueObject::eDereference &&
3037 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3038 {
3039 Error error;
3040 root = root->Dereference(error);
3041 if (error.Fail() || !root.get())
3042 {
3043 *first_unparsed = expression_cstr;
3044 *reason_to_stop = ValueObject::eDereferencingFailed;
3045 *final_result = ValueObject::eInvalid;
3046 return 0;
3047 }
3048 else
3049 {
3050 *what_next = ValueObject::eNothing;
3051 continue;
3052 }
3053 }
3054 else
3055 {
Johnny Chen44805302011-07-19 19:48:13 +00003056 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003057 index <= index_higher; index++)
3058 {
3059 ValueObjectSP child =
3060 root->GetChildAtIndex(index, true);
3061 list->Append(child);
3062 }
3063 *first_unparsed = end+1;
3064 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
3065 *final_result = ValueObject::eValueObjectList;
3066 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3067 }
3068 }
3069 break;
3070 }
3071 default: // some non-[ separator, or something entirely wrong, is in the way
3072 {
3073 *first_unparsed = expression_cstr;
3074 *reason_to_stop = ValueObject::eUnexpectedSymbol;
3075 *final_result = ValueObject::eInvalid;
3076 return 0;
3077 break;
3078 }
3079 }
3080 }
3081}
3082
Enrico Granata0c489f52012-03-01 04:24:26 +00003083static void
3084DumpValueObject_Impl (Stream &s,
3085 ValueObject *valobj,
3086 const ValueObject::DumpValueObjectOptions& options,
3087 uint32_t ptr_depth,
3088 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003089{
Greg Clayton007d5be2011-05-30 00:49:24 +00003090 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003091 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003092 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003093
Enrico Granata0c489f52012-03-01 04:24:26 +00003094 const char *root_valobj_name =
3095 options.m_root_valobj_name.empty() ?
3096 valobj->GetName().AsCString() :
3097 options.m_root_valobj_name.c_str();
3098
3099 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003100 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003101 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003102 if (dynamic_value)
3103 valobj = dynamic_value;
3104 }
3105
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003106 clang_type_t clang_type = valobj->GetClangType();
3107
Greg Clayton73b472d2010-10-27 03:32:59 +00003108 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003109 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003110 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3111 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003112
Enrico Granata0c489f52012-03-01 04:24:26 +00003113 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003114
3115 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003116 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003117 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003118 {
Jim Ingham6035b672011-03-31 00:19:25 +00003119 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003120 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003121
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003122 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003123
Greg Clayton7c8a9662010-11-02 01:50:16 +00003124 // Always show the type for the top level items.
Enrico Granata0c489f52012-03-01 04:24:26 +00003125 if (options.m_show_types || (curr_depth == 0 && !options.m_flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003126 {
Enrico Granata9910bc82011-08-03 02:18:51 +00003127 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
3128 s.Printf("(%s", typeName);
3129 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003130 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003131 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003132 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003133 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003134 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3135 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003136 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003137 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003138 else
3139 {
3140 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3141 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003142 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003143 else
3144 {
3145 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3146 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003147 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003148 else
3149 s.Printf(", dynamic type: %s) ",
3150 runtime->GetActualTypeName(isa).GetCString());
3151 }
3152 }
3153 }
3154 else
3155 s.Printf(") ");
3156 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003157
Greg Clayton1d3afba2010-10-05 00:00:42 +00003158
Enrico Granata0c489f52012-03-01 04:24:26 +00003159 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003160 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003161 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003162 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003163 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003164 s.PutCString(" =");
3165 }
3166 else
3167 {
3168 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3169 s.Printf ("%s =", name_cstr);
3170 }
3171
Enrico Granata0c489f52012-03-01 04:24:26 +00003172 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003173 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003174 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003175 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003176 }
3177
Enrico Granata0c489f52012-03-01 04:24:26 +00003178 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003179 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003180 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003181 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003182 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003183
Enrico Granata0c489f52012-03-01 04:24:26 +00003184 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003185 entry = NULL;
3186
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003187 if (err_cstr == NULL)
3188 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003189 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003190 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003191 valobj->GetValueAsCString(options.m_format,
3192 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003193 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003194 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003195 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003196 val_cstr = valobj->GetValueAsCString();
3197 if (val_cstr)
3198 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003199 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003200 err_cstr = valobj->GetError().AsCString();
3201 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003202
3203 if (err_cstr)
3204 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003205 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003206 }
3207 else
3208 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003209 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003210 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003211 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003212 if (options.m_omit_summary_depth == 0)
3213 {
3214 if (options.m_summary_sp)
3215 {
3216 valobj->GetSummaryAsCString(entry, summary_str);
3217 sum_cstr = summary_str.c_str();
3218 }
3219 else
3220 sum_cstr = valobj->GetSummaryAsCString();
3221 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003222
Greg Clayton6efba4f2012-01-26 21:08:30 +00003223 // Make sure we have a value and make sure the summary didn't
3224 // specify that the value should not be printed
3225 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3226 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003227
Enrico Granata9dd75c82011-07-15 23:30:15 +00003228 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003229 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003230
Enrico Granata0c489f52012-03-01 04:24:26 +00003231 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003232 {
Jim Ingham6035b672011-03-31 00:19:25 +00003233 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003234 if (object_desc)
3235 s.Printf(" %s\n", object_desc);
3236 else
Sean Callanan672ad942010-10-23 00:18:49 +00003237 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003238 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003239 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003240 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003241
Enrico Granata0c489f52012-03-01 04:24:26 +00003242 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003243 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003244 // We will show children for all concrete types. We won't show
3245 // pointer contents unless a pointer depth has been specified.
3246 // We won't reference contents unless the reference is the
3247 // root object (depth of zero).
3248 bool print_children = true;
3249
3250 // Use a new temporary pointer depth in case we override the
3251 // current pointer depth below...
3252 uint32_t curr_ptr_depth = ptr_depth;
3253
3254 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3255 if (is_ptr || is_ref)
3256 {
3257 // We have a pointer or reference whose value is an address.
3258 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003259 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003260 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003261 print_children = false;
3262
3263 else if (is_ref && curr_depth == 0)
3264 {
3265 // If this is the root object (depth is zero) that we are showing
3266 // and it is a reference, and no pointer depth has been supplied
3267 // print out what it references. Don't do this at deeper depths
3268 // otherwise we can end up with infinite recursion...
3269 curr_ptr_depth = 1;
3270 }
3271
3272 if (curr_ptr_depth == 0)
3273 print_children = false;
3274 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003275
Enrico Granata0a3958e2011-07-02 00:25:22 +00003276 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003277 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003278 ValueObjectSP synth_valobj = valobj->GetSyntheticValue (options.m_use_synthetic ?
Greg Claytoncc4d0142012-02-17 07:49:44 +00003279 eUseSyntheticFilter :
3280 eNoSyntheticFilter);
Enrico Granatac482a192011-08-17 22:13:59 +00003281 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003282 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003283 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003284 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003285 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003286 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003287 if (print_valobj)
3288 s.EOL();
3289 }
3290 else
3291 {
3292 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003293 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003294 s.IndentMore();
3295 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003296
Greg Claytoncc4d0142012-02-17 07:49:44 +00003297 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003298
Enrico Granata0c489f52012-03-01 04:24:26 +00003299 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003300 {
3301 num_children = max_num_children;
3302 print_dotdotdot = true;
3303 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003304
Enrico Granata0c489f52012-03-01 04:24:26 +00003305 ValueObject::DumpValueObjectOptions child_options(options);
3306 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3307 child_options.SetScopeChecked(true)
3308 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003309 for (uint32_t idx=0; idx<num_children; ++idx)
3310 {
Enrico Granatac482a192011-08-17 22:13:59 +00003311 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003312 if (child_sp.get())
3313 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003314 DumpValueObject_Impl (s,
3315 child_sp.get(),
3316 child_options,
3317 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3318 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003319 }
3320 }
3321
Enrico Granata0c489f52012-03-01 04:24:26 +00003322 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003323 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003324 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003325 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003326 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3327 Target *target = exe_ctx.GetTargetPtr();
3328 if (target)
3329 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003330 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003331 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003332 s.IndentLess();
3333 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003334 }
3335 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003336 else if (has_children)
3337 {
3338 // Aggregate, no children...
3339 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003340 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003341 }
3342 else
3343 {
3344 if (print_valobj)
3345 s.EOL();
3346 }
3347
Greg Clayton1d3afba2010-10-05 00:00:42 +00003348 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003349 else
3350 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003351 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003352 }
3353 }
3354 else
3355 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003356 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003357 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003358 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003359 }
3360 }
3361 }
3362 }
3363}
3364
Enrico Granata0c489f52012-03-01 04:24:26 +00003365void
3366ValueObject::DumpValueObject (Stream &s,
3367 ValueObject *valobj)
3368{
3369
3370 if (!valobj)
3371 return;
3372
3373 DumpValueObject_Impl(s,
3374 valobj,
3375 DumpValueObjectOptions::DefaultOptions(),
3376 0,
3377 0);
3378}
3379
3380void
3381ValueObject::DumpValueObject (Stream &s,
3382 ValueObject *valobj,
3383 const DumpValueObjectOptions& options)
3384{
3385 DumpValueObject_Impl(s,
3386 valobj,
3387 options,
3388 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3389 0 // current object depth is 0 since we are just starting
3390 );
3391}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003392
3393ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003394ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003395{
3396 ValueObjectSP valobj_sp;
3397
Enrico Granatac3e320a2011-08-02 17:27:39 +00003398 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003399 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003400 ExecutionContext exe_ctx (GetExecutionContextRef());
3401 clang::ASTContext *ast = GetClangAST ();
3402
3403 DataExtractor data;
3404 data.SetByteOrder (m_data.GetByteOrder());
3405 data.SetAddressByteSize(m_data.GetAddressByteSize());
3406
Greg Claytone72dfb32012-02-24 01:59:29 +00003407 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003408
3409 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3410 ast,
3411 GetClangType(),
3412 name,
3413 data,
3414 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003415 }
Jim Ingham6035b672011-03-31 00:19:25 +00003416
3417 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003418 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003419 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003420 }
3421 return valobj_sp;
3422}
3423
Greg Claytonafacd142011-09-02 01:15:17 +00003424ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003425ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003426{
Jim Ingham58b59f92011-04-22 23:53:53 +00003427 if (m_deref_valobj)
3428 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003429
Greg Clayton54979cd2010-12-15 05:08:08 +00003430 const bool is_pointer_type = IsPointerType();
3431 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003432 {
3433 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003434 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003435
3436 std::string child_name_str;
3437 uint32_t child_byte_size = 0;
3438 int32_t child_byte_offset = 0;
3439 uint32_t child_bitfield_bit_size = 0;
3440 uint32_t child_bitfield_bit_offset = 0;
3441 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003442 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003443 const bool transparent_pointers = false;
3444 clang::ASTContext *clang_ast = GetClangAST();
3445 clang_type_t clang_type = GetClangType();
3446 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003447
Greg Claytoncc4d0142012-02-17 07:49:44 +00003448 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003449
3450 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3451 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003452 GetName().GetCString(),
3453 clang_type,
3454 0,
3455 transparent_pointers,
3456 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003457 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003458 child_name_str,
3459 child_byte_size,
3460 child_byte_offset,
3461 child_bitfield_bit_size,
3462 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003463 child_is_base_class,
3464 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003465 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003466 {
3467 ConstString child_name;
3468 if (!child_name_str.empty())
3469 child_name.SetCString (child_name_str.c_str());
3470
Jim Ingham58b59f92011-04-22 23:53:53 +00003471 m_deref_valobj = new ValueObjectChild (*this,
3472 clang_ast,
3473 child_clang_type,
3474 child_name,
3475 child_byte_size,
3476 child_byte_offset,
3477 child_bitfield_bit_size,
3478 child_bitfield_bit_offset,
3479 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003480 child_is_deref_of_parent,
3481 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003482 }
3483 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003484
Jim Ingham58b59f92011-04-22 23:53:53 +00003485 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003486 {
3487 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003488 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003489 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003490 else
3491 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003492 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003493 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003494
3495 if (is_pointer_type)
3496 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3497 else
3498 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003499 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003500 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003501}
3502
Greg Claytonafacd142011-09-02 01:15:17 +00003503ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003504ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003505{
Jim Ingham78a685a2011-04-16 00:01:13 +00003506 if (m_addr_of_valobj_sp)
3507 return m_addr_of_valobj_sp;
3508
Greg Claytone0d378b2011-03-24 21:19:54 +00003509 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003510 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003511 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003512 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003513 if (addr != LLDB_INVALID_ADDRESS)
3514 {
3515 switch (address_type)
3516 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003517 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003518 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003519 {
3520 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003521 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003522 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3523 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003524 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003525
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003526 case eAddressTypeFile:
3527 case eAddressTypeLoad:
3528 case eAddressTypeHost:
3529 {
3530 clang::ASTContext *ast = GetClangAST();
3531 clang_type_t clang_type = GetClangType();
3532 if (ast && clang_type)
3533 {
3534 std::string name (1, '&');
3535 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003536 ExecutionContext exe_ctx (GetExecutionContextRef());
3537 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003538 ast,
3539 ClangASTContext::CreatePointerType (ast, clang_type),
3540 ConstString (name.c_str()),
3541 addr,
3542 eAddressTypeInvalid,
3543 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003544 }
3545 }
3546 break;
3547 }
3548 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003549 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003550}
3551
Greg Clayton9a142cf2012-02-03 05:34:10 +00003552ValueObjectSP
3553ValueObject::Cast (const ClangASTType &clang_ast_type)
3554{
Greg Clayton81e871e2012-02-04 02:27:34 +00003555 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003556}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003557
Greg Claytonafacd142011-09-02 01:15:17 +00003558ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003559ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3560{
Greg Claytonafacd142011-09-02 01:15:17 +00003561 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003562 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003563 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003564
3565 if (ptr_value != LLDB_INVALID_ADDRESS)
3566 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003567 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003568 ExecutionContext exe_ctx (GetExecutionContextRef());
3569 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003570 name,
3571 ptr_addr,
3572 clang_ast_type);
3573 }
3574 return valobj_sp;
3575}
3576
Greg Claytonafacd142011-09-02 01:15:17 +00003577ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003578ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3579{
Greg Claytonafacd142011-09-02 01:15:17 +00003580 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003581 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003582 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003583
3584 if (ptr_value != LLDB_INVALID_ADDRESS)
3585 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003586 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003587 ExecutionContext exe_ctx (GetExecutionContextRef());
3588 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003589 name,
3590 ptr_addr,
3591 type_sp);
3592 }
3593 return valobj_sp;
3594}
3595
Jim Ingham6035b672011-03-31 00:19:25 +00003596ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003597 m_mod_id(),
3598 m_exe_ctx_ref(),
3599 m_needs_update (true),
3600 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003601{
3602}
3603
3604ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003605 m_mod_id(),
3606 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003607 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003608 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003609{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003610 ExecutionContext exe_ctx(exe_scope);
3611 TargetSP target_sp (exe_ctx.GetTargetSP());
3612 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003613 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003614 m_exe_ctx_ref.SetTargetSP (target_sp);
3615 ProcessSP process_sp (exe_ctx.GetProcessSP());
3616 if (!process_sp)
3617 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003618
Greg Claytoncc4d0142012-02-17 07:49:44 +00003619 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003620 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003621 m_mod_id = process_sp->GetModID();
3622 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003623
Greg Claytoncc4d0142012-02-17 07:49:44 +00003624 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003625
Greg Claytoncc4d0142012-02-17 07:49:44 +00003626 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003627 {
3628 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003629 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003630 }
Jim Ingham6035b672011-03-31 00:19:25 +00003631
Greg Claytoncc4d0142012-02-17 07:49:44 +00003632 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003633 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003634 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003635
Greg Claytoncc4d0142012-02-17 07:49:44 +00003636 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3637 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003638 {
3639 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003640 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003641 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003642 if (frame_sp)
3643 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003644 }
3645 }
3646 }
Jim Ingham6035b672011-03-31 00:19:25 +00003647}
3648
3649ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003650 m_mod_id(),
3651 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3652 m_needs_update (true),
3653 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003654{
3655}
3656
3657ValueObject::EvaluationPoint::~EvaluationPoint ()
3658{
3659}
3660
Jim Ingham6035b672011-03-31 00:19:25 +00003661// This function checks the EvaluationPoint against the current process state. If the current
3662// state matches the evaluation point, or the evaluation point is already invalid, then we return
3663// false, meaning "no change". If the current state is different, we update our state, and return
3664// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3665// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003666// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003667
3668bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003669ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003670{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003671
3672 // 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 +00003673 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003674
Greg Claytoncc4d0142012-02-17 07:49:44 +00003675 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003676 return false;
3677
Jim Ingham6035b672011-03-31 00:19:25 +00003678 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003679 Process *process = exe_ctx.GetProcessPtr();
3680 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003681 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003682
Jim Ingham6035b672011-03-31 00:19:25 +00003683 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003684 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003685
Jim Ingham78a685a2011-04-16 00:01:13 +00003686 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3687 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003688 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003689 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003690
3691 bool changed;
3692
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003693 if (m_mod_id.IsValid())
3694 {
3695 if (m_mod_id == current_mod_id)
3696 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003697 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003698 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003699 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003700 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003701 else
3702 {
3703 m_mod_id = current_mod_id;
3704 m_needs_update = true;
3705 changed = true;
3706 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003707 }
Jim Ingham6035b672011-03-31 00:19:25 +00003708
Jim Ingham73ca05a2011-12-17 01:35:57 +00003709 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3710 // That way we'll be sure to return a valid exe_scope.
3711 // 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 +00003712
Greg Claytoncc4d0142012-02-17 07:49:44 +00003713 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003714 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003715 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3716 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003717 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003718 if (m_exe_ctx_ref.HasFrameRef())
3719 {
3720 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3721 if (!frame_sp)
3722 {
3723 // We used to have a frame, but now it is gone
3724 SetInvalid();
3725 }
3726 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003727 }
Jim Ingham6035b672011-03-31 00:19:25 +00003728 else
3729 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003730 // We used to have a thread, but now it is gone
3731 SetInvalid();
Jim Ingham6035b672011-03-31 00:19:25 +00003732 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003733
Jim Ingham6035b672011-03-31 00:19:25 +00003734 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003735 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003736}
3737
Jim Ingham61be0902011-05-02 18:13:59 +00003738void
3739ValueObject::EvaluationPoint::SetUpdated ()
3740{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003741 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3742 if (process_sp)
3743 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003744 m_first_update = false;
3745 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003746}
3747
3748
Greg Claytoncc4d0142012-02-17 07:49:44 +00003749//bool
3750//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3751//{
3752// if (!IsValid())
3753// return false;
3754//
3755// bool needs_update = false;
3756//
3757// // The target has to be non-null, and the
3758// Target *target = exe_scope->CalculateTarget();
3759// if (target != NULL)
3760// {
3761// Target *old_target = m_target_sp.get();
3762// assert (target == old_target);
3763// Process *process = exe_scope->CalculateProcess();
3764// if (process != NULL)
3765// {
3766// // FOR NOW - assume you can't update variable objects across process boundaries.
3767// Process *old_process = m_process_sp.get();
3768// assert (process == old_process);
3769// ProcessModID current_mod_id = process->GetModID();
3770// if (m_mod_id != current_mod_id)
3771// {
3772// needs_update = true;
3773// m_mod_id = current_mod_id;
3774// }
3775// // See if we're switching the thread or stack context. If no thread is given, this is
3776// // being evaluated in a global context.
3777// Thread *thread = exe_scope->CalculateThread();
3778// if (thread != NULL)
3779// {
3780// user_id_t new_thread_index = thread->GetIndexID();
3781// if (new_thread_index != m_thread_id)
3782// {
3783// needs_update = true;
3784// m_thread_id = new_thread_index;
3785// m_stack_id.Clear();
3786// }
3787//
3788// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3789// if (new_frame != NULL)
3790// {
3791// if (new_frame->GetStackID() != m_stack_id)
3792// {
3793// needs_update = true;
3794// m_stack_id = new_frame->GetStackID();
3795// }
3796// }
3797// else
3798// {
3799// m_stack_id.Clear();
3800// needs_update = true;
3801// }
3802// }
3803// else
3804// {
3805// // If this had been given a thread, and now there is none, we should update.
3806// // Otherwise we don't have to do anything.
3807// if (m_thread_id != LLDB_INVALID_UID)
3808// {
3809// m_thread_id = LLDB_INVALID_UID;
3810// m_stack_id.Clear();
3811// needs_update = true;
3812// }
3813// }
3814// }
3815// else
3816// {
3817// // If there is no process, then we don't need to update anything.
3818// // But if we're switching from having a process to not, we should try to update.
3819// if (m_process_sp.get() != NULL)
3820// {
3821// needs_update = true;
3822// m_process_sp.reset();
3823// m_thread_id = LLDB_INVALID_UID;
3824// m_stack_id.Clear();
3825// }
3826// }
3827// }
3828// else
3829// {
3830// // If there's no target, nothing can change so we don't need to update anything.
3831// // But if we're switching from having a target to not, we should try to update.
3832// if (m_target_sp.get() != NULL)
3833// {
3834// needs_update = true;
3835// m_target_sp.reset();
3836// m_process_sp.reset();
3837// m_thread_id = LLDB_INVALID_UID;
3838// m_stack_id.Clear();
3839// }
3840// }
3841// if (!m_needs_update)
3842// m_needs_update = needs_update;
3843//
3844// return needs_update;
3845//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003846
3847void
3848ValueObject::ClearUserVisibleData()
3849{
3850 m_location_str.clear();
3851 m_value_str.clear();
3852 m_summary_str.clear();
3853 m_object_desc_str.clear();
Enrico Granata0c489f52012-03-01 04:24:26 +00003854 m_synthetic_value = NULL;
Greg Clayton48ca8b82012-01-07 20:58:07 +00003855 m_is_getting_summary = false;
Johnny Chen44805302011-07-19 19:48:13 +00003856}
Enrico Granata9128ee22011-09-06 19:20:51 +00003857
3858SymbolContextScope *
3859ValueObject::GetSymbolContextScope()
3860{
3861 if (m_parent)
3862 {
3863 if (!m_parent->IsPointerOrReferenceType())
3864 return m_parent->GetSymbolContextScope();
3865 }
3866 return NULL;
3867}