blob: fce00f6d4f39468735a0d5b7a50b59e060bc4381 [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 Granatae992a082011-07-22 17:03:19 +0000944// this call should only return pointers to data that needs no special memory management
945// (either because they are hardcoded strings, or because they are backed by some other
946// object); returning any new()-ed or malloc()-ed data here, will lead to leaks!
Enrico Granata0a3958e2011-07-02 00:25:22 +0000947const char *
948ValueObject::GetPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
949 lldb::Format custom_format)
950{
Enrico Granataf4efecd2011-07-12 22:56:10 +0000951
952 RefCounter ref(&m_dump_printable_counter);
953
Enrico Granata9dd75c82011-07-15 23:30:15 +0000954 if (custom_format != lldb::eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +0000955 SetFormat(custom_format);
956
957 const char * return_value;
958
959 switch(val_obj_display)
960 {
961 case eDisplayValue:
962 return_value = GetValueAsCString();
963 break;
964 case eDisplaySummary:
965 return_value = GetSummaryAsCString();
966 break;
967 case eDisplayLanguageSpecific:
968 return_value = GetObjectDescription();
969 break;
Enrico Granataf2bbf712011-07-15 02:26:42 +0000970 case eDisplayLocation:
971 return_value = GetLocationAsCString();
972 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000973 }
974
Enrico Granataf4efecd2011-07-12 22:56:10 +0000975 // this code snippet might lead to endless recursion, thus we use a RefCounter here to
976 // check that we are not looping endlessly
977 if (!return_value && (m_dump_printable_counter < 3))
Enrico Granata9fc19442011-07-06 02:13:41 +0000978 {
979 // try to pick the other choice
980 if (val_obj_display == eDisplayValue)
981 return_value = GetSummaryAsCString();
982 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +0000983 {
984 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
985 {
986 // this thing has no value
987 return_value = "<no summary defined for this datatype>";
988 }
989 else
990 return_value = GetValueAsCString();
991 }
Enrico Granata9fc19442011-07-06 02:13:41 +0000992 }
Enrico Granata0a3958e2011-07-02 00:25:22 +0000993
Enrico Granatae992a082011-07-22 17:03:19 +0000994 return (return_value ? return_value : "<no printable representation>");
Enrico Granata0a3958e2011-07-02 00:25:22 +0000995
996}
997
Enrico Granata9fc19442011-07-06 02:13:41 +0000998bool
999ValueObject::DumpPrintableRepresentation(Stream& s,
1000 ValueObjectRepresentationStyle val_obj_display,
1001 lldb::Format custom_format)
1002{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001003
1004 clang_type_t elem_or_pointee_type;
1005 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001006
Enrico Granataf4efecd2011-07-12 22:56:10 +00001007 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1008 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001009 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001010 // when being asked to get a printable display an array or pointer type directly,
1011 // try to "do the right thing"
1012
1013 if (IsCStringContainer(true) &&
1014 (custom_format == lldb::eFormatCString ||
1015 custom_format == lldb::eFormatCharArray ||
1016 custom_format == lldb::eFormatChar ||
1017 custom_format == lldb::eFormatVectorOfChar)) // print char[] & char* directly
1018 {
1019 Error error;
1020 ReadPointedString(s,
1021 error,
1022 0,
1023 (custom_format == lldb::eFormatVectorOfChar) ||
1024 (custom_format == lldb::eFormatCharArray));
1025 return !error.Fail();
1026 }
1027
1028 if (custom_format == lldb::eFormatEnum)
1029 return false;
1030
1031 // this only works for arrays, because I have no way to know when
1032 // the pointed memory ends, and no special \0 end of data marker
1033 if (flags.Test(ClangASTContext::eTypeIsArray))
1034 {
1035 if ((custom_format == lldb::eFormatBytes) ||
1036 (custom_format == lldb::eFormatBytesWithASCII))
1037 {
1038 uint32_t count = GetNumChildren();
1039
1040 s << '[';
1041 for (uint32_t low = 0; low < count; low++)
1042 {
1043
1044 if (low)
1045 s << ',';
1046
1047 ValueObjectSP child = GetChildAtIndex(low,true);
1048 if (!child.get())
1049 {
Enrico Granatae992a082011-07-22 17:03:19 +00001050 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001051 continue;
1052 }
1053 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1054 }
1055
1056 s << ']';
1057
1058 return true;
1059 }
1060
1061 if ((custom_format == lldb::eFormatVectorOfChar) ||
1062 (custom_format == lldb::eFormatVectorOfFloat32) ||
1063 (custom_format == lldb::eFormatVectorOfFloat64) ||
1064 (custom_format == lldb::eFormatVectorOfSInt16) ||
1065 (custom_format == lldb::eFormatVectorOfSInt32) ||
1066 (custom_format == lldb::eFormatVectorOfSInt64) ||
1067 (custom_format == lldb::eFormatVectorOfSInt8) ||
1068 (custom_format == lldb::eFormatVectorOfUInt128) ||
1069 (custom_format == lldb::eFormatVectorOfUInt16) ||
1070 (custom_format == lldb::eFormatVectorOfUInt32) ||
1071 (custom_format == lldb::eFormatVectorOfUInt64) ||
1072 (custom_format == lldb::eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1073 {
1074 uint32_t count = GetNumChildren();
1075
1076 lldb::Format format = FormatManager::GetSingleItemFormat(custom_format);
1077
1078 s << '[';
1079 for (uint32_t low = 0; low < count; low++)
1080 {
1081
1082 if (low)
1083 s << ',';
1084
1085 ValueObjectSP child = GetChildAtIndex(low,true);
1086 if (!child.get())
1087 {
Enrico Granatae992a082011-07-22 17:03:19 +00001088 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001089 continue;
1090 }
1091 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1092 }
1093
1094 s << ']';
1095
1096 return true;
1097 }
1098 }
1099
1100 if ((custom_format == lldb::eFormatBoolean) ||
1101 (custom_format == lldb::eFormatBinary) ||
1102 (custom_format == lldb::eFormatChar) ||
1103 (custom_format == lldb::eFormatCharPrintable) ||
1104 (custom_format == lldb::eFormatComplexFloat) ||
1105 (custom_format == lldb::eFormatDecimal) ||
1106 (custom_format == lldb::eFormatHex) ||
1107 (custom_format == lldb::eFormatFloat) ||
1108 (custom_format == lldb::eFormatOctal) ||
1109 (custom_format == lldb::eFormatOSType) ||
1110 (custom_format == lldb::eFormatUnicode16) ||
1111 (custom_format == lldb::eFormatUnicode32) ||
1112 (custom_format == lldb::eFormatUnsigned) ||
1113 (custom_format == lldb::eFormatPointer) ||
1114 (custom_format == lldb::eFormatComplexInteger) ||
1115 (custom_format == lldb::eFormatComplex) ||
1116 (custom_format == lldb::eFormatDefault)) // use the [] operator
1117 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001118 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001119 const char *targetvalue = GetPrintableRepresentation(val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001120 if (targetvalue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001121 s.PutCString(targetvalue);
1122 bool var_success = (targetvalue != NULL);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001123 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001124 SetFormat(eFormatDefault);
1125 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001126}
1127
Greg Clayton737b9322010-09-13 03:32:57 +00001128addr_t
Greg Claytone0d378b2011-03-24 21:19:54 +00001129ValueObject::GetAddressOf (AddressType &address_type, bool scalar_is_load_address)
Greg Clayton73b472d2010-10-27 03:32:59 +00001130{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001131 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001132 return LLDB_INVALID_ADDRESS;
1133
Greg Clayton73b472d2010-10-27 03:32:59 +00001134 switch (m_value.GetValueType())
1135 {
1136 case Value::eValueTypeScalar:
1137 if (scalar_is_load_address)
1138 {
1139 address_type = eAddressTypeLoad;
1140 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1141 }
1142 break;
1143
1144 case Value::eValueTypeLoadAddress:
1145 case Value::eValueTypeFileAddress:
1146 case Value::eValueTypeHostAddress:
1147 {
1148 address_type = m_value.GetValueAddressType ();
1149 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1150 }
1151 break;
1152 }
1153 address_type = eAddressTypeInvalid;
1154 return LLDB_INVALID_ADDRESS;
1155}
1156
1157addr_t
Greg Claytone0d378b2011-03-24 21:19:54 +00001158ValueObject::GetPointerValue (AddressType &address_type, bool scalar_is_load_address)
Greg Clayton737b9322010-09-13 03:32:57 +00001159{
1160 lldb::addr_t address = LLDB_INVALID_ADDRESS;
1161 address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001162
Enrico Granatac3e320a2011-08-02 17:27:39 +00001163 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001164 return address;
1165
Greg Clayton73b472d2010-10-27 03:32:59 +00001166 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001167 {
1168 case Value::eValueTypeScalar:
1169 if (scalar_is_load_address)
1170 {
1171 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1172 address_type = eAddressTypeLoad;
1173 }
1174 break;
1175
1176 case Value::eValueTypeLoadAddress:
1177 case Value::eValueTypeFileAddress:
1178 case Value::eValueTypeHostAddress:
1179 {
1180 uint32_t data_offset = 0;
1181 address = m_data.GetPointer(&data_offset);
1182 address_type = m_value.GetValueAddressType();
1183 if (address_type == eAddressTypeInvalid)
1184 address_type = eAddressTypeLoad;
1185 }
1186 break;
1187 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001188
1189 if (m_pointers_point_to_load_addrs)
1190 address_type = eAddressTypeLoad;
1191
Greg Clayton737b9322010-09-13 03:32:57 +00001192 return address;
1193}
1194
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001195bool
Jim Ingham6035b672011-03-31 00:19:25 +00001196ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001197{
1198 // Make sure our value is up to date first so that our location and location
1199 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001200 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001201 return false;
1202
1203 uint32_t count = 0;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001204 lldb::Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001205
1206 char *end = NULL;
Greg Claytonb1320972010-07-14 00:18:15 +00001207 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001208 switch (encoding)
1209 {
1210 case eEncodingInvalid:
1211 return false;
1212
1213 case eEncodingUint:
1214 if (byte_size > sizeof(unsigned long long))
1215 {
1216 return false;
1217 }
1218 else
1219 {
1220 unsigned long long ull_val = strtoull(value_str, &end, 0);
1221 if (end && *end != '\0')
1222 return false;
Greg Clayton644247c2011-07-07 01:59:51 +00001223 m_value.GetScalar() = ull_val;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001224 // Limit the bytes in our m_data appropriately.
1225 m_value.GetScalar().GetData (m_data, byte_size);
1226 }
1227 break;
1228
1229 case eEncodingSint:
1230 if (byte_size > sizeof(long long))
1231 {
1232 return false;
1233 }
1234 else
1235 {
1236 long long sll_val = strtoll(value_str, &end, 0);
1237 if (end && *end != '\0')
1238 return false;
Greg Clayton644247c2011-07-07 01:59:51 +00001239 m_value.GetScalar() = sll_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 eEncodingIEEE754:
1246 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001247 const off_t byte_offset = GetByteOffset();
Greg Claytonc982c762010-07-09 20:39:50 +00001248 uint8_t *dst = const_cast<uint8_t *>(m_data.PeekData(byte_offset, byte_size));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001249 if (dst != NULL)
1250 {
1251 // We are decoding a float into host byte order below, so make
1252 // sure m_data knows what it contains.
Greg Clayton7fb56d02011-02-01 01:31:41 +00001253 m_data.SetByteOrder(lldb::endian::InlHostByteOrder());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001254 const size_t converted_byte_size = ClangASTContext::ConvertStringToFloatValue (
1255 GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +00001256 GetClangType(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001257 value_str,
1258 dst,
1259 byte_size);
1260
1261 if (converted_byte_size == byte_size)
1262 {
1263 }
1264 }
1265 }
1266 break;
1267
1268 case eEncodingVector:
1269 return false;
1270
1271 default:
1272 return false;
1273 }
1274
1275 // If we have made it here the value is in m_data and we should write it
1276 // out to the target
1277 return Write ();
1278}
1279
1280bool
1281ValueObject::Write ()
1282{
1283 // Clear the update ID so the next time we try and read the value
1284 // we try and read it again.
Jim Ingham6035b672011-03-31 00:19:25 +00001285 m_update_point.SetNeedsUpdate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001286
1287 // TODO: when Value has a method to write a value back, call it from here.
1288 return false;
1289
1290}
1291
Jim Ingham5a369122010-09-28 01:25:32 +00001292lldb::LanguageType
1293ValueObject::GetObjectRuntimeLanguage ()
1294{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001295 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1296 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001297}
1298
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001299void
Jim Ingham58b59f92011-04-22 23:53:53 +00001300ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001301{
Jim Ingham58b59f92011-04-22 23:53:53 +00001302 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001303}
1304
1305ValueObjectSP
1306ValueObject::GetSyntheticChild (const ConstString &key) const
1307{
1308 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001309 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001310 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001311 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001312 return synthetic_child_sp;
1313}
1314
1315bool
1316ValueObject::IsPointerType ()
1317{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001318 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001319}
1320
Jim Inghamb7603bb2011-03-18 00:05:18 +00001321bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001322ValueObject::IsArrayType ()
1323{
1324 return ClangASTContext::IsArrayType (GetClangType());
1325}
1326
1327bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001328ValueObject::IsScalarType ()
1329{
1330 return ClangASTContext::IsScalarType (GetClangType());
1331}
1332
1333bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001334ValueObject::IsIntegerType (bool &is_signed)
1335{
1336 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1337}
Greg Clayton73b472d2010-10-27 03:32:59 +00001338
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001339bool
1340ValueObject::IsPointerOrReferenceType ()
1341{
Greg Clayton007d5be2011-05-30 00:49:24 +00001342 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1343}
1344
1345bool
1346ValueObject::IsPossibleCPlusPlusDynamicType ()
1347{
1348 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001349}
1350
Greg Claytondea8cb42011-06-29 22:09:02 +00001351bool
1352ValueObject::IsPossibleDynamicType ()
1353{
1354 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1355}
1356
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001357ValueObjectSP
1358ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1359{
1360 ValueObjectSP synthetic_child_sp;
1361 if (IsPointerType ())
1362 {
1363 char index_str[64];
1364 snprintf(index_str, sizeof(index_str), "[%i]", index);
1365 ConstString index_const_str(index_str);
1366 // Check if we have already created a synthetic array member in this
1367 // valid object. If we have we will re-use it.
1368 synthetic_child_sp = GetSyntheticChild (index_const_str);
1369 if (!synthetic_child_sp)
1370 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001371 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001372 // We haven't made a synthetic array member for INDEX yet, so
1373 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001374 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001375
1376 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001377 if (synthetic_child)
1378 {
1379 AddSyntheticChild(index_const_str, synthetic_child);
1380 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001381 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001382 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001383 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001384 }
1385 }
1386 return synthetic_child_sp;
1387}
Jim Ingham22777012010-09-23 02:01:19 +00001388
Greg Claytondaf515f2011-07-09 20:12:33 +00001389// This allows you to create an array member using and index
1390// that doesn't not fall in the normal bounds of the array.
1391// Many times structure can be defined as:
1392// struct Collection
1393// {
1394// uint32_t item_count;
1395// Item item_array[0];
1396// };
1397// The size of the "item_array" is 1, but many times in practice
1398// there are more items in "item_array".
1399
1400ValueObjectSP
1401ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1402{
1403 ValueObjectSP synthetic_child_sp;
1404 if (IsArrayType ())
1405 {
1406 char index_str[64];
1407 snprintf(index_str, sizeof(index_str), "[%i]", index);
1408 ConstString index_const_str(index_str);
1409 // Check if we have already created a synthetic array member in this
1410 // valid object. If we have we will re-use it.
1411 synthetic_child_sp = GetSyntheticChild (index_const_str);
1412 if (!synthetic_child_sp)
1413 {
1414 ValueObject *synthetic_child;
1415 // We haven't made a synthetic array member for INDEX yet, so
1416 // lets make one and cache it for any future reference.
1417 synthetic_child = CreateChildAtIndex(0, true, index);
1418
1419 // Cache the value if we got one back...
1420 if (synthetic_child)
1421 {
1422 AddSyntheticChild(index_const_str, synthetic_child);
1423 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001424 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001425 synthetic_child_sp->m_is_array_item_for_pointer = true;
1426 }
1427 }
1428 }
1429 return synthetic_child_sp;
1430}
1431
Enrico Granata9fc19442011-07-06 02:13:41 +00001432ValueObjectSP
1433ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1434{
1435 ValueObjectSP synthetic_child_sp;
1436 if (IsScalarType ())
1437 {
1438 char index_str[64];
1439 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1440 ConstString index_const_str(index_str);
1441 // Check if we have already created a synthetic array member in this
1442 // valid object. If we have we will re-use it.
1443 synthetic_child_sp = GetSyntheticChild (index_const_str);
1444 if (!synthetic_child_sp)
1445 {
1446 ValueObjectChild *synthetic_child;
1447 // We haven't made a synthetic array member for INDEX yet, so
1448 // lets make one and cache it for any future reference.
1449 synthetic_child = new ValueObjectChild(*this,
1450 GetClangAST(),
1451 GetClangType(),
1452 index_const_str,
1453 GetByteSize(),
1454 0,
1455 to-from+1,
1456 from,
1457 false,
1458 false);
1459
1460 // Cache the value if we got one back...
1461 if (synthetic_child)
1462 {
1463 AddSyntheticChild(index_const_str, synthetic_child);
1464 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001465 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001466 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1467 }
1468 }
1469 }
1470 return synthetic_child_sp;
1471}
1472
Enrico Granata6f3533f2011-07-29 19:53:35 +00001473lldb::ValueObjectSP
1474ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1475{
1476
1477 ValueObjectSP synthetic_child_sp;
1478
1479 char name_str[64];
1480 snprintf(name_str, sizeof(name_str), "@%i", offset);
1481 ConstString name_const_str(name_str);
1482
1483 // Check if we have already created a synthetic array member in this
1484 // valid object. If we have we will re-use it.
1485 synthetic_child_sp = GetSyntheticChild (name_const_str);
1486
1487 if (synthetic_child_sp.get())
1488 return synthetic_child_sp;
1489
1490 if (!can_create)
1491 return lldb::ValueObjectSP();
1492
1493 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1494 type.GetASTContext(),
1495 type.GetOpaqueQualType(),
1496 name_const_str,
1497 type.GetTypeByteSize(),
1498 offset,
1499 0,
1500 0,
1501 false,
1502 false);
1503 if (synthetic_child)
1504 {
1505 AddSyntheticChild(name_const_str, synthetic_child);
1506 synthetic_child_sp = synthetic_child->GetSP();
1507 synthetic_child_sp->SetName(name_const_str);
1508 synthetic_child_sp->m_is_child_at_offset = true;
1509 }
1510 return synthetic_child_sp;
1511}
1512
Enrico Granatad55546b2011-07-22 00:16:08 +00001513// your expression path needs to have a leading . or ->
1514// (unless it somehow "looks like" an array, in which case it has
1515// a leading [ symbol). while the [ is meaningful and should be shown
1516// to the user, . and -> are just parser design, but by no means
1517// added information for the user.. strip them off
1518static const char*
1519SkipLeadingExpressionPathSeparators(const char* expression)
1520{
1521 if (!expression || !expression[0])
1522 return expression;
1523 if (expression[0] == '.')
1524 return expression+1;
1525 if (expression[0] == '-' && expression[1] == '>')
1526 return expression+2;
1527 return expression;
1528}
1529
1530lldb::ValueObjectSP
1531ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1532{
1533 ValueObjectSP synthetic_child_sp;
1534 ConstString name_const_string(expression);
1535 // Check if we have already created a synthetic array member in this
1536 // valid object. If we have we will re-use it.
1537 synthetic_child_sp = GetSyntheticChild (name_const_string);
1538 if (!synthetic_child_sp)
1539 {
1540 // We haven't made a synthetic array member for expression yet, so
1541 // lets make one and cache it for any future reference.
1542 synthetic_child_sp = GetValueForExpressionPath(expression);
1543
1544 // Cache the value if we got one back...
1545 if (synthetic_child_sp.get())
1546 {
1547 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001548 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001549 synthetic_child_sp->m_is_expression_path_child = true;
1550 }
1551 }
1552 return synthetic_child_sp;
1553}
1554
1555void
1556ValueObject::CalculateSyntheticValue (lldb::SyntheticValueType use_synthetic)
1557{
1558 if (use_synthetic == lldb::eNoSyntheticFilter)
1559 return;
1560
Enrico Granatac3e320a2011-08-02 17:27:39 +00001561 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001562
1563 if (m_last_synthetic_filter.get() == NULL)
1564 return;
1565
Enrico Granataa37a0652011-07-24 00:14:56 +00001566 if (m_synthetic_value == NULL)
1567 m_synthetic_value = new ValueObjectSynthetic(*this, m_last_synthetic_filter);
Enrico Granatad55546b2011-07-22 00:16:08 +00001568
1569}
1570
Jim Ingham78a685a2011-04-16 00:01:13 +00001571void
Jim Ingham2837b762011-05-04 03:43:18 +00001572ValueObject::CalculateDynamicValue (lldb::DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00001573{
Jim Ingham2837b762011-05-04 03:43:18 +00001574 if (use_dynamic == lldb::eNoDynamicValues)
1575 return;
1576
Jim Ingham58b59f92011-04-22 23:53:53 +00001577 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00001578 {
Enrico Granata6f3533f2011-07-29 19:53:35 +00001579 Process *process = m_update_point.GetProcessSP().get();
Jim Ingham78a685a2011-04-16 00:01:13 +00001580 bool worth_having_dynamic_value = false;
Jim Ingham22777012010-09-23 02:01:19 +00001581
Jim Ingham78a685a2011-04-16 00:01:13 +00001582
1583 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
1584 // hard code this everywhere.
1585 lldb::LanguageType known_type = GetObjectRuntimeLanguage();
1586 if (known_type != lldb::eLanguageTypeUnknown && known_type != lldb::eLanguageTypeC)
1587 {
1588 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
1589 if (runtime)
1590 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
1591 }
1592 else
1593 {
1594 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeC_plus_plus);
1595 if (cpp_runtime)
1596 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
1597
1598 if (!worth_having_dynamic_value)
1599 {
1600 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeObjC);
1601 if (objc_runtime)
Jim Ingham2837b762011-05-04 03:43:18 +00001602 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00001603 }
1604 }
1605
1606 if (worth_having_dynamic_value)
Jim Ingham2837b762011-05-04 03:43:18 +00001607 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham58b59f92011-04-22 23:53:53 +00001608
1609// if (worth_having_dynamic_value)
1610// printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager);
1611
Jim Ingham78a685a2011-04-16 00:01:13 +00001612 }
1613}
1614
Jim Ingham58b59f92011-04-22 23:53:53 +00001615ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00001616ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00001617{
Jim Ingham2837b762011-05-04 03:43:18 +00001618 if (use_dynamic == lldb::eNoDynamicValues)
1619 return ValueObjectSP();
1620
1621 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00001622 {
Jim Ingham2837b762011-05-04 03:43:18 +00001623 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001624 }
Jim Ingham58b59f92011-04-22 23:53:53 +00001625 if (m_dynamic_value)
1626 return m_dynamic_value->GetSP();
1627 else
1628 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00001629}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001630
Enrico Granatad55546b2011-07-22 00:16:08 +00001631// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
1632// or we do not really want a dynamic VO. this method instead returns this object
1633// itself when making it synthetic has no meaning. this makes it much simpler
1634// to replace the SyntheticValue for the ValueObject
1635ValueObjectSP
1636ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
1637{
1638 if (use_synthetic == lldb::eNoSyntheticFilter)
1639 return GetSP();
1640
Enrico Granatac3e320a2011-08-02 17:27:39 +00001641 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001642
1643 if (m_last_synthetic_filter.get() == NULL)
1644 return GetSP();
1645
1646 CalculateSyntheticValue(use_synthetic);
1647
1648 if (m_synthetic_value)
1649 return m_synthetic_value->GetSP();
1650 else
1651 return GetSP();
1652}
1653
Greg Claytone221f822011-01-21 01:59:00 +00001654bool
1655ValueObject::GetBaseClassPath (Stream &s)
1656{
1657 if (IsBaseClass())
1658 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001659 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00001660 clang_type_t clang_type = GetClangType();
1661 std::string cxx_class_name;
1662 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
1663 if (this_had_base_class)
1664 {
1665 if (parent_had_base_class)
1666 s.PutCString("::");
1667 s.PutCString(cxx_class_name.c_str());
1668 }
1669 return parent_had_base_class || this_had_base_class;
1670 }
1671 return false;
1672}
1673
1674
1675ValueObject *
1676ValueObject::GetNonBaseClassParent()
1677{
Jim Ingham78a685a2011-04-16 00:01:13 +00001678 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00001679 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001680 if (GetParent()->IsBaseClass())
1681 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00001682 else
Jim Ingham78a685a2011-04-16 00:01:13 +00001683 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00001684 }
1685 return NULL;
1686}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001687
1688void
Enrico Granata4becb372011-06-29 22:27:15 +00001689ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001690{
Greg Claytone221f822011-01-21 01:59:00 +00001691 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00001692
Enrico Granata9dd75c82011-07-15 23:30:15 +00001693 if (is_deref_of_parent && epformat == eDereferencePointers) {
Enrico Granata4becb372011-06-29 22:27:15 +00001694 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
1695 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
1696 // the eHonorPointers mode is meant to produce strings in this latter format
1697 s.PutCString("*(");
1698 }
Greg Claytone221f822011-01-21 01:59:00 +00001699
Enrico Granata4becb372011-06-29 22:27:15 +00001700 ValueObject* parent = GetParent();
1701
1702 if (parent)
1703 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00001704
1705 // if we are a deref_of_parent just because we are synthetic array
1706 // members made up to allow ptr[%d] syntax to work in variable
1707 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00001708 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001709 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00001710
Greg Claytone221f822011-01-21 01:59:00 +00001711 if (!IsBaseClass())
1712 {
1713 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001714 {
Greg Claytone221f822011-01-21 01:59:00 +00001715 ValueObject *non_base_class_parent = GetNonBaseClassParent();
1716 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001717 {
Greg Claytone221f822011-01-21 01:59:00 +00001718 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
1719 if (non_base_class_parent_clang_type)
1720 {
1721 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
1722
Enrico Granata9dd75c82011-07-15 23:30:15 +00001723 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00001724 {
1725 s.PutCString("->");
1726 }
Enrico Granata4becb372011-06-29 22:27:15 +00001727 else
1728 {
1729 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
1730 {
1731 s.PutCString("->");
1732 }
1733 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
1734 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
1735 {
1736 s.PutChar('.');
1737 }
Greg Claytone221f822011-01-21 01:59:00 +00001738 }
1739 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001740 }
Greg Claytone221f822011-01-21 01:59:00 +00001741
1742 const char *name = GetName().GetCString();
1743 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001744 {
Greg Claytone221f822011-01-21 01:59:00 +00001745 if (qualify_cxx_base_classes)
1746 {
1747 if (GetBaseClassPath (s))
1748 s.PutCString("::");
1749 }
1750 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001751 }
1752 }
1753 }
1754
Enrico Granata4becb372011-06-29 22:27:15 +00001755 if (is_deref_of_parent && epformat == eDereferencePointers) {
Greg Claytone221f822011-01-21 01:59:00 +00001756 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00001757 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001758}
1759
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001760lldb::ValueObjectSP
1761ValueObject::GetValueForExpressionPath(const char* expression,
1762 const char** first_unparsed,
1763 ExpressionPathScanEndReason* reason_to_stop,
1764 ExpressionPathEndResultType* final_value_type,
1765 const GetValueForExpressionPathOptions& options,
1766 ExpressionPathAftermath* final_task_on_target)
1767{
1768
1769 const char* dummy_first_unparsed;
1770 ExpressionPathScanEndReason dummy_reason_to_stop;
1771 ExpressionPathEndResultType dummy_final_value_type;
1772 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
1773
1774 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
1775 first_unparsed ? first_unparsed : &dummy_first_unparsed,
1776 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
1777 final_value_type ? final_value_type : &dummy_final_value_type,
1778 options,
1779 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
1780
1781 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
1782 {
1783 return ret_val;
1784 }
1785 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
1786 {
1787 if (*final_task_on_target == ValueObject::eDereference)
1788 {
1789 Error error;
1790 ValueObjectSP final_value = ret_val->Dereference(error);
1791 if (error.Fail() || !final_value.get())
1792 {
1793 *reason_to_stop = ValueObject::eDereferencingFailed;
1794 *final_value_type = ValueObject::eInvalid;
1795 return ValueObjectSP();
1796 }
1797 else
1798 {
1799 *final_task_on_target = ValueObject::eNothing;
1800 return final_value;
1801 }
1802 }
1803 if (*final_task_on_target == ValueObject::eTakeAddress)
1804 {
1805 Error error;
1806 ValueObjectSP final_value = ret_val->AddressOf(error);
1807 if (error.Fail() || !final_value.get())
1808 {
1809 *reason_to_stop = ValueObject::eTakingAddressFailed;
1810 *final_value_type = ValueObject::eInvalid;
1811 return ValueObjectSP();
1812 }
1813 else
1814 {
1815 *final_task_on_target = ValueObject::eNothing;
1816 return final_value;
1817 }
1818 }
1819 }
1820 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
1821}
1822
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001823int
1824ValueObject::GetValuesForExpressionPath(const char* expression,
1825 lldb::ValueObjectListSP& list,
1826 const char** first_unparsed,
1827 ExpressionPathScanEndReason* reason_to_stop,
1828 ExpressionPathEndResultType* final_value_type,
1829 const GetValueForExpressionPathOptions& options,
1830 ExpressionPathAftermath* final_task_on_target)
1831{
1832 const char* dummy_first_unparsed;
1833 ExpressionPathScanEndReason dummy_reason_to_stop;
1834 ExpressionPathEndResultType dummy_final_value_type;
1835 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
1836
1837 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
1838 first_unparsed ? first_unparsed : &dummy_first_unparsed,
1839 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
1840 final_value_type ? final_value_type : &dummy_final_value_type,
1841 options,
1842 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
1843
1844 if (!ret_val.get()) // if there are errors, I add nothing to the list
1845 return 0;
1846
1847 if (*reason_to_stop != eArrayRangeOperatorMet)
1848 {
1849 // I need not expand a range, just post-process the final value and return
1850 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
1851 {
1852 list->Append(ret_val);
1853 return 1;
1854 }
1855 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
1856 {
1857 if (*final_task_on_target == ValueObject::eDereference)
1858 {
1859 Error error;
1860 ValueObjectSP final_value = ret_val->Dereference(error);
1861 if (error.Fail() || !final_value.get())
1862 {
1863 *reason_to_stop = ValueObject::eDereferencingFailed;
1864 *final_value_type = ValueObject::eInvalid;
1865 return 0;
1866 }
1867 else
1868 {
1869 *final_task_on_target = ValueObject::eNothing;
1870 list->Append(final_value);
1871 return 1;
1872 }
1873 }
1874 if (*final_task_on_target == ValueObject::eTakeAddress)
1875 {
1876 Error error;
1877 ValueObjectSP final_value = ret_val->AddressOf(error);
1878 if (error.Fail() || !final_value.get())
1879 {
1880 *reason_to_stop = ValueObject::eTakingAddressFailed;
1881 *final_value_type = ValueObject::eInvalid;
1882 return 0;
1883 }
1884 else
1885 {
1886 *final_task_on_target = ValueObject::eNothing;
1887 list->Append(final_value);
1888 return 1;
1889 }
1890 }
1891 }
1892 }
1893 else
1894 {
1895 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
1896 first_unparsed ? first_unparsed : &dummy_first_unparsed,
1897 ret_val,
1898 list,
1899 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
1900 final_value_type ? final_value_type : &dummy_final_value_type,
1901 options,
1902 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
1903 }
1904 // in any non-covered case, just do the obviously right thing
1905 list->Append(ret_val);
1906 return 1;
1907}
1908
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001909lldb::ValueObjectSP
1910ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
1911 const char** first_unparsed,
1912 ExpressionPathScanEndReason* reason_to_stop,
1913 ExpressionPathEndResultType* final_result,
1914 const GetValueForExpressionPathOptions& options,
1915 ExpressionPathAftermath* what_next)
1916{
1917 ValueObjectSP root = GetSP();
1918
1919 if (!root.get())
1920 return ValueObjectSP();
1921
1922 *first_unparsed = expression_cstr;
1923
1924 while (true)
1925 {
1926
1927 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
1928
1929 lldb::clang_type_t root_clang_type = root->GetClangType();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001930 lldb::clang_type_t pointee_clang_type;
1931 Flags root_clang_type_info,pointee_clang_type_info;
1932
1933 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
1934 if (pointee_clang_type)
1935 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001936
1937 if (!expression_cstr || *expression_cstr == '\0')
1938 {
1939 *reason_to_stop = ValueObject::eEndOfString;
1940 return root;
1941 }
1942
1943 switch (*expression_cstr)
1944 {
1945 case '-':
1946 {
1947 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001948 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 +00001949 {
1950 *first_unparsed = expression_cstr;
1951 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
1952 *final_result = ValueObject::eInvalid;
1953 return ValueObjectSP();
1954 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001955 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
1956 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001957 options.m_no_fragile_ivar)
1958 {
1959 *first_unparsed = expression_cstr;
1960 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
1961 *final_result = ValueObject::eInvalid;
1962 return ValueObjectSP();
1963 }
1964 if (expression_cstr[1] != '>')
1965 {
1966 *first_unparsed = expression_cstr;
1967 *reason_to_stop = ValueObject::eUnexpectedSymbol;
1968 *final_result = ValueObject::eInvalid;
1969 return ValueObjectSP();
1970 }
1971 expression_cstr++; // skip the -
1972 }
1973 case '.': // or fallthrough from ->
1974 {
1975 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001976 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 +00001977 {
1978 *first_unparsed = expression_cstr;
1979 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
1980 *final_result = ValueObject::eInvalid;
1981 return ValueObjectSP();
1982 }
1983 expression_cstr++; // skip .
1984 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
1985 ConstString child_name;
1986 if (!next_separator) // if no other separator just expand this last layer
1987 {
1988 child_name.SetCString (expression_cstr);
1989 root = root->GetChildMemberWithName(child_name, true);
1990 if (root.get()) // we know we are done, so just return
1991 {
1992 *first_unparsed = '\0';
1993 *reason_to_stop = ValueObject::eEndOfString;
1994 *final_result = ValueObject::ePlain;
1995 return root;
1996 }
1997 else
1998 {
1999 *first_unparsed = expression_cstr;
2000 *reason_to_stop = ValueObject::eNoSuchChild;
2001 *final_result = ValueObject::eInvalid;
2002 return ValueObjectSP();
2003 }
2004 }
2005 else // other layers do expand
2006 {
2007 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
2008 root = root->GetChildMemberWithName(child_name, true);
2009 if (root.get()) // store the new root and move on
2010 {
2011 *first_unparsed = next_separator;
2012 *final_result = ValueObject::ePlain;
2013 continue;
2014 }
2015 else
2016 {
2017 *first_unparsed = expression_cstr;
2018 *reason_to_stop = ValueObject::eNoSuchChild;
2019 *final_result = ValueObject::eInvalid;
2020 return ValueObjectSP();
2021 }
2022 }
2023 break;
2024 }
2025 case '[':
2026 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002027 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 +00002028 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002029 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002030 {
2031 *first_unparsed = expression_cstr;
2032 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2033 *final_result = ValueObject::eInvalid;
2034 return ValueObjectSP();
2035 }
2036 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2037 {
2038 *first_unparsed = expression_cstr;
2039 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2040 *final_result = ValueObject::eInvalid;
2041 return ValueObjectSP();
2042 }
2043 }
2044 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2045 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002046 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002047 {
2048 *first_unparsed = expression_cstr;
2049 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2050 *final_result = ValueObject::eInvalid;
2051 return ValueObjectSP();
2052 }
2053 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2054 {
2055 *first_unparsed = expression_cstr+2;
2056 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2057 *final_result = ValueObject::eUnboundedRange;
2058 return root;
2059 }
2060 }
2061 const char *separator_position = ::strchr(expression_cstr+1,'-');
2062 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2063 if (!close_bracket_position) // if there is no ], this is a syntax error
2064 {
2065 *first_unparsed = expression_cstr;
2066 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2067 *final_result = ValueObject::eInvalid;
2068 return ValueObjectSP();
2069 }
2070 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2071 {
2072 char *end = NULL;
2073 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2074 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2075 {
2076 *first_unparsed = expression_cstr;
2077 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2078 *final_result = ValueObject::eInvalid;
2079 return ValueObjectSP();
2080 }
2081 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2082 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002083 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002084 {
2085 *first_unparsed = expression_cstr+2;
2086 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2087 *final_result = ValueObject::eUnboundedRange;
2088 return root;
2089 }
2090 else
2091 {
2092 *first_unparsed = expression_cstr;
2093 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2094 *final_result = ValueObject::eInvalid;
2095 return ValueObjectSP();
2096 }
2097 }
2098 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002099 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002100 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002101 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2102 if (!child_valobj_sp)
2103 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
2104 if (child_valobj_sp)
2105 {
2106 root = child_valobj_sp;
2107 *first_unparsed = end+1; // skip ]
2108 *final_result = ValueObject::ePlain;
2109 continue;
2110 }
2111 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002112 {
2113 *first_unparsed = expression_cstr;
2114 *reason_to_stop = ValueObject::eNoSuchChild;
2115 *final_result = ValueObject::eInvalid;
2116 return ValueObjectSP();
2117 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002118 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002119 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002120 {
2121 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 +00002122 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002123 {
2124 Error error;
2125 root = root->Dereference(error);
2126 if (error.Fail() || !root.get())
2127 {
2128 *first_unparsed = expression_cstr;
2129 *reason_to_stop = ValueObject::eDereferencingFailed;
2130 *final_result = ValueObject::eInvalid;
2131 return ValueObjectSP();
2132 }
2133 else
2134 {
2135 *what_next = eNothing;
2136 continue;
2137 }
2138 }
2139 else
2140 {
2141 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2142 if (!root.get())
2143 {
2144 *first_unparsed = expression_cstr;
2145 *reason_to_stop = ValueObject::eNoSuchChild;
2146 *final_result = ValueObject::eInvalid;
2147 return ValueObjectSP();
2148 }
2149 else
2150 {
2151 *first_unparsed = end+1; // skip ]
2152 *final_result = ValueObject::ePlain;
2153 continue;
2154 }
2155 }
2156 }
2157 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2158 {
2159 root = root->GetSyntheticBitFieldChild(index, index, true);
2160 if (!root.get())
2161 {
2162 *first_unparsed = expression_cstr;
2163 *reason_to_stop = ValueObject::eNoSuchChild;
2164 *final_result = ValueObject::eInvalid;
2165 return ValueObjectSP();
2166 }
2167 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2168 {
2169 *first_unparsed = end+1; // skip ]
2170 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2171 *final_result = ValueObject::eBitfield;
2172 return root;
2173 }
2174 }
2175 }
2176 else // we have a low and a high index
2177 {
2178 char *end = NULL;
2179 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2180 if (!end || end != separator_position) // if something weird is in our way return an error
2181 {
2182 *first_unparsed = expression_cstr;
2183 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2184 *final_result = ValueObject::eInvalid;
2185 return ValueObjectSP();
2186 }
2187 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2188 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2189 {
2190 *first_unparsed = expression_cstr;
2191 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2192 *final_result = ValueObject::eInvalid;
2193 return ValueObjectSP();
2194 }
2195 if (index_lower > index_higher) // swap indices if required
2196 {
2197 unsigned long temp = index_lower;
2198 index_lower = index_higher;
2199 index_higher = temp;
2200 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002201 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002202 {
2203 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2204 if (!root.get())
2205 {
2206 *first_unparsed = expression_cstr;
2207 *reason_to_stop = ValueObject::eNoSuchChild;
2208 *final_result = ValueObject::eInvalid;
2209 return ValueObjectSP();
2210 }
2211 else
2212 {
2213 *first_unparsed = end+1; // skip ]
2214 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2215 *final_result = ValueObject::eBitfield;
2216 return root;
2217 }
2218 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002219 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 +00002220 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002221 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002222 {
2223 Error error;
2224 root = root->Dereference(error);
2225 if (error.Fail() || !root.get())
2226 {
2227 *first_unparsed = expression_cstr;
2228 *reason_to_stop = ValueObject::eDereferencingFailed;
2229 *final_result = ValueObject::eInvalid;
2230 return ValueObjectSP();
2231 }
2232 else
2233 {
2234 *what_next = ValueObject::eNothing;
2235 continue;
2236 }
2237 }
2238 else
2239 {
2240 *first_unparsed = expression_cstr;
2241 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2242 *final_result = ValueObject::eBoundedRange;
2243 return root;
2244 }
2245 }
2246 break;
2247 }
2248 default: // some non-separator is in the way
2249 {
2250 *first_unparsed = expression_cstr;
2251 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2252 *final_result = ValueObject::eInvalid;
2253 return ValueObjectSP();
2254 break;
2255 }
2256 }
2257 }
2258}
2259
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002260int
2261ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2262 const char** first_unparsed,
2263 lldb::ValueObjectSP root,
2264 lldb::ValueObjectListSP& list,
2265 ExpressionPathScanEndReason* reason_to_stop,
2266 ExpressionPathEndResultType* final_result,
2267 const GetValueForExpressionPathOptions& options,
2268 ExpressionPathAftermath* what_next)
2269{
2270 if (!root.get())
2271 return 0;
2272
2273 *first_unparsed = expression_cstr;
2274
2275 while (true)
2276 {
2277
2278 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2279
2280 lldb::clang_type_t root_clang_type = root->GetClangType();
2281 lldb::clang_type_t pointee_clang_type;
2282 Flags root_clang_type_info,pointee_clang_type_info;
2283
2284 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2285 if (pointee_clang_type)
2286 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2287
2288 if (!expression_cstr || *expression_cstr == '\0')
2289 {
2290 *reason_to_stop = ValueObject::eEndOfString;
2291 list->Append(root);
2292 return 1;
2293 }
2294
2295 switch (*expression_cstr)
2296 {
2297 case '[':
2298 {
2299 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2300 {
2301 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2302 {
2303 *first_unparsed = expression_cstr;
2304 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2305 *final_result = ValueObject::eInvalid;
2306 return 0;
2307 }
2308 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2309 {
2310 *first_unparsed = expression_cstr;
2311 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2312 *final_result = ValueObject::eInvalid;
2313 return 0;
2314 }
2315 }
2316 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2317 {
2318 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2319 {
2320 *first_unparsed = expression_cstr;
2321 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2322 *final_result = ValueObject::eInvalid;
2323 return 0;
2324 }
2325 else // expand this into list
2326 {
2327 int max_index = root->GetNumChildren() - 1;
2328 for (int index = 0; index < max_index; index++)
2329 {
2330 ValueObjectSP child =
2331 root->GetChildAtIndex(index, true);
2332 list->Append(child);
2333 }
2334 *first_unparsed = expression_cstr+2;
2335 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2336 *final_result = ValueObject::eValueObjectList;
2337 return max_index; // tell me number of items I added to the VOList
2338 }
2339 }
2340 const char *separator_position = ::strchr(expression_cstr+1,'-');
2341 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2342 if (!close_bracket_position) // if there is no ], this is a syntax error
2343 {
2344 *first_unparsed = expression_cstr;
2345 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2346 *final_result = ValueObject::eInvalid;
2347 return 0;
2348 }
2349 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2350 {
2351 char *end = NULL;
2352 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2353 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2354 {
2355 *first_unparsed = expression_cstr;
2356 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2357 *final_result = ValueObject::eInvalid;
2358 return 0;
2359 }
2360 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2361 {
2362 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2363 {
2364 int max_index = root->GetNumChildren() - 1;
2365 for (int index = 0; index < max_index; index++)
2366 {
2367 ValueObjectSP child =
2368 root->GetChildAtIndex(index, true);
2369 list->Append(child);
2370 }
2371 *first_unparsed = expression_cstr+2;
2372 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2373 *final_result = ValueObject::eValueObjectList;
2374 return max_index; // tell me number of items I added to the VOList
2375 }
2376 else
2377 {
2378 *first_unparsed = expression_cstr;
2379 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2380 *final_result = ValueObject::eInvalid;
2381 return 0;
2382 }
2383 }
2384 // from here on we do have a valid index
2385 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2386 {
2387 root = root->GetChildAtIndex(index, true);
2388 if (!root.get())
2389 {
2390 *first_unparsed = expression_cstr;
2391 *reason_to_stop = ValueObject::eNoSuchChild;
2392 *final_result = ValueObject::eInvalid;
2393 return 0;
2394 }
2395 else
2396 {
2397 list->Append(root);
2398 *first_unparsed = end+1; // skip ]
2399 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2400 *final_result = ValueObject::eValueObjectList;
2401 return 1;
2402 }
2403 }
2404 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2405 {
2406 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
2407 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2408 {
2409 Error error;
2410 root = root->Dereference(error);
2411 if (error.Fail() || !root.get())
2412 {
2413 *first_unparsed = expression_cstr;
2414 *reason_to_stop = ValueObject::eDereferencingFailed;
2415 *final_result = ValueObject::eInvalid;
2416 return 0;
2417 }
2418 else
2419 {
2420 *what_next = eNothing;
2421 continue;
2422 }
2423 }
2424 else
2425 {
2426 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2427 if (!root.get())
2428 {
2429 *first_unparsed = expression_cstr;
2430 *reason_to_stop = ValueObject::eNoSuchChild;
2431 *final_result = ValueObject::eInvalid;
2432 return 0;
2433 }
2434 else
2435 {
2436 list->Append(root);
2437 *first_unparsed = end+1; // skip ]
2438 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2439 *final_result = ValueObject::eValueObjectList;
2440 return 1;
2441 }
2442 }
2443 }
2444 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2445 {
2446 root = root->GetSyntheticBitFieldChild(index, index, true);
2447 if (!root.get())
2448 {
2449 *first_unparsed = expression_cstr;
2450 *reason_to_stop = ValueObject::eNoSuchChild;
2451 *final_result = ValueObject::eInvalid;
2452 return 0;
2453 }
2454 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2455 {
2456 list->Append(root);
2457 *first_unparsed = end+1; // skip ]
2458 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2459 *final_result = ValueObject::eValueObjectList;
2460 return 1;
2461 }
2462 }
2463 }
2464 else // we have a low and a high index
2465 {
2466 char *end = NULL;
2467 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2468 if (!end || end != separator_position) // if something weird is in our way return an error
2469 {
2470 *first_unparsed = expression_cstr;
2471 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2472 *final_result = ValueObject::eInvalid;
2473 return 0;
2474 }
2475 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2476 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2477 {
2478 *first_unparsed = expression_cstr;
2479 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2480 *final_result = ValueObject::eInvalid;
2481 return 0;
2482 }
2483 if (index_lower > index_higher) // swap indices if required
2484 {
2485 unsigned long temp = index_lower;
2486 index_lower = index_higher;
2487 index_higher = temp;
2488 }
2489 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
2490 {
2491 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2492 if (!root.get())
2493 {
2494 *first_unparsed = expression_cstr;
2495 *reason_to_stop = ValueObject::eNoSuchChild;
2496 *final_result = ValueObject::eInvalid;
2497 return 0;
2498 }
2499 else
2500 {
2501 list->Append(root);
2502 *first_unparsed = end+1; // skip ]
2503 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2504 *final_result = ValueObject::eValueObjectList;
2505 return 1;
2506 }
2507 }
2508 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
2509 *what_next == ValueObject::eDereference &&
2510 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2511 {
2512 Error error;
2513 root = root->Dereference(error);
2514 if (error.Fail() || !root.get())
2515 {
2516 *first_unparsed = expression_cstr;
2517 *reason_to_stop = ValueObject::eDereferencingFailed;
2518 *final_result = ValueObject::eInvalid;
2519 return 0;
2520 }
2521 else
2522 {
2523 *what_next = ValueObject::eNothing;
2524 continue;
2525 }
2526 }
2527 else
2528 {
Johnny Chen44805302011-07-19 19:48:13 +00002529 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002530 index <= index_higher; index++)
2531 {
2532 ValueObjectSP child =
2533 root->GetChildAtIndex(index, true);
2534 list->Append(child);
2535 }
2536 *first_unparsed = end+1;
2537 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2538 *final_result = ValueObject::eValueObjectList;
2539 return index_higher-index_lower+1; // tell me number of items I added to the VOList
2540 }
2541 }
2542 break;
2543 }
2544 default: // some non-[ separator, or something entirely wrong, is in the way
2545 {
2546 *first_unparsed = expression_cstr;
2547 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2548 *final_result = ValueObject::eInvalid;
2549 return 0;
2550 break;
2551 }
2552 }
2553 }
2554}
2555
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002556void
Greg Clayton1d3afba2010-10-05 00:00:42 +00002557ValueObject::DumpValueObject
2558(
2559 Stream &s,
Greg Clayton1d3afba2010-10-05 00:00:42 +00002560 ValueObject *valobj,
2561 const char *root_valobj_name,
2562 uint32_t ptr_depth,
2563 uint32_t curr_depth,
2564 uint32_t max_depth,
2565 bool show_types,
2566 bool show_location,
2567 bool use_objc,
Jim Ingham2837b762011-05-04 03:43:18 +00002568 lldb::DynamicValueType use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00002569 bool use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002570 bool scope_already_checked,
Enrico Granata0c5ef692011-07-16 01:22:04 +00002571 bool flat_output,
2572 uint32_t omit_summary_depth
Greg Clayton1d3afba2010-10-05 00:00:42 +00002573)
2574{
Greg Clayton007d5be2011-05-30 00:49:24 +00002575 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002576 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00002577 bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00002578
2579 if (update_success && use_dynamic != lldb::eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00002580 {
Jim Ingham2837b762011-05-04 03:43:18 +00002581 ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00002582 if (dynamic_value)
2583 valobj = dynamic_value;
2584 }
2585
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002586 clang_type_t clang_type = valobj->GetClangType();
2587
Greg Clayton73b472d2010-10-27 03:32:59 +00002588 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002589 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00002590 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
2591 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002592
2593 const bool print_valobj = flat_output == false || has_value;
2594
2595 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002596 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002597 if (show_location)
2598 {
Jim Ingham6035b672011-03-31 00:19:25 +00002599 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002600 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002601
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002602 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00002603
Greg Clayton7c8a9662010-11-02 01:50:16 +00002604 // Always show the type for the top level items.
Greg Claytone221f822011-01-21 01:59:00 +00002605 if (show_types || (curr_depth == 0 && !flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00002606 {
Enrico Granata9910bc82011-08-03 02:18:51 +00002607 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
2608 s.Printf("(%s", typeName);
2609 // only show dynamic types if the user really wants to see types
2610 if (show_types && use_dynamic != lldb::eNoDynamicValues &&
2611 (/*strstr(typeName, "id") == typeName ||*/
2612 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == lldb::eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00002613 {
2614 Process* process = valobj->GetUpdatePoint().GetProcessSP().get();
2615 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00002616 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002617 else
2618 {
2619 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
2620 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00002621 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002622 else
2623 {
2624 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
2625 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00002626 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002627 else
2628 s.Printf(", dynamic type: %s) ",
2629 runtime->GetActualTypeName(isa).GetCString());
2630 }
2631 }
2632 }
2633 else
2634 s.Printf(") ");
2635 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002636
Greg Clayton1d3afba2010-10-05 00:00:42 +00002637
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002638 if (flat_output)
2639 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00002640 // If we are showing types, also qualify the C++ base classes
2641 const bool qualify_cxx_base_classes = show_types;
2642 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002643 s.PutCString(" =");
2644 }
2645 else
2646 {
2647 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
2648 s.Printf ("%s =", name_cstr);
2649 }
2650
Jim Ingham6035b672011-03-31 00:19:25 +00002651 if (!scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002652 {
Greg Clayton007d5be2011-05-30 00:49:24 +00002653 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002654 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002655 }
2656
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002657 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00002658 const char *sum_cstr = NULL;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002659 SummaryFormat* entry = valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002660
Enrico Granata0c5ef692011-07-16 01:22:04 +00002661 if (omit_summary_depth > 0)
2662 entry = NULL;
2663
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002664 if (err_cstr == NULL)
2665 {
Jim Ingham6035b672011-03-31 00:19:25 +00002666 val_cstr = valobj->GetValueAsCString();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002667 err_cstr = valobj->GetError().AsCString();
2668 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002669
2670 if (err_cstr)
2671 {
Greg Clayton007d5be2011-05-30 00:49:24 +00002672 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00002673 }
2674 else
2675 {
Greg Clayton73b472d2010-10-27 03:32:59 +00002676 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002677 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002678 {
Enrico Granata4becb372011-06-29 22:27:15 +00002679
Enrico Granata0c5ef692011-07-16 01:22:04 +00002680 sum_cstr = (omit_summary_depth == 0) ? valobj->GetSummaryAsCString() : NULL;
Greg Clayton1d3afba2010-10-05 00:00:42 +00002681
Enrico Granata4becb372011-06-29 22:27:15 +00002682 // We must calculate this value in realtime because entry might alter this variable's value
2683 // (e.g. by saying ${var%fmt}) and render precached values useless
2684 if (val_cstr && (!entry || entry->DoesPrintValue() || !sum_cstr))
2685 s.Printf(" %s", valobj->GetValueAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002686
Enrico Granata9dd75c82011-07-15 23:30:15 +00002687 if (sum_cstr)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002688 {
2689 // for some reason, using %@ (ObjC description) in a summary string, makes
2690 // us believe we need to reset ourselves, thus invalidating the content of
2691 // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty
2692 // let us recalculate it!
2693 if (sum_cstr[0] == '\0')
2694 s.Printf(" %s", valobj->GetSummaryAsCString());
2695 else
2696 s.Printf(" %s", sum_cstr);
2697 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002698
2699 if (use_objc)
2700 {
Jim Ingham6035b672011-03-31 00:19:25 +00002701 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002702 if (object_desc)
2703 s.Printf(" %s\n", object_desc);
2704 else
Sean Callanan672ad942010-10-23 00:18:49 +00002705 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002706 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00002707 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002708 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002709
2710 if (curr_depth < max_depth)
2711 {
Greg Clayton73b472d2010-10-27 03:32:59 +00002712 // We will show children for all concrete types. We won't show
2713 // pointer contents unless a pointer depth has been specified.
2714 // We won't reference contents unless the reference is the
2715 // root object (depth of zero).
2716 bool print_children = true;
2717
2718 // Use a new temporary pointer depth in case we override the
2719 // current pointer depth below...
2720 uint32_t curr_ptr_depth = ptr_depth;
2721
2722 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
2723 if (is_ptr || is_ref)
2724 {
2725 // We have a pointer or reference whose value is an address.
2726 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00002727 AddressType ptr_address_type;
Greg Clayton73b472d2010-10-27 03:32:59 +00002728 if (valobj->GetPointerValue (ptr_address_type, true) == 0)
2729 print_children = false;
2730
2731 else if (is_ref && curr_depth == 0)
2732 {
2733 // If this is the root object (depth is zero) that we are showing
2734 // and it is a reference, and no pointer depth has been supplied
2735 // print out what it references. Don't do this at deeper depths
2736 // otherwise we can end up with infinite recursion...
2737 curr_ptr_depth = 1;
2738 }
2739
2740 if (curr_ptr_depth == 0)
2741 print_children = false;
2742 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002743
Enrico Granata0a3958e2011-07-02 00:25:22 +00002744 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00002745 {
Enrico Granatad55546b2011-07-22 00:16:08 +00002746 ValueObjectSP synth_vobj = valobj->GetSyntheticValue(use_synth ?
2747 lldb::eUseSyntheticFilter :
2748 lldb::eNoSyntheticFilter);
2749 const uint32_t num_children = synth_vobj->GetNumChildren();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002750 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002751 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002752 if (flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002753 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002754 if (print_valobj)
2755 s.EOL();
2756 }
2757 else
2758 {
2759 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00002760 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002761 s.IndentMore();
2762 }
2763
2764 for (uint32_t idx=0; idx<num_children; ++idx)
2765 {
Enrico Granatad55546b2011-07-22 00:16:08 +00002766 ValueObjectSP child_sp(synth_vobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002767 if (child_sp.get())
2768 {
2769 DumpValueObject (s,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002770 child_sp.get(),
2771 NULL,
Greg Clayton73b472d2010-10-27 03:32:59 +00002772 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002773 curr_depth + 1,
2774 max_depth,
2775 show_types,
2776 show_location,
2777 false,
Jim Ingham78a685a2011-04-16 00:01:13 +00002778 use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00002779 use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002780 true,
Enrico Granata0c5ef692011-07-16 01:22:04 +00002781 flat_output,
2782 omit_summary_depth > 1 ? omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002783 }
2784 }
2785
2786 if (!flat_output)
2787 {
2788 s.IndentLess();
2789 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00002790 }
2791 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002792 else if (has_children)
2793 {
2794 // Aggregate, no children...
2795 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00002796 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002797 }
2798 else
2799 {
2800 if (print_valobj)
2801 s.EOL();
2802 }
2803
Greg Clayton1d3afba2010-10-05 00:00:42 +00002804 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002805 else
2806 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00002807 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00002808 }
2809 }
2810 else
2811 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002812 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002813 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002814 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00002815 }
2816 }
2817 }
2818 }
2819}
2820
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002821
2822ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00002823ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002824{
2825 ValueObjectSP valobj_sp;
2826
Enrico Granatac3e320a2011-08-02 17:27:39 +00002827 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002828 {
Jim Ingham6035b672011-03-31 00:19:25 +00002829 ExecutionContextScope *exe_scope = GetExecutionContextScope();
2830 if (exe_scope)
2831 {
2832 ExecutionContext exe_ctx;
2833 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002834
Jim Ingham6035b672011-03-31 00:19:25 +00002835 clang::ASTContext *ast = GetClangAST ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002836
Jim Ingham6035b672011-03-31 00:19:25 +00002837 DataExtractor data;
2838 data.SetByteOrder (m_data.GetByteOrder());
2839 data.SetAddressByteSize(m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002840
Greg Clayton644247c2011-07-07 01:59:51 +00002841 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002842
Jim Ingham58b59f92011-04-22 23:53:53 +00002843 valobj_sp = ValueObjectConstResult::Create (exe_scope,
2844 ast,
2845 GetClangType(),
2846 name,
2847 data);
Jim Ingham6035b672011-03-31 00:19:25 +00002848 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002849 }
Jim Ingham6035b672011-03-31 00:19:25 +00002850
2851 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002852 {
Jim Ingham58b59f92011-04-22 23:53:53 +00002853 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002854 }
2855 return valobj_sp;
2856}
2857
2858lldb::ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00002859ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002860{
Jim Ingham58b59f92011-04-22 23:53:53 +00002861 if (m_deref_valobj)
2862 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00002863
Greg Clayton54979cd2010-12-15 05:08:08 +00002864 const bool is_pointer_type = IsPointerType();
2865 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002866 {
2867 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00002868 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002869
2870 std::string child_name_str;
2871 uint32_t child_byte_size = 0;
2872 int32_t child_byte_offset = 0;
2873 uint32_t child_bitfield_bit_size = 0;
2874 uint32_t child_bitfield_bit_offset = 0;
2875 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00002876 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002877 const bool transparent_pointers = false;
2878 clang::ASTContext *clang_ast = GetClangAST();
2879 clang_type_t clang_type = GetClangType();
2880 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00002881
2882 ExecutionContext exe_ctx;
2883 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
2884
2885 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
2886 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002887 GetName().GetCString(),
2888 clang_type,
2889 0,
2890 transparent_pointers,
2891 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00002892 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002893 child_name_str,
2894 child_byte_size,
2895 child_byte_offset,
2896 child_bitfield_bit_size,
2897 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00002898 child_is_base_class,
2899 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00002900 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002901 {
2902 ConstString child_name;
2903 if (!child_name_str.empty())
2904 child_name.SetCString (child_name_str.c_str());
2905
Jim Ingham58b59f92011-04-22 23:53:53 +00002906 m_deref_valobj = new ValueObjectChild (*this,
2907 clang_ast,
2908 child_clang_type,
2909 child_name,
2910 child_byte_size,
2911 child_byte_offset,
2912 child_bitfield_bit_size,
2913 child_bitfield_bit_offset,
2914 child_is_base_class,
2915 child_is_deref_of_parent);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002916 }
2917 }
Greg Clayton54979cd2010-12-15 05:08:08 +00002918
Jim Ingham58b59f92011-04-22 23:53:53 +00002919 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00002920 {
2921 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00002922 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00002923 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002924 else
2925 {
Greg Clayton54979cd2010-12-15 05:08:08 +00002926 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00002927 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00002928
2929 if (is_pointer_type)
2930 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
2931 else
2932 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00002933 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002934 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002935}
2936
Jim Ingham78a685a2011-04-16 00:01:13 +00002937lldb::ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00002938ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002939{
Jim Ingham78a685a2011-04-16 00:01:13 +00002940 if (m_addr_of_valobj_sp)
2941 return m_addr_of_valobj_sp;
2942
Greg Claytone0d378b2011-03-24 21:19:54 +00002943 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002944 const bool scalar_is_load_address = false;
2945 lldb::addr_t addr = GetAddressOf (address_type, scalar_is_load_address);
Greg Clayton54979cd2010-12-15 05:08:08 +00002946 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002947 if (addr != LLDB_INVALID_ADDRESS)
2948 {
2949 switch (address_type)
2950 {
Greg Clayton54979cd2010-12-15 05:08:08 +00002951 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002952 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00002953 {
2954 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00002955 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00002956 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
2957 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002958 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00002959
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002960 case eAddressTypeFile:
2961 case eAddressTypeLoad:
2962 case eAddressTypeHost:
2963 {
2964 clang::ASTContext *ast = GetClangAST();
2965 clang_type_t clang_type = GetClangType();
2966 if (ast && clang_type)
2967 {
2968 std::string name (1, '&');
2969 name.append (m_name.AsCString(""));
Jim Ingham58b59f92011-04-22 23:53:53 +00002970 m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(),
2971 ast,
2972 ClangASTContext::CreatePointerType (ast, clang_type),
2973 ConstString (name.c_str()),
2974 addr,
2975 eAddressTypeInvalid,
2976 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002977 }
2978 }
2979 break;
2980 }
2981 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002982 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002983}
2984
Greg Claytonb2dcc362011-05-05 23:32:56 +00002985
2986lldb::ValueObjectSP
2987ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
2988{
2989 lldb::ValueObjectSP valobj_sp;
2990 AddressType address_type;
2991 const bool scalar_is_load_address = true;
2992 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address);
2993
2994 if (ptr_value != LLDB_INVALID_ADDRESS)
2995 {
2996 Address ptr_addr (NULL, ptr_value);
2997
2998 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
2999 name,
3000 ptr_addr,
3001 clang_ast_type);
3002 }
3003 return valobj_sp;
3004}
3005
3006lldb::ValueObjectSP
3007ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3008{
3009 lldb::ValueObjectSP valobj_sp;
3010 AddressType address_type;
3011 const bool scalar_is_load_address = true;
3012 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address);
3013
3014 if (ptr_value != LLDB_INVALID_ADDRESS)
3015 {
3016 Address ptr_addr (NULL, ptr_value);
3017
3018 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3019 name,
3020 ptr_addr,
3021 type_sp);
3022 }
3023 return valobj_sp;
3024}
3025
Jim Ingham6035b672011-03-31 00:19:25 +00003026ValueObject::EvaluationPoint::EvaluationPoint () :
Stephen Wilson71c21d12011-04-11 19:41:40 +00003027 m_thread_id (LLDB_INVALID_UID),
3028 m_stop_id (0)
Jim Ingham6035b672011-03-31 00:19:25 +00003029{
3030}
3031
3032ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Jim Ingham6035b672011-03-31 00:19:25 +00003033 m_needs_update (true),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003034 m_first_update (true),
Jim Ingham89b61092011-07-06 17:42:14 +00003035 m_thread_id (LLDB_INVALID_THREAD_ID),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003036 m_stop_id (0)
3037
Jim Ingham6035b672011-03-31 00:19:25 +00003038{
3039 ExecutionContext exe_ctx;
3040 ExecutionContextScope *computed_exe_scope = exe_scope; // If use_selected is true, we may find a better scope,
3041 // and if so we want to cache that not the original.
3042 if (exe_scope)
3043 exe_scope->CalculateExecutionContext(exe_ctx);
3044 if (exe_ctx.target != NULL)
3045 {
3046 m_target_sp = exe_ctx.target->GetSP();
3047
3048 if (exe_ctx.process == NULL)
3049 m_process_sp = exe_ctx.target->GetProcessSP();
3050 else
3051 m_process_sp = exe_ctx.process->GetSP();
3052
3053 if (m_process_sp != NULL)
3054 {
3055 m_stop_id = m_process_sp->GetStopID();
3056 Thread *thread = NULL;
3057
3058 if (exe_ctx.thread == NULL)
3059 {
3060 if (use_selected)
3061 {
3062 thread = m_process_sp->GetThreadList().GetSelectedThread().get();
3063 if (thread)
3064 computed_exe_scope = thread;
3065 }
3066 }
3067 else
3068 thread = exe_ctx.thread;
3069
3070 if (thread != NULL)
3071 {
3072 m_thread_id = thread->GetIndexID();
3073 if (exe_ctx.frame == NULL)
3074 {
3075 if (use_selected)
3076 {
3077 StackFrame *frame = exe_ctx.thread->GetSelectedFrame().get();
3078 if (frame)
3079 {
3080 m_stack_id = frame->GetStackID();
3081 computed_exe_scope = frame;
3082 }
3083 }
3084 }
3085 else
3086 m_stack_id = exe_ctx.frame->GetStackID();
3087 }
3088 }
3089 }
3090 m_exe_scope = computed_exe_scope;
3091}
3092
3093ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
3094 m_exe_scope (rhs.m_exe_scope),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003095 m_needs_update(true),
3096 m_first_update(true),
Jim Ingham6035b672011-03-31 00:19:25 +00003097 m_target_sp (rhs.m_target_sp),
3098 m_process_sp (rhs.m_process_sp),
3099 m_thread_id (rhs.m_thread_id),
3100 m_stack_id (rhs.m_stack_id),
Jim Ingham6035b672011-03-31 00:19:25 +00003101 m_stop_id (0)
3102{
3103}
3104
3105ValueObject::EvaluationPoint::~EvaluationPoint ()
3106{
3107}
3108
3109ExecutionContextScope *
3110ValueObject::EvaluationPoint::GetExecutionContextScope ()
3111{
3112 // We have to update before giving out the scope, or we could be handing out stale pointers.
3113 SyncWithProcessState();
3114
3115 return m_exe_scope;
3116}
3117
3118// This function checks the EvaluationPoint against the current process state. If the current
3119// state matches the evaluation point, or the evaluation point is already invalid, then we return
3120// false, meaning "no change". If the current state is different, we update our state, and return
3121// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3122// future calls to NeedsUpdate will return true.
3123
3124bool
3125ValueObject::EvaluationPoint::SyncWithProcessState()
3126{
3127 // If we're already invalid, we don't need to do anything, and nothing has changed:
3128 if (m_stop_id == LLDB_INVALID_UID)
3129 {
3130 // Can't update with an invalid state.
3131 m_needs_update = false;
3132 return false;
3133 }
3134
3135 // If we don't have a process nothing can change.
3136 if (!m_process_sp)
3137 return false;
3138
3139 // If our stop id is the current stop ID, nothing has changed:
Jim Ingham78a685a2011-04-16 00:01:13 +00003140 uint32_t cur_stop_id = m_process_sp->GetStopID();
3141 if (m_stop_id == cur_stop_id)
Jim Ingham6035b672011-03-31 00:19:25 +00003142 return false;
3143
Jim Ingham78a685a2011-04-16 00:01:13 +00003144 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3145 // In either case, we aren't going to be able to sync with the process state.
3146 if (cur_stop_id == 0)
3147 return false;
3148
3149 m_stop_id = cur_stop_id;
Jim Ingham6035b672011-03-31 00:19:25 +00003150 m_needs_update = true;
3151 m_exe_scope = m_process_sp.get();
3152
3153 // Something has changed, so we will return true. Now make sure the thread & frame still exist, and if either
3154 // doesn't, mark ourselves as invalid.
3155
3156 if (m_thread_id != LLDB_INVALID_THREAD_ID)
3157 {
3158 Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get();
3159 if (our_thread == NULL)
Greg Clayton262f80d2011-07-06 16:49:27 +00003160 {
Jim Ingham89b61092011-07-06 17:42:14 +00003161 SetInvalid();
Greg Clayton262f80d2011-07-06 16:49:27 +00003162 }
Jim Ingham6035b672011-03-31 00:19:25 +00003163 else
3164 {
3165 m_exe_scope = our_thread;
3166
3167 if (m_stack_id.IsValid())
3168 {
3169 StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get();
3170 if (our_frame == NULL)
3171 SetInvalid();
3172 else
3173 m_exe_scope = our_frame;
3174 }
3175 }
3176 }
3177 return true;
3178}
3179
Jim Ingham61be0902011-05-02 18:13:59 +00003180void
3181ValueObject::EvaluationPoint::SetUpdated ()
3182{
3183 m_first_update = false;
3184 m_needs_update = false;
3185 if (m_process_sp)
3186 m_stop_id = m_process_sp->GetStopID();
3187}
3188
3189
Jim Ingham6035b672011-03-31 00:19:25 +00003190bool
3191ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3192{
3193 if (!IsValid())
3194 return false;
3195
3196 bool needs_update = false;
3197 m_exe_scope = NULL;
3198
3199 // The target has to be non-null, and the
3200 Target *target = exe_scope->CalculateTarget();
3201 if (target != NULL)
3202 {
3203 Target *old_target = m_target_sp.get();
3204 assert (target == old_target);
3205 Process *process = exe_scope->CalculateProcess();
3206 if (process != NULL)
3207 {
3208 // FOR NOW - assume you can't update variable objects across process boundaries.
3209 Process *old_process = m_process_sp.get();
3210 assert (process == old_process);
3211
3212 lldb::user_id_t stop_id = process->GetStopID();
3213 if (stop_id != m_stop_id)
3214 {
3215 needs_update = true;
3216 m_stop_id = stop_id;
3217 }
3218 // See if we're switching the thread or stack context. If no thread is given, this is
3219 // being evaluated in a global context.
3220 Thread *thread = exe_scope->CalculateThread();
3221 if (thread != NULL)
3222 {
3223 lldb::user_id_t new_thread_index = thread->GetIndexID();
3224 if (new_thread_index != m_thread_id)
3225 {
3226 needs_update = true;
3227 m_thread_id = new_thread_index;
3228 m_stack_id.Clear();
3229 }
3230
3231 StackFrame *new_frame = exe_scope->CalculateStackFrame();
3232 if (new_frame != NULL)
3233 {
3234 if (new_frame->GetStackID() != m_stack_id)
3235 {
3236 needs_update = true;
3237 m_stack_id = new_frame->GetStackID();
3238 }
3239 }
3240 else
3241 {
3242 m_stack_id.Clear();
3243 needs_update = true;
3244 }
3245 }
3246 else
3247 {
3248 // If this had been given a thread, and now there is none, we should update.
3249 // Otherwise we don't have to do anything.
3250 if (m_thread_id != LLDB_INVALID_UID)
3251 {
3252 m_thread_id = LLDB_INVALID_UID;
3253 m_stack_id.Clear();
3254 needs_update = true;
3255 }
3256 }
3257 }
3258 else
3259 {
3260 // If there is no process, then we don't need to update anything.
3261 // But if we're switching from having a process to not, we should try to update.
3262 if (m_process_sp.get() != NULL)
3263 {
3264 needs_update = true;
3265 m_process_sp.reset();
3266 m_thread_id = LLDB_INVALID_UID;
3267 m_stack_id.Clear();
3268 }
3269 }
3270 }
3271 else
3272 {
3273 // If there's no target, nothing can change so we don't need to update anything.
3274 // But if we're switching from having a target to not, we should try to update.
3275 if (m_target_sp.get() != NULL)
3276 {
3277 needs_update = true;
3278 m_target_sp.reset();
3279 m_process_sp.reset();
3280 m_thread_id = LLDB_INVALID_UID;
3281 m_stack_id.Clear();
3282 }
3283 }
3284 if (!m_needs_update)
3285 m_needs_update = needs_update;
3286
3287 return needs_update;
3288}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003289
3290void
3291ValueObject::ClearUserVisibleData()
3292{
3293 m_location_str.clear();
3294 m_value_str.clear();
3295 m_summary_str.clear();
3296 m_object_desc_str.clear();
Johnny Chen44805302011-07-19 19:48:13 +00003297}