blob: e88bcb9ed4a3c352b095f76bc0699ab09c61996a [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 Granata4becb372011-06-29 22:27:15 +000022#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000023#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Core/StreamString.h"
25#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000026#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000027#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000029#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000030#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031
Greg Clayton7fb56d02011-02-01 01:31:41 +000032#include "lldb/Host/Endian.h"
33
Enrico Granataf2bbf712011-07-15 02:26:42 +000034#include "lldb/Interpreter/ScriptInterpreterPython.h"
35
Greg Claytone1a916a2010-07-21 22:12:05 +000036#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037#include "lldb/Symbol/ClangASTContext.h"
38#include "lldb/Symbol/Type.h"
39
Jim Ingham53c47f12010-09-10 23:12:17 +000040#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000041#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000042#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Target/Process.h"
44#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000045#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047
Enrico Granataf4efecd2011-07-12 22:56:10 +000048#include "lldb/Utility/RefCounter.h"
49
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050using namespace lldb;
51using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000052using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053
54static lldb::user_id_t g_value_obj_uid = 0;
55
56//----------------------------------------------------------------------
57// ValueObject constructor
58//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000059ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000061 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000062 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063 m_name (),
64 m_data (),
65 m_value (),
66 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000067 m_value_str (),
68 m_old_value_str (),
69 m_location_str (),
70 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000071 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000072 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000073 m_children (),
74 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000075 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000076 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000077 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000078 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000079 m_last_format_mgr_revision(0),
Enrico Granatad8b5fce2011-08-02 23:12:24 +000080 m_last_format_mgr_dynamic(parent.m_last_format_mgr_dynamic),
Enrico Granata9df29e32011-07-19 20:57:44 +000081 m_last_summary_format(),
82 m_forced_summary_format(),
83 m_last_value_format(),
Enrico Granatad55546b2011-07-22 00:16:08 +000084 m_last_synthetic_filter(),
Enrico Granata9df29e32011-07-19 20:57:44 +000085 m_user_id_of_forced_summary(0),
Greg Clayton288bdf92010-09-02 02:59:18 +000086 m_value_is_valid (false),
87 m_value_did_change (false),
88 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000089 m_old_value_valid (false),
Greg Claytone221f822011-01-21 01:59:00 +000090 m_pointers_point_to_load_addrs (false),
Enrico Granata4becb372011-06-29 22:27:15 +000091 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000092 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000093 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +000094 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000095 m_is_child_at_offset(false),
Enrico Granata9910bc82011-08-03 02:18:51 +000096 m_is_expression_result(parent.m_is_expression_result),
Enrico Granataf4efecd2011-07-12 22:56:10 +000097 m_dump_printable_counter(0)
Jim Ingham6035b672011-03-31 00:19:25 +000098{
Jim Ingham58b59f92011-04-22 23:53:53 +000099 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000100}
101
102//----------------------------------------------------------------------
103// ValueObject constructor
104//----------------------------------------------------------------------
105ValueObject::ValueObject (ExecutionContextScope *exe_scope) :
106 UserID (++g_value_obj_uid), // Unique identifier for every value object
107 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000108 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000109 m_name (),
110 m_data (),
111 m_value (),
112 m_error (),
113 m_value_str (),
114 m_old_value_str (),
115 m_location_str (),
116 m_summary_str (),
117 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000118 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000119 m_children (),
120 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000121 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000122 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000123 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000124 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000125 m_last_format_mgr_revision(0),
Enrico Granatac3e320a2011-08-02 17:27:39 +0000126 m_last_format_mgr_dynamic(lldb::eNoDynamicValues),
Enrico Granata9df29e32011-07-19 20:57:44 +0000127 m_last_summary_format(),
128 m_forced_summary_format(),
129 m_last_value_format(),
Enrico Granatad55546b2011-07-22 00:16:08 +0000130 m_last_synthetic_filter(),
Enrico Granata9df29e32011-07-19 20:57:44 +0000131 m_user_id_of_forced_summary(0),
Jim Ingham6035b672011-03-31 00:19:25 +0000132 m_value_is_valid (false),
133 m_value_did_change (false),
134 m_children_count_valid (false),
135 m_old_value_valid (false),
136 m_pointers_point_to_load_addrs (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000137 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000138 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000139 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000140 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000141 m_is_child_at_offset(false),
Enrico Granatac3e320a2011-08-02 17:27:39 +0000142 m_is_expression_result(false),
Enrico Granataf4efecd2011-07-12 22:56:10 +0000143 m_dump_printable_counter(0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000144{
Jim Ingham58b59f92011-04-22 23:53:53 +0000145 m_manager = new ValueObjectManager();
146 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147}
148
149//----------------------------------------------------------------------
150// Destructor
151//----------------------------------------------------------------------
152ValueObject::~ValueObject ()
153{
154}
155
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000157ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000159 return UpdateValueIfNeeded(m_last_format_mgr_dynamic, update_format);
160}
161
162bool
163ValueObject::UpdateValueIfNeeded (lldb::DynamicValueType use_dynamic, bool update_format)
164{
Enrico Granata4becb372011-06-29 22:27:15 +0000165
Enrico Granata0a3958e2011-07-02 00:25:22 +0000166 if (update_format)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000167 UpdateFormatsIfNeeded(use_dynamic);
Enrico Granata4becb372011-06-29 22:27:15 +0000168
Greg Claytonb71f3842010-10-05 03:13:51 +0000169 // If this is a constant value, then our success is predicated on whether
170 // we have an error or not
171 if (GetIsConstant())
172 return m_error.Success();
173
Jim Ingham6035b672011-03-31 00:19:25 +0000174 bool first_update = m_update_point.IsFirstEvaluation();
175
176 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000177 {
Jim Ingham6035b672011-03-31 00:19:25 +0000178 m_update_point.SetUpdated();
179
180 // Save the old value using swap to avoid a string copy which
181 // also will clear our m_value_str
182 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000183 {
Jim Ingham6035b672011-03-31 00:19:25 +0000184 m_old_value_valid = false;
185 }
186 else
187 {
188 m_old_value_valid = true;
189 m_old_value_str.swap (m_value_str);
190 m_value_str.clear();
191 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192
Enrico Granataf2bbf712011-07-15 02:26:42 +0000193 ClearUserVisibleData();
194
Jim Ingham6035b672011-03-31 00:19:25 +0000195 const bool value_was_valid = GetValueIsValid();
196 SetValueDidChange (false);
Greg Clayton73b953b2010-08-28 00:08:07 +0000197
Jim Ingham6035b672011-03-31 00:19:25 +0000198 m_error.Clear();
Greg Clayton73b953b2010-08-28 00:08:07 +0000199
Jim Ingham6035b672011-03-31 00:19:25 +0000200 // Call the pure virtual function to update the value
201 bool success = UpdateValue ();
202
203 SetValueIsValid (success);
204
205 if (first_update)
206 SetValueDidChange (false);
207 else if (!m_value_did_change && success == false)
208 {
209 // The value wasn't gotten successfully, so we mark this
210 // as changed if the value used to be valid and now isn't
211 SetValueDidChange (value_was_valid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000212 }
213 }
214 return m_error.Success();
215}
216
Enrico Granata4becb372011-06-29 22:27:15 +0000217void
Enrico Granatac3e320a2011-08-02 17:27:39 +0000218ValueObject::UpdateFormatsIfNeeded(lldb::DynamicValueType use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000219{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000220 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
221 if (log)
222 log->Printf("checking for FormatManager revisions. VO named %s is at revision %d, while the format manager is at revision %d",
223 GetName().GetCString(),
Enrico Granata4becb372011-06-29 22:27:15 +0000224 m_last_format_mgr_revision,
Enrico Granata6f3533f2011-07-29 19:53:35 +0000225 Debugger::Formatting::ValueFormats::GetCurrentRevision());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000226 if (HasCustomSummaryFormat() && m_update_point.GetUpdateID() != m_user_id_of_forced_summary)
227 {
228 ClearCustomSummaryFormat();
229 m_summary_str.clear();
230 }
Enrico Granatac3e320a2011-08-02 17:27:39 +0000231 if ( (m_last_format_mgr_revision != Debugger::Formatting::ValueFormats::GetCurrentRevision()) ||
232 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000233 {
234 if (m_last_summary_format.get())
Enrico Granataf2bbf712011-07-15 02:26:42 +0000235 m_last_summary_format.reset((StringSummaryFormat*)NULL);
Enrico Granata4becb372011-06-29 22:27:15 +0000236 if (m_last_value_format.get())
Enrico Granatad55546b2011-07-22 00:16:08 +0000237 m_last_value_format.reset(/*(ValueFormat*)NULL*/);
238 if (m_last_synthetic_filter.get())
239 m_last_synthetic_filter.reset(/*(SyntheticFilter*)NULL*/);
Enrico Granataa37a0652011-07-24 00:14:56 +0000240
241 m_synthetic_value = NULL;
Enrico Granata1490c6f2011-07-19 02:34:21 +0000242
Enrico Granata9910bc82011-08-03 02:18:51 +0000243 Debugger::Formatting::ValueFormats::Get(*this, lldb::eNoDynamicValues, m_last_value_format);
Enrico Granatac3e320a2011-08-02 17:27:39 +0000244 Debugger::Formatting::GetSummaryFormat(*this, use_dynamic, m_last_summary_format);
245 Debugger::Formatting::GetSyntheticFilter(*this, use_dynamic, m_last_synthetic_filter);
Enrico Granata1490c6f2011-07-19 02:34:21 +0000246
247 m_last_format_mgr_revision = Debugger::Formatting::ValueFormats::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000248 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granataf2bbf712011-07-15 02:26:42 +0000249
250 ClearUserVisibleData();
Enrico Granata4becb372011-06-29 22:27:15 +0000251 }
252}
253
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000254DataExtractor &
255ValueObject::GetDataExtractor ()
256{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000257 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000258 return m_data;
259}
260
261const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000262ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000263{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000264 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265 return m_error;
266}
267
268const ConstString &
269ValueObject::GetName() const
270{
271 return m_name;
272}
273
274const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000275ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000277 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278 {
279 if (m_location_str.empty())
280 {
281 StreamString sstr;
282
283 switch (m_value.GetValueType())
284 {
285 default:
286 break;
287
288 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000289 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000290 {
291 RegisterInfo *reg_info = m_value.GetRegisterInfo();
292 if (reg_info)
293 {
294 if (reg_info->name)
295 m_location_str = reg_info->name;
296 else if (reg_info->alt_name)
297 m_location_str = reg_info->alt_name;
298 break;
299 }
300 }
301 m_location_str = "scalar";
302 break;
303
304 case Value::eValueTypeLoadAddress:
305 case Value::eValueTypeFileAddress:
306 case Value::eValueTypeHostAddress:
307 {
308 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
309 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
310 m_location_str.swap(sstr.GetString());
311 }
312 break;
313 }
314 }
315 }
316 return m_location_str.c_str();
317}
318
319Value &
320ValueObject::GetValue()
321{
322 return m_value;
323}
324
325const Value &
326ValueObject::GetValue() const
327{
328 return m_value;
329}
330
331bool
Jim Ingham6035b672011-03-31 00:19:25 +0000332ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000333{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000334 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
335 {
336 ExecutionContext exe_ctx;
337 ExecutionContextScope *exe_scope = GetExecutionContextScope();
338 if (exe_scope)
339 exe_scope->CalculateExecutionContext(exe_ctx);
340 scalar = m_value.ResolveValue(&exe_ctx, GetClangAST ());
341 return scalar.IsValid();
342 }
343 else
344 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000345}
346
347bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000348ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000349{
Greg Clayton288bdf92010-09-02 02:59:18 +0000350 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351}
352
353
354void
355ValueObject::SetValueIsValid (bool b)
356{
Greg Clayton288bdf92010-09-02 02:59:18 +0000357 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000358}
359
360bool
Jim Ingham6035b672011-03-31 00:19:25 +0000361ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000362{
Jim Ingham6035b672011-03-31 00:19:25 +0000363 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000364 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000365}
366
367void
368ValueObject::SetValueDidChange (bool value_changed)
369{
Greg Clayton288bdf92010-09-02 02:59:18 +0000370 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000371}
372
373ValueObjectSP
374ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
375{
376 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000377 // We may need to update our value if we are dynamic
378 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000379 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000380 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000382 // Check if we have already made the child value object?
383 if (can_create && m_children[idx] == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000385 // No we haven't created the child at this index, so lets have our
386 // subclass do it and cache the result for quick future access.
387 m_children[idx] = CreateChildAtIndex (idx, false, 0);
Jim Ingham78a685a2011-04-16 00:01:13 +0000388 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000389
390 if (m_children[idx] != NULL)
391 return m_children[idx]->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392 }
393 return child_sp;
394}
395
396uint32_t
397ValueObject::GetIndexOfChildWithName (const ConstString &name)
398{
399 bool omit_empty_base_classes = true;
400 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000401 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000402 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403 omit_empty_base_classes);
404}
405
406ValueObjectSP
407ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
408{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000409 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410 // classes (which really aren't part of the expression path), so we
411 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000413
Greg Claytondea8cb42011-06-29 22:09:02 +0000414 // We may need to update our value if we are dynamic
415 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000416 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000417
418 std::vector<uint32_t> child_indexes;
419 clang::ASTContext *clang_ast = GetClangAST();
420 void *clang_type = GetClangType();
421 bool omit_empty_base_classes = true;
422 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
423 clang_type,
424 name.GetCString(),
425 omit_empty_base_classes,
426 child_indexes);
427 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000429 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
430 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
431
432 child_sp = GetChildAtIndex(*pos, can_create);
433 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000435 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000436 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000437 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
438 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000439 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000440 else
441 {
442 child_sp.reset();
443 }
444
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445 }
446 }
447 return child_sp;
448}
449
450
451uint32_t
452ValueObject::GetNumChildren ()
453{
Greg Clayton288bdf92010-09-02 02:59:18 +0000454 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 {
456 SetNumChildren (CalculateNumChildren());
457 }
458 return m_children.size();
459}
460void
461ValueObject::SetNumChildren (uint32_t num_children)
462{
Greg Clayton288bdf92010-09-02 02:59:18 +0000463 m_children_count_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464 m_children.resize(num_children);
465}
466
467void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468ValueObject::SetName (const ConstString &name)
469{
470 m_name = name;
471}
472
Jim Ingham58b59f92011-04-22 23:53:53 +0000473ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000474ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
475{
Jim Ingham2eec4872011-05-07 00:10:58 +0000476 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000477
Greg Claytondea8cb42011-06-29 22:09:02 +0000478 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000479 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000480 std::string child_name_str;
481 uint32_t child_byte_size = 0;
482 int32_t child_byte_offset = 0;
483 uint32_t child_bitfield_bit_size = 0;
484 uint32_t child_bitfield_bit_offset = 0;
485 bool child_is_base_class = false;
486 bool child_is_deref_of_parent = false;
487
488 const bool transparent_pointers = synthetic_array_member == false;
489 clang::ASTContext *clang_ast = GetClangAST();
490 clang_type_t clang_type = GetClangType();
491 clang_type_t child_clang_type;
492
493 ExecutionContext exe_ctx;
494 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
495
496 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
497 clang_ast,
498 GetName().GetCString(),
499 clang_type,
500 idx,
501 transparent_pointers,
502 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000503 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000504 child_name_str,
505 child_byte_size,
506 child_byte_offset,
507 child_bitfield_bit_size,
508 child_bitfield_bit_offset,
509 child_is_base_class,
510 child_is_deref_of_parent);
511 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000512 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000513 if (synthetic_index)
514 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000515
Greg Claytondea8cb42011-06-29 22:09:02 +0000516 ConstString child_name;
517 if (!child_name_str.empty())
518 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519
Greg Claytondea8cb42011-06-29 22:09:02 +0000520 valobj = new ValueObjectChild (*this,
521 clang_ast,
522 child_clang_type,
523 child_name,
524 child_byte_size,
525 child_byte_offset,
526 child_bitfield_bit_size,
527 child_bitfield_bit_offset,
528 child_is_base_class,
529 child_is_deref_of_parent);
530 if (m_pointers_point_to_load_addrs)
531 valobj->SetPointersPointToLoadAddrs (m_pointers_point_to_load_addrs);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000532 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000533
Jim Ingham58b59f92011-04-22 23:53:53 +0000534 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000535}
536
537const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000538ValueObject::GetSummaryAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000539{
Enrico Granatad8b5fce2011-08-02 23:12:24 +0000540 if (UpdateValueIfNeeded (true))
Enrico Granata4becb372011-06-29 22:27:15 +0000541 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542 if (m_summary_str.empty())
543 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000544 SummaryFormat *summary_format = GetSummaryFormat().get();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000545
546 if (summary_format)
Enrico Granata4becb372011-06-29 22:27:15 +0000547 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000548 m_summary_str = summary_format->FormatObject(GetSP());
Enrico Granata4becb372011-06-29 22:27:15 +0000549 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000550 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000551 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000552 clang_type_t clang_type = GetClangType();
Greg Clayton737b9322010-09-13 03:32:57 +0000553
Enrico Granata9dd75c82011-07-15 23:30:15 +0000554 // Do some default printout for function pointers
Enrico Granataf2bbf712011-07-15 02:26:42 +0000555 if (clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000556 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000557 StreamString sstr;
558 clang_type_t elem_or_pointee_clang_type;
559 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
560 GetClangAST(),
561 &elem_or_pointee_clang_type));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000562
Enrico Granataf2bbf712011-07-15 02:26:42 +0000563 ExecutionContextScope *exe_scope = GetExecutionContextScope();
564 if (exe_scope)
565 {
Enrico Granata9dd75c82011-07-15 23:30:15 +0000566 if (ClangASTContext::IsFunctionPointerType (clang_type))
Jim Ingham6035b672011-03-31 00:19:25 +0000567 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000568 AddressType func_ptr_address_type = eAddressTypeInvalid;
569 lldb::addr_t func_ptr_address = GetPointerValue (func_ptr_address_type, true);
570
571 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
572 {
573 switch (func_ptr_address_type)
574 {
575 case eAddressTypeInvalid:
576 case eAddressTypeFile:
577 break;
578
579 case eAddressTypeLoad:
580 {
581 Address so_addr;
582 Target *target = exe_scope->CalculateTarget();
583 if (target && target->GetSectionLoadList().IsEmpty() == false)
584 {
585 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
586 {
587 so_addr.Dump (&sstr,
588 exe_scope,
589 Address::DumpStyleResolvedDescription,
590 Address::DumpStyleSectionNameOffset);
591 }
592 }
593 }
594 break;
595
596 case eAddressTypeHost:
597 break;
598 }
599 }
600 if (sstr.GetSize() > 0)
601 {
602 m_summary_str.assign (1, '(');
603 m_summary_str.append (sstr.GetData(), sstr.GetSize());
604 m_summary_str.append (1, ')');
605 }
Jim Ingham6035b672011-03-31 00:19:25 +0000606 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000607 }
608 }
609 }
610 }
611 }
612 if (m_summary_str.empty())
613 return NULL;
614 return m_summary_str.c_str();
615}
616
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000617bool
618ValueObject::IsCStringContainer(bool check_pointer)
619{
620 clang_type_t elem_or_pointee_clang_type;
621 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
622 GetClangAST(),
623 &elem_or_pointee_clang_type));
624 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
625 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
626 if (!is_char_arr_ptr)
627 return false;
628 if (!check_pointer)
629 return true;
630 if (type_flags.Test(ClangASTContext::eTypeIsArray))
631 return true;
632 lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS;
633 AddressType cstr_address_type = eAddressTypeInvalid;
634 cstr_address = GetAddressOf (cstr_address_type, true);
635 return (cstr_address != LLDB_INVALID_ADDRESS);
636}
637
638void
639ValueObject::ReadPointedString(Stream& s,
640 Error& error,
Enrico Granataf4efecd2011-07-12 22:56:10 +0000641 uint32_t max_length,
642 bool honor_array,
643 lldb::Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000644{
645
646 if (max_length == 0)
Enrico Granataf4efecd2011-07-12 22:56:10 +0000647 max_length = 128; // FIXME this should be a setting, or a formatting parameter
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000648
649 clang_type_t clang_type = GetClangType();
650 clang_type_t elem_or_pointee_clang_type;
651 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
652 GetClangAST(),
653 &elem_or_pointee_clang_type));
654 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
655 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
656 {
657 ExecutionContextScope *exe_scope = GetExecutionContextScope();
658 if (exe_scope)
659 {
660 Target *target = exe_scope->CalculateTarget();
Enrico Granata6f3533f2011-07-29 19:53:35 +0000661 if (target == NULL)
662 {
663 s << "<no target to read from>";
664 }
665 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000666 {
667 lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS;
668 AddressType cstr_address_type = eAddressTypeInvalid;
669
670 size_t cstr_len = 0;
671 bool capped_data = false;
672 if (type_flags.Test (ClangASTContext::eTypeIsArray))
673 {
674 // We have an array
675 cstr_len = ClangASTContext::GetArraySize (clang_type);
Enrico Granataf4efecd2011-07-12 22:56:10 +0000676 if (cstr_len > max_length)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000677 {
Enrico Granataf4efecd2011-07-12 22:56:10 +0000678 capped_data = true;
679 cstr_len = max_length;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000680 }
681 cstr_address = GetAddressOf (cstr_address_type, true);
682 }
683 else
684 {
685 // We have a pointer
686 cstr_address = GetPointerValue (cstr_address_type, true);
687 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000688 if (cstr_address == LLDB_INVALID_ADDRESS)
689 {
690 s << "<invalid address for data>";
691 }
692 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000693 {
694 Address cstr_so_addr (NULL, cstr_address);
695 DataExtractor data;
696 size_t bytes_read = 0;
697 std::vector<char> data_buffer;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000698 bool prefer_file_cache = false;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000699 if (cstr_len > 0 && honor_array)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000700 {
701 data_buffer.resize(cstr_len);
702 data.SetData (&data_buffer.front(), data_buffer.size(), lldb::endian::InlHostByteOrder());
703 bytes_read = target->ReadMemory (cstr_so_addr,
704 prefer_file_cache,
705 &data_buffer.front(),
706 cstr_len,
707 error);
708 if (bytes_read > 0)
709 {
710 s << '"';
711 data.Dump (&s,
712 0, // Start offset in "data"
Enrico Granataf4efecd2011-07-12 22:56:10 +0000713 item_format,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000714 1, // Size of item (1 byte for a char!)
715 bytes_read, // How many bytes to print?
716 UINT32_MAX, // num per line
717 LLDB_INVALID_ADDRESS,// base address
718 0, // bitfield bit size
719 0); // bitfield bit offset
720 if (capped_data)
721 s << "...";
722 s << '"';
723 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000724 else
725 s << "\"<data not available>\"";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000726 }
727 else
728 {
Enrico Granataf4efecd2011-07-12 22:56:10 +0000729 cstr_len = max_length;
730 const size_t k_max_buf_size = 64;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000731 data_buffer.resize (k_max_buf_size + 1);
732 // NULL terminate in case we don't get the entire C string
733 data_buffer.back() = '\0';
734
735 s << '"';
736
Enrico Granata6f3533f2011-07-29 19:53:35 +0000737 bool any_data = false;
738
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000739 data.SetData (&data_buffer.front(), data_buffer.size(), endian::InlHostByteOrder());
740 while ((bytes_read = target->ReadMemory (cstr_so_addr,
741 prefer_file_cache,
742 &data_buffer.front(),
743 k_max_buf_size,
744 error)) > 0)
745 {
Enrico Granata6f3533f2011-07-29 19:53:35 +0000746 any_data = true;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000747 size_t len = strlen(&data_buffer.front());
748 if (len == 0)
749 break;
750 if (len > bytes_read)
751 len = bytes_read;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000752 if (len > cstr_len)
753 len = cstr_len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000754
755 data.Dump (&s,
756 0, // Start offset in "data"
Enrico Granataf4efecd2011-07-12 22:56:10 +0000757 item_format,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000758 1, // Size of item (1 byte for a char!)
759 len, // How many bytes to print?
760 UINT32_MAX, // num per line
761 LLDB_INVALID_ADDRESS,// base address
762 0, // bitfield bit size
763 0); // bitfield bit offset
764
765 if (len < k_max_buf_size)
766 break;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000767 if (len >= cstr_len)
768 {
769 s << "...";
770 break;
771 }
772 cstr_len -= len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000773 cstr_so_addr.Slide (k_max_buf_size);
774 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000775
776 if (any_data == false)
777 s << "<data not available>";
778
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000779 s << '"';
780 }
781 }
782 }
783 }
784 }
785 else
786 {
787 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +0000788 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000789 }
790}
791
Jim Ingham53c47f12010-09-10 23:12:17 +0000792const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000793ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +0000794{
Enrico Granata0a3958e2011-07-02 00:25:22 +0000795
Enrico Granatad8b5fce2011-08-02 23:12:24 +0000796 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +0000797 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000798
799 if (!m_object_desc_str.empty())
800 return m_object_desc_str.c_str();
801
Jim Ingham6035b672011-03-31 00:19:25 +0000802 ExecutionContextScope *exe_scope = GetExecutionContextScope();
803 if (exe_scope == NULL)
804 return NULL;
805
Jim Ingham53c47f12010-09-10 23:12:17 +0000806 Process *process = exe_scope->CalculateProcess();
Jim Ingham5a369122010-09-28 01:25:32 +0000807 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +0000808 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +0000809
Jim Ingham53c47f12010-09-10 23:12:17 +0000810 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +0000811
812 lldb::LanguageType language = GetObjectRuntimeLanguage();
813 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
814
Jim Inghama2cf2632010-12-23 02:29:54 +0000815 if (runtime == NULL)
816 {
Jim Inghamb7603bb2011-03-18 00:05:18 +0000817 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +0000818 clang_type_t opaque_qual_type = GetClangType();
819 if (opaque_qual_type != NULL)
820 {
Jim Inghamb7603bb2011-03-18 00:05:18 +0000821 bool is_signed;
822 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
823 || ClangASTContext::IsPointerType (opaque_qual_type))
824 {
Jim Inghama2cf2632010-12-23 02:29:54 +0000825 runtime = process->GetLanguageRuntime(lldb::eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +0000826 }
Jim Inghama2cf2632010-12-23 02:29:54 +0000827 }
828 }
829
Jim Ingham8d543de2011-03-31 23:01:21 +0000830 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +0000831 {
832 m_object_desc_str.append (s.GetData());
833 }
Sean Callanan672ad942010-10-23 00:18:49 +0000834
835 if (m_object_desc_str.empty())
836 return NULL;
837 else
838 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +0000839}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000840
841const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000842ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000843{
844 // If our byte size is zero this is an aggregate type that has children
Greg Clayton1be10fc2010-09-29 01:12:09 +0000845 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000846 {
Enrico Granatac3e320a2011-08-02 17:27:39 +0000847 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000848 {
849 if (m_value_str.empty())
850 {
851 const Value::ContextType context_type = m_value.GetContextType();
852
853 switch (context_type)
854 {
Greg Clayton526e5af2010-11-13 03:52:47 +0000855 case Value::eContextTypeClangType:
856 case Value::eContextTypeLLDBType:
857 case Value::eContextTypeVariable:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858 {
Greg Clayton73b472d2010-10-27 03:32:59 +0000859 clang_type_t clang_type = GetClangType ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000860 if (clang_type)
861 {
Enrico Granatac3e320a2011-08-02 17:27:39 +0000862 if (m_format == lldb::eFormatDefault && m_last_value_format)
Enrico Granata4becb372011-06-29 22:27:15 +0000863 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000864 m_value_str = m_last_value_format->FormatObject(GetSP());
Enrico Granata4becb372011-06-29 22:27:15 +0000865 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000866 else
Greg Clayton007d5be2011-05-30 00:49:24 +0000867 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000868 StreamString sstr;
869 Format format = GetFormat();
870 if (format == eFormatDefault)
871 format = (m_is_bitfield_for_scalar ? eFormatUnsigned :
872 ClangASTType::GetFormat(clang_type));
873
874 if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
875 clang_type, // The clang type to display
876 &sstr,
877 format, // Format to display this type with
878 m_data, // Data to extract from
879 0, // Byte offset into "m_data"
880 GetByteSize(), // Byte size of item in "m_data"
881 GetBitfieldBitSize(), // Bitfield bit size
882 GetBitfieldBitOffset())) // Bitfield bit offset
883 m_value_str.swap(sstr.GetString());
884 else
885 {
886 m_error.SetErrorStringWithFormat ("unsufficient data for value (only %u of %u bytes available)",
887 m_data.GetByteSize(),
888 GetByteSize());
889 m_value_str.clear();
890 }
Greg Clayton007d5be2011-05-30 00:49:24 +0000891 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000892 }
893 }
894 break;
895
Greg Clayton526e5af2010-11-13 03:52:47 +0000896 case Value::eContextTypeRegisterInfo:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000897 {
898 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
899 if (reg_info)
900 {
901 StreamString reg_sstr;
902 m_data.Dump(&reg_sstr, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
903 m_value_str.swap(reg_sstr.GetString());
904 }
905 }
906 break;
Greg Claytonc982c762010-07-09 20:39:50 +0000907
908 default:
909 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000910 }
911 }
Greg Clayton288bdf92010-09-02 02:59:18 +0000912
913 if (!m_value_did_change && m_old_value_valid)
914 {
915 // The value was gotten successfully, so we consider the
916 // value as changed if the value string differs
917 SetValueDidChange (m_old_value_str != m_value_str);
918 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000919 }
920 }
921 if (m_value_str.empty())
922 return NULL;
923 return m_value_str.c_str();
924}
925
Enrico Granatac3e320a2011-08-02 17:27:39 +0000926// if > 8bytes, 0 is returned. this method should mostly be used
927// to read address values out of pointers
928unsigned long long
929ValueObject::GetValueAsUnsigned()
930{
931 // If our byte size is zero this is an aggregate type that has children
932 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
933 {
934 if (UpdateValueIfNeeded(true))
935 {
936 uint32_t offset = 0;
937 return m_data.GetMaxU64(&offset,
938 m_data.GetByteSize());
939 }
940 }
941 return 0;
942}
943
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000944bool
945ValueObject::GetPrintableRepresentation(Stream& s,
946 ValueObjectRepresentationStyle val_obj_display,
Enrico Granata0a3958e2011-07-02 00:25:22 +0000947 lldb::Format custom_format)
948{
Enrico Granataf4efecd2011-07-12 22:56:10 +0000949
950 RefCounter ref(&m_dump_printable_counter);
951
Enrico Granata9dd75c82011-07-15 23:30:15 +0000952 if (custom_format != lldb::eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +0000953 SetFormat(custom_format);
954
955 const char * return_value;
Enrico Granatacd1c0232011-08-04 23:37:18 +0000956 std::string alloc_mem;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000957
958 switch(val_obj_display)
959 {
960 case eDisplayValue:
961 return_value = GetValueAsCString();
962 break;
963 case eDisplaySummary:
964 return_value = GetSummaryAsCString();
965 break;
966 case eDisplayLanguageSpecific:
967 return_value = GetObjectDescription();
968 break;
Enrico Granataf2bbf712011-07-15 02:26:42 +0000969 case eDisplayLocation:
970 return_value = GetLocationAsCString();
971 break;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000972 case eDisplayChildrenCount:
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000973 {
Enrico Granatacd1c0232011-08-04 23:37:18 +0000974 alloc_mem.resize(512);
975 return_value = &alloc_mem[0];
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000976 int count = GetNumChildren();
Enrico Granatacd1c0232011-08-04 23:37:18 +0000977 snprintf((char*)return_value, 512, "%d", count);
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000978 break;
979 }
980 default:
981 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000982 }
983
Enrico Granataf4efecd2011-07-12 22:56:10 +0000984 // this code snippet might lead to endless recursion, thus we use a RefCounter here to
985 // check that we are not looping endlessly
986 if (!return_value && (m_dump_printable_counter < 3))
Enrico Granata9fc19442011-07-06 02:13:41 +0000987 {
988 // try to pick the other choice
989 if (val_obj_display == eDisplayValue)
990 return_value = GetSummaryAsCString();
991 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +0000992 {
993 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
994 {
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000995 // this thing has no value, and it seems to have no summary
996 // some combination of unitialized data and other factors can also
997 // raise this condition, so let's print a nice generic error message
998 return_value = "<no available summary>";
Enrico Granatae992a082011-07-22 17:03:19 +0000999 }
1000 else
1001 return_value = GetValueAsCString();
1002 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001003 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001004
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001005 if (return_value)
1006 s.PutCString(return_value);
1007 else
1008 s.PutCString("<no printable representation>");
1009
1010 // we should only return false here if we could not do *anything*
1011 // even if we have an error message as output, that's a success
1012 // from our callers' perspective, so return true
1013 return true;
1014
Enrico Granata0a3958e2011-07-02 00:25:22 +00001015}
1016
Enrico Granata9fc19442011-07-06 02:13:41 +00001017bool
1018ValueObject::DumpPrintableRepresentation(Stream& s,
1019 ValueObjectRepresentationStyle val_obj_display,
1020 lldb::Format custom_format)
1021{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001022
1023 clang_type_t elem_or_pointee_type;
1024 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001025
Enrico Granataf4efecd2011-07-12 22:56:10 +00001026 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1027 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001028 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001029 // when being asked to get a printable display an array or pointer type directly,
1030 // try to "do the right thing"
1031
1032 if (IsCStringContainer(true) &&
1033 (custom_format == lldb::eFormatCString ||
1034 custom_format == lldb::eFormatCharArray ||
1035 custom_format == lldb::eFormatChar ||
1036 custom_format == lldb::eFormatVectorOfChar)) // print char[] & char* directly
1037 {
1038 Error error;
1039 ReadPointedString(s,
1040 error,
1041 0,
1042 (custom_format == lldb::eFormatVectorOfChar) ||
1043 (custom_format == lldb::eFormatCharArray));
1044 return !error.Fail();
1045 }
1046
1047 if (custom_format == lldb::eFormatEnum)
1048 return false;
1049
1050 // this only works for arrays, because I have no way to know when
1051 // the pointed memory ends, and no special \0 end of data marker
1052 if (flags.Test(ClangASTContext::eTypeIsArray))
1053 {
1054 if ((custom_format == lldb::eFormatBytes) ||
1055 (custom_format == lldb::eFormatBytesWithASCII))
1056 {
1057 uint32_t count = GetNumChildren();
1058
1059 s << '[';
1060 for (uint32_t low = 0; low < count; low++)
1061 {
1062
1063 if (low)
1064 s << ',';
1065
1066 ValueObjectSP child = GetChildAtIndex(low,true);
1067 if (!child.get())
1068 {
Enrico Granatae992a082011-07-22 17:03:19 +00001069 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001070 continue;
1071 }
1072 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1073 }
1074
1075 s << ']';
1076
1077 return true;
1078 }
1079
1080 if ((custom_format == lldb::eFormatVectorOfChar) ||
1081 (custom_format == lldb::eFormatVectorOfFloat32) ||
1082 (custom_format == lldb::eFormatVectorOfFloat64) ||
1083 (custom_format == lldb::eFormatVectorOfSInt16) ||
1084 (custom_format == lldb::eFormatVectorOfSInt32) ||
1085 (custom_format == lldb::eFormatVectorOfSInt64) ||
1086 (custom_format == lldb::eFormatVectorOfSInt8) ||
1087 (custom_format == lldb::eFormatVectorOfUInt128) ||
1088 (custom_format == lldb::eFormatVectorOfUInt16) ||
1089 (custom_format == lldb::eFormatVectorOfUInt32) ||
1090 (custom_format == lldb::eFormatVectorOfUInt64) ||
1091 (custom_format == lldb::eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1092 {
1093 uint32_t count = GetNumChildren();
1094
1095 lldb::Format format = FormatManager::GetSingleItemFormat(custom_format);
1096
1097 s << '[';
1098 for (uint32_t low = 0; low < count; low++)
1099 {
1100
1101 if (low)
1102 s << ',';
1103
1104 ValueObjectSP child = GetChildAtIndex(low,true);
1105 if (!child.get())
1106 {
Enrico Granatae992a082011-07-22 17:03:19 +00001107 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001108 continue;
1109 }
1110 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1111 }
1112
1113 s << ']';
1114
1115 return true;
1116 }
1117 }
1118
1119 if ((custom_format == lldb::eFormatBoolean) ||
1120 (custom_format == lldb::eFormatBinary) ||
1121 (custom_format == lldb::eFormatChar) ||
1122 (custom_format == lldb::eFormatCharPrintable) ||
1123 (custom_format == lldb::eFormatComplexFloat) ||
1124 (custom_format == lldb::eFormatDecimal) ||
1125 (custom_format == lldb::eFormatHex) ||
1126 (custom_format == lldb::eFormatFloat) ||
1127 (custom_format == lldb::eFormatOctal) ||
1128 (custom_format == lldb::eFormatOSType) ||
1129 (custom_format == lldb::eFormatUnicode16) ||
1130 (custom_format == lldb::eFormatUnicode32) ||
1131 (custom_format == lldb::eFormatUnsigned) ||
1132 (custom_format == lldb::eFormatPointer) ||
1133 (custom_format == lldb::eFormatComplexInteger) ||
1134 (custom_format == lldb::eFormatComplex) ||
1135 (custom_format == lldb::eFormatDefault)) // use the [] operator
1136 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001137 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001138 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001139 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001140 SetFormat(eFormatDefault);
1141 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001142}
1143
Greg Clayton737b9322010-09-13 03:32:57 +00001144addr_t
Greg Claytone0d378b2011-03-24 21:19:54 +00001145ValueObject::GetAddressOf (AddressType &address_type, bool scalar_is_load_address)
Greg Clayton73b472d2010-10-27 03:32:59 +00001146{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001147 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001148 return LLDB_INVALID_ADDRESS;
1149
Greg Clayton73b472d2010-10-27 03:32:59 +00001150 switch (m_value.GetValueType())
1151 {
1152 case Value::eValueTypeScalar:
1153 if (scalar_is_load_address)
1154 {
1155 address_type = eAddressTypeLoad;
1156 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1157 }
1158 break;
1159
1160 case Value::eValueTypeLoadAddress:
1161 case Value::eValueTypeFileAddress:
1162 case Value::eValueTypeHostAddress:
1163 {
1164 address_type = m_value.GetValueAddressType ();
1165 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1166 }
1167 break;
1168 }
1169 address_type = eAddressTypeInvalid;
1170 return LLDB_INVALID_ADDRESS;
1171}
1172
1173addr_t
Greg Claytone0d378b2011-03-24 21:19:54 +00001174ValueObject::GetPointerValue (AddressType &address_type, bool scalar_is_load_address)
Greg Clayton737b9322010-09-13 03:32:57 +00001175{
1176 lldb::addr_t address = LLDB_INVALID_ADDRESS;
1177 address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001178
Enrico Granatac3e320a2011-08-02 17:27:39 +00001179 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001180 return address;
1181
Greg Clayton73b472d2010-10-27 03:32:59 +00001182 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001183 {
1184 case Value::eValueTypeScalar:
1185 if (scalar_is_load_address)
1186 {
1187 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1188 address_type = eAddressTypeLoad;
1189 }
1190 break;
1191
1192 case Value::eValueTypeLoadAddress:
1193 case Value::eValueTypeFileAddress:
1194 case Value::eValueTypeHostAddress:
1195 {
1196 uint32_t data_offset = 0;
1197 address = m_data.GetPointer(&data_offset);
1198 address_type = m_value.GetValueAddressType();
1199 if (address_type == eAddressTypeInvalid)
1200 address_type = eAddressTypeLoad;
1201 }
1202 break;
1203 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001204
1205 if (m_pointers_point_to_load_addrs)
1206 address_type = eAddressTypeLoad;
1207
Greg Clayton737b9322010-09-13 03:32:57 +00001208 return address;
1209}
1210
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001211bool
Jim Ingham6035b672011-03-31 00:19:25 +00001212ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001213{
1214 // Make sure our value is up to date first so that our location and location
1215 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001216 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001217 return false;
1218
1219 uint32_t count = 0;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001220 lldb::Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001221
1222 char *end = NULL;
Greg Claytonb1320972010-07-14 00:18:15 +00001223 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001224 switch (encoding)
1225 {
1226 case eEncodingInvalid:
1227 return false;
1228
1229 case eEncodingUint:
1230 if (byte_size > sizeof(unsigned long long))
1231 {
1232 return false;
1233 }
1234 else
1235 {
1236 unsigned long long ull_val = strtoull(value_str, &end, 0);
1237 if (end && *end != '\0')
1238 return false;
Greg Clayton644247c2011-07-07 01:59:51 +00001239 m_value.GetScalar() = ull_val;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001240 // Limit the bytes in our m_data appropriately.
1241 m_value.GetScalar().GetData (m_data, byte_size);
1242 }
1243 break;
1244
1245 case eEncodingSint:
1246 if (byte_size > sizeof(long long))
1247 {
1248 return false;
1249 }
1250 else
1251 {
1252 long long sll_val = strtoll(value_str, &end, 0);
1253 if (end && *end != '\0')
1254 return false;
Greg Clayton644247c2011-07-07 01:59:51 +00001255 m_value.GetScalar() = sll_val;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001256 // Limit the bytes in our m_data appropriately.
1257 m_value.GetScalar().GetData (m_data, byte_size);
1258 }
1259 break;
1260
1261 case eEncodingIEEE754:
1262 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001263 const off_t byte_offset = GetByteOffset();
Greg Claytonc982c762010-07-09 20:39:50 +00001264 uint8_t *dst = const_cast<uint8_t *>(m_data.PeekData(byte_offset, byte_size));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001265 if (dst != NULL)
1266 {
1267 // We are decoding a float into host byte order below, so make
1268 // sure m_data knows what it contains.
Greg Clayton7fb56d02011-02-01 01:31:41 +00001269 m_data.SetByteOrder(lldb::endian::InlHostByteOrder());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001270 const size_t converted_byte_size = ClangASTContext::ConvertStringToFloatValue (
1271 GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +00001272 GetClangType(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001273 value_str,
1274 dst,
1275 byte_size);
1276
1277 if (converted_byte_size == byte_size)
1278 {
1279 }
1280 }
1281 }
1282 break;
1283
1284 case eEncodingVector:
1285 return false;
1286
1287 default:
1288 return false;
1289 }
1290
1291 // If we have made it here the value is in m_data and we should write it
1292 // out to the target
1293 return Write ();
1294}
1295
1296bool
1297ValueObject::Write ()
1298{
1299 // Clear the update ID so the next time we try and read the value
1300 // we try and read it again.
Jim Ingham6035b672011-03-31 00:19:25 +00001301 m_update_point.SetNeedsUpdate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001302
1303 // TODO: when Value has a method to write a value back, call it from here.
1304 return false;
1305
1306}
1307
Jim Ingham5a369122010-09-28 01:25:32 +00001308lldb::LanguageType
1309ValueObject::GetObjectRuntimeLanguage ()
1310{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001311 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1312 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001313}
1314
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001315void
Jim Ingham58b59f92011-04-22 23:53:53 +00001316ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001317{
Jim Ingham58b59f92011-04-22 23:53:53 +00001318 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001319}
1320
1321ValueObjectSP
1322ValueObject::GetSyntheticChild (const ConstString &key) const
1323{
1324 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001325 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001326 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001327 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001328 return synthetic_child_sp;
1329}
1330
1331bool
1332ValueObject::IsPointerType ()
1333{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001334 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001335}
1336
Jim Inghamb7603bb2011-03-18 00:05:18 +00001337bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001338ValueObject::IsArrayType ()
1339{
1340 return ClangASTContext::IsArrayType (GetClangType());
1341}
1342
1343bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001344ValueObject::IsScalarType ()
1345{
1346 return ClangASTContext::IsScalarType (GetClangType());
1347}
1348
1349bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001350ValueObject::IsIntegerType (bool &is_signed)
1351{
1352 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1353}
Greg Clayton73b472d2010-10-27 03:32:59 +00001354
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001355bool
1356ValueObject::IsPointerOrReferenceType ()
1357{
Greg Clayton007d5be2011-05-30 00:49:24 +00001358 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1359}
1360
1361bool
1362ValueObject::IsPossibleCPlusPlusDynamicType ()
1363{
1364 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001365}
1366
Greg Claytondea8cb42011-06-29 22:09:02 +00001367bool
1368ValueObject::IsPossibleDynamicType ()
1369{
1370 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1371}
1372
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001373ValueObjectSP
1374ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1375{
1376 ValueObjectSP synthetic_child_sp;
1377 if (IsPointerType ())
1378 {
1379 char index_str[64];
1380 snprintf(index_str, sizeof(index_str), "[%i]", index);
1381 ConstString index_const_str(index_str);
1382 // Check if we have already created a synthetic array member in this
1383 // valid object. If we have we will re-use it.
1384 synthetic_child_sp = GetSyntheticChild (index_const_str);
1385 if (!synthetic_child_sp)
1386 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001387 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001388 // We haven't made a synthetic array member for INDEX yet, so
1389 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001390 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001391
1392 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001393 if (synthetic_child)
1394 {
1395 AddSyntheticChild(index_const_str, synthetic_child);
1396 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001397 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001398 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001399 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001400 }
1401 }
1402 return synthetic_child_sp;
1403}
Jim Ingham22777012010-09-23 02:01:19 +00001404
Greg Claytondaf515f2011-07-09 20:12:33 +00001405// This allows you to create an array member using and index
1406// that doesn't not fall in the normal bounds of the array.
1407// Many times structure can be defined as:
1408// struct Collection
1409// {
1410// uint32_t item_count;
1411// Item item_array[0];
1412// };
1413// The size of the "item_array" is 1, but many times in practice
1414// there are more items in "item_array".
1415
1416ValueObjectSP
1417ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1418{
1419 ValueObjectSP synthetic_child_sp;
1420 if (IsArrayType ())
1421 {
1422 char index_str[64];
1423 snprintf(index_str, sizeof(index_str), "[%i]", index);
1424 ConstString index_const_str(index_str);
1425 // Check if we have already created a synthetic array member in this
1426 // valid object. If we have we will re-use it.
1427 synthetic_child_sp = GetSyntheticChild (index_const_str);
1428 if (!synthetic_child_sp)
1429 {
1430 ValueObject *synthetic_child;
1431 // We haven't made a synthetic array member for INDEX yet, so
1432 // lets make one and cache it for any future reference.
1433 synthetic_child = CreateChildAtIndex(0, true, index);
1434
1435 // Cache the value if we got one back...
1436 if (synthetic_child)
1437 {
1438 AddSyntheticChild(index_const_str, synthetic_child);
1439 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001440 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001441 synthetic_child_sp->m_is_array_item_for_pointer = true;
1442 }
1443 }
1444 }
1445 return synthetic_child_sp;
1446}
1447
Enrico Granata9fc19442011-07-06 02:13:41 +00001448ValueObjectSP
1449ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1450{
1451 ValueObjectSP synthetic_child_sp;
1452 if (IsScalarType ())
1453 {
1454 char index_str[64];
1455 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1456 ConstString index_const_str(index_str);
1457 // Check if we have already created a synthetic array member in this
1458 // valid object. If we have we will re-use it.
1459 synthetic_child_sp = GetSyntheticChild (index_const_str);
1460 if (!synthetic_child_sp)
1461 {
1462 ValueObjectChild *synthetic_child;
1463 // We haven't made a synthetic array member for INDEX yet, so
1464 // lets make one and cache it for any future reference.
1465 synthetic_child = new ValueObjectChild(*this,
1466 GetClangAST(),
1467 GetClangType(),
1468 index_const_str,
1469 GetByteSize(),
1470 0,
1471 to-from+1,
1472 from,
1473 false,
1474 false);
1475
1476 // Cache the value if we got one back...
1477 if (synthetic_child)
1478 {
1479 AddSyntheticChild(index_const_str, synthetic_child);
1480 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001481 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001482 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1483 }
1484 }
1485 }
1486 return synthetic_child_sp;
1487}
1488
Enrico Granata6f3533f2011-07-29 19:53:35 +00001489lldb::ValueObjectSP
1490ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1491{
1492
1493 ValueObjectSP synthetic_child_sp;
1494
1495 char name_str[64];
1496 snprintf(name_str, sizeof(name_str), "@%i", offset);
1497 ConstString name_const_str(name_str);
1498
1499 // Check if we have already created a synthetic array member in this
1500 // valid object. If we have we will re-use it.
1501 synthetic_child_sp = GetSyntheticChild (name_const_str);
1502
1503 if (synthetic_child_sp.get())
1504 return synthetic_child_sp;
1505
1506 if (!can_create)
1507 return lldb::ValueObjectSP();
1508
1509 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1510 type.GetASTContext(),
1511 type.GetOpaqueQualType(),
1512 name_const_str,
1513 type.GetTypeByteSize(),
1514 offset,
1515 0,
1516 0,
1517 false,
1518 false);
1519 if (synthetic_child)
1520 {
1521 AddSyntheticChild(name_const_str, synthetic_child);
1522 synthetic_child_sp = synthetic_child->GetSP();
1523 synthetic_child_sp->SetName(name_const_str);
1524 synthetic_child_sp->m_is_child_at_offset = true;
1525 }
1526 return synthetic_child_sp;
1527}
1528
Enrico Granatad55546b2011-07-22 00:16:08 +00001529// your expression path needs to have a leading . or ->
1530// (unless it somehow "looks like" an array, in which case it has
1531// a leading [ symbol). while the [ is meaningful and should be shown
1532// to the user, . and -> are just parser design, but by no means
1533// added information for the user.. strip them off
1534static const char*
1535SkipLeadingExpressionPathSeparators(const char* expression)
1536{
1537 if (!expression || !expression[0])
1538 return expression;
1539 if (expression[0] == '.')
1540 return expression+1;
1541 if (expression[0] == '-' && expression[1] == '>')
1542 return expression+2;
1543 return expression;
1544}
1545
1546lldb::ValueObjectSP
1547ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1548{
1549 ValueObjectSP synthetic_child_sp;
1550 ConstString name_const_string(expression);
1551 // Check if we have already created a synthetic array member in this
1552 // valid object. If we have we will re-use it.
1553 synthetic_child_sp = GetSyntheticChild (name_const_string);
1554 if (!synthetic_child_sp)
1555 {
1556 // We haven't made a synthetic array member for expression yet, so
1557 // lets make one and cache it for any future reference.
1558 synthetic_child_sp = GetValueForExpressionPath(expression);
1559
1560 // Cache the value if we got one back...
1561 if (synthetic_child_sp.get())
1562 {
1563 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001564 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001565 synthetic_child_sp->m_is_expression_path_child = true;
1566 }
1567 }
1568 return synthetic_child_sp;
1569}
1570
1571void
1572ValueObject::CalculateSyntheticValue (lldb::SyntheticValueType use_synthetic)
1573{
1574 if (use_synthetic == lldb::eNoSyntheticFilter)
1575 return;
1576
Enrico Granatac3e320a2011-08-02 17:27:39 +00001577 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001578
1579 if (m_last_synthetic_filter.get() == NULL)
1580 return;
1581
Enrico Granataa37a0652011-07-24 00:14:56 +00001582 if (m_synthetic_value == NULL)
1583 m_synthetic_value = new ValueObjectSynthetic(*this, m_last_synthetic_filter);
Enrico Granatad55546b2011-07-22 00:16:08 +00001584
1585}
1586
Jim Ingham78a685a2011-04-16 00:01:13 +00001587void
Jim Ingham2837b762011-05-04 03:43:18 +00001588ValueObject::CalculateDynamicValue (lldb::DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00001589{
Jim Ingham2837b762011-05-04 03:43:18 +00001590 if (use_dynamic == lldb::eNoDynamicValues)
1591 return;
1592
Jim Ingham58b59f92011-04-22 23:53:53 +00001593 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00001594 {
Enrico Granata6f3533f2011-07-29 19:53:35 +00001595 Process *process = m_update_point.GetProcessSP().get();
Jim Ingham78a685a2011-04-16 00:01:13 +00001596 bool worth_having_dynamic_value = false;
Jim Ingham22777012010-09-23 02:01:19 +00001597
Jim Ingham78a685a2011-04-16 00:01:13 +00001598
1599 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
1600 // hard code this everywhere.
1601 lldb::LanguageType known_type = GetObjectRuntimeLanguage();
1602 if (known_type != lldb::eLanguageTypeUnknown && known_type != lldb::eLanguageTypeC)
1603 {
1604 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
1605 if (runtime)
1606 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
1607 }
1608 else
1609 {
1610 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeC_plus_plus);
1611 if (cpp_runtime)
1612 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
1613
1614 if (!worth_having_dynamic_value)
1615 {
1616 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeObjC);
1617 if (objc_runtime)
Jim Ingham2837b762011-05-04 03:43:18 +00001618 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00001619 }
1620 }
1621
1622 if (worth_having_dynamic_value)
Jim Ingham2837b762011-05-04 03:43:18 +00001623 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham58b59f92011-04-22 23:53:53 +00001624
1625// if (worth_having_dynamic_value)
1626// printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager);
1627
Jim Ingham78a685a2011-04-16 00:01:13 +00001628 }
1629}
1630
Jim Ingham58b59f92011-04-22 23:53:53 +00001631ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00001632ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00001633{
Jim Ingham2837b762011-05-04 03:43:18 +00001634 if (use_dynamic == lldb::eNoDynamicValues)
1635 return ValueObjectSP();
1636
1637 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00001638 {
Jim Ingham2837b762011-05-04 03:43:18 +00001639 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001640 }
Jim Ingham58b59f92011-04-22 23:53:53 +00001641 if (m_dynamic_value)
1642 return m_dynamic_value->GetSP();
1643 else
1644 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00001645}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001646
Enrico Granatad55546b2011-07-22 00:16:08 +00001647// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
1648// or we do not really want a dynamic VO. this method instead returns this object
1649// itself when making it synthetic has no meaning. this makes it much simpler
1650// to replace the SyntheticValue for the ValueObject
1651ValueObjectSP
1652ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
1653{
1654 if (use_synthetic == lldb::eNoSyntheticFilter)
1655 return GetSP();
1656
Enrico Granatac3e320a2011-08-02 17:27:39 +00001657 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001658
1659 if (m_last_synthetic_filter.get() == NULL)
1660 return GetSP();
1661
1662 CalculateSyntheticValue(use_synthetic);
1663
1664 if (m_synthetic_value)
1665 return m_synthetic_value->GetSP();
1666 else
1667 return GetSP();
1668}
1669
Greg Claytone221f822011-01-21 01:59:00 +00001670bool
Enrico Granata27b625e2011-08-09 01:04:56 +00001671ValueObject::HasSyntheticValue()
1672{
1673 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
1674
1675 if (m_last_synthetic_filter.get() == NULL)
1676 return false;
1677
1678 CalculateSyntheticValue(lldb::eUseSyntheticFilter);
1679
1680 if (m_synthetic_value)
1681 return true;
1682 else
1683 return false;
1684}
1685
1686bool
Greg Claytone221f822011-01-21 01:59:00 +00001687ValueObject::GetBaseClassPath (Stream &s)
1688{
1689 if (IsBaseClass())
1690 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001691 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00001692 clang_type_t clang_type = GetClangType();
1693 std::string cxx_class_name;
1694 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
1695 if (this_had_base_class)
1696 {
1697 if (parent_had_base_class)
1698 s.PutCString("::");
1699 s.PutCString(cxx_class_name.c_str());
1700 }
1701 return parent_had_base_class || this_had_base_class;
1702 }
1703 return false;
1704}
1705
1706
1707ValueObject *
1708ValueObject::GetNonBaseClassParent()
1709{
Jim Ingham78a685a2011-04-16 00:01:13 +00001710 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00001711 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001712 if (GetParent()->IsBaseClass())
1713 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00001714 else
Jim Ingham78a685a2011-04-16 00:01:13 +00001715 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00001716 }
1717 return NULL;
1718}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001719
1720void
Enrico Granata4becb372011-06-29 22:27:15 +00001721ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001722{
Greg Claytone221f822011-01-21 01:59:00 +00001723 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00001724
Enrico Granata9dd75c82011-07-15 23:30:15 +00001725 if (is_deref_of_parent && epformat == eDereferencePointers) {
Enrico Granata4becb372011-06-29 22:27:15 +00001726 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
1727 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
1728 // the eHonorPointers mode is meant to produce strings in this latter format
1729 s.PutCString("*(");
1730 }
Greg Claytone221f822011-01-21 01:59:00 +00001731
Enrico Granata4becb372011-06-29 22:27:15 +00001732 ValueObject* parent = GetParent();
1733
1734 if (parent)
1735 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00001736
1737 // if we are a deref_of_parent just because we are synthetic array
1738 // members made up to allow ptr[%d] syntax to work in variable
1739 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00001740 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001741 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00001742
Greg Claytone221f822011-01-21 01:59:00 +00001743 if (!IsBaseClass())
1744 {
1745 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001746 {
Greg Claytone221f822011-01-21 01:59:00 +00001747 ValueObject *non_base_class_parent = GetNonBaseClassParent();
1748 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001749 {
Greg Claytone221f822011-01-21 01:59:00 +00001750 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
1751 if (non_base_class_parent_clang_type)
1752 {
1753 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
1754
Enrico Granata9dd75c82011-07-15 23:30:15 +00001755 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00001756 {
1757 s.PutCString("->");
1758 }
Enrico Granata4becb372011-06-29 22:27:15 +00001759 else
1760 {
1761 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
1762 {
1763 s.PutCString("->");
1764 }
1765 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
1766 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
1767 {
1768 s.PutChar('.');
1769 }
Greg Claytone221f822011-01-21 01:59:00 +00001770 }
1771 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001772 }
Greg Claytone221f822011-01-21 01:59:00 +00001773
1774 const char *name = GetName().GetCString();
1775 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001776 {
Greg Claytone221f822011-01-21 01:59:00 +00001777 if (qualify_cxx_base_classes)
1778 {
1779 if (GetBaseClassPath (s))
1780 s.PutCString("::");
1781 }
1782 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001783 }
1784 }
1785 }
1786
Enrico Granata4becb372011-06-29 22:27:15 +00001787 if (is_deref_of_parent && epformat == eDereferencePointers) {
Greg Claytone221f822011-01-21 01:59:00 +00001788 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00001789 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001790}
1791
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001792lldb::ValueObjectSP
1793ValueObject::GetValueForExpressionPath(const char* expression,
1794 const char** first_unparsed,
1795 ExpressionPathScanEndReason* reason_to_stop,
1796 ExpressionPathEndResultType* final_value_type,
1797 const GetValueForExpressionPathOptions& options,
1798 ExpressionPathAftermath* final_task_on_target)
1799{
1800
1801 const char* dummy_first_unparsed;
1802 ExpressionPathScanEndReason dummy_reason_to_stop;
1803 ExpressionPathEndResultType dummy_final_value_type;
1804 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
1805
1806 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
1807 first_unparsed ? first_unparsed : &dummy_first_unparsed,
1808 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
1809 final_value_type ? final_value_type : &dummy_final_value_type,
1810 options,
1811 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
1812
1813 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
1814 {
1815 return ret_val;
1816 }
1817 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
1818 {
1819 if (*final_task_on_target == ValueObject::eDereference)
1820 {
1821 Error error;
1822 ValueObjectSP final_value = ret_val->Dereference(error);
1823 if (error.Fail() || !final_value.get())
1824 {
1825 *reason_to_stop = ValueObject::eDereferencingFailed;
1826 *final_value_type = ValueObject::eInvalid;
1827 return ValueObjectSP();
1828 }
1829 else
1830 {
1831 *final_task_on_target = ValueObject::eNothing;
1832 return final_value;
1833 }
1834 }
1835 if (*final_task_on_target == ValueObject::eTakeAddress)
1836 {
1837 Error error;
1838 ValueObjectSP final_value = ret_val->AddressOf(error);
1839 if (error.Fail() || !final_value.get())
1840 {
1841 *reason_to_stop = ValueObject::eTakingAddressFailed;
1842 *final_value_type = ValueObject::eInvalid;
1843 return ValueObjectSP();
1844 }
1845 else
1846 {
1847 *final_task_on_target = ValueObject::eNothing;
1848 return final_value;
1849 }
1850 }
1851 }
1852 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
1853}
1854
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001855int
1856ValueObject::GetValuesForExpressionPath(const char* expression,
1857 lldb::ValueObjectListSP& list,
1858 const char** first_unparsed,
1859 ExpressionPathScanEndReason* reason_to_stop,
1860 ExpressionPathEndResultType* final_value_type,
1861 const GetValueForExpressionPathOptions& options,
1862 ExpressionPathAftermath* final_task_on_target)
1863{
1864 const char* dummy_first_unparsed;
1865 ExpressionPathScanEndReason dummy_reason_to_stop;
1866 ExpressionPathEndResultType dummy_final_value_type;
1867 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
1868
1869 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
1870 first_unparsed ? first_unparsed : &dummy_first_unparsed,
1871 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
1872 final_value_type ? final_value_type : &dummy_final_value_type,
1873 options,
1874 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
1875
1876 if (!ret_val.get()) // if there are errors, I add nothing to the list
1877 return 0;
1878
1879 if (*reason_to_stop != eArrayRangeOperatorMet)
1880 {
1881 // I need not expand a range, just post-process the final value and return
1882 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
1883 {
1884 list->Append(ret_val);
1885 return 1;
1886 }
1887 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
1888 {
1889 if (*final_task_on_target == ValueObject::eDereference)
1890 {
1891 Error error;
1892 ValueObjectSP final_value = ret_val->Dereference(error);
1893 if (error.Fail() || !final_value.get())
1894 {
1895 *reason_to_stop = ValueObject::eDereferencingFailed;
1896 *final_value_type = ValueObject::eInvalid;
1897 return 0;
1898 }
1899 else
1900 {
1901 *final_task_on_target = ValueObject::eNothing;
1902 list->Append(final_value);
1903 return 1;
1904 }
1905 }
1906 if (*final_task_on_target == ValueObject::eTakeAddress)
1907 {
1908 Error error;
1909 ValueObjectSP final_value = ret_val->AddressOf(error);
1910 if (error.Fail() || !final_value.get())
1911 {
1912 *reason_to_stop = ValueObject::eTakingAddressFailed;
1913 *final_value_type = ValueObject::eInvalid;
1914 return 0;
1915 }
1916 else
1917 {
1918 *final_task_on_target = ValueObject::eNothing;
1919 list->Append(final_value);
1920 return 1;
1921 }
1922 }
1923 }
1924 }
1925 else
1926 {
1927 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
1928 first_unparsed ? first_unparsed : &dummy_first_unparsed,
1929 ret_val,
1930 list,
1931 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
1932 final_value_type ? final_value_type : &dummy_final_value_type,
1933 options,
1934 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
1935 }
1936 // in any non-covered case, just do the obviously right thing
1937 list->Append(ret_val);
1938 return 1;
1939}
1940
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001941lldb::ValueObjectSP
1942ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
1943 const char** first_unparsed,
1944 ExpressionPathScanEndReason* reason_to_stop,
1945 ExpressionPathEndResultType* final_result,
1946 const GetValueForExpressionPathOptions& options,
1947 ExpressionPathAftermath* what_next)
1948{
1949 ValueObjectSP root = GetSP();
1950
1951 if (!root.get())
1952 return ValueObjectSP();
1953
1954 *first_unparsed = expression_cstr;
1955
1956 while (true)
1957 {
1958
1959 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
1960
1961 lldb::clang_type_t root_clang_type = root->GetClangType();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001962 lldb::clang_type_t pointee_clang_type;
1963 Flags root_clang_type_info,pointee_clang_type_info;
1964
1965 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
1966 if (pointee_clang_type)
1967 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001968
1969 if (!expression_cstr || *expression_cstr == '\0')
1970 {
1971 *reason_to_stop = ValueObject::eEndOfString;
1972 return root;
1973 }
1974
1975 switch (*expression_cstr)
1976 {
1977 case '-':
1978 {
1979 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001980 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 +00001981 {
1982 *first_unparsed = expression_cstr;
1983 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
1984 *final_result = ValueObject::eInvalid;
1985 return ValueObjectSP();
1986 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001987 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
1988 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001989 options.m_no_fragile_ivar)
1990 {
1991 *first_unparsed = expression_cstr;
1992 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
1993 *final_result = ValueObject::eInvalid;
1994 return ValueObjectSP();
1995 }
1996 if (expression_cstr[1] != '>')
1997 {
1998 *first_unparsed = expression_cstr;
1999 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2000 *final_result = ValueObject::eInvalid;
2001 return ValueObjectSP();
2002 }
2003 expression_cstr++; // skip the -
2004 }
2005 case '.': // or fallthrough from ->
2006 {
2007 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002008 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 +00002009 {
2010 *first_unparsed = expression_cstr;
2011 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
2012 *final_result = ValueObject::eInvalid;
2013 return ValueObjectSP();
2014 }
2015 expression_cstr++; // skip .
2016 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2017 ConstString child_name;
2018 if (!next_separator) // if no other separator just expand this last layer
2019 {
2020 child_name.SetCString (expression_cstr);
2021 root = root->GetChildMemberWithName(child_name, true);
2022 if (root.get()) // we know we are done, so just return
2023 {
2024 *first_unparsed = '\0';
2025 *reason_to_stop = ValueObject::eEndOfString;
2026 *final_result = ValueObject::ePlain;
2027 return root;
2028 }
2029 else
2030 {
2031 *first_unparsed = expression_cstr;
2032 *reason_to_stop = ValueObject::eNoSuchChild;
2033 *final_result = ValueObject::eInvalid;
2034 return ValueObjectSP();
2035 }
2036 }
2037 else // other layers do expand
2038 {
2039 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
2040 root = root->GetChildMemberWithName(child_name, true);
2041 if (root.get()) // store the new root and move on
2042 {
2043 *first_unparsed = next_separator;
2044 *final_result = ValueObject::ePlain;
2045 continue;
2046 }
2047 else
2048 {
2049 *first_unparsed = expression_cstr;
2050 *reason_to_stop = ValueObject::eNoSuchChild;
2051 *final_result = ValueObject::eInvalid;
2052 return ValueObjectSP();
2053 }
2054 }
2055 break;
2056 }
2057 case '[':
2058 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002059 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 +00002060 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002061 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002062 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002063 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2064 {
2065 *first_unparsed = expression_cstr;
2066 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2067 *final_result = ValueObject::eInvalid;
2068 return ValueObjectSP();
2069 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002070 }
2071 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2072 {
2073 *first_unparsed = expression_cstr;
2074 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2075 *final_result = ValueObject::eInvalid;
2076 return ValueObjectSP();
2077 }
2078 }
2079 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2080 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002081 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002082 {
2083 *first_unparsed = expression_cstr;
2084 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2085 *final_result = ValueObject::eInvalid;
2086 return ValueObjectSP();
2087 }
2088 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2089 {
2090 *first_unparsed = expression_cstr+2;
2091 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2092 *final_result = ValueObject::eUnboundedRange;
2093 return root;
2094 }
2095 }
2096 const char *separator_position = ::strchr(expression_cstr+1,'-');
2097 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2098 if (!close_bracket_position) // if there is no ], this is a syntax error
2099 {
2100 *first_unparsed = expression_cstr;
2101 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2102 *final_result = ValueObject::eInvalid;
2103 return ValueObjectSP();
2104 }
2105 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2106 {
2107 char *end = NULL;
2108 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2109 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2110 {
2111 *first_unparsed = expression_cstr;
2112 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2113 *final_result = ValueObject::eInvalid;
2114 return ValueObjectSP();
2115 }
2116 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2117 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002118 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002119 {
2120 *first_unparsed = expression_cstr+2;
2121 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2122 *final_result = ValueObject::eUnboundedRange;
2123 return root;
2124 }
2125 else
2126 {
2127 *first_unparsed = expression_cstr;
2128 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2129 *final_result = ValueObject::eInvalid;
2130 return ValueObjectSP();
2131 }
2132 }
2133 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002134 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002135 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002136 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2137 if (!child_valobj_sp)
2138 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002139 if (!child_valobj_sp)
2140 if (root->HasSyntheticValue() && root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetNumChildren() > index)
2141 child_valobj_sp = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002142 if (child_valobj_sp)
2143 {
2144 root = child_valobj_sp;
2145 *first_unparsed = end+1; // skip ]
2146 *final_result = ValueObject::ePlain;
2147 continue;
2148 }
2149 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002150 {
2151 *first_unparsed = expression_cstr;
2152 *reason_to_stop = ValueObject::eNoSuchChild;
2153 *final_result = ValueObject::eInvalid;
2154 return ValueObjectSP();
2155 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002156 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002157 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002158 {
2159 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 +00002160 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002161 {
2162 Error error;
2163 root = root->Dereference(error);
2164 if (error.Fail() || !root.get())
2165 {
2166 *first_unparsed = expression_cstr;
2167 *reason_to_stop = ValueObject::eDereferencingFailed;
2168 *final_result = ValueObject::eInvalid;
2169 return ValueObjectSP();
2170 }
2171 else
2172 {
2173 *what_next = eNothing;
2174 continue;
2175 }
2176 }
2177 else
2178 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002179 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
2180 root->GetClangType()) == lldb::eLanguageTypeObjC
2181 &&
2182 ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2183 &&
2184 root->HasSyntheticValue()
2185 &&
2186 options.m_no_synthetic_children == false)
2187 {
2188 root = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildAtIndex(index, true);
2189 }
2190 else
2191 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002192 if (!root.get())
2193 {
2194 *first_unparsed = expression_cstr;
2195 *reason_to_stop = ValueObject::eNoSuchChild;
2196 *final_result = ValueObject::eInvalid;
2197 return ValueObjectSP();
2198 }
2199 else
2200 {
2201 *first_unparsed = end+1; // skip ]
2202 *final_result = ValueObject::ePlain;
2203 continue;
2204 }
2205 }
2206 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002207 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002208 {
2209 root = root->GetSyntheticBitFieldChild(index, index, true);
2210 if (!root.get())
2211 {
2212 *first_unparsed = expression_cstr;
2213 *reason_to_stop = ValueObject::eNoSuchChild;
2214 *final_result = ValueObject::eInvalid;
2215 return ValueObjectSP();
2216 }
2217 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2218 {
2219 *first_unparsed = end+1; // skip ]
2220 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2221 *final_result = ValueObject::eBitfield;
2222 return root;
2223 }
2224 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002225 else if (root->HasSyntheticValue() && options.m_no_synthetic_children)
2226 {
2227 root = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildAtIndex(index, true);
2228 if (!root.get())
2229 {
2230 *first_unparsed = expression_cstr;
2231 *reason_to_stop = ValueObject::eNoSuchChild;
2232 *final_result = ValueObject::eInvalid;
2233 return ValueObjectSP();
2234 }
2235 }
2236 else
2237 {
2238 *first_unparsed = expression_cstr;
2239 *reason_to_stop = ValueObject::eNoSuchChild;
2240 *final_result = ValueObject::eInvalid;
2241 return ValueObjectSP();
2242 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002243 }
2244 else // we have a low and a high index
2245 {
2246 char *end = NULL;
2247 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2248 if (!end || end != separator_position) // if something weird is in our way return an error
2249 {
2250 *first_unparsed = expression_cstr;
2251 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2252 *final_result = ValueObject::eInvalid;
2253 return ValueObjectSP();
2254 }
2255 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2256 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2257 {
2258 *first_unparsed = expression_cstr;
2259 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2260 *final_result = ValueObject::eInvalid;
2261 return ValueObjectSP();
2262 }
2263 if (index_lower > index_higher) // swap indices if required
2264 {
2265 unsigned long temp = index_lower;
2266 index_lower = index_higher;
2267 index_higher = temp;
2268 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002269 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002270 {
2271 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2272 if (!root.get())
2273 {
2274 *first_unparsed = expression_cstr;
2275 *reason_to_stop = ValueObject::eNoSuchChild;
2276 *final_result = ValueObject::eInvalid;
2277 return ValueObjectSP();
2278 }
2279 else
2280 {
2281 *first_unparsed = end+1; // skip ]
2282 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2283 *final_result = ValueObject::eBitfield;
2284 return root;
2285 }
2286 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002287 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 +00002288 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002289 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002290 {
2291 Error error;
2292 root = root->Dereference(error);
2293 if (error.Fail() || !root.get())
2294 {
2295 *first_unparsed = expression_cstr;
2296 *reason_to_stop = ValueObject::eDereferencingFailed;
2297 *final_result = ValueObject::eInvalid;
2298 return ValueObjectSP();
2299 }
2300 else
2301 {
2302 *what_next = ValueObject::eNothing;
2303 continue;
2304 }
2305 }
2306 else
2307 {
2308 *first_unparsed = expression_cstr;
2309 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2310 *final_result = ValueObject::eBoundedRange;
2311 return root;
2312 }
2313 }
2314 break;
2315 }
2316 default: // some non-separator is in the way
2317 {
2318 *first_unparsed = expression_cstr;
2319 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2320 *final_result = ValueObject::eInvalid;
2321 return ValueObjectSP();
2322 break;
2323 }
2324 }
2325 }
2326}
2327
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002328int
2329ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2330 const char** first_unparsed,
2331 lldb::ValueObjectSP root,
2332 lldb::ValueObjectListSP& list,
2333 ExpressionPathScanEndReason* reason_to_stop,
2334 ExpressionPathEndResultType* final_result,
2335 const GetValueForExpressionPathOptions& options,
2336 ExpressionPathAftermath* what_next)
2337{
2338 if (!root.get())
2339 return 0;
2340
2341 *first_unparsed = expression_cstr;
2342
2343 while (true)
2344 {
2345
2346 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2347
2348 lldb::clang_type_t root_clang_type = root->GetClangType();
2349 lldb::clang_type_t pointee_clang_type;
2350 Flags root_clang_type_info,pointee_clang_type_info;
2351
2352 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2353 if (pointee_clang_type)
2354 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2355
2356 if (!expression_cstr || *expression_cstr == '\0')
2357 {
2358 *reason_to_stop = ValueObject::eEndOfString;
2359 list->Append(root);
2360 return 1;
2361 }
2362
2363 switch (*expression_cstr)
2364 {
2365 case '[':
2366 {
2367 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2368 {
2369 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2370 {
2371 *first_unparsed = expression_cstr;
2372 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2373 *final_result = ValueObject::eInvalid;
2374 return 0;
2375 }
2376 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2377 {
2378 *first_unparsed = expression_cstr;
2379 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2380 *final_result = ValueObject::eInvalid;
2381 return 0;
2382 }
2383 }
2384 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2385 {
2386 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2387 {
2388 *first_unparsed = expression_cstr;
2389 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2390 *final_result = ValueObject::eInvalid;
2391 return 0;
2392 }
2393 else // expand this into list
2394 {
2395 int max_index = root->GetNumChildren() - 1;
2396 for (int index = 0; index < max_index; index++)
2397 {
2398 ValueObjectSP child =
2399 root->GetChildAtIndex(index, true);
2400 list->Append(child);
2401 }
2402 *first_unparsed = expression_cstr+2;
2403 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2404 *final_result = ValueObject::eValueObjectList;
2405 return max_index; // tell me number of items I added to the VOList
2406 }
2407 }
2408 const char *separator_position = ::strchr(expression_cstr+1,'-');
2409 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2410 if (!close_bracket_position) // if there is no ], this is a syntax error
2411 {
2412 *first_unparsed = expression_cstr;
2413 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2414 *final_result = ValueObject::eInvalid;
2415 return 0;
2416 }
2417 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2418 {
2419 char *end = NULL;
2420 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2421 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2422 {
2423 *first_unparsed = expression_cstr;
2424 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2425 *final_result = ValueObject::eInvalid;
2426 return 0;
2427 }
2428 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2429 {
2430 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2431 {
2432 int max_index = root->GetNumChildren() - 1;
2433 for (int index = 0; index < max_index; index++)
2434 {
2435 ValueObjectSP child =
2436 root->GetChildAtIndex(index, true);
2437 list->Append(child);
2438 }
2439 *first_unparsed = expression_cstr+2;
2440 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2441 *final_result = ValueObject::eValueObjectList;
2442 return max_index; // tell me number of items I added to the VOList
2443 }
2444 else
2445 {
2446 *first_unparsed = expression_cstr;
2447 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2448 *final_result = ValueObject::eInvalid;
2449 return 0;
2450 }
2451 }
2452 // from here on we do have a valid index
2453 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2454 {
2455 root = root->GetChildAtIndex(index, true);
2456 if (!root.get())
2457 {
2458 *first_unparsed = expression_cstr;
2459 *reason_to_stop = ValueObject::eNoSuchChild;
2460 *final_result = ValueObject::eInvalid;
2461 return 0;
2462 }
2463 else
2464 {
2465 list->Append(root);
2466 *first_unparsed = end+1; // skip ]
2467 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2468 *final_result = ValueObject::eValueObjectList;
2469 return 1;
2470 }
2471 }
2472 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2473 {
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
2475 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2476 {
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 0;
2485 }
2486 else
2487 {
2488 *what_next = eNothing;
2489 continue;
2490 }
2491 }
2492 else
2493 {
2494 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2495 if (!root.get())
2496 {
2497 *first_unparsed = expression_cstr;
2498 *reason_to_stop = ValueObject::eNoSuchChild;
2499 *final_result = ValueObject::eInvalid;
2500 return 0;
2501 }
2502 else
2503 {
2504 list->Append(root);
2505 *first_unparsed = end+1; // skip ]
2506 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2507 *final_result = ValueObject::eValueObjectList;
2508 return 1;
2509 }
2510 }
2511 }
2512 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2513 {
2514 root = root->GetSyntheticBitFieldChild(index, index, true);
2515 if (!root.get())
2516 {
2517 *first_unparsed = expression_cstr;
2518 *reason_to_stop = ValueObject::eNoSuchChild;
2519 *final_result = ValueObject::eInvalid;
2520 return 0;
2521 }
2522 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2523 {
2524 list->Append(root);
2525 *first_unparsed = end+1; // skip ]
2526 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2527 *final_result = ValueObject::eValueObjectList;
2528 return 1;
2529 }
2530 }
2531 }
2532 else // we have a low and a high index
2533 {
2534 char *end = NULL;
2535 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2536 if (!end || end != separator_position) // if something weird is in our way return an error
2537 {
2538 *first_unparsed = expression_cstr;
2539 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2540 *final_result = ValueObject::eInvalid;
2541 return 0;
2542 }
2543 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2544 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2545 {
2546 *first_unparsed = expression_cstr;
2547 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2548 *final_result = ValueObject::eInvalid;
2549 return 0;
2550 }
2551 if (index_lower > index_higher) // swap indices if required
2552 {
2553 unsigned long temp = index_lower;
2554 index_lower = index_higher;
2555 index_higher = temp;
2556 }
2557 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
2558 {
2559 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2560 if (!root.get())
2561 {
2562 *first_unparsed = expression_cstr;
2563 *reason_to_stop = ValueObject::eNoSuchChild;
2564 *final_result = ValueObject::eInvalid;
2565 return 0;
2566 }
2567 else
2568 {
2569 list->Append(root);
2570 *first_unparsed = end+1; // skip ]
2571 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2572 *final_result = ValueObject::eValueObjectList;
2573 return 1;
2574 }
2575 }
2576 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
2577 *what_next == ValueObject::eDereference &&
2578 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2579 {
2580 Error error;
2581 root = root->Dereference(error);
2582 if (error.Fail() || !root.get())
2583 {
2584 *first_unparsed = expression_cstr;
2585 *reason_to_stop = ValueObject::eDereferencingFailed;
2586 *final_result = ValueObject::eInvalid;
2587 return 0;
2588 }
2589 else
2590 {
2591 *what_next = ValueObject::eNothing;
2592 continue;
2593 }
2594 }
2595 else
2596 {
Johnny Chen44805302011-07-19 19:48:13 +00002597 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002598 index <= index_higher; index++)
2599 {
2600 ValueObjectSP child =
2601 root->GetChildAtIndex(index, true);
2602 list->Append(child);
2603 }
2604 *first_unparsed = end+1;
2605 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2606 *final_result = ValueObject::eValueObjectList;
2607 return index_higher-index_lower+1; // tell me number of items I added to the VOList
2608 }
2609 }
2610 break;
2611 }
2612 default: // some non-[ separator, or something entirely wrong, is in the way
2613 {
2614 *first_unparsed = expression_cstr;
2615 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2616 *final_result = ValueObject::eInvalid;
2617 return 0;
2618 break;
2619 }
2620 }
2621 }
2622}
2623
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002624void
Greg Clayton1d3afba2010-10-05 00:00:42 +00002625ValueObject::DumpValueObject
2626(
2627 Stream &s,
Greg Clayton1d3afba2010-10-05 00:00:42 +00002628 ValueObject *valobj,
2629 const char *root_valobj_name,
2630 uint32_t ptr_depth,
2631 uint32_t curr_depth,
2632 uint32_t max_depth,
2633 bool show_types,
2634 bool show_location,
2635 bool use_objc,
Jim Ingham2837b762011-05-04 03:43:18 +00002636 lldb::DynamicValueType use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00002637 bool use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002638 bool scope_already_checked,
Enrico Granata0c5ef692011-07-16 01:22:04 +00002639 bool flat_output,
2640 uint32_t omit_summary_depth
Greg Clayton1d3afba2010-10-05 00:00:42 +00002641)
2642{
Greg Clayton007d5be2011-05-30 00:49:24 +00002643 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002644 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00002645 bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00002646
2647 if (update_success && use_dynamic != lldb::eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00002648 {
Jim Ingham2837b762011-05-04 03:43:18 +00002649 ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00002650 if (dynamic_value)
2651 valobj = dynamic_value;
2652 }
2653
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002654 clang_type_t clang_type = valobj->GetClangType();
2655
Greg Clayton73b472d2010-10-27 03:32:59 +00002656 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002657 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00002658 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
2659 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002660
2661 const bool print_valobj = flat_output == false || has_value;
2662
2663 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002664 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002665 if (show_location)
2666 {
Jim Ingham6035b672011-03-31 00:19:25 +00002667 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002668 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002669
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002670 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00002671
Greg Clayton7c8a9662010-11-02 01:50:16 +00002672 // Always show the type for the top level items.
Greg Claytone221f822011-01-21 01:59:00 +00002673 if (show_types || (curr_depth == 0 && !flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00002674 {
Enrico Granata9910bc82011-08-03 02:18:51 +00002675 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
2676 s.Printf("(%s", typeName);
2677 // only show dynamic types if the user really wants to see types
2678 if (show_types && use_dynamic != lldb::eNoDynamicValues &&
2679 (/*strstr(typeName, "id") == typeName ||*/
2680 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == lldb::eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00002681 {
2682 Process* process = valobj->GetUpdatePoint().GetProcessSP().get();
2683 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00002684 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002685 else
2686 {
2687 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
2688 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00002689 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002690 else
2691 {
2692 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
2693 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00002694 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002695 else
2696 s.Printf(", dynamic type: %s) ",
2697 runtime->GetActualTypeName(isa).GetCString());
2698 }
2699 }
2700 }
2701 else
2702 s.Printf(") ");
2703 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002704
Greg Clayton1d3afba2010-10-05 00:00:42 +00002705
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002706 if (flat_output)
2707 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00002708 // If we are showing types, also qualify the C++ base classes
2709 const bool qualify_cxx_base_classes = show_types;
2710 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002711 s.PutCString(" =");
2712 }
2713 else
2714 {
2715 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
2716 s.Printf ("%s =", name_cstr);
2717 }
2718
Jim Ingham6035b672011-03-31 00:19:25 +00002719 if (!scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002720 {
Greg Clayton007d5be2011-05-30 00:49:24 +00002721 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002722 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002723 }
2724
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002725 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00002726 const char *sum_cstr = NULL;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002727 SummaryFormat* entry = valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002728
Enrico Granata0c5ef692011-07-16 01:22:04 +00002729 if (omit_summary_depth > 0)
2730 entry = NULL;
2731
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002732 if (err_cstr == NULL)
2733 {
Jim Ingham6035b672011-03-31 00:19:25 +00002734 val_cstr = valobj->GetValueAsCString();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002735 err_cstr = valobj->GetError().AsCString();
2736 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002737
2738 if (err_cstr)
2739 {
Greg Clayton007d5be2011-05-30 00:49:24 +00002740 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00002741 }
2742 else
2743 {
Greg Clayton73b472d2010-10-27 03:32:59 +00002744 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002745 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002746 {
Enrico Granata4becb372011-06-29 22:27:15 +00002747
Enrico Granata0c5ef692011-07-16 01:22:04 +00002748 sum_cstr = (omit_summary_depth == 0) ? valobj->GetSummaryAsCString() : NULL;
Greg Clayton1d3afba2010-10-05 00:00:42 +00002749
Enrico Granata4becb372011-06-29 22:27:15 +00002750 // We must calculate this value in realtime because entry might alter this variable's value
2751 // (e.g. by saying ${var%fmt}) and render precached values useless
2752 if (val_cstr && (!entry || entry->DoesPrintValue() || !sum_cstr))
2753 s.Printf(" %s", valobj->GetValueAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002754
Enrico Granata9dd75c82011-07-15 23:30:15 +00002755 if (sum_cstr)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002756 {
2757 // for some reason, using %@ (ObjC description) in a summary string, makes
2758 // us believe we need to reset ourselves, thus invalidating the content of
2759 // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty
2760 // let us recalculate it!
2761 if (sum_cstr[0] == '\0')
2762 s.Printf(" %s", valobj->GetSummaryAsCString());
2763 else
2764 s.Printf(" %s", sum_cstr);
2765 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002766
2767 if (use_objc)
2768 {
Jim Ingham6035b672011-03-31 00:19:25 +00002769 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002770 if (object_desc)
2771 s.Printf(" %s\n", object_desc);
2772 else
Sean Callanan672ad942010-10-23 00:18:49 +00002773 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002774 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00002775 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002776 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002777
2778 if (curr_depth < max_depth)
2779 {
Greg Clayton73b472d2010-10-27 03:32:59 +00002780 // We will show children for all concrete types. We won't show
2781 // pointer contents unless a pointer depth has been specified.
2782 // We won't reference contents unless the reference is the
2783 // root object (depth of zero).
2784 bool print_children = true;
2785
2786 // Use a new temporary pointer depth in case we override the
2787 // current pointer depth below...
2788 uint32_t curr_ptr_depth = ptr_depth;
2789
2790 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
2791 if (is_ptr || is_ref)
2792 {
2793 // We have a pointer or reference whose value is an address.
2794 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00002795 AddressType ptr_address_type;
Greg Clayton73b472d2010-10-27 03:32:59 +00002796 if (valobj->GetPointerValue (ptr_address_type, true) == 0)
2797 print_children = false;
2798
2799 else if (is_ref && curr_depth == 0)
2800 {
2801 // If this is the root object (depth is zero) that we are showing
2802 // and it is a reference, and no pointer depth has been supplied
2803 // print out what it references. Don't do this at deeper depths
2804 // otherwise we can end up with infinite recursion...
2805 curr_ptr_depth = 1;
2806 }
2807
2808 if (curr_ptr_depth == 0)
2809 print_children = false;
2810 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002811
Enrico Granata0a3958e2011-07-02 00:25:22 +00002812 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00002813 {
Enrico Granatad55546b2011-07-22 00:16:08 +00002814 ValueObjectSP synth_vobj = valobj->GetSyntheticValue(use_synth ?
2815 lldb::eUseSyntheticFilter :
2816 lldb::eNoSyntheticFilter);
2817 const uint32_t num_children = synth_vobj->GetNumChildren();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002818 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002819 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002820 if (flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002821 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002822 if (print_valobj)
2823 s.EOL();
2824 }
2825 else
2826 {
2827 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00002828 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002829 s.IndentMore();
2830 }
2831
2832 for (uint32_t idx=0; idx<num_children; ++idx)
2833 {
Enrico Granatad55546b2011-07-22 00:16:08 +00002834 ValueObjectSP child_sp(synth_vobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002835 if (child_sp.get())
2836 {
2837 DumpValueObject (s,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002838 child_sp.get(),
2839 NULL,
Greg Clayton73b472d2010-10-27 03:32:59 +00002840 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002841 curr_depth + 1,
2842 max_depth,
2843 show_types,
2844 show_location,
2845 false,
Jim Ingham78a685a2011-04-16 00:01:13 +00002846 use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00002847 use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002848 true,
Enrico Granata0c5ef692011-07-16 01:22:04 +00002849 flat_output,
2850 omit_summary_depth > 1 ? omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002851 }
2852 }
2853
2854 if (!flat_output)
2855 {
2856 s.IndentLess();
2857 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00002858 }
2859 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002860 else if (has_children)
2861 {
2862 // Aggregate, no children...
2863 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00002864 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002865 }
2866 else
2867 {
2868 if (print_valobj)
2869 s.EOL();
2870 }
2871
Greg Clayton1d3afba2010-10-05 00:00:42 +00002872 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002873 else
2874 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00002875 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00002876 }
2877 }
2878 else
2879 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002880 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002881 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002882 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00002883 }
2884 }
2885 }
2886 }
2887}
2888
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002889
2890ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00002891ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002892{
2893 ValueObjectSP valobj_sp;
2894
Enrico Granatac3e320a2011-08-02 17:27:39 +00002895 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002896 {
Jim Ingham6035b672011-03-31 00:19:25 +00002897 ExecutionContextScope *exe_scope = GetExecutionContextScope();
2898 if (exe_scope)
2899 {
2900 ExecutionContext exe_ctx;
2901 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002902
Jim Ingham6035b672011-03-31 00:19:25 +00002903 clang::ASTContext *ast = GetClangAST ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002904
Jim Ingham6035b672011-03-31 00:19:25 +00002905 DataExtractor data;
2906 data.SetByteOrder (m_data.GetByteOrder());
2907 data.SetAddressByteSize(m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002908
Greg Clayton644247c2011-07-07 01:59:51 +00002909 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002910
Jim Ingham58b59f92011-04-22 23:53:53 +00002911 valobj_sp = ValueObjectConstResult::Create (exe_scope,
2912 ast,
2913 GetClangType(),
2914 name,
2915 data);
Jim Ingham6035b672011-03-31 00:19:25 +00002916 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002917 }
Jim Ingham6035b672011-03-31 00:19:25 +00002918
2919 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002920 {
Jim Ingham58b59f92011-04-22 23:53:53 +00002921 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002922 }
2923 return valobj_sp;
2924}
2925
2926lldb::ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00002927ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002928{
Jim Ingham58b59f92011-04-22 23:53:53 +00002929 if (m_deref_valobj)
2930 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00002931
Greg Clayton54979cd2010-12-15 05:08:08 +00002932 const bool is_pointer_type = IsPointerType();
2933 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002934 {
2935 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00002936 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002937
2938 std::string child_name_str;
2939 uint32_t child_byte_size = 0;
2940 int32_t child_byte_offset = 0;
2941 uint32_t child_bitfield_bit_size = 0;
2942 uint32_t child_bitfield_bit_offset = 0;
2943 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00002944 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002945 const bool transparent_pointers = false;
2946 clang::ASTContext *clang_ast = GetClangAST();
2947 clang_type_t clang_type = GetClangType();
2948 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00002949
2950 ExecutionContext exe_ctx;
2951 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
2952
2953 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
2954 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002955 GetName().GetCString(),
2956 clang_type,
2957 0,
2958 transparent_pointers,
2959 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00002960 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002961 child_name_str,
2962 child_byte_size,
2963 child_byte_offset,
2964 child_bitfield_bit_size,
2965 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00002966 child_is_base_class,
2967 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00002968 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002969 {
2970 ConstString child_name;
2971 if (!child_name_str.empty())
2972 child_name.SetCString (child_name_str.c_str());
2973
Jim Ingham58b59f92011-04-22 23:53:53 +00002974 m_deref_valobj = new ValueObjectChild (*this,
2975 clang_ast,
2976 child_clang_type,
2977 child_name,
2978 child_byte_size,
2979 child_byte_offset,
2980 child_bitfield_bit_size,
2981 child_bitfield_bit_offset,
2982 child_is_base_class,
2983 child_is_deref_of_parent);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002984 }
2985 }
Greg Clayton54979cd2010-12-15 05:08:08 +00002986
Jim Ingham58b59f92011-04-22 23:53:53 +00002987 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00002988 {
2989 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00002990 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00002991 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002992 else
2993 {
Greg Clayton54979cd2010-12-15 05:08:08 +00002994 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00002995 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00002996
2997 if (is_pointer_type)
2998 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
2999 else
3000 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003001 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003002 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003003}
3004
Jim Ingham78a685a2011-04-16 00:01:13 +00003005lldb::ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003006ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003007{
Jim Ingham78a685a2011-04-16 00:01:13 +00003008 if (m_addr_of_valobj_sp)
3009 return m_addr_of_valobj_sp;
3010
Greg Claytone0d378b2011-03-24 21:19:54 +00003011 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003012 const bool scalar_is_load_address = false;
3013 lldb::addr_t addr = GetAddressOf (address_type, scalar_is_load_address);
Greg Clayton54979cd2010-12-15 05:08:08 +00003014 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003015 if (addr != LLDB_INVALID_ADDRESS)
3016 {
3017 switch (address_type)
3018 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003019 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003020 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003021 {
3022 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003023 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003024 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3025 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003026 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003027
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003028 case eAddressTypeFile:
3029 case eAddressTypeLoad:
3030 case eAddressTypeHost:
3031 {
3032 clang::ASTContext *ast = GetClangAST();
3033 clang_type_t clang_type = GetClangType();
3034 if (ast && clang_type)
3035 {
3036 std::string name (1, '&');
3037 name.append (m_name.AsCString(""));
Jim Ingham58b59f92011-04-22 23:53:53 +00003038 m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(),
3039 ast,
3040 ClangASTContext::CreatePointerType (ast, clang_type),
3041 ConstString (name.c_str()),
3042 addr,
3043 eAddressTypeInvalid,
3044 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003045 }
3046 }
3047 break;
3048 }
3049 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003050 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003051}
3052
Greg Claytonb2dcc362011-05-05 23:32:56 +00003053
3054lldb::ValueObjectSP
3055ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3056{
3057 lldb::ValueObjectSP valobj_sp;
3058 AddressType address_type;
3059 const bool scalar_is_load_address = true;
3060 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address);
3061
3062 if (ptr_value != LLDB_INVALID_ADDRESS)
3063 {
3064 Address ptr_addr (NULL, ptr_value);
3065
3066 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3067 name,
3068 ptr_addr,
3069 clang_ast_type);
3070 }
3071 return valobj_sp;
3072}
3073
3074lldb::ValueObjectSP
3075ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3076{
3077 lldb::ValueObjectSP valobj_sp;
3078 AddressType address_type;
3079 const bool scalar_is_load_address = true;
3080 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address);
3081
3082 if (ptr_value != LLDB_INVALID_ADDRESS)
3083 {
3084 Address ptr_addr (NULL, ptr_value);
3085
3086 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3087 name,
3088 ptr_addr,
3089 type_sp);
3090 }
3091 return valobj_sp;
3092}
3093
Jim Ingham6035b672011-03-31 00:19:25 +00003094ValueObject::EvaluationPoint::EvaluationPoint () :
Stephen Wilson71c21d12011-04-11 19:41:40 +00003095 m_thread_id (LLDB_INVALID_UID),
3096 m_stop_id (0)
Jim Ingham6035b672011-03-31 00:19:25 +00003097{
3098}
3099
3100ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Jim Ingham6035b672011-03-31 00:19:25 +00003101 m_needs_update (true),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003102 m_first_update (true),
Jim Ingham89b61092011-07-06 17:42:14 +00003103 m_thread_id (LLDB_INVALID_THREAD_ID),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003104 m_stop_id (0)
3105
Jim Ingham6035b672011-03-31 00:19:25 +00003106{
3107 ExecutionContext exe_ctx;
3108 ExecutionContextScope *computed_exe_scope = exe_scope; // If use_selected is true, we may find a better scope,
3109 // and if so we want to cache that not the original.
3110 if (exe_scope)
3111 exe_scope->CalculateExecutionContext(exe_ctx);
3112 if (exe_ctx.target != NULL)
3113 {
3114 m_target_sp = exe_ctx.target->GetSP();
3115
3116 if (exe_ctx.process == NULL)
3117 m_process_sp = exe_ctx.target->GetProcessSP();
3118 else
3119 m_process_sp = exe_ctx.process->GetSP();
3120
3121 if (m_process_sp != NULL)
3122 {
3123 m_stop_id = m_process_sp->GetStopID();
3124 Thread *thread = NULL;
3125
3126 if (exe_ctx.thread == NULL)
3127 {
3128 if (use_selected)
3129 {
3130 thread = m_process_sp->GetThreadList().GetSelectedThread().get();
3131 if (thread)
3132 computed_exe_scope = thread;
3133 }
3134 }
3135 else
3136 thread = exe_ctx.thread;
3137
3138 if (thread != NULL)
3139 {
3140 m_thread_id = thread->GetIndexID();
3141 if (exe_ctx.frame == NULL)
3142 {
3143 if (use_selected)
3144 {
3145 StackFrame *frame = exe_ctx.thread->GetSelectedFrame().get();
3146 if (frame)
3147 {
3148 m_stack_id = frame->GetStackID();
3149 computed_exe_scope = frame;
3150 }
3151 }
3152 }
3153 else
3154 m_stack_id = exe_ctx.frame->GetStackID();
3155 }
3156 }
3157 }
3158 m_exe_scope = computed_exe_scope;
3159}
3160
3161ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
3162 m_exe_scope (rhs.m_exe_scope),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003163 m_needs_update(true),
3164 m_first_update(true),
Jim Ingham6035b672011-03-31 00:19:25 +00003165 m_target_sp (rhs.m_target_sp),
3166 m_process_sp (rhs.m_process_sp),
3167 m_thread_id (rhs.m_thread_id),
3168 m_stack_id (rhs.m_stack_id),
Jim Ingham6035b672011-03-31 00:19:25 +00003169 m_stop_id (0)
3170{
3171}
3172
3173ValueObject::EvaluationPoint::~EvaluationPoint ()
3174{
3175}
3176
3177ExecutionContextScope *
3178ValueObject::EvaluationPoint::GetExecutionContextScope ()
3179{
3180 // We have to update before giving out the scope, or we could be handing out stale pointers.
3181 SyncWithProcessState();
3182
3183 return m_exe_scope;
3184}
3185
3186// This function checks the EvaluationPoint against the current process state. If the current
3187// state matches the evaluation point, or the evaluation point is already invalid, then we return
3188// false, meaning "no change". If the current state is different, we update our state, and return
3189// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3190// future calls to NeedsUpdate will return true.
3191
3192bool
3193ValueObject::EvaluationPoint::SyncWithProcessState()
3194{
3195 // If we're already invalid, we don't need to do anything, and nothing has changed:
3196 if (m_stop_id == LLDB_INVALID_UID)
3197 {
3198 // Can't update with an invalid state.
3199 m_needs_update = false;
3200 return false;
3201 }
3202
3203 // If we don't have a process nothing can change.
3204 if (!m_process_sp)
3205 return false;
3206
3207 // If our stop id is the current stop ID, nothing has changed:
Jim Ingham78a685a2011-04-16 00:01:13 +00003208 uint32_t cur_stop_id = m_process_sp->GetStopID();
3209 if (m_stop_id == cur_stop_id)
Jim Ingham6035b672011-03-31 00:19:25 +00003210 return false;
3211
Jim Ingham78a685a2011-04-16 00:01:13 +00003212 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3213 // In either case, we aren't going to be able to sync with the process state.
3214 if (cur_stop_id == 0)
3215 return false;
3216
3217 m_stop_id = cur_stop_id;
Jim Ingham6035b672011-03-31 00:19:25 +00003218 m_needs_update = true;
3219 m_exe_scope = m_process_sp.get();
3220
3221 // Something has changed, so we will return true. Now make sure the thread & frame still exist, and if either
3222 // doesn't, mark ourselves as invalid.
3223
3224 if (m_thread_id != LLDB_INVALID_THREAD_ID)
3225 {
3226 Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get();
3227 if (our_thread == NULL)
Greg Clayton262f80d2011-07-06 16:49:27 +00003228 {
Jim Ingham89b61092011-07-06 17:42:14 +00003229 SetInvalid();
Greg Clayton262f80d2011-07-06 16:49:27 +00003230 }
Jim Ingham6035b672011-03-31 00:19:25 +00003231 else
3232 {
3233 m_exe_scope = our_thread;
3234
3235 if (m_stack_id.IsValid())
3236 {
3237 StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get();
3238 if (our_frame == NULL)
3239 SetInvalid();
3240 else
3241 m_exe_scope = our_frame;
3242 }
3243 }
3244 }
3245 return true;
3246}
3247
Jim Ingham61be0902011-05-02 18:13:59 +00003248void
3249ValueObject::EvaluationPoint::SetUpdated ()
3250{
3251 m_first_update = false;
3252 m_needs_update = false;
3253 if (m_process_sp)
3254 m_stop_id = m_process_sp->GetStopID();
3255}
3256
3257
Jim Ingham6035b672011-03-31 00:19:25 +00003258bool
3259ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3260{
3261 if (!IsValid())
3262 return false;
3263
3264 bool needs_update = false;
3265 m_exe_scope = NULL;
3266
3267 // The target has to be non-null, and the
3268 Target *target = exe_scope->CalculateTarget();
3269 if (target != NULL)
3270 {
3271 Target *old_target = m_target_sp.get();
3272 assert (target == old_target);
3273 Process *process = exe_scope->CalculateProcess();
3274 if (process != NULL)
3275 {
3276 // FOR NOW - assume you can't update variable objects across process boundaries.
3277 Process *old_process = m_process_sp.get();
3278 assert (process == old_process);
3279
3280 lldb::user_id_t stop_id = process->GetStopID();
3281 if (stop_id != m_stop_id)
3282 {
3283 needs_update = true;
3284 m_stop_id = stop_id;
3285 }
3286 // See if we're switching the thread or stack context. If no thread is given, this is
3287 // being evaluated in a global context.
3288 Thread *thread = exe_scope->CalculateThread();
3289 if (thread != NULL)
3290 {
3291 lldb::user_id_t new_thread_index = thread->GetIndexID();
3292 if (new_thread_index != m_thread_id)
3293 {
3294 needs_update = true;
3295 m_thread_id = new_thread_index;
3296 m_stack_id.Clear();
3297 }
3298
3299 StackFrame *new_frame = exe_scope->CalculateStackFrame();
3300 if (new_frame != NULL)
3301 {
3302 if (new_frame->GetStackID() != m_stack_id)
3303 {
3304 needs_update = true;
3305 m_stack_id = new_frame->GetStackID();
3306 }
3307 }
3308 else
3309 {
3310 m_stack_id.Clear();
3311 needs_update = true;
3312 }
3313 }
3314 else
3315 {
3316 // If this had been given a thread, and now there is none, we should update.
3317 // Otherwise we don't have to do anything.
3318 if (m_thread_id != LLDB_INVALID_UID)
3319 {
3320 m_thread_id = LLDB_INVALID_UID;
3321 m_stack_id.Clear();
3322 needs_update = true;
3323 }
3324 }
3325 }
3326 else
3327 {
3328 // If there is no process, then we don't need to update anything.
3329 // But if we're switching from having a process to not, we should try to update.
3330 if (m_process_sp.get() != NULL)
3331 {
3332 needs_update = true;
3333 m_process_sp.reset();
3334 m_thread_id = LLDB_INVALID_UID;
3335 m_stack_id.Clear();
3336 }
3337 }
3338 }
3339 else
3340 {
3341 // If there's no target, nothing can change so we don't need to update anything.
3342 // But if we're switching from having a target to not, we should try to update.
3343 if (m_target_sp.get() != NULL)
3344 {
3345 needs_update = true;
3346 m_target_sp.reset();
3347 m_process_sp.reset();
3348 m_thread_id = LLDB_INVALID_UID;
3349 m_stack_id.Clear();
3350 }
3351 }
3352 if (!m_needs_update)
3353 m_needs_update = needs_update;
3354
3355 return needs_update;
3356}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003357
3358void
3359ValueObject::ClearUserVisibleData()
3360{
3361 m_location_str.clear();
3362 m_value_str.clear();
3363 m_summary_str.clear();
3364 m_object_desc_str.clear();
Johnny Chen44805302011-07-19 19:48:13 +00003365}