blob: 2ab5ac4cbcf1705a0af33ee7fe4ad4af6dd9ceb2 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/ValueObject.h"
11
12// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000013#include <stdlib.h>
14
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015// C++ Includes
16// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000018#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
20// Project includes
21#include "lldb/Core/DataBufferHeap.h"
Enrico Granata0a976142011-08-22 22:03:47 +000022#include "lldb/Core/DataVisualization.h"
Enrico Granata4becb372011-06-29 22:27:15 +000023#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000024#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/StreamString.h"
26#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000027#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000028#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000030#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000031#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Greg Clayton7fb56d02011-02-01 01:31:41 +000033#include "lldb/Host/Endian.h"
34
Enrico Granata61a80ba2011-08-12 16:42:31 +000035#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000036#include "lldb/Interpreter/ScriptInterpreterPython.h"
37
Greg Claytone1a916a2010-07-21 22:12:05 +000038#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Symbol/ClangASTContext.h"
40#include "lldb/Symbol/Type.h"
41
Jim Ingham53c47f12010-09-10 23:12:17 +000042#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000043#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000044#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045#include "lldb/Target/Process.h"
46#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000047#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049
Enrico Granataf4efecd2011-07-12 22:56:10 +000050#include "lldb/Utility/RefCounter.h"
51
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052using namespace lldb;
53using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000054using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055
Greg Claytonafacd142011-09-02 01:15:17 +000056static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057
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),
Greg Claytonafacd142011-09-02 01:15:17 +0000128 m_last_format_mgr_dynamic(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
Greg Claytonafacd142011-09-02 01:15:17 +0000165ValueObject::UpdateValueIfNeeded (DynamicValueType use_dynamic, bool update_format)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000166{
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
Greg Claytonafacd142011-09-02 01:15:17 +0000220ValueObject::UpdateFormatsIfNeeded(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
Greg Claytonafacd142011-09-02 01:15:17 +0000245 DataVisualization::ValueFormats::Get(*this, eNoDynamicValues, m_last_value_format);
Enrico Granatac482a192011-08-17 22:13:59 +0000246 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;
Greg Claytonafacd142011-09-02 01:15:17 +0000581 addr_t func_ptr_address = GetPointerValue (func_ptr_address_type, true);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000582
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;
Greg Claytonafacd142011-09-02 01:15:17 +0000644 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000645 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,
Greg Claytonafacd142011-09-02 01:15:17 +0000655 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 {
Greg Claytonafacd142011-09-02 01:15:17 +0000679 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000680 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);
Greg Claytonafacd142011-09-02 01:15:17 +0000714 data.SetData (&data_buffer.front(), data_buffer.size(), endian::InlHostByteOrder());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000715 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
Greg Claytonafacd142011-09-02 01:15:17 +0000824 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +0000825 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 {
Greg Claytonafacd142011-09-02 01:15:17 +0000837 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +0000838 }
Jim Inghama2cf2632010-12-23 02:29:54 +0000839 }
840 }
841
Jim Ingham8d543de2011-03-31 23:01:21 +0000842 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +0000843 {
844 m_object_desc_str.append (s.GetData());
845 }
Sean Callanan672ad942010-10-23 00:18:49 +0000846
847 if (m_object_desc_str.empty())
848 return NULL;
849 else
850 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +0000851}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000852
853const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000854ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000855{
856 // If our byte size is zero this is an aggregate type that has children
Greg Clayton1be10fc2010-09-29 01:12:09 +0000857 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858 {
Enrico Granatac3e320a2011-08-02 17:27:39 +0000859 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000860 {
861 if (m_value_str.empty())
862 {
863 const Value::ContextType context_type = m_value.GetContextType();
864
865 switch (context_type)
866 {
Greg Clayton526e5af2010-11-13 03:52:47 +0000867 case Value::eContextTypeClangType:
868 case Value::eContextTypeLLDBType:
869 case Value::eContextTypeVariable:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000870 {
Greg Clayton73b472d2010-10-27 03:32:59 +0000871 clang_type_t clang_type = GetClangType ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000872 if (clang_type)
873 {
Enrico Granatac3e320a2011-08-02 17:27:39 +0000874 if (m_format == lldb::eFormatDefault && m_last_value_format)
Enrico Granata4becb372011-06-29 22:27:15 +0000875 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000876 m_value_str = m_last_value_format->FormatObject(GetSP());
Enrico Granata4becb372011-06-29 22:27:15 +0000877 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000878 else
Greg Clayton007d5be2011-05-30 00:49:24 +0000879 {
Enrico Granataf2bbf712011-07-15 02:26:42 +0000880 StreamString sstr;
881 Format format = GetFormat();
882 if (format == eFormatDefault)
883 format = (m_is_bitfield_for_scalar ? eFormatUnsigned :
884 ClangASTType::GetFormat(clang_type));
885
886 if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
887 clang_type, // The clang type to display
888 &sstr,
889 format, // Format to display this type with
890 m_data, // Data to extract from
891 0, // Byte offset into "m_data"
892 GetByteSize(), // Byte size of item in "m_data"
893 GetBitfieldBitSize(), // Bitfield bit size
894 GetBitfieldBitOffset())) // Bitfield bit offset
895 m_value_str.swap(sstr.GetString());
896 else
897 {
898 m_error.SetErrorStringWithFormat ("unsufficient data for value (only %u of %u bytes available)",
899 m_data.GetByteSize(),
900 GetByteSize());
901 m_value_str.clear();
902 }
Greg Clayton007d5be2011-05-30 00:49:24 +0000903 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000904 }
905 }
906 break;
907
Greg Clayton526e5af2010-11-13 03:52:47 +0000908 case Value::eContextTypeRegisterInfo:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000909 {
910 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
911 if (reg_info)
912 {
913 StreamString reg_sstr;
914 m_data.Dump(&reg_sstr, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
915 m_value_str.swap(reg_sstr.GetString());
916 }
917 }
918 break;
Greg Claytonc982c762010-07-09 20:39:50 +0000919
920 default:
921 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000922 }
923 }
Greg Clayton288bdf92010-09-02 02:59:18 +0000924
925 if (!m_value_did_change && m_old_value_valid)
926 {
927 // The value was gotten successfully, so we consider the
928 // value as changed if the value string differs
929 SetValueDidChange (m_old_value_str != m_value_str);
930 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000931 }
932 }
933 if (m_value_str.empty())
934 return NULL;
935 return m_value_str.c_str();
936}
937
Enrico Granatac3e320a2011-08-02 17:27:39 +0000938// if > 8bytes, 0 is returned. this method should mostly be used
939// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000940uint64_t
941ValueObject::GetValueAsUnsigned (uint64_t fail_value)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000942{
943 // If our byte size is zero this is an aggregate type that has children
944 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
945 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000946 Scalar scalar;
947 if (ResolveValue (scalar))
948 return scalar.GetRawBits64(fail_value);
Enrico Granatac3e320a2011-08-02 17:27:39 +0000949 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000950 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +0000951}
952
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000953bool
954ValueObject::GetPrintableRepresentation(Stream& s,
955 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +0000956 Format custom_format)
Enrico Granata0a3958e2011-07-02 00:25:22 +0000957{
Enrico Granataf4efecd2011-07-12 22:56:10 +0000958
959 RefCounter ref(&m_dump_printable_counter);
960
Greg Claytonafacd142011-09-02 01:15:17 +0000961 if (custom_format != eFormatInvalid)
Enrico Granata0a3958e2011-07-02 00:25:22 +0000962 SetFormat(custom_format);
963
964 const char * return_value;
Enrico Granatacd1c0232011-08-04 23:37:18 +0000965 std::string alloc_mem;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000966
967 switch(val_obj_display)
968 {
969 case eDisplayValue:
970 return_value = GetValueAsCString();
971 break;
972 case eDisplaySummary:
973 return_value = GetSummaryAsCString();
974 break;
975 case eDisplayLanguageSpecific:
976 return_value = GetObjectDescription();
977 break;
Enrico Granataf2bbf712011-07-15 02:26:42 +0000978 case eDisplayLocation:
979 return_value = GetLocationAsCString();
980 break;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000981 case eDisplayChildrenCount:
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000982 {
Enrico Granatacd1c0232011-08-04 23:37:18 +0000983 alloc_mem.resize(512);
984 return_value = &alloc_mem[0];
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000985 int count = GetNumChildren();
Enrico Granatacd1c0232011-08-04 23:37:18 +0000986 snprintf((char*)return_value, 512, "%d", count);
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000987 break;
988 }
Enrico Granatad64d0bc2011-08-19 21:13:46 +0000989 case eDisplayType:
990 return_value = GetTypeName().AsCString();
991 break;
Enrico Granata5dfd49c2011-08-04 02:34:29 +0000992 default:
993 break;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000994 }
995
Enrico Granataf4efecd2011-07-12 22:56:10 +0000996 // this code snippet might lead to endless recursion, thus we use a RefCounter here to
997 // check that we are not looping endlessly
998 if (!return_value && (m_dump_printable_counter < 3))
Enrico Granata9fc19442011-07-06 02:13:41 +0000999 {
1000 // try to pick the other choice
1001 if (val_obj_display == eDisplayValue)
1002 return_value = GetSummaryAsCString();
1003 else if (val_obj_display == eDisplaySummary)
Enrico Granatae992a082011-07-22 17:03:19 +00001004 {
1005 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1006 {
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001007 // this thing has no value, and it seems to have no summary
1008 // some combination of unitialized data and other factors can also
1009 // raise this condition, so let's print a nice generic error message
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001010 {
1011 alloc_mem.resize(684);
1012 return_value = &alloc_mem[0];
1013 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1014 }
Enrico Granatae992a082011-07-22 17:03:19 +00001015 }
1016 else
1017 return_value = GetValueAsCString();
1018 }
Enrico Granata9fc19442011-07-06 02:13:41 +00001019 }
Enrico Granata0a3958e2011-07-02 00:25:22 +00001020
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001021 if (return_value)
1022 s.PutCString(return_value);
1023 else
Enrico Granata88da35f2011-08-23 21:26:09 +00001024 {
1025 if (m_error.Fail())
1026 s.Printf("<%s>", m_error.AsCString());
1027 else if (val_obj_display == eDisplaySummary)
1028 s.PutCString("<no summary available>");
1029 else if (val_obj_display == eDisplayValue)
1030 s.PutCString("<no value available>");
1031 else if (val_obj_display == eDisplayLanguageSpecific)
1032 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1033 else
1034 s.PutCString("<no printable representation>");
1035 }
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001036
1037 // we should only return false here if we could not do *anything*
1038 // even if we have an error message as output, that's a success
1039 // from our callers' perspective, so return true
1040 return true;
1041
Enrico Granata0a3958e2011-07-02 00:25:22 +00001042}
1043
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001044// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1045// this call up to date by returning true for your new special cases. We will eventually move
1046// to checking this call result before trying to display special cases
1047bool
1048ValueObject::HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001049 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001050{
1051 clang_type_t elem_or_pointee_type;
1052 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1053
1054 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1055 && val_obj_display == ValueObject::eDisplayValue)
1056 {
1057 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001058 (custom_format == eFormatCString ||
1059 custom_format == eFormatCharArray ||
1060 custom_format == eFormatChar ||
1061 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001062 return true;
1063
1064 if (flags.Test(ClangASTContext::eTypeIsArray))
1065 {
Greg Claytonafacd142011-09-02 01:15:17 +00001066 if ((custom_format == eFormatBytes) ||
1067 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001068 return true;
1069
Greg Claytonafacd142011-09-02 01:15:17 +00001070 if ((custom_format == eFormatVectorOfChar) ||
1071 (custom_format == eFormatVectorOfFloat32) ||
1072 (custom_format == eFormatVectorOfFloat64) ||
1073 (custom_format == eFormatVectorOfSInt16) ||
1074 (custom_format == eFormatVectorOfSInt32) ||
1075 (custom_format == eFormatVectorOfSInt64) ||
1076 (custom_format == eFormatVectorOfSInt8) ||
1077 (custom_format == eFormatVectorOfUInt128) ||
1078 (custom_format == eFormatVectorOfUInt16) ||
1079 (custom_format == eFormatVectorOfUInt32) ||
1080 (custom_format == eFormatVectorOfUInt64) ||
1081 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001082 return true;
1083 }
1084 }
1085 return false;
1086}
1087
Enrico Granata9fc19442011-07-06 02:13:41 +00001088bool
1089ValueObject::DumpPrintableRepresentation(Stream& s,
1090 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001091 Format custom_format,
Enrico Granata85933ed2011-08-18 16:38:26 +00001092 bool only_special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001093{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001094
1095 clang_type_t elem_or_pointee_type;
1096 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001097
Enrico Granataf4efecd2011-07-12 22:56:10 +00001098 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1099 && val_obj_display == ValueObject::eDisplayValue)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001100 {
Enrico Granataf4efecd2011-07-12 22:56:10 +00001101 // when being asked to get a printable display an array or pointer type directly,
1102 // try to "do the right thing"
1103
1104 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001105 (custom_format == eFormatCString ||
1106 custom_format == eFormatCharArray ||
1107 custom_format == eFormatChar ||
1108 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001109 {
1110 Error error;
1111 ReadPointedString(s,
1112 error,
1113 0,
Greg Claytonafacd142011-09-02 01:15:17 +00001114 (custom_format == eFormatVectorOfChar) ||
1115 (custom_format == eFormatCharArray));
Enrico Granataf4efecd2011-07-12 22:56:10 +00001116 return !error.Fail();
1117 }
1118
Greg Claytonafacd142011-09-02 01:15:17 +00001119 if (custom_format == eFormatEnum)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001120 return false;
1121
1122 // this only works for arrays, because I have no way to know when
1123 // the pointed memory ends, and no special \0 end of data marker
1124 if (flags.Test(ClangASTContext::eTypeIsArray))
1125 {
Greg Claytonafacd142011-09-02 01:15:17 +00001126 if ((custom_format == eFormatBytes) ||
1127 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001128 {
1129 uint32_t count = GetNumChildren();
1130
1131 s << '[';
1132 for (uint32_t low = 0; low < count; low++)
1133 {
1134
1135 if (low)
1136 s << ',';
1137
1138 ValueObjectSP child = GetChildAtIndex(low,true);
1139 if (!child.get())
1140 {
Enrico Granatae992a082011-07-22 17:03:19 +00001141 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001142 continue;
1143 }
1144 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format);
1145 }
1146
1147 s << ']';
1148
1149 return true;
1150 }
1151
Greg Claytonafacd142011-09-02 01:15:17 +00001152 if ((custom_format == eFormatVectorOfChar) ||
1153 (custom_format == eFormatVectorOfFloat32) ||
1154 (custom_format == eFormatVectorOfFloat64) ||
1155 (custom_format == eFormatVectorOfSInt16) ||
1156 (custom_format == eFormatVectorOfSInt32) ||
1157 (custom_format == eFormatVectorOfSInt64) ||
1158 (custom_format == eFormatVectorOfSInt8) ||
1159 (custom_format == eFormatVectorOfUInt128) ||
1160 (custom_format == eFormatVectorOfUInt16) ||
1161 (custom_format == eFormatVectorOfUInt32) ||
1162 (custom_format == eFormatVectorOfUInt64) ||
1163 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001164 {
1165 uint32_t count = GetNumChildren();
1166
Greg Claytonafacd142011-09-02 01:15:17 +00001167 Format format = FormatManager::GetSingleItemFormat(custom_format);
Enrico Granataf4efecd2011-07-12 22:56:10 +00001168
1169 s << '[';
1170 for (uint32_t low = 0; low < count; low++)
1171 {
1172
1173 if (low)
1174 s << ',';
1175
1176 ValueObjectSP child = GetChildAtIndex(low,true);
1177 if (!child.get())
1178 {
Enrico Granatae992a082011-07-22 17:03:19 +00001179 s << "<invalid child>";
Enrico Granataf4efecd2011-07-12 22:56:10 +00001180 continue;
1181 }
1182 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format);
1183 }
1184
1185 s << ']';
1186
1187 return true;
1188 }
1189 }
1190
Greg Claytonafacd142011-09-02 01:15:17 +00001191 if ((custom_format == eFormatBoolean) ||
1192 (custom_format == eFormatBinary) ||
1193 (custom_format == eFormatChar) ||
1194 (custom_format == eFormatCharPrintable) ||
1195 (custom_format == eFormatComplexFloat) ||
1196 (custom_format == eFormatDecimal) ||
1197 (custom_format == eFormatHex) ||
1198 (custom_format == eFormatFloat) ||
1199 (custom_format == eFormatOctal) ||
1200 (custom_format == eFormatOSType) ||
1201 (custom_format == eFormatUnicode16) ||
1202 (custom_format == eFormatUnicode32) ||
1203 (custom_format == eFormatUnsigned) ||
1204 (custom_format == eFormatPointer) ||
1205 (custom_format == eFormatComplexInteger) ||
1206 (custom_format == eFormatComplex) ||
1207 (custom_format == eFormatDefault)) // use the [] operator
Enrico Granataf4efecd2011-07-12 22:56:10 +00001208 return false;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001209 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001210
1211 if (only_special)
1212 return false;
1213
Enrico Granata5dfd49c2011-08-04 02:34:29 +00001214 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format);
Enrico Granata9dd75c82011-07-15 23:30:15 +00001215 if (custom_format != eFormatInvalid)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001216 SetFormat(eFormatDefault);
1217 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001218}
1219
Greg Clayton737b9322010-09-13 03:32:57 +00001220addr_t
Greg Claytone0d378b2011-03-24 21:19:54 +00001221ValueObject::GetAddressOf (AddressType &address_type, bool scalar_is_load_address)
Greg Clayton73b472d2010-10-27 03:32:59 +00001222{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001223 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001224 return LLDB_INVALID_ADDRESS;
1225
Greg Clayton73b472d2010-10-27 03:32:59 +00001226 switch (m_value.GetValueType())
1227 {
1228 case Value::eValueTypeScalar:
1229 if (scalar_is_load_address)
1230 {
1231 address_type = eAddressTypeLoad;
1232 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1233 }
1234 break;
1235
1236 case Value::eValueTypeLoadAddress:
1237 case Value::eValueTypeFileAddress:
1238 case Value::eValueTypeHostAddress:
1239 {
1240 address_type = m_value.GetValueAddressType ();
1241 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1242 }
1243 break;
1244 }
1245 address_type = eAddressTypeInvalid;
1246 return LLDB_INVALID_ADDRESS;
1247}
1248
1249addr_t
Greg Claytone0d378b2011-03-24 21:19:54 +00001250ValueObject::GetPointerValue (AddressType &address_type, bool scalar_is_load_address)
Greg Clayton737b9322010-09-13 03:32:57 +00001251{
Greg Claytonafacd142011-09-02 01:15:17 +00001252 addr_t address = LLDB_INVALID_ADDRESS;
Greg Clayton737b9322010-09-13 03:32:57 +00001253 address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001254
Enrico Granatac3e320a2011-08-02 17:27:39 +00001255 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001256 return address;
1257
Greg Clayton73b472d2010-10-27 03:32:59 +00001258 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001259 {
1260 case Value::eValueTypeScalar:
1261 if (scalar_is_load_address)
1262 {
1263 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1264 address_type = eAddressTypeLoad;
1265 }
1266 break;
1267
1268 case Value::eValueTypeLoadAddress:
1269 case Value::eValueTypeFileAddress:
1270 case Value::eValueTypeHostAddress:
1271 {
1272 uint32_t data_offset = 0;
1273 address = m_data.GetPointer(&data_offset);
1274 address_type = m_value.GetValueAddressType();
1275 if (address_type == eAddressTypeInvalid)
1276 address_type = eAddressTypeLoad;
1277 }
1278 break;
1279 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001280
1281 if (m_pointers_point_to_load_addrs)
1282 address_type = eAddressTypeLoad;
1283
Greg Clayton737b9322010-09-13 03:32:57 +00001284 return address;
1285}
1286
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001287bool
Jim Ingham6035b672011-03-31 00:19:25 +00001288ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001289{
1290 // Make sure our value is up to date first so that our location and location
1291 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001292 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001293 return false;
1294
1295 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001296 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001297
Greg Claytonb1320972010-07-14 00:18:15 +00001298 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001299
Jim Ingham16e0c682011-08-12 23:34:31 +00001300 Value::ValueType value_type = m_value.GetValueType();
1301
1302 if (value_type == Value::eValueTypeScalar)
1303 {
1304 // If the value is already a scalar, then let the scalar change itself:
1305 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1306 }
1307 else if (byte_size <= Scalar::GetMaxByteSize())
1308 {
1309 // If the value fits in a scalar, then make a new scalar and again let the
1310 // scalar code do the conversion, then figure out where to put the new value.
1311 Scalar new_scalar;
1312 Error error;
1313 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1314 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001315 {
Jim Ingham4b536182011-08-09 02:12:22 +00001316 switch (value_type)
1317 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001318 case Value::eValueTypeLoadAddress:
1319 {
1320 // If it is a load address, then the scalar value is the storage location
1321 // of the data, and we have to shove this value down to that load location.
1322 ProcessSP process_sp = GetUpdatePoint().GetProcessSP();
1323 if (process_sp)
1324 {
Greg Claytonafacd142011-09-02 01:15:17 +00001325 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Jim Ingham16e0c682011-08-12 23:34:31 +00001326 size_t bytes_written = process_sp->WriteScalarToMemory (target_addr,
1327 new_scalar,
1328 byte_size,
1329 error);
1330 if (!error.Success() || bytes_written != byte_size)
1331 return false;
1332 }
1333 }
Jim Ingham4b536182011-08-09 02:12:22 +00001334 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001335 case Value::eValueTypeHostAddress:
1336 {
1337 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1338 DataExtractor new_data;
1339 new_data.SetByteOrder (m_data.GetByteOrder());
1340
1341 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1342 m_data.SetData(buffer_sp, 0);
1343 bool success = new_scalar.GetData(new_data);
1344 if (success)
1345 {
1346 new_data.CopyByteOrderedData(0,
1347 byte_size,
1348 const_cast<uint8_t *>(m_data.GetDataStart()),
1349 byte_size,
1350 m_data.GetByteOrder());
1351 }
1352 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1353
1354 }
Jim Ingham4b536182011-08-09 02:12:22 +00001355 break;
Jim Ingham16e0c682011-08-12 23:34:31 +00001356 case Value::eValueTypeFileAddress:
1357 case Value::eValueTypeScalar:
1358 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001359 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001360 }
1361 else
1362 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001363 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001364 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001365 }
1366 else
1367 {
1368 // We don't support setting things bigger than a scalar at present.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001369 return false;
1370 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001371
1372 // If we have reached this point, then we have successfully changed the value.
1373 SetNeedsUpdate();
1374 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001375}
1376
Greg Claytonafacd142011-09-02 01:15:17 +00001377LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001378ValueObject::GetObjectRuntimeLanguage ()
1379{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001380 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1381 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001382}
1383
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001384void
Jim Ingham58b59f92011-04-22 23:53:53 +00001385ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001386{
Jim Ingham58b59f92011-04-22 23:53:53 +00001387 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001388}
1389
1390ValueObjectSP
1391ValueObject::GetSyntheticChild (const ConstString &key) const
1392{
1393 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001394 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001395 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001396 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001397 return synthetic_child_sp;
1398}
1399
1400bool
1401ValueObject::IsPointerType ()
1402{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001403 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001404}
1405
Jim Inghamb7603bb2011-03-18 00:05:18 +00001406bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001407ValueObject::IsArrayType ()
1408{
1409 return ClangASTContext::IsArrayType (GetClangType());
1410}
1411
1412bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001413ValueObject::IsScalarType ()
1414{
1415 return ClangASTContext::IsScalarType (GetClangType());
1416}
1417
1418bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001419ValueObject::IsIntegerType (bool &is_signed)
1420{
1421 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1422}
Greg Clayton73b472d2010-10-27 03:32:59 +00001423
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001424bool
1425ValueObject::IsPointerOrReferenceType ()
1426{
Greg Clayton007d5be2011-05-30 00:49:24 +00001427 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1428}
1429
1430bool
1431ValueObject::IsPossibleCPlusPlusDynamicType ()
1432{
1433 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001434}
1435
Greg Claytondea8cb42011-06-29 22:09:02 +00001436bool
1437ValueObject::IsPossibleDynamicType ()
1438{
1439 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1440}
1441
Greg Claytonafacd142011-09-02 01:15:17 +00001442ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001443ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1444{
1445 if (IsArrayType())
1446 return GetSyntheticArrayMemberFromArray(index, can_create);
1447
1448 if (IsPointerType())
1449 return GetSyntheticArrayMemberFromPointer(index, can_create);
1450
1451 return ValueObjectSP();
1452
1453}
1454
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001455ValueObjectSP
1456ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1457{
1458 ValueObjectSP synthetic_child_sp;
1459 if (IsPointerType ())
1460 {
1461 char index_str[64];
1462 snprintf(index_str, sizeof(index_str), "[%i]", index);
1463 ConstString index_const_str(index_str);
1464 // Check if we have already created a synthetic array member in this
1465 // valid object. If we have we will re-use it.
1466 synthetic_child_sp = GetSyntheticChild (index_const_str);
1467 if (!synthetic_child_sp)
1468 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001469 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001470 // We haven't made a synthetic array member for INDEX yet, so
1471 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001472 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001473
1474 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001475 if (synthetic_child)
1476 {
1477 AddSyntheticChild(index_const_str, synthetic_child);
1478 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001479 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001480 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001481 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001482 }
1483 }
1484 return synthetic_child_sp;
1485}
Jim Ingham22777012010-09-23 02:01:19 +00001486
Greg Claytondaf515f2011-07-09 20:12:33 +00001487// This allows you to create an array member using and index
1488// that doesn't not fall in the normal bounds of the array.
1489// Many times structure can be defined as:
1490// struct Collection
1491// {
1492// uint32_t item_count;
1493// Item item_array[0];
1494// };
1495// The size of the "item_array" is 1, but many times in practice
1496// there are more items in "item_array".
1497
1498ValueObjectSP
1499ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1500{
1501 ValueObjectSP synthetic_child_sp;
1502 if (IsArrayType ())
1503 {
1504 char index_str[64];
1505 snprintf(index_str, sizeof(index_str), "[%i]", index);
1506 ConstString index_const_str(index_str);
1507 // Check if we have already created a synthetic array member in this
1508 // valid object. If we have we will re-use it.
1509 synthetic_child_sp = GetSyntheticChild (index_const_str);
1510 if (!synthetic_child_sp)
1511 {
1512 ValueObject *synthetic_child;
1513 // We haven't made a synthetic array member for INDEX yet, so
1514 // lets make one and cache it for any future reference.
1515 synthetic_child = CreateChildAtIndex(0, true, index);
1516
1517 // Cache the value if we got one back...
1518 if (synthetic_child)
1519 {
1520 AddSyntheticChild(index_const_str, synthetic_child);
1521 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001522 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001523 synthetic_child_sp->m_is_array_item_for_pointer = true;
1524 }
1525 }
1526 }
1527 return synthetic_child_sp;
1528}
1529
Enrico Granata9fc19442011-07-06 02:13:41 +00001530ValueObjectSP
1531ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1532{
1533 ValueObjectSP synthetic_child_sp;
1534 if (IsScalarType ())
1535 {
1536 char index_str[64];
1537 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1538 ConstString index_const_str(index_str);
1539 // Check if we have already created a synthetic array member in this
1540 // valid object. If we have we will re-use it.
1541 synthetic_child_sp = GetSyntheticChild (index_const_str);
1542 if (!synthetic_child_sp)
1543 {
1544 ValueObjectChild *synthetic_child;
1545 // We haven't made a synthetic array member for INDEX yet, so
1546 // lets make one and cache it for any future reference.
1547 synthetic_child = new ValueObjectChild(*this,
1548 GetClangAST(),
1549 GetClangType(),
1550 index_const_str,
1551 GetByteSize(),
1552 0,
1553 to-from+1,
1554 from,
1555 false,
1556 false);
1557
1558 // Cache the value if we got one back...
1559 if (synthetic_child)
1560 {
1561 AddSyntheticChild(index_const_str, synthetic_child);
1562 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001563 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001564 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1565 }
1566 }
1567 }
1568 return synthetic_child_sp;
1569}
1570
Greg Claytonafacd142011-09-02 01:15:17 +00001571ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001572ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1573{
1574 ValueObjectSP synthetic_child_sp;
1575 if (IsArrayType () || IsPointerType ())
1576 {
1577 char index_str[64];
1578 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1579 ConstString index_const_str(index_str);
1580 // Check if we have already created a synthetic array member in this
1581 // valid object. If we have we will re-use it.
1582 synthetic_child_sp = GetSyntheticChild (index_const_str);
1583 if (!synthetic_child_sp)
1584 {
1585 ValueObjectSynthetic *synthetic_child;
1586
1587 // We haven't made a synthetic array member for INDEX yet, so
1588 // lets make one and cache it for any future reference.
1589 SyntheticArrayView *view = new SyntheticArrayView();
1590 view->AddRange(from,to);
1591 SyntheticChildrenSP view_sp(view);
1592 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1593
1594 // Cache the value if we got one back...
1595 if (synthetic_child)
1596 {
1597 AddSyntheticChild(index_const_str, synthetic_child);
1598 synthetic_child_sp = synthetic_child->GetSP();
1599 synthetic_child_sp->SetName(ConstString(index_str));
1600 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1601 }
1602 }
1603 }
1604 return synthetic_child_sp;
1605}
1606
Greg Claytonafacd142011-09-02 01:15:17 +00001607ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001608ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1609{
1610
1611 ValueObjectSP synthetic_child_sp;
1612
1613 char name_str[64];
1614 snprintf(name_str, sizeof(name_str), "@%i", offset);
1615 ConstString name_const_str(name_str);
1616
1617 // Check if we have already created a synthetic array member in this
1618 // valid object. If we have we will re-use it.
1619 synthetic_child_sp = GetSyntheticChild (name_const_str);
1620
1621 if (synthetic_child_sp.get())
1622 return synthetic_child_sp;
1623
1624 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001625 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001626
1627 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1628 type.GetASTContext(),
1629 type.GetOpaqueQualType(),
1630 name_const_str,
1631 type.GetTypeByteSize(),
1632 offset,
1633 0,
1634 0,
1635 false,
1636 false);
1637 if (synthetic_child)
1638 {
1639 AddSyntheticChild(name_const_str, synthetic_child);
1640 synthetic_child_sp = synthetic_child->GetSP();
1641 synthetic_child_sp->SetName(name_const_str);
1642 synthetic_child_sp->m_is_child_at_offset = true;
1643 }
1644 return synthetic_child_sp;
1645}
1646
Enrico Granatad55546b2011-07-22 00:16:08 +00001647// your expression path needs to have a leading . or ->
1648// (unless it somehow "looks like" an array, in which case it has
1649// a leading [ symbol). while the [ is meaningful and should be shown
1650// to the user, . and -> are just parser design, but by no means
1651// added information for the user.. strip them off
1652static const char*
1653SkipLeadingExpressionPathSeparators(const char* expression)
1654{
1655 if (!expression || !expression[0])
1656 return expression;
1657 if (expression[0] == '.')
1658 return expression+1;
1659 if (expression[0] == '-' && expression[1] == '>')
1660 return expression+2;
1661 return expression;
1662}
1663
Greg Claytonafacd142011-09-02 01:15:17 +00001664ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00001665ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1666{
1667 ValueObjectSP synthetic_child_sp;
1668 ConstString name_const_string(expression);
1669 // Check if we have already created a synthetic array member in this
1670 // valid object. If we have we will re-use it.
1671 synthetic_child_sp = GetSyntheticChild (name_const_string);
1672 if (!synthetic_child_sp)
1673 {
1674 // We haven't made a synthetic array member for expression yet, so
1675 // lets make one and cache it for any future reference.
1676 synthetic_child_sp = GetValueForExpressionPath(expression);
1677
1678 // Cache the value if we got one back...
1679 if (synthetic_child_sp.get())
1680 {
1681 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001682 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00001683 synthetic_child_sp->m_is_expression_path_child = true;
1684 }
1685 }
1686 return synthetic_child_sp;
1687}
1688
1689void
Greg Claytonafacd142011-09-02 01:15:17 +00001690ValueObject::CalculateSyntheticValue (SyntheticValueType use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00001691{
Greg Claytonafacd142011-09-02 01:15:17 +00001692 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001693 return;
1694
Enrico Granatac3e320a2011-08-02 17:27:39 +00001695 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001696
1697 if (m_last_synthetic_filter.get() == NULL)
1698 return;
1699
Enrico Granataa37a0652011-07-24 00:14:56 +00001700 if (m_synthetic_value == NULL)
1701 m_synthetic_value = new ValueObjectSynthetic(*this, m_last_synthetic_filter);
Enrico Granatad55546b2011-07-22 00:16:08 +00001702
1703}
1704
Jim Ingham78a685a2011-04-16 00:01:13 +00001705void
Greg Claytonafacd142011-09-02 01:15:17 +00001706ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00001707{
Greg Claytonafacd142011-09-02 01:15:17 +00001708 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00001709 return;
1710
Jim Ingham58b59f92011-04-22 23:53:53 +00001711 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00001712 {
Enrico Granata6f3533f2011-07-29 19:53:35 +00001713 Process *process = m_update_point.GetProcessSP().get();
Jim Ingham78a685a2011-04-16 00:01:13 +00001714 bool worth_having_dynamic_value = false;
Jim Ingham22777012010-09-23 02:01:19 +00001715
Jim Ingham78a685a2011-04-16 00:01:13 +00001716
1717 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
1718 // hard code this everywhere.
Greg Claytonafacd142011-09-02 01:15:17 +00001719 LanguageType known_type = GetObjectRuntimeLanguage();
1720 if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
Jim Ingham78a685a2011-04-16 00:01:13 +00001721 {
1722 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
1723 if (runtime)
1724 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
1725 }
1726 else
1727 {
Greg Claytonafacd142011-09-02 01:15:17 +00001728 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus);
Jim Ingham78a685a2011-04-16 00:01:13 +00001729 if (cpp_runtime)
1730 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
1731
1732 if (!worth_having_dynamic_value)
1733 {
Greg Claytonafacd142011-09-02 01:15:17 +00001734 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC);
Jim Ingham78a685a2011-04-16 00:01:13 +00001735 if (objc_runtime)
Jim Ingham2837b762011-05-04 03:43:18 +00001736 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00001737 }
1738 }
1739
1740 if (worth_having_dynamic_value)
Jim Ingham2837b762011-05-04 03:43:18 +00001741 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham58b59f92011-04-22 23:53:53 +00001742
1743// if (worth_having_dynamic_value)
1744// printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager);
1745
Jim Ingham78a685a2011-04-16 00:01:13 +00001746 }
1747}
1748
Jim Ingham58b59f92011-04-22 23:53:53 +00001749ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00001750ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00001751{
Greg Claytonafacd142011-09-02 01:15:17 +00001752 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00001753 return ValueObjectSP();
1754
1755 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00001756 {
Jim Ingham2837b762011-05-04 03:43:18 +00001757 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001758 }
Jim Ingham58b59f92011-04-22 23:53:53 +00001759 if (m_dynamic_value)
1760 return m_dynamic_value->GetSP();
1761 else
1762 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00001763}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001764
Enrico Granatad55546b2011-07-22 00:16:08 +00001765// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic
1766// or we do not really want a dynamic VO. this method instead returns this object
1767// itself when making it synthetic has no meaning. this makes it much simpler
1768// to replace the SyntheticValue for the ValueObject
1769ValueObjectSP
1770ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic)
1771{
Greg Claytonafacd142011-09-02 01:15:17 +00001772 if (use_synthetic == eNoSyntheticFilter)
Enrico Granatad55546b2011-07-22 00:16:08 +00001773 return GetSP();
1774
Enrico Granatac3e320a2011-08-02 17:27:39 +00001775 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
Enrico Granatad55546b2011-07-22 00:16:08 +00001776
1777 if (m_last_synthetic_filter.get() == NULL)
1778 return GetSP();
1779
1780 CalculateSyntheticValue(use_synthetic);
1781
1782 if (m_synthetic_value)
1783 return m_synthetic_value->GetSP();
1784 else
1785 return GetSP();
1786}
1787
Greg Claytone221f822011-01-21 01:59:00 +00001788bool
Enrico Granata27b625e2011-08-09 01:04:56 +00001789ValueObject::HasSyntheticValue()
1790{
1791 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
1792
1793 if (m_last_synthetic_filter.get() == NULL)
1794 return false;
1795
Greg Claytonafacd142011-09-02 01:15:17 +00001796 CalculateSyntheticValue(eUseSyntheticFilter);
Enrico Granata27b625e2011-08-09 01:04:56 +00001797
1798 if (m_synthetic_value)
1799 return true;
1800 else
1801 return false;
1802}
1803
1804bool
Greg Claytone221f822011-01-21 01:59:00 +00001805ValueObject::GetBaseClassPath (Stream &s)
1806{
1807 if (IsBaseClass())
1808 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001809 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00001810 clang_type_t clang_type = GetClangType();
1811 std::string cxx_class_name;
1812 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
1813 if (this_had_base_class)
1814 {
1815 if (parent_had_base_class)
1816 s.PutCString("::");
1817 s.PutCString(cxx_class_name.c_str());
1818 }
1819 return parent_had_base_class || this_had_base_class;
1820 }
1821 return false;
1822}
1823
1824
1825ValueObject *
1826ValueObject::GetNonBaseClassParent()
1827{
Jim Ingham78a685a2011-04-16 00:01:13 +00001828 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00001829 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001830 if (GetParent()->IsBaseClass())
1831 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00001832 else
Jim Ingham78a685a2011-04-16 00:01:13 +00001833 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00001834 }
1835 return NULL;
1836}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001837
1838void
Enrico Granata4becb372011-06-29 22:27:15 +00001839ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001840{
Greg Claytone221f822011-01-21 01:59:00 +00001841 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00001842
Enrico Granata85933ed2011-08-18 16:38:26 +00001843 if (is_deref_of_parent && epformat == eDereferencePointers)
1844 {
Enrico Granata4becb372011-06-29 22:27:15 +00001845 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
1846 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
1847 // the eHonorPointers mode is meant to produce strings in this latter format
1848 s.PutCString("*(");
1849 }
Greg Claytone221f822011-01-21 01:59:00 +00001850
Enrico Granata4becb372011-06-29 22:27:15 +00001851 ValueObject* parent = GetParent();
1852
1853 if (parent)
1854 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00001855
1856 // if we are a deref_of_parent just because we are synthetic array
1857 // members made up to allow ptr[%d] syntax to work in variable
1858 // printing, then add our name ([%d]) to the expression path
Enrico Granata9dd75c82011-07-15 23:30:15 +00001859 if (m_is_array_item_for_pointer && epformat == eHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00001860 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00001861
Greg Claytone221f822011-01-21 01:59:00 +00001862 if (!IsBaseClass())
1863 {
1864 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001865 {
Greg Claytone221f822011-01-21 01:59:00 +00001866 ValueObject *non_base_class_parent = GetNonBaseClassParent();
1867 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001868 {
Greg Claytone221f822011-01-21 01:59:00 +00001869 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
1870 if (non_base_class_parent_clang_type)
1871 {
1872 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
1873
Enrico Granata9dd75c82011-07-15 23:30:15 +00001874 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00001875 {
1876 s.PutCString("->");
1877 }
Enrico Granata4becb372011-06-29 22:27:15 +00001878 else
1879 {
1880 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
1881 {
1882 s.PutCString("->");
1883 }
1884 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
1885 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
1886 {
1887 s.PutChar('.');
1888 }
Greg Claytone221f822011-01-21 01:59:00 +00001889 }
1890 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001891 }
Greg Claytone221f822011-01-21 01:59:00 +00001892
1893 const char *name = GetName().GetCString();
1894 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001895 {
Greg Claytone221f822011-01-21 01:59:00 +00001896 if (qualify_cxx_base_classes)
1897 {
1898 if (GetBaseClassPath (s))
1899 s.PutCString("::");
1900 }
1901 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001902 }
1903 }
1904 }
1905
Enrico Granata85933ed2011-08-18 16:38:26 +00001906 if (is_deref_of_parent && epformat == eDereferencePointers)
1907 {
Greg Claytone221f822011-01-21 01:59:00 +00001908 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00001909 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001910}
1911
Greg Claytonafacd142011-09-02 01:15:17 +00001912ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00001913ValueObject::GetValueForExpressionPath(const char* expression,
1914 const char** first_unparsed,
1915 ExpressionPathScanEndReason* reason_to_stop,
1916 ExpressionPathEndResultType* final_value_type,
1917 const GetValueForExpressionPathOptions& options,
1918 ExpressionPathAftermath* final_task_on_target)
1919{
1920
1921 const char* dummy_first_unparsed;
1922 ExpressionPathScanEndReason dummy_reason_to_stop;
1923 ExpressionPathEndResultType dummy_final_value_type;
1924 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
1925
1926 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
1927 first_unparsed ? first_unparsed : &dummy_first_unparsed,
1928 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
1929 final_value_type ? final_value_type : &dummy_final_value_type,
1930 options,
1931 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
1932
1933 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
1934 {
1935 return ret_val;
1936 }
1937 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
1938 {
1939 if (*final_task_on_target == ValueObject::eDereference)
1940 {
1941 Error error;
1942 ValueObjectSP final_value = ret_val->Dereference(error);
1943 if (error.Fail() || !final_value.get())
1944 {
1945 *reason_to_stop = ValueObject::eDereferencingFailed;
1946 *final_value_type = ValueObject::eInvalid;
1947 return ValueObjectSP();
1948 }
1949 else
1950 {
1951 *final_task_on_target = ValueObject::eNothing;
1952 return final_value;
1953 }
1954 }
1955 if (*final_task_on_target == ValueObject::eTakeAddress)
1956 {
1957 Error error;
1958 ValueObjectSP final_value = ret_val->AddressOf(error);
1959 if (error.Fail() || !final_value.get())
1960 {
1961 *reason_to_stop = ValueObject::eTakingAddressFailed;
1962 *final_value_type = ValueObject::eInvalid;
1963 return ValueObjectSP();
1964 }
1965 else
1966 {
1967 *final_task_on_target = ValueObject::eNothing;
1968 return final_value;
1969 }
1970 }
1971 }
1972 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
1973}
1974
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001975int
1976ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00001977 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001978 const char** first_unparsed,
1979 ExpressionPathScanEndReason* reason_to_stop,
1980 ExpressionPathEndResultType* final_value_type,
1981 const GetValueForExpressionPathOptions& options,
1982 ExpressionPathAftermath* final_task_on_target)
1983{
1984 const char* dummy_first_unparsed;
1985 ExpressionPathScanEndReason dummy_reason_to_stop;
1986 ExpressionPathEndResultType dummy_final_value_type;
1987 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing;
1988
1989 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
1990 first_unparsed ? first_unparsed : &dummy_first_unparsed,
1991 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
1992 final_value_type ? final_value_type : &dummy_final_value_type,
1993 options,
1994 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
1995
1996 if (!ret_val.get()) // if there are errors, I add nothing to the list
1997 return 0;
1998
1999 if (*reason_to_stop != eArrayRangeOperatorMet)
2000 {
2001 // I need not expand a range, just post-process the final value and return
2002 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing)
2003 {
2004 list->Append(ret_val);
2005 return 1;
2006 }
2007 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects
2008 {
2009 if (*final_task_on_target == ValueObject::eDereference)
2010 {
2011 Error error;
2012 ValueObjectSP final_value = ret_val->Dereference(error);
2013 if (error.Fail() || !final_value.get())
2014 {
2015 *reason_to_stop = ValueObject::eDereferencingFailed;
2016 *final_value_type = ValueObject::eInvalid;
2017 return 0;
2018 }
2019 else
2020 {
2021 *final_task_on_target = ValueObject::eNothing;
2022 list->Append(final_value);
2023 return 1;
2024 }
2025 }
2026 if (*final_task_on_target == ValueObject::eTakeAddress)
2027 {
2028 Error error;
2029 ValueObjectSP final_value = ret_val->AddressOf(error);
2030 if (error.Fail() || !final_value.get())
2031 {
2032 *reason_to_stop = ValueObject::eTakingAddressFailed;
2033 *final_value_type = ValueObject::eInvalid;
2034 return 0;
2035 }
2036 else
2037 {
2038 *final_task_on_target = ValueObject::eNothing;
2039 list->Append(final_value);
2040 return 1;
2041 }
2042 }
2043 }
2044 }
2045 else
2046 {
2047 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2048 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2049 ret_val,
2050 list,
2051 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2052 final_value_type ? final_value_type : &dummy_final_value_type,
2053 options,
2054 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2055 }
2056 // in any non-covered case, just do the obviously right thing
2057 list->Append(ret_val);
2058 return 1;
2059}
2060
Greg Claytonafacd142011-09-02 01:15:17 +00002061ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002062ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2063 const char** first_unparsed,
2064 ExpressionPathScanEndReason* reason_to_stop,
2065 ExpressionPathEndResultType* final_result,
2066 const GetValueForExpressionPathOptions& options,
2067 ExpressionPathAftermath* what_next)
2068{
2069 ValueObjectSP root = GetSP();
2070
2071 if (!root.get())
2072 return ValueObjectSP();
2073
2074 *first_unparsed = expression_cstr;
2075
2076 while (true)
2077 {
2078
2079 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2080
Greg Claytonafacd142011-09-02 01:15:17 +00002081 clang_type_t root_clang_type = root->GetClangType();
2082 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002083 Flags root_clang_type_info,pointee_clang_type_info;
2084
2085 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2086 if (pointee_clang_type)
2087 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002088
2089 if (!expression_cstr || *expression_cstr == '\0')
2090 {
2091 *reason_to_stop = ValueObject::eEndOfString;
2092 return root;
2093 }
2094
2095 switch (*expression_cstr)
2096 {
2097 case '-':
2098 {
2099 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002100 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 +00002101 {
2102 *first_unparsed = expression_cstr;
2103 *reason_to_stop = ValueObject::eArrowInsteadOfDot;
2104 *final_result = ValueObject::eInvalid;
2105 return ValueObjectSP();
2106 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002107 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2108 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002109 options.m_no_fragile_ivar)
2110 {
2111 *first_unparsed = expression_cstr;
2112 *reason_to_stop = ValueObject::eFragileIVarNotAllowed;
2113 *final_result = ValueObject::eInvalid;
2114 return ValueObjectSP();
2115 }
2116 if (expression_cstr[1] != '>')
2117 {
2118 *first_unparsed = expression_cstr;
2119 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2120 *final_result = ValueObject::eInvalid;
2121 return ValueObjectSP();
2122 }
2123 expression_cstr++; // skip the -
2124 }
2125 case '.': // or fallthrough from ->
2126 {
2127 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002128 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 +00002129 {
2130 *first_unparsed = expression_cstr;
2131 *reason_to_stop = ValueObject::eDotInsteadOfArrow;
2132 *final_result = ValueObject::eInvalid;
2133 return ValueObjectSP();
2134 }
2135 expression_cstr++; // skip .
2136 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2137 ConstString child_name;
2138 if (!next_separator) // if no other separator just expand this last layer
2139 {
2140 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002141 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2142
2143 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002144 {
2145 *first_unparsed = '\0';
2146 *reason_to_stop = ValueObject::eEndOfString;
2147 *final_result = ValueObject::ePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002148 return child_valobj_sp;
2149 }
2150 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2151 {
Greg Claytonafacd142011-09-02 01:15:17 +00002152 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002153 }
2154
2155 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2156 // so we hit the "else" branch, and return an error
2157 if(child_valobj_sp.get()) // if it worked, just return
2158 {
2159 *first_unparsed = '\0';
2160 *reason_to_stop = ValueObject::eEndOfString;
2161 *final_result = ValueObject::ePlain;
2162 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002163 }
2164 else
2165 {
2166 *first_unparsed = expression_cstr;
2167 *reason_to_stop = ValueObject::eNoSuchChild;
2168 *final_result = ValueObject::eInvalid;
2169 return ValueObjectSP();
2170 }
2171 }
2172 else // other layers do expand
2173 {
2174 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002175 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2176 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002177 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002178 root = child_valobj_sp;
2179 *first_unparsed = next_separator;
2180 *final_result = ValueObject::ePlain;
2181 continue;
2182 }
2183 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2184 {
Greg Claytonafacd142011-09-02 01:15:17 +00002185 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002186 }
2187
2188 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2189 // so we hit the "else" branch, and return an error
2190 if(child_valobj_sp.get()) // if it worked, move on
2191 {
2192 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002193 *first_unparsed = next_separator;
2194 *final_result = ValueObject::ePlain;
2195 continue;
2196 }
2197 else
2198 {
2199 *first_unparsed = expression_cstr;
2200 *reason_to_stop = ValueObject::eNoSuchChild;
2201 *final_result = ValueObject::eInvalid;
2202 return ValueObjectSP();
2203 }
2204 }
2205 break;
2206 }
2207 case '[':
2208 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002209 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 +00002210 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002211 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002212 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002213 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2214 {
2215 *first_unparsed = expression_cstr;
2216 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2217 *final_result = ValueObject::eInvalid;
2218 return ValueObjectSP();
2219 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002220 }
2221 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2222 {
2223 *first_unparsed = expression_cstr;
2224 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2225 *final_result = ValueObject::eInvalid;
2226 return ValueObjectSP();
2227 }
2228 }
2229 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2230 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002231 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002232 {
2233 *first_unparsed = expression_cstr;
2234 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2235 *final_result = ValueObject::eInvalid;
2236 return ValueObjectSP();
2237 }
2238 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2239 {
2240 *first_unparsed = expression_cstr+2;
2241 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2242 *final_result = ValueObject::eUnboundedRange;
2243 return root;
2244 }
2245 }
2246 const char *separator_position = ::strchr(expression_cstr+1,'-');
2247 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2248 if (!close_bracket_position) // if there is no ], this is a syntax error
2249 {
2250 *first_unparsed = expression_cstr;
2251 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2252 *final_result = ValueObject::eInvalid;
2253 return ValueObjectSP();
2254 }
2255 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2256 {
2257 char *end = NULL;
2258 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2259 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2260 {
2261 *first_unparsed = expression_cstr;
2262 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2263 *final_result = ValueObject::eInvalid;
2264 return ValueObjectSP();
2265 }
2266 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2267 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002268 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002269 {
2270 *first_unparsed = expression_cstr+2;
2271 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2272 *final_result = ValueObject::eUnboundedRange;
2273 return root;
2274 }
2275 else
2276 {
2277 *first_unparsed = expression_cstr;
2278 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2279 *final_result = ValueObject::eInvalid;
2280 return ValueObjectSP();
2281 }
2282 }
2283 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002284 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002285 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002286 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2287 if (!child_valobj_sp)
2288 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002289 if (!child_valobj_sp)
Greg Claytonafacd142011-09-02 01:15:17 +00002290 if (root->HasSyntheticValue() && root->GetSyntheticValue(eUseSyntheticFilter)->GetNumChildren() > index)
2291 child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002292 if (child_valobj_sp)
2293 {
2294 root = child_valobj_sp;
2295 *first_unparsed = end+1; // skip ]
2296 *final_result = ValueObject::ePlain;
2297 continue;
2298 }
2299 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002300 {
2301 *first_unparsed = expression_cstr;
2302 *reason_to_stop = ValueObject::eNoSuchChild;
2303 *final_result = ValueObject::eInvalid;
2304 return ValueObjectSP();
2305 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002306 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002307 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002308 {
2309 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 +00002310 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002311 {
2312 Error error;
2313 root = root->Dereference(error);
2314 if (error.Fail() || !root.get())
2315 {
2316 *first_unparsed = expression_cstr;
2317 *reason_to_stop = ValueObject::eDereferencingFailed;
2318 *final_result = ValueObject::eInvalid;
2319 return ValueObjectSP();
2320 }
2321 else
2322 {
2323 *what_next = eNothing;
2324 continue;
2325 }
2326 }
2327 else
2328 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002329 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Claytonafacd142011-09-02 01:15:17 +00002330 root->GetClangType()) == eLanguageTypeObjC
Enrico Granata27b625e2011-08-09 01:04:56 +00002331 &&
2332 ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2333 &&
2334 root->HasSyntheticValue()
2335 &&
2336 options.m_no_synthetic_children == false)
2337 {
Greg Claytonafacd142011-09-02 01:15:17 +00002338 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002339 }
2340 else
2341 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002342 if (!root.get())
2343 {
2344 *first_unparsed = expression_cstr;
2345 *reason_to_stop = ValueObject::eNoSuchChild;
2346 *final_result = ValueObject::eInvalid;
2347 return ValueObjectSP();
2348 }
2349 else
2350 {
2351 *first_unparsed = end+1; // skip ]
2352 *final_result = ValueObject::ePlain;
2353 continue;
2354 }
2355 }
2356 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002357 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002358 {
2359 root = root->GetSyntheticBitFieldChild(index, index, true);
2360 if (!root.get())
2361 {
2362 *first_unparsed = expression_cstr;
2363 *reason_to_stop = ValueObject::eNoSuchChild;
2364 *final_result = ValueObject::eInvalid;
2365 return ValueObjectSP();
2366 }
2367 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2368 {
2369 *first_unparsed = end+1; // skip ]
2370 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2371 *final_result = ValueObject::eBitfield;
2372 return root;
2373 }
2374 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002375 else if (root->HasSyntheticValue() && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002376 {
Greg Claytonafacd142011-09-02 01:15:17 +00002377 root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002378 if (!root.get())
2379 {
2380 *first_unparsed = expression_cstr;
2381 *reason_to_stop = ValueObject::eNoSuchChild;
2382 *final_result = ValueObject::eInvalid;
2383 return ValueObjectSP();
2384 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002385 else
2386 {
2387 *first_unparsed = end+1; // skip ]
2388 *final_result = ValueObject::ePlain;
2389 continue;
2390 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002391 }
2392 else
2393 {
2394 *first_unparsed = expression_cstr;
2395 *reason_to_stop = ValueObject::eNoSuchChild;
2396 *final_result = ValueObject::eInvalid;
2397 return ValueObjectSP();
2398 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002399 }
2400 else // we have a low and a high index
2401 {
2402 char *end = NULL;
2403 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2404 if (!end || end != separator_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 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2412 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2413 {
2414 *first_unparsed = expression_cstr;
2415 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2416 *final_result = ValueObject::eInvalid;
2417 return ValueObjectSP();
2418 }
2419 if (index_lower > index_higher) // swap indices if required
2420 {
2421 unsigned long temp = index_lower;
2422 index_lower = index_higher;
2423 index_higher = temp;
2424 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002425 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002426 {
2427 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2428 if (!root.get())
2429 {
2430 *first_unparsed = expression_cstr;
2431 *reason_to_stop = ValueObject::eNoSuchChild;
2432 *final_result = ValueObject::eInvalid;
2433 return ValueObjectSP();
2434 }
2435 else
2436 {
2437 *first_unparsed = end+1; // skip ]
2438 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet;
2439 *final_result = ValueObject::eBitfield;
2440 return root;
2441 }
2442 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002443 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 +00002444 *what_next == ValueObject::eDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002445 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002446 {
2447 Error error;
2448 root = root->Dereference(error);
2449 if (error.Fail() || !root.get())
2450 {
2451 *first_unparsed = expression_cstr;
2452 *reason_to_stop = ValueObject::eDereferencingFailed;
2453 *final_result = ValueObject::eInvalid;
2454 return ValueObjectSP();
2455 }
2456 else
2457 {
2458 *what_next = ValueObject::eNothing;
2459 continue;
2460 }
2461 }
2462 else
2463 {
2464 *first_unparsed = expression_cstr;
2465 *reason_to_stop = ValueObject::eArrayRangeOperatorMet;
2466 *final_result = ValueObject::eBoundedRange;
2467 return root;
2468 }
2469 }
2470 break;
2471 }
2472 default: // some non-separator is in the way
2473 {
2474 *first_unparsed = expression_cstr;
2475 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2476 *final_result = ValueObject::eInvalid;
2477 return ValueObjectSP();
2478 break;
2479 }
2480 }
2481 }
2482}
2483
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002484int
2485ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2486 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002487 ValueObjectSP root,
2488 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002489 ExpressionPathScanEndReason* reason_to_stop,
2490 ExpressionPathEndResultType* final_result,
2491 const GetValueForExpressionPathOptions& options,
2492 ExpressionPathAftermath* what_next)
2493{
2494 if (!root.get())
2495 return 0;
2496
2497 *first_unparsed = expression_cstr;
2498
2499 while (true)
2500 {
2501
2502 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2503
Greg Claytonafacd142011-09-02 01:15:17 +00002504 clang_type_t root_clang_type = root->GetClangType();
2505 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002506 Flags root_clang_type_info,pointee_clang_type_info;
2507
2508 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2509 if (pointee_clang_type)
2510 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2511
2512 if (!expression_cstr || *expression_cstr == '\0')
2513 {
2514 *reason_to_stop = ValueObject::eEndOfString;
2515 list->Append(root);
2516 return 1;
2517 }
2518
2519 switch (*expression_cstr)
2520 {
2521 case '[':
2522 {
2523 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2524 {
2525 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2526 {
2527 *first_unparsed = expression_cstr;
2528 *reason_to_stop = ValueObject::eRangeOperatorInvalid;
2529 *final_result = ValueObject::eInvalid;
2530 return 0;
2531 }
2532 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2533 {
2534 *first_unparsed = expression_cstr;
2535 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed;
2536 *final_result = ValueObject::eInvalid;
2537 return 0;
2538 }
2539 }
2540 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2541 {
2542 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2543 {
2544 *first_unparsed = expression_cstr;
2545 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2546 *final_result = ValueObject::eInvalid;
2547 return 0;
2548 }
2549 else // expand this into list
2550 {
2551 int max_index = root->GetNumChildren() - 1;
2552 for (int index = 0; index < max_index; index++)
2553 {
2554 ValueObjectSP child =
2555 root->GetChildAtIndex(index, true);
2556 list->Append(child);
2557 }
2558 *first_unparsed = expression_cstr+2;
2559 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2560 *final_result = ValueObject::eValueObjectList;
2561 return max_index; // tell me number of items I added to the VOList
2562 }
2563 }
2564 const char *separator_position = ::strchr(expression_cstr+1,'-');
2565 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2566 if (!close_bracket_position) // if there is no ], this is a syntax error
2567 {
2568 *first_unparsed = expression_cstr;
2569 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2570 *final_result = ValueObject::eInvalid;
2571 return 0;
2572 }
2573 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2574 {
2575 char *end = NULL;
2576 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2577 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2578 {
2579 *first_unparsed = expression_cstr;
2580 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2581 *final_result = ValueObject::eInvalid;
2582 return 0;
2583 }
2584 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2585 {
2586 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2587 {
2588 int max_index = root->GetNumChildren() - 1;
2589 for (int index = 0; index < max_index; index++)
2590 {
2591 ValueObjectSP child =
2592 root->GetChildAtIndex(index, true);
2593 list->Append(child);
2594 }
2595 *first_unparsed = expression_cstr+2;
2596 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2597 *final_result = ValueObject::eValueObjectList;
2598 return max_index; // tell me number of items I added to the VOList
2599 }
2600 else
2601 {
2602 *first_unparsed = expression_cstr;
2603 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed;
2604 *final_result = ValueObject::eInvalid;
2605 return 0;
2606 }
2607 }
2608 // from here on we do have a valid index
2609 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2610 {
2611 root = root->GetChildAtIndex(index, true);
2612 if (!root.get())
2613 {
2614 *first_unparsed = expression_cstr;
2615 *reason_to_stop = ValueObject::eNoSuchChild;
2616 *final_result = ValueObject::eInvalid;
2617 return 0;
2618 }
2619 else
2620 {
2621 list->Append(root);
2622 *first_unparsed = end+1; // skip ]
2623 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2624 *final_result = ValueObject::eValueObjectList;
2625 return 1;
2626 }
2627 }
2628 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2629 {
2630 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
2631 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2632 {
2633 Error error;
2634 root = root->Dereference(error);
2635 if (error.Fail() || !root.get())
2636 {
2637 *first_unparsed = expression_cstr;
2638 *reason_to_stop = ValueObject::eDereferencingFailed;
2639 *final_result = ValueObject::eInvalid;
2640 return 0;
2641 }
2642 else
2643 {
2644 *what_next = eNothing;
2645 continue;
2646 }
2647 }
2648 else
2649 {
2650 root = root->GetSyntheticArrayMemberFromPointer(index, true);
2651 if (!root.get())
2652 {
2653 *first_unparsed = expression_cstr;
2654 *reason_to_stop = ValueObject::eNoSuchChild;
2655 *final_result = ValueObject::eInvalid;
2656 return 0;
2657 }
2658 else
2659 {
2660 list->Append(root);
2661 *first_unparsed = end+1; // skip ]
2662 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2663 *final_result = ValueObject::eValueObjectList;
2664 return 1;
2665 }
2666 }
2667 }
2668 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
2669 {
2670 root = root->GetSyntheticBitFieldChild(index, index, true);
2671 if (!root.get())
2672 {
2673 *first_unparsed = expression_cstr;
2674 *reason_to_stop = ValueObject::eNoSuchChild;
2675 *final_result = ValueObject::eInvalid;
2676 return 0;
2677 }
2678 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2679 {
2680 list->Append(root);
2681 *first_unparsed = end+1; // skip ]
2682 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2683 *final_result = ValueObject::eValueObjectList;
2684 return 1;
2685 }
2686 }
2687 }
2688 else // we have a low and a high index
2689 {
2690 char *end = NULL;
2691 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2692 if (!end || end != separator_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 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2700 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2701 {
2702 *first_unparsed = expression_cstr;
2703 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2704 *final_result = ValueObject::eInvalid;
2705 return 0;
2706 }
2707 if (index_lower > index_higher) // swap indices if required
2708 {
2709 unsigned long temp = index_lower;
2710 index_lower = index_higher;
2711 index_higher = temp;
2712 }
2713 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
2714 {
2715 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2716 if (!root.get())
2717 {
2718 *first_unparsed = expression_cstr;
2719 *reason_to_stop = ValueObject::eNoSuchChild;
2720 *final_result = ValueObject::eInvalid;
2721 return 0;
2722 }
2723 else
2724 {
2725 list->Append(root);
2726 *first_unparsed = end+1; // skip ]
2727 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2728 *final_result = ValueObject::eValueObjectList;
2729 return 1;
2730 }
2731 }
2732 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
2733 *what_next == ValueObject::eDereference &&
2734 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2735 {
2736 Error error;
2737 root = root->Dereference(error);
2738 if (error.Fail() || !root.get())
2739 {
2740 *first_unparsed = expression_cstr;
2741 *reason_to_stop = ValueObject::eDereferencingFailed;
2742 *final_result = ValueObject::eInvalid;
2743 return 0;
2744 }
2745 else
2746 {
2747 *what_next = ValueObject::eNothing;
2748 continue;
2749 }
2750 }
2751 else
2752 {
Johnny Chen44805302011-07-19 19:48:13 +00002753 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002754 index <= index_higher; index++)
2755 {
2756 ValueObjectSP child =
2757 root->GetChildAtIndex(index, true);
2758 list->Append(child);
2759 }
2760 *first_unparsed = end+1;
2761 *reason_to_stop = ValueObject::eRangeOperatorExpanded;
2762 *final_result = ValueObject::eValueObjectList;
2763 return index_higher-index_lower+1; // tell me number of items I added to the VOList
2764 }
2765 }
2766 break;
2767 }
2768 default: // some non-[ separator, or something entirely wrong, is in the way
2769 {
2770 *first_unparsed = expression_cstr;
2771 *reason_to_stop = ValueObject::eUnexpectedSymbol;
2772 *final_result = ValueObject::eInvalid;
2773 return 0;
2774 break;
2775 }
2776 }
2777 }
2778}
2779
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002780void
Greg Clayton1d3afba2010-10-05 00:00:42 +00002781ValueObject::DumpValueObject
2782(
2783 Stream &s,
Greg Clayton1d3afba2010-10-05 00:00:42 +00002784 ValueObject *valobj,
2785 const char *root_valobj_name,
2786 uint32_t ptr_depth,
2787 uint32_t curr_depth,
2788 uint32_t max_depth,
2789 bool show_types,
2790 bool show_location,
2791 bool use_objc,
Greg Claytonafacd142011-09-02 01:15:17 +00002792 DynamicValueType use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00002793 bool use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002794 bool scope_already_checked,
Enrico Granata0c5ef692011-07-16 01:22:04 +00002795 bool flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00002796 uint32_t omit_summary_depth,
2797 bool ignore_cap
Greg Clayton1d3afba2010-10-05 00:00:42 +00002798)
2799{
Greg Clayton007d5be2011-05-30 00:49:24 +00002800 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002801 {
Enrico Granatac3e320a2011-08-02 17:27:39 +00002802 bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00002803
Greg Claytonafacd142011-09-02 01:15:17 +00002804 if (update_success && use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00002805 {
Jim Ingham2837b762011-05-04 03:43:18 +00002806 ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00002807 if (dynamic_value)
2808 valobj = dynamic_value;
2809 }
2810
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002811 clang_type_t clang_type = valobj->GetClangType();
2812
Greg Clayton73b472d2010-10-27 03:32:59 +00002813 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002814 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00002815 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
2816 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002817
2818 const bool print_valobj = flat_output == false || has_value;
2819
2820 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002821 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002822 if (show_location)
2823 {
Jim Ingham6035b672011-03-31 00:19:25 +00002824 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002825 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002826
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002827 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00002828
Greg Clayton7c8a9662010-11-02 01:50:16 +00002829 // Always show the type for the top level items.
Greg Claytone221f822011-01-21 01:59:00 +00002830 if (show_types || (curr_depth == 0 && !flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00002831 {
Enrico Granata9910bc82011-08-03 02:18:51 +00002832 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
2833 s.Printf("(%s", typeName);
2834 // only show dynamic types if the user really wants to see types
Greg Claytonafacd142011-09-02 01:15:17 +00002835 if (show_types && use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00002836 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00002837 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00002838 {
2839 Process* process = valobj->GetUpdatePoint().GetProcessSP().get();
2840 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00002841 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002842 else
2843 {
2844 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
2845 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00002846 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002847 else
2848 {
2849 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
2850 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00002851 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00002852 else
2853 s.Printf(", dynamic type: %s) ",
2854 runtime->GetActualTypeName(isa).GetCString());
2855 }
2856 }
2857 }
2858 else
2859 s.Printf(") ");
2860 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002861
Greg Clayton1d3afba2010-10-05 00:00:42 +00002862
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002863 if (flat_output)
2864 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00002865 // If we are showing types, also qualify the C++ base classes
2866 const bool qualify_cxx_base_classes = show_types;
2867 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002868 s.PutCString(" =");
2869 }
2870 else
2871 {
2872 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
2873 s.Printf ("%s =", name_cstr);
2874 }
2875
Jim Ingham6035b672011-03-31 00:19:25 +00002876 if (!scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002877 {
Greg Clayton007d5be2011-05-30 00:49:24 +00002878 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002879 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002880 }
2881
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002882 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00002883 const char *sum_cstr = NULL;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002884 SummaryFormat* entry = valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002885
Enrico Granata0c5ef692011-07-16 01:22:04 +00002886 if (omit_summary_depth > 0)
2887 entry = NULL;
2888
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002889 if (err_cstr == NULL)
2890 {
Jim Ingham6035b672011-03-31 00:19:25 +00002891 val_cstr = valobj->GetValueAsCString();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002892 err_cstr = valobj->GetError().AsCString();
2893 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002894
2895 if (err_cstr)
2896 {
Greg Clayton007d5be2011-05-30 00:49:24 +00002897 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00002898 }
2899 else
2900 {
Greg Clayton73b472d2010-10-27 03:32:59 +00002901 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002902 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002903 {
Enrico Granata4becb372011-06-29 22:27:15 +00002904
Enrico Granata0c5ef692011-07-16 01:22:04 +00002905 sum_cstr = (omit_summary_depth == 0) ? valobj->GetSummaryAsCString() : NULL;
Greg Clayton1d3afba2010-10-05 00:00:42 +00002906
Enrico Granata4becb372011-06-29 22:27:15 +00002907 // We must calculate this value in realtime because entry might alter this variable's value
2908 // (e.g. by saying ${var%fmt}) and render precached values useless
2909 if (val_cstr && (!entry || entry->DoesPrintValue() || !sum_cstr))
2910 s.Printf(" %s", valobj->GetValueAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002911
Enrico Granata9dd75c82011-07-15 23:30:15 +00002912 if (sum_cstr)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002913 {
2914 // for some reason, using %@ (ObjC description) in a summary string, makes
2915 // us believe we need to reset ourselves, thus invalidating the content of
2916 // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty
2917 // let us recalculate it!
2918 if (sum_cstr[0] == '\0')
2919 s.Printf(" %s", valobj->GetSummaryAsCString());
2920 else
2921 s.Printf(" %s", sum_cstr);
2922 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002923
2924 if (use_objc)
2925 {
Jim Ingham6035b672011-03-31 00:19:25 +00002926 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002927 if (object_desc)
2928 s.Printf(" %s\n", object_desc);
2929 else
Sean Callanan672ad942010-10-23 00:18:49 +00002930 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002931 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00002932 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002933 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002934
2935 if (curr_depth < max_depth)
2936 {
Greg Clayton73b472d2010-10-27 03:32:59 +00002937 // We will show children for all concrete types. We won't show
2938 // pointer contents unless a pointer depth has been specified.
2939 // We won't reference contents unless the reference is the
2940 // root object (depth of zero).
2941 bool print_children = true;
2942
2943 // Use a new temporary pointer depth in case we override the
2944 // current pointer depth below...
2945 uint32_t curr_ptr_depth = ptr_depth;
2946
2947 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
2948 if (is_ptr || is_ref)
2949 {
2950 // We have a pointer or reference whose value is an address.
2951 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00002952 AddressType ptr_address_type;
Greg Clayton73b472d2010-10-27 03:32:59 +00002953 if (valobj->GetPointerValue (ptr_address_type, true) == 0)
2954 print_children = false;
2955
2956 else if (is_ref && curr_depth == 0)
2957 {
2958 // If this is the root object (depth is zero) that we are showing
2959 // and it is a reference, and no pointer depth has been supplied
2960 // print out what it references. Don't do this at deeper depths
2961 // otherwise we can end up with infinite recursion...
2962 curr_ptr_depth = 1;
2963 }
2964
2965 if (curr_ptr_depth == 0)
2966 print_children = false;
2967 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00002968
Enrico Granata0a3958e2011-07-02 00:25:22 +00002969 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00002970 {
Enrico Granatac482a192011-08-17 22:13:59 +00002971 ValueObjectSP synth_valobj = valobj->GetSyntheticValue(use_synth ?
Greg Claytonafacd142011-09-02 01:15:17 +00002972 eUseSyntheticFilter :
2973 eNoSyntheticFilter);
Enrico Granatac482a192011-08-17 22:13:59 +00002974 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00002975 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002976 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002977 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002978 if (flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00002979 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002980 if (print_valobj)
2981 s.EOL();
2982 }
2983 else
2984 {
2985 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00002986 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002987 s.IndentMore();
2988 }
Enrico Granata22c55d12011-08-12 02:00:06 +00002989
2990 uint32_t max_num_children = valobj->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
2991
2992 if (num_children > max_num_children && !ignore_cap)
2993 {
2994 num_children = max_num_children;
2995 print_dotdotdot = true;
2996 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002997
2998 for (uint32_t idx=0; idx<num_children; ++idx)
2999 {
Enrico Granatac482a192011-08-17 22:13:59 +00003000 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003001 if (child_sp.get())
3002 {
3003 DumpValueObject (s,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003004 child_sp.get(),
3005 NULL,
Greg Clayton73b472d2010-10-27 03:32:59 +00003006 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003007 curr_depth + 1,
3008 max_depth,
3009 show_types,
3010 show_location,
3011 false,
Jim Ingham78a685a2011-04-16 00:01:13 +00003012 use_dynamic,
Enrico Granatad55546b2011-07-22 00:16:08 +00003013 use_synth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003014 true,
Enrico Granata0c5ef692011-07-16 01:22:04 +00003015 flat_output,
Enrico Granata22c55d12011-08-12 02:00:06 +00003016 omit_summary_depth > 1 ? omit_summary_depth - 1 : 0,
3017 ignore_cap);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003018 }
3019 }
3020
3021 if (!flat_output)
3022 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003023 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003024 {
3025 valobj->GetUpdatePoint().GetTargetSP()->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003026 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003027 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003028 s.IndentLess();
3029 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003030 }
3031 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003032 else if (has_children)
3033 {
3034 // Aggregate, no children...
3035 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003036 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003037 }
3038 else
3039 {
3040 if (print_valobj)
3041 s.EOL();
3042 }
3043
Greg Clayton1d3afba2010-10-05 00:00:42 +00003044 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003045 else
3046 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003047 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003048 }
3049 }
3050 else
3051 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003052 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003053 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003054 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003055 }
3056 }
3057 }
3058 }
3059}
3060
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003061
3062ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003063ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003064{
3065 ValueObjectSP valobj_sp;
3066
Enrico Granatac3e320a2011-08-02 17:27:39 +00003067 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003068 {
Jim Ingham6035b672011-03-31 00:19:25 +00003069 ExecutionContextScope *exe_scope = GetExecutionContextScope();
3070 if (exe_scope)
3071 {
3072 ExecutionContext exe_ctx;
3073 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003074
Jim Ingham6035b672011-03-31 00:19:25 +00003075 clang::ASTContext *ast = GetClangAST ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003076
Jim Ingham6035b672011-03-31 00:19:25 +00003077 DataExtractor data;
3078 data.SetByteOrder (m_data.GetByteOrder());
3079 data.SetAddressByteSize(m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003080
Greg Clayton644247c2011-07-07 01:59:51 +00003081 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003082
Jim Ingham58b59f92011-04-22 23:53:53 +00003083 valobj_sp = ValueObjectConstResult::Create (exe_scope,
3084 ast,
3085 GetClangType(),
3086 name,
3087 data);
Jim Ingham6035b672011-03-31 00:19:25 +00003088 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003089 }
Jim Ingham6035b672011-03-31 00:19:25 +00003090
3091 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003092 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003093 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003094 }
3095 return valobj_sp;
3096}
3097
Greg Claytonafacd142011-09-02 01:15:17 +00003098ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003099ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003100{
Jim Ingham58b59f92011-04-22 23:53:53 +00003101 if (m_deref_valobj)
3102 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003103
Greg Clayton54979cd2010-12-15 05:08:08 +00003104 const bool is_pointer_type = IsPointerType();
3105 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003106 {
3107 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003108 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003109
3110 std::string child_name_str;
3111 uint32_t child_byte_size = 0;
3112 int32_t child_byte_offset = 0;
3113 uint32_t child_bitfield_bit_size = 0;
3114 uint32_t child_bitfield_bit_offset = 0;
3115 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003116 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003117 const bool transparent_pointers = false;
3118 clang::ASTContext *clang_ast = GetClangAST();
3119 clang_type_t clang_type = GetClangType();
3120 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003121
3122 ExecutionContext exe_ctx;
3123 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
3124
3125 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3126 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003127 GetName().GetCString(),
3128 clang_type,
3129 0,
3130 transparent_pointers,
3131 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003132 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003133 child_name_str,
3134 child_byte_size,
3135 child_byte_offset,
3136 child_bitfield_bit_size,
3137 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003138 child_is_base_class,
3139 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003140 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003141 {
3142 ConstString child_name;
3143 if (!child_name_str.empty())
3144 child_name.SetCString (child_name_str.c_str());
3145
Jim Ingham58b59f92011-04-22 23:53:53 +00003146 m_deref_valobj = new ValueObjectChild (*this,
3147 clang_ast,
3148 child_clang_type,
3149 child_name,
3150 child_byte_size,
3151 child_byte_offset,
3152 child_bitfield_bit_size,
3153 child_bitfield_bit_offset,
3154 child_is_base_class,
3155 child_is_deref_of_parent);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003156 }
3157 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003158
Jim Ingham58b59f92011-04-22 23:53:53 +00003159 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003160 {
3161 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003162 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003163 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003164 else
3165 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003166 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003167 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003168
3169 if (is_pointer_type)
3170 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3171 else
3172 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003173 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003174 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003175}
3176
Greg Claytonafacd142011-09-02 01:15:17 +00003177ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003178ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003179{
Jim Ingham78a685a2011-04-16 00:01:13 +00003180 if (m_addr_of_valobj_sp)
3181 return m_addr_of_valobj_sp;
3182
Greg Claytone0d378b2011-03-24 21:19:54 +00003183 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003184 const bool scalar_is_load_address = false;
Greg Claytonafacd142011-09-02 01:15:17 +00003185 addr_t addr = GetAddressOf (address_type, scalar_is_load_address);
Greg Clayton54979cd2010-12-15 05:08:08 +00003186 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003187 if (addr != LLDB_INVALID_ADDRESS)
3188 {
3189 switch (address_type)
3190 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003191 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003192 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003193 {
3194 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003195 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003196 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3197 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003198 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003199
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003200 case eAddressTypeFile:
3201 case eAddressTypeLoad:
3202 case eAddressTypeHost:
3203 {
3204 clang::ASTContext *ast = GetClangAST();
3205 clang_type_t clang_type = GetClangType();
3206 if (ast && clang_type)
3207 {
3208 std::string name (1, '&');
3209 name.append (m_name.AsCString(""));
Jim Ingham58b59f92011-04-22 23:53:53 +00003210 m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(),
3211 ast,
3212 ClangASTContext::CreatePointerType (ast, clang_type),
3213 ConstString (name.c_str()),
3214 addr,
3215 eAddressTypeInvalid,
3216 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003217 }
3218 }
3219 break;
3220 }
3221 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003222 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003223}
3224
Greg Claytonb2dcc362011-05-05 23:32:56 +00003225
Greg Claytonafacd142011-09-02 01:15:17 +00003226ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003227ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3228{
Greg Claytonafacd142011-09-02 01:15:17 +00003229 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003230 AddressType address_type;
3231 const bool scalar_is_load_address = true;
Greg Claytonafacd142011-09-02 01:15:17 +00003232 addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003233
3234 if (ptr_value != LLDB_INVALID_ADDRESS)
3235 {
3236 Address ptr_addr (NULL, ptr_value);
3237
3238 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3239 name,
3240 ptr_addr,
3241 clang_ast_type);
3242 }
3243 return valobj_sp;
3244}
3245
Greg Claytonafacd142011-09-02 01:15:17 +00003246ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003247ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3248{
Greg Claytonafacd142011-09-02 01:15:17 +00003249 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003250 AddressType address_type;
3251 const bool scalar_is_load_address = true;
Greg Claytonafacd142011-09-02 01:15:17 +00003252 addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003253
3254 if (ptr_value != LLDB_INVALID_ADDRESS)
3255 {
3256 Address ptr_addr (NULL, ptr_value);
3257
3258 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
3259 name,
3260 ptr_addr,
3261 type_sp);
3262 }
3263 return valobj_sp;
3264}
3265
Jim Ingham6035b672011-03-31 00:19:25 +00003266ValueObject::EvaluationPoint::EvaluationPoint () :
Stephen Wilson71c21d12011-04-11 19:41:40 +00003267 m_thread_id (LLDB_INVALID_UID),
Jim Ingham4b536182011-08-09 02:12:22 +00003268 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003269{
3270}
3271
3272ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Jim Ingham6035b672011-03-31 00:19:25 +00003273 m_needs_update (true),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003274 m_first_update (true),
Jim Ingham89b61092011-07-06 17:42:14 +00003275 m_thread_id (LLDB_INVALID_THREAD_ID),
Jim Ingham4b536182011-08-09 02:12:22 +00003276 m_mod_id ()
Stephen Wilson71c21d12011-04-11 19:41:40 +00003277
Jim Ingham6035b672011-03-31 00:19:25 +00003278{
3279 ExecutionContext exe_ctx;
3280 ExecutionContextScope *computed_exe_scope = exe_scope; // If use_selected is true, we may find a better scope,
3281 // and if so we want to cache that not the original.
3282 if (exe_scope)
3283 exe_scope->CalculateExecutionContext(exe_ctx);
3284 if (exe_ctx.target != NULL)
3285 {
3286 m_target_sp = exe_ctx.target->GetSP();
3287
3288 if (exe_ctx.process == NULL)
3289 m_process_sp = exe_ctx.target->GetProcessSP();
3290 else
3291 m_process_sp = exe_ctx.process->GetSP();
3292
3293 if (m_process_sp != NULL)
3294 {
Jim Ingham4b536182011-08-09 02:12:22 +00003295 m_mod_id = m_process_sp->GetModID();
3296
Jim Ingham6035b672011-03-31 00:19:25 +00003297 Thread *thread = NULL;
3298
3299 if (exe_ctx.thread == NULL)
3300 {
3301 if (use_selected)
3302 {
3303 thread = m_process_sp->GetThreadList().GetSelectedThread().get();
3304 if (thread)
3305 computed_exe_scope = thread;
3306 }
3307 }
3308 else
3309 thread = exe_ctx.thread;
3310
3311 if (thread != NULL)
3312 {
3313 m_thread_id = thread->GetIndexID();
3314 if (exe_ctx.frame == NULL)
3315 {
3316 if (use_selected)
3317 {
3318 StackFrame *frame = exe_ctx.thread->GetSelectedFrame().get();
3319 if (frame)
3320 {
3321 m_stack_id = frame->GetStackID();
3322 computed_exe_scope = frame;
3323 }
3324 }
3325 }
3326 else
3327 m_stack_id = exe_ctx.frame->GetStackID();
3328 }
3329 }
3330 }
3331 m_exe_scope = computed_exe_scope;
3332}
3333
3334ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
3335 m_exe_scope (rhs.m_exe_scope),
Stephen Wilson71c21d12011-04-11 19:41:40 +00003336 m_needs_update(true),
3337 m_first_update(true),
Jim Ingham6035b672011-03-31 00:19:25 +00003338 m_target_sp (rhs.m_target_sp),
3339 m_process_sp (rhs.m_process_sp),
3340 m_thread_id (rhs.m_thread_id),
3341 m_stack_id (rhs.m_stack_id),
Jim Ingham4b536182011-08-09 02:12:22 +00003342 m_mod_id ()
Jim Ingham6035b672011-03-31 00:19:25 +00003343{
3344}
3345
3346ValueObject::EvaluationPoint::~EvaluationPoint ()
3347{
3348}
3349
3350ExecutionContextScope *
3351ValueObject::EvaluationPoint::GetExecutionContextScope ()
3352{
3353 // We have to update before giving out the scope, or we could be handing out stale pointers.
3354 SyncWithProcessState();
3355
3356 return m_exe_scope;
3357}
3358
3359// This function checks the EvaluationPoint against the current process state. If the current
3360// state matches the evaluation point, or the evaluation point is already invalid, then we return
3361// false, meaning "no change". If the current state is different, we update our state, and return
3362// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3363// future calls to NeedsUpdate will return true.
3364
3365bool
3366ValueObject::EvaluationPoint::SyncWithProcessState()
3367{
Jim Ingham6035b672011-03-31 00:19:25 +00003368 // If we don't have a process nothing can change.
3369 if (!m_process_sp)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003370 {
3371 m_exe_scope = m_target_sp.get();
Jim Ingham6035b672011-03-31 00:19:25 +00003372 return false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003373 }
Jim Ingham6035b672011-03-31 00:19:25 +00003374
3375 // If our stop id is the current stop ID, nothing has changed:
Jim Ingham4b536182011-08-09 02:12:22 +00003376 ProcessModID current_mod_id = m_process_sp->GetModID();
3377
Jim Ingham78a685a2011-04-16 00:01:13 +00003378 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3379 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003380 if (current_mod_id.GetStopID() == 0)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003381 {
3382 m_exe_scope = m_target_sp.get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003383 return false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003384 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003385
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003386 if (m_mod_id.IsValid())
3387 {
3388 if (m_mod_id == current_mod_id)
3389 {
3390 // Everything is already up to date in this object, no need do
3391 // update the execution context scope.
3392 return false;
3393 }
3394 m_mod_id = current_mod_id;
3395 m_needs_update = true;
3396 }
Jim Ingham6035b672011-03-31 00:19:25 +00003397 m_exe_scope = m_process_sp.get();
3398
3399 // Something has changed, so we will return true. Now make sure the thread & frame still exist, and if either
3400 // doesn't, mark ourselves as invalid.
3401
3402 if (m_thread_id != LLDB_INVALID_THREAD_ID)
3403 {
3404 Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get();
3405 if (our_thread == NULL)
Greg Clayton262f80d2011-07-06 16:49:27 +00003406 {
Jim Ingham89b61092011-07-06 17:42:14 +00003407 SetInvalid();
Greg Clayton262f80d2011-07-06 16:49:27 +00003408 }
Jim Ingham6035b672011-03-31 00:19:25 +00003409 else
3410 {
3411 m_exe_scope = our_thread;
3412
3413 if (m_stack_id.IsValid())
3414 {
3415 StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get();
3416 if (our_frame == NULL)
3417 SetInvalid();
3418 else
3419 m_exe_scope = our_frame;
3420 }
3421 }
3422 }
3423 return true;
3424}
3425
Jim Ingham61be0902011-05-02 18:13:59 +00003426void
3427ValueObject::EvaluationPoint::SetUpdated ()
3428{
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003429 // this will update the execution context scope and the m_mod_id
3430 SyncWithProcessState();
Jim Ingham61be0902011-05-02 18:13:59 +00003431 m_first_update = false;
3432 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003433}
3434
3435
Jim Ingham6035b672011-03-31 00:19:25 +00003436bool
3437ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3438{
3439 if (!IsValid())
3440 return false;
3441
3442 bool needs_update = false;
3443 m_exe_scope = NULL;
3444
3445 // The target has to be non-null, and the
3446 Target *target = exe_scope->CalculateTarget();
3447 if (target != NULL)
3448 {
3449 Target *old_target = m_target_sp.get();
3450 assert (target == old_target);
3451 Process *process = exe_scope->CalculateProcess();
3452 if (process != NULL)
3453 {
3454 // FOR NOW - assume you can't update variable objects across process boundaries.
3455 Process *old_process = m_process_sp.get();
3456 assert (process == old_process);
Jim Ingham4b536182011-08-09 02:12:22 +00003457 ProcessModID current_mod_id = process->GetModID();
3458 if (m_mod_id != current_mod_id)
Jim Ingham6035b672011-03-31 00:19:25 +00003459 {
3460 needs_update = true;
Jim Ingham4b536182011-08-09 02:12:22 +00003461 m_mod_id = current_mod_id;
Jim Ingham6035b672011-03-31 00:19:25 +00003462 }
3463 // See if we're switching the thread or stack context. If no thread is given, this is
3464 // being evaluated in a global context.
3465 Thread *thread = exe_scope->CalculateThread();
3466 if (thread != NULL)
3467 {
Greg Claytonafacd142011-09-02 01:15:17 +00003468 user_id_t new_thread_index = thread->GetIndexID();
Jim Ingham6035b672011-03-31 00:19:25 +00003469 if (new_thread_index != m_thread_id)
3470 {
3471 needs_update = true;
3472 m_thread_id = new_thread_index;
3473 m_stack_id.Clear();
3474 }
3475
3476 StackFrame *new_frame = exe_scope->CalculateStackFrame();
3477 if (new_frame != NULL)
3478 {
3479 if (new_frame->GetStackID() != m_stack_id)
3480 {
3481 needs_update = true;
3482 m_stack_id = new_frame->GetStackID();
3483 }
3484 }
3485 else
3486 {
3487 m_stack_id.Clear();
3488 needs_update = true;
3489 }
3490 }
3491 else
3492 {
3493 // If this had been given a thread, and now there is none, we should update.
3494 // Otherwise we don't have to do anything.
3495 if (m_thread_id != LLDB_INVALID_UID)
3496 {
3497 m_thread_id = LLDB_INVALID_UID;
3498 m_stack_id.Clear();
3499 needs_update = true;
3500 }
3501 }
3502 }
3503 else
3504 {
3505 // If there is no process, then we don't need to update anything.
3506 // But if we're switching from having a process to not, we should try to update.
3507 if (m_process_sp.get() != NULL)
3508 {
3509 needs_update = true;
3510 m_process_sp.reset();
3511 m_thread_id = LLDB_INVALID_UID;
3512 m_stack_id.Clear();
3513 }
3514 }
3515 }
3516 else
3517 {
3518 // If there's no target, nothing can change so we don't need to update anything.
3519 // But if we're switching from having a target to not, we should try to update.
3520 if (m_target_sp.get() != NULL)
3521 {
3522 needs_update = true;
3523 m_target_sp.reset();
3524 m_process_sp.reset();
3525 m_thread_id = LLDB_INVALID_UID;
3526 m_stack_id.Clear();
3527 }
3528 }
3529 if (!m_needs_update)
3530 m_needs_update = needs_update;
3531
3532 return needs_update;
3533}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003534
3535void
3536ValueObject::ClearUserVisibleData()
3537{
3538 m_location_str.clear();
3539 m_value_str.clear();
3540 m_summary_str.clear();
3541 m_object_desc_str.clear();
Johnny Chen44805302011-07-19 19:48:13 +00003542}