blob: 3d82995b08381eb652b2795c693b585e1e8623c9 [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 Granata0c489f52012-03-01 04:24:26 +00001207 GetValueAsCString(my_format, m_value_str);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001208 }
1209 if (m_value_str.empty())
1210 return NULL;
1211 return m_value_str.c_str();
1212}
1213
Enrico Granatac3e320a2011-08-02 17:27:39 +00001214// if > 8bytes, 0 is returned. this method should mostly be used
1215// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001216uint64_t
1217ValueObject::GetValueAsUnsigned (uint64_t fail_value)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001218{
1219 // If our byte size is zero this is an aggregate type that has children
1220 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1221 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001222 Scalar scalar;
1223 if (ResolveValue (scalar))
1224 return scalar.GetRawBits64(fail_value);
Enrico Granatac3e320a2011-08-02 17:27:39 +00001225 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001226 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001227}
1228
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001229bool
1230ValueObject::GetPrintableRepresentation(Stream& s,
1231 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001232 Format custom_format)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001233{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001234
Greg Claytonafacd142011-09-02 01:15:17 +00001235 if (custom_format != eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001236 SetFormat(custom_format);
1237
1238 const char * return_value;
Enrico Granatacd1c0232011-08-04 23:37:18 +00001239 std::string alloc_mem;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001240
1241 switch(val_obj_display)
1242 {
1243 case eDisplayValue:
1244 return_value = GetValueAsCString();
1245 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001246
Enrico Granata0a3958e2011-07-02 00:25:22 +00001247 case eDisplaySummary:
Greg Clayton48ca8b82012-01-07 20:58:07 +00001248 return_value = GetSummaryAsCString();
1249 break;
1250
Enrico Granata0a3958e2011-07-02 00:25:22 +00001251 case eDisplayLanguageSpecific:
1252 return_value = GetObjectDescription();
1253 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001254
Enrico Granataf2bbf712011-07-15 02:26:42 +00001255 case eDisplayLocation:
1256 return_value = GetLocationAsCString();
1257 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001258
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001259 case eDisplayChildrenCount:
Greg Clayton48ca8b82012-01-07 20:58:07 +00001260 {
1261 alloc_mem.resize(512);
1262 return_value = &alloc_mem[0];
1263 int count = GetNumChildren();
1264 snprintf((char*)return_value, 512, "%d", count);
1265 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001266 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001267
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001268 case eDisplayType:
1269 return_value = GetTypeName().AsCString();
1270 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001271
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001272 default:
1273 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001274 }
1275
Enrico Granata855cd902011-09-06 22:59:55 +00001276 if (!return_value)
Enrico Granata9fc19442011-07-06 02:13:41 +00001277 {
Enrico Granata9fc19442011-07-06 02:13:41 +00001278 if (val_obj_display == eDisplayValue)
Enrico Granata855cd902011-09-06 22:59:55 +00001279 return_value = GetSummaryAsCString();
Enrico Granata9fc19442011-07-06 02:13:41 +00001280 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +00001281 {
1282 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1283 {
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001284 // this thing has no value, and it seems to have no summary
1285 // some combination of unitialized data and other factors can also
Enrico Granata855cd902011-09-06 22:59:55 +00001286 // raise this condition, so let's print a nice generic description
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001287 {
1288 alloc_mem.resize(684);
1289 return_value = &alloc_mem[0];
1290 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1291 }
Enrico Granatae992a082011-07-22 17:03:19 +00001292 }
1293 else
1294 return_value = GetValueAsCString();
1295 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001296 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001297
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001298 if (return_value)
1299 s.PutCString(return_value);
1300 else
Enrico Granata88da35f2011-08-23 21:26:09 +00001301 {
1302 if (m_error.Fail())
1303 s.Printf("<%s>", m_error.AsCString());
1304 else if (val_obj_display == eDisplaySummary)
1305 s.PutCString("<no summary available>");
1306 else if (val_obj_display == eDisplayValue)
1307 s.PutCString("<no value available>");
1308 else if (val_obj_display == eDisplayLanguageSpecific)
1309 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1310 else
1311 s.PutCString("<no printable representation>");
1312 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001313
1314 // we should only return false here if we could not do *anything*
1315 // even if we have an error message as output, that's a success
1316 // from our callers' perspective, so return true
1317 return true;
1318
Enrico Granata0a3958e2011-07-02 00:25:22 +00001319}
1320
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001321// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1322// this call up to date by returning true for your new special cases. We will eventually move
1323// to checking this call result before trying to display special cases
1324bool
1325ValueObject::HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001326 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001327{
1328 clang_type_t elem_or_pointee_type;
1329 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1330
1331 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1332 && val_obj_display == ValueObject::eDisplayValue)
1333 {
1334 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001335 (custom_format == eFormatCString ||
1336 custom_format == eFormatCharArray ||
1337 custom_format == eFormatChar ||
1338 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001339 return true;
1340
1341 if (flags.Test(ClangASTContext::eTypeIsArray))
1342 {
Greg Claytonafacd142011-09-02 01:15:17 +00001343 if ((custom_format == eFormatBytes) ||
1344 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001345 return true;
1346
Greg Claytonafacd142011-09-02 01:15:17 +00001347 if ((custom_format == eFormatVectorOfChar) ||
1348 (custom_format == eFormatVectorOfFloat32) ||
1349 (custom_format == eFormatVectorOfFloat64) ||
1350 (custom_format == eFormatVectorOfSInt16) ||
1351 (custom_format == eFormatVectorOfSInt32) ||
1352 (custom_format == eFormatVectorOfSInt64) ||
1353 (custom_format == eFormatVectorOfSInt8) ||
1354 (custom_format == eFormatVectorOfUInt128) ||
1355 (custom_format == eFormatVectorOfUInt16) ||
1356 (custom_format == eFormatVectorOfUInt32) ||
1357 (custom_format == eFormatVectorOfUInt64) ||
1358 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001359 return true;
1360 }
1361 }
1362 return false;
1363}
1364
Enrico Granata9fc19442011-07-06 02:13:41 +00001365bool
1366ValueObject::DumpPrintableRepresentation(Stream& s,
1367 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001368 Format custom_format,
Enrico Granata85933ed2011-08-18 16:38:26 +00001369 bool only_special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001370{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001371
1372 clang_type_t elem_or_pointee_type;
1373 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001374
Enrico Granataf4efecd2011-07-12 22:56:10 +00001375 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1376 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001377 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001378 // when being asked to get a printable display an array or pointer type directly,
1379 // try to "do the right thing"
1380
1381 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001382 (custom_format == eFormatCString ||
1383 custom_format == eFormatCharArray ||
1384 custom_format == eFormatChar ||
1385 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001386 {
1387 Error error;
1388 ReadPointedString(s,
1389 error,
1390 0,
Greg Claytonafacd142011-09-02 01:15:17 +00001391 (custom_format == eFormatVectorOfChar) ||
1392 (custom_format == eFormatCharArray));
Enrico Granataf4efecd2011-07-12 22:56:10 +00001393 return !error.Fail();
1394 }
1395
Greg Claytonafacd142011-09-02 01:15:17 +00001396 if (custom_format == eFormatEnum)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001397 return false;
1398
1399 // this only works for arrays, because I have no way to know when
1400 // the pointed memory ends, and no special \0 end of data marker
1401 if (flags.Test(ClangASTContext::eTypeIsArray))
1402 {
Greg Claytonafacd142011-09-02 01:15:17 +00001403 if ((custom_format == eFormatBytes) ||
1404 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001405 {
1406 uint32_t count = GetNumChildren();
1407
1408 s << '[';
1409 for (uint32_t low = 0; low < count; low++)
1410 {
1411
1412 if (low)
1413 s << ',';
1414
1415 ValueObjectSP child = GetChildAtIndex(low,true);
1416 if (!child.get())
1417 {
Enrico Granatae992a082011-07-22 17:03:19 +00001418 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001419 continue;
1420 }
1421 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1422 }
1423
1424 s << ']';
1425
1426 return true;
1427 }
1428
Greg Claytonafacd142011-09-02 01:15:17 +00001429 if ((custom_format == eFormatVectorOfChar) ||
1430 (custom_format == eFormatVectorOfFloat32) ||
1431 (custom_format == eFormatVectorOfFloat64) ||
1432 (custom_format == eFormatVectorOfSInt16) ||
1433 (custom_format == eFormatVectorOfSInt32) ||
1434 (custom_format == eFormatVectorOfSInt64) ||
1435 (custom_format == eFormatVectorOfSInt8) ||
1436 (custom_format == eFormatVectorOfUInt128) ||
1437 (custom_format == eFormatVectorOfUInt16) ||
1438 (custom_format == eFormatVectorOfUInt32) ||
1439 (custom_format == eFormatVectorOfUInt64) ||
1440 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001441 {
1442 uint32_t count = GetNumChildren();
1443
Greg Claytonafacd142011-09-02 01:15:17 +00001444 Format format = FormatManager::GetSingleItemFormat(custom_format);
Enrico Granataf4efecd2011-07-12 22:56:10 +00001445
1446 s << '[';
1447 for (uint32_t low = 0; low < count; low++)
1448 {
1449
1450 if (low)
1451 s << ',';
1452
1453 ValueObjectSP child = GetChildAtIndex(low,true);
1454 if (!child.get())
1455 {
Enrico Granatae992a082011-07-22 17:03:19 +00001456 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001457 continue;
1458 }
1459 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1460 }
1461
1462 s << ']';
1463
1464 return true;
1465 }
1466 }
1467
Greg Claytonafacd142011-09-02 01:15:17 +00001468 if ((custom_format == eFormatBoolean) ||
1469 (custom_format == eFormatBinary) ||
1470 (custom_format == eFormatChar) ||
1471 (custom_format == eFormatCharPrintable) ||
1472 (custom_format == eFormatComplexFloat) ||
1473 (custom_format == eFormatDecimal) ||
1474 (custom_format == eFormatHex) ||
1475 (custom_format == eFormatFloat) ||
1476 (custom_format == eFormatOctal) ||
1477 (custom_format == eFormatOSType) ||
1478 (custom_format == eFormatUnicode16) ||
1479 (custom_format == eFormatUnicode32) ||
1480 (custom_format == eFormatUnsigned) ||
1481 (custom_format == eFormatPointer) ||
1482 (custom_format == eFormatComplexInteger) ||
1483 (custom_format == eFormatComplex) ||
1484 (custom_format == eFormatDefault)) // use the [] operator
Enrico Granataf4efecd2011-07-12 22:56:10 +00001485 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001486 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001487
1488 if (only_special)
1489 return false;
1490
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001491 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001492 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001493 SetFormat(eFormatDefault);
1494 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001495}
1496
Greg Clayton737b9322010-09-13 03:32:57 +00001497addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001498ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001499{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001500 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001501 return LLDB_INVALID_ADDRESS;
1502
Greg Clayton73b472d2010-10-27 03:32:59 +00001503 switch (m_value.GetValueType())
1504 {
1505 case Value::eValueTypeScalar:
1506 if (scalar_is_load_address)
1507 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001508 if(address_type)
1509 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001510 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1511 }
1512 break;
1513
1514 case Value::eValueTypeLoadAddress:
1515 case Value::eValueTypeFileAddress:
1516 case Value::eValueTypeHostAddress:
1517 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001518 if(address_type)
1519 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001520 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1521 }
1522 break;
1523 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001524 if (address_type)
1525 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001526 return LLDB_INVALID_ADDRESS;
1527}
1528
1529addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001530ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001531{
Greg Claytonafacd142011-09-02 01:15:17 +00001532 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001533 if(address_type)
1534 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001535
Enrico Granatac3e320a2011-08-02 17:27:39 +00001536 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001537 return address;
1538
Greg Clayton73b472d2010-10-27 03:32:59 +00001539 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001540 {
1541 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001542 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001543 break;
1544
Enrico Granata9128ee22011-09-06 19:20:51 +00001545 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001546 case Value::eValueTypeLoadAddress:
1547 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001548 {
1549 uint32_t data_offset = 0;
1550 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001551 }
1552 break;
1553 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001554
Enrico Granata9128ee22011-09-06 19:20:51 +00001555 if (address_type)
1556 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001557
Greg Clayton737b9322010-09-13 03:32:57 +00001558 return address;
1559}
1560
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001561bool
Jim Ingham6035b672011-03-31 00:19:25 +00001562ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001563{
1564 // Make sure our value is up to date first so that our location and location
1565 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001566 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001567 return false;
1568
1569 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001570 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001571
Greg Claytonb1320972010-07-14 00:18:15 +00001572 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001573
Jim Ingham16e0c682011-08-12 23:34:31 +00001574 Value::ValueType value_type = m_value.GetValueType();
1575
1576 if (value_type == Value::eValueTypeScalar)
1577 {
1578 // If the value is already a scalar, then let the scalar change itself:
1579 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1580 }
1581 else if (byte_size <= Scalar::GetMaxByteSize())
1582 {
1583 // If the value fits in a scalar, then make a new scalar and again let the
1584 // scalar code do the conversion, then figure out where to put the new value.
1585 Scalar new_scalar;
1586 Error error;
1587 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1588 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001589 {
Jim Ingham4b536182011-08-09 02:12:22 +00001590 switch (value_type)
1591 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001592 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001593 {
1594 // If it is a load address, then the scalar value is the storage location
1595 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001596 ExecutionContext exe_ctx (GetExecutionContextRef());
1597 Process *process = exe_ctx.GetProcessPtr();
1598 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001599 {
Greg Claytonafacd142011-09-02 01:15:17 +00001600 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001601 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1602 new_scalar,
1603 byte_size,
1604 error);
Jim Ingham16e0c682011-08-12 23:34:31 +00001605 if (!error.Success() || bytes_written != byte_size)
1606 return false;
1607 }
1608 }
Jim Ingham4b536182011-08-09 02:12:22 +00001609 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001610 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001611 {
1612 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1613 DataExtractor new_data;
1614 new_data.SetByteOrder (m_data.GetByteOrder());
1615
1616 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1617 m_data.SetData(buffer_sp, 0);
1618 bool success = new_scalar.GetData(new_data);
1619 if (success)
1620 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001621 new_data.CopyByteOrderedData (0,
1622 byte_size,
1623 const_cast<uint8_t *>(m_data.GetDataStart()),
1624 byte_size,
1625 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001626 }
1627 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1628
1629 }
Jim Ingham4b536182011-08-09 02:12:22 +00001630 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001631 case Value::eValueTypeFileAddress:
1632 case Value::eValueTypeScalar:
Jim Ingham16e0c682011-08-12 23:34:31 +00001633 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001634 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001635 }
1636 else
1637 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001638 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001639 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001640 }
1641 else
1642 {
1643 // We don't support setting things bigger than a scalar at present.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001644 return false;
1645 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001646
1647 // If we have reached this point, then we have successfully changed the value.
1648 SetNeedsUpdate();
1649 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001650}
1651
Greg Clayton81e871e2012-02-04 02:27:34 +00001652bool
1653ValueObject::GetDeclaration (Declaration &decl)
1654{
1655 decl.Clear();
1656 return false;
1657}
1658
Greg Claytonafacd142011-09-02 01:15:17 +00001659LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001660ValueObject::GetObjectRuntimeLanguage ()
1661{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001662 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1663 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001664}
1665
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001666void
Jim Ingham58b59f92011-04-22 23:53:53 +00001667ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001668{
Jim Ingham58b59f92011-04-22 23:53:53 +00001669 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001670}
1671
1672ValueObjectSP
1673ValueObject::GetSyntheticChild (const ConstString &key) const
1674{
1675 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001676 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001677 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001678 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001679 return synthetic_child_sp;
1680}
1681
1682bool
1683ValueObject::IsPointerType ()
1684{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001685 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001686}
1687
Jim Inghamb7603bb2011-03-18 00:05:18 +00001688bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001689ValueObject::IsArrayType ()
1690{
1691 return ClangASTContext::IsArrayType (GetClangType());
1692}
1693
1694bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001695ValueObject::IsScalarType ()
1696{
1697 return ClangASTContext::IsScalarType (GetClangType());
1698}
1699
1700bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001701ValueObject::IsIntegerType (bool &is_signed)
1702{
1703 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1704}
Greg Clayton73b472d2010-10-27 03:32:59 +00001705
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001706bool
1707ValueObject::IsPointerOrReferenceType ()
1708{
Greg Clayton007d5be2011-05-30 00:49:24 +00001709 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1710}
1711
1712bool
1713ValueObject::IsPossibleCPlusPlusDynamicType ()
1714{
1715 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001716}
1717
Greg Claytondea8cb42011-06-29 22:09:02 +00001718bool
1719ValueObject::IsPossibleDynamicType ()
1720{
1721 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1722}
1723
Greg Claytonafacd142011-09-02 01:15:17 +00001724ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001725ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1726{
1727 if (IsArrayType())
1728 return GetSyntheticArrayMemberFromArray(index, can_create);
1729
1730 if (IsPointerType())
1731 return GetSyntheticArrayMemberFromPointer(index, can_create);
1732
1733 return ValueObjectSP();
1734
1735}
1736
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001737ValueObjectSP
1738ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1739{
1740 ValueObjectSP synthetic_child_sp;
1741 if (IsPointerType ())
1742 {
1743 char index_str[64];
1744 snprintf(index_str, sizeof(index_str), "[%i]", index);
1745 ConstString index_const_str(index_str);
1746 // Check if we have already created a synthetic array member in this
1747 // valid object. If we have we will re-use it.
1748 synthetic_child_sp = GetSyntheticChild (index_const_str);
1749 if (!synthetic_child_sp)
1750 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001751 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001752 // We haven't made a synthetic array member for INDEX yet, so
1753 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001754 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001755
1756 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001757 if (synthetic_child)
1758 {
1759 AddSyntheticChild(index_const_str, synthetic_child);
1760 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001761 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001762 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001763 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001764 }
1765 }
1766 return synthetic_child_sp;
1767}
Jim Ingham22777012010-09-23 02:01:19 +00001768
Greg Claytondaf515f2011-07-09 20:12:33 +00001769// This allows you to create an array member using and index
1770// that doesn't not fall in the normal bounds of the array.
1771// Many times structure can be defined as:
1772// struct Collection
1773// {
1774// uint32_t item_count;
1775// Item item_array[0];
1776// };
1777// The size of the "item_array" is 1, but many times in practice
1778// there are more items in "item_array".
1779
1780ValueObjectSP
1781ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1782{
1783 ValueObjectSP synthetic_child_sp;
1784 if (IsArrayType ())
1785 {
1786 char index_str[64];
1787 snprintf(index_str, sizeof(index_str), "[%i]", index);
1788 ConstString index_const_str(index_str);
1789 // Check if we have already created a synthetic array member in this
1790 // valid object. If we have we will re-use it.
1791 synthetic_child_sp = GetSyntheticChild (index_const_str);
1792 if (!synthetic_child_sp)
1793 {
1794 ValueObject *synthetic_child;
1795 // We haven't made a synthetic array member for INDEX yet, so
1796 // lets make one and cache it for any future reference.
1797 synthetic_child = CreateChildAtIndex(0, true, index);
1798
1799 // Cache the value if we got one back...
1800 if (synthetic_child)
1801 {
1802 AddSyntheticChild(index_const_str, synthetic_child);
1803 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001804 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001805 synthetic_child_sp->m_is_array_item_for_pointer = true;
1806 }
1807 }
1808 }
1809 return synthetic_child_sp;
1810}
1811
Enrico Granata9fc19442011-07-06 02:13:41 +00001812ValueObjectSP
1813ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1814{
1815 ValueObjectSP synthetic_child_sp;
1816 if (IsScalarType ())
1817 {
1818 char index_str[64];
1819 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1820 ConstString index_const_str(index_str);
1821 // Check if we have already created a synthetic array member in this
1822 // valid object. If we have we will re-use it.
1823 synthetic_child_sp = GetSyntheticChild (index_const_str);
1824 if (!synthetic_child_sp)
1825 {
1826 ValueObjectChild *synthetic_child;
1827 // We haven't made a synthetic array member for INDEX yet, so
1828 // lets make one and cache it for any future reference.
1829 synthetic_child = new ValueObjectChild(*this,
1830 GetClangAST(),
1831 GetClangType(),
1832 index_const_str,
1833 GetByteSize(),
1834 0,
1835 to-from+1,
1836 from,
1837 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001838 false,
1839 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001840
1841 // Cache the value if we got one back...
1842 if (synthetic_child)
1843 {
1844 AddSyntheticChild(index_const_str, synthetic_child);
1845 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001846 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001847 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1848 }
1849 }
1850 }
1851 return synthetic_child_sp;
1852}
1853
Greg Claytonafacd142011-09-02 01:15:17 +00001854ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001855ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1856{
1857 ValueObjectSP synthetic_child_sp;
1858 if (IsArrayType () || IsPointerType ())
1859 {
1860 char index_str[64];
1861 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1862 ConstString index_const_str(index_str);
1863 // Check if we have already created a synthetic array member in this
1864 // valid object. If we have we will re-use it.
1865 synthetic_child_sp = GetSyntheticChild (index_const_str);
1866 if (!synthetic_child_sp)
1867 {
1868 ValueObjectSynthetic *synthetic_child;
1869
1870 // We haven't made a synthetic array member for INDEX yet, so
1871 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001872 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001873 view->AddRange(from,to);
1874 SyntheticChildrenSP view_sp(view);
1875 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1876
1877 // Cache the value if we got one back...
1878 if (synthetic_child)
1879 {
1880 AddSyntheticChild(index_const_str, synthetic_child);
1881 synthetic_child_sp = synthetic_child->GetSP();
1882 synthetic_child_sp->SetName(ConstString(index_str));
1883 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1884 }
1885 }
1886 }
1887 return synthetic_child_sp;
1888}
1889
Greg Claytonafacd142011-09-02 01:15:17 +00001890ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001891ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1892{
1893
1894 ValueObjectSP synthetic_child_sp;
1895
1896 char name_str[64];
1897 snprintf(name_str, sizeof(name_str), "@%i", offset);
1898 ConstString name_const_str(name_str);
1899
1900 // Check if we have already created a synthetic array member in this
1901 // valid object. If we have we will re-use it.
1902 synthetic_child_sp = GetSyntheticChild (name_const_str);
1903
1904 if (synthetic_child_sp.get())
1905 return synthetic_child_sp;
1906
1907 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001908 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001909
1910 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1911 type.GetASTContext(),
1912 type.GetOpaqueQualType(),
1913 name_const_str,
1914 type.GetTypeByteSize(),
1915 offset,
1916 0,
1917 0,
1918 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001919 false,
1920 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001921 if (synthetic_child)
1922 {
1923 AddSyntheticChild(name_const_str, synthetic_child);
1924 synthetic_child_sp = synthetic_child->GetSP();
1925 synthetic_child_sp->SetName(name_const_str);
1926 synthetic_child_sp->m_is_child_at_offset = true;
1927 }
1928 return synthetic_child_sp;
1929}
1930
Enrico Granatad55546b2011-07-22 00:16:08 +00001931// your expression path needs to have a leading . or ->
1932// (unless it somehow "looks like" an array, in which case it has
1933// a leading [ symbol). while the [ is meaningful and should be shown
1934// to the user, . and -> are just parser design, but by no means
1935// added information for the user.. strip them off
1936static const char*
1937SkipLeadingExpressionPathSeparators(const char* expression)
1938{
1939 if (!expression || !expression[0])
1940 return expression;
1941 if (expression[0] == '.')
1942 return expression+1;
1943 if (expression[0] == '-' && expression[1] == '>')
1944 return expression+2;
1945 return expression;
1946}
1947
Greg Claytonafacd142011-09-02 01:15:17 +00001948ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00001949ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1950{
1951 ValueObjectSP synthetic_child_sp;
1952 ConstString name_const_string(expression);
1953 // Check if we have already created a synthetic array member in this
1954 // valid object. If we have we will re-use it.
1955 synthetic_child_sp = GetSyntheticChild (name_const_string);
1956 if (!synthetic_child_sp)
1957 {
1958 // We haven't made a synthetic array member for expression yet, so
1959 // lets make one and cache it for any future reference.
1960 synthetic_child_sp = GetValueForExpressionPath(expression);
1961
1962 // Cache the value if we got one back...
1963 if (synthetic_child_sp.get())
1964 {
1965 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001966 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001967 synthetic_child_sp->m_is_expression_path_child = true;
1968 }
1969 }
1970 return synthetic_child_sp;
1971}
1972
1973void
Greg Claytonafacd142011-09-02 01:15:17 +00001974ValueObject::CalculateSyntheticValue (SyntheticValueType use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00001975{
Greg Claytonafacd142011-09-02 01:15:17 +00001976 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001977 return;
1978
Enrico Granatac3e320a2011-08-02 17:27:39 +00001979 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001980
Enrico Granata0c489f52012-03-01 04:24:26 +00001981 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00001982 return;
1983
Enrico Granataa37a0652011-07-24 00:14:56 +00001984 if (m_synthetic_value == NULL)
Enrico Granata0c489f52012-03-01 04:24:26 +00001985 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00001986
1987}
1988
Jim Ingham78a685a2011-04-16 00:01:13 +00001989void
Greg Claytonafacd142011-09-02 01:15:17 +00001990ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00001991{
Greg Claytonafacd142011-09-02 01:15:17 +00001992 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00001993 return;
1994
Jim Ingham58b59f92011-04-22 23:53:53 +00001995 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00001996 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001997 ExecutionContext exe_ctx (GetExecutionContextRef());
1998 Process *process = exe_ctx.GetProcessPtr();
1999 if (process)
Jim Ingham78a685a2011-04-16 00:01:13 +00002000 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002001 bool worth_having_dynamic_value = false;
Jim Ingham78a685a2011-04-16 00:01:13 +00002002
Greg Claytoncc4d0142012-02-17 07:49:44 +00002003
2004 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
2005 // hard code this everywhere.
2006 LanguageType known_type = GetObjectRuntimeLanguage();
2007 if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
Jim Ingham78a685a2011-04-16 00:01:13 +00002008 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002009 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
2010 if (runtime)
2011 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00002012 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00002013 else
2014 {
2015 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus);
2016 if (cpp_runtime)
2017 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
2018
2019 if (!worth_having_dynamic_value)
2020 {
2021 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC);
2022 if (objc_runtime)
2023 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
2024 }
2025 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002026
Greg Claytoncc4d0142012-02-17 07:49:44 +00002027 if (worth_having_dynamic_value)
2028 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
2029 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002030 }
2031}
2032
Jim Ingham58b59f92011-04-22 23:53:53 +00002033ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002034ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002035{
Greg Claytonafacd142011-09-02 01:15:17 +00002036 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002037 return ValueObjectSP();
2038
2039 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002040 {
Jim Ingham2837b762011-05-04 03:43:18 +00002041 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002042 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002043 if (m_dynamic_value)
2044 return m_dynamic_value->GetSP();
2045 else
2046 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002047}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002048
Jim Ingham60dbabb2011-12-08 19:44:08 +00002049ValueObjectSP
2050ValueObject::GetStaticValue()
2051{
2052 return GetSP();
2053}
2054
Enrico Granatad55546b2011-07-22 00:16:08 +00002055// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
2056// or we do not really want a dynamic VO. this method instead returns this object
2057// itself when making it synthetic has no meaning. this makes it much simpler
2058// to replace the SyntheticValue for the ValueObject
2059ValueObjectSP
2060ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
2061{
Greg Claytonafacd142011-09-02 01:15:17 +00002062 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00002063 return GetSP();
2064
Enrico Granatac3e320a2011-08-02 17:27:39 +00002065 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00002066
Enrico Granata0c489f52012-03-01 04:24:26 +00002067 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002068 return GetSP();
2069
2070 CalculateSyntheticValue(use_synthetic);
2071
2072 if (m_synthetic_value)
2073 return m_synthetic_value->GetSP();
2074 else
2075 return GetSP();
2076}
2077
Greg Claytone221f822011-01-21 01:59:00 +00002078bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002079ValueObject::HasSyntheticValue()
2080{
2081 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2082
Enrico Granata0c489f52012-03-01 04:24:26 +00002083 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002084 return false;
2085
Greg Claytonafacd142011-09-02 01:15:17 +00002086 CalculateSyntheticValue(eUseSyntheticFilter);
Enrico Granata27b625e2011-08-09 01:04:56 +00002087
2088 if (m_synthetic_value)
2089 return true;
2090 else
2091 return false;
2092}
2093
2094bool
Greg Claytone221f822011-01-21 01:59:00 +00002095ValueObject::GetBaseClassPath (Stream &s)
2096{
2097 if (IsBaseClass())
2098 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002099 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002100 clang_type_t clang_type = GetClangType();
2101 std::string cxx_class_name;
2102 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2103 if (this_had_base_class)
2104 {
2105 if (parent_had_base_class)
2106 s.PutCString("::");
2107 s.PutCString(cxx_class_name.c_str());
2108 }
2109 return parent_had_base_class || this_had_base_class;
2110 }
2111 return false;
2112}
2113
2114
2115ValueObject *
2116ValueObject::GetNonBaseClassParent()
2117{
Jim Ingham78a685a2011-04-16 00:01:13 +00002118 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002119 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002120 if (GetParent()->IsBaseClass())
2121 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002122 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002123 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002124 }
2125 return NULL;
2126}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002127
2128void
Enrico Granata4becb372011-06-29 22:27:15 +00002129ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002130{
Greg Claytone221f822011-01-21 01:59:00 +00002131 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002132
Enrico Granata85933ed2011-08-18 16:38:26 +00002133 if (is_deref_of_parent && epformat == eDereferencePointers)
2134 {
Enrico Granata4becb372011-06-29 22:27:15 +00002135 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2136 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2137 // the eHonorPointers mode is meant to produce strings in this latter format
2138 s.PutCString("*(");
2139 }
Greg Claytone221f822011-01-21 01:59:00 +00002140
Enrico Granata4becb372011-06-29 22:27:15 +00002141 ValueObject* parent = GetParent();
2142
2143 if (parent)
2144 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002145
2146 // if we are a deref_of_parent just because we are synthetic array
2147 // members made up to allow ptr[%d] syntax to work in variable
2148 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00002149 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002150 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002151
Greg Claytone221f822011-01-21 01:59:00 +00002152 if (!IsBaseClass())
2153 {
2154 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002155 {
Greg Claytone221f822011-01-21 01:59:00 +00002156 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2157 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002158 {
Greg Claytone221f822011-01-21 01:59:00 +00002159 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2160 if (non_base_class_parent_clang_type)
2161 {
2162 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2163
Enrico Granata9dd75c82011-07-15 23:30:15 +00002164 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002165 {
2166 s.PutCString("->");
2167 }
Enrico Granata4becb372011-06-29 22:27:15 +00002168 else
2169 {
2170 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2171 {
2172 s.PutCString("->");
2173 }
2174 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2175 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2176 {
2177 s.PutChar('.');
2178 }
Greg Claytone221f822011-01-21 01:59:00 +00002179 }
2180 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002181 }
Greg Claytone221f822011-01-21 01:59:00 +00002182
2183 const char *name = GetName().GetCString();
2184 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002185 {
Greg Claytone221f822011-01-21 01:59:00 +00002186 if (qualify_cxx_base_classes)
2187 {
2188 if (GetBaseClassPath (s))
2189 s.PutCString("::");
2190 }
2191 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002192 }
2193 }
2194 }
2195
Enrico Granata85933ed2011-08-18 16:38:26 +00002196 if (is_deref_of_parent && epformat == eDereferencePointers)
2197 {
Greg Claytone221f822011-01-21 01:59:00 +00002198 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002199 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002200}
2201
Greg Claytonafacd142011-09-02 01:15:17 +00002202ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002203ValueObject::GetValueForExpressionPath(const char* expression,
2204 const char** first_unparsed,
2205 ExpressionPathScanEndReason* reason_to_stop,
2206 ExpressionPathEndResultType* final_value_type,
2207 const GetValueForExpressionPathOptions& options,
2208 ExpressionPathAftermath* final_task_on_target)
2209{
2210
2211 const char* dummy_first_unparsed;
2212 ExpressionPathScanEndReason dummy_reason_to_stop;
2213 ExpressionPathEndResultType dummy_final_value_type;
2214 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2215
2216 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2217 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2218 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2219 final_value_type ? final_value_type : &dummy_final_value_type,
2220 options,
2221 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2222
2223 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002224 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002225
2226 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 +00002227 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002228 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002229 {
2230 Error error;
2231 ValueObjectSP final_value = ret_val->Dereference(error);
2232 if (error.Fail() || !final_value.get())
2233 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002234 if (reason_to_stop)
2235 *reason_to_stop = ValueObject::eDereferencingFailed;
2236 if (final_value_type)
2237 *final_value_type = ValueObject::eInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002238 return ValueObjectSP();
2239 }
2240 else
2241 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002242 if (final_task_on_target)
2243 *final_task_on_target = ValueObject::eNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002244 return final_value;
2245 }
2246 }
2247 if (*final_task_on_target == ValueObject::eTakeAddress)
2248 {
2249 Error error;
2250 ValueObjectSP final_value = ret_val->AddressOf(error);
2251 if (error.Fail() || !final_value.get())
2252 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002253 if (reason_to_stop)
2254 *reason_to_stop = ValueObject::eTakingAddressFailed;
2255 if (final_value_type)
2256 *final_value_type = ValueObject::eInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002257 return ValueObjectSP();
2258 }
2259 else
2260 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002261 if (final_task_on_target)
2262 *final_task_on_target = ValueObject::eNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002263 return final_value;
2264 }
2265 }
2266 }
2267 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2268}
2269
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002270int
2271ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002272 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002273 const char** first_unparsed,
2274 ExpressionPathScanEndReason* reason_to_stop,
2275 ExpressionPathEndResultType* final_value_type,
2276 const GetValueForExpressionPathOptions& options,
2277 ExpressionPathAftermath* final_task_on_target)
2278{
2279 const char* dummy_first_unparsed;
2280 ExpressionPathScanEndReason dummy_reason_to_stop;
2281 ExpressionPathEndResultType dummy_final_value_type;
2282 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2283
2284 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2285 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2286 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2287 final_value_type ? final_value_type : &dummy_final_value_type,
2288 options,
2289 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2290
2291 if (!ret_val.get()) // if there are errors, I add nothing to the list
2292 return 0;
2293
2294 if (*reason_to_stop != eArrayRangeOperatorMet)
2295 {
2296 // I need not expand a range, just post-process the final value and return
2297 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2298 {
2299 list->Append(ret_val);
2300 return 1;
2301 }
2302 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2303 {
2304 if (*final_task_on_target == ValueObject::eDereference)
2305 {
2306 Error error;
2307 ValueObjectSP final_value = ret_val->Dereference(error);
2308 if (error.Fail() || !final_value.get())
2309 {
2310 *reason_to_stop = ValueObject::eDereferencingFailed;
2311 *final_value_type = ValueObject::eInvalid;
2312 return 0;
2313 }
2314 else
2315 {
2316 *final_task_on_target = ValueObject::eNothing;
2317 list->Append(final_value);
2318 return 1;
2319 }
2320 }
2321 if (*final_task_on_target == ValueObject::eTakeAddress)
2322 {
2323 Error error;
2324 ValueObjectSP final_value = ret_val->AddressOf(error);
2325 if (error.Fail() || !final_value.get())
2326 {
2327 *reason_to_stop = ValueObject::eTakingAddressFailed;
2328 *final_value_type = ValueObject::eInvalid;
2329 return 0;
2330 }
2331 else
2332 {
2333 *final_task_on_target = ValueObject::eNothing;
2334 list->Append(final_value);
2335 return 1;
2336 }
2337 }
2338 }
2339 }
2340 else
2341 {
2342 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2343 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2344 ret_val,
2345 list,
2346 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2347 final_value_type ? final_value_type : &dummy_final_value_type,
2348 options,
2349 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2350 }
2351 // in any non-covered case, just do the obviously right thing
2352 list->Append(ret_val);
2353 return 1;
2354}
2355
Greg Claytonafacd142011-09-02 01:15:17 +00002356ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002357ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2358 const char** first_unparsed,
2359 ExpressionPathScanEndReason* reason_to_stop,
2360 ExpressionPathEndResultType* final_result,
2361 const GetValueForExpressionPathOptions& options,
2362 ExpressionPathAftermath* what_next)
2363{
2364 ValueObjectSP root = GetSP();
2365
2366 if (!root.get())
2367 return ValueObjectSP();
2368
2369 *first_unparsed = expression_cstr;
2370
2371 while (true)
2372 {
2373
2374 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2375
Greg Claytonafacd142011-09-02 01:15:17 +00002376 clang_type_t root_clang_type = root->GetClangType();
2377 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002378 Flags root_clang_type_info,pointee_clang_type_info;
2379
2380 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2381 if (pointee_clang_type)
2382 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002383
2384 if (!expression_cstr || *expression_cstr == '\0')
2385 {
2386 *reason_to_stop = ValueObject::eEndOfString;
2387 return root;
2388 }
2389
2390 switch (*expression_cstr)
2391 {
2392 case '-':
2393 {
2394 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002395 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 +00002396 {
2397 *first_unparsed = expression_cstr;
2398 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
2399 *final_result = ValueObject::eInvalid;
2400 return ValueObjectSP();
2401 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002402 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2403 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002404 options.m_no_fragile_ivar)
2405 {
2406 *first_unparsed = expression_cstr;
2407 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
2408 *final_result = ValueObject::eInvalid;
2409 return ValueObjectSP();
2410 }
2411 if (expression_cstr[1] != '>')
2412 {
2413 *first_unparsed = expression_cstr;
2414 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2415 *final_result = ValueObject::eInvalid;
2416 return ValueObjectSP();
2417 }
2418 expression_cstr++; // skip the -
2419 }
2420 case '.': // or fallthrough from ->
2421 {
2422 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002423 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 +00002424 {
2425 *first_unparsed = expression_cstr;
2426 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
2427 *final_result = ValueObject::eInvalid;
2428 return ValueObjectSP();
2429 }
2430 expression_cstr++; // skip .
2431 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2432 ConstString child_name;
2433 if (!next_separator) // if no other separator just expand this last layer
2434 {
2435 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002436 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2437
2438 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002439 {
2440 *first_unparsed = '\0';
2441 *reason_to_stop = ValueObject::eEndOfString;
2442 *final_result = ValueObject::ePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002443 return child_valobj_sp;
2444 }
2445 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2446 {
Greg Clayton4c3b8fb2011-12-02 22:48:25 +00002447 child_valobj_sp = root->GetSyntheticValue(eNoSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002448 }
2449
2450 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2451 // so we hit the "else" branch, and return an error
2452 if(child_valobj_sp.get()) // if it worked, just return
2453 {
2454 *first_unparsed = '\0';
2455 *reason_to_stop = ValueObject::eEndOfString;
2456 *final_result = ValueObject::ePlain;
2457 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002458 }
2459 else
2460 {
2461 *first_unparsed = expression_cstr;
2462 *reason_to_stop = ValueObject::eNoSuchChild;
2463 *final_result = ValueObject::eInvalid;
2464 return ValueObjectSP();
2465 }
2466 }
2467 else // other layers do expand
2468 {
2469 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002470 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2471 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002472 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002473 root = child_valobj_sp;
2474 *first_unparsed = next_separator;
2475 *final_result = ValueObject::ePlain;
2476 continue;
2477 }
2478 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2479 {
Greg Claytonafacd142011-09-02 01:15:17 +00002480 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002481 }
2482
2483 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2484 // so we hit the "else" branch, and return an error
2485 if(child_valobj_sp.get()) // if it worked, move on
2486 {
2487 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002488 *first_unparsed = next_separator;
2489 *final_result = ValueObject::ePlain;
2490 continue;
2491 }
2492 else
2493 {
2494 *first_unparsed = expression_cstr;
2495 *reason_to_stop = ValueObject::eNoSuchChild;
2496 *final_result = ValueObject::eInvalid;
2497 return ValueObjectSP();
2498 }
2499 }
2500 break;
2501 }
2502 case '[':
2503 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002504 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 +00002505 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002506 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002507 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002508 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2509 {
2510 *first_unparsed = expression_cstr;
2511 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2512 *final_result = ValueObject::eInvalid;
2513 return ValueObjectSP();
2514 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002515 }
2516 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2517 {
2518 *first_unparsed = expression_cstr;
2519 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2520 *final_result = ValueObject::eInvalid;
2521 return ValueObjectSP();
2522 }
2523 }
2524 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2525 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002526 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002527 {
2528 *first_unparsed = expression_cstr;
2529 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2530 *final_result = ValueObject::eInvalid;
2531 return ValueObjectSP();
2532 }
2533 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2534 {
2535 *first_unparsed = expression_cstr+2;
2536 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2537 *final_result = ValueObject::eUnboundedRange;
2538 return root;
2539 }
2540 }
2541 const char *separator_position = ::strchr(expression_cstr+1,'-');
2542 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2543 if (!close_bracket_position) // if there is no ], this is a syntax error
2544 {
2545 *first_unparsed = expression_cstr;
2546 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2547 *final_result = ValueObject::eInvalid;
2548 return ValueObjectSP();
2549 }
2550 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2551 {
2552 char *end = NULL;
2553 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2554 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2555 {
2556 *first_unparsed = expression_cstr;
2557 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2558 *final_result = ValueObject::eInvalid;
2559 return ValueObjectSP();
2560 }
2561 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2562 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002563 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002564 {
2565 *first_unparsed = expression_cstr+2;
2566 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2567 *final_result = ValueObject::eUnboundedRange;
2568 return root;
2569 }
2570 else
2571 {
2572 *first_unparsed = expression_cstr;
2573 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2574 *final_result = ValueObject::eInvalid;
2575 return ValueObjectSP();
2576 }
2577 }
2578 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002579 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002580 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002581 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2582 if (!child_valobj_sp)
2583 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002584 if (!child_valobj_sp)
Greg Claytonafacd142011-09-02 01:15:17 +00002585 if (root->HasSyntheticValue() && root->GetSyntheticValue(eUseSyntheticFilter)->GetNumChildren() > index)
2586 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002587 if (child_valobj_sp)
2588 {
2589 root = child_valobj_sp;
2590 *first_unparsed = end+1; // skip ]
2591 *final_result = ValueObject::ePlain;
2592 continue;
2593 }
2594 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002595 {
2596 *first_unparsed = expression_cstr;
2597 *reason_to_stop = ValueObject::eNoSuchChild;
2598 *final_result = ValueObject::eInvalid;
2599 return ValueObjectSP();
2600 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002601 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002602 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002603 {
2604 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 +00002605 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002606 {
2607 Error error;
2608 root = root->Dereference(error);
2609 if (error.Fail() || !root.get())
2610 {
2611 *first_unparsed = expression_cstr;
2612 *reason_to_stop = ValueObject::eDereferencingFailed;
2613 *final_result = ValueObject::eInvalid;
2614 return ValueObjectSP();
2615 }
2616 else
2617 {
2618 *what_next = eNothing;
2619 continue;
2620 }
2621 }
2622 else
2623 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002624 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Claytonafacd142011-09-02 01:15:17 +00002625 root->GetClangType()) == eLanguageTypeObjC
Enrico Granata27b625e2011-08-09 01:04:56 +00002626 &&
2627 ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2628 &&
2629 root->HasSyntheticValue()
2630 &&
2631 options.m_no_synthetic_children == false)
2632 {
Greg Claytonafacd142011-09-02 01:15:17 +00002633 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002634 }
2635 else
2636 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002637 if (!root.get())
2638 {
2639 *first_unparsed = expression_cstr;
2640 *reason_to_stop = ValueObject::eNoSuchChild;
2641 *final_result = ValueObject::eInvalid;
2642 return ValueObjectSP();
2643 }
2644 else
2645 {
2646 *first_unparsed = end+1; // skip ]
2647 *final_result = ValueObject::ePlain;
2648 continue;
2649 }
2650 }
2651 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002652 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002653 {
2654 root = root->GetSyntheticBitFieldChild(index, index, true);
2655 if (!root.get())
2656 {
2657 *first_unparsed = expression_cstr;
2658 *reason_to_stop = ValueObject::eNoSuchChild;
2659 *final_result = ValueObject::eInvalid;
2660 return ValueObjectSP();
2661 }
2662 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2663 {
2664 *first_unparsed = end+1; // skip ]
2665 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2666 *final_result = ValueObject::eBitfield;
2667 return root;
2668 }
2669 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002670 else if (root->HasSyntheticValue() && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002671 {
Greg Claytonafacd142011-09-02 01:15:17 +00002672 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002673 if (!root.get())
2674 {
2675 *first_unparsed = expression_cstr;
2676 *reason_to_stop = ValueObject::eNoSuchChild;
2677 *final_result = ValueObject::eInvalid;
2678 return ValueObjectSP();
2679 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002680 else
2681 {
2682 *first_unparsed = end+1; // skip ]
2683 *final_result = ValueObject::ePlain;
2684 continue;
2685 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002686 }
2687 else
2688 {
2689 *first_unparsed = expression_cstr;
2690 *reason_to_stop = ValueObject::eNoSuchChild;
2691 *final_result = ValueObject::eInvalid;
2692 return ValueObjectSP();
2693 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002694 }
2695 else // we have a low and a high index
2696 {
2697 char *end = NULL;
2698 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2699 if (!end || end != separator_position) // if something weird is in our way return an error
2700 {
2701 *first_unparsed = expression_cstr;
2702 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2703 *final_result = ValueObject::eInvalid;
2704 return ValueObjectSP();
2705 }
2706 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2707 if (!end || end != close_bracket_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 if (index_lower > index_higher) // swap indices if required
2715 {
2716 unsigned long temp = index_lower;
2717 index_lower = index_higher;
2718 index_higher = temp;
2719 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002720 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002721 {
2722 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2723 if (!root.get())
2724 {
2725 *first_unparsed = expression_cstr;
2726 *reason_to_stop = ValueObject::eNoSuchChild;
2727 *final_result = ValueObject::eInvalid;
2728 return ValueObjectSP();
2729 }
2730 else
2731 {
2732 *first_unparsed = end+1; // skip ]
2733 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2734 *final_result = ValueObject::eBitfield;
2735 return root;
2736 }
2737 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002738 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 +00002739 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002740 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002741 {
2742 Error error;
2743 root = root->Dereference(error);
2744 if (error.Fail() || !root.get())
2745 {
2746 *first_unparsed = expression_cstr;
2747 *reason_to_stop = ValueObject::eDereferencingFailed;
2748 *final_result = ValueObject::eInvalid;
2749 return ValueObjectSP();
2750 }
2751 else
2752 {
2753 *what_next = ValueObject::eNothing;
2754 continue;
2755 }
2756 }
2757 else
2758 {
2759 *first_unparsed = expression_cstr;
2760 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2761 *final_result = ValueObject::eBoundedRange;
2762 return root;
2763 }
2764 }
2765 break;
2766 }
2767 default: // some non-separator is in the way
2768 {
2769 *first_unparsed = expression_cstr;
2770 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2771 *final_result = ValueObject::eInvalid;
2772 return ValueObjectSP();
2773 break;
2774 }
2775 }
2776 }
2777}
2778
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002779int
2780ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2781 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002782 ValueObjectSP root,
2783 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002784 ExpressionPathScanEndReason* reason_to_stop,
2785 ExpressionPathEndResultType* final_result,
2786 const GetValueForExpressionPathOptions& options,
2787 ExpressionPathAftermath* what_next)
2788{
2789 if (!root.get())
2790 return 0;
2791
2792 *first_unparsed = expression_cstr;
2793
2794 while (true)
2795 {
2796
2797 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2798
Greg Claytonafacd142011-09-02 01:15:17 +00002799 clang_type_t root_clang_type = root->GetClangType();
2800 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002801 Flags root_clang_type_info,pointee_clang_type_info;
2802
2803 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2804 if (pointee_clang_type)
2805 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2806
2807 if (!expression_cstr || *expression_cstr == '\0')
2808 {
2809 *reason_to_stop = ValueObject::eEndOfString;
2810 list->Append(root);
2811 return 1;
2812 }
2813
2814 switch (*expression_cstr)
2815 {
2816 case '[':
2817 {
2818 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2819 {
2820 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2821 {
2822 *first_unparsed = expression_cstr;
2823 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2824 *final_result = ValueObject::eInvalid;
2825 return 0;
2826 }
2827 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2828 {
2829 *first_unparsed = expression_cstr;
2830 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2831 *final_result = ValueObject::eInvalid;
2832 return 0;
2833 }
2834 }
2835 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2836 {
2837 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2838 {
2839 *first_unparsed = expression_cstr;
2840 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2841 *final_result = ValueObject::eInvalid;
2842 return 0;
2843 }
2844 else // expand this into list
2845 {
2846 int max_index = root->GetNumChildren() - 1;
2847 for (int index = 0; index < max_index; index++)
2848 {
2849 ValueObjectSP child =
2850 root->GetChildAtIndex(index, true);
2851 list->Append(child);
2852 }
2853 *first_unparsed = expression_cstr+2;
2854 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2855 *final_result = ValueObject::eValueObjectList;
2856 return max_index; // tell me number of items I added to the VOList
2857 }
2858 }
2859 const char *separator_position = ::strchr(expression_cstr+1,'-');
2860 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2861 if (!close_bracket_position) // if there is no ], this is a syntax error
2862 {
2863 *first_unparsed = expression_cstr;
2864 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2865 *final_result = ValueObject::eInvalid;
2866 return 0;
2867 }
2868 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2869 {
2870 char *end = NULL;
2871 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2872 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2873 {
2874 *first_unparsed = expression_cstr;
2875 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2876 *final_result = ValueObject::eInvalid;
2877 return 0;
2878 }
2879 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2880 {
2881 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2882 {
2883 int max_index = root->GetNumChildren() - 1;
2884 for (int index = 0; index < max_index; index++)
2885 {
2886 ValueObjectSP child =
2887 root->GetChildAtIndex(index, true);
2888 list->Append(child);
2889 }
2890 *first_unparsed = expression_cstr+2;
2891 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2892 *final_result = ValueObject::eValueObjectList;
2893 return max_index; // tell me number of items I added to the VOList
2894 }
2895 else
2896 {
2897 *first_unparsed = expression_cstr;
2898 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2899 *final_result = ValueObject::eInvalid;
2900 return 0;
2901 }
2902 }
2903 // from here on we do have a valid index
2904 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2905 {
2906 root = root->GetChildAtIndex(index, true);
2907 if (!root.get())
2908 {
2909 *first_unparsed = expression_cstr;
2910 *reason_to_stop = ValueObject::eNoSuchChild;
2911 *final_result = ValueObject::eInvalid;
2912 return 0;
2913 }
2914 else
2915 {
2916 list->Append(root);
2917 *first_unparsed = end+1; // skip ]
2918 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2919 *final_result = ValueObject::eValueObjectList;
2920 return 1;
2921 }
2922 }
2923 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2924 {
2925 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
2926 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2927 {
2928 Error error;
2929 root = root->Dereference(error);
2930 if (error.Fail() || !root.get())
2931 {
2932 *first_unparsed = expression_cstr;
2933 *reason_to_stop = ValueObject::eDereferencingFailed;
2934 *final_result = ValueObject::eInvalid;
2935 return 0;
2936 }
2937 else
2938 {
2939 *what_next = eNothing;
2940 continue;
2941 }
2942 }
2943 else
2944 {
2945 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2946 if (!root.get())
2947 {
2948 *first_unparsed = expression_cstr;
2949 *reason_to_stop = ValueObject::eNoSuchChild;
2950 *final_result = ValueObject::eInvalid;
2951 return 0;
2952 }
2953 else
2954 {
2955 list->Append(root);
2956 *first_unparsed = end+1; // skip ]
2957 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2958 *final_result = ValueObject::eValueObjectList;
2959 return 1;
2960 }
2961 }
2962 }
2963 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2964 {
2965 root = root->GetSyntheticBitFieldChild(index, index, true);
2966 if (!root.get())
2967 {
2968 *first_unparsed = expression_cstr;
2969 *reason_to_stop = ValueObject::eNoSuchChild;
2970 *final_result = ValueObject::eInvalid;
2971 return 0;
2972 }
2973 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2974 {
2975 list->Append(root);
2976 *first_unparsed = end+1; // skip ]
2977 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2978 *final_result = ValueObject::eValueObjectList;
2979 return 1;
2980 }
2981 }
2982 }
2983 else // we have a low and a high index
2984 {
2985 char *end = NULL;
2986 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2987 if (!end || end != separator_position) // if something weird is in our way return an error
2988 {
2989 *first_unparsed = expression_cstr;
2990 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2991 *final_result = ValueObject::eInvalid;
2992 return 0;
2993 }
2994 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2995 if (!end || end != close_bracket_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 if (index_lower > index_higher) // swap indices if required
3003 {
3004 unsigned long temp = index_lower;
3005 index_lower = index_higher;
3006 index_higher = temp;
3007 }
3008 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3009 {
3010 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3011 if (!root.get())
3012 {
3013 *first_unparsed = expression_cstr;
3014 *reason_to_stop = ValueObject::eNoSuchChild;
3015 *final_result = ValueObject::eInvalid;
3016 return 0;
3017 }
3018 else
3019 {
3020 list->Append(root);
3021 *first_unparsed = end+1; // skip ]
3022 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
3023 *final_result = ValueObject::eValueObjectList;
3024 return 1;
3025 }
3026 }
3027 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
3028 *what_next == ValueObject::eDereference &&
3029 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3030 {
3031 Error error;
3032 root = root->Dereference(error);
3033 if (error.Fail() || !root.get())
3034 {
3035 *first_unparsed = expression_cstr;
3036 *reason_to_stop = ValueObject::eDereferencingFailed;
3037 *final_result = ValueObject::eInvalid;
3038 return 0;
3039 }
3040 else
3041 {
3042 *what_next = ValueObject::eNothing;
3043 continue;
3044 }
3045 }
3046 else
3047 {
Johnny Chen44805302011-07-19 19:48:13 +00003048 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003049 index <= index_higher; index++)
3050 {
3051 ValueObjectSP child =
3052 root->GetChildAtIndex(index, true);
3053 list->Append(child);
3054 }
3055 *first_unparsed = end+1;
3056 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
3057 *final_result = ValueObject::eValueObjectList;
3058 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3059 }
3060 }
3061 break;
3062 }
3063 default: // some non-[ separator, or something entirely wrong, is in the way
3064 {
3065 *first_unparsed = expression_cstr;
3066 *reason_to_stop = ValueObject::eUnexpectedSymbol;
3067 *final_result = ValueObject::eInvalid;
3068 return 0;
3069 break;
3070 }
3071 }
3072 }
3073}
3074
Enrico Granata0c489f52012-03-01 04:24:26 +00003075static void
3076DumpValueObject_Impl (Stream &s,
3077 ValueObject *valobj,
3078 const ValueObject::DumpValueObjectOptions& options,
3079 uint32_t ptr_depth,
3080 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003081{
Greg Clayton007d5be2011-05-30 00:49:24 +00003082 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003083 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003084 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003085
Enrico Granata0c489f52012-03-01 04:24:26 +00003086 const char *root_valobj_name =
3087 options.m_root_valobj_name.empty() ?
3088 valobj->GetName().AsCString() :
3089 options.m_root_valobj_name.c_str();
3090
3091 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003092 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003093 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003094 if (dynamic_value)
3095 valobj = dynamic_value;
3096 }
3097
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003098 clang_type_t clang_type = valobj->GetClangType();
3099
Greg Clayton73b472d2010-10-27 03:32:59 +00003100 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003101 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003102 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3103 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003104
Enrico Granata0c489f52012-03-01 04:24:26 +00003105 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003106
3107 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003108 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003109 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003110 {
Jim Ingham6035b672011-03-31 00:19:25 +00003111 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003112 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003113
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003114 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003115
Greg Clayton7c8a9662010-11-02 01:50:16 +00003116 // Always show the type for the top level items.
Enrico Granata0c489f52012-03-01 04:24:26 +00003117 if (options.m_show_types || (curr_depth == 0 && !options.m_flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003118 {
Enrico Granata9910bc82011-08-03 02:18:51 +00003119 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
3120 s.Printf("(%s", typeName);
3121 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003122 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003123 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003124 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003125 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003126 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3127 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003128 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003129 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003130 else
3131 {
3132 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3133 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003134 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003135 else
3136 {
3137 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3138 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003139 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003140 else
3141 s.Printf(", dynamic type: %s) ",
3142 runtime->GetActualTypeName(isa).GetCString());
3143 }
3144 }
3145 }
3146 else
3147 s.Printf(") ");
3148 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003149
Greg Clayton1d3afba2010-10-05 00:00:42 +00003150
Enrico Granata0c489f52012-03-01 04:24:26 +00003151 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003152 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003153 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003154 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003155 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003156 s.PutCString(" =");
3157 }
3158 else
3159 {
3160 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3161 s.Printf ("%s =", name_cstr);
3162 }
3163
Enrico Granata0c489f52012-03-01 04:24:26 +00003164 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003165 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003166 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003167 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003168 }
3169
Enrico Granata0c489f52012-03-01 04:24:26 +00003170 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003171 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003172 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003173 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003174 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003175
Enrico Granata0c489f52012-03-01 04:24:26 +00003176 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003177 entry = NULL;
3178
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003179 if (err_cstr == NULL)
3180 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003181 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003182 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003183 valobj->GetValueAsCString(options.m_format,
3184 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003185 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003186 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003187 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003188 val_cstr = valobj->GetValueAsCString();
3189 if (val_cstr)
3190 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003191 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003192 err_cstr = valobj->GetError().AsCString();
3193 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003194
3195 if (err_cstr)
3196 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003197 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003198 }
3199 else
3200 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003201 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003202 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003203 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003204 if (options.m_omit_summary_depth == 0)
3205 {
3206 if (options.m_summary_sp)
3207 {
3208 valobj->GetSummaryAsCString(entry, summary_str);
3209 sum_cstr = summary_str.c_str();
3210 }
3211 else
3212 sum_cstr = valobj->GetSummaryAsCString();
3213 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003214
Greg Clayton6efba4f2012-01-26 21:08:30 +00003215 // Make sure we have a value and make sure the summary didn't
3216 // specify that the value should not be printed
3217 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3218 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003219
Enrico Granata9dd75c82011-07-15 23:30:15 +00003220 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003221 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003222
Enrico Granata0c489f52012-03-01 04:24:26 +00003223 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003224 {
Jim Ingham6035b672011-03-31 00:19:25 +00003225 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003226 if (object_desc)
3227 s.Printf(" %s\n", object_desc);
3228 else
Sean Callanan672ad942010-10-23 00:18:49 +00003229 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003230 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003231 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003232 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003233
Enrico Granata0c489f52012-03-01 04:24:26 +00003234 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003235 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003236 // We will show children for all concrete types. We won't show
3237 // pointer contents unless a pointer depth has been specified.
3238 // We won't reference contents unless the reference is the
3239 // root object (depth of zero).
3240 bool print_children = true;
3241
3242 // Use a new temporary pointer depth in case we override the
3243 // current pointer depth below...
3244 uint32_t curr_ptr_depth = ptr_depth;
3245
3246 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3247 if (is_ptr || is_ref)
3248 {
3249 // We have a pointer or reference whose value is an address.
3250 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003251 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003252 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003253 print_children = false;
3254
3255 else if (is_ref && curr_depth == 0)
3256 {
3257 // If this is the root object (depth is zero) that we are showing
3258 // and it is a reference, and no pointer depth has been supplied
3259 // print out what it references. Don't do this at deeper depths
3260 // otherwise we can end up with infinite recursion...
3261 curr_ptr_depth = 1;
3262 }
3263
3264 if (curr_ptr_depth == 0)
3265 print_children = false;
3266 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003267
Enrico Granata0a3958e2011-07-02 00:25:22 +00003268 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003269 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003270 ValueObjectSP synth_valobj = valobj->GetSyntheticValue (options.m_use_synthetic ?
Greg Claytoncc4d0142012-02-17 07:49:44 +00003271 eUseSyntheticFilter :
3272 eNoSyntheticFilter);
Enrico Granatac482a192011-08-17 22:13:59 +00003273 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003274 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003275 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003276 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003277 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003278 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003279 if (print_valobj)
3280 s.EOL();
3281 }
3282 else
3283 {
3284 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003285 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003286 s.IndentMore();
3287 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003288
Greg Claytoncc4d0142012-02-17 07:49:44 +00003289 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003290
Enrico Granata0c489f52012-03-01 04:24:26 +00003291 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003292 {
3293 num_children = max_num_children;
3294 print_dotdotdot = true;
3295 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003296
Enrico Granata0c489f52012-03-01 04:24:26 +00003297 ValueObject::DumpValueObjectOptions child_options(options);
3298 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3299 child_options.SetScopeChecked(true)
3300 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003301 for (uint32_t idx=0; idx<num_children; ++idx)
3302 {
Enrico Granatac482a192011-08-17 22:13:59 +00003303 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003304 if (child_sp.get())
3305 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003306 DumpValueObject_Impl (s,
3307 child_sp.get(),
3308 child_options,
3309 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3310 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003311 }
3312 }
3313
Enrico Granata0c489f52012-03-01 04:24:26 +00003314 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003315 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003316 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003317 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003318 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3319 Target *target = exe_ctx.GetTargetPtr();
3320 if (target)
3321 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003322 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003323 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003324 s.IndentLess();
3325 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003326 }
3327 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003328 else if (has_children)
3329 {
3330 // Aggregate, no children...
3331 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003332 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003333 }
3334 else
3335 {
3336 if (print_valobj)
3337 s.EOL();
3338 }
3339
Greg Clayton1d3afba2010-10-05 00:00:42 +00003340 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003341 else
3342 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003343 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003344 }
3345 }
3346 else
3347 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003348 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003349 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003350 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003351 }
3352 }
3353 }
3354 }
3355}
3356
Enrico Granata0c489f52012-03-01 04:24:26 +00003357void
3358ValueObject::DumpValueObject (Stream &s,
3359 ValueObject *valobj)
3360{
3361
3362 if (!valobj)
3363 return;
3364
3365 DumpValueObject_Impl(s,
3366 valobj,
3367 DumpValueObjectOptions::DefaultOptions(),
3368 0,
3369 0);
3370}
3371
3372void
3373ValueObject::DumpValueObject (Stream &s,
3374 ValueObject *valobj,
3375 const DumpValueObjectOptions& options)
3376{
3377 DumpValueObject_Impl(s,
3378 valobj,
3379 options,
3380 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3381 0 // current object depth is 0 since we are just starting
3382 );
3383}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003384
3385ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003386ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003387{
3388 ValueObjectSP valobj_sp;
3389
Enrico Granatac3e320a2011-08-02 17:27:39 +00003390 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003391 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003392 ExecutionContext exe_ctx (GetExecutionContextRef());
3393 clang::ASTContext *ast = GetClangAST ();
3394
3395 DataExtractor data;
3396 data.SetByteOrder (m_data.GetByteOrder());
3397 data.SetAddressByteSize(m_data.GetAddressByteSize());
3398
Greg Claytone72dfb32012-02-24 01:59:29 +00003399 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003400
3401 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3402 ast,
3403 GetClangType(),
3404 name,
3405 data,
3406 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003407 }
Jim Ingham6035b672011-03-31 00:19:25 +00003408
3409 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003410 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003411 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003412 }
3413 return valobj_sp;
3414}
3415
Greg Claytonafacd142011-09-02 01:15:17 +00003416ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003417ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003418{
Jim Ingham58b59f92011-04-22 23:53:53 +00003419 if (m_deref_valobj)
3420 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003421
Greg Clayton54979cd2010-12-15 05:08:08 +00003422 const bool is_pointer_type = IsPointerType();
3423 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003424 {
3425 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003426 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003427
3428 std::string child_name_str;
3429 uint32_t child_byte_size = 0;
3430 int32_t child_byte_offset = 0;
3431 uint32_t child_bitfield_bit_size = 0;
3432 uint32_t child_bitfield_bit_offset = 0;
3433 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003434 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003435 const bool transparent_pointers = false;
3436 clang::ASTContext *clang_ast = GetClangAST();
3437 clang_type_t clang_type = GetClangType();
3438 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003439
Greg Claytoncc4d0142012-02-17 07:49:44 +00003440 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003441
3442 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3443 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003444 GetName().GetCString(),
3445 clang_type,
3446 0,
3447 transparent_pointers,
3448 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003449 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003450 child_name_str,
3451 child_byte_size,
3452 child_byte_offset,
3453 child_bitfield_bit_size,
3454 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003455 child_is_base_class,
3456 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003457 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003458 {
3459 ConstString child_name;
3460 if (!child_name_str.empty())
3461 child_name.SetCString (child_name_str.c_str());
3462
Jim Ingham58b59f92011-04-22 23:53:53 +00003463 m_deref_valobj = new ValueObjectChild (*this,
3464 clang_ast,
3465 child_clang_type,
3466 child_name,
3467 child_byte_size,
3468 child_byte_offset,
3469 child_bitfield_bit_size,
3470 child_bitfield_bit_offset,
3471 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003472 child_is_deref_of_parent,
3473 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003474 }
3475 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003476
Jim Ingham58b59f92011-04-22 23:53:53 +00003477 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003478 {
3479 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003480 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003481 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003482 else
3483 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003484 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003485 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003486
3487 if (is_pointer_type)
3488 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3489 else
3490 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003491 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003492 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003493}
3494
Greg Claytonafacd142011-09-02 01:15:17 +00003495ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003496ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003497{
Jim Ingham78a685a2011-04-16 00:01:13 +00003498 if (m_addr_of_valobj_sp)
3499 return m_addr_of_valobj_sp;
3500
Greg Claytone0d378b2011-03-24 21:19:54 +00003501 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003502 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003503 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003504 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003505 if (addr != LLDB_INVALID_ADDRESS)
3506 {
3507 switch (address_type)
3508 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003509 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003510 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003511 {
3512 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003513 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003514 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3515 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003516 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003517
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003518 case eAddressTypeFile:
3519 case eAddressTypeLoad:
3520 case eAddressTypeHost:
3521 {
3522 clang::ASTContext *ast = GetClangAST();
3523 clang_type_t clang_type = GetClangType();
3524 if (ast && clang_type)
3525 {
3526 std::string name (1, '&');
3527 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003528 ExecutionContext exe_ctx (GetExecutionContextRef());
3529 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003530 ast,
3531 ClangASTContext::CreatePointerType (ast, clang_type),
3532 ConstString (name.c_str()),
3533 addr,
3534 eAddressTypeInvalid,
3535 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003536 }
3537 }
3538 break;
3539 }
3540 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003541 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003542}
3543
Greg Clayton9a142cf2012-02-03 05:34:10 +00003544ValueObjectSP
3545ValueObject::Cast (const ClangASTType &clang_ast_type)
3546{
Greg Clayton81e871e2012-02-04 02:27:34 +00003547 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003548}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003549
Greg Claytonafacd142011-09-02 01:15:17 +00003550ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003551ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3552{
Greg Claytonafacd142011-09-02 01:15:17 +00003553 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003554 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003555 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003556
3557 if (ptr_value != LLDB_INVALID_ADDRESS)
3558 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003559 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003560 ExecutionContext exe_ctx (GetExecutionContextRef());
3561 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003562 name,
3563 ptr_addr,
3564 clang_ast_type);
3565 }
3566 return valobj_sp;
3567}
3568
Greg Claytonafacd142011-09-02 01:15:17 +00003569ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003570ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3571{
Greg Claytonafacd142011-09-02 01:15:17 +00003572 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003573 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003574 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003575
3576 if (ptr_value != LLDB_INVALID_ADDRESS)
3577 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003578 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003579 ExecutionContext exe_ctx (GetExecutionContextRef());
3580 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003581 name,
3582 ptr_addr,
3583 type_sp);
3584 }
3585 return valobj_sp;
3586}
3587
Jim Ingham6035b672011-03-31 00:19:25 +00003588ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003589 m_mod_id(),
3590 m_exe_ctx_ref(),
3591 m_needs_update (true),
3592 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003593{
3594}
3595
3596ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003597 m_mod_id(),
3598 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003599 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003600 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003601{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003602 ExecutionContext exe_ctx(exe_scope);
3603 TargetSP target_sp (exe_ctx.GetTargetSP());
3604 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003605 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003606 m_exe_ctx_ref.SetTargetSP (target_sp);
3607 ProcessSP process_sp (exe_ctx.GetProcessSP());
3608 if (!process_sp)
3609 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003610
Greg Claytoncc4d0142012-02-17 07:49:44 +00003611 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003612 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003613 m_mod_id = process_sp->GetModID();
3614 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003615
Greg Claytoncc4d0142012-02-17 07:49:44 +00003616 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003617
Greg Claytoncc4d0142012-02-17 07:49:44 +00003618 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003619 {
3620 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003621 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003622 }
Jim Ingham6035b672011-03-31 00:19:25 +00003623
Greg Claytoncc4d0142012-02-17 07:49:44 +00003624 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003625 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003626 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003627
Greg Claytoncc4d0142012-02-17 07:49:44 +00003628 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3629 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003630 {
3631 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003632 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003633 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003634 if (frame_sp)
3635 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003636 }
3637 }
3638 }
Jim Ingham6035b672011-03-31 00:19:25 +00003639}
3640
3641ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003642 m_mod_id(),
3643 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3644 m_needs_update (true),
3645 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003646{
3647}
3648
3649ValueObject::EvaluationPoint::~EvaluationPoint ()
3650{
3651}
3652
Jim Ingham6035b672011-03-31 00:19:25 +00003653// This function checks the EvaluationPoint against the current process state. If the current
3654// state matches the evaluation point, or the evaluation point is already invalid, then we return
3655// false, meaning "no change". If the current state is different, we update our state, and return
3656// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3657// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003658// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003659
3660bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003661ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003662{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003663
3664 // 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 +00003665 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003666
Greg Claytoncc4d0142012-02-17 07:49:44 +00003667 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003668 return false;
3669
Jim Ingham6035b672011-03-31 00:19:25 +00003670 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003671 Process *process = exe_ctx.GetProcessPtr();
3672 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003673 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003674
Jim Ingham6035b672011-03-31 00:19:25 +00003675 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003676 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003677
Jim Ingham78a685a2011-04-16 00:01:13 +00003678 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3679 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003680 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003681 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003682
3683 bool changed;
3684
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003685 if (m_mod_id.IsValid())
3686 {
3687 if (m_mod_id == current_mod_id)
3688 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003689 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003690 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003691 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003692 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003693 else
3694 {
3695 m_mod_id = current_mod_id;
3696 m_needs_update = true;
3697 changed = true;
3698 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003699 }
Jim Ingham6035b672011-03-31 00:19:25 +00003700
Jim Ingham73ca05a2011-12-17 01:35:57 +00003701 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3702 // That way we'll be sure to return a valid exe_scope.
3703 // 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 +00003704
Greg Claytoncc4d0142012-02-17 07:49:44 +00003705 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003706 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003707 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3708 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003709 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003710 if (m_exe_ctx_ref.HasFrameRef())
3711 {
3712 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3713 if (!frame_sp)
3714 {
3715 // We used to have a frame, but now it is gone
3716 SetInvalid();
3717 }
3718 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003719 }
Jim Ingham6035b672011-03-31 00:19:25 +00003720 else
3721 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003722 // We used to have a thread, but now it is gone
3723 SetInvalid();
Jim Ingham6035b672011-03-31 00:19:25 +00003724 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003725
Jim Ingham6035b672011-03-31 00:19:25 +00003726 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003727 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003728}
3729
Jim Ingham61be0902011-05-02 18:13:59 +00003730void
3731ValueObject::EvaluationPoint::SetUpdated ()
3732{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003733 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3734 if (process_sp)
3735 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003736 m_first_update = false;
3737 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003738}
3739
3740
Greg Claytoncc4d0142012-02-17 07:49:44 +00003741//bool
3742//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3743//{
3744// if (!IsValid())
3745// return false;
3746//
3747// bool needs_update = false;
3748//
3749// // The target has to be non-null, and the
3750// Target *target = exe_scope->CalculateTarget();
3751// if (target != NULL)
3752// {
3753// Target *old_target = m_target_sp.get();
3754// assert (target == old_target);
3755// Process *process = exe_scope->CalculateProcess();
3756// if (process != NULL)
3757// {
3758// // FOR NOW - assume you can't update variable objects across process boundaries.
3759// Process *old_process = m_process_sp.get();
3760// assert (process == old_process);
3761// ProcessModID current_mod_id = process->GetModID();
3762// if (m_mod_id != current_mod_id)
3763// {
3764// needs_update = true;
3765// m_mod_id = current_mod_id;
3766// }
3767// // See if we're switching the thread or stack context. If no thread is given, this is
3768// // being evaluated in a global context.
3769// Thread *thread = exe_scope->CalculateThread();
3770// if (thread != NULL)
3771// {
3772// user_id_t new_thread_index = thread->GetIndexID();
3773// if (new_thread_index != m_thread_id)
3774// {
3775// needs_update = true;
3776// m_thread_id = new_thread_index;
3777// m_stack_id.Clear();
3778// }
3779//
3780// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3781// if (new_frame != NULL)
3782// {
3783// if (new_frame->GetStackID() != m_stack_id)
3784// {
3785// needs_update = true;
3786// m_stack_id = new_frame->GetStackID();
3787// }
3788// }
3789// else
3790// {
3791// m_stack_id.Clear();
3792// needs_update = true;
3793// }
3794// }
3795// else
3796// {
3797// // If this had been given a thread, and now there is none, we should update.
3798// // Otherwise we don't have to do anything.
3799// if (m_thread_id != LLDB_INVALID_UID)
3800// {
3801// m_thread_id = LLDB_INVALID_UID;
3802// m_stack_id.Clear();
3803// needs_update = true;
3804// }
3805// }
3806// }
3807// else
3808// {
3809// // If there is no process, then we don't need to update anything.
3810// // But if we're switching from having a process to not, we should try to update.
3811// if (m_process_sp.get() != NULL)
3812// {
3813// needs_update = true;
3814// m_process_sp.reset();
3815// m_thread_id = LLDB_INVALID_UID;
3816// m_stack_id.Clear();
3817// }
3818// }
3819// }
3820// else
3821// {
3822// // If there's no target, nothing can change so we don't need to update anything.
3823// // But if we're switching from having a target to not, we should try to update.
3824// if (m_target_sp.get() != NULL)
3825// {
3826// needs_update = true;
3827// m_target_sp.reset();
3828// m_process_sp.reset();
3829// m_thread_id = LLDB_INVALID_UID;
3830// m_stack_id.Clear();
3831// }
3832// }
3833// if (!m_needs_update)
3834// m_needs_update = needs_update;
3835//
3836// return needs_update;
3837//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003838
3839void
3840ValueObject::ClearUserVisibleData()
3841{
3842 m_location_str.clear();
3843 m_value_str.clear();
3844 m_summary_str.clear();
3845 m_object_desc_str.clear();
Enrico Granata0c489f52012-03-01 04:24:26 +00003846 m_synthetic_value = NULL;
Greg Clayton48ca8b82012-01-07 20:58:07 +00003847 m_is_getting_summary = false;
Johnny Chen44805302011-07-19 19:48:13 +00003848}
Enrico Granata9128ee22011-09-06 19:20:51 +00003849
3850SymbolContextScope *
3851ValueObject::GetSymbolContextScope()
3852{
3853 if (m_parent)
3854 {
3855 if (!m_parent->IsPointerOrReferenceType())
3856 return m_parent->GetSymbolContextScope();
3857 }
3858 return NULL;
3859}