blob: 25ad733b8cf4a210633adb0b469ddf092f96ed24 [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),
Greg Clayton48ca8b82012-01-07 20:58:07 +000098 m_is_getting_summary(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),
Greg Clayton48ca8b82012-01-07 20:58:07 +0000144 m_is_getting_summary(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{
Greg Clayton48ca8b82012-01-07 20:58:07 +0000567 // Watch for recursion which can happen with summary strings and other
568 // variable formatting options.
569 if (m_is_getting_summary)
570 return NULL;
571
572 m_is_getting_summary = true;
573
Enrico Granatad8b5fce2011-08-02 23:12:24 +0000574 if (UpdateValueIfNeeded (true))
Enrico Granata4becb372011-06-29 22:27:15 +0000575 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000576 if (m_summary_str.empty())
577 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000578 SummaryFormat *summary_format = GetSummaryFormat().get();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000579
580 if (summary_format)
Enrico Granata4becb372011-06-29 22:27:15 +0000581 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000582 m_summary_str = summary_format->FormatObject(GetSP());
Enrico Granata4becb372011-06-29 22:27:15 +0000583 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000584 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000585 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000586 clang_type_t clang_type = GetClangType();
Greg Clayton737b9322010-09-13 03:32:57 +0000587
Enrico Granata9dd75c82011-07-15 23:30:15 +0000588 // Do some default printout for function pointers
Enrico Granataf2bbf712011-07-15 02:26:42 +0000589 if (clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000590 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000591 StreamString sstr;
592 clang_type_t elem_or_pointee_clang_type;
593 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
594 GetClangAST(),
595 &elem_or_pointee_clang_type));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000596
Enrico Granataf2bbf712011-07-15 02:26:42 +0000597 ExecutionContextScope *exe_scope = GetExecutionContextScope();
598 if (exe_scope)
599 {
Enrico Granata9dd75c82011-07-15 23:30:15 +0000600 if (ClangASTContext::IsFunctionPointerType (clang_type))
Jim Ingham6035b672011-03-31 00:19:25 +0000601 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000602 AddressType func_ptr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000603 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000604 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
605 {
606 switch (func_ptr_address_type)
607 {
608 case eAddressTypeInvalid:
609 case eAddressTypeFile:
610 break;
611
612 case eAddressTypeLoad:
613 {
614 Address so_addr;
615 Target *target = exe_scope->CalculateTarget();
616 if (target && target->GetSectionLoadList().IsEmpty() == false)
617 {
618 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
619 {
620 so_addr.Dump (&sstr,
621 exe_scope,
622 Address::DumpStyleResolvedDescription,
623 Address::DumpStyleSectionNameOffset);
624 }
625 }
626 }
627 break;
628
629 case eAddressTypeHost:
630 break;
631 }
632 }
633 if (sstr.GetSize() > 0)
634 {
635 m_summary_str.assign (1, '(');
636 m_summary_str.append (sstr.GetData(), sstr.GetSize());
637 m_summary_str.append (1, ')');
638 }
Jim Ingham6035b672011-03-31 00:19:25 +0000639 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000640 }
641 }
642 }
643 }
644 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000645 m_is_getting_summary = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000646 if (m_summary_str.empty())
647 return NULL;
648 return m_summary_str.c_str();
649}
650
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000651bool
652ValueObject::IsCStringContainer(bool check_pointer)
653{
654 clang_type_t elem_or_pointee_clang_type;
655 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
656 GetClangAST(),
657 &elem_or_pointee_clang_type));
658 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
659 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
660 if (!is_char_arr_ptr)
661 return false;
662 if (!check_pointer)
663 return true;
664 if (type_flags.Test(ClangASTContext::eTypeIsArray))
665 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000666 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000667 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000668 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000669 return (cstr_address != LLDB_INVALID_ADDRESS);
670}
671
Enrico Granata9128ee22011-09-06 19:20:51 +0000672size_t
673ValueObject::GetPointeeData (DataExtractor& data,
674 uint32_t item_idx,
675 uint32_t item_count)
676{
677 if (!IsPointerType() && !IsArrayType())
678 return 0;
679
680 if (item_count == 0)
681 return 0;
682
683 uint32_t stride = 0;
684
685 ClangASTType type(GetClangAST(),
686 GetClangType());
687
688 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
689 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
690
691 const uint64_t bytes = item_count * item_type_size;
692
693 const uint64_t offset = item_idx * item_type_size;
694
695 if (item_idx == 0 && item_count == 1) // simply a deref
696 {
697 if (IsPointerType())
698 {
699 Error error;
700 ValueObjectSP pointee_sp = Dereference(error);
701 if (error.Fail() || pointee_sp.get() == NULL)
702 return 0;
703 return pointee_sp->GetDataExtractor().Copy(data);
704 }
705 else
706 {
707 ValueObjectSP child_sp = GetChildAtIndex(0, true);
708 if (child_sp.get() == NULL)
709 return 0;
710 return child_sp->GetDataExtractor().Copy(data);
711 }
712 return true;
713 }
714 else /* (items > 1) */
715 {
716 Error error;
717 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
718 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
719
720 AddressType addr_type;
721 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
722
Jim Ingham73ca05a2011-12-17 01:35:57 +0000723 ExecutionContextScope *exe_scope = GetExecutionContextScope();
Enrico Granata9128ee22011-09-06 19:20:51 +0000724
725
726 switch (addr_type)
727 {
728 case eAddressTypeFile:
729 {
730 Module* module = GetModule();
731 if (module)
732 {
733 Address so_addr;
734 module->ResolveFileAddress(addr, so_addr);
735 if (exe_scope)
736 {
737 Target* target = exe_scope->CalculateTarget();
738 if (target)
739 {
740 heap_buf_ptr->SetByteSize(bytes);
741 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
742 if (error.Success())
743 {
744 data.SetData(data_sp);
745 return bytes_read;
746 }
747 }
748 }
749 }
750 }
751 break;
752 case eAddressTypeLoad:
753 if (exe_scope)
754 {
755 Process *process = exe_scope->CalculateProcess();
756 if (process)
757 {
758 heap_buf_ptr->SetByteSize(bytes);
759 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
760 if (error.Success())
761 {
762 data.SetData(data_sp);
763 return bytes_read;
764 }
765 }
766 }
767 break;
768 case eAddressTypeHost:
769 {
770 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
771 data.SetData(data_sp);
772 return bytes;
773 }
774 break;
775 case eAddressTypeInvalid:
776 default:
777 break;
778 }
779 }
780 return 0;
781}
782
783size_t
784ValueObject::GetData (DataExtractor& data)
785{
786 UpdateValueIfNeeded(false);
787 ExecutionContext exe_ctx;
788 GetExecutionContextScope()->CalculateExecutionContext(exe_ctx);
789 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule());
790 if (error.Fail())
791 return 0;
792 data.SetAddressByteSize(m_data.GetAddressByteSize());
793 data.SetByteOrder(m_data.GetByteOrder());
794 return data.GetByteSize();
795}
796
797// will compute strlen(str), but without consuming more than
798// maxlen bytes out of str (this serves the purpose of reading
799// chunks of a string without having to worry about
800// missing NULL terminators in the chunk)
801// of course, if strlen(str) > maxlen, the function will return
802// maxlen_value (which should be != maxlen, because that allows you
803// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
804static uint32_t
805strlen_or_inf (const char* str,
806 uint32_t maxlen,
807 uint32_t maxlen_value)
808{
809 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000810 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000811 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000812 while(*str)
813 {
814 len++;str++;
815 if (len > maxlen)
816 return maxlen_value;
817 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000818 }
819 return len;
820}
821
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000822void
823ValueObject::ReadPointedString(Stream& s,
824 Error& error,
Enrico Granataf4efecd2011-07-12 22:56:10 +0000825 uint32_t max_length,
826 bool honor_array,
Greg Claytonafacd142011-09-02 01:15:17 +0000827 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000828{
829
830 if (max_length == 0)
Enrico Granata9128ee22011-09-06 19:20:51 +0000831 max_length = GetUpdatePoint().GetTargetSP()->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000832
833 clang_type_t clang_type = GetClangType();
834 clang_type_t elem_or_pointee_clang_type;
835 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
836 GetClangAST(),
837 &elem_or_pointee_clang_type));
838 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
839 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
840 {
841 ExecutionContextScope *exe_scope = GetExecutionContextScope();
842 if (exe_scope)
843 {
844 Target *target = exe_scope->CalculateTarget();
Enrico Granata6f3533f2011-07-29 19:53:35 +0000845 if (target == NULL)
846 {
847 s << "<no target to read from>";
848 }
849 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000850 {
Greg Claytonafacd142011-09-02 01:15:17 +0000851 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000852 AddressType cstr_address_type = eAddressTypeInvalid;
853
854 size_t cstr_len = 0;
855 bool capped_data = false;
856 if (type_flags.Test (ClangASTContext::eTypeIsArray))
857 {
858 // We have an array
859 cstr_len = ClangASTContext::GetArraySize (clang_type);
Enrico Granataf4efecd2011-07-12 22:56:10 +0000860 if (cstr_len > max_length)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000861 {
Enrico Granataf4efecd2011-07-12 22:56:10 +0000862 capped_data = true;
863 cstr_len = max_length;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000864 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000865 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000866 }
867 else
868 {
869 // We have a pointer
Enrico Granata9128ee22011-09-06 19:20:51 +0000870 cstr_address = GetPointerValue (&cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000871 }
Greg Clayton8dd5c172011-10-05 22:19:51 +0000872 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000873 {
874 Address cstr_so_addr (NULL, cstr_address);
875 DataExtractor data;
876 size_t bytes_read = 0;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000877 if (cstr_len > 0 && honor_array)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000878 {
Enrico Granata9128ee22011-09-06 19:20:51 +0000879 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
880 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
881 GetPointeeData(data, 0, cstr_len);
882
Greg Clayton8dd5c172011-10-05 22:19:51 +0000883 if ((bytes_read = data.GetByteSize()) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000884 {
885 s << '"';
886 data.Dump (&s,
887 0, // Start offset in "data"
Enrico Granataf4efecd2011-07-12 22:56:10 +0000888 item_format,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000889 1, // Size of item (1 byte for a char!)
890 bytes_read, // How many bytes to print?
891 UINT32_MAX, // num per line
892 LLDB_INVALID_ADDRESS,// base address
893 0, // bitfield bit size
894 0); // bitfield bit offset
895 if (capped_data)
896 s << "...";
897 s << '"';
898 }
899 }
900 else
901 {
Enrico Granataf4efecd2011-07-12 22:56:10 +0000902 cstr_len = max_length;
903 const size_t k_max_buf_size = 64;
Enrico Granata9128ee22011-09-06 19:20:51 +0000904
905 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000906
Greg Clayton8dd5c172011-10-05 22:19:51 +0000907 int cstr_len_displayed = -1;
908 bool capped_cstr = false;
Enrico Granata9128ee22011-09-06 19:20:51 +0000909 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
910 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
Greg Clayton8dd5c172011-10-05 22:19:51 +0000911 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000912 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000913 const char *cstr = data.PeekCStr(0);
914 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
Enrico Granata9128ee22011-09-06 19:20:51 +0000915 if (len > k_max_buf_size)
916 len = k_max_buf_size;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000917 if (cstr && cstr_len_displayed < 0)
Enrico Granata9128ee22011-09-06 19:20:51 +0000918 s << '"';
Greg Clayton8dd5c172011-10-05 22:19:51 +0000919
920 if (cstr_len_displayed < 0)
921 cstr_len_displayed = len;
922
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000923 if (len == 0)
924 break;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000925 cstr_len_displayed += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000926 if (len > bytes_read)
927 len = bytes_read;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000928 if (len > cstr_len)
929 len = cstr_len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000930
931 data.Dump (&s,
932 0, // Start offset in "data"
Enrico Granataf4efecd2011-07-12 22:56:10 +0000933 item_format,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000934 1, // Size of item (1 byte for a char!)
935 len, // How many bytes to print?
936 UINT32_MAX, // num per line
937 LLDB_INVALID_ADDRESS,// base address
938 0, // bitfield bit size
939 0); // bitfield bit offset
940
941 if (len < k_max_buf_size)
942 break;
Enrico Granata9128ee22011-09-06 19:20:51 +0000943
Enrico Granataf4efecd2011-07-12 22:56:10 +0000944 if (len >= cstr_len)
Greg Clayton8dd5c172011-10-05 22:19:51 +0000945 {
946 capped_cstr = true;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000947 break;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000948 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000949
Enrico Granataf4efecd2011-07-12 22:56:10 +0000950 cstr_len -= len;
Enrico Granata9128ee22011-09-06 19:20:51 +0000951 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000952 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000953
Greg Clayton8dd5c172011-10-05 22:19:51 +0000954 if (cstr_len_displayed >= 0)
Enrico Granata9128ee22011-09-06 19:20:51 +0000955 {
956 s << '"';
Greg Clayton8dd5c172011-10-05 22:19:51 +0000957 if (capped_cstr)
Enrico Granata9128ee22011-09-06 19:20:51 +0000958 s << "...";
959 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000960 }
961 }
962 }
963 }
964 }
965 else
966 {
967 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +0000968 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000969 }
970}
971
Jim Ingham53c47f12010-09-10 23:12:17 +0000972const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000973ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +0000974{
Enrico Granata0a3958e2011-07-02 00:25:22 +0000975
Enrico Granatad8b5fce2011-08-02 23:12:24 +0000976 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +0000977 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000978
979 if (!m_object_desc_str.empty())
980 return m_object_desc_str.c_str();
981
Jim Ingham6035b672011-03-31 00:19:25 +0000982 ExecutionContextScope *exe_scope = GetExecutionContextScope();
983 if (exe_scope == NULL)
984 return NULL;
985
Jim Ingham53c47f12010-09-10 23:12:17 +0000986 Process *process = exe_scope->CalculateProcess();
Jim Ingham5a369122010-09-28 01:25:32 +0000987 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +0000988 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +0000989
Jim Ingham53c47f12010-09-10 23:12:17 +0000990 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +0000991
Greg Claytonafacd142011-09-02 01:15:17 +0000992 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +0000993 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
994
Jim Inghama2cf2632010-12-23 02:29:54 +0000995 if (runtime == NULL)
996 {
Jim Inghamb7603bb2011-03-18 00:05:18 +0000997 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +0000998 clang_type_t opaque_qual_type = GetClangType();
999 if (opaque_qual_type != NULL)
1000 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001001 bool is_signed;
1002 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1003 || ClangASTContext::IsPointerType (opaque_qual_type))
1004 {
Greg Claytonafacd142011-09-02 01:15:17 +00001005 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001006 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001007 }
1008 }
1009
Jim Ingham8d543de2011-03-31 23:01:21 +00001010 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001011 {
1012 m_object_desc_str.append (s.GetData());
1013 }
Sean Callanan672ad942010-10-23 00:18:49 +00001014
1015 if (m_object_desc_str.empty())
1016 return NULL;
1017 else
1018 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001019}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001020
1021const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001022ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001023{
1024 // If our byte size is zero this is an aggregate type that has children
Greg Clayton1be10fc2010-09-29 01:12:09 +00001025 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001026 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00001027 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001028 {
1029 if (m_value_str.empty())
1030 {
1031 const Value::ContextType context_type = m_value.GetContextType();
1032
1033 switch (context_type)
1034 {
Greg Clayton526e5af2010-11-13 03:52:47 +00001035 case Value::eContextTypeClangType:
1036 case Value::eContextTypeLLDBType:
1037 case Value::eContextTypeVariable:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001038 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001039 lldb::Format my_format = GetFormat();
Greg Clayton73b472d2010-10-27 03:32:59 +00001040 clang_type_t clang_type = GetClangType ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001041 if (clang_type)
1042 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001043 if (m_format == lldb::eFormatDefault)
Enrico Granata4becb372011-06-29 22:27:15 +00001044 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001045 if (m_last_value_format)
1046 my_format = m_last_value_format->GetFormat();
Enrico Granataf2bbf712011-07-15 02:26:42 +00001047 else
1048 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001049 if (m_is_bitfield_for_scalar)
1050 my_format = eFormatUnsigned;
1051 else
1052 my_format = ClangASTType::GetFormat(clang_type);
Enrico Granataf2bbf712011-07-15 02:26:42 +00001053 }
Greg Clayton007d5be2011-05-30 00:49:24 +00001054 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001055 StreamString sstr;
1056 if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1057 clang_type, // The clang type to display
1058 &sstr,
1059 my_format, // Format to display this type with
1060 m_data, // Data to extract from
1061 0, // Byte offset into "m_data"
1062 GetByteSize(), // Byte size of item in "m_data"
1063 GetBitfieldBitSize(), // Bitfield bit size
Greg Clayton5009f9d2011-10-27 17:55:14 +00001064 GetBitfieldBitOffset(),
1065 GetExecutionContextScope())) // Bitfield bit offset
Enrico Granata9128ee22011-09-06 19:20:51 +00001066 m_value_str.swap(sstr.GetString());
1067 else
1068 {
Jason Molenda7e589a62011-09-20 00:26:08 +00001069 m_error.SetErrorStringWithFormat ("unsufficient data for value (only %lu of %lu bytes available)",
Enrico Granata9128ee22011-09-06 19:20:51 +00001070 m_data.GetByteSize(),
1071 GetByteSize());
1072 m_value_str.clear();
1073 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001074 }
1075 }
1076 break;
1077
Greg Clayton526e5af2010-11-13 03:52:47 +00001078 case Value::eContextTypeRegisterInfo:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001079 {
1080 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1081 if (reg_info)
1082 {
1083 StreamString reg_sstr;
Greg Clayton5009f9d2011-10-27 17:55:14 +00001084 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 +00001085 m_value_str.swap(reg_sstr.GetString());
1086 }
1087 }
1088 break;
Greg Claytonc982c762010-07-09 20:39:50 +00001089
1090 default:
1091 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001092 }
1093 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001094
1095 if (!m_value_did_change && m_old_value_valid)
1096 {
1097 // The value was gotten successfully, so we consider the
1098 // value as changed if the value string differs
1099 SetValueDidChange (m_old_value_str != m_value_str);
1100 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001101 }
1102 }
1103 if (m_value_str.empty())
1104 return NULL;
1105 return m_value_str.c_str();
1106}
1107
Enrico Granatac3e320a2011-08-02 17:27:39 +00001108// if > 8bytes, 0 is returned. this method should mostly be used
1109// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001110uint64_t
1111ValueObject::GetValueAsUnsigned (uint64_t fail_value)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001112{
1113 // If our byte size is zero this is an aggregate type that has children
1114 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1115 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001116 Scalar scalar;
1117 if (ResolveValue (scalar))
1118 return scalar.GetRawBits64(fail_value);
Enrico Granatac3e320a2011-08-02 17:27:39 +00001119 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001120 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001121}
1122
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001123bool
1124ValueObject::GetPrintableRepresentation(Stream& s,
1125 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001126 Format custom_format)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001127{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001128
Greg Claytonafacd142011-09-02 01:15:17 +00001129 if (custom_format != eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001130 SetFormat(custom_format);
1131
1132 const char * return_value;
Enrico Granatacd1c0232011-08-04 23:37:18 +00001133 std::string alloc_mem;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001134
1135 switch(val_obj_display)
1136 {
1137 case eDisplayValue:
1138 return_value = GetValueAsCString();
1139 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001140
Enrico Granata0a3958e2011-07-02 00:25:22 +00001141 case eDisplaySummary:
Greg Clayton48ca8b82012-01-07 20:58:07 +00001142 return_value = GetSummaryAsCString();
1143 break;
1144
Enrico Granata0a3958e2011-07-02 00:25:22 +00001145 case eDisplayLanguageSpecific:
1146 return_value = GetObjectDescription();
1147 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001148
Enrico Granataf2bbf712011-07-15 02:26:42 +00001149 case eDisplayLocation:
1150 return_value = GetLocationAsCString();
1151 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001152
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001153 case eDisplayChildrenCount:
Greg Clayton48ca8b82012-01-07 20:58:07 +00001154 {
1155 alloc_mem.resize(512);
1156 return_value = &alloc_mem[0];
1157 int count = GetNumChildren();
1158 snprintf((char*)return_value, 512, "%d", count);
1159 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001160 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001161
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001162 case eDisplayType:
1163 return_value = GetTypeName().AsCString();
1164 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001165
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001166 default:
1167 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001168 }
1169
Enrico Granata855cd902011-09-06 22:59:55 +00001170 if (!return_value)
Enrico Granata9fc19442011-07-06 02:13:41 +00001171 {
Enrico Granata9fc19442011-07-06 02:13:41 +00001172 if (val_obj_display == eDisplayValue)
Enrico Granata855cd902011-09-06 22:59:55 +00001173 return_value = GetSummaryAsCString();
Enrico Granata9fc19442011-07-06 02:13:41 +00001174 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +00001175 {
1176 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1177 {
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001178 // this thing has no value, and it seems to have no summary
1179 // some combination of unitialized data and other factors can also
Enrico Granata855cd902011-09-06 22:59:55 +00001180 // raise this condition, so let's print a nice generic description
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001181 {
1182 alloc_mem.resize(684);
1183 return_value = &alloc_mem[0];
1184 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1185 }
Enrico Granatae992a082011-07-22 17:03:19 +00001186 }
1187 else
1188 return_value = GetValueAsCString();
1189 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001190 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001191
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001192 if (return_value)
1193 s.PutCString(return_value);
1194 else
Enrico Granata88da35f2011-08-23 21:26:09 +00001195 {
1196 if (m_error.Fail())
1197 s.Printf("<%s>", m_error.AsCString());
1198 else if (val_obj_display == eDisplaySummary)
1199 s.PutCString("<no summary available>");
1200 else if (val_obj_display == eDisplayValue)
1201 s.PutCString("<no value available>");
1202 else if (val_obj_display == eDisplayLanguageSpecific)
1203 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1204 else
1205 s.PutCString("<no printable representation>");
1206 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001207
1208 // we should only return false here if we could not do *anything*
1209 // even if we have an error message as output, that's a success
1210 // from our callers' perspective, so return true
1211 return true;
1212
Enrico Granata0a3958e2011-07-02 00:25:22 +00001213}
1214
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001215// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1216// this call up to date by returning true for your new special cases. We will eventually move
1217// to checking this call result before trying to display special cases
1218bool
1219ValueObject::HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001220 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001221{
1222 clang_type_t elem_or_pointee_type;
1223 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1224
1225 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1226 && val_obj_display == ValueObject::eDisplayValue)
1227 {
1228 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001229 (custom_format == eFormatCString ||
1230 custom_format == eFormatCharArray ||
1231 custom_format == eFormatChar ||
1232 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001233 return true;
1234
1235 if (flags.Test(ClangASTContext::eTypeIsArray))
1236 {
Greg Claytonafacd142011-09-02 01:15:17 +00001237 if ((custom_format == eFormatBytes) ||
1238 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001239 return true;
1240
Greg Claytonafacd142011-09-02 01:15:17 +00001241 if ((custom_format == eFormatVectorOfChar) ||
1242 (custom_format == eFormatVectorOfFloat32) ||
1243 (custom_format == eFormatVectorOfFloat64) ||
1244 (custom_format == eFormatVectorOfSInt16) ||
1245 (custom_format == eFormatVectorOfSInt32) ||
1246 (custom_format == eFormatVectorOfSInt64) ||
1247 (custom_format == eFormatVectorOfSInt8) ||
1248 (custom_format == eFormatVectorOfUInt128) ||
1249 (custom_format == eFormatVectorOfUInt16) ||
1250 (custom_format == eFormatVectorOfUInt32) ||
1251 (custom_format == eFormatVectorOfUInt64) ||
1252 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001253 return true;
1254 }
1255 }
1256 return false;
1257}
1258
Enrico Granata9fc19442011-07-06 02:13:41 +00001259bool
1260ValueObject::DumpPrintableRepresentation(Stream& s,
1261 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001262 Format custom_format,
Enrico Granata85933ed2011-08-18 16:38:26 +00001263 bool only_special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001264{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001265
1266 clang_type_t elem_or_pointee_type;
1267 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001268
Enrico Granataf4efecd2011-07-12 22:56:10 +00001269 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1270 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001271 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001272 // when being asked to get a printable display an array or pointer type directly,
1273 // try to "do the right thing"
1274
1275 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001276 (custom_format == eFormatCString ||
1277 custom_format == eFormatCharArray ||
1278 custom_format == eFormatChar ||
1279 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001280 {
1281 Error error;
1282 ReadPointedString(s,
1283 error,
1284 0,
Greg Claytonafacd142011-09-02 01:15:17 +00001285 (custom_format == eFormatVectorOfChar) ||
1286 (custom_format == eFormatCharArray));
Enrico Granataf4efecd2011-07-12 22:56:10 +00001287 return !error.Fail();
1288 }
1289
Greg Claytonafacd142011-09-02 01:15:17 +00001290 if (custom_format == eFormatEnum)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001291 return false;
1292
1293 // this only works for arrays, because I have no way to know when
1294 // the pointed memory ends, and no special \0 end of data marker
1295 if (flags.Test(ClangASTContext::eTypeIsArray))
1296 {
Greg Claytonafacd142011-09-02 01:15:17 +00001297 if ((custom_format == eFormatBytes) ||
1298 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001299 {
1300 uint32_t count = GetNumChildren();
1301
1302 s << '[';
1303 for (uint32_t low = 0; low < count; low++)
1304 {
1305
1306 if (low)
1307 s << ',';
1308
1309 ValueObjectSP child = GetChildAtIndex(low,true);
1310 if (!child.get())
1311 {
Enrico Granatae992a082011-07-22 17:03:19 +00001312 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001313 continue;
1314 }
1315 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1316 }
1317
1318 s << ']';
1319
1320 return true;
1321 }
1322
Greg Claytonafacd142011-09-02 01:15:17 +00001323 if ((custom_format == eFormatVectorOfChar) ||
1324 (custom_format == eFormatVectorOfFloat32) ||
1325 (custom_format == eFormatVectorOfFloat64) ||
1326 (custom_format == eFormatVectorOfSInt16) ||
1327 (custom_format == eFormatVectorOfSInt32) ||
1328 (custom_format == eFormatVectorOfSInt64) ||
1329 (custom_format == eFormatVectorOfSInt8) ||
1330 (custom_format == eFormatVectorOfUInt128) ||
1331 (custom_format == eFormatVectorOfUInt16) ||
1332 (custom_format == eFormatVectorOfUInt32) ||
1333 (custom_format == eFormatVectorOfUInt64) ||
1334 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001335 {
1336 uint32_t count = GetNumChildren();
1337
Greg Claytonafacd142011-09-02 01:15:17 +00001338 Format format = FormatManager::GetSingleItemFormat(custom_format);
Enrico Granataf4efecd2011-07-12 22:56:10 +00001339
1340 s << '[';
1341 for (uint32_t low = 0; low < count; low++)
1342 {
1343
1344 if (low)
1345 s << ',';
1346
1347 ValueObjectSP child = GetChildAtIndex(low,true);
1348 if (!child.get())
1349 {
Enrico Granatae992a082011-07-22 17:03:19 +00001350 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001351 continue;
1352 }
1353 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1354 }
1355
1356 s << ']';
1357
1358 return true;
1359 }
1360 }
1361
Greg Claytonafacd142011-09-02 01:15:17 +00001362 if ((custom_format == eFormatBoolean) ||
1363 (custom_format == eFormatBinary) ||
1364 (custom_format == eFormatChar) ||
1365 (custom_format == eFormatCharPrintable) ||
1366 (custom_format == eFormatComplexFloat) ||
1367 (custom_format == eFormatDecimal) ||
1368 (custom_format == eFormatHex) ||
1369 (custom_format == eFormatFloat) ||
1370 (custom_format == eFormatOctal) ||
1371 (custom_format == eFormatOSType) ||
1372 (custom_format == eFormatUnicode16) ||
1373 (custom_format == eFormatUnicode32) ||
1374 (custom_format == eFormatUnsigned) ||
1375 (custom_format == eFormatPointer) ||
1376 (custom_format == eFormatComplexInteger) ||
1377 (custom_format == eFormatComplex) ||
1378 (custom_format == eFormatDefault)) // use the [] operator
Enrico Granataf4efecd2011-07-12 22:56:10 +00001379 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001380 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001381
1382 if (only_special)
1383 return false;
1384
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001385 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001386 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001387 SetFormat(eFormatDefault);
1388 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001389}
1390
Greg Clayton737b9322010-09-13 03:32:57 +00001391addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001392ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001393{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001394 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001395 return LLDB_INVALID_ADDRESS;
1396
Greg Clayton73b472d2010-10-27 03:32:59 +00001397 switch (m_value.GetValueType())
1398 {
1399 case Value::eValueTypeScalar:
1400 if (scalar_is_load_address)
1401 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001402 if(address_type)
1403 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001404 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1405 }
1406 break;
1407
1408 case Value::eValueTypeLoadAddress:
1409 case Value::eValueTypeFileAddress:
1410 case Value::eValueTypeHostAddress:
1411 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001412 if(address_type)
1413 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001414 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1415 }
1416 break;
1417 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001418 if (address_type)
1419 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001420 return LLDB_INVALID_ADDRESS;
1421}
1422
1423addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001424ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001425{
Greg Claytonafacd142011-09-02 01:15:17 +00001426 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001427 if(address_type)
1428 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001429
Enrico Granatac3e320a2011-08-02 17:27:39 +00001430 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001431 return address;
1432
Greg Clayton73b472d2010-10-27 03:32:59 +00001433 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001434 {
1435 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001436 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001437 break;
1438
Enrico Granata9128ee22011-09-06 19:20:51 +00001439 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001440 case Value::eValueTypeLoadAddress:
1441 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001442 {
1443 uint32_t data_offset = 0;
1444 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001445 }
1446 break;
1447 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001448
Enrico Granata9128ee22011-09-06 19:20:51 +00001449 if (address_type)
1450 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001451
Greg Clayton737b9322010-09-13 03:32:57 +00001452 return address;
1453}
1454
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001455bool
Jim Ingham6035b672011-03-31 00:19:25 +00001456ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001457{
1458 // Make sure our value is up to date first so that our location and location
1459 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001460 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001461 return false;
1462
1463 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001464 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001465
Greg Claytonb1320972010-07-14 00:18:15 +00001466 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001467
Jim Ingham16e0c682011-08-12 23:34:31 +00001468 Value::ValueType value_type = m_value.GetValueType();
1469
1470 if (value_type == Value::eValueTypeScalar)
1471 {
1472 // If the value is already a scalar, then let the scalar change itself:
1473 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1474 }
1475 else if (byte_size <= Scalar::GetMaxByteSize())
1476 {
1477 // If the value fits in a scalar, then make a new scalar and again let the
1478 // scalar code do the conversion, then figure out where to put the new value.
1479 Scalar new_scalar;
1480 Error error;
1481 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1482 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001483 {
Jim Ingham4b536182011-08-09 02:12:22 +00001484 switch (value_type)
1485 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001486 case Value::eValueTypeLoadAddress:
1487 {
1488 // If it is a load address, then the scalar value is the storage location
1489 // of the data, and we have to shove this value down to that load location.
1490 ProcessSP process_sp = GetUpdatePoint().GetProcessSP();
1491 if (process_sp)
1492 {
Greg Claytonafacd142011-09-02 01:15:17 +00001493 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Jim Ingham16e0c682011-08-12 23:34:31 +00001494 size_t bytes_written = process_sp->WriteScalarToMemory (target_addr,
1495 new_scalar,
1496 byte_size,
1497 error);
1498 if (!error.Success() || bytes_written != byte_size)
1499 return false;
1500 }
1501 }
Jim Ingham4b536182011-08-09 02:12:22 +00001502 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001503 case Value::eValueTypeHostAddress:
1504 {
1505 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1506 DataExtractor new_data;
1507 new_data.SetByteOrder (m_data.GetByteOrder());
1508
1509 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1510 m_data.SetData(buffer_sp, 0);
1511 bool success = new_scalar.GetData(new_data);
1512 if (success)
1513 {
1514 new_data.CopyByteOrderedData(0,
1515 byte_size,
1516 const_cast<uint8_t *>(m_data.GetDataStart()),
1517 byte_size,
1518 m_data.GetByteOrder());
1519 }
1520 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1521
1522 }
Jim Ingham4b536182011-08-09 02:12:22 +00001523 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001524 case Value::eValueTypeFileAddress:
1525 case Value::eValueTypeScalar:
1526 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001527 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001528 }
1529 else
1530 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001531 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001532 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001533 }
1534 else
1535 {
1536 // We don't support setting things bigger than a scalar at present.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001537 return false;
1538 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001539
1540 // If we have reached this point, then we have successfully changed the value.
1541 SetNeedsUpdate();
1542 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001543}
1544
Greg Claytonafacd142011-09-02 01:15:17 +00001545LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001546ValueObject::GetObjectRuntimeLanguage ()
1547{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001548 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1549 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001550}
1551
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001552void
Jim Ingham58b59f92011-04-22 23:53:53 +00001553ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001554{
Jim Ingham58b59f92011-04-22 23:53:53 +00001555 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001556}
1557
1558ValueObjectSP
1559ValueObject::GetSyntheticChild (const ConstString &key) const
1560{
1561 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001562 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001563 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001564 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001565 return synthetic_child_sp;
1566}
1567
1568bool
1569ValueObject::IsPointerType ()
1570{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001571 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001572}
1573
Jim Inghamb7603bb2011-03-18 00:05:18 +00001574bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001575ValueObject::IsArrayType ()
1576{
1577 return ClangASTContext::IsArrayType (GetClangType());
1578}
1579
1580bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001581ValueObject::IsScalarType ()
1582{
1583 return ClangASTContext::IsScalarType (GetClangType());
1584}
1585
1586bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001587ValueObject::IsIntegerType (bool &is_signed)
1588{
1589 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1590}
Greg Clayton73b472d2010-10-27 03:32:59 +00001591
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001592bool
1593ValueObject::IsPointerOrReferenceType ()
1594{
Greg Clayton007d5be2011-05-30 00:49:24 +00001595 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1596}
1597
1598bool
1599ValueObject::IsPossibleCPlusPlusDynamicType ()
1600{
1601 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001602}
1603
Greg Claytondea8cb42011-06-29 22:09:02 +00001604bool
1605ValueObject::IsPossibleDynamicType ()
1606{
1607 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1608}
1609
Greg Claytonafacd142011-09-02 01:15:17 +00001610ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001611ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1612{
1613 if (IsArrayType())
1614 return GetSyntheticArrayMemberFromArray(index, can_create);
1615
1616 if (IsPointerType())
1617 return GetSyntheticArrayMemberFromPointer(index, can_create);
1618
1619 return ValueObjectSP();
1620
1621}
1622
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001623ValueObjectSP
1624ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1625{
1626 ValueObjectSP synthetic_child_sp;
1627 if (IsPointerType ())
1628 {
1629 char index_str[64];
1630 snprintf(index_str, sizeof(index_str), "[%i]", index);
1631 ConstString index_const_str(index_str);
1632 // Check if we have already created a synthetic array member in this
1633 // valid object. If we have we will re-use it.
1634 synthetic_child_sp = GetSyntheticChild (index_const_str);
1635 if (!synthetic_child_sp)
1636 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001637 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001638 // We haven't made a synthetic array member for INDEX yet, so
1639 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001640 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001641
1642 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001643 if (synthetic_child)
1644 {
1645 AddSyntheticChild(index_const_str, synthetic_child);
1646 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001647 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001648 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001649 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001650 }
1651 }
1652 return synthetic_child_sp;
1653}
Jim Ingham22777012010-09-23 02:01:19 +00001654
Greg Claytondaf515f2011-07-09 20:12:33 +00001655// This allows you to create an array member using and index
1656// that doesn't not fall in the normal bounds of the array.
1657// Many times structure can be defined as:
1658// struct Collection
1659// {
1660// uint32_t item_count;
1661// Item item_array[0];
1662// };
1663// The size of the "item_array" is 1, but many times in practice
1664// there are more items in "item_array".
1665
1666ValueObjectSP
1667ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1668{
1669 ValueObjectSP synthetic_child_sp;
1670 if (IsArrayType ())
1671 {
1672 char index_str[64];
1673 snprintf(index_str, sizeof(index_str), "[%i]", index);
1674 ConstString index_const_str(index_str);
1675 // Check if we have already created a synthetic array member in this
1676 // valid object. If we have we will re-use it.
1677 synthetic_child_sp = GetSyntheticChild (index_const_str);
1678 if (!synthetic_child_sp)
1679 {
1680 ValueObject *synthetic_child;
1681 // We haven't made a synthetic array member for INDEX yet, so
1682 // lets make one and cache it for any future reference.
1683 synthetic_child = CreateChildAtIndex(0, true, index);
1684
1685 // Cache the value if we got one back...
1686 if (synthetic_child)
1687 {
1688 AddSyntheticChild(index_const_str, synthetic_child);
1689 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001690 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001691 synthetic_child_sp->m_is_array_item_for_pointer = true;
1692 }
1693 }
1694 }
1695 return synthetic_child_sp;
1696}
1697
Enrico Granata9fc19442011-07-06 02:13:41 +00001698ValueObjectSP
1699ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1700{
1701 ValueObjectSP synthetic_child_sp;
1702 if (IsScalarType ())
1703 {
1704 char index_str[64];
1705 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1706 ConstString index_const_str(index_str);
1707 // Check if we have already created a synthetic array member in this
1708 // valid object. If we have we will re-use it.
1709 synthetic_child_sp = GetSyntheticChild (index_const_str);
1710 if (!synthetic_child_sp)
1711 {
1712 ValueObjectChild *synthetic_child;
1713 // We haven't made a synthetic array member for INDEX yet, so
1714 // lets make one and cache it for any future reference.
1715 synthetic_child = new ValueObjectChild(*this,
1716 GetClangAST(),
1717 GetClangType(),
1718 index_const_str,
1719 GetByteSize(),
1720 0,
1721 to-from+1,
1722 from,
1723 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001724 false,
1725 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001726
1727 // Cache the value if we got one back...
1728 if (synthetic_child)
1729 {
1730 AddSyntheticChild(index_const_str, synthetic_child);
1731 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001732 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001733 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1734 }
1735 }
1736 }
1737 return synthetic_child_sp;
1738}
1739
Greg Claytonafacd142011-09-02 01:15:17 +00001740ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001741ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1742{
1743 ValueObjectSP synthetic_child_sp;
1744 if (IsArrayType () || IsPointerType ())
1745 {
1746 char index_str[64];
1747 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1748 ConstString index_const_str(index_str);
1749 // Check if we have already created a synthetic array member in this
1750 // valid object. If we have we will re-use it.
1751 synthetic_child_sp = GetSyntheticChild (index_const_str);
1752 if (!synthetic_child_sp)
1753 {
1754 ValueObjectSynthetic *synthetic_child;
1755
1756 // We haven't made a synthetic array member for INDEX yet, so
1757 // lets make one and cache it for any future reference.
1758 SyntheticArrayView *view = new SyntheticArrayView();
1759 view->AddRange(from,to);
1760 SyntheticChildrenSP view_sp(view);
1761 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1762
1763 // Cache the value if we got one back...
1764 if (synthetic_child)
1765 {
1766 AddSyntheticChild(index_const_str, synthetic_child);
1767 synthetic_child_sp = synthetic_child->GetSP();
1768 synthetic_child_sp->SetName(ConstString(index_str));
1769 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1770 }
1771 }
1772 }
1773 return synthetic_child_sp;
1774}
1775
Greg Claytonafacd142011-09-02 01:15:17 +00001776ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001777ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1778{
1779
1780 ValueObjectSP synthetic_child_sp;
1781
1782 char name_str[64];
1783 snprintf(name_str, sizeof(name_str), "@%i", offset);
1784 ConstString name_const_str(name_str);
1785
1786 // Check if we have already created a synthetic array member in this
1787 // valid object. If we have we will re-use it.
1788 synthetic_child_sp = GetSyntheticChild (name_const_str);
1789
1790 if (synthetic_child_sp.get())
1791 return synthetic_child_sp;
1792
1793 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001794 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001795
1796 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1797 type.GetASTContext(),
1798 type.GetOpaqueQualType(),
1799 name_const_str,
1800 type.GetTypeByteSize(),
1801 offset,
1802 0,
1803 0,
1804 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001805 false,
1806 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001807 if (synthetic_child)
1808 {
1809 AddSyntheticChild(name_const_str, synthetic_child);
1810 synthetic_child_sp = synthetic_child->GetSP();
1811 synthetic_child_sp->SetName(name_const_str);
1812 synthetic_child_sp->m_is_child_at_offset = true;
1813 }
1814 return synthetic_child_sp;
1815}
1816
Enrico Granatad55546b2011-07-22 00:16:08 +00001817// your expression path needs to have a leading . or ->
1818// (unless it somehow "looks like" an array, in which case it has
1819// a leading [ symbol). while the [ is meaningful and should be shown
1820// to the user, . and -> are just parser design, but by no means
1821// added information for the user.. strip them off
1822static const char*
1823SkipLeadingExpressionPathSeparators(const char* expression)
1824{
1825 if (!expression || !expression[0])
1826 return expression;
1827 if (expression[0] == '.')
1828 return expression+1;
1829 if (expression[0] == '-' && expression[1] == '>')
1830 return expression+2;
1831 return expression;
1832}
1833
Greg Claytonafacd142011-09-02 01:15:17 +00001834ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00001835ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1836{
1837 ValueObjectSP synthetic_child_sp;
1838 ConstString name_const_string(expression);
1839 // Check if we have already created a synthetic array member in this
1840 // valid object. If we have we will re-use it.
1841 synthetic_child_sp = GetSyntheticChild (name_const_string);
1842 if (!synthetic_child_sp)
1843 {
1844 // We haven't made a synthetic array member for expression yet, so
1845 // lets make one and cache it for any future reference.
1846 synthetic_child_sp = GetValueForExpressionPath(expression);
1847
1848 // Cache the value if we got one back...
1849 if (synthetic_child_sp.get())
1850 {
1851 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001852 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001853 synthetic_child_sp->m_is_expression_path_child = true;
1854 }
1855 }
1856 return synthetic_child_sp;
1857}
1858
1859void
Greg Claytonafacd142011-09-02 01:15:17 +00001860ValueObject::CalculateSyntheticValue (SyntheticValueType use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00001861{
Greg Claytonafacd142011-09-02 01:15:17 +00001862 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001863 return;
1864
Enrico Granatac3e320a2011-08-02 17:27:39 +00001865 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001866
1867 if (m_last_synthetic_filter.get() == NULL)
1868 return;
1869
Enrico Granataa37a0652011-07-24 00:14:56 +00001870 if (m_synthetic_value == NULL)
1871 m_synthetic_value = new ValueObjectSynthetic(*this, m_last_synthetic_filter);
Enrico Granatad55546b2011-07-22 00:16:08 +00001872
1873}
1874
Jim Ingham78a685a2011-04-16 00:01:13 +00001875void
Greg Claytonafacd142011-09-02 01:15:17 +00001876ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00001877{
Greg Claytonafacd142011-09-02 01:15:17 +00001878 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00001879 return;
1880
Jim Ingham58b59f92011-04-22 23:53:53 +00001881 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00001882 {
Enrico Granata6f3533f2011-07-29 19:53:35 +00001883 Process *process = m_update_point.GetProcessSP().get();
Jim Ingham78a685a2011-04-16 00:01:13 +00001884 bool worth_having_dynamic_value = false;
Jim Ingham22777012010-09-23 02:01:19 +00001885
Jim Ingham78a685a2011-04-16 00:01:13 +00001886
1887 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
1888 // hard code this everywhere.
Greg Claytonafacd142011-09-02 01:15:17 +00001889 LanguageType known_type = GetObjectRuntimeLanguage();
1890 if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
Jim Ingham78a685a2011-04-16 00:01:13 +00001891 {
1892 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
1893 if (runtime)
1894 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
1895 }
1896 else
1897 {
Greg Claytonafacd142011-09-02 01:15:17 +00001898 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus);
Jim Ingham78a685a2011-04-16 00:01:13 +00001899 if (cpp_runtime)
1900 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
1901
1902 if (!worth_having_dynamic_value)
1903 {
Greg Claytonafacd142011-09-02 01:15:17 +00001904 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC);
Jim Ingham78a685a2011-04-16 00:01:13 +00001905 if (objc_runtime)
Jim Ingham2837b762011-05-04 03:43:18 +00001906 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00001907 }
1908 }
1909
1910 if (worth_having_dynamic_value)
Jim Ingham2837b762011-05-04 03:43:18 +00001911 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham58b59f92011-04-22 23:53:53 +00001912
1913// if (worth_having_dynamic_value)
1914// printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager);
1915
Jim Ingham78a685a2011-04-16 00:01:13 +00001916 }
1917}
1918
Jim Ingham58b59f92011-04-22 23:53:53 +00001919ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00001920ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00001921{
Greg Claytonafacd142011-09-02 01:15:17 +00001922 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00001923 return ValueObjectSP();
1924
1925 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00001926 {
Jim Ingham2837b762011-05-04 03:43:18 +00001927 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001928 }
Jim Ingham58b59f92011-04-22 23:53:53 +00001929 if (m_dynamic_value)
1930 return m_dynamic_value->GetSP();
1931 else
1932 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00001933}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001934
Jim Ingham60dbabb2011-12-08 19:44:08 +00001935ValueObjectSP
1936ValueObject::GetStaticValue()
1937{
1938 return GetSP();
1939}
1940
Enrico Granatad55546b2011-07-22 00:16:08 +00001941// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
1942// or we do not really want a dynamic VO. this method instead returns this object
1943// itself when making it synthetic has no meaning. this makes it much simpler
1944// to replace the SyntheticValue for the ValueObject
1945ValueObjectSP
1946ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
1947{
Greg Claytonafacd142011-09-02 01:15:17 +00001948 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001949 return GetSP();
1950
Enrico Granatac3e320a2011-08-02 17:27:39 +00001951 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001952
1953 if (m_last_synthetic_filter.get() == NULL)
1954 return GetSP();
1955
1956 CalculateSyntheticValue(use_synthetic);
1957
1958 if (m_synthetic_value)
1959 return m_synthetic_value->GetSP();
1960 else
1961 return GetSP();
1962}
1963
Greg Claytone221f822011-01-21 01:59:00 +00001964bool
Enrico Granata27b625e2011-08-09 01:04:56 +00001965ValueObject::HasSyntheticValue()
1966{
1967 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
1968
1969 if (m_last_synthetic_filter.get() == NULL)
1970 return false;
1971
Greg Claytonafacd142011-09-02 01:15:17 +00001972 CalculateSyntheticValue(eUseSyntheticFilter);
Enrico Granata27b625e2011-08-09 01:04:56 +00001973
1974 if (m_synthetic_value)
1975 return true;
1976 else
1977 return false;
1978}
1979
1980bool
Greg Claytone221f822011-01-21 01:59:00 +00001981ValueObject::GetBaseClassPath (Stream &s)
1982{
1983 if (IsBaseClass())
1984 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001985 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00001986 clang_type_t clang_type = GetClangType();
1987 std::string cxx_class_name;
1988 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
1989 if (this_had_base_class)
1990 {
1991 if (parent_had_base_class)
1992 s.PutCString("::");
1993 s.PutCString(cxx_class_name.c_str());
1994 }
1995 return parent_had_base_class || this_had_base_class;
1996 }
1997 return false;
1998}
1999
2000
2001ValueObject *
2002ValueObject::GetNonBaseClassParent()
2003{
Jim Ingham78a685a2011-04-16 00:01:13 +00002004 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002005 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002006 if (GetParent()->IsBaseClass())
2007 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002008 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002009 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002010 }
2011 return NULL;
2012}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002013
2014void
Enrico Granata4becb372011-06-29 22:27:15 +00002015ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002016{
Greg Claytone221f822011-01-21 01:59:00 +00002017 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002018
Enrico Granata85933ed2011-08-18 16:38:26 +00002019 if (is_deref_of_parent && epformat == eDereferencePointers)
2020 {
Enrico Granata4becb372011-06-29 22:27:15 +00002021 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2022 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2023 // the eHonorPointers mode is meant to produce strings in this latter format
2024 s.PutCString("*(");
2025 }
Greg Claytone221f822011-01-21 01:59:00 +00002026
Enrico Granata4becb372011-06-29 22:27:15 +00002027 ValueObject* parent = GetParent();
2028
2029 if (parent)
2030 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002031
2032 // if we are a deref_of_parent just because we are synthetic array
2033 // members made up to allow ptr[%d] syntax to work in variable
2034 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00002035 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002036 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002037
Greg Claytone221f822011-01-21 01:59:00 +00002038 if (!IsBaseClass())
2039 {
2040 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002041 {
Greg Claytone221f822011-01-21 01:59:00 +00002042 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2043 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002044 {
Greg Claytone221f822011-01-21 01:59:00 +00002045 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2046 if (non_base_class_parent_clang_type)
2047 {
2048 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2049
Enrico Granata9dd75c82011-07-15 23:30:15 +00002050 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002051 {
2052 s.PutCString("->");
2053 }
Enrico Granata4becb372011-06-29 22:27:15 +00002054 else
2055 {
2056 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2057 {
2058 s.PutCString("->");
2059 }
2060 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2061 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2062 {
2063 s.PutChar('.');
2064 }
Greg Claytone221f822011-01-21 01:59:00 +00002065 }
2066 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002067 }
Greg Claytone221f822011-01-21 01:59:00 +00002068
2069 const char *name = GetName().GetCString();
2070 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002071 {
Greg Claytone221f822011-01-21 01:59:00 +00002072 if (qualify_cxx_base_classes)
2073 {
2074 if (GetBaseClassPath (s))
2075 s.PutCString("::");
2076 }
2077 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002078 }
2079 }
2080 }
2081
Enrico Granata85933ed2011-08-18 16:38:26 +00002082 if (is_deref_of_parent && epformat == eDereferencePointers)
2083 {
Greg Claytone221f822011-01-21 01:59:00 +00002084 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002085 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002086}
2087
Greg Claytonafacd142011-09-02 01:15:17 +00002088ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002089ValueObject::GetValueForExpressionPath(const char* expression,
2090 const char** first_unparsed,
2091 ExpressionPathScanEndReason* reason_to_stop,
2092 ExpressionPathEndResultType* final_value_type,
2093 const GetValueForExpressionPathOptions& options,
2094 ExpressionPathAftermath* final_task_on_target)
2095{
2096
2097 const char* dummy_first_unparsed;
2098 ExpressionPathScanEndReason dummy_reason_to_stop;
2099 ExpressionPathEndResultType dummy_final_value_type;
2100 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2101
2102 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2103 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2104 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2105 final_value_type ? final_value_type : &dummy_final_value_type,
2106 options,
2107 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2108
2109 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2110 {
2111 return ret_val;
2112 }
2113 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2114 {
2115 if (*final_task_on_target == ValueObject::eDereference)
2116 {
2117 Error error;
2118 ValueObjectSP final_value = ret_val->Dereference(error);
2119 if (error.Fail() || !final_value.get())
2120 {
2121 *reason_to_stop = ValueObject::eDereferencingFailed;
2122 *final_value_type = ValueObject::eInvalid;
2123 return ValueObjectSP();
2124 }
2125 else
2126 {
2127 *final_task_on_target = ValueObject::eNothing;
2128 return final_value;
2129 }
2130 }
2131 if (*final_task_on_target == ValueObject::eTakeAddress)
2132 {
2133 Error error;
2134 ValueObjectSP final_value = ret_val->AddressOf(error);
2135 if (error.Fail() || !final_value.get())
2136 {
2137 *reason_to_stop = ValueObject::eTakingAddressFailed;
2138 *final_value_type = ValueObject::eInvalid;
2139 return ValueObjectSP();
2140 }
2141 else
2142 {
2143 *final_task_on_target = ValueObject::eNothing;
2144 return final_value;
2145 }
2146 }
2147 }
2148 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2149}
2150
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002151int
2152ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002153 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002154 const char** first_unparsed,
2155 ExpressionPathScanEndReason* reason_to_stop,
2156 ExpressionPathEndResultType* final_value_type,
2157 const GetValueForExpressionPathOptions& options,
2158 ExpressionPathAftermath* final_task_on_target)
2159{
2160 const char* dummy_first_unparsed;
2161 ExpressionPathScanEndReason dummy_reason_to_stop;
2162 ExpressionPathEndResultType dummy_final_value_type;
2163 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2164
2165 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2166 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2167 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2168 final_value_type ? final_value_type : &dummy_final_value_type,
2169 options,
2170 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2171
2172 if (!ret_val.get()) // if there are errors, I add nothing to the list
2173 return 0;
2174
2175 if (*reason_to_stop != eArrayRangeOperatorMet)
2176 {
2177 // I need not expand a range, just post-process the final value and return
2178 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2179 {
2180 list->Append(ret_val);
2181 return 1;
2182 }
2183 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2184 {
2185 if (*final_task_on_target == ValueObject::eDereference)
2186 {
2187 Error error;
2188 ValueObjectSP final_value = ret_val->Dereference(error);
2189 if (error.Fail() || !final_value.get())
2190 {
2191 *reason_to_stop = ValueObject::eDereferencingFailed;
2192 *final_value_type = ValueObject::eInvalid;
2193 return 0;
2194 }
2195 else
2196 {
2197 *final_task_on_target = ValueObject::eNothing;
2198 list->Append(final_value);
2199 return 1;
2200 }
2201 }
2202 if (*final_task_on_target == ValueObject::eTakeAddress)
2203 {
2204 Error error;
2205 ValueObjectSP final_value = ret_val->AddressOf(error);
2206 if (error.Fail() || !final_value.get())
2207 {
2208 *reason_to_stop = ValueObject::eTakingAddressFailed;
2209 *final_value_type = ValueObject::eInvalid;
2210 return 0;
2211 }
2212 else
2213 {
2214 *final_task_on_target = ValueObject::eNothing;
2215 list->Append(final_value);
2216 return 1;
2217 }
2218 }
2219 }
2220 }
2221 else
2222 {
2223 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2224 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2225 ret_val,
2226 list,
2227 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2228 final_value_type ? final_value_type : &dummy_final_value_type,
2229 options,
2230 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2231 }
2232 // in any non-covered case, just do the obviously right thing
2233 list->Append(ret_val);
2234 return 1;
2235}
2236
Greg Claytonafacd142011-09-02 01:15:17 +00002237ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002238ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2239 const char** first_unparsed,
2240 ExpressionPathScanEndReason* reason_to_stop,
2241 ExpressionPathEndResultType* final_result,
2242 const GetValueForExpressionPathOptions& options,
2243 ExpressionPathAftermath* what_next)
2244{
2245 ValueObjectSP root = GetSP();
2246
2247 if (!root.get())
2248 return ValueObjectSP();
2249
2250 *first_unparsed = expression_cstr;
2251
2252 while (true)
2253 {
2254
2255 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2256
Greg Claytonafacd142011-09-02 01:15:17 +00002257 clang_type_t root_clang_type = root->GetClangType();
2258 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002259 Flags root_clang_type_info,pointee_clang_type_info;
2260
2261 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2262 if (pointee_clang_type)
2263 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002264
2265 if (!expression_cstr || *expression_cstr == '\0')
2266 {
2267 *reason_to_stop = ValueObject::eEndOfString;
2268 return root;
2269 }
2270
2271 switch (*expression_cstr)
2272 {
2273 case '-':
2274 {
2275 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002276 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 +00002277 {
2278 *first_unparsed = expression_cstr;
2279 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
2280 *final_result = ValueObject::eInvalid;
2281 return ValueObjectSP();
2282 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002283 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2284 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002285 options.m_no_fragile_ivar)
2286 {
2287 *first_unparsed = expression_cstr;
2288 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
2289 *final_result = ValueObject::eInvalid;
2290 return ValueObjectSP();
2291 }
2292 if (expression_cstr[1] != '>')
2293 {
2294 *first_unparsed = expression_cstr;
2295 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2296 *final_result = ValueObject::eInvalid;
2297 return ValueObjectSP();
2298 }
2299 expression_cstr++; // skip the -
2300 }
2301 case '.': // or fallthrough from ->
2302 {
2303 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002304 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 +00002305 {
2306 *first_unparsed = expression_cstr;
2307 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
2308 *final_result = ValueObject::eInvalid;
2309 return ValueObjectSP();
2310 }
2311 expression_cstr++; // skip .
2312 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2313 ConstString child_name;
2314 if (!next_separator) // if no other separator just expand this last layer
2315 {
2316 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002317 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2318
2319 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002320 {
2321 *first_unparsed = '\0';
2322 *reason_to_stop = ValueObject::eEndOfString;
2323 *final_result = ValueObject::ePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002324 return child_valobj_sp;
2325 }
2326 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2327 {
Greg Clayton4c3b8fb2011-12-02 22:48:25 +00002328 child_valobj_sp = root->GetSyntheticValue(eNoSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002329 }
2330
2331 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2332 // so we hit the "else" branch, and return an error
2333 if(child_valobj_sp.get()) // if it worked, just return
2334 {
2335 *first_unparsed = '\0';
2336 *reason_to_stop = ValueObject::eEndOfString;
2337 *final_result = ValueObject::ePlain;
2338 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002339 }
2340 else
2341 {
2342 *first_unparsed = expression_cstr;
2343 *reason_to_stop = ValueObject::eNoSuchChild;
2344 *final_result = ValueObject::eInvalid;
2345 return ValueObjectSP();
2346 }
2347 }
2348 else // other layers do expand
2349 {
2350 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002351 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2352 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002353 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002354 root = child_valobj_sp;
2355 *first_unparsed = next_separator;
2356 *final_result = ValueObject::ePlain;
2357 continue;
2358 }
2359 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2360 {
Greg Claytonafacd142011-09-02 01:15:17 +00002361 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002362 }
2363
2364 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2365 // so we hit the "else" branch, and return an error
2366 if(child_valobj_sp.get()) // if it worked, move on
2367 {
2368 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002369 *first_unparsed = next_separator;
2370 *final_result = ValueObject::ePlain;
2371 continue;
2372 }
2373 else
2374 {
2375 *first_unparsed = expression_cstr;
2376 *reason_to_stop = ValueObject::eNoSuchChild;
2377 *final_result = ValueObject::eInvalid;
2378 return ValueObjectSP();
2379 }
2380 }
2381 break;
2382 }
2383 case '[':
2384 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002385 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 +00002386 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002387 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002388 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002389 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2390 {
2391 *first_unparsed = expression_cstr;
2392 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2393 *final_result = ValueObject::eInvalid;
2394 return ValueObjectSP();
2395 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002396 }
2397 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2398 {
2399 *first_unparsed = expression_cstr;
2400 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2401 *final_result = ValueObject::eInvalid;
2402 return ValueObjectSP();
2403 }
2404 }
2405 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2406 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002407 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002408 {
2409 *first_unparsed = expression_cstr;
2410 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2411 *final_result = ValueObject::eInvalid;
2412 return ValueObjectSP();
2413 }
2414 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2415 {
2416 *first_unparsed = expression_cstr+2;
2417 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2418 *final_result = ValueObject::eUnboundedRange;
2419 return root;
2420 }
2421 }
2422 const char *separator_position = ::strchr(expression_cstr+1,'-');
2423 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2424 if (!close_bracket_position) // if there is no ], this is a syntax error
2425 {
2426 *first_unparsed = expression_cstr;
2427 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2428 *final_result = ValueObject::eInvalid;
2429 return ValueObjectSP();
2430 }
2431 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2432 {
2433 char *end = NULL;
2434 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2435 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2436 {
2437 *first_unparsed = expression_cstr;
2438 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2439 *final_result = ValueObject::eInvalid;
2440 return ValueObjectSP();
2441 }
2442 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2443 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002444 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002445 {
2446 *first_unparsed = expression_cstr+2;
2447 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2448 *final_result = ValueObject::eUnboundedRange;
2449 return root;
2450 }
2451 else
2452 {
2453 *first_unparsed = expression_cstr;
2454 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2455 *final_result = ValueObject::eInvalid;
2456 return ValueObjectSP();
2457 }
2458 }
2459 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002460 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002461 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002462 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2463 if (!child_valobj_sp)
2464 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002465 if (!child_valobj_sp)
Greg Claytonafacd142011-09-02 01:15:17 +00002466 if (root->HasSyntheticValue() && root->GetSyntheticValue(eUseSyntheticFilter)->GetNumChildren() > index)
2467 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002468 if (child_valobj_sp)
2469 {
2470 root = child_valobj_sp;
2471 *first_unparsed = end+1; // skip ]
2472 *final_result = ValueObject::ePlain;
2473 continue;
2474 }
2475 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002476 {
2477 *first_unparsed = expression_cstr;
2478 *reason_to_stop = ValueObject::eNoSuchChild;
2479 *final_result = ValueObject::eInvalid;
2480 return ValueObjectSP();
2481 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002482 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002483 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002484 {
2485 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 +00002486 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002487 {
2488 Error error;
2489 root = root->Dereference(error);
2490 if (error.Fail() || !root.get())
2491 {
2492 *first_unparsed = expression_cstr;
2493 *reason_to_stop = ValueObject::eDereferencingFailed;
2494 *final_result = ValueObject::eInvalid;
2495 return ValueObjectSP();
2496 }
2497 else
2498 {
2499 *what_next = eNothing;
2500 continue;
2501 }
2502 }
2503 else
2504 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002505 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Claytonafacd142011-09-02 01:15:17 +00002506 root->GetClangType()) == eLanguageTypeObjC
Enrico Granata27b625e2011-08-09 01:04:56 +00002507 &&
2508 ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2509 &&
2510 root->HasSyntheticValue()
2511 &&
2512 options.m_no_synthetic_children == false)
2513 {
Greg Claytonafacd142011-09-02 01:15:17 +00002514 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002515 }
2516 else
2517 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002518 if (!root.get())
2519 {
2520 *first_unparsed = expression_cstr;
2521 *reason_to_stop = ValueObject::eNoSuchChild;
2522 *final_result = ValueObject::eInvalid;
2523 return ValueObjectSP();
2524 }
2525 else
2526 {
2527 *first_unparsed = end+1; // skip ]
2528 *final_result = ValueObject::ePlain;
2529 continue;
2530 }
2531 }
2532 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002533 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002534 {
2535 root = root->GetSyntheticBitFieldChild(index, index, true);
2536 if (!root.get())
2537 {
2538 *first_unparsed = expression_cstr;
2539 *reason_to_stop = ValueObject::eNoSuchChild;
2540 *final_result = ValueObject::eInvalid;
2541 return ValueObjectSP();
2542 }
2543 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2544 {
2545 *first_unparsed = end+1; // skip ]
2546 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2547 *final_result = ValueObject::eBitfield;
2548 return root;
2549 }
2550 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002551 else if (root->HasSyntheticValue() && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002552 {
Greg Claytonafacd142011-09-02 01:15:17 +00002553 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002554 if (!root.get())
2555 {
2556 *first_unparsed = expression_cstr;
2557 *reason_to_stop = ValueObject::eNoSuchChild;
2558 *final_result = ValueObject::eInvalid;
2559 return ValueObjectSP();
2560 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002561 else
2562 {
2563 *first_unparsed = end+1; // skip ]
2564 *final_result = ValueObject::ePlain;
2565 continue;
2566 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002567 }
2568 else
2569 {
2570 *first_unparsed = expression_cstr;
2571 *reason_to_stop = ValueObject::eNoSuchChild;
2572 *final_result = ValueObject::eInvalid;
2573 return ValueObjectSP();
2574 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002575 }
2576 else // we have a low and a high index
2577 {
2578 char *end = NULL;
2579 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2580 if (!end || end != separator_position) // if something weird is in our way return an error
2581 {
2582 *first_unparsed = expression_cstr;
2583 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2584 *final_result = ValueObject::eInvalid;
2585 return ValueObjectSP();
2586 }
2587 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2588 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2589 {
2590 *first_unparsed = expression_cstr;
2591 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2592 *final_result = ValueObject::eInvalid;
2593 return ValueObjectSP();
2594 }
2595 if (index_lower > index_higher) // swap indices if required
2596 {
2597 unsigned long temp = index_lower;
2598 index_lower = index_higher;
2599 index_higher = temp;
2600 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002601 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002602 {
2603 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2604 if (!root.get())
2605 {
2606 *first_unparsed = expression_cstr;
2607 *reason_to_stop = ValueObject::eNoSuchChild;
2608 *final_result = ValueObject::eInvalid;
2609 return ValueObjectSP();
2610 }
2611 else
2612 {
2613 *first_unparsed = end+1; // skip ]
2614 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2615 *final_result = ValueObject::eBitfield;
2616 return root;
2617 }
2618 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002619 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 +00002620 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002621 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002622 {
2623 Error error;
2624 root = root->Dereference(error);
2625 if (error.Fail() || !root.get())
2626 {
2627 *first_unparsed = expression_cstr;
2628 *reason_to_stop = ValueObject::eDereferencingFailed;
2629 *final_result = ValueObject::eInvalid;
2630 return ValueObjectSP();
2631 }
2632 else
2633 {
2634 *what_next = ValueObject::eNothing;
2635 continue;
2636 }
2637 }
2638 else
2639 {
2640 *first_unparsed = expression_cstr;
2641 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2642 *final_result = ValueObject::eBoundedRange;
2643 return root;
2644 }
2645 }
2646 break;
2647 }
2648 default: // some non-separator is in the way
2649 {
2650 *first_unparsed = expression_cstr;
2651 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2652 *final_result = ValueObject::eInvalid;
2653 return ValueObjectSP();
2654 break;
2655 }
2656 }
2657 }
2658}
2659
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002660int
2661ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2662 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002663 ValueObjectSP root,
2664 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002665 ExpressionPathScanEndReason* reason_to_stop,
2666 ExpressionPathEndResultType* final_result,
2667 const GetValueForExpressionPathOptions& options,
2668 ExpressionPathAftermath* what_next)
2669{
2670 if (!root.get())
2671 return 0;
2672
2673 *first_unparsed = expression_cstr;
2674
2675 while (true)
2676 {
2677
2678 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2679
Greg Claytonafacd142011-09-02 01:15:17 +00002680 clang_type_t root_clang_type = root->GetClangType();
2681 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002682 Flags root_clang_type_info,pointee_clang_type_info;
2683
2684 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2685 if (pointee_clang_type)
2686 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2687
2688 if (!expression_cstr || *expression_cstr == '\0')
2689 {
2690 *reason_to_stop = ValueObject::eEndOfString;
2691 list->Append(root);
2692 return 1;
2693 }
2694
2695 switch (*expression_cstr)
2696 {
2697 case '[':
2698 {
2699 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2700 {
2701 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2702 {
2703 *first_unparsed = expression_cstr;
2704 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2705 *final_result = ValueObject::eInvalid;
2706 return 0;
2707 }
2708 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2709 {
2710 *first_unparsed = expression_cstr;
2711 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2712 *final_result = ValueObject::eInvalid;
2713 return 0;
2714 }
2715 }
2716 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2717 {
2718 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2719 {
2720 *first_unparsed = expression_cstr;
2721 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2722 *final_result = ValueObject::eInvalid;
2723 return 0;
2724 }
2725 else // expand this into list
2726 {
2727 int max_index = root->GetNumChildren() - 1;
2728 for (int index = 0; index < max_index; index++)
2729 {
2730 ValueObjectSP child =
2731 root->GetChildAtIndex(index, true);
2732 list->Append(child);
2733 }
2734 *first_unparsed = expression_cstr+2;
2735 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2736 *final_result = ValueObject::eValueObjectList;
2737 return max_index; // tell me number of items I added to the VOList
2738 }
2739 }
2740 const char *separator_position = ::strchr(expression_cstr+1,'-');
2741 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2742 if (!close_bracket_position) // if there is no ], this is a syntax error
2743 {
2744 *first_unparsed = expression_cstr;
2745 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2746 *final_result = ValueObject::eInvalid;
2747 return 0;
2748 }
2749 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2750 {
2751 char *end = NULL;
2752 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2753 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2754 {
2755 *first_unparsed = expression_cstr;
2756 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2757 *final_result = ValueObject::eInvalid;
2758 return 0;
2759 }
2760 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2761 {
2762 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2763 {
2764 int max_index = root->GetNumChildren() - 1;
2765 for (int index = 0; index < max_index; index++)
2766 {
2767 ValueObjectSP child =
2768 root->GetChildAtIndex(index, true);
2769 list->Append(child);
2770 }
2771 *first_unparsed = expression_cstr+2;
2772 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2773 *final_result = ValueObject::eValueObjectList;
2774 return max_index; // tell me number of items I added to the VOList
2775 }
2776 else
2777 {
2778 *first_unparsed = expression_cstr;
2779 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2780 *final_result = ValueObject::eInvalid;
2781 return 0;
2782 }
2783 }
2784 // from here on we do have a valid index
2785 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2786 {
2787 root = root->GetChildAtIndex(index, true);
2788 if (!root.get())
2789 {
2790 *first_unparsed = expression_cstr;
2791 *reason_to_stop = ValueObject::eNoSuchChild;
2792 *final_result = ValueObject::eInvalid;
2793 return 0;
2794 }
2795 else
2796 {
2797 list->Append(root);
2798 *first_unparsed = end+1; // skip ]
2799 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2800 *final_result = ValueObject::eValueObjectList;
2801 return 1;
2802 }
2803 }
2804 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2805 {
2806 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
2807 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2808 {
2809 Error error;
2810 root = root->Dereference(error);
2811 if (error.Fail() || !root.get())
2812 {
2813 *first_unparsed = expression_cstr;
2814 *reason_to_stop = ValueObject::eDereferencingFailed;
2815 *final_result = ValueObject::eInvalid;
2816 return 0;
2817 }
2818 else
2819 {
2820 *what_next = eNothing;
2821 continue;
2822 }
2823 }
2824 else
2825 {
2826 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2827 if (!root.get())
2828 {
2829 *first_unparsed = expression_cstr;
2830 *reason_to_stop = ValueObject::eNoSuchChild;
2831 *final_result = ValueObject::eInvalid;
2832 return 0;
2833 }
2834 else
2835 {
2836 list->Append(root);
2837 *first_unparsed = end+1; // skip ]
2838 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2839 *final_result = ValueObject::eValueObjectList;
2840 return 1;
2841 }
2842 }
2843 }
2844 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2845 {
2846 root = root->GetSyntheticBitFieldChild(index, index, true);
2847 if (!root.get())
2848 {
2849 *first_unparsed = expression_cstr;
2850 *reason_to_stop = ValueObject::eNoSuchChild;
2851 *final_result = ValueObject::eInvalid;
2852 return 0;
2853 }
2854 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2855 {
2856 list->Append(root);
2857 *first_unparsed = end+1; // skip ]
2858 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2859 *final_result = ValueObject::eValueObjectList;
2860 return 1;
2861 }
2862 }
2863 }
2864 else // we have a low and a high index
2865 {
2866 char *end = NULL;
2867 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2868 if (!end || end != separator_position) // if something weird is in our way return an error
2869 {
2870 *first_unparsed = expression_cstr;
2871 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2872 *final_result = ValueObject::eInvalid;
2873 return 0;
2874 }
2875 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2876 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2877 {
2878 *first_unparsed = expression_cstr;
2879 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2880 *final_result = ValueObject::eInvalid;
2881 return 0;
2882 }
2883 if (index_lower > index_higher) // swap indices if required
2884 {
2885 unsigned long temp = index_lower;
2886 index_lower = index_higher;
2887 index_higher = temp;
2888 }
2889 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
2890 {
2891 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2892 if (!root.get())
2893 {
2894 *first_unparsed = expression_cstr;
2895 *reason_to_stop = ValueObject::eNoSuchChild;
2896 *final_result = ValueObject::eInvalid;
2897 return 0;
2898 }
2899 else
2900 {
2901 list->Append(root);
2902 *first_unparsed = end+1; // skip ]
2903 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2904 *final_result = ValueObject::eValueObjectList;
2905 return 1;
2906 }
2907 }
2908 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
2909 *what_next == ValueObject::eDereference &&
2910 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2911 {
2912 Error error;
2913 root = root->Dereference(error);
2914 if (error.Fail() || !root.get())
2915 {
2916 *first_unparsed = expression_cstr;
2917 *reason_to_stop = ValueObject::eDereferencingFailed;
2918 *final_result = ValueObject::eInvalid;
2919 return 0;
2920 }
2921 else
2922 {
2923 *what_next = ValueObject::eNothing;
2924 continue;
2925 }
2926 }
2927 else
2928 {
Johnny Chen44805302011-07-19 19:48:13 +00002929 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002930 index <= index_higher; index++)
2931 {
2932 ValueObjectSP child =
2933 root->GetChildAtIndex(index, true);
2934 list->Append(child);
2935 }
2936 *first_unparsed = end+1;
2937 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2938 *final_result = ValueObject::eValueObjectList;
2939 return index_higher-index_lower+1; // tell me number of items I added to the VOList
2940 }
2941 }
2942 break;
2943 }
2944 default: // some non-[ separator, or something entirely wrong, is in the way
2945 {
2946 *first_unparsed = expression_cstr;
2947 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2948 *final_result = ValueObject::eInvalid;
2949 return 0;
2950 break;
2951 }
2952 }
2953 }
2954}
2955
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002956void
Greg Clayton1d3afba2010-10-05 00:00:42 +00002957ValueObject::DumpValueObject
2958(
2959 Stream &s,
Greg Clayton1d3afba2010-10-05 00:00:42 +00002960 ValueObject *valobj,
2961 const char *root_valobj_name,
2962 uint32_t ptr_depth,
2963 uint32_t curr_depth,
2964 uint32_t max_depth,
2965 bool show_types,
2966 bool show_location,
2967 bool use_objc,
Greg Claytonafacd142011-09-02 01:15:17 +00002968 DynamicValueType use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00002969 bool use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002970 bool scope_already_checked,
Enrico Granata0c5ef692011-07-16 01:22:04 +00002971 bool flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00002972 uint32_t omit_summary_depth,
2973 bool ignore_cap
Greg Clayton1d3afba2010-10-05 00:00:42 +00002974)
2975{
Greg Clayton007d5be2011-05-30 00:49:24 +00002976 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002977 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00002978 bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00002979
Greg Claytonafacd142011-09-02 01:15:17 +00002980 if (update_success && use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00002981 {
Jim Ingham2837b762011-05-04 03:43:18 +00002982 ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00002983 if (dynamic_value)
2984 valobj = dynamic_value;
2985 }
2986
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002987 clang_type_t clang_type = valobj->GetClangType();
2988
Greg Clayton73b472d2010-10-27 03:32:59 +00002989 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002990 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00002991 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
2992 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002993
2994 const bool print_valobj = flat_output == false || has_value;
2995
2996 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002997 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002998 if (show_location)
2999 {
Jim Ingham6035b672011-03-31 00:19:25 +00003000 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003001 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003002
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003003 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003004
Greg Clayton7c8a9662010-11-02 01:50:16 +00003005 // Always show the type for the top level items.
Greg Claytone221f822011-01-21 01:59:00 +00003006 if (show_types || (curr_depth == 0 && !flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003007 {
Enrico Granata9910bc82011-08-03 02:18:51 +00003008 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
3009 s.Printf("(%s", typeName);
3010 // only show dynamic types if the user really wants to see types
Greg Claytonafacd142011-09-02 01:15:17 +00003011 if (show_types && use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003012 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003013 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003014 {
3015 Process* process = valobj->GetUpdatePoint().GetProcessSP().get();
3016 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003017 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003018 else
3019 {
3020 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3021 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003022 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003023 else
3024 {
3025 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3026 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003027 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003028 else
3029 s.Printf(", dynamic type: %s) ",
3030 runtime->GetActualTypeName(isa).GetCString());
3031 }
3032 }
3033 }
3034 else
3035 s.Printf(") ");
3036 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003037
Greg Clayton1d3afba2010-10-05 00:00:42 +00003038
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003039 if (flat_output)
3040 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003041 // If we are showing types, also qualify the C++ base classes
3042 const bool qualify_cxx_base_classes = show_types;
3043 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003044 s.PutCString(" =");
3045 }
3046 else
3047 {
3048 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3049 s.Printf ("%s =", name_cstr);
3050 }
3051
Jim Ingham6035b672011-03-31 00:19:25 +00003052 if (!scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003053 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003054 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003055 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003056 }
3057
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003058 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003059 const char *sum_cstr = NULL;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003060 SummaryFormat* entry = valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003061
Enrico Granata0c5ef692011-07-16 01:22:04 +00003062 if (omit_summary_depth > 0)
3063 entry = NULL;
3064
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003065 if (err_cstr == NULL)
3066 {
Jim Ingham6035b672011-03-31 00:19:25 +00003067 val_cstr = valobj->GetValueAsCString();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003068 err_cstr = valobj->GetError().AsCString();
3069 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003070
3071 if (err_cstr)
3072 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003073 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003074 }
3075 else
3076 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003077 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003078 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003079 {
Enrico Granata4becb372011-06-29 22:27:15 +00003080
Enrico Granata0c5ef692011-07-16 01:22:04 +00003081 sum_cstr = (omit_summary_depth == 0) ? valobj->GetSummaryAsCString() : NULL;
Greg Clayton1d3afba2010-10-05 00:00:42 +00003082
Enrico Granata4becb372011-06-29 22:27:15 +00003083 // We must calculate this value in realtime because entry might alter this variable's value
3084 // (e.g. by saying ${var%fmt}) and render precached values useless
3085 if (val_cstr && (!entry || entry->DoesPrintValue() || !sum_cstr))
3086 s.Printf(" %s", valobj->GetValueAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003087
Enrico Granata9dd75c82011-07-15 23:30:15 +00003088 if (sum_cstr)
Enrico Granata0a3958e2011-07-02 00:25:22 +00003089 {
3090 // for some reason, using %@ (ObjC description) in a summary string, makes
3091 // us believe we need to reset ourselves, thus invalidating the content of
3092 // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty
3093 // let us recalculate it!
3094 if (sum_cstr[0] == '\0')
3095 s.Printf(" %s", valobj->GetSummaryAsCString());
3096 else
3097 s.Printf(" %s", sum_cstr);
3098 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003099
3100 if (use_objc)
3101 {
Jim Ingham6035b672011-03-31 00:19:25 +00003102 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003103 if (object_desc)
3104 s.Printf(" %s\n", object_desc);
3105 else
Sean Callanan672ad942010-10-23 00:18:49 +00003106 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003107 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003108 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003109 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003110
3111 if (curr_depth < max_depth)
3112 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003113 // We will show children for all concrete types. We won't show
3114 // pointer contents unless a pointer depth has been specified.
3115 // We won't reference contents unless the reference is the
3116 // root object (depth of zero).
3117 bool print_children = true;
3118
3119 // Use a new temporary pointer depth in case we override the
3120 // current pointer depth below...
3121 uint32_t curr_ptr_depth = ptr_depth;
3122
3123 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3124 if (is_ptr || is_ref)
3125 {
3126 // We have a pointer or reference whose value is an address.
3127 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003128 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003129 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003130 print_children = false;
3131
3132 else if (is_ref && curr_depth == 0)
3133 {
3134 // If this is the root object (depth is zero) that we are showing
3135 // and it is a reference, and no pointer depth has been supplied
3136 // print out what it references. Don't do this at deeper depths
3137 // otherwise we can end up with infinite recursion...
3138 curr_ptr_depth = 1;
3139 }
3140
3141 if (curr_ptr_depth == 0)
3142 print_children = false;
3143 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003144
Enrico Granata0a3958e2011-07-02 00:25:22 +00003145 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003146 {
Enrico Granatac482a192011-08-17 22:13:59 +00003147 ValueObjectSP synth_valobj = valobj->GetSyntheticValue(use_synth ?
Greg Claytonafacd142011-09-02 01:15:17 +00003148 eUseSyntheticFilter :
3149 eNoSyntheticFilter);
Enrico Granatac482a192011-08-17 22:13:59 +00003150 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003151 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003152 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003153 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003154 if (flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003155 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003156 if (print_valobj)
3157 s.EOL();
3158 }
3159 else
3160 {
3161 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003162 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003163 s.IndentMore();
3164 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003165
3166 uint32_t max_num_children = valobj->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
3167
3168 if (num_children > max_num_children && !ignore_cap)
3169 {
3170 num_children = max_num_children;
3171 print_dotdotdot = true;
3172 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003173
3174 for (uint32_t idx=0; idx<num_children; ++idx)
3175 {
Enrico Granatac482a192011-08-17 22:13:59 +00003176 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003177 if (child_sp.get())
3178 {
3179 DumpValueObject (s,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003180 child_sp.get(),
3181 NULL,
Greg Clayton73b472d2010-10-27 03:32:59 +00003182 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003183 curr_depth + 1,
3184 max_depth,
3185 show_types,
3186 show_location,
3187 false,
Jim Ingham78a685a2011-04-16 00:01:13 +00003188 use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00003189 use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003190 true,
Enrico Granata0c5ef692011-07-16 01:22:04 +00003191 flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00003192 omit_summary_depth > 1 ? omit_summary_depth - 1 : 0,
3193 ignore_cap);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003194 }
3195 }
3196
3197 if (!flat_output)
3198 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003199 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003200 {
3201 valobj->GetUpdatePoint().GetTargetSP()->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003202 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003203 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003204 s.IndentLess();
3205 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003206 }
3207 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003208 else if (has_children)
3209 {
3210 // Aggregate, no children...
3211 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003212 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003213 }
3214 else
3215 {
3216 if (print_valobj)
3217 s.EOL();
3218 }
3219
Greg Clayton1d3afba2010-10-05 00:00:42 +00003220 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003221 else
3222 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003223 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003224 }
3225 }
3226 else
3227 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003228 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003229 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003230 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003231 }
3232 }
3233 }
3234 }
3235}
3236
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003237
3238ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003239ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003240{
3241 ValueObjectSP valobj_sp;
3242
Enrico Granatac3e320a2011-08-02 17:27:39 +00003243 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003244 {
Jim Ingham6035b672011-03-31 00:19:25 +00003245 ExecutionContextScope *exe_scope = GetExecutionContextScope();
3246 if (exe_scope)
3247 {
3248 ExecutionContext exe_ctx;
3249 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003250
Jim Ingham6035b672011-03-31 00:19:25 +00003251 clang::ASTContext *ast = GetClangAST ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003252
Jim Ingham6035b672011-03-31 00:19:25 +00003253 DataExtractor data;
3254 data.SetByteOrder (m_data.GetByteOrder());
3255 data.SetAddressByteSize(m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003256
Greg Clayton644247c2011-07-07 01:59:51 +00003257 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003258
Jim Ingham58b59f92011-04-22 23:53:53 +00003259 valobj_sp = ValueObjectConstResult::Create (exe_scope,
3260 ast,
3261 GetClangType(),
3262 name,
Enrico Granata9128ee22011-09-06 19:20:51 +00003263 data,
3264 GetAddressOf());
Jim Ingham6035b672011-03-31 00:19:25 +00003265 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003266 }
Jim Ingham6035b672011-03-31 00:19:25 +00003267
3268 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003269 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003270 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003271 }
3272 return valobj_sp;
3273}
3274
Greg Claytonafacd142011-09-02 01:15:17 +00003275ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003276ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003277{
Jim Ingham58b59f92011-04-22 23:53:53 +00003278 if (m_deref_valobj)
3279 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003280
Greg Clayton54979cd2010-12-15 05:08:08 +00003281 const bool is_pointer_type = IsPointerType();
3282 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003283 {
3284 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003285 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003286
3287 std::string child_name_str;
3288 uint32_t child_byte_size = 0;
3289 int32_t child_byte_offset = 0;
3290 uint32_t child_bitfield_bit_size = 0;
3291 uint32_t child_bitfield_bit_offset = 0;
3292 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003293 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003294 const bool transparent_pointers = false;
3295 clang::ASTContext *clang_ast = GetClangAST();
3296 clang_type_t clang_type = GetClangType();
3297 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003298
3299 ExecutionContext exe_ctx;
3300 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
3301
3302 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3303 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003304 GetName().GetCString(),
3305 clang_type,
3306 0,
3307 transparent_pointers,
3308 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003309 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003310 child_name_str,
3311 child_byte_size,
3312 child_byte_offset,
3313 child_bitfield_bit_size,
3314 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003315 child_is_base_class,
3316 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003317 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003318 {
3319 ConstString child_name;
3320 if (!child_name_str.empty())
3321 child_name.SetCString (child_name_str.c_str());
3322
Jim Ingham58b59f92011-04-22 23:53:53 +00003323 m_deref_valobj = new ValueObjectChild (*this,
3324 clang_ast,
3325 child_clang_type,
3326 child_name,
3327 child_byte_size,
3328 child_byte_offset,
3329 child_bitfield_bit_size,
3330 child_bitfield_bit_offset,
3331 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003332 child_is_deref_of_parent,
3333 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003334 }
3335 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003336
Jim Ingham58b59f92011-04-22 23:53:53 +00003337 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003338 {
3339 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003340 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003341 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003342 else
3343 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003344 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003345 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003346
3347 if (is_pointer_type)
3348 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3349 else
3350 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003351 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003352 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003353}
3354
Greg Claytonafacd142011-09-02 01:15:17 +00003355ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003356ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003357{
Jim Ingham78a685a2011-04-16 00:01:13 +00003358 if (m_addr_of_valobj_sp)
3359 return m_addr_of_valobj_sp;
3360
Greg Claytone0d378b2011-03-24 21:19:54 +00003361 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003362 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003363 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003364 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003365 if (addr != LLDB_INVALID_ADDRESS)
3366 {
3367 switch (address_type)
3368 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003369 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003370 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003371 {
3372 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003373 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003374 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3375 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003376 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003377
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003378 case eAddressTypeFile:
3379 case eAddressTypeLoad:
3380 case eAddressTypeHost:
3381 {
3382 clang::ASTContext *ast = GetClangAST();
3383 clang_type_t clang_type = GetClangType();
3384 if (ast && clang_type)
3385 {
3386 std::string name (1, '&');
3387 name.append (m_name.AsCString(""));
Jim Ingham58b59f92011-04-22 23:53:53 +00003388 m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(),
3389 ast,
3390 ClangASTContext::CreatePointerType (ast, clang_type),
3391 ConstString (name.c_str()),
3392 addr,
3393 eAddressTypeInvalid,
3394 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003395 }
3396 }
3397 break;
3398 }
3399 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003400 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003401}
3402
Greg Claytonb2dcc362011-05-05 23:32:56 +00003403
Greg Claytonafacd142011-09-02 01:15:17 +00003404ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003405ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3406{
Greg Claytonafacd142011-09-02 01:15:17 +00003407 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003408 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003409 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003410
3411 if (ptr_value != LLDB_INVALID_ADDRESS)
3412 {
3413 Address ptr_addr (NULL, ptr_value);
3414
3415 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3416 name,
3417 ptr_addr,
3418 clang_ast_type);
3419 }
3420 return valobj_sp;
3421}
3422
Greg Claytonafacd142011-09-02 01:15:17 +00003423ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003424ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3425{
Greg Claytonafacd142011-09-02 01:15:17 +00003426 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003427 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003428 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003429
3430 if (ptr_value != LLDB_INVALID_ADDRESS)
3431 {
3432 Address ptr_addr (NULL, ptr_value);
3433
3434 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3435 name,
3436 ptr_addr,
3437 type_sp);
3438 }
3439 return valobj_sp;
3440}
3441
Jim Ingham6035b672011-03-31 00:19:25 +00003442ValueObject::EvaluationPoint::EvaluationPoint () :
Jim Ingham73ca05a2011-12-17 01:35:57 +00003443 ExecutionContextScope(),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003444 m_thread_id (LLDB_INVALID_UID),
Jim Ingham4b536182011-08-09 02:12:22 +00003445 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003446{
3447}
3448
3449ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Jim Ingham73ca05a2011-12-17 01:35:57 +00003450 ExecutionContextScope (),
Jim Ingham6035b672011-03-31 00:19:25 +00003451 m_needs_update (true),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003452 m_first_update (true),
Jim Ingham89b61092011-07-06 17:42:14 +00003453 m_thread_id (LLDB_INVALID_THREAD_ID),
Jim Ingham4b536182011-08-09 02:12:22 +00003454 m_mod_id ()
Stephen Wilson71c21d12011-04-11 19:41:40 +00003455
Jim Ingham6035b672011-03-31 00:19:25 +00003456{
3457 ExecutionContext exe_ctx;
Jim Ingham9ee01152011-12-10 01:49:43 +00003458
Jim Ingham6035b672011-03-31 00:19:25 +00003459 if (exe_scope)
3460 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Claytonc14ee322011-09-22 04:58:26 +00003461 Target *target = exe_ctx.GetTargetPtr();
3462 if (target != NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003463 {
Greg Claytonc14ee322011-09-22 04:58:26 +00003464 m_target_sp = target;
3465 m_process_sp = exe_ctx.GetProcessSP();
3466 if (!m_process_sp)
3467 m_process_sp = target->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003468
Greg Claytonc14ee322011-09-22 04:58:26 +00003469 if (m_process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003470 {
Jim Ingham4b536182011-08-09 02:12:22 +00003471 m_mod_id = m_process_sp->GetModID();
3472
Greg Claytonc14ee322011-09-22 04:58:26 +00003473 Thread *thread = exe_ctx.GetThreadPtr();
Jim Ingham6035b672011-03-31 00:19:25 +00003474
Greg Claytonc14ee322011-09-22 04:58:26 +00003475 if (thread == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003476 {
3477 if (use_selected)
Jim Ingham6035b672011-03-31 00:19:25 +00003478 thread = m_process_sp->GetThreadList().GetSelectedThread().get();
Jim Ingham6035b672011-03-31 00:19:25 +00003479 }
Jim Ingham6035b672011-03-31 00:19:25 +00003480
3481 if (thread != NULL)
3482 {
3483 m_thread_id = thread->GetIndexID();
Greg Claytonc14ee322011-09-22 04:58:26 +00003484
3485 StackFrame *frame = exe_ctx.GetFramePtr();
3486 if (frame == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003487 {
3488 if (use_selected)
3489 {
Greg Claytonc14ee322011-09-22 04:58:26 +00003490 frame = thread->GetSelectedFrame().get();
Jim Ingham6035b672011-03-31 00:19:25 +00003491 if (frame)
Jim Ingham6035b672011-03-31 00:19:25 +00003492 m_stack_id = frame->GetStackID();
Jim Ingham6035b672011-03-31 00:19:25 +00003493 }
3494 }
3495 else
Greg Claytonc14ee322011-09-22 04:58:26 +00003496 m_stack_id = frame->GetStackID();
Jim Ingham6035b672011-03-31 00:19:25 +00003497 }
3498 }
3499 }
Jim Ingham6035b672011-03-31 00:19:25 +00003500}
3501
3502ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Stephen Wilson71c21d12011-04-11 19:41:40 +00003503 m_needs_update(true),
3504 m_first_update(true),
Jim Ingham6035b672011-03-31 00:19:25 +00003505 m_target_sp (rhs.m_target_sp),
3506 m_process_sp (rhs.m_process_sp),
3507 m_thread_id (rhs.m_thread_id),
3508 m_stack_id (rhs.m_stack_id),
Jim Ingham4b536182011-08-09 02:12:22 +00003509 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003510{
3511}
3512
3513ValueObject::EvaluationPoint::~EvaluationPoint ()
3514{
3515}
3516
Jim Ingham73ca05a2011-12-17 01:35:57 +00003517Target *
3518ValueObject::EvaluationPoint::CalculateTarget ()
Jim Ingham6035b672011-03-31 00:19:25 +00003519{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003520 return m_target_sp.get();
3521}
3522
3523Process *
3524ValueObject::EvaluationPoint::CalculateProcess ()
3525{
3526 return m_process_sp.get();
3527}
3528
3529Thread *
3530ValueObject::EvaluationPoint::CalculateThread ()
3531{
3532 ExecutionContextScope *exe_scope;
Jim Ingham9ee01152011-12-10 01:49:43 +00003533 SyncWithProcessState(exe_scope);
Jim Ingham73ca05a2011-12-17 01:35:57 +00003534 if (exe_scope)
3535 return exe_scope->CalculateThread();
3536 else
3537 return NULL;
3538}
3539
3540StackFrame *
3541ValueObject::EvaluationPoint::CalculateStackFrame ()
3542{
3543 ExecutionContextScope *exe_scope;
3544 SyncWithProcessState(exe_scope);
3545 if (exe_scope)
3546 return exe_scope->CalculateStackFrame();
3547 else
3548 return NULL;
3549}
3550
3551void
3552ValueObject::EvaluationPoint::CalculateExecutionContext (ExecutionContext &exe_ctx)
3553{
3554 ExecutionContextScope *exe_scope;
3555 SyncWithProcessState(exe_scope);
3556 if (exe_scope)
3557 return exe_scope->CalculateExecutionContext (exe_ctx);
Jim Ingham6035b672011-03-31 00:19:25 +00003558}
3559
3560// This function checks the EvaluationPoint against the current process state. If the current
3561// state matches the evaluation point, or the evaluation point is already invalid, then we return
3562// false, meaning "no change". If the current state is different, we update our state, and return
3563// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3564// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003565// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003566
3567bool
Jim Ingham9ee01152011-12-10 01:49:43 +00003568ValueObject::EvaluationPoint::SyncWithProcessState(ExecutionContextScope *&exe_scope)
Jim Ingham6035b672011-03-31 00:19:25 +00003569{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003570
3571 // Start with the target, if it is NULL, then we're obviously not going to get any further:
3572 exe_scope = m_target_sp.get();
3573
3574 if (exe_scope == NULL)
3575 return false;
3576
Jim Ingham6035b672011-03-31 00:19:25 +00003577 // If we don't have a process nothing can change.
3578 if (!m_process_sp)
3579 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003580
3581 exe_scope = m_process_sp.get();
Jim Ingham6035b672011-03-31 00:19:25 +00003582
3583 // If our stop id is the current stop ID, nothing has changed:
Jim Ingham4b536182011-08-09 02:12:22 +00003584 ProcessModID current_mod_id = m_process_sp->GetModID();
3585
Jim Ingham78a685a2011-04-16 00:01:13 +00003586 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3587 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003588 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003589 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003590
3591 bool changed;
3592
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003593 if (m_mod_id.IsValid())
3594 {
3595 if (m_mod_id == current_mod_id)
3596 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003597 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003598 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003599 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003600 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003601 else
3602 {
3603 m_mod_id = current_mod_id;
3604 m_needs_update = true;
3605 changed = true;
3606 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003607 }
Jim Ingham6035b672011-03-31 00:19:25 +00003608
Jim Ingham73ca05a2011-12-17 01:35:57 +00003609 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3610 // That way we'll be sure to return a valid exe_scope.
3611 // 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 +00003612
3613 if (m_thread_id != LLDB_INVALID_THREAD_ID)
3614 {
3615 Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get();
3616 if (our_thread == NULL)
Greg Clayton262f80d2011-07-06 16:49:27 +00003617 {
Jim Ingham89b61092011-07-06 17:42:14 +00003618 SetInvalid();
Greg Clayton262f80d2011-07-06 16:49:27 +00003619 }
Jim Ingham6035b672011-03-31 00:19:25 +00003620 else
3621 {
Jim Ingham9ee01152011-12-10 01:49:43 +00003622 exe_scope = our_thread;
Jim Ingham6035b672011-03-31 00:19:25 +00003623
3624 if (m_stack_id.IsValid())
3625 {
3626 StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get();
3627 if (our_frame == NULL)
3628 SetInvalid();
3629 else
Jim Ingham9ee01152011-12-10 01:49:43 +00003630 exe_scope = our_frame;
Jim Ingham6035b672011-03-31 00:19:25 +00003631 }
3632 }
3633 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003634 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003635}
3636
Jim Ingham61be0902011-05-02 18:13:59 +00003637void
3638ValueObject::EvaluationPoint::SetUpdated ()
3639{
Jim Ingham9ee01152011-12-10 01:49:43 +00003640 if (m_process_sp)
3641 m_mod_id = m_process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003642 m_first_update = false;
3643 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003644}
3645
3646
Jim Ingham6035b672011-03-31 00:19:25 +00003647bool
3648ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3649{
3650 if (!IsValid())
3651 return false;
3652
3653 bool needs_update = false;
Jim Ingham6035b672011-03-31 00:19:25 +00003654
3655 // The target has to be non-null, and the
3656 Target *target = exe_scope->CalculateTarget();
3657 if (target != NULL)
3658 {
3659 Target *old_target = m_target_sp.get();
3660 assert (target == old_target);
3661 Process *process = exe_scope->CalculateProcess();
3662 if (process != NULL)
3663 {
3664 // FOR NOW - assume you can't update variable objects across process boundaries.
3665 Process *old_process = m_process_sp.get();
3666 assert (process == old_process);
Jim Ingham4b536182011-08-09 02:12:22 +00003667 ProcessModID current_mod_id = process->GetModID();
3668 if (m_mod_id != current_mod_id)
Jim Ingham6035b672011-03-31 00:19:25 +00003669 {
3670 needs_update = true;
Jim Ingham4b536182011-08-09 02:12:22 +00003671 m_mod_id = current_mod_id;
Jim Ingham6035b672011-03-31 00:19:25 +00003672 }
3673 // See if we're switching the thread or stack context. If no thread is given, this is
3674 // being evaluated in a global context.
3675 Thread *thread = exe_scope->CalculateThread();
3676 if (thread != NULL)
3677 {
Greg Claytonafacd142011-09-02 01:15:17 +00003678 user_id_t new_thread_index = thread->GetIndexID();
Jim Ingham6035b672011-03-31 00:19:25 +00003679 if (new_thread_index != m_thread_id)
3680 {
3681 needs_update = true;
3682 m_thread_id = new_thread_index;
3683 m_stack_id.Clear();
3684 }
3685
3686 StackFrame *new_frame = exe_scope->CalculateStackFrame();
3687 if (new_frame != NULL)
3688 {
3689 if (new_frame->GetStackID() != m_stack_id)
3690 {
3691 needs_update = true;
3692 m_stack_id = new_frame->GetStackID();
3693 }
3694 }
3695 else
3696 {
3697 m_stack_id.Clear();
3698 needs_update = true;
3699 }
3700 }
3701 else
3702 {
3703 // If this had been given a thread, and now there is none, we should update.
3704 // Otherwise we don't have to do anything.
3705 if (m_thread_id != LLDB_INVALID_UID)
3706 {
3707 m_thread_id = LLDB_INVALID_UID;
3708 m_stack_id.Clear();
3709 needs_update = true;
3710 }
3711 }
3712 }
3713 else
3714 {
3715 // If there is no process, then we don't need to update anything.
3716 // But if we're switching from having a process to not, we should try to update.
3717 if (m_process_sp.get() != NULL)
3718 {
3719 needs_update = true;
3720 m_process_sp.reset();
3721 m_thread_id = LLDB_INVALID_UID;
3722 m_stack_id.Clear();
3723 }
3724 }
3725 }
3726 else
3727 {
3728 // If there's no target, nothing can change so we don't need to update anything.
3729 // But if we're switching from having a target to not, we should try to update.
3730 if (m_target_sp.get() != NULL)
3731 {
3732 needs_update = true;
3733 m_target_sp.reset();
3734 m_process_sp.reset();
3735 m_thread_id = LLDB_INVALID_UID;
3736 m_stack_id.Clear();
3737 }
3738 }
3739 if (!m_needs_update)
3740 m_needs_update = needs_update;
3741
3742 return needs_update;
3743}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003744
3745void
3746ValueObject::ClearUserVisibleData()
3747{
3748 m_location_str.clear();
3749 m_value_str.clear();
3750 m_summary_str.clear();
3751 m_object_desc_str.clear();
Greg Clayton48ca8b82012-01-07 20:58:07 +00003752 m_is_getting_summary = false;
Johnny Chen44805302011-07-19 19:48:13 +00003753}
Enrico Granata9128ee22011-09-06 19:20:51 +00003754
3755SymbolContextScope *
3756ValueObject::GetSymbolContextScope()
3757{
3758 if (m_parent)
3759 {
3760 if (!m_parent->IsPointerOrReferenceType())
3761 return m_parent->GetSymbolContextScope();
3762 }
3763 return NULL;
3764}