blob: 78e18ac9f3d7ed6d1efbaeb87ec2d5b7d9fbbc5b [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(),
Greg Clayton288bdf92010-09-02 02:59:18 +000088 m_value_is_valid (false),
89 m_value_did_change (false),
90 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000091 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000092 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000093 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000094 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +000095 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000096 m_is_child_at_offset(false),
Enrico Granata9128ee22011-09-06 19:20:51 +000097 m_dump_printable_counter(0),
98 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid)
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(),
Jim Ingham6035b672011-03-31 00:19:25 +0000134 m_value_is_valid (false),
135 m_value_did_change (false),
136 m_children_count_valid (false),
137 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000138 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000139 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000140 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000141 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000142 m_is_child_at_offset(false),
Enrico Granata9128ee22011-09-06 19:20:51 +0000143 m_dump_printable_counter(0),
144 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type)
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();
244 m_summary_str.clear();
Enrico Granata9128ee22011-09-06 19:20:51 +0000245 any_change = true;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000246 }
Enrico Granata85933ed2011-08-18 16:38:26 +0000247 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) ||
Enrico Granatac3e320a2011-08-02 17:27:39 +0000248 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000249 {
250 if (m_last_summary_format.get())
Enrico Granataf2bbf712011-07-15 02:26:42 +0000251 m_last_summary_format.reset((StringSummaryFormat*)NULL);
Enrico Granata4becb372011-06-29 22:27:15 +0000252 if (m_last_value_format.get())
Enrico Granatad55546b2011-07-22 00:16:08 +0000253 m_last_value_format.reset(/*(ValueFormat*)NULL*/);
254 if (m_last_synthetic_filter.get())
255 m_last_synthetic_filter.reset(/*(SyntheticFilter*)NULL*/);
Enrico Granataa37a0652011-07-24 00:14:56 +0000256
257 m_synthetic_value = NULL;
Enrico Granata1490c6f2011-07-19 02:34:21 +0000258
Enrico Granata9128ee22011-09-06 19:20:51 +0000259 any_change = true;
Greg Claytonafacd142011-09-02 01:15:17 +0000260 DataVisualization::ValueFormats::Get(*this, eNoDynamicValues, m_last_value_format);
Enrico Granatac482a192011-08-17 22:13:59 +0000261 DataVisualization::GetSummaryFormat(*this, use_dynamic, m_last_summary_format);
262 DataVisualization::GetSyntheticChildren(*this, use_dynamic, m_last_synthetic_filter);
Enrico Granata1490c6f2011-07-19 02:34:21 +0000263
Enrico Granata85933ed2011-08-18 16:38:26 +0000264 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000265 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granataf2bbf712011-07-15 02:26:42 +0000266
267 ClearUserVisibleData();
Enrico Granata4becb372011-06-29 22:27:15 +0000268 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000269
270 return any_change;
271
Enrico Granata4becb372011-06-29 22:27:15 +0000272}
273
Jim Ingham16e0c682011-08-12 23:34:31 +0000274void
275ValueObject::SetNeedsUpdate ()
276{
277 m_update_point.SetNeedsUpdate();
278 // We have to clear the value string here so ConstResult children will notice if their values are
279 // changed by hand (i.e. with SetValueAsCString).
280 m_value_str.clear();
281}
282
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000283DataExtractor &
284ValueObject::GetDataExtractor ()
285{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000286 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000287 return m_data;
288}
289
290const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000291ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000292{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000293 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000294 return m_error;
295}
296
297const ConstString &
298ValueObject::GetName() const
299{
300 return m_name;
301}
302
303const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000304ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000305{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000306 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000307 {
308 if (m_location_str.empty())
309 {
310 StreamString sstr;
311
312 switch (m_value.GetValueType())
313 {
314 default:
315 break;
316
317 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000318 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000319 {
320 RegisterInfo *reg_info = m_value.GetRegisterInfo();
321 if (reg_info)
322 {
323 if (reg_info->name)
324 m_location_str = reg_info->name;
325 else if (reg_info->alt_name)
326 m_location_str = reg_info->alt_name;
327 break;
328 }
329 }
330 m_location_str = "scalar";
331 break;
332
333 case Value::eValueTypeLoadAddress:
334 case Value::eValueTypeFileAddress:
335 case Value::eValueTypeHostAddress:
336 {
337 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
338 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
339 m_location_str.swap(sstr.GetString());
340 }
341 break;
342 }
343 }
344 }
345 return m_location_str.c_str();
346}
347
348Value &
349ValueObject::GetValue()
350{
351 return m_value;
352}
353
354const Value &
355ValueObject::GetValue() const
356{
357 return m_value;
358}
359
360bool
Jim Ingham6035b672011-03-31 00:19:25 +0000361ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000362{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000363 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
364 {
365 ExecutionContext exe_ctx;
366 ExecutionContextScope *exe_scope = GetExecutionContextScope();
367 if (exe_scope)
368 exe_scope->CalculateExecutionContext(exe_ctx);
Jim Ingham16e0c682011-08-12 23:34:31 +0000369 Value tmp_value(m_value);
370 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Enrico Granata6fd87d52011-08-04 01:41:02 +0000371 return scalar.IsValid();
372 }
373 else
374 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000375}
376
377bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000378ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379{
Greg Clayton288bdf92010-09-02 02:59:18 +0000380 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381}
382
383
384void
385ValueObject::SetValueIsValid (bool b)
386{
Greg Clayton288bdf92010-09-02 02:59:18 +0000387 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000388}
389
390bool
Jim Ingham6035b672011-03-31 00:19:25 +0000391ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392{
Jim Ingham6035b672011-03-31 00:19:25 +0000393 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000394 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000395}
396
397void
398ValueObject::SetValueDidChange (bool value_changed)
399{
Greg Clayton288bdf92010-09-02 02:59:18 +0000400 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000401}
402
403ValueObjectSP
404ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
405{
406 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000407 // We may need to update our value if we are dynamic
408 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000409 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000410 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000412 // Check if we have already made the child value object?
413 if (can_create && m_children[idx] == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000415 // No we haven't created the child at this index, so lets have our
416 // subclass do it and cache the result for quick future access.
417 m_children[idx] = CreateChildAtIndex (idx, false, 0);
Jim Ingham78a685a2011-04-16 00:01:13 +0000418 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000419
420 if (m_children[idx] != NULL)
421 return m_children[idx]->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422 }
423 return child_sp;
424}
425
426uint32_t
427ValueObject::GetIndexOfChildWithName (const ConstString &name)
428{
429 bool omit_empty_base_classes = true;
430 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000431 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000432 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000433 omit_empty_base_classes);
434}
435
436ValueObjectSP
437ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
438{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000439 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000440 // classes (which really aren't part of the expression path), so we
441 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000442 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000443
Greg Claytondea8cb42011-06-29 22:09:02 +0000444 // We may need to update our value if we are dynamic
445 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000446 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000447
448 std::vector<uint32_t> child_indexes;
449 clang::ASTContext *clang_ast = GetClangAST();
450 void *clang_type = GetClangType();
451 bool omit_empty_base_classes = true;
452 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
453 clang_type,
454 name.GetCString(),
455 omit_empty_base_classes,
456 child_indexes);
457 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000458 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000459 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
460 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
461
462 child_sp = GetChildAtIndex(*pos, can_create);
463 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000465 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000466 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000467 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
468 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000469 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000470 else
471 {
472 child_sp.reset();
473 }
474
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000475 }
476 }
477 return child_sp;
478}
479
480
481uint32_t
482ValueObject::GetNumChildren ()
483{
Greg Clayton288bdf92010-09-02 02:59:18 +0000484 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000485 {
486 SetNumChildren (CalculateNumChildren());
487 }
488 return m_children.size();
489}
490void
491ValueObject::SetNumChildren (uint32_t num_children)
492{
Greg Clayton288bdf92010-09-02 02:59:18 +0000493 m_children_count_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000494 m_children.resize(num_children);
495}
496
497void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000498ValueObject::SetName (const ConstString &name)
499{
500 m_name = name;
501}
502
Jim Ingham58b59f92011-04-22 23:53:53 +0000503ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
505{
Jim Ingham2eec4872011-05-07 00:10:58 +0000506 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000507
Greg Claytondea8cb42011-06-29 22:09:02 +0000508 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000509 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000510 std::string child_name_str;
511 uint32_t child_byte_size = 0;
512 int32_t child_byte_offset = 0;
513 uint32_t child_bitfield_bit_size = 0;
514 uint32_t child_bitfield_bit_offset = 0;
515 bool child_is_base_class = false;
516 bool child_is_deref_of_parent = false;
517
518 const bool transparent_pointers = synthetic_array_member == false;
519 clang::ASTContext *clang_ast = GetClangAST();
520 clang_type_t clang_type = GetClangType();
521 clang_type_t child_clang_type;
522
523 ExecutionContext exe_ctx;
524 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
525
526 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
527 clang_ast,
528 GetName().GetCString(),
529 clang_type,
530 idx,
531 transparent_pointers,
532 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000533 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000534 child_name_str,
535 child_byte_size,
536 child_byte_offset,
537 child_bitfield_bit_size,
538 child_bitfield_bit_offset,
539 child_is_base_class,
540 child_is_deref_of_parent);
541 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000543 if (synthetic_index)
544 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000545
Greg Claytondea8cb42011-06-29 22:09:02 +0000546 ConstString child_name;
547 if (!child_name_str.empty())
548 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549
Greg Claytondea8cb42011-06-29 22:09:02 +0000550 valobj = new ValueObjectChild (*this,
551 clang_ast,
552 child_clang_type,
553 child_name,
554 child_byte_size,
555 child_byte_offset,
556 child_bitfield_bit_size,
557 child_bitfield_bit_offset,
558 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000559 child_is_deref_of_parent,
560 eAddressTypeInvalid);
561 //if (valobj)
562 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
563 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000564
Jim Ingham58b59f92011-04-22 23:53:53 +0000565 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000566}
567
568const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000569ValueObject::GetSummaryAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000570{
Enrico Granatad8b5fce2011-08-02 23:12:24 +0000571 if (UpdateValueIfNeeded (true))
Enrico Granata4becb372011-06-29 22:27:15 +0000572 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573 if (m_summary_str.empty())
574 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000575 SummaryFormat *summary_format = GetSummaryFormat().get();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000576
577 if (summary_format)
Enrico Granata4becb372011-06-29 22:27:15 +0000578 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000579 m_summary_str = summary_format->FormatObject(GetSP());
Enrico Granata4becb372011-06-29 22:27:15 +0000580 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000581 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000582 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000583 clang_type_t clang_type = GetClangType();
Greg Clayton737b9322010-09-13 03:32:57 +0000584
Enrico Granata9dd75c82011-07-15 23:30:15 +0000585 // Do some default printout for function pointers
Enrico Granataf2bbf712011-07-15 02:26:42 +0000586 if (clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000587 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000588 StreamString sstr;
589 clang_type_t elem_or_pointee_clang_type;
590 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
591 GetClangAST(),
592 &elem_or_pointee_clang_type));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000593
Enrico Granataf2bbf712011-07-15 02:26:42 +0000594 ExecutionContextScope *exe_scope = GetExecutionContextScope();
595 if (exe_scope)
596 {
Enrico Granata9dd75c82011-07-15 23:30:15 +0000597 if (ClangASTContext::IsFunctionPointerType (clang_type))
Jim Ingham6035b672011-03-31 00:19:25 +0000598 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000599 AddressType func_ptr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000600 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000601 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
602 {
603 switch (func_ptr_address_type)
604 {
605 case eAddressTypeInvalid:
606 case eAddressTypeFile:
607 break;
608
609 case eAddressTypeLoad:
610 {
611 Address so_addr;
612 Target *target = exe_scope->CalculateTarget();
613 if (target && target->GetSectionLoadList().IsEmpty() == false)
614 {
615 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
616 {
617 so_addr.Dump (&sstr,
618 exe_scope,
619 Address::DumpStyleResolvedDescription,
620 Address::DumpStyleSectionNameOffset);
621 }
622 }
623 }
624 break;
625
626 case eAddressTypeHost:
627 break;
628 }
629 }
630 if (sstr.GetSize() > 0)
631 {
632 m_summary_str.assign (1, '(');
633 m_summary_str.append (sstr.GetData(), sstr.GetSize());
634 m_summary_str.append (1, ')');
635 }
Jim Ingham6035b672011-03-31 00:19:25 +0000636 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637 }
638 }
639 }
640 }
641 }
642 if (m_summary_str.empty())
643 return NULL;
644 return m_summary_str.c_str();
645}
646
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000647bool
648ValueObject::IsCStringContainer(bool check_pointer)
649{
650 clang_type_t elem_or_pointee_clang_type;
651 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
652 GetClangAST(),
653 &elem_or_pointee_clang_type));
654 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
655 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
656 if (!is_char_arr_ptr)
657 return false;
658 if (!check_pointer)
659 return true;
660 if (type_flags.Test(ClangASTContext::eTypeIsArray))
661 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000662 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000663 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000664 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000665 return (cstr_address != LLDB_INVALID_ADDRESS);
666}
667
Enrico Granata9128ee22011-09-06 19:20:51 +0000668size_t
669ValueObject::GetPointeeData (DataExtractor& data,
670 uint32_t item_idx,
671 uint32_t item_count)
672{
673 if (!IsPointerType() && !IsArrayType())
674 return 0;
675
676 if (item_count == 0)
677 return 0;
678
679 uint32_t stride = 0;
680
681 ClangASTType type(GetClangAST(),
682 GetClangType());
683
684 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
685 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
686
687 const uint64_t bytes = item_count * item_type_size;
688
689 const uint64_t offset = item_idx * item_type_size;
690
691 if (item_idx == 0 && item_count == 1) // simply a deref
692 {
693 if (IsPointerType())
694 {
695 Error error;
696 ValueObjectSP pointee_sp = Dereference(error);
697 if (error.Fail() || pointee_sp.get() == NULL)
698 return 0;
699 return pointee_sp->GetDataExtractor().Copy(data);
700 }
701 else
702 {
703 ValueObjectSP child_sp = GetChildAtIndex(0, true);
704 if (child_sp.get() == NULL)
705 return 0;
706 return child_sp->GetDataExtractor().Copy(data);
707 }
708 return true;
709 }
710 else /* (items > 1) */
711 {
712 Error error;
713 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
714 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
715
716 AddressType addr_type;
717 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
718
719 ExecutionContextScope *exe_scope = m_update_point.GetExecutionContextScope();
720
721
722 switch (addr_type)
723 {
724 case eAddressTypeFile:
725 {
726 Module* module = GetModule();
727 if (module)
728 {
729 Address so_addr;
730 module->ResolveFileAddress(addr, so_addr);
731 if (exe_scope)
732 {
733 Target* target = exe_scope->CalculateTarget();
734 if (target)
735 {
736 heap_buf_ptr->SetByteSize(bytes);
737 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
738 if (error.Success())
739 {
740 data.SetData(data_sp);
741 return bytes_read;
742 }
743 }
744 }
745 }
746 }
747 break;
748 case eAddressTypeLoad:
749 if (exe_scope)
750 {
751 Process *process = exe_scope->CalculateProcess();
752 if (process)
753 {
754 heap_buf_ptr->SetByteSize(bytes);
755 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
756 if (error.Success())
757 {
758 data.SetData(data_sp);
759 return bytes_read;
760 }
761 }
762 }
763 break;
764 case eAddressTypeHost:
765 {
766 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
767 data.SetData(data_sp);
768 return bytes;
769 }
770 break;
771 case eAddressTypeInvalid:
772 default:
773 break;
774 }
775 }
776 return 0;
777}
778
779size_t
780ValueObject::GetData (DataExtractor& data)
781{
782 UpdateValueIfNeeded(false);
783 ExecutionContext exe_ctx;
784 GetExecutionContextScope()->CalculateExecutionContext(exe_ctx);
785 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule());
786 if (error.Fail())
787 return 0;
788 data.SetAddressByteSize(m_data.GetAddressByteSize());
789 data.SetByteOrder(m_data.GetByteOrder());
790 return data.GetByteSize();
791}
792
793// will compute strlen(str), but without consuming more than
794// maxlen bytes out of str (this serves the purpose of reading
795// chunks of a string without having to worry about
796// missing NULL terminators in the chunk)
797// of course, if strlen(str) > maxlen, the function will return
798// maxlen_value (which should be != maxlen, because that allows you
799// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
800static uint32_t
801strlen_or_inf (const char* str,
802 uint32_t maxlen,
803 uint32_t maxlen_value)
804{
805 uint32_t len = 0;
806 while(*str)
807 {
808 len++;str++;
809 if (len > maxlen)
810 return maxlen_value;
811 }
812 return len;
813}
814
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000815void
816ValueObject::ReadPointedString(Stream& s,
817 Error& error,
Enrico Granataf4efecd2011-07-12 22:56:10 +0000818 uint32_t max_length,
819 bool honor_array,
Greg Claytonafacd142011-09-02 01:15:17 +0000820 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000821{
822
823 if (max_length == 0)
Enrico Granata9128ee22011-09-06 19:20:51 +0000824 max_length = GetUpdatePoint().GetTargetSP()->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000825
826 clang_type_t clang_type = GetClangType();
827 clang_type_t elem_or_pointee_clang_type;
828 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
829 GetClangAST(),
830 &elem_or_pointee_clang_type));
831 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
832 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
833 {
834 ExecutionContextScope *exe_scope = GetExecutionContextScope();
835 if (exe_scope)
836 {
837 Target *target = exe_scope->CalculateTarget();
Enrico Granata6f3533f2011-07-29 19:53:35 +0000838 if (target == NULL)
839 {
840 s << "<no target to read from>";
841 }
842 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000843 {
Greg Claytonafacd142011-09-02 01:15:17 +0000844 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000845 AddressType cstr_address_type = eAddressTypeInvalid;
846
847 size_t cstr_len = 0;
848 bool capped_data = false;
849 if (type_flags.Test (ClangASTContext::eTypeIsArray))
850 {
851 // We have an array
852 cstr_len = ClangASTContext::GetArraySize (clang_type);
Enrico Granataf4efecd2011-07-12 22:56:10 +0000853 if (cstr_len > max_length)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000854 {
Enrico Granataf4efecd2011-07-12 22:56:10 +0000855 capped_data = true;
856 cstr_len = max_length;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000857 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000858 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000859 }
860 else
861 {
862 // We have a pointer
Enrico Granata9128ee22011-09-06 19:20:51 +0000863 cstr_address = GetPointerValue (&cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000864 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000865 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000866 {
867 s << "<invalid address for data>";
868 }
869 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000870 {
871 Address cstr_so_addr (NULL, cstr_address);
872 DataExtractor data;
873 size_t bytes_read = 0;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000874 if (cstr_len > 0 && honor_array)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000875 {
Enrico Granata9128ee22011-09-06 19:20:51 +0000876 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
877 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
878 GetPointeeData(data, 0, cstr_len);
879
880 if ( (bytes_read = data.GetByteSize()) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000881 {
882 s << '"';
883 data.Dump (&s,
884 0, // Start offset in "data"
Enrico Granataf4efecd2011-07-12 22:56:10 +0000885 item_format,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000886 1, // Size of item (1 byte for a char!)
887 bytes_read, // How many bytes to print?
888 UINT32_MAX, // num per line
889 LLDB_INVALID_ADDRESS,// base address
890 0, // bitfield bit size
891 0); // bitfield bit offset
892 if (capped_data)
893 s << "...";
894 s << '"';
895 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000896 else
897 s << "\"<data not available>\"";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000898 }
899 else
900 {
Enrico Granataf4efecd2011-07-12 22:56:10 +0000901 cstr_len = max_length;
902 const size_t k_max_buf_size = 64;
Enrico Granata9128ee22011-09-06 19:20:51 +0000903
904 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000905
Enrico Granata6f3533f2011-07-29 19:53:35 +0000906 bool any_data = false;
Enrico Granata9128ee22011-09-06 19:20:51 +0000907 bool finished = false;
908 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
909 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
910 while ( (bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0 )
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000911 {
Enrico Granata9128ee22011-09-06 19:20:51 +0000912 size_t len = strlen_or_inf(data.PeekCStr(0), k_max_buf_size, k_max_buf_size+1);
913 if (len > k_max_buf_size)
914 len = k_max_buf_size;
915 if (!any_data)
916 {
917 s << '"';
918 any_data = true;
919 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000920 if (len == 0)
921 break;
922 if (len > bytes_read)
923 len = bytes_read;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000924 if (len > cstr_len)
925 len = cstr_len;
Enrico Granata9128ee22011-09-06 19:20:51 +0000926 else
927 finished = true;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000928
929 data.Dump (&s,
930 0, // Start offset in "data"
Enrico Granataf4efecd2011-07-12 22:56:10 +0000931 item_format,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000932 1, // Size of item (1 byte for a char!)
933 len, // How many bytes to print?
934 UINT32_MAX, // num per line
935 LLDB_INVALID_ADDRESS,// base address
936 0, // bitfield bit size
937 0); // bitfield bit offset
938
939 if (len < k_max_buf_size)
940 break;
Enrico Granata9128ee22011-09-06 19:20:51 +0000941
Enrico Granataf4efecd2011-07-12 22:56:10 +0000942 if (len >= cstr_len)
Enrico Granataf4efecd2011-07-12 22:56:10 +0000943 break;
Enrico Granata9128ee22011-09-06 19:20:51 +0000944
Enrico Granataf4efecd2011-07-12 22:56:10 +0000945 cstr_len -= len;
Enrico Granata9128ee22011-09-06 19:20:51 +0000946 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000947 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000948
949 if (any_data == false)
950 s << "<data not available>";
Enrico Granata9128ee22011-09-06 19:20:51 +0000951 else
952 {
953 s << '"';
954 if (finished == false)
955 s << "...";
956 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000957 }
958 }
959 }
960 }
961 }
962 else
963 {
964 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +0000965 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000966 }
967}
968
Jim Ingham53c47f12010-09-10 23:12:17 +0000969const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000970ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +0000971{
Enrico Granata0a3958e2011-07-02 00:25:22 +0000972
Enrico Granatad8b5fce2011-08-02 23:12:24 +0000973 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +0000974 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000975
976 if (!m_object_desc_str.empty())
977 return m_object_desc_str.c_str();
978
Jim Ingham6035b672011-03-31 00:19:25 +0000979 ExecutionContextScope *exe_scope = GetExecutionContextScope();
980 if (exe_scope == NULL)
981 return NULL;
982
Jim Ingham53c47f12010-09-10 23:12:17 +0000983 Process *process = exe_scope->CalculateProcess();
Jim Ingham5a369122010-09-28 01:25:32 +0000984 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +0000985 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +0000986
Jim Ingham53c47f12010-09-10 23:12:17 +0000987 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +0000988
Greg Claytonafacd142011-09-02 01:15:17 +0000989 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +0000990 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
991
Jim Inghama2cf2632010-12-23 02:29:54 +0000992 if (runtime == NULL)
993 {
Jim Inghamb7603bb2011-03-18 00:05:18 +0000994 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +0000995 clang_type_t opaque_qual_type = GetClangType();
996 if (opaque_qual_type != NULL)
997 {
Jim Inghamb7603bb2011-03-18 00:05:18 +0000998 bool is_signed;
999 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1000 || ClangASTContext::IsPointerType (opaque_qual_type))
1001 {
Greg Claytonafacd142011-09-02 01:15:17 +00001002 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001003 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001004 }
1005 }
1006
Jim Ingham8d543de2011-03-31 23:01:21 +00001007 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001008 {
1009 m_object_desc_str.append (s.GetData());
1010 }
Sean Callanan672ad942010-10-23 00:18:49 +00001011
1012 if (m_object_desc_str.empty())
1013 return NULL;
1014 else
1015 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001016}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001017
1018const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001019ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001020{
1021 // If our byte size is zero this is an aggregate type that has children
Greg Clayton1be10fc2010-09-29 01:12:09 +00001022 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001023 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00001024 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001025 {
1026 if (m_value_str.empty())
1027 {
1028 const Value::ContextType context_type = m_value.GetContextType();
1029
1030 switch (context_type)
1031 {
Greg Clayton526e5af2010-11-13 03:52:47 +00001032 case Value::eContextTypeClangType:
1033 case Value::eContextTypeLLDBType:
1034 case Value::eContextTypeVariable:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001035 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001036 lldb::Format my_format = GetFormat();
Greg Clayton73b472d2010-10-27 03:32:59 +00001037 clang_type_t clang_type = GetClangType ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001038 if (clang_type)
1039 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001040 if (m_format == lldb::eFormatDefault)
Enrico Granata4becb372011-06-29 22:27:15 +00001041 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001042 if (m_last_value_format)
1043 my_format = m_last_value_format->GetFormat();
Enrico Granataf2bbf712011-07-15 02:26:42 +00001044 else
1045 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001046 if (m_is_bitfield_for_scalar)
1047 my_format = eFormatUnsigned;
1048 else
1049 my_format = ClangASTType::GetFormat(clang_type);
Enrico Granataf2bbf712011-07-15 02:26:42 +00001050 }
Greg Clayton007d5be2011-05-30 00:49:24 +00001051 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001052 StreamString sstr;
1053 if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1054 clang_type, // The clang type to display
1055 &sstr,
1056 my_format, // Format to display this type with
1057 m_data, // Data to extract from
1058 0, // Byte offset into "m_data"
1059 GetByteSize(), // Byte size of item in "m_data"
1060 GetBitfieldBitSize(), // Bitfield bit size
1061 GetBitfieldBitOffset())) // Bitfield bit offset
1062 m_value_str.swap(sstr.GetString());
1063 else
1064 {
1065 m_error.SetErrorStringWithFormat ("unsufficient data for value (only %u of %u bytes available)",
1066 m_data.GetByteSize(),
1067 GetByteSize());
1068 m_value_str.clear();
1069 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001070 }
1071 }
1072 break;
1073
Greg Clayton526e5af2010-11-13 03:52:47 +00001074 case Value::eContextTypeRegisterInfo:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001075 {
1076 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1077 if (reg_info)
1078 {
1079 StreamString reg_sstr;
1080 m_data.Dump(&reg_sstr, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
1081 m_value_str.swap(reg_sstr.GetString());
1082 }
1083 }
1084 break;
Greg Claytonc982c762010-07-09 20:39:50 +00001085
1086 default:
1087 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001088 }
1089 }
Greg Clayton288bdf92010-09-02 02:59:18 +00001090
1091 if (!m_value_did_change && m_old_value_valid)
1092 {
1093 // The value was gotten successfully, so we consider the
1094 // value as changed if the value string differs
1095 SetValueDidChange (m_old_value_str != m_value_str);
1096 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001097 }
1098 }
1099 if (m_value_str.empty())
1100 return NULL;
1101 return m_value_str.c_str();
1102}
1103
Enrico Granatac3e320a2011-08-02 17:27:39 +00001104// if > 8bytes, 0 is returned. this method should mostly be used
1105// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001106uint64_t
1107ValueObject::GetValueAsUnsigned (uint64_t fail_value)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001108{
1109 // If our byte size is zero this is an aggregate type that has children
1110 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1111 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001112 Scalar scalar;
1113 if (ResolveValue (scalar))
1114 return scalar.GetRawBits64(fail_value);
Enrico Granatac3e320a2011-08-02 17:27:39 +00001115 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001116 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001117}
1118
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001119bool
1120ValueObject::GetPrintableRepresentation(Stream& s,
1121 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001122 Format custom_format)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001123{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001124
1125 RefCounter ref(&m_dump_printable_counter);
1126
Greg Claytonafacd142011-09-02 01:15:17 +00001127 if (custom_format != eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001128 SetFormat(custom_format);
1129
1130 const char * return_value;
Enrico Granatacd1c0232011-08-04 23:37:18 +00001131 std::string alloc_mem;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001132
1133 switch(val_obj_display)
1134 {
1135 case eDisplayValue:
1136 return_value = GetValueAsCString();
1137 break;
1138 case eDisplaySummary:
1139 return_value = GetSummaryAsCString();
1140 break;
1141 case eDisplayLanguageSpecific:
1142 return_value = GetObjectDescription();
1143 break;
Enrico Granataf2bbf712011-07-15 02:26:42 +00001144 case eDisplayLocation:
1145 return_value = GetLocationAsCString();
1146 break;
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001147 case eDisplayChildrenCount:
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001148 {
Enrico Granatacd1c0232011-08-04 23:37:18 +00001149 alloc_mem.resize(512);
1150 return_value = &alloc_mem[0];
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001151 int count = GetNumChildren();
Enrico Granatacd1c0232011-08-04 23:37:18 +00001152 snprintf((char*)return_value, 512, "%d", count);
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001153 break;
1154 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001155 case eDisplayType:
1156 return_value = GetTypeName().AsCString();
1157 break;
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001158 default:
1159 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001160 }
1161
Enrico Granataf4efecd2011-07-12 22:56:10 +00001162 // this code snippet might lead to endless recursion, thus we use a RefCounter here to
1163 // check that we are not looping endlessly
1164 if (!return_value && (m_dump_printable_counter < 3))
Enrico Granata9fc19442011-07-06 02:13:41 +00001165 {
1166 // try to pick the other choice
1167 if (val_obj_display == eDisplayValue)
1168 return_value = GetSummaryAsCString();
1169 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +00001170 {
1171 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1172 {
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001173 // this thing has no value, and it seems to have no summary
1174 // some combination of unitialized data and other factors can also
1175 // raise this condition, so let's print a nice generic error message
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001176 {
1177 alloc_mem.resize(684);
1178 return_value = &alloc_mem[0];
1179 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1180 }
Enrico Granatae992a082011-07-22 17:03:19 +00001181 }
1182 else
1183 return_value = GetValueAsCString();
1184 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001185 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001186
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001187 if (return_value)
1188 s.PutCString(return_value);
1189 else
Enrico Granata88da35f2011-08-23 21:26:09 +00001190 {
1191 if (m_error.Fail())
1192 s.Printf("<%s>", m_error.AsCString());
1193 else if (val_obj_display == eDisplaySummary)
1194 s.PutCString("<no summary available>");
1195 else if (val_obj_display == eDisplayValue)
1196 s.PutCString("<no value available>");
1197 else if (val_obj_display == eDisplayLanguageSpecific)
1198 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1199 else
1200 s.PutCString("<no printable representation>");
1201 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001202
1203 // we should only return false here if we could not do *anything*
1204 // even if we have an error message as output, that's a success
1205 // from our callers' perspective, so return true
1206 return true;
1207
Enrico Granata0a3958e2011-07-02 00:25:22 +00001208}
1209
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001210// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1211// this call up to date by returning true for your new special cases. We will eventually move
1212// to checking this call result before trying to display special cases
1213bool
1214ValueObject::HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001215 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001216{
1217 clang_type_t elem_or_pointee_type;
1218 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1219
1220 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1221 && val_obj_display == ValueObject::eDisplayValue)
1222 {
1223 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001224 (custom_format == eFormatCString ||
1225 custom_format == eFormatCharArray ||
1226 custom_format == eFormatChar ||
1227 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001228 return true;
1229
1230 if (flags.Test(ClangASTContext::eTypeIsArray))
1231 {
Greg Claytonafacd142011-09-02 01:15:17 +00001232 if ((custom_format == eFormatBytes) ||
1233 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001234 return true;
1235
Greg Claytonafacd142011-09-02 01:15:17 +00001236 if ((custom_format == eFormatVectorOfChar) ||
1237 (custom_format == eFormatVectorOfFloat32) ||
1238 (custom_format == eFormatVectorOfFloat64) ||
1239 (custom_format == eFormatVectorOfSInt16) ||
1240 (custom_format == eFormatVectorOfSInt32) ||
1241 (custom_format == eFormatVectorOfSInt64) ||
1242 (custom_format == eFormatVectorOfSInt8) ||
1243 (custom_format == eFormatVectorOfUInt128) ||
1244 (custom_format == eFormatVectorOfUInt16) ||
1245 (custom_format == eFormatVectorOfUInt32) ||
1246 (custom_format == eFormatVectorOfUInt64) ||
1247 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001248 return true;
1249 }
1250 }
1251 return false;
1252}
1253
Enrico Granata9fc19442011-07-06 02:13:41 +00001254bool
1255ValueObject::DumpPrintableRepresentation(Stream& s,
1256 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001257 Format custom_format,
Enrico Granata85933ed2011-08-18 16:38:26 +00001258 bool only_special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001259{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001260
1261 clang_type_t elem_or_pointee_type;
1262 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001263
Enrico Granataf4efecd2011-07-12 22:56:10 +00001264 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1265 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001266 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001267 // when being asked to get a printable display an array or pointer type directly,
1268 // try to "do the right thing"
1269
1270 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001271 (custom_format == eFormatCString ||
1272 custom_format == eFormatCharArray ||
1273 custom_format == eFormatChar ||
1274 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001275 {
1276 Error error;
1277 ReadPointedString(s,
1278 error,
1279 0,
Greg Claytonafacd142011-09-02 01:15:17 +00001280 (custom_format == eFormatVectorOfChar) ||
1281 (custom_format == eFormatCharArray));
Enrico Granataf4efecd2011-07-12 22:56:10 +00001282 return !error.Fail();
1283 }
1284
Greg Claytonafacd142011-09-02 01:15:17 +00001285 if (custom_format == eFormatEnum)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001286 return false;
1287
1288 // this only works for arrays, because I have no way to know when
1289 // the pointed memory ends, and no special \0 end of data marker
1290 if (flags.Test(ClangASTContext::eTypeIsArray))
1291 {
Greg Claytonafacd142011-09-02 01:15:17 +00001292 if ((custom_format == eFormatBytes) ||
1293 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001294 {
1295 uint32_t count = GetNumChildren();
1296
1297 s << '[';
1298 for (uint32_t low = 0; low < count; low++)
1299 {
1300
1301 if (low)
1302 s << ',';
1303
1304 ValueObjectSP child = GetChildAtIndex(low,true);
1305 if (!child.get())
1306 {
Enrico Granatae992a082011-07-22 17:03:19 +00001307 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001308 continue;
1309 }
1310 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1311 }
1312
1313 s << ']';
1314
1315 return true;
1316 }
1317
Greg Claytonafacd142011-09-02 01:15:17 +00001318 if ((custom_format == eFormatVectorOfChar) ||
1319 (custom_format == eFormatVectorOfFloat32) ||
1320 (custom_format == eFormatVectorOfFloat64) ||
1321 (custom_format == eFormatVectorOfSInt16) ||
1322 (custom_format == eFormatVectorOfSInt32) ||
1323 (custom_format == eFormatVectorOfSInt64) ||
1324 (custom_format == eFormatVectorOfSInt8) ||
1325 (custom_format == eFormatVectorOfUInt128) ||
1326 (custom_format == eFormatVectorOfUInt16) ||
1327 (custom_format == eFormatVectorOfUInt32) ||
1328 (custom_format == eFormatVectorOfUInt64) ||
1329 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001330 {
1331 uint32_t count = GetNumChildren();
1332
Greg Claytonafacd142011-09-02 01:15:17 +00001333 Format format = FormatManager::GetSingleItemFormat(custom_format);
Enrico Granataf4efecd2011-07-12 22:56:10 +00001334
1335 s << '[';
1336 for (uint32_t low = 0; low < count; low++)
1337 {
1338
1339 if (low)
1340 s << ',';
1341
1342 ValueObjectSP child = GetChildAtIndex(low,true);
1343 if (!child.get())
1344 {
Enrico Granatae992a082011-07-22 17:03:19 +00001345 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001346 continue;
1347 }
1348 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1349 }
1350
1351 s << ']';
1352
1353 return true;
1354 }
1355 }
1356
Greg Claytonafacd142011-09-02 01:15:17 +00001357 if ((custom_format == eFormatBoolean) ||
1358 (custom_format == eFormatBinary) ||
1359 (custom_format == eFormatChar) ||
1360 (custom_format == eFormatCharPrintable) ||
1361 (custom_format == eFormatComplexFloat) ||
1362 (custom_format == eFormatDecimal) ||
1363 (custom_format == eFormatHex) ||
1364 (custom_format == eFormatFloat) ||
1365 (custom_format == eFormatOctal) ||
1366 (custom_format == eFormatOSType) ||
1367 (custom_format == eFormatUnicode16) ||
1368 (custom_format == eFormatUnicode32) ||
1369 (custom_format == eFormatUnsigned) ||
1370 (custom_format == eFormatPointer) ||
1371 (custom_format == eFormatComplexInteger) ||
1372 (custom_format == eFormatComplex) ||
1373 (custom_format == eFormatDefault)) // use the [] operator
Enrico Granataf4efecd2011-07-12 22:56:10 +00001374 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001375 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001376
1377 if (only_special)
1378 return false;
1379
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001380 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001381 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001382 SetFormat(eFormatDefault);
1383 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001384}
1385
Greg Clayton737b9322010-09-13 03:32:57 +00001386addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001387ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001388{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001389 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001390 return LLDB_INVALID_ADDRESS;
1391
Greg Clayton73b472d2010-10-27 03:32:59 +00001392 switch (m_value.GetValueType())
1393 {
1394 case Value::eValueTypeScalar:
1395 if (scalar_is_load_address)
1396 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001397 if(address_type)
1398 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001399 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1400 }
1401 break;
1402
1403 case Value::eValueTypeLoadAddress:
1404 case Value::eValueTypeFileAddress:
1405 case Value::eValueTypeHostAddress:
1406 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001407 if(address_type)
1408 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001409 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1410 }
1411 break;
1412 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001413 if (address_type)
1414 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001415 return LLDB_INVALID_ADDRESS;
1416}
1417
1418addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001419ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001420{
Greg Claytonafacd142011-09-02 01:15:17 +00001421 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001422 if(address_type)
1423 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001424
Enrico Granatac3e320a2011-08-02 17:27:39 +00001425 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001426 return address;
1427
Greg Clayton73b472d2010-10-27 03:32:59 +00001428 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001429 {
1430 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001431 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001432 break;
1433
Enrico Granata9128ee22011-09-06 19:20:51 +00001434 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001435 case Value::eValueTypeLoadAddress:
1436 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001437 {
1438 uint32_t data_offset = 0;
1439 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001440 }
1441 break;
1442 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001443
Enrico Granata9128ee22011-09-06 19:20:51 +00001444 if (address_type)
1445 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001446
Greg Clayton737b9322010-09-13 03:32:57 +00001447 return address;
1448}
1449
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001450bool
Jim Ingham6035b672011-03-31 00:19:25 +00001451ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001452{
1453 // Make sure our value is up to date first so that our location and location
1454 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001455 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001456 return false;
1457
1458 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001459 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001460
Greg Claytonb1320972010-07-14 00:18:15 +00001461 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001462
Jim Ingham16e0c682011-08-12 23:34:31 +00001463 Value::ValueType value_type = m_value.GetValueType();
1464
1465 if (value_type == Value::eValueTypeScalar)
1466 {
1467 // If the value is already a scalar, then let the scalar change itself:
1468 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1469 }
1470 else if (byte_size <= Scalar::GetMaxByteSize())
1471 {
1472 // If the value fits in a scalar, then make a new scalar and again let the
1473 // scalar code do the conversion, then figure out where to put the new value.
1474 Scalar new_scalar;
1475 Error error;
1476 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1477 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001478 {
Jim Ingham4b536182011-08-09 02:12:22 +00001479 switch (value_type)
1480 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001481 case Value::eValueTypeLoadAddress:
1482 {
1483 // If it is a load address, then the scalar value is the storage location
1484 // of the data, and we have to shove this value down to that load location.
1485 ProcessSP process_sp = GetUpdatePoint().GetProcessSP();
1486 if (process_sp)
1487 {
Greg Claytonafacd142011-09-02 01:15:17 +00001488 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Jim Ingham16e0c682011-08-12 23:34:31 +00001489 size_t bytes_written = process_sp->WriteScalarToMemory (target_addr,
1490 new_scalar,
1491 byte_size,
1492 error);
1493 if (!error.Success() || bytes_written != byte_size)
1494 return false;
1495 }
1496 }
Jim Ingham4b536182011-08-09 02:12:22 +00001497 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001498 case Value::eValueTypeHostAddress:
1499 {
1500 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1501 DataExtractor new_data;
1502 new_data.SetByteOrder (m_data.GetByteOrder());
1503
1504 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1505 m_data.SetData(buffer_sp, 0);
1506 bool success = new_scalar.GetData(new_data);
1507 if (success)
1508 {
1509 new_data.CopyByteOrderedData(0,
1510 byte_size,
1511 const_cast<uint8_t *>(m_data.GetDataStart()),
1512 byte_size,
1513 m_data.GetByteOrder());
1514 }
1515 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1516
1517 }
Jim Ingham4b536182011-08-09 02:12:22 +00001518 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001519 case Value::eValueTypeFileAddress:
1520 case Value::eValueTypeScalar:
1521 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001522 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001523 }
1524 else
1525 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001526 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001527 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001528 }
1529 else
1530 {
1531 // We don't support setting things bigger than a scalar at present.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001532 return false;
1533 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001534
1535 // If we have reached this point, then we have successfully changed the value.
1536 SetNeedsUpdate();
1537 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001538}
1539
Greg Claytonafacd142011-09-02 01:15:17 +00001540LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001541ValueObject::GetObjectRuntimeLanguage ()
1542{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001543 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1544 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001545}
1546
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001547void
Jim Ingham58b59f92011-04-22 23:53:53 +00001548ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001549{
Jim Ingham58b59f92011-04-22 23:53:53 +00001550 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001551}
1552
1553ValueObjectSP
1554ValueObject::GetSyntheticChild (const ConstString &key) const
1555{
1556 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001557 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001558 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001559 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001560 return synthetic_child_sp;
1561}
1562
1563bool
1564ValueObject::IsPointerType ()
1565{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001566 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001567}
1568
Jim Inghamb7603bb2011-03-18 00:05:18 +00001569bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001570ValueObject::IsArrayType ()
1571{
1572 return ClangASTContext::IsArrayType (GetClangType());
1573}
1574
1575bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001576ValueObject::IsScalarType ()
1577{
1578 return ClangASTContext::IsScalarType (GetClangType());
1579}
1580
1581bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001582ValueObject::IsIntegerType (bool &is_signed)
1583{
1584 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1585}
Greg Clayton73b472d2010-10-27 03:32:59 +00001586
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001587bool
1588ValueObject::IsPointerOrReferenceType ()
1589{
Greg Clayton007d5be2011-05-30 00:49:24 +00001590 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1591}
1592
1593bool
1594ValueObject::IsPossibleCPlusPlusDynamicType ()
1595{
1596 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001597}
1598
Greg Claytondea8cb42011-06-29 22:09:02 +00001599bool
1600ValueObject::IsPossibleDynamicType ()
1601{
1602 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1603}
1604
Greg Claytonafacd142011-09-02 01:15:17 +00001605ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001606ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1607{
1608 if (IsArrayType())
1609 return GetSyntheticArrayMemberFromArray(index, can_create);
1610
1611 if (IsPointerType())
1612 return GetSyntheticArrayMemberFromPointer(index, can_create);
1613
1614 return ValueObjectSP();
1615
1616}
1617
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001618ValueObjectSP
1619ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1620{
1621 ValueObjectSP synthetic_child_sp;
1622 if (IsPointerType ())
1623 {
1624 char index_str[64];
1625 snprintf(index_str, sizeof(index_str), "[%i]", index);
1626 ConstString index_const_str(index_str);
1627 // Check if we have already created a synthetic array member in this
1628 // valid object. If we have we will re-use it.
1629 synthetic_child_sp = GetSyntheticChild (index_const_str);
1630 if (!synthetic_child_sp)
1631 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001632 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001633 // We haven't made a synthetic array member for INDEX yet, so
1634 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001635 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001636
1637 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001638 if (synthetic_child)
1639 {
1640 AddSyntheticChild(index_const_str, synthetic_child);
1641 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001642 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001643 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001644 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001645 }
1646 }
1647 return synthetic_child_sp;
1648}
Jim Ingham22777012010-09-23 02:01:19 +00001649
Greg Claytondaf515f2011-07-09 20:12:33 +00001650// This allows you to create an array member using and index
1651// that doesn't not fall in the normal bounds of the array.
1652// Many times structure can be defined as:
1653// struct Collection
1654// {
1655// uint32_t item_count;
1656// Item item_array[0];
1657// };
1658// The size of the "item_array" is 1, but many times in practice
1659// there are more items in "item_array".
1660
1661ValueObjectSP
1662ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1663{
1664 ValueObjectSP synthetic_child_sp;
1665 if (IsArrayType ())
1666 {
1667 char index_str[64];
1668 snprintf(index_str, sizeof(index_str), "[%i]", index);
1669 ConstString index_const_str(index_str);
1670 // Check if we have already created a synthetic array member in this
1671 // valid object. If we have we will re-use it.
1672 synthetic_child_sp = GetSyntheticChild (index_const_str);
1673 if (!synthetic_child_sp)
1674 {
1675 ValueObject *synthetic_child;
1676 // We haven't made a synthetic array member for INDEX yet, so
1677 // lets make one and cache it for any future reference.
1678 synthetic_child = CreateChildAtIndex(0, true, index);
1679
1680 // Cache the value if we got one back...
1681 if (synthetic_child)
1682 {
1683 AddSyntheticChild(index_const_str, synthetic_child);
1684 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001685 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001686 synthetic_child_sp->m_is_array_item_for_pointer = true;
1687 }
1688 }
1689 }
1690 return synthetic_child_sp;
1691}
1692
Enrico Granata9fc19442011-07-06 02:13:41 +00001693ValueObjectSP
1694ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1695{
1696 ValueObjectSP synthetic_child_sp;
1697 if (IsScalarType ())
1698 {
1699 char index_str[64];
1700 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1701 ConstString index_const_str(index_str);
1702 // Check if we have already created a synthetic array member in this
1703 // valid object. If we have we will re-use it.
1704 synthetic_child_sp = GetSyntheticChild (index_const_str);
1705 if (!synthetic_child_sp)
1706 {
1707 ValueObjectChild *synthetic_child;
1708 // We haven't made a synthetic array member for INDEX yet, so
1709 // lets make one and cache it for any future reference.
1710 synthetic_child = new ValueObjectChild(*this,
1711 GetClangAST(),
1712 GetClangType(),
1713 index_const_str,
1714 GetByteSize(),
1715 0,
1716 to-from+1,
1717 from,
1718 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001719 false,
1720 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001721
1722 // Cache the value if we got one back...
1723 if (synthetic_child)
1724 {
1725 AddSyntheticChild(index_const_str, synthetic_child);
1726 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001727 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001728 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1729 }
1730 }
1731 }
1732 return synthetic_child_sp;
1733}
1734
Greg Claytonafacd142011-09-02 01:15:17 +00001735ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001736ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1737{
1738 ValueObjectSP synthetic_child_sp;
1739 if (IsArrayType () || IsPointerType ())
1740 {
1741 char index_str[64];
1742 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1743 ConstString index_const_str(index_str);
1744 // Check if we have already created a synthetic array member in this
1745 // valid object. If we have we will re-use it.
1746 synthetic_child_sp = GetSyntheticChild (index_const_str);
1747 if (!synthetic_child_sp)
1748 {
1749 ValueObjectSynthetic *synthetic_child;
1750
1751 // We haven't made a synthetic array member for INDEX yet, so
1752 // lets make one and cache it for any future reference.
1753 SyntheticArrayView *view = new SyntheticArrayView();
1754 view->AddRange(from,to);
1755 SyntheticChildrenSP view_sp(view);
1756 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1757
1758 // Cache the value if we got one back...
1759 if (synthetic_child)
1760 {
1761 AddSyntheticChild(index_const_str, synthetic_child);
1762 synthetic_child_sp = synthetic_child->GetSP();
1763 synthetic_child_sp->SetName(ConstString(index_str));
1764 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1765 }
1766 }
1767 }
1768 return synthetic_child_sp;
1769}
1770
Greg Claytonafacd142011-09-02 01:15:17 +00001771ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001772ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1773{
1774
1775 ValueObjectSP synthetic_child_sp;
1776
1777 char name_str[64];
1778 snprintf(name_str, sizeof(name_str), "@%i", offset);
1779 ConstString name_const_str(name_str);
1780
1781 // Check if we have already created a synthetic array member in this
1782 // valid object. If we have we will re-use it.
1783 synthetic_child_sp = GetSyntheticChild (name_const_str);
1784
1785 if (synthetic_child_sp.get())
1786 return synthetic_child_sp;
1787
1788 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001789 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001790
1791 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1792 type.GetASTContext(),
1793 type.GetOpaqueQualType(),
1794 name_const_str,
1795 type.GetTypeByteSize(),
1796 offset,
1797 0,
1798 0,
1799 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001800 false,
1801 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001802 if (synthetic_child)
1803 {
1804 AddSyntheticChild(name_const_str, synthetic_child);
1805 synthetic_child_sp = synthetic_child->GetSP();
1806 synthetic_child_sp->SetName(name_const_str);
1807 synthetic_child_sp->m_is_child_at_offset = true;
1808 }
1809 return synthetic_child_sp;
1810}
1811
Enrico Granatad55546b2011-07-22 00:16:08 +00001812// your expression path needs to have a leading . or ->
1813// (unless it somehow "looks like" an array, in which case it has
1814// a leading [ symbol). while the [ is meaningful and should be shown
1815// to the user, . and -> are just parser design, but by no means
1816// added information for the user.. strip them off
1817static const char*
1818SkipLeadingExpressionPathSeparators(const char* expression)
1819{
1820 if (!expression || !expression[0])
1821 return expression;
1822 if (expression[0] == '.')
1823 return expression+1;
1824 if (expression[0] == '-' && expression[1] == '>')
1825 return expression+2;
1826 return expression;
1827}
1828
Greg Claytonafacd142011-09-02 01:15:17 +00001829ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00001830ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1831{
1832 ValueObjectSP synthetic_child_sp;
1833 ConstString name_const_string(expression);
1834 // Check if we have already created a synthetic array member in this
1835 // valid object. If we have we will re-use it.
1836 synthetic_child_sp = GetSyntheticChild (name_const_string);
1837 if (!synthetic_child_sp)
1838 {
1839 // We haven't made a synthetic array member for expression yet, so
1840 // lets make one and cache it for any future reference.
1841 synthetic_child_sp = GetValueForExpressionPath(expression);
1842
1843 // Cache the value if we got one back...
1844 if (synthetic_child_sp.get())
1845 {
1846 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001847 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001848 synthetic_child_sp->m_is_expression_path_child = true;
1849 }
1850 }
1851 return synthetic_child_sp;
1852}
1853
1854void
Greg Claytonafacd142011-09-02 01:15:17 +00001855ValueObject::CalculateSyntheticValue (SyntheticValueType use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00001856{
Greg Claytonafacd142011-09-02 01:15:17 +00001857 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001858 return;
1859
Enrico Granatac3e320a2011-08-02 17:27:39 +00001860 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001861
1862 if (m_last_synthetic_filter.get() == NULL)
1863 return;
1864
Enrico Granataa37a0652011-07-24 00:14:56 +00001865 if (m_synthetic_value == NULL)
1866 m_synthetic_value = new ValueObjectSynthetic(*this, m_last_synthetic_filter);
Enrico Granatad55546b2011-07-22 00:16:08 +00001867
1868}
1869
Jim Ingham78a685a2011-04-16 00:01:13 +00001870void
Greg Claytonafacd142011-09-02 01:15:17 +00001871ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00001872{
Greg Claytonafacd142011-09-02 01:15:17 +00001873 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00001874 return;
1875
Jim Ingham58b59f92011-04-22 23:53:53 +00001876 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00001877 {
Enrico Granata6f3533f2011-07-29 19:53:35 +00001878 Process *process = m_update_point.GetProcessSP().get();
Jim Ingham78a685a2011-04-16 00:01:13 +00001879 bool worth_having_dynamic_value = false;
Jim Ingham22777012010-09-23 02:01:19 +00001880
Jim Ingham78a685a2011-04-16 00:01:13 +00001881
1882 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
1883 // hard code this everywhere.
Greg Claytonafacd142011-09-02 01:15:17 +00001884 LanguageType known_type = GetObjectRuntimeLanguage();
1885 if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
Jim Ingham78a685a2011-04-16 00:01:13 +00001886 {
1887 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
1888 if (runtime)
1889 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
1890 }
1891 else
1892 {
Greg Claytonafacd142011-09-02 01:15:17 +00001893 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus);
Jim Ingham78a685a2011-04-16 00:01:13 +00001894 if (cpp_runtime)
1895 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
1896
1897 if (!worth_having_dynamic_value)
1898 {
Greg Claytonafacd142011-09-02 01:15:17 +00001899 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC);
Jim Ingham78a685a2011-04-16 00:01:13 +00001900 if (objc_runtime)
Jim Ingham2837b762011-05-04 03:43:18 +00001901 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00001902 }
1903 }
1904
1905 if (worth_having_dynamic_value)
Jim Ingham2837b762011-05-04 03:43:18 +00001906 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham58b59f92011-04-22 23:53:53 +00001907
1908// if (worth_having_dynamic_value)
1909// printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager);
1910
Jim Ingham78a685a2011-04-16 00:01:13 +00001911 }
1912}
1913
Jim Ingham58b59f92011-04-22 23:53:53 +00001914ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00001915ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00001916{
Greg Claytonafacd142011-09-02 01:15:17 +00001917 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00001918 return ValueObjectSP();
1919
1920 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00001921 {
Jim Ingham2837b762011-05-04 03:43:18 +00001922 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001923 }
Jim Ingham58b59f92011-04-22 23:53:53 +00001924 if (m_dynamic_value)
1925 return m_dynamic_value->GetSP();
1926 else
1927 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00001928}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001929
Enrico Granatad55546b2011-07-22 00:16:08 +00001930// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
1931// or we do not really want a dynamic VO. this method instead returns this object
1932// itself when making it synthetic has no meaning. this makes it much simpler
1933// to replace the SyntheticValue for the ValueObject
1934ValueObjectSP
1935ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
1936{
Greg Claytonafacd142011-09-02 01:15:17 +00001937 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001938 return GetSP();
1939
Enrico Granatac3e320a2011-08-02 17:27:39 +00001940 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001941
1942 if (m_last_synthetic_filter.get() == NULL)
1943 return GetSP();
1944
1945 CalculateSyntheticValue(use_synthetic);
1946
1947 if (m_synthetic_value)
1948 return m_synthetic_value->GetSP();
1949 else
1950 return GetSP();
1951}
1952
Greg Claytone221f822011-01-21 01:59:00 +00001953bool
Enrico Granata27b625e2011-08-09 01:04:56 +00001954ValueObject::HasSyntheticValue()
1955{
1956 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
1957
1958 if (m_last_synthetic_filter.get() == NULL)
1959 return false;
1960
Greg Claytonafacd142011-09-02 01:15:17 +00001961 CalculateSyntheticValue(eUseSyntheticFilter);
Enrico Granata27b625e2011-08-09 01:04:56 +00001962
1963 if (m_synthetic_value)
1964 return true;
1965 else
1966 return false;
1967}
1968
1969bool
Greg Claytone221f822011-01-21 01:59:00 +00001970ValueObject::GetBaseClassPath (Stream &s)
1971{
1972 if (IsBaseClass())
1973 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001974 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00001975 clang_type_t clang_type = GetClangType();
1976 std::string cxx_class_name;
1977 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
1978 if (this_had_base_class)
1979 {
1980 if (parent_had_base_class)
1981 s.PutCString("::");
1982 s.PutCString(cxx_class_name.c_str());
1983 }
1984 return parent_had_base_class || this_had_base_class;
1985 }
1986 return false;
1987}
1988
1989
1990ValueObject *
1991ValueObject::GetNonBaseClassParent()
1992{
Jim Ingham78a685a2011-04-16 00:01:13 +00001993 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00001994 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001995 if (GetParent()->IsBaseClass())
1996 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00001997 else
Jim Ingham78a685a2011-04-16 00:01:13 +00001998 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00001999 }
2000 return NULL;
2001}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002002
2003void
Enrico Granata4becb372011-06-29 22:27:15 +00002004ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002005{
Greg Claytone221f822011-01-21 01:59:00 +00002006 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002007
Enrico Granata85933ed2011-08-18 16:38:26 +00002008 if (is_deref_of_parent && epformat == eDereferencePointers)
2009 {
Enrico Granata4becb372011-06-29 22:27:15 +00002010 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2011 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2012 // the eHonorPointers mode is meant to produce strings in this latter format
2013 s.PutCString("*(");
2014 }
Greg Claytone221f822011-01-21 01:59:00 +00002015
Enrico Granata4becb372011-06-29 22:27:15 +00002016 ValueObject* parent = GetParent();
2017
2018 if (parent)
2019 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002020
2021 // if we are a deref_of_parent just because we are synthetic array
2022 // members made up to allow ptr[%d] syntax to work in variable
2023 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00002024 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002025 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002026
Greg Claytone221f822011-01-21 01:59:00 +00002027 if (!IsBaseClass())
2028 {
2029 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002030 {
Greg Claytone221f822011-01-21 01:59:00 +00002031 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2032 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002033 {
Greg Claytone221f822011-01-21 01:59:00 +00002034 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2035 if (non_base_class_parent_clang_type)
2036 {
2037 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2038
Enrico Granata9dd75c82011-07-15 23:30:15 +00002039 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002040 {
2041 s.PutCString("->");
2042 }
Enrico Granata4becb372011-06-29 22:27:15 +00002043 else
2044 {
2045 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2046 {
2047 s.PutCString("->");
2048 }
2049 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2050 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2051 {
2052 s.PutChar('.');
2053 }
Greg Claytone221f822011-01-21 01:59:00 +00002054 }
2055 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002056 }
Greg Claytone221f822011-01-21 01:59:00 +00002057
2058 const char *name = GetName().GetCString();
2059 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002060 {
Greg Claytone221f822011-01-21 01:59:00 +00002061 if (qualify_cxx_base_classes)
2062 {
2063 if (GetBaseClassPath (s))
2064 s.PutCString("::");
2065 }
2066 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002067 }
2068 }
2069 }
2070
Enrico Granata85933ed2011-08-18 16:38:26 +00002071 if (is_deref_of_parent && epformat == eDereferencePointers)
2072 {
Greg Claytone221f822011-01-21 01:59:00 +00002073 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002074 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002075}
2076
Greg Claytonafacd142011-09-02 01:15:17 +00002077ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002078ValueObject::GetValueForExpressionPath(const char* expression,
2079 const char** first_unparsed,
2080 ExpressionPathScanEndReason* reason_to_stop,
2081 ExpressionPathEndResultType* final_value_type,
2082 const GetValueForExpressionPathOptions& options,
2083 ExpressionPathAftermath* final_task_on_target)
2084{
2085
2086 const char* dummy_first_unparsed;
2087 ExpressionPathScanEndReason dummy_reason_to_stop;
2088 ExpressionPathEndResultType dummy_final_value_type;
2089 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2090
2091 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2092 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2093 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2094 final_value_type ? final_value_type : &dummy_final_value_type,
2095 options,
2096 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2097
2098 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2099 {
2100 return ret_val;
2101 }
2102 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2103 {
2104 if (*final_task_on_target == ValueObject::eDereference)
2105 {
2106 Error error;
2107 ValueObjectSP final_value = ret_val->Dereference(error);
2108 if (error.Fail() || !final_value.get())
2109 {
2110 *reason_to_stop = ValueObject::eDereferencingFailed;
2111 *final_value_type = ValueObject::eInvalid;
2112 return ValueObjectSP();
2113 }
2114 else
2115 {
2116 *final_task_on_target = ValueObject::eNothing;
2117 return final_value;
2118 }
2119 }
2120 if (*final_task_on_target == ValueObject::eTakeAddress)
2121 {
2122 Error error;
2123 ValueObjectSP final_value = ret_val->AddressOf(error);
2124 if (error.Fail() || !final_value.get())
2125 {
2126 *reason_to_stop = ValueObject::eTakingAddressFailed;
2127 *final_value_type = ValueObject::eInvalid;
2128 return ValueObjectSP();
2129 }
2130 else
2131 {
2132 *final_task_on_target = ValueObject::eNothing;
2133 return final_value;
2134 }
2135 }
2136 }
2137 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2138}
2139
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002140int
2141ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002142 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002143 const char** first_unparsed,
2144 ExpressionPathScanEndReason* reason_to_stop,
2145 ExpressionPathEndResultType* final_value_type,
2146 const GetValueForExpressionPathOptions& options,
2147 ExpressionPathAftermath* final_task_on_target)
2148{
2149 const char* dummy_first_unparsed;
2150 ExpressionPathScanEndReason dummy_reason_to_stop;
2151 ExpressionPathEndResultType dummy_final_value_type;
2152 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
2153
2154 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2155 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2156 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2157 final_value_type ? final_value_type : &dummy_final_value_type,
2158 options,
2159 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2160
2161 if (!ret_val.get()) // if there are errors, I add nothing to the list
2162 return 0;
2163
2164 if (*reason_to_stop != eArrayRangeOperatorMet)
2165 {
2166 // I need not expand a range, just post-process the final value and return
2167 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2168 {
2169 list->Append(ret_val);
2170 return 1;
2171 }
2172 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2173 {
2174 if (*final_task_on_target == ValueObject::eDereference)
2175 {
2176 Error error;
2177 ValueObjectSP final_value = ret_val->Dereference(error);
2178 if (error.Fail() || !final_value.get())
2179 {
2180 *reason_to_stop = ValueObject::eDereferencingFailed;
2181 *final_value_type = ValueObject::eInvalid;
2182 return 0;
2183 }
2184 else
2185 {
2186 *final_task_on_target = ValueObject::eNothing;
2187 list->Append(final_value);
2188 return 1;
2189 }
2190 }
2191 if (*final_task_on_target == ValueObject::eTakeAddress)
2192 {
2193 Error error;
2194 ValueObjectSP final_value = ret_val->AddressOf(error);
2195 if (error.Fail() || !final_value.get())
2196 {
2197 *reason_to_stop = ValueObject::eTakingAddressFailed;
2198 *final_value_type = ValueObject::eInvalid;
2199 return 0;
2200 }
2201 else
2202 {
2203 *final_task_on_target = ValueObject::eNothing;
2204 list->Append(final_value);
2205 return 1;
2206 }
2207 }
2208 }
2209 }
2210 else
2211 {
2212 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2213 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2214 ret_val,
2215 list,
2216 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2217 final_value_type ? final_value_type : &dummy_final_value_type,
2218 options,
2219 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2220 }
2221 // in any non-covered case, just do the obviously right thing
2222 list->Append(ret_val);
2223 return 1;
2224}
2225
Greg Claytonafacd142011-09-02 01:15:17 +00002226ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002227ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2228 const char** first_unparsed,
2229 ExpressionPathScanEndReason* reason_to_stop,
2230 ExpressionPathEndResultType* final_result,
2231 const GetValueForExpressionPathOptions& options,
2232 ExpressionPathAftermath* what_next)
2233{
2234 ValueObjectSP root = GetSP();
2235
2236 if (!root.get())
2237 return ValueObjectSP();
2238
2239 *first_unparsed = expression_cstr;
2240
2241 while (true)
2242 {
2243
2244 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2245
Greg Claytonafacd142011-09-02 01:15:17 +00002246 clang_type_t root_clang_type = root->GetClangType();
2247 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002248 Flags root_clang_type_info,pointee_clang_type_info;
2249
2250 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2251 if (pointee_clang_type)
2252 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002253
2254 if (!expression_cstr || *expression_cstr == '\0')
2255 {
2256 *reason_to_stop = ValueObject::eEndOfString;
2257 return root;
2258 }
2259
2260 switch (*expression_cstr)
2261 {
2262 case '-':
2263 {
2264 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002265 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 +00002266 {
2267 *first_unparsed = expression_cstr;
2268 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
2269 *final_result = ValueObject::eInvalid;
2270 return ValueObjectSP();
2271 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002272 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2273 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002274 options.m_no_fragile_ivar)
2275 {
2276 *first_unparsed = expression_cstr;
2277 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
2278 *final_result = ValueObject::eInvalid;
2279 return ValueObjectSP();
2280 }
2281 if (expression_cstr[1] != '>')
2282 {
2283 *first_unparsed = expression_cstr;
2284 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2285 *final_result = ValueObject::eInvalid;
2286 return ValueObjectSP();
2287 }
2288 expression_cstr++; // skip the -
2289 }
2290 case '.': // or fallthrough from ->
2291 {
2292 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002293 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 +00002294 {
2295 *first_unparsed = expression_cstr;
2296 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
2297 *final_result = ValueObject::eInvalid;
2298 return ValueObjectSP();
2299 }
2300 expression_cstr++; // skip .
2301 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2302 ConstString child_name;
2303 if (!next_separator) // if no other separator just expand this last layer
2304 {
2305 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002306 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2307
2308 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002309 {
2310 *first_unparsed = '\0';
2311 *reason_to_stop = ValueObject::eEndOfString;
2312 *final_result = ValueObject::ePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002313 return child_valobj_sp;
2314 }
2315 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2316 {
Greg Claytonafacd142011-09-02 01:15:17 +00002317 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002318 }
2319
2320 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2321 // so we hit the "else" branch, and return an error
2322 if(child_valobj_sp.get()) // if it worked, just return
2323 {
2324 *first_unparsed = '\0';
2325 *reason_to_stop = ValueObject::eEndOfString;
2326 *final_result = ValueObject::ePlain;
2327 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002328 }
2329 else
2330 {
2331 *first_unparsed = expression_cstr;
2332 *reason_to_stop = ValueObject::eNoSuchChild;
2333 *final_result = ValueObject::eInvalid;
2334 return ValueObjectSP();
2335 }
2336 }
2337 else // other layers do expand
2338 {
2339 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002340 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2341 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002342 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002343 root = child_valobj_sp;
2344 *first_unparsed = next_separator;
2345 *final_result = ValueObject::ePlain;
2346 continue;
2347 }
2348 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2349 {
Greg Claytonafacd142011-09-02 01:15:17 +00002350 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002351 }
2352
2353 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2354 // so we hit the "else" branch, and return an error
2355 if(child_valobj_sp.get()) // if it worked, move on
2356 {
2357 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002358 *first_unparsed = next_separator;
2359 *final_result = ValueObject::ePlain;
2360 continue;
2361 }
2362 else
2363 {
2364 *first_unparsed = expression_cstr;
2365 *reason_to_stop = ValueObject::eNoSuchChild;
2366 *final_result = ValueObject::eInvalid;
2367 return ValueObjectSP();
2368 }
2369 }
2370 break;
2371 }
2372 case '[':
2373 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002374 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 +00002375 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002376 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002377 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002378 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2379 {
2380 *first_unparsed = expression_cstr;
2381 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2382 *final_result = ValueObject::eInvalid;
2383 return ValueObjectSP();
2384 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002385 }
2386 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2387 {
2388 *first_unparsed = expression_cstr;
2389 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2390 *final_result = ValueObject::eInvalid;
2391 return ValueObjectSP();
2392 }
2393 }
2394 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2395 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002396 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002397 {
2398 *first_unparsed = expression_cstr;
2399 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2400 *final_result = ValueObject::eInvalid;
2401 return ValueObjectSP();
2402 }
2403 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2404 {
2405 *first_unparsed = expression_cstr+2;
2406 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2407 *final_result = ValueObject::eUnboundedRange;
2408 return root;
2409 }
2410 }
2411 const char *separator_position = ::strchr(expression_cstr+1,'-');
2412 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2413 if (!close_bracket_position) // if there is no ], this is a syntax error
2414 {
2415 *first_unparsed = expression_cstr;
2416 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2417 *final_result = ValueObject::eInvalid;
2418 return ValueObjectSP();
2419 }
2420 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2421 {
2422 char *end = NULL;
2423 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2424 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2425 {
2426 *first_unparsed = expression_cstr;
2427 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2428 *final_result = ValueObject::eInvalid;
2429 return ValueObjectSP();
2430 }
2431 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2432 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002433 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002434 {
2435 *first_unparsed = expression_cstr+2;
2436 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2437 *final_result = ValueObject::eUnboundedRange;
2438 return root;
2439 }
2440 else
2441 {
2442 *first_unparsed = expression_cstr;
2443 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2444 *final_result = ValueObject::eInvalid;
2445 return ValueObjectSP();
2446 }
2447 }
2448 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002449 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002450 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002451 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2452 if (!child_valobj_sp)
2453 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002454 if (!child_valobj_sp)
Greg Claytonafacd142011-09-02 01:15:17 +00002455 if (root->HasSyntheticValue() && root->GetSyntheticValue(eUseSyntheticFilter)->GetNumChildren() > index)
2456 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002457 if (child_valobj_sp)
2458 {
2459 root = child_valobj_sp;
2460 *first_unparsed = end+1; // skip ]
2461 *final_result = ValueObject::ePlain;
2462 continue;
2463 }
2464 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002465 {
2466 *first_unparsed = expression_cstr;
2467 *reason_to_stop = ValueObject::eNoSuchChild;
2468 *final_result = ValueObject::eInvalid;
2469 return ValueObjectSP();
2470 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002471 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002472 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002473 {
2474 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 +00002475 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002476 {
2477 Error error;
2478 root = root->Dereference(error);
2479 if (error.Fail() || !root.get())
2480 {
2481 *first_unparsed = expression_cstr;
2482 *reason_to_stop = ValueObject::eDereferencingFailed;
2483 *final_result = ValueObject::eInvalid;
2484 return ValueObjectSP();
2485 }
2486 else
2487 {
2488 *what_next = eNothing;
2489 continue;
2490 }
2491 }
2492 else
2493 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002494 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Claytonafacd142011-09-02 01:15:17 +00002495 root->GetClangType()) == eLanguageTypeObjC
Enrico Granata27b625e2011-08-09 01:04:56 +00002496 &&
2497 ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2498 &&
2499 root->HasSyntheticValue()
2500 &&
2501 options.m_no_synthetic_children == false)
2502 {
Greg Claytonafacd142011-09-02 01:15:17 +00002503 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002504 }
2505 else
2506 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002507 if (!root.get())
2508 {
2509 *first_unparsed = expression_cstr;
2510 *reason_to_stop = ValueObject::eNoSuchChild;
2511 *final_result = ValueObject::eInvalid;
2512 return ValueObjectSP();
2513 }
2514 else
2515 {
2516 *first_unparsed = end+1; // skip ]
2517 *final_result = ValueObject::ePlain;
2518 continue;
2519 }
2520 }
2521 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002522 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002523 {
2524 root = root->GetSyntheticBitFieldChild(index, index, true);
2525 if (!root.get())
2526 {
2527 *first_unparsed = expression_cstr;
2528 *reason_to_stop = ValueObject::eNoSuchChild;
2529 *final_result = ValueObject::eInvalid;
2530 return ValueObjectSP();
2531 }
2532 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2533 {
2534 *first_unparsed = end+1; // skip ]
2535 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2536 *final_result = ValueObject::eBitfield;
2537 return root;
2538 }
2539 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002540 else if (root->HasSyntheticValue() && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002541 {
Greg Claytonafacd142011-09-02 01:15:17 +00002542 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002543 if (!root.get())
2544 {
2545 *first_unparsed = expression_cstr;
2546 *reason_to_stop = ValueObject::eNoSuchChild;
2547 *final_result = ValueObject::eInvalid;
2548 return ValueObjectSP();
2549 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002550 else
2551 {
2552 *first_unparsed = end+1; // skip ]
2553 *final_result = ValueObject::ePlain;
2554 continue;
2555 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002556 }
2557 else
2558 {
2559 *first_unparsed = expression_cstr;
2560 *reason_to_stop = ValueObject::eNoSuchChild;
2561 *final_result = ValueObject::eInvalid;
2562 return ValueObjectSP();
2563 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002564 }
2565 else // we have a low and a high index
2566 {
2567 char *end = NULL;
2568 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2569 if (!end || end != separator_position) // if something weird is in our way return an error
2570 {
2571 *first_unparsed = expression_cstr;
2572 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2573 *final_result = ValueObject::eInvalid;
2574 return ValueObjectSP();
2575 }
2576 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2577 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2578 {
2579 *first_unparsed = expression_cstr;
2580 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2581 *final_result = ValueObject::eInvalid;
2582 return ValueObjectSP();
2583 }
2584 if (index_lower > index_higher) // swap indices if required
2585 {
2586 unsigned long temp = index_lower;
2587 index_lower = index_higher;
2588 index_higher = temp;
2589 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002590 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002591 {
2592 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2593 if (!root.get())
2594 {
2595 *first_unparsed = expression_cstr;
2596 *reason_to_stop = ValueObject::eNoSuchChild;
2597 *final_result = ValueObject::eInvalid;
2598 return ValueObjectSP();
2599 }
2600 else
2601 {
2602 *first_unparsed = end+1; // skip ]
2603 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2604 *final_result = ValueObject::eBitfield;
2605 return root;
2606 }
2607 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002608 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 +00002609 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002610 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002611 {
2612 Error error;
2613 root = root->Dereference(error);
2614 if (error.Fail() || !root.get())
2615 {
2616 *first_unparsed = expression_cstr;
2617 *reason_to_stop = ValueObject::eDereferencingFailed;
2618 *final_result = ValueObject::eInvalid;
2619 return ValueObjectSP();
2620 }
2621 else
2622 {
2623 *what_next = ValueObject::eNothing;
2624 continue;
2625 }
2626 }
2627 else
2628 {
2629 *first_unparsed = expression_cstr;
2630 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2631 *final_result = ValueObject::eBoundedRange;
2632 return root;
2633 }
2634 }
2635 break;
2636 }
2637 default: // some non-separator is in the way
2638 {
2639 *first_unparsed = expression_cstr;
2640 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2641 *final_result = ValueObject::eInvalid;
2642 return ValueObjectSP();
2643 break;
2644 }
2645 }
2646 }
2647}
2648
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002649int
2650ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2651 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002652 ValueObjectSP root,
2653 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002654 ExpressionPathScanEndReason* reason_to_stop,
2655 ExpressionPathEndResultType* final_result,
2656 const GetValueForExpressionPathOptions& options,
2657 ExpressionPathAftermath* what_next)
2658{
2659 if (!root.get())
2660 return 0;
2661
2662 *first_unparsed = expression_cstr;
2663
2664 while (true)
2665 {
2666
2667 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2668
Greg Claytonafacd142011-09-02 01:15:17 +00002669 clang_type_t root_clang_type = root->GetClangType();
2670 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002671 Flags root_clang_type_info,pointee_clang_type_info;
2672
2673 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2674 if (pointee_clang_type)
2675 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2676
2677 if (!expression_cstr || *expression_cstr == '\0')
2678 {
2679 *reason_to_stop = ValueObject::eEndOfString;
2680 list->Append(root);
2681 return 1;
2682 }
2683
2684 switch (*expression_cstr)
2685 {
2686 case '[':
2687 {
2688 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2689 {
2690 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2691 {
2692 *first_unparsed = expression_cstr;
2693 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2694 *final_result = ValueObject::eInvalid;
2695 return 0;
2696 }
2697 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2698 {
2699 *first_unparsed = expression_cstr;
2700 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2701 *final_result = ValueObject::eInvalid;
2702 return 0;
2703 }
2704 }
2705 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2706 {
2707 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2708 {
2709 *first_unparsed = expression_cstr;
2710 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2711 *final_result = ValueObject::eInvalid;
2712 return 0;
2713 }
2714 else // expand this into list
2715 {
2716 int max_index = root->GetNumChildren() - 1;
2717 for (int index = 0; index < max_index; index++)
2718 {
2719 ValueObjectSP child =
2720 root->GetChildAtIndex(index, true);
2721 list->Append(child);
2722 }
2723 *first_unparsed = expression_cstr+2;
2724 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2725 *final_result = ValueObject::eValueObjectList;
2726 return max_index; // tell me number of items I added to the VOList
2727 }
2728 }
2729 const char *separator_position = ::strchr(expression_cstr+1,'-');
2730 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2731 if (!close_bracket_position) // if there is no ], this is a syntax error
2732 {
2733 *first_unparsed = expression_cstr;
2734 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2735 *final_result = ValueObject::eInvalid;
2736 return 0;
2737 }
2738 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2739 {
2740 char *end = NULL;
2741 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2742 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2743 {
2744 *first_unparsed = expression_cstr;
2745 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2746 *final_result = ValueObject::eInvalid;
2747 return 0;
2748 }
2749 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2750 {
2751 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2752 {
2753 int max_index = root->GetNumChildren() - 1;
2754 for (int index = 0; index < max_index; index++)
2755 {
2756 ValueObjectSP child =
2757 root->GetChildAtIndex(index, true);
2758 list->Append(child);
2759 }
2760 *first_unparsed = expression_cstr+2;
2761 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2762 *final_result = ValueObject::eValueObjectList;
2763 return max_index; // tell me number of items I added to the VOList
2764 }
2765 else
2766 {
2767 *first_unparsed = expression_cstr;
2768 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2769 *final_result = ValueObject::eInvalid;
2770 return 0;
2771 }
2772 }
2773 // from here on we do have a valid index
2774 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2775 {
2776 root = root->GetChildAtIndex(index, true);
2777 if (!root.get())
2778 {
2779 *first_unparsed = expression_cstr;
2780 *reason_to_stop = ValueObject::eNoSuchChild;
2781 *final_result = ValueObject::eInvalid;
2782 return 0;
2783 }
2784 else
2785 {
2786 list->Append(root);
2787 *first_unparsed = end+1; // skip ]
2788 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2789 *final_result = ValueObject::eValueObjectList;
2790 return 1;
2791 }
2792 }
2793 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2794 {
2795 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
2796 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2797 {
2798 Error error;
2799 root = root->Dereference(error);
2800 if (error.Fail() || !root.get())
2801 {
2802 *first_unparsed = expression_cstr;
2803 *reason_to_stop = ValueObject::eDereferencingFailed;
2804 *final_result = ValueObject::eInvalid;
2805 return 0;
2806 }
2807 else
2808 {
2809 *what_next = eNothing;
2810 continue;
2811 }
2812 }
2813 else
2814 {
2815 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2816 if (!root.get())
2817 {
2818 *first_unparsed = expression_cstr;
2819 *reason_to_stop = ValueObject::eNoSuchChild;
2820 *final_result = ValueObject::eInvalid;
2821 return 0;
2822 }
2823 else
2824 {
2825 list->Append(root);
2826 *first_unparsed = end+1; // skip ]
2827 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2828 *final_result = ValueObject::eValueObjectList;
2829 return 1;
2830 }
2831 }
2832 }
2833 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2834 {
2835 root = root->GetSyntheticBitFieldChild(index, index, true);
2836 if (!root.get())
2837 {
2838 *first_unparsed = expression_cstr;
2839 *reason_to_stop = ValueObject::eNoSuchChild;
2840 *final_result = ValueObject::eInvalid;
2841 return 0;
2842 }
2843 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2844 {
2845 list->Append(root);
2846 *first_unparsed = end+1; // skip ]
2847 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2848 *final_result = ValueObject::eValueObjectList;
2849 return 1;
2850 }
2851 }
2852 }
2853 else // we have a low and a high index
2854 {
2855 char *end = NULL;
2856 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2857 if (!end || end != separator_position) // if something weird is in our way return an error
2858 {
2859 *first_unparsed = expression_cstr;
2860 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2861 *final_result = ValueObject::eInvalid;
2862 return 0;
2863 }
2864 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2865 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2866 {
2867 *first_unparsed = expression_cstr;
2868 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2869 *final_result = ValueObject::eInvalid;
2870 return 0;
2871 }
2872 if (index_lower > index_higher) // swap indices if required
2873 {
2874 unsigned long temp = index_lower;
2875 index_lower = index_higher;
2876 index_higher = temp;
2877 }
2878 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
2879 {
2880 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2881 if (!root.get())
2882 {
2883 *first_unparsed = expression_cstr;
2884 *reason_to_stop = ValueObject::eNoSuchChild;
2885 *final_result = ValueObject::eInvalid;
2886 return 0;
2887 }
2888 else
2889 {
2890 list->Append(root);
2891 *first_unparsed = end+1; // skip ]
2892 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2893 *final_result = ValueObject::eValueObjectList;
2894 return 1;
2895 }
2896 }
2897 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
2898 *what_next == ValueObject::eDereference &&
2899 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2900 {
2901 Error error;
2902 root = root->Dereference(error);
2903 if (error.Fail() || !root.get())
2904 {
2905 *first_unparsed = expression_cstr;
2906 *reason_to_stop = ValueObject::eDereferencingFailed;
2907 *final_result = ValueObject::eInvalid;
2908 return 0;
2909 }
2910 else
2911 {
2912 *what_next = ValueObject::eNothing;
2913 continue;
2914 }
2915 }
2916 else
2917 {
Johnny Chen44805302011-07-19 19:48:13 +00002918 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002919 index <= index_higher; index++)
2920 {
2921 ValueObjectSP child =
2922 root->GetChildAtIndex(index, true);
2923 list->Append(child);
2924 }
2925 *first_unparsed = end+1;
2926 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2927 *final_result = ValueObject::eValueObjectList;
2928 return index_higher-index_lower+1; // tell me number of items I added to the VOList
2929 }
2930 }
2931 break;
2932 }
2933 default: // some non-[ separator, or something entirely wrong, is in the way
2934 {
2935 *first_unparsed = expression_cstr;
2936 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2937 *final_result = ValueObject::eInvalid;
2938 return 0;
2939 break;
2940 }
2941 }
2942 }
2943}
2944
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002945void
Greg Clayton1d3afba2010-10-05 00:00:42 +00002946ValueObject::DumpValueObject
2947(
2948 Stream &s,
Greg Clayton1d3afba2010-10-05 00:00:42 +00002949 ValueObject *valobj,
2950 const char *root_valobj_name,
2951 uint32_t ptr_depth,
2952 uint32_t curr_depth,
2953 uint32_t max_depth,
2954 bool show_types,
2955 bool show_location,
2956 bool use_objc,
Greg Claytonafacd142011-09-02 01:15:17 +00002957 DynamicValueType use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00002958 bool use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002959 bool scope_already_checked,
Enrico Granata0c5ef692011-07-16 01:22:04 +00002960 bool flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00002961 uint32_t omit_summary_depth,
2962 bool ignore_cap
Greg Clayton1d3afba2010-10-05 00:00:42 +00002963)
2964{
Greg Clayton007d5be2011-05-30 00:49:24 +00002965 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002966 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00002967 bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00002968
Greg Claytonafacd142011-09-02 01:15:17 +00002969 if (update_success && use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00002970 {
Jim Ingham2837b762011-05-04 03:43:18 +00002971 ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00002972 if (dynamic_value)
2973 valobj = dynamic_value;
2974 }
2975
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002976 clang_type_t clang_type = valobj->GetClangType();
2977
Greg Clayton73b472d2010-10-27 03:32:59 +00002978 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002979 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00002980 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
2981 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002982
2983 const bool print_valobj = flat_output == false || has_value;
2984
2985 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002986 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002987 if (show_location)
2988 {
Jim Ingham6035b672011-03-31 00:19:25 +00002989 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002990 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002991
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002992 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00002993
Greg Clayton7c8a9662010-11-02 01:50:16 +00002994 // Always show the type for the top level items.
Greg Claytone221f822011-01-21 01:59:00 +00002995 if (show_types || (curr_depth == 0 && !flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00002996 {
Enrico Granata9910bc82011-08-03 02:18:51 +00002997 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
2998 s.Printf("(%s", typeName);
2999 // only show dynamic types if the user really wants to see types
Greg Claytonafacd142011-09-02 01:15:17 +00003000 if (show_types && use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003001 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003002 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003003 {
3004 Process* process = valobj->GetUpdatePoint().GetProcessSP().get();
3005 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003006 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003007 else
3008 {
3009 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3010 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003011 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003012 else
3013 {
3014 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3015 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003016 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003017 else
3018 s.Printf(", dynamic type: %s) ",
3019 runtime->GetActualTypeName(isa).GetCString());
3020 }
3021 }
3022 }
3023 else
3024 s.Printf(") ");
3025 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003026
Greg Clayton1d3afba2010-10-05 00:00:42 +00003027
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003028 if (flat_output)
3029 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003030 // If we are showing types, also qualify the C++ base classes
3031 const bool qualify_cxx_base_classes = show_types;
3032 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003033 s.PutCString(" =");
3034 }
3035 else
3036 {
3037 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3038 s.Printf ("%s =", name_cstr);
3039 }
3040
Jim Ingham6035b672011-03-31 00:19:25 +00003041 if (!scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003042 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003043 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003044 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003045 }
3046
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003047 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003048 const char *sum_cstr = NULL;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003049 SummaryFormat* entry = valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003050
Enrico Granata0c5ef692011-07-16 01:22:04 +00003051 if (omit_summary_depth > 0)
3052 entry = NULL;
3053
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003054 if (err_cstr == NULL)
3055 {
Jim Ingham6035b672011-03-31 00:19:25 +00003056 val_cstr = valobj->GetValueAsCString();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003057 err_cstr = valobj->GetError().AsCString();
3058 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003059
3060 if (err_cstr)
3061 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003062 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003063 }
3064 else
3065 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003066 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003067 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003068 {
Enrico Granata4becb372011-06-29 22:27:15 +00003069
Enrico Granata0c5ef692011-07-16 01:22:04 +00003070 sum_cstr = (omit_summary_depth == 0) ? valobj->GetSummaryAsCString() : NULL;
Greg Clayton1d3afba2010-10-05 00:00:42 +00003071
Enrico Granata4becb372011-06-29 22:27:15 +00003072 // We must calculate this value in realtime because entry might alter this variable's value
3073 // (e.g. by saying ${var%fmt}) and render precached values useless
3074 if (val_cstr && (!entry || entry->DoesPrintValue() || !sum_cstr))
3075 s.Printf(" %s", valobj->GetValueAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003076
Enrico Granata9dd75c82011-07-15 23:30:15 +00003077 if (sum_cstr)
Enrico Granata0a3958e2011-07-02 00:25:22 +00003078 {
3079 // for some reason, using %@ (ObjC description) in a summary string, makes
3080 // us believe we need to reset ourselves, thus invalidating the content of
3081 // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty
3082 // let us recalculate it!
3083 if (sum_cstr[0] == '\0')
3084 s.Printf(" %s", valobj->GetSummaryAsCString());
3085 else
3086 s.Printf(" %s", sum_cstr);
3087 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003088
3089 if (use_objc)
3090 {
Jim Ingham6035b672011-03-31 00:19:25 +00003091 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003092 if (object_desc)
3093 s.Printf(" %s\n", object_desc);
3094 else
Sean Callanan672ad942010-10-23 00:18:49 +00003095 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003096 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003097 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003098 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003099
3100 if (curr_depth < max_depth)
3101 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003102 // We will show children for all concrete types. We won't show
3103 // pointer contents unless a pointer depth has been specified.
3104 // We won't reference contents unless the reference is the
3105 // root object (depth of zero).
3106 bool print_children = true;
3107
3108 // Use a new temporary pointer depth in case we override the
3109 // current pointer depth below...
3110 uint32_t curr_ptr_depth = ptr_depth;
3111
3112 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3113 if (is_ptr || is_ref)
3114 {
3115 // We have a pointer or reference whose value is an address.
3116 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003117 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003118 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003119 print_children = false;
3120
3121 else if (is_ref && curr_depth == 0)
3122 {
3123 // If this is the root object (depth is zero) that we are showing
3124 // and it is a reference, and no pointer depth has been supplied
3125 // print out what it references. Don't do this at deeper depths
3126 // otherwise we can end up with infinite recursion...
3127 curr_ptr_depth = 1;
3128 }
3129
3130 if (curr_ptr_depth == 0)
3131 print_children = false;
3132 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003133
Enrico Granata0a3958e2011-07-02 00:25:22 +00003134 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003135 {
Enrico Granatac482a192011-08-17 22:13:59 +00003136 ValueObjectSP synth_valobj = valobj->GetSyntheticValue(use_synth ?
Greg Claytonafacd142011-09-02 01:15:17 +00003137 eUseSyntheticFilter :
3138 eNoSyntheticFilter);
Enrico Granatac482a192011-08-17 22:13:59 +00003139 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003140 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003141 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003142 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003143 if (flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003144 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003145 if (print_valobj)
3146 s.EOL();
3147 }
3148 else
3149 {
3150 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003151 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003152 s.IndentMore();
3153 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003154
3155 uint32_t max_num_children = valobj->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
3156
3157 if (num_children > max_num_children && !ignore_cap)
3158 {
3159 num_children = max_num_children;
3160 print_dotdotdot = true;
3161 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003162
3163 for (uint32_t idx=0; idx<num_children; ++idx)
3164 {
Enrico Granatac482a192011-08-17 22:13:59 +00003165 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003166 if (child_sp.get())
3167 {
3168 DumpValueObject (s,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003169 child_sp.get(),
3170 NULL,
Greg Clayton73b472d2010-10-27 03:32:59 +00003171 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003172 curr_depth + 1,
3173 max_depth,
3174 show_types,
3175 show_location,
3176 false,
Jim Ingham78a685a2011-04-16 00:01:13 +00003177 use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00003178 use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003179 true,
Enrico Granata0c5ef692011-07-16 01:22:04 +00003180 flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00003181 omit_summary_depth > 1 ? omit_summary_depth - 1 : 0,
3182 ignore_cap);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003183 }
3184 }
3185
3186 if (!flat_output)
3187 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003188 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003189 {
3190 valobj->GetUpdatePoint().GetTargetSP()->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003191 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003192 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003193 s.IndentLess();
3194 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003195 }
3196 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003197 else if (has_children)
3198 {
3199 // Aggregate, no children...
3200 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003201 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003202 }
3203 else
3204 {
3205 if (print_valobj)
3206 s.EOL();
3207 }
3208
Greg Clayton1d3afba2010-10-05 00:00:42 +00003209 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003210 else
3211 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003212 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003213 }
3214 }
3215 else
3216 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003217 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003218 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003219 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003220 }
3221 }
3222 }
3223 }
3224}
3225
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003226
3227ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003228ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003229{
3230 ValueObjectSP valobj_sp;
3231
Enrico Granatac3e320a2011-08-02 17:27:39 +00003232 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003233 {
Jim Ingham6035b672011-03-31 00:19:25 +00003234 ExecutionContextScope *exe_scope = GetExecutionContextScope();
3235 if (exe_scope)
3236 {
3237 ExecutionContext exe_ctx;
3238 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003239
Jim Ingham6035b672011-03-31 00:19:25 +00003240 clang::ASTContext *ast = GetClangAST ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003241
Jim Ingham6035b672011-03-31 00:19:25 +00003242 DataExtractor data;
3243 data.SetByteOrder (m_data.GetByteOrder());
3244 data.SetAddressByteSize(m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003245
Greg Clayton644247c2011-07-07 01:59:51 +00003246 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003247
Jim Ingham58b59f92011-04-22 23:53:53 +00003248 valobj_sp = ValueObjectConstResult::Create (exe_scope,
3249 ast,
3250 GetClangType(),
3251 name,
Enrico Granata9128ee22011-09-06 19:20:51 +00003252 data,
3253 GetAddressOf());
Jim Ingham6035b672011-03-31 00:19:25 +00003254 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003255 }
Jim Ingham6035b672011-03-31 00:19:25 +00003256
3257 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003258 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003259 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003260 }
3261 return valobj_sp;
3262}
3263
Greg Claytonafacd142011-09-02 01:15:17 +00003264ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003265ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003266{
Jim Ingham58b59f92011-04-22 23:53:53 +00003267 if (m_deref_valobj)
3268 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003269
Greg Clayton54979cd2010-12-15 05:08:08 +00003270 const bool is_pointer_type = IsPointerType();
3271 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003272 {
3273 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003274 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003275
3276 std::string child_name_str;
3277 uint32_t child_byte_size = 0;
3278 int32_t child_byte_offset = 0;
3279 uint32_t child_bitfield_bit_size = 0;
3280 uint32_t child_bitfield_bit_offset = 0;
3281 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003282 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003283 const bool transparent_pointers = false;
3284 clang::ASTContext *clang_ast = GetClangAST();
3285 clang_type_t clang_type = GetClangType();
3286 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003287
3288 ExecutionContext exe_ctx;
3289 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
3290
3291 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3292 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003293 GetName().GetCString(),
3294 clang_type,
3295 0,
3296 transparent_pointers,
3297 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003298 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003299 child_name_str,
3300 child_byte_size,
3301 child_byte_offset,
3302 child_bitfield_bit_size,
3303 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003304 child_is_base_class,
3305 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003306 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003307 {
3308 ConstString child_name;
3309 if (!child_name_str.empty())
3310 child_name.SetCString (child_name_str.c_str());
3311
Jim Ingham58b59f92011-04-22 23:53:53 +00003312 m_deref_valobj = new ValueObjectChild (*this,
3313 clang_ast,
3314 child_clang_type,
3315 child_name,
3316 child_byte_size,
3317 child_byte_offset,
3318 child_bitfield_bit_size,
3319 child_bitfield_bit_offset,
3320 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003321 child_is_deref_of_parent,
3322 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003323 }
3324 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003325
Jim Ingham58b59f92011-04-22 23:53:53 +00003326 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003327 {
3328 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003329 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003330 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003331 else
3332 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003333 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003334 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003335
3336 if (is_pointer_type)
3337 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3338 else
3339 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003340 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003341 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003342}
3343
Greg Claytonafacd142011-09-02 01:15:17 +00003344ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003345ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003346{
Jim Ingham78a685a2011-04-16 00:01:13 +00003347 if (m_addr_of_valobj_sp)
3348 return m_addr_of_valobj_sp;
3349
Greg Claytone0d378b2011-03-24 21:19:54 +00003350 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003351 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003352 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003353 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003354 if (addr != LLDB_INVALID_ADDRESS)
3355 {
3356 switch (address_type)
3357 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003358 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003359 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003360 {
3361 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003362 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003363 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3364 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003365 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003366
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003367 case eAddressTypeFile:
3368 case eAddressTypeLoad:
3369 case eAddressTypeHost:
3370 {
3371 clang::ASTContext *ast = GetClangAST();
3372 clang_type_t clang_type = GetClangType();
3373 if (ast && clang_type)
3374 {
3375 std::string name (1, '&');
3376 name.append (m_name.AsCString(""));
Jim Ingham58b59f92011-04-22 23:53:53 +00003377 m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(),
3378 ast,
3379 ClangASTContext::CreatePointerType (ast, clang_type),
3380 ConstString (name.c_str()),
3381 addr,
3382 eAddressTypeInvalid,
3383 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003384 }
3385 }
3386 break;
3387 }
3388 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003389 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003390}
3391
Greg Claytonb2dcc362011-05-05 23:32:56 +00003392
Greg Claytonafacd142011-09-02 01:15:17 +00003393ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003394ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3395{
Greg Claytonafacd142011-09-02 01:15:17 +00003396 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003397 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003398 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003399
3400 if (ptr_value != LLDB_INVALID_ADDRESS)
3401 {
3402 Address ptr_addr (NULL, ptr_value);
3403
3404 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3405 name,
3406 ptr_addr,
3407 clang_ast_type);
3408 }
3409 return valobj_sp;
3410}
3411
Greg Claytonafacd142011-09-02 01:15:17 +00003412ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003413ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3414{
Greg Claytonafacd142011-09-02 01:15:17 +00003415 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003416 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003417 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003418
3419 if (ptr_value != LLDB_INVALID_ADDRESS)
3420 {
3421 Address ptr_addr (NULL, ptr_value);
3422
3423 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3424 name,
3425 ptr_addr,
3426 type_sp);
3427 }
3428 return valobj_sp;
3429}
3430
Jim Ingham6035b672011-03-31 00:19:25 +00003431ValueObject::EvaluationPoint::EvaluationPoint () :
Stephen Wilson71c21d12011-04-11 19:41:40 +00003432 m_thread_id (LLDB_INVALID_UID),
Jim Ingham4b536182011-08-09 02:12:22 +00003433 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003434{
3435}
3436
3437ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Jim Ingham6035b672011-03-31 00:19:25 +00003438 m_needs_update (true),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003439 m_first_update (true),
Jim Ingham89b61092011-07-06 17:42:14 +00003440 m_thread_id (LLDB_INVALID_THREAD_ID),
Jim Ingham4b536182011-08-09 02:12:22 +00003441 m_mod_id ()
Stephen Wilson71c21d12011-04-11 19:41:40 +00003442
Jim Ingham6035b672011-03-31 00:19:25 +00003443{
3444 ExecutionContext exe_ctx;
3445 ExecutionContextScope *computed_exe_scope = exe_scope; // If use_selected is true, we may find a better scope,
3446 // and if so we want to cache that not the original.
3447 if (exe_scope)
3448 exe_scope->CalculateExecutionContext(exe_ctx);
3449 if (exe_ctx.target != NULL)
3450 {
3451 m_target_sp = exe_ctx.target->GetSP();
3452
3453 if (exe_ctx.process == NULL)
3454 m_process_sp = exe_ctx.target->GetProcessSP();
3455 else
3456 m_process_sp = exe_ctx.process->GetSP();
3457
3458 if (m_process_sp != NULL)
3459 {
Jim Ingham4b536182011-08-09 02:12:22 +00003460 m_mod_id = m_process_sp->GetModID();
3461
Jim Ingham6035b672011-03-31 00:19:25 +00003462 Thread *thread = NULL;
3463
3464 if (exe_ctx.thread == NULL)
3465 {
3466 if (use_selected)
3467 {
3468 thread = m_process_sp->GetThreadList().GetSelectedThread().get();
3469 if (thread)
3470 computed_exe_scope = thread;
3471 }
3472 }
3473 else
3474 thread = exe_ctx.thread;
3475
3476 if (thread != NULL)
3477 {
3478 m_thread_id = thread->GetIndexID();
3479 if (exe_ctx.frame == NULL)
3480 {
3481 if (use_selected)
3482 {
3483 StackFrame *frame = exe_ctx.thread->GetSelectedFrame().get();
3484 if (frame)
3485 {
3486 m_stack_id = frame->GetStackID();
3487 computed_exe_scope = frame;
3488 }
3489 }
3490 }
3491 else
3492 m_stack_id = exe_ctx.frame->GetStackID();
3493 }
3494 }
3495 }
3496 m_exe_scope = computed_exe_scope;
3497}
3498
3499ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
3500 m_exe_scope (rhs.m_exe_scope),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003501 m_needs_update(true),
3502 m_first_update(true),
Jim Ingham6035b672011-03-31 00:19:25 +00003503 m_target_sp (rhs.m_target_sp),
3504 m_process_sp (rhs.m_process_sp),
3505 m_thread_id (rhs.m_thread_id),
3506 m_stack_id (rhs.m_stack_id),
Jim Ingham4b536182011-08-09 02:12:22 +00003507 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003508{
3509}
3510
3511ValueObject::EvaluationPoint::~EvaluationPoint ()
3512{
3513}
3514
3515ExecutionContextScope *
3516ValueObject::EvaluationPoint::GetExecutionContextScope ()
3517{
3518 // We have to update before giving out the scope, or we could be handing out stale pointers.
3519 SyncWithProcessState();
3520
3521 return m_exe_scope;
3522}
3523
3524// This function checks the EvaluationPoint against the current process state. If the current
3525// state matches the evaluation point, or the evaluation point is already invalid, then we return
3526// false, meaning "no change". If the current state is different, we update our state, and return
3527// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3528// future calls to NeedsUpdate will return true.
3529
3530bool
3531ValueObject::EvaluationPoint::SyncWithProcessState()
3532{
Jim Ingham6035b672011-03-31 00:19:25 +00003533 // If we don't have a process nothing can change.
3534 if (!m_process_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003535 {
3536 m_exe_scope = m_target_sp.get();
Jim Ingham6035b672011-03-31 00:19:25 +00003537 return false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003538 }
Jim Ingham6035b672011-03-31 00:19:25 +00003539
3540 // If our stop id is the current stop ID, nothing has changed:
Jim Ingham4b536182011-08-09 02:12:22 +00003541 ProcessModID current_mod_id = m_process_sp->GetModID();
3542
Jim Ingham78a685a2011-04-16 00:01:13 +00003543 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3544 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003545 if (current_mod_id.GetStopID() == 0)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003546 {
3547 m_exe_scope = m_target_sp.get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003548 return false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003549 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003550
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003551 if (m_mod_id.IsValid())
3552 {
3553 if (m_mod_id == current_mod_id)
3554 {
3555 // Everything is already up to date in this object, no need do
3556 // update the execution context scope.
3557 return false;
3558 }
3559 m_mod_id = current_mod_id;
3560 m_needs_update = true;
3561 }
Jim Ingham6035b672011-03-31 00:19:25 +00003562 m_exe_scope = m_process_sp.get();
3563
3564 // Something has changed, so we will return true. Now make sure the thread & frame still exist, and if either
3565 // doesn't, mark ourselves as invalid.
3566
3567 if (m_thread_id != LLDB_INVALID_THREAD_ID)
3568 {
3569 Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get();
3570 if (our_thread == NULL)
Greg Clayton262f80d2011-07-06 16:49:27 +00003571 {
Jim Ingham89b61092011-07-06 17:42:14 +00003572 SetInvalid();
Greg Clayton262f80d2011-07-06 16:49:27 +00003573 }
Jim Ingham6035b672011-03-31 00:19:25 +00003574 else
3575 {
3576 m_exe_scope = our_thread;
3577
3578 if (m_stack_id.IsValid())
3579 {
3580 StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get();
3581 if (our_frame == NULL)
3582 SetInvalid();
3583 else
3584 m_exe_scope = our_frame;
3585 }
3586 }
3587 }
3588 return true;
3589}
3590
Jim Ingham61be0902011-05-02 18:13:59 +00003591void
3592ValueObject::EvaluationPoint::SetUpdated ()
3593{
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003594 // this will update the execution context scope and the m_mod_id
3595 SyncWithProcessState();
Jim Ingham61be0902011-05-02 18:13:59 +00003596 m_first_update = false;
3597 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003598}
3599
3600
Jim Ingham6035b672011-03-31 00:19:25 +00003601bool
3602ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3603{
3604 if (!IsValid())
3605 return false;
3606
3607 bool needs_update = false;
3608 m_exe_scope = NULL;
3609
3610 // The target has to be non-null, and the
3611 Target *target = exe_scope->CalculateTarget();
3612 if (target != NULL)
3613 {
3614 Target *old_target = m_target_sp.get();
3615 assert (target == old_target);
3616 Process *process = exe_scope->CalculateProcess();
3617 if (process != NULL)
3618 {
3619 // FOR NOW - assume you can't update variable objects across process boundaries.
3620 Process *old_process = m_process_sp.get();
3621 assert (process == old_process);
Jim Ingham4b536182011-08-09 02:12:22 +00003622 ProcessModID current_mod_id = process->GetModID();
3623 if (m_mod_id != current_mod_id)
Jim Ingham6035b672011-03-31 00:19:25 +00003624 {
3625 needs_update = true;
Jim Ingham4b536182011-08-09 02:12:22 +00003626 m_mod_id = current_mod_id;
Jim Ingham6035b672011-03-31 00:19:25 +00003627 }
3628 // See if we're switching the thread or stack context. If no thread is given, this is
3629 // being evaluated in a global context.
3630 Thread *thread = exe_scope->CalculateThread();
3631 if (thread != NULL)
3632 {
Greg Claytonafacd142011-09-02 01:15:17 +00003633 user_id_t new_thread_index = thread->GetIndexID();
Jim Ingham6035b672011-03-31 00:19:25 +00003634 if (new_thread_index != m_thread_id)
3635 {
3636 needs_update = true;
3637 m_thread_id = new_thread_index;
3638 m_stack_id.Clear();
3639 }
3640
3641 StackFrame *new_frame = exe_scope->CalculateStackFrame();
3642 if (new_frame != NULL)
3643 {
3644 if (new_frame->GetStackID() != m_stack_id)
3645 {
3646 needs_update = true;
3647 m_stack_id = new_frame->GetStackID();
3648 }
3649 }
3650 else
3651 {
3652 m_stack_id.Clear();
3653 needs_update = true;
3654 }
3655 }
3656 else
3657 {
3658 // If this had been given a thread, and now there is none, we should update.
3659 // Otherwise we don't have to do anything.
3660 if (m_thread_id != LLDB_INVALID_UID)
3661 {
3662 m_thread_id = LLDB_INVALID_UID;
3663 m_stack_id.Clear();
3664 needs_update = true;
3665 }
3666 }
3667 }
3668 else
3669 {
3670 // If there is no process, then we don't need to update anything.
3671 // But if we're switching from having a process to not, we should try to update.
3672 if (m_process_sp.get() != NULL)
3673 {
3674 needs_update = true;
3675 m_process_sp.reset();
3676 m_thread_id = LLDB_INVALID_UID;
3677 m_stack_id.Clear();
3678 }
3679 }
3680 }
3681 else
3682 {
3683 // If there's no target, nothing can change so we don't need to update anything.
3684 // But if we're switching from having a target to not, we should try to update.
3685 if (m_target_sp.get() != NULL)
3686 {
3687 needs_update = true;
3688 m_target_sp.reset();
3689 m_process_sp.reset();
3690 m_thread_id = LLDB_INVALID_UID;
3691 m_stack_id.Clear();
3692 }
3693 }
3694 if (!m_needs_update)
3695 m_needs_update = needs_update;
3696
3697 return needs_update;
3698}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003699
3700void
3701ValueObject::ClearUserVisibleData()
3702{
3703 m_location_str.clear();
3704 m_value_str.clear();
3705 m_summary_str.clear();
3706 m_object_desc_str.clear();
Johnny Chen44805302011-07-19 19:48:13 +00003707}
Enrico Granata9128ee22011-09-06 19:20:51 +00003708
3709SymbolContextScope *
3710ValueObject::GetSymbolContextScope()
3711{
3712 if (m_parent)
3713 {
3714 if (!m_parent->IsPointerOrReferenceType())
3715 return m_parent->GetSymbolContextScope();
3716 }
3717 return NULL;
3718}