blob: a9e2236013d00ea2b030d58fd8720c152da172c3 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/ValueObject.h"
11
12// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000013#include <stdlib.h>
14
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015// C++ Includes
16// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000018#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
20// Project includes
21#include "lldb/Core/DataBufferHeap.h"
Enrico Granata4becb372011-06-29 22:27:15 +000022#include "lldb/Core/Debugger.h"
Enrico Granatac482a192011-08-17 22:13:59 +000023#include "lldb/Core/FormatManager.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
940unsigned long long
941ValueObject::GetValueAsUnsigned()
942{
943 // If our byte size is zero this is an aggregate type that has children
944 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
945 {
946 if (UpdateValueIfNeeded(true))
947 {
948 uint32_t offset = 0;
949 return m_data.GetMaxU64(&offset,
950 m_data.GetByteSize());
951 }
952 }
953 return 0;
954}
955
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000956bool
957ValueObject::GetPrintableRepresentation(Stream& s,
958 ValueObjectRepresentationStyle val_obj_display,
Enrico Granata0a3958e2011-07-02 00:25:22 +0000959 lldb::Format custom_format)
960{
Enrico Granataf4efecd2011-07-12 22:56:10 +0000961
962 RefCounter ref(&m_dump_printable_counter);
963
Enrico Granata9dd75c82011-07-15 23:30:15 +0000964 if (custom_format != lldb::eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +0000965 SetFormat(custom_format);
966
967 const char * return_value;
Enrico Granatacd1c0232011-08-04 23:37:18 +0000968 std::string alloc_mem;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000969
970 switch(val_obj_display)
971 {
972 case eDisplayValue:
973 return_value = GetValueAsCString();
974 break;
975 case eDisplaySummary:
976 return_value = GetSummaryAsCString();
977 break;
978 case eDisplayLanguageSpecific:
979 return_value = GetObjectDescription();
980 break;
Enrico Granataf2bbf712011-07-15 02:26:42 +0000981 case eDisplayLocation:
982 return_value = GetLocationAsCString();
983 break;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000984 case eDisplayChildrenCount:
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000985 {
Enrico Granatacd1c0232011-08-04 23:37:18 +0000986 alloc_mem.resize(512);
987 return_value = &alloc_mem[0];
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000988 int count = GetNumChildren();
Enrico Granatacd1c0232011-08-04 23:37:18 +0000989 snprintf((char*)return_value, 512, "%d", count);
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000990 break;
991 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +0000992 case eDisplayType:
993 return_value = GetTypeName().AsCString();
994 break;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000995 default:
996 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000997 }
998
Enrico Granataf4efecd2011-07-12 22:56:10 +0000999 // this code snippet might lead to endless recursion, thus we use a RefCounter here to
1000 // check that we are not looping endlessly
1001 if (!return_value && (m_dump_printable_counter < 3))
Enrico Granata9fc19442011-07-06 02:13:41 +00001002 {
1003 // try to pick the other choice
1004 if (val_obj_display == eDisplayValue)
1005 return_value = GetSummaryAsCString();
1006 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +00001007 {
1008 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1009 {
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001010 // this thing has no value, and it seems to have no summary
1011 // some combination of unitialized data and other factors can also
1012 // raise this condition, so let's print a nice generic error message
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001013 {
1014 alloc_mem.resize(684);
1015 return_value = &alloc_mem[0];
1016 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1017 }
Enrico Granatae992a082011-07-22 17:03:19 +00001018 }
1019 else
1020 return_value = GetValueAsCString();
1021 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001022 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001023
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001024 if (return_value)
1025 s.PutCString(return_value);
1026 else
1027 s.PutCString("<no printable representation>");
1028
1029 // we should only return false here if we could not do *anything*
1030 // even if we have an error message as output, that's a success
1031 // from our callers' perspective, so return true
1032 return true;
1033
Enrico Granata0a3958e2011-07-02 00:25:22 +00001034}
1035
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001036// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1037// this call up to date by returning true for your new special cases. We will eventually move
1038// to checking this call result before trying to display special cases
1039bool
1040ValueObject::HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1041 lldb::Format custom_format)
1042{
1043 clang_type_t elem_or_pointee_type;
1044 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1045
1046 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1047 && val_obj_display == ValueObject::eDisplayValue)
1048 {
1049 if (IsCStringContainer(true) &&
1050 (custom_format == lldb::eFormatCString ||
1051 custom_format == lldb::eFormatCharArray ||
1052 custom_format == lldb::eFormatChar ||
1053 custom_format == lldb::eFormatVectorOfChar))
1054 return true;
1055
1056 if (flags.Test(ClangASTContext::eTypeIsArray))
1057 {
1058 if ((custom_format == lldb::eFormatBytes) ||
1059 (custom_format == lldb::eFormatBytesWithASCII))
1060 return true;
1061
1062 if ((custom_format == lldb::eFormatVectorOfChar) ||
1063 (custom_format == lldb::eFormatVectorOfFloat32) ||
1064 (custom_format == lldb::eFormatVectorOfFloat64) ||
1065 (custom_format == lldb::eFormatVectorOfSInt16) ||
1066 (custom_format == lldb::eFormatVectorOfSInt32) ||
1067 (custom_format == lldb::eFormatVectorOfSInt64) ||
1068 (custom_format == lldb::eFormatVectorOfSInt8) ||
1069 (custom_format == lldb::eFormatVectorOfUInt128) ||
1070 (custom_format == lldb::eFormatVectorOfUInt16) ||
1071 (custom_format == lldb::eFormatVectorOfUInt32) ||
1072 (custom_format == lldb::eFormatVectorOfUInt64) ||
1073 (custom_format == lldb::eFormatVectorOfUInt8))
1074 return true;
1075 }
1076 }
1077 return false;
1078}
1079
Enrico Granata9fc19442011-07-06 02:13:41 +00001080bool
1081ValueObject::DumpPrintableRepresentation(Stream& s,
1082 ValueObjectRepresentationStyle val_obj_display,
Enrico Granata85933ed2011-08-18 16:38:26 +00001083 lldb::Format custom_format,
1084 bool only_special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001085{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001086
1087 clang_type_t elem_or_pointee_type;
1088 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001089
Enrico Granataf4efecd2011-07-12 22:56:10 +00001090 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1091 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001092 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001093 // when being asked to get a printable display an array or pointer type directly,
1094 // try to "do the right thing"
1095
1096 if (IsCStringContainer(true) &&
1097 (custom_format == lldb::eFormatCString ||
1098 custom_format == lldb::eFormatCharArray ||
1099 custom_format == lldb::eFormatChar ||
1100 custom_format == lldb::eFormatVectorOfChar)) // print char[] & char* directly
1101 {
1102 Error error;
1103 ReadPointedString(s,
1104 error,
1105 0,
1106 (custom_format == lldb::eFormatVectorOfChar) ||
1107 (custom_format == lldb::eFormatCharArray));
1108 return !error.Fail();
1109 }
1110
1111 if (custom_format == lldb::eFormatEnum)
1112 return false;
1113
1114 // this only works for arrays, because I have no way to know when
1115 // the pointed memory ends, and no special \0 end of data marker
1116 if (flags.Test(ClangASTContext::eTypeIsArray))
1117 {
1118 if ((custom_format == lldb::eFormatBytes) ||
1119 (custom_format == lldb::eFormatBytesWithASCII))
1120 {
1121 uint32_t count = GetNumChildren();
1122
1123 s << '[';
1124 for (uint32_t low = 0; low < count; low++)
1125 {
1126
1127 if (low)
1128 s << ',';
1129
1130 ValueObjectSP child = GetChildAtIndex(low,true);
1131 if (!child.get())
1132 {
Enrico Granatae992a082011-07-22 17:03:19 +00001133 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001134 continue;
1135 }
1136 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1137 }
1138
1139 s << ']';
1140
1141 return true;
1142 }
1143
1144 if ((custom_format == lldb::eFormatVectorOfChar) ||
1145 (custom_format == lldb::eFormatVectorOfFloat32) ||
1146 (custom_format == lldb::eFormatVectorOfFloat64) ||
1147 (custom_format == lldb::eFormatVectorOfSInt16) ||
1148 (custom_format == lldb::eFormatVectorOfSInt32) ||
1149 (custom_format == lldb::eFormatVectorOfSInt64) ||
1150 (custom_format == lldb::eFormatVectorOfSInt8) ||
1151 (custom_format == lldb::eFormatVectorOfUInt128) ||
1152 (custom_format == lldb::eFormatVectorOfUInt16) ||
1153 (custom_format == lldb::eFormatVectorOfUInt32) ||
1154 (custom_format == lldb::eFormatVectorOfUInt64) ||
1155 (custom_format == lldb::eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1156 {
1157 uint32_t count = GetNumChildren();
1158
1159 lldb::Format format = FormatManager::GetSingleItemFormat(custom_format);
1160
1161 s << '[';
1162 for (uint32_t low = 0; low < count; low++)
1163 {
1164
1165 if (low)
1166 s << ',';
1167
1168 ValueObjectSP child = GetChildAtIndex(low,true);
1169 if (!child.get())
1170 {
Enrico Granatae992a082011-07-22 17:03:19 +00001171 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001172 continue;
1173 }
1174 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1175 }
1176
1177 s << ']';
1178
1179 return true;
1180 }
1181 }
1182
1183 if ((custom_format == lldb::eFormatBoolean) ||
1184 (custom_format == lldb::eFormatBinary) ||
1185 (custom_format == lldb::eFormatChar) ||
1186 (custom_format == lldb::eFormatCharPrintable) ||
1187 (custom_format == lldb::eFormatComplexFloat) ||
1188 (custom_format == lldb::eFormatDecimal) ||
1189 (custom_format == lldb::eFormatHex) ||
1190 (custom_format == lldb::eFormatFloat) ||
1191 (custom_format == lldb::eFormatOctal) ||
1192 (custom_format == lldb::eFormatOSType) ||
1193 (custom_format == lldb::eFormatUnicode16) ||
1194 (custom_format == lldb::eFormatUnicode32) ||
1195 (custom_format == lldb::eFormatUnsigned) ||
1196 (custom_format == lldb::eFormatPointer) ||
1197 (custom_format == lldb::eFormatComplexInteger) ||
1198 (custom_format == lldb::eFormatComplex) ||
1199 (custom_format == lldb::eFormatDefault)) // use the [] operator
1200 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001201 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001202
1203 if (only_special)
1204 return false;
1205
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001206 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001207 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001208 SetFormat(eFormatDefault);
1209 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001210}
1211
Greg Clayton737b9322010-09-13 03:32:57 +00001212addr_t
Greg Claytone0d378b2011-03-24 21:19:54 +00001213ValueObject::GetAddressOf (AddressType &address_type, bool scalar_is_load_address)
Greg Clayton73b472d2010-10-27 03:32:59 +00001214{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001215 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001216 return LLDB_INVALID_ADDRESS;
1217
Greg Clayton73b472d2010-10-27 03:32:59 +00001218 switch (m_value.GetValueType())
1219 {
1220 case Value::eValueTypeScalar:
1221 if (scalar_is_load_address)
1222 {
1223 address_type = eAddressTypeLoad;
1224 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1225 }
1226 break;
1227
1228 case Value::eValueTypeLoadAddress:
1229 case Value::eValueTypeFileAddress:
1230 case Value::eValueTypeHostAddress:
1231 {
1232 address_type = m_value.GetValueAddressType ();
1233 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1234 }
1235 break;
1236 }
1237 address_type = eAddressTypeInvalid;
1238 return LLDB_INVALID_ADDRESS;
1239}
1240
1241addr_t
Greg Claytone0d378b2011-03-24 21:19:54 +00001242ValueObject::GetPointerValue (AddressType &address_type, bool scalar_is_load_address)
Greg Clayton737b9322010-09-13 03:32:57 +00001243{
1244 lldb::addr_t address = LLDB_INVALID_ADDRESS;
1245 address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001246
Enrico Granatac3e320a2011-08-02 17:27:39 +00001247 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001248 return address;
1249
Greg Clayton73b472d2010-10-27 03:32:59 +00001250 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001251 {
1252 case Value::eValueTypeScalar:
1253 if (scalar_is_load_address)
1254 {
1255 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1256 address_type = eAddressTypeLoad;
1257 }
1258 break;
1259
1260 case Value::eValueTypeLoadAddress:
1261 case Value::eValueTypeFileAddress:
1262 case Value::eValueTypeHostAddress:
1263 {
1264 uint32_t data_offset = 0;
1265 address = m_data.GetPointer(&data_offset);
1266 address_type = m_value.GetValueAddressType();
1267 if (address_type == eAddressTypeInvalid)
1268 address_type = eAddressTypeLoad;
1269 }
1270 break;
1271 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001272
1273 if (m_pointers_point_to_load_addrs)
1274 address_type = eAddressTypeLoad;
1275
Greg Clayton737b9322010-09-13 03:32:57 +00001276 return address;
1277}
1278
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001279bool
Jim Ingham6035b672011-03-31 00:19:25 +00001280ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001281{
1282 // Make sure our value is up to date first so that our location and location
1283 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001284 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001285 return false;
1286
1287 uint32_t count = 0;
Greg Clayton1be10fc2010-09-29 01:12:09 +00001288 lldb::Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001289
Greg Claytonb1320972010-07-14 00:18:15 +00001290 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001291
Jim Ingham16e0c682011-08-12 23:34:31 +00001292 Value::ValueType value_type = m_value.GetValueType();
1293
1294 if (value_type == Value::eValueTypeScalar)
1295 {
1296 // If the value is already a scalar, then let the scalar change itself:
1297 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1298 }
1299 else if (byte_size <= Scalar::GetMaxByteSize())
1300 {
1301 // If the value fits in a scalar, then make a new scalar and again let the
1302 // scalar code do the conversion, then figure out where to put the new value.
1303 Scalar new_scalar;
1304 Error error;
1305 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1306 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001307 {
Jim Ingham4b536182011-08-09 02:12:22 +00001308 switch (value_type)
1309 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001310 case Value::eValueTypeLoadAddress:
1311 {
1312 // If it is a load address, then the scalar value is the storage location
1313 // of the data, and we have to shove this value down to that load location.
1314 ProcessSP process_sp = GetUpdatePoint().GetProcessSP();
1315 if (process_sp)
1316 {
1317 lldb::addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
1318 size_t bytes_written = process_sp->WriteScalarToMemory (target_addr,
1319 new_scalar,
1320 byte_size,
1321 error);
1322 if (!error.Success() || bytes_written != byte_size)
1323 return false;
1324 }
1325 }
Jim Ingham4b536182011-08-09 02:12:22 +00001326 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001327 case Value::eValueTypeHostAddress:
1328 {
1329 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1330 DataExtractor new_data;
1331 new_data.SetByteOrder (m_data.GetByteOrder());
1332
1333 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1334 m_data.SetData(buffer_sp, 0);
1335 bool success = new_scalar.GetData(new_data);
1336 if (success)
1337 {
1338 new_data.CopyByteOrderedData(0,
1339 byte_size,
1340 const_cast<uint8_t *>(m_data.GetDataStart()),
1341 byte_size,
1342 m_data.GetByteOrder());
1343 }
1344 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1345
1346 }
Jim Ingham4b536182011-08-09 02:12:22 +00001347 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001348 case Value::eValueTypeFileAddress:
1349 case Value::eValueTypeScalar:
1350 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001351 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001352 }
1353 else
1354 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001355 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001356 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001357 }
1358 else
1359 {
1360 // We don't support setting things bigger than a scalar at present.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001361 return false;
1362 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001363
1364 // If we have reached this point, then we have successfully changed the value.
1365 SetNeedsUpdate();
1366 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001367}
1368
Jim Ingham5a369122010-09-28 01:25:32 +00001369lldb::LanguageType
1370ValueObject::GetObjectRuntimeLanguage ()
1371{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001372 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1373 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001374}
1375
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001376void
Jim Ingham58b59f92011-04-22 23:53:53 +00001377ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001378{
Jim Ingham58b59f92011-04-22 23:53:53 +00001379 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001380}
1381
1382ValueObjectSP
1383ValueObject::GetSyntheticChild (const ConstString &key) const
1384{
1385 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001386 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001387 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001388 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001389 return synthetic_child_sp;
1390}
1391
1392bool
1393ValueObject::IsPointerType ()
1394{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001395 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001396}
1397
Jim Inghamb7603bb2011-03-18 00:05:18 +00001398bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001399ValueObject::IsArrayType ()
1400{
1401 return ClangASTContext::IsArrayType (GetClangType());
1402}
1403
1404bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001405ValueObject::IsScalarType ()
1406{
1407 return ClangASTContext::IsScalarType (GetClangType());
1408}
1409
1410bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001411ValueObject::IsIntegerType (bool &is_signed)
1412{
1413 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1414}
Greg Clayton73b472d2010-10-27 03:32:59 +00001415
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001416bool
1417ValueObject::IsPointerOrReferenceType ()
1418{
Greg Clayton007d5be2011-05-30 00:49:24 +00001419 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1420}
1421
1422bool
1423ValueObject::IsPossibleCPlusPlusDynamicType ()
1424{
1425 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001426}
1427
Greg Claytondea8cb42011-06-29 22:09:02 +00001428bool
1429ValueObject::IsPossibleDynamicType ()
1430{
1431 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1432}
1433
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001434lldb::ValueObjectSP
1435ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1436{
1437 if (IsArrayType())
1438 return GetSyntheticArrayMemberFromArray(index, can_create);
1439
1440 if (IsPointerType())
1441 return GetSyntheticArrayMemberFromPointer(index, can_create);
1442
1443 return ValueObjectSP();
1444
1445}
1446
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001447ValueObjectSP
1448ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1449{
1450 ValueObjectSP synthetic_child_sp;
1451 if (IsPointerType ())
1452 {
1453 char index_str[64];
1454 snprintf(index_str, sizeof(index_str), "[%i]", index);
1455 ConstString index_const_str(index_str);
1456 // Check if we have already created a synthetic array member in this
1457 // valid object. If we have we will re-use it.
1458 synthetic_child_sp = GetSyntheticChild (index_const_str);
1459 if (!synthetic_child_sp)
1460 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001461 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001462 // We haven't made a synthetic array member for INDEX yet, so
1463 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001464 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001465
1466 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001467 if (synthetic_child)
1468 {
1469 AddSyntheticChild(index_const_str, synthetic_child);
1470 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001471 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001472 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001473 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001474 }
1475 }
1476 return synthetic_child_sp;
1477}
Jim Ingham22777012010-09-23 02:01:19 +00001478
Greg Claytondaf515f2011-07-09 20:12:33 +00001479// This allows you to create an array member using and index
1480// that doesn't not fall in the normal bounds of the array.
1481// Many times structure can be defined as:
1482// struct Collection
1483// {
1484// uint32_t item_count;
1485// Item item_array[0];
1486// };
1487// The size of the "item_array" is 1, but many times in practice
1488// there are more items in "item_array".
1489
1490ValueObjectSP
1491ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1492{
1493 ValueObjectSP synthetic_child_sp;
1494 if (IsArrayType ())
1495 {
1496 char index_str[64];
1497 snprintf(index_str, sizeof(index_str), "[%i]", index);
1498 ConstString index_const_str(index_str);
1499 // Check if we have already created a synthetic array member in this
1500 // valid object. If we have we will re-use it.
1501 synthetic_child_sp = GetSyntheticChild (index_const_str);
1502 if (!synthetic_child_sp)
1503 {
1504 ValueObject *synthetic_child;
1505 // We haven't made a synthetic array member for INDEX yet, so
1506 // lets make one and cache it for any future reference.
1507 synthetic_child = CreateChildAtIndex(0, true, index);
1508
1509 // Cache the value if we got one back...
1510 if (synthetic_child)
1511 {
1512 AddSyntheticChild(index_const_str, synthetic_child);
1513 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001514 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001515 synthetic_child_sp->m_is_array_item_for_pointer = true;
1516 }
1517 }
1518 }
1519 return synthetic_child_sp;
1520}
1521
Enrico Granata9fc19442011-07-06 02:13:41 +00001522ValueObjectSP
1523ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1524{
1525 ValueObjectSP synthetic_child_sp;
1526 if (IsScalarType ())
1527 {
1528 char index_str[64];
1529 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1530 ConstString index_const_str(index_str);
1531 // Check if we have already created a synthetic array member in this
1532 // valid object. If we have we will re-use it.
1533 synthetic_child_sp = GetSyntheticChild (index_const_str);
1534 if (!synthetic_child_sp)
1535 {
1536 ValueObjectChild *synthetic_child;
1537 // We haven't made a synthetic array member for INDEX yet, so
1538 // lets make one and cache it for any future reference.
1539 synthetic_child = new ValueObjectChild(*this,
1540 GetClangAST(),
1541 GetClangType(),
1542 index_const_str,
1543 GetByteSize(),
1544 0,
1545 to-from+1,
1546 from,
1547 false,
1548 false);
1549
1550 // Cache the value if we got one back...
1551 if (synthetic_child)
1552 {
1553 AddSyntheticChild(index_const_str, synthetic_child);
1554 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001555 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001556 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1557 }
1558 }
1559 }
1560 return synthetic_child_sp;
1561}
1562
Enrico Granata6f3533f2011-07-29 19:53:35 +00001563lldb::ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001564ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1565{
1566 ValueObjectSP synthetic_child_sp;
1567 if (IsArrayType () || IsPointerType ())
1568 {
1569 char index_str[64];
1570 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1571 ConstString index_const_str(index_str);
1572 // Check if we have already created a synthetic array member in this
1573 // valid object. If we have we will re-use it.
1574 synthetic_child_sp = GetSyntheticChild (index_const_str);
1575 if (!synthetic_child_sp)
1576 {
1577 ValueObjectSynthetic *synthetic_child;
1578
1579 // We haven't made a synthetic array member for INDEX yet, so
1580 // lets make one and cache it for any future reference.
1581 SyntheticArrayView *view = new SyntheticArrayView();
1582 view->AddRange(from,to);
1583 SyntheticChildrenSP view_sp(view);
1584 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1585
1586 // Cache the value if we got one back...
1587 if (synthetic_child)
1588 {
1589 AddSyntheticChild(index_const_str, synthetic_child);
1590 synthetic_child_sp = synthetic_child->GetSP();
1591 synthetic_child_sp->SetName(ConstString(index_str));
1592 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1593 }
1594 }
1595 }
1596 return synthetic_child_sp;
1597}
1598
1599lldb::ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001600ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1601{
1602
1603 ValueObjectSP synthetic_child_sp;
1604
1605 char name_str[64];
1606 snprintf(name_str, sizeof(name_str), "@%i", offset);
1607 ConstString name_const_str(name_str);
1608
1609 // Check if we have already created a synthetic array member in this
1610 // valid object. If we have we will re-use it.
1611 synthetic_child_sp = GetSyntheticChild (name_const_str);
1612
1613 if (synthetic_child_sp.get())
1614 return synthetic_child_sp;
1615
1616 if (!can_create)
1617 return lldb::ValueObjectSP();
1618
1619 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1620 type.GetASTContext(),
1621 type.GetOpaqueQualType(),
1622 name_const_str,
1623 type.GetTypeByteSize(),
1624 offset,
1625 0,
1626 0,
1627 false,
1628 false);
1629 if (synthetic_child)
1630 {
1631 AddSyntheticChild(name_const_str, synthetic_child);
1632 synthetic_child_sp = synthetic_child->GetSP();
1633 synthetic_child_sp->SetName(name_const_str);
1634 synthetic_child_sp->m_is_child_at_offset = true;
1635 }
1636 return synthetic_child_sp;
1637}
1638
Enrico Granatad55546b2011-07-22 00:16:08 +00001639// your expression path needs to have a leading . or ->
1640// (unless it somehow "looks like" an array, in which case it has
1641// a leading [ symbol). while the [ is meaningful and should be shown
1642// to the user, . and -> are just parser design, but by no means
1643// added information for the user.. strip them off
1644static const char*
1645SkipLeadingExpressionPathSeparators(const char* expression)
1646{
1647 if (!expression || !expression[0])
1648 return expression;
1649 if (expression[0] == '.')
1650 return expression+1;
1651 if (expression[0] == '-' && expression[1] == '>')
1652 return expression+2;
1653 return expression;
1654}
1655
1656lldb::ValueObjectSP
1657ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1658{
1659 ValueObjectSP synthetic_child_sp;
1660 ConstString name_const_string(expression);
1661 // Check if we have already created a synthetic array member in this
1662 // valid object. If we have we will re-use it.
1663 synthetic_child_sp = GetSyntheticChild (name_const_string);
1664 if (!synthetic_child_sp)
1665 {
1666 // We haven't made a synthetic array member for expression yet, so
1667 // lets make one and cache it for any future reference.
1668 synthetic_child_sp = GetValueForExpressionPath(expression);
1669
1670 // Cache the value if we got one back...
1671 if (synthetic_child_sp.get())
1672 {
1673 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001674 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001675 synthetic_child_sp->m_is_expression_path_child = true;
1676 }
1677 }
1678 return synthetic_child_sp;
1679}
1680
1681void
1682ValueObject::CalculateSyntheticValue (lldb::SyntheticValueType use_synthetic)
1683{
1684 if (use_synthetic == lldb::eNoSyntheticFilter)
1685 return;
1686
Enrico Granatac3e320a2011-08-02 17:27:39 +00001687 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001688
1689 if (m_last_synthetic_filter.get() == NULL)
1690 return;
1691
Enrico Granataa37a0652011-07-24 00:14:56 +00001692 if (m_synthetic_value == NULL)
1693 m_synthetic_value = new ValueObjectSynthetic(*this, m_last_synthetic_filter);
Enrico Granatad55546b2011-07-22 00:16:08 +00001694
1695}
1696
Jim Ingham78a685a2011-04-16 00:01:13 +00001697void
Jim Ingham2837b762011-05-04 03:43:18 +00001698ValueObject::CalculateDynamicValue (lldb::DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00001699{
Jim Ingham2837b762011-05-04 03:43:18 +00001700 if (use_dynamic == lldb::eNoDynamicValues)
1701 return;
1702
Jim Ingham58b59f92011-04-22 23:53:53 +00001703 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00001704 {
Enrico Granata6f3533f2011-07-29 19:53:35 +00001705 Process *process = m_update_point.GetProcessSP().get();
Jim Ingham78a685a2011-04-16 00:01:13 +00001706 bool worth_having_dynamic_value = false;
Jim Ingham22777012010-09-23 02:01:19 +00001707
Jim Ingham78a685a2011-04-16 00:01:13 +00001708
1709 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
1710 // hard code this everywhere.
1711 lldb::LanguageType known_type = GetObjectRuntimeLanguage();
1712 if (known_type != lldb::eLanguageTypeUnknown && known_type != lldb::eLanguageTypeC)
1713 {
1714 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
1715 if (runtime)
1716 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
1717 }
1718 else
1719 {
1720 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeC_plus_plus);
1721 if (cpp_runtime)
1722 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
1723
1724 if (!worth_having_dynamic_value)
1725 {
1726 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeObjC);
1727 if (objc_runtime)
Jim Ingham2837b762011-05-04 03:43:18 +00001728 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00001729 }
1730 }
1731
1732 if (worth_having_dynamic_value)
Jim Ingham2837b762011-05-04 03:43:18 +00001733 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham58b59f92011-04-22 23:53:53 +00001734
1735// if (worth_having_dynamic_value)
1736// printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager);
1737
Jim Ingham78a685a2011-04-16 00:01:13 +00001738 }
1739}
1740
Jim Ingham58b59f92011-04-22 23:53:53 +00001741ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00001742ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00001743{
Jim Ingham2837b762011-05-04 03:43:18 +00001744 if (use_dynamic == lldb::eNoDynamicValues)
1745 return ValueObjectSP();
1746
1747 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00001748 {
Jim Ingham2837b762011-05-04 03:43:18 +00001749 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001750 }
Jim Ingham58b59f92011-04-22 23:53:53 +00001751 if (m_dynamic_value)
1752 return m_dynamic_value->GetSP();
1753 else
1754 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00001755}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001756
Enrico Granatad55546b2011-07-22 00:16:08 +00001757// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
1758// or we do not really want a dynamic VO. this method instead returns this object
1759// itself when making it synthetic has no meaning. this makes it much simpler
1760// to replace the SyntheticValue for the ValueObject
1761ValueObjectSP
1762ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
1763{
1764 if (use_synthetic == lldb::eNoSyntheticFilter)
1765 return GetSP();
1766
Enrico Granatac3e320a2011-08-02 17:27:39 +00001767 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001768
1769 if (m_last_synthetic_filter.get() == NULL)
1770 return GetSP();
1771
1772 CalculateSyntheticValue(use_synthetic);
1773
1774 if (m_synthetic_value)
1775 return m_synthetic_value->GetSP();
1776 else
1777 return GetSP();
1778}
1779
Greg Claytone221f822011-01-21 01:59:00 +00001780bool
Enrico Granata27b625e2011-08-09 01:04:56 +00001781ValueObject::HasSyntheticValue()
1782{
1783 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
1784
1785 if (m_last_synthetic_filter.get() == NULL)
1786 return false;
1787
1788 CalculateSyntheticValue(lldb::eUseSyntheticFilter);
1789
1790 if (m_synthetic_value)
1791 return true;
1792 else
1793 return false;
1794}
1795
1796bool
Greg Claytone221f822011-01-21 01:59:00 +00001797ValueObject::GetBaseClassPath (Stream &s)
1798{
1799 if (IsBaseClass())
1800 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001801 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00001802 clang_type_t clang_type = GetClangType();
1803 std::string cxx_class_name;
1804 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
1805 if (this_had_base_class)
1806 {
1807 if (parent_had_base_class)
1808 s.PutCString("::");
1809 s.PutCString(cxx_class_name.c_str());
1810 }
1811 return parent_had_base_class || this_had_base_class;
1812 }
1813 return false;
1814}
1815
1816
1817ValueObject *
1818ValueObject::GetNonBaseClassParent()
1819{
Jim Ingham78a685a2011-04-16 00:01:13 +00001820 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00001821 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001822 if (GetParent()->IsBaseClass())
1823 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00001824 else
Jim Ingham78a685a2011-04-16 00:01:13 +00001825 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00001826 }
1827 return NULL;
1828}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001829
1830void
Enrico Granata4becb372011-06-29 22:27:15 +00001831ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001832{
Greg Claytone221f822011-01-21 01:59:00 +00001833 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00001834
Enrico Granata85933ed2011-08-18 16:38:26 +00001835 if (is_deref_of_parent && epformat == eDereferencePointers)
1836 {
Enrico Granata4becb372011-06-29 22:27:15 +00001837 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
1838 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
1839 // the eHonorPointers mode is meant to produce strings in this latter format
1840 s.PutCString("*(");
1841 }
Greg Claytone221f822011-01-21 01:59:00 +00001842
Enrico Granata4becb372011-06-29 22:27:15 +00001843 ValueObject* parent = GetParent();
1844
1845 if (parent)
1846 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00001847
1848 // if we are a deref_of_parent just because we are synthetic array
1849 // members made up to allow ptr[%d] syntax to work in variable
1850 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00001851 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001852 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00001853
Greg Claytone221f822011-01-21 01:59:00 +00001854 if (!IsBaseClass())
1855 {
1856 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001857 {
Greg Claytone221f822011-01-21 01:59:00 +00001858 ValueObject *non_base_class_parent = GetNonBaseClassParent();
1859 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001860 {
Greg Claytone221f822011-01-21 01:59:00 +00001861 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
1862 if (non_base_class_parent_clang_type)
1863 {
1864 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
1865
Enrico Granata9dd75c82011-07-15 23:30:15 +00001866 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00001867 {
1868 s.PutCString("->");
1869 }
Enrico Granata4becb372011-06-29 22:27:15 +00001870 else
1871 {
1872 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
1873 {
1874 s.PutCString("->");
1875 }
1876 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
1877 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
1878 {
1879 s.PutChar('.');
1880 }
Greg Claytone221f822011-01-21 01:59:00 +00001881 }
1882 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001883 }
Greg Claytone221f822011-01-21 01:59:00 +00001884
1885 const char *name = GetName().GetCString();
1886 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001887 {
Greg Claytone221f822011-01-21 01:59:00 +00001888 if (qualify_cxx_base_classes)
1889 {
1890 if (GetBaseClassPath (s))
1891 s.PutCString("::");
1892 }
1893 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001894 }
1895 }
1896 }
1897
Enrico Granata85933ed2011-08-18 16:38:26 +00001898 if (is_deref_of_parent && epformat == eDereferencePointers)
1899 {
Greg Claytone221f822011-01-21 01:59:00 +00001900 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00001901 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001902}
1903
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001904lldb::ValueObjectSP
1905ValueObject::GetValueForExpressionPath(const char* expression,
1906 const char** first_unparsed,
1907 ExpressionPathScanEndReason* reason_to_stop,
1908 ExpressionPathEndResultType* final_value_type,
1909 const GetValueForExpressionPathOptions& options,
1910 ExpressionPathAftermath* final_task_on_target)
1911{
1912
1913 const char* dummy_first_unparsed;
1914 ExpressionPathScanEndReason dummy_reason_to_stop;
1915 ExpressionPathEndResultType dummy_final_value_type;
1916 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
1917
1918 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
1919 first_unparsed ? first_unparsed : &dummy_first_unparsed,
1920 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
1921 final_value_type ? final_value_type : &dummy_final_value_type,
1922 options,
1923 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
1924
1925 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
1926 {
1927 return ret_val;
1928 }
1929 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
1930 {
1931 if (*final_task_on_target == ValueObject::eDereference)
1932 {
1933 Error error;
1934 ValueObjectSP final_value = ret_val->Dereference(error);
1935 if (error.Fail() || !final_value.get())
1936 {
1937 *reason_to_stop = ValueObject::eDereferencingFailed;
1938 *final_value_type = ValueObject::eInvalid;
1939 return ValueObjectSP();
1940 }
1941 else
1942 {
1943 *final_task_on_target = ValueObject::eNothing;
1944 return final_value;
1945 }
1946 }
1947 if (*final_task_on_target == ValueObject::eTakeAddress)
1948 {
1949 Error error;
1950 ValueObjectSP final_value = ret_val->AddressOf(error);
1951 if (error.Fail() || !final_value.get())
1952 {
1953 *reason_to_stop = ValueObject::eTakingAddressFailed;
1954 *final_value_type = ValueObject::eInvalid;
1955 return ValueObjectSP();
1956 }
1957 else
1958 {
1959 *final_task_on_target = ValueObject::eNothing;
1960 return final_value;
1961 }
1962 }
1963 }
1964 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
1965}
1966
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001967int
1968ValueObject::GetValuesForExpressionPath(const char* expression,
1969 lldb::ValueObjectListSP& list,
1970 const char** first_unparsed,
1971 ExpressionPathScanEndReason* reason_to_stop,
1972 ExpressionPathEndResultType* final_value_type,
1973 const GetValueForExpressionPathOptions& options,
1974 ExpressionPathAftermath* final_task_on_target)
1975{
1976 const char* dummy_first_unparsed;
1977 ExpressionPathScanEndReason dummy_reason_to_stop;
1978 ExpressionPathEndResultType dummy_final_value_type;
1979 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
1980
1981 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
1982 first_unparsed ? first_unparsed : &dummy_first_unparsed,
1983 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
1984 final_value_type ? final_value_type : &dummy_final_value_type,
1985 options,
1986 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
1987
1988 if (!ret_val.get()) // if there are errors, I add nothing to the list
1989 return 0;
1990
1991 if (*reason_to_stop != eArrayRangeOperatorMet)
1992 {
1993 // I need not expand a range, just post-process the final value and return
1994 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
1995 {
1996 list->Append(ret_val);
1997 return 1;
1998 }
1999 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2000 {
2001 if (*final_task_on_target == ValueObject::eDereference)
2002 {
2003 Error error;
2004 ValueObjectSP final_value = ret_val->Dereference(error);
2005 if (error.Fail() || !final_value.get())
2006 {
2007 *reason_to_stop = ValueObject::eDereferencingFailed;
2008 *final_value_type = ValueObject::eInvalid;
2009 return 0;
2010 }
2011 else
2012 {
2013 *final_task_on_target = ValueObject::eNothing;
2014 list->Append(final_value);
2015 return 1;
2016 }
2017 }
2018 if (*final_task_on_target == ValueObject::eTakeAddress)
2019 {
2020 Error error;
2021 ValueObjectSP final_value = ret_val->AddressOf(error);
2022 if (error.Fail() || !final_value.get())
2023 {
2024 *reason_to_stop = ValueObject::eTakingAddressFailed;
2025 *final_value_type = ValueObject::eInvalid;
2026 return 0;
2027 }
2028 else
2029 {
2030 *final_task_on_target = ValueObject::eNothing;
2031 list->Append(final_value);
2032 return 1;
2033 }
2034 }
2035 }
2036 }
2037 else
2038 {
2039 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2040 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2041 ret_val,
2042 list,
2043 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2044 final_value_type ? final_value_type : &dummy_final_value_type,
2045 options,
2046 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2047 }
2048 // in any non-covered case, just do the obviously right thing
2049 list->Append(ret_val);
2050 return 1;
2051}
2052
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002053lldb::ValueObjectSP
2054ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2055 const char** first_unparsed,
2056 ExpressionPathScanEndReason* reason_to_stop,
2057 ExpressionPathEndResultType* final_result,
2058 const GetValueForExpressionPathOptions& options,
2059 ExpressionPathAftermath* what_next)
2060{
2061 ValueObjectSP root = GetSP();
2062
2063 if (!root.get())
2064 return ValueObjectSP();
2065
2066 *first_unparsed = expression_cstr;
2067
2068 while (true)
2069 {
2070
2071 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2072
2073 lldb::clang_type_t root_clang_type = root->GetClangType();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002074 lldb::clang_type_t pointee_clang_type;
2075 Flags root_clang_type_info,pointee_clang_type_info;
2076
2077 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2078 if (pointee_clang_type)
2079 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002080
2081 if (!expression_cstr || *expression_cstr == '\0')
2082 {
2083 *reason_to_stop = ValueObject::eEndOfString;
2084 return root;
2085 }
2086
2087 switch (*expression_cstr)
2088 {
2089 case '-':
2090 {
2091 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002092 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 +00002093 {
2094 *first_unparsed = expression_cstr;
2095 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
2096 *final_result = ValueObject::eInvalid;
2097 return ValueObjectSP();
2098 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002099 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2100 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002101 options.m_no_fragile_ivar)
2102 {
2103 *first_unparsed = expression_cstr;
2104 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
2105 *final_result = ValueObject::eInvalid;
2106 return ValueObjectSP();
2107 }
2108 if (expression_cstr[1] != '>')
2109 {
2110 *first_unparsed = expression_cstr;
2111 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2112 *final_result = ValueObject::eInvalid;
2113 return ValueObjectSP();
2114 }
2115 expression_cstr++; // skip the -
2116 }
2117 case '.': // or fallthrough from ->
2118 {
2119 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002120 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 +00002121 {
2122 *first_unparsed = expression_cstr;
2123 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
2124 *final_result = ValueObject::eInvalid;
2125 return ValueObjectSP();
2126 }
2127 expression_cstr++; // skip .
2128 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2129 ConstString child_name;
2130 if (!next_separator) // if no other separator just expand this last layer
2131 {
2132 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002133 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2134
2135 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002136 {
2137 *first_unparsed = '\0';
2138 *reason_to_stop = ValueObject::eEndOfString;
2139 *final_result = ValueObject::ePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002140 return child_valobj_sp;
2141 }
2142 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2143 {
2144 child_valobj_sp = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
2145 }
2146
2147 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2148 // so we hit the "else" branch, and return an error
2149 if(child_valobj_sp.get()) // if it worked, just return
2150 {
2151 *first_unparsed = '\0';
2152 *reason_to_stop = ValueObject::eEndOfString;
2153 *final_result = ValueObject::ePlain;
2154 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002155 }
2156 else
2157 {
2158 *first_unparsed = expression_cstr;
2159 *reason_to_stop = ValueObject::eNoSuchChild;
2160 *final_result = ValueObject::eInvalid;
2161 return ValueObjectSP();
2162 }
2163 }
2164 else // other layers do expand
2165 {
2166 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002167 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2168 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002169 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002170 root = child_valobj_sp;
2171 *first_unparsed = next_separator;
2172 *final_result = ValueObject::ePlain;
2173 continue;
2174 }
2175 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2176 {
2177 child_valobj_sp = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
2178 }
2179
2180 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2181 // so we hit the "else" branch, and return an error
2182 if(child_valobj_sp.get()) // if it worked, move on
2183 {
2184 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002185 *first_unparsed = next_separator;
2186 *final_result = ValueObject::ePlain;
2187 continue;
2188 }
2189 else
2190 {
2191 *first_unparsed = expression_cstr;
2192 *reason_to_stop = ValueObject::eNoSuchChild;
2193 *final_result = ValueObject::eInvalid;
2194 return ValueObjectSP();
2195 }
2196 }
2197 break;
2198 }
2199 case '[':
2200 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002201 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 +00002202 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002203 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002204 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002205 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2206 {
2207 *first_unparsed = expression_cstr;
2208 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2209 *final_result = ValueObject::eInvalid;
2210 return ValueObjectSP();
2211 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002212 }
2213 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2214 {
2215 *first_unparsed = expression_cstr;
2216 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2217 *final_result = ValueObject::eInvalid;
2218 return ValueObjectSP();
2219 }
2220 }
2221 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2222 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002223 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002224 {
2225 *first_unparsed = expression_cstr;
2226 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2227 *final_result = ValueObject::eInvalid;
2228 return ValueObjectSP();
2229 }
2230 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2231 {
2232 *first_unparsed = expression_cstr+2;
2233 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2234 *final_result = ValueObject::eUnboundedRange;
2235 return root;
2236 }
2237 }
2238 const char *separator_position = ::strchr(expression_cstr+1,'-');
2239 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2240 if (!close_bracket_position) // if there is no ], this is a syntax error
2241 {
2242 *first_unparsed = expression_cstr;
2243 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2244 *final_result = ValueObject::eInvalid;
2245 return ValueObjectSP();
2246 }
2247 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2248 {
2249 char *end = NULL;
2250 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2251 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2252 {
2253 *first_unparsed = expression_cstr;
2254 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2255 *final_result = ValueObject::eInvalid;
2256 return ValueObjectSP();
2257 }
2258 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2259 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002260 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002261 {
2262 *first_unparsed = expression_cstr+2;
2263 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2264 *final_result = ValueObject::eUnboundedRange;
2265 return root;
2266 }
2267 else
2268 {
2269 *first_unparsed = expression_cstr;
2270 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2271 *final_result = ValueObject::eInvalid;
2272 return ValueObjectSP();
2273 }
2274 }
2275 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002276 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002277 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002278 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2279 if (!child_valobj_sp)
2280 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002281 if (!child_valobj_sp)
2282 if (root->HasSyntheticValue() && root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetNumChildren() > index)
2283 child_valobj_sp = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002284 if (child_valobj_sp)
2285 {
2286 root = child_valobj_sp;
2287 *first_unparsed = end+1; // skip ]
2288 *final_result = ValueObject::ePlain;
2289 continue;
2290 }
2291 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002292 {
2293 *first_unparsed = expression_cstr;
2294 *reason_to_stop = ValueObject::eNoSuchChild;
2295 *final_result = ValueObject::eInvalid;
2296 return ValueObjectSP();
2297 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002298 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002299 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002300 {
2301 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 +00002302 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002303 {
2304 Error error;
2305 root = root->Dereference(error);
2306 if (error.Fail() || !root.get())
2307 {
2308 *first_unparsed = expression_cstr;
2309 *reason_to_stop = ValueObject::eDereferencingFailed;
2310 *final_result = ValueObject::eInvalid;
2311 return ValueObjectSP();
2312 }
2313 else
2314 {
2315 *what_next = eNothing;
2316 continue;
2317 }
2318 }
2319 else
2320 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002321 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
2322 root->GetClangType()) == lldb::eLanguageTypeObjC
2323 &&
2324 ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2325 &&
2326 root->HasSyntheticValue()
2327 &&
2328 options.m_no_synthetic_children == false)
2329 {
2330 root = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildAtIndex(index, true);
2331 }
2332 else
2333 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002334 if (!root.get())
2335 {
2336 *first_unparsed = expression_cstr;
2337 *reason_to_stop = ValueObject::eNoSuchChild;
2338 *final_result = ValueObject::eInvalid;
2339 return ValueObjectSP();
2340 }
2341 else
2342 {
2343 *first_unparsed = end+1; // skip ]
2344 *final_result = ValueObject::ePlain;
2345 continue;
2346 }
2347 }
2348 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002349 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002350 {
2351 root = root->GetSyntheticBitFieldChild(index, index, true);
2352 if (!root.get())
2353 {
2354 *first_unparsed = expression_cstr;
2355 *reason_to_stop = ValueObject::eNoSuchChild;
2356 *final_result = ValueObject::eInvalid;
2357 return ValueObjectSP();
2358 }
2359 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2360 {
2361 *first_unparsed = end+1; // skip ]
2362 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2363 *final_result = ValueObject::eBitfield;
2364 return root;
2365 }
2366 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002367 else if (root->HasSyntheticValue() && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002368 {
2369 root = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildAtIndex(index, true);
2370 if (!root.get())
2371 {
2372 *first_unparsed = expression_cstr;
2373 *reason_to_stop = ValueObject::eNoSuchChild;
2374 *final_result = ValueObject::eInvalid;
2375 return ValueObjectSP();
2376 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002377 else
2378 {
2379 *first_unparsed = end+1; // skip ]
2380 *final_result = ValueObject::ePlain;
2381 continue;
2382 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002383 }
2384 else
2385 {
2386 *first_unparsed = expression_cstr;
2387 *reason_to_stop = ValueObject::eNoSuchChild;
2388 *final_result = ValueObject::eInvalid;
2389 return ValueObjectSP();
2390 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002391 }
2392 else // we have a low and a high index
2393 {
2394 char *end = NULL;
2395 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2396 if (!end || end != separator_position) // if something weird is in our way return an error
2397 {
2398 *first_unparsed = expression_cstr;
2399 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2400 *final_result = ValueObject::eInvalid;
2401 return ValueObjectSP();
2402 }
2403 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2404 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2405 {
2406 *first_unparsed = expression_cstr;
2407 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2408 *final_result = ValueObject::eInvalid;
2409 return ValueObjectSP();
2410 }
2411 if (index_lower > index_higher) // swap indices if required
2412 {
2413 unsigned long temp = index_lower;
2414 index_lower = index_higher;
2415 index_higher = temp;
2416 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002417 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002418 {
2419 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2420 if (!root.get())
2421 {
2422 *first_unparsed = expression_cstr;
2423 *reason_to_stop = ValueObject::eNoSuchChild;
2424 *final_result = ValueObject::eInvalid;
2425 return ValueObjectSP();
2426 }
2427 else
2428 {
2429 *first_unparsed = end+1; // skip ]
2430 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2431 *final_result = ValueObject::eBitfield;
2432 return root;
2433 }
2434 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002435 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 +00002436 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002437 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002438 {
2439 Error error;
2440 root = root->Dereference(error);
2441 if (error.Fail() || !root.get())
2442 {
2443 *first_unparsed = expression_cstr;
2444 *reason_to_stop = ValueObject::eDereferencingFailed;
2445 *final_result = ValueObject::eInvalid;
2446 return ValueObjectSP();
2447 }
2448 else
2449 {
2450 *what_next = ValueObject::eNothing;
2451 continue;
2452 }
2453 }
2454 else
2455 {
2456 *first_unparsed = expression_cstr;
2457 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2458 *final_result = ValueObject::eBoundedRange;
2459 return root;
2460 }
2461 }
2462 break;
2463 }
2464 default: // some non-separator is in the way
2465 {
2466 *first_unparsed = expression_cstr;
2467 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2468 *final_result = ValueObject::eInvalid;
2469 return ValueObjectSP();
2470 break;
2471 }
2472 }
2473 }
2474}
2475
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002476int
2477ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2478 const char** first_unparsed,
2479 lldb::ValueObjectSP root,
2480 lldb::ValueObjectListSP& list,
2481 ExpressionPathScanEndReason* reason_to_stop,
2482 ExpressionPathEndResultType* final_result,
2483 const GetValueForExpressionPathOptions& options,
2484 ExpressionPathAftermath* what_next)
2485{
2486 if (!root.get())
2487 return 0;
2488
2489 *first_unparsed = expression_cstr;
2490
2491 while (true)
2492 {
2493
2494 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2495
2496 lldb::clang_type_t root_clang_type = root->GetClangType();
2497 lldb::clang_type_t pointee_clang_type;
2498 Flags root_clang_type_info,pointee_clang_type_info;
2499
2500 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2501 if (pointee_clang_type)
2502 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2503
2504 if (!expression_cstr || *expression_cstr == '\0')
2505 {
2506 *reason_to_stop = ValueObject::eEndOfString;
2507 list->Append(root);
2508 return 1;
2509 }
2510
2511 switch (*expression_cstr)
2512 {
2513 case '[':
2514 {
2515 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2516 {
2517 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2518 {
2519 *first_unparsed = expression_cstr;
2520 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2521 *final_result = ValueObject::eInvalid;
2522 return 0;
2523 }
2524 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2525 {
2526 *first_unparsed = expression_cstr;
2527 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2528 *final_result = ValueObject::eInvalid;
2529 return 0;
2530 }
2531 }
2532 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2533 {
2534 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2535 {
2536 *first_unparsed = expression_cstr;
2537 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2538 *final_result = ValueObject::eInvalid;
2539 return 0;
2540 }
2541 else // expand this into list
2542 {
2543 int max_index = root->GetNumChildren() - 1;
2544 for (int index = 0; index < max_index; index++)
2545 {
2546 ValueObjectSP child =
2547 root->GetChildAtIndex(index, true);
2548 list->Append(child);
2549 }
2550 *first_unparsed = expression_cstr+2;
2551 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2552 *final_result = ValueObject::eValueObjectList;
2553 return max_index; // tell me number of items I added to the VOList
2554 }
2555 }
2556 const char *separator_position = ::strchr(expression_cstr+1,'-');
2557 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2558 if (!close_bracket_position) // if there is no ], this is a syntax error
2559 {
2560 *first_unparsed = expression_cstr;
2561 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2562 *final_result = ValueObject::eInvalid;
2563 return 0;
2564 }
2565 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2566 {
2567 char *end = NULL;
2568 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2569 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2570 {
2571 *first_unparsed = expression_cstr;
2572 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2573 *final_result = ValueObject::eInvalid;
2574 return 0;
2575 }
2576 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2577 {
2578 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2579 {
2580 int max_index = root->GetNumChildren() - 1;
2581 for (int index = 0; index < max_index; index++)
2582 {
2583 ValueObjectSP child =
2584 root->GetChildAtIndex(index, true);
2585 list->Append(child);
2586 }
2587 *first_unparsed = expression_cstr+2;
2588 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2589 *final_result = ValueObject::eValueObjectList;
2590 return max_index; // tell me number of items I added to the VOList
2591 }
2592 else
2593 {
2594 *first_unparsed = expression_cstr;
2595 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2596 *final_result = ValueObject::eInvalid;
2597 return 0;
2598 }
2599 }
2600 // from here on we do have a valid index
2601 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2602 {
2603 root = root->GetChildAtIndex(index, true);
2604 if (!root.get())
2605 {
2606 *first_unparsed = expression_cstr;
2607 *reason_to_stop = ValueObject::eNoSuchChild;
2608 *final_result = ValueObject::eInvalid;
2609 return 0;
2610 }
2611 else
2612 {
2613 list->Append(root);
2614 *first_unparsed = end+1; // skip ]
2615 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2616 *final_result = ValueObject::eValueObjectList;
2617 return 1;
2618 }
2619 }
2620 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2621 {
2622 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
2623 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2624 {
2625 Error error;
2626 root = root->Dereference(error);
2627 if (error.Fail() || !root.get())
2628 {
2629 *first_unparsed = expression_cstr;
2630 *reason_to_stop = ValueObject::eDereferencingFailed;
2631 *final_result = ValueObject::eInvalid;
2632 return 0;
2633 }
2634 else
2635 {
2636 *what_next = eNothing;
2637 continue;
2638 }
2639 }
2640 else
2641 {
2642 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2643 if (!root.get())
2644 {
2645 *first_unparsed = expression_cstr;
2646 *reason_to_stop = ValueObject::eNoSuchChild;
2647 *final_result = ValueObject::eInvalid;
2648 return 0;
2649 }
2650 else
2651 {
2652 list->Append(root);
2653 *first_unparsed = end+1; // skip ]
2654 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2655 *final_result = ValueObject::eValueObjectList;
2656 return 1;
2657 }
2658 }
2659 }
2660 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2661 {
2662 root = root->GetSyntheticBitFieldChild(index, index, true);
2663 if (!root.get())
2664 {
2665 *first_unparsed = expression_cstr;
2666 *reason_to_stop = ValueObject::eNoSuchChild;
2667 *final_result = ValueObject::eInvalid;
2668 return 0;
2669 }
2670 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2671 {
2672 list->Append(root);
2673 *first_unparsed = end+1; // skip ]
2674 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2675 *final_result = ValueObject::eValueObjectList;
2676 return 1;
2677 }
2678 }
2679 }
2680 else // we have a low and a high index
2681 {
2682 char *end = NULL;
2683 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2684 if (!end || end != separator_position) // if something weird is in our way return an error
2685 {
2686 *first_unparsed = expression_cstr;
2687 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2688 *final_result = ValueObject::eInvalid;
2689 return 0;
2690 }
2691 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2692 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2693 {
2694 *first_unparsed = expression_cstr;
2695 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2696 *final_result = ValueObject::eInvalid;
2697 return 0;
2698 }
2699 if (index_lower > index_higher) // swap indices if required
2700 {
2701 unsigned long temp = index_lower;
2702 index_lower = index_higher;
2703 index_higher = temp;
2704 }
2705 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
2706 {
2707 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2708 if (!root.get())
2709 {
2710 *first_unparsed = expression_cstr;
2711 *reason_to_stop = ValueObject::eNoSuchChild;
2712 *final_result = ValueObject::eInvalid;
2713 return 0;
2714 }
2715 else
2716 {
2717 list->Append(root);
2718 *first_unparsed = end+1; // skip ]
2719 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2720 *final_result = ValueObject::eValueObjectList;
2721 return 1;
2722 }
2723 }
2724 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
2725 *what_next == ValueObject::eDereference &&
2726 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2727 {
2728 Error error;
2729 root = root->Dereference(error);
2730 if (error.Fail() || !root.get())
2731 {
2732 *first_unparsed = expression_cstr;
2733 *reason_to_stop = ValueObject::eDereferencingFailed;
2734 *final_result = ValueObject::eInvalid;
2735 return 0;
2736 }
2737 else
2738 {
2739 *what_next = ValueObject::eNothing;
2740 continue;
2741 }
2742 }
2743 else
2744 {
Johnny Chen44805302011-07-19 19:48:13 +00002745 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002746 index <= index_higher; index++)
2747 {
2748 ValueObjectSP child =
2749 root->GetChildAtIndex(index, true);
2750 list->Append(child);
2751 }
2752 *first_unparsed = end+1;
2753 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2754 *final_result = ValueObject::eValueObjectList;
2755 return index_higher-index_lower+1; // tell me number of items I added to the VOList
2756 }
2757 }
2758 break;
2759 }
2760 default: // some non-[ separator, or something entirely wrong, is in the way
2761 {
2762 *first_unparsed = expression_cstr;
2763 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2764 *final_result = ValueObject::eInvalid;
2765 return 0;
2766 break;
2767 }
2768 }
2769 }
2770}
2771
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002772void
Greg Clayton1d3afba2010-10-05 00:00:42 +00002773ValueObject::DumpValueObject
2774(
2775 Stream &s,
Greg Clayton1d3afba2010-10-05 00:00:42 +00002776 ValueObject *valobj,
2777 const char *root_valobj_name,
2778 uint32_t ptr_depth,
2779 uint32_t curr_depth,
2780 uint32_t max_depth,
2781 bool show_types,
2782 bool show_location,
2783 bool use_objc,
Jim Ingham2837b762011-05-04 03:43:18 +00002784 lldb::DynamicValueType use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00002785 bool use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002786 bool scope_already_checked,
Enrico Granata0c5ef692011-07-16 01:22:04 +00002787 bool flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00002788 uint32_t omit_summary_depth,
2789 bool ignore_cap
Greg Clayton1d3afba2010-10-05 00:00:42 +00002790)
2791{
Greg Clayton007d5be2011-05-30 00:49:24 +00002792 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002793 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00002794 bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00002795
2796 if (update_success && use_dynamic != lldb::eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00002797 {
Jim Ingham2837b762011-05-04 03:43:18 +00002798 ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00002799 if (dynamic_value)
2800 valobj = dynamic_value;
2801 }
2802
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002803 clang_type_t clang_type = valobj->GetClangType();
2804
Greg Clayton73b472d2010-10-27 03:32:59 +00002805 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002806 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00002807 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
2808 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002809
2810 const bool print_valobj = flat_output == false || has_value;
2811
2812 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002813 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002814 if (show_location)
2815 {
Jim Ingham6035b672011-03-31 00:19:25 +00002816 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002817 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002818
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002819 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00002820
Greg Clayton7c8a9662010-11-02 01:50:16 +00002821 // Always show the type for the top level items.
Greg Claytone221f822011-01-21 01:59:00 +00002822 if (show_types || (curr_depth == 0 && !flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00002823 {
Enrico Granata9910bc82011-08-03 02:18:51 +00002824 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
2825 s.Printf("(%s", typeName);
2826 // only show dynamic types if the user really wants to see types
2827 if (show_types && use_dynamic != lldb::eNoDynamicValues &&
2828 (/*strstr(typeName, "id") == typeName ||*/
2829 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == lldb::eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00002830 {
2831 Process* process = valobj->GetUpdatePoint().GetProcessSP().get();
2832 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00002833 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002834 else
2835 {
2836 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
2837 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00002838 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002839 else
2840 {
2841 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
2842 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00002843 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002844 else
2845 s.Printf(", dynamic type: %s) ",
2846 runtime->GetActualTypeName(isa).GetCString());
2847 }
2848 }
2849 }
2850 else
2851 s.Printf(") ");
2852 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002853
Greg Clayton1d3afba2010-10-05 00:00:42 +00002854
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002855 if (flat_output)
2856 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00002857 // If we are showing types, also qualify the C++ base classes
2858 const bool qualify_cxx_base_classes = show_types;
2859 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002860 s.PutCString(" =");
2861 }
2862 else
2863 {
2864 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
2865 s.Printf ("%s =", name_cstr);
2866 }
2867
Jim Ingham6035b672011-03-31 00:19:25 +00002868 if (!scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002869 {
Greg Clayton007d5be2011-05-30 00:49:24 +00002870 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002871 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002872 }
2873
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002874 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00002875 const char *sum_cstr = NULL;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002876 SummaryFormat* entry = valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002877
Enrico Granata0c5ef692011-07-16 01:22:04 +00002878 if (omit_summary_depth > 0)
2879 entry = NULL;
2880
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002881 if (err_cstr == NULL)
2882 {
Jim Ingham6035b672011-03-31 00:19:25 +00002883 val_cstr = valobj->GetValueAsCString();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002884 err_cstr = valobj->GetError().AsCString();
2885 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002886
2887 if (err_cstr)
2888 {
Greg Clayton007d5be2011-05-30 00:49:24 +00002889 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00002890 }
2891 else
2892 {
Greg Clayton73b472d2010-10-27 03:32:59 +00002893 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002894 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002895 {
Enrico Granata4becb372011-06-29 22:27:15 +00002896
Enrico Granata0c5ef692011-07-16 01:22:04 +00002897 sum_cstr = (omit_summary_depth == 0) ? valobj->GetSummaryAsCString() : NULL;
Greg Clayton1d3afba2010-10-05 00:00:42 +00002898
Enrico Granata4becb372011-06-29 22:27:15 +00002899 // We must calculate this value in realtime because entry might alter this variable's value
2900 // (e.g. by saying ${var%fmt}) and render precached values useless
2901 if (val_cstr && (!entry || entry->DoesPrintValue() || !sum_cstr))
2902 s.Printf(" %s", valobj->GetValueAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002903
Enrico Granata9dd75c82011-07-15 23:30:15 +00002904 if (sum_cstr)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002905 {
2906 // for some reason, using %@ (ObjC description) in a summary string, makes
2907 // us believe we need to reset ourselves, thus invalidating the content of
2908 // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty
2909 // let us recalculate it!
2910 if (sum_cstr[0] == '\0')
2911 s.Printf(" %s", valobj->GetSummaryAsCString());
2912 else
2913 s.Printf(" %s", sum_cstr);
2914 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002915
2916 if (use_objc)
2917 {
Jim Ingham6035b672011-03-31 00:19:25 +00002918 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002919 if (object_desc)
2920 s.Printf(" %s\n", object_desc);
2921 else
Sean Callanan672ad942010-10-23 00:18:49 +00002922 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002923 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00002924 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002925 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002926
2927 if (curr_depth < max_depth)
2928 {
Greg Clayton73b472d2010-10-27 03:32:59 +00002929 // We will show children for all concrete types. We won't show
2930 // pointer contents unless a pointer depth has been specified.
2931 // We won't reference contents unless the reference is the
2932 // root object (depth of zero).
2933 bool print_children = true;
2934
2935 // Use a new temporary pointer depth in case we override the
2936 // current pointer depth below...
2937 uint32_t curr_ptr_depth = ptr_depth;
2938
2939 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
2940 if (is_ptr || is_ref)
2941 {
2942 // We have a pointer or reference whose value is an address.
2943 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00002944 AddressType ptr_address_type;
Greg Clayton73b472d2010-10-27 03:32:59 +00002945 if (valobj->GetPointerValue (ptr_address_type, true) == 0)
2946 print_children = false;
2947
2948 else if (is_ref && curr_depth == 0)
2949 {
2950 // If this is the root object (depth is zero) that we are showing
2951 // and it is a reference, and no pointer depth has been supplied
2952 // print out what it references. Don't do this at deeper depths
2953 // otherwise we can end up with infinite recursion...
2954 curr_ptr_depth = 1;
2955 }
2956
2957 if (curr_ptr_depth == 0)
2958 print_children = false;
2959 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002960
Enrico Granata0a3958e2011-07-02 00:25:22 +00002961 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00002962 {
Enrico Granatac482a192011-08-17 22:13:59 +00002963 ValueObjectSP synth_valobj = valobj->GetSyntheticValue(use_synth ?
Enrico Granatad55546b2011-07-22 00:16:08 +00002964 lldb::eUseSyntheticFilter :
2965 lldb::eNoSyntheticFilter);
Enrico Granatac482a192011-08-17 22:13:59 +00002966 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00002967 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002968 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002969 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002970 if (flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002971 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002972 if (print_valobj)
2973 s.EOL();
2974 }
2975 else
2976 {
2977 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00002978 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002979 s.IndentMore();
2980 }
Enrico Granata22c55d12011-08-12 02:00:06 +00002981
2982 uint32_t max_num_children = valobj->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
2983
2984 if (num_children > max_num_children && !ignore_cap)
2985 {
2986 num_children = max_num_children;
2987 print_dotdotdot = true;
2988 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002989
2990 for (uint32_t idx=0; idx<num_children; ++idx)
2991 {
Enrico Granatac482a192011-08-17 22:13:59 +00002992 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002993 if (child_sp.get())
2994 {
2995 DumpValueObject (s,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002996 child_sp.get(),
2997 NULL,
Greg Clayton73b472d2010-10-27 03:32:59 +00002998 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002999 curr_depth + 1,
3000 max_depth,
3001 show_types,
3002 show_location,
3003 false,
Jim Ingham78a685a2011-04-16 00:01:13 +00003004 use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00003005 use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003006 true,
Enrico Granata0c5ef692011-07-16 01:22:04 +00003007 flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00003008 omit_summary_depth > 1 ? omit_summary_depth - 1 : 0,
3009 ignore_cap);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003010 }
3011 }
3012
3013 if (!flat_output)
3014 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003015 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003016 {
3017 valobj->GetUpdatePoint().GetTargetSP()->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003018 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003019 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003020 s.IndentLess();
3021 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003022 }
3023 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003024 else if (has_children)
3025 {
3026 // Aggregate, no children...
3027 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003028 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003029 }
3030 else
3031 {
3032 if (print_valobj)
3033 s.EOL();
3034 }
3035
Greg Clayton1d3afba2010-10-05 00:00:42 +00003036 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003037 else
3038 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003039 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003040 }
3041 }
3042 else
3043 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003044 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003045 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003046 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003047 }
3048 }
3049 }
3050 }
3051}
3052
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003053
3054ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003055ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003056{
3057 ValueObjectSP valobj_sp;
3058
Enrico Granatac3e320a2011-08-02 17:27:39 +00003059 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003060 {
Jim Ingham6035b672011-03-31 00:19:25 +00003061 ExecutionContextScope *exe_scope = GetExecutionContextScope();
3062 if (exe_scope)
3063 {
3064 ExecutionContext exe_ctx;
3065 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003066
Jim Ingham6035b672011-03-31 00:19:25 +00003067 clang::ASTContext *ast = GetClangAST ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003068
Jim Ingham6035b672011-03-31 00:19:25 +00003069 DataExtractor data;
3070 data.SetByteOrder (m_data.GetByteOrder());
3071 data.SetAddressByteSize(m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003072
Greg Clayton644247c2011-07-07 01:59:51 +00003073 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003074
Jim Ingham58b59f92011-04-22 23:53:53 +00003075 valobj_sp = ValueObjectConstResult::Create (exe_scope,
3076 ast,
3077 GetClangType(),
3078 name,
3079 data);
Jim Ingham6035b672011-03-31 00:19:25 +00003080 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003081 }
Jim Ingham6035b672011-03-31 00:19:25 +00003082
3083 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003084 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003085 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003086 }
3087 return valobj_sp;
3088}
3089
3090lldb::ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003091ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003092{
Jim Ingham58b59f92011-04-22 23:53:53 +00003093 if (m_deref_valobj)
3094 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003095
Greg Clayton54979cd2010-12-15 05:08:08 +00003096 const bool is_pointer_type = IsPointerType();
3097 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003098 {
3099 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003100 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003101
3102 std::string child_name_str;
3103 uint32_t child_byte_size = 0;
3104 int32_t child_byte_offset = 0;
3105 uint32_t child_bitfield_bit_size = 0;
3106 uint32_t child_bitfield_bit_offset = 0;
3107 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003108 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003109 const bool transparent_pointers = false;
3110 clang::ASTContext *clang_ast = GetClangAST();
3111 clang_type_t clang_type = GetClangType();
3112 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003113
3114 ExecutionContext exe_ctx;
3115 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
3116
3117 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3118 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003119 GetName().GetCString(),
3120 clang_type,
3121 0,
3122 transparent_pointers,
3123 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003124 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003125 child_name_str,
3126 child_byte_size,
3127 child_byte_offset,
3128 child_bitfield_bit_size,
3129 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003130 child_is_base_class,
3131 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003132 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003133 {
3134 ConstString child_name;
3135 if (!child_name_str.empty())
3136 child_name.SetCString (child_name_str.c_str());
3137
Jim Ingham58b59f92011-04-22 23:53:53 +00003138 m_deref_valobj = new ValueObjectChild (*this,
3139 clang_ast,
3140 child_clang_type,
3141 child_name,
3142 child_byte_size,
3143 child_byte_offset,
3144 child_bitfield_bit_size,
3145 child_bitfield_bit_offset,
3146 child_is_base_class,
3147 child_is_deref_of_parent);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003148 }
3149 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003150
Jim Ingham58b59f92011-04-22 23:53:53 +00003151 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003152 {
3153 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003154 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003155 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003156 else
3157 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003158 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003159 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003160
3161 if (is_pointer_type)
3162 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3163 else
3164 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003165 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003166 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003167}
3168
Jim Ingham78a685a2011-04-16 00:01:13 +00003169lldb::ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003170ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003171{
Jim Ingham78a685a2011-04-16 00:01:13 +00003172 if (m_addr_of_valobj_sp)
3173 return m_addr_of_valobj_sp;
3174
Greg Claytone0d378b2011-03-24 21:19:54 +00003175 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003176 const bool scalar_is_load_address = false;
3177 lldb::addr_t addr = GetAddressOf (address_type, scalar_is_load_address);
Greg Clayton54979cd2010-12-15 05:08:08 +00003178 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003179 if (addr != LLDB_INVALID_ADDRESS)
3180 {
3181 switch (address_type)
3182 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003183 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003184 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003185 {
3186 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003187 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003188 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3189 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003190 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003191
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003192 case eAddressTypeFile:
3193 case eAddressTypeLoad:
3194 case eAddressTypeHost:
3195 {
3196 clang::ASTContext *ast = GetClangAST();
3197 clang_type_t clang_type = GetClangType();
3198 if (ast && clang_type)
3199 {
3200 std::string name (1, '&');
3201 name.append (m_name.AsCString(""));
Jim Ingham58b59f92011-04-22 23:53:53 +00003202 m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(),
3203 ast,
3204 ClangASTContext::CreatePointerType (ast, clang_type),
3205 ConstString (name.c_str()),
3206 addr,
3207 eAddressTypeInvalid,
3208 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003209 }
3210 }
3211 break;
3212 }
3213 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003214 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003215}
3216
Greg Claytonb2dcc362011-05-05 23:32:56 +00003217
3218lldb::ValueObjectSP
3219ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3220{
3221 lldb::ValueObjectSP valobj_sp;
3222 AddressType address_type;
3223 const bool scalar_is_load_address = true;
3224 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address);
3225
3226 if (ptr_value != LLDB_INVALID_ADDRESS)
3227 {
3228 Address ptr_addr (NULL, ptr_value);
3229
3230 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3231 name,
3232 ptr_addr,
3233 clang_ast_type);
3234 }
3235 return valobj_sp;
3236}
3237
3238lldb::ValueObjectSP
3239ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3240{
3241 lldb::ValueObjectSP valobj_sp;
3242 AddressType address_type;
3243 const bool scalar_is_load_address = true;
3244 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address);
3245
3246 if (ptr_value != LLDB_INVALID_ADDRESS)
3247 {
3248 Address ptr_addr (NULL, ptr_value);
3249
3250 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3251 name,
3252 ptr_addr,
3253 type_sp);
3254 }
3255 return valobj_sp;
3256}
3257
Jim Ingham6035b672011-03-31 00:19:25 +00003258ValueObject::EvaluationPoint::EvaluationPoint () :
Stephen Wilson71c21d12011-04-11 19:41:40 +00003259 m_thread_id (LLDB_INVALID_UID),
Jim Ingham4b536182011-08-09 02:12:22 +00003260 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003261{
3262}
3263
3264ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Jim Ingham6035b672011-03-31 00:19:25 +00003265 m_needs_update (true),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003266 m_first_update (true),
Jim Ingham89b61092011-07-06 17:42:14 +00003267 m_thread_id (LLDB_INVALID_THREAD_ID),
Jim Ingham4b536182011-08-09 02:12:22 +00003268 m_mod_id ()
Stephen Wilson71c21d12011-04-11 19:41:40 +00003269
Jim Ingham6035b672011-03-31 00:19:25 +00003270{
3271 ExecutionContext exe_ctx;
3272 ExecutionContextScope *computed_exe_scope = exe_scope; // If use_selected is true, we may find a better scope,
3273 // and if so we want to cache that not the original.
3274 if (exe_scope)
3275 exe_scope->CalculateExecutionContext(exe_ctx);
3276 if (exe_ctx.target != NULL)
3277 {
3278 m_target_sp = exe_ctx.target->GetSP();
3279
3280 if (exe_ctx.process == NULL)
3281 m_process_sp = exe_ctx.target->GetProcessSP();
3282 else
3283 m_process_sp = exe_ctx.process->GetSP();
3284
3285 if (m_process_sp != NULL)
3286 {
Jim Ingham4b536182011-08-09 02:12:22 +00003287 m_mod_id = m_process_sp->GetModID();
3288
Jim Ingham6035b672011-03-31 00:19:25 +00003289 Thread *thread = NULL;
3290
3291 if (exe_ctx.thread == NULL)
3292 {
3293 if (use_selected)
3294 {
3295 thread = m_process_sp->GetThreadList().GetSelectedThread().get();
3296 if (thread)
3297 computed_exe_scope = thread;
3298 }
3299 }
3300 else
3301 thread = exe_ctx.thread;
3302
3303 if (thread != NULL)
3304 {
3305 m_thread_id = thread->GetIndexID();
3306 if (exe_ctx.frame == NULL)
3307 {
3308 if (use_selected)
3309 {
3310 StackFrame *frame = exe_ctx.thread->GetSelectedFrame().get();
3311 if (frame)
3312 {
3313 m_stack_id = frame->GetStackID();
3314 computed_exe_scope = frame;
3315 }
3316 }
3317 }
3318 else
3319 m_stack_id = exe_ctx.frame->GetStackID();
3320 }
3321 }
3322 }
3323 m_exe_scope = computed_exe_scope;
3324}
3325
3326ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
3327 m_exe_scope (rhs.m_exe_scope),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003328 m_needs_update(true),
3329 m_first_update(true),
Jim Ingham6035b672011-03-31 00:19:25 +00003330 m_target_sp (rhs.m_target_sp),
3331 m_process_sp (rhs.m_process_sp),
3332 m_thread_id (rhs.m_thread_id),
3333 m_stack_id (rhs.m_stack_id),
Jim Ingham4b536182011-08-09 02:12:22 +00003334 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003335{
3336}
3337
3338ValueObject::EvaluationPoint::~EvaluationPoint ()
3339{
3340}
3341
3342ExecutionContextScope *
3343ValueObject::EvaluationPoint::GetExecutionContextScope ()
3344{
3345 // We have to update before giving out the scope, or we could be handing out stale pointers.
3346 SyncWithProcessState();
3347
3348 return m_exe_scope;
3349}
3350
3351// This function checks the EvaluationPoint against the current process state. If the current
3352// state matches the evaluation point, or the evaluation point is already invalid, then we return
3353// false, meaning "no change". If the current state is different, we update our state, and return
3354// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3355// future calls to NeedsUpdate will return true.
3356
3357bool
3358ValueObject::EvaluationPoint::SyncWithProcessState()
3359{
Jim Ingham6035b672011-03-31 00:19:25 +00003360 // If we don't have a process nothing can change.
3361 if (!m_process_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003362 {
3363 m_exe_scope = m_target_sp.get();
Jim Ingham6035b672011-03-31 00:19:25 +00003364 return false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003365 }
Jim Ingham6035b672011-03-31 00:19:25 +00003366
3367 // If our stop id is the current stop ID, nothing has changed:
Jim Ingham4b536182011-08-09 02:12:22 +00003368 ProcessModID current_mod_id = m_process_sp->GetModID();
3369
Jim Ingham78a685a2011-04-16 00:01:13 +00003370 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3371 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003372 if (current_mod_id.GetStopID() == 0)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003373 {
3374 m_exe_scope = m_target_sp.get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003375 return false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003376 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003377
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003378 if (m_mod_id.IsValid())
3379 {
3380 if (m_mod_id == current_mod_id)
3381 {
3382 // Everything is already up to date in this object, no need do
3383 // update the execution context scope.
3384 return false;
3385 }
3386 m_mod_id = current_mod_id;
3387 m_needs_update = true;
3388 }
Jim Ingham6035b672011-03-31 00:19:25 +00003389 m_exe_scope = m_process_sp.get();
3390
3391 // Something has changed, so we will return true. Now make sure the thread & frame still exist, and if either
3392 // doesn't, mark ourselves as invalid.
3393
3394 if (m_thread_id != LLDB_INVALID_THREAD_ID)
3395 {
3396 Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get();
3397 if (our_thread == NULL)
Greg Clayton262f80d2011-07-06 16:49:27 +00003398 {
Jim Ingham89b61092011-07-06 17:42:14 +00003399 SetInvalid();
Greg Clayton262f80d2011-07-06 16:49:27 +00003400 }
Jim Ingham6035b672011-03-31 00:19:25 +00003401 else
3402 {
3403 m_exe_scope = our_thread;
3404
3405 if (m_stack_id.IsValid())
3406 {
3407 StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get();
3408 if (our_frame == NULL)
3409 SetInvalid();
3410 else
3411 m_exe_scope = our_frame;
3412 }
3413 }
3414 }
3415 return true;
3416}
3417
Jim Ingham61be0902011-05-02 18:13:59 +00003418void
3419ValueObject::EvaluationPoint::SetUpdated ()
3420{
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003421 // this will update the execution context scope and the m_mod_id
3422 SyncWithProcessState();
Jim Ingham61be0902011-05-02 18:13:59 +00003423 m_first_update = false;
3424 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003425}
3426
3427
Jim Ingham6035b672011-03-31 00:19:25 +00003428bool
3429ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3430{
3431 if (!IsValid())
3432 return false;
3433
3434 bool needs_update = false;
3435 m_exe_scope = NULL;
3436
3437 // The target has to be non-null, and the
3438 Target *target = exe_scope->CalculateTarget();
3439 if (target != NULL)
3440 {
3441 Target *old_target = m_target_sp.get();
3442 assert (target == old_target);
3443 Process *process = exe_scope->CalculateProcess();
3444 if (process != NULL)
3445 {
3446 // FOR NOW - assume you can't update variable objects across process boundaries.
3447 Process *old_process = m_process_sp.get();
3448 assert (process == old_process);
Jim Ingham4b536182011-08-09 02:12:22 +00003449 ProcessModID current_mod_id = process->GetModID();
3450 if (m_mod_id != current_mod_id)
Jim Ingham6035b672011-03-31 00:19:25 +00003451 {
3452 needs_update = true;
Jim Ingham4b536182011-08-09 02:12:22 +00003453 m_mod_id = current_mod_id;
Jim Ingham6035b672011-03-31 00:19:25 +00003454 }
3455 // See if we're switching the thread or stack context. If no thread is given, this is
3456 // being evaluated in a global context.
3457 Thread *thread = exe_scope->CalculateThread();
3458 if (thread != NULL)
3459 {
3460 lldb::user_id_t new_thread_index = thread->GetIndexID();
3461 if (new_thread_index != m_thread_id)
3462 {
3463 needs_update = true;
3464 m_thread_id = new_thread_index;
3465 m_stack_id.Clear();
3466 }
3467
3468 StackFrame *new_frame = exe_scope->CalculateStackFrame();
3469 if (new_frame != NULL)
3470 {
3471 if (new_frame->GetStackID() != m_stack_id)
3472 {
3473 needs_update = true;
3474 m_stack_id = new_frame->GetStackID();
3475 }
3476 }
3477 else
3478 {
3479 m_stack_id.Clear();
3480 needs_update = true;
3481 }
3482 }
3483 else
3484 {
3485 // If this had been given a thread, and now there is none, we should update.
3486 // Otherwise we don't have to do anything.
3487 if (m_thread_id != LLDB_INVALID_UID)
3488 {
3489 m_thread_id = LLDB_INVALID_UID;
3490 m_stack_id.Clear();
3491 needs_update = true;
3492 }
3493 }
3494 }
3495 else
3496 {
3497 // If there is no process, then we don't need to update anything.
3498 // But if we're switching from having a process to not, we should try to update.
3499 if (m_process_sp.get() != NULL)
3500 {
3501 needs_update = true;
3502 m_process_sp.reset();
3503 m_thread_id = LLDB_INVALID_UID;
3504 m_stack_id.Clear();
3505 }
3506 }
3507 }
3508 else
3509 {
3510 // If there's no target, nothing can change so we don't need to update anything.
3511 // But if we're switching from having a target to not, we should try to update.
3512 if (m_target_sp.get() != NULL)
3513 {
3514 needs_update = true;
3515 m_target_sp.reset();
3516 m_process_sp.reset();
3517 m_thread_id = LLDB_INVALID_UID;
3518 m_stack_id.Clear();
3519 }
3520 }
3521 if (!m_needs_update)
3522 m_needs_update = needs_update;
3523
3524 return needs_update;
3525}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003526
3527void
3528ValueObject::ClearUserVisibleData()
3529{
3530 m_location_str.clear();
3531 m_value_str.clear();
3532 m_summary_str.clear();
3533 m_object_desc_str.clear();
Johnny Chen44805302011-07-19 19:48:13 +00003534}