blob: 23d22d17257e9d54a8d8dd3e709be402fe080180 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/ValueObject.h"
11
12// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000013#include <stdlib.h>
14
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015// C++ Includes
16// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000018#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
20// Project includes
21#include "lldb/Core/DataBufferHeap.h"
Enrico Granata0a976142011-08-22 22:03:47 +000022#include "lldb/Core/DataVisualization.h"
Enrico Granata4becb372011-06-29 22:27:15 +000023#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000024#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/StreamString.h"
26#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000027#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000028#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000030#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000031#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Greg Clayton7fb56d02011-02-01 01:31:41 +000033#include "lldb/Host/Endian.h"
34
Enrico Granata61a80ba2011-08-12 16:42:31 +000035#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000036#include "lldb/Interpreter/ScriptInterpreterPython.h"
37
Greg Claytone1a916a2010-07-21 22:12:05 +000038#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Symbol/ClangASTContext.h"
40#include "lldb/Symbol/Type.h"
41
Jim Ingham53c47f12010-09-10 23:12:17 +000042#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000043#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000044#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045#include "lldb/Target/Process.h"
46#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000047#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049
Enrico Granataf4efecd2011-07-12 22:56:10 +000050#include "lldb/Utility/RefCounter.h"
51
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052using namespace lldb;
53using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000054using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055
Greg Claytonafacd142011-09-02 01:15:17 +000056static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057
58//----------------------------------------------------------------------
59// ValueObject constructor
60//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000061ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000063 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000064 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065 m_name (),
66 m_data (),
67 m_value (),
68 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000069 m_value_str (),
70 m_old_value_str (),
71 m_location_str (),
72 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000073 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000074 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000075 m_children (),
76 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000077 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000078 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000079 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000080 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000081 m_last_format_mgr_revision(0),
Enrico Granatad8b5fce2011-08-02 23:12:24 +000082 m_last_format_mgr_dynamic(parent.m_last_format_mgr_dynamic),
Enrico Granata9df29e32011-07-19 20:57:44 +000083 m_last_summary_format(),
84 m_forced_summary_format(),
85 m_last_value_format(),
Enrico Granatad55546b2011-07-22 00:16:08 +000086 m_last_synthetic_filter(),
Jim Ingham4b536182011-08-09 02:12:22 +000087 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000088 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000089 m_value_is_valid (false),
90 m_value_did_change (false),
91 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000092 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000093 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000094 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000095 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +000096 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000097 m_is_child_at_offset(false),
Enrico Granata855cd902011-09-06 22:59:55 +000098 m_trying_summary_already(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 Granata9df29e32011-07-19 20:57:44 +0000129 m_last_summary_format(),
130 m_forced_summary_format(),
131 m_last_value_format(),
Enrico Granatad55546b2011-07-22 00:16:08 +0000132 m_last_synthetic_filter(),
Jim Ingham4b536182011-08-09 02:12:22 +0000133 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000134 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000135 m_value_is_valid (false),
136 m_value_did_change (false),
137 m_children_count_valid (false),
138 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000139 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000140 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000141 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000142 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000143 m_is_child_at_offset(false),
Enrico Granata855cd902011-09-06 22:59:55 +0000144 m_trying_summary_already(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
Jim Ingham4b536182011-08-09 02:12:22 +0000241 if (HasCustomSummaryFormat() && m_update_point.GetModID() != m_user_id_of_forced_summary)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000242 {
243 ClearCustomSummaryFormat();
Enrico Granata855cd902011-09-06 22:59:55 +0000244
Enrico Granata9128ee22011-09-06 19:20:51 +0000245 any_change = true;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000246 }
Enrico Granata855cd902011-09-06 22:59:55 +0000247
Enrico Granata85933ed2011-08-18 16:38:26 +0000248 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) ||
Enrico Granatac3e320a2011-08-02 17:27:39 +0000249 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000250 {
Enrico Granata78d06382011-09-09 23:33:14 +0000251 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
252 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, use_dynamic));
253 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, use_dynamic));
Enrico Granata1490c6f2011-07-19 02:34:21 +0000254
Enrico Granata85933ed2011-08-18 16:38:26 +0000255 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000256 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granata855cd902011-09-06 22:59:55 +0000257
258 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000259 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000260
261 return any_change;
262
Enrico Granata4becb372011-06-29 22:27:15 +0000263}
264
Jim Ingham16e0c682011-08-12 23:34:31 +0000265void
266ValueObject::SetNeedsUpdate ()
267{
268 m_update_point.SetNeedsUpdate();
269 // We have to clear the value string here so ConstResult children will notice if their values are
270 // changed by hand (i.e. with SetValueAsCString).
271 m_value_str.clear();
272}
273
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000274DataExtractor &
275ValueObject::GetDataExtractor ()
276{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000277 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278 return m_data;
279}
280
281const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000282ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000283{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000284 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000285 return m_error;
286}
287
288const ConstString &
289ValueObject::GetName() const
290{
291 return m_name;
292}
293
294const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000295ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000296{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000297 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000298 {
299 if (m_location_str.empty())
300 {
301 StreamString sstr;
302
303 switch (m_value.GetValueType())
304 {
305 default:
306 break;
307
308 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000309 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310 {
311 RegisterInfo *reg_info = m_value.GetRegisterInfo();
312 if (reg_info)
313 {
314 if (reg_info->name)
315 m_location_str = reg_info->name;
316 else if (reg_info->alt_name)
317 m_location_str = reg_info->alt_name;
318 break;
319 }
320 }
321 m_location_str = "scalar";
322 break;
323
324 case Value::eValueTypeLoadAddress:
325 case Value::eValueTypeFileAddress:
326 case Value::eValueTypeHostAddress:
327 {
328 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
329 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
330 m_location_str.swap(sstr.GetString());
331 }
332 break;
333 }
334 }
335 }
336 return m_location_str.c_str();
337}
338
339Value &
340ValueObject::GetValue()
341{
342 return m_value;
343}
344
345const Value &
346ValueObject::GetValue() const
347{
348 return m_value;
349}
350
351bool
Jim Ingham6035b672011-03-31 00:19:25 +0000352ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000353{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000354 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
355 {
356 ExecutionContext exe_ctx;
357 ExecutionContextScope *exe_scope = GetExecutionContextScope();
358 if (exe_scope)
359 exe_scope->CalculateExecutionContext(exe_ctx);
Jim Ingham16e0c682011-08-12 23:34:31 +0000360 Value tmp_value(m_value);
361 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000362 if (scalar.IsValid())
363 {
364 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
365 if (bitfield_bit_size)
366 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
367 return true;
368 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000369 }
Greg Claytondcad5022011-12-29 01:26:56 +0000370 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000371}
372
373bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000374ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375{
Greg Clayton288bdf92010-09-02 02:59:18 +0000376 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000377}
378
379
380void
381ValueObject::SetValueIsValid (bool b)
382{
Greg Clayton288bdf92010-09-02 02:59:18 +0000383 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384}
385
386bool
Jim Ingham6035b672011-03-31 00:19:25 +0000387ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000388{
Jim Ingham6035b672011-03-31 00:19:25 +0000389 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000390 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000391}
392
393void
394ValueObject::SetValueDidChange (bool value_changed)
395{
Greg Clayton288bdf92010-09-02 02:59:18 +0000396 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000397}
398
399ValueObjectSP
400ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
401{
402 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000403 // We may need to update our value if we are dynamic
404 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000405 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000406 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000408 // Check if we have already made the child value object?
409 if (can_create && m_children[idx] == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000411 // No we haven't created the child at this index, so lets have our
412 // subclass do it and cache the result for quick future access.
413 m_children[idx] = CreateChildAtIndex (idx, false, 0);
Jim Ingham78a685a2011-04-16 00:01:13 +0000414 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000415
416 if (m_children[idx] != NULL)
417 return m_children[idx]->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000418 }
419 return child_sp;
420}
421
422uint32_t
423ValueObject::GetIndexOfChildWithName (const ConstString &name)
424{
425 bool omit_empty_base_classes = true;
426 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000427 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000428 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429 omit_empty_base_classes);
430}
431
432ValueObjectSP
433ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
434{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000435 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000436 // classes (which really aren't part of the expression path), so we
437 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000439
Greg Claytondea8cb42011-06-29 22:09:02 +0000440 // We may need to update our value if we are dynamic
441 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000442 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000443
444 std::vector<uint32_t> child_indexes;
445 clang::ASTContext *clang_ast = GetClangAST();
446 void *clang_type = GetClangType();
447 bool omit_empty_base_classes = true;
448 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
449 clang_type,
450 name.GetCString(),
451 omit_empty_base_classes,
452 child_indexes);
453 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000455 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
456 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
457
458 child_sp = GetChildAtIndex(*pos, can_create);
459 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000461 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000462 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000463 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
464 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000465 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000466 else
467 {
468 child_sp.reset();
469 }
470
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471 }
472 }
473 return child_sp;
474}
475
476
477uint32_t
478ValueObject::GetNumChildren ()
479{
Greg Clayton288bdf92010-09-02 02:59:18 +0000480 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481 {
482 SetNumChildren (CalculateNumChildren());
483 }
484 return m_children.size();
485}
486void
487ValueObject::SetNumChildren (uint32_t num_children)
488{
Greg Clayton288bdf92010-09-02 02:59:18 +0000489 m_children_count_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490 m_children.resize(num_children);
491}
492
493void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000494ValueObject::SetName (const ConstString &name)
495{
496 m_name = name;
497}
498
Jim Ingham58b59f92011-04-22 23:53:53 +0000499ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000500ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
501{
Jim Ingham2eec4872011-05-07 00:10:58 +0000502 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000503
Greg Claytondea8cb42011-06-29 22:09:02 +0000504 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000505 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000506 std::string child_name_str;
507 uint32_t child_byte_size = 0;
508 int32_t child_byte_offset = 0;
509 uint32_t child_bitfield_bit_size = 0;
510 uint32_t child_bitfield_bit_offset = 0;
511 bool child_is_base_class = false;
512 bool child_is_deref_of_parent = false;
513
514 const bool transparent_pointers = synthetic_array_member == false;
515 clang::ASTContext *clang_ast = GetClangAST();
516 clang_type_t clang_type = GetClangType();
517 clang_type_t child_clang_type;
518
519 ExecutionContext exe_ctx;
520 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
521
522 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
523 clang_ast,
524 GetName().GetCString(),
525 clang_type,
526 idx,
527 transparent_pointers,
528 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000529 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000530 child_name_str,
531 child_byte_size,
532 child_byte_offset,
533 child_bitfield_bit_size,
534 child_bitfield_bit_offset,
535 child_is_base_class,
536 child_is_deref_of_parent);
537 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000539 if (synthetic_index)
540 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000541
Greg Claytondea8cb42011-06-29 22:09:02 +0000542 ConstString child_name;
543 if (!child_name_str.empty())
544 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000545
Greg Claytondea8cb42011-06-29 22:09:02 +0000546 valobj = new ValueObjectChild (*this,
547 clang_ast,
548 child_clang_type,
549 child_name,
550 child_byte_size,
551 child_byte_offset,
552 child_bitfield_bit_size,
553 child_bitfield_bit_offset,
554 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000555 child_is_deref_of_parent,
556 eAddressTypeInvalid);
557 //if (valobj)
558 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
559 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000560
Jim Ingham58b59f92011-04-22 23:53:53 +0000561 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000562}
563
564const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000565ValueObject::GetSummaryAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000566{
Enrico Granatad8b5fce2011-08-02 23:12:24 +0000567 if (UpdateValueIfNeeded (true))
Enrico Granata4becb372011-06-29 22:27:15 +0000568 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569 if (m_summary_str.empty())
570 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000571 SummaryFormat *summary_format = GetSummaryFormat().get();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000572
573 if (summary_format)
Enrico Granata4becb372011-06-29 22:27:15 +0000574 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000575 m_summary_str = summary_format->FormatObject(GetSP());
Enrico Granata4becb372011-06-29 22:27:15 +0000576 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000577 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000578 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000579 clang_type_t clang_type = GetClangType();
Greg Clayton737b9322010-09-13 03:32:57 +0000580
Enrico Granata9dd75c82011-07-15 23:30:15 +0000581 // Do some default printout for function pointers
Enrico Granataf2bbf712011-07-15 02:26:42 +0000582 if (clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000583 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000584 StreamString sstr;
585 clang_type_t elem_or_pointee_clang_type;
586 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
587 GetClangAST(),
588 &elem_or_pointee_clang_type));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000589
Enrico Granataf2bbf712011-07-15 02:26:42 +0000590 ExecutionContextScope *exe_scope = GetExecutionContextScope();
591 if (exe_scope)
592 {
Enrico Granata9dd75c82011-07-15 23:30:15 +0000593 if (ClangASTContext::IsFunctionPointerType (clang_type))
Jim Ingham6035b672011-03-31 00:19:25 +0000594 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000595 AddressType func_ptr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000596 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000597 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
598 {
599 switch (func_ptr_address_type)
600 {
601 case eAddressTypeInvalid:
602 case eAddressTypeFile:
603 break;
604
605 case eAddressTypeLoad:
606 {
607 Address so_addr;
608 Target *target = exe_scope->CalculateTarget();
609 if (target && target->GetSectionLoadList().IsEmpty() == false)
610 {
611 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
612 {
613 so_addr.Dump (&sstr,
614 exe_scope,
615 Address::DumpStyleResolvedDescription,
616 Address::DumpStyleSectionNameOffset);
617 }
618 }
619 }
620 break;
621
622 case eAddressTypeHost:
623 break;
624 }
625 }
626 if (sstr.GetSize() > 0)
627 {
628 m_summary_str.assign (1, '(');
629 m_summary_str.append (sstr.GetData(), sstr.GetSize());
630 m_summary_str.append (1, ')');
631 }
Jim Ingham6035b672011-03-31 00:19:25 +0000632 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000633 }
634 }
635 }
636 }
637 }
638 if (m_summary_str.empty())
639 return NULL;
640 return m_summary_str.c_str();
641}
642
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000643bool
644ValueObject::IsCStringContainer(bool check_pointer)
645{
646 clang_type_t elem_or_pointee_clang_type;
647 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
648 GetClangAST(),
649 &elem_or_pointee_clang_type));
650 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
651 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
652 if (!is_char_arr_ptr)
653 return false;
654 if (!check_pointer)
655 return true;
656 if (type_flags.Test(ClangASTContext::eTypeIsArray))
657 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000658 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000659 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000660 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000661 return (cstr_address != LLDB_INVALID_ADDRESS);
662}
663
Enrico Granata9128ee22011-09-06 19:20:51 +0000664size_t
665ValueObject::GetPointeeData (DataExtractor& data,
666 uint32_t item_idx,
667 uint32_t item_count)
668{
669 if (!IsPointerType() && !IsArrayType())
670 return 0;
671
672 if (item_count == 0)
673 return 0;
674
675 uint32_t stride = 0;
676
677 ClangASTType type(GetClangAST(),
678 GetClangType());
679
680 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
681 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
682
683 const uint64_t bytes = item_count * item_type_size;
684
685 const uint64_t offset = item_idx * item_type_size;
686
687 if (item_idx == 0 && item_count == 1) // simply a deref
688 {
689 if (IsPointerType())
690 {
691 Error error;
692 ValueObjectSP pointee_sp = Dereference(error);
693 if (error.Fail() || pointee_sp.get() == NULL)
694 return 0;
695 return pointee_sp->GetDataExtractor().Copy(data);
696 }
697 else
698 {
699 ValueObjectSP child_sp = GetChildAtIndex(0, true);
700 if (child_sp.get() == NULL)
701 return 0;
702 return child_sp->GetDataExtractor().Copy(data);
703 }
704 return true;
705 }
706 else /* (items > 1) */
707 {
708 Error error;
709 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
710 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
711
712 AddressType addr_type;
713 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
714
Jim Ingham73ca05a2011-12-17 01:35:57 +0000715 ExecutionContextScope *exe_scope = GetExecutionContextScope();
Enrico Granata9128ee22011-09-06 19:20:51 +0000716
717
718 switch (addr_type)
719 {
720 case eAddressTypeFile:
721 {
722 Module* module = GetModule();
723 if (module)
724 {
725 Address so_addr;
726 module->ResolveFileAddress(addr, so_addr);
727 if (exe_scope)
728 {
729 Target* target = exe_scope->CalculateTarget();
730 if (target)
731 {
732 heap_buf_ptr->SetByteSize(bytes);
733 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
734 if (error.Success())
735 {
736 data.SetData(data_sp);
737 return bytes_read;
738 }
739 }
740 }
741 }
742 }
743 break;
744 case eAddressTypeLoad:
745 if (exe_scope)
746 {
747 Process *process = exe_scope->CalculateProcess();
748 if (process)
749 {
750 heap_buf_ptr->SetByteSize(bytes);
751 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
752 if (error.Success())
753 {
754 data.SetData(data_sp);
755 return bytes_read;
756 }
757 }
758 }
759 break;
760 case eAddressTypeHost:
761 {
762 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
763 data.SetData(data_sp);
764 return bytes;
765 }
766 break;
767 case eAddressTypeInvalid:
768 default:
769 break;
770 }
771 }
772 return 0;
773}
774
775size_t
776ValueObject::GetData (DataExtractor& data)
777{
778 UpdateValueIfNeeded(false);
779 ExecutionContext exe_ctx;
780 GetExecutionContextScope()->CalculateExecutionContext(exe_ctx);
781 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule());
782 if (error.Fail())
783 return 0;
784 data.SetAddressByteSize(m_data.GetAddressByteSize());
785 data.SetByteOrder(m_data.GetByteOrder());
786 return data.GetByteSize();
787}
788
789// will compute strlen(str), but without consuming more than
790// maxlen bytes out of str (this serves the purpose of reading
791// chunks of a string without having to worry about
792// missing NULL terminators in the chunk)
793// of course, if strlen(str) > maxlen, the function will return
794// maxlen_value (which should be != maxlen, because that allows you
795// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
796static uint32_t
797strlen_or_inf (const char* str,
798 uint32_t maxlen,
799 uint32_t maxlen_value)
800{
801 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000802 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000803 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000804 while(*str)
805 {
806 len++;str++;
807 if (len > maxlen)
808 return maxlen_value;
809 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000810 }
811 return len;
812}
813
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000814void
815ValueObject::ReadPointedString(Stream& s,
816 Error& error,
Enrico Granataf4efecd2011-07-12 22:56:10 +0000817 uint32_t max_length,
818 bool honor_array,
Greg Claytonafacd142011-09-02 01:15:17 +0000819 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000820{
821
822 if (max_length == 0)
Enrico Granata9128ee22011-09-06 19:20:51 +0000823 max_length = GetUpdatePoint().GetTargetSP()->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000824
825 clang_type_t clang_type = GetClangType();
826 clang_type_t elem_or_pointee_clang_type;
827 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
828 GetClangAST(),
829 &elem_or_pointee_clang_type));
830 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
831 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
832 {
833 ExecutionContextScope *exe_scope = GetExecutionContextScope();
834 if (exe_scope)
835 {
836 Target *target = exe_scope->CalculateTarget();
Enrico Granata6f3533f2011-07-29 19:53:35 +0000837 if (target == NULL)
838 {
839 s << "<no target to read from>";
840 }
841 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000842 {
Greg Claytonafacd142011-09-02 01:15:17 +0000843 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000844 AddressType cstr_address_type = eAddressTypeInvalid;
845
846 size_t cstr_len = 0;
847 bool capped_data = false;
848 if (type_flags.Test (ClangASTContext::eTypeIsArray))
849 {
850 // We have an array
851 cstr_len = ClangASTContext::GetArraySize (clang_type);
Enrico Granataf4efecd2011-07-12 22:56:10 +0000852 if (cstr_len > max_length)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000853 {
Enrico Granataf4efecd2011-07-12 22:56:10 +0000854 capped_data = true;
855 cstr_len = max_length;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000856 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000857 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000858 }
859 else
860 {
861 // We have a pointer
Enrico Granata9128ee22011-09-06 19:20:51 +0000862 cstr_address = GetPointerValue (&cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000863 }
Greg Clayton8dd5c172011-10-05 22:19:51 +0000864 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000865 {
866 Address cstr_so_addr (NULL, cstr_address);
867 DataExtractor data;
868 size_t bytes_read = 0;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000869 if (cstr_len > 0 && honor_array)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000870 {
Enrico Granata9128ee22011-09-06 19:20:51 +0000871 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
872 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
873 GetPointeeData(data, 0, cstr_len);
874
Greg Clayton8dd5c172011-10-05 22:19:51 +0000875 if ((bytes_read = data.GetByteSize()) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000876 {
877 s << '"';
878 data.Dump (&s,
879 0, // Start offset in "data"
Enrico Granataf4efecd2011-07-12 22:56:10 +0000880 item_format,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000881 1, // Size of item (1 byte for a char!)
882 bytes_read, // How many bytes to print?
883 UINT32_MAX, // num per line
884 LLDB_INVALID_ADDRESS,// base address
885 0, // bitfield bit size
886 0); // bitfield bit offset
887 if (capped_data)
888 s << "...";
889 s << '"';
890 }
891 }
892 else
893 {
Enrico Granataf4efecd2011-07-12 22:56:10 +0000894 cstr_len = max_length;
895 const size_t k_max_buf_size = 64;
Enrico Granata9128ee22011-09-06 19:20:51 +0000896
897 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000898
Greg Clayton8dd5c172011-10-05 22:19:51 +0000899 int cstr_len_displayed = -1;
900 bool capped_cstr = false;
Enrico Granata9128ee22011-09-06 19:20:51 +0000901 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
902 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
Greg Clayton8dd5c172011-10-05 22:19:51 +0000903 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000904 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000905 const char *cstr = data.PeekCStr(0);
906 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
Enrico Granata9128ee22011-09-06 19:20:51 +0000907 if (len > k_max_buf_size)
908 len = k_max_buf_size;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000909 if (cstr && cstr_len_displayed < 0)
Enrico Granata9128ee22011-09-06 19:20:51 +0000910 s << '"';
Greg Clayton8dd5c172011-10-05 22:19:51 +0000911
912 if (cstr_len_displayed < 0)
913 cstr_len_displayed = len;
914
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000915 if (len == 0)
916 break;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000917 cstr_len_displayed += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000918 if (len > bytes_read)
919 len = bytes_read;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000920 if (len > cstr_len)
921 len = cstr_len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000922
923 data.Dump (&s,
924 0, // Start offset in "data"
Enrico Granataf4efecd2011-07-12 22:56:10 +0000925 item_format,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000926 1, // Size of item (1 byte for a char!)
927 len, // How many bytes to print?
928 UINT32_MAX, // num per line
929 LLDB_INVALID_ADDRESS,// base address
930 0, // bitfield bit size
931 0); // bitfield bit offset
932
933 if (len < k_max_buf_size)
934 break;
Enrico Granata9128ee22011-09-06 19:20:51 +0000935
Enrico Granataf4efecd2011-07-12 22:56:10 +0000936 if (len >= cstr_len)
Greg Clayton8dd5c172011-10-05 22:19:51 +0000937 {
938 capped_cstr = true;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000939 break;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000940 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000941
Enrico Granataf4efecd2011-07-12 22:56:10 +0000942 cstr_len -= len;
Enrico Granata9128ee22011-09-06 19:20:51 +0000943 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000944 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000945
Greg Clayton8dd5c172011-10-05 22:19:51 +0000946 if (cstr_len_displayed >= 0)
Enrico Granata9128ee22011-09-06 19:20:51 +0000947 {
948 s << '"';
Greg Clayton8dd5c172011-10-05 22:19:51 +0000949 if (capped_cstr)
Enrico Granata9128ee22011-09-06 19:20:51 +0000950 s << "...";
951 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000952 }
953 }
954 }
955 }
956 }
957 else
958 {
959 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +0000960 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000961 }
962}
963
Jim Ingham53c47f12010-09-10 23:12:17 +0000964const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000965ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +0000966{
Enrico Granata0a3958e2011-07-02 00:25:22 +0000967
Enrico Granatad8b5fce2011-08-02 23:12:24 +0000968 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +0000969 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000970
971 if (!m_object_desc_str.empty())
972 return m_object_desc_str.c_str();
973
Jim Ingham6035b672011-03-31 00:19:25 +0000974 ExecutionContextScope *exe_scope = GetExecutionContextScope();
975 if (exe_scope == NULL)
976 return NULL;
977
Jim Ingham53c47f12010-09-10 23:12:17 +0000978 Process *process = exe_scope->CalculateProcess();
Jim Ingham5a369122010-09-28 01:25:32 +0000979 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +0000980 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +0000981
Jim Ingham53c47f12010-09-10 23:12:17 +0000982 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +0000983
Greg Claytonafacd142011-09-02 01:15:17 +0000984 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +0000985 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
986
Jim Inghama2cf2632010-12-23 02:29:54 +0000987 if (runtime == NULL)
988 {
Jim Inghamb7603bb2011-03-18 00:05:18 +0000989 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +0000990 clang_type_t opaque_qual_type = GetClangType();
991 if (opaque_qual_type != NULL)
992 {
Jim Inghamb7603bb2011-03-18 00:05:18 +0000993 bool is_signed;
994 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
995 || ClangASTContext::IsPointerType (opaque_qual_type))
996 {
Greg Claytonafacd142011-09-02 01:15:17 +0000997 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +0000998 }
Jim Inghama2cf2632010-12-23 02:29:54 +0000999 }
1000 }
1001
Jim Ingham8d543de2011-03-31 23:01:21 +00001002 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001003 {
1004 m_object_desc_str.append (s.GetData());
1005 }
Sean Callanan672ad942010-10-23 00:18:49 +00001006
1007 if (m_object_desc_str.empty())
1008 return NULL;
1009 else
1010 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001011}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001012
1013const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001014ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001015{
1016 // If our byte size is zero this is an aggregate type that has children
Greg Clayton1be10fc2010-09-29 01:12:09 +00001017 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001018 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00001019 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001020 {
1021 if (m_value_str.empty())
1022 {
1023 const Value::ContextType context_type = m_value.GetContextType();
1024
1025 switch (context_type)
1026 {
Greg Clayton526e5af2010-11-13 03:52:47 +00001027 case Value::eContextTypeClangType:
1028 case Value::eContextTypeLLDBType:
1029 case Value::eContextTypeVariable:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001030 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001031 lldb::Format my_format = GetFormat();
Greg Clayton73b472d2010-10-27 03:32:59 +00001032 clang_type_t clang_type = GetClangType ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001033 if (clang_type)
1034 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001035 if (m_format == lldb::eFormatDefault)
Enrico Granata4becb372011-06-29 22:27:15 +00001036 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001037 if (m_last_value_format)
1038 my_format = m_last_value_format->GetFormat();
Enrico Granataf2bbf712011-07-15 02:26:42 +00001039 else
1040 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001041 if (m_is_bitfield_for_scalar)
1042 my_format = eFormatUnsigned;
1043 else
1044 my_format = ClangASTType::GetFormat(clang_type);
Enrico Granataf2bbf712011-07-15 02:26:42 +00001045 }
Greg Clayton007d5be2011-05-30 00:49:24 +00001046 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001047 StreamString sstr;
1048 if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1049 clang_type, // The clang type to display
1050 &sstr,
1051 my_format, // Format to display this type with
1052 m_data, // Data to extract from
1053 0, // Byte offset into "m_data"
1054 GetByteSize(), // Byte size of item in "m_data"
1055 GetBitfieldBitSize(), // Bitfield bit size
Greg Clayton5009f9d2011-10-27 17:55:14 +00001056 GetBitfieldBitOffset(),
1057 GetExecutionContextScope())) // Bitfield bit offset
Enrico Granata9128ee22011-09-06 19:20:51 +00001058 m_value_str.swap(sstr.GetString());
1059 else
1060 {
Jason Molenda7e589a62011-09-20 00:26:08 +00001061 m_error.SetErrorStringWithFormat ("unsufficient data for value (only %lu of %lu bytes available)",
Enrico Granata9128ee22011-09-06 19:20:51 +00001062 m_data.GetByteSize(),
1063 GetByteSize());
1064 m_value_str.clear();
1065 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001066 }
1067 }
1068 break;
1069
Greg Clayton526e5af2010-11-13 03:52:47 +00001070 case Value::eContextTypeRegisterInfo:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001071 {
1072 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1073 if (reg_info)
1074 {
1075 StreamString reg_sstr;
Greg Clayton5009f9d2011-10-27 17:55:14 +00001076 m_data.Dump(&reg_sstr, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0, GetExecutionContextScope());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001077 m_value_str.swap(reg_sstr.GetString());
1078 }
1079 }
1080 break;
Greg Claytonc982c762010-07-09 20:39:50 +00001081
1082 default:
1083 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001084 }
1085 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001086
1087 if (!m_value_did_change && m_old_value_valid)
1088 {
1089 // The value was gotten successfully, so we consider the
1090 // value as changed if the value string differs
1091 SetValueDidChange (m_old_value_str != m_value_str);
1092 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001093 }
1094 }
1095 if (m_value_str.empty())
1096 return NULL;
1097 return m_value_str.c_str();
1098}
1099
Enrico Granatac3e320a2011-08-02 17:27:39 +00001100// if > 8bytes, 0 is returned. this method should mostly be used
1101// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001102uint64_t
1103ValueObject::GetValueAsUnsigned (uint64_t fail_value)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001104{
1105 // If our byte size is zero this is an aggregate type that has children
1106 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1107 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001108 Scalar scalar;
1109 if (ResolveValue (scalar))
1110 return scalar.GetRawBits64(fail_value);
Enrico Granatac3e320a2011-08-02 17:27:39 +00001111 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001112 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001113}
1114
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001115bool
1116ValueObject::GetPrintableRepresentation(Stream& s,
1117 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001118 Format custom_format)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001119{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001120
Greg Claytonafacd142011-09-02 01:15:17 +00001121 if (custom_format != eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001122 SetFormat(custom_format);
1123
1124 const char * return_value;
Enrico Granatacd1c0232011-08-04 23:37:18 +00001125 std::string alloc_mem;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001126
1127 switch(val_obj_display)
1128 {
1129 case eDisplayValue:
1130 return_value = GetValueAsCString();
1131 break;
1132 case eDisplaySummary:
Enrico Granata855cd902011-09-06 22:59:55 +00001133 if (m_trying_summary_already)
1134 return_value = NULL;
1135 else
1136 {
1137 m_trying_summary_already = true;
1138 return_value = GetSummaryAsCString();
1139 m_trying_summary_already = false;
1140 break;
1141 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001142 case eDisplayLanguageSpecific:
1143 return_value = GetObjectDescription();
1144 break;
Enrico Granataf2bbf712011-07-15 02:26:42 +00001145 case eDisplayLocation:
1146 return_value = GetLocationAsCString();
1147 break;
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001148 case eDisplayChildrenCount:
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001149 {
Enrico Granatacd1c0232011-08-04 23:37:18 +00001150 alloc_mem.resize(512);
1151 return_value = &alloc_mem[0];
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001152 int count = GetNumChildren();
Enrico Granatacd1c0232011-08-04 23:37:18 +00001153 snprintf((char*)return_value, 512, "%d", count);
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001154 break;
1155 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001156 case eDisplayType:
1157 return_value = GetTypeName().AsCString();
1158 break;
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001159 default:
1160 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001161 }
1162
Enrico Granata855cd902011-09-06 22:59:55 +00001163 if (!return_value)
Enrico Granata9fc19442011-07-06 02:13:41 +00001164 {
Enrico Granata9fc19442011-07-06 02:13:41 +00001165 if (val_obj_display == eDisplayValue)
Enrico Granata855cd902011-09-06 22:59:55 +00001166 return_value = GetSummaryAsCString();
Enrico Granata9fc19442011-07-06 02:13:41 +00001167 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +00001168 {
1169 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1170 {
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001171 // this thing has no value, and it seems to have no summary
1172 // some combination of unitialized data and other factors can also
Enrico Granata855cd902011-09-06 22:59:55 +00001173 // raise this condition, so let's print a nice generic description
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001174 {
1175 alloc_mem.resize(684);
1176 return_value = &alloc_mem[0];
1177 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1178 }
Enrico Granatae992a082011-07-22 17:03:19 +00001179 }
1180 else
1181 return_value = GetValueAsCString();
1182 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001183 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001184
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001185 if (return_value)
1186 s.PutCString(return_value);
1187 else
Enrico Granata88da35f2011-08-23 21:26:09 +00001188 {
1189 if (m_error.Fail())
1190 s.Printf("<%s>", m_error.AsCString());
1191 else if (val_obj_display == eDisplaySummary)
1192 s.PutCString("<no summary available>");
1193 else if (val_obj_display == eDisplayValue)
1194 s.PutCString("<no value available>");
1195 else if (val_obj_display == eDisplayLanguageSpecific)
1196 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1197 else
1198 s.PutCString("<no printable representation>");
1199 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001200
1201 // we should only return false here if we could not do *anything*
1202 // even if we have an error message as output, that's a success
1203 // from our callers' perspective, so return true
1204 return true;
1205
Enrico Granata0a3958e2011-07-02 00:25:22 +00001206}
1207
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001208// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1209// this call up to date by returning true for your new special cases. We will eventually move
1210// to checking this call result before trying to display special cases
1211bool
1212ValueObject::HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001213 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001214{
1215 clang_type_t elem_or_pointee_type;
1216 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1217
1218 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1219 && val_obj_display == ValueObject::eDisplayValue)
1220 {
1221 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001222 (custom_format == eFormatCString ||
1223 custom_format == eFormatCharArray ||
1224 custom_format == eFormatChar ||
1225 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001226 return true;
1227
1228 if (flags.Test(ClangASTContext::eTypeIsArray))
1229 {
Greg Claytonafacd142011-09-02 01:15:17 +00001230 if ((custom_format == eFormatBytes) ||
1231 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001232 return true;
1233
Greg Claytonafacd142011-09-02 01:15:17 +00001234 if ((custom_format == eFormatVectorOfChar) ||
1235 (custom_format == eFormatVectorOfFloat32) ||
1236 (custom_format == eFormatVectorOfFloat64) ||
1237 (custom_format == eFormatVectorOfSInt16) ||
1238 (custom_format == eFormatVectorOfSInt32) ||
1239 (custom_format == eFormatVectorOfSInt64) ||
1240 (custom_format == eFormatVectorOfSInt8) ||
1241 (custom_format == eFormatVectorOfUInt128) ||
1242 (custom_format == eFormatVectorOfUInt16) ||
1243 (custom_format == eFormatVectorOfUInt32) ||
1244 (custom_format == eFormatVectorOfUInt64) ||
1245 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001246 return true;
1247 }
1248 }
1249 return false;
1250}
1251
Enrico Granata9fc19442011-07-06 02:13:41 +00001252bool
1253ValueObject::DumpPrintableRepresentation(Stream& s,
1254 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001255 Format custom_format,
Enrico Granata85933ed2011-08-18 16:38:26 +00001256 bool only_special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001257{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001258
1259 clang_type_t elem_or_pointee_type;
1260 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001261
Enrico Granataf4efecd2011-07-12 22:56:10 +00001262 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1263 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001264 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001265 // when being asked to get a printable display an array or pointer type directly,
1266 // try to "do the right thing"
1267
1268 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001269 (custom_format == eFormatCString ||
1270 custom_format == eFormatCharArray ||
1271 custom_format == eFormatChar ||
1272 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001273 {
1274 Error error;
1275 ReadPointedString(s,
1276 error,
1277 0,
Greg Claytonafacd142011-09-02 01:15:17 +00001278 (custom_format == eFormatVectorOfChar) ||
1279 (custom_format == eFormatCharArray));
Enrico Granataf4efecd2011-07-12 22:56:10 +00001280 return !error.Fail();
1281 }
1282
Greg Claytonafacd142011-09-02 01:15:17 +00001283 if (custom_format == eFormatEnum)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001284 return false;
1285
1286 // this only works for arrays, because I have no way to know when
1287 // the pointed memory ends, and no special \0 end of data marker
1288 if (flags.Test(ClangASTContext::eTypeIsArray))
1289 {
Greg Claytonafacd142011-09-02 01:15:17 +00001290 if ((custom_format == eFormatBytes) ||
1291 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001292 {
1293 uint32_t count = GetNumChildren();
1294
1295 s << '[';
1296 for (uint32_t low = 0; low < count; low++)
1297 {
1298
1299 if (low)
1300 s << ',';
1301
1302 ValueObjectSP child = GetChildAtIndex(low,true);
1303 if (!child.get())
1304 {
Enrico Granatae992a082011-07-22 17:03:19 +00001305 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001306 continue;
1307 }
1308 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1309 }
1310
1311 s << ']';
1312
1313 return true;
1314 }
1315
Greg Claytonafacd142011-09-02 01:15:17 +00001316 if ((custom_format == eFormatVectorOfChar) ||
1317 (custom_format == eFormatVectorOfFloat32) ||
1318 (custom_format == eFormatVectorOfFloat64) ||
1319 (custom_format == eFormatVectorOfSInt16) ||
1320 (custom_format == eFormatVectorOfSInt32) ||
1321 (custom_format == eFormatVectorOfSInt64) ||
1322 (custom_format == eFormatVectorOfSInt8) ||
1323 (custom_format == eFormatVectorOfUInt128) ||
1324 (custom_format == eFormatVectorOfUInt16) ||
1325 (custom_format == eFormatVectorOfUInt32) ||
1326 (custom_format == eFormatVectorOfUInt64) ||
1327 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001328 {
1329 uint32_t count = GetNumChildren();
1330
Greg Claytonafacd142011-09-02 01:15:17 +00001331 Format format = FormatManager::GetSingleItemFormat(custom_format);
Enrico Granataf4efecd2011-07-12 22:56:10 +00001332
1333 s << '[';
1334 for (uint32_t low = 0; low < count; low++)
1335 {
1336
1337 if (low)
1338 s << ',';
1339
1340 ValueObjectSP child = GetChildAtIndex(low,true);
1341 if (!child.get())
1342 {
Enrico Granatae992a082011-07-22 17:03:19 +00001343 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001344 continue;
1345 }
1346 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1347 }
1348
1349 s << ']';
1350
1351 return true;
1352 }
1353 }
1354
Greg Claytonafacd142011-09-02 01:15:17 +00001355 if ((custom_format == eFormatBoolean) ||
1356 (custom_format == eFormatBinary) ||
1357 (custom_format == eFormatChar) ||
1358 (custom_format == eFormatCharPrintable) ||
1359 (custom_format == eFormatComplexFloat) ||
1360 (custom_format == eFormatDecimal) ||
1361 (custom_format == eFormatHex) ||
1362 (custom_format == eFormatFloat) ||
1363 (custom_format == eFormatOctal) ||
1364 (custom_format == eFormatOSType) ||
1365 (custom_format == eFormatUnicode16) ||
1366 (custom_format == eFormatUnicode32) ||
1367 (custom_format == eFormatUnsigned) ||
1368 (custom_format == eFormatPointer) ||
1369 (custom_format == eFormatComplexInteger) ||
1370 (custom_format == eFormatComplex) ||
1371 (custom_format == eFormatDefault)) // use the [] operator
Enrico Granataf4efecd2011-07-12 22:56:10 +00001372 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001373 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001374
1375 if (only_special)
1376 return false;
1377
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001378 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001379 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001380 SetFormat(eFormatDefault);
1381 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001382}
1383
Greg Clayton737b9322010-09-13 03:32:57 +00001384addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001385ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001386{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001387 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001388 return LLDB_INVALID_ADDRESS;
1389
Greg Clayton73b472d2010-10-27 03:32:59 +00001390 switch (m_value.GetValueType())
1391 {
1392 case Value::eValueTypeScalar:
1393 if (scalar_is_load_address)
1394 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001395 if(address_type)
1396 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001397 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1398 }
1399 break;
1400
1401 case Value::eValueTypeLoadAddress:
1402 case Value::eValueTypeFileAddress:
1403 case Value::eValueTypeHostAddress:
1404 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001405 if(address_type)
1406 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001407 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1408 }
1409 break;
1410 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001411 if (address_type)
1412 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001413 return LLDB_INVALID_ADDRESS;
1414}
1415
1416addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001417ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001418{
Greg Claytonafacd142011-09-02 01:15:17 +00001419 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001420 if(address_type)
1421 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001422
Enrico Granatac3e320a2011-08-02 17:27:39 +00001423 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001424 return address;
1425
Greg Clayton73b472d2010-10-27 03:32:59 +00001426 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001427 {
1428 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001429 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001430 break;
1431
Enrico Granata9128ee22011-09-06 19:20:51 +00001432 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001433 case Value::eValueTypeLoadAddress:
1434 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001435 {
1436 uint32_t data_offset = 0;
1437 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001438 }
1439 break;
1440 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001441
Enrico Granata9128ee22011-09-06 19:20:51 +00001442 if (address_type)
1443 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001444
Greg Clayton737b9322010-09-13 03:32:57 +00001445 return address;
1446}
1447
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001448bool
Jim Ingham6035b672011-03-31 00:19:25 +00001449ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001450{
1451 // Make sure our value is up to date first so that our location and location
1452 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001453 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001454 return false;
1455
1456 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001457 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001458
Greg Claytonb1320972010-07-14 00:18:15 +00001459 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001460
Jim Ingham16e0c682011-08-12 23:34:31 +00001461 Value::ValueType value_type = m_value.GetValueType();
1462
1463 if (value_type == Value::eValueTypeScalar)
1464 {
1465 // If the value is already a scalar, then let the scalar change itself:
1466 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1467 }
1468 else if (byte_size <= Scalar::GetMaxByteSize())
1469 {
1470 // If the value fits in a scalar, then make a new scalar and again let the
1471 // scalar code do the conversion, then figure out where to put the new value.
1472 Scalar new_scalar;
1473 Error error;
1474 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1475 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001476 {
Jim Ingham4b536182011-08-09 02:12:22 +00001477 switch (value_type)
1478 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001479 case Value::eValueTypeLoadAddress:
1480 {
1481 // If it is a load address, then the scalar value is the storage location
1482 // of the data, and we have to shove this value down to that load location.
1483 ProcessSP process_sp = GetUpdatePoint().GetProcessSP();
1484 if (process_sp)
1485 {
Greg Claytonafacd142011-09-02 01:15:17 +00001486 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Jim Ingham16e0c682011-08-12 23:34:31 +00001487 size_t bytes_written = process_sp->WriteScalarToMemory (target_addr,
1488 new_scalar,
1489 byte_size,
1490 error);
1491 if (!error.Success() || bytes_written != byte_size)
1492 return false;
1493 }
1494 }
Jim Ingham4b536182011-08-09 02:12:22 +00001495 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001496 case Value::eValueTypeHostAddress:
1497 {
1498 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1499 DataExtractor new_data;
1500 new_data.SetByteOrder (m_data.GetByteOrder());
1501
1502 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1503 m_data.SetData(buffer_sp, 0);
1504 bool success = new_scalar.GetData(new_data);
1505 if (success)
1506 {
1507 new_data.CopyByteOrderedData(0,
1508 byte_size,
1509 const_cast<uint8_t *>(m_data.GetDataStart()),
1510 byte_size,
1511 m_data.GetByteOrder());
1512 }
1513 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1514
1515 }
Jim Ingham4b536182011-08-09 02:12:22 +00001516 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001517 case Value::eValueTypeFileAddress:
1518 case Value::eValueTypeScalar:
1519 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001520 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001521 }
1522 else
1523 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001524 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001525 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001526 }
1527 else
1528 {
1529 // We don't support setting things bigger than a scalar at present.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001530 return false;
1531 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001532
1533 // If we have reached this point, then we have successfully changed the value.
1534 SetNeedsUpdate();
1535 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001536}
1537
Greg Claytonafacd142011-09-02 01:15:17 +00001538LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001539ValueObject::GetObjectRuntimeLanguage ()
1540{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001541 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1542 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001543}
1544
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001545void
Jim Ingham58b59f92011-04-22 23:53:53 +00001546ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001547{
Jim Ingham58b59f92011-04-22 23:53:53 +00001548 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001549}
1550
1551ValueObjectSP
1552ValueObject::GetSyntheticChild (const ConstString &key) const
1553{
1554 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001555 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001556 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001557 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001558 return synthetic_child_sp;
1559}
1560
1561bool
1562ValueObject::IsPointerType ()
1563{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001564 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001565}
1566
Jim Inghamb7603bb2011-03-18 00:05:18 +00001567bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001568ValueObject::IsArrayType ()
1569{
1570 return ClangASTContext::IsArrayType (GetClangType());
1571}
1572
1573bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001574ValueObject::IsScalarType ()
1575{
1576 return ClangASTContext::IsScalarType (GetClangType());
1577}
1578
1579bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001580ValueObject::IsIntegerType (bool &is_signed)
1581{
1582 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1583}
Greg Clayton73b472d2010-10-27 03:32:59 +00001584
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001585bool
1586ValueObject::IsPointerOrReferenceType ()
1587{
Greg Clayton007d5be2011-05-30 00:49:24 +00001588 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1589}
1590
1591bool
1592ValueObject::IsPossibleCPlusPlusDynamicType ()
1593{
1594 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001595}
1596
Greg Claytondea8cb42011-06-29 22:09:02 +00001597bool
1598ValueObject::IsPossibleDynamicType ()
1599{
1600 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1601}
1602
Greg Claytonafacd142011-09-02 01:15:17 +00001603ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001604ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1605{
1606 if (IsArrayType())
1607 return GetSyntheticArrayMemberFromArray(index, can_create);
1608
1609 if (IsPointerType())
1610 return GetSyntheticArrayMemberFromPointer(index, can_create);
1611
1612 return ValueObjectSP();
1613
1614}
1615
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001616ValueObjectSP
1617ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1618{
1619 ValueObjectSP synthetic_child_sp;
1620 if (IsPointerType ())
1621 {
1622 char index_str[64];
1623 snprintf(index_str, sizeof(index_str), "[%i]", index);
1624 ConstString index_const_str(index_str);
1625 // Check if we have already created a synthetic array member in this
1626 // valid object. If we have we will re-use it.
1627 synthetic_child_sp = GetSyntheticChild (index_const_str);
1628 if (!synthetic_child_sp)
1629 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001630 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001631 // We haven't made a synthetic array member for INDEX yet, so
1632 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001633 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001634
1635 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001636 if (synthetic_child)
1637 {
1638 AddSyntheticChild(index_const_str, synthetic_child);
1639 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001640 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001641 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001642 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001643 }
1644 }
1645 return synthetic_child_sp;
1646}
Jim Ingham22777012010-09-23 02:01:19 +00001647
Greg Claytondaf515f2011-07-09 20:12:33 +00001648// This allows you to create an array member using and index
1649// that doesn't not fall in the normal bounds of the array.
1650// Many times structure can be defined as:
1651// struct Collection
1652// {
1653// uint32_t item_count;
1654// Item item_array[0];
1655// };
1656// The size of the "item_array" is 1, but many times in practice
1657// there are more items in "item_array".
1658
1659ValueObjectSP
1660ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1661{
1662 ValueObjectSP synthetic_child_sp;
1663 if (IsArrayType ())
1664 {
1665 char index_str[64];
1666 snprintf(index_str, sizeof(index_str), "[%i]", index);
1667 ConstString index_const_str(index_str);
1668 // Check if we have already created a synthetic array member in this
1669 // valid object. If we have we will re-use it.
1670 synthetic_child_sp = GetSyntheticChild (index_const_str);
1671 if (!synthetic_child_sp)
1672 {
1673 ValueObject *synthetic_child;
1674 // We haven't made a synthetic array member for INDEX yet, so
1675 // lets make one and cache it for any future reference.
1676 synthetic_child = CreateChildAtIndex(0, true, index);
1677
1678 // Cache the value if we got one back...
1679 if (synthetic_child)
1680 {
1681 AddSyntheticChild(index_const_str, synthetic_child);
1682 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001683 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001684 synthetic_child_sp->m_is_array_item_for_pointer = true;
1685 }
1686 }
1687 }
1688 return synthetic_child_sp;
1689}
1690
Enrico Granata9fc19442011-07-06 02:13:41 +00001691ValueObjectSP
1692ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1693{
1694 ValueObjectSP synthetic_child_sp;
1695 if (IsScalarType ())
1696 {
1697 char index_str[64];
1698 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1699 ConstString index_const_str(index_str);
1700 // Check if we have already created a synthetic array member in this
1701 // valid object. If we have we will re-use it.
1702 synthetic_child_sp = GetSyntheticChild (index_const_str);
1703 if (!synthetic_child_sp)
1704 {
1705 ValueObjectChild *synthetic_child;
1706 // We haven't made a synthetic array member for INDEX yet, so
1707 // lets make one and cache it for any future reference.
1708 synthetic_child = new ValueObjectChild(*this,
1709 GetClangAST(),
1710 GetClangType(),
1711 index_const_str,
1712 GetByteSize(),
1713 0,
1714 to-from+1,
1715 from,
1716 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001717 false,
1718 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001719
1720 // Cache the value if we got one back...
1721 if (synthetic_child)
1722 {
1723 AddSyntheticChild(index_const_str, synthetic_child);
1724 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001725 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001726 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1727 }
1728 }
1729 }
1730 return synthetic_child_sp;
1731}
1732
Greg Claytonafacd142011-09-02 01:15:17 +00001733ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001734ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1735{
1736 ValueObjectSP synthetic_child_sp;
1737 if (IsArrayType () || IsPointerType ())
1738 {
1739 char index_str[64];
1740 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1741 ConstString index_const_str(index_str);
1742 // Check if we have already created a synthetic array member in this
1743 // valid object. If we have we will re-use it.
1744 synthetic_child_sp = GetSyntheticChild (index_const_str);
1745 if (!synthetic_child_sp)
1746 {
1747 ValueObjectSynthetic *synthetic_child;
1748
1749 // We haven't made a synthetic array member for INDEX yet, so
1750 // lets make one and cache it for any future reference.
1751 SyntheticArrayView *view = new SyntheticArrayView();
1752 view->AddRange(from,to);
1753 SyntheticChildrenSP view_sp(view);
1754 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1755
1756 // Cache the value if we got one back...
1757 if (synthetic_child)
1758 {
1759 AddSyntheticChild(index_const_str, synthetic_child);
1760 synthetic_child_sp = synthetic_child->GetSP();
1761 synthetic_child_sp->SetName(ConstString(index_str));
1762 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1763 }
1764 }
1765 }
1766 return synthetic_child_sp;
1767}
1768
Greg Claytonafacd142011-09-02 01:15:17 +00001769ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001770ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1771{
1772
1773 ValueObjectSP synthetic_child_sp;
1774
1775 char name_str[64];
1776 snprintf(name_str, sizeof(name_str), "@%i", offset);
1777 ConstString name_const_str(name_str);
1778
1779 // Check if we have already created a synthetic array member in this
1780 // valid object. If we have we will re-use it.
1781 synthetic_child_sp = GetSyntheticChild (name_const_str);
1782
1783 if (synthetic_child_sp.get())
1784 return synthetic_child_sp;
1785
1786 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001787 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001788
1789 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1790 type.GetASTContext(),
1791 type.GetOpaqueQualType(),
1792 name_const_str,
1793 type.GetTypeByteSize(),
1794 offset,
1795 0,
1796 0,
1797 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001798 false,
1799 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001800 if (synthetic_child)
1801 {
1802 AddSyntheticChild(name_const_str, synthetic_child);
1803 synthetic_child_sp = synthetic_child->GetSP();
1804 synthetic_child_sp->SetName(name_const_str);
1805 synthetic_child_sp->m_is_child_at_offset = true;
1806 }
1807 return synthetic_child_sp;
1808}
1809
Enrico Granatad55546b2011-07-22 00:16:08 +00001810// your expression path needs to have a leading . or ->
1811// (unless it somehow "looks like" an array, in which case it has
1812// a leading [ symbol). while the [ is meaningful and should be shown
1813// to the user, . and -> are just parser design, but by no means
1814// added information for the user.. strip them off
1815static const char*
1816SkipLeadingExpressionPathSeparators(const char* expression)
1817{
1818 if (!expression || !expression[0])
1819 return expression;
1820 if (expression[0] == '.')
1821 return expression+1;
1822 if (expression[0] == '-' && expression[1] == '>')
1823 return expression+2;
1824 return expression;
1825}
1826
Greg Claytonafacd142011-09-02 01:15:17 +00001827ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00001828ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1829{
1830 ValueObjectSP synthetic_child_sp;
1831 ConstString name_const_string(expression);
1832 // Check if we have already created a synthetic array member in this
1833 // valid object. If we have we will re-use it.
1834 synthetic_child_sp = GetSyntheticChild (name_const_string);
1835 if (!synthetic_child_sp)
1836 {
1837 // We haven't made a synthetic array member for expression yet, so
1838 // lets make one and cache it for any future reference.
1839 synthetic_child_sp = GetValueForExpressionPath(expression);
1840
1841 // Cache the value if we got one back...
1842 if (synthetic_child_sp.get())
1843 {
1844 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001845 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001846 synthetic_child_sp->m_is_expression_path_child = true;
1847 }
1848 }
1849 return synthetic_child_sp;
1850}
1851
1852void
Greg Claytonafacd142011-09-02 01:15:17 +00001853ValueObject::CalculateSyntheticValue (SyntheticValueType use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00001854{
Greg Claytonafacd142011-09-02 01:15:17 +00001855 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001856 return;
1857
Enrico Granatac3e320a2011-08-02 17:27:39 +00001858 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001859
1860 if (m_last_synthetic_filter.get() == NULL)
1861 return;
1862
Enrico Granataa37a0652011-07-24 00:14:56 +00001863 if (m_synthetic_value == NULL)
1864 m_synthetic_value = new ValueObjectSynthetic(*this, m_last_synthetic_filter);
Enrico Granatad55546b2011-07-22 00:16:08 +00001865
1866}
1867
Jim Ingham78a685a2011-04-16 00:01:13 +00001868void
Greg Claytonafacd142011-09-02 01:15:17 +00001869ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00001870{
Greg Claytonafacd142011-09-02 01:15:17 +00001871 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00001872 return;
1873
Jim Ingham58b59f92011-04-22 23:53:53 +00001874 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00001875 {
Enrico Granata6f3533f2011-07-29 19:53:35 +00001876 Process *process = m_update_point.GetProcessSP().get();
Jim Ingham78a685a2011-04-16 00:01:13 +00001877 bool worth_having_dynamic_value = false;
Jim Ingham22777012010-09-23 02:01:19 +00001878
Jim Ingham78a685a2011-04-16 00:01:13 +00001879
1880 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
1881 // hard code this everywhere.
Greg Claytonafacd142011-09-02 01:15:17 +00001882 LanguageType known_type = GetObjectRuntimeLanguage();
1883 if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
Jim Ingham78a685a2011-04-16 00:01:13 +00001884 {
1885 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
1886 if (runtime)
1887 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
1888 }
1889 else
1890 {
Greg Claytonafacd142011-09-02 01:15:17 +00001891 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus);
Jim Ingham78a685a2011-04-16 00:01:13 +00001892 if (cpp_runtime)
1893 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
1894
1895 if (!worth_having_dynamic_value)
1896 {
Greg Claytonafacd142011-09-02 01:15:17 +00001897 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC);
Jim Ingham78a685a2011-04-16 00:01:13 +00001898 if (objc_runtime)
Jim Ingham2837b762011-05-04 03:43:18 +00001899 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00001900 }
1901 }
1902
1903 if (worth_having_dynamic_value)
Jim Ingham2837b762011-05-04 03:43:18 +00001904 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham58b59f92011-04-22 23:53:53 +00001905
1906// if (worth_having_dynamic_value)
1907// printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager);
1908
Jim Ingham78a685a2011-04-16 00:01:13 +00001909 }
1910}
1911
Jim Ingham58b59f92011-04-22 23:53:53 +00001912ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00001913ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00001914{
Greg Claytonafacd142011-09-02 01:15:17 +00001915 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00001916 return ValueObjectSP();
1917
1918 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00001919 {
Jim Ingham2837b762011-05-04 03:43:18 +00001920 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001921 }
Jim Ingham58b59f92011-04-22 23:53:53 +00001922 if (m_dynamic_value)
1923 return m_dynamic_value->GetSP();
1924 else
1925 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00001926}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001927
Jim Ingham60dbabb2011-12-08 19:44:08 +00001928ValueObjectSP
1929ValueObject::GetStaticValue()
1930{
1931 return GetSP();
1932}
1933
Enrico Granatad55546b2011-07-22 00:16:08 +00001934// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
1935// or we do not really want a dynamic VO. this method instead returns this object
1936// itself when making it synthetic has no meaning. this makes it much simpler
1937// to replace the SyntheticValue for the ValueObject
1938ValueObjectSP
1939ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
1940{
Greg Claytonafacd142011-09-02 01:15:17 +00001941 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001942 return GetSP();
1943
Enrico Granatac3e320a2011-08-02 17:27:39 +00001944 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001945
1946 if (m_last_synthetic_filter.get() == NULL)
1947 return GetSP();
1948
1949 CalculateSyntheticValue(use_synthetic);
1950
1951 if (m_synthetic_value)
1952 return m_synthetic_value->GetSP();
1953 else
1954 return GetSP();
1955}
1956
Greg Claytone221f822011-01-21 01:59:00 +00001957bool
Enrico Granata27b625e2011-08-09 01:04:56 +00001958ValueObject::HasSyntheticValue()
1959{
1960 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
1961
1962 if (m_last_synthetic_filter.get() == NULL)
1963 return false;
1964
Greg Claytonafacd142011-09-02 01:15:17 +00001965 CalculateSyntheticValue(eUseSyntheticFilter);
Enrico Granata27b625e2011-08-09 01:04:56 +00001966
1967 if (m_synthetic_value)
1968 return true;
1969 else
1970 return false;
1971}
1972
1973bool
Greg Claytone221f822011-01-21 01:59:00 +00001974ValueObject::GetBaseClassPath (Stream &s)
1975{
1976 if (IsBaseClass())
1977 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001978 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00001979 clang_type_t clang_type = GetClangType();
1980 std::string cxx_class_name;
1981 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
1982 if (this_had_base_class)
1983 {
1984 if (parent_had_base_class)
1985 s.PutCString("::");
1986 s.PutCString(cxx_class_name.c_str());
1987 }
1988 return parent_had_base_class || this_had_base_class;
1989 }
1990 return false;
1991}
1992
1993
1994ValueObject *
1995ValueObject::GetNonBaseClassParent()
1996{
Jim Ingham78a685a2011-04-16 00:01:13 +00001997 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00001998 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001999 if (GetParent()->IsBaseClass())
2000 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002001 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002002 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002003 }
2004 return NULL;
2005}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002006
2007void
Enrico Granata4becb372011-06-29 22:27:15 +00002008ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002009{
Greg Claytone221f822011-01-21 01:59:00 +00002010 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002011
Enrico Granata85933ed2011-08-18 16:38:26 +00002012 if (is_deref_of_parent && epformat == eDereferencePointers)
2013 {
Enrico Granata4becb372011-06-29 22:27:15 +00002014 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2015 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2016 // the eHonorPointers mode is meant to produce strings in this latter format
2017 s.PutCString("*(");
2018 }
Greg Claytone221f822011-01-21 01:59:00 +00002019
Enrico Granata4becb372011-06-29 22:27:15 +00002020 ValueObject* parent = GetParent();
2021
2022 if (parent)
2023 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002024
2025 // if we are a deref_of_parent just because we are synthetic array
2026 // members made up to allow ptr[%d] syntax to work in variable
2027 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00002028 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002029 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002030
Greg Claytone221f822011-01-21 01:59:00 +00002031 if (!IsBaseClass())
2032 {
2033 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002034 {
Greg Claytone221f822011-01-21 01:59:00 +00002035 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2036 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002037 {
Greg Claytone221f822011-01-21 01:59:00 +00002038 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2039 if (non_base_class_parent_clang_type)
2040 {
2041 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2042
Enrico Granata9dd75c82011-07-15 23:30:15 +00002043 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002044 {
2045 s.PutCString("->");
2046 }
Enrico Granata4becb372011-06-29 22:27:15 +00002047 else
2048 {
2049 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2050 {
2051 s.PutCString("->");
2052 }
2053 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2054 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2055 {
2056 s.PutChar('.');
2057 }
Greg Claytone221f822011-01-21 01:59:00 +00002058 }
2059 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002060 }
Greg Claytone221f822011-01-21 01:59:00 +00002061
2062 const char *name = GetName().GetCString();
2063 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002064 {
Greg Claytone221f822011-01-21 01:59:00 +00002065 if (qualify_cxx_base_classes)
2066 {
2067 if (GetBaseClassPath (s))
2068 s.PutCString("::");
2069 }
2070 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002071 }
2072 }
2073 }
2074
Enrico Granata85933ed2011-08-18 16:38:26 +00002075 if (is_deref_of_parent && epformat == eDereferencePointers)
2076 {
Greg Claytone221f822011-01-21 01:59:00 +00002077 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002078 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002079}
2080
Greg Claytonafacd142011-09-02 01:15:17 +00002081ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002082ValueObject::GetValueForExpressionPath(const char* expression,
2083 const char** first_unparsed,
2084 ExpressionPathScanEndReason* reason_to_stop,
2085 ExpressionPathEndResultType* final_value_type,
2086 const GetValueForExpressionPathOptions& options,
2087 ExpressionPathAftermath* final_task_on_target)
2088{
2089
2090 const char* dummy_first_unparsed;
2091 ExpressionPathScanEndReason dummy_reason_to_stop;
2092 ExpressionPathEndResultType dummy_final_value_type;
2093 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2094
2095 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2096 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2097 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2098 final_value_type ? final_value_type : &dummy_final_value_type,
2099 options,
2100 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2101
2102 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2103 {
2104 return ret_val;
2105 }
2106 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2107 {
2108 if (*final_task_on_target == ValueObject::eDereference)
2109 {
2110 Error error;
2111 ValueObjectSP final_value = ret_val->Dereference(error);
2112 if (error.Fail() || !final_value.get())
2113 {
2114 *reason_to_stop = ValueObject::eDereferencingFailed;
2115 *final_value_type = ValueObject::eInvalid;
2116 return ValueObjectSP();
2117 }
2118 else
2119 {
2120 *final_task_on_target = ValueObject::eNothing;
2121 return final_value;
2122 }
2123 }
2124 if (*final_task_on_target == ValueObject::eTakeAddress)
2125 {
2126 Error error;
2127 ValueObjectSP final_value = ret_val->AddressOf(error);
2128 if (error.Fail() || !final_value.get())
2129 {
2130 *reason_to_stop = ValueObject::eTakingAddressFailed;
2131 *final_value_type = ValueObject::eInvalid;
2132 return ValueObjectSP();
2133 }
2134 else
2135 {
2136 *final_task_on_target = ValueObject::eNothing;
2137 return final_value;
2138 }
2139 }
2140 }
2141 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2142}
2143
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002144int
2145ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002146 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002147 const char** first_unparsed,
2148 ExpressionPathScanEndReason* reason_to_stop,
2149 ExpressionPathEndResultType* final_value_type,
2150 const GetValueForExpressionPathOptions& options,
2151 ExpressionPathAftermath* final_task_on_target)
2152{
2153 const char* dummy_first_unparsed;
2154 ExpressionPathScanEndReason dummy_reason_to_stop;
2155 ExpressionPathEndResultType dummy_final_value_type;
2156 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2157
2158 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2159 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2160 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2161 final_value_type ? final_value_type : &dummy_final_value_type,
2162 options,
2163 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2164
2165 if (!ret_val.get()) // if there are errors, I add nothing to the list
2166 return 0;
2167
2168 if (*reason_to_stop != eArrayRangeOperatorMet)
2169 {
2170 // I need not expand a range, just post-process the final value and return
2171 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2172 {
2173 list->Append(ret_val);
2174 return 1;
2175 }
2176 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2177 {
2178 if (*final_task_on_target == ValueObject::eDereference)
2179 {
2180 Error error;
2181 ValueObjectSP final_value = ret_val->Dereference(error);
2182 if (error.Fail() || !final_value.get())
2183 {
2184 *reason_to_stop = ValueObject::eDereferencingFailed;
2185 *final_value_type = ValueObject::eInvalid;
2186 return 0;
2187 }
2188 else
2189 {
2190 *final_task_on_target = ValueObject::eNothing;
2191 list->Append(final_value);
2192 return 1;
2193 }
2194 }
2195 if (*final_task_on_target == ValueObject::eTakeAddress)
2196 {
2197 Error error;
2198 ValueObjectSP final_value = ret_val->AddressOf(error);
2199 if (error.Fail() || !final_value.get())
2200 {
2201 *reason_to_stop = ValueObject::eTakingAddressFailed;
2202 *final_value_type = ValueObject::eInvalid;
2203 return 0;
2204 }
2205 else
2206 {
2207 *final_task_on_target = ValueObject::eNothing;
2208 list->Append(final_value);
2209 return 1;
2210 }
2211 }
2212 }
2213 }
2214 else
2215 {
2216 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2217 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2218 ret_val,
2219 list,
2220 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2221 final_value_type ? final_value_type : &dummy_final_value_type,
2222 options,
2223 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2224 }
2225 // in any non-covered case, just do the obviously right thing
2226 list->Append(ret_val);
2227 return 1;
2228}
2229
Greg Claytonafacd142011-09-02 01:15:17 +00002230ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002231ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2232 const char** first_unparsed,
2233 ExpressionPathScanEndReason* reason_to_stop,
2234 ExpressionPathEndResultType* final_result,
2235 const GetValueForExpressionPathOptions& options,
2236 ExpressionPathAftermath* what_next)
2237{
2238 ValueObjectSP root = GetSP();
2239
2240 if (!root.get())
2241 return ValueObjectSP();
2242
2243 *first_unparsed = expression_cstr;
2244
2245 while (true)
2246 {
2247
2248 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2249
Greg Claytonafacd142011-09-02 01:15:17 +00002250 clang_type_t root_clang_type = root->GetClangType();
2251 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002252 Flags root_clang_type_info,pointee_clang_type_info;
2253
2254 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2255 if (pointee_clang_type)
2256 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002257
2258 if (!expression_cstr || *expression_cstr == '\0')
2259 {
2260 *reason_to_stop = ValueObject::eEndOfString;
2261 return root;
2262 }
2263
2264 switch (*expression_cstr)
2265 {
2266 case '-':
2267 {
2268 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002269 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 +00002270 {
2271 *first_unparsed = expression_cstr;
2272 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
2273 *final_result = ValueObject::eInvalid;
2274 return ValueObjectSP();
2275 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002276 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2277 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002278 options.m_no_fragile_ivar)
2279 {
2280 *first_unparsed = expression_cstr;
2281 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
2282 *final_result = ValueObject::eInvalid;
2283 return ValueObjectSP();
2284 }
2285 if (expression_cstr[1] != '>')
2286 {
2287 *first_unparsed = expression_cstr;
2288 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2289 *final_result = ValueObject::eInvalid;
2290 return ValueObjectSP();
2291 }
2292 expression_cstr++; // skip the -
2293 }
2294 case '.': // or fallthrough from ->
2295 {
2296 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002297 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 +00002298 {
2299 *first_unparsed = expression_cstr;
2300 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
2301 *final_result = ValueObject::eInvalid;
2302 return ValueObjectSP();
2303 }
2304 expression_cstr++; // skip .
2305 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2306 ConstString child_name;
2307 if (!next_separator) // if no other separator just expand this last layer
2308 {
2309 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002310 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2311
2312 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002313 {
2314 *first_unparsed = '\0';
2315 *reason_to_stop = ValueObject::eEndOfString;
2316 *final_result = ValueObject::ePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002317 return child_valobj_sp;
2318 }
2319 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2320 {
Greg Clayton4c3b8fb2011-12-02 22:48:25 +00002321 child_valobj_sp = root->GetSyntheticValue(eNoSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002322 }
2323
2324 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2325 // so we hit the "else" branch, and return an error
2326 if(child_valobj_sp.get()) // if it worked, just return
2327 {
2328 *first_unparsed = '\0';
2329 *reason_to_stop = ValueObject::eEndOfString;
2330 *final_result = ValueObject::ePlain;
2331 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002332 }
2333 else
2334 {
2335 *first_unparsed = expression_cstr;
2336 *reason_to_stop = ValueObject::eNoSuchChild;
2337 *final_result = ValueObject::eInvalid;
2338 return ValueObjectSP();
2339 }
2340 }
2341 else // other layers do expand
2342 {
2343 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002344 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2345 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002346 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002347 root = child_valobj_sp;
2348 *first_unparsed = next_separator;
2349 *final_result = ValueObject::ePlain;
2350 continue;
2351 }
2352 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2353 {
Greg Claytonafacd142011-09-02 01:15:17 +00002354 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002355 }
2356
2357 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2358 // so we hit the "else" branch, and return an error
2359 if(child_valobj_sp.get()) // if it worked, move on
2360 {
2361 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002362 *first_unparsed = next_separator;
2363 *final_result = ValueObject::ePlain;
2364 continue;
2365 }
2366 else
2367 {
2368 *first_unparsed = expression_cstr;
2369 *reason_to_stop = ValueObject::eNoSuchChild;
2370 *final_result = ValueObject::eInvalid;
2371 return ValueObjectSP();
2372 }
2373 }
2374 break;
2375 }
2376 case '[':
2377 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002378 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 +00002379 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002380 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002381 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002382 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2383 {
2384 *first_unparsed = expression_cstr;
2385 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2386 *final_result = ValueObject::eInvalid;
2387 return ValueObjectSP();
2388 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002389 }
2390 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2391 {
2392 *first_unparsed = expression_cstr;
2393 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2394 *final_result = ValueObject::eInvalid;
2395 return ValueObjectSP();
2396 }
2397 }
2398 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2399 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002400 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002401 {
2402 *first_unparsed = expression_cstr;
2403 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2404 *final_result = ValueObject::eInvalid;
2405 return ValueObjectSP();
2406 }
2407 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2408 {
2409 *first_unparsed = expression_cstr+2;
2410 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2411 *final_result = ValueObject::eUnboundedRange;
2412 return root;
2413 }
2414 }
2415 const char *separator_position = ::strchr(expression_cstr+1,'-');
2416 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2417 if (!close_bracket_position) // if there is no ], this is a syntax error
2418 {
2419 *first_unparsed = expression_cstr;
2420 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2421 *final_result = ValueObject::eInvalid;
2422 return ValueObjectSP();
2423 }
2424 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2425 {
2426 char *end = NULL;
2427 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2428 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2429 {
2430 *first_unparsed = expression_cstr;
2431 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2432 *final_result = ValueObject::eInvalid;
2433 return ValueObjectSP();
2434 }
2435 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2436 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002437 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002438 {
2439 *first_unparsed = expression_cstr+2;
2440 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2441 *final_result = ValueObject::eUnboundedRange;
2442 return root;
2443 }
2444 else
2445 {
2446 *first_unparsed = expression_cstr;
2447 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2448 *final_result = ValueObject::eInvalid;
2449 return ValueObjectSP();
2450 }
2451 }
2452 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002453 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002454 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002455 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2456 if (!child_valobj_sp)
2457 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002458 if (!child_valobj_sp)
Greg Claytonafacd142011-09-02 01:15:17 +00002459 if (root->HasSyntheticValue() && root->GetSyntheticValue(eUseSyntheticFilter)->GetNumChildren() > index)
2460 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002461 if (child_valobj_sp)
2462 {
2463 root = child_valobj_sp;
2464 *first_unparsed = end+1; // skip ]
2465 *final_result = ValueObject::ePlain;
2466 continue;
2467 }
2468 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002469 {
2470 *first_unparsed = expression_cstr;
2471 *reason_to_stop = ValueObject::eNoSuchChild;
2472 *final_result = ValueObject::eInvalid;
2473 return ValueObjectSP();
2474 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002475 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002476 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002477 {
2478 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 +00002479 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002480 {
2481 Error error;
2482 root = root->Dereference(error);
2483 if (error.Fail() || !root.get())
2484 {
2485 *first_unparsed = expression_cstr;
2486 *reason_to_stop = ValueObject::eDereferencingFailed;
2487 *final_result = ValueObject::eInvalid;
2488 return ValueObjectSP();
2489 }
2490 else
2491 {
2492 *what_next = eNothing;
2493 continue;
2494 }
2495 }
2496 else
2497 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002498 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Claytonafacd142011-09-02 01:15:17 +00002499 root->GetClangType()) == eLanguageTypeObjC
Enrico Granata27b625e2011-08-09 01:04:56 +00002500 &&
2501 ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2502 &&
2503 root->HasSyntheticValue()
2504 &&
2505 options.m_no_synthetic_children == false)
2506 {
Greg Claytonafacd142011-09-02 01:15:17 +00002507 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002508 }
2509 else
2510 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002511 if (!root.get())
2512 {
2513 *first_unparsed = expression_cstr;
2514 *reason_to_stop = ValueObject::eNoSuchChild;
2515 *final_result = ValueObject::eInvalid;
2516 return ValueObjectSP();
2517 }
2518 else
2519 {
2520 *first_unparsed = end+1; // skip ]
2521 *final_result = ValueObject::ePlain;
2522 continue;
2523 }
2524 }
2525 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002526 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002527 {
2528 root = root->GetSyntheticBitFieldChild(index, index, true);
2529 if (!root.get())
2530 {
2531 *first_unparsed = expression_cstr;
2532 *reason_to_stop = ValueObject::eNoSuchChild;
2533 *final_result = ValueObject::eInvalid;
2534 return ValueObjectSP();
2535 }
2536 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2537 {
2538 *first_unparsed = end+1; // skip ]
2539 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2540 *final_result = ValueObject::eBitfield;
2541 return root;
2542 }
2543 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002544 else if (root->HasSyntheticValue() && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002545 {
Greg Claytonafacd142011-09-02 01:15:17 +00002546 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002547 if (!root.get())
2548 {
2549 *first_unparsed = expression_cstr;
2550 *reason_to_stop = ValueObject::eNoSuchChild;
2551 *final_result = ValueObject::eInvalid;
2552 return ValueObjectSP();
2553 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002554 else
2555 {
2556 *first_unparsed = end+1; // skip ]
2557 *final_result = ValueObject::ePlain;
2558 continue;
2559 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002560 }
2561 else
2562 {
2563 *first_unparsed = expression_cstr;
2564 *reason_to_stop = ValueObject::eNoSuchChild;
2565 *final_result = ValueObject::eInvalid;
2566 return ValueObjectSP();
2567 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002568 }
2569 else // we have a low and a high index
2570 {
2571 char *end = NULL;
2572 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2573 if (!end || end != separator_position) // if something weird is in our way return an error
2574 {
2575 *first_unparsed = expression_cstr;
2576 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2577 *final_result = ValueObject::eInvalid;
2578 return ValueObjectSP();
2579 }
2580 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2581 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2582 {
2583 *first_unparsed = expression_cstr;
2584 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2585 *final_result = ValueObject::eInvalid;
2586 return ValueObjectSP();
2587 }
2588 if (index_lower > index_higher) // swap indices if required
2589 {
2590 unsigned long temp = index_lower;
2591 index_lower = index_higher;
2592 index_higher = temp;
2593 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002594 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002595 {
2596 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2597 if (!root.get())
2598 {
2599 *first_unparsed = expression_cstr;
2600 *reason_to_stop = ValueObject::eNoSuchChild;
2601 *final_result = ValueObject::eInvalid;
2602 return ValueObjectSP();
2603 }
2604 else
2605 {
2606 *first_unparsed = end+1; // skip ]
2607 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2608 *final_result = ValueObject::eBitfield;
2609 return root;
2610 }
2611 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002612 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 +00002613 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002614 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002615 {
2616 Error error;
2617 root = root->Dereference(error);
2618 if (error.Fail() || !root.get())
2619 {
2620 *first_unparsed = expression_cstr;
2621 *reason_to_stop = ValueObject::eDereferencingFailed;
2622 *final_result = ValueObject::eInvalid;
2623 return ValueObjectSP();
2624 }
2625 else
2626 {
2627 *what_next = ValueObject::eNothing;
2628 continue;
2629 }
2630 }
2631 else
2632 {
2633 *first_unparsed = expression_cstr;
2634 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2635 *final_result = ValueObject::eBoundedRange;
2636 return root;
2637 }
2638 }
2639 break;
2640 }
2641 default: // some non-separator is in the way
2642 {
2643 *first_unparsed = expression_cstr;
2644 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2645 *final_result = ValueObject::eInvalid;
2646 return ValueObjectSP();
2647 break;
2648 }
2649 }
2650 }
2651}
2652
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002653int
2654ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2655 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002656 ValueObjectSP root,
2657 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002658 ExpressionPathScanEndReason* reason_to_stop,
2659 ExpressionPathEndResultType* final_result,
2660 const GetValueForExpressionPathOptions& options,
2661 ExpressionPathAftermath* what_next)
2662{
2663 if (!root.get())
2664 return 0;
2665
2666 *first_unparsed = expression_cstr;
2667
2668 while (true)
2669 {
2670
2671 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2672
Greg Claytonafacd142011-09-02 01:15:17 +00002673 clang_type_t root_clang_type = root->GetClangType();
2674 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002675 Flags root_clang_type_info,pointee_clang_type_info;
2676
2677 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2678 if (pointee_clang_type)
2679 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2680
2681 if (!expression_cstr || *expression_cstr == '\0')
2682 {
2683 *reason_to_stop = ValueObject::eEndOfString;
2684 list->Append(root);
2685 return 1;
2686 }
2687
2688 switch (*expression_cstr)
2689 {
2690 case '[':
2691 {
2692 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2693 {
2694 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2695 {
2696 *first_unparsed = expression_cstr;
2697 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2698 *final_result = ValueObject::eInvalid;
2699 return 0;
2700 }
2701 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2702 {
2703 *first_unparsed = expression_cstr;
2704 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2705 *final_result = ValueObject::eInvalid;
2706 return 0;
2707 }
2708 }
2709 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2710 {
2711 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2712 {
2713 *first_unparsed = expression_cstr;
2714 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2715 *final_result = ValueObject::eInvalid;
2716 return 0;
2717 }
2718 else // expand this into list
2719 {
2720 int max_index = root->GetNumChildren() - 1;
2721 for (int index = 0; index < max_index; index++)
2722 {
2723 ValueObjectSP child =
2724 root->GetChildAtIndex(index, true);
2725 list->Append(child);
2726 }
2727 *first_unparsed = expression_cstr+2;
2728 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2729 *final_result = ValueObject::eValueObjectList;
2730 return max_index; // tell me number of items I added to the VOList
2731 }
2732 }
2733 const char *separator_position = ::strchr(expression_cstr+1,'-');
2734 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2735 if (!close_bracket_position) // if there is no ], this is a syntax error
2736 {
2737 *first_unparsed = expression_cstr;
2738 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2739 *final_result = ValueObject::eInvalid;
2740 return 0;
2741 }
2742 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2743 {
2744 char *end = NULL;
2745 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2746 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2747 {
2748 *first_unparsed = expression_cstr;
2749 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2750 *final_result = ValueObject::eInvalid;
2751 return 0;
2752 }
2753 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2754 {
2755 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2756 {
2757 int max_index = root->GetNumChildren() - 1;
2758 for (int index = 0; index < max_index; index++)
2759 {
2760 ValueObjectSP child =
2761 root->GetChildAtIndex(index, true);
2762 list->Append(child);
2763 }
2764 *first_unparsed = expression_cstr+2;
2765 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2766 *final_result = ValueObject::eValueObjectList;
2767 return max_index; // tell me number of items I added to the VOList
2768 }
2769 else
2770 {
2771 *first_unparsed = expression_cstr;
2772 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2773 *final_result = ValueObject::eInvalid;
2774 return 0;
2775 }
2776 }
2777 // from here on we do have a valid index
2778 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2779 {
2780 root = root->GetChildAtIndex(index, true);
2781 if (!root.get())
2782 {
2783 *first_unparsed = expression_cstr;
2784 *reason_to_stop = ValueObject::eNoSuchChild;
2785 *final_result = ValueObject::eInvalid;
2786 return 0;
2787 }
2788 else
2789 {
2790 list->Append(root);
2791 *first_unparsed = end+1; // skip ]
2792 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2793 *final_result = ValueObject::eValueObjectList;
2794 return 1;
2795 }
2796 }
2797 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2798 {
2799 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
2800 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2801 {
2802 Error error;
2803 root = root->Dereference(error);
2804 if (error.Fail() || !root.get())
2805 {
2806 *first_unparsed = expression_cstr;
2807 *reason_to_stop = ValueObject::eDereferencingFailed;
2808 *final_result = ValueObject::eInvalid;
2809 return 0;
2810 }
2811 else
2812 {
2813 *what_next = eNothing;
2814 continue;
2815 }
2816 }
2817 else
2818 {
2819 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2820 if (!root.get())
2821 {
2822 *first_unparsed = expression_cstr;
2823 *reason_to_stop = ValueObject::eNoSuchChild;
2824 *final_result = ValueObject::eInvalid;
2825 return 0;
2826 }
2827 else
2828 {
2829 list->Append(root);
2830 *first_unparsed = end+1; // skip ]
2831 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2832 *final_result = ValueObject::eValueObjectList;
2833 return 1;
2834 }
2835 }
2836 }
2837 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2838 {
2839 root = root->GetSyntheticBitFieldChild(index, index, true);
2840 if (!root.get())
2841 {
2842 *first_unparsed = expression_cstr;
2843 *reason_to_stop = ValueObject::eNoSuchChild;
2844 *final_result = ValueObject::eInvalid;
2845 return 0;
2846 }
2847 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2848 {
2849 list->Append(root);
2850 *first_unparsed = end+1; // skip ]
2851 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2852 *final_result = ValueObject::eValueObjectList;
2853 return 1;
2854 }
2855 }
2856 }
2857 else // we have a low and a high index
2858 {
2859 char *end = NULL;
2860 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2861 if (!end || end != separator_position) // if something weird is in our way return an error
2862 {
2863 *first_unparsed = expression_cstr;
2864 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2865 *final_result = ValueObject::eInvalid;
2866 return 0;
2867 }
2868 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2869 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2870 {
2871 *first_unparsed = expression_cstr;
2872 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2873 *final_result = ValueObject::eInvalid;
2874 return 0;
2875 }
2876 if (index_lower > index_higher) // swap indices if required
2877 {
2878 unsigned long temp = index_lower;
2879 index_lower = index_higher;
2880 index_higher = temp;
2881 }
2882 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
2883 {
2884 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2885 if (!root.get())
2886 {
2887 *first_unparsed = expression_cstr;
2888 *reason_to_stop = ValueObject::eNoSuchChild;
2889 *final_result = ValueObject::eInvalid;
2890 return 0;
2891 }
2892 else
2893 {
2894 list->Append(root);
2895 *first_unparsed = end+1; // skip ]
2896 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2897 *final_result = ValueObject::eValueObjectList;
2898 return 1;
2899 }
2900 }
2901 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
2902 *what_next == ValueObject::eDereference &&
2903 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2904 {
2905 Error error;
2906 root = root->Dereference(error);
2907 if (error.Fail() || !root.get())
2908 {
2909 *first_unparsed = expression_cstr;
2910 *reason_to_stop = ValueObject::eDereferencingFailed;
2911 *final_result = ValueObject::eInvalid;
2912 return 0;
2913 }
2914 else
2915 {
2916 *what_next = ValueObject::eNothing;
2917 continue;
2918 }
2919 }
2920 else
2921 {
Johnny Chen44805302011-07-19 19:48:13 +00002922 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002923 index <= index_higher; index++)
2924 {
2925 ValueObjectSP child =
2926 root->GetChildAtIndex(index, true);
2927 list->Append(child);
2928 }
2929 *first_unparsed = end+1;
2930 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2931 *final_result = ValueObject::eValueObjectList;
2932 return index_higher-index_lower+1; // tell me number of items I added to the VOList
2933 }
2934 }
2935 break;
2936 }
2937 default: // some non-[ separator, or something entirely wrong, is in the way
2938 {
2939 *first_unparsed = expression_cstr;
2940 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2941 *final_result = ValueObject::eInvalid;
2942 return 0;
2943 break;
2944 }
2945 }
2946 }
2947}
2948
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002949void
Greg Clayton1d3afba2010-10-05 00:00:42 +00002950ValueObject::DumpValueObject
2951(
2952 Stream &s,
Greg Clayton1d3afba2010-10-05 00:00:42 +00002953 ValueObject *valobj,
2954 const char *root_valobj_name,
2955 uint32_t ptr_depth,
2956 uint32_t curr_depth,
2957 uint32_t max_depth,
2958 bool show_types,
2959 bool show_location,
2960 bool use_objc,
Greg Claytonafacd142011-09-02 01:15:17 +00002961 DynamicValueType use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00002962 bool use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002963 bool scope_already_checked,
Enrico Granata0c5ef692011-07-16 01:22:04 +00002964 bool flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00002965 uint32_t omit_summary_depth,
2966 bool ignore_cap
Greg Clayton1d3afba2010-10-05 00:00:42 +00002967)
2968{
Greg Clayton007d5be2011-05-30 00:49:24 +00002969 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002970 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00002971 bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00002972
Greg Claytonafacd142011-09-02 01:15:17 +00002973 if (update_success && use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00002974 {
Jim Ingham2837b762011-05-04 03:43:18 +00002975 ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00002976 if (dynamic_value)
2977 valobj = dynamic_value;
2978 }
2979
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002980 clang_type_t clang_type = valobj->GetClangType();
2981
Greg Clayton73b472d2010-10-27 03:32:59 +00002982 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002983 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00002984 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
2985 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002986
2987 const bool print_valobj = flat_output == false || has_value;
2988
2989 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002990 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002991 if (show_location)
2992 {
Jim Ingham6035b672011-03-31 00:19:25 +00002993 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002994 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002995
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002996 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00002997
Greg Clayton7c8a9662010-11-02 01:50:16 +00002998 // Always show the type for the top level items.
Greg Claytone221f822011-01-21 01:59:00 +00002999 if (show_types || (curr_depth == 0 && !flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003000 {
Enrico Granata9910bc82011-08-03 02:18:51 +00003001 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
3002 s.Printf("(%s", typeName);
3003 // only show dynamic types if the user really wants to see types
Greg Claytonafacd142011-09-02 01:15:17 +00003004 if (show_types && use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003005 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003006 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003007 {
3008 Process* process = valobj->GetUpdatePoint().GetProcessSP().get();
3009 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003010 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003011 else
3012 {
3013 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3014 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003015 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003016 else
3017 {
3018 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3019 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003020 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003021 else
3022 s.Printf(", dynamic type: %s) ",
3023 runtime->GetActualTypeName(isa).GetCString());
3024 }
3025 }
3026 }
3027 else
3028 s.Printf(") ");
3029 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003030
Greg Clayton1d3afba2010-10-05 00:00:42 +00003031
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003032 if (flat_output)
3033 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003034 // If we are showing types, also qualify the C++ base classes
3035 const bool qualify_cxx_base_classes = show_types;
3036 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003037 s.PutCString(" =");
3038 }
3039 else
3040 {
3041 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3042 s.Printf ("%s =", name_cstr);
3043 }
3044
Jim Ingham6035b672011-03-31 00:19:25 +00003045 if (!scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003046 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003047 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003048 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003049 }
3050
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003051 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003052 const char *sum_cstr = NULL;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003053 SummaryFormat* entry = valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003054
Enrico Granata0c5ef692011-07-16 01:22:04 +00003055 if (omit_summary_depth > 0)
3056 entry = NULL;
3057
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003058 if (err_cstr == NULL)
3059 {
Jim Ingham6035b672011-03-31 00:19:25 +00003060 val_cstr = valobj->GetValueAsCString();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003061 err_cstr = valobj->GetError().AsCString();
3062 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003063
3064 if (err_cstr)
3065 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003066 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003067 }
3068 else
3069 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003070 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003071 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003072 {
Enrico Granata4becb372011-06-29 22:27:15 +00003073
Enrico Granata0c5ef692011-07-16 01:22:04 +00003074 sum_cstr = (omit_summary_depth == 0) ? valobj->GetSummaryAsCString() : NULL;
Greg Clayton1d3afba2010-10-05 00:00:42 +00003075
Enrico Granata4becb372011-06-29 22:27:15 +00003076 // We must calculate this value in realtime because entry might alter this variable's value
3077 // (e.g. by saying ${var%fmt}) and render precached values useless
3078 if (val_cstr && (!entry || entry->DoesPrintValue() || !sum_cstr))
3079 s.Printf(" %s", valobj->GetValueAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003080
Enrico Granata9dd75c82011-07-15 23:30:15 +00003081 if (sum_cstr)
Enrico Granata0a3958e2011-07-02 00:25:22 +00003082 {
3083 // for some reason, using %@ (ObjC description) in a summary string, makes
3084 // us believe we need to reset ourselves, thus invalidating the content of
3085 // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty
3086 // let us recalculate it!
3087 if (sum_cstr[0] == '\0')
3088 s.Printf(" %s", valobj->GetSummaryAsCString());
3089 else
3090 s.Printf(" %s", sum_cstr);
3091 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003092
3093 if (use_objc)
3094 {
Jim Ingham6035b672011-03-31 00:19:25 +00003095 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003096 if (object_desc)
3097 s.Printf(" %s\n", object_desc);
3098 else
Sean Callanan672ad942010-10-23 00:18:49 +00003099 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003100 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003101 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003102 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003103
3104 if (curr_depth < max_depth)
3105 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003106 // We will show children for all concrete types. We won't show
3107 // pointer contents unless a pointer depth has been specified.
3108 // We won't reference contents unless the reference is the
3109 // root object (depth of zero).
3110 bool print_children = true;
3111
3112 // Use a new temporary pointer depth in case we override the
3113 // current pointer depth below...
3114 uint32_t curr_ptr_depth = ptr_depth;
3115
3116 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3117 if (is_ptr || is_ref)
3118 {
3119 // We have a pointer or reference whose value is an address.
3120 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003121 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003122 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003123 print_children = false;
3124
3125 else if (is_ref && curr_depth == 0)
3126 {
3127 // If this is the root object (depth is zero) that we are showing
3128 // and it is a reference, and no pointer depth has been supplied
3129 // print out what it references. Don't do this at deeper depths
3130 // otherwise we can end up with infinite recursion...
3131 curr_ptr_depth = 1;
3132 }
3133
3134 if (curr_ptr_depth == 0)
3135 print_children = false;
3136 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003137
Enrico Granata0a3958e2011-07-02 00:25:22 +00003138 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003139 {
Enrico Granatac482a192011-08-17 22:13:59 +00003140 ValueObjectSP synth_valobj = valobj->GetSyntheticValue(use_synth ?
Greg Claytonafacd142011-09-02 01:15:17 +00003141 eUseSyntheticFilter :
3142 eNoSyntheticFilter);
Enrico Granatac482a192011-08-17 22:13:59 +00003143 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003144 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003145 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003146 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003147 if (flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003148 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003149 if (print_valobj)
3150 s.EOL();
3151 }
3152 else
3153 {
3154 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003155 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003156 s.IndentMore();
3157 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003158
3159 uint32_t max_num_children = valobj->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
3160
3161 if (num_children > max_num_children && !ignore_cap)
3162 {
3163 num_children = max_num_children;
3164 print_dotdotdot = true;
3165 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003166
3167 for (uint32_t idx=0; idx<num_children; ++idx)
3168 {
Enrico Granatac482a192011-08-17 22:13:59 +00003169 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003170 if (child_sp.get())
3171 {
3172 DumpValueObject (s,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003173 child_sp.get(),
3174 NULL,
Greg Clayton73b472d2010-10-27 03:32:59 +00003175 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003176 curr_depth + 1,
3177 max_depth,
3178 show_types,
3179 show_location,
3180 false,
Jim Ingham78a685a2011-04-16 00:01:13 +00003181 use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00003182 use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003183 true,
Enrico Granata0c5ef692011-07-16 01:22:04 +00003184 flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00003185 omit_summary_depth > 1 ? omit_summary_depth - 1 : 0,
3186 ignore_cap);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003187 }
3188 }
3189
3190 if (!flat_output)
3191 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003192 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003193 {
3194 valobj->GetUpdatePoint().GetTargetSP()->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003195 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003196 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003197 s.IndentLess();
3198 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003199 }
3200 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003201 else if (has_children)
3202 {
3203 // Aggregate, no children...
3204 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003205 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003206 }
3207 else
3208 {
3209 if (print_valobj)
3210 s.EOL();
3211 }
3212
Greg Clayton1d3afba2010-10-05 00:00:42 +00003213 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003214 else
3215 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003216 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003217 }
3218 }
3219 else
3220 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003221 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003222 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003223 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003224 }
3225 }
3226 }
3227 }
3228}
3229
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003230
3231ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003232ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003233{
3234 ValueObjectSP valobj_sp;
3235
Enrico Granatac3e320a2011-08-02 17:27:39 +00003236 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003237 {
Jim Ingham6035b672011-03-31 00:19:25 +00003238 ExecutionContextScope *exe_scope = GetExecutionContextScope();
3239 if (exe_scope)
3240 {
3241 ExecutionContext exe_ctx;
3242 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003243
Jim Ingham6035b672011-03-31 00:19:25 +00003244 clang::ASTContext *ast = GetClangAST ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003245
Jim Ingham6035b672011-03-31 00:19:25 +00003246 DataExtractor data;
3247 data.SetByteOrder (m_data.GetByteOrder());
3248 data.SetAddressByteSize(m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003249
Greg Clayton644247c2011-07-07 01:59:51 +00003250 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003251
Jim Ingham58b59f92011-04-22 23:53:53 +00003252 valobj_sp = ValueObjectConstResult::Create (exe_scope,
3253 ast,
3254 GetClangType(),
3255 name,
Enrico Granata9128ee22011-09-06 19:20:51 +00003256 data,
3257 GetAddressOf());
Jim Ingham6035b672011-03-31 00:19:25 +00003258 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003259 }
Jim Ingham6035b672011-03-31 00:19:25 +00003260
3261 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003262 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003263 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003264 }
3265 return valobj_sp;
3266}
3267
Greg Claytonafacd142011-09-02 01:15:17 +00003268ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003269ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003270{
Jim Ingham58b59f92011-04-22 23:53:53 +00003271 if (m_deref_valobj)
3272 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003273
Greg Clayton54979cd2010-12-15 05:08:08 +00003274 const bool is_pointer_type = IsPointerType();
3275 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003276 {
3277 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003278 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003279
3280 std::string child_name_str;
3281 uint32_t child_byte_size = 0;
3282 int32_t child_byte_offset = 0;
3283 uint32_t child_bitfield_bit_size = 0;
3284 uint32_t child_bitfield_bit_offset = 0;
3285 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003286 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003287 const bool transparent_pointers = false;
3288 clang::ASTContext *clang_ast = GetClangAST();
3289 clang_type_t clang_type = GetClangType();
3290 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003291
3292 ExecutionContext exe_ctx;
3293 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
3294
3295 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3296 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003297 GetName().GetCString(),
3298 clang_type,
3299 0,
3300 transparent_pointers,
3301 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003302 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003303 child_name_str,
3304 child_byte_size,
3305 child_byte_offset,
3306 child_bitfield_bit_size,
3307 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003308 child_is_base_class,
3309 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003310 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003311 {
3312 ConstString child_name;
3313 if (!child_name_str.empty())
3314 child_name.SetCString (child_name_str.c_str());
3315
Jim Ingham58b59f92011-04-22 23:53:53 +00003316 m_deref_valobj = new ValueObjectChild (*this,
3317 clang_ast,
3318 child_clang_type,
3319 child_name,
3320 child_byte_size,
3321 child_byte_offset,
3322 child_bitfield_bit_size,
3323 child_bitfield_bit_offset,
3324 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003325 child_is_deref_of_parent,
3326 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003327 }
3328 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003329
Jim Ingham58b59f92011-04-22 23:53:53 +00003330 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003331 {
3332 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003333 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003334 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003335 else
3336 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003337 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003338 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003339
3340 if (is_pointer_type)
3341 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3342 else
3343 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003344 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003345 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003346}
3347
Greg Claytonafacd142011-09-02 01:15:17 +00003348ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003349ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003350{
Jim Ingham78a685a2011-04-16 00:01:13 +00003351 if (m_addr_of_valobj_sp)
3352 return m_addr_of_valobj_sp;
3353
Greg Claytone0d378b2011-03-24 21:19:54 +00003354 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003355 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003356 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003357 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003358 if (addr != LLDB_INVALID_ADDRESS)
3359 {
3360 switch (address_type)
3361 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003362 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003363 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003364 {
3365 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003366 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003367 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3368 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003369 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003370
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003371 case eAddressTypeFile:
3372 case eAddressTypeLoad:
3373 case eAddressTypeHost:
3374 {
3375 clang::ASTContext *ast = GetClangAST();
3376 clang_type_t clang_type = GetClangType();
3377 if (ast && clang_type)
3378 {
3379 std::string name (1, '&');
3380 name.append (m_name.AsCString(""));
Jim Ingham58b59f92011-04-22 23:53:53 +00003381 m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(),
3382 ast,
3383 ClangASTContext::CreatePointerType (ast, clang_type),
3384 ConstString (name.c_str()),
3385 addr,
3386 eAddressTypeInvalid,
3387 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003388 }
3389 }
3390 break;
3391 }
3392 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003393 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003394}
3395
Greg Claytonb2dcc362011-05-05 23:32:56 +00003396
Greg Claytonafacd142011-09-02 01:15:17 +00003397ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003398ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3399{
Greg Claytonafacd142011-09-02 01:15:17 +00003400 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003401 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003402 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003403
3404 if (ptr_value != LLDB_INVALID_ADDRESS)
3405 {
3406 Address ptr_addr (NULL, ptr_value);
3407
3408 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3409 name,
3410 ptr_addr,
3411 clang_ast_type);
3412 }
3413 return valobj_sp;
3414}
3415
Greg Claytonafacd142011-09-02 01:15:17 +00003416ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003417ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3418{
Greg Claytonafacd142011-09-02 01:15:17 +00003419 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003420 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003421 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003422
3423 if (ptr_value != LLDB_INVALID_ADDRESS)
3424 {
3425 Address ptr_addr (NULL, ptr_value);
3426
3427 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3428 name,
3429 ptr_addr,
3430 type_sp);
3431 }
3432 return valobj_sp;
3433}
3434
Jim Ingham6035b672011-03-31 00:19:25 +00003435ValueObject::EvaluationPoint::EvaluationPoint () :
Jim Ingham73ca05a2011-12-17 01:35:57 +00003436 ExecutionContextScope(),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003437 m_thread_id (LLDB_INVALID_UID),
Jim Ingham4b536182011-08-09 02:12:22 +00003438 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003439{
3440}
3441
3442ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Jim Ingham73ca05a2011-12-17 01:35:57 +00003443 ExecutionContextScope (),
Jim Ingham6035b672011-03-31 00:19:25 +00003444 m_needs_update (true),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003445 m_first_update (true),
Jim Ingham89b61092011-07-06 17:42:14 +00003446 m_thread_id (LLDB_INVALID_THREAD_ID),
Jim Ingham4b536182011-08-09 02:12:22 +00003447 m_mod_id ()
Stephen Wilson71c21d12011-04-11 19:41:40 +00003448
Jim Ingham6035b672011-03-31 00:19:25 +00003449{
3450 ExecutionContext exe_ctx;
Jim Ingham9ee01152011-12-10 01:49:43 +00003451
Jim Ingham6035b672011-03-31 00:19:25 +00003452 if (exe_scope)
3453 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Claytonc14ee322011-09-22 04:58:26 +00003454 Target *target = exe_ctx.GetTargetPtr();
3455 if (target != NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003456 {
Greg Claytonc14ee322011-09-22 04:58:26 +00003457 m_target_sp = target;
3458 m_process_sp = exe_ctx.GetProcessSP();
3459 if (!m_process_sp)
3460 m_process_sp = target->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003461
Greg Claytonc14ee322011-09-22 04:58:26 +00003462 if (m_process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003463 {
Jim Ingham4b536182011-08-09 02:12:22 +00003464 m_mod_id = m_process_sp->GetModID();
3465
Greg Claytonc14ee322011-09-22 04:58:26 +00003466 Thread *thread = exe_ctx.GetThreadPtr();
Jim Ingham6035b672011-03-31 00:19:25 +00003467
Greg Claytonc14ee322011-09-22 04:58:26 +00003468 if (thread == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003469 {
3470 if (use_selected)
Jim Ingham6035b672011-03-31 00:19:25 +00003471 thread = m_process_sp->GetThreadList().GetSelectedThread().get();
Jim Ingham6035b672011-03-31 00:19:25 +00003472 }
Jim Ingham6035b672011-03-31 00:19:25 +00003473
3474 if (thread != NULL)
3475 {
3476 m_thread_id = thread->GetIndexID();
Greg Claytonc14ee322011-09-22 04:58:26 +00003477
3478 StackFrame *frame = exe_ctx.GetFramePtr();
3479 if (frame == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003480 {
3481 if (use_selected)
3482 {
Greg Claytonc14ee322011-09-22 04:58:26 +00003483 frame = thread->GetSelectedFrame().get();
Jim Ingham6035b672011-03-31 00:19:25 +00003484 if (frame)
Jim Ingham6035b672011-03-31 00:19:25 +00003485 m_stack_id = frame->GetStackID();
Jim Ingham6035b672011-03-31 00:19:25 +00003486 }
3487 }
3488 else
Greg Claytonc14ee322011-09-22 04:58:26 +00003489 m_stack_id = frame->GetStackID();
Jim Ingham6035b672011-03-31 00:19:25 +00003490 }
3491 }
3492 }
Jim Ingham6035b672011-03-31 00:19:25 +00003493}
3494
3495ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Stephen Wilson71c21d12011-04-11 19:41:40 +00003496 m_needs_update(true),
3497 m_first_update(true),
Jim Ingham6035b672011-03-31 00:19:25 +00003498 m_target_sp (rhs.m_target_sp),
3499 m_process_sp (rhs.m_process_sp),
3500 m_thread_id (rhs.m_thread_id),
3501 m_stack_id (rhs.m_stack_id),
Jim Ingham4b536182011-08-09 02:12:22 +00003502 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003503{
3504}
3505
3506ValueObject::EvaluationPoint::~EvaluationPoint ()
3507{
3508}
3509
Jim Ingham73ca05a2011-12-17 01:35:57 +00003510Target *
3511ValueObject::EvaluationPoint::CalculateTarget ()
Jim Ingham6035b672011-03-31 00:19:25 +00003512{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003513 return m_target_sp.get();
3514}
3515
3516Process *
3517ValueObject::EvaluationPoint::CalculateProcess ()
3518{
3519 return m_process_sp.get();
3520}
3521
3522Thread *
3523ValueObject::EvaluationPoint::CalculateThread ()
3524{
3525 ExecutionContextScope *exe_scope;
Jim Ingham9ee01152011-12-10 01:49:43 +00003526 SyncWithProcessState(exe_scope);
Jim Ingham73ca05a2011-12-17 01:35:57 +00003527 if (exe_scope)
3528 return exe_scope->CalculateThread();
3529 else
3530 return NULL;
3531}
3532
3533StackFrame *
3534ValueObject::EvaluationPoint::CalculateStackFrame ()
3535{
3536 ExecutionContextScope *exe_scope;
3537 SyncWithProcessState(exe_scope);
3538 if (exe_scope)
3539 return exe_scope->CalculateStackFrame();
3540 else
3541 return NULL;
3542}
3543
3544void
3545ValueObject::EvaluationPoint::CalculateExecutionContext (ExecutionContext &exe_ctx)
3546{
3547 ExecutionContextScope *exe_scope;
3548 SyncWithProcessState(exe_scope);
3549 if (exe_scope)
3550 return exe_scope->CalculateExecutionContext (exe_ctx);
Jim Ingham6035b672011-03-31 00:19:25 +00003551}
3552
3553// This function checks the EvaluationPoint against the current process state. If the current
3554// state matches the evaluation point, or the evaluation point is already invalid, then we return
3555// false, meaning "no change". If the current state is different, we update our state, and return
3556// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3557// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003558// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003559
3560bool
Jim Ingham9ee01152011-12-10 01:49:43 +00003561ValueObject::EvaluationPoint::SyncWithProcessState(ExecutionContextScope *&exe_scope)
Jim Ingham6035b672011-03-31 00:19:25 +00003562{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003563
3564 // Start with the target, if it is NULL, then we're obviously not going to get any further:
3565 exe_scope = m_target_sp.get();
3566
3567 if (exe_scope == NULL)
3568 return false;
3569
Jim Ingham6035b672011-03-31 00:19:25 +00003570 // If we don't have a process nothing can change.
3571 if (!m_process_sp)
3572 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003573
3574 exe_scope = m_process_sp.get();
Jim Ingham6035b672011-03-31 00:19:25 +00003575
3576 // If our stop id is the current stop ID, nothing has changed:
Jim Ingham4b536182011-08-09 02:12:22 +00003577 ProcessModID current_mod_id = m_process_sp->GetModID();
3578
Jim Ingham78a685a2011-04-16 00:01:13 +00003579 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3580 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003581 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003582 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003583
3584 bool changed;
3585
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003586 if (m_mod_id.IsValid())
3587 {
3588 if (m_mod_id == current_mod_id)
3589 {
3590 // Everything is already up to date in this object, no need do
3591 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003592 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003593 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003594 else
3595 {
3596 m_mod_id = current_mod_id;
3597 m_needs_update = true;
3598 changed = true;
3599 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003600 }
Jim Ingham6035b672011-03-31 00:19:25 +00003601
Jim Ingham73ca05a2011-12-17 01:35:57 +00003602 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3603 // That way we'll be sure to return a valid exe_scope.
3604 // 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 +00003605
3606 if (m_thread_id != LLDB_INVALID_THREAD_ID)
3607 {
3608 Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get();
3609 if (our_thread == NULL)
Greg Clayton262f80d2011-07-06 16:49:27 +00003610 {
Jim Ingham89b61092011-07-06 17:42:14 +00003611 SetInvalid();
Greg Clayton262f80d2011-07-06 16:49:27 +00003612 }
Jim Ingham6035b672011-03-31 00:19:25 +00003613 else
3614 {
Jim Ingham9ee01152011-12-10 01:49:43 +00003615 exe_scope = our_thread;
Jim Ingham6035b672011-03-31 00:19:25 +00003616
3617 if (m_stack_id.IsValid())
3618 {
3619 StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get();
3620 if (our_frame == NULL)
3621 SetInvalid();
3622 else
Jim Ingham9ee01152011-12-10 01:49:43 +00003623 exe_scope = our_frame;
Jim Ingham6035b672011-03-31 00:19:25 +00003624 }
3625 }
3626 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003627 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003628}
3629
Jim Ingham61be0902011-05-02 18:13:59 +00003630void
3631ValueObject::EvaluationPoint::SetUpdated ()
3632{
Jim Ingham9ee01152011-12-10 01:49:43 +00003633 if (m_process_sp)
3634 m_mod_id = m_process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003635 m_first_update = false;
3636 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003637}
3638
3639
Jim Ingham6035b672011-03-31 00:19:25 +00003640bool
3641ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3642{
3643 if (!IsValid())
3644 return false;
3645
3646 bool needs_update = false;
Jim Ingham6035b672011-03-31 00:19:25 +00003647
3648 // The target has to be non-null, and the
3649 Target *target = exe_scope->CalculateTarget();
3650 if (target != NULL)
3651 {
3652 Target *old_target = m_target_sp.get();
3653 assert (target == old_target);
3654 Process *process = exe_scope->CalculateProcess();
3655 if (process != NULL)
3656 {
3657 // FOR NOW - assume you can't update variable objects across process boundaries.
3658 Process *old_process = m_process_sp.get();
3659 assert (process == old_process);
Jim Ingham4b536182011-08-09 02:12:22 +00003660 ProcessModID current_mod_id = process->GetModID();
3661 if (m_mod_id != current_mod_id)
Jim Ingham6035b672011-03-31 00:19:25 +00003662 {
3663 needs_update = true;
Jim Ingham4b536182011-08-09 02:12:22 +00003664 m_mod_id = current_mod_id;
Jim Ingham6035b672011-03-31 00:19:25 +00003665 }
3666 // See if we're switching the thread or stack context. If no thread is given, this is
3667 // being evaluated in a global context.
3668 Thread *thread = exe_scope->CalculateThread();
3669 if (thread != NULL)
3670 {
Greg Claytonafacd142011-09-02 01:15:17 +00003671 user_id_t new_thread_index = thread->GetIndexID();
Jim Ingham6035b672011-03-31 00:19:25 +00003672 if (new_thread_index != m_thread_id)
3673 {
3674 needs_update = true;
3675 m_thread_id = new_thread_index;
3676 m_stack_id.Clear();
3677 }
3678
3679 StackFrame *new_frame = exe_scope->CalculateStackFrame();
3680 if (new_frame != NULL)
3681 {
3682 if (new_frame->GetStackID() != m_stack_id)
3683 {
3684 needs_update = true;
3685 m_stack_id = new_frame->GetStackID();
3686 }
3687 }
3688 else
3689 {
3690 m_stack_id.Clear();
3691 needs_update = true;
3692 }
3693 }
3694 else
3695 {
3696 // If this had been given a thread, and now there is none, we should update.
3697 // Otherwise we don't have to do anything.
3698 if (m_thread_id != LLDB_INVALID_UID)
3699 {
3700 m_thread_id = LLDB_INVALID_UID;
3701 m_stack_id.Clear();
3702 needs_update = true;
3703 }
3704 }
3705 }
3706 else
3707 {
3708 // If there is no process, then we don't need to update anything.
3709 // But if we're switching from having a process to not, we should try to update.
3710 if (m_process_sp.get() != NULL)
3711 {
3712 needs_update = true;
3713 m_process_sp.reset();
3714 m_thread_id = LLDB_INVALID_UID;
3715 m_stack_id.Clear();
3716 }
3717 }
3718 }
3719 else
3720 {
3721 // If there's no target, nothing can change so we don't need to update anything.
3722 // But if we're switching from having a target to not, we should try to update.
3723 if (m_target_sp.get() != NULL)
3724 {
3725 needs_update = true;
3726 m_target_sp.reset();
3727 m_process_sp.reset();
3728 m_thread_id = LLDB_INVALID_UID;
3729 m_stack_id.Clear();
3730 }
3731 }
3732 if (!m_needs_update)
3733 m_needs_update = needs_update;
3734
3735 return needs_update;
3736}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003737
3738void
3739ValueObject::ClearUserVisibleData()
3740{
3741 m_location_str.clear();
3742 m_value_str.clear();
3743 m_summary_str.clear();
3744 m_object_desc_str.clear();
Enrico Granata855cd902011-09-06 22:59:55 +00003745 m_trying_summary_already = false;
Johnny Chen44805302011-07-19 19:48:13 +00003746}
Enrico Granata9128ee22011-09-06 19:20:51 +00003747
3748SymbolContextScope *
3749ValueObject::GetSymbolContextScope()
3750{
3751 if (m_parent)
3752 {
3753 if (!m_parent->IsPointerOrReferenceType())
3754 return m_parent->GetSymbolContextScope();
3755 }
3756 return NULL;
3757}