blob: 948109d5415cedae4c25e064235af0fee796f5ae [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/ValueObject.h"
11
12// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000013#include <stdlib.h>
14
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015// C++ Includes
16// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000018#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
20// Project includes
21#include "lldb/Core/DataBufferHeap.h"
Enrico Granata0a976142011-08-22 22:03:47 +000022#include "lldb/Core/DataVisualization.h"
Enrico Granata4becb372011-06-29 22:27:15 +000023#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000024#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/StreamString.h"
26#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000027#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000028#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000030#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000031#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Greg Clayton7fb56d02011-02-01 01:31:41 +000033#include "lldb/Host/Endian.h"
34
Enrico Granata61a80ba2011-08-12 16:42:31 +000035#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000036#include "lldb/Interpreter/ScriptInterpreterPython.h"
37
Greg Claytone1a916a2010-07-21 22:12:05 +000038#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Symbol/ClangASTContext.h"
40#include "lldb/Symbol/Type.h"
41
Jim Ingham53c47f12010-09-10 23:12:17 +000042#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000043#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000044#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045#include "lldb/Target/Process.h"
46#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000047#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049
Enrico Granataf4efecd2011-07-12 22:56:10 +000050#include "lldb/Utility/RefCounter.h"
51
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052using namespace lldb;
53using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000054using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055
56static lldb::user_id_t g_value_obj_uid = 0;
57
58//----------------------------------------------------------------------
59// ValueObject constructor
60//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000061ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000063 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000064 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065 m_name (),
66 m_data (),
67 m_value (),
68 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000069 m_value_str (),
70 m_old_value_str (),
71 m_location_str (),
72 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000073 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000074 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000075 m_children (),
76 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000077 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000078 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000079 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000080 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000081 m_last_format_mgr_revision(0),
Enrico Granatad8b5fce2011-08-02 23:12:24 +000082 m_last_format_mgr_dynamic(parent.m_last_format_mgr_dynamic),
Enrico Granata9df29e32011-07-19 20:57:44 +000083 m_last_summary_format(),
84 m_forced_summary_format(),
85 m_last_value_format(),
Enrico Granatad55546b2011-07-22 00:16:08 +000086 m_last_synthetic_filter(),
Jim Ingham4b536182011-08-09 02:12:22 +000087 m_user_id_of_forced_summary(),
Greg Clayton288bdf92010-09-02 02:59:18 +000088 m_value_is_valid (false),
89 m_value_did_change (false),
90 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000091 m_old_value_valid (false),
Greg Claytone221f822011-01-21 01:59:00 +000092 m_pointers_point_to_load_addrs (false),
Enrico Granata4becb372011-06-29 22:27:15 +000093 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000094 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000095 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +000096 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000097 m_is_child_at_offset(false),
Enrico Granata9910bc82011-08-03 02:18:51 +000098 m_is_expression_result(parent.m_is_expression_result),
Enrico Granataf4efecd2011-07-12 22:56:10 +000099 m_dump_printable_counter(0)
Jim Ingham6035b672011-03-31 00:19:25 +0000100{
Jim Ingham58b59f92011-04-22 23:53:53 +0000101 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000102}
103
104//----------------------------------------------------------------------
105// ValueObject constructor
106//----------------------------------------------------------------------
107ValueObject::ValueObject (ExecutionContextScope *exe_scope) :
108 UserID (++g_value_obj_uid), // Unique identifier for every value object
109 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000110 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000111 m_name (),
112 m_data (),
113 m_value (),
114 m_error (),
115 m_value_str (),
116 m_old_value_str (),
117 m_location_str (),
118 m_summary_str (),
119 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000120 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000121 m_children (),
122 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000123 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000124 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000125 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000126 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000127 m_last_format_mgr_revision(0),
Enrico Granatac3e320a2011-08-02 17:27:39 +0000128 m_last_format_mgr_dynamic(lldb::eNoDynamicValues),
Enrico Granata9df29e32011-07-19 20:57:44 +0000129 m_last_summary_format(),
130 m_forced_summary_format(),
131 m_last_value_format(),
Enrico Granatad55546b2011-07-22 00:16:08 +0000132 m_last_synthetic_filter(),
Jim Ingham4b536182011-08-09 02:12:22 +0000133 m_user_id_of_forced_summary(),
Jim Ingham6035b672011-03-31 00:19:25 +0000134 m_value_is_valid (false),
135 m_value_did_change (false),
136 m_children_count_valid (false),
137 m_old_value_valid (false),
138 m_pointers_point_to_load_addrs (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000139 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000140 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000141 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000142 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000143 m_is_child_at_offset(false),
Enrico Granatac3e320a2011-08-02 17:27:39 +0000144 m_is_expression_result(false),
Enrico Granataf4efecd2011-07-12 22:56:10 +0000145 m_dump_printable_counter(0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146{
Jim Ingham58b59f92011-04-22 23:53:53 +0000147 m_manager = new ValueObjectManager();
148 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000149}
150
151//----------------------------------------------------------------------
152// Destructor
153//----------------------------------------------------------------------
154ValueObject::~ValueObject ()
155{
156}
157
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000159ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000161 return UpdateValueIfNeeded(m_last_format_mgr_dynamic, update_format);
162}
163
164bool
165ValueObject::UpdateValueIfNeeded (lldb::DynamicValueType use_dynamic, bool update_format)
166{
Enrico Granata4becb372011-06-29 22:27:15 +0000167
Enrico Granata0a3958e2011-07-02 00:25:22 +0000168 if (update_format)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000169 UpdateFormatsIfNeeded(use_dynamic);
Enrico Granata4becb372011-06-29 22:27:15 +0000170
Greg Claytonb71f3842010-10-05 03:13:51 +0000171 // If this is a constant value, then our success is predicated on whether
172 // we have an error or not
173 if (GetIsConstant())
174 return m_error.Success();
175
Jim Ingham6035b672011-03-31 00:19:25 +0000176 bool first_update = m_update_point.IsFirstEvaluation();
177
178 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000179 {
Jim Ingham6035b672011-03-31 00:19:25 +0000180 m_update_point.SetUpdated();
181
182 // Save the old value using swap to avoid a string copy which
183 // also will clear our m_value_str
184 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000185 {
Jim Ingham6035b672011-03-31 00:19:25 +0000186 m_old_value_valid = false;
187 }
188 else
189 {
190 m_old_value_valid = true;
191 m_old_value_str.swap (m_value_str);
192 m_value_str.clear();
193 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000194
Enrico Granataf2bbf712011-07-15 02:26:42 +0000195 ClearUserVisibleData();
196
Jim Ingham6035b672011-03-31 00:19:25 +0000197 const bool value_was_valid = GetValueIsValid();
198 SetValueDidChange (false);
Greg Clayton73b953b2010-08-28 00:08:07 +0000199
Jim Ingham6035b672011-03-31 00:19:25 +0000200 m_error.Clear();
Greg Clayton73b953b2010-08-28 00:08:07 +0000201
Jim Ingham6035b672011-03-31 00:19:25 +0000202 // Call the pure virtual function to update the value
203 bool success = UpdateValue ();
204
205 SetValueIsValid (success);
206
207 if (first_update)
208 SetValueDidChange (false);
209 else if (!m_value_did_change && success == false)
210 {
211 // The value wasn't gotten successfully, so we mark this
212 // as changed if the value used to be valid and now isn't
213 SetValueDidChange (value_was_valid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214 }
215 }
216 return m_error.Success();
217}
218
Enrico Granata4becb372011-06-29 22:27:15 +0000219void
Enrico Granatac3e320a2011-08-02 17:27:39 +0000220ValueObject::UpdateFormatsIfNeeded(lldb::DynamicValueType use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000221{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000222 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
223 if (log)
224 log->Printf("checking for FormatManager revisions. VO named %s is at revision %d, while the format manager is at revision %d",
225 GetName().GetCString(),
Enrico Granata4becb372011-06-29 22:27:15 +0000226 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000227 DataVisualization::GetCurrentRevision());
Jim Ingham4b536182011-08-09 02:12:22 +0000228 if (HasCustomSummaryFormat() && m_update_point.GetModID() != m_user_id_of_forced_summary)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000229 {
230 ClearCustomSummaryFormat();
231 m_summary_str.clear();
232 }
Enrico Granata85933ed2011-08-18 16:38:26 +0000233 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) ||
Enrico Granatac3e320a2011-08-02 17:27:39 +0000234 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000235 {
236 if (m_last_summary_format.get())
Enrico Granataf2bbf712011-07-15 02:26:42 +0000237 m_last_summary_format.reset((StringSummaryFormat*)NULL);
Enrico Granata4becb372011-06-29 22:27:15 +0000238 if (m_last_value_format.get())
Enrico Granatad55546b2011-07-22 00:16:08 +0000239 m_last_value_format.reset(/*(ValueFormat*)NULL*/);
240 if (m_last_synthetic_filter.get())
241 m_last_synthetic_filter.reset(/*(SyntheticFilter*)NULL*/);
Enrico Granataa37a0652011-07-24 00:14:56 +0000242
243 m_synthetic_value = NULL;
Enrico Granata1490c6f2011-07-19 02:34:21 +0000244
Enrico Granatac482a192011-08-17 22:13:59 +0000245 DataVisualization::ValueFormats::Get(*this, lldb::eNoDynamicValues, m_last_value_format);
246 DataVisualization::GetSummaryFormat(*this, use_dynamic, m_last_summary_format);
247 DataVisualization::GetSyntheticChildren(*this, use_dynamic, m_last_synthetic_filter);
Enrico Granata1490c6f2011-07-19 02:34:21 +0000248
Enrico Granata85933ed2011-08-18 16:38:26 +0000249 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000250 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granataf2bbf712011-07-15 02:26:42 +0000251
252 ClearUserVisibleData();
Enrico Granata4becb372011-06-29 22:27:15 +0000253 }
254}
255
Jim Ingham16e0c682011-08-12 23:34:31 +0000256void
257ValueObject::SetNeedsUpdate ()
258{
259 m_update_point.SetNeedsUpdate();
260 // We have to clear the value string here so ConstResult children will notice if their values are
261 // changed by hand (i.e. with SetValueAsCString).
262 m_value_str.clear();
263}
264
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265DataExtractor &
266ValueObject::GetDataExtractor ()
267{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000268 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000269 return m_data;
270}
271
272const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000273ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000274{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000275 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276 return m_error;
277}
278
279const ConstString &
280ValueObject::GetName() const
281{
282 return m_name;
283}
284
285const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000286ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000287{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000288 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000289 {
290 if (m_location_str.empty())
291 {
292 StreamString sstr;
293
294 switch (m_value.GetValueType())
295 {
296 default:
297 break;
298
299 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000300 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000301 {
302 RegisterInfo *reg_info = m_value.GetRegisterInfo();
303 if (reg_info)
304 {
305 if (reg_info->name)
306 m_location_str = reg_info->name;
307 else if (reg_info->alt_name)
308 m_location_str = reg_info->alt_name;
309 break;
310 }
311 }
312 m_location_str = "scalar";
313 break;
314
315 case Value::eValueTypeLoadAddress:
316 case Value::eValueTypeFileAddress:
317 case Value::eValueTypeHostAddress:
318 {
319 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
320 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
321 m_location_str.swap(sstr.GetString());
322 }
323 break;
324 }
325 }
326 }
327 return m_location_str.c_str();
328}
329
330Value &
331ValueObject::GetValue()
332{
333 return m_value;
334}
335
336const Value &
337ValueObject::GetValue() const
338{
339 return m_value;
340}
341
342bool
Jim Ingham6035b672011-03-31 00:19:25 +0000343ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000344{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000345 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
346 {
347 ExecutionContext exe_ctx;
348 ExecutionContextScope *exe_scope = GetExecutionContextScope();
349 if (exe_scope)
350 exe_scope->CalculateExecutionContext(exe_ctx);
Jim Ingham16e0c682011-08-12 23:34:31 +0000351 Value tmp_value(m_value);
352 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Enrico Granata6fd87d52011-08-04 01:41:02 +0000353 return scalar.IsValid();
354 }
355 else
356 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000357}
358
359bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000360ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000361{
Greg Clayton288bdf92010-09-02 02:59:18 +0000362 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000363}
364
365
366void
367ValueObject::SetValueIsValid (bool b)
368{
Greg Clayton288bdf92010-09-02 02:59:18 +0000369 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370}
371
372bool
Jim Ingham6035b672011-03-31 00:19:25 +0000373ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374{
Jim Ingham6035b672011-03-31 00:19:25 +0000375 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000376 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000377}
378
379void
380ValueObject::SetValueDidChange (bool value_changed)
381{
Greg Clayton288bdf92010-09-02 02:59:18 +0000382 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383}
384
385ValueObjectSP
386ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
387{
388 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000389 // We may need to update our value if we are dynamic
390 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000391 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000392 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000393 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000394 // Check if we have already made the child value object?
395 if (can_create && m_children[idx] == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000397 // No we haven't created the child at this index, so lets have our
398 // subclass do it and cache the result for quick future access.
399 m_children[idx] = CreateChildAtIndex (idx, false, 0);
Jim Ingham78a685a2011-04-16 00:01:13 +0000400 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000401
402 if (m_children[idx] != NULL)
403 return m_children[idx]->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000404 }
405 return child_sp;
406}
407
408uint32_t
409ValueObject::GetIndexOfChildWithName (const ConstString &name)
410{
411 bool omit_empty_base_classes = true;
412 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000413 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000414 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415 omit_empty_base_classes);
416}
417
418ValueObjectSP
419ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
420{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000421 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422 // classes (which really aren't part of the expression path), so we
423 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000425
Greg Claytondea8cb42011-06-29 22:09:02 +0000426 // We may need to update our value if we are dynamic
427 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000428 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000429
430 std::vector<uint32_t> child_indexes;
431 clang::ASTContext *clang_ast = GetClangAST();
432 void *clang_type = GetClangType();
433 bool omit_empty_base_classes = true;
434 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
435 clang_type,
436 name.GetCString(),
437 omit_empty_base_classes,
438 child_indexes);
439 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000440 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000441 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
442 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
443
444 child_sp = GetChildAtIndex(*pos, can_create);
445 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000447 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000448 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000449 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
450 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000451 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000452 else
453 {
454 child_sp.reset();
455 }
456
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457 }
458 }
459 return child_sp;
460}
461
462
463uint32_t
464ValueObject::GetNumChildren ()
465{
Greg Clayton288bdf92010-09-02 02:59:18 +0000466 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000467 {
468 SetNumChildren (CalculateNumChildren());
469 }
470 return m_children.size();
471}
472void
473ValueObject::SetNumChildren (uint32_t num_children)
474{
Greg Clayton288bdf92010-09-02 02:59:18 +0000475 m_children_count_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476 m_children.resize(num_children);
477}
478
479void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480ValueObject::SetName (const ConstString &name)
481{
482 m_name = name;
483}
484
Jim Ingham58b59f92011-04-22 23:53:53 +0000485ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
487{
Jim Ingham2eec4872011-05-07 00:10:58 +0000488 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000489
Greg Claytondea8cb42011-06-29 22:09:02 +0000490 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000491 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000492 std::string child_name_str;
493 uint32_t child_byte_size = 0;
494 int32_t child_byte_offset = 0;
495 uint32_t child_bitfield_bit_size = 0;
496 uint32_t child_bitfield_bit_offset = 0;
497 bool child_is_base_class = false;
498 bool child_is_deref_of_parent = false;
499
500 const bool transparent_pointers = synthetic_array_member == false;
501 clang::ASTContext *clang_ast = GetClangAST();
502 clang_type_t clang_type = GetClangType();
503 clang_type_t child_clang_type;
504
505 ExecutionContext exe_ctx;
506 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
507
508 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
509 clang_ast,
510 GetName().GetCString(),
511 clang_type,
512 idx,
513 transparent_pointers,
514 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000515 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000516 child_name_str,
517 child_byte_size,
518 child_byte_offset,
519 child_bitfield_bit_size,
520 child_bitfield_bit_offset,
521 child_is_base_class,
522 child_is_deref_of_parent);
523 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000525 if (synthetic_index)
526 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527
Greg Claytondea8cb42011-06-29 22:09:02 +0000528 ConstString child_name;
529 if (!child_name_str.empty())
530 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531
Greg Claytondea8cb42011-06-29 22:09:02 +0000532 valobj = new ValueObjectChild (*this,
533 clang_ast,
534 child_clang_type,
535 child_name,
536 child_byte_size,
537 child_byte_offset,
538 child_bitfield_bit_size,
539 child_bitfield_bit_offset,
540 child_is_base_class,
541 child_is_deref_of_parent);
542 if (m_pointers_point_to_load_addrs)
543 valobj->SetPointersPointToLoadAddrs (m_pointers_point_to_load_addrs);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000544 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000545
Jim Ingham58b59f92011-04-22 23:53:53 +0000546 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547}
548
549const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000550ValueObject::GetSummaryAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000551{
Enrico Granatad8b5fce2011-08-02 23:12:24 +0000552 if (UpdateValueIfNeeded (true))
Enrico Granata4becb372011-06-29 22:27:15 +0000553 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000554 if (m_summary_str.empty())
555 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000556 SummaryFormat *summary_format = GetSummaryFormat().get();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000557
558 if (summary_format)
Enrico Granata4becb372011-06-29 22:27:15 +0000559 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000560 m_summary_str = summary_format->FormatObject(GetSP());
Enrico Granata4becb372011-06-29 22:27:15 +0000561 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000562 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000563 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000564 clang_type_t clang_type = GetClangType();
Greg Clayton737b9322010-09-13 03:32:57 +0000565
Enrico Granata9dd75c82011-07-15 23:30:15 +0000566 // Do some default printout for function pointers
Enrico Granataf2bbf712011-07-15 02:26:42 +0000567 if (clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000568 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000569 StreamString sstr;
570 clang_type_t elem_or_pointee_clang_type;
571 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
572 GetClangAST(),
573 &elem_or_pointee_clang_type));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000574
Enrico Granataf2bbf712011-07-15 02:26:42 +0000575 ExecutionContextScope *exe_scope = GetExecutionContextScope();
576 if (exe_scope)
577 {
Enrico Granata9dd75c82011-07-15 23:30:15 +0000578 if (ClangASTContext::IsFunctionPointerType (clang_type))
Jim Ingham6035b672011-03-31 00:19:25 +0000579 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000580 AddressType func_ptr_address_type = eAddressTypeInvalid;
581 lldb::addr_t func_ptr_address = GetPointerValue (func_ptr_address_type, true);
582
583 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
584 {
585 switch (func_ptr_address_type)
586 {
587 case eAddressTypeInvalid:
588 case eAddressTypeFile:
589 break;
590
591 case eAddressTypeLoad:
592 {
593 Address so_addr;
594 Target *target = exe_scope->CalculateTarget();
595 if (target && target->GetSectionLoadList().IsEmpty() == false)
596 {
597 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
598 {
599 so_addr.Dump (&sstr,
600 exe_scope,
601 Address::DumpStyleResolvedDescription,
602 Address::DumpStyleSectionNameOffset);
603 }
604 }
605 }
606 break;
607
608 case eAddressTypeHost:
609 break;
610 }
611 }
612 if (sstr.GetSize() > 0)
613 {
614 m_summary_str.assign (1, '(');
615 m_summary_str.append (sstr.GetData(), sstr.GetSize());
616 m_summary_str.append (1, ')');
617 }
Jim Ingham6035b672011-03-31 00:19:25 +0000618 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000619 }
620 }
621 }
622 }
623 }
624 if (m_summary_str.empty())
625 return NULL;
626 return m_summary_str.c_str();
627}
628
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000629bool
630ValueObject::IsCStringContainer(bool check_pointer)
631{
632 clang_type_t elem_or_pointee_clang_type;
633 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
634 GetClangAST(),
635 &elem_or_pointee_clang_type));
636 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
637 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
638 if (!is_char_arr_ptr)
639 return false;
640 if (!check_pointer)
641 return true;
642 if (type_flags.Test(ClangASTContext::eTypeIsArray))
643 return true;
644 lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS;
645 AddressType cstr_address_type = eAddressTypeInvalid;
646 cstr_address = GetAddressOf (cstr_address_type, true);
647 return (cstr_address != LLDB_INVALID_ADDRESS);
648}
649
650void
651ValueObject::ReadPointedString(Stream& s,
652 Error& error,
Enrico Granataf4efecd2011-07-12 22:56:10 +0000653 uint32_t max_length,
654 bool honor_array,
655 lldb::Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000656{
657
658 if (max_length == 0)
Enrico Granataf4efecd2011-07-12 22:56:10 +0000659 max_length = 128; // FIXME this should be a setting, or a formatting parameter
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000660
661 clang_type_t clang_type = GetClangType();
662 clang_type_t elem_or_pointee_clang_type;
663 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
664 GetClangAST(),
665 &elem_or_pointee_clang_type));
666 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
667 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
668 {
669 ExecutionContextScope *exe_scope = GetExecutionContextScope();
670 if (exe_scope)
671 {
672 Target *target = exe_scope->CalculateTarget();
Enrico Granata6f3533f2011-07-29 19:53:35 +0000673 if (target == NULL)
674 {
675 s << "<no target to read from>";
676 }
677 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000678 {
679 lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS;
680 AddressType cstr_address_type = eAddressTypeInvalid;
681
682 size_t cstr_len = 0;
683 bool capped_data = false;
684 if (type_flags.Test (ClangASTContext::eTypeIsArray))
685 {
686 // We have an array
687 cstr_len = ClangASTContext::GetArraySize (clang_type);
Enrico Granataf4efecd2011-07-12 22:56:10 +0000688 if (cstr_len > max_length)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000689 {
Enrico Granataf4efecd2011-07-12 22:56:10 +0000690 capped_data = true;
691 cstr_len = max_length;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000692 }
693 cstr_address = GetAddressOf (cstr_address_type, true);
694 }
695 else
696 {
697 // We have a pointer
698 cstr_address = GetPointerValue (cstr_address_type, true);
699 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000700 if (cstr_address == LLDB_INVALID_ADDRESS)
701 {
702 s << "<invalid address for data>";
703 }
704 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000705 {
706 Address cstr_so_addr (NULL, cstr_address);
707 DataExtractor data;
708 size_t bytes_read = 0;
709 std::vector<char> data_buffer;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000710 bool prefer_file_cache = false;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000711 if (cstr_len > 0 && honor_array)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000712 {
713 data_buffer.resize(cstr_len);
714 data.SetData (&data_buffer.front(), data_buffer.size(), lldb::endian::InlHostByteOrder());
715 bytes_read = target->ReadMemory (cstr_so_addr,
716 prefer_file_cache,
717 &data_buffer.front(),
718 cstr_len,
719 error);
720 if (bytes_read > 0)
721 {
722 s << '"';
723 data.Dump (&s,
724 0, // Start offset in "data"
Enrico Granataf4efecd2011-07-12 22:56:10 +0000725 item_format,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000726 1, // Size of item (1 byte for a char!)
727 bytes_read, // How many bytes to print?
728 UINT32_MAX, // num per line
729 LLDB_INVALID_ADDRESS,// base address
730 0, // bitfield bit size
731 0); // bitfield bit offset
732 if (capped_data)
733 s << "...";
734 s << '"';
735 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000736 else
737 s << "\"<data not available>\"";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000738 }
739 else
740 {
Enrico Granataf4efecd2011-07-12 22:56:10 +0000741 cstr_len = max_length;
742 const size_t k_max_buf_size = 64;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000743 data_buffer.resize (k_max_buf_size + 1);
744 // NULL terminate in case we don't get the entire C string
745 data_buffer.back() = '\0';
746
747 s << '"';
748
Enrico Granata6f3533f2011-07-29 19:53:35 +0000749 bool any_data = false;
750
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000751 data.SetData (&data_buffer.front(), data_buffer.size(), endian::InlHostByteOrder());
752 while ((bytes_read = target->ReadMemory (cstr_so_addr,
753 prefer_file_cache,
754 &data_buffer.front(),
755 k_max_buf_size,
756 error)) > 0)
757 {
Enrico Granata6f3533f2011-07-29 19:53:35 +0000758 any_data = true;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000759 size_t len = strlen(&data_buffer.front());
760 if (len == 0)
761 break;
762 if (len > bytes_read)
763 len = bytes_read;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000764 if (len > cstr_len)
765 len = cstr_len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000766
767 data.Dump (&s,
768 0, // Start offset in "data"
Enrico Granataf4efecd2011-07-12 22:56:10 +0000769 item_format,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000770 1, // Size of item (1 byte for a char!)
771 len, // How many bytes to print?
772 UINT32_MAX, // num per line
773 LLDB_INVALID_ADDRESS,// base address
774 0, // bitfield bit size
775 0); // bitfield bit offset
776
777 if (len < k_max_buf_size)
778 break;
Enrico Granataf4efecd2011-07-12 22:56:10 +0000779 if (len >= cstr_len)
780 {
781 s << "...";
782 break;
783 }
784 cstr_len -= len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000785 cstr_so_addr.Slide (k_max_buf_size);
786 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000787
788 if (any_data == false)
789 s << "<data not available>";
790
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000791 s << '"';
792 }
793 }
794 }
795 }
796 }
797 else
798 {
799 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +0000800 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000801 }
802}
803
Jim Ingham53c47f12010-09-10 23:12:17 +0000804const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000805ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +0000806{
Enrico Granata0a3958e2011-07-02 00:25:22 +0000807
Enrico Granatad8b5fce2011-08-02 23:12:24 +0000808 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +0000809 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000810
811 if (!m_object_desc_str.empty())
812 return m_object_desc_str.c_str();
813
Jim Ingham6035b672011-03-31 00:19:25 +0000814 ExecutionContextScope *exe_scope = GetExecutionContextScope();
815 if (exe_scope == NULL)
816 return NULL;
817
Jim Ingham53c47f12010-09-10 23:12:17 +0000818 Process *process = exe_scope->CalculateProcess();
Jim Ingham5a369122010-09-28 01:25:32 +0000819 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +0000820 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +0000821
Jim Ingham53c47f12010-09-10 23:12:17 +0000822 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +0000823
824 lldb::LanguageType language = GetObjectRuntimeLanguage();
825 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
826
Jim Inghama2cf2632010-12-23 02:29:54 +0000827 if (runtime == NULL)
828 {
Jim Inghamb7603bb2011-03-18 00:05:18 +0000829 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +0000830 clang_type_t opaque_qual_type = GetClangType();
831 if (opaque_qual_type != NULL)
832 {
Jim Inghamb7603bb2011-03-18 00:05:18 +0000833 bool is_signed;
834 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
835 || ClangASTContext::IsPointerType (opaque_qual_type))
836 {
Jim Inghama2cf2632010-12-23 02:29:54 +0000837 runtime = process->GetLanguageRuntime(lldb::eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +0000838 }
Jim Inghama2cf2632010-12-23 02:29:54 +0000839 }
840 }
841
Jim Ingham8d543de2011-03-31 23:01:21 +0000842 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +0000843 {
844 m_object_desc_str.append (s.GetData());
845 }
Sean Callanan672ad942010-10-23 00:18:49 +0000846
847 if (m_object_desc_str.empty())
848 return NULL;
849 else
850 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +0000851}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000852
853const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000854ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000855{
856 // If our byte size is zero this is an aggregate type that has children
Greg Clayton1be10fc2010-09-29 01:12:09 +0000857 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858 {
Enrico Granatac3e320a2011-08-02 17:27:39 +0000859 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000860 {
861 if (m_value_str.empty())
862 {
863 const Value::ContextType context_type = m_value.GetContextType();
864
865 switch (context_type)
866 {
Greg Clayton526e5af2010-11-13 03:52:47 +0000867 case Value::eContextTypeClangType:
868 case Value::eContextTypeLLDBType:
869 case Value::eContextTypeVariable:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000870 {
Greg Clayton73b472d2010-10-27 03:32:59 +0000871 clang_type_t clang_type = GetClangType ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000872 if (clang_type)
873 {
Enrico Granatac3e320a2011-08-02 17:27:39 +0000874 if (m_format == lldb::eFormatDefault && m_last_value_format)
Enrico Granata4becb372011-06-29 22:27:15 +0000875 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000876 m_value_str = m_last_value_format->FormatObject(GetSP());
Enrico Granata4becb372011-06-29 22:27:15 +0000877 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000878 else
Greg Clayton007d5be2011-05-30 00:49:24 +0000879 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000880 StreamString sstr;
881 Format format = GetFormat();
882 if (format == eFormatDefault)
883 format = (m_is_bitfield_for_scalar ? eFormatUnsigned :
884 ClangASTType::GetFormat(clang_type));
885
886 if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
887 clang_type, // The clang type to display
888 &sstr,
889 format, // Format to display this type with
890 m_data, // Data to extract from
891 0, // Byte offset into "m_data"
892 GetByteSize(), // Byte size of item in "m_data"
893 GetBitfieldBitSize(), // Bitfield bit size
894 GetBitfieldBitOffset())) // Bitfield bit offset
895 m_value_str.swap(sstr.GetString());
896 else
897 {
898 m_error.SetErrorStringWithFormat ("unsufficient data for value (only %u of %u bytes available)",
899 m_data.GetByteSize(),
900 GetByteSize());
901 m_value_str.clear();
902 }
Greg Clayton007d5be2011-05-30 00:49:24 +0000903 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000904 }
905 }
906 break;
907
Greg Clayton526e5af2010-11-13 03:52:47 +0000908 case Value::eContextTypeRegisterInfo:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000909 {
910 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
911 if (reg_info)
912 {
913 StreamString reg_sstr;
914 m_data.Dump(&reg_sstr, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
915 m_value_str.swap(reg_sstr.GetString());
916 }
917 }
918 break;
Greg Claytonc982c762010-07-09 20:39:50 +0000919
920 default:
921 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000922 }
923 }
Greg Clayton288bdf92010-09-02 02:59:18 +0000924
925 if (!m_value_did_change && m_old_value_valid)
926 {
927 // The value was gotten successfully, so we consider the
928 // value as changed if the value string differs
929 SetValueDidChange (m_old_value_str != m_value_str);
930 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000931 }
932 }
933 if (m_value_str.empty())
934 return NULL;
935 return m_value_str.c_str();
936}
937
Enrico Granatac3e320a2011-08-02 17:27:39 +0000938// if > 8bytes, 0 is returned. this method should mostly be used
939// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000940uint64_t
941ValueObject::GetValueAsUnsigned (uint64_t fail_value)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000942{
943 // If our byte size is zero this is an aggregate type that has children
944 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
945 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000946 Scalar scalar;
947 if (ResolveValue (scalar))
948 return scalar.GetRawBits64(fail_value);
Enrico Granatac3e320a2011-08-02 17:27:39 +0000949 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000950 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +0000951}
952
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000953bool
954ValueObject::GetPrintableRepresentation(Stream& s,
955 ValueObjectRepresentationStyle val_obj_display,
Enrico Granata0a3958e2011-07-02 00:25:22 +0000956 lldb::Format custom_format)
957{
Enrico Granataf4efecd2011-07-12 22:56:10 +0000958
959 RefCounter ref(&m_dump_printable_counter);
960
Enrico Granata9dd75c82011-07-15 23:30:15 +0000961 if (custom_format != lldb::eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +0000962 SetFormat(custom_format);
963
964 const char * return_value;
Enrico Granatacd1c0232011-08-04 23:37:18 +0000965 std::string alloc_mem;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000966
967 switch(val_obj_display)
968 {
969 case eDisplayValue:
970 return_value = GetValueAsCString();
971 break;
972 case eDisplaySummary:
973 return_value = GetSummaryAsCString();
974 break;
975 case eDisplayLanguageSpecific:
976 return_value = GetObjectDescription();
977 break;
Enrico Granataf2bbf712011-07-15 02:26:42 +0000978 case eDisplayLocation:
979 return_value = GetLocationAsCString();
980 break;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000981 case eDisplayChildrenCount:
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000982 {
Enrico Granatacd1c0232011-08-04 23:37:18 +0000983 alloc_mem.resize(512);
984 return_value = &alloc_mem[0];
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000985 int count = GetNumChildren();
Enrico Granatacd1c0232011-08-04 23:37:18 +0000986 snprintf((char*)return_value, 512, "%d", count);
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000987 break;
988 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +0000989 case eDisplayType:
990 return_value = GetTypeName().AsCString();
991 break;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000992 default:
993 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000994 }
995
Enrico Granataf4efecd2011-07-12 22:56:10 +0000996 // this code snippet might lead to endless recursion, thus we use a RefCounter here to
997 // check that we are not looping endlessly
998 if (!return_value && (m_dump_printable_counter < 3))
Enrico Granata9fc19442011-07-06 02:13:41 +0000999 {
1000 // try to pick the other choice
1001 if (val_obj_display == eDisplayValue)
1002 return_value = GetSummaryAsCString();
1003 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +00001004 {
1005 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1006 {
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001007 // this thing has no value, and it seems to have no summary
1008 // some combination of unitialized data and other factors can also
1009 // raise this condition, so let's print a nice generic error message
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001010 {
1011 alloc_mem.resize(684);
1012 return_value = &alloc_mem[0];
1013 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1014 }
Enrico Granatae992a082011-07-22 17:03:19 +00001015 }
1016 else
1017 return_value = GetValueAsCString();
1018 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001019 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001020
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001021 if (return_value)
1022 s.PutCString(return_value);
1023 else
1024 s.PutCString("<no printable representation>");
1025
1026 // we should only return false here if we could not do *anything*
1027 // even if we have an error message as output, that's a success
1028 // from our callers' perspective, so return true
1029 return true;
1030
Enrico Granata0a3958e2011-07-02 00:25:22 +00001031}
1032
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001033// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1034// this call up to date by returning true for your new special cases. We will eventually move
1035// to checking this call result before trying to display special cases
1036bool
1037ValueObject::HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1038 lldb::Format custom_format)
1039{
1040 clang_type_t elem_or_pointee_type;
1041 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1042
1043 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1044 && val_obj_display == ValueObject::eDisplayValue)
1045 {
1046 if (IsCStringContainer(true) &&
1047 (custom_format == lldb::eFormatCString ||
1048 custom_format == lldb::eFormatCharArray ||
1049 custom_format == lldb::eFormatChar ||
1050 custom_format == lldb::eFormatVectorOfChar))
1051 return true;
1052
1053 if (flags.Test(ClangASTContext::eTypeIsArray))
1054 {
1055 if ((custom_format == lldb::eFormatBytes) ||
1056 (custom_format == lldb::eFormatBytesWithASCII))
1057 return true;
1058
1059 if ((custom_format == lldb::eFormatVectorOfChar) ||
1060 (custom_format == lldb::eFormatVectorOfFloat32) ||
1061 (custom_format == lldb::eFormatVectorOfFloat64) ||
1062 (custom_format == lldb::eFormatVectorOfSInt16) ||
1063 (custom_format == lldb::eFormatVectorOfSInt32) ||
1064 (custom_format == lldb::eFormatVectorOfSInt64) ||
1065 (custom_format == lldb::eFormatVectorOfSInt8) ||
1066 (custom_format == lldb::eFormatVectorOfUInt128) ||
1067 (custom_format == lldb::eFormatVectorOfUInt16) ||
1068 (custom_format == lldb::eFormatVectorOfUInt32) ||
1069 (custom_format == lldb::eFormatVectorOfUInt64) ||
1070 (custom_format == lldb::eFormatVectorOfUInt8))
1071 return true;
1072 }
1073 }
1074 return false;
1075}
1076
Enrico Granata9fc19442011-07-06 02:13:41 +00001077bool
1078ValueObject::DumpPrintableRepresentation(Stream& s,
1079 ValueObjectRepresentationStyle val_obj_display,
Enrico Granata85933ed2011-08-18 16:38:26 +00001080 lldb::Format custom_format,
1081 bool only_special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001082{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001083
1084 clang_type_t elem_or_pointee_type;
1085 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001086
Enrico Granataf4efecd2011-07-12 22:56:10 +00001087 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1088 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001089 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001090 // when being asked to get a printable display an array or pointer type directly,
1091 // try to "do the right thing"
1092
1093 if (IsCStringContainer(true) &&
1094 (custom_format == lldb::eFormatCString ||
1095 custom_format == lldb::eFormatCharArray ||
1096 custom_format == lldb::eFormatChar ||
1097 custom_format == lldb::eFormatVectorOfChar)) // print char[] & char* directly
1098 {
1099 Error error;
1100 ReadPointedString(s,
1101 error,
1102 0,
1103 (custom_format == lldb::eFormatVectorOfChar) ||
1104 (custom_format == lldb::eFormatCharArray));
1105 return !error.Fail();
1106 }
1107
1108 if (custom_format == lldb::eFormatEnum)
1109 return false;
1110
1111 // this only works for arrays, because I have no way to know when
1112 // the pointed memory ends, and no special \0 end of data marker
1113 if (flags.Test(ClangASTContext::eTypeIsArray))
1114 {
1115 if ((custom_format == lldb::eFormatBytes) ||
1116 (custom_format == lldb::eFormatBytesWithASCII))
1117 {
1118 uint32_t count = GetNumChildren();
1119
1120 s << '[';
1121 for (uint32_t low = 0; low < count; low++)
1122 {
1123
1124 if (low)
1125 s << ',';
1126
1127 ValueObjectSP child = GetChildAtIndex(low,true);
1128 if (!child.get())
1129 {
Enrico Granatae992a082011-07-22 17:03:19 +00001130 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001131 continue;
1132 }
1133 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1134 }
1135
1136 s << ']';
1137
1138 return true;
1139 }
1140
1141 if ((custom_format == lldb::eFormatVectorOfChar) ||
1142 (custom_format == lldb::eFormatVectorOfFloat32) ||
1143 (custom_format == lldb::eFormatVectorOfFloat64) ||
1144 (custom_format == lldb::eFormatVectorOfSInt16) ||
1145 (custom_format == lldb::eFormatVectorOfSInt32) ||
1146 (custom_format == lldb::eFormatVectorOfSInt64) ||
1147 (custom_format == lldb::eFormatVectorOfSInt8) ||
1148 (custom_format == lldb::eFormatVectorOfUInt128) ||
1149 (custom_format == lldb::eFormatVectorOfUInt16) ||
1150 (custom_format == lldb::eFormatVectorOfUInt32) ||
1151 (custom_format == lldb::eFormatVectorOfUInt64) ||
1152 (custom_format == lldb::eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1153 {
1154 uint32_t count = GetNumChildren();
1155
1156 lldb::Format format = FormatManager::GetSingleItemFormat(custom_format);
1157
1158 s << '[';
1159 for (uint32_t low = 0; low < count; low++)
1160 {
1161
1162 if (low)
1163 s << ',';
1164
1165 ValueObjectSP child = GetChildAtIndex(low,true);
1166 if (!child.get())
1167 {
Enrico Granatae992a082011-07-22 17:03:19 +00001168 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001169 continue;
1170 }
1171 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1172 }
1173
1174 s << ']';
1175
1176 return true;
1177 }
1178 }
1179
1180 if ((custom_format == lldb::eFormatBoolean) ||
1181 (custom_format == lldb::eFormatBinary) ||
1182 (custom_format == lldb::eFormatChar) ||
1183 (custom_format == lldb::eFormatCharPrintable) ||
1184 (custom_format == lldb::eFormatComplexFloat) ||
1185 (custom_format == lldb::eFormatDecimal) ||
1186 (custom_format == lldb::eFormatHex) ||
1187 (custom_format == lldb::eFormatFloat) ||
1188 (custom_format == lldb::eFormatOctal) ||
1189 (custom_format == lldb::eFormatOSType) ||
1190 (custom_format == lldb::eFormatUnicode16) ||
1191 (custom_format == lldb::eFormatUnicode32) ||
1192 (custom_format == lldb::eFormatUnsigned) ||
1193 (custom_format == lldb::eFormatPointer) ||
1194 (custom_format == lldb::eFormatComplexInteger) ||
1195 (custom_format == lldb::eFormatComplex) ||
1196 (custom_format == lldb::eFormatDefault)) // use the [] operator
1197 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001198 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001199
1200 if (only_special)
1201 return false;
1202
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001203 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001204 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001205 SetFormat(eFormatDefault);
1206 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001207}
1208
Greg Clayton737b9322010-09-13 03:32:57 +00001209addr_t
Greg Claytone0d378b2011-03-24 21:19:54 +00001210ValueObject::GetAddressOf (AddressType &address_type, bool scalar_is_load_address)
Greg Clayton73b472d2010-10-27 03:32:59 +00001211{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001212 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001213 return LLDB_INVALID_ADDRESS;
1214
Greg Clayton73b472d2010-10-27 03:32:59 +00001215 switch (m_value.GetValueType())
1216 {
1217 case Value::eValueTypeScalar:
1218 if (scalar_is_load_address)
1219 {
1220 address_type = eAddressTypeLoad;
1221 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1222 }
1223 break;
1224
1225 case Value::eValueTypeLoadAddress:
1226 case Value::eValueTypeFileAddress:
1227 case Value::eValueTypeHostAddress:
1228 {
1229 address_type = m_value.GetValueAddressType ();
1230 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1231 }
1232 break;
1233 }
1234 address_type = eAddressTypeInvalid;
1235 return LLDB_INVALID_ADDRESS;
1236}
1237
1238addr_t
Greg Claytone0d378b2011-03-24 21:19:54 +00001239ValueObject::GetPointerValue (AddressType &address_type, bool scalar_is_load_address)
Greg Clayton737b9322010-09-13 03:32:57 +00001240{
1241 lldb::addr_t address = LLDB_INVALID_ADDRESS;
1242 address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001243
Enrico Granatac3e320a2011-08-02 17:27:39 +00001244 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001245 return address;
1246
Greg Clayton73b472d2010-10-27 03:32:59 +00001247 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001248 {
1249 case Value::eValueTypeScalar:
1250 if (scalar_is_load_address)
1251 {
1252 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1253 address_type = eAddressTypeLoad;
1254 }
1255 break;
1256
1257 case Value::eValueTypeLoadAddress:
1258 case Value::eValueTypeFileAddress:
1259 case Value::eValueTypeHostAddress:
1260 {
1261 uint32_t data_offset = 0;
1262 address = m_data.GetPointer(&data_offset);
1263 address_type = m_value.GetValueAddressType();
1264 if (address_type == eAddressTypeInvalid)
1265 address_type = eAddressTypeLoad;
1266 }
1267 break;
1268 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001269
1270 if (m_pointers_point_to_load_addrs)
1271 address_type = eAddressTypeLoad;
1272
Greg Clayton737b9322010-09-13 03:32:57 +00001273 return address;
1274}
1275
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001276bool
Jim Ingham6035b672011-03-31 00:19:25 +00001277ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001278{
1279 // Make sure our value is up to date first so that our location and location
1280 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001281 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001282 return false;
1283
1284 uint32_t count = 0;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001285 lldb::Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001286
Greg Claytonb1320972010-07-14 00:18:15 +00001287 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001288
Jim Ingham16e0c682011-08-12 23:34:31 +00001289 Value::ValueType value_type = m_value.GetValueType();
1290
1291 if (value_type == Value::eValueTypeScalar)
1292 {
1293 // If the value is already a scalar, then let the scalar change itself:
1294 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1295 }
1296 else if (byte_size <= Scalar::GetMaxByteSize())
1297 {
1298 // If the value fits in a scalar, then make a new scalar and again let the
1299 // scalar code do the conversion, then figure out where to put the new value.
1300 Scalar new_scalar;
1301 Error error;
1302 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1303 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001304 {
Jim Ingham4b536182011-08-09 02:12:22 +00001305 switch (value_type)
1306 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001307 case Value::eValueTypeLoadAddress:
1308 {
1309 // If it is a load address, then the scalar value is the storage location
1310 // of the data, and we have to shove this value down to that load location.
1311 ProcessSP process_sp = GetUpdatePoint().GetProcessSP();
1312 if (process_sp)
1313 {
1314 lldb::addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
1315 size_t bytes_written = process_sp->WriteScalarToMemory (target_addr,
1316 new_scalar,
1317 byte_size,
1318 error);
1319 if (!error.Success() || bytes_written != byte_size)
1320 return false;
1321 }
1322 }
Jim Ingham4b536182011-08-09 02:12:22 +00001323 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001324 case Value::eValueTypeHostAddress:
1325 {
1326 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1327 DataExtractor new_data;
1328 new_data.SetByteOrder (m_data.GetByteOrder());
1329
1330 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1331 m_data.SetData(buffer_sp, 0);
1332 bool success = new_scalar.GetData(new_data);
1333 if (success)
1334 {
1335 new_data.CopyByteOrderedData(0,
1336 byte_size,
1337 const_cast<uint8_t *>(m_data.GetDataStart()),
1338 byte_size,
1339 m_data.GetByteOrder());
1340 }
1341 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1342
1343 }
Jim Ingham4b536182011-08-09 02:12:22 +00001344 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001345 case Value::eValueTypeFileAddress:
1346 case Value::eValueTypeScalar:
1347 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001348 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001349 }
1350 else
1351 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001352 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001353 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001354 }
1355 else
1356 {
1357 // We don't support setting things bigger than a scalar at present.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001358 return false;
1359 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001360
1361 // If we have reached this point, then we have successfully changed the value.
1362 SetNeedsUpdate();
1363 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001364}
1365
Jim Ingham5a369122010-09-28 01:25:32 +00001366lldb::LanguageType
1367ValueObject::GetObjectRuntimeLanguage ()
1368{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001369 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1370 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001371}
1372
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001373void
Jim Ingham58b59f92011-04-22 23:53:53 +00001374ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001375{
Jim Ingham58b59f92011-04-22 23:53:53 +00001376 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001377}
1378
1379ValueObjectSP
1380ValueObject::GetSyntheticChild (const ConstString &key) const
1381{
1382 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001383 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001384 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001385 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001386 return synthetic_child_sp;
1387}
1388
1389bool
1390ValueObject::IsPointerType ()
1391{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001392 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001393}
1394
Jim Inghamb7603bb2011-03-18 00:05:18 +00001395bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001396ValueObject::IsArrayType ()
1397{
1398 return ClangASTContext::IsArrayType (GetClangType());
1399}
1400
1401bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001402ValueObject::IsScalarType ()
1403{
1404 return ClangASTContext::IsScalarType (GetClangType());
1405}
1406
1407bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001408ValueObject::IsIntegerType (bool &is_signed)
1409{
1410 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1411}
Greg Clayton73b472d2010-10-27 03:32:59 +00001412
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001413bool
1414ValueObject::IsPointerOrReferenceType ()
1415{
Greg Clayton007d5be2011-05-30 00:49:24 +00001416 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1417}
1418
1419bool
1420ValueObject::IsPossibleCPlusPlusDynamicType ()
1421{
1422 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001423}
1424
Greg Claytondea8cb42011-06-29 22:09:02 +00001425bool
1426ValueObject::IsPossibleDynamicType ()
1427{
1428 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1429}
1430
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001431lldb::ValueObjectSP
1432ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1433{
1434 if (IsArrayType())
1435 return GetSyntheticArrayMemberFromArray(index, can_create);
1436
1437 if (IsPointerType())
1438 return GetSyntheticArrayMemberFromPointer(index, can_create);
1439
1440 return ValueObjectSP();
1441
1442}
1443
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001444ValueObjectSP
1445ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1446{
1447 ValueObjectSP synthetic_child_sp;
1448 if (IsPointerType ())
1449 {
1450 char index_str[64];
1451 snprintf(index_str, sizeof(index_str), "[%i]", index);
1452 ConstString index_const_str(index_str);
1453 // Check if we have already created a synthetic array member in this
1454 // valid object. If we have we will re-use it.
1455 synthetic_child_sp = GetSyntheticChild (index_const_str);
1456 if (!synthetic_child_sp)
1457 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001458 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001459 // We haven't made a synthetic array member for INDEX yet, so
1460 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001461 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001462
1463 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001464 if (synthetic_child)
1465 {
1466 AddSyntheticChild(index_const_str, synthetic_child);
1467 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001468 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001469 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001470 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001471 }
1472 }
1473 return synthetic_child_sp;
1474}
Jim Ingham22777012010-09-23 02:01:19 +00001475
Greg Claytondaf515f2011-07-09 20:12:33 +00001476// This allows you to create an array member using and index
1477// that doesn't not fall in the normal bounds of the array.
1478// Many times structure can be defined as:
1479// struct Collection
1480// {
1481// uint32_t item_count;
1482// Item item_array[0];
1483// };
1484// The size of the "item_array" is 1, but many times in practice
1485// there are more items in "item_array".
1486
1487ValueObjectSP
1488ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1489{
1490 ValueObjectSP synthetic_child_sp;
1491 if (IsArrayType ())
1492 {
1493 char index_str[64];
1494 snprintf(index_str, sizeof(index_str), "[%i]", index);
1495 ConstString index_const_str(index_str);
1496 // Check if we have already created a synthetic array member in this
1497 // valid object. If we have we will re-use it.
1498 synthetic_child_sp = GetSyntheticChild (index_const_str);
1499 if (!synthetic_child_sp)
1500 {
1501 ValueObject *synthetic_child;
1502 // We haven't made a synthetic array member for INDEX yet, so
1503 // lets make one and cache it for any future reference.
1504 synthetic_child = CreateChildAtIndex(0, true, index);
1505
1506 // Cache the value if we got one back...
1507 if (synthetic_child)
1508 {
1509 AddSyntheticChild(index_const_str, synthetic_child);
1510 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001511 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001512 synthetic_child_sp->m_is_array_item_for_pointer = true;
1513 }
1514 }
1515 }
1516 return synthetic_child_sp;
1517}
1518
Enrico Granata9fc19442011-07-06 02:13:41 +00001519ValueObjectSP
1520ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1521{
1522 ValueObjectSP synthetic_child_sp;
1523 if (IsScalarType ())
1524 {
1525 char index_str[64];
1526 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1527 ConstString index_const_str(index_str);
1528 // Check if we have already created a synthetic array member in this
1529 // valid object. If we have we will re-use it.
1530 synthetic_child_sp = GetSyntheticChild (index_const_str);
1531 if (!synthetic_child_sp)
1532 {
1533 ValueObjectChild *synthetic_child;
1534 // We haven't made a synthetic array member for INDEX yet, so
1535 // lets make one and cache it for any future reference.
1536 synthetic_child = new ValueObjectChild(*this,
1537 GetClangAST(),
1538 GetClangType(),
1539 index_const_str,
1540 GetByteSize(),
1541 0,
1542 to-from+1,
1543 from,
1544 false,
1545 false);
1546
1547 // Cache the value if we got one back...
1548 if (synthetic_child)
1549 {
1550 AddSyntheticChild(index_const_str, synthetic_child);
1551 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001552 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001553 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1554 }
1555 }
1556 }
1557 return synthetic_child_sp;
1558}
1559
Enrico Granata6f3533f2011-07-29 19:53:35 +00001560lldb::ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001561ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1562{
1563 ValueObjectSP synthetic_child_sp;
1564 if (IsArrayType () || IsPointerType ())
1565 {
1566 char index_str[64];
1567 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1568 ConstString index_const_str(index_str);
1569 // Check if we have already created a synthetic array member in this
1570 // valid object. If we have we will re-use it.
1571 synthetic_child_sp = GetSyntheticChild (index_const_str);
1572 if (!synthetic_child_sp)
1573 {
1574 ValueObjectSynthetic *synthetic_child;
1575
1576 // We haven't made a synthetic array member for INDEX yet, so
1577 // lets make one and cache it for any future reference.
1578 SyntheticArrayView *view = new SyntheticArrayView();
1579 view->AddRange(from,to);
1580 SyntheticChildrenSP view_sp(view);
1581 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1582
1583 // Cache the value if we got one back...
1584 if (synthetic_child)
1585 {
1586 AddSyntheticChild(index_const_str, synthetic_child);
1587 synthetic_child_sp = synthetic_child->GetSP();
1588 synthetic_child_sp->SetName(ConstString(index_str));
1589 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1590 }
1591 }
1592 }
1593 return synthetic_child_sp;
1594}
1595
1596lldb::ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001597ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1598{
1599
1600 ValueObjectSP synthetic_child_sp;
1601
1602 char name_str[64];
1603 snprintf(name_str, sizeof(name_str), "@%i", offset);
1604 ConstString name_const_str(name_str);
1605
1606 // Check if we have already created a synthetic array member in this
1607 // valid object. If we have we will re-use it.
1608 synthetic_child_sp = GetSyntheticChild (name_const_str);
1609
1610 if (synthetic_child_sp.get())
1611 return synthetic_child_sp;
1612
1613 if (!can_create)
1614 return lldb::ValueObjectSP();
1615
1616 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1617 type.GetASTContext(),
1618 type.GetOpaqueQualType(),
1619 name_const_str,
1620 type.GetTypeByteSize(),
1621 offset,
1622 0,
1623 0,
1624 false,
1625 false);
1626 if (synthetic_child)
1627 {
1628 AddSyntheticChild(name_const_str, synthetic_child);
1629 synthetic_child_sp = synthetic_child->GetSP();
1630 synthetic_child_sp->SetName(name_const_str);
1631 synthetic_child_sp->m_is_child_at_offset = true;
1632 }
1633 return synthetic_child_sp;
1634}
1635
Enrico Granatad55546b2011-07-22 00:16:08 +00001636// your expression path needs to have a leading . or ->
1637// (unless it somehow "looks like" an array, in which case it has
1638// a leading [ symbol). while the [ is meaningful and should be shown
1639// to the user, . and -> are just parser design, but by no means
1640// added information for the user.. strip them off
1641static const char*
1642SkipLeadingExpressionPathSeparators(const char* expression)
1643{
1644 if (!expression || !expression[0])
1645 return expression;
1646 if (expression[0] == '.')
1647 return expression+1;
1648 if (expression[0] == '-' && expression[1] == '>')
1649 return expression+2;
1650 return expression;
1651}
1652
1653lldb::ValueObjectSP
1654ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1655{
1656 ValueObjectSP synthetic_child_sp;
1657 ConstString name_const_string(expression);
1658 // Check if we have already created a synthetic array member in this
1659 // valid object. If we have we will re-use it.
1660 synthetic_child_sp = GetSyntheticChild (name_const_string);
1661 if (!synthetic_child_sp)
1662 {
1663 // We haven't made a synthetic array member for expression yet, so
1664 // lets make one and cache it for any future reference.
1665 synthetic_child_sp = GetValueForExpressionPath(expression);
1666
1667 // Cache the value if we got one back...
1668 if (synthetic_child_sp.get())
1669 {
1670 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001671 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001672 synthetic_child_sp->m_is_expression_path_child = true;
1673 }
1674 }
1675 return synthetic_child_sp;
1676}
1677
1678void
1679ValueObject::CalculateSyntheticValue (lldb::SyntheticValueType use_synthetic)
1680{
1681 if (use_synthetic == lldb::eNoSyntheticFilter)
1682 return;
1683
Enrico Granatac3e320a2011-08-02 17:27:39 +00001684 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001685
1686 if (m_last_synthetic_filter.get() == NULL)
1687 return;
1688
Enrico Granataa37a0652011-07-24 00:14:56 +00001689 if (m_synthetic_value == NULL)
1690 m_synthetic_value = new ValueObjectSynthetic(*this, m_last_synthetic_filter);
Enrico Granatad55546b2011-07-22 00:16:08 +00001691
1692}
1693
Jim Ingham78a685a2011-04-16 00:01:13 +00001694void
Jim Ingham2837b762011-05-04 03:43:18 +00001695ValueObject::CalculateDynamicValue (lldb::DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00001696{
Jim Ingham2837b762011-05-04 03:43:18 +00001697 if (use_dynamic == lldb::eNoDynamicValues)
1698 return;
1699
Jim Ingham58b59f92011-04-22 23:53:53 +00001700 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00001701 {
Enrico Granata6f3533f2011-07-29 19:53:35 +00001702 Process *process = m_update_point.GetProcessSP().get();
Jim Ingham78a685a2011-04-16 00:01:13 +00001703 bool worth_having_dynamic_value = false;
Jim Ingham22777012010-09-23 02:01:19 +00001704
Jim Ingham78a685a2011-04-16 00:01:13 +00001705
1706 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
1707 // hard code this everywhere.
1708 lldb::LanguageType known_type = GetObjectRuntimeLanguage();
1709 if (known_type != lldb::eLanguageTypeUnknown && known_type != lldb::eLanguageTypeC)
1710 {
1711 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
1712 if (runtime)
1713 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
1714 }
1715 else
1716 {
1717 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeC_plus_plus);
1718 if (cpp_runtime)
1719 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
1720
1721 if (!worth_having_dynamic_value)
1722 {
1723 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeObjC);
1724 if (objc_runtime)
Jim Ingham2837b762011-05-04 03:43:18 +00001725 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00001726 }
1727 }
1728
1729 if (worth_having_dynamic_value)
Jim Ingham2837b762011-05-04 03:43:18 +00001730 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham58b59f92011-04-22 23:53:53 +00001731
1732// if (worth_having_dynamic_value)
1733// printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager);
1734
Jim Ingham78a685a2011-04-16 00:01:13 +00001735 }
1736}
1737
Jim Ingham58b59f92011-04-22 23:53:53 +00001738ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00001739ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00001740{
Jim Ingham2837b762011-05-04 03:43:18 +00001741 if (use_dynamic == lldb::eNoDynamicValues)
1742 return ValueObjectSP();
1743
1744 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00001745 {
Jim Ingham2837b762011-05-04 03:43:18 +00001746 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001747 }
Jim Ingham58b59f92011-04-22 23:53:53 +00001748 if (m_dynamic_value)
1749 return m_dynamic_value->GetSP();
1750 else
1751 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00001752}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001753
Enrico Granatad55546b2011-07-22 00:16:08 +00001754// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
1755// or we do not really want a dynamic VO. this method instead returns this object
1756// itself when making it synthetic has no meaning. this makes it much simpler
1757// to replace the SyntheticValue for the ValueObject
1758ValueObjectSP
1759ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
1760{
1761 if (use_synthetic == lldb::eNoSyntheticFilter)
1762 return GetSP();
1763
Enrico Granatac3e320a2011-08-02 17:27:39 +00001764 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001765
1766 if (m_last_synthetic_filter.get() == NULL)
1767 return GetSP();
1768
1769 CalculateSyntheticValue(use_synthetic);
1770
1771 if (m_synthetic_value)
1772 return m_synthetic_value->GetSP();
1773 else
1774 return GetSP();
1775}
1776
Greg Claytone221f822011-01-21 01:59:00 +00001777bool
Enrico Granata27b625e2011-08-09 01:04:56 +00001778ValueObject::HasSyntheticValue()
1779{
1780 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
1781
1782 if (m_last_synthetic_filter.get() == NULL)
1783 return false;
1784
1785 CalculateSyntheticValue(lldb::eUseSyntheticFilter);
1786
1787 if (m_synthetic_value)
1788 return true;
1789 else
1790 return false;
1791}
1792
1793bool
Greg Claytone221f822011-01-21 01:59:00 +00001794ValueObject::GetBaseClassPath (Stream &s)
1795{
1796 if (IsBaseClass())
1797 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001798 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00001799 clang_type_t clang_type = GetClangType();
1800 std::string cxx_class_name;
1801 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
1802 if (this_had_base_class)
1803 {
1804 if (parent_had_base_class)
1805 s.PutCString("::");
1806 s.PutCString(cxx_class_name.c_str());
1807 }
1808 return parent_had_base_class || this_had_base_class;
1809 }
1810 return false;
1811}
1812
1813
1814ValueObject *
1815ValueObject::GetNonBaseClassParent()
1816{
Jim Ingham78a685a2011-04-16 00:01:13 +00001817 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00001818 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001819 if (GetParent()->IsBaseClass())
1820 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00001821 else
Jim Ingham78a685a2011-04-16 00:01:13 +00001822 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00001823 }
1824 return NULL;
1825}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001826
1827void
Enrico Granata4becb372011-06-29 22:27:15 +00001828ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001829{
Greg Claytone221f822011-01-21 01:59:00 +00001830 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00001831
Enrico Granata85933ed2011-08-18 16:38:26 +00001832 if (is_deref_of_parent && epformat == eDereferencePointers)
1833 {
Enrico Granata4becb372011-06-29 22:27:15 +00001834 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
1835 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
1836 // the eHonorPointers mode is meant to produce strings in this latter format
1837 s.PutCString("*(");
1838 }
Greg Claytone221f822011-01-21 01:59:00 +00001839
Enrico Granata4becb372011-06-29 22:27:15 +00001840 ValueObject* parent = GetParent();
1841
1842 if (parent)
1843 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00001844
1845 // if we are a deref_of_parent just because we are synthetic array
1846 // members made up to allow ptr[%d] syntax to work in variable
1847 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00001848 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001849 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00001850
Greg Claytone221f822011-01-21 01:59:00 +00001851 if (!IsBaseClass())
1852 {
1853 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001854 {
Greg Claytone221f822011-01-21 01:59:00 +00001855 ValueObject *non_base_class_parent = GetNonBaseClassParent();
1856 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001857 {
Greg Claytone221f822011-01-21 01:59:00 +00001858 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
1859 if (non_base_class_parent_clang_type)
1860 {
1861 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
1862
Enrico Granata9dd75c82011-07-15 23:30:15 +00001863 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00001864 {
1865 s.PutCString("->");
1866 }
Enrico Granata4becb372011-06-29 22:27:15 +00001867 else
1868 {
1869 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
1870 {
1871 s.PutCString("->");
1872 }
1873 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
1874 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
1875 {
1876 s.PutChar('.');
1877 }
Greg Claytone221f822011-01-21 01:59:00 +00001878 }
1879 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001880 }
Greg Claytone221f822011-01-21 01:59:00 +00001881
1882 const char *name = GetName().GetCString();
1883 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001884 {
Greg Claytone221f822011-01-21 01:59:00 +00001885 if (qualify_cxx_base_classes)
1886 {
1887 if (GetBaseClassPath (s))
1888 s.PutCString("::");
1889 }
1890 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001891 }
1892 }
1893 }
1894
Enrico Granata85933ed2011-08-18 16:38:26 +00001895 if (is_deref_of_parent && epformat == eDereferencePointers)
1896 {
Greg Claytone221f822011-01-21 01:59:00 +00001897 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00001898 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001899}
1900
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001901lldb::ValueObjectSP
1902ValueObject::GetValueForExpressionPath(const char* expression,
1903 const char** first_unparsed,
1904 ExpressionPathScanEndReason* reason_to_stop,
1905 ExpressionPathEndResultType* final_value_type,
1906 const GetValueForExpressionPathOptions& options,
1907 ExpressionPathAftermath* final_task_on_target)
1908{
1909
1910 const char* dummy_first_unparsed;
1911 ExpressionPathScanEndReason dummy_reason_to_stop;
1912 ExpressionPathEndResultType dummy_final_value_type;
1913 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
1914
1915 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
1916 first_unparsed ? first_unparsed : &dummy_first_unparsed,
1917 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
1918 final_value_type ? final_value_type : &dummy_final_value_type,
1919 options,
1920 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
1921
1922 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
1923 {
1924 return ret_val;
1925 }
1926 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
1927 {
1928 if (*final_task_on_target == ValueObject::eDereference)
1929 {
1930 Error error;
1931 ValueObjectSP final_value = ret_val->Dereference(error);
1932 if (error.Fail() || !final_value.get())
1933 {
1934 *reason_to_stop = ValueObject::eDereferencingFailed;
1935 *final_value_type = ValueObject::eInvalid;
1936 return ValueObjectSP();
1937 }
1938 else
1939 {
1940 *final_task_on_target = ValueObject::eNothing;
1941 return final_value;
1942 }
1943 }
1944 if (*final_task_on_target == ValueObject::eTakeAddress)
1945 {
1946 Error error;
1947 ValueObjectSP final_value = ret_val->AddressOf(error);
1948 if (error.Fail() || !final_value.get())
1949 {
1950 *reason_to_stop = ValueObject::eTakingAddressFailed;
1951 *final_value_type = ValueObject::eInvalid;
1952 return ValueObjectSP();
1953 }
1954 else
1955 {
1956 *final_task_on_target = ValueObject::eNothing;
1957 return final_value;
1958 }
1959 }
1960 }
1961 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
1962}
1963
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001964int
1965ValueObject::GetValuesForExpressionPath(const char* expression,
1966 lldb::ValueObjectListSP& list,
1967 const char** first_unparsed,
1968 ExpressionPathScanEndReason* reason_to_stop,
1969 ExpressionPathEndResultType* final_value_type,
1970 const GetValueForExpressionPathOptions& options,
1971 ExpressionPathAftermath* final_task_on_target)
1972{
1973 const char* dummy_first_unparsed;
1974 ExpressionPathScanEndReason dummy_reason_to_stop;
1975 ExpressionPathEndResultType dummy_final_value_type;
1976 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
1977
1978 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
1979 first_unparsed ? first_unparsed : &dummy_first_unparsed,
1980 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
1981 final_value_type ? final_value_type : &dummy_final_value_type,
1982 options,
1983 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
1984
1985 if (!ret_val.get()) // if there are errors, I add nothing to the list
1986 return 0;
1987
1988 if (*reason_to_stop != eArrayRangeOperatorMet)
1989 {
1990 // I need not expand a range, just post-process the final value and return
1991 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
1992 {
1993 list->Append(ret_val);
1994 return 1;
1995 }
1996 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
1997 {
1998 if (*final_task_on_target == ValueObject::eDereference)
1999 {
2000 Error error;
2001 ValueObjectSP final_value = ret_val->Dereference(error);
2002 if (error.Fail() || !final_value.get())
2003 {
2004 *reason_to_stop = ValueObject::eDereferencingFailed;
2005 *final_value_type = ValueObject::eInvalid;
2006 return 0;
2007 }
2008 else
2009 {
2010 *final_task_on_target = ValueObject::eNothing;
2011 list->Append(final_value);
2012 return 1;
2013 }
2014 }
2015 if (*final_task_on_target == ValueObject::eTakeAddress)
2016 {
2017 Error error;
2018 ValueObjectSP final_value = ret_val->AddressOf(error);
2019 if (error.Fail() || !final_value.get())
2020 {
2021 *reason_to_stop = ValueObject::eTakingAddressFailed;
2022 *final_value_type = ValueObject::eInvalid;
2023 return 0;
2024 }
2025 else
2026 {
2027 *final_task_on_target = ValueObject::eNothing;
2028 list->Append(final_value);
2029 return 1;
2030 }
2031 }
2032 }
2033 }
2034 else
2035 {
2036 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2037 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2038 ret_val,
2039 list,
2040 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2041 final_value_type ? final_value_type : &dummy_final_value_type,
2042 options,
2043 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2044 }
2045 // in any non-covered case, just do the obviously right thing
2046 list->Append(ret_val);
2047 return 1;
2048}
2049
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002050lldb::ValueObjectSP
2051ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2052 const char** first_unparsed,
2053 ExpressionPathScanEndReason* reason_to_stop,
2054 ExpressionPathEndResultType* final_result,
2055 const GetValueForExpressionPathOptions& options,
2056 ExpressionPathAftermath* what_next)
2057{
2058 ValueObjectSP root = GetSP();
2059
2060 if (!root.get())
2061 return ValueObjectSP();
2062
2063 *first_unparsed = expression_cstr;
2064
2065 while (true)
2066 {
2067
2068 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2069
2070 lldb::clang_type_t root_clang_type = root->GetClangType();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002071 lldb::clang_type_t pointee_clang_type;
2072 Flags root_clang_type_info,pointee_clang_type_info;
2073
2074 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2075 if (pointee_clang_type)
2076 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002077
2078 if (!expression_cstr || *expression_cstr == '\0')
2079 {
2080 *reason_to_stop = ValueObject::eEndOfString;
2081 return root;
2082 }
2083
2084 switch (*expression_cstr)
2085 {
2086 case '-':
2087 {
2088 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002089 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 +00002090 {
2091 *first_unparsed = expression_cstr;
2092 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
2093 *final_result = ValueObject::eInvalid;
2094 return ValueObjectSP();
2095 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002096 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2097 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002098 options.m_no_fragile_ivar)
2099 {
2100 *first_unparsed = expression_cstr;
2101 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
2102 *final_result = ValueObject::eInvalid;
2103 return ValueObjectSP();
2104 }
2105 if (expression_cstr[1] != '>')
2106 {
2107 *first_unparsed = expression_cstr;
2108 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2109 *final_result = ValueObject::eInvalid;
2110 return ValueObjectSP();
2111 }
2112 expression_cstr++; // skip the -
2113 }
2114 case '.': // or fallthrough from ->
2115 {
2116 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002117 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 +00002118 {
2119 *first_unparsed = expression_cstr;
2120 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
2121 *final_result = ValueObject::eInvalid;
2122 return ValueObjectSP();
2123 }
2124 expression_cstr++; // skip .
2125 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2126 ConstString child_name;
2127 if (!next_separator) // if no other separator just expand this last layer
2128 {
2129 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002130 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2131
2132 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002133 {
2134 *first_unparsed = '\0';
2135 *reason_to_stop = ValueObject::eEndOfString;
2136 *final_result = ValueObject::ePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002137 return child_valobj_sp;
2138 }
2139 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2140 {
2141 child_valobj_sp = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
2142 }
2143
2144 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2145 // so we hit the "else" branch, and return an error
2146 if(child_valobj_sp.get()) // if it worked, just return
2147 {
2148 *first_unparsed = '\0';
2149 *reason_to_stop = ValueObject::eEndOfString;
2150 *final_result = ValueObject::ePlain;
2151 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002152 }
2153 else
2154 {
2155 *first_unparsed = expression_cstr;
2156 *reason_to_stop = ValueObject::eNoSuchChild;
2157 *final_result = ValueObject::eInvalid;
2158 return ValueObjectSP();
2159 }
2160 }
2161 else // other layers do expand
2162 {
2163 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002164 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2165 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002166 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002167 root = child_valobj_sp;
2168 *first_unparsed = next_separator;
2169 *final_result = ValueObject::ePlain;
2170 continue;
2171 }
2172 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2173 {
2174 child_valobj_sp = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
2175 }
2176
2177 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2178 // so we hit the "else" branch, and return an error
2179 if(child_valobj_sp.get()) // if it worked, move on
2180 {
2181 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002182 *first_unparsed = next_separator;
2183 *final_result = ValueObject::ePlain;
2184 continue;
2185 }
2186 else
2187 {
2188 *first_unparsed = expression_cstr;
2189 *reason_to_stop = ValueObject::eNoSuchChild;
2190 *final_result = ValueObject::eInvalid;
2191 return ValueObjectSP();
2192 }
2193 }
2194 break;
2195 }
2196 case '[':
2197 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002198 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 +00002199 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002200 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002201 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002202 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2203 {
2204 *first_unparsed = expression_cstr;
2205 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2206 *final_result = ValueObject::eInvalid;
2207 return ValueObjectSP();
2208 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002209 }
2210 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2211 {
2212 *first_unparsed = expression_cstr;
2213 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2214 *final_result = ValueObject::eInvalid;
2215 return ValueObjectSP();
2216 }
2217 }
2218 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2219 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002220 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002221 {
2222 *first_unparsed = expression_cstr;
2223 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2224 *final_result = ValueObject::eInvalid;
2225 return ValueObjectSP();
2226 }
2227 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2228 {
2229 *first_unparsed = expression_cstr+2;
2230 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2231 *final_result = ValueObject::eUnboundedRange;
2232 return root;
2233 }
2234 }
2235 const char *separator_position = ::strchr(expression_cstr+1,'-');
2236 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2237 if (!close_bracket_position) // if there is no ], this is a syntax error
2238 {
2239 *first_unparsed = expression_cstr;
2240 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2241 *final_result = ValueObject::eInvalid;
2242 return ValueObjectSP();
2243 }
2244 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2245 {
2246 char *end = NULL;
2247 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2248 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2249 {
2250 *first_unparsed = expression_cstr;
2251 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2252 *final_result = ValueObject::eInvalid;
2253 return ValueObjectSP();
2254 }
2255 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2256 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002257 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002258 {
2259 *first_unparsed = expression_cstr+2;
2260 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2261 *final_result = ValueObject::eUnboundedRange;
2262 return root;
2263 }
2264 else
2265 {
2266 *first_unparsed = expression_cstr;
2267 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2268 *final_result = ValueObject::eInvalid;
2269 return ValueObjectSP();
2270 }
2271 }
2272 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002273 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002274 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002275 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2276 if (!child_valobj_sp)
2277 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002278 if (!child_valobj_sp)
2279 if (root->HasSyntheticValue() && root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetNumChildren() > index)
2280 child_valobj_sp = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002281 if (child_valobj_sp)
2282 {
2283 root = child_valobj_sp;
2284 *first_unparsed = end+1; // skip ]
2285 *final_result = ValueObject::ePlain;
2286 continue;
2287 }
2288 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002289 {
2290 *first_unparsed = expression_cstr;
2291 *reason_to_stop = ValueObject::eNoSuchChild;
2292 *final_result = ValueObject::eInvalid;
2293 return ValueObjectSP();
2294 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002295 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002296 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002297 {
2298 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 +00002299 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002300 {
2301 Error error;
2302 root = root->Dereference(error);
2303 if (error.Fail() || !root.get())
2304 {
2305 *first_unparsed = expression_cstr;
2306 *reason_to_stop = ValueObject::eDereferencingFailed;
2307 *final_result = ValueObject::eInvalid;
2308 return ValueObjectSP();
2309 }
2310 else
2311 {
2312 *what_next = eNothing;
2313 continue;
2314 }
2315 }
2316 else
2317 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002318 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
2319 root->GetClangType()) == lldb::eLanguageTypeObjC
2320 &&
2321 ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2322 &&
2323 root->HasSyntheticValue()
2324 &&
2325 options.m_no_synthetic_children == false)
2326 {
2327 root = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildAtIndex(index, true);
2328 }
2329 else
2330 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002331 if (!root.get())
2332 {
2333 *first_unparsed = expression_cstr;
2334 *reason_to_stop = ValueObject::eNoSuchChild;
2335 *final_result = ValueObject::eInvalid;
2336 return ValueObjectSP();
2337 }
2338 else
2339 {
2340 *first_unparsed = end+1; // skip ]
2341 *final_result = ValueObject::ePlain;
2342 continue;
2343 }
2344 }
2345 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002346 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002347 {
2348 root = root->GetSyntheticBitFieldChild(index, index, true);
2349 if (!root.get())
2350 {
2351 *first_unparsed = expression_cstr;
2352 *reason_to_stop = ValueObject::eNoSuchChild;
2353 *final_result = ValueObject::eInvalid;
2354 return ValueObjectSP();
2355 }
2356 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2357 {
2358 *first_unparsed = end+1; // skip ]
2359 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2360 *final_result = ValueObject::eBitfield;
2361 return root;
2362 }
2363 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002364 else if (root->HasSyntheticValue() && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002365 {
2366 root = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildAtIndex(index, true);
2367 if (!root.get())
2368 {
2369 *first_unparsed = expression_cstr;
2370 *reason_to_stop = ValueObject::eNoSuchChild;
2371 *final_result = ValueObject::eInvalid;
2372 return ValueObjectSP();
2373 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002374 else
2375 {
2376 *first_unparsed = end+1; // skip ]
2377 *final_result = ValueObject::ePlain;
2378 continue;
2379 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002380 }
2381 else
2382 {
2383 *first_unparsed = expression_cstr;
2384 *reason_to_stop = ValueObject::eNoSuchChild;
2385 *final_result = ValueObject::eInvalid;
2386 return ValueObjectSP();
2387 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002388 }
2389 else // we have a low and a high index
2390 {
2391 char *end = NULL;
2392 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2393 if (!end || end != separator_position) // if something weird is in our way return an error
2394 {
2395 *first_unparsed = expression_cstr;
2396 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2397 *final_result = ValueObject::eInvalid;
2398 return ValueObjectSP();
2399 }
2400 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2401 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2402 {
2403 *first_unparsed = expression_cstr;
2404 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2405 *final_result = ValueObject::eInvalid;
2406 return ValueObjectSP();
2407 }
2408 if (index_lower > index_higher) // swap indices if required
2409 {
2410 unsigned long temp = index_lower;
2411 index_lower = index_higher;
2412 index_higher = temp;
2413 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002414 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002415 {
2416 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2417 if (!root.get())
2418 {
2419 *first_unparsed = expression_cstr;
2420 *reason_to_stop = ValueObject::eNoSuchChild;
2421 *final_result = ValueObject::eInvalid;
2422 return ValueObjectSP();
2423 }
2424 else
2425 {
2426 *first_unparsed = end+1; // skip ]
2427 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2428 *final_result = ValueObject::eBitfield;
2429 return root;
2430 }
2431 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002432 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 +00002433 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002434 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002435 {
2436 Error error;
2437 root = root->Dereference(error);
2438 if (error.Fail() || !root.get())
2439 {
2440 *first_unparsed = expression_cstr;
2441 *reason_to_stop = ValueObject::eDereferencingFailed;
2442 *final_result = ValueObject::eInvalid;
2443 return ValueObjectSP();
2444 }
2445 else
2446 {
2447 *what_next = ValueObject::eNothing;
2448 continue;
2449 }
2450 }
2451 else
2452 {
2453 *first_unparsed = expression_cstr;
2454 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2455 *final_result = ValueObject::eBoundedRange;
2456 return root;
2457 }
2458 }
2459 break;
2460 }
2461 default: // some non-separator is in the way
2462 {
2463 *first_unparsed = expression_cstr;
2464 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2465 *final_result = ValueObject::eInvalid;
2466 return ValueObjectSP();
2467 break;
2468 }
2469 }
2470 }
2471}
2472
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002473int
2474ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2475 const char** first_unparsed,
2476 lldb::ValueObjectSP root,
2477 lldb::ValueObjectListSP& list,
2478 ExpressionPathScanEndReason* reason_to_stop,
2479 ExpressionPathEndResultType* final_result,
2480 const GetValueForExpressionPathOptions& options,
2481 ExpressionPathAftermath* what_next)
2482{
2483 if (!root.get())
2484 return 0;
2485
2486 *first_unparsed = expression_cstr;
2487
2488 while (true)
2489 {
2490
2491 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2492
2493 lldb::clang_type_t root_clang_type = root->GetClangType();
2494 lldb::clang_type_t pointee_clang_type;
2495 Flags root_clang_type_info,pointee_clang_type_info;
2496
2497 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2498 if (pointee_clang_type)
2499 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2500
2501 if (!expression_cstr || *expression_cstr == '\0')
2502 {
2503 *reason_to_stop = ValueObject::eEndOfString;
2504 list->Append(root);
2505 return 1;
2506 }
2507
2508 switch (*expression_cstr)
2509 {
2510 case '[':
2511 {
2512 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2513 {
2514 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2515 {
2516 *first_unparsed = expression_cstr;
2517 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2518 *final_result = ValueObject::eInvalid;
2519 return 0;
2520 }
2521 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2522 {
2523 *first_unparsed = expression_cstr;
2524 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2525 *final_result = ValueObject::eInvalid;
2526 return 0;
2527 }
2528 }
2529 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2530 {
2531 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2532 {
2533 *first_unparsed = expression_cstr;
2534 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2535 *final_result = ValueObject::eInvalid;
2536 return 0;
2537 }
2538 else // expand this into list
2539 {
2540 int max_index = root->GetNumChildren() - 1;
2541 for (int index = 0; index < max_index; index++)
2542 {
2543 ValueObjectSP child =
2544 root->GetChildAtIndex(index, true);
2545 list->Append(child);
2546 }
2547 *first_unparsed = expression_cstr+2;
2548 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2549 *final_result = ValueObject::eValueObjectList;
2550 return max_index; // tell me number of items I added to the VOList
2551 }
2552 }
2553 const char *separator_position = ::strchr(expression_cstr+1,'-');
2554 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2555 if (!close_bracket_position) // if there is no ], this is a syntax error
2556 {
2557 *first_unparsed = expression_cstr;
2558 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2559 *final_result = ValueObject::eInvalid;
2560 return 0;
2561 }
2562 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2563 {
2564 char *end = NULL;
2565 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2566 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2567 {
2568 *first_unparsed = expression_cstr;
2569 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2570 *final_result = ValueObject::eInvalid;
2571 return 0;
2572 }
2573 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2574 {
2575 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2576 {
2577 int max_index = root->GetNumChildren() - 1;
2578 for (int index = 0; index < max_index; index++)
2579 {
2580 ValueObjectSP child =
2581 root->GetChildAtIndex(index, true);
2582 list->Append(child);
2583 }
2584 *first_unparsed = expression_cstr+2;
2585 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2586 *final_result = ValueObject::eValueObjectList;
2587 return max_index; // tell me number of items I added to the VOList
2588 }
2589 else
2590 {
2591 *first_unparsed = expression_cstr;
2592 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2593 *final_result = ValueObject::eInvalid;
2594 return 0;
2595 }
2596 }
2597 // from here on we do have a valid index
2598 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2599 {
2600 root = root->GetChildAtIndex(index, true);
2601 if (!root.get())
2602 {
2603 *first_unparsed = expression_cstr;
2604 *reason_to_stop = ValueObject::eNoSuchChild;
2605 *final_result = ValueObject::eInvalid;
2606 return 0;
2607 }
2608 else
2609 {
2610 list->Append(root);
2611 *first_unparsed = end+1; // skip ]
2612 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2613 *final_result = ValueObject::eValueObjectList;
2614 return 1;
2615 }
2616 }
2617 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2618 {
2619 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
2620 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2621 {
2622 Error error;
2623 root = root->Dereference(error);
2624 if (error.Fail() || !root.get())
2625 {
2626 *first_unparsed = expression_cstr;
2627 *reason_to_stop = ValueObject::eDereferencingFailed;
2628 *final_result = ValueObject::eInvalid;
2629 return 0;
2630 }
2631 else
2632 {
2633 *what_next = eNothing;
2634 continue;
2635 }
2636 }
2637 else
2638 {
2639 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2640 if (!root.get())
2641 {
2642 *first_unparsed = expression_cstr;
2643 *reason_to_stop = ValueObject::eNoSuchChild;
2644 *final_result = ValueObject::eInvalid;
2645 return 0;
2646 }
2647 else
2648 {
2649 list->Append(root);
2650 *first_unparsed = end+1; // skip ]
2651 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2652 *final_result = ValueObject::eValueObjectList;
2653 return 1;
2654 }
2655 }
2656 }
2657 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2658 {
2659 root = root->GetSyntheticBitFieldChild(index, index, true);
2660 if (!root.get())
2661 {
2662 *first_unparsed = expression_cstr;
2663 *reason_to_stop = ValueObject::eNoSuchChild;
2664 *final_result = ValueObject::eInvalid;
2665 return 0;
2666 }
2667 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2668 {
2669 list->Append(root);
2670 *first_unparsed = end+1; // skip ]
2671 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2672 *final_result = ValueObject::eValueObjectList;
2673 return 1;
2674 }
2675 }
2676 }
2677 else // we have a low and a high index
2678 {
2679 char *end = NULL;
2680 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2681 if (!end || end != separator_position) // if something weird is in our way return an error
2682 {
2683 *first_unparsed = expression_cstr;
2684 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2685 *final_result = ValueObject::eInvalid;
2686 return 0;
2687 }
2688 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2689 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2690 {
2691 *first_unparsed = expression_cstr;
2692 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2693 *final_result = ValueObject::eInvalid;
2694 return 0;
2695 }
2696 if (index_lower > index_higher) // swap indices if required
2697 {
2698 unsigned long temp = index_lower;
2699 index_lower = index_higher;
2700 index_higher = temp;
2701 }
2702 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
2703 {
2704 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2705 if (!root.get())
2706 {
2707 *first_unparsed = expression_cstr;
2708 *reason_to_stop = ValueObject::eNoSuchChild;
2709 *final_result = ValueObject::eInvalid;
2710 return 0;
2711 }
2712 else
2713 {
2714 list->Append(root);
2715 *first_unparsed = end+1; // skip ]
2716 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2717 *final_result = ValueObject::eValueObjectList;
2718 return 1;
2719 }
2720 }
2721 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
2722 *what_next == ValueObject::eDereference &&
2723 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2724 {
2725 Error error;
2726 root = root->Dereference(error);
2727 if (error.Fail() || !root.get())
2728 {
2729 *first_unparsed = expression_cstr;
2730 *reason_to_stop = ValueObject::eDereferencingFailed;
2731 *final_result = ValueObject::eInvalid;
2732 return 0;
2733 }
2734 else
2735 {
2736 *what_next = ValueObject::eNothing;
2737 continue;
2738 }
2739 }
2740 else
2741 {
Johnny Chen44805302011-07-19 19:48:13 +00002742 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002743 index <= index_higher; index++)
2744 {
2745 ValueObjectSP child =
2746 root->GetChildAtIndex(index, true);
2747 list->Append(child);
2748 }
2749 *first_unparsed = end+1;
2750 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2751 *final_result = ValueObject::eValueObjectList;
2752 return index_higher-index_lower+1; // tell me number of items I added to the VOList
2753 }
2754 }
2755 break;
2756 }
2757 default: // some non-[ separator, or something entirely wrong, is in the way
2758 {
2759 *first_unparsed = expression_cstr;
2760 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2761 *final_result = ValueObject::eInvalid;
2762 return 0;
2763 break;
2764 }
2765 }
2766 }
2767}
2768
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002769void
Greg Clayton1d3afba2010-10-05 00:00:42 +00002770ValueObject::DumpValueObject
2771(
2772 Stream &s,
Greg Clayton1d3afba2010-10-05 00:00:42 +00002773 ValueObject *valobj,
2774 const char *root_valobj_name,
2775 uint32_t ptr_depth,
2776 uint32_t curr_depth,
2777 uint32_t max_depth,
2778 bool show_types,
2779 bool show_location,
2780 bool use_objc,
Jim Ingham2837b762011-05-04 03:43:18 +00002781 lldb::DynamicValueType use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00002782 bool use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002783 bool scope_already_checked,
Enrico Granata0c5ef692011-07-16 01:22:04 +00002784 bool flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00002785 uint32_t omit_summary_depth,
2786 bool ignore_cap
Greg Clayton1d3afba2010-10-05 00:00:42 +00002787)
2788{
Greg Clayton007d5be2011-05-30 00:49:24 +00002789 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002790 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00002791 bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00002792
2793 if (update_success && use_dynamic != lldb::eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00002794 {
Jim Ingham2837b762011-05-04 03:43:18 +00002795 ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00002796 if (dynamic_value)
2797 valobj = dynamic_value;
2798 }
2799
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002800 clang_type_t clang_type = valobj->GetClangType();
2801
Greg Clayton73b472d2010-10-27 03:32:59 +00002802 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002803 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00002804 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
2805 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002806
2807 const bool print_valobj = flat_output == false || has_value;
2808
2809 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002810 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002811 if (show_location)
2812 {
Jim Ingham6035b672011-03-31 00:19:25 +00002813 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002814 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002815
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002816 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00002817
Greg Clayton7c8a9662010-11-02 01:50:16 +00002818 // Always show the type for the top level items.
Greg Claytone221f822011-01-21 01:59:00 +00002819 if (show_types || (curr_depth == 0 && !flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00002820 {
Enrico Granata9910bc82011-08-03 02:18:51 +00002821 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
2822 s.Printf("(%s", typeName);
2823 // only show dynamic types if the user really wants to see types
2824 if (show_types && use_dynamic != lldb::eNoDynamicValues &&
2825 (/*strstr(typeName, "id") == typeName ||*/
2826 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == lldb::eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00002827 {
2828 Process* process = valobj->GetUpdatePoint().GetProcessSP().get();
2829 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00002830 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002831 else
2832 {
2833 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
2834 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00002835 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002836 else
2837 {
2838 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
2839 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00002840 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002841 else
2842 s.Printf(", dynamic type: %s) ",
2843 runtime->GetActualTypeName(isa).GetCString());
2844 }
2845 }
2846 }
2847 else
2848 s.Printf(") ");
2849 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002850
Greg Clayton1d3afba2010-10-05 00:00:42 +00002851
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002852 if (flat_output)
2853 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00002854 // If we are showing types, also qualify the C++ base classes
2855 const bool qualify_cxx_base_classes = show_types;
2856 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002857 s.PutCString(" =");
2858 }
2859 else
2860 {
2861 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
2862 s.Printf ("%s =", name_cstr);
2863 }
2864
Jim Ingham6035b672011-03-31 00:19:25 +00002865 if (!scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002866 {
Greg Clayton007d5be2011-05-30 00:49:24 +00002867 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002868 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002869 }
2870
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002871 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00002872 const char *sum_cstr = NULL;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002873 SummaryFormat* entry = valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002874
Enrico Granata0c5ef692011-07-16 01:22:04 +00002875 if (omit_summary_depth > 0)
2876 entry = NULL;
2877
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002878 if (err_cstr == NULL)
2879 {
Jim Ingham6035b672011-03-31 00:19:25 +00002880 val_cstr = valobj->GetValueAsCString();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002881 err_cstr = valobj->GetError().AsCString();
2882 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002883
2884 if (err_cstr)
2885 {
Greg Clayton007d5be2011-05-30 00:49:24 +00002886 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00002887 }
2888 else
2889 {
Greg Clayton73b472d2010-10-27 03:32:59 +00002890 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002891 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002892 {
Enrico Granata4becb372011-06-29 22:27:15 +00002893
Enrico Granata0c5ef692011-07-16 01:22:04 +00002894 sum_cstr = (omit_summary_depth == 0) ? valobj->GetSummaryAsCString() : NULL;
Greg Clayton1d3afba2010-10-05 00:00:42 +00002895
Enrico Granata4becb372011-06-29 22:27:15 +00002896 // We must calculate this value in realtime because entry might alter this variable's value
2897 // (e.g. by saying ${var%fmt}) and render precached values useless
2898 if (val_cstr && (!entry || entry->DoesPrintValue() || !sum_cstr))
2899 s.Printf(" %s", valobj->GetValueAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002900
Enrico Granata9dd75c82011-07-15 23:30:15 +00002901 if (sum_cstr)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002902 {
2903 // for some reason, using %@ (ObjC description) in a summary string, makes
2904 // us believe we need to reset ourselves, thus invalidating the content of
2905 // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty
2906 // let us recalculate it!
2907 if (sum_cstr[0] == '\0')
2908 s.Printf(" %s", valobj->GetSummaryAsCString());
2909 else
2910 s.Printf(" %s", sum_cstr);
2911 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002912
2913 if (use_objc)
2914 {
Jim Ingham6035b672011-03-31 00:19:25 +00002915 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002916 if (object_desc)
2917 s.Printf(" %s\n", object_desc);
2918 else
Sean Callanan672ad942010-10-23 00:18:49 +00002919 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002920 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00002921 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002922 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002923
2924 if (curr_depth < max_depth)
2925 {
Greg Clayton73b472d2010-10-27 03:32:59 +00002926 // We will show children for all concrete types. We won't show
2927 // pointer contents unless a pointer depth has been specified.
2928 // We won't reference contents unless the reference is the
2929 // root object (depth of zero).
2930 bool print_children = true;
2931
2932 // Use a new temporary pointer depth in case we override the
2933 // current pointer depth below...
2934 uint32_t curr_ptr_depth = ptr_depth;
2935
2936 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
2937 if (is_ptr || is_ref)
2938 {
2939 // We have a pointer or reference whose value is an address.
2940 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00002941 AddressType ptr_address_type;
Greg Clayton73b472d2010-10-27 03:32:59 +00002942 if (valobj->GetPointerValue (ptr_address_type, true) == 0)
2943 print_children = false;
2944
2945 else if (is_ref && curr_depth == 0)
2946 {
2947 // If this is the root object (depth is zero) that we are showing
2948 // and it is a reference, and no pointer depth has been supplied
2949 // print out what it references. Don't do this at deeper depths
2950 // otherwise we can end up with infinite recursion...
2951 curr_ptr_depth = 1;
2952 }
2953
2954 if (curr_ptr_depth == 0)
2955 print_children = false;
2956 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002957
Enrico Granata0a3958e2011-07-02 00:25:22 +00002958 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00002959 {
Enrico Granatac482a192011-08-17 22:13:59 +00002960 ValueObjectSP synth_valobj = valobj->GetSyntheticValue(use_synth ?
Enrico Granatad55546b2011-07-22 00:16:08 +00002961 lldb::eUseSyntheticFilter :
2962 lldb::eNoSyntheticFilter);
Enrico Granatac482a192011-08-17 22:13:59 +00002963 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00002964 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002965 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002966 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002967 if (flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002968 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002969 if (print_valobj)
2970 s.EOL();
2971 }
2972 else
2973 {
2974 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00002975 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002976 s.IndentMore();
2977 }
Enrico Granata22c55d12011-08-12 02:00:06 +00002978
2979 uint32_t max_num_children = valobj->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
2980
2981 if (num_children > max_num_children && !ignore_cap)
2982 {
2983 num_children = max_num_children;
2984 print_dotdotdot = true;
2985 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002986
2987 for (uint32_t idx=0; idx<num_children; ++idx)
2988 {
Enrico Granatac482a192011-08-17 22:13:59 +00002989 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002990 if (child_sp.get())
2991 {
2992 DumpValueObject (s,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002993 child_sp.get(),
2994 NULL,
Greg Clayton73b472d2010-10-27 03:32:59 +00002995 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002996 curr_depth + 1,
2997 max_depth,
2998 show_types,
2999 show_location,
3000 false,
Jim Ingham78a685a2011-04-16 00:01:13 +00003001 use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00003002 use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003003 true,
Enrico Granata0c5ef692011-07-16 01:22:04 +00003004 flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00003005 omit_summary_depth > 1 ? omit_summary_depth - 1 : 0,
3006 ignore_cap);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003007 }
3008 }
3009
3010 if (!flat_output)
3011 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003012 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003013 {
3014 valobj->GetUpdatePoint().GetTargetSP()->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003015 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003016 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003017 s.IndentLess();
3018 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003019 }
3020 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003021 else if (has_children)
3022 {
3023 // Aggregate, no children...
3024 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003025 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003026 }
3027 else
3028 {
3029 if (print_valobj)
3030 s.EOL();
3031 }
3032
Greg Clayton1d3afba2010-10-05 00:00:42 +00003033 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003034 else
3035 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003036 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003037 }
3038 }
3039 else
3040 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003041 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003042 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003043 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003044 }
3045 }
3046 }
3047 }
3048}
3049
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003050
3051ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003052ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003053{
3054 ValueObjectSP valobj_sp;
3055
Enrico Granatac3e320a2011-08-02 17:27:39 +00003056 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003057 {
Jim Ingham6035b672011-03-31 00:19:25 +00003058 ExecutionContextScope *exe_scope = GetExecutionContextScope();
3059 if (exe_scope)
3060 {
3061 ExecutionContext exe_ctx;
3062 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003063
Jim Ingham6035b672011-03-31 00:19:25 +00003064 clang::ASTContext *ast = GetClangAST ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003065
Jim Ingham6035b672011-03-31 00:19:25 +00003066 DataExtractor data;
3067 data.SetByteOrder (m_data.GetByteOrder());
3068 data.SetAddressByteSize(m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003069
Greg Clayton644247c2011-07-07 01:59:51 +00003070 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003071
Jim Ingham58b59f92011-04-22 23:53:53 +00003072 valobj_sp = ValueObjectConstResult::Create (exe_scope,
3073 ast,
3074 GetClangType(),
3075 name,
3076 data);
Jim Ingham6035b672011-03-31 00:19:25 +00003077 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003078 }
Jim Ingham6035b672011-03-31 00:19:25 +00003079
3080 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003081 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003082 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003083 }
3084 return valobj_sp;
3085}
3086
3087lldb::ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003088ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003089{
Jim Ingham58b59f92011-04-22 23:53:53 +00003090 if (m_deref_valobj)
3091 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003092
Greg Clayton54979cd2010-12-15 05:08:08 +00003093 const bool is_pointer_type = IsPointerType();
3094 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003095 {
3096 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003097 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003098
3099 std::string child_name_str;
3100 uint32_t child_byte_size = 0;
3101 int32_t child_byte_offset = 0;
3102 uint32_t child_bitfield_bit_size = 0;
3103 uint32_t child_bitfield_bit_offset = 0;
3104 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003105 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003106 const bool transparent_pointers = false;
3107 clang::ASTContext *clang_ast = GetClangAST();
3108 clang_type_t clang_type = GetClangType();
3109 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003110
3111 ExecutionContext exe_ctx;
3112 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
3113
3114 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3115 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003116 GetName().GetCString(),
3117 clang_type,
3118 0,
3119 transparent_pointers,
3120 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003121 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003122 child_name_str,
3123 child_byte_size,
3124 child_byte_offset,
3125 child_bitfield_bit_size,
3126 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003127 child_is_base_class,
3128 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003129 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003130 {
3131 ConstString child_name;
3132 if (!child_name_str.empty())
3133 child_name.SetCString (child_name_str.c_str());
3134
Jim Ingham58b59f92011-04-22 23:53:53 +00003135 m_deref_valobj = new ValueObjectChild (*this,
3136 clang_ast,
3137 child_clang_type,
3138 child_name,
3139 child_byte_size,
3140 child_byte_offset,
3141 child_bitfield_bit_size,
3142 child_bitfield_bit_offset,
3143 child_is_base_class,
3144 child_is_deref_of_parent);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003145 }
3146 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003147
Jim Ingham58b59f92011-04-22 23:53:53 +00003148 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003149 {
3150 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003151 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003152 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003153 else
3154 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003155 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003156 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003157
3158 if (is_pointer_type)
3159 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3160 else
3161 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003162 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003163 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003164}
3165
Jim Ingham78a685a2011-04-16 00:01:13 +00003166lldb::ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003167ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003168{
Jim Ingham78a685a2011-04-16 00:01:13 +00003169 if (m_addr_of_valobj_sp)
3170 return m_addr_of_valobj_sp;
3171
Greg Claytone0d378b2011-03-24 21:19:54 +00003172 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003173 const bool scalar_is_load_address = false;
3174 lldb::addr_t addr = GetAddressOf (address_type, scalar_is_load_address);
Greg Clayton54979cd2010-12-15 05:08:08 +00003175 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003176 if (addr != LLDB_INVALID_ADDRESS)
3177 {
3178 switch (address_type)
3179 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003180 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003181 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003182 {
3183 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003184 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003185 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3186 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003187 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003188
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003189 case eAddressTypeFile:
3190 case eAddressTypeLoad:
3191 case eAddressTypeHost:
3192 {
3193 clang::ASTContext *ast = GetClangAST();
3194 clang_type_t clang_type = GetClangType();
3195 if (ast && clang_type)
3196 {
3197 std::string name (1, '&');
3198 name.append (m_name.AsCString(""));
Jim Ingham58b59f92011-04-22 23:53:53 +00003199 m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(),
3200 ast,
3201 ClangASTContext::CreatePointerType (ast, clang_type),
3202 ConstString (name.c_str()),
3203 addr,
3204 eAddressTypeInvalid,
3205 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003206 }
3207 }
3208 break;
3209 }
3210 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003211 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003212}
3213
Greg Claytonb2dcc362011-05-05 23:32:56 +00003214
3215lldb::ValueObjectSP
3216ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3217{
3218 lldb::ValueObjectSP valobj_sp;
3219 AddressType address_type;
3220 const bool scalar_is_load_address = true;
3221 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address);
3222
3223 if (ptr_value != LLDB_INVALID_ADDRESS)
3224 {
3225 Address ptr_addr (NULL, ptr_value);
3226
3227 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3228 name,
3229 ptr_addr,
3230 clang_ast_type);
3231 }
3232 return valobj_sp;
3233}
3234
3235lldb::ValueObjectSP
3236ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3237{
3238 lldb::ValueObjectSP valobj_sp;
3239 AddressType address_type;
3240 const bool scalar_is_load_address = true;
3241 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address);
3242
3243 if (ptr_value != LLDB_INVALID_ADDRESS)
3244 {
3245 Address ptr_addr (NULL, ptr_value);
3246
3247 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3248 name,
3249 ptr_addr,
3250 type_sp);
3251 }
3252 return valobj_sp;
3253}
3254
Jim Ingham6035b672011-03-31 00:19:25 +00003255ValueObject::EvaluationPoint::EvaluationPoint () :
Stephen Wilson71c21d12011-04-11 19:41:40 +00003256 m_thread_id (LLDB_INVALID_UID),
Jim Ingham4b536182011-08-09 02:12:22 +00003257 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003258{
3259}
3260
3261ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Jim Ingham6035b672011-03-31 00:19:25 +00003262 m_needs_update (true),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003263 m_first_update (true),
Jim Ingham89b61092011-07-06 17:42:14 +00003264 m_thread_id (LLDB_INVALID_THREAD_ID),
Jim Ingham4b536182011-08-09 02:12:22 +00003265 m_mod_id ()
Stephen Wilson71c21d12011-04-11 19:41:40 +00003266
Jim Ingham6035b672011-03-31 00:19:25 +00003267{
3268 ExecutionContext exe_ctx;
3269 ExecutionContextScope *computed_exe_scope = exe_scope; // If use_selected is true, we may find a better scope,
3270 // and if so we want to cache that not the original.
3271 if (exe_scope)
3272 exe_scope->CalculateExecutionContext(exe_ctx);
3273 if (exe_ctx.target != NULL)
3274 {
3275 m_target_sp = exe_ctx.target->GetSP();
3276
3277 if (exe_ctx.process == NULL)
3278 m_process_sp = exe_ctx.target->GetProcessSP();
3279 else
3280 m_process_sp = exe_ctx.process->GetSP();
3281
3282 if (m_process_sp != NULL)
3283 {
Jim Ingham4b536182011-08-09 02:12:22 +00003284 m_mod_id = m_process_sp->GetModID();
3285
Jim Ingham6035b672011-03-31 00:19:25 +00003286 Thread *thread = NULL;
3287
3288 if (exe_ctx.thread == NULL)
3289 {
3290 if (use_selected)
3291 {
3292 thread = m_process_sp->GetThreadList().GetSelectedThread().get();
3293 if (thread)
3294 computed_exe_scope = thread;
3295 }
3296 }
3297 else
3298 thread = exe_ctx.thread;
3299
3300 if (thread != NULL)
3301 {
3302 m_thread_id = thread->GetIndexID();
3303 if (exe_ctx.frame == NULL)
3304 {
3305 if (use_selected)
3306 {
3307 StackFrame *frame = exe_ctx.thread->GetSelectedFrame().get();
3308 if (frame)
3309 {
3310 m_stack_id = frame->GetStackID();
3311 computed_exe_scope = frame;
3312 }
3313 }
3314 }
3315 else
3316 m_stack_id = exe_ctx.frame->GetStackID();
3317 }
3318 }
3319 }
3320 m_exe_scope = computed_exe_scope;
3321}
3322
3323ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
3324 m_exe_scope (rhs.m_exe_scope),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003325 m_needs_update(true),
3326 m_first_update(true),
Jim Ingham6035b672011-03-31 00:19:25 +00003327 m_target_sp (rhs.m_target_sp),
3328 m_process_sp (rhs.m_process_sp),
3329 m_thread_id (rhs.m_thread_id),
3330 m_stack_id (rhs.m_stack_id),
Jim Ingham4b536182011-08-09 02:12:22 +00003331 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003332{
3333}
3334
3335ValueObject::EvaluationPoint::~EvaluationPoint ()
3336{
3337}
3338
3339ExecutionContextScope *
3340ValueObject::EvaluationPoint::GetExecutionContextScope ()
3341{
3342 // We have to update before giving out the scope, or we could be handing out stale pointers.
3343 SyncWithProcessState();
3344
3345 return m_exe_scope;
3346}
3347
3348// This function checks the EvaluationPoint against the current process state. If the current
3349// state matches the evaluation point, or the evaluation point is already invalid, then we return
3350// false, meaning "no change". If the current state is different, we update our state, and return
3351// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3352// future calls to NeedsUpdate will return true.
3353
3354bool
3355ValueObject::EvaluationPoint::SyncWithProcessState()
3356{
Jim Ingham6035b672011-03-31 00:19:25 +00003357 // If we don't have a process nothing can change.
3358 if (!m_process_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003359 {
3360 m_exe_scope = m_target_sp.get();
Jim Ingham6035b672011-03-31 00:19:25 +00003361 return false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003362 }
Jim Ingham6035b672011-03-31 00:19:25 +00003363
3364 // If our stop id is the current stop ID, nothing has changed:
Jim Ingham4b536182011-08-09 02:12:22 +00003365 ProcessModID current_mod_id = m_process_sp->GetModID();
3366
Jim Ingham78a685a2011-04-16 00:01:13 +00003367 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3368 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003369 if (current_mod_id.GetStopID() == 0)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003370 {
3371 m_exe_scope = m_target_sp.get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003372 return false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003373 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003374
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003375 if (m_mod_id.IsValid())
3376 {
3377 if (m_mod_id == current_mod_id)
3378 {
3379 // Everything is already up to date in this object, no need do
3380 // update the execution context scope.
3381 return false;
3382 }
3383 m_mod_id = current_mod_id;
3384 m_needs_update = true;
3385 }
Jim Ingham6035b672011-03-31 00:19:25 +00003386 m_exe_scope = m_process_sp.get();
3387
3388 // Something has changed, so we will return true. Now make sure the thread & frame still exist, and if either
3389 // doesn't, mark ourselves as invalid.
3390
3391 if (m_thread_id != LLDB_INVALID_THREAD_ID)
3392 {
3393 Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get();
3394 if (our_thread == NULL)
Greg Clayton262f80d2011-07-06 16:49:27 +00003395 {
Jim Ingham89b61092011-07-06 17:42:14 +00003396 SetInvalid();
Greg Clayton262f80d2011-07-06 16:49:27 +00003397 }
Jim Ingham6035b672011-03-31 00:19:25 +00003398 else
3399 {
3400 m_exe_scope = our_thread;
3401
3402 if (m_stack_id.IsValid())
3403 {
3404 StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get();
3405 if (our_frame == NULL)
3406 SetInvalid();
3407 else
3408 m_exe_scope = our_frame;
3409 }
3410 }
3411 }
3412 return true;
3413}
3414
Jim Ingham61be0902011-05-02 18:13:59 +00003415void
3416ValueObject::EvaluationPoint::SetUpdated ()
3417{
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003418 // this will update the execution context scope and the m_mod_id
3419 SyncWithProcessState();
Jim Ingham61be0902011-05-02 18:13:59 +00003420 m_first_update = false;
3421 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003422}
3423
3424
Jim Ingham6035b672011-03-31 00:19:25 +00003425bool
3426ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3427{
3428 if (!IsValid())
3429 return false;
3430
3431 bool needs_update = false;
3432 m_exe_scope = NULL;
3433
3434 // The target has to be non-null, and the
3435 Target *target = exe_scope->CalculateTarget();
3436 if (target != NULL)
3437 {
3438 Target *old_target = m_target_sp.get();
3439 assert (target == old_target);
3440 Process *process = exe_scope->CalculateProcess();
3441 if (process != NULL)
3442 {
3443 // FOR NOW - assume you can't update variable objects across process boundaries.
3444 Process *old_process = m_process_sp.get();
3445 assert (process == old_process);
Jim Ingham4b536182011-08-09 02:12:22 +00003446 ProcessModID current_mod_id = process->GetModID();
3447 if (m_mod_id != current_mod_id)
Jim Ingham6035b672011-03-31 00:19:25 +00003448 {
3449 needs_update = true;
Jim Ingham4b536182011-08-09 02:12:22 +00003450 m_mod_id = current_mod_id;
Jim Ingham6035b672011-03-31 00:19:25 +00003451 }
3452 // See if we're switching the thread or stack context. If no thread is given, this is
3453 // being evaluated in a global context.
3454 Thread *thread = exe_scope->CalculateThread();
3455 if (thread != NULL)
3456 {
3457 lldb::user_id_t new_thread_index = thread->GetIndexID();
3458 if (new_thread_index != m_thread_id)
3459 {
3460 needs_update = true;
3461 m_thread_id = new_thread_index;
3462 m_stack_id.Clear();
3463 }
3464
3465 StackFrame *new_frame = exe_scope->CalculateStackFrame();
3466 if (new_frame != NULL)
3467 {
3468 if (new_frame->GetStackID() != m_stack_id)
3469 {
3470 needs_update = true;
3471 m_stack_id = new_frame->GetStackID();
3472 }
3473 }
3474 else
3475 {
3476 m_stack_id.Clear();
3477 needs_update = true;
3478 }
3479 }
3480 else
3481 {
3482 // If this had been given a thread, and now there is none, we should update.
3483 // Otherwise we don't have to do anything.
3484 if (m_thread_id != LLDB_INVALID_UID)
3485 {
3486 m_thread_id = LLDB_INVALID_UID;
3487 m_stack_id.Clear();
3488 needs_update = true;
3489 }
3490 }
3491 }
3492 else
3493 {
3494 // If there is no process, then we don't need to update anything.
3495 // But if we're switching from having a process to not, we should try to update.
3496 if (m_process_sp.get() != NULL)
3497 {
3498 needs_update = true;
3499 m_process_sp.reset();
3500 m_thread_id = LLDB_INVALID_UID;
3501 m_stack_id.Clear();
3502 }
3503 }
3504 }
3505 else
3506 {
3507 // If there's no target, nothing can change so we don't need to update anything.
3508 // But if we're switching from having a target to not, we should try to update.
3509 if (m_target_sp.get() != NULL)
3510 {
3511 needs_update = true;
3512 m_target_sp.reset();
3513 m_process_sp.reset();
3514 m_thread_id = LLDB_INVALID_UID;
3515 m_stack_id.Clear();
3516 }
3517 }
3518 if (!m_needs_update)
3519 m_needs_update = needs_update;
3520
3521 return needs_update;
3522}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003523
3524void
3525ValueObject::ClearUserVisibleData()
3526{
3527 m_location_str.clear();
3528 m_value_str.clear();
3529 m_summary_str.clear();
3530 m_object_desc_str.clear();
Johnny Chen44805302011-07-19 19:48:13 +00003531}