blob: 1453ee23714a69530746f5ac48d44887f8c04827 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/ValueObject.h"
11
12// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000013#include <stdlib.h>
14
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015// C++ Includes
16// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000018#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
20// Project includes
21#include "lldb/Core/DataBufferHeap.h"
Enrico Granata4becb372011-06-29 22:27:15 +000022#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000023#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Core/StreamString.h"
25#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000026#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000027#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000029#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000030#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031
Greg Clayton7fb56d02011-02-01 01:31:41 +000032#include "lldb/Host/Endian.h"
33
Enrico Granataf2bbf712011-07-15 02:26:42 +000034#include "lldb/Interpreter/ScriptInterpreterPython.h"
35
Greg Claytone1a916a2010-07-21 22:12:05 +000036#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037#include "lldb/Symbol/ClangASTContext.h"
38#include "lldb/Symbol/Type.h"
39
Jim Ingham53c47f12010-09-10 23:12:17 +000040#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000041#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000042#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Target/Process.h"
44#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000045#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047
Enrico Granataf4efecd2011-07-12 22:56:10 +000048#include "lldb/Utility/RefCounter.h"
49
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050using namespace lldb;
51using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000052using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053
54static lldb::user_id_t g_value_obj_uid = 0;
55
56//----------------------------------------------------------------------
57// ValueObject constructor
58//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000059ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000061 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000062 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063 m_name (),
64 m_data (),
65 m_value (),
66 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000067 m_value_str (),
68 m_old_value_str (),
69 m_location_str (),
70 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000071 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000072 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000073 m_children (),
74 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000075 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000076 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000077 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000078 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000079 m_last_format_mgr_revision(0),
Enrico Granatad8b5fce2011-08-02 23:12:24 +000080 m_last_format_mgr_dynamic(parent.m_last_format_mgr_dynamic),
Enrico Granata9df29e32011-07-19 20:57:44 +000081 m_last_summary_format(),
82 m_forced_summary_format(),
83 m_last_value_format(),
Enrico Granatad55546b2011-07-22 00:16:08 +000084 m_last_synthetic_filter(),
Enrico Granata9df29e32011-07-19 20:57:44 +000085 m_user_id_of_forced_summary(0),
Greg Clayton288bdf92010-09-02 02:59:18 +000086 m_value_is_valid (false),
87 m_value_did_change (false),
88 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000089 m_old_value_valid (false),
Greg Claytone221f822011-01-21 01:59:00 +000090 m_pointers_point_to_load_addrs (false),
Enrico Granata4becb372011-06-29 22:27:15 +000091 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000092 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000093 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +000094 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000095 m_is_child_at_offset(false),
Enrico Granata9910bc82011-08-03 02:18:51 +000096 m_is_expression_result(parent.m_is_expression_result),
Enrico Granataf4efecd2011-07-12 22:56:10 +000097 m_dump_printable_counter(0)
Jim Ingham6035b672011-03-31 00:19:25 +000098{
Jim Ingham58b59f92011-04-22 23:53:53 +000099 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000100}
101
102//----------------------------------------------------------------------
103// ValueObject constructor
104//----------------------------------------------------------------------
105ValueObject::ValueObject (ExecutionContextScope *exe_scope) :
106 UserID (++g_value_obj_uid), // Unique identifier for every value object
107 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000108 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000109 m_name (),
110 m_data (),
111 m_value (),
112 m_error (),
113 m_value_str (),
114 m_old_value_str (),
115 m_location_str (),
116 m_summary_str (),
117 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000118 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000119 m_children (),
120 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000121 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000122 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000123 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000124 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000125 m_last_format_mgr_revision(0),
Enrico Granatac3e320a2011-08-02 17:27:39 +0000126 m_last_format_mgr_dynamic(lldb::eNoDynamicValues),
Enrico Granata9df29e32011-07-19 20:57:44 +0000127 m_last_summary_format(),
128 m_forced_summary_format(),
129 m_last_value_format(),
Enrico Granatad55546b2011-07-22 00:16:08 +0000130 m_last_synthetic_filter(),
Enrico Granata9df29e32011-07-19 20:57:44 +0000131 m_user_id_of_forced_summary(0),
Jim Ingham6035b672011-03-31 00:19:25 +0000132 m_value_is_valid (false),
133 m_value_did_change (false),
134 m_children_count_valid (false),
135 m_old_value_valid (false),
136 m_pointers_point_to_load_addrs (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000137 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000138 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000139 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000140 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000141 m_is_child_at_offset(false),
Enrico Granatac3e320a2011-08-02 17:27:39 +0000142 m_is_expression_result(false),
Enrico Granataf4efecd2011-07-12 22:56:10 +0000143 m_dump_printable_counter(0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000144{
Jim Ingham58b59f92011-04-22 23:53:53 +0000145 m_manager = new ValueObjectManager();
146 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147}
148
149//----------------------------------------------------------------------
150// Destructor
151//----------------------------------------------------------------------
152ValueObject::~ValueObject ()
153{
154}
155
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000157ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000159 return UpdateValueIfNeeded(m_last_format_mgr_dynamic, update_format);
160}
161
162bool
163ValueObject::UpdateValueIfNeeded (lldb::DynamicValueType use_dynamic, bool update_format)
164{
Enrico Granata4becb372011-06-29 22:27:15 +0000165
Enrico Granata0a3958e2011-07-02 00:25:22 +0000166 if (update_format)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000167 UpdateFormatsIfNeeded(use_dynamic);
Enrico Granata4becb372011-06-29 22:27:15 +0000168
Greg Claytonb71f3842010-10-05 03:13:51 +0000169 // If this is a constant value, then our success is predicated on whether
170 // we have an error or not
171 if (GetIsConstant())
172 return m_error.Success();
173
Jim Ingham6035b672011-03-31 00:19:25 +0000174 bool first_update = m_update_point.IsFirstEvaluation();
175
176 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000177 {
Jim Ingham6035b672011-03-31 00:19:25 +0000178 m_update_point.SetUpdated();
179
180 // Save the old value using swap to avoid a string copy which
181 // also will clear our m_value_str
182 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000183 {
Jim Ingham6035b672011-03-31 00:19:25 +0000184 m_old_value_valid = false;
185 }
186 else
187 {
188 m_old_value_valid = true;
189 m_old_value_str.swap (m_value_str);
190 m_value_str.clear();
191 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192
Enrico Granataf2bbf712011-07-15 02:26:42 +0000193 ClearUserVisibleData();
194
Jim Ingham6035b672011-03-31 00:19:25 +0000195 const bool value_was_valid = GetValueIsValid();
196 SetValueDidChange (false);
Greg Clayton73b953b2010-08-28 00:08:07 +0000197
Jim Ingham6035b672011-03-31 00:19:25 +0000198 m_error.Clear();
Greg Clayton73b953b2010-08-28 00:08:07 +0000199
Jim Ingham6035b672011-03-31 00:19:25 +0000200 // Call the pure virtual function to update the value
201 bool success = UpdateValue ();
202
203 SetValueIsValid (success);
204
205 if (first_update)
206 SetValueDidChange (false);
207 else if (!m_value_did_change && success == false)
208 {
209 // The value wasn't gotten successfully, so we mark this
210 // as changed if the value used to be valid and now isn't
211 SetValueDidChange (value_was_valid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000212 }
213 }
214 return m_error.Success();
215}
216
Enrico Granata4becb372011-06-29 22:27:15 +0000217void
Enrico Granatac3e320a2011-08-02 17:27:39 +0000218ValueObject::UpdateFormatsIfNeeded(lldb::DynamicValueType use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000219{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000220 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
221 if (log)
222 log->Printf("checking for FormatManager revisions. VO named %s is at revision %d, while the format manager is at revision %d",
223 GetName().GetCString(),
Enrico Granata4becb372011-06-29 22:27:15 +0000224 m_last_format_mgr_revision,
Enrico Granata6f3533f2011-07-29 19:53:35 +0000225 Debugger::Formatting::ValueFormats::GetCurrentRevision());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000226 if (HasCustomSummaryFormat() && m_update_point.GetUpdateID() != m_user_id_of_forced_summary)
227 {
228 ClearCustomSummaryFormat();
229 m_summary_str.clear();
230 }
Enrico Granatac3e320a2011-08-02 17:27:39 +0000231 if ( (m_last_format_mgr_revision != Debugger::Formatting::ValueFormats::GetCurrentRevision()) ||
232 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000233 {
234 if (m_last_summary_format.get())
Enrico Granataf2bbf712011-07-15 02:26:42 +0000235 m_last_summary_format.reset((StringSummaryFormat*)NULL);
Enrico Granata4becb372011-06-29 22:27:15 +0000236 if (m_last_value_format.get())
Enrico Granatad55546b2011-07-22 00:16:08 +0000237 m_last_value_format.reset(/*(ValueFormat*)NULL*/);
238 if (m_last_synthetic_filter.get())
239 m_last_synthetic_filter.reset(/*(SyntheticFilter*)NULL*/);
Enrico Granataa37a0652011-07-24 00:14:56 +0000240
241 m_synthetic_value = NULL;
Enrico Granata1490c6f2011-07-19 02:34:21 +0000242
Enrico Granata9910bc82011-08-03 02:18:51 +0000243 Debugger::Formatting::ValueFormats::Get(*this, lldb::eNoDynamicValues, m_last_value_format);
Enrico Granatac3e320a2011-08-02 17:27:39 +0000244 Debugger::Formatting::GetSummaryFormat(*this, use_dynamic, m_last_summary_format);
245 Debugger::Formatting::GetSyntheticFilter(*this, use_dynamic, m_last_synthetic_filter);
Enrico Granata1490c6f2011-07-19 02:34:21 +0000246
247 m_last_format_mgr_revision = Debugger::Formatting::ValueFormats::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000248 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granataf2bbf712011-07-15 02:26:42 +0000249
250 ClearUserVisibleData();
Enrico Granata4becb372011-06-29 22:27:15 +0000251 }
252}
253
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000254DataExtractor &
255ValueObject::GetDataExtractor ()
256{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000257 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000258 return m_data;
259}
260
261const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000262ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000263{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000264 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265 return m_error;
266}
267
268const ConstString &
269ValueObject::GetName() const
270{
271 return m_name;
272}
273
274const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000275ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000277 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278 {
279 if (m_location_str.empty())
280 {
281 StreamString sstr;
282
283 switch (m_value.GetValueType())
284 {
285 default:
286 break;
287
288 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000289 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000290 {
291 RegisterInfo *reg_info = m_value.GetRegisterInfo();
292 if (reg_info)
293 {
294 if (reg_info->name)
295 m_location_str = reg_info->name;
296 else if (reg_info->alt_name)
297 m_location_str = reg_info->alt_name;
298 break;
299 }
300 }
301 m_location_str = "scalar";
302 break;
303
304 case Value::eValueTypeLoadAddress:
305 case Value::eValueTypeFileAddress:
306 case Value::eValueTypeHostAddress:
307 {
308 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
309 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
310 m_location_str.swap(sstr.GetString());
311 }
312 break;
313 }
314 }
315 }
316 return m_location_str.c_str();
317}
318
319Value &
320ValueObject::GetValue()
321{
322 return m_value;
323}
324
325const Value &
326ValueObject::GetValue() const
327{
328 return m_value;
329}
330
331bool
Jim Ingham6035b672011-03-31 00:19:25 +0000332ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000333{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000334 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
335 {
336 ExecutionContext exe_ctx;
337 ExecutionContextScope *exe_scope = GetExecutionContextScope();
338 if (exe_scope)
339 exe_scope->CalculateExecutionContext(exe_ctx);
340 scalar = m_value.ResolveValue(&exe_ctx, GetClangAST ());
341 return scalar.IsValid();
342 }
343 else
344 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000345}
346
347bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000348ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000349{
Greg Clayton288bdf92010-09-02 02:59:18 +0000350 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351}
352
353
354void
355ValueObject::SetValueIsValid (bool b)
356{
Greg Clayton288bdf92010-09-02 02:59:18 +0000357 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000358}
359
360bool
Jim Ingham6035b672011-03-31 00:19:25 +0000361ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000362{
Jim Ingham6035b672011-03-31 00:19:25 +0000363 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000364 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000365}
366
367void
368ValueObject::SetValueDidChange (bool value_changed)
369{
Greg Clayton288bdf92010-09-02 02:59:18 +0000370 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000371}
372
373ValueObjectSP
374ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
375{
376 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000377 // We may need to update our value if we are dynamic
378 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000379 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000380 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000382 // Check if we have already made the child value object?
383 if (can_create && m_children[idx] == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000385 // No we haven't created the child at this index, so lets have our
386 // subclass do it and cache the result for quick future access.
387 m_children[idx] = CreateChildAtIndex (idx, false, 0);
Jim Ingham78a685a2011-04-16 00:01:13 +0000388 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000389
390 if (m_children[idx] != NULL)
391 return m_children[idx]->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392 }
393 return child_sp;
394}
395
396uint32_t
397ValueObject::GetIndexOfChildWithName (const ConstString &name)
398{
399 bool omit_empty_base_classes = true;
400 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000401 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000402 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403 omit_empty_base_classes);
404}
405
406ValueObjectSP
407ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
408{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000409 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410 // classes (which really aren't part of the expression path), so we
411 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000413
Greg Claytondea8cb42011-06-29 22:09:02 +0000414 // We may need to update our value if we are dynamic
415 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000416 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000417
418 std::vector<uint32_t> child_indexes;
419 clang::ASTContext *clang_ast = GetClangAST();
420 void *clang_type = GetClangType();
421 bool omit_empty_base_classes = true;
422 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
423 clang_type,
424 name.GetCString(),
425 omit_empty_base_classes,
426 child_indexes);
427 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000429 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
430 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
431
432 child_sp = GetChildAtIndex(*pos, can_create);
433 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000435 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000436 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000437 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
438 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000439 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000440 else
441 {
442 child_sp.reset();
443 }
444
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445 }
446 }
447 return child_sp;
448}
449
450
451uint32_t
452ValueObject::GetNumChildren ()
453{
Greg Clayton288bdf92010-09-02 02:59:18 +0000454 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 {
456 SetNumChildren (CalculateNumChildren());
457 }
458 return m_children.size();
459}
460void
461ValueObject::SetNumChildren (uint32_t num_children)
462{
Greg Clayton288bdf92010-09-02 02:59:18 +0000463 m_children_count_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464 m_children.resize(num_children);
465}
466
467void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468ValueObject::SetName (const ConstString &name)
469{
470 m_name = name;
471}
472
Jim Ingham58b59f92011-04-22 23:53:53 +0000473ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000474ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
475{
Jim Ingham2eec4872011-05-07 00:10:58 +0000476 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000477
Greg Claytondea8cb42011-06-29 22:09:02 +0000478 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000479 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000480 std::string child_name_str;
481 uint32_t child_byte_size = 0;
482 int32_t child_byte_offset = 0;
483 uint32_t child_bitfield_bit_size = 0;
484 uint32_t child_bitfield_bit_offset = 0;
485 bool child_is_base_class = false;
486 bool child_is_deref_of_parent = false;
487
488 const bool transparent_pointers = synthetic_array_member == false;
489 clang::ASTContext *clang_ast = GetClangAST();
490 clang_type_t clang_type = GetClangType();
491 clang_type_t child_clang_type;
492
493 ExecutionContext exe_ctx;
494 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
495
496 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
497 clang_ast,
498 GetName().GetCString(),
499 clang_type,
500 idx,
501 transparent_pointers,
502 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000503 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000504 child_name_str,
505 child_byte_size,
506 child_byte_offset,
507 child_bitfield_bit_size,
508 child_bitfield_bit_offset,
509 child_is_base_class,
510 child_is_deref_of_parent);
511 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000512 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000513 if (synthetic_index)
514 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000515
Greg Claytondea8cb42011-06-29 22:09:02 +0000516 ConstString child_name;
517 if (!child_name_str.empty())
518 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519
Greg Claytondea8cb42011-06-29 22:09:02 +0000520 valobj = new ValueObjectChild (*this,
521 clang_ast,
522 child_clang_type,
523 child_name,
524 child_byte_size,
525 child_byte_offset,
526 child_bitfield_bit_size,
527 child_bitfield_bit_offset,
528 child_is_base_class,
529 child_is_deref_of_parent);
530 if (m_pointers_point_to_load_addrs)
531 valobj->SetPointersPointToLoadAddrs (m_pointers_point_to_load_addrs);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000532 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000533
Jim Ingham58b59f92011-04-22 23:53:53 +0000534 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000535}
536
537const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000538ValueObject::GetSummaryAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000539{
Enrico Granatad8b5fce2011-08-02 23:12:24 +0000540 if (UpdateValueIfNeeded (true))
Enrico Granata4becb372011-06-29 22:27:15 +0000541 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542 if (m_summary_str.empty())
543 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000544 SummaryFormat *summary_format = GetSummaryFormat().get();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000545
546 if (summary_format)
Enrico Granata4becb372011-06-29 22:27:15 +0000547 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000548 m_summary_str = summary_format->FormatObject(GetSP());
Enrico Granata4becb372011-06-29 22:27:15 +0000549 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000550 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000551 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000552 clang_type_t clang_type = GetClangType();
Greg Clayton737b9322010-09-13 03:32:57 +0000553
Enrico Granata9dd75c82011-07-15 23:30:15 +0000554 // Do some default printout for function pointers
Enrico Granataf2bbf712011-07-15 02:26:42 +0000555 if (clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000556 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000557 StreamString sstr;
558 clang_type_t elem_or_pointee_clang_type;
559 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
560 GetClangAST(),
561 &elem_or_pointee_clang_type));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000562
Enrico Granataf2bbf712011-07-15 02:26:42 +0000563 ExecutionContextScope *exe_scope = GetExecutionContextScope();
564 if (exe_scope)
565 {
Enrico Granata9dd75c82011-07-15 23:30:15 +0000566 if (ClangASTContext::IsFunctionPointerType (clang_type))
Jim Ingham6035b672011-03-31 00:19:25 +0000567 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000568 AddressType func_ptr_address_type = eAddressTypeInvalid;
569 lldb::addr_t func_ptr_address = GetPointerValue (func_ptr_address_type, true);
570
571 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
572 {
573 switch (func_ptr_address_type)
574 {
575 case eAddressTypeInvalid:
576 case eAddressTypeFile:
577 break;
578
579 case eAddressTypeLoad:
580 {
581 Address so_addr;
582 Target *target = exe_scope->CalculateTarget();
583 if (target && target->GetSectionLoadList().IsEmpty() == false)
584 {
585 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
586 {
587 so_addr.Dump (&sstr,
588 exe_scope,
589 Address::DumpStyleResolvedDescription,
590 Address::DumpStyleSectionNameOffset);
591 }
592 }
593 }
594 break;
595
596 case eAddressTypeHost:
597 break;
598 }
599 }
600 if (sstr.GetSize() > 0)
601 {
602 m_summary_str.assign (1, '(');
603 m_summary_str.append (sstr.GetData(), sstr.GetSize());
604 m_summary_str.append (1, ')');
605 }
Jim Ingham6035b672011-03-31 00:19:25 +0000606 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000607 }
608 }
609 }
610 }
611 }
612 if (m_summary_str.empty())
613 return NULL;
614 return m_summary_str.c_str();
615}
616
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000617bool
618ValueObject::IsCStringContainer(bool check_pointer)
619{
620 clang_type_t elem_or_pointee_clang_type;
621 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
622 GetClangAST(),
623 &elem_or_pointee_clang_type));
624 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
625 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
626 if (!is_char_arr_ptr)
627 return false;
628 if (!check_pointer)
629 return true;
630 if (type_flags.Test(ClangASTContext::eTypeIsArray))
631 return true;
632 lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS;
633 AddressType cstr_address_type = eAddressTypeInvalid;
634 cstr_address = GetAddressOf (cstr_address_type, true);
635 return (cstr_address != LLDB_INVALID_ADDRESS);
636}
637
638void
639ValueObject::ReadPointedString(Stream& s,
640 Error& error,
Enrico Granataf4efecd2011-07-12 22:56:10 +0000641 uint32_t max_length,
642 bool honor_array,
643 lldb::Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000644{
645
646 if (max_length == 0)
Enrico Granataf4efecd2011-07-12 22:56:10 +0000647 max_length = 128; // FIXME this should be a setting, or a formatting parameter
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000648
649 clang_type_t clang_type = GetClangType();
650 clang_type_t elem_or_pointee_clang_type;
651 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
652 GetClangAST(),
653 &elem_or_pointee_clang_type));
654 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
655 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
656 {
657 ExecutionContextScope *exe_scope = GetExecutionContextScope();
658 if (exe_scope)
659 {
660 Target *target = exe_scope->CalculateTarget();
Enrico Granata6f3533f2011-07-29 19:53:35 +0000661 if (target == NULL)
662 {
663 s << "<no target to read from>";
664 }
665 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000666 {
667 lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS;
668 AddressType cstr_address_type = eAddressTypeInvalid;
669
670 size_t cstr_len = 0;
671 bool capped_data = false;
672 if (type_flags.Test (ClangASTContext::eTypeIsArray))
673 {
674 // We have an array
675 cstr_len = ClangASTContext::GetArraySize (clang_type);
Enrico Granataf4efecd2011-07-12 22:56:10 +0000676 if (cstr_len > max_length)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000677 {
Enrico Granataf4efecd2011-07-12 22:56:10 +0000678 capped_data = true;
679 cstr_len = max_length;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000680 }
681 cstr_address = GetAddressOf (cstr_address_type, true);
682 }
683 else
684 {
685 // We have a pointer
686 cstr_address = GetPointerValue (cstr_address_type, true);
687 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000688 if (cstr_address == LLDB_INVALID_ADDRESS)
689 {
690 s << "<invalid address for data>";
691 }
692 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000693 {
694 Address cstr_so_addr (NULL, cstr_address);
695 DataExtractor data;
696 size_t bytes_read = 0;
697 std::vector<char> data_buffer;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000698 bool prefer_file_cache = false;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000699 if (cstr_len > 0 && honor_array)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000700 {
701 data_buffer.resize(cstr_len);
702 data.SetData (&data_buffer.front(), data_buffer.size(), lldb::endian::InlHostByteOrder());
703 bytes_read = target->ReadMemory (cstr_so_addr,
704 prefer_file_cache,
705 &data_buffer.front(),
706 cstr_len,
707 error);
708 if (bytes_read > 0)
709 {
710 s << '"';
711 data.Dump (&s,
712 0, // Start offset in "data"
Enrico Granataf4efecd2011-07-12 22:56:10 +0000713 item_format,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000714 1, // Size of item (1 byte for a char!)
715 bytes_read, // How many bytes to print?
716 UINT32_MAX, // num per line
717 LLDB_INVALID_ADDRESS,// base address
718 0, // bitfield bit size
719 0); // bitfield bit offset
720 if (capped_data)
721 s << "...";
722 s << '"';
723 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000724 else
725 s << "\"<data not available>\"";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000726 }
727 else
728 {
Enrico Granataf4efecd2011-07-12 22:56:10 +0000729 cstr_len = max_length;
730 const size_t k_max_buf_size = 64;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000731 data_buffer.resize (k_max_buf_size + 1);
732 // NULL terminate in case we don't get the entire C string
733 data_buffer.back() = '\0';
734
735 s << '"';
736
Enrico Granata6f3533f2011-07-29 19:53:35 +0000737 bool any_data = false;
738
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000739 data.SetData (&data_buffer.front(), data_buffer.size(), endian::InlHostByteOrder());
740 while ((bytes_read = target->ReadMemory (cstr_so_addr,
741 prefer_file_cache,
742 &data_buffer.front(),
743 k_max_buf_size,
744 error)) > 0)
745 {
Enrico Granata6f3533f2011-07-29 19:53:35 +0000746 any_data = true;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000747 size_t len = strlen(&data_buffer.front());
748 if (len == 0)
749 break;
750 if (len > bytes_read)
751 len = bytes_read;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000752 if (len > cstr_len)
753 len = cstr_len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000754
755 data.Dump (&s,
756 0, // Start offset in "data"
Enrico Granataf4efecd2011-07-12 22:56:10 +0000757 item_format,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000758 1, // Size of item (1 byte for a char!)
759 len, // How many bytes to print?
760 UINT32_MAX, // num per line
761 LLDB_INVALID_ADDRESS,// base address
762 0, // bitfield bit size
763 0); // bitfield bit offset
764
765 if (len < k_max_buf_size)
766 break;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000767 if (len >= cstr_len)
768 {
769 s << "...";
770 break;
771 }
772 cstr_len -= len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000773 cstr_so_addr.Slide (k_max_buf_size);
774 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000775
776 if (any_data == false)
777 s << "<data not available>";
778
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000779 s << '"';
780 }
781 }
782 }
783 }
784 }
785 else
786 {
787 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +0000788 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000789 }
790}
791
Jim Ingham53c47f12010-09-10 23:12:17 +0000792const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000793ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +0000794{
Enrico Granata0a3958e2011-07-02 00:25:22 +0000795
Enrico Granatad8b5fce2011-08-02 23:12:24 +0000796 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +0000797 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000798
799 if (!m_object_desc_str.empty())
800 return m_object_desc_str.c_str();
801
Jim Ingham6035b672011-03-31 00:19:25 +0000802 ExecutionContextScope *exe_scope = GetExecutionContextScope();
803 if (exe_scope == NULL)
804 return NULL;
805
Jim Ingham53c47f12010-09-10 23:12:17 +0000806 Process *process = exe_scope->CalculateProcess();
Jim Ingham5a369122010-09-28 01:25:32 +0000807 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +0000808 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +0000809
Jim Ingham53c47f12010-09-10 23:12:17 +0000810 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +0000811
812 lldb::LanguageType language = GetObjectRuntimeLanguage();
813 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
814
Jim Inghama2cf2632010-12-23 02:29:54 +0000815 if (runtime == NULL)
816 {
Jim Inghamb7603bb2011-03-18 00:05:18 +0000817 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +0000818 clang_type_t opaque_qual_type = GetClangType();
819 if (opaque_qual_type != NULL)
820 {
Jim Inghamb7603bb2011-03-18 00:05:18 +0000821 bool is_signed;
822 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
823 || ClangASTContext::IsPointerType (opaque_qual_type))
824 {
Jim Inghama2cf2632010-12-23 02:29:54 +0000825 runtime = process->GetLanguageRuntime(lldb::eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +0000826 }
Jim Inghama2cf2632010-12-23 02:29:54 +0000827 }
828 }
829
Jim Ingham8d543de2011-03-31 23:01:21 +0000830 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +0000831 {
832 m_object_desc_str.append (s.GetData());
833 }
Sean Callanan672ad942010-10-23 00:18:49 +0000834
835 if (m_object_desc_str.empty())
836 return NULL;
837 else
838 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +0000839}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000840
841const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000842ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000843{
844 // If our byte size is zero this is an aggregate type that has children
Greg Clayton1be10fc2010-09-29 01:12:09 +0000845 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000846 {
Enrico Granatac3e320a2011-08-02 17:27:39 +0000847 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000848 {
849 if (m_value_str.empty())
850 {
851 const Value::ContextType context_type = m_value.GetContextType();
852
853 switch (context_type)
854 {
Greg Clayton526e5af2010-11-13 03:52:47 +0000855 case Value::eContextTypeClangType:
856 case Value::eContextTypeLLDBType:
857 case Value::eContextTypeVariable:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858 {
Greg Clayton73b472d2010-10-27 03:32:59 +0000859 clang_type_t clang_type = GetClangType ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000860 if (clang_type)
861 {
Enrico Granatac3e320a2011-08-02 17:27:39 +0000862 if (m_format == lldb::eFormatDefault && m_last_value_format)
Enrico Granata4becb372011-06-29 22:27:15 +0000863 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000864 m_value_str = m_last_value_format->FormatObject(GetSP());
Enrico Granata4becb372011-06-29 22:27:15 +0000865 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000866 else
Greg Clayton007d5be2011-05-30 00:49:24 +0000867 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000868 StreamString sstr;
869 Format format = GetFormat();
870 if (format == eFormatDefault)
871 format = (m_is_bitfield_for_scalar ? eFormatUnsigned :
872 ClangASTType::GetFormat(clang_type));
873
874 if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
875 clang_type, // The clang type to display
876 &sstr,
877 format, // Format to display this type with
878 m_data, // Data to extract from
879 0, // Byte offset into "m_data"
880 GetByteSize(), // Byte size of item in "m_data"
881 GetBitfieldBitSize(), // Bitfield bit size
882 GetBitfieldBitOffset())) // Bitfield bit offset
883 m_value_str.swap(sstr.GetString());
884 else
885 {
886 m_error.SetErrorStringWithFormat ("unsufficient data for value (only %u of %u bytes available)",
887 m_data.GetByteSize(),
888 GetByteSize());
889 m_value_str.clear();
890 }
Greg Clayton007d5be2011-05-30 00:49:24 +0000891 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000892 }
893 }
894 break;
895
Greg Clayton526e5af2010-11-13 03:52:47 +0000896 case Value::eContextTypeRegisterInfo:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000897 {
898 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
899 if (reg_info)
900 {
901 StreamString reg_sstr;
902 m_data.Dump(&reg_sstr, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
903 m_value_str.swap(reg_sstr.GetString());
904 }
905 }
906 break;
Greg Claytonc982c762010-07-09 20:39:50 +0000907
908 default:
909 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000910 }
911 }
Greg Clayton288bdf92010-09-02 02:59:18 +0000912
913 if (!m_value_did_change && m_old_value_valid)
914 {
915 // The value was gotten successfully, so we consider the
916 // value as changed if the value string differs
917 SetValueDidChange (m_old_value_str != m_value_str);
918 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000919 }
920 }
921 if (m_value_str.empty())
922 return NULL;
923 return m_value_str.c_str();
924}
925
Enrico Granatac3e320a2011-08-02 17:27:39 +0000926// if > 8bytes, 0 is returned. this method should mostly be used
927// to read address values out of pointers
928unsigned long long
929ValueObject::GetValueAsUnsigned()
930{
931 // If our byte size is zero this is an aggregate type that has children
932 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
933 {
934 if (UpdateValueIfNeeded(true))
935 {
936 uint32_t offset = 0;
937 return m_data.GetMaxU64(&offset,
938 m_data.GetByteSize());
939 }
940 }
941 return 0;
942}
943
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000944bool
945ValueObject::GetPrintableRepresentation(Stream& s,
946 ValueObjectRepresentationStyle val_obj_display,
Enrico Granata0a3958e2011-07-02 00:25:22 +0000947 lldb::Format custom_format)
948{
Enrico Granataf4efecd2011-07-12 22:56:10 +0000949
950 RefCounter ref(&m_dump_printable_counter);
951
Enrico Granata9dd75c82011-07-15 23:30:15 +0000952 if (custom_format != lldb::eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +0000953 SetFormat(custom_format);
954
955 const char * return_value;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000956 std::auto_ptr<char> alloc_mem;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000957
958 switch(val_obj_display)
959 {
960 case eDisplayValue:
961 return_value = GetValueAsCString();
962 break;
963 case eDisplaySummary:
964 return_value = GetSummaryAsCString();
965 break;
966 case eDisplayLanguageSpecific:
967 return_value = GetObjectDescription();
968 break;
Enrico Granataf2bbf712011-07-15 02:26:42 +0000969 case eDisplayLocation:
970 return_value = GetLocationAsCString();
971 break;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000972 case eDisplayChildrenCount:
973 // keep this out of the local scope so it will only get deleted when
974 // we exit the function (..and we have a copy of the data into the Stream)
975 alloc_mem = std::auto_ptr<char>((char*)(return_value = new char[512]));
976 {
977 int count = GetNumChildren();
978 snprintf(alloc_mem.get(), 512, "%d", count);
979 break;
980 }
981 default:
982 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000983 }
984
Enrico Granataf4efecd2011-07-12 22:56:10 +0000985 // this code snippet might lead to endless recursion, thus we use a RefCounter here to
986 // check that we are not looping endlessly
987 if (!return_value && (m_dump_printable_counter < 3))
Enrico Granata9fc19442011-07-06 02:13:41 +0000988 {
989 // try to pick the other choice
990 if (val_obj_display == eDisplayValue)
991 return_value = GetSummaryAsCString();
992 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +0000993 {
994 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
995 {
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000996 // this thing has no value, and it seems to have no summary
997 // some combination of unitialized data and other factors can also
998 // raise this condition, so let's print a nice generic error message
999 return_value = "<no available summary>";
Enrico Granatae992a082011-07-22 17:03:19 +00001000 }
1001 else
1002 return_value = GetValueAsCString();
1003 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001004 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001005
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001006 if (return_value)
1007 s.PutCString(return_value);
1008 else
1009 s.PutCString("<no printable representation>");
1010
1011 // we should only return false here if we could not do *anything*
1012 // even if we have an error message as output, that's a success
1013 // from our callers' perspective, so return true
1014 return true;
1015
Enrico Granata0a3958e2011-07-02 00:25:22 +00001016}
1017
Enrico Granata9fc19442011-07-06 02:13:41 +00001018bool
1019ValueObject::DumpPrintableRepresentation(Stream& s,
1020 ValueObjectRepresentationStyle val_obj_display,
1021 lldb::Format custom_format)
1022{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001023
1024 clang_type_t elem_or_pointee_type;
1025 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001026
Enrico Granataf4efecd2011-07-12 22:56:10 +00001027 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1028 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001029 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001030 // when being asked to get a printable display an array or pointer type directly,
1031 // try to "do the right thing"
1032
1033 if (IsCStringContainer(true) &&
1034 (custom_format == lldb::eFormatCString ||
1035 custom_format == lldb::eFormatCharArray ||
1036 custom_format == lldb::eFormatChar ||
1037 custom_format == lldb::eFormatVectorOfChar)) // print char[] & char* directly
1038 {
1039 Error error;
1040 ReadPointedString(s,
1041 error,
1042 0,
1043 (custom_format == lldb::eFormatVectorOfChar) ||
1044 (custom_format == lldb::eFormatCharArray));
1045 return !error.Fail();
1046 }
1047
1048 if (custom_format == lldb::eFormatEnum)
1049 return false;
1050
1051 // this only works for arrays, because I have no way to know when
1052 // the pointed memory ends, and no special \0 end of data marker
1053 if (flags.Test(ClangASTContext::eTypeIsArray))
1054 {
1055 if ((custom_format == lldb::eFormatBytes) ||
1056 (custom_format == lldb::eFormatBytesWithASCII))
1057 {
1058 uint32_t count = GetNumChildren();
1059
1060 s << '[';
1061 for (uint32_t low = 0; low < count; low++)
1062 {
1063
1064 if (low)
1065 s << ',';
1066
1067 ValueObjectSP child = GetChildAtIndex(low,true);
1068 if (!child.get())
1069 {
Enrico Granatae992a082011-07-22 17:03:19 +00001070 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001071 continue;
1072 }
1073 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1074 }
1075
1076 s << ']';
1077
1078 return true;
1079 }
1080
1081 if ((custom_format == lldb::eFormatVectorOfChar) ||
1082 (custom_format == lldb::eFormatVectorOfFloat32) ||
1083 (custom_format == lldb::eFormatVectorOfFloat64) ||
1084 (custom_format == lldb::eFormatVectorOfSInt16) ||
1085 (custom_format == lldb::eFormatVectorOfSInt32) ||
1086 (custom_format == lldb::eFormatVectorOfSInt64) ||
1087 (custom_format == lldb::eFormatVectorOfSInt8) ||
1088 (custom_format == lldb::eFormatVectorOfUInt128) ||
1089 (custom_format == lldb::eFormatVectorOfUInt16) ||
1090 (custom_format == lldb::eFormatVectorOfUInt32) ||
1091 (custom_format == lldb::eFormatVectorOfUInt64) ||
1092 (custom_format == lldb::eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1093 {
1094 uint32_t count = GetNumChildren();
1095
1096 lldb::Format format = FormatManager::GetSingleItemFormat(custom_format);
1097
1098 s << '[';
1099 for (uint32_t low = 0; low < count; low++)
1100 {
1101
1102 if (low)
1103 s << ',';
1104
1105 ValueObjectSP child = GetChildAtIndex(low,true);
1106 if (!child.get())
1107 {
Enrico Granatae992a082011-07-22 17:03:19 +00001108 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001109 continue;
1110 }
1111 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1112 }
1113
1114 s << ']';
1115
1116 return true;
1117 }
1118 }
1119
1120 if ((custom_format == lldb::eFormatBoolean) ||
1121 (custom_format == lldb::eFormatBinary) ||
1122 (custom_format == lldb::eFormatChar) ||
1123 (custom_format == lldb::eFormatCharPrintable) ||
1124 (custom_format == lldb::eFormatComplexFloat) ||
1125 (custom_format == lldb::eFormatDecimal) ||
1126 (custom_format == lldb::eFormatHex) ||
1127 (custom_format == lldb::eFormatFloat) ||
1128 (custom_format == lldb::eFormatOctal) ||
1129 (custom_format == lldb::eFormatOSType) ||
1130 (custom_format == lldb::eFormatUnicode16) ||
1131 (custom_format == lldb::eFormatUnicode32) ||
1132 (custom_format == lldb::eFormatUnsigned) ||
1133 (custom_format == lldb::eFormatPointer) ||
1134 (custom_format == lldb::eFormatComplexInteger) ||
1135 (custom_format == lldb::eFormatComplex) ||
1136 (custom_format == lldb::eFormatDefault)) // use the [] operator
1137 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001138 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001139 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001140 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001141 SetFormat(eFormatDefault);
1142 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001143}
1144
Greg Clayton737b9322010-09-13 03:32:57 +00001145addr_t
Greg Claytone0d378b2011-03-24 21:19:54 +00001146ValueObject::GetAddressOf (AddressType &address_type, bool scalar_is_load_address)
Greg Clayton73b472d2010-10-27 03:32:59 +00001147{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001148 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001149 return LLDB_INVALID_ADDRESS;
1150
Greg Clayton73b472d2010-10-27 03:32:59 +00001151 switch (m_value.GetValueType())
1152 {
1153 case Value::eValueTypeScalar:
1154 if (scalar_is_load_address)
1155 {
1156 address_type = eAddressTypeLoad;
1157 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1158 }
1159 break;
1160
1161 case Value::eValueTypeLoadAddress:
1162 case Value::eValueTypeFileAddress:
1163 case Value::eValueTypeHostAddress:
1164 {
1165 address_type = m_value.GetValueAddressType ();
1166 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1167 }
1168 break;
1169 }
1170 address_type = eAddressTypeInvalid;
1171 return LLDB_INVALID_ADDRESS;
1172}
1173
1174addr_t
Greg Claytone0d378b2011-03-24 21:19:54 +00001175ValueObject::GetPointerValue (AddressType &address_type, bool scalar_is_load_address)
Greg Clayton737b9322010-09-13 03:32:57 +00001176{
1177 lldb::addr_t address = LLDB_INVALID_ADDRESS;
1178 address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001179
Enrico Granatac3e320a2011-08-02 17:27:39 +00001180 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001181 return address;
1182
Greg Clayton73b472d2010-10-27 03:32:59 +00001183 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001184 {
1185 case Value::eValueTypeScalar:
1186 if (scalar_is_load_address)
1187 {
1188 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1189 address_type = eAddressTypeLoad;
1190 }
1191 break;
1192
1193 case Value::eValueTypeLoadAddress:
1194 case Value::eValueTypeFileAddress:
1195 case Value::eValueTypeHostAddress:
1196 {
1197 uint32_t data_offset = 0;
1198 address = m_data.GetPointer(&data_offset);
1199 address_type = m_value.GetValueAddressType();
1200 if (address_type == eAddressTypeInvalid)
1201 address_type = eAddressTypeLoad;
1202 }
1203 break;
1204 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001205
1206 if (m_pointers_point_to_load_addrs)
1207 address_type = eAddressTypeLoad;
1208
Greg Clayton737b9322010-09-13 03:32:57 +00001209 return address;
1210}
1211
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212bool
Jim Ingham6035b672011-03-31 00:19:25 +00001213ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001214{
1215 // Make sure our value is up to date first so that our location and location
1216 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001217 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001218 return false;
1219
1220 uint32_t count = 0;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001221 lldb::Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001222
1223 char *end = NULL;
Greg Claytonb1320972010-07-14 00:18:15 +00001224 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001225 switch (encoding)
1226 {
1227 case eEncodingInvalid:
1228 return false;
1229
1230 case eEncodingUint:
1231 if (byte_size > sizeof(unsigned long long))
1232 {
1233 return false;
1234 }
1235 else
1236 {
1237 unsigned long long ull_val = strtoull(value_str, &end, 0);
1238 if (end && *end != '\0')
1239 return false;
Greg Clayton644247c2011-07-07 01:59:51 +00001240 m_value.GetScalar() = ull_val;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001241 // Limit the bytes in our m_data appropriately.
1242 m_value.GetScalar().GetData (m_data, byte_size);
1243 }
1244 break;
1245
1246 case eEncodingSint:
1247 if (byte_size > sizeof(long long))
1248 {
1249 return false;
1250 }
1251 else
1252 {
1253 long long sll_val = strtoll(value_str, &end, 0);
1254 if (end && *end != '\0')
1255 return false;
Greg Clayton644247c2011-07-07 01:59:51 +00001256 m_value.GetScalar() = sll_val;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001257 // Limit the bytes in our m_data appropriately.
1258 m_value.GetScalar().GetData (m_data, byte_size);
1259 }
1260 break;
1261
1262 case eEncodingIEEE754:
1263 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001264 const off_t byte_offset = GetByteOffset();
Greg Claytonc982c762010-07-09 20:39:50 +00001265 uint8_t *dst = const_cast<uint8_t *>(m_data.PeekData(byte_offset, byte_size));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001266 if (dst != NULL)
1267 {
1268 // We are decoding a float into host byte order below, so make
1269 // sure m_data knows what it contains.
Greg Clayton7fb56d02011-02-01 01:31:41 +00001270 m_data.SetByteOrder(lldb::endian::InlHostByteOrder());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001271 const size_t converted_byte_size = ClangASTContext::ConvertStringToFloatValue (
1272 GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +00001273 GetClangType(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001274 value_str,
1275 dst,
1276 byte_size);
1277
1278 if (converted_byte_size == byte_size)
1279 {
1280 }
1281 }
1282 }
1283 break;
1284
1285 case eEncodingVector:
1286 return false;
1287
1288 default:
1289 return false;
1290 }
1291
1292 // If we have made it here the value is in m_data and we should write it
1293 // out to the target
1294 return Write ();
1295}
1296
1297bool
1298ValueObject::Write ()
1299{
1300 // Clear the update ID so the next time we try and read the value
1301 // we try and read it again.
Jim Ingham6035b672011-03-31 00:19:25 +00001302 m_update_point.SetNeedsUpdate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001303
1304 // TODO: when Value has a method to write a value back, call it from here.
1305 return false;
1306
1307}
1308
Jim Ingham5a369122010-09-28 01:25:32 +00001309lldb::LanguageType
1310ValueObject::GetObjectRuntimeLanguage ()
1311{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001312 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1313 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001314}
1315
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001316void
Jim Ingham58b59f92011-04-22 23:53:53 +00001317ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001318{
Jim Ingham58b59f92011-04-22 23:53:53 +00001319 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001320}
1321
1322ValueObjectSP
1323ValueObject::GetSyntheticChild (const ConstString &key) const
1324{
1325 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001326 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001327 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001328 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001329 return synthetic_child_sp;
1330}
1331
1332bool
1333ValueObject::IsPointerType ()
1334{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001335 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001336}
1337
Jim Inghamb7603bb2011-03-18 00:05:18 +00001338bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001339ValueObject::IsArrayType ()
1340{
1341 return ClangASTContext::IsArrayType (GetClangType());
1342}
1343
1344bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001345ValueObject::IsScalarType ()
1346{
1347 return ClangASTContext::IsScalarType (GetClangType());
1348}
1349
1350bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001351ValueObject::IsIntegerType (bool &is_signed)
1352{
1353 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1354}
Greg Clayton73b472d2010-10-27 03:32:59 +00001355
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001356bool
1357ValueObject::IsPointerOrReferenceType ()
1358{
Greg Clayton007d5be2011-05-30 00:49:24 +00001359 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1360}
1361
1362bool
1363ValueObject::IsPossibleCPlusPlusDynamicType ()
1364{
1365 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001366}
1367
Greg Claytondea8cb42011-06-29 22:09:02 +00001368bool
1369ValueObject::IsPossibleDynamicType ()
1370{
1371 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1372}
1373
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001374ValueObjectSP
1375ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1376{
1377 ValueObjectSP synthetic_child_sp;
1378 if (IsPointerType ())
1379 {
1380 char index_str[64];
1381 snprintf(index_str, sizeof(index_str), "[%i]", index);
1382 ConstString index_const_str(index_str);
1383 // Check if we have already created a synthetic array member in this
1384 // valid object. If we have we will re-use it.
1385 synthetic_child_sp = GetSyntheticChild (index_const_str);
1386 if (!synthetic_child_sp)
1387 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001388 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001389 // We haven't made a synthetic array member for INDEX yet, so
1390 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001391 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001392
1393 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001394 if (synthetic_child)
1395 {
1396 AddSyntheticChild(index_const_str, synthetic_child);
1397 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001398 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001399 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001400 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001401 }
1402 }
1403 return synthetic_child_sp;
1404}
Jim Ingham22777012010-09-23 02:01:19 +00001405
Greg Claytondaf515f2011-07-09 20:12:33 +00001406// This allows you to create an array member using and index
1407// that doesn't not fall in the normal bounds of the array.
1408// Many times structure can be defined as:
1409// struct Collection
1410// {
1411// uint32_t item_count;
1412// Item item_array[0];
1413// };
1414// The size of the "item_array" is 1, but many times in practice
1415// there are more items in "item_array".
1416
1417ValueObjectSP
1418ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1419{
1420 ValueObjectSP synthetic_child_sp;
1421 if (IsArrayType ())
1422 {
1423 char index_str[64];
1424 snprintf(index_str, sizeof(index_str), "[%i]", index);
1425 ConstString index_const_str(index_str);
1426 // Check if we have already created a synthetic array member in this
1427 // valid object. If we have we will re-use it.
1428 synthetic_child_sp = GetSyntheticChild (index_const_str);
1429 if (!synthetic_child_sp)
1430 {
1431 ValueObject *synthetic_child;
1432 // We haven't made a synthetic array member for INDEX yet, so
1433 // lets make one and cache it for any future reference.
1434 synthetic_child = CreateChildAtIndex(0, true, index);
1435
1436 // Cache the value if we got one back...
1437 if (synthetic_child)
1438 {
1439 AddSyntheticChild(index_const_str, synthetic_child);
1440 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001441 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001442 synthetic_child_sp->m_is_array_item_for_pointer = true;
1443 }
1444 }
1445 }
1446 return synthetic_child_sp;
1447}
1448
Enrico Granata9fc19442011-07-06 02:13:41 +00001449ValueObjectSP
1450ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1451{
1452 ValueObjectSP synthetic_child_sp;
1453 if (IsScalarType ())
1454 {
1455 char index_str[64];
1456 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1457 ConstString index_const_str(index_str);
1458 // Check if we have already created a synthetic array member in this
1459 // valid object. If we have we will re-use it.
1460 synthetic_child_sp = GetSyntheticChild (index_const_str);
1461 if (!synthetic_child_sp)
1462 {
1463 ValueObjectChild *synthetic_child;
1464 // We haven't made a synthetic array member for INDEX yet, so
1465 // lets make one and cache it for any future reference.
1466 synthetic_child = new ValueObjectChild(*this,
1467 GetClangAST(),
1468 GetClangType(),
1469 index_const_str,
1470 GetByteSize(),
1471 0,
1472 to-from+1,
1473 from,
1474 false,
1475 false);
1476
1477 // Cache the value if we got one back...
1478 if (synthetic_child)
1479 {
1480 AddSyntheticChild(index_const_str, synthetic_child);
1481 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001482 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001483 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1484 }
1485 }
1486 }
1487 return synthetic_child_sp;
1488}
1489
Enrico Granata6f3533f2011-07-29 19:53:35 +00001490lldb::ValueObjectSP
1491ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1492{
1493
1494 ValueObjectSP synthetic_child_sp;
1495
1496 char name_str[64];
1497 snprintf(name_str, sizeof(name_str), "@%i", offset);
1498 ConstString name_const_str(name_str);
1499
1500 // Check if we have already created a synthetic array member in this
1501 // valid object. If we have we will re-use it.
1502 synthetic_child_sp = GetSyntheticChild (name_const_str);
1503
1504 if (synthetic_child_sp.get())
1505 return synthetic_child_sp;
1506
1507 if (!can_create)
1508 return lldb::ValueObjectSP();
1509
1510 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1511 type.GetASTContext(),
1512 type.GetOpaqueQualType(),
1513 name_const_str,
1514 type.GetTypeByteSize(),
1515 offset,
1516 0,
1517 0,
1518 false,
1519 false);
1520 if (synthetic_child)
1521 {
1522 AddSyntheticChild(name_const_str, synthetic_child);
1523 synthetic_child_sp = synthetic_child->GetSP();
1524 synthetic_child_sp->SetName(name_const_str);
1525 synthetic_child_sp->m_is_child_at_offset = true;
1526 }
1527 return synthetic_child_sp;
1528}
1529
Enrico Granatad55546b2011-07-22 00:16:08 +00001530// your expression path needs to have a leading . or ->
1531// (unless it somehow "looks like" an array, in which case it has
1532// a leading [ symbol). while the [ is meaningful and should be shown
1533// to the user, . and -> are just parser design, but by no means
1534// added information for the user.. strip them off
1535static const char*
1536SkipLeadingExpressionPathSeparators(const char* expression)
1537{
1538 if (!expression || !expression[0])
1539 return expression;
1540 if (expression[0] == '.')
1541 return expression+1;
1542 if (expression[0] == '-' && expression[1] == '>')
1543 return expression+2;
1544 return expression;
1545}
1546
1547lldb::ValueObjectSP
1548ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1549{
1550 ValueObjectSP synthetic_child_sp;
1551 ConstString name_const_string(expression);
1552 // Check if we have already created a synthetic array member in this
1553 // valid object. If we have we will re-use it.
1554 synthetic_child_sp = GetSyntheticChild (name_const_string);
1555 if (!synthetic_child_sp)
1556 {
1557 // We haven't made a synthetic array member for expression yet, so
1558 // lets make one and cache it for any future reference.
1559 synthetic_child_sp = GetValueForExpressionPath(expression);
1560
1561 // Cache the value if we got one back...
1562 if (synthetic_child_sp.get())
1563 {
1564 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001565 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001566 synthetic_child_sp->m_is_expression_path_child = true;
1567 }
1568 }
1569 return synthetic_child_sp;
1570}
1571
1572void
1573ValueObject::CalculateSyntheticValue (lldb::SyntheticValueType use_synthetic)
1574{
1575 if (use_synthetic == lldb::eNoSyntheticFilter)
1576 return;
1577
Enrico Granatac3e320a2011-08-02 17:27:39 +00001578 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001579
1580 if (m_last_synthetic_filter.get() == NULL)
1581 return;
1582
Enrico Granataa37a0652011-07-24 00:14:56 +00001583 if (m_synthetic_value == NULL)
1584 m_synthetic_value = new ValueObjectSynthetic(*this, m_last_synthetic_filter);
Enrico Granatad55546b2011-07-22 00:16:08 +00001585
1586}
1587
Jim Ingham78a685a2011-04-16 00:01:13 +00001588void
Jim Ingham2837b762011-05-04 03:43:18 +00001589ValueObject::CalculateDynamicValue (lldb::DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00001590{
Jim Ingham2837b762011-05-04 03:43:18 +00001591 if (use_dynamic == lldb::eNoDynamicValues)
1592 return;
1593
Jim Ingham58b59f92011-04-22 23:53:53 +00001594 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00001595 {
Enrico Granata6f3533f2011-07-29 19:53:35 +00001596 Process *process = m_update_point.GetProcessSP().get();
Jim Ingham78a685a2011-04-16 00:01:13 +00001597 bool worth_having_dynamic_value = false;
Jim Ingham22777012010-09-23 02:01:19 +00001598
Jim Ingham78a685a2011-04-16 00:01:13 +00001599
1600 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
1601 // hard code this everywhere.
1602 lldb::LanguageType known_type = GetObjectRuntimeLanguage();
1603 if (known_type != lldb::eLanguageTypeUnknown && known_type != lldb::eLanguageTypeC)
1604 {
1605 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
1606 if (runtime)
1607 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
1608 }
1609 else
1610 {
1611 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeC_plus_plus);
1612 if (cpp_runtime)
1613 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
1614
1615 if (!worth_having_dynamic_value)
1616 {
1617 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeObjC);
1618 if (objc_runtime)
Jim Ingham2837b762011-05-04 03:43:18 +00001619 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00001620 }
1621 }
1622
1623 if (worth_having_dynamic_value)
Jim Ingham2837b762011-05-04 03:43:18 +00001624 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham58b59f92011-04-22 23:53:53 +00001625
1626// if (worth_having_dynamic_value)
1627// printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager);
1628
Jim Ingham78a685a2011-04-16 00:01:13 +00001629 }
1630}
1631
Jim Ingham58b59f92011-04-22 23:53:53 +00001632ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00001633ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00001634{
Jim Ingham2837b762011-05-04 03:43:18 +00001635 if (use_dynamic == lldb::eNoDynamicValues)
1636 return ValueObjectSP();
1637
1638 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00001639 {
Jim Ingham2837b762011-05-04 03:43:18 +00001640 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001641 }
Jim Ingham58b59f92011-04-22 23:53:53 +00001642 if (m_dynamic_value)
1643 return m_dynamic_value->GetSP();
1644 else
1645 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00001646}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001647
Enrico Granatad55546b2011-07-22 00:16:08 +00001648// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
1649// or we do not really want a dynamic VO. this method instead returns this object
1650// itself when making it synthetic has no meaning. this makes it much simpler
1651// to replace the SyntheticValue for the ValueObject
1652ValueObjectSP
1653ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
1654{
1655 if (use_synthetic == lldb::eNoSyntheticFilter)
1656 return GetSP();
1657
Enrico Granatac3e320a2011-08-02 17:27:39 +00001658 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001659
1660 if (m_last_synthetic_filter.get() == NULL)
1661 return GetSP();
1662
1663 CalculateSyntheticValue(use_synthetic);
1664
1665 if (m_synthetic_value)
1666 return m_synthetic_value->GetSP();
1667 else
1668 return GetSP();
1669}
1670
Greg Claytone221f822011-01-21 01:59:00 +00001671bool
1672ValueObject::GetBaseClassPath (Stream &s)
1673{
1674 if (IsBaseClass())
1675 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001676 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00001677 clang_type_t clang_type = GetClangType();
1678 std::string cxx_class_name;
1679 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
1680 if (this_had_base_class)
1681 {
1682 if (parent_had_base_class)
1683 s.PutCString("::");
1684 s.PutCString(cxx_class_name.c_str());
1685 }
1686 return parent_had_base_class || this_had_base_class;
1687 }
1688 return false;
1689}
1690
1691
1692ValueObject *
1693ValueObject::GetNonBaseClassParent()
1694{
Jim Ingham78a685a2011-04-16 00:01:13 +00001695 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00001696 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001697 if (GetParent()->IsBaseClass())
1698 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00001699 else
Jim Ingham78a685a2011-04-16 00:01:13 +00001700 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00001701 }
1702 return NULL;
1703}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001704
1705void
Enrico Granata4becb372011-06-29 22:27:15 +00001706ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001707{
Greg Claytone221f822011-01-21 01:59:00 +00001708 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00001709
Enrico Granata9dd75c82011-07-15 23:30:15 +00001710 if (is_deref_of_parent && epformat == eDereferencePointers) {
Enrico Granata4becb372011-06-29 22:27:15 +00001711 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
1712 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
1713 // the eHonorPointers mode is meant to produce strings in this latter format
1714 s.PutCString("*(");
1715 }
Greg Claytone221f822011-01-21 01:59:00 +00001716
Enrico Granata4becb372011-06-29 22:27:15 +00001717 ValueObject* parent = GetParent();
1718
1719 if (parent)
1720 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00001721
1722 // if we are a deref_of_parent just because we are synthetic array
1723 // members made up to allow ptr[%d] syntax to work in variable
1724 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00001725 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001726 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00001727
Greg Claytone221f822011-01-21 01:59:00 +00001728 if (!IsBaseClass())
1729 {
1730 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001731 {
Greg Claytone221f822011-01-21 01:59:00 +00001732 ValueObject *non_base_class_parent = GetNonBaseClassParent();
1733 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001734 {
Greg Claytone221f822011-01-21 01:59:00 +00001735 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
1736 if (non_base_class_parent_clang_type)
1737 {
1738 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
1739
Enrico Granata9dd75c82011-07-15 23:30:15 +00001740 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00001741 {
1742 s.PutCString("->");
1743 }
Enrico Granata4becb372011-06-29 22:27:15 +00001744 else
1745 {
1746 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
1747 {
1748 s.PutCString("->");
1749 }
1750 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
1751 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
1752 {
1753 s.PutChar('.');
1754 }
Greg Claytone221f822011-01-21 01:59:00 +00001755 }
1756 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001757 }
Greg Claytone221f822011-01-21 01:59:00 +00001758
1759 const char *name = GetName().GetCString();
1760 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001761 {
Greg Claytone221f822011-01-21 01:59:00 +00001762 if (qualify_cxx_base_classes)
1763 {
1764 if (GetBaseClassPath (s))
1765 s.PutCString("::");
1766 }
1767 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001768 }
1769 }
1770 }
1771
Enrico Granata4becb372011-06-29 22:27:15 +00001772 if (is_deref_of_parent && epformat == eDereferencePointers) {
Greg Claytone221f822011-01-21 01:59:00 +00001773 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00001774 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001775}
1776
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001777lldb::ValueObjectSP
1778ValueObject::GetValueForExpressionPath(const char* expression,
1779 const char** first_unparsed,
1780 ExpressionPathScanEndReason* reason_to_stop,
1781 ExpressionPathEndResultType* final_value_type,
1782 const GetValueForExpressionPathOptions& options,
1783 ExpressionPathAftermath* final_task_on_target)
1784{
1785
1786 const char* dummy_first_unparsed;
1787 ExpressionPathScanEndReason dummy_reason_to_stop;
1788 ExpressionPathEndResultType dummy_final_value_type;
1789 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
1790
1791 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
1792 first_unparsed ? first_unparsed : &dummy_first_unparsed,
1793 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
1794 final_value_type ? final_value_type : &dummy_final_value_type,
1795 options,
1796 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
1797
1798 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
1799 {
1800 return ret_val;
1801 }
1802 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
1803 {
1804 if (*final_task_on_target == ValueObject::eDereference)
1805 {
1806 Error error;
1807 ValueObjectSP final_value = ret_val->Dereference(error);
1808 if (error.Fail() || !final_value.get())
1809 {
1810 *reason_to_stop = ValueObject::eDereferencingFailed;
1811 *final_value_type = ValueObject::eInvalid;
1812 return ValueObjectSP();
1813 }
1814 else
1815 {
1816 *final_task_on_target = ValueObject::eNothing;
1817 return final_value;
1818 }
1819 }
1820 if (*final_task_on_target == ValueObject::eTakeAddress)
1821 {
1822 Error error;
1823 ValueObjectSP final_value = ret_val->AddressOf(error);
1824 if (error.Fail() || !final_value.get())
1825 {
1826 *reason_to_stop = ValueObject::eTakingAddressFailed;
1827 *final_value_type = ValueObject::eInvalid;
1828 return ValueObjectSP();
1829 }
1830 else
1831 {
1832 *final_task_on_target = ValueObject::eNothing;
1833 return final_value;
1834 }
1835 }
1836 }
1837 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
1838}
1839
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001840int
1841ValueObject::GetValuesForExpressionPath(const char* expression,
1842 lldb::ValueObjectListSP& list,
1843 const char** first_unparsed,
1844 ExpressionPathScanEndReason* reason_to_stop,
1845 ExpressionPathEndResultType* final_value_type,
1846 const GetValueForExpressionPathOptions& options,
1847 ExpressionPathAftermath* final_task_on_target)
1848{
1849 const char* dummy_first_unparsed;
1850 ExpressionPathScanEndReason dummy_reason_to_stop;
1851 ExpressionPathEndResultType dummy_final_value_type;
1852 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
1853
1854 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
1855 first_unparsed ? first_unparsed : &dummy_first_unparsed,
1856 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
1857 final_value_type ? final_value_type : &dummy_final_value_type,
1858 options,
1859 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
1860
1861 if (!ret_val.get()) // if there are errors, I add nothing to the list
1862 return 0;
1863
1864 if (*reason_to_stop != eArrayRangeOperatorMet)
1865 {
1866 // I need not expand a range, just post-process the final value and return
1867 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
1868 {
1869 list->Append(ret_val);
1870 return 1;
1871 }
1872 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
1873 {
1874 if (*final_task_on_target == ValueObject::eDereference)
1875 {
1876 Error error;
1877 ValueObjectSP final_value = ret_val->Dereference(error);
1878 if (error.Fail() || !final_value.get())
1879 {
1880 *reason_to_stop = ValueObject::eDereferencingFailed;
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 if (*final_task_on_target == ValueObject::eTakeAddress)
1892 {
1893 Error error;
1894 ValueObjectSP final_value = ret_val->AddressOf(error);
1895 if (error.Fail() || !final_value.get())
1896 {
1897 *reason_to_stop = ValueObject::eTakingAddressFailed;
1898 *final_value_type = ValueObject::eInvalid;
1899 return 0;
1900 }
1901 else
1902 {
1903 *final_task_on_target = ValueObject::eNothing;
1904 list->Append(final_value);
1905 return 1;
1906 }
1907 }
1908 }
1909 }
1910 else
1911 {
1912 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
1913 first_unparsed ? first_unparsed : &dummy_first_unparsed,
1914 ret_val,
1915 list,
1916 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
1917 final_value_type ? final_value_type : &dummy_final_value_type,
1918 options,
1919 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
1920 }
1921 // in any non-covered case, just do the obviously right thing
1922 list->Append(ret_val);
1923 return 1;
1924}
1925
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001926lldb::ValueObjectSP
1927ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
1928 const char** first_unparsed,
1929 ExpressionPathScanEndReason* reason_to_stop,
1930 ExpressionPathEndResultType* final_result,
1931 const GetValueForExpressionPathOptions& options,
1932 ExpressionPathAftermath* what_next)
1933{
1934 ValueObjectSP root = GetSP();
1935
1936 if (!root.get())
1937 return ValueObjectSP();
1938
1939 *first_unparsed = expression_cstr;
1940
1941 while (true)
1942 {
1943
1944 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
1945
1946 lldb::clang_type_t root_clang_type = root->GetClangType();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001947 lldb::clang_type_t pointee_clang_type;
1948 Flags root_clang_type_info,pointee_clang_type_info;
1949
1950 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
1951 if (pointee_clang_type)
1952 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001953
1954 if (!expression_cstr || *expression_cstr == '\0')
1955 {
1956 *reason_to_stop = ValueObject::eEndOfString;
1957 return root;
1958 }
1959
1960 switch (*expression_cstr)
1961 {
1962 case '-':
1963 {
1964 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001965 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 +00001966 {
1967 *first_unparsed = expression_cstr;
1968 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
1969 *final_result = ValueObject::eInvalid;
1970 return ValueObjectSP();
1971 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001972 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
1973 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001974 options.m_no_fragile_ivar)
1975 {
1976 *first_unparsed = expression_cstr;
1977 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
1978 *final_result = ValueObject::eInvalid;
1979 return ValueObjectSP();
1980 }
1981 if (expression_cstr[1] != '>')
1982 {
1983 *first_unparsed = expression_cstr;
1984 *reason_to_stop = ValueObject::eUnexpectedSymbol;
1985 *final_result = ValueObject::eInvalid;
1986 return ValueObjectSP();
1987 }
1988 expression_cstr++; // skip the -
1989 }
1990 case '.': // or fallthrough from ->
1991 {
1992 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001993 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 +00001994 {
1995 *first_unparsed = expression_cstr;
1996 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
1997 *final_result = ValueObject::eInvalid;
1998 return ValueObjectSP();
1999 }
2000 expression_cstr++; // skip .
2001 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2002 ConstString child_name;
2003 if (!next_separator) // if no other separator just expand this last layer
2004 {
2005 child_name.SetCString (expression_cstr);
2006 root = root->GetChildMemberWithName(child_name, true);
2007 if (root.get()) // we know we are done, so just return
2008 {
2009 *first_unparsed = '\0';
2010 *reason_to_stop = ValueObject::eEndOfString;
2011 *final_result = ValueObject::ePlain;
2012 return root;
2013 }
2014 else
2015 {
2016 *first_unparsed = expression_cstr;
2017 *reason_to_stop = ValueObject::eNoSuchChild;
2018 *final_result = ValueObject::eInvalid;
2019 return ValueObjectSP();
2020 }
2021 }
2022 else // other layers do expand
2023 {
2024 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
2025 root = root->GetChildMemberWithName(child_name, true);
2026 if (root.get()) // store the new root and move on
2027 {
2028 *first_unparsed = next_separator;
2029 *final_result = ValueObject::ePlain;
2030 continue;
2031 }
2032 else
2033 {
2034 *first_unparsed = expression_cstr;
2035 *reason_to_stop = ValueObject::eNoSuchChild;
2036 *final_result = ValueObject::eInvalid;
2037 return ValueObjectSP();
2038 }
2039 }
2040 break;
2041 }
2042 case '[':
2043 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002044 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 +00002045 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002046 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 +00002047 {
2048 *first_unparsed = expression_cstr;
2049 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2050 *final_result = ValueObject::eInvalid;
2051 return ValueObjectSP();
2052 }
2053 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2054 {
2055 *first_unparsed = expression_cstr;
2056 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2057 *final_result = ValueObject::eInvalid;
2058 return ValueObjectSP();
2059 }
2060 }
2061 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2062 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002063 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002064 {
2065 *first_unparsed = expression_cstr;
2066 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2067 *final_result = ValueObject::eInvalid;
2068 return ValueObjectSP();
2069 }
2070 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2071 {
2072 *first_unparsed = expression_cstr+2;
2073 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2074 *final_result = ValueObject::eUnboundedRange;
2075 return root;
2076 }
2077 }
2078 const char *separator_position = ::strchr(expression_cstr+1,'-');
2079 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2080 if (!close_bracket_position) // if there is no ], this is a syntax error
2081 {
2082 *first_unparsed = expression_cstr;
2083 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2084 *final_result = ValueObject::eInvalid;
2085 return ValueObjectSP();
2086 }
2087 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2088 {
2089 char *end = NULL;
2090 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2091 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2092 {
2093 *first_unparsed = expression_cstr;
2094 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2095 *final_result = ValueObject::eInvalid;
2096 return ValueObjectSP();
2097 }
2098 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2099 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002100 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002101 {
2102 *first_unparsed = expression_cstr+2;
2103 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2104 *final_result = ValueObject::eUnboundedRange;
2105 return root;
2106 }
2107 else
2108 {
2109 *first_unparsed = expression_cstr;
2110 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2111 *final_result = ValueObject::eInvalid;
2112 return ValueObjectSP();
2113 }
2114 }
2115 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002116 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002117 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002118 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2119 if (!child_valobj_sp)
2120 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
2121 if (child_valobj_sp)
2122 {
2123 root = child_valobj_sp;
2124 *first_unparsed = end+1; // skip ]
2125 *final_result = ValueObject::ePlain;
2126 continue;
2127 }
2128 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002129 {
2130 *first_unparsed = expression_cstr;
2131 *reason_to_stop = ValueObject::eNoSuchChild;
2132 *final_result = ValueObject::eInvalid;
2133 return ValueObjectSP();
2134 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002135 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002136 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002137 {
2138 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 +00002139 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002140 {
2141 Error error;
2142 root = root->Dereference(error);
2143 if (error.Fail() || !root.get())
2144 {
2145 *first_unparsed = expression_cstr;
2146 *reason_to_stop = ValueObject::eDereferencingFailed;
2147 *final_result = ValueObject::eInvalid;
2148 return ValueObjectSP();
2149 }
2150 else
2151 {
2152 *what_next = eNothing;
2153 continue;
2154 }
2155 }
2156 else
2157 {
2158 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2159 if (!root.get())
2160 {
2161 *first_unparsed = expression_cstr;
2162 *reason_to_stop = ValueObject::eNoSuchChild;
2163 *final_result = ValueObject::eInvalid;
2164 return ValueObjectSP();
2165 }
2166 else
2167 {
2168 *first_unparsed = end+1; // skip ]
2169 *final_result = ValueObject::ePlain;
2170 continue;
2171 }
2172 }
2173 }
2174 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2175 {
2176 root = root->GetSyntheticBitFieldChild(index, index, true);
2177 if (!root.get())
2178 {
2179 *first_unparsed = expression_cstr;
2180 *reason_to_stop = ValueObject::eNoSuchChild;
2181 *final_result = ValueObject::eInvalid;
2182 return ValueObjectSP();
2183 }
2184 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2185 {
2186 *first_unparsed = end+1; // skip ]
2187 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2188 *final_result = ValueObject::eBitfield;
2189 return root;
2190 }
2191 }
2192 }
2193 else // we have a low and a high index
2194 {
2195 char *end = NULL;
2196 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2197 if (!end || end != separator_position) // if something weird is in our way return an error
2198 {
2199 *first_unparsed = expression_cstr;
2200 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2201 *final_result = ValueObject::eInvalid;
2202 return ValueObjectSP();
2203 }
2204 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2205 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2206 {
2207 *first_unparsed = expression_cstr;
2208 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2209 *final_result = ValueObject::eInvalid;
2210 return ValueObjectSP();
2211 }
2212 if (index_lower > index_higher) // swap indices if required
2213 {
2214 unsigned long temp = index_lower;
2215 index_lower = index_higher;
2216 index_higher = temp;
2217 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002218 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002219 {
2220 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2221 if (!root.get())
2222 {
2223 *first_unparsed = expression_cstr;
2224 *reason_to_stop = ValueObject::eNoSuchChild;
2225 *final_result = ValueObject::eInvalid;
2226 return ValueObjectSP();
2227 }
2228 else
2229 {
2230 *first_unparsed = end+1; // skip ]
2231 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2232 *final_result = ValueObject::eBitfield;
2233 return root;
2234 }
2235 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002236 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 +00002237 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002238 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002239 {
2240 Error error;
2241 root = root->Dereference(error);
2242 if (error.Fail() || !root.get())
2243 {
2244 *first_unparsed = expression_cstr;
2245 *reason_to_stop = ValueObject::eDereferencingFailed;
2246 *final_result = ValueObject::eInvalid;
2247 return ValueObjectSP();
2248 }
2249 else
2250 {
2251 *what_next = ValueObject::eNothing;
2252 continue;
2253 }
2254 }
2255 else
2256 {
2257 *first_unparsed = expression_cstr;
2258 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2259 *final_result = ValueObject::eBoundedRange;
2260 return root;
2261 }
2262 }
2263 break;
2264 }
2265 default: // some non-separator is in the way
2266 {
2267 *first_unparsed = expression_cstr;
2268 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2269 *final_result = ValueObject::eInvalid;
2270 return ValueObjectSP();
2271 break;
2272 }
2273 }
2274 }
2275}
2276
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002277int
2278ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2279 const char** first_unparsed,
2280 lldb::ValueObjectSP root,
2281 lldb::ValueObjectListSP& list,
2282 ExpressionPathScanEndReason* reason_to_stop,
2283 ExpressionPathEndResultType* final_result,
2284 const GetValueForExpressionPathOptions& options,
2285 ExpressionPathAftermath* what_next)
2286{
2287 if (!root.get())
2288 return 0;
2289
2290 *first_unparsed = expression_cstr;
2291
2292 while (true)
2293 {
2294
2295 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2296
2297 lldb::clang_type_t root_clang_type = root->GetClangType();
2298 lldb::clang_type_t pointee_clang_type;
2299 Flags root_clang_type_info,pointee_clang_type_info;
2300
2301 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2302 if (pointee_clang_type)
2303 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2304
2305 if (!expression_cstr || *expression_cstr == '\0')
2306 {
2307 *reason_to_stop = ValueObject::eEndOfString;
2308 list->Append(root);
2309 return 1;
2310 }
2311
2312 switch (*expression_cstr)
2313 {
2314 case '[':
2315 {
2316 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2317 {
2318 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2319 {
2320 *first_unparsed = expression_cstr;
2321 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2322 *final_result = ValueObject::eInvalid;
2323 return 0;
2324 }
2325 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2326 {
2327 *first_unparsed = expression_cstr;
2328 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2329 *final_result = ValueObject::eInvalid;
2330 return 0;
2331 }
2332 }
2333 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2334 {
2335 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2336 {
2337 *first_unparsed = expression_cstr;
2338 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2339 *final_result = ValueObject::eInvalid;
2340 return 0;
2341 }
2342 else // expand this into list
2343 {
2344 int max_index = root->GetNumChildren() - 1;
2345 for (int index = 0; index < max_index; index++)
2346 {
2347 ValueObjectSP child =
2348 root->GetChildAtIndex(index, true);
2349 list->Append(child);
2350 }
2351 *first_unparsed = expression_cstr+2;
2352 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2353 *final_result = ValueObject::eValueObjectList;
2354 return max_index; // tell me number of items I added to the VOList
2355 }
2356 }
2357 const char *separator_position = ::strchr(expression_cstr+1,'-');
2358 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2359 if (!close_bracket_position) // if there is no ], this is a syntax error
2360 {
2361 *first_unparsed = expression_cstr;
2362 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2363 *final_result = ValueObject::eInvalid;
2364 return 0;
2365 }
2366 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2367 {
2368 char *end = NULL;
2369 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2370 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2371 {
2372 *first_unparsed = expression_cstr;
2373 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2374 *final_result = ValueObject::eInvalid;
2375 return 0;
2376 }
2377 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2378 {
2379 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2380 {
2381 int max_index = root->GetNumChildren() - 1;
2382 for (int index = 0; index < max_index; index++)
2383 {
2384 ValueObjectSP child =
2385 root->GetChildAtIndex(index, true);
2386 list->Append(child);
2387 }
2388 *first_unparsed = expression_cstr+2;
2389 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2390 *final_result = ValueObject::eValueObjectList;
2391 return max_index; // tell me number of items I added to the VOList
2392 }
2393 else
2394 {
2395 *first_unparsed = expression_cstr;
2396 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2397 *final_result = ValueObject::eInvalid;
2398 return 0;
2399 }
2400 }
2401 // from here on we do have a valid index
2402 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2403 {
2404 root = root->GetChildAtIndex(index, true);
2405 if (!root.get())
2406 {
2407 *first_unparsed = expression_cstr;
2408 *reason_to_stop = ValueObject::eNoSuchChild;
2409 *final_result = ValueObject::eInvalid;
2410 return 0;
2411 }
2412 else
2413 {
2414 list->Append(root);
2415 *first_unparsed = end+1; // skip ]
2416 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2417 *final_result = ValueObject::eValueObjectList;
2418 return 1;
2419 }
2420 }
2421 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2422 {
2423 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
2424 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2425 {
2426 Error error;
2427 root = root->Dereference(error);
2428 if (error.Fail() || !root.get())
2429 {
2430 *first_unparsed = expression_cstr;
2431 *reason_to_stop = ValueObject::eDereferencingFailed;
2432 *final_result = ValueObject::eInvalid;
2433 return 0;
2434 }
2435 else
2436 {
2437 *what_next = eNothing;
2438 continue;
2439 }
2440 }
2441 else
2442 {
2443 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2444 if (!root.get())
2445 {
2446 *first_unparsed = expression_cstr;
2447 *reason_to_stop = ValueObject::eNoSuchChild;
2448 *final_result = ValueObject::eInvalid;
2449 return 0;
2450 }
2451 else
2452 {
2453 list->Append(root);
2454 *first_unparsed = end+1; // skip ]
2455 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2456 *final_result = ValueObject::eValueObjectList;
2457 return 1;
2458 }
2459 }
2460 }
2461 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2462 {
2463 root = root->GetSyntheticBitFieldChild(index, index, true);
2464 if (!root.get())
2465 {
2466 *first_unparsed = expression_cstr;
2467 *reason_to_stop = ValueObject::eNoSuchChild;
2468 *final_result = ValueObject::eInvalid;
2469 return 0;
2470 }
2471 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2472 {
2473 list->Append(root);
2474 *first_unparsed = end+1; // skip ]
2475 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2476 *final_result = ValueObject::eValueObjectList;
2477 return 1;
2478 }
2479 }
2480 }
2481 else // we have a low and a high index
2482 {
2483 char *end = NULL;
2484 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2485 if (!end || end != separator_position) // if something weird is in our way return an error
2486 {
2487 *first_unparsed = expression_cstr;
2488 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2489 *final_result = ValueObject::eInvalid;
2490 return 0;
2491 }
2492 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2493 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2494 {
2495 *first_unparsed = expression_cstr;
2496 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2497 *final_result = ValueObject::eInvalid;
2498 return 0;
2499 }
2500 if (index_lower > index_higher) // swap indices if required
2501 {
2502 unsigned long temp = index_lower;
2503 index_lower = index_higher;
2504 index_higher = temp;
2505 }
2506 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
2507 {
2508 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2509 if (!root.get())
2510 {
2511 *first_unparsed = expression_cstr;
2512 *reason_to_stop = ValueObject::eNoSuchChild;
2513 *final_result = ValueObject::eInvalid;
2514 return 0;
2515 }
2516 else
2517 {
2518 list->Append(root);
2519 *first_unparsed = end+1; // skip ]
2520 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2521 *final_result = ValueObject::eValueObjectList;
2522 return 1;
2523 }
2524 }
2525 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
2526 *what_next == ValueObject::eDereference &&
2527 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2528 {
2529 Error error;
2530 root = root->Dereference(error);
2531 if (error.Fail() || !root.get())
2532 {
2533 *first_unparsed = expression_cstr;
2534 *reason_to_stop = ValueObject::eDereferencingFailed;
2535 *final_result = ValueObject::eInvalid;
2536 return 0;
2537 }
2538 else
2539 {
2540 *what_next = ValueObject::eNothing;
2541 continue;
2542 }
2543 }
2544 else
2545 {
Johnny Chen44805302011-07-19 19:48:13 +00002546 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002547 index <= index_higher; index++)
2548 {
2549 ValueObjectSP child =
2550 root->GetChildAtIndex(index, true);
2551 list->Append(child);
2552 }
2553 *first_unparsed = end+1;
2554 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2555 *final_result = ValueObject::eValueObjectList;
2556 return index_higher-index_lower+1; // tell me number of items I added to the VOList
2557 }
2558 }
2559 break;
2560 }
2561 default: // some non-[ separator, or something entirely wrong, is in the way
2562 {
2563 *first_unparsed = expression_cstr;
2564 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2565 *final_result = ValueObject::eInvalid;
2566 return 0;
2567 break;
2568 }
2569 }
2570 }
2571}
2572
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002573void
Greg Clayton1d3afba2010-10-05 00:00:42 +00002574ValueObject::DumpValueObject
2575(
2576 Stream &s,
Greg Clayton1d3afba2010-10-05 00:00:42 +00002577 ValueObject *valobj,
2578 const char *root_valobj_name,
2579 uint32_t ptr_depth,
2580 uint32_t curr_depth,
2581 uint32_t max_depth,
2582 bool show_types,
2583 bool show_location,
2584 bool use_objc,
Jim Ingham2837b762011-05-04 03:43:18 +00002585 lldb::DynamicValueType use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00002586 bool use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002587 bool scope_already_checked,
Enrico Granata0c5ef692011-07-16 01:22:04 +00002588 bool flat_output,
2589 uint32_t omit_summary_depth
Greg Clayton1d3afba2010-10-05 00:00:42 +00002590)
2591{
Greg Clayton007d5be2011-05-30 00:49:24 +00002592 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002593 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00002594 bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00002595
2596 if (update_success && use_dynamic != lldb::eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00002597 {
Jim Ingham2837b762011-05-04 03:43:18 +00002598 ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00002599 if (dynamic_value)
2600 valobj = dynamic_value;
2601 }
2602
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002603 clang_type_t clang_type = valobj->GetClangType();
2604
Greg Clayton73b472d2010-10-27 03:32:59 +00002605 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002606 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00002607 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
2608 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002609
2610 const bool print_valobj = flat_output == false || has_value;
2611
2612 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002613 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002614 if (show_location)
2615 {
Jim Ingham6035b672011-03-31 00:19:25 +00002616 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002617 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002618
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002619 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00002620
Greg Clayton7c8a9662010-11-02 01:50:16 +00002621 // Always show the type for the top level items.
Greg Claytone221f822011-01-21 01:59:00 +00002622 if (show_types || (curr_depth == 0 && !flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00002623 {
Enrico Granata9910bc82011-08-03 02:18:51 +00002624 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
2625 s.Printf("(%s", typeName);
2626 // only show dynamic types if the user really wants to see types
2627 if (show_types && use_dynamic != lldb::eNoDynamicValues &&
2628 (/*strstr(typeName, "id") == typeName ||*/
2629 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == lldb::eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00002630 {
2631 Process* process = valobj->GetUpdatePoint().GetProcessSP().get();
2632 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00002633 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002634 else
2635 {
2636 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
2637 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00002638 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002639 else
2640 {
2641 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
2642 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00002643 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002644 else
2645 s.Printf(", dynamic type: %s) ",
2646 runtime->GetActualTypeName(isa).GetCString());
2647 }
2648 }
2649 }
2650 else
2651 s.Printf(") ");
2652 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002653
Greg Clayton1d3afba2010-10-05 00:00:42 +00002654
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002655 if (flat_output)
2656 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00002657 // If we are showing types, also qualify the C++ base classes
2658 const bool qualify_cxx_base_classes = show_types;
2659 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002660 s.PutCString(" =");
2661 }
2662 else
2663 {
2664 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
2665 s.Printf ("%s =", name_cstr);
2666 }
2667
Jim Ingham6035b672011-03-31 00:19:25 +00002668 if (!scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002669 {
Greg Clayton007d5be2011-05-30 00:49:24 +00002670 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002671 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002672 }
2673
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002674 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00002675 const char *sum_cstr = NULL;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002676 SummaryFormat* entry = valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002677
Enrico Granata0c5ef692011-07-16 01:22:04 +00002678 if (omit_summary_depth > 0)
2679 entry = NULL;
2680
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002681 if (err_cstr == NULL)
2682 {
Jim Ingham6035b672011-03-31 00:19:25 +00002683 val_cstr = valobj->GetValueAsCString();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002684 err_cstr = valobj->GetError().AsCString();
2685 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002686
2687 if (err_cstr)
2688 {
Greg Clayton007d5be2011-05-30 00:49:24 +00002689 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00002690 }
2691 else
2692 {
Greg Clayton73b472d2010-10-27 03:32:59 +00002693 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002694 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002695 {
Enrico Granata4becb372011-06-29 22:27:15 +00002696
Enrico Granata0c5ef692011-07-16 01:22:04 +00002697 sum_cstr = (omit_summary_depth == 0) ? valobj->GetSummaryAsCString() : NULL;
Greg Clayton1d3afba2010-10-05 00:00:42 +00002698
Enrico Granata4becb372011-06-29 22:27:15 +00002699 // We must calculate this value in realtime because entry might alter this variable's value
2700 // (e.g. by saying ${var%fmt}) and render precached values useless
2701 if (val_cstr && (!entry || entry->DoesPrintValue() || !sum_cstr))
2702 s.Printf(" %s", valobj->GetValueAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002703
Enrico Granata9dd75c82011-07-15 23:30:15 +00002704 if (sum_cstr)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002705 {
2706 // for some reason, using %@ (ObjC description) in a summary string, makes
2707 // us believe we need to reset ourselves, thus invalidating the content of
2708 // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty
2709 // let us recalculate it!
2710 if (sum_cstr[0] == '\0')
2711 s.Printf(" %s", valobj->GetSummaryAsCString());
2712 else
2713 s.Printf(" %s", sum_cstr);
2714 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002715
2716 if (use_objc)
2717 {
Jim Ingham6035b672011-03-31 00:19:25 +00002718 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002719 if (object_desc)
2720 s.Printf(" %s\n", object_desc);
2721 else
Sean Callanan672ad942010-10-23 00:18:49 +00002722 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002723 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00002724 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002725 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002726
2727 if (curr_depth < max_depth)
2728 {
Greg Clayton73b472d2010-10-27 03:32:59 +00002729 // We will show children for all concrete types. We won't show
2730 // pointer contents unless a pointer depth has been specified.
2731 // We won't reference contents unless the reference is the
2732 // root object (depth of zero).
2733 bool print_children = true;
2734
2735 // Use a new temporary pointer depth in case we override the
2736 // current pointer depth below...
2737 uint32_t curr_ptr_depth = ptr_depth;
2738
2739 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
2740 if (is_ptr || is_ref)
2741 {
2742 // We have a pointer or reference whose value is an address.
2743 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00002744 AddressType ptr_address_type;
Greg Clayton73b472d2010-10-27 03:32:59 +00002745 if (valobj->GetPointerValue (ptr_address_type, true) == 0)
2746 print_children = false;
2747
2748 else if (is_ref && curr_depth == 0)
2749 {
2750 // If this is the root object (depth is zero) that we are showing
2751 // and it is a reference, and no pointer depth has been supplied
2752 // print out what it references. Don't do this at deeper depths
2753 // otherwise we can end up with infinite recursion...
2754 curr_ptr_depth = 1;
2755 }
2756
2757 if (curr_ptr_depth == 0)
2758 print_children = false;
2759 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002760
Enrico Granata0a3958e2011-07-02 00:25:22 +00002761 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00002762 {
Enrico Granatad55546b2011-07-22 00:16:08 +00002763 ValueObjectSP synth_vobj = valobj->GetSyntheticValue(use_synth ?
2764 lldb::eUseSyntheticFilter :
2765 lldb::eNoSyntheticFilter);
2766 const uint32_t num_children = synth_vobj->GetNumChildren();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002767 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002768 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002769 if (flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002770 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002771 if (print_valobj)
2772 s.EOL();
2773 }
2774 else
2775 {
2776 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00002777 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002778 s.IndentMore();
2779 }
2780
2781 for (uint32_t idx=0; idx<num_children; ++idx)
2782 {
Enrico Granatad55546b2011-07-22 00:16:08 +00002783 ValueObjectSP child_sp(synth_vobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002784 if (child_sp.get())
2785 {
2786 DumpValueObject (s,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002787 child_sp.get(),
2788 NULL,
Greg Clayton73b472d2010-10-27 03:32:59 +00002789 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002790 curr_depth + 1,
2791 max_depth,
2792 show_types,
2793 show_location,
2794 false,
Jim Ingham78a685a2011-04-16 00:01:13 +00002795 use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00002796 use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002797 true,
Enrico Granata0c5ef692011-07-16 01:22:04 +00002798 flat_output,
2799 omit_summary_depth > 1 ? omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002800 }
2801 }
2802
2803 if (!flat_output)
2804 {
2805 s.IndentLess();
2806 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00002807 }
2808 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002809 else if (has_children)
2810 {
2811 // Aggregate, no children...
2812 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00002813 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002814 }
2815 else
2816 {
2817 if (print_valobj)
2818 s.EOL();
2819 }
2820
Greg Clayton1d3afba2010-10-05 00:00:42 +00002821 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002822 else
2823 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00002824 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00002825 }
2826 }
2827 else
2828 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002829 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002830 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002831 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00002832 }
2833 }
2834 }
2835 }
2836}
2837
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002838
2839ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00002840ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002841{
2842 ValueObjectSP valobj_sp;
2843
Enrico Granatac3e320a2011-08-02 17:27:39 +00002844 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002845 {
Jim Ingham6035b672011-03-31 00:19:25 +00002846 ExecutionContextScope *exe_scope = GetExecutionContextScope();
2847 if (exe_scope)
2848 {
2849 ExecutionContext exe_ctx;
2850 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002851
Jim Ingham6035b672011-03-31 00:19:25 +00002852 clang::ASTContext *ast = GetClangAST ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002853
Jim Ingham6035b672011-03-31 00:19:25 +00002854 DataExtractor data;
2855 data.SetByteOrder (m_data.GetByteOrder());
2856 data.SetAddressByteSize(m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002857
Greg Clayton644247c2011-07-07 01:59:51 +00002858 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002859
Jim Ingham58b59f92011-04-22 23:53:53 +00002860 valobj_sp = ValueObjectConstResult::Create (exe_scope,
2861 ast,
2862 GetClangType(),
2863 name,
2864 data);
Jim Ingham6035b672011-03-31 00:19:25 +00002865 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002866 }
Jim Ingham6035b672011-03-31 00:19:25 +00002867
2868 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002869 {
Jim Ingham58b59f92011-04-22 23:53:53 +00002870 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002871 }
2872 return valobj_sp;
2873}
2874
2875lldb::ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00002876ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002877{
Jim Ingham58b59f92011-04-22 23:53:53 +00002878 if (m_deref_valobj)
2879 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00002880
Greg Clayton54979cd2010-12-15 05:08:08 +00002881 const bool is_pointer_type = IsPointerType();
2882 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002883 {
2884 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00002885 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002886
2887 std::string child_name_str;
2888 uint32_t child_byte_size = 0;
2889 int32_t child_byte_offset = 0;
2890 uint32_t child_bitfield_bit_size = 0;
2891 uint32_t child_bitfield_bit_offset = 0;
2892 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00002893 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002894 const bool transparent_pointers = false;
2895 clang::ASTContext *clang_ast = GetClangAST();
2896 clang_type_t clang_type = GetClangType();
2897 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00002898
2899 ExecutionContext exe_ctx;
2900 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
2901
2902 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
2903 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002904 GetName().GetCString(),
2905 clang_type,
2906 0,
2907 transparent_pointers,
2908 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00002909 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002910 child_name_str,
2911 child_byte_size,
2912 child_byte_offset,
2913 child_bitfield_bit_size,
2914 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00002915 child_is_base_class,
2916 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00002917 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002918 {
2919 ConstString child_name;
2920 if (!child_name_str.empty())
2921 child_name.SetCString (child_name_str.c_str());
2922
Jim Ingham58b59f92011-04-22 23:53:53 +00002923 m_deref_valobj = new ValueObjectChild (*this,
2924 clang_ast,
2925 child_clang_type,
2926 child_name,
2927 child_byte_size,
2928 child_byte_offset,
2929 child_bitfield_bit_size,
2930 child_bitfield_bit_offset,
2931 child_is_base_class,
2932 child_is_deref_of_parent);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002933 }
2934 }
Greg Clayton54979cd2010-12-15 05:08:08 +00002935
Jim Ingham58b59f92011-04-22 23:53:53 +00002936 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00002937 {
2938 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00002939 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00002940 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002941 else
2942 {
Greg Clayton54979cd2010-12-15 05:08:08 +00002943 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00002944 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00002945
2946 if (is_pointer_type)
2947 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
2948 else
2949 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00002950 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002951 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002952}
2953
Jim Ingham78a685a2011-04-16 00:01:13 +00002954lldb::ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00002955ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002956{
Jim Ingham78a685a2011-04-16 00:01:13 +00002957 if (m_addr_of_valobj_sp)
2958 return m_addr_of_valobj_sp;
2959
Greg Claytone0d378b2011-03-24 21:19:54 +00002960 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002961 const bool scalar_is_load_address = false;
2962 lldb::addr_t addr = GetAddressOf (address_type, scalar_is_load_address);
Greg Clayton54979cd2010-12-15 05:08:08 +00002963 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002964 if (addr != LLDB_INVALID_ADDRESS)
2965 {
2966 switch (address_type)
2967 {
Greg Clayton54979cd2010-12-15 05:08:08 +00002968 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002969 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00002970 {
2971 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00002972 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00002973 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
2974 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002975 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00002976
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002977 case eAddressTypeFile:
2978 case eAddressTypeLoad:
2979 case eAddressTypeHost:
2980 {
2981 clang::ASTContext *ast = GetClangAST();
2982 clang_type_t clang_type = GetClangType();
2983 if (ast && clang_type)
2984 {
2985 std::string name (1, '&');
2986 name.append (m_name.AsCString(""));
Jim Ingham58b59f92011-04-22 23:53:53 +00002987 m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(),
2988 ast,
2989 ClangASTContext::CreatePointerType (ast, clang_type),
2990 ConstString (name.c_str()),
2991 addr,
2992 eAddressTypeInvalid,
2993 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00002994 }
2995 }
2996 break;
2997 }
2998 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002999 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003000}
3001
Greg Claytonb2dcc362011-05-05 23:32:56 +00003002
3003lldb::ValueObjectSP
3004ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3005{
3006 lldb::ValueObjectSP valobj_sp;
3007 AddressType address_type;
3008 const bool scalar_is_load_address = true;
3009 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address);
3010
3011 if (ptr_value != LLDB_INVALID_ADDRESS)
3012 {
3013 Address ptr_addr (NULL, ptr_value);
3014
3015 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3016 name,
3017 ptr_addr,
3018 clang_ast_type);
3019 }
3020 return valobj_sp;
3021}
3022
3023lldb::ValueObjectSP
3024ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3025{
3026 lldb::ValueObjectSP valobj_sp;
3027 AddressType address_type;
3028 const bool scalar_is_load_address = true;
3029 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address);
3030
3031 if (ptr_value != LLDB_INVALID_ADDRESS)
3032 {
3033 Address ptr_addr (NULL, ptr_value);
3034
3035 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3036 name,
3037 ptr_addr,
3038 type_sp);
3039 }
3040 return valobj_sp;
3041}
3042
Jim Ingham6035b672011-03-31 00:19:25 +00003043ValueObject::EvaluationPoint::EvaluationPoint () :
Stephen Wilson71c21d12011-04-11 19:41:40 +00003044 m_thread_id (LLDB_INVALID_UID),
3045 m_stop_id (0)
Jim Ingham6035b672011-03-31 00:19:25 +00003046{
3047}
3048
3049ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Jim Ingham6035b672011-03-31 00:19:25 +00003050 m_needs_update (true),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003051 m_first_update (true),
Jim Ingham89b61092011-07-06 17:42:14 +00003052 m_thread_id (LLDB_INVALID_THREAD_ID),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003053 m_stop_id (0)
3054
Jim Ingham6035b672011-03-31 00:19:25 +00003055{
3056 ExecutionContext exe_ctx;
3057 ExecutionContextScope *computed_exe_scope = exe_scope; // If use_selected is true, we may find a better scope,
3058 // and if so we want to cache that not the original.
3059 if (exe_scope)
3060 exe_scope->CalculateExecutionContext(exe_ctx);
3061 if (exe_ctx.target != NULL)
3062 {
3063 m_target_sp = exe_ctx.target->GetSP();
3064
3065 if (exe_ctx.process == NULL)
3066 m_process_sp = exe_ctx.target->GetProcessSP();
3067 else
3068 m_process_sp = exe_ctx.process->GetSP();
3069
3070 if (m_process_sp != NULL)
3071 {
3072 m_stop_id = m_process_sp->GetStopID();
3073 Thread *thread = NULL;
3074
3075 if (exe_ctx.thread == NULL)
3076 {
3077 if (use_selected)
3078 {
3079 thread = m_process_sp->GetThreadList().GetSelectedThread().get();
3080 if (thread)
3081 computed_exe_scope = thread;
3082 }
3083 }
3084 else
3085 thread = exe_ctx.thread;
3086
3087 if (thread != NULL)
3088 {
3089 m_thread_id = thread->GetIndexID();
3090 if (exe_ctx.frame == NULL)
3091 {
3092 if (use_selected)
3093 {
3094 StackFrame *frame = exe_ctx.thread->GetSelectedFrame().get();
3095 if (frame)
3096 {
3097 m_stack_id = frame->GetStackID();
3098 computed_exe_scope = frame;
3099 }
3100 }
3101 }
3102 else
3103 m_stack_id = exe_ctx.frame->GetStackID();
3104 }
3105 }
3106 }
3107 m_exe_scope = computed_exe_scope;
3108}
3109
3110ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
3111 m_exe_scope (rhs.m_exe_scope),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003112 m_needs_update(true),
3113 m_first_update(true),
Jim Ingham6035b672011-03-31 00:19:25 +00003114 m_target_sp (rhs.m_target_sp),
3115 m_process_sp (rhs.m_process_sp),
3116 m_thread_id (rhs.m_thread_id),
3117 m_stack_id (rhs.m_stack_id),
Jim Ingham6035b672011-03-31 00:19:25 +00003118 m_stop_id (0)
3119{
3120}
3121
3122ValueObject::EvaluationPoint::~EvaluationPoint ()
3123{
3124}
3125
3126ExecutionContextScope *
3127ValueObject::EvaluationPoint::GetExecutionContextScope ()
3128{
3129 // We have to update before giving out the scope, or we could be handing out stale pointers.
3130 SyncWithProcessState();
3131
3132 return m_exe_scope;
3133}
3134
3135// This function checks the EvaluationPoint against the current process state. If the current
3136// state matches the evaluation point, or the evaluation point is already invalid, then we return
3137// false, meaning "no change". If the current state is different, we update our state, and return
3138// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3139// future calls to NeedsUpdate will return true.
3140
3141bool
3142ValueObject::EvaluationPoint::SyncWithProcessState()
3143{
3144 // If we're already invalid, we don't need to do anything, and nothing has changed:
3145 if (m_stop_id == LLDB_INVALID_UID)
3146 {
3147 // Can't update with an invalid state.
3148 m_needs_update = false;
3149 return false;
3150 }
3151
3152 // If we don't have a process nothing can change.
3153 if (!m_process_sp)
3154 return false;
3155
3156 // If our stop id is the current stop ID, nothing has changed:
Jim Ingham78a685a2011-04-16 00:01:13 +00003157 uint32_t cur_stop_id = m_process_sp->GetStopID();
3158 if (m_stop_id == cur_stop_id)
Jim Ingham6035b672011-03-31 00:19:25 +00003159 return false;
3160
Jim Ingham78a685a2011-04-16 00:01:13 +00003161 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3162 // In either case, we aren't going to be able to sync with the process state.
3163 if (cur_stop_id == 0)
3164 return false;
3165
3166 m_stop_id = cur_stop_id;
Jim Ingham6035b672011-03-31 00:19:25 +00003167 m_needs_update = true;
3168 m_exe_scope = m_process_sp.get();
3169
3170 // Something has changed, so we will return true. Now make sure the thread & frame still exist, and if either
3171 // doesn't, mark ourselves as invalid.
3172
3173 if (m_thread_id != LLDB_INVALID_THREAD_ID)
3174 {
3175 Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get();
3176 if (our_thread == NULL)
Greg Clayton262f80d2011-07-06 16:49:27 +00003177 {
Jim Ingham89b61092011-07-06 17:42:14 +00003178 SetInvalid();
Greg Clayton262f80d2011-07-06 16:49:27 +00003179 }
Jim Ingham6035b672011-03-31 00:19:25 +00003180 else
3181 {
3182 m_exe_scope = our_thread;
3183
3184 if (m_stack_id.IsValid())
3185 {
3186 StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get();
3187 if (our_frame == NULL)
3188 SetInvalid();
3189 else
3190 m_exe_scope = our_frame;
3191 }
3192 }
3193 }
3194 return true;
3195}
3196
Jim Ingham61be0902011-05-02 18:13:59 +00003197void
3198ValueObject::EvaluationPoint::SetUpdated ()
3199{
3200 m_first_update = false;
3201 m_needs_update = false;
3202 if (m_process_sp)
3203 m_stop_id = m_process_sp->GetStopID();
3204}
3205
3206
Jim Ingham6035b672011-03-31 00:19:25 +00003207bool
3208ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3209{
3210 if (!IsValid())
3211 return false;
3212
3213 bool needs_update = false;
3214 m_exe_scope = NULL;
3215
3216 // The target has to be non-null, and the
3217 Target *target = exe_scope->CalculateTarget();
3218 if (target != NULL)
3219 {
3220 Target *old_target = m_target_sp.get();
3221 assert (target == old_target);
3222 Process *process = exe_scope->CalculateProcess();
3223 if (process != NULL)
3224 {
3225 // FOR NOW - assume you can't update variable objects across process boundaries.
3226 Process *old_process = m_process_sp.get();
3227 assert (process == old_process);
3228
3229 lldb::user_id_t stop_id = process->GetStopID();
3230 if (stop_id != m_stop_id)
3231 {
3232 needs_update = true;
3233 m_stop_id = stop_id;
3234 }
3235 // See if we're switching the thread or stack context. If no thread is given, this is
3236 // being evaluated in a global context.
3237 Thread *thread = exe_scope->CalculateThread();
3238 if (thread != NULL)
3239 {
3240 lldb::user_id_t new_thread_index = thread->GetIndexID();
3241 if (new_thread_index != m_thread_id)
3242 {
3243 needs_update = true;
3244 m_thread_id = new_thread_index;
3245 m_stack_id.Clear();
3246 }
3247
3248 StackFrame *new_frame = exe_scope->CalculateStackFrame();
3249 if (new_frame != NULL)
3250 {
3251 if (new_frame->GetStackID() != m_stack_id)
3252 {
3253 needs_update = true;
3254 m_stack_id = new_frame->GetStackID();
3255 }
3256 }
3257 else
3258 {
3259 m_stack_id.Clear();
3260 needs_update = true;
3261 }
3262 }
3263 else
3264 {
3265 // If this had been given a thread, and now there is none, we should update.
3266 // Otherwise we don't have to do anything.
3267 if (m_thread_id != LLDB_INVALID_UID)
3268 {
3269 m_thread_id = LLDB_INVALID_UID;
3270 m_stack_id.Clear();
3271 needs_update = true;
3272 }
3273 }
3274 }
3275 else
3276 {
3277 // If there is no process, then we don't need to update anything.
3278 // But if we're switching from having a process to not, we should try to update.
3279 if (m_process_sp.get() != NULL)
3280 {
3281 needs_update = true;
3282 m_process_sp.reset();
3283 m_thread_id = LLDB_INVALID_UID;
3284 m_stack_id.Clear();
3285 }
3286 }
3287 }
3288 else
3289 {
3290 // If there's no target, nothing can change so we don't need to update anything.
3291 // But if we're switching from having a target to not, we should try to update.
3292 if (m_target_sp.get() != NULL)
3293 {
3294 needs_update = true;
3295 m_target_sp.reset();
3296 m_process_sp.reset();
3297 m_thread_id = LLDB_INVALID_UID;
3298 m_stack_id.Clear();
3299 }
3300 }
3301 if (!m_needs_update)
3302 m_needs_update = needs_update;
3303
3304 return needs_update;
3305}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003306
3307void
3308ValueObject::ClearUserVisibleData()
3309{
3310 m_location_str.clear();
3311 m_value_str.clear();
3312 m_summary_str.clear();
3313 m_object_desc_str.clear();
Johnny Chen44805302011-07-19 19:48:13 +00003314}