blob: 918be0923c30eddd41c8364ae95999ce50e4f405 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/ValueObject.h"
11
12// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000013#include <stdlib.h>
14
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015// C++ Includes
16// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000018#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
20// Project includes
21#include "lldb/Core/DataBufferHeap.h"
Enrico Granata4becb372011-06-29 22:27:15 +000022#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Core/StreamString.h"
24#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000025#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000026#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000028#include "lldb/Core/ValueObjectMemory.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029
Greg Clayton7fb56d02011-02-01 01:31:41 +000030#include "lldb/Host/Endian.h"
31
Greg Claytone1a916a2010-07-21 22:12:05 +000032#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Symbol/ClangASTContext.h"
34#include "lldb/Symbol/Type.h"
35
Jim Ingham53c47f12010-09-10 23:12:17 +000036#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000037#include "lldb/Target/LanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038#include "lldb/Target/Process.h"
39#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000040#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042
43using namespace lldb;
44using namespace lldb_private;
45
46static lldb::user_id_t g_value_obj_uid = 0;
47
48//----------------------------------------------------------------------
49// ValueObject constructor
50//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000051ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000053 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000054 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055 m_name (),
56 m_data (),
57 m_value (),
58 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000059 m_value_str (),
60 m_old_value_str (),
61 m_location_str (),
62 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000063 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000064 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000065 m_children (),
66 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000067 m_dynamic_value (NULL),
68 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000069 m_format (eFormatDefault),
Greg Clayton288bdf92010-09-02 02:59:18 +000070 m_value_is_valid (false),
71 m_value_did_change (false),
72 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000073 m_old_value_valid (false),
Greg Claytone221f822011-01-21 01:59:00 +000074 m_pointers_point_to_load_addrs (false),
Enrico Granata4becb372011-06-29 22:27:15 +000075 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000076 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000077 m_is_bitfield_for_scalar(false),
Enrico Granata4becb372011-06-29 22:27:15 +000078 m_last_format_mgr_revision(0),
79 m_last_summary_format(),
80 m_last_value_format()
Jim Ingham6035b672011-03-31 00:19:25 +000081{
Jim Ingham58b59f92011-04-22 23:53:53 +000082 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +000083}
84
85//----------------------------------------------------------------------
86// ValueObject constructor
87//----------------------------------------------------------------------
88ValueObject::ValueObject (ExecutionContextScope *exe_scope) :
89 UserID (++g_value_obj_uid), // Unique identifier for every value object
90 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +000091 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +000092 m_name (),
93 m_data (),
94 m_value (),
95 m_error (),
96 m_value_str (),
97 m_old_value_str (),
98 m_location_str (),
99 m_summary_str (),
100 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000101 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000102 m_children (),
103 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000104 m_dynamic_value (NULL),
105 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000106 m_format (eFormatDefault),
107 m_value_is_valid (false),
108 m_value_did_change (false),
109 m_children_count_valid (false),
110 m_old_value_valid (false),
111 m_pointers_point_to_load_addrs (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000112 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000113 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000114 m_is_bitfield_for_scalar(false),
Enrico Granata4becb372011-06-29 22:27:15 +0000115 m_last_format_mgr_revision(0),
116 m_last_summary_format(),
117 m_last_value_format()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118{
Jim Ingham58b59f92011-04-22 23:53:53 +0000119 m_manager = new ValueObjectManager();
120 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000121}
122
123//----------------------------------------------------------------------
124// Destructor
125//----------------------------------------------------------------------
126ValueObject::~ValueObject ()
127{
128}
129
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000130bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000131ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000132{
Enrico Granata4becb372011-06-29 22:27:15 +0000133
Enrico Granata0a3958e2011-07-02 00:25:22 +0000134 if (update_format)
135 UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000136
Greg Claytonb71f3842010-10-05 03:13:51 +0000137 // If this is a constant value, then our success is predicated on whether
138 // we have an error or not
139 if (GetIsConstant())
140 return m_error.Success();
141
Jim Ingham6035b672011-03-31 00:19:25 +0000142 bool first_update = m_update_point.IsFirstEvaluation();
143
144 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000145 {
Jim Ingham6035b672011-03-31 00:19:25 +0000146 m_update_point.SetUpdated();
147
148 // Save the old value using swap to avoid a string copy which
149 // also will clear our m_value_str
150 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000151 {
Jim Ingham6035b672011-03-31 00:19:25 +0000152 m_old_value_valid = false;
153 }
154 else
155 {
156 m_old_value_valid = true;
157 m_old_value_str.swap (m_value_str);
158 m_value_str.clear();
159 }
160 m_location_str.clear();
161 m_summary_str.clear();
162 m_object_desc_str.clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163
Jim Ingham6035b672011-03-31 00:19:25 +0000164 const bool value_was_valid = GetValueIsValid();
165 SetValueDidChange (false);
Greg Clayton73b953b2010-08-28 00:08:07 +0000166
Jim Ingham6035b672011-03-31 00:19:25 +0000167 m_error.Clear();
Greg Clayton73b953b2010-08-28 00:08:07 +0000168
Jim Ingham6035b672011-03-31 00:19:25 +0000169 // Call the pure virtual function to update the value
170 bool success = UpdateValue ();
171
172 SetValueIsValid (success);
173
174 if (first_update)
175 SetValueDidChange (false);
176 else if (!m_value_did_change && success == false)
177 {
178 // The value wasn't gotten successfully, so we mark this
179 // as changed if the value used to be valid and now isn't
180 SetValueDidChange (value_was_valid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000181 }
182 }
183 return m_error.Success();
184}
185
Enrico Granata4becb372011-06-29 22:27:15 +0000186void
187ValueObject::UpdateFormatsIfNeeded()
188{
189 /*printf("CHECKING FOR UPDATES. I am at revision %d, while the format manager is at revision %d\n",
190 m_last_format_mgr_revision,
191 Debugger::ValueFormats::GetCurrentRevision());*/
192 if (m_last_format_mgr_revision != Debugger::ValueFormats::GetCurrentRevision())
193 {
194 if (m_last_summary_format.get())
195 m_last_summary_format.reset((SummaryFormat*)NULL);
196 if (m_last_value_format.get())
197 m_last_value_format.reset((ValueFormat*)NULL);
198 Debugger::ValueFormats::Get(*this, m_last_value_format);
Enrico Granata0a3958e2011-07-02 00:25:22 +0000199 if (!Debugger::SummaryFormats::Get(*this, m_last_summary_format))
200 Debugger::RegexSummaryFormats::Get(*this, m_last_summary_format);
Enrico Granata4becb372011-06-29 22:27:15 +0000201 m_last_format_mgr_revision = Debugger::ValueFormats::GetCurrentRevision();
202 m_value_str.clear();
203 m_summary_str.clear();
204 }
205}
206
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000207DataExtractor &
208ValueObject::GetDataExtractor ()
209{
Jim Ingham78a685a2011-04-16 00:01:13 +0000210 UpdateValueIfNeeded();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000211 return m_data;
212}
213
214const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000215ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000216{
Greg Clayton262f80d2011-07-06 16:49:27 +0000217 UpdateValueIfNeeded();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000218 return m_error;
219}
220
221const ConstString &
222ValueObject::GetName() const
223{
224 return m_name;
225}
226
227const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000228ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000229{
Jim Ingham6035b672011-03-31 00:19:25 +0000230 if (UpdateValueIfNeeded())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231 {
232 if (m_location_str.empty())
233 {
234 StreamString sstr;
235
236 switch (m_value.GetValueType())
237 {
238 default:
239 break;
240
241 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000242 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000243 {
244 RegisterInfo *reg_info = m_value.GetRegisterInfo();
245 if (reg_info)
246 {
247 if (reg_info->name)
248 m_location_str = reg_info->name;
249 else if (reg_info->alt_name)
250 m_location_str = reg_info->alt_name;
251 break;
252 }
253 }
254 m_location_str = "scalar";
255 break;
256
257 case Value::eValueTypeLoadAddress:
258 case Value::eValueTypeFileAddress:
259 case Value::eValueTypeHostAddress:
260 {
261 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
262 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
263 m_location_str.swap(sstr.GetString());
264 }
265 break;
266 }
267 }
268 }
269 return m_location_str.c_str();
270}
271
272Value &
273ValueObject::GetValue()
274{
275 return m_value;
276}
277
278const Value &
279ValueObject::GetValue() const
280{
281 return m_value;
282}
283
284bool
Jim Ingham6035b672011-03-31 00:19:25 +0000285ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000286{
287 ExecutionContext exe_ctx;
Jim Ingham6035b672011-03-31 00:19:25 +0000288 ExecutionContextScope *exe_scope = GetExecutionContextScope();
289 if (exe_scope)
290 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Clayton8f343b02010-11-04 01:54:29 +0000291 scalar = m_value.ResolveValue(&exe_ctx, GetClangAST ());
292 return scalar.IsValid();
293}
294
295bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000296ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000297{
Greg Clayton288bdf92010-09-02 02:59:18 +0000298 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000299}
300
301
302void
303ValueObject::SetValueIsValid (bool b)
304{
Greg Clayton288bdf92010-09-02 02:59:18 +0000305 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000306}
307
308bool
Jim Ingham6035b672011-03-31 00:19:25 +0000309ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310{
Jim Ingham6035b672011-03-31 00:19:25 +0000311 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000312 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000313}
314
315void
316ValueObject::SetValueDidChange (bool value_changed)
317{
Greg Clayton288bdf92010-09-02 02:59:18 +0000318 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000319}
320
321ValueObjectSP
322ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
323{
324 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000325 // We may need to update our value if we are dynamic
326 if (IsPossibleDynamicType ())
327 UpdateValueIfNeeded();
328 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000329 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000330 // Check if we have already made the child value object?
331 if (can_create && m_children[idx] == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000332 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000333 // No we haven't created the child at this index, so lets have our
334 // subclass do it and cache the result for quick future access.
335 m_children[idx] = CreateChildAtIndex (idx, false, 0);
Jim Ingham78a685a2011-04-16 00:01:13 +0000336 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000337
338 if (m_children[idx] != NULL)
339 return m_children[idx]->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000340 }
341 return child_sp;
342}
343
344uint32_t
345ValueObject::GetIndexOfChildWithName (const ConstString &name)
346{
347 bool omit_empty_base_classes = true;
348 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000349 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000350 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351 omit_empty_base_classes);
352}
353
354ValueObjectSP
355ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
356{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000357 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000358 // classes (which really aren't part of the expression path), so we
359 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000360 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000361
Greg Claytondea8cb42011-06-29 22:09:02 +0000362 // We may need to update our value if we are dynamic
363 if (IsPossibleDynamicType ())
364 UpdateValueIfNeeded();
365
366 std::vector<uint32_t> child_indexes;
367 clang::ASTContext *clang_ast = GetClangAST();
368 void *clang_type = GetClangType();
369 bool omit_empty_base_classes = true;
370 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
371 clang_type,
372 name.GetCString(),
373 omit_empty_base_classes,
374 child_indexes);
375 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000376 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000377 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
378 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
379
380 child_sp = GetChildAtIndex(*pos, can_create);
381 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000382 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000383 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000384 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000385 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
386 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000387 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000388 else
389 {
390 child_sp.reset();
391 }
392
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000393 }
394 }
395 return child_sp;
396}
397
398
399uint32_t
400ValueObject::GetNumChildren ()
401{
Greg Clayton288bdf92010-09-02 02:59:18 +0000402 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403 {
404 SetNumChildren (CalculateNumChildren());
405 }
406 return m_children.size();
407}
408void
409ValueObject::SetNumChildren (uint32_t num_children)
410{
Greg Clayton288bdf92010-09-02 02:59:18 +0000411 m_children_count_valid = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412 m_children.resize(num_children);
413}
414
415void
416ValueObject::SetName (const char *name)
417{
418 m_name.SetCString(name);
419}
420
421void
422ValueObject::SetName (const ConstString &name)
423{
424 m_name = name;
425}
426
Jim Ingham58b59f92011-04-22 23:53:53 +0000427ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
429{
Jim Ingham2eec4872011-05-07 00:10:58 +0000430 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000431
Greg Claytondea8cb42011-06-29 22:09:02 +0000432 bool omit_empty_base_classes = true;
433
434 std::string child_name_str;
435 uint32_t child_byte_size = 0;
436 int32_t child_byte_offset = 0;
437 uint32_t child_bitfield_bit_size = 0;
438 uint32_t child_bitfield_bit_offset = 0;
439 bool child_is_base_class = false;
440 bool child_is_deref_of_parent = false;
441
442 const bool transparent_pointers = synthetic_array_member == false;
443 clang::ASTContext *clang_ast = GetClangAST();
444 clang_type_t clang_type = GetClangType();
445 clang_type_t child_clang_type;
446
447 ExecutionContext exe_ctx;
448 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
449
450 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
451 clang_ast,
452 GetName().GetCString(),
453 clang_type,
454 idx,
455 transparent_pointers,
456 omit_empty_base_classes,
457 child_name_str,
458 child_byte_size,
459 child_byte_offset,
460 child_bitfield_bit_size,
461 child_bitfield_bit_offset,
462 child_is_base_class,
463 child_is_deref_of_parent);
464 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000465 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000466 if (synthetic_index)
467 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468
Greg Claytondea8cb42011-06-29 22:09:02 +0000469 ConstString child_name;
470 if (!child_name_str.empty())
471 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472
Greg Claytondea8cb42011-06-29 22:09:02 +0000473 valobj = new ValueObjectChild (*this,
474 clang_ast,
475 child_clang_type,
476 child_name,
477 child_byte_size,
478 child_byte_offset,
479 child_bitfield_bit_size,
480 child_bitfield_bit_offset,
481 child_is_base_class,
482 child_is_deref_of_parent);
483 if (m_pointers_point_to_load_addrs)
484 valobj->SetPointersPointToLoadAddrs (m_pointers_point_to_load_addrs);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000485 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000486
Jim Ingham58b59f92011-04-22 23:53:53 +0000487 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488}
489
490const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000491ValueObject::GetSummaryAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000492{
Jim Ingham6035b672011-03-31 00:19:25 +0000493 if (UpdateValueIfNeeded ())
Enrico Granata4becb372011-06-29 22:27:15 +0000494 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000495 if (m_summary_str.empty())
496 {
Enrico Granata4becb372011-06-29 22:27:15 +0000497 if (m_last_summary_format.get())
498 {
499 StreamString s;
500 ExecutionContext exe_ctx;
501 this->GetExecutionContextScope()->CalculateExecutionContext(exe_ctx);
502 SymbolContext sc = exe_ctx.frame->GetSymbolContext(eSymbolContextEverything);
Enrico Granata0a3958e2011-07-02 00:25:22 +0000503
504 if (m_last_summary_format->m_show_members_oneliner)
Enrico Granata4becb372011-06-29 22:27:15 +0000505 {
Enrico Granata0a3958e2011-07-02 00:25:22 +0000506 const uint32_t num_children = GetNumChildren();
507 if (num_children)
508 {
509
510 s.PutChar('(');
511
512 for (uint32_t idx=0; idx<num_children; ++idx)
513 {
514 ValueObjectSP child_sp(GetChildAtIndex(idx, true));
515 if (child_sp.get())
516 {
517 if (idx)
518 s.PutCString(", ");
519 s.PutCString(child_sp.get()->GetName().AsCString());
520 s.PutChar('=');
Enrico Granata9fc19442011-07-06 02:13:41 +0000521 s.PutCString(child_sp.get()->GetPrintableRepresentation());
Enrico Granata0a3958e2011-07-02 00:25:22 +0000522 }
523 }
524
525 s.PutChar(')');
526
527 m_summary_str.swap(s.GetString());
528 return m_summary_str.c_str();
529 }
530 else
531 return "()";
532
Enrico Granata4becb372011-06-29 22:27:15 +0000533 }
Enrico Granata0a3958e2011-07-02 00:25:22 +0000534 else
535 {
536 if (Debugger::FormatPrompt(m_last_summary_format->m_format.c_str(), &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, NULL, this))
537 {
538 m_summary_str.swap(s.GetString());
539 return m_summary_str.c_str();
540 }
541 else
542 return NULL;
543 }
Enrico Granata4becb372011-06-29 22:27:15 +0000544 }
545
Greg Clayton73b472d2010-10-27 03:32:59 +0000546 clang_type_t clang_type = GetClangType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547
548 // See if this is a pointer to a C string?
Greg Clayton737b9322010-09-13 03:32:57 +0000549 if (clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000550 {
Greg Clayton737b9322010-09-13 03:32:57 +0000551 StreamString sstr;
Greg Clayton73b472d2010-10-27 03:32:59 +0000552 clang_type_t elem_or_pointee_clang_type;
553 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000554 GetClangAST(),
555 &elem_or_pointee_clang_type));
Greg Clayton737b9322010-09-13 03:32:57 +0000556
Jim Ingham6035b672011-03-31 00:19:25 +0000557 ExecutionContextScope *exe_scope = GetExecutionContextScope();
558 if (exe_scope)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000559 {
Jim Ingham6035b672011-03-31 00:19:25 +0000560 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
561 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000562 {
Jim Ingham6035b672011-03-31 00:19:25 +0000563 Process *process = exe_scope->CalculateProcess();
564 if (process != NULL)
565 {
566 lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS;
567 AddressType cstr_address_type = eAddressTypeInvalid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000568
Jim Ingham6035b672011-03-31 00:19:25 +0000569 size_t cstr_len = 0;
570 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000571 {
Jim Ingham6035b672011-03-31 00:19:25 +0000572 // We have an array
573 cstr_len = ClangASTContext::GetArraySize (clang_type);
574 cstr_address = GetAddressOf (cstr_address_type, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000575 }
Greg Clayton737b9322010-09-13 03:32:57 +0000576 else
577 {
Jim Ingham6035b672011-03-31 00:19:25 +0000578 // We have a pointer
579 cstr_address = GetPointerValue (cstr_address_type, true);
Greg Clayton737b9322010-09-13 03:32:57 +0000580 }
Jim Ingham6035b672011-03-31 00:19:25 +0000581 if (cstr_address != LLDB_INVALID_ADDRESS)
Greg Clayton737b9322010-09-13 03:32:57 +0000582 {
Jim Ingham6035b672011-03-31 00:19:25 +0000583 DataExtractor data;
584 size_t bytes_read = 0;
585 std::vector<char> data_buffer;
586 Error error;
587 if (cstr_len > 0)
Greg Clayton737b9322010-09-13 03:32:57 +0000588 {
Jim Ingham6035b672011-03-31 00:19:25 +0000589 data_buffer.resize(cstr_len);
590 data.SetData (&data_buffer.front(), data_buffer.size(), lldb::endian::InlHostByteOrder());
591 bytes_read = process->ReadMemory (cstr_address, &data_buffer.front(), cstr_len, error);
592 if (bytes_read > 0)
Greg Clayton737b9322010-09-13 03:32:57 +0000593 {
Jim Ingham6035b672011-03-31 00:19:25 +0000594 sstr << '"';
595 data.Dump (&sstr,
596 0, // Start offset in "data"
Greg Clayton4e4294b2011-06-17 23:50:44 +0000597 eFormatCharArray, // Print as characters
Jim Ingham6035b672011-03-31 00:19:25 +0000598 1, // Size of item (1 byte for a char!)
599 bytes_read, // How many bytes to print?
600 UINT32_MAX, // num per line
601 LLDB_INVALID_ADDRESS,// base address
602 0, // bitfield bit size
603 0); // bitfield bit offset
604 sstr << '"';
Greg Clayton737b9322010-09-13 03:32:57 +0000605 }
606 }
Jim Ingham6035b672011-03-31 00:19:25 +0000607 else
608 {
609 const size_t k_max_buf_size = 256;
610 data_buffer.resize (k_max_buf_size + 1);
611 // NULL terminate in case we don't get the entire C string
612 data_buffer.back() = '\0';
Greg Clayton737b9322010-09-13 03:32:57 +0000613
Jim Ingham6035b672011-03-31 00:19:25 +0000614 sstr << '"';
615
616 data.SetData (&data_buffer.front(), data_buffer.size(), endian::InlHostByteOrder());
617 while ((bytes_read = process->ReadMemory (cstr_address, &data_buffer.front(), k_max_buf_size, error)) > 0)
618 {
619 size_t len = strlen(&data_buffer.front());
620 if (len == 0)
621 break;
622 if (len > bytes_read)
623 len = bytes_read;
624
625 data.Dump (&sstr,
626 0, // Start offset in "data"
Greg Clayton4e4294b2011-06-17 23:50:44 +0000627 eFormatCharArray, // Print as characters
Jim Ingham6035b672011-03-31 00:19:25 +0000628 1, // Size of item (1 byte for a char!)
629 len, // How many bytes to print?
630 UINT32_MAX, // num per line
631 LLDB_INVALID_ADDRESS,// base address
632 0, // bitfield bit size
633 0); // bitfield bit offset
634
635 if (len < k_max_buf_size)
636 break;
637 cstr_address += k_max_buf_size;
638 }
639 sstr << '"';
640 }
641 }
Greg Clayton737b9322010-09-13 03:32:57 +0000642 }
Jim Ingham6035b672011-03-31 00:19:25 +0000643
644 if (sstr.GetSize() > 0)
645 m_summary_str.assign (sstr.GetData(), sstr.GetSize());
Greg Clayton737b9322010-09-13 03:32:57 +0000646 }
Jim Ingham6035b672011-03-31 00:19:25 +0000647 else if (ClangASTContext::IsFunctionPointerType (clang_type))
Greg Clayton737b9322010-09-13 03:32:57 +0000648 {
Jim Ingham6035b672011-03-31 00:19:25 +0000649 AddressType func_ptr_address_type = eAddressTypeInvalid;
650 lldb::addr_t func_ptr_address = GetPointerValue (func_ptr_address_type, true);
651
652 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
653 {
654 switch (func_ptr_address_type)
655 {
656 case eAddressTypeInvalid:
657 case eAddressTypeFile:
658 break;
659
660 case eAddressTypeLoad:
661 {
662 Address so_addr;
663 Target *target = exe_scope->CalculateTarget();
664 if (target && target->GetSectionLoadList().IsEmpty() == false)
665 {
666 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
667 {
668 so_addr.Dump (&sstr,
669 exe_scope,
670 Address::DumpStyleResolvedDescription,
671 Address::DumpStyleSectionNameOffset);
672 }
673 }
674 }
675 break;
676
677 case eAddressTypeHost:
678 break;
679 }
680 }
681 if (sstr.GetSize() > 0)
682 {
683 m_summary_str.assign (1, '(');
684 m_summary_str.append (sstr.GetData(), sstr.GetSize());
685 m_summary_str.append (1, ')');
686 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687 }
688 }
689 }
690 }
691 }
692 if (m_summary_str.empty())
693 return NULL;
694 return m_summary_str.c_str();
695}
696
Jim Ingham53c47f12010-09-10 23:12:17 +0000697const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000698ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +0000699{
Enrico Granata0a3958e2011-07-02 00:25:22 +0000700
Jim Ingham6035b672011-03-31 00:19:25 +0000701 if (!UpdateValueIfNeeded ())
Jim Ingham53c47f12010-09-10 23:12:17 +0000702 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +0000703
704 if (!m_object_desc_str.empty())
705 return m_object_desc_str.c_str();
706
Jim Ingham6035b672011-03-31 00:19:25 +0000707 ExecutionContextScope *exe_scope = GetExecutionContextScope();
708 if (exe_scope == NULL)
709 return NULL;
710
Jim Ingham53c47f12010-09-10 23:12:17 +0000711 Process *process = exe_scope->CalculateProcess();
Jim Ingham5a369122010-09-28 01:25:32 +0000712 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +0000713 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +0000714
Jim Ingham53c47f12010-09-10 23:12:17 +0000715 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +0000716
717 lldb::LanguageType language = GetObjectRuntimeLanguage();
718 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
719
Jim Inghama2cf2632010-12-23 02:29:54 +0000720 if (runtime == NULL)
721 {
Jim Inghamb7603bb2011-03-18 00:05:18 +0000722 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +0000723 clang_type_t opaque_qual_type = GetClangType();
724 if (opaque_qual_type != NULL)
725 {
Jim Inghamb7603bb2011-03-18 00:05:18 +0000726 bool is_signed;
727 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
728 || ClangASTContext::IsPointerType (opaque_qual_type))
729 {
Jim Inghama2cf2632010-12-23 02:29:54 +0000730 runtime = process->GetLanguageRuntime(lldb::eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +0000731 }
Jim Inghama2cf2632010-12-23 02:29:54 +0000732 }
733 }
734
Jim Ingham8d543de2011-03-31 23:01:21 +0000735 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +0000736 {
737 m_object_desc_str.append (s.GetData());
738 }
Sean Callanan672ad942010-10-23 00:18:49 +0000739
740 if (m_object_desc_str.empty())
741 return NULL;
742 else
743 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +0000744}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000745
746const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000747ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000748{
749 // If our byte size is zero this is an aggregate type that has children
Greg Clayton1be10fc2010-09-29 01:12:09 +0000750 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000751 {
Jim Ingham6035b672011-03-31 00:19:25 +0000752 if (UpdateValueIfNeeded())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000753 {
754 if (m_value_str.empty())
755 {
756 const Value::ContextType context_type = m_value.GetContextType();
757
758 switch (context_type)
759 {
Greg Clayton526e5af2010-11-13 03:52:47 +0000760 case Value::eContextTypeClangType:
761 case Value::eContextTypeLLDBType:
762 case Value::eContextTypeVariable:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000763 {
Greg Clayton73b472d2010-10-27 03:32:59 +0000764 clang_type_t clang_type = GetClangType ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000765 if (clang_type)
766 {
767 StreamString sstr;
Greg Clayton68ebae62011-04-28 20:55:26 +0000768 Format format = GetFormat();
Enrico Granata4becb372011-06-29 22:27:15 +0000769 if (format == eFormatDefault)
770 {
771 if (m_last_value_format)
772 format = m_last_value_format->m_format;
773 else
Enrico Granata9fc19442011-07-06 02:13:41 +0000774 // force the system into using unsigned integers for bitfields
775 format = (m_is_bitfield_for_scalar ? eFormatUnsigned :
776 ClangASTType::GetFormat(clang_type));
Enrico Granata4becb372011-06-29 22:27:15 +0000777 }
Greg Clayton32c40852010-10-06 03:09:11 +0000778
779 if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
780 clang_type, // The clang type to display
781 &sstr,
Enrico Granata4becb372011-06-29 22:27:15 +0000782 format, // Format to display this type with
Greg Clayton32c40852010-10-06 03:09:11 +0000783 m_data, // Data to extract from
784 0, // Byte offset into "m_data"
785 GetByteSize(), // Byte size of item in "m_data"
786 GetBitfieldBitSize(), // Bitfield bit size
787 GetBitfieldBitOffset())) // Bitfield bit offset
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000788 m_value_str.swap(sstr.GetString());
789 else
Greg Clayton007d5be2011-05-30 00:49:24 +0000790 {
791 m_error.SetErrorStringWithFormat ("unsufficient data for value (only %u of %u bytes available)",
792 m_data.GetByteSize(),
793 GetByteSize());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000794 m_value_str.clear();
Greg Clayton007d5be2011-05-30 00:49:24 +0000795 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796 }
797 }
798 break;
799
Greg Clayton526e5af2010-11-13 03:52:47 +0000800 case Value::eContextTypeRegisterInfo:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000801 {
802 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
803 if (reg_info)
804 {
805 StreamString reg_sstr;
806 m_data.Dump(&reg_sstr, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
807 m_value_str.swap(reg_sstr.GetString());
808 }
809 }
810 break;
Greg Claytonc982c762010-07-09 20:39:50 +0000811
812 default:
813 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000814 }
815 }
Greg Clayton288bdf92010-09-02 02:59:18 +0000816
817 if (!m_value_did_change && m_old_value_valid)
818 {
819 // The value was gotten successfully, so we consider the
820 // value as changed if the value string differs
821 SetValueDidChange (m_old_value_str != m_value_str);
822 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000823 }
824 }
825 if (m_value_str.empty())
826 return NULL;
827 return m_value_str.c_str();
828}
829
Enrico Granata0a3958e2011-07-02 00:25:22 +0000830const char *
831ValueObject::GetPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
832 lldb::Format custom_format)
833{
834 if(custom_format != lldb::eFormatInvalid)
835 SetFormat(custom_format);
836
837 const char * return_value;
838
839 switch(val_obj_display)
840 {
841 case eDisplayValue:
842 return_value = GetValueAsCString();
843 break;
844 case eDisplaySummary:
845 return_value = GetSummaryAsCString();
846 break;
847 case eDisplayLanguageSpecific:
848 return_value = GetObjectDescription();
849 break;
850 }
851
Enrico Granata9fc19442011-07-06 02:13:41 +0000852 if (!return_value)
853 {
854 // try to pick the other choice
855 if (val_obj_display == eDisplayValue)
856 return_value = GetSummaryAsCString();
857 else if (val_obj_display == eDisplaySummary)
858 return_value = GetValueAsCString();
859 else
860 return_value = "";
861 }
Enrico Granata0a3958e2011-07-02 00:25:22 +0000862
Enrico Granata9fc19442011-07-06 02:13:41 +0000863 return (return_value ? return_value : "");
Enrico Granata0a3958e2011-07-02 00:25:22 +0000864
865}
866
Enrico Granata9fc19442011-07-06 02:13:41 +0000867bool
868ValueObject::DumpPrintableRepresentation(Stream& s,
869 ValueObjectRepresentationStyle val_obj_display,
870 lldb::Format custom_format)
871{
872 const char *targetvalue = GetPrintableRepresentation(val_obj_display, custom_format);
873 if(targetvalue)
874 s.PutCString(targetvalue);
875 bool var_success = (targetvalue != NULL);
876 if(custom_format != eFormatInvalid)
877 SetFormat(eFormatDefault);
878 return var_success;
879}
880
Greg Clayton737b9322010-09-13 03:32:57 +0000881addr_t
Greg Claytone0d378b2011-03-24 21:19:54 +0000882ValueObject::GetAddressOf (AddressType &address_type, bool scalar_is_load_address)
Greg Clayton73b472d2010-10-27 03:32:59 +0000883{
Jim Ingham78a685a2011-04-16 00:01:13 +0000884 if (!UpdateValueIfNeeded())
885 return LLDB_INVALID_ADDRESS;
886
Greg Clayton73b472d2010-10-27 03:32:59 +0000887 switch (m_value.GetValueType())
888 {
889 case Value::eValueTypeScalar:
890 if (scalar_is_load_address)
891 {
892 address_type = eAddressTypeLoad;
893 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
894 }
895 break;
896
897 case Value::eValueTypeLoadAddress:
898 case Value::eValueTypeFileAddress:
899 case Value::eValueTypeHostAddress:
900 {
901 address_type = m_value.GetValueAddressType ();
902 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
903 }
904 break;
905 }
906 address_type = eAddressTypeInvalid;
907 return LLDB_INVALID_ADDRESS;
908}
909
910addr_t
Greg Claytone0d378b2011-03-24 21:19:54 +0000911ValueObject::GetPointerValue (AddressType &address_type, bool scalar_is_load_address)
Greg Clayton737b9322010-09-13 03:32:57 +0000912{
913 lldb::addr_t address = LLDB_INVALID_ADDRESS;
914 address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +0000915
916 if (!UpdateValueIfNeeded())
917 return address;
918
Greg Clayton73b472d2010-10-27 03:32:59 +0000919 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +0000920 {
921 case Value::eValueTypeScalar:
922 if (scalar_is_load_address)
923 {
924 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
925 address_type = eAddressTypeLoad;
926 }
927 break;
928
929 case Value::eValueTypeLoadAddress:
930 case Value::eValueTypeFileAddress:
931 case Value::eValueTypeHostAddress:
932 {
933 uint32_t data_offset = 0;
934 address = m_data.GetPointer(&data_offset);
935 address_type = m_value.GetValueAddressType();
936 if (address_type == eAddressTypeInvalid)
937 address_type = eAddressTypeLoad;
938 }
939 break;
940 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000941
942 if (m_pointers_point_to_load_addrs)
943 address_type = eAddressTypeLoad;
944
Greg Clayton737b9322010-09-13 03:32:57 +0000945 return address;
946}
947
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000948bool
Jim Ingham6035b672011-03-31 00:19:25 +0000949ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000950{
951 // Make sure our value is up to date first so that our location and location
952 // type is valid.
Jim Ingham6035b672011-03-31 00:19:25 +0000953 if (!UpdateValueIfNeeded())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000954 return false;
955
956 uint32_t count = 0;
Greg Clayton1be10fc2010-09-29 01:12:09 +0000957 lldb::Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000958
959 char *end = NULL;
Greg Claytonb1320972010-07-14 00:18:15 +0000960 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000961 switch (encoding)
962 {
963 case eEncodingInvalid:
964 return false;
965
966 case eEncodingUint:
967 if (byte_size > sizeof(unsigned long long))
968 {
969 return false;
970 }
971 else
972 {
973 unsigned long long ull_val = strtoull(value_str, &end, 0);
974 if (end && *end != '\0')
975 return false;
Greg Clayton644247c2011-07-07 01:59:51 +0000976 m_value.GetScalar() = ull_val;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000977 // Limit the bytes in our m_data appropriately.
978 m_value.GetScalar().GetData (m_data, byte_size);
979 }
980 break;
981
982 case eEncodingSint:
983 if (byte_size > sizeof(long long))
984 {
985 return false;
986 }
987 else
988 {
989 long long sll_val = strtoll(value_str, &end, 0);
990 if (end && *end != '\0')
991 return false;
Greg Clayton644247c2011-07-07 01:59:51 +0000992 m_value.GetScalar() = sll_val;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000993 // Limit the bytes in our m_data appropriately.
994 m_value.GetScalar().GetData (m_data, byte_size);
995 }
996 break;
997
998 case eEncodingIEEE754:
999 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001000 const off_t byte_offset = GetByteOffset();
Greg Claytonc982c762010-07-09 20:39:50 +00001001 uint8_t *dst = const_cast<uint8_t *>(m_data.PeekData(byte_offset, byte_size));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001002 if (dst != NULL)
1003 {
1004 // We are decoding a float into host byte order below, so make
1005 // sure m_data knows what it contains.
Greg Clayton7fb56d02011-02-01 01:31:41 +00001006 m_data.SetByteOrder(lldb::endian::InlHostByteOrder());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001007 const size_t converted_byte_size = ClangASTContext::ConvertStringToFloatValue (
1008 GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +00001009 GetClangType(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001010 value_str,
1011 dst,
1012 byte_size);
1013
1014 if (converted_byte_size == byte_size)
1015 {
1016 }
1017 }
1018 }
1019 break;
1020
1021 case eEncodingVector:
1022 return false;
1023
1024 default:
1025 return false;
1026 }
1027
1028 // If we have made it here the value is in m_data and we should write it
1029 // out to the target
1030 return Write ();
1031}
1032
1033bool
1034ValueObject::Write ()
1035{
1036 // Clear the update ID so the next time we try and read the value
1037 // we try and read it again.
Jim Ingham6035b672011-03-31 00:19:25 +00001038 m_update_point.SetNeedsUpdate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001039
1040 // TODO: when Value has a method to write a value back, call it from here.
1041 return false;
1042
1043}
1044
Jim Ingham5a369122010-09-28 01:25:32 +00001045lldb::LanguageType
1046ValueObject::GetObjectRuntimeLanguage ()
1047{
Greg Clayton73b472d2010-10-27 03:32:59 +00001048 clang_type_t opaque_qual_type = GetClangType();
Jim Ingham5a369122010-09-28 01:25:32 +00001049 if (opaque_qual_type == NULL)
1050 return lldb::eLanguageTypeC;
1051
1052 // If the type is a reference, then resolve it to what it refers to first:
1053 clang::QualType qual_type (clang::QualType::getFromOpaquePtr(opaque_qual_type).getNonReferenceType());
1054 if (qual_type->isAnyPointerType())
1055 {
1056 if (qual_type->isObjCObjectPointerType())
1057 return lldb::eLanguageTypeObjC;
1058
1059 clang::QualType pointee_type (qual_type->getPointeeType());
1060 if (pointee_type->getCXXRecordDeclForPointerType() != NULL)
1061 return lldb::eLanguageTypeC_plus_plus;
1062 if (pointee_type->isObjCObjectOrInterfaceType())
1063 return lldb::eLanguageTypeObjC;
1064 if (pointee_type->isObjCClassType())
1065 return lldb::eLanguageTypeObjC;
1066 }
1067 else
1068 {
1069 if (ClangASTContext::IsObjCClassType (opaque_qual_type))
1070 return lldb::eLanguageTypeObjC;
Johnny Chend440bcc2010-09-28 16:10:54 +00001071 if (ClangASTContext::IsCXXClassType (opaque_qual_type))
Jim Ingham5a369122010-09-28 01:25:32 +00001072 return lldb::eLanguageTypeC_plus_plus;
1073 }
1074
1075 return lldb::eLanguageTypeC;
1076}
1077
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001078void
Jim Ingham58b59f92011-04-22 23:53:53 +00001079ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001080{
Jim Ingham58b59f92011-04-22 23:53:53 +00001081 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001082}
1083
1084ValueObjectSP
1085ValueObject::GetSyntheticChild (const ConstString &key) const
1086{
1087 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001088 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001089 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001090 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001091 return synthetic_child_sp;
1092}
1093
1094bool
1095ValueObject::IsPointerType ()
1096{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001097 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001098}
1099
Jim Inghamb7603bb2011-03-18 00:05:18 +00001100bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001101ValueObject::IsScalarType ()
1102{
1103 return ClangASTContext::IsScalarType (GetClangType());
1104}
1105
1106bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001107ValueObject::IsIntegerType (bool &is_signed)
1108{
1109 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1110}
Greg Clayton73b472d2010-10-27 03:32:59 +00001111
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001112bool
1113ValueObject::IsPointerOrReferenceType ()
1114{
Greg Clayton007d5be2011-05-30 00:49:24 +00001115 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1116}
1117
1118bool
1119ValueObject::IsPossibleCPlusPlusDynamicType ()
1120{
1121 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001122}
1123
Greg Claytondea8cb42011-06-29 22:09:02 +00001124bool
1125ValueObject::IsPossibleDynamicType ()
1126{
1127 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1128}
1129
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001130ValueObjectSP
1131ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1132{
1133 ValueObjectSP synthetic_child_sp;
1134 if (IsPointerType ())
1135 {
1136 char index_str[64];
1137 snprintf(index_str, sizeof(index_str), "[%i]", index);
1138 ConstString index_const_str(index_str);
1139 // Check if we have already created a synthetic array member in this
1140 // valid object. If we have we will re-use it.
1141 synthetic_child_sp = GetSyntheticChild (index_const_str);
1142 if (!synthetic_child_sp)
1143 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001144 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001145 // We haven't made a synthetic array member for INDEX yet, so
1146 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001147 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001148
1149 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001150 if (synthetic_child)
1151 {
1152 AddSyntheticChild(index_const_str, synthetic_child);
1153 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata0a3958e2011-07-02 00:25:22 +00001154 synthetic_child_sp->SetName(index_str);
1155 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001156 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001157 }
1158 }
1159 return synthetic_child_sp;
1160}
Jim Ingham22777012010-09-23 02:01:19 +00001161
Enrico Granata9fc19442011-07-06 02:13:41 +00001162ValueObjectSP
1163ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1164{
1165 ValueObjectSP synthetic_child_sp;
1166 if (IsScalarType ())
1167 {
1168 char index_str[64];
1169 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1170 ConstString index_const_str(index_str);
1171 // Check if we have already created a synthetic array member in this
1172 // valid object. If we have we will re-use it.
1173 synthetic_child_sp = GetSyntheticChild (index_const_str);
1174 if (!synthetic_child_sp)
1175 {
1176 ValueObjectChild *synthetic_child;
1177 // We haven't made a synthetic array member for INDEX yet, so
1178 // lets make one and cache it for any future reference.
1179 synthetic_child = new ValueObjectChild(*this,
1180 GetClangAST(),
1181 GetClangType(),
1182 index_const_str,
1183 GetByteSize(),
1184 0,
1185 to-from+1,
1186 from,
1187 false,
1188 false);
1189
1190 // Cache the value if we got one back...
1191 if (synthetic_child)
1192 {
1193 AddSyntheticChild(index_const_str, synthetic_child);
1194 synthetic_child_sp = synthetic_child->GetSP();
1195 synthetic_child_sp->SetName(index_str);
1196 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1197 }
1198 }
1199 }
1200 return synthetic_child_sp;
1201}
1202
Jim Ingham78a685a2011-04-16 00:01:13 +00001203void
Jim Ingham2837b762011-05-04 03:43:18 +00001204ValueObject::CalculateDynamicValue (lldb::DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00001205{
Jim Ingham2837b762011-05-04 03:43:18 +00001206 if (use_dynamic == lldb::eNoDynamicValues)
1207 return;
1208
Jim Ingham58b59f92011-04-22 23:53:53 +00001209 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00001210 {
1211 Process *process = m_update_point.GetProcess();
1212 bool worth_having_dynamic_value = false;
Jim Ingham22777012010-09-23 02:01:19 +00001213
Jim Ingham78a685a2011-04-16 00:01:13 +00001214
1215 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
1216 // hard code this everywhere.
1217 lldb::LanguageType known_type = GetObjectRuntimeLanguage();
1218 if (known_type != lldb::eLanguageTypeUnknown && known_type != lldb::eLanguageTypeC)
1219 {
1220 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
1221 if (runtime)
1222 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
1223 }
1224 else
1225 {
1226 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeC_plus_plus);
1227 if (cpp_runtime)
1228 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
1229
1230 if (!worth_having_dynamic_value)
1231 {
1232 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeObjC);
1233 if (objc_runtime)
Jim Ingham2837b762011-05-04 03:43:18 +00001234 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00001235 }
1236 }
1237
1238 if (worth_having_dynamic_value)
Jim Ingham2837b762011-05-04 03:43:18 +00001239 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham58b59f92011-04-22 23:53:53 +00001240
1241// if (worth_having_dynamic_value)
1242// printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager);
1243
Jim Ingham78a685a2011-04-16 00:01:13 +00001244 }
1245}
1246
Jim Ingham58b59f92011-04-22 23:53:53 +00001247ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00001248ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00001249{
Jim Ingham2837b762011-05-04 03:43:18 +00001250 if (use_dynamic == lldb::eNoDynamicValues)
1251 return ValueObjectSP();
1252
1253 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00001254 {
Jim Ingham2837b762011-05-04 03:43:18 +00001255 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00001256 }
Jim Ingham58b59f92011-04-22 23:53:53 +00001257 if (m_dynamic_value)
1258 return m_dynamic_value->GetSP();
1259 else
1260 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00001261}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001262
Greg Claytone221f822011-01-21 01:59:00 +00001263bool
1264ValueObject::GetBaseClassPath (Stream &s)
1265{
1266 if (IsBaseClass())
1267 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001268 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00001269 clang_type_t clang_type = GetClangType();
1270 std::string cxx_class_name;
1271 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
1272 if (this_had_base_class)
1273 {
1274 if (parent_had_base_class)
1275 s.PutCString("::");
1276 s.PutCString(cxx_class_name.c_str());
1277 }
1278 return parent_had_base_class || this_had_base_class;
1279 }
1280 return false;
1281}
1282
1283
1284ValueObject *
1285ValueObject::GetNonBaseClassParent()
1286{
Jim Ingham78a685a2011-04-16 00:01:13 +00001287 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00001288 {
Jim Ingham78a685a2011-04-16 00:01:13 +00001289 if (GetParent()->IsBaseClass())
1290 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00001291 else
Jim Ingham78a685a2011-04-16 00:01:13 +00001292 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00001293 }
1294 return NULL;
1295}
Greg Clayton1d3afba2010-10-05 00:00:42 +00001296
1297void
Enrico Granata4becb372011-06-29 22:27:15 +00001298ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001299{
Greg Claytone221f822011-01-21 01:59:00 +00001300 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00001301
Enrico Granata4becb372011-06-29 22:27:15 +00001302 if(is_deref_of_parent && epformat == eDereferencePointers) {
1303 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
1304 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
1305 // the eHonorPointers mode is meant to produce strings in this latter format
1306 s.PutCString("*(");
1307 }
Greg Claytone221f822011-01-21 01:59:00 +00001308
Enrico Granata4becb372011-06-29 22:27:15 +00001309 ValueObject* parent = GetParent();
1310
1311 if (parent)
1312 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00001313
1314 // if we are a deref_of_parent just because we are synthetic array
1315 // members made up to allow ptr[%d] syntax to work in variable
1316 // printing, then add our name ([%d]) to the expression path
1317 if(m_is_array_item_for_pointer && epformat == eHonorPointers)
1318 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00001319
Greg Claytone221f822011-01-21 01:59:00 +00001320 if (!IsBaseClass())
1321 {
1322 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001323 {
Greg Claytone221f822011-01-21 01:59:00 +00001324 ValueObject *non_base_class_parent = GetNonBaseClassParent();
1325 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001326 {
Greg Claytone221f822011-01-21 01:59:00 +00001327 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
1328 if (non_base_class_parent_clang_type)
1329 {
1330 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
1331
Enrico Granata4becb372011-06-29 22:27:15 +00001332 if(parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00001333 {
1334 s.PutCString("->");
1335 }
Enrico Granata4becb372011-06-29 22:27:15 +00001336 else
1337 {
1338 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
1339 {
1340 s.PutCString("->");
1341 }
1342 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
1343 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
1344 {
1345 s.PutChar('.');
1346 }
Greg Claytone221f822011-01-21 01:59:00 +00001347 }
1348 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001349 }
Greg Claytone221f822011-01-21 01:59:00 +00001350
1351 const char *name = GetName().GetCString();
1352 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001353 {
Greg Claytone221f822011-01-21 01:59:00 +00001354 if (qualify_cxx_base_classes)
1355 {
1356 if (GetBaseClassPath (s))
1357 s.PutCString("::");
1358 }
1359 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001360 }
1361 }
1362 }
1363
Enrico Granata4becb372011-06-29 22:27:15 +00001364 if (is_deref_of_parent && epformat == eDereferencePointers) {
Greg Claytone221f822011-01-21 01:59:00 +00001365 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00001366 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001367}
1368
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001369void
Greg Clayton1d3afba2010-10-05 00:00:42 +00001370ValueObject::DumpValueObject
1371(
1372 Stream &s,
Greg Clayton1d3afba2010-10-05 00:00:42 +00001373 ValueObject *valobj,
1374 const char *root_valobj_name,
1375 uint32_t ptr_depth,
1376 uint32_t curr_depth,
1377 uint32_t max_depth,
1378 bool show_types,
1379 bool show_location,
1380 bool use_objc,
Jim Ingham2837b762011-05-04 03:43:18 +00001381 lldb::DynamicValueType use_dynamic,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001382 bool scope_already_checked,
1383 bool flat_output
Greg Clayton1d3afba2010-10-05 00:00:42 +00001384)
1385{
Greg Clayton007d5be2011-05-30 00:49:24 +00001386 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00001387 {
Greg Clayton007d5be2011-05-30 00:49:24 +00001388 bool update_success = valobj->UpdateValueIfNeeded ();
1389
1390 if (update_success && use_dynamic != lldb::eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00001391 {
Jim Ingham2837b762011-05-04 03:43:18 +00001392 ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00001393 if (dynamic_value)
1394 valobj = dynamic_value;
1395 }
1396
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001397 clang_type_t clang_type = valobj->GetClangType();
1398
Greg Clayton73b472d2010-10-27 03:32:59 +00001399 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001400 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00001401 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
1402 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001403
1404 const bool print_valobj = flat_output == false || has_value;
1405
1406 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00001407 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001408 if (show_location)
1409 {
Jim Ingham6035b672011-03-31 00:19:25 +00001410 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001411 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00001412
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001413 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00001414
Greg Clayton7c8a9662010-11-02 01:50:16 +00001415 // Always show the type for the top level items.
Greg Claytone221f822011-01-21 01:59:00 +00001416 if (show_types || (curr_depth == 0 && !flat_output))
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001417 s.Printf("(%s) ", valobj->GetTypeName().AsCString("<invalid type>"));
Greg Clayton1d3afba2010-10-05 00:00:42 +00001418
Greg Clayton1d3afba2010-10-05 00:00:42 +00001419
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001420 if (flat_output)
1421 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00001422 // If we are showing types, also qualify the C++ base classes
1423 const bool qualify_cxx_base_classes = show_types;
1424 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001425 s.PutCString(" =");
1426 }
1427 else
1428 {
1429 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
1430 s.Printf ("%s =", name_cstr);
1431 }
1432
Jim Ingham6035b672011-03-31 00:19:25 +00001433 if (!scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001434 {
Greg Clayton007d5be2011-05-30 00:49:24 +00001435 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001436 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00001437 }
1438
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001439 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00001440 const char *sum_cstr = NULL;
1441 SummaryFormat* entry = valobj->m_last_summary_format.get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001442
1443 if (err_cstr == NULL)
1444 {
Jim Ingham6035b672011-03-31 00:19:25 +00001445 val_cstr = valobj->GetValueAsCString();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001446 err_cstr = valobj->GetError().AsCString();
1447 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00001448
1449 if (err_cstr)
1450 {
Greg Clayton007d5be2011-05-30 00:49:24 +00001451 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00001452 }
1453 else
1454 {
Greg Clayton73b472d2010-10-27 03:32:59 +00001455 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001456 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00001457 {
Enrico Granata4becb372011-06-29 22:27:15 +00001458
1459 sum_cstr = valobj->GetSummaryAsCString();
Greg Clayton1d3afba2010-10-05 00:00:42 +00001460
Enrico Granata4becb372011-06-29 22:27:15 +00001461 // We must calculate this value in realtime because entry might alter this variable's value
1462 // (e.g. by saying ${var%fmt}) and render precached values useless
1463 if (val_cstr && (!entry || entry->DoesPrintValue() || !sum_cstr))
1464 s.Printf(" %s", valobj->GetValueAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001465
Enrico Granata0a3958e2011-07-02 00:25:22 +00001466 if(sum_cstr)
1467 {
1468 // for some reason, using %@ (ObjC description) in a summary string, makes
1469 // us believe we need to reset ourselves, thus invalidating the content of
1470 // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty
1471 // let us recalculate it!
1472 if (sum_cstr[0] == '\0')
1473 s.Printf(" %s", valobj->GetSummaryAsCString());
1474 else
1475 s.Printf(" %s", sum_cstr);
1476 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001477
1478 if (use_objc)
1479 {
Jim Ingham6035b672011-03-31 00:19:25 +00001480 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001481 if (object_desc)
1482 s.Printf(" %s\n", object_desc);
1483 else
Sean Callanan672ad942010-10-23 00:18:49 +00001484 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001485 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001486 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001487 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00001488
1489 if (curr_depth < max_depth)
1490 {
Greg Clayton73b472d2010-10-27 03:32:59 +00001491 // We will show children for all concrete types. We won't show
1492 // pointer contents unless a pointer depth has been specified.
1493 // We won't reference contents unless the reference is the
1494 // root object (depth of zero).
1495 bool print_children = true;
1496
1497 // Use a new temporary pointer depth in case we override the
1498 // current pointer depth below...
1499 uint32_t curr_ptr_depth = ptr_depth;
1500
1501 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
1502 if (is_ptr || is_ref)
1503 {
1504 // We have a pointer or reference whose value is an address.
1505 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00001506 AddressType ptr_address_type;
Greg Clayton73b472d2010-10-27 03:32:59 +00001507 if (valobj->GetPointerValue (ptr_address_type, true) == 0)
1508 print_children = false;
1509
1510 else if (is_ref && curr_depth == 0)
1511 {
1512 // If this is the root object (depth is zero) that we are showing
1513 // and it is a reference, and no pointer depth has been supplied
1514 // print out what it references. Don't do this at deeper depths
1515 // otherwise we can end up with infinite recursion...
1516 curr_ptr_depth = 1;
1517 }
1518
1519 if (curr_ptr_depth == 0)
1520 print_children = false;
1521 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00001522
Enrico Granata0a3958e2011-07-02 00:25:22 +00001523 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00001524 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001525 const uint32_t num_children = valobj->GetNumChildren();
1526 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00001527 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001528 if (flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00001529 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001530 if (print_valobj)
1531 s.EOL();
1532 }
1533 else
1534 {
1535 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00001536 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001537 s.IndentMore();
1538 }
1539
1540 for (uint32_t idx=0; idx<num_children; ++idx)
1541 {
1542 ValueObjectSP child_sp(valobj->GetChildAtIndex(idx, true));
1543 if (child_sp.get())
1544 {
1545 DumpValueObject (s,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001546 child_sp.get(),
1547 NULL,
Greg Clayton73b472d2010-10-27 03:32:59 +00001548 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001549 curr_depth + 1,
1550 max_depth,
1551 show_types,
1552 show_location,
1553 false,
Jim Ingham78a685a2011-04-16 00:01:13 +00001554 use_dynamic,
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001555 true,
1556 flat_output);
1557 }
1558 }
1559
1560 if (!flat_output)
1561 {
1562 s.IndentLess();
1563 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00001564 }
1565 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001566 else if (has_children)
1567 {
1568 // Aggregate, no children...
1569 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00001570 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001571 }
1572 else
1573 {
1574 if (print_valobj)
1575 s.EOL();
1576 }
1577
Greg Clayton1d3afba2010-10-05 00:00:42 +00001578 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001579 else
1580 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00001581 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00001582 }
1583 }
1584 else
1585 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001586 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00001587 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00001588 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00001589 }
1590 }
1591 }
1592 }
1593}
1594
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001595
1596ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00001597ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001598{
1599 ValueObjectSP valobj_sp;
1600
Jim Ingham6035b672011-03-31 00:19:25 +00001601 if (UpdateValueIfNeeded() && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001602 {
Jim Ingham6035b672011-03-31 00:19:25 +00001603 ExecutionContextScope *exe_scope = GetExecutionContextScope();
1604 if (exe_scope)
1605 {
1606 ExecutionContext exe_ctx;
1607 exe_scope->CalculateExecutionContext(exe_ctx);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001608
Jim Ingham6035b672011-03-31 00:19:25 +00001609 clang::ASTContext *ast = GetClangAST ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001610
Jim Ingham6035b672011-03-31 00:19:25 +00001611 DataExtractor data;
1612 data.SetByteOrder (m_data.GetByteOrder());
1613 data.SetAddressByteSize(m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001614
Greg Clayton644247c2011-07-07 01:59:51 +00001615 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001616
Jim Ingham58b59f92011-04-22 23:53:53 +00001617 valobj_sp = ValueObjectConstResult::Create (exe_scope,
1618 ast,
1619 GetClangType(),
1620 name,
1621 data);
Jim Ingham6035b672011-03-31 00:19:25 +00001622 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001623 }
Jim Ingham6035b672011-03-31 00:19:25 +00001624
1625 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001626 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001627 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001628 }
1629 return valobj_sp;
1630}
1631
1632lldb::ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00001633ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001634{
Jim Ingham58b59f92011-04-22 23:53:53 +00001635 if (m_deref_valobj)
1636 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00001637
Greg Clayton54979cd2010-12-15 05:08:08 +00001638 const bool is_pointer_type = IsPointerType();
1639 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001640 {
1641 bool omit_empty_base_classes = true;
1642
1643 std::string child_name_str;
1644 uint32_t child_byte_size = 0;
1645 int32_t child_byte_offset = 0;
1646 uint32_t child_bitfield_bit_size = 0;
1647 uint32_t child_bitfield_bit_offset = 0;
1648 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00001649 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001650 const bool transparent_pointers = false;
1651 clang::ASTContext *clang_ast = GetClangAST();
1652 clang_type_t clang_type = GetClangType();
1653 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00001654
1655 ExecutionContext exe_ctx;
1656 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx);
1657
1658 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
1659 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001660 GetName().GetCString(),
1661 clang_type,
1662 0,
1663 transparent_pointers,
1664 omit_empty_base_classes,
1665 child_name_str,
1666 child_byte_size,
1667 child_byte_offset,
1668 child_bitfield_bit_size,
1669 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00001670 child_is_base_class,
1671 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00001672 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001673 {
1674 ConstString child_name;
1675 if (!child_name_str.empty())
1676 child_name.SetCString (child_name_str.c_str());
1677
Jim Ingham58b59f92011-04-22 23:53:53 +00001678 m_deref_valobj = new ValueObjectChild (*this,
1679 clang_ast,
1680 child_clang_type,
1681 child_name,
1682 child_byte_size,
1683 child_byte_offset,
1684 child_bitfield_bit_size,
1685 child_bitfield_bit_offset,
1686 child_is_base_class,
1687 child_is_deref_of_parent);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001688 }
1689 }
Greg Clayton54979cd2010-12-15 05:08:08 +00001690
Jim Ingham58b59f92011-04-22 23:53:53 +00001691 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00001692 {
1693 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00001694 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00001695 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001696 else
1697 {
Greg Clayton54979cd2010-12-15 05:08:08 +00001698 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001699 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00001700
1701 if (is_pointer_type)
1702 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
1703 else
1704 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00001705 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001706 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001707}
1708
Jim Ingham78a685a2011-04-16 00:01:13 +00001709lldb::ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00001710ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001711{
Jim Ingham78a685a2011-04-16 00:01:13 +00001712 if (m_addr_of_valobj_sp)
1713 return m_addr_of_valobj_sp;
1714
Greg Claytone0d378b2011-03-24 21:19:54 +00001715 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001716 const bool scalar_is_load_address = false;
1717 lldb::addr_t addr = GetAddressOf (address_type, scalar_is_load_address);
Greg Clayton54979cd2010-12-15 05:08:08 +00001718 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001719 if (addr != LLDB_INVALID_ADDRESS)
1720 {
1721 switch (address_type)
1722 {
Greg Clayton54979cd2010-12-15 05:08:08 +00001723 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001724 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00001725 {
1726 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00001727 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00001728 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
1729 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001730 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00001731
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001732 case eAddressTypeFile:
1733 case eAddressTypeLoad:
1734 case eAddressTypeHost:
1735 {
1736 clang::ASTContext *ast = GetClangAST();
1737 clang_type_t clang_type = GetClangType();
1738 if (ast && clang_type)
1739 {
1740 std::string name (1, '&');
1741 name.append (m_name.AsCString(""));
Jim Ingham58b59f92011-04-22 23:53:53 +00001742 m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(),
1743 ast,
1744 ClangASTContext::CreatePointerType (ast, clang_type),
1745 ConstString (name.c_str()),
1746 addr,
1747 eAddressTypeInvalid,
1748 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001749 }
1750 }
1751 break;
1752 }
1753 }
Jim Ingham78a685a2011-04-16 00:01:13 +00001754 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001755}
1756
Greg Claytonb2dcc362011-05-05 23:32:56 +00001757
1758lldb::ValueObjectSP
1759ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
1760{
1761 lldb::ValueObjectSP valobj_sp;
1762 AddressType address_type;
1763 const bool scalar_is_load_address = true;
1764 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address);
1765
1766 if (ptr_value != LLDB_INVALID_ADDRESS)
1767 {
1768 Address ptr_addr (NULL, ptr_value);
1769
1770 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
1771 name,
1772 ptr_addr,
1773 clang_ast_type);
1774 }
1775 return valobj_sp;
1776}
1777
1778lldb::ValueObjectSP
1779ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
1780{
1781 lldb::ValueObjectSP valobj_sp;
1782 AddressType address_type;
1783 const bool scalar_is_load_address = true;
1784 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address);
1785
1786 if (ptr_value != LLDB_INVALID_ADDRESS)
1787 {
1788 Address ptr_addr (NULL, ptr_value);
1789
1790 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(),
1791 name,
1792 ptr_addr,
1793 type_sp);
1794 }
1795 return valobj_sp;
1796}
1797
1798
Jim Ingham6035b672011-03-31 00:19:25 +00001799ValueObject::EvaluationPoint::EvaluationPoint () :
Stephen Wilson71c21d12011-04-11 19:41:40 +00001800 m_thread_id (LLDB_INVALID_UID),
1801 m_stop_id (0)
Jim Ingham6035b672011-03-31 00:19:25 +00001802{
1803}
1804
1805ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Jim Ingham6035b672011-03-31 00:19:25 +00001806 m_needs_update (true),
Stephen Wilson71c21d12011-04-11 19:41:40 +00001807 m_first_update (true),
Jim Ingham89b61092011-07-06 17:42:14 +00001808 m_thread_id (LLDB_INVALID_THREAD_ID),
Stephen Wilson71c21d12011-04-11 19:41:40 +00001809 m_stop_id (0)
1810
Jim Ingham6035b672011-03-31 00:19:25 +00001811{
1812 ExecutionContext exe_ctx;
1813 ExecutionContextScope *computed_exe_scope = exe_scope; // If use_selected is true, we may find a better scope,
1814 // and if so we want to cache that not the original.
1815 if (exe_scope)
1816 exe_scope->CalculateExecutionContext(exe_ctx);
1817 if (exe_ctx.target != NULL)
1818 {
1819 m_target_sp = exe_ctx.target->GetSP();
1820
1821 if (exe_ctx.process == NULL)
1822 m_process_sp = exe_ctx.target->GetProcessSP();
1823 else
1824 m_process_sp = exe_ctx.process->GetSP();
1825
1826 if (m_process_sp != NULL)
1827 {
1828 m_stop_id = m_process_sp->GetStopID();
1829 Thread *thread = NULL;
1830
1831 if (exe_ctx.thread == NULL)
1832 {
1833 if (use_selected)
1834 {
1835 thread = m_process_sp->GetThreadList().GetSelectedThread().get();
1836 if (thread)
1837 computed_exe_scope = thread;
1838 }
1839 }
1840 else
1841 thread = exe_ctx.thread;
1842
1843 if (thread != NULL)
1844 {
1845 m_thread_id = thread->GetIndexID();
1846 if (exe_ctx.frame == NULL)
1847 {
1848 if (use_selected)
1849 {
1850 StackFrame *frame = exe_ctx.thread->GetSelectedFrame().get();
1851 if (frame)
1852 {
1853 m_stack_id = frame->GetStackID();
1854 computed_exe_scope = frame;
1855 }
1856 }
1857 }
1858 else
1859 m_stack_id = exe_ctx.frame->GetStackID();
1860 }
1861 }
1862 }
1863 m_exe_scope = computed_exe_scope;
1864}
1865
1866ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
1867 m_exe_scope (rhs.m_exe_scope),
Stephen Wilson71c21d12011-04-11 19:41:40 +00001868 m_needs_update(true),
1869 m_first_update(true),
Jim Ingham6035b672011-03-31 00:19:25 +00001870 m_target_sp (rhs.m_target_sp),
1871 m_process_sp (rhs.m_process_sp),
1872 m_thread_id (rhs.m_thread_id),
1873 m_stack_id (rhs.m_stack_id),
Jim Ingham6035b672011-03-31 00:19:25 +00001874 m_stop_id (0)
1875{
1876}
1877
1878ValueObject::EvaluationPoint::~EvaluationPoint ()
1879{
1880}
1881
1882ExecutionContextScope *
1883ValueObject::EvaluationPoint::GetExecutionContextScope ()
1884{
1885 // We have to update before giving out the scope, or we could be handing out stale pointers.
1886 SyncWithProcessState();
1887
1888 return m_exe_scope;
1889}
1890
1891// This function checks the EvaluationPoint against the current process state. If the current
1892// state matches the evaluation point, or the evaluation point is already invalid, then we return
1893// false, meaning "no change". If the current state is different, we update our state, and return
1894// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
1895// future calls to NeedsUpdate will return true.
1896
1897bool
1898ValueObject::EvaluationPoint::SyncWithProcessState()
1899{
1900 // If we're already invalid, we don't need to do anything, and nothing has changed:
1901 if (m_stop_id == LLDB_INVALID_UID)
1902 {
1903 // Can't update with an invalid state.
1904 m_needs_update = false;
1905 return false;
1906 }
1907
1908 // If we don't have a process nothing can change.
1909 if (!m_process_sp)
1910 return false;
1911
1912 // If our stop id is the current stop ID, nothing has changed:
Jim Ingham78a685a2011-04-16 00:01:13 +00001913 uint32_t cur_stop_id = m_process_sp->GetStopID();
1914 if (m_stop_id == cur_stop_id)
Jim Ingham6035b672011-03-31 00:19:25 +00001915 return false;
1916
Jim Ingham78a685a2011-04-16 00:01:13 +00001917 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
1918 // In either case, we aren't going to be able to sync with the process state.
1919 if (cur_stop_id == 0)
1920 return false;
1921
1922 m_stop_id = cur_stop_id;
Jim Ingham6035b672011-03-31 00:19:25 +00001923 m_needs_update = true;
1924 m_exe_scope = m_process_sp.get();
1925
1926 // Something has changed, so we will return true. Now make sure the thread & frame still exist, and if either
1927 // doesn't, mark ourselves as invalid.
1928
1929 if (m_thread_id != LLDB_INVALID_THREAD_ID)
1930 {
1931 Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get();
1932 if (our_thread == NULL)
Greg Clayton262f80d2011-07-06 16:49:27 +00001933 {
Jim Ingham89b61092011-07-06 17:42:14 +00001934 SetInvalid();
Greg Clayton262f80d2011-07-06 16:49:27 +00001935 }
Jim Ingham6035b672011-03-31 00:19:25 +00001936 else
1937 {
1938 m_exe_scope = our_thread;
1939
1940 if (m_stack_id.IsValid())
1941 {
1942 StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get();
1943 if (our_frame == NULL)
1944 SetInvalid();
1945 else
1946 m_exe_scope = our_frame;
1947 }
1948 }
1949 }
1950 return true;
1951}
1952
Jim Ingham61be0902011-05-02 18:13:59 +00001953void
1954ValueObject::EvaluationPoint::SetUpdated ()
1955{
1956 m_first_update = false;
1957 m_needs_update = false;
1958 if (m_process_sp)
1959 m_stop_id = m_process_sp->GetStopID();
1960}
1961
1962
Jim Ingham6035b672011-03-31 00:19:25 +00001963bool
1964ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
1965{
1966 if (!IsValid())
1967 return false;
1968
1969 bool needs_update = false;
1970 m_exe_scope = NULL;
1971
1972 // The target has to be non-null, and the
1973 Target *target = exe_scope->CalculateTarget();
1974 if (target != NULL)
1975 {
1976 Target *old_target = m_target_sp.get();
1977 assert (target == old_target);
1978 Process *process = exe_scope->CalculateProcess();
1979 if (process != NULL)
1980 {
1981 // FOR NOW - assume you can't update variable objects across process boundaries.
1982 Process *old_process = m_process_sp.get();
1983 assert (process == old_process);
1984
1985 lldb::user_id_t stop_id = process->GetStopID();
1986 if (stop_id != m_stop_id)
1987 {
1988 needs_update = true;
1989 m_stop_id = stop_id;
1990 }
1991 // See if we're switching the thread or stack context. If no thread is given, this is
1992 // being evaluated in a global context.
1993 Thread *thread = exe_scope->CalculateThread();
1994 if (thread != NULL)
1995 {
1996 lldb::user_id_t new_thread_index = thread->GetIndexID();
1997 if (new_thread_index != m_thread_id)
1998 {
1999 needs_update = true;
2000 m_thread_id = new_thread_index;
2001 m_stack_id.Clear();
2002 }
2003
2004 StackFrame *new_frame = exe_scope->CalculateStackFrame();
2005 if (new_frame != NULL)
2006 {
2007 if (new_frame->GetStackID() != m_stack_id)
2008 {
2009 needs_update = true;
2010 m_stack_id = new_frame->GetStackID();
2011 }
2012 }
2013 else
2014 {
2015 m_stack_id.Clear();
2016 needs_update = true;
2017 }
2018 }
2019 else
2020 {
2021 // If this had been given a thread, and now there is none, we should update.
2022 // Otherwise we don't have to do anything.
2023 if (m_thread_id != LLDB_INVALID_UID)
2024 {
2025 m_thread_id = LLDB_INVALID_UID;
2026 m_stack_id.Clear();
2027 needs_update = true;
2028 }
2029 }
2030 }
2031 else
2032 {
2033 // If there is no process, then we don't need to update anything.
2034 // But if we're switching from having a process to not, we should try to update.
2035 if (m_process_sp.get() != NULL)
2036 {
2037 needs_update = true;
2038 m_process_sp.reset();
2039 m_thread_id = LLDB_INVALID_UID;
2040 m_stack_id.Clear();
2041 }
2042 }
2043 }
2044 else
2045 {
2046 // If there's no target, nothing can change so we don't need to update anything.
2047 // But if we're switching from having a target to not, we should try to update.
2048 if (m_target_sp.get() != NULL)
2049 {
2050 needs_update = true;
2051 m_target_sp.reset();
2052 m_process_sp.reset();
2053 m_thread_id = LLDB_INVALID_UID;
2054 m_stack_id.Clear();
2055 }
2056 }
2057 if (!m_needs_update)
2058 m_needs_update = needs_update;
2059
2060 return needs_update;
2061}