blob: 657faf36f85a4eb178876c54b533937117a9c5c2 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/ValueObject.h"
11
12// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000013#include <stdlib.h>
14
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015// C++ Includes
16// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000018#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
20// Project includes
21#include "lldb/Core/DataBufferHeap.h"
Enrico Granata0a976142011-08-22 22:03:47 +000022#include "lldb/Core/DataVisualization.h"
Enrico Granata4becb372011-06-29 22:27:15 +000023#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000024#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/StreamString.h"
26#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000027#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000028#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000030#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000031#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Greg Clayton7fb56d02011-02-01 01:31:41 +000033#include "lldb/Host/Endian.h"
34
Enrico Granata61a80ba2011-08-12 16:42:31 +000035#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000036#include "lldb/Interpreter/ScriptInterpreterPython.h"
37
Greg Claytone1a916a2010-07-21 22:12:05 +000038#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Symbol/ClangASTContext.h"
40#include "lldb/Symbol/Type.h"
41
Jim Ingham53c47f12010-09-10 23:12:17 +000042#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000043#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000044#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045#include "lldb/Target/Process.h"
46#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000047#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049
Enrico Granataf4efecd2011-07-12 22:56:10 +000050#include "lldb/Utility/RefCounter.h"
51
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052using namespace lldb;
53using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000054using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055
Greg Claytonafacd142011-09-02 01:15:17 +000056static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057
58//----------------------------------------------------------------------
59// ValueObject constructor
60//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000061ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000063 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000064 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065 m_name (),
66 m_data (),
67 m_value (),
68 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000069 m_value_str (),
70 m_old_value_str (),
71 m_location_str (),
72 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000073 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000074 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000075 m_children (),
76 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000077 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000078 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000079 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000080 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000081 m_last_format_mgr_revision(0),
Enrico Granatad8b5fce2011-08-02 23:12:24 +000082 m_last_format_mgr_dynamic(parent.m_last_format_mgr_dynamic),
Enrico Granata9df29e32011-07-19 20:57:44 +000083 m_last_summary_format(),
84 m_forced_summary_format(),
85 m_last_value_format(),
Enrico Granatad55546b2011-07-22 00:16:08 +000086 m_last_synthetic_filter(),
Jim Ingham4b536182011-08-09 02:12:22 +000087 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000088 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000089 m_value_is_valid (false),
90 m_value_did_change (false),
91 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000092 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000093 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000094 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000095 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +000096 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000097 m_is_child_at_offset(false),
Enrico Granata855cd902011-09-06 22:59:55 +000098 m_trying_summary_already(false)
Jim Ingham6035b672011-03-31 00:19:25 +000099{
Jim Ingham58b59f92011-04-22 23:53:53 +0000100 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000101}
102
103//----------------------------------------------------------------------
104// ValueObject constructor
105//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000106ValueObject::ValueObject (ExecutionContextScope *exe_scope,
107 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000108 UserID (++g_value_obj_uid), // Unique identifier for every value object
109 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000110 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000111 m_name (),
112 m_data (),
113 m_value (),
114 m_error (),
115 m_value_str (),
116 m_old_value_str (),
117 m_location_str (),
118 m_summary_str (),
119 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000120 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000121 m_children (),
122 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000123 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000124 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000125 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000126 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000127 m_last_format_mgr_revision(0),
Greg Claytonafacd142011-09-02 01:15:17 +0000128 m_last_format_mgr_dynamic(eNoDynamicValues),
Enrico Granata9df29e32011-07-19 20:57:44 +0000129 m_last_summary_format(),
130 m_forced_summary_format(),
131 m_last_value_format(),
Enrico Granatad55546b2011-07-22 00:16:08 +0000132 m_last_synthetic_filter(),
Jim Ingham4b536182011-08-09 02:12:22 +0000133 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000134 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000135 m_value_is_valid (false),
136 m_value_did_change (false),
137 m_children_count_valid (false),
138 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000139 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000140 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000141 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000142 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000143 m_is_child_at_offset(false),
Enrico Granata855cd902011-09-06 22:59:55 +0000144 m_trying_summary_already(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000145{
Jim Ingham58b59f92011-04-22 23:53:53 +0000146 m_manager = new ValueObjectManager();
147 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148}
149
150//----------------------------------------------------------------------
151// Destructor
152//----------------------------------------------------------------------
153ValueObject::~ValueObject ()
154{
155}
156
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000157bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000158ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000160 return UpdateValueIfNeeded(m_last_format_mgr_dynamic, update_format);
161}
162
163bool
Greg Claytonafacd142011-09-02 01:15:17 +0000164ValueObject::UpdateValueIfNeeded (DynamicValueType use_dynamic, bool update_format)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000165{
Enrico Granata4becb372011-06-29 22:27:15 +0000166
Enrico Granata9128ee22011-09-06 19:20:51 +0000167 bool did_change_formats = false;
168
Enrico Granata0a3958e2011-07-02 00:25:22 +0000169 if (update_format)
Enrico Granata9128ee22011-09-06 19:20:51 +0000170 did_change_formats = UpdateFormatsIfNeeded(use_dynamic);
Enrico Granata4becb372011-06-29 22:27:15 +0000171
Greg Claytonb71f3842010-10-05 03:13:51 +0000172 // If this is a constant value, then our success is predicated on whether
173 // we have an error or not
174 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000175 {
176 // if you were asked to update your formatters, but did not get a chance to do it
177 // clear your own values (this serves the purpose of faking a stop-id for frozen
178 // objects (which are regarded as constant, but could have changes behind their backs
179 // because of the frozen-pointer depth limit)
180 // TODO: decouple summary from value and then remove this code and only force-clear the summary
181 if (update_format && !did_change_formats)
182 m_summary_str.clear();
Greg Claytonb71f3842010-10-05 03:13:51 +0000183 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000184 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000185
Jim Ingham6035b672011-03-31 00:19:25 +0000186 bool first_update = m_update_point.IsFirstEvaluation();
187
188 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189 {
Jim Ingham6035b672011-03-31 00:19:25 +0000190 m_update_point.SetUpdated();
191
192 // Save the old value using swap to avoid a string copy which
193 // also will clear our m_value_str
194 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000195 {
Jim Ingham6035b672011-03-31 00:19:25 +0000196 m_old_value_valid = false;
197 }
198 else
199 {
200 m_old_value_valid = true;
201 m_old_value_str.swap (m_value_str);
202 m_value_str.clear();
203 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000204
Enrico Granataf2bbf712011-07-15 02:26:42 +0000205 ClearUserVisibleData();
206
Jim Ingham6035b672011-03-31 00:19:25 +0000207 const bool value_was_valid = GetValueIsValid();
208 SetValueDidChange (false);
Greg Clayton73b953b2010-08-28 00:08:07 +0000209
Jim Ingham6035b672011-03-31 00:19:25 +0000210 m_error.Clear();
Greg Clayton73b953b2010-08-28 00:08:07 +0000211
Jim Ingham6035b672011-03-31 00:19:25 +0000212 // Call the pure virtual function to update the value
213 bool success = UpdateValue ();
214
215 SetValueIsValid (success);
216
217 if (first_update)
218 SetValueDidChange (false);
219 else if (!m_value_did_change && success == false)
220 {
221 // The value wasn't gotten successfully, so we mark this
222 // as changed if the value used to be valid and now isn't
223 SetValueDidChange (value_was_valid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224 }
225 }
226 return m_error.Success();
227}
228
Enrico Granata9128ee22011-09-06 19:20:51 +0000229bool
Greg Claytonafacd142011-09-02 01:15:17 +0000230ValueObject::UpdateFormatsIfNeeded(DynamicValueType use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000231{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000232 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
233 if (log)
234 log->Printf("checking for FormatManager revisions. VO named %s is at revision %d, while the format manager is at revision %d",
235 GetName().GetCString(),
Enrico Granata4becb372011-06-29 22:27:15 +0000236 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000237 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000238
239 bool any_change = false;
240
Jim Ingham4b536182011-08-09 02:12:22 +0000241 if (HasCustomSummaryFormat() && m_update_point.GetModID() != m_user_id_of_forced_summary)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000242 {
243 ClearCustomSummaryFormat();
Enrico Granata855cd902011-09-06 22:59:55 +0000244
Enrico Granata9128ee22011-09-06 19:20:51 +0000245 any_change = true;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000246 }
Enrico Granata855cd902011-09-06 22:59:55 +0000247
Enrico Granata85933ed2011-08-18 16:38:26 +0000248 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) ||
Enrico Granatac3e320a2011-08-02 17:27:39 +0000249 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000250 {
Enrico Granata78d06382011-09-09 23:33:14 +0000251 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
252 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, use_dynamic));
253 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, use_dynamic));
Enrico Granata1490c6f2011-07-19 02:34:21 +0000254
Enrico Granata85933ed2011-08-18 16:38:26 +0000255 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000256 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granata855cd902011-09-06 22:59:55 +0000257
258 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000259 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000260
261 return any_change;
262
Enrico Granata4becb372011-06-29 22:27:15 +0000263}
264
Jim Ingham16e0c682011-08-12 23:34:31 +0000265void
266ValueObject::SetNeedsUpdate ()
267{
268 m_update_point.SetNeedsUpdate();
269 // We have to clear the value string here so ConstResult children will notice if their values are
270 // changed by hand (i.e. with SetValueAsCString).
271 m_value_str.clear();
272}
273
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000274DataExtractor &
275ValueObject::GetDataExtractor ()
276{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000277 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278 return m_data;
279}
280
281const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000282ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000283{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000284 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000285 return m_error;
286}
287
288const ConstString &
289ValueObject::GetName() const
290{
291 return m_name;
292}
293
294const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000295ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000296{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000297 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000298 {
299 if (m_location_str.empty())
300 {
301 StreamString sstr;
302
303 switch (m_value.GetValueType())
304 {
305 default:
306 break;
307
308 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000309 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310 {
311 RegisterInfo *reg_info = m_value.GetRegisterInfo();
312 if (reg_info)
313 {
314 if (reg_info->name)
315 m_location_str = reg_info->name;
316 else if (reg_info->alt_name)
317 m_location_str = reg_info->alt_name;
318 break;
319 }
320 }
321 m_location_str = "scalar";
322 break;
323
324 case Value::eValueTypeLoadAddress:
325 case Value::eValueTypeFileAddress:
326 case Value::eValueTypeHostAddress:
327 {
328 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
329 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
330 m_location_str.swap(sstr.GetString());
331 }
332 break;
333 }
334 }
335 }
336 return m_location_str.c_str();
337}
338
339Value &
340ValueObject::GetValue()
341{
342 return m_value;
343}
344
345const Value &
346ValueObject::GetValue() const
347{
348 return m_value;
349}
350
351bool
Jim Ingham6035b672011-03-31 00:19:25 +0000352ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000353{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000354 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
355 {
356 ExecutionContext exe_ctx;
357 ExecutionContextScope *exe_scope = GetExecutionContextScope();
358 if (exe_scope)
359 exe_scope->CalculateExecutionContext(exe_ctx);
Jim Ingham16e0c682011-08-12 23:34:31 +0000360 Value tmp_value(m_value);
361 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Enrico Granata6fd87d52011-08-04 01:41:02 +0000362 return scalar.IsValid();
363 }
364 else
365 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000366}
367
368bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000369ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370{
Greg Clayton288bdf92010-09-02 02:59:18 +0000371 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000372}
373
374
375void
376ValueObject::SetValueIsValid (bool b)
377{
Greg Clayton288bdf92010-09-02 02:59:18 +0000378 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379}
380
381bool
Jim Ingham6035b672011-03-31 00:19:25 +0000382ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383{
Jim Ingham6035b672011-03-31 00:19:25 +0000384 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000385 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000386}
387
388void
389ValueObject::SetValueDidChange (bool value_changed)
390{
Greg Clayton288bdf92010-09-02 02:59:18 +0000391 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392}
393
394ValueObjectSP
395ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
396{
397 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000398 // We may need to update our value if we are dynamic
399 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000400 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000401 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000402 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000403 // Check if we have already made the child value object?
404 if (can_create && m_children[idx] == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000406 // No we haven't created the child at this index, so lets have our
407 // subclass do it and cache the result for quick future access.
408 m_children[idx] = CreateChildAtIndex (idx, false, 0);
Jim Ingham78a685a2011-04-16 00:01:13 +0000409 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000410
411 if (m_children[idx] != NULL)
412 return m_children[idx]->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413 }
414 return child_sp;
415}
416
417uint32_t
418ValueObject::GetIndexOfChildWithName (const ConstString &name)
419{
420 bool omit_empty_base_classes = true;
421 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000422 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000423 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424 omit_empty_base_classes);
425}
426
427ValueObjectSP
428ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
429{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000430 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000431 // classes (which really aren't part of the expression path), so we
432 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000433 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000434
Greg Claytondea8cb42011-06-29 22:09:02 +0000435 // We may need to update our value if we are dynamic
436 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000437 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000438
439 std::vector<uint32_t> child_indexes;
440 clang::ASTContext *clang_ast = GetClangAST();
441 void *clang_type = GetClangType();
442 bool omit_empty_base_classes = true;
443 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
444 clang_type,
445 name.GetCString(),
446 omit_empty_base_classes,
447 child_indexes);
448 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000449 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000450 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
451 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
452
453 child_sp = GetChildAtIndex(*pos, can_create);
454 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000456 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000457 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000458 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
459 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000460 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000461 else
462 {
463 child_sp.reset();
464 }
465
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000466 }
467 }
468 return child_sp;
469}
470
471
472uint32_t
473ValueObject::GetNumChildren ()
474{
Greg Clayton288bdf92010-09-02 02:59:18 +0000475 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476 {
477 SetNumChildren (CalculateNumChildren());
478 }
479 return m_children.size();
480}
481void
482ValueObject::SetNumChildren (uint32_t num_children)
483{
Greg Clayton288bdf92010-09-02 02:59:18 +0000484 m_children_count_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000485 m_children.resize(num_children);
486}
487
488void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489ValueObject::SetName (const ConstString &name)
490{
491 m_name = name;
492}
493
Jim Ingham58b59f92011-04-22 23:53:53 +0000494ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000495ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
496{
Jim Ingham2eec4872011-05-07 00:10:58 +0000497 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000498
Greg Claytondea8cb42011-06-29 22:09:02 +0000499 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000500 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000501 std::string child_name_str;
502 uint32_t child_byte_size = 0;
503 int32_t child_byte_offset = 0;
504 uint32_t child_bitfield_bit_size = 0;
505 uint32_t child_bitfield_bit_offset = 0;
506 bool child_is_base_class = false;
507 bool child_is_deref_of_parent = false;
508
509 const bool transparent_pointers = synthetic_array_member == false;
510 clang::ASTContext *clang_ast = GetClangAST();
511 clang_type_t clang_type = GetClangType();
512 clang_type_t child_clang_type;
513
514 ExecutionContext exe_ctx;
515 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
516
517 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
518 clang_ast,
519 GetName().GetCString(),
520 clang_type,
521 idx,
522 transparent_pointers,
523 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000524 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000525 child_name_str,
526 child_byte_size,
527 child_byte_offset,
528 child_bitfield_bit_size,
529 child_bitfield_bit_offset,
530 child_is_base_class,
531 child_is_deref_of_parent);
532 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000533 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000534 if (synthetic_index)
535 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000536
Greg Claytondea8cb42011-06-29 22:09:02 +0000537 ConstString child_name;
538 if (!child_name_str.empty())
539 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000540
Greg Claytondea8cb42011-06-29 22:09:02 +0000541 valobj = new ValueObjectChild (*this,
542 clang_ast,
543 child_clang_type,
544 child_name,
545 child_byte_size,
546 child_byte_offset,
547 child_bitfield_bit_size,
548 child_bitfield_bit_offset,
549 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000550 child_is_deref_of_parent,
551 eAddressTypeInvalid);
552 //if (valobj)
553 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
554 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000555
Jim Ingham58b59f92011-04-22 23:53:53 +0000556 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000557}
558
559const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000560ValueObject::GetSummaryAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561{
Enrico Granatad8b5fce2011-08-02 23:12:24 +0000562 if (UpdateValueIfNeeded (true))
Enrico Granata4becb372011-06-29 22:27:15 +0000563 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564 if (m_summary_str.empty())
565 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000566 SummaryFormat *summary_format = GetSummaryFormat().get();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000567
568 if (summary_format)
Enrico Granata4becb372011-06-29 22:27:15 +0000569 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000570 m_summary_str = summary_format->FormatObject(GetSP());
Enrico Granata4becb372011-06-29 22:27:15 +0000571 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000572 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000574 clang_type_t clang_type = GetClangType();
Greg Clayton737b9322010-09-13 03:32:57 +0000575
Enrico Granata9dd75c82011-07-15 23:30:15 +0000576 // Do some default printout for function pointers
Enrico Granataf2bbf712011-07-15 02:26:42 +0000577 if (clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000578 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000579 StreamString sstr;
580 clang_type_t elem_or_pointee_clang_type;
581 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
582 GetClangAST(),
583 &elem_or_pointee_clang_type));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000584
Enrico Granataf2bbf712011-07-15 02:26:42 +0000585 ExecutionContextScope *exe_scope = GetExecutionContextScope();
586 if (exe_scope)
587 {
Enrico Granata9dd75c82011-07-15 23:30:15 +0000588 if (ClangASTContext::IsFunctionPointerType (clang_type))
Jim Ingham6035b672011-03-31 00:19:25 +0000589 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000590 AddressType func_ptr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000591 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000592 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
593 {
594 switch (func_ptr_address_type)
595 {
596 case eAddressTypeInvalid:
597 case eAddressTypeFile:
598 break;
599
600 case eAddressTypeLoad:
601 {
602 Address so_addr;
603 Target *target = exe_scope->CalculateTarget();
604 if (target && target->GetSectionLoadList().IsEmpty() == false)
605 {
606 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
607 {
608 so_addr.Dump (&sstr,
609 exe_scope,
610 Address::DumpStyleResolvedDescription,
611 Address::DumpStyleSectionNameOffset);
612 }
613 }
614 }
615 break;
616
617 case eAddressTypeHost:
618 break;
619 }
620 }
621 if (sstr.GetSize() > 0)
622 {
623 m_summary_str.assign (1, '(');
624 m_summary_str.append (sstr.GetData(), sstr.GetSize());
625 m_summary_str.append (1, ')');
626 }
Jim Ingham6035b672011-03-31 00:19:25 +0000627 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000628 }
629 }
630 }
631 }
632 }
633 if (m_summary_str.empty())
634 return NULL;
635 return m_summary_str.c_str();
636}
637
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000638bool
639ValueObject::IsCStringContainer(bool check_pointer)
640{
641 clang_type_t elem_or_pointee_clang_type;
642 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
643 GetClangAST(),
644 &elem_or_pointee_clang_type));
645 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
646 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
647 if (!is_char_arr_ptr)
648 return false;
649 if (!check_pointer)
650 return true;
651 if (type_flags.Test(ClangASTContext::eTypeIsArray))
652 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000653 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000654 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000655 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000656 return (cstr_address != LLDB_INVALID_ADDRESS);
657}
658
Enrico Granata9128ee22011-09-06 19:20:51 +0000659size_t
660ValueObject::GetPointeeData (DataExtractor& data,
661 uint32_t item_idx,
662 uint32_t item_count)
663{
664 if (!IsPointerType() && !IsArrayType())
665 return 0;
666
667 if (item_count == 0)
668 return 0;
669
670 uint32_t stride = 0;
671
672 ClangASTType type(GetClangAST(),
673 GetClangType());
674
675 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
676 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
677
678 const uint64_t bytes = item_count * item_type_size;
679
680 const uint64_t offset = item_idx * item_type_size;
681
682 if (item_idx == 0 && item_count == 1) // simply a deref
683 {
684 if (IsPointerType())
685 {
686 Error error;
687 ValueObjectSP pointee_sp = Dereference(error);
688 if (error.Fail() || pointee_sp.get() == NULL)
689 return 0;
690 return pointee_sp->GetDataExtractor().Copy(data);
691 }
692 else
693 {
694 ValueObjectSP child_sp = GetChildAtIndex(0, true);
695 if (child_sp.get() == NULL)
696 return 0;
697 return child_sp->GetDataExtractor().Copy(data);
698 }
699 return true;
700 }
701 else /* (items > 1) */
702 {
703 Error error;
704 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
705 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
706
707 AddressType addr_type;
708 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
709
710 ExecutionContextScope *exe_scope = m_update_point.GetExecutionContextScope();
711
712
713 switch (addr_type)
714 {
715 case eAddressTypeFile:
716 {
717 Module* module = GetModule();
718 if (module)
719 {
720 Address so_addr;
721 module->ResolveFileAddress(addr, so_addr);
722 if (exe_scope)
723 {
724 Target* target = exe_scope->CalculateTarget();
725 if (target)
726 {
727 heap_buf_ptr->SetByteSize(bytes);
728 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
729 if (error.Success())
730 {
731 data.SetData(data_sp);
732 return bytes_read;
733 }
734 }
735 }
736 }
737 }
738 break;
739 case eAddressTypeLoad:
740 if (exe_scope)
741 {
742 Process *process = exe_scope->CalculateProcess();
743 if (process)
744 {
745 heap_buf_ptr->SetByteSize(bytes);
746 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
747 if (error.Success())
748 {
749 data.SetData(data_sp);
750 return bytes_read;
751 }
752 }
753 }
754 break;
755 case eAddressTypeHost:
756 {
757 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
758 data.SetData(data_sp);
759 return bytes;
760 }
761 break;
762 case eAddressTypeInvalid:
763 default:
764 break;
765 }
766 }
767 return 0;
768}
769
770size_t
771ValueObject::GetData (DataExtractor& data)
772{
773 UpdateValueIfNeeded(false);
774 ExecutionContext exe_ctx;
775 GetExecutionContextScope()->CalculateExecutionContext(exe_ctx);
776 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule());
777 if (error.Fail())
778 return 0;
779 data.SetAddressByteSize(m_data.GetAddressByteSize());
780 data.SetByteOrder(m_data.GetByteOrder());
781 return data.GetByteSize();
782}
783
784// will compute strlen(str), but without consuming more than
785// maxlen bytes out of str (this serves the purpose of reading
786// chunks of a string without having to worry about
787// missing NULL terminators in the chunk)
788// of course, if strlen(str) > maxlen, the function will return
789// maxlen_value (which should be != maxlen, because that allows you
790// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
791static uint32_t
792strlen_or_inf (const char* str,
793 uint32_t maxlen,
794 uint32_t maxlen_value)
795{
796 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000797 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000798 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000799 while(*str)
800 {
801 len++;str++;
802 if (len > maxlen)
803 return maxlen_value;
804 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000805 }
806 return len;
807}
808
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000809void
810ValueObject::ReadPointedString(Stream& s,
811 Error& error,
Enrico Granataf4efecd2011-07-12 22:56:10 +0000812 uint32_t max_length,
813 bool honor_array,
Greg Claytonafacd142011-09-02 01:15:17 +0000814 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000815{
816
817 if (max_length == 0)
Enrico Granata9128ee22011-09-06 19:20:51 +0000818 max_length = GetUpdatePoint().GetTargetSP()->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000819
820 clang_type_t clang_type = GetClangType();
821 clang_type_t elem_or_pointee_clang_type;
822 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
823 GetClangAST(),
824 &elem_or_pointee_clang_type));
825 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
826 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
827 {
828 ExecutionContextScope *exe_scope = GetExecutionContextScope();
829 if (exe_scope)
830 {
831 Target *target = exe_scope->CalculateTarget();
Enrico Granata6f3533f2011-07-29 19:53:35 +0000832 if (target == NULL)
833 {
834 s << "<no target to read from>";
835 }
836 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000837 {
Greg Claytonafacd142011-09-02 01:15:17 +0000838 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000839 AddressType cstr_address_type = eAddressTypeInvalid;
840
841 size_t cstr_len = 0;
842 bool capped_data = false;
843 if (type_flags.Test (ClangASTContext::eTypeIsArray))
844 {
845 // We have an array
846 cstr_len = ClangASTContext::GetArraySize (clang_type);
Enrico Granataf4efecd2011-07-12 22:56:10 +0000847 if (cstr_len > max_length)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000848 {
Enrico Granataf4efecd2011-07-12 22:56:10 +0000849 capped_data = true;
850 cstr_len = max_length;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000851 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000852 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000853 }
854 else
855 {
856 // We have a pointer
Enrico Granata9128ee22011-09-06 19:20:51 +0000857 cstr_address = GetPointerValue (&cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000858 }
Greg Clayton8dd5c172011-10-05 22:19:51 +0000859 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000860 {
861 Address cstr_so_addr (NULL, cstr_address);
862 DataExtractor data;
863 size_t bytes_read = 0;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000864 if (cstr_len > 0 && honor_array)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000865 {
Enrico Granata9128ee22011-09-06 19:20:51 +0000866 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
867 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
868 GetPointeeData(data, 0, cstr_len);
869
Greg Clayton8dd5c172011-10-05 22:19:51 +0000870 if ((bytes_read = data.GetByteSize()) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000871 {
872 s << '"';
873 data.Dump (&s,
874 0, // Start offset in "data"
Enrico Granataf4efecd2011-07-12 22:56:10 +0000875 item_format,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000876 1, // Size of item (1 byte for a char!)
877 bytes_read, // How many bytes to print?
878 UINT32_MAX, // num per line
879 LLDB_INVALID_ADDRESS,// base address
880 0, // bitfield bit size
881 0); // bitfield bit offset
882 if (capped_data)
883 s << "...";
884 s << '"';
885 }
886 }
887 else
888 {
Enrico Granataf4efecd2011-07-12 22:56:10 +0000889 cstr_len = max_length;
890 const size_t k_max_buf_size = 64;
Enrico Granata9128ee22011-09-06 19:20:51 +0000891
892 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000893
Greg Clayton8dd5c172011-10-05 22:19:51 +0000894 int cstr_len_displayed = -1;
895 bool capped_cstr = false;
Enrico Granata9128ee22011-09-06 19:20:51 +0000896 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
897 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
Greg Clayton8dd5c172011-10-05 22:19:51 +0000898 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000899 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000900 const char *cstr = data.PeekCStr(0);
901 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
Enrico Granata9128ee22011-09-06 19:20:51 +0000902 if (len > k_max_buf_size)
903 len = k_max_buf_size;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000904 if (cstr && cstr_len_displayed < 0)
Enrico Granata9128ee22011-09-06 19:20:51 +0000905 s << '"';
Greg Clayton8dd5c172011-10-05 22:19:51 +0000906
907 if (cstr_len_displayed < 0)
908 cstr_len_displayed = len;
909
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000910 if (len == 0)
911 break;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000912 cstr_len_displayed += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000913 if (len > bytes_read)
914 len = bytes_read;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000915 if (len > cstr_len)
916 len = cstr_len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000917
918 data.Dump (&s,
919 0, // Start offset in "data"
Enrico Granataf4efecd2011-07-12 22:56:10 +0000920 item_format,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000921 1, // Size of item (1 byte for a char!)
922 len, // How many bytes to print?
923 UINT32_MAX, // num per line
924 LLDB_INVALID_ADDRESS,// base address
925 0, // bitfield bit size
926 0); // bitfield bit offset
927
928 if (len < k_max_buf_size)
929 break;
Enrico Granata9128ee22011-09-06 19:20:51 +0000930
Enrico Granataf4efecd2011-07-12 22:56:10 +0000931 if (len >= cstr_len)
Greg Clayton8dd5c172011-10-05 22:19:51 +0000932 {
933 capped_cstr = true;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000934 break;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000935 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000936
Enrico Granataf4efecd2011-07-12 22:56:10 +0000937 cstr_len -= len;
Enrico Granata9128ee22011-09-06 19:20:51 +0000938 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000939 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000940
Greg Clayton8dd5c172011-10-05 22:19:51 +0000941 if (cstr_len_displayed >= 0)
Enrico Granata9128ee22011-09-06 19:20:51 +0000942 {
943 s << '"';
Greg Clayton8dd5c172011-10-05 22:19:51 +0000944 if (capped_cstr)
Enrico Granata9128ee22011-09-06 19:20:51 +0000945 s << "...";
946 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000947 }
948 }
949 }
950 }
951 }
952 else
953 {
954 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +0000955 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000956 }
957}
958
Jim Ingham53c47f12010-09-10 23:12:17 +0000959const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000960ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +0000961{
Enrico Granata0a3958e2011-07-02 00:25:22 +0000962
Enrico Granatad8b5fce2011-08-02 23:12:24 +0000963 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +0000964 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000965
966 if (!m_object_desc_str.empty())
967 return m_object_desc_str.c_str();
968
Jim Ingham6035b672011-03-31 00:19:25 +0000969 ExecutionContextScope *exe_scope = GetExecutionContextScope();
970 if (exe_scope == NULL)
971 return NULL;
972
Jim Ingham53c47f12010-09-10 23:12:17 +0000973 Process *process = exe_scope->CalculateProcess();
Jim Ingham5a369122010-09-28 01:25:32 +0000974 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +0000975 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +0000976
Jim Ingham53c47f12010-09-10 23:12:17 +0000977 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +0000978
Greg Claytonafacd142011-09-02 01:15:17 +0000979 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +0000980 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
981
Jim Inghama2cf2632010-12-23 02:29:54 +0000982 if (runtime == NULL)
983 {
Jim Inghamb7603bb2011-03-18 00:05:18 +0000984 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +0000985 clang_type_t opaque_qual_type = GetClangType();
986 if (opaque_qual_type != NULL)
987 {
Jim Inghamb7603bb2011-03-18 00:05:18 +0000988 bool is_signed;
989 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
990 || ClangASTContext::IsPointerType (opaque_qual_type))
991 {
Greg Claytonafacd142011-09-02 01:15:17 +0000992 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +0000993 }
Jim Inghama2cf2632010-12-23 02:29:54 +0000994 }
995 }
996
Jim Ingham8d543de2011-03-31 23:01:21 +0000997 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +0000998 {
999 m_object_desc_str.append (s.GetData());
1000 }
Sean Callanan672ad942010-10-23 00:18:49 +00001001
1002 if (m_object_desc_str.empty())
1003 return NULL;
1004 else
1005 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001006}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001007
1008const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001009ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001010{
1011 // If our byte size is zero this is an aggregate type that has children
Greg Clayton1be10fc2010-09-29 01:12:09 +00001012 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001013 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00001014 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001015 {
1016 if (m_value_str.empty())
1017 {
1018 const Value::ContextType context_type = m_value.GetContextType();
1019
1020 switch (context_type)
1021 {
Greg Clayton526e5af2010-11-13 03:52:47 +00001022 case Value::eContextTypeClangType:
1023 case Value::eContextTypeLLDBType:
1024 case Value::eContextTypeVariable:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001025 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001026 lldb::Format my_format = GetFormat();
Greg Clayton73b472d2010-10-27 03:32:59 +00001027 clang_type_t clang_type = GetClangType ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001028 if (clang_type)
1029 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001030 if (m_format == lldb::eFormatDefault)
Enrico Granata4becb372011-06-29 22:27:15 +00001031 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001032 if (m_last_value_format)
1033 my_format = m_last_value_format->GetFormat();
Enrico Granataf2bbf712011-07-15 02:26:42 +00001034 else
1035 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001036 if (m_is_bitfield_for_scalar)
1037 my_format = eFormatUnsigned;
1038 else
1039 my_format = ClangASTType::GetFormat(clang_type);
Enrico Granataf2bbf712011-07-15 02:26:42 +00001040 }
Greg Clayton007d5be2011-05-30 00:49:24 +00001041 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001042 StreamString sstr;
1043 if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1044 clang_type, // The clang type to display
1045 &sstr,
1046 my_format, // Format to display this type with
1047 m_data, // Data to extract from
1048 0, // Byte offset into "m_data"
1049 GetByteSize(), // Byte size of item in "m_data"
1050 GetBitfieldBitSize(), // Bitfield bit size
Greg Clayton5009f9d2011-10-27 17:55:14 +00001051 GetBitfieldBitOffset(),
1052 GetExecutionContextScope())) // Bitfield bit offset
Enrico Granata9128ee22011-09-06 19:20:51 +00001053 m_value_str.swap(sstr.GetString());
1054 else
1055 {
Jason Molenda7e589a62011-09-20 00:26:08 +00001056 m_error.SetErrorStringWithFormat ("unsufficient data for value (only %lu of %lu bytes available)",
Enrico Granata9128ee22011-09-06 19:20:51 +00001057 m_data.GetByteSize(),
1058 GetByteSize());
1059 m_value_str.clear();
1060 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001061 }
1062 }
1063 break;
1064
Greg Clayton526e5af2010-11-13 03:52:47 +00001065 case Value::eContextTypeRegisterInfo:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001066 {
1067 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1068 if (reg_info)
1069 {
1070 StreamString reg_sstr;
Greg Clayton5009f9d2011-10-27 17:55:14 +00001071 m_data.Dump(&reg_sstr, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0, GetExecutionContextScope());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001072 m_value_str.swap(reg_sstr.GetString());
1073 }
1074 }
1075 break;
Greg Claytonc982c762010-07-09 20:39:50 +00001076
1077 default:
1078 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001079 }
1080 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001081
1082 if (!m_value_did_change && m_old_value_valid)
1083 {
1084 // The value was gotten successfully, so we consider the
1085 // value as changed if the value string differs
1086 SetValueDidChange (m_old_value_str != m_value_str);
1087 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001088 }
1089 }
1090 if (m_value_str.empty())
1091 return NULL;
1092 return m_value_str.c_str();
1093}
1094
Enrico Granatac3e320a2011-08-02 17:27:39 +00001095// if > 8bytes, 0 is returned. this method should mostly be used
1096// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001097uint64_t
1098ValueObject::GetValueAsUnsigned (uint64_t fail_value)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001099{
1100 // If our byte size is zero this is an aggregate type that has children
1101 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1102 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001103 Scalar scalar;
1104 if (ResolveValue (scalar))
1105 return scalar.GetRawBits64(fail_value);
Enrico Granatac3e320a2011-08-02 17:27:39 +00001106 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001107 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001108}
1109
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001110bool
1111ValueObject::GetPrintableRepresentation(Stream& s,
1112 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001113 Format custom_format)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001114{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001115
Greg Claytonafacd142011-09-02 01:15:17 +00001116 if (custom_format != eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001117 SetFormat(custom_format);
1118
1119 const char * return_value;
Enrico Granatacd1c0232011-08-04 23:37:18 +00001120 std::string alloc_mem;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001121
1122 switch(val_obj_display)
1123 {
1124 case eDisplayValue:
1125 return_value = GetValueAsCString();
1126 break;
1127 case eDisplaySummary:
Enrico Granata855cd902011-09-06 22:59:55 +00001128 if (m_trying_summary_already)
1129 return_value = NULL;
1130 else
1131 {
1132 m_trying_summary_already = true;
1133 return_value = GetSummaryAsCString();
1134 m_trying_summary_already = false;
1135 break;
1136 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001137 case eDisplayLanguageSpecific:
1138 return_value = GetObjectDescription();
1139 break;
Enrico Granataf2bbf712011-07-15 02:26:42 +00001140 case eDisplayLocation:
1141 return_value = GetLocationAsCString();
1142 break;
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001143 case eDisplayChildrenCount:
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001144 {
Enrico Granatacd1c0232011-08-04 23:37:18 +00001145 alloc_mem.resize(512);
1146 return_value = &alloc_mem[0];
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001147 int count = GetNumChildren();
Enrico Granatacd1c0232011-08-04 23:37:18 +00001148 snprintf((char*)return_value, 512, "%d", count);
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001149 break;
1150 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001151 case eDisplayType:
1152 return_value = GetTypeName().AsCString();
1153 break;
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001154 default:
1155 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001156 }
1157
Enrico Granata855cd902011-09-06 22:59:55 +00001158 if (!return_value)
Enrico Granata9fc19442011-07-06 02:13:41 +00001159 {
Enrico Granata9fc19442011-07-06 02:13:41 +00001160 if (val_obj_display == eDisplayValue)
Enrico Granata855cd902011-09-06 22:59:55 +00001161 return_value = GetSummaryAsCString();
Enrico Granata9fc19442011-07-06 02:13:41 +00001162 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +00001163 {
1164 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1165 {
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001166 // this thing has no value, and it seems to have no summary
1167 // some combination of unitialized data and other factors can also
Enrico Granata855cd902011-09-06 22:59:55 +00001168 // raise this condition, so let's print a nice generic description
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001169 {
1170 alloc_mem.resize(684);
1171 return_value = &alloc_mem[0];
1172 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1173 }
Enrico Granatae992a082011-07-22 17:03:19 +00001174 }
1175 else
1176 return_value = GetValueAsCString();
1177 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001178 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001179
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001180 if (return_value)
1181 s.PutCString(return_value);
1182 else
Enrico Granata88da35f2011-08-23 21:26:09 +00001183 {
1184 if (m_error.Fail())
1185 s.Printf("<%s>", m_error.AsCString());
1186 else if (val_obj_display == eDisplaySummary)
1187 s.PutCString("<no summary available>");
1188 else if (val_obj_display == eDisplayValue)
1189 s.PutCString("<no value available>");
1190 else if (val_obj_display == eDisplayLanguageSpecific)
1191 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1192 else
1193 s.PutCString("<no printable representation>");
1194 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001195
1196 // we should only return false here if we could not do *anything*
1197 // even if we have an error message as output, that's a success
1198 // from our callers' perspective, so return true
1199 return true;
1200
Enrico Granata0a3958e2011-07-02 00:25:22 +00001201}
1202
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001203// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1204// this call up to date by returning true for your new special cases. We will eventually move
1205// to checking this call result before trying to display special cases
1206bool
1207ValueObject::HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001208 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001209{
1210 clang_type_t elem_or_pointee_type;
1211 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1212
1213 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1214 && val_obj_display == ValueObject::eDisplayValue)
1215 {
1216 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001217 (custom_format == eFormatCString ||
1218 custom_format == eFormatCharArray ||
1219 custom_format == eFormatChar ||
1220 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001221 return true;
1222
1223 if (flags.Test(ClangASTContext::eTypeIsArray))
1224 {
Greg Claytonafacd142011-09-02 01:15:17 +00001225 if ((custom_format == eFormatBytes) ||
1226 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001227 return true;
1228
Greg Claytonafacd142011-09-02 01:15:17 +00001229 if ((custom_format == eFormatVectorOfChar) ||
1230 (custom_format == eFormatVectorOfFloat32) ||
1231 (custom_format == eFormatVectorOfFloat64) ||
1232 (custom_format == eFormatVectorOfSInt16) ||
1233 (custom_format == eFormatVectorOfSInt32) ||
1234 (custom_format == eFormatVectorOfSInt64) ||
1235 (custom_format == eFormatVectorOfSInt8) ||
1236 (custom_format == eFormatVectorOfUInt128) ||
1237 (custom_format == eFormatVectorOfUInt16) ||
1238 (custom_format == eFormatVectorOfUInt32) ||
1239 (custom_format == eFormatVectorOfUInt64) ||
1240 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001241 return true;
1242 }
1243 }
1244 return false;
1245}
1246
Enrico Granata9fc19442011-07-06 02:13:41 +00001247bool
1248ValueObject::DumpPrintableRepresentation(Stream& s,
1249 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001250 Format custom_format,
Enrico Granata85933ed2011-08-18 16:38:26 +00001251 bool only_special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001252{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001253
1254 clang_type_t elem_or_pointee_type;
1255 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001256
Enrico Granataf4efecd2011-07-12 22:56:10 +00001257 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1258 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001259 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001260 // when being asked to get a printable display an array or pointer type directly,
1261 // try to "do the right thing"
1262
1263 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001264 (custom_format == eFormatCString ||
1265 custom_format == eFormatCharArray ||
1266 custom_format == eFormatChar ||
1267 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001268 {
1269 Error error;
1270 ReadPointedString(s,
1271 error,
1272 0,
Greg Claytonafacd142011-09-02 01:15:17 +00001273 (custom_format == eFormatVectorOfChar) ||
1274 (custom_format == eFormatCharArray));
Enrico Granataf4efecd2011-07-12 22:56:10 +00001275 return !error.Fail();
1276 }
1277
Greg Claytonafacd142011-09-02 01:15:17 +00001278 if (custom_format == eFormatEnum)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001279 return false;
1280
1281 // this only works for arrays, because I have no way to know when
1282 // the pointed memory ends, and no special \0 end of data marker
1283 if (flags.Test(ClangASTContext::eTypeIsArray))
1284 {
Greg Claytonafacd142011-09-02 01:15:17 +00001285 if ((custom_format == eFormatBytes) ||
1286 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001287 {
1288 uint32_t count = GetNumChildren();
1289
1290 s << '[';
1291 for (uint32_t low = 0; low < count; low++)
1292 {
1293
1294 if (low)
1295 s << ',';
1296
1297 ValueObjectSP child = GetChildAtIndex(low,true);
1298 if (!child.get())
1299 {
Enrico Granatae992a082011-07-22 17:03:19 +00001300 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001301 continue;
1302 }
1303 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1304 }
1305
1306 s << ']';
1307
1308 return true;
1309 }
1310
Greg Claytonafacd142011-09-02 01:15:17 +00001311 if ((custom_format == eFormatVectorOfChar) ||
1312 (custom_format == eFormatVectorOfFloat32) ||
1313 (custom_format == eFormatVectorOfFloat64) ||
1314 (custom_format == eFormatVectorOfSInt16) ||
1315 (custom_format == eFormatVectorOfSInt32) ||
1316 (custom_format == eFormatVectorOfSInt64) ||
1317 (custom_format == eFormatVectorOfSInt8) ||
1318 (custom_format == eFormatVectorOfUInt128) ||
1319 (custom_format == eFormatVectorOfUInt16) ||
1320 (custom_format == eFormatVectorOfUInt32) ||
1321 (custom_format == eFormatVectorOfUInt64) ||
1322 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001323 {
1324 uint32_t count = GetNumChildren();
1325
Greg Claytonafacd142011-09-02 01:15:17 +00001326 Format format = FormatManager::GetSingleItemFormat(custom_format);
Enrico Granataf4efecd2011-07-12 22:56:10 +00001327
1328 s << '[';
1329 for (uint32_t low = 0; low < count; low++)
1330 {
1331
1332 if (low)
1333 s << ',';
1334
1335 ValueObjectSP child = GetChildAtIndex(low,true);
1336 if (!child.get())
1337 {
Enrico Granatae992a082011-07-22 17:03:19 +00001338 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001339 continue;
1340 }
1341 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1342 }
1343
1344 s << ']';
1345
1346 return true;
1347 }
1348 }
1349
Greg Claytonafacd142011-09-02 01:15:17 +00001350 if ((custom_format == eFormatBoolean) ||
1351 (custom_format == eFormatBinary) ||
1352 (custom_format == eFormatChar) ||
1353 (custom_format == eFormatCharPrintable) ||
1354 (custom_format == eFormatComplexFloat) ||
1355 (custom_format == eFormatDecimal) ||
1356 (custom_format == eFormatHex) ||
1357 (custom_format == eFormatFloat) ||
1358 (custom_format == eFormatOctal) ||
1359 (custom_format == eFormatOSType) ||
1360 (custom_format == eFormatUnicode16) ||
1361 (custom_format == eFormatUnicode32) ||
1362 (custom_format == eFormatUnsigned) ||
1363 (custom_format == eFormatPointer) ||
1364 (custom_format == eFormatComplexInteger) ||
1365 (custom_format == eFormatComplex) ||
1366 (custom_format == eFormatDefault)) // use the [] operator
Enrico Granataf4efecd2011-07-12 22:56:10 +00001367 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001368 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001369
1370 if (only_special)
1371 return false;
1372
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001373 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001374 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001375 SetFormat(eFormatDefault);
1376 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001377}
1378
Greg Clayton737b9322010-09-13 03:32:57 +00001379addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001380ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001381{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001382 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001383 return LLDB_INVALID_ADDRESS;
1384
Greg Clayton73b472d2010-10-27 03:32:59 +00001385 switch (m_value.GetValueType())
1386 {
1387 case Value::eValueTypeScalar:
1388 if (scalar_is_load_address)
1389 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001390 if(address_type)
1391 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001392 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1393 }
1394 break;
1395
1396 case Value::eValueTypeLoadAddress:
1397 case Value::eValueTypeFileAddress:
1398 case Value::eValueTypeHostAddress:
1399 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001400 if(address_type)
1401 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001402 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1403 }
1404 break;
1405 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001406 if (address_type)
1407 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001408 return LLDB_INVALID_ADDRESS;
1409}
1410
1411addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001412ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001413{
Greg Claytonafacd142011-09-02 01:15:17 +00001414 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001415 if(address_type)
1416 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001417
Enrico Granatac3e320a2011-08-02 17:27:39 +00001418 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001419 return address;
1420
Greg Clayton73b472d2010-10-27 03:32:59 +00001421 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001422 {
1423 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001424 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001425 break;
1426
Enrico Granata9128ee22011-09-06 19:20:51 +00001427 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001428 case Value::eValueTypeLoadAddress:
1429 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001430 {
1431 uint32_t data_offset = 0;
1432 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001433 }
1434 break;
1435 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001436
Enrico Granata9128ee22011-09-06 19:20:51 +00001437 if (address_type)
1438 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001439
Greg Clayton737b9322010-09-13 03:32:57 +00001440 return address;
1441}
1442
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001443bool
Jim Ingham6035b672011-03-31 00:19:25 +00001444ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001445{
1446 // Make sure our value is up to date first so that our location and location
1447 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001448 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001449 return false;
1450
1451 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001452 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001453
Greg Claytonb1320972010-07-14 00:18:15 +00001454 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001455
Jim Ingham16e0c682011-08-12 23:34:31 +00001456 Value::ValueType value_type = m_value.GetValueType();
1457
1458 if (value_type == Value::eValueTypeScalar)
1459 {
1460 // If the value is already a scalar, then let the scalar change itself:
1461 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1462 }
1463 else if (byte_size <= Scalar::GetMaxByteSize())
1464 {
1465 // If the value fits in a scalar, then make a new scalar and again let the
1466 // scalar code do the conversion, then figure out where to put the new value.
1467 Scalar new_scalar;
1468 Error error;
1469 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1470 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001471 {
Jim Ingham4b536182011-08-09 02:12:22 +00001472 switch (value_type)
1473 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001474 case Value::eValueTypeLoadAddress:
1475 {
1476 // If it is a load address, then the scalar value is the storage location
1477 // of the data, and we have to shove this value down to that load location.
1478 ProcessSP process_sp = GetUpdatePoint().GetProcessSP();
1479 if (process_sp)
1480 {
Greg Claytonafacd142011-09-02 01:15:17 +00001481 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Jim Ingham16e0c682011-08-12 23:34:31 +00001482 size_t bytes_written = process_sp->WriteScalarToMemory (target_addr,
1483 new_scalar,
1484 byte_size,
1485 error);
1486 if (!error.Success() || bytes_written != byte_size)
1487 return false;
1488 }
1489 }
Jim Ingham4b536182011-08-09 02:12:22 +00001490 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001491 case Value::eValueTypeHostAddress:
1492 {
1493 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1494 DataExtractor new_data;
1495 new_data.SetByteOrder (m_data.GetByteOrder());
1496
1497 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1498 m_data.SetData(buffer_sp, 0);
1499 bool success = new_scalar.GetData(new_data);
1500 if (success)
1501 {
1502 new_data.CopyByteOrderedData(0,
1503 byte_size,
1504 const_cast<uint8_t *>(m_data.GetDataStart()),
1505 byte_size,
1506 m_data.GetByteOrder());
1507 }
1508 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1509
1510 }
Jim Ingham4b536182011-08-09 02:12:22 +00001511 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001512 case Value::eValueTypeFileAddress:
1513 case Value::eValueTypeScalar:
1514 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001515 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001516 }
1517 else
1518 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001519 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001520 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001521 }
1522 else
1523 {
1524 // We don't support setting things bigger than a scalar at present.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001525 return false;
1526 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001527
1528 // If we have reached this point, then we have successfully changed the value.
1529 SetNeedsUpdate();
1530 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001531}
1532
Greg Claytonafacd142011-09-02 01:15:17 +00001533LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001534ValueObject::GetObjectRuntimeLanguage ()
1535{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001536 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1537 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001538}
1539
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001540void
Jim Ingham58b59f92011-04-22 23:53:53 +00001541ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001542{
Jim Ingham58b59f92011-04-22 23:53:53 +00001543 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001544}
1545
1546ValueObjectSP
1547ValueObject::GetSyntheticChild (const ConstString &key) const
1548{
1549 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001550 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001551 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001552 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001553 return synthetic_child_sp;
1554}
1555
1556bool
1557ValueObject::IsPointerType ()
1558{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001559 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001560}
1561
Jim Inghamb7603bb2011-03-18 00:05:18 +00001562bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001563ValueObject::IsArrayType ()
1564{
1565 return ClangASTContext::IsArrayType (GetClangType());
1566}
1567
1568bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001569ValueObject::IsScalarType ()
1570{
1571 return ClangASTContext::IsScalarType (GetClangType());
1572}
1573
1574bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001575ValueObject::IsIntegerType (bool &is_signed)
1576{
1577 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1578}
Greg Clayton73b472d2010-10-27 03:32:59 +00001579
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001580bool
1581ValueObject::IsPointerOrReferenceType ()
1582{
Greg Clayton007d5be2011-05-30 00:49:24 +00001583 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1584}
1585
1586bool
1587ValueObject::IsPossibleCPlusPlusDynamicType ()
1588{
1589 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001590}
1591
Greg Claytondea8cb42011-06-29 22:09:02 +00001592bool
1593ValueObject::IsPossibleDynamicType ()
1594{
1595 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1596}
1597
Greg Claytonafacd142011-09-02 01:15:17 +00001598ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001599ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1600{
1601 if (IsArrayType())
1602 return GetSyntheticArrayMemberFromArray(index, can_create);
1603
1604 if (IsPointerType())
1605 return GetSyntheticArrayMemberFromPointer(index, can_create);
1606
1607 return ValueObjectSP();
1608
1609}
1610
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001611ValueObjectSP
1612ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1613{
1614 ValueObjectSP synthetic_child_sp;
1615 if (IsPointerType ())
1616 {
1617 char index_str[64];
1618 snprintf(index_str, sizeof(index_str), "[%i]", index);
1619 ConstString index_const_str(index_str);
1620 // Check if we have already created a synthetic array member in this
1621 // valid object. If we have we will re-use it.
1622 synthetic_child_sp = GetSyntheticChild (index_const_str);
1623 if (!synthetic_child_sp)
1624 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001625 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001626 // We haven't made a synthetic array member for INDEX yet, so
1627 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001628 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001629
1630 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001631 if (synthetic_child)
1632 {
1633 AddSyntheticChild(index_const_str, synthetic_child);
1634 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001635 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001636 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001637 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001638 }
1639 }
1640 return synthetic_child_sp;
1641}
Jim Ingham22777012010-09-23 02:01:19 +00001642
Greg Claytondaf515f2011-07-09 20:12:33 +00001643// This allows you to create an array member using and index
1644// that doesn't not fall in the normal bounds of the array.
1645// Many times structure can be defined as:
1646// struct Collection
1647// {
1648// uint32_t item_count;
1649// Item item_array[0];
1650// };
1651// The size of the "item_array" is 1, but many times in practice
1652// there are more items in "item_array".
1653
1654ValueObjectSP
1655ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1656{
1657 ValueObjectSP synthetic_child_sp;
1658 if (IsArrayType ())
1659 {
1660 char index_str[64];
1661 snprintf(index_str, sizeof(index_str), "[%i]", index);
1662 ConstString index_const_str(index_str);
1663 // Check if we have already created a synthetic array member in this
1664 // valid object. If we have we will re-use it.
1665 synthetic_child_sp = GetSyntheticChild (index_const_str);
1666 if (!synthetic_child_sp)
1667 {
1668 ValueObject *synthetic_child;
1669 // We haven't made a synthetic array member for INDEX yet, so
1670 // lets make one and cache it for any future reference.
1671 synthetic_child = CreateChildAtIndex(0, true, index);
1672
1673 // Cache the value if we got one back...
1674 if (synthetic_child)
1675 {
1676 AddSyntheticChild(index_const_str, synthetic_child);
1677 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001678 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001679 synthetic_child_sp->m_is_array_item_for_pointer = true;
1680 }
1681 }
1682 }
1683 return synthetic_child_sp;
1684}
1685
Enrico Granata9fc19442011-07-06 02:13:41 +00001686ValueObjectSP
1687ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1688{
1689 ValueObjectSP synthetic_child_sp;
1690 if (IsScalarType ())
1691 {
1692 char index_str[64];
1693 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1694 ConstString index_const_str(index_str);
1695 // Check if we have already created a synthetic array member in this
1696 // valid object. If we have we will re-use it.
1697 synthetic_child_sp = GetSyntheticChild (index_const_str);
1698 if (!synthetic_child_sp)
1699 {
1700 ValueObjectChild *synthetic_child;
1701 // We haven't made a synthetic array member for INDEX yet, so
1702 // lets make one and cache it for any future reference.
1703 synthetic_child = new ValueObjectChild(*this,
1704 GetClangAST(),
1705 GetClangType(),
1706 index_const_str,
1707 GetByteSize(),
1708 0,
1709 to-from+1,
1710 from,
1711 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001712 false,
1713 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001714
1715 // Cache the value if we got one back...
1716 if (synthetic_child)
1717 {
1718 AddSyntheticChild(index_const_str, synthetic_child);
1719 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001720 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001721 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1722 }
1723 }
1724 }
1725 return synthetic_child_sp;
1726}
1727
Greg Claytonafacd142011-09-02 01:15:17 +00001728ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001729ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1730{
1731 ValueObjectSP synthetic_child_sp;
1732 if (IsArrayType () || IsPointerType ())
1733 {
1734 char index_str[64];
1735 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1736 ConstString index_const_str(index_str);
1737 // Check if we have already created a synthetic array member in this
1738 // valid object. If we have we will re-use it.
1739 synthetic_child_sp = GetSyntheticChild (index_const_str);
1740 if (!synthetic_child_sp)
1741 {
1742 ValueObjectSynthetic *synthetic_child;
1743
1744 // We haven't made a synthetic array member for INDEX yet, so
1745 // lets make one and cache it for any future reference.
1746 SyntheticArrayView *view = new SyntheticArrayView();
1747 view->AddRange(from,to);
1748 SyntheticChildrenSP view_sp(view);
1749 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1750
1751 // Cache the value if we got one back...
1752 if (synthetic_child)
1753 {
1754 AddSyntheticChild(index_const_str, synthetic_child);
1755 synthetic_child_sp = synthetic_child->GetSP();
1756 synthetic_child_sp->SetName(ConstString(index_str));
1757 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1758 }
1759 }
1760 }
1761 return synthetic_child_sp;
1762}
1763
Greg Claytonafacd142011-09-02 01:15:17 +00001764ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001765ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1766{
1767
1768 ValueObjectSP synthetic_child_sp;
1769
1770 char name_str[64];
1771 snprintf(name_str, sizeof(name_str), "@%i", offset);
1772 ConstString name_const_str(name_str);
1773
1774 // Check if we have already created a synthetic array member in this
1775 // valid object. If we have we will re-use it.
1776 synthetic_child_sp = GetSyntheticChild (name_const_str);
1777
1778 if (synthetic_child_sp.get())
1779 return synthetic_child_sp;
1780
1781 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001782 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001783
1784 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1785 type.GetASTContext(),
1786 type.GetOpaqueQualType(),
1787 name_const_str,
1788 type.GetTypeByteSize(),
1789 offset,
1790 0,
1791 0,
1792 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001793 false,
1794 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001795 if (synthetic_child)
1796 {
1797 AddSyntheticChild(name_const_str, synthetic_child);
1798 synthetic_child_sp = synthetic_child->GetSP();
1799 synthetic_child_sp->SetName(name_const_str);
1800 synthetic_child_sp->m_is_child_at_offset = true;
1801 }
1802 return synthetic_child_sp;
1803}
1804
Enrico Granatad55546b2011-07-22 00:16:08 +00001805// your expression path needs to have a leading . or ->
1806// (unless it somehow "looks like" an array, in which case it has
1807// a leading [ symbol). while the [ is meaningful and should be shown
1808// to the user, . and -> are just parser design, but by no means
1809// added information for the user.. strip them off
1810static const char*
1811SkipLeadingExpressionPathSeparators(const char* expression)
1812{
1813 if (!expression || !expression[0])
1814 return expression;
1815 if (expression[0] == '.')
1816 return expression+1;
1817 if (expression[0] == '-' && expression[1] == '>')
1818 return expression+2;
1819 return expression;
1820}
1821
Greg Claytonafacd142011-09-02 01:15:17 +00001822ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00001823ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1824{
1825 ValueObjectSP synthetic_child_sp;
1826 ConstString name_const_string(expression);
1827 // Check if we have already created a synthetic array member in this
1828 // valid object. If we have we will re-use it.
1829 synthetic_child_sp = GetSyntheticChild (name_const_string);
1830 if (!synthetic_child_sp)
1831 {
1832 // We haven't made a synthetic array member for expression yet, so
1833 // lets make one and cache it for any future reference.
1834 synthetic_child_sp = GetValueForExpressionPath(expression);
1835
1836 // Cache the value if we got one back...
1837 if (synthetic_child_sp.get())
1838 {
1839 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001840 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001841 synthetic_child_sp->m_is_expression_path_child = true;
1842 }
1843 }
1844 return synthetic_child_sp;
1845}
1846
1847void
Greg Claytonafacd142011-09-02 01:15:17 +00001848ValueObject::CalculateSyntheticValue (SyntheticValueType use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00001849{
Greg Claytonafacd142011-09-02 01:15:17 +00001850 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001851 return;
1852
Enrico Granatac3e320a2011-08-02 17:27:39 +00001853 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001854
1855 if (m_last_synthetic_filter.get() == NULL)
1856 return;
1857
Enrico Granataa37a0652011-07-24 00:14:56 +00001858 if (m_synthetic_value == NULL)
1859 m_synthetic_value = new ValueObjectSynthetic(*this, m_last_synthetic_filter);
Enrico Granatad55546b2011-07-22 00:16:08 +00001860
1861}
1862
Jim Ingham78a685a2011-04-16 00:01:13 +00001863void
Greg Claytonafacd142011-09-02 01:15:17 +00001864ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00001865{
Greg Claytonafacd142011-09-02 01:15:17 +00001866 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00001867 return;
1868
Jim Ingham58b59f92011-04-22 23:53:53 +00001869 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00001870 {
Enrico Granata6f3533f2011-07-29 19:53:35 +00001871 Process *process = m_update_point.GetProcessSP().get();
Jim Ingham78a685a2011-04-16 00:01:13 +00001872 bool worth_having_dynamic_value = false;
Jim Ingham22777012010-09-23 02:01:19 +00001873
Jim Ingham78a685a2011-04-16 00:01:13 +00001874
1875 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
1876 // hard code this everywhere.
Greg Claytonafacd142011-09-02 01:15:17 +00001877 LanguageType known_type = GetObjectRuntimeLanguage();
1878 if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
Jim Ingham78a685a2011-04-16 00:01:13 +00001879 {
1880 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
1881 if (runtime)
1882 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
1883 }
1884 else
1885 {
Greg Claytonafacd142011-09-02 01:15:17 +00001886 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus);
Jim Ingham78a685a2011-04-16 00:01:13 +00001887 if (cpp_runtime)
1888 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
1889
1890 if (!worth_having_dynamic_value)
1891 {
Greg Claytonafacd142011-09-02 01:15:17 +00001892 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC);
Jim Ingham78a685a2011-04-16 00:01:13 +00001893 if (objc_runtime)
Jim Ingham2837b762011-05-04 03:43:18 +00001894 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00001895 }
1896 }
1897
1898 if (worth_having_dynamic_value)
Jim Ingham2837b762011-05-04 03:43:18 +00001899 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham58b59f92011-04-22 23:53:53 +00001900
1901// if (worth_having_dynamic_value)
1902// printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager);
1903
Jim Ingham78a685a2011-04-16 00:01:13 +00001904 }
1905}
1906
Jim Ingham58b59f92011-04-22 23:53:53 +00001907ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00001908ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00001909{
Greg Claytonafacd142011-09-02 01:15:17 +00001910 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00001911 return ValueObjectSP();
1912
1913 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00001914 {
Jim Ingham2837b762011-05-04 03:43:18 +00001915 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001916 }
Jim Ingham58b59f92011-04-22 23:53:53 +00001917 if (m_dynamic_value)
1918 return m_dynamic_value->GetSP();
1919 else
1920 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00001921}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001922
Jim Ingham60dbabb2011-12-08 19:44:08 +00001923ValueObjectSP
1924ValueObject::GetStaticValue()
1925{
1926 return GetSP();
1927}
1928
Enrico Granatad55546b2011-07-22 00:16:08 +00001929// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
1930// or we do not really want a dynamic VO. this method instead returns this object
1931// itself when making it synthetic has no meaning. this makes it much simpler
1932// to replace the SyntheticValue for the ValueObject
1933ValueObjectSP
1934ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
1935{
Greg Claytonafacd142011-09-02 01:15:17 +00001936 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001937 return GetSP();
1938
Enrico Granatac3e320a2011-08-02 17:27:39 +00001939 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001940
1941 if (m_last_synthetic_filter.get() == NULL)
1942 return GetSP();
1943
1944 CalculateSyntheticValue(use_synthetic);
1945
1946 if (m_synthetic_value)
1947 return m_synthetic_value->GetSP();
1948 else
1949 return GetSP();
1950}
1951
Greg Claytone221f822011-01-21 01:59:00 +00001952bool
Enrico Granata27b625e2011-08-09 01:04:56 +00001953ValueObject::HasSyntheticValue()
1954{
1955 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
1956
1957 if (m_last_synthetic_filter.get() == NULL)
1958 return false;
1959
Greg Claytonafacd142011-09-02 01:15:17 +00001960 CalculateSyntheticValue(eUseSyntheticFilter);
Enrico Granata27b625e2011-08-09 01:04:56 +00001961
1962 if (m_synthetic_value)
1963 return true;
1964 else
1965 return false;
1966}
1967
1968bool
Greg Claytone221f822011-01-21 01:59:00 +00001969ValueObject::GetBaseClassPath (Stream &s)
1970{
1971 if (IsBaseClass())
1972 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001973 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00001974 clang_type_t clang_type = GetClangType();
1975 std::string cxx_class_name;
1976 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
1977 if (this_had_base_class)
1978 {
1979 if (parent_had_base_class)
1980 s.PutCString("::");
1981 s.PutCString(cxx_class_name.c_str());
1982 }
1983 return parent_had_base_class || this_had_base_class;
1984 }
1985 return false;
1986}
1987
1988
1989ValueObject *
1990ValueObject::GetNonBaseClassParent()
1991{
Jim Ingham78a685a2011-04-16 00:01:13 +00001992 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00001993 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001994 if (GetParent()->IsBaseClass())
1995 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00001996 else
Jim Ingham78a685a2011-04-16 00:01:13 +00001997 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00001998 }
1999 return NULL;
2000}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002001
2002void
Enrico Granata4becb372011-06-29 22:27:15 +00002003ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002004{
Greg Claytone221f822011-01-21 01:59:00 +00002005 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002006
Enrico Granata85933ed2011-08-18 16:38:26 +00002007 if (is_deref_of_parent && epformat == eDereferencePointers)
2008 {
Enrico Granata4becb372011-06-29 22:27:15 +00002009 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2010 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2011 // the eHonorPointers mode is meant to produce strings in this latter format
2012 s.PutCString("*(");
2013 }
Greg Claytone221f822011-01-21 01:59:00 +00002014
Enrico Granata4becb372011-06-29 22:27:15 +00002015 ValueObject* parent = GetParent();
2016
2017 if (parent)
2018 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002019
2020 // if we are a deref_of_parent just because we are synthetic array
2021 // members made up to allow ptr[%d] syntax to work in variable
2022 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00002023 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002024 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002025
Greg Claytone221f822011-01-21 01:59:00 +00002026 if (!IsBaseClass())
2027 {
2028 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002029 {
Greg Claytone221f822011-01-21 01:59:00 +00002030 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2031 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002032 {
Greg Claytone221f822011-01-21 01:59:00 +00002033 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2034 if (non_base_class_parent_clang_type)
2035 {
2036 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2037
Enrico Granata9dd75c82011-07-15 23:30:15 +00002038 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002039 {
2040 s.PutCString("->");
2041 }
Enrico Granata4becb372011-06-29 22:27:15 +00002042 else
2043 {
2044 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2045 {
2046 s.PutCString("->");
2047 }
2048 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2049 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2050 {
2051 s.PutChar('.');
2052 }
Greg Claytone221f822011-01-21 01:59:00 +00002053 }
2054 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002055 }
Greg Claytone221f822011-01-21 01:59:00 +00002056
2057 const char *name = GetName().GetCString();
2058 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002059 {
Greg Claytone221f822011-01-21 01:59:00 +00002060 if (qualify_cxx_base_classes)
2061 {
2062 if (GetBaseClassPath (s))
2063 s.PutCString("::");
2064 }
2065 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002066 }
2067 }
2068 }
2069
Enrico Granata85933ed2011-08-18 16:38:26 +00002070 if (is_deref_of_parent && epformat == eDereferencePointers)
2071 {
Greg Claytone221f822011-01-21 01:59:00 +00002072 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002073 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002074}
2075
Greg Claytonafacd142011-09-02 01:15:17 +00002076ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002077ValueObject::GetValueForExpressionPath(const char* expression,
2078 const char** first_unparsed,
2079 ExpressionPathScanEndReason* reason_to_stop,
2080 ExpressionPathEndResultType* final_value_type,
2081 const GetValueForExpressionPathOptions& options,
2082 ExpressionPathAftermath* final_task_on_target)
2083{
2084
2085 const char* dummy_first_unparsed;
2086 ExpressionPathScanEndReason dummy_reason_to_stop;
2087 ExpressionPathEndResultType dummy_final_value_type;
2088 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2089
2090 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2091 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2092 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2093 final_value_type ? final_value_type : &dummy_final_value_type,
2094 options,
2095 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2096
2097 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2098 {
2099 return ret_val;
2100 }
2101 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2102 {
2103 if (*final_task_on_target == ValueObject::eDereference)
2104 {
2105 Error error;
2106 ValueObjectSP final_value = ret_val->Dereference(error);
2107 if (error.Fail() || !final_value.get())
2108 {
2109 *reason_to_stop = ValueObject::eDereferencingFailed;
2110 *final_value_type = ValueObject::eInvalid;
2111 return ValueObjectSP();
2112 }
2113 else
2114 {
2115 *final_task_on_target = ValueObject::eNothing;
2116 return final_value;
2117 }
2118 }
2119 if (*final_task_on_target == ValueObject::eTakeAddress)
2120 {
2121 Error error;
2122 ValueObjectSP final_value = ret_val->AddressOf(error);
2123 if (error.Fail() || !final_value.get())
2124 {
2125 *reason_to_stop = ValueObject::eTakingAddressFailed;
2126 *final_value_type = ValueObject::eInvalid;
2127 return ValueObjectSP();
2128 }
2129 else
2130 {
2131 *final_task_on_target = ValueObject::eNothing;
2132 return final_value;
2133 }
2134 }
2135 }
2136 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2137}
2138
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002139int
2140ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002141 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002142 const char** first_unparsed,
2143 ExpressionPathScanEndReason* reason_to_stop,
2144 ExpressionPathEndResultType* final_value_type,
2145 const GetValueForExpressionPathOptions& options,
2146 ExpressionPathAftermath* final_task_on_target)
2147{
2148 const char* dummy_first_unparsed;
2149 ExpressionPathScanEndReason dummy_reason_to_stop;
2150 ExpressionPathEndResultType dummy_final_value_type;
2151 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2152
2153 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2154 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2155 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2156 final_value_type ? final_value_type : &dummy_final_value_type,
2157 options,
2158 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2159
2160 if (!ret_val.get()) // if there are errors, I add nothing to the list
2161 return 0;
2162
2163 if (*reason_to_stop != eArrayRangeOperatorMet)
2164 {
2165 // I need not expand a range, just post-process the final value and return
2166 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2167 {
2168 list->Append(ret_val);
2169 return 1;
2170 }
2171 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2172 {
2173 if (*final_task_on_target == ValueObject::eDereference)
2174 {
2175 Error error;
2176 ValueObjectSP final_value = ret_val->Dereference(error);
2177 if (error.Fail() || !final_value.get())
2178 {
2179 *reason_to_stop = ValueObject::eDereferencingFailed;
2180 *final_value_type = ValueObject::eInvalid;
2181 return 0;
2182 }
2183 else
2184 {
2185 *final_task_on_target = ValueObject::eNothing;
2186 list->Append(final_value);
2187 return 1;
2188 }
2189 }
2190 if (*final_task_on_target == ValueObject::eTakeAddress)
2191 {
2192 Error error;
2193 ValueObjectSP final_value = ret_val->AddressOf(error);
2194 if (error.Fail() || !final_value.get())
2195 {
2196 *reason_to_stop = ValueObject::eTakingAddressFailed;
2197 *final_value_type = ValueObject::eInvalid;
2198 return 0;
2199 }
2200 else
2201 {
2202 *final_task_on_target = ValueObject::eNothing;
2203 list->Append(final_value);
2204 return 1;
2205 }
2206 }
2207 }
2208 }
2209 else
2210 {
2211 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2212 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2213 ret_val,
2214 list,
2215 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2216 final_value_type ? final_value_type : &dummy_final_value_type,
2217 options,
2218 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2219 }
2220 // in any non-covered case, just do the obviously right thing
2221 list->Append(ret_val);
2222 return 1;
2223}
2224
Greg Claytonafacd142011-09-02 01:15:17 +00002225ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002226ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2227 const char** first_unparsed,
2228 ExpressionPathScanEndReason* reason_to_stop,
2229 ExpressionPathEndResultType* final_result,
2230 const GetValueForExpressionPathOptions& options,
2231 ExpressionPathAftermath* what_next)
2232{
2233 ValueObjectSP root = GetSP();
2234
2235 if (!root.get())
2236 return ValueObjectSP();
2237
2238 *first_unparsed = expression_cstr;
2239
2240 while (true)
2241 {
2242
2243 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2244
Greg Claytonafacd142011-09-02 01:15:17 +00002245 clang_type_t root_clang_type = root->GetClangType();
2246 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002247 Flags root_clang_type_info,pointee_clang_type_info;
2248
2249 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2250 if (pointee_clang_type)
2251 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002252
2253 if (!expression_cstr || *expression_cstr == '\0')
2254 {
2255 *reason_to_stop = ValueObject::eEndOfString;
2256 return root;
2257 }
2258
2259 switch (*expression_cstr)
2260 {
2261 case '-':
2262 {
2263 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002264 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 +00002265 {
2266 *first_unparsed = expression_cstr;
2267 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
2268 *final_result = ValueObject::eInvalid;
2269 return ValueObjectSP();
2270 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002271 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2272 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002273 options.m_no_fragile_ivar)
2274 {
2275 *first_unparsed = expression_cstr;
2276 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
2277 *final_result = ValueObject::eInvalid;
2278 return ValueObjectSP();
2279 }
2280 if (expression_cstr[1] != '>')
2281 {
2282 *first_unparsed = expression_cstr;
2283 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2284 *final_result = ValueObject::eInvalid;
2285 return ValueObjectSP();
2286 }
2287 expression_cstr++; // skip the -
2288 }
2289 case '.': // or fallthrough from ->
2290 {
2291 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002292 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 +00002293 {
2294 *first_unparsed = expression_cstr;
2295 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
2296 *final_result = ValueObject::eInvalid;
2297 return ValueObjectSP();
2298 }
2299 expression_cstr++; // skip .
2300 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2301 ConstString child_name;
2302 if (!next_separator) // if no other separator just expand this last layer
2303 {
2304 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002305 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2306
2307 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002308 {
2309 *first_unparsed = '\0';
2310 *reason_to_stop = ValueObject::eEndOfString;
2311 *final_result = ValueObject::ePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002312 return child_valobj_sp;
2313 }
2314 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2315 {
Greg Clayton4c3b8fb2011-12-02 22:48:25 +00002316 child_valobj_sp = root->GetSyntheticValue(eNoSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002317 }
2318
2319 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2320 // so we hit the "else" branch, and return an error
2321 if(child_valobj_sp.get()) // if it worked, just return
2322 {
2323 *first_unparsed = '\0';
2324 *reason_to_stop = ValueObject::eEndOfString;
2325 *final_result = ValueObject::ePlain;
2326 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002327 }
2328 else
2329 {
2330 *first_unparsed = expression_cstr;
2331 *reason_to_stop = ValueObject::eNoSuchChild;
2332 *final_result = ValueObject::eInvalid;
2333 return ValueObjectSP();
2334 }
2335 }
2336 else // other layers do expand
2337 {
2338 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002339 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2340 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002341 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002342 root = child_valobj_sp;
2343 *first_unparsed = next_separator;
2344 *final_result = ValueObject::ePlain;
2345 continue;
2346 }
2347 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2348 {
Greg Claytonafacd142011-09-02 01:15:17 +00002349 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002350 }
2351
2352 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2353 // so we hit the "else" branch, and return an error
2354 if(child_valobj_sp.get()) // if it worked, move on
2355 {
2356 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002357 *first_unparsed = next_separator;
2358 *final_result = ValueObject::ePlain;
2359 continue;
2360 }
2361 else
2362 {
2363 *first_unparsed = expression_cstr;
2364 *reason_to_stop = ValueObject::eNoSuchChild;
2365 *final_result = ValueObject::eInvalid;
2366 return ValueObjectSP();
2367 }
2368 }
2369 break;
2370 }
2371 case '[':
2372 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002373 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 +00002374 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002375 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002376 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002377 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2378 {
2379 *first_unparsed = expression_cstr;
2380 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2381 *final_result = ValueObject::eInvalid;
2382 return ValueObjectSP();
2383 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002384 }
2385 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2386 {
2387 *first_unparsed = expression_cstr;
2388 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2389 *final_result = ValueObject::eInvalid;
2390 return ValueObjectSP();
2391 }
2392 }
2393 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2394 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002395 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002396 {
2397 *first_unparsed = expression_cstr;
2398 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2399 *final_result = ValueObject::eInvalid;
2400 return ValueObjectSP();
2401 }
2402 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2403 {
2404 *first_unparsed = expression_cstr+2;
2405 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2406 *final_result = ValueObject::eUnboundedRange;
2407 return root;
2408 }
2409 }
2410 const char *separator_position = ::strchr(expression_cstr+1,'-');
2411 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2412 if (!close_bracket_position) // if there is no ], this is a syntax error
2413 {
2414 *first_unparsed = expression_cstr;
2415 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2416 *final_result = ValueObject::eInvalid;
2417 return ValueObjectSP();
2418 }
2419 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2420 {
2421 char *end = NULL;
2422 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2423 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2424 {
2425 *first_unparsed = expression_cstr;
2426 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2427 *final_result = ValueObject::eInvalid;
2428 return ValueObjectSP();
2429 }
2430 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2431 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002432 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002433 {
2434 *first_unparsed = expression_cstr+2;
2435 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2436 *final_result = ValueObject::eUnboundedRange;
2437 return root;
2438 }
2439 else
2440 {
2441 *first_unparsed = expression_cstr;
2442 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2443 *final_result = ValueObject::eInvalid;
2444 return ValueObjectSP();
2445 }
2446 }
2447 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002448 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002449 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002450 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2451 if (!child_valobj_sp)
2452 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002453 if (!child_valobj_sp)
Greg Claytonafacd142011-09-02 01:15:17 +00002454 if (root->HasSyntheticValue() && root->GetSyntheticValue(eUseSyntheticFilter)->GetNumChildren() > index)
2455 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002456 if (child_valobj_sp)
2457 {
2458 root = child_valobj_sp;
2459 *first_unparsed = end+1; // skip ]
2460 *final_result = ValueObject::ePlain;
2461 continue;
2462 }
2463 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002464 {
2465 *first_unparsed = expression_cstr;
2466 *reason_to_stop = ValueObject::eNoSuchChild;
2467 *final_result = ValueObject::eInvalid;
2468 return ValueObjectSP();
2469 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002470 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002471 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002472 {
2473 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 +00002474 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002475 {
2476 Error error;
2477 root = root->Dereference(error);
2478 if (error.Fail() || !root.get())
2479 {
2480 *first_unparsed = expression_cstr;
2481 *reason_to_stop = ValueObject::eDereferencingFailed;
2482 *final_result = ValueObject::eInvalid;
2483 return ValueObjectSP();
2484 }
2485 else
2486 {
2487 *what_next = eNothing;
2488 continue;
2489 }
2490 }
2491 else
2492 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002493 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Claytonafacd142011-09-02 01:15:17 +00002494 root->GetClangType()) == eLanguageTypeObjC
Enrico Granata27b625e2011-08-09 01:04:56 +00002495 &&
2496 ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2497 &&
2498 root->HasSyntheticValue()
2499 &&
2500 options.m_no_synthetic_children == false)
2501 {
Greg Claytonafacd142011-09-02 01:15:17 +00002502 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002503 }
2504 else
2505 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002506 if (!root.get())
2507 {
2508 *first_unparsed = expression_cstr;
2509 *reason_to_stop = ValueObject::eNoSuchChild;
2510 *final_result = ValueObject::eInvalid;
2511 return ValueObjectSP();
2512 }
2513 else
2514 {
2515 *first_unparsed = end+1; // skip ]
2516 *final_result = ValueObject::ePlain;
2517 continue;
2518 }
2519 }
2520 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002521 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002522 {
2523 root = root->GetSyntheticBitFieldChild(index, index, true);
2524 if (!root.get())
2525 {
2526 *first_unparsed = expression_cstr;
2527 *reason_to_stop = ValueObject::eNoSuchChild;
2528 *final_result = ValueObject::eInvalid;
2529 return ValueObjectSP();
2530 }
2531 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2532 {
2533 *first_unparsed = end+1; // skip ]
2534 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2535 *final_result = ValueObject::eBitfield;
2536 return root;
2537 }
2538 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002539 else if (root->HasSyntheticValue() && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002540 {
Greg Claytonafacd142011-09-02 01:15:17 +00002541 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002542 if (!root.get())
2543 {
2544 *first_unparsed = expression_cstr;
2545 *reason_to_stop = ValueObject::eNoSuchChild;
2546 *final_result = ValueObject::eInvalid;
2547 return ValueObjectSP();
2548 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002549 else
2550 {
2551 *first_unparsed = end+1; // skip ]
2552 *final_result = ValueObject::ePlain;
2553 continue;
2554 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002555 }
2556 else
2557 {
2558 *first_unparsed = expression_cstr;
2559 *reason_to_stop = ValueObject::eNoSuchChild;
2560 *final_result = ValueObject::eInvalid;
2561 return ValueObjectSP();
2562 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002563 }
2564 else // we have a low and a high index
2565 {
2566 char *end = NULL;
2567 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2568 if (!end || end != separator_position) // if something weird is in our way return an error
2569 {
2570 *first_unparsed = expression_cstr;
2571 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2572 *final_result = ValueObject::eInvalid;
2573 return ValueObjectSP();
2574 }
2575 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2576 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2577 {
2578 *first_unparsed = expression_cstr;
2579 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2580 *final_result = ValueObject::eInvalid;
2581 return ValueObjectSP();
2582 }
2583 if (index_lower > index_higher) // swap indices if required
2584 {
2585 unsigned long temp = index_lower;
2586 index_lower = index_higher;
2587 index_higher = temp;
2588 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002589 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002590 {
2591 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2592 if (!root.get())
2593 {
2594 *first_unparsed = expression_cstr;
2595 *reason_to_stop = ValueObject::eNoSuchChild;
2596 *final_result = ValueObject::eInvalid;
2597 return ValueObjectSP();
2598 }
2599 else
2600 {
2601 *first_unparsed = end+1; // skip ]
2602 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2603 *final_result = ValueObject::eBitfield;
2604 return root;
2605 }
2606 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002607 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 +00002608 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002609 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002610 {
2611 Error error;
2612 root = root->Dereference(error);
2613 if (error.Fail() || !root.get())
2614 {
2615 *first_unparsed = expression_cstr;
2616 *reason_to_stop = ValueObject::eDereferencingFailed;
2617 *final_result = ValueObject::eInvalid;
2618 return ValueObjectSP();
2619 }
2620 else
2621 {
2622 *what_next = ValueObject::eNothing;
2623 continue;
2624 }
2625 }
2626 else
2627 {
2628 *first_unparsed = expression_cstr;
2629 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2630 *final_result = ValueObject::eBoundedRange;
2631 return root;
2632 }
2633 }
2634 break;
2635 }
2636 default: // some non-separator is in the way
2637 {
2638 *first_unparsed = expression_cstr;
2639 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2640 *final_result = ValueObject::eInvalid;
2641 return ValueObjectSP();
2642 break;
2643 }
2644 }
2645 }
2646}
2647
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002648int
2649ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2650 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002651 ValueObjectSP root,
2652 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002653 ExpressionPathScanEndReason* reason_to_stop,
2654 ExpressionPathEndResultType* final_result,
2655 const GetValueForExpressionPathOptions& options,
2656 ExpressionPathAftermath* what_next)
2657{
2658 if (!root.get())
2659 return 0;
2660
2661 *first_unparsed = expression_cstr;
2662
2663 while (true)
2664 {
2665
2666 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2667
Greg Claytonafacd142011-09-02 01:15:17 +00002668 clang_type_t root_clang_type = root->GetClangType();
2669 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002670 Flags root_clang_type_info,pointee_clang_type_info;
2671
2672 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2673 if (pointee_clang_type)
2674 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2675
2676 if (!expression_cstr || *expression_cstr == '\0')
2677 {
2678 *reason_to_stop = ValueObject::eEndOfString;
2679 list->Append(root);
2680 return 1;
2681 }
2682
2683 switch (*expression_cstr)
2684 {
2685 case '[':
2686 {
2687 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2688 {
2689 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2690 {
2691 *first_unparsed = expression_cstr;
2692 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2693 *final_result = ValueObject::eInvalid;
2694 return 0;
2695 }
2696 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2697 {
2698 *first_unparsed = expression_cstr;
2699 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2700 *final_result = ValueObject::eInvalid;
2701 return 0;
2702 }
2703 }
2704 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2705 {
2706 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2707 {
2708 *first_unparsed = expression_cstr;
2709 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2710 *final_result = ValueObject::eInvalid;
2711 return 0;
2712 }
2713 else // expand this into list
2714 {
2715 int max_index = root->GetNumChildren() - 1;
2716 for (int index = 0; index < max_index; index++)
2717 {
2718 ValueObjectSP child =
2719 root->GetChildAtIndex(index, true);
2720 list->Append(child);
2721 }
2722 *first_unparsed = expression_cstr+2;
2723 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2724 *final_result = ValueObject::eValueObjectList;
2725 return max_index; // tell me number of items I added to the VOList
2726 }
2727 }
2728 const char *separator_position = ::strchr(expression_cstr+1,'-');
2729 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2730 if (!close_bracket_position) // if there is no ], this is a syntax error
2731 {
2732 *first_unparsed = expression_cstr;
2733 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2734 *final_result = ValueObject::eInvalid;
2735 return 0;
2736 }
2737 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2738 {
2739 char *end = NULL;
2740 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2741 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2742 {
2743 *first_unparsed = expression_cstr;
2744 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2745 *final_result = ValueObject::eInvalid;
2746 return 0;
2747 }
2748 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2749 {
2750 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2751 {
2752 int max_index = root->GetNumChildren() - 1;
2753 for (int index = 0; index < max_index; index++)
2754 {
2755 ValueObjectSP child =
2756 root->GetChildAtIndex(index, true);
2757 list->Append(child);
2758 }
2759 *first_unparsed = expression_cstr+2;
2760 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2761 *final_result = ValueObject::eValueObjectList;
2762 return max_index; // tell me number of items I added to the VOList
2763 }
2764 else
2765 {
2766 *first_unparsed = expression_cstr;
2767 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2768 *final_result = ValueObject::eInvalid;
2769 return 0;
2770 }
2771 }
2772 // from here on we do have a valid index
2773 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2774 {
2775 root = root->GetChildAtIndex(index, true);
2776 if (!root.get())
2777 {
2778 *first_unparsed = expression_cstr;
2779 *reason_to_stop = ValueObject::eNoSuchChild;
2780 *final_result = ValueObject::eInvalid;
2781 return 0;
2782 }
2783 else
2784 {
2785 list->Append(root);
2786 *first_unparsed = end+1; // skip ]
2787 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2788 *final_result = ValueObject::eValueObjectList;
2789 return 1;
2790 }
2791 }
2792 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2793 {
2794 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
2795 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2796 {
2797 Error error;
2798 root = root->Dereference(error);
2799 if (error.Fail() || !root.get())
2800 {
2801 *first_unparsed = expression_cstr;
2802 *reason_to_stop = ValueObject::eDereferencingFailed;
2803 *final_result = ValueObject::eInvalid;
2804 return 0;
2805 }
2806 else
2807 {
2808 *what_next = eNothing;
2809 continue;
2810 }
2811 }
2812 else
2813 {
2814 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2815 if (!root.get())
2816 {
2817 *first_unparsed = expression_cstr;
2818 *reason_to_stop = ValueObject::eNoSuchChild;
2819 *final_result = ValueObject::eInvalid;
2820 return 0;
2821 }
2822 else
2823 {
2824 list->Append(root);
2825 *first_unparsed = end+1; // skip ]
2826 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2827 *final_result = ValueObject::eValueObjectList;
2828 return 1;
2829 }
2830 }
2831 }
2832 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2833 {
2834 root = root->GetSyntheticBitFieldChild(index, index, true);
2835 if (!root.get())
2836 {
2837 *first_unparsed = expression_cstr;
2838 *reason_to_stop = ValueObject::eNoSuchChild;
2839 *final_result = ValueObject::eInvalid;
2840 return 0;
2841 }
2842 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2843 {
2844 list->Append(root);
2845 *first_unparsed = end+1; // skip ]
2846 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2847 *final_result = ValueObject::eValueObjectList;
2848 return 1;
2849 }
2850 }
2851 }
2852 else // we have a low and a high index
2853 {
2854 char *end = NULL;
2855 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2856 if (!end || end != separator_position) // if something weird is in our way return an error
2857 {
2858 *first_unparsed = expression_cstr;
2859 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2860 *final_result = ValueObject::eInvalid;
2861 return 0;
2862 }
2863 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2864 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2865 {
2866 *first_unparsed = expression_cstr;
2867 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2868 *final_result = ValueObject::eInvalid;
2869 return 0;
2870 }
2871 if (index_lower > index_higher) // swap indices if required
2872 {
2873 unsigned long temp = index_lower;
2874 index_lower = index_higher;
2875 index_higher = temp;
2876 }
2877 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
2878 {
2879 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2880 if (!root.get())
2881 {
2882 *first_unparsed = expression_cstr;
2883 *reason_to_stop = ValueObject::eNoSuchChild;
2884 *final_result = ValueObject::eInvalid;
2885 return 0;
2886 }
2887 else
2888 {
2889 list->Append(root);
2890 *first_unparsed = end+1; // skip ]
2891 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2892 *final_result = ValueObject::eValueObjectList;
2893 return 1;
2894 }
2895 }
2896 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
2897 *what_next == ValueObject::eDereference &&
2898 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2899 {
2900 Error error;
2901 root = root->Dereference(error);
2902 if (error.Fail() || !root.get())
2903 {
2904 *first_unparsed = expression_cstr;
2905 *reason_to_stop = ValueObject::eDereferencingFailed;
2906 *final_result = ValueObject::eInvalid;
2907 return 0;
2908 }
2909 else
2910 {
2911 *what_next = ValueObject::eNothing;
2912 continue;
2913 }
2914 }
2915 else
2916 {
Johnny Chen44805302011-07-19 19:48:13 +00002917 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002918 index <= index_higher; index++)
2919 {
2920 ValueObjectSP child =
2921 root->GetChildAtIndex(index, true);
2922 list->Append(child);
2923 }
2924 *first_unparsed = end+1;
2925 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2926 *final_result = ValueObject::eValueObjectList;
2927 return index_higher-index_lower+1; // tell me number of items I added to the VOList
2928 }
2929 }
2930 break;
2931 }
2932 default: // some non-[ separator, or something entirely wrong, is in the way
2933 {
2934 *first_unparsed = expression_cstr;
2935 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2936 *final_result = ValueObject::eInvalid;
2937 return 0;
2938 break;
2939 }
2940 }
2941 }
2942}
2943
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002944void
Greg Clayton1d3afba2010-10-05 00:00:42 +00002945ValueObject::DumpValueObject
2946(
2947 Stream &s,
Greg Clayton1d3afba2010-10-05 00:00:42 +00002948 ValueObject *valobj,
2949 const char *root_valobj_name,
2950 uint32_t ptr_depth,
2951 uint32_t curr_depth,
2952 uint32_t max_depth,
2953 bool show_types,
2954 bool show_location,
2955 bool use_objc,
Greg Claytonafacd142011-09-02 01:15:17 +00002956 DynamicValueType use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00002957 bool use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002958 bool scope_already_checked,
Enrico Granata0c5ef692011-07-16 01:22:04 +00002959 bool flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00002960 uint32_t omit_summary_depth,
2961 bool ignore_cap
Greg Clayton1d3afba2010-10-05 00:00:42 +00002962)
2963{
Greg Clayton007d5be2011-05-30 00:49:24 +00002964 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002965 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00002966 bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00002967
Greg Claytonafacd142011-09-02 01:15:17 +00002968 if (update_success && use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00002969 {
Jim Ingham2837b762011-05-04 03:43:18 +00002970 ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00002971 if (dynamic_value)
2972 valobj = dynamic_value;
2973 }
2974
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002975 clang_type_t clang_type = valobj->GetClangType();
2976
Greg Clayton73b472d2010-10-27 03:32:59 +00002977 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002978 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00002979 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
2980 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002981
2982 const bool print_valobj = flat_output == false || has_value;
2983
2984 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002985 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002986 if (show_location)
2987 {
Jim Ingham6035b672011-03-31 00:19:25 +00002988 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002989 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002990
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002991 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00002992
Greg Clayton7c8a9662010-11-02 01:50:16 +00002993 // Always show the type for the top level items.
Greg Claytone221f822011-01-21 01:59:00 +00002994 if (show_types || (curr_depth == 0 && !flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00002995 {
Enrico Granata9910bc82011-08-03 02:18:51 +00002996 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
2997 s.Printf("(%s", typeName);
2998 // only show dynamic types if the user really wants to see types
Greg Claytonafacd142011-09-02 01:15:17 +00002999 if (show_types && use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003000 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003001 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003002 {
3003 Process* process = valobj->GetUpdatePoint().GetProcessSP().get();
3004 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003005 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003006 else
3007 {
3008 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3009 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003010 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003011 else
3012 {
3013 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3014 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003015 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003016 else
3017 s.Printf(", dynamic type: %s) ",
3018 runtime->GetActualTypeName(isa).GetCString());
3019 }
3020 }
3021 }
3022 else
3023 s.Printf(") ");
3024 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003025
Greg Clayton1d3afba2010-10-05 00:00:42 +00003026
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003027 if (flat_output)
3028 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003029 // If we are showing types, also qualify the C++ base classes
3030 const bool qualify_cxx_base_classes = show_types;
3031 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003032 s.PutCString(" =");
3033 }
3034 else
3035 {
3036 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3037 s.Printf ("%s =", name_cstr);
3038 }
3039
Jim Ingham6035b672011-03-31 00:19:25 +00003040 if (!scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003041 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003042 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003043 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003044 }
3045
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003046 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003047 const char *sum_cstr = NULL;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003048 SummaryFormat* entry = valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003049
Enrico Granata0c5ef692011-07-16 01:22:04 +00003050 if (omit_summary_depth > 0)
3051 entry = NULL;
3052
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003053 if (err_cstr == NULL)
3054 {
Jim Ingham6035b672011-03-31 00:19:25 +00003055 val_cstr = valobj->GetValueAsCString();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003056 err_cstr = valobj->GetError().AsCString();
3057 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003058
3059 if (err_cstr)
3060 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003061 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003062 }
3063 else
3064 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003065 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003066 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003067 {
Enrico Granata4becb372011-06-29 22:27:15 +00003068
Enrico Granata0c5ef692011-07-16 01:22:04 +00003069 sum_cstr = (omit_summary_depth == 0) ? valobj->GetSummaryAsCString() : NULL;
Greg Clayton1d3afba2010-10-05 00:00:42 +00003070
Enrico Granata4becb372011-06-29 22:27:15 +00003071 // We must calculate this value in realtime because entry might alter this variable's value
3072 // (e.g. by saying ${var%fmt}) and render precached values useless
3073 if (val_cstr && (!entry || entry->DoesPrintValue() || !sum_cstr))
3074 s.Printf(" %s", valobj->GetValueAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003075
Enrico Granata9dd75c82011-07-15 23:30:15 +00003076 if (sum_cstr)
Enrico Granata0a3958e2011-07-02 00:25:22 +00003077 {
3078 // for some reason, using %@ (ObjC description) in a summary string, makes
3079 // us believe we need to reset ourselves, thus invalidating the content of
3080 // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty
3081 // let us recalculate it!
3082 if (sum_cstr[0] == '\0')
3083 s.Printf(" %s", valobj->GetSummaryAsCString());
3084 else
3085 s.Printf(" %s", sum_cstr);
3086 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003087
3088 if (use_objc)
3089 {
Jim Ingham6035b672011-03-31 00:19:25 +00003090 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003091 if (object_desc)
3092 s.Printf(" %s\n", object_desc);
3093 else
Sean Callanan672ad942010-10-23 00:18:49 +00003094 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003095 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003096 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003097 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003098
3099 if (curr_depth < max_depth)
3100 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003101 // We will show children for all concrete types. We won't show
3102 // pointer contents unless a pointer depth has been specified.
3103 // We won't reference contents unless the reference is the
3104 // root object (depth of zero).
3105 bool print_children = true;
3106
3107 // Use a new temporary pointer depth in case we override the
3108 // current pointer depth below...
3109 uint32_t curr_ptr_depth = ptr_depth;
3110
3111 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3112 if (is_ptr || is_ref)
3113 {
3114 // We have a pointer or reference whose value is an address.
3115 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003116 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003117 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003118 print_children = false;
3119
3120 else if (is_ref && curr_depth == 0)
3121 {
3122 // If this is the root object (depth is zero) that we are showing
3123 // and it is a reference, and no pointer depth has been supplied
3124 // print out what it references. Don't do this at deeper depths
3125 // otherwise we can end up with infinite recursion...
3126 curr_ptr_depth = 1;
3127 }
3128
3129 if (curr_ptr_depth == 0)
3130 print_children = false;
3131 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003132
Enrico Granata0a3958e2011-07-02 00:25:22 +00003133 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003134 {
Enrico Granatac482a192011-08-17 22:13:59 +00003135 ValueObjectSP synth_valobj = valobj->GetSyntheticValue(use_synth ?
Greg Claytonafacd142011-09-02 01:15:17 +00003136 eUseSyntheticFilter :
3137 eNoSyntheticFilter);
Enrico Granatac482a192011-08-17 22:13:59 +00003138 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003139 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003140 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003141 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003142 if (flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003143 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003144 if (print_valobj)
3145 s.EOL();
3146 }
3147 else
3148 {
3149 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003150 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003151 s.IndentMore();
3152 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003153
3154 uint32_t max_num_children = valobj->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
3155
3156 if (num_children > max_num_children && !ignore_cap)
3157 {
3158 num_children = max_num_children;
3159 print_dotdotdot = true;
3160 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003161
3162 for (uint32_t idx=0; idx<num_children; ++idx)
3163 {
Enrico Granatac482a192011-08-17 22:13:59 +00003164 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003165 if (child_sp.get())
3166 {
3167 DumpValueObject (s,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003168 child_sp.get(),
3169 NULL,
Greg Clayton73b472d2010-10-27 03:32:59 +00003170 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003171 curr_depth + 1,
3172 max_depth,
3173 show_types,
3174 show_location,
3175 false,
Jim Ingham78a685a2011-04-16 00:01:13 +00003176 use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00003177 use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003178 true,
Enrico Granata0c5ef692011-07-16 01:22:04 +00003179 flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00003180 omit_summary_depth > 1 ? omit_summary_depth - 1 : 0,
3181 ignore_cap);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003182 }
3183 }
3184
3185 if (!flat_output)
3186 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003187 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003188 {
3189 valobj->GetUpdatePoint().GetTargetSP()->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003190 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003191 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003192 s.IndentLess();
3193 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003194 }
3195 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003196 else if (has_children)
3197 {
3198 // Aggregate, no children...
3199 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003200 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003201 }
3202 else
3203 {
3204 if (print_valobj)
3205 s.EOL();
3206 }
3207
Greg Clayton1d3afba2010-10-05 00:00:42 +00003208 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003209 else
3210 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003211 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003212 }
3213 }
3214 else
3215 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003216 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003217 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003218 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003219 }
3220 }
3221 }
3222 }
3223}
3224
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003225
3226ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003227ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003228{
3229 ValueObjectSP valobj_sp;
3230
Enrico Granatac3e320a2011-08-02 17:27:39 +00003231 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003232 {
Jim Ingham6035b672011-03-31 00:19:25 +00003233 ExecutionContextScope *exe_scope = GetExecutionContextScope();
3234 if (exe_scope)
3235 {
3236 ExecutionContext exe_ctx;
3237 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003238
Jim Ingham6035b672011-03-31 00:19:25 +00003239 clang::ASTContext *ast = GetClangAST ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003240
Jim Ingham6035b672011-03-31 00:19:25 +00003241 DataExtractor data;
3242 data.SetByteOrder (m_data.GetByteOrder());
3243 data.SetAddressByteSize(m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003244
Greg Clayton644247c2011-07-07 01:59:51 +00003245 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003246
Jim Ingham58b59f92011-04-22 23:53:53 +00003247 valobj_sp = ValueObjectConstResult::Create (exe_scope,
3248 ast,
3249 GetClangType(),
3250 name,
Enrico Granata9128ee22011-09-06 19:20:51 +00003251 data,
3252 GetAddressOf());
Jim Ingham6035b672011-03-31 00:19:25 +00003253 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003254 }
Jim Ingham6035b672011-03-31 00:19:25 +00003255
3256 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003257 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003258 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003259 }
3260 return valobj_sp;
3261}
3262
Greg Claytonafacd142011-09-02 01:15:17 +00003263ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003264ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003265{
Jim Ingham58b59f92011-04-22 23:53:53 +00003266 if (m_deref_valobj)
3267 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003268
Greg Clayton54979cd2010-12-15 05:08:08 +00003269 const bool is_pointer_type = IsPointerType();
3270 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003271 {
3272 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003273 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003274
3275 std::string child_name_str;
3276 uint32_t child_byte_size = 0;
3277 int32_t child_byte_offset = 0;
3278 uint32_t child_bitfield_bit_size = 0;
3279 uint32_t child_bitfield_bit_offset = 0;
3280 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003281 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003282 const bool transparent_pointers = false;
3283 clang::ASTContext *clang_ast = GetClangAST();
3284 clang_type_t clang_type = GetClangType();
3285 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003286
3287 ExecutionContext exe_ctx;
3288 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
3289
3290 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3291 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003292 GetName().GetCString(),
3293 clang_type,
3294 0,
3295 transparent_pointers,
3296 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003297 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003298 child_name_str,
3299 child_byte_size,
3300 child_byte_offset,
3301 child_bitfield_bit_size,
3302 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003303 child_is_base_class,
3304 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003305 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003306 {
3307 ConstString child_name;
3308 if (!child_name_str.empty())
3309 child_name.SetCString (child_name_str.c_str());
3310
Jim Ingham58b59f92011-04-22 23:53:53 +00003311 m_deref_valobj = new ValueObjectChild (*this,
3312 clang_ast,
3313 child_clang_type,
3314 child_name,
3315 child_byte_size,
3316 child_byte_offset,
3317 child_bitfield_bit_size,
3318 child_bitfield_bit_offset,
3319 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003320 child_is_deref_of_parent,
3321 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003322 }
3323 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003324
Jim Ingham58b59f92011-04-22 23:53:53 +00003325 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003326 {
3327 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003328 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003329 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003330 else
3331 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003332 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003333 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003334
3335 if (is_pointer_type)
3336 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3337 else
3338 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003339 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003340 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003341}
3342
Greg Claytonafacd142011-09-02 01:15:17 +00003343ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003344ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003345{
Jim Ingham78a685a2011-04-16 00:01:13 +00003346 if (m_addr_of_valobj_sp)
3347 return m_addr_of_valobj_sp;
3348
Greg Claytone0d378b2011-03-24 21:19:54 +00003349 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003350 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003351 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003352 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003353 if (addr != LLDB_INVALID_ADDRESS)
3354 {
3355 switch (address_type)
3356 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003357 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003358 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003359 {
3360 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003361 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003362 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3363 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003364 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003365
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003366 case eAddressTypeFile:
3367 case eAddressTypeLoad:
3368 case eAddressTypeHost:
3369 {
3370 clang::ASTContext *ast = GetClangAST();
3371 clang_type_t clang_type = GetClangType();
3372 if (ast && clang_type)
3373 {
3374 std::string name (1, '&');
3375 name.append (m_name.AsCString(""));
Jim Ingham58b59f92011-04-22 23:53:53 +00003376 m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(),
3377 ast,
3378 ClangASTContext::CreatePointerType (ast, clang_type),
3379 ConstString (name.c_str()),
3380 addr,
3381 eAddressTypeInvalid,
3382 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003383 }
3384 }
3385 break;
3386 }
3387 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003388 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003389}
3390
Greg Claytonb2dcc362011-05-05 23:32:56 +00003391
Greg Claytonafacd142011-09-02 01:15:17 +00003392ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003393ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3394{
Greg Claytonafacd142011-09-02 01:15:17 +00003395 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003396 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003397 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003398
3399 if (ptr_value != LLDB_INVALID_ADDRESS)
3400 {
3401 Address ptr_addr (NULL, ptr_value);
3402
3403 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3404 name,
3405 ptr_addr,
3406 clang_ast_type);
3407 }
3408 return valobj_sp;
3409}
3410
Greg Claytonafacd142011-09-02 01:15:17 +00003411ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003412ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3413{
Greg Claytonafacd142011-09-02 01:15:17 +00003414 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003415 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003416 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003417
3418 if (ptr_value != LLDB_INVALID_ADDRESS)
3419 {
3420 Address ptr_addr (NULL, ptr_value);
3421
3422 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3423 name,
3424 ptr_addr,
3425 type_sp);
3426 }
3427 return valobj_sp;
3428}
3429
Jim Ingham6035b672011-03-31 00:19:25 +00003430ValueObject::EvaluationPoint::EvaluationPoint () :
Stephen Wilson71c21d12011-04-11 19:41:40 +00003431 m_thread_id (LLDB_INVALID_UID),
Jim Ingham4b536182011-08-09 02:12:22 +00003432 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003433{
3434}
3435
3436ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Jim Ingham6035b672011-03-31 00:19:25 +00003437 m_needs_update (true),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003438 m_first_update (true),
Jim Ingham89b61092011-07-06 17:42:14 +00003439 m_thread_id (LLDB_INVALID_THREAD_ID),
Jim Ingham4b536182011-08-09 02:12:22 +00003440 m_mod_id ()
Stephen Wilson71c21d12011-04-11 19:41:40 +00003441
Jim Ingham6035b672011-03-31 00:19:25 +00003442{
3443 ExecutionContext exe_ctx;
Jim Ingham9ee01152011-12-10 01:49:43 +00003444
Jim Ingham6035b672011-03-31 00:19:25 +00003445 if (exe_scope)
3446 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Claytonc14ee322011-09-22 04:58:26 +00003447 Target *target = exe_ctx.GetTargetPtr();
3448 if (target != NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003449 {
Greg Claytonc14ee322011-09-22 04:58:26 +00003450 m_target_sp = target;
3451 m_process_sp = exe_ctx.GetProcessSP();
3452 if (!m_process_sp)
3453 m_process_sp = target->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003454
Greg Claytonc14ee322011-09-22 04:58:26 +00003455 if (m_process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003456 {
Jim Ingham4b536182011-08-09 02:12:22 +00003457 m_mod_id = m_process_sp->GetModID();
3458
Greg Claytonc14ee322011-09-22 04:58:26 +00003459 Thread *thread = exe_ctx.GetThreadPtr();
Jim Ingham6035b672011-03-31 00:19:25 +00003460
Greg Claytonc14ee322011-09-22 04:58:26 +00003461 if (thread == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003462 {
3463 if (use_selected)
Jim Ingham6035b672011-03-31 00:19:25 +00003464 thread = m_process_sp->GetThreadList().GetSelectedThread().get();
Jim Ingham6035b672011-03-31 00:19:25 +00003465 }
Jim Ingham6035b672011-03-31 00:19:25 +00003466
3467 if (thread != NULL)
3468 {
3469 m_thread_id = thread->GetIndexID();
Greg Claytonc14ee322011-09-22 04:58:26 +00003470
3471 StackFrame *frame = exe_ctx.GetFramePtr();
3472 if (frame == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003473 {
3474 if (use_selected)
3475 {
Greg Claytonc14ee322011-09-22 04:58:26 +00003476 frame = thread->GetSelectedFrame().get();
Jim Ingham6035b672011-03-31 00:19:25 +00003477 if (frame)
Jim Ingham6035b672011-03-31 00:19:25 +00003478 m_stack_id = frame->GetStackID();
Jim Ingham6035b672011-03-31 00:19:25 +00003479 }
3480 }
3481 else
Greg Claytonc14ee322011-09-22 04:58:26 +00003482 m_stack_id = frame->GetStackID();
Jim Ingham6035b672011-03-31 00:19:25 +00003483 }
3484 }
3485 }
Jim Ingham6035b672011-03-31 00:19:25 +00003486}
3487
3488ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Stephen Wilson71c21d12011-04-11 19:41:40 +00003489 m_needs_update(true),
3490 m_first_update(true),
Jim Ingham6035b672011-03-31 00:19:25 +00003491 m_target_sp (rhs.m_target_sp),
3492 m_process_sp (rhs.m_process_sp),
3493 m_thread_id (rhs.m_thread_id),
3494 m_stack_id (rhs.m_stack_id),
Jim Ingham4b536182011-08-09 02:12:22 +00003495 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003496{
3497}
3498
3499ValueObject::EvaluationPoint::~EvaluationPoint ()
3500{
3501}
3502
3503ExecutionContextScope *
3504ValueObject::EvaluationPoint::GetExecutionContextScope ()
3505{
Jim Ingham9ee01152011-12-10 01:49:43 +00003506 // We have to update before giving out the scope, or we could be handing out stale pointers.
3507 ExecutionContextScope *exe_scope;
3508 SyncWithProcessState(exe_scope);
Jim Ingham6035b672011-03-31 00:19:25 +00003509
Jim Ingham9ee01152011-12-10 01:49:43 +00003510 return exe_scope;
Jim Ingham6035b672011-03-31 00:19:25 +00003511}
3512
3513// This function checks the EvaluationPoint against the current process state. If the current
3514// state matches the evaluation point, or the evaluation point is already invalid, then we return
3515// false, meaning "no change". If the current state is different, we update our state, and return
3516// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3517// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003518// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003519
3520bool
Jim Ingham9ee01152011-12-10 01:49:43 +00003521ValueObject::EvaluationPoint::SyncWithProcessState(ExecutionContextScope *&exe_scope)
Jim Ingham6035b672011-03-31 00:19:25 +00003522{
Jim Ingham6035b672011-03-31 00:19:25 +00003523 // If we don't have a process nothing can change.
3524 if (!m_process_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003525 {
Jim Ingham9ee01152011-12-10 01:49:43 +00003526 exe_scope = m_target_sp.get();
Jim Ingham6035b672011-03-31 00:19:25 +00003527 return false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003528 }
Jim Ingham6035b672011-03-31 00:19:25 +00003529
3530 // If our stop id is the current stop ID, nothing has changed:
Jim Ingham4b536182011-08-09 02:12:22 +00003531 ProcessModID current_mod_id = m_process_sp->GetModID();
3532
Jim Ingham78a685a2011-04-16 00:01:13 +00003533 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3534 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003535 if (current_mod_id.GetStopID() == 0)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003536 {
Jim Ingham9ee01152011-12-10 01:49:43 +00003537 exe_scope = m_target_sp.get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003538 return false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003539 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003540
3541 bool changed;
3542
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003543 if (m_mod_id.IsValid())
3544 {
3545 if (m_mod_id == current_mod_id)
3546 {
3547 // Everything is already up to date in this object, no need do
3548 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003549 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003550 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003551 else
3552 {
3553 m_mod_id = current_mod_id;
3554 m_needs_update = true;
3555 changed = true;
3556 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003557 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003558 exe_scope = m_process_sp.get();
Jim Ingham6035b672011-03-31 00:19:25 +00003559
3560 // Something has changed, so we will return true. Now make sure the thread & frame still exist, and if either
3561 // doesn't, mark ourselves as invalid.
3562
3563 if (m_thread_id != LLDB_INVALID_THREAD_ID)
3564 {
3565 Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get();
3566 if (our_thread == NULL)
Greg Clayton262f80d2011-07-06 16:49:27 +00003567 {
Jim Ingham89b61092011-07-06 17:42:14 +00003568 SetInvalid();
Greg Clayton262f80d2011-07-06 16:49:27 +00003569 }
Jim Ingham6035b672011-03-31 00:19:25 +00003570 else
3571 {
Jim Ingham9ee01152011-12-10 01:49:43 +00003572 exe_scope = our_thread;
Jim Ingham6035b672011-03-31 00:19:25 +00003573
3574 if (m_stack_id.IsValid())
3575 {
3576 StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get();
3577 if (our_frame == NULL)
3578 SetInvalid();
3579 else
Jim Ingham9ee01152011-12-10 01:49:43 +00003580 exe_scope = our_frame;
Jim Ingham6035b672011-03-31 00:19:25 +00003581 }
3582 }
3583 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003584 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003585}
3586
Jim Ingham61be0902011-05-02 18:13:59 +00003587void
3588ValueObject::EvaluationPoint::SetUpdated ()
3589{
Jim Ingham9ee01152011-12-10 01:49:43 +00003590 if (m_process_sp)
3591 m_mod_id = m_process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003592 m_first_update = false;
3593 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003594}
3595
3596
Jim Ingham6035b672011-03-31 00:19:25 +00003597bool
3598ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3599{
3600 if (!IsValid())
3601 return false;
3602
3603 bool needs_update = false;
Jim Ingham6035b672011-03-31 00:19:25 +00003604
3605 // The target has to be non-null, and the
3606 Target *target = exe_scope->CalculateTarget();
3607 if (target != NULL)
3608 {
3609 Target *old_target = m_target_sp.get();
3610 assert (target == old_target);
3611 Process *process = exe_scope->CalculateProcess();
3612 if (process != NULL)
3613 {
3614 // FOR NOW - assume you can't update variable objects across process boundaries.
3615 Process *old_process = m_process_sp.get();
3616 assert (process == old_process);
Jim Ingham4b536182011-08-09 02:12:22 +00003617 ProcessModID current_mod_id = process->GetModID();
3618 if (m_mod_id != current_mod_id)
Jim Ingham6035b672011-03-31 00:19:25 +00003619 {
3620 needs_update = true;
Jim Ingham4b536182011-08-09 02:12:22 +00003621 m_mod_id = current_mod_id;
Jim Ingham6035b672011-03-31 00:19:25 +00003622 }
3623 // See if we're switching the thread or stack context. If no thread is given, this is
3624 // being evaluated in a global context.
3625 Thread *thread = exe_scope->CalculateThread();
3626 if (thread != NULL)
3627 {
Greg Claytonafacd142011-09-02 01:15:17 +00003628 user_id_t new_thread_index = thread->GetIndexID();
Jim Ingham6035b672011-03-31 00:19:25 +00003629 if (new_thread_index != m_thread_id)
3630 {
3631 needs_update = true;
3632 m_thread_id = new_thread_index;
3633 m_stack_id.Clear();
3634 }
3635
3636 StackFrame *new_frame = exe_scope->CalculateStackFrame();
3637 if (new_frame != NULL)
3638 {
3639 if (new_frame->GetStackID() != m_stack_id)
3640 {
3641 needs_update = true;
3642 m_stack_id = new_frame->GetStackID();
3643 }
3644 }
3645 else
3646 {
3647 m_stack_id.Clear();
3648 needs_update = true;
3649 }
3650 }
3651 else
3652 {
3653 // If this had been given a thread, and now there is none, we should update.
3654 // Otherwise we don't have to do anything.
3655 if (m_thread_id != LLDB_INVALID_UID)
3656 {
3657 m_thread_id = LLDB_INVALID_UID;
3658 m_stack_id.Clear();
3659 needs_update = true;
3660 }
3661 }
3662 }
3663 else
3664 {
3665 // If there is no process, then we don't need to update anything.
3666 // But if we're switching from having a process to not, we should try to update.
3667 if (m_process_sp.get() != NULL)
3668 {
3669 needs_update = true;
3670 m_process_sp.reset();
3671 m_thread_id = LLDB_INVALID_UID;
3672 m_stack_id.Clear();
3673 }
3674 }
3675 }
3676 else
3677 {
3678 // If there's no target, nothing can change so we don't need to update anything.
3679 // But if we're switching from having a target to not, we should try to update.
3680 if (m_target_sp.get() != NULL)
3681 {
3682 needs_update = true;
3683 m_target_sp.reset();
3684 m_process_sp.reset();
3685 m_thread_id = LLDB_INVALID_UID;
3686 m_stack_id.Clear();
3687 }
3688 }
3689 if (!m_needs_update)
3690 m_needs_update = needs_update;
3691
3692 return needs_update;
3693}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003694
3695void
3696ValueObject::ClearUserVisibleData()
3697{
3698 m_location_str.clear();
3699 m_value_str.clear();
3700 m_summary_str.clear();
3701 m_object_desc_str.clear();
Enrico Granata855cd902011-09-06 22:59:55 +00003702 m_trying_summary_already = false;
Johnny Chen44805302011-07-19 19:48:13 +00003703}
Enrico Granata9128ee22011-09-06 19:20:51 +00003704
3705SymbolContextScope *
3706ValueObject::GetSymbolContextScope()
3707{
3708 if (m_parent)
3709 {
3710 if (!m_parent->IsPointerOrReferenceType())
3711 return m_parent->GetSymbolContextScope();
3712 }
3713 return NULL;
3714}