blob: cfc5dcd3fd2533c5b6f92d15c6c754d691b9735f [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 {
Jim Ingham6657d092012-01-19 21:10:56 +00001083 lldb::Format my_format = GetFormat();
1084 if (m_format == lldb::eFormatDefault)
1085 {
1086 if (m_last_value_format)
1087 my_format = m_last_value_format->GetFormat();
1088 else
1089 my_format = reg_info->format;
1090 }
1091
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001092 StreamString reg_sstr;
Jim Ingham6657d092012-01-19 21:10:56 +00001093 m_data.Dump(&reg_sstr, 0, my_format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0, GetExecutionContextScope());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001094 m_value_str.swap(reg_sstr.GetString());
1095 }
1096 }
1097 break;
Greg Claytonc982c762010-07-09 20:39:50 +00001098
1099 default:
1100 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001101 }
1102 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001103
1104 if (!m_value_did_change && m_old_value_valid)
1105 {
1106 // The value was gotten successfully, so we consider the
1107 // value as changed if the value string differs
1108 SetValueDidChange (m_old_value_str != m_value_str);
1109 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001110 }
1111 }
1112 if (m_value_str.empty())
1113 return NULL;
1114 return m_value_str.c_str();
1115}
1116
Enrico Granatac3e320a2011-08-02 17:27:39 +00001117// if > 8bytes, 0 is returned. this method should mostly be used
1118// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001119uint64_t
1120ValueObject::GetValueAsUnsigned (uint64_t fail_value)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001121{
1122 // If our byte size is zero this is an aggregate type that has children
1123 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1124 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001125 Scalar scalar;
1126 if (ResolveValue (scalar))
1127 return scalar.GetRawBits64(fail_value);
Enrico Granatac3e320a2011-08-02 17:27:39 +00001128 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001129 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001130}
1131
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001132bool
1133ValueObject::GetPrintableRepresentation(Stream& s,
1134 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001135 Format custom_format)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001136{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001137
Greg Claytonafacd142011-09-02 01:15:17 +00001138 if (custom_format != eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001139 SetFormat(custom_format);
1140
1141 const char * return_value;
Enrico Granatacd1c0232011-08-04 23:37:18 +00001142 std::string alloc_mem;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001143
1144 switch(val_obj_display)
1145 {
1146 case eDisplayValue:
1147 return_value = GetValueAsCString();
1148 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001149
Enrico Granata0a3958e2011-07-02 00:25:22 +00001150 case eDisplaySummary:
Greg Clayton48ca8b82012-01-07 20:58:07 +00001151 return_value = GetSummaryAsCString();
1152 break;
1153
Enrico Granata0a3958e2011-07-02 00:25:22 +00001154 case eDisplayLanguageSpecific:
1155 return_value = GetObjectDescription();
1156 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001157
Enrico Granataf2bbf712011-07-15 02:26:42 +00001158 case eDisplayLocation:
1159 return_value = GetLocationAsCString();
1160 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001161
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001162 case eDisplayChildrenCount:
Greg Clayton48ca8b82012-01-07 20:58:07 +00001163 {
1164 alloc_mem.resize(512);
1165 return_value = &alloc_mem[0];
1166 int count = GetNumChildren();
1167 snprintf((char*)return_value, 512, "%d", count);
1168 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001169 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001170
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001171 case eDisplayType:
1172 return_value = GetTypeName().AsCString();
1173 break;
Greg Clayton48ca8b82012-01-07 20:58:07 +00001174
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001175 default:
1176 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001177 }
1178
Enrico Granata855cd902011-09-06 22:59:55 +00001179 if (!return_value)
Enrico Granata9fc19442011-07-06 02:13:41 +00001180 {
Enrico Granata9fc19442011-07-06 02:13:41 +00001181 if (val_obj_display == eDisplayValue)
Enrico Granata855cd902011-09-06 22:59:55 +00001182 return_value = GetSummaryAsCString();
Enrico Granata9fc19442011-07-06 02:13:41 +00001183 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +00001184 {
1185 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1186 {
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001187 // this thing has no value, and it seems to have no summary
1188 // some combination of unitialized data and other factors can also
Enrico Granata855cd902011-09-06 22:59:55 +00001189 // raise this condition, so let's print a nice generic description
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001190 {
1191 alloc_mem.resize(684);
1192 return_value = &alloc_mem[0];
1193 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1194 }
Enrico Granatae992a082011-07-22 17:03:19 +00001195 }
1196 else
1197 return_value = GetValueAsCString();
1198 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001199 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001200
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001201 if (return_value)
1202 s.PutCString(return_value);
1203 else
Enrico Granata88da35f2011-08-23 21:26:09 +00001204 {
1205 if (m_error.Fail())
1206 s.Printf("<%s>", m_error.AsCString());
1207 else if (val_obj_display == eDisplaySummary)
1208 s.PutCString("<no summary available>");
1209 else if (val_obj_display == eDisplayValue)
1210 s.PutCString("<no value available>");
1211 else if (val_obj_display == eDisplayLanguageSpecific)
1212 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1213 else
1214 s.PutCString("<no printable representation>");
1215 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001216
1217 // we should only return false here if we could not do *anything*
1218 // even if we have an error message as output, that's a success
1219 // from our callers' perspective, so return true
1220 return true;
1221
Enrico Granata0a3958e2011-07-02 00:25:22 +00001222}
1223
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001224// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1225// this call up to date by returning true for your new special cases. We will eventually move
1226// to checking this call result before trying to display special cases
1227bool
1228ValueObject::HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001229 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001230{
1231 clang_type_t elem_or_pointee_type;
1232 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1233
1234 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1235 && val_obj_display == ValueObject::eDisplayValue)
1236 {
1237 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001238 (custom_format == eFormatCString ||
1239 custom_format == eFormatCharArray ||
1240 custom_format == eFormatChar ||
1241 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001242 return true;
1243
1244 if (flags.Test(ClangASTContext::eTypeIsArray))
1245 {
Greg Claytonafacd142011-09-02 01:15:17 +00001246 if ((custom_format == eFormatBytes) ||
1247 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001248 return true;
1249
Greg Claytonafacd142011-09-02 01:15:17 +00001250 if ((custom_format == eFormatVectorOfChar) ||
1251 (custom_format == eFormatVectorOfFloat32) ||
1252 (custom_format == eFormatVectorOfFloat64) ||
1253 (custom_format == eFormatVectorOfSInt16) ||
1254 (custom_format == eFormatVectorOfSInt32) ||
1255 (custom_format == eFormatVectorOfSInt64) ||
1256 (custom_format == eFormatVectorOfSInt8) ||
1257 (custom_format == eFormatVectorOfUInt128) ||
1258 (custom_format == eFormatVectorOfUInt16) ||
1259 (custom_format == eFormatVectorOfUInt32) ||
1260 (custom_format == eFormatVectorOfUInt64) ||
1261 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001262 return true;
1263 }
1264 }
1265 return false;
1266}
1267
Enrico Granata9fc19442011-07-06 02:13:41 +00001268bool
1269ValueObject::DumpPrintableRepresentation(Stream& s,
1270 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001271 Format custom_format,
Enrico Granata85933ed2011-08-18 16:38:26 +00001272 bool only_special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001273{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001274
1275 clang_type_t elem_or_pointee_type;
1276 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001277
Enrico Granataf4efecd2011-07-12 22:56:10 +00001278 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1279 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001280 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001281 // when being asked to get a printable display an array or pointer type directly,
1282 // try to "do the right thing"
1283
1284 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001285 (custom_format == eFormatCString ||
1286 custom_format == eFormatCharArray ||
1287 custom_format == eFormatChar ||
1288 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001289 {
1290 Error error;
1291 ReadPointedString(s,
1292 error,
1293 0,
Greg Claytonafacd142011-09-02 01:15:17 +00001294 (custom_format == eFormatVectorOfChar) ||
1295 (custom_format == eFormatCharArray));
Enrico Granataf4efecd2011-07-12 22:56:10 +00001296 return !error.Fail();
1297 }
1298
Greg Claytonafacd142011-09-02 01:15:17 +00001299 if (custom_format == eFormatEnum)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001300 return false;
1301
1302 // this only works for arrays, because I have no way to know when
1303 // the pointed memory ends, and no special \0 end of data marker
1304 if (flags.Test(ClangASTContext::eTypeIsArray))
1305 {
Greg Claytonafacd142011-09-02 01:15:17 +00001306 if ((custom_format == eFormatBytes) ||
1307 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001308 {
1309 uint32_t count = GetNumChildren();
1310
1311 s << '[';
1312 for (uint32_t low = 0; low < count; low++)
1313 {
1314
1315 if (low)
1316 s << ',';
1317
1318 ValueObjectSP child = GetChildAtIndex(low,true);
1319 if (!child.get())
1320 {
Enrico Granatae992a082011-07-22 17:03:19 +00001321 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001322 continue;
1323 }
1324 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1325 }
1326
1327 s << ']';
1328
1329 return true;
1330 }
1331
Greg Claytonafacd142011-09-02 01:15:17 +00001332 if ((custom_format == eFormatVectorOfChar) ||
1333 (custom_format == eFormatVectorOfFloat32) ||
1334 (custom_format == eFormatVectorOfFloat64) ||
1335 (custom_format == eFormatVectorOfSInt16) ||
1336 (custom_format == eFormatVectorOfSInt32) ||
1337 (custom_format == eFormatVectorOfSInt64) ||
1338 (custom_format == eFormatVectorOfSInt8) ||
1339 (custom_format == eFormatVectorOfUInt128) ||
1340 (custom_format == eFormatVectorOfUInt16) ||
1341 (custom_format == eFormatVectorOfUInt32) ||
1342 (custom_format == eFormatVectorOfUInt64) ||
1343 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001344 {
1345 uint32_t count = GetNumChildren();
1346
Greg Claytonafacd142011-09-02 01:15:17 +00001347 Format format = FormatManager::GetSingleItemFormat(custom_format);
Enrico Granataf4efecd2011-07-12 22:56:10 +00001348
1349 s << '[';
1350 for (uint32_t low = 0; low < count; low++)
1351 {
1352
1353 if (low)
1354 s << ',';
1355
1356 ValueObjectSP child = GetChildAtIndex(low,true);
1357 if (!child.get())
1358 {
Enrico Granatae992a082011-07-22 17:03:19 +00001359 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001360 continue;
1361 }
1362 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1363 }
1364
1365 s << ']';
1366
1367 return true;
1368 }
1369 }
1370
Greg Claytonafacd142011-09-02 01:15:17 +00001371 if ((custom_format == eFormatBoolean) ||
1372 (custom_format == eFormatBinary) ||
1373 (custom_format == eFormatChar) ||
1374 (custom_format == eFormatCharPrintable) ||
1375 (custom_format == eFormatComplexFloat) ||
1376 (custom_format == eFormatDecimal) ||
1377 (custom_format == eFormatHex) ||
1378 (custom_format == eFormatFloat) ||
1379 (custom_format == eFormatOctal) ||
1380 (custom_format == eFormatOSType) ||
1381 (custom_format == eFormatUnicode16) ||
1382 (custom_format == eFormatUnicode32) ||
1383 (custom_format == eFormatUnsigned) ||
1384 (custom_format == eFormatPointer) ||
1385 (custom_format == eFormatComplexInteger) ||
1386 (custom_format == eFormatComplex) ||
1387 (custom_format == eFormatDefault)) // use the [] operator
Enrico Granataf4efecd2011-07-12 22:56:10 +00001388 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001389 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001390
1391 if (only_special)
1392 return false;
1393
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001394 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001395 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001396 SetFormat(eFormatDefault);
1397 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001398}
1399
Greg Clayton737b9322010-09-13 03:32:57 +00001400addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001401ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001402{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001403 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001404 return LLDB_INVALID_ADDRESS;
1405
Greg Clayton73b472d2010-10-27 03:32:59 +00001406 switch (m_value.GetValueType())
1407 {
1408 case Value::eValueTypeScalar:
1409 if (scalar_is_load_address)
1410 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001411 if(address_type)
1412 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001413 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1414 }
1415 break;
1416
1417 case Value::eValueTypeLoadAddress:
1418 case Value::eValueTypeFileAddress:
1419 case Value::eValueTypeHostAddress:
1420 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001421 if(address_type)
1422 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001423 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1424 }
1425 break;
1426 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001427 if (address_type)
1428 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001429 return LLDB_INVALID_ADDRESS;
1430}
1431
1432addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001433ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001434{
Greg Claytonafacd142011-09-02 01:15:17 +00001435 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001436 if(address_type)
1437 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001438
Enrico Granatac3e320a2011-08-02 17:27:39 +00001439 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001440 return address;
1441
Greg Clayton73b472d2010-10-27 03:32:59 +00001442 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001443 {
1444 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001445 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001446 break;
1447
Enrico Granata9128ee22011-09-06 19:20:51 +00001448 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001449 case Value::eValueTypeLoadAddress:
1450 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001451 {
1452 uint32_t data_offset = 0;
1453 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001454 }
1455 break;
1456 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001457
Enrico Granata9128ee22011-09-06 19:20:51 +00001458 if (address_type)
1459 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001460
Greg Clayton737b9322010-09-13 03:32:57 +00001461 return address;
1462}
1463
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001464bool
Jim Ingham6035b672011-03-31 00:19:25 +00001465ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001466{
1467 // Make sure our value is up to date first so that our location and location
1468 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001469 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001470 return false;
1471
1472 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001473 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001474
Greg Claytonb1320972010-07-14 00:18:15 +00001475 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001476
Jim Ingham16e0c682011-08-12 23:34:31 +00001477 Value::ValueType value_type = m_value.GetValueType();
1478
1479 if (value_type == Value::eValueTypeScalar)
1480 {
1481 // If the value is already a scalar, then let the scalar change itself:
1482 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1483 }
1484 else if (byte_size <= Scalar::GetMaxByteSize())
1485 {
1486 // If the value fits in a scalar, then make a new scalar and again let the
1487 // scalar code do the conversion, then figure out where to put the new value.
1488 Scalar new_scalar;
1489 Error error;
1490 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1491 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001492 {
Jim Ingham4b536182011-08-09 02:12:22 +00001493 switch (value_type)
1494 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001495 case Value::eValueTypeLoadAddress:
1496 {
1497 // If it is a load address, then the scalar value is the storage location
1498 // of the data, and we have to shove this value down to that load location.
1499 ProcessSP process_sp = GetUpdatePoint().GetProcessSP();
1500 if (process_sp)
1501 {
Greg Claytonafacd142011-09-02 01:15:17 +00001502 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Jim Ingham16e0c682011-08-12 23:34:31 +00001503 size_t bytes_written = process_sp->WriteScalarToMemory (target_addr,
1504 new_scalar,
1505 byte_size,
1506 error);
1507 if (!error.Success() || bytes_written != byte_size)
1508 return false;
1509 }
1510 }
Jim Ingham4b536182011-08-09 02:12:22 +00001511 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001512 case Value::eValueTypeHostAddress:
1513 {
1514 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1515 DataExtractor new_data;
1516 new_data.SetByteOrder (m_data.GetByteOrder());
1517
1518 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1519 m_data.SetData(buffer_sp, 0);
1520 bool success = new_scalar.GetData(new_data);
1521 if (success)
1522 {
1523 new_data.CopyByteOrderedData(0,
1524 byte_size,
1525 const_cast<uint8_t *>(m_data.GetDataStart()),
1526 byte_size,
1527 m_data.GetByteOrder());
1528 }
1529 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1530
1531 }
Jim Ingham4b536182011-08-09 02:12:22 +00001532 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001533 case Value::eValueTypeFileAddress:
1534 case Value::eValueTypeScalar:
1535 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001536 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001537 }
1538 else
1539 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001540 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001541 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001542 }
1543 else
1544 {
1545 // We don't support setting things bigger than a scalar at present.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001546 return false;
1547 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001548
1549 // If we have reached this point, then we have successfully changed the value.
1550 SetNeedsUpdate();
1551 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001552}
1553
Greg Claytonafacd142011-09-02 01:15:17 +00001554LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001555ValueObject::GetObjectRuntimeLanguage ()
1556{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001557 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1558 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001559}
1560
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001561void
Jim Ingham58b59f92011-04-22 23:53:53 +00001562ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001563{
Jim Ingham58b59f92011-04-22 23:53:53 +00001564 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001565}
1566
1567ValueObjectSP
1568ValueObject::GetSyntheticChild (const ConstString &key) const
1569{
1570 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001571 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001572 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001573 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001574 return synthetic_child_sp;
1575}
1576
1577bool
1578ValueObject::IsPointerType ()
1579{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001580 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001581}
1582
Jim Inghamb7603bb2011-03-18 00:05:18 +00001583bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001584ValueObject::IsArrayType ()
1585{
1586 return ClangASTContext::IsArrayType (GetClangType());
1587}
1588
1589bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001590ValueObject::IsScalarType ()
1591{
1592 return ClangASTContext::IsScalarType (GetClangType());
1593}
1594
1595bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001596ValueObject::IsIntegerType (bool &is_signed)
1597{
1598 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1599}
Greg Clayton73b472d2010-10-27 03:32:59 +00001600
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001601bool
1602ValueObject::IsPointerOrReferenceType ()
1603{
Greg Clayton007d5be2011-05-30 00:49:24 +00001604 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1605}
1606
1607bool
1608ValueObject::IsPossibleCPlusPlusDynamicType ()
1609{
1610 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001611}
1612
Greg Claytondea8cb42011-06-29 22:09:02 +00001613bool
1614ValueObject::IsPossibleDynamicType ()
1615{
1616 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1617}
1618
Greg Claytonafacd142011-09-02 01:15:17 +00001619ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001620ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1621{
1622 if (IsArrayType())
1623 return GetSyntheticArrayMemberFromArray(index, can_create);
1624
1625 if (IsPointerType())
1626 return GetSyntheticArrayMemberFromPointer(index, can_create);
1627
1628 return ValueObjectSP();
1629
1630}
1631
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001632ValueObjectSP
1633ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1634{
1635 ValueObjectSP synthetic_child_sp;
1636 if (IsPointerType ())
1637 {
1638 char index_str[64];
1639 snprintf(index_str, sizeof(index_str), "[%i]", index);
1640 ConstString index_const_str(index_str);
1641 // Check if we have already created a synthetic array member in this
1642 // valid object. If we have we will re-use it.
1643 synthetic_child_sp = GetSyntheticChild (index_const_str);
1644 if (!synthetic_child_sp)
1645 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001646 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001647 // We haven't made a synthetic array member for INDEX yet, so
1648 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001649 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001650
1651 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001652 if (synthetic_child)
1653 {
1654 AddSyntheticChild(index_const_str, synthetic_child);
1655 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001656 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001657 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001658 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001659 }
1660 }
1661 return synthetic_child_sp;
1662}
Jim Ingham22777012010-09-23 02:01:19 +00001663
Greg Claytondaf515f2011-07-09 20:12:33 +00001664// This allows you to create an array member using and index
1665// that doesn't not fall in the normal bounds of the array.
1666// Many times structure can be defined as:
1667// struct Collection
1668// {
1669// uint32_t item_count;
1670// Item item_array[0];
1671// };
1672// The size of the "item_array" is 1, but many times in practice
1673// there are more items in "item_array".
1674
1675ValueObjectSP
1676ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1677{
1678 ValueObjectSP synthetic_child_sp;
1679 if (IsArrayType ())
1680 {
1681 char index_str[64];
1682 snprintf(index_str, sizeof(index_str), "[%i]", index);
1683 ConstString index_const_str(index_str);
1684 // Check if we have already created a synthetic array member in this
1685 // valid object. If we have we will re-use it.
1686 synthetic_child_sp = GetSyntheticChild (index_const_str);
1687 if (!synthetic_child_sp)
1688 {
1689 ValueObject *synthetic_child;
1690 // We haven't made a synthetic array member for INDEX yet, so
1691 // lets make one and cache it for any future reference.
1692 synthetic_child = CreateChildAtIndex(0, true, index);
1693
1694 // Cache the value if we got one back...
1695 if (synthetic_child)
1696 {
1697 AddSyntheticChild(index_const_str, synthetic_child);
1698 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001699 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001700 synthetic_child_sp->m_is_array_item_for_pointer = true;
1701 }
1702 }
1703 }
1704 return synthetic_child_sp;
1705}
1706
Enrico Granata9fc19442011-07-06 02:13:41 +00001707ValueObjectSP
1708ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1709{
1710 ValueObjectSP synthetic_child_sp;
1711 if (IsScalarType ())
1712 {
1713 char index_str[64];
1714 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1715 ConstString index_const_str(index_str);
1716 // Check if we have already created a synthetic array member in this
1717 // valid object. If we have we will re-use it.
1718 synthetic_child_sp = GetSyntheticChild (index_const_str);
1719 if (!synthetic_child_sp)
1720 {
1721 ValueObjectChild *synthetic_child;
1722 // We haven't made a synthetic array member for INDEX yet, so
1723 // lets make one and cache it for any future reference.
1724 synthetic_child = new ValueObjectChild(*this,
1725 GetClangAST(),
1726 GetClangType(),
1727 index_const_str,
1728 GetByteSize(),
1729 0,
1730 to-from+1,
1731 from,
1732 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001733 false,
1734 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001735
1736 // Cache the value if we got one back...
1737 if (synthetic_child)
1738 {
1739 AddSyntheticChild(index_const_str, synthetic_child);
1740 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001741 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001742 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1743 }
1744 }
1745 }
1746 return synthetic_child_sp;
1747}
1748
Greg Claytonafacd142011-09-02 01:15:17 +00001749ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001750ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1751{
1752 ValueObjectSP synthetic_child_sp;
1753 if (IsArrayType () || IsPointerType ())
1754 {
1755 char index_str[64];
1756 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1757 ConstString index_const_str(index_str);
1758 // Check if we have already created a synthetic array member in this
1759 // valid object. If we have we will re-use it.
1760 synthetic_child_sp = GetSyntheticChild (index_const_str);
1761 if (!synthetic_child_sp)
1762 {
1763 ValueObjectSynthetic *synthetic_child;
1764
1765 // We haven't made a synthetic array member for INDEX yet, so
1766 // lets make one and cache it for any future reference.
1767 SyntheticArrayView *view = new SyntheticArrayView();
1768 view->AddRange(from,to);
1769 SyntheticChildrenSP view_sp(view);
1770 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1771
1772 // Cache the value if we got one back...
1773 if (synthetic_child)
1774 {
1775 AddSyntheticChild(index_const_str, synthetic_child);
1776 synthetic_child_sp = synthetic_child->GetSP();
1777 synthetic_child_sp->SetName(ConstString(index_str));
1778 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1779 }
1780 }
1781 }
1782 return synthetic_child_sp;
1783}
1784
Greg Claytonafacd142011-09-02 01:15:17 +00001785ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001786ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1787{
1788
1789 ValueObjectSP synthetic_child_sp;
1790
1791 char name_str[64];
1792 snprintf(name_str, sizeof(name_str), "@%i", offset);
1793 ConstString name_const_str(name_str);
1794
1795 // Check if we have already created a synthetic array member in this
1796 // valid object. If we have we will re-use it.
1797 synthetic_child_sp = GetSyntheticChild (name_const_str);
1798
1799 if (synthetic_child_sp.get())
1800 return synthetic_child_sp;
1801
1802 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001803 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001804
1805 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1806 type.GetASTContext(),
1807 type.GetOpaqueQualType(),
1808 name_const_str,
1809 type.GetTypeByteSize(),
1810 offset,
1811 0,
1812 0,
1813 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001814 false,
1815 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001816 if (synthetic_child)
1817 {
1818 AddSyntheticChild(name_const_str, synthetic_child);
1819 synthetic_child_sp = synthetic_child->GetSP();
1820 synthetic_child_sp->SetName(name_const_str);
1821 synthetic_child_sp->m_is_child_at_offset = true;
1822 }
1823 return synthetic_child_sp;
1824}
1825
Enrico Granatad55546b2011-07-22 00:16:08 +00001826// your expression path needs to have a leading . or ->
1827// (unless it somehow "looks like" an array, in which case it has
1828// a leading [ symbol). while the [ is meaningful and should be shown
1829// to the user, . and -> are just parser design, but by no means
1830// added information for the user.. strip them off
1831static const char*
1832SkipLeadingExpressionPathSeparators(const char* expression)
1833{
1834 if (!expression || !expression[0])
1835 return expression;
1836 if (expression[0] == '.')
1837 return expression+1;
1838 if (expression[0] == '-' && expression[1] == '>')
1839 return expression+2;
1840 return expression;
1841}
1842
Greg Claytonafacd142011-09-02 01:15:17 +00001843ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00001844ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1845{
1846 ValueObjectSP synthetic_child_sp;
1847 ConstString name_const_string(expression);
1848 // Check if we have already created a synthetic array member in this
1849 // valid object. If we have we will re-use it.
1850 synthetic_child_sp = GetSyntheticChild (name_const_string);
1851 if (!synthetic_child_sp)
1852 {
1853 // We haven't made a synthetic array member for expression yet, so
1854 // lets make one and cache it for any future reference.
1855 synthetic_child_sp = GetValueForExpressionPath(expression);
1856
1857 // Cache the value if we got one back...
1858 if (synthetic_child_sp.get())
1859 {
1860 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001861 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001862 synthetic_child_sp->m_is_expression_path_child = true;
1863 }
1864 }
1865 return synthetic_child_sp;
1866}
1867
1868void
Greg Claytonafacd142011-09-02 01:15:17 +00001869ValueObject::CalculateSyntheticValue (SyntheticValueType use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00001870{
Greg Claytonafacd142011-09-02 01:15:17 +00001871 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001872 return;
1873
Enrico Granatac3e320a2011-08-02 17:27:39 +00001874 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001875
1876 if (m_last_synthetic_filter.get() == NULL)
1877 return;
1878
Enrico Granataa37a0652011-07-24 00:14:56 +00001879 if (m_synthetic_value == NULL)
1880 m_synthetic_value = new ValueObjectSynthetic(*this, m_last_synthetic_filter);
Enrico Granatad55546b2011-07-22 00:16:08 +00001881
1882}
1883
Jim Ingham78a685a2011-04-16 00:01:13 +00001884void
Greg Claytonafacd142011-09-02 01:15:17 +00001885ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00001886{
Greg Claytonafacd142011-09-02 01:15:17 +00001887 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00001888 return;
1889
Jim Ingham58b59f92011-04-22 23:53:53 +00001890 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00001891 {
Enrico Granata6f3533f2011-07-29 19:53:35 +00001892 Process *process = m_update_point.GetProcessSP().get();
Jim Ingham78a685a2011-04-16 00:01:13 +00001893 bool worth_having_dynamic_value = false;
Jim Ingham22777012010-09-23 02:01:19 +00001894
Jim Ingham78a685a2011-04-16 00:01:13 +00001895
1896 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
1897 // hard code this everywhere.
Greg Claytonafacd142011-09-02 01:15:17 +00001898 LanguageType known_type = GetObjectRuntimeLanguage();
1899 if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
Jim Ingham78a685a2011-04-16 00:01:13 +00001900 {
1901 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
1902 if (runtime)
1903 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
1904 }
1905 else
1906 {
Greg Claytonafacd142011-09-02 01:15:17 +00001907 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus);
Jim Ingham78a685a2011-04-16 00:01:13 +00001908 if (cpp_runtime)
1909 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
1910
1911 if (!worth_having_dynamic_value)
1912 {
Greg Claytonafacd142011-09-02 01:15:17 +00001913 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC);
Jim Ingham78a685a2011-04-16 00:01:13 +00001914 if (objc_runtime)
Jim Ingham2837b762011-05-04 03:43:18 +00001915 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00001916 }
1917 }
1918
1919 if (worth_having_dynamic_value)
Jim Ingham2837b762011-05-04 03:43:18 +00001920 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham58b59f92011-04-22 23:53:53 +00001921
1922// if (worth_having_dynamic_value)
1923// printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager);
1924
Jim Ingham78a685a2011-04-16 00:01:13 +00001925 }
1926}
1927
Jim Ingham58b59f92011-04-22 23:53:53 +00001928ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00001929ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00001930{
Greg Claytonafacd142011-09-02 01:15:17 +00001931 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00001932 return ValueObjectSP();
1933
1934 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00001935 {
Jim Ingham2837b762011-05-04 03:43:18 +00001936 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001937 }
Jim Ingham58b59f92011-04-22 23:53:53 +00001938 if (m_dynamic_value)
1939 return m_dynamic_value->GetSP();
1940 else
1941 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00001942}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001943
Jim Ingham60dbabb2011-12-08 19:44:08 +00001944ValueObjectSP
1945ValueObject::GetStaticValue()
1946{
1947 return GetSP();
1948}
1949
Enrico Granatad55546b2011-07-22 00:16:08 +00001950// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
1951// or we do not really want a dynamic VO. this method instead returns this object
1952// itself when making it synthetic has no meaning. this makes it much simpler
1953// to replace the SyntheticValue for the ValueObject
1954ValueObjectSP
1955ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
1956{
Greg Claytonafacd142011-09-02 01:15:17 +00001957 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001958 return GetSP();
1959
Enrico Granatac3e320a2011-08-02 17:27:39 +00001960 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001961
1962 if (m_last_synthetic_filter.get() == NULL)
1963 return GetSP();
1964
1965 CalculateSyntheticValue(use_synthetic);
1966
1967 if (m_synthetic_value)
1968 return m_synthetic_value->GetSP();
1969 else
1970 return GetSP();
1971}
1972
Greg Claytone221f822011-01-21 01:59:00 +00001973bool
Enrico Granata27b625e2011-08-09 01:04:56 +00001974ValueObject::HasSyntheticValue()
1975{
1976 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
1977
1978 if (m_last_synthetic_filter.get() == NULL)
1979 return false;
1980
Greg Claytonafacd142011-09-02 01:15:17 +00001981 CalculateSyntheticValue(eUseSyntheticFilter);
Enrico Granata27b625e2011-08-09 01:04:56 +00001982
1983 if (m_synthetic_value)
1984 return true;
1985 else
1986 return false;
1987}
1988
1989bool
Greg Claytone221f822011-01-21 01:59:00 +00001990ValueObject::GetBaseClassPath (Stream &s)
1991{
1992 if (IsBaseClass())
1993 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001994 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00001995 clang_type_t clang_type = GetClangType();
1996 std::string cxx_class_name;
1997 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
1998 if (this_had_base_class)
1999 {
2000 if (parent_had_base_class)
2001 s.PutCString("::");
2002 s.PutCString(cxx_class_name.c_str());
2003 }
2004 return parent_had_base_class || this_had_base_class;
2005 }
2006 return false;
2007}
2008
2009
2010ValueObject *
2011ValueObject::GetNonBaseClassParent()
2012{
Jim Ingham78a685a2011-04-16 00:01:13 +00002013 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002014 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002015 if (GetParent()->IsBaseClass())
2016 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002017 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002018 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002019 }
2020 return NULL;
2021}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002022
2023void
Enrico Granata4becb372011-06-29 22:27:15 +00002024ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002025{
Greg Claytone221f822011-01-21 01:59:00 +00002026 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002027
Enrico Granata85933ed2011-08-18 16:38:26 +00002028 if (is_deref_of_parent && epformat == eDereferencePointers)
2029 {
Enrico Granata4becb372011-06-29 22:27:15 +00002030 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2031 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2032 // the eHonorPointers mode is meant to produce strings in this latter format
2033 s.PutCString("*(");
2034 }
Greg Claytone221f822011-01-21 01:59:00 +00002035
Enrico Granata4becb372011-06-29 22:27:15 +00002036 ValueObject* parent = GetParent();
2037
2038 if (parent)
2039 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002040
2041 // if we are a deref_of_parent just because we are synthetic array
2042 // members made up to allow ptr[%d] syntax to work in variable
2043 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00002044 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002045 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002046
Greg Claytone221f822011-01-21 01:59:00 +00002047 if (!IsBaseClass())
2048 {
2049 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002050 {
Greg Claytone221f822011-01-21 01:59:00 +00002051 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2052 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002053 {
Greg Claytone221f822011-01-21 01:59:00 +00002054 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2055 if (non_base_class_parent_clang_type)
2056 {
2057 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2058
Enrico Granata9dd75c82011-07-15 23:30:15 +00002059 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002060 {
2061 s.PutCString("->");
2062 }
Enrico Granata4becb372011-06-29 22:27:15 +00002063 else
2064 {
2065 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2066 {
2067 s.PutCString("->");
2068 }
2069 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2070 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2071 {
2072 s.PutChar('.');
2073 }
Greg Claytone221f822011-01-21 01:59:00 +00002074 }
2075 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002076 }
Greg Claytone221f822011-01-21 01:59:00 +00002077
2078 const char *name = GetName().GetCString();
2079 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002080 {
Greg Claytone221f822011-01-21 01:59:00 +00002081 if (qualify_cxx_base_classes)
2082 {
2083 if (GetBaseClassPath (s))
2084 s.PutCString("::");
2085 }
2086 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002087 }
2088 }
2089 }
2090
Enrico Granata85933ed2011-08-18 16:38:26 +00002091 if (is_deref_of_parent && epformat == eDereferencePointers)
2092 {
Greg Claytone221f822011-01-21 01:59:00 +00002093 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002094 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002095}
2096
Greg Claytonafacd142011-09-02 01:15:17 +00002097ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002098ValueObject::GetValueForExpressionPath(const char* expression,
2099 const char** first_unparsed,
2100 ExpressionPathScanEndReason* reason_to_stop,
2101 ExpressionPathEndResultType* final_value_type,
2102 const GetValueForExpressionPathOptions& options,
2103 ExpressionPathAftermath* final_task_on_target)
2104{
2105
2106 const char* dummy_first_unparsed;
2107 ExpressionPathScanEndReason dummy_reason_to_stop;
2108 ExpressionPathEndResultType dummy_final_value_type;
2109 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2110
2111 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2112 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2113 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2114 final_value_type ? final_value_type : &dummy_final_value_type,
2115 options,
2116 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2117
2118 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2119 {
2120 return ret_val;
2121 }
2122 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2123 {
2124 if (*final_task_on_target == ValueObject::eDereference)
2125 {
2126 Error error;
2127 ValueObjectSP final_value = ret_val->Dereference(error);
2128 if (error.Fail() || !final_value.get())
2129 {
2130 *reason_to_stop = ValueObject::eDereferencingFailed;
2131 *final_value_type = ValueObject::eInvalid;
2132 return ValueObjectSP();
2133 }
2134 else
2135 {
2136 *final_task_on_target = ValueObject::eNothing;
2137 return final_value;
2138 }
2139 }
2140 if (*final_task_on_target == ValueObject::eTakeAddress)
2141 {
2142 Error error;
2143 ValueObjectSP final_value = ret_val->AddressOf(error);
2144 if (error.Fail() || !final_value.get())
2145 {
2146 *reason_to_stop = ValueObject::eTakingAddressFailed;
2147 *final_value_type = ValueObject::eInvalid;
2148 return ValueObjectSP();
2149 }
2150 else
2151 {
2152 *final_task_on_target = ValueObject::eNothing;
2153 return final_value;
2154 }
2155 }
2156 }
2157 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2158}
2159
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002160int
2161ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002162 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002163 const char** first_unparsed,
2164 ExpressionPathScanEndReason* reason_to_stop,
2165 ExpressionPathEndResultType* final_value_type,
2166 const GetValueForExpressionPathOptions& options,
2167 ExpressionPathAftermath* final_task_on_target)
2168{
2169 const char* dummy_first_unparsed;
2170 ExpressionPathScanEndReason dummy_reason_to_stop;
2171 ExpressionPathEndResultType dummy_final_value_type;
2172 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2173
2174 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2175 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2176 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2177 final_value_type ? final_value_type : &dummy_final_value_type,
2178 options,
2179 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2180
2181 if (!ret_val.get()) // if there are errors, I add nothing to the list
2182 return 0;
2183
2184 if (*reason_to_stop != eArrayRangeOperatorMet)
2185 {
2186 // I need not expand a range, just post-process the final value and return
2187 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2188 {
2189 list->Append(ret_val);
2190 return 1;
2191 }
2192 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2193 {
2194 if (*final_task_on_target == ValueObject::eDereference)
2195 {
2196 Error error;
2197 ValueObjectSP final_value = ret_val->Dereference(error);
2198 if (error.Fail() || !final_value.get())
2199 {
2200 *reason_to_stop = ValueObject::eDereferencingFailed;
2201 *final_value_type = ValueObject::eInvalid;
2202 return 0;
2203 }
2204 else
2205 {
2206 *final_task_on_target = ValueObject::eNothing;
2207 list->Append(final_value);
2208 return 1;
2209 }
2210 }
2211 if (*final_task_on_target == ValueObject::eTakeAddress)
2212 {
2213 Error error;
2214 ValueObjectSP final_value = ret_val->AddressOf(error);
2215 if (error.Fail() || !final_value.get())
2216 {
2217 *reason_to_stop = ValueObject::eTakingAddressFailed;
2218 *final_value_type = ValueObject::eInvalid;
2219 return 0;
2220 }
2221 else
2222 {
2223 *final_task_on_target = ValueObject::eNothing;
2224 list->Append(final_value);
2225 return 1;
2226 }
2227 }
2228 }
2229 }
2230 else
2231 {
2232 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2233 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2234 ret_val,
2235 list,
2236 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2237 final_value_type ? final_value_type : &dummy_final_value_type,
2238 options,
2239 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2240 }
2241 // in any non-covered case, just do the obviously right thing
2242 list->Append(ret_val);
2243 return 1;
2244}
2245
Greg Claytonafacd142011-09-02 01:15:17 +00002246ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002247ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2248 const char** first_unparsed,
2249 ExpressionPathScanEndReason* reason_to_stop,
2250 ExpressionPathEndResultType* final_result,
2251 const GetValueForExpressionPathOptions& options,
2252 ExpressionPathAftermath* what_next)
2253{
2254 ValueObjectSP root = GetSP();
2255
2256 if (!root.get())
2257 return ValueObjectSP();
2258
2259 *first_unparsed = expression_cstr;
2260
2261 while (true)
2262 {
2263
2264 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2265
Greg Claytonafacd142011-09-02 01:15:17 +00002266 clang_type_t root_clang_type = root->GetClangType();
2267 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002268 Flags root_clang_type_info,pointee_clang_type_info;
2269
2270 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2271 if (pointee_clang_type)
2272 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002273
2274 if (!expression_cstr || *expression_cstr == '\0')
2275 {
2276 *reason_to_stop = ValueObject::eEndOfString;
2277 return root;
2278 }
2279
2280 switch (*expression_cstr)
2281 {
2282 case '-':
2283 {
2284 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002285 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 +00002286 {
2287 *first_unparsed = expression_cstr;
2288 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
2289 *final_result = ValueObject::eInvalid;
2290 return ValueObjectSP();
2291 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002292 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2293 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002294 options.m_no_fragile_ivar)
2295 {
2296 *first_unparsed = expression_cstr;
2297 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
2298 *final_result = ValueObject::eInvalid;
2299 return ValueObjectSP();
2300 }
2301 if (expression_cstr[1] != '>')
2302 {
2303 *first_unparsed = expression_cstr;
2304 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2305 *final_result = ValueObject::eInvalid;
2306 return ValueObjectSP();
2307 }
2308 expression_cstr++; // skip the -
2309 }
2310 case '.': // or fallthrough from ->
2311 {
2312 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002313 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 +00002314 {
2315 *first_unparsed = expression_cstr;
2316 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
2317 *final_result = ValueObject::eInvalid;
2318 return ValueObjectSP();
2319 }
2320 expression_cstr++; // skip .
2321 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2322 ConstString child_name;
2323 if (!next_separator) // if no other separator just expand this last layer
2324 {
2325 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002326 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2327
2328 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002329 {
2330 *first_unparsed = '\0';
2331 *reason_to_stop = ValueObject::eEndOfString;
2332 *final_result = ValueObject::ePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002333 return child_valobj_sp;
2334 }
2335 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2336 {
Greg Clayton4c3b8fb2011-12-02 22:48:25 +00002337 child_valobj_sp = root->GetSyntheticValue(eNoSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002338 }
2339
2340 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2341 // so we hit the "else" branch, and return an error
2342 if(child_valobj_sp.get()) // if it worked, just return
2343 {
2344 *first_unparsed = '\0';
2345 *reason_to_stop = ValueObject::eEndOfString;
2346 *final_result = ValueObject::ePlain;
2347 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002348 }
2349 else
2350 {
2351 *first_unparsed = expression_cstr;
2352 *reason_to_stop = ValueObject::eNoSuchChild;
2353 *final_result = ValueObject::eInvalid;
2354 return ValueObjectSP();
2355 }
2356 }
2357 else // other layers do expand
2358 {
2359 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002360 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2361 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002362 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002363 root = child_valobj_sp;
2364 *first_unparsed = next_separator;
2365 *final_result = ValueObject::ePlain;
2366 continue;
2367 }
2368 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2369 {
Greg Claytonafacd142011-09-02 01:15:17 +00002370 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002371 }
2372
2373 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2374 // so we hit the "else" branch, and return an error
2375 if(child_valobj_sp.get()) // if it worked, move on
2376 {
2377 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002378 *first_unparsed = next_separator;
2379 *final_result = ValueObject::ePlain;
2380 continue;
2381 }
2382 else
2383 {
2384 *first_unparsed = expression_cstr;
2385 *reason_to_stop = ValueObject::eNoSuchChild;
2386 *final_result = ValueObject::eInvalid;
2387 return ValueObjectSP();
2388 }
2389 }
2390 break;
2391 }
2392 case '[':
2393 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002394 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 +00002395 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002396 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002397 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002398 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2399 {
2400 *first_unparsed = expression_cstr;
2401 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2402 *final_result = ValueObject::eInvalid;
2403 return ValueObjectSP();
2404 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002405 }
2406 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2407 {
2408 *first_unparsed = expression_cstr;
2409 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2410 *final_result = ValueObject::eInvalid;
2411 return ValueObjectSP();
2412 }
2413 }
2414 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2415 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002416 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002417 {
2418 *first_unparsed = expression_cstr;
2419 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2420 *final_result = ValueObject::eInvalid;
2421 return ValueObjectSP();
2422 }
2423 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2424 {
2425 *first_unparsed = expression_cstr+2;
2426 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2427 *final_result = ValueObject::eUnboundedRange;
2428 return root;
2429 }
2430 }
2431 const char *separator_position = ::strchr(expression_cstr+1,'-');
2432 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2433 if (!close_bracket_position) // if there is no ], this is a syntax error
2434 {
2435 *first_unparsed = expression_cstr;
2436 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2437 *final_result = ValueObject::eInvalid;
2438 return ValueObjectSP();
2439 }
2440 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2441 {
2442 char *end = NULL;
2443 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2444 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2445 {
2446 *first_unparsed = expression_cstr;
2447 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2448 *final_result = ValueObject::eInvalid;
2449 return ValueObjectSP();
2450 }
2451 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2452 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002453 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002454 {
2455 *first_unparsed = expression_cstr+2;
2456 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2457 *final_result = ValueObject::eUnboundedRange;
2458 return root;
2459 }
2460 else
2461 {
2462 *first_unparsed = expression_cstr;
2463 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2464 *final_result = ValueObject::eInvalid;
2465 return ValueObjectSP();
2466 }
2467 }
2468 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002469 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002470 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002471 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2472 if (!child_valobj_sp)
2473 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002474 if (!child_valobj_sp)
Greg Claytonafacd142011-09-02 01:15:17 +00002475 if (root->HasSyntheticValue() && root->GetSyntheticValue(eUseSyntheticFilter)->GetNumChildren() > index)
2476 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002477 if (child_valobj_sp)
2478 {
2479 root = child_valobj_sp;
2480 *first_unparsed = end+1; // skip ]
2481 *final_result = ValueObject::ePlain;
2482 continue;
2483 }
2484 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002485 {
2486 *first_unparsed = expression_cstr;
2487 *reason_to_stop = ValueObject::eNoSuchChild;
2488 *final_result = ValueObject::eInvalid;
2489 return ValueObjectSP();
2490 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002491 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002492 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002493 {
2494 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 +00002495 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002496 {
2497 Error error;
2498 root = root->Dereference(error);
2499 if (error.Fail() || !root.get())
2500 {
2501 *first_unparsed = expression_cstr;
2502 *reason_to_stop = ValueObject::eDereferencingFailed;
2503 *final_result = ValueObject::eInvalid;
2504 return ValueObjectSP();
2505 }
2506 else
2507 {
2508 *what_next = eNothing;
2509 continue;
2510 }
2511 }
2512 else
2513 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002514 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Claytonafacd142011-09-02 01:15:17 +00002515 root->GetClangType()) == eLanguageTypeObjC
Enrico Granata27b625e2011-08-09 01:04:56 +00002516 &&
2517 ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2518 &&
2519 root->HasSyntheticValue()
2520 &&
2521 options.m_no_synthetic_children == false)
2522 {
Greg Claytonafacd142011-09-02 01:15:17 +00002523 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002524 }
2525 else
2526 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002527 if (!root.get())
2528 {
2529 *first_unparsed = expression_cstr;
2530 *reason_to_stop = ValueObject::eNoSuchChild;
2531 *final_result = ValueObject::eInvalid;
2532 return ValueObjectSP();
2533 }
2534 else
2535 {
2536 *first_unparsed = end+1; // skip ]
2537 *final_result = ValueObject::ePlain;
2538 continue;
2539 }
2540 }
2541 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002542 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002543 {
2544 root = root->GetSyntheticBitFieldChild(index, index, true);
2545 if (!root.get())
2546 {
2547 *first_unparsed = expression_cstr;
2548 *reason_to_stop = ValueObject::eNoSuchChild;
2549 *final_result = ValueObject::eInvalid;
2550 return ValueObjectSP();
2551 }
2552 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2553 {
2554 *first_unparsed = end+1; // skip ]
2555 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2556 *final_result = ValueObject::eBitfield;
2557 return root;
2558 }
2559 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002560 else if (root->HasSyntheticValue() && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002561 {
Greg Claytonafacd142011-09-02 01:15:17 +00002562 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002563 if (!root.get())
2564 {
2565 *first_unparsed = expression_cstr;
2566 *reason_to_stop = ValueObject::eNoSuchChild;
2567 *final_result = ValueObject::eInvalid;
2568 return ValueObjectSP();
2569 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002570 else
2571 {
2572 *first_unparsed = end+1; // skip ]
2573 *final_result = ValueObject::ePlain;
2574 continue;
2575 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002576 }
2577 else
2578 {
2579 *first_unparsed = expression_cstr;
2580 *reason_to_stop = ValueObject::eNoSuchChild;
2581 *final_result = ValueObject::eInvalid;
2582 return ValueObjectSP();
2583 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002584 }
2585 else // we have a low and a high index
2586 {
2587 char *end = NULL;
2588 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2589 if (!end || end != separator_position) // if something weird is in our way return an error
2590 {
2591 *first_unparsed = expression_cstr;
2592 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2593 *final_result = ValueObject::eInvalid;
2594 return ValueObjectSP();
2595 }
2596 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2597 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2598 {
2599 *first_unparsed = expression_cstr;
2600 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2601 *final_result = ValueObject::eInvalid;
2602 return ValueObjectSP();
2603 }
2604 if (index_lower > index_higher) // swap indices if required
2605 {
2606 unsigned long temp = index_lower;
2607 index_lower = index_higher;
2608 index_higher = temp;
2609 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002610 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002611 {
2612 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2613 if (!root.get())
2614 {
2615 *first_unparsed = expression_cstr;
2616 *reason_to_stop = ValueObject::eNoSuchChild;
2617 *final_result = ValueObject::eInvalid;
2618 return ValueObjectSP();
2619 }
2620 else
2621 {
2622 *first_unparsed = end+1; // skip ]
2623 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2624 *final_result = ValueObject::eBitfield;
2625 return root;
2626 }
2627 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002628 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 +00002629 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002630 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002631 {
2632 Error error;
2633 root = root->Dereference(error);
2634 if (error.Fail() || !root.get())
2635 {
2636 *first_unparsed = expression_cstr;
2637 *reason_to_stop = ValueObject::eDereferencingFailed;
2638 *final_result = ValueObject::eInvalid;
2639 return ValueObjectSP();
2640 }
2641 else
2642 {
2643 *what_next = ValueObject::eNothing;
2644 continue;
2645 }
2646 }
2647 else
2648 {
2649 *first_unparsed = expression_cstr;
2650 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2651 *final_result = ValueObject::eBoundedRange;
2652 return root;
2653 }
2654 }
2655 break;
2656 }
2657 default: // some non-separator is in the way
2658 {
2659 *first_unparsed = expression_cstr;
2660 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2661 *final_result = ValueObject::eInvalid;
2662 return ValueObjectSP();
2663 break;
2664 }
2665 }
2666 }
2667}
2668
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002669int
2670ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2671 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002672 ValueObjectSP root,
2673 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002674 ExpressionPathScanEndReason* reason_to_stop,
2675 ExpressionPathEndResultType* final_result,
2676 const GetValueForExpressionPathOptions& options,
2677 ExpressionPathAftermath* what_next)
2678{
2679 if (!root.get())
2680 return 0;
2681
2682 *first_unparsed = expression_cstr;
2683
2684 while (true)
2685 {
2686
2687 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2688
Greg Claytonafacd142011-09-02 01:15:17 +00002689 clang_type_t root_clang_type = root->GetClangType();
2690 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002691 Flags root_clang_type_info,pointee_clang_type_info;
2692
2693 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2694 if (pointee_clang_type)
2695 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2696
2697 if (!expression_cstr || *expression_cstr == '\0')
2698 {
2699 *reason_to_stop = ValueObject::eEndOfString;
2700 list->Append(root);
2701 return 1;
2702 }
2703
2704 switch (*expression_cstr)
2705 {
2706 case '[':
2707 {
2708 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2709 {
2710 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2711 {
2712 *first_unparsed = expression_cstr;
2713 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2714 *final_result = ValueObject::eInvalid;
2715 return 0;
2716 }
2717 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2718 {
2719 *first_unparsed = expression_cstr;
2720 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2721 *final_result = ValueObject::eInvalid;
2722 return 0;
2723 }
2724 }
2725 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2726 {
2727 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2728 {
2729 *first_unparsed = expression_cstr;
2730 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2731 *final_result = ValueObject::eInvalid;
2732 return 0;
2733 }
2734 else // expand this into list
2735 {
2736 int max_index = root->GetNumChildren() - 1;
2737 for (int index = 0; index < max_index; index++)
2738 {
2739 ValueObjectSP child =
2740 root->GetChildAtIndex(index, true);
2741 list->Append(child);
2742 }
2743 *first_unparsed = expression_cstr+2;
2744 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2745 *final_result = ValueObject::eValueObjectList;
2746 return max_index; // tell me number of items I added to the VOList
2747 }
2748 }
2749 const char *separator_position = ::strchr(expression_cstr+1,'-');
2750 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2751 if (!close_bracket_position) // if there is no ], this is a syntax error
2752 {
2753 *first_unparsed = expression_cstr;
2754 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2755 *final_result = ValueObject::eInvalid;
2756 return 0;
2757 }
2758 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2759 {
2760 char *end = NULL;
2761 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2762 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2763 {
2764 *first_unparsed = expression_cstr;
2765 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2766 *final_result = ValueObject::eInvalid;
2767 return 0;
2768 }
2769 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2770 {
2771 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2772 {
2773 int max_index = root->GetNumChildren() - 1;
2774 for (int index = 0; index < max_index; index++)
2775 {
2776 ValueObjectSP child =
2777 root->GetChildAtIndex(index, true);
2778 list->Append(child);
2779 }
2780 *first_unparsed = expression_cstr+2;
2781 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2782 *final_result = ValueObject::eValueObjectList;
2783 return max_index; // tell me number of items I added to the VOList
2784 }
2785 else
2786 {
2787 *first_unparsed = expression_cstr;
2788 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2789 *final_result = ValueObject::eInvalid;
2790 return 0;
2791 }
2792 }
2793 // from here on we do have a valid index
2794 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2795 {
2796 root = root->GetChildAtIndex(index, true);
2797 if (!root.get())
2798 {
2799 *first_unparsed = expression_cstr;
2800 *reason_to_stop = ValueObject::eNoSuchChild;
2801 *final_result = ValueObject::eInvalid;
2802 return 0;
2803 }
2804 else
2805 {
2806 list->Append(root);
2807 *first_unparsed = end+1; // skip ]
2808 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2809 *final_result = ValueObject::eValueObjectList;
2810 return 1;
2811 }
2812 }
2813 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2814 {
2815 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
2816 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2817 {
2818 Error error;
2819 root = root->Dereference(error);
2820 if (error.Fail() || !root.get())
2821 {
2822 *first_unparsed = expression_cstr;
2823 *reason_to_stop = ValueObject::eDereferencingFailed;
2824 *final_result = ValueObject::eInvalid;
2825 return 0;
2826 }
2827 else
2828 {
2829 *what_next = eNothing;
2830 continue;
2831 }
2832 }
2833 else
2834 {
2835 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2836 if (!root.get())
2837 {
2838 *first_unparsed = expression_cstr;
2839 *reason_to_stop = ValueObject::eNoSuchChild;
2840 *final_result = ValueObject::eInvalid;
2841 return 0;
2842 }
2843 else
2844 {
2845 list->Append(root);
2846 *first_unparsed = end+1; // skip ]
2847 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2848 *final_result = ValueObject::eValueObjectList;
2849 return 1;
2850 }
2851 }
2852 }
2853 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2854 {
2855 root = root->GetSyntheticBitFieldChild(index, index, true);
2856 if (!root.get())
2857 {
2858 *first_unparsed = expression_cstr;
2859 *reason_to_stop = ValueObject::eNoSuchChild;
2860 *final_result = ValueObject::eInvalid;
2861 return 0;
2862 }
2863 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2864 {
2865 list->Append(root);
2866 *first_unparsed = end+1; // skip ]
2867 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2868 *final_result = ValueObject::eValueObjectList;
2869 return 1;
2870 }
2871 }
2872 }
2873 else // we have a low and a high index
2874 {
2875 char *end = NULL;
2876 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2877 if (!end || end != separator_position) // if something weird is in our way return an error
2878 {
2879 *first_unparsed = expression_cstr;
2880 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2881 *final_result = ValueObject::eInvalid;
2882 return 0;
2883 }
2884 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2885 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2886 {
2887 *first_unparsed = expression_cstr;
2888 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2889 *final_result = ValueObject::eInvalid;
2890 return 0;
2891 }
2892 if (index_lower > index_higher) // swap indices if required
2893 {
2894 unsigned long temp = index_lower;
2895 index_lower = index_higher;
2896 index_higher = temp;
2897 }
2898 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
2899 {
2900 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2901 if (!root.get())
2902 {
2903 *first_unparsed = expression_cstr;
2904 *reason_to_stop = ValueObject::eNoSuchChild;
2905 *final_result = ValueObject::eInvalid;
2906 return 0;
2907 }
2908 else
2909 {
2910 list->Append(root);
2911 *first_unparsed = end+1; // skip ]
2912 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2913 *final_result = ValueObject::eValueObjectList;
2914 return 1;
2915 }
2916 }
2917 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
2918 *what_next == ValueObject::eDereference &&
2919 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2920 {
2921 Error error;
2922 root = root->Dereference(error);
2923 if (error.Fail() || !root.get())
2924 {
2925 *first_unparsed = expression_cstr;
2926 *reason_to_stop = ValueObject::eDereferencingFailed;
2927 *final_result = ValueObject::eInvalid;
2928 return 0;
2929 }
2930 else
2931 {
2932 *what_next = ValueObject::eNothing;
2933 continue;
2934 }
2935 }
2936 else
2937 {
Johnny Chen44805302011-07-19 19:48:13 +00002938 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002939 index <= index_higher; index++)
2940 {
2941 ValueObjectSP child =
2942 root->GetChildAtIndex(index, true);
2943 list->Append(child);
2944 }
2945 *first_unparsed = end+1;
2946 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2947 *final_result = ValueObject::eValueObjectList;
2948 return index_higher-index_lower+1; // tell me number of items I added to the VOList
2949 }
2950 }
2951 break;
2952 }
2953 default: // some non-[ separator, or something entirely wrong, is in the way
2954 {
2955 *first_unparsed = expression_cstr;
2956 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2957 *final_result = ValueObject::eInvalid;
2958 return 0;
2959 break;
2960 }
2961 }
2962 }
2963}
2964
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002965void
Greg Clayton1d3afba2010-10-05 00:00:42 +00002966ValueObject::DumpValueObject
2967(
2968 Stream &s,
Greg Clayton1d3afba2010-10-05 00:00:42 +00002969 ValueObject *valobj,
2970 const char *root_valobj_name,
2971 uint32_t ptr_depth,
2972 uint32_t curr_depth,
2973 uint32_t max_depth,
2974 bool show_types,
2975 bool show_location,
2976 bool use_objc,
Greg Claytonafacd142011-09-02 01:15:17 +00002977 DynamicValueType use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00002978 bool use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002979 bool scope_already_checked,
Enrico Granata0c5ef692011-07-16 01:22:04 +00002980 bool flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00002981 uint32_t omit_summary_depth,
Greg Clayton6efba4f2012-01-26 21:08:30 +00002982 bool ignore_cap,
2983 Format format_override // Normally the format is in the valobj, but we might want to override this
Greg Clayton1d3afba2010-10-05 00:00:42 +00002984)
2985{
Greg Clayton007d5be2011-05-30 00:49:24 +00002986 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002987 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00002988 bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00002989
Greg Claytonafacd142011-09-02 01:15:17 +00002990 if (update_success && use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00002991 {
Jim Ingham2837b762011-05-04 03:43:18 +00002992 ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00002993 if (dynamic_value)
2994 valobj = dynamic_value;
2995 }
2996
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002997 clang_type_t clang_type = valobj->GetClangType();
2998
Greg Clayton73b472d2010-10-27 03:32:59 +00002999 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003000 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003001 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3002 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003003
3004 const bool print_valobj = flat_output == false || has_value;
3005
3006 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003007 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003008 if (show_location)
3009 {
Jim Ingham6035b672011-03-31 00:19:25 +00003010 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003011 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003012
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003013 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003014
Greg Clayton7c8a9662010-11-02 01:50:16 +00003015 // Always show the type for the top level items.
Greg Claytone221f822011-01-21 01:59:00 +00003016 if (show_types || (curr_depth == 0 && !flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003017 {
Enrico Granata9910bc82011-08-03 02:18:51 +00003018 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
3019 s.Printf("(%s", typeName);
3020 // only show dynamic types if the user really wants to see types
Greg Claytonafacd142011-09-02 01:15:17 +00003021 if (show_types && use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003022 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003023 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003024 {
3025 Process* process = valobj->GetUpdatePoint().GetProcessSP().get();
3026 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003027 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003028 else
3029 {
3030 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3031 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003032 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003033 else
3034 {
3035 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3036 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003037 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003038 else
3039 s.Printf(", dynamic type: %s) ",
3040 runtime->GetActualTypeName(isa).GetCString());
3041 }
3042 }
3043 }
3044 else
3045 s.Printf(") ");
3046 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003047
Greg Clayton1d3afba2010-10-05 00:00:42 +00003048
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003049 if (flat_output)
3050 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003051 // If we are showing types, also qualify the C++ base classes
3052 const bool qualify_cxx_base_classes = show_types;
3053 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003054 s.PutCString(" =");
3055 }
3056 else
3057 {
3058 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3059 s.Printf ("%s =", name_cstr);
3060 }
3061
Jim Ingham6035b672011-03-31 00:19:25 +00003062 if (!scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003063 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003064 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003065 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003066 }
3067
Greg Clayton6efba4f2012-01-26 21:08:30 +00003068 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003069 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003070 const char *sum_cstr = NULL;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003071 SummaryFormat* entry = valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003072
Enrico Granata0c5ef692011-07-16 01:22:04 +00003073 if (omit_summary_depth > 0)
3074 entry = NULL;
3075
Greg Clayton6efba4f2012-01-26 21:08:30 +00003076 Format orig_format = kNumFormats;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003077 if (err_cstr == NULL)
3078 {
Greg Clayton6efba4f2012-01-26 21:08:30 +00003079 if (format_override != eFormatDefault)
3080 {
3081 orig_format = valobj->GetFormat();
3082 valobj->SetFormat (format_override);
3083 }
Jim Ingham6035b672011-03-31 00:19:25 +00003084 val_cstr = valobj->GetValueAsCString();
Greg Clayton6efba4f2012-01-26 21:08:30 +00003085 if (val_cstr)
3086 {
3087 // Cache the value in our own storage as running summaries might
3088 // change our value from underneath us
3089 value_str = val_cstr;
3090 }
3091 if (orig_format != kNumFormats && orig_format != format_override)
3092 {
3093 valobj->SetFormat (orig_format);
3094 orig_format = kNumFormats;
3095 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003096 err_cstr = valobj->GetError().AsCString();
3097 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003098
3099 if (err_cstr)
3100 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003101 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003102 }
3103 else
3104 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003105 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003106 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003107 {
Greg Clayton6efba4f2012-01-26 21:08:30 +00003108 if (omit_summary_depth == 0)
3109 sum_cstr = valobj->GetSummaryAsCString();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003110
Greg Clayton6efba4f2012-01-26 21:08:30 +00003111 // Make sure we have a value and make sure the summary didn't
3112 // specify that the value should not be printed
3113 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3114 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003115
Enrico Granata9dd75c82011-07-15 23:30:15 +00003116 if (sum_cstr)
Enrico Granata0a3958e2011-07-02 00:25:22 +00003117 {
3118 // for some reason, using %@ (ObjC description) in a summary string, makes
3119 // us believe we need to reset ourselves, thus invalidating the content of
3120 // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty
3121 // let us recalculate it!
3122 if (sum_cstr[0] == '\0')
3123 s.Printf(" %s", valobj->GetSummaryAsCString());
3124 else
3125 s.Printf(" %s", sum_cstr);
3126 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003127
3128 if (use_objc)
3129 {
Jim Ingham6035b672011-03-31 00:19:25 +00003130 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003131 if (object_desc)
3132 s.Printf(" %s\n", object_desc);
3133 else
Sean Callanan672ad942010-10-23 00:18:49 +00003134 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003135 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003136 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003137 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003138
3139 if (curr_depth < max_depth)
3140 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003141 // We will show children for all concrete types. We won't show
3142 // pointer contents unless a pointer depth has been specified.
3143 // We won't reference contents unless the reference is the
3144 // root object (depth of zero).
3145 bool print_children = true;
3146
3147 // Use a new temporary pointer depth in case we override the
3148 // current pointer depth below...
3149 uint32_t curr_ptr_depth = ptr_depth;
3150
3151 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3152 if (is_ptr || is_ref)
3153 {
3154 // We have a pointer or reference whose value is an address.
3155 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003156 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003157 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003158 print_children = false;
3159
3160 else if (is_ref && curr_depth == 0)
3161 {
3162 // If this is the root object (depth is zero) that we are showing
3163 // and it is a reference, and no pointer depth has been supplied
3164 // print out what it references. Don't do this at deeper depths
3165 // otherwise we can end up with infinite recursion...
3166 curr_ptr_depth = 1;
3167 }
3168
3169 if (curr_ptr_depth == 0)
3170 print_children = false;
3171 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003172
Enrico Granata0a3958e2011-07-02 00:25:22 +00003173 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003174 {
Enrico Granatac482a192011-08-17 22:13:59 +00003175 ValueObjectSP synth_valobj = valobj->GetSyntheticValue(use_synth ?
Greg Claytonafacd142011-09-02 01:15:17 +00003176 eUseSyntheticFilter :
3177 eNoSyntheticFilter);
Enrico Granatac482a192011-08-17 22:13:59 +00003178 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003179 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003180 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003181 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003182 if (flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003183 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003184 if (print_valobj)
3185 s.EOL();
3186 }
3187 else
3188 {
3189 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003190 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003191 s.IndentMore();
3192 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003193
3194 uint32_t max_num_children = valobj->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
3195
3196 if (num_children > max_num_children && !ignore_cap)
3197 {
3198 num_children = max_num_children;
3199 print_dotdotdot = true;
3200 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003201
3202 for (uint32_t idx=0; idx<num_children; ++idx)
3203 {
Enrico Granatac482a192011-08-17 22:13:59 +00003204 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003205 if (child_sp.get())
3206 {
3207 DumpValueObject (s,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003208 child_sp.get(),
3209 NULL,
Greg Clayton73b472d2010-10-27 03:32:59 +00003210 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003211 curr_depth + 1,
3212 max_depth,
3213 show_types,
3214 show_location,
3215 false,
Jim Ingham78a685a2011-04-16 00:01:13 +00003216 use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00003217 use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003218 true,
Enrico Granata0c5ef692011-07-16 01:22:04 +00003219 flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00003220 omit_summary_depth > 1 ? omit_summary_depth - 1 : 0,
Greg Clayton6efba4f2012-01-26 21:08:30 +00003221 ignore_cap,
3222 format_override);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003223 }
3224 }
3225
3226 if (!flat_output)
3227 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003228 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003229 {
3230 valobj->GetUpdatePoint().GetTargetSP()->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003231 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003232 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003233 s.IndentLess();
3234 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003235 }
3236 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003237 else if (has_children)
3238 {
3239 // Aggregate, no children...
3240 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003241 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003242 }
3243 else
3244 {
3245 if (print_valobj)
3246 s.EOL();
3247 }
3248
Greg Clayton1d3afba2010-10-05 00:00:42 +00003249 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003250 else
3251 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003252 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003253 }
3254 }
3255 else
3256 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003257 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003258 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003259 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003260 }
3261 }
3262 }
3263 }
3264}
3265
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003266
3267ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003268ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003269{
3270 ValueObjectSP valobj_sp;
3271
Enrico Granatac3e320a2011-08-02 17:27:39 +00003272 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003273 {
Jim Ingham6035b672011-03-31 00:19:25 +00003274 ExecutionContextScope *exe_scope = GetExecutionContextScope();
3275 if (exe_scope)
3276 {
3277 ExecutionContext exe_ctx;
3278 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003279
Jim Ingham6035b672011-03-31 00:19:25 +00003280 clang::ASTContext *ast = GetClangAST ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003281
Jim Ingham6035b672011-03-31 00:19:25 +00003282 DataExtractor data;
3283 data.SetByteOrder (m_data.GetByteOrder());
3284 data.SetAddressByteSize(m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003285
Greg Clayton644247c2011-07-07 01:59:51 +00003286 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003287
Jim Ingham58b59f92011-04-22 23:53:53 +00003288 valobj_sp = ValueObjectConstResult::Create (exe_scope,
3289 ast,
3290 GetClangType(),
3291 name,
Enrico Granata9128ee22011-09-06 19:20:51 +00003292 data,
3293 GetAddressOf());
Jim Ingham6035b672011-03-31 00:19:25 +00003294 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003295 }
Jim Ingham6035b672011-03-31 00:19:25 +00003296
3297 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003298 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003299 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003300 }
3301 return valobj_sp;
3302}
3303
Greg Claytonafacd142011-09-02 01:15:17 +00003304ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003305ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003306{
Jim Ingham58b59f92011-04-22 23:53:53 +00003307 if (m_deref_valobj)
3308 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003309
Greg Clayton54979cd2010-12-15 05:08:08 +00003310 const bool is_pointer_type = IsPointerType();
3311 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003312 {
3313 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003314 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003315
3316 std::string child_name_str;
3317 uint32_t child_byte_size = 0;
3318 int32_t child_byte_offset = 0;
3319 uint32_t child_bitfield_bit_size = 0;
3320 uint32_t child_bitfield_bit_offset = 0;
3321 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003322 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003323 const bool transparent_pointers = false;
3324 clang::ASTContext *clang_ast = GetClangAST();
3325 clang_type_t clang_type = GetClangType();
3326 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003327
3328 ExecutionContext exe_ctx;
3329 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
3330
3331 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3332 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003333 GetName().GetCString(),
3334 clang_type,
3335 0,
3336 transparent_pointers,
3337 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003338 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003339 child_name_str,
3340 child_byte_size,
3341 child_byte_offset,
3342 child_bitfield_bit_size,
3343 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003344 child_is_base_class,
3345 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003346 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003347 {
3348 ConstString child_name;
3349 if (!child_name_str.empty())
3350 child_name.SetCString (child_name_str.c_str());
3351
Jim Ingham58b59f92011-04-22 23:53:53 +00003352 m_deref_valobj = new ValueObjectChild (*this,
3353 clang_ast,
3354 child_clang_type,
3355 child_name,
3356 child_byte_size,
3357 child_byte_offset,
3358 child_bitfield_bit_size,
3359 child_bitfield_bit_offset,
3360 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003361 child_is_deref_of_parent,
3362 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003363 }
3364 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003365
Jim Ingham58b59f92011-04-22 23:53:53 +00003366 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003367 {
3368 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003369 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003370 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003371 else
3372 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003373 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003374 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003375
3376 if (is_pointer_type)
3377 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3378 else
3379 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003380 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003381 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003382}
3383
Greg Claytonafacd142011-09-02 01:15:17 +00003384ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003385ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003386{
Jim Ingham78a685a2011-04-16 00:01:13 +00003387 if (m_addr_of_valobj_sp)
3388 return m_addr_of_valobj_sp;
3389
Greg Claytone0d378b2011-03-24 21:19:54 +00003390 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003391 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003392 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003393 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003394 if (addr != LLDB_INVALID_ADDRESS)
3395 {
3396 switch (address_type)
3397 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003398 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003399 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003400 {
3401 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003402 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003403 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3404 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003405 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003406
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003407 case eAddressTypeFile:
3408 case eAddressTypeLoad:
3409 case eAddressTypeHost:
3410 {
3411 clang::ASTContext *ast = GetClangAST();
3412 clang_type_t clang_type = GetClangType();
3413 if (ast && clang_type)
3414 {
3415 std::string name (1, '&');
3416 name.append (m_name.AsCString(""));
Jim Ingham58b59f92011-04-22 23:53:53 +00003417 m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(),
3418 ast,
3419 ClangASTContext::CreatePointerType (ast, clang_type),
3420 ConstString (name.c_str()),
3421 addr,
3422 eAddressTypeInvalid,
3423 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003424 }
3425 }
3426 break;
3427 }
3428 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003429 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003430}
3431
Greg Claytonb2dcc362011-05-05 23:32:56 +00003432
Greg Claytonafacd142011-09-02 01:15:17 +00003433ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003434ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3435{
Greg Claytonafacd142011-09-02 01:15:17 +00003436 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003437 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003438 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003439
3440 if (ptr_value != LLDB_INVALID_ADDRESS)
3441 {
3442 Address ptr_addr (NULL, ptr_value);
3443
3444 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3445 name,
3446 ptr_addr,
3447 clang_ast_type);
3448 }
3449 return valobj_sp;
3450}
3451
Greg Claytonafacd142011-09-02 01:15:17 +00003452ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003453ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3454{
Greg Claytonafacd142011-09-02 01:15:17 +00003455 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003456 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003457 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003458
3459 if (ptr_value != LLDB_INVALID_ADDRESS)
3460 {
3461 Address ptr_addr (NULL, ptr_value);
3462
3463 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3464 name,
3465 ptr_addr,
3466 type_sp);
3467 }
3468 return valobj_sp;
3469}
3470
Jim Ingham6035b672011-03-31 00:19:25 +00003471ValueObject::EvaluationPoint::EvaluationPoint () :
Jim Ingham73ca05a2011-12-17 01:35:57 +00003472 ExecutionContextScope(),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003473 m_thread_id (LLDB_INVALID_UID),
Jim Ingham4b536182011-08-09 02:12:22 +00003474 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003475{
3476}
3477
3478ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Jim Ingham73ca05a2011-12-17 01:35:57 +00003479 ExecutionContextScope (),
Jim Ingham6035b672011-03-31 00:19:25 +00003480 m_needs_update (true),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003481 m_first_update (true),
Jim Ingham89b61092011-07-06 17:42:14 +00003482 m_thread_id (LLDB_INVALID_THREAD_ID),
Jim Ingham4b536182011-08-09 02:12:22 +00003483 m_mod_id ()
Stephen Wilson71c21d12011-04-11 19:41:40 +00003484
Jim Ingham6035b672011-03-31 00:19:25 +00003485{
3486 ExecutionContext exe_ctx;
Jim Ingham9ee01152011-12-10 01:49:43 +00003487
Jim Ingham6035b672011-03-31 00:19:25 +00003488 if (exe_scope)
3489 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Claytonc14ee322011-09-22 04:58:26 +00003490 Target *target = exe_ctx.GetTargetPtr();
3491 if (target != NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003492 {
Greg Claytonc14ee322011-09-22 04:58:26 +00003493 m_target_sp = target;
3494 m_process_sp = exe_ctx.GetProcessSP();
3495 if (!m_process_sp)
3496 m_process_sp = target->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003497
Greg Claytonc14ee322011-09-22 04:58:26 +00003498 if (m_process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003499 {
Jim Ingham4b536182011-08-09 02:12:22 +00003500 m_mod_id = m_process_sp->GetModID();
3501
Greg Claytonc14ee322011-09-22 04:58:26 +00003502 Thread *thread = exe_ctx.GetThreadPtr();
Jim Ingham6035b672011-03-31 00:19:25 +00003503
Greg Claytonc14ee322011-09-22 04:58:26 +00003504 if (thread == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003505 {
3506 if (use_selected)
Jim Ingham6035b672011-03-31 00:19:25 +00003507 thread = m_process_sp->GetThreadList().GetSelectedThread().get();
Jim Ingham6035b672011-03-31 00:19:25 +00003508 }
Jim Ingham6035b672011-03-31 00:19:25 +00003509
3510 if (thread != NULL)
3511 {
3512 m_thread_id = thread->GetIndexID();
Greg Claytonc14ee322011-09-22 04:58:26 +00003513
3514 StackFrame *frame = exe_ctx.GetFramePtr();
3515 if (frame == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003516 {
3517 if (use_selected)
3518 {
Greg Claytonc14ee322011-09-22 04:58:26 +00003519 frame = thread->GetSelectedFrame().get();
Jim Ingham6035b672011-03-31 00:19:25 +00003520 if (frame)
Jim Ingham6035b672011-03-31 00:19:25 +00003521 m_stack_id = frame->GetStackID();
Jim Ingham6035b672011-03-31 00:19:25 +00003522 }
3523 }
3524 else
Greg Claytonc14ee322011-09-22 04:58:26 +00003525 m_stack_id = frame->GetStackID();
Jim Ingham6035b672011-03-31 00:19:25 +00003526 }
3527 }
3528 }
Jim Ingham6035b672011-03-31 00:19:25 +00003529}
3530
3531ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Stephen Wilson71c21d12011-04-11 19:41:40 +00003532 m_needs_update(true),
3533 m_first_update(true),
Jim Ingham6035b672011-03-31 00:19:25 +00003534 m_target_sp (rhs.m_target_sp),
3535 m_process_sp (rhs.m_process_sp),
3536 m_thread_id (rhs.m_thread_id),
3537 m_stack_id (rhs.m_stack_id),
Jim Ingham4b536182011-08-09 02:12:22 +00003538 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003539{
3540}
3541
3542ValueObject::EvaluationPoint::~EvaluationPoint ()
3543{
3544}
3545
Jim Ingham73ca05a2011-12-17 01:35:57 +00003546Target *
3547ValueObject::EvaluationPoint::CalculateTarget ()
Jim Ingham6035b672011-03-31 00:19:25 +00003548{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003549 return m_target_sp.get();
3550}
3551
3552Process *
3553ValueObject::EvaluationPoint::CalculateProcess ()
3554{
3555 return m_process_sp.get();
3556}
3557
3558Thread *
3559ValueObject::EvaluationPoint::CalculateThread ()
3560{
3561 ExecutionContextScope *exe_scope;
Jim Ingham9ee01152011-12-10 01:49:43 +00003562 SyncWithProcessState(exe_scope);
Jim Ingham73ca05a2011-12-17 01:35:57 +00003563 if (exe_scope)
3564 return exe_scope->CalculateThread();
3565 else
3566 return NULL;
3567}
3568
3569StackFrame *
3570ValueObject::EvaluationPoint::CalculateStackFrame ()
3571{
3572 ExecutionContextScope *exe_scope;
3573 SyncWithProcessState(exe_scope);
3574 if (exe_scope)
3575 return exe_scope->CalculateStackFrame();
3576 else
3577 return NULL;
3578}
3579
3580void
3581ValueObject::EvaluationPoint::CalculateExecutionContext (ExecutionContext &exe_ctx)
3582{
3583 ExecutionContextScope *exe_scope;
3584 SyncWithProcessState(exe_scope);
3585 if (exe_scope)
3586 return exe_scope->CalculateExecutionContext (exe_ctx);
Jim Ingham6035b672011-03-31 00:19:25 +00003587}
3588
3589// This function checks the EvaluationPoint against the current process state. If the current
3590// state matches the evaluation point, or the evaluation point is already invalid, then we return
3591// false, meaning "no change". If the current state is different, we update our state, and return
3592// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3593// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003594// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003595
3596bool
Jim Ingham9ee01152011-12-10 01:49:43 +00003597ValueObject::EvaluationPoint::SyncWithProcessState(ExecutionContextScope *&exe_scope)
Jim Ingham6035b672011-03-31 00:19:25 +00003598{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003599
3600 // Start with the target, if it is NULL, then we're obviously not going to get any further:
3601 exe_scope = m_target_sp.get();
3602
3603 if (exe_scope == NULL)
3604 return false;
3605
Jim Ingham6035b672011-03-31 00:19:25 +00003606 // If we don't have a process nothing can change.
3607 if (!m_process_sp)
3608 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003609
3610 exe_scope = m_process_sp.get();
Jim Ingham6035b672011-03-31 00:19:25 +00003611
3612 // If our stop id is the current stop ID, nothing has changed:
Jim Ingham4b536182011-08-09 02:12:22 +00003613 ProcessModID current_mod_id = m_process_sp->GetModID();
3614
Jim Ingham78a685a2011-04-16 00:01:13 +00003615 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3616 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003617 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003618 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003619
3620 bool changed;
3621
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003622 if (m_mod_id.IsValid())
3623 {
3624 if (m_mod_id == current_mod_id)
3625 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003626 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003627 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003628 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003629 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003630 else
3631 {
3632 m_mod_id = current_mod_id;
3633 m_needs_update = true;
3634 changed = true;
3635 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003636 }
Jim Ingham6035b672011-03-31 00:19:25 +00003637
Jim Ingham73ca05a2011-12-17 01:35:57 +00003638 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3639 // That way we'll be sure to return a valid exe_scope.
3640 // 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 +00003641
3642 if (m_thread_id != LLDB_INVALID_THREAD_ID)
3643 {
3644 Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get();
3645 if (our_thread == NULL)
Greg Clayton262f80d2011-07-06 16:49:27 +00003646 {
Jim Ingham89b61092011-07-06 17:42:14 +00003647 SetInvalid();
Greg Clayton262f80d2011-07-06 16:49:27 +00003648 }
Jim Ingham6035b672011-03-31 00:19:25 +00003649 else
3650 {
Jim Ingham9ee01152011-12-10 01:49:43 +00003651 exe_scope = our_thread;
Jim Ingham6035b672011-03-31 00:19:25 +00003652
3653 if (m_stack_id.IsValid())
3654 {
3655 StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get();
3656 if (our_frame == NULL)
3657 SetInvalid();
3658 else
Jim Ingham9ee01152011-12-10 01:49:43 +00003659 exe_scope = our_frame;
Jim Ingham6035b672011-03-31 00:19:25 +00003660 }
3661 }
3662 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003663 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003664}
3665
Jim Ingham61be0902011-05-02 18:13:59 +00003666void
3667ValueObject::EvaluationPoint::SetUpdated ()
3668{
Jim Ingham9ee01152011-12-10 01:49:43 +00003669 if (m_process_sp)
3670 m_mod_id = m_process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003671 m_first_update = false;
3672 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003673}
3674
3675
Jim Ingham6035b672011-03-31 00:19:25 +00003676bool
3677ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3678{
3679 if (!IsValid())
3680 return false;
3681
3682 bool needs_update = false;
Jim Ingham6035b672011-03-31 00:19:25 +00003683
3684 // The target has to be non-null, and the
3685 Target *target = exe_scope->CalculateTarget();
3686 if (target != NULL)
3687 {
3688 Target *old_target = m_target_sp.get();
3689 assert (target == old_target);
3690 Process *process = exe_scope->CalculateProcess();
3691 if (process != NULL)
3692 {
3693 // FOR NOW - assume you can't update variable objects across process boundaries.
3694 Process *old_process = m_process_sp.get();
3695 assert (process == old_process);
Jim Ingham4b536182011-08-09 02:12:22 +00003696 ProcessModID current_mod_id = process->GetModID();
3697 if (m_mod_id != current_mod_id)
Jim Ingham6035b672011-03-31 00:19:25 +00003698 {
3699 needs_update = true;
Jim Ingham4b536182011-08-09 02:12:22 +00003700 m_mod_id = current_mod_id;
Jim Ingham6035b672011-03-31 00:19:25 +00003701 }
3702 // See if we're switching the thread or stack context. If no thread is given, this is
3703 // being evaluated in a global context.
3704 Thread *thread = exe_scope->CalculateThread();
3705 if (thread != NULL)
3706 {
Greg Claytonafacd142011-09-02 01:15:17 +00003707 user_id_t new_thread_index = thread->GetIndexID();
Jim Ingham6035b672011-03-31 00:19:25 +00003708 if (new_thread_index != m_thread_id)
3709 {
3710 needs_update = true;
3711 m_thread_id = new_thread_index;
3712 m_stack_id.Clear();
3713 }
3714
3715 StackFrame *new_frame = exe_scope->CalculateStackFrame();
3716 if (new_frame != NULL)
3717 {
3718 if (new_frame->GetStackID() != m_stack_id)
3719 {
3720 needs_update = true;
3721 m_stack_id = new_frame->GetStackID();
3722 }
3723 }
3724 else
3725 {
3726 m_stack_id.Clear();
3727 needs_update = true;
3728 }
3729 }
3730 else
3731 {
3732 // If this had been given a thread, and now there is none, we should update.
3733 // Otherwise we don't have to do anything.
3734 if (m_thread_id != LLDB_INVALID_UID)
3735 {
3736 m_thread_id = LLDB_INVALID_UID;
3737 m_stack_id.Clear();
3738 needs_update = true;
3739 }
3740 }
3741 }
3742 else
3743 {
3744 // If there is no process, then we don't need to update anything.
3745 // But if we're switching from having a process to not, we should try to update.
3746 if (m_process_sp.get() != NULL)
3747 {
3748 needs_update = true;
3749 m_process_sp.reset();
3750 m_thread_id = LLDB_INVALID_UID;
3751 m_stack_id.Clear();
3752 }
3753 }
3754 }
3755 else
3756 {
3757 // If there's no target, nothing can change so we don't need to update anything.
3758 // But if we're switching from having a target to not, we should try to update.
3759 if (m_target_sp.get() != NULL)
3760 {
3761 needs_update = true;
3762 m_target_sp.reset();
3763 m_process_sp.reset();
3764 m_thread_id = LLDB_INVALID_UID;
3765 m_stack_id.Clear();
3766 }
3767 }
3768 if (!m_needs_update)
3769 m_needs_update = needs_update;
3770
3771 return needs_update;
3772}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003773
3774void
3775ValueObject::ClearUserVisibleData()
3776{
3777 m_location_str.clear();
3778 m_value_str.clear();
3779 m_summary_str.clear();
3780 m_object_desc_str.clear();
Greg Clayton48ca8b82012-01-07 20:58:07 +00003781 m_is_getting_summary = false;
Johnny Chen44805302011-07-19 19:48:13 +00003782}
Enrico Granata9128ee22011-09-06 19:20:51 +00003783
3784SymbolContextScope *
3785ValueObject::GetSymbolContextScope()
3786{
3787 if (m_parent)
3788 {
3789 if (!m_parent->IsPointerOrReferenceType())
3790 return m_parent->GetSymbolContextScope();
3791 }
3792 return NULL;
3793}