Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 13 | #include <stdlib.h> |
| 14 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | // C++ Includes |
| 16 | // Other libraries and framework includes |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "llvm/Support/raw_ostream.h" |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 18 | #include "clang/AST/Type.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | |
| 20 | // Project includes |
| 21 | #include "lldb/Core/DataBufferHeap.h" |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 22 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Core/StreamString.h" |
| 24 | #include "lldb/Core/ValueObjectChild.h" |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 25 | #include "lldb/Core/ValueObjectConstResult.h" |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 26 | #include "lldb/Core/ValueObjectDynamicValue.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | #include "lldb/Core/ValueObjectList.h" |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 28 | #include "lldb/Core/ValueObjectMemory.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | |
Greg Clayton | 7fb56d0 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 30 | #include "lldb/Host/Endian.h" |
| 31 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 32 | #include "lldb/Symbol/ClangASTType.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | #include "lldb/Symbol/ClangASTContext.h" |
| 34 | #include "lldb/Symbol/Type.h" |
| 35 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 36 | #include "lldb/Target/ExecutionContext.h" |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 37 | #include "lldb/Target/LanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | #include "lldb/Target/Process.h" |
| 39 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 40 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | #include "lldb/Target/Thread.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | |
| 43 | using namespace lldb; |
| 44 | using namespace lldb_private; |
| 45 | |
| 46 | static lldb::user_id_t g_value_obj_uid = 0; |
| 47 | |
| 48 | //---------------------------------------------------------------------- |
| 49 | // ValueObject constructor |
| 50 | //---------------------------------------------------------------------- |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 51 | ValueObject::ValueObject (ValueObject &parent) : |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | UserID (++g_value_obj_uid), // Unique identifier for every value object |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 53 | m_parent (&parent), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 54 | m_update_point (parent.GetUpdatePoint ()), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 55 | m_name (), |
| 56 | m_data (), |
| 57 | m_value (), |
| 58 | m_error (), |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 59 | m_value_str (), |
| 60 | m_old_value_str (), |
| 61 | m_location_str (), |
| 62 | m_summary_str (), |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 63 | m_object_desc_str (), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 64 | m_manager(parent.GetManager()), |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 65 | m_children (), |
| 66 | m_synthetic_children (), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 67 | m_dynamic_value (NULL), |
| 68 | m_deref_valobj(NULL), |
Greg Clayton | 32c4085 | 2010-10-06 03:09:11 +0000 | [diff] [blame] | 69 | m_format (eFormatDefault), |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 70 | m_value_is_valid (false), |
| 71 | m_value_did_change (false), |
| 72 | m_children_count_valid (false), |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 73 | m_old_value_valid (false), |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 74 | m_pointers_point_to_load_addrs (false), |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 75 | m_is_deref_of_parent (false), |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 76 | m_is_array_item_for_pointer(false), |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 77 | m_is_bitfield_for_scalar(false), |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 78 | m_last_format_mgr_revision(0), |
| 79 | m_last_summary_format(), |
| 80 | m_last_value_format() |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 81 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 82 | m_manager->ManageObject(this); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | //---------------------------------------------------------------------- |
| 86 | // ValueObject constructor |
| 87 | //---------------------------------------------------------------------- |
| 88 | ValueObject::ValueObject (ExecutionContextScope *exe_scope) : |
| 89 | UserID (++g_value_obj_uid), // Unique identifier for every value object |
| 90 | m_parent (NULL), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 91 | m_update_point (exe_scope), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 92 | 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 Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 101 | m_manager(), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 102 | m_children (), |
| 103 | m_synthetic_children (), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 104 | m_dynamic_value (NULL), |
| 105 | m_deref_valobj(NULL), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 106 | 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 Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 112 | m_is_deref_of_parent (false), |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 113 | m_is_array_item_for_pointer(false), |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 114 | m_is_bitfield_for_scalar(false), |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 115 | m_last_format_mgr_revision(0), |
| 116 | m_last_summary_format(), |
| 117 | m_last_value_format() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 118 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 119 | m_manager = new ValueObjectManager(); |
| 120 | m_manager->ManageObject (this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | //---------------------------------------------------------------------- |
| 124 | // Destructor |
| 125 | //---------------------------------------------------------------------- |
| 126 | ValueObject::~ValueObject () |
| 127 | { |
| 128 | } |
| 129 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 130 | bool |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 131 | ValueObject::UpdateValueIfNeeded (bool update_format) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 132 | { |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 133 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 134 | if (update_format) |
| 135 | UpdateFormatsIfNeeded(); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 136 | |
Greg Clayton | b71f384 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 137 | // 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 Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 142 | bool first_update = m_update_point.IsFirstEvaluation(); |
| 143 | |
| 144 | if (m_update_point.NeedsUpdating()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 146 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 151 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 152 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 163 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 164 | const bool value_was_valid = GetValueIsValid(); |
| 165 | SetValueDidChange (false); |
Greg Clayton | 73b953b | 2010-08-28 00:08:07 +0000 | [diff] [blame] | 166 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 167 | m_error.Clear(); |
Greg Clayton | 73b953b | 2010-08-28 00:08:07 +0000 | [diff] [blame] | 168 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 169 | // 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | return m_error.Success(); |
| 184 | } |
| 185 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 186 | void |
| 187 | ValueObject::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 Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 199 | if (!Debugger::SummaryFormats::Get(*this, m_last_summary_format)) |
| 200 | Debugger::RegexSummaryFormats::Get(*this, m_last_summary_format); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 201 | m_last_format_mgr_revision = Debugger::ValueFormats::GetCurrentRevision(); |
| 202 | m_value_str.clear(); |
| 203 | m_summary_str.clear(); |
| 204 | } |
| 205 | } |
| 206 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 207 | DataExtractor & |
| 208 | ValueObject::GetDataExtractor () |
| 209 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 210 | UpdateValueIfNeeded(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 211 | return m_data; |
| 212 | } |
| 213 | |
| 214 | const Error & |
Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame^] | 215 | ValueObject::GetError() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 216 | { |
Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame^] | 217 | UpdateValueIfNeeded(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 218 | return m_error; |
| 219 | } |
| 220 | |
| 221 | const ConstString & |
| 222 | ValueObject::GetName() const |
| 223 | { |
| 224 | return m_name; |
| 225 | } |
| 226 | |
| 227 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 228 | ValueObject::GetLocationAsCString () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 229 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 230 | if (UpdateValueIfNeeded()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 231 | { |
| 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 Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 242 | if (m_value.GetContextType() == Value::eContextTypeRegisterInfo) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 243 | { |
| 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 | |
| 272 | Value & |
| 273 | ValueObject::GetValue() |
| 274 | { |
| 275 | return m_value; |
| 276 | } |
| 277 | |
| 278 | const Value & |
| 279 | ValueObject::GetValue() const |
| 280 | { |
| 281 | return m_value; |
| 282 | } |
| 283 | |
| 284 | bool |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 285 | ValueObject::ResolveValue (Scalar &scalar) |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 286 | { |
| 287 | ExecutionContext exe_ctx; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 288 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 289 | if (exe_scope) |
| 290 | exe_scope->CalculateExecutionContext(exe_ctx); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 291 | scalar = m_value.ResolveValue(&exe_ctx, GetClangAST ()); |
| 292 | return scalar.IsValid(); |
| 293 | } |
| 294 | |
| 295 | bool |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 296 | ValueObject::GetValueIsValid () const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 297 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 298 | return m_value_is_valid; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | |
| 302 | void |
| 303 | ValueObject::SetValueIsValid (bool b) |
| 304 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 305 | m_value_is_valid = b; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | bool |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 309 | ValueObject::GetValueDidChange () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 310 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 311 | GetValueAsCString (); |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 312 | return m_value_did_change; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void |
| 316 | ValueObject::SetValueDidChange (bool value_changed) |
| 317 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 318 | m_value_did_change = value_changed; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | ValueObjectSP |
| 322 | ValueObject::GetChildAtIndex (uint32_t idx, bool can_create) |
| 323 | { |
| 324 | ValueObjectSP child_sp; |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 325 | // We may need to update our value if we are dynamic |
| 326 | if (IsPossibleDynamicType ()) |
| 327 | UpdateValueIfNeeded(); |
| 328 | if (idx < GetNumChildren()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 329 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 330 | // Check if we have already made the child value object? |
| 331 | if (can_create && m_children[idx] == NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 332 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 333 | // 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 Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 336 | } |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 337 | |
| 338 | if (m_children[idx] != NULL) |
| 339 | return m_children[idx]->GetSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 340 | } |
| 341 | return child_sp; |
| 342 | } |
| 343 | |
| 344 | uint32_t |
| 345 | ValueObject::GetIndexOfChildWithName (const ConstString &name) |
| 346 | { |
| 347 | bool omit_empty_base_classes = true; |
| 348 | return ClangASTContext::GetIndexOfChildWithName (GetClangAST(), |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 349 | GetClangType(), |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 350 | name.GetCString(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 351 | omit_empty_base_classes); |
| 352 | } |
| 353 | |
| 354 | ValueObjectSP |
| 355 | ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create) |
| 356 | { |
Greg Clayton | 710dd5a | 2011-01-08 20:28:42 +0000 | [diff] [blame] | 357 | // when getting a child by name, it could be buried inside some base |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 358 | // 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 360 | ValueObjectSP child_sp; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 361 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 362 | // 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 376 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 377 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 382 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 383 | if (child_sp) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 384 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 385 | ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create)); |
| 386 | child_sp = new_child_sp; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 387 | } |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 388 | else |
| 389 | { |
| 390 | child_sp.reset(); |
| 391 | } |
| 392 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | return child_sp; |
| 396 | } |
| 397 | |
| 398 | |
| 399 | uint32_t |
| 400 | ValueObject::GetNumChildren () |
| 401 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 402 | if (!m_children_count_valid) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 403 | { |
| 404 | SetNumChildren (CalculateNumChildren()); |
| 405 | } |
| 406 | return m_children.size(); |
| 407 | } |
| 408 | void |
| 409 | ValueObject::SetNumChildren (uint32_t num_children) |
| 410 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 411 | m_children_count_valid = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 412 | m_children.resize(num_children); |
| 413 | } |
| 414 | |
| 415 | void |
| 416 | ValueObject::SetName (const char *name) |
| 417 | { |
| 418 | m_name.SetCString(name); |
| 419 | } |
| 420 | |
| 421 | void |
| 422 | ValueObject::SetName (const ConstString &name) |
| 423 | { |
| 424 | m_name = name; |
| 425 | } |
| 426 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 427 | ValueObject * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 428 | ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index) |
| 429 | { |
Jim Ingham | 2eec487 | 2011-05-07 00:10:58 +0000 | [diff] [blame] | 430 | ValueObject *valobj = NULL; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 431 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 432 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 465 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 466 | if (synthetic_index) |
| 467 | child_byte_offset += child_byte_size * synthetic_index; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 468 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 469 | ConstString child_name; |
| 470 | if (!child_name_str.empty()) |
| 471 | child_name.SetCString (child_name_str.c_str()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 472 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 473 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 485 | } |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 486 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 487 | return valobj; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 491 | ValueObject::GetSummaryAsCString () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 492 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 493 | if (UpdateValueIfNeeded ()) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 494 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 495 | if (m_summary_str.empty()) |
| 496 | { |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 497 | 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 Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 503 | |
| 504 | if (m_last_summary_format->m_show_members_oneliner) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 505 | { |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 506 | 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 Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 521 | s.PutCString(child_sp.get()->GetPrintableRepresentation()); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 522 | } |
| 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 Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 533 | } |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 534 | 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 Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 544 | } |
| 545 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 546 | clang_type_t clang_type = GetClangType(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 547 | |
| 548 | // See if this is a pointer to a C string? |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 549 | if (clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 550 | { |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 551 | StreamString sstr; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 552 | clang_type_t elem_or_pointee_clang_type; |
| 553 | const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 554 | GetClangAST(), |
| 555 | &elem_or_pointee_clang_type)); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 556 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 557 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 558 | if (exe_scope) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 559 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 560 | if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) && |
| 561 | ClangASTContext::IsCharType (elem_or_pointee_clang_type)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 562 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 563 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 568 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 569 | size_t cstr_len = 0; |
| 570 | if (type_flags.Test (ClangASTContext::eTypeIsArray)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 571 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 572 | // We have an array |
| 573 | cstr_len = ClangASTContext::GetArraySize (clang_type); |
| 574 | cstr_address = GetAddressOf (cstr_address_type, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 575 | } |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 576 | else |
| 577 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 578 | // We have a pointer |
| 579 | cstr_address = GetPointerValue (cstr_address_type, true); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 580 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 581 | if (cstr_address != LLDB_INVALID_ADDRESS) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 582 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 583 | DataExtractor data; |
| 584 | size_t bytes_read = 0; |
| 585 | std::vector<char> data_buffer; |
| 586 | Error error; |
| 587 | if (cstr_len > 0) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 588 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 589 | 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 Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 593 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 594 | sstr << '"'; |
| 595 | data.Dump (&sstr, |
| 596 | 0, // Start offset in "data" |
Greg Clayton | 4e4294b | 2011-06-17 23:50:44 +0000 | [diff] [blame] | 597 | eFormatCharArray, // Print as characters |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 598 | 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 Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 605 | } |
| 606 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 607 | 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 Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 613 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 614 | 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 Clayton | 4e4294b | 2011-06-17 23:50:44 +0000 | [diff] [blame] | 627 | eFormatCharArray, // Print as characters |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 628 | 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 Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 642 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 643 | |
| 644 | if (sstr.GetSize() > 0) |
| 645 | m_summary_str.assign (sstr.GetData(), sstr.GetSize()); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 646 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 647 | else if (ClangASTContext::IsFunctionPointerType (clang_type)) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 648 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 649 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | } |
| 692 | if (m_summary_str.empty()) |
| 693 | return NULL; |
| 694 | return m_summary_str.c_str(); |
| 695 | } |
| 696 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 697 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 698 | ValueObject::GetObjectDescription () |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 699 | { |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 700 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 701 | if (!UpdateValueIfNeeded ()) |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 702 | return NULL; |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 703 | |
| 704 | if (!m_object_desc_str.empty()) |
| 705 | return m_object_desc_str.c_str(); |
| 706 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 707 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 708 | if (exe_scope == NULL) |
| 709 | return NULL; |
| 710 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 711 | Process *process = exe_scope->CalculateProcess(); |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 712 | if (process == NULL) |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 713 | return NULL; |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 714 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 715 | StreamString s; |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 716 | |
| 717 | lldb::LanguageType language = GetObjectRuntimeLanguage(); |
| 718 | LanguageRuntime *runtime = process->GetLanguageRuntime(language); |
| 719 | |
Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 720 | if (runtime == NULL) |
| 721 | { |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 722 | // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway... |
Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 723 | clang_type_t opaque_qual_type = GetClangType(); |
| 724 | if (opaque_qual_type != NULL) |
| 725 | { |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 726 | bool is_signed; |
| 727 | if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed) |
| 728 | || ClangASTContext::IsPointerType (opaque_qual_type)) |
| 729 | { |
Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 730 | runtime = process->GetLanguageRuntime(lldb::eLanguageTypeObjC); |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 731 | } |
Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | |
Jim Ingham | 8d543de | 2011-03-31 23:01:21 +0000 | [diff] [blame] | 735 | if (runtime && runtime->GetObjectDescription(s, *this)) |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 736 | { |
| 737 | m_object_desc_str.append (s.GetData()); |
| 738 | } |
Sean Callanan | 672ad94 | 2010-10-23 00:18:49 +0000 | [diff] [blame] | 739 | |
| 740 | if (m_object_desc_str.empty()) |
| 741 | return NULL; |
| 742 | else |
| 743 | return m_object_desc_str.c_str(); |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 744 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 745 | |
| 746 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 747 | ValueObject::GetValueAsCString () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 748 | { |
| 749 | // If our byte size is zero this is an aggregate type that has children |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 750 | if (ClangASTContext::IsAggregateType (GetClangType()) == false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 751 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 752 | if (UpdateValueIfNeeded()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 753 | { |
| 754 | if (m_value_str.empty()) |
| 755 | { |
| 756 | const Value::ContextType context_type = m_value.GetContextType(); |
| 757 | |
| 758 | switch (context_type) |
| 759 | { |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 760 | case Value::eContextTypeClangType: |
| 761 | case Value::eContextTypeLLDBType: |
| 762 | case Value::eContextTypeVariable: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 763 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 764 | clang_type_t clang_type = GetClangType (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 765 | if (clang_type) |
| 766 | { |
| 767 | StreamString sstr; |
Greg Clayton | 68ebae6 | 2011-04-28 20:55:26 +0000 | [diff] [blame] | 768 | Format format = GetFormat(); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 769 | if (format == eFormatDefault) |
| 770 | { |
| 771 | if (m_last_value_format) |
| 772 | format = m_last_value_format->m_format; |
| 773 | else |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 774 | // force the system into using unsigned integers for bitfields |
| 775 | format = (m_is_bitfield_for_scalar ? eFormatUnsigned : |
| 776 | ClangASTType::GetFormat(clang_type)); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 777 | } |
Greg Clayton | 32c4085 | 2010-10-06 03:09:11 +0000 | [diff] [blame] | 778 | |
| 779 | if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST |
| 780 | clang_type, // The clang type to display |
| 781 | &sstr, |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 782 | format, // Format to display this type with |
Greg Clayton | 32c4085 | 2010-10-06 03:09:11 +0000 | [diff] [blame] | 783 | 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 788 | m_value_str.swap(sstr.GetString()); |
| 789 | else |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 790 | { |
| 791 | m_error.SetErrorStringWithFormat ("unsufficient data for value (only %u of %u bytes available)", |
| 792 | m_data.GetByteSize(), |
| 793 | GetByteSize()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 794 | m_value_str.clear(); |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 795 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 796 | } |
| 797 | } |
| 798 | break; |
| 799 | |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 800 | case Value::eContextTypeRegisterInfo: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 801 | { |
| 802 | const RegisterInfo *reg_info = m_value.GetRegisterInfo(); |
| 803 | if (reg_info) |
| 804 | { |
| 805 | StreamString reg_sstr; |
| 806 | m_data.Dump(®_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 Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 811 | |
| 812 | default: |
| 813 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 814 | } |
| 815 | } |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 816 | |
| 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 823 | } |
| 824 | } |
| 825 | if (m_value_str.empty()) |
| 826 | return NULL; |
| 827 | return m_value_str.c_str(); |
| 828 | } |
| 829 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 830 | const char * |
| 831 | ValueObject::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 Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 852 | 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 Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 862 | |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 863 | return (return_value ? return_value : ""); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 864 | |
| 865 | } |
| 866 | |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 867 | bool |
| 868 | ValueObject::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 Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 881 | addr_t |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 882 | ValueObject::GetAddressOf (AddressType &address_type, bool scalar_is_load_address) |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 883 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 884 | if (!UpdateValueIfNeeded()) |
| 885 | return LLDB_INVALID_ADDRESS; |
| 886 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 887 | 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 | |
| 910 | addr_t |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 911 | ValueObject::GetPointerValue (AddressType &address_type, bool scalar_is_load_address) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 912 | { |
| 913 | lldb::addr_t address = LLDB_INVALID_ADDRESS; |
| 914 | address_type = eAddressTypeInvalid; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 915 | |
| 916 | if (!UpdateValueIfNeeded()) |
| 917 | return address; |
| 918 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 919 | switch (m_value.GetValueType()) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 920 | { |
| 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 Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 941 | |
| 942 | if (m_pointers_point_to_load_addrs) |
| 943 | address_type = eAddressTypeLoad; |
| 944 | |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 945 | return address; |
| 946 | } |
| 947 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 948 | bool |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 949 | ValueObject::SetValueFromCString (const char *value_str) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 950 | { |
| 951 | // Make sure our value is up to date first so that our location and location |
| 952 | // type is valid. |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 953 | if (!UpdateValueIfNeeded()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 954 | return false; |
| 955 | |
| 956 | uint32_t count = 0; |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 957 | lldb::Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 958 | |
| 959 | char *end = NULL; |
Greg Clayton | b132097 | 2010-07-14 00:18:15 +0000 | [diff] [blame] | 960 | const size_t byte_size = GetByteSize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 961 | 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; |
| 976 | m_value = ull_val; |
| 977 | // 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; |
| 992 | m_value = sll_val; |
| 993 | // 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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1000 | const off_t byte_offset = GetByteOffset(); |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1001 | uint8_t *dst = const_cast<uint8_t *>(m_data.PeekData(byte_offset, byte_size)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1002 | 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 Clayton | 7fb56d0 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 1006 | m_data.SetByteOrder(lldb::endian::InlHostByteOrder()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1007 | const size_t converted_byte_size = ClangASTContext::ConvertStringToFloatValue ( |
| 1008 | GetClangAST(), |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1009 | GetClangType(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1010 | 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 | |
| 1033 | bool |
| 1034 | ValueObject::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 Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1038 | m_update_point.SetNeedsUpdate(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1039 | |
| 1040 | // TODO: when Value has a method to write a value back, call it from here. |
| 1041 | return false; |
| 1042 | |
| 1043 | } |
| 1044 | |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1045 | lldb::LanguageType |
| 1046 | ValueObject::GetObjectRuntimeLanguage () |
| 1047 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1048 | clang_type_t opaque_qual_type = GetClangType(); |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1049 | 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 Chen | d440bcc | 2010-09-28 16:10:54 +0000 | [diff] [blame] | 1071 | if (ClangASTContext::IsCXXClassType (opaque_qual_type)) |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1072 | return lldb::eLanguageTypeC_plus_plus; |
| 1073 | } |
| 1074 | |
| 1075 | return lldb::eLanguageTypeC; |
| 1076 | } |
| 1077 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1078 | void |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1079 | ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1080 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1081 | m_synthetic_children[key] = valobj; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | ValueObjectSP |
| 1085 | ValueObject::GetSyntheticChild (const ConstString &key) const |
| 1086 | { |
| 1087 | ValueObjectSP synthetic_child_sp; |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1088 | std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1089 | if (pos != m_synthetic_children.end()) |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1090 | synthetic_child_sp = pos->second->GetSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1091 | return synthetic_child_sp; |
| 1092 | } |
| 1093 | |
| 1094 | bool |
| 1095 | ValueObject::IsPointerType () |
| 1096 | { |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1097 | return ClangASTContext::IsPointerType (GetClangType()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 1100 | bool |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1101 | ValueObject::IsScalarType () |
| 1102 | { |
| 1103 | return ClangASTContext::IsScalarType (GetClangType()); |
| 1104 | } |
| 1105 | |
| 1106 | bool |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 1107 | ValueObject::IsIntegerType (bool &is_signed) |
| 1108 | { |
| 1109 | return ClangASTContext::IsIntegerType (GetClangType(), is_signed); |
| 1110 | } |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1111 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1112 | bool |
| 1113 | ValueObject::IsPointerOrReferenceType () |
| 1114 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 1115 | return ClangASTContext::IsPointerOrReferenceType (GetClangType()); |
| 1116 | } |
| 1117 | |
| 1118 | bool |
| 1119 | ValueObject::IsPossibleCPlusPlusDynamicType () |
| 1120 | { |
| 1121 | return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 1124 | bool |
| 1125 | ValueObject::IsPossibleDynamicType () |
| 1126 | { |
| 1127 | return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType()); |
| 1128 | } |
| 1129 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1130 | ValueObjectSP |
| 1131 | ValueObject::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 Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1144 | ValueObject *synthetic_child; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1145 | // We haven't made a synthetic array member for INDEX yet, so |
| 1146 | // lets make one and cache it for any future reference. |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1147 | synthetic_child = CreateChildAtIndex(0, true, index); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1148 | |
| 1149 | // Cache the value if we got one back... |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1150 | if (synthetic_child) |
| 1151 | { |
| 1152 | AddSyntheticChild(index_const_str, synthetic_child); |
| 1153 | synthetic_child_sp = synthetic_child->GetSP(); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1154 | synthetic_child_sp->SetName(index_str); |
| 1155 | synthetic_child_sp->m_is_array_item_for_pointer = true; |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1156 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1157 | } |
| 1158 | } |
| 1159 | return synthetic_child_sp; |
| 1160 | } |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1161 | |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1162 | ValueObjectSP |
| 1163 | ValueObject::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 Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1203 | void |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1204 | ValueObject::CalculateDynamicValue (lldb::DynamicValueType use_dynamic) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1205 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1206 | if (use_dynamic == lldb::eNoDynamicValues) |
| 1207 | return; |
| 1208 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1209 | if (!m_dynamic_value && !IsDynamic()) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1210 | { |
| 1211 | Process *process = m_update_point.GetProcess(); |
| 1212 | bool worth_having_dynamic_value = false; |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1213 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1214 | |
| 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 Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1234 | worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | if (worth_having_dynamic_value) |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1239 | m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1240 | |
| 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 Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1244 | } |
| 1245 | } |
| 1246 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1247 | ValueObjectSP |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1248 | ValueObject::GetDynamicValue (DynamicValueType use_dynamic) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1249 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1250 | if (use_dynamic == lldb::eNoDynamicValues) |
| 1251 | return ValueObjectSP(); |
| 1252 | |
| 1253 | if (!IsDynamic() && m_dynamic_value == NULL) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1254 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1255 | CalculateDynamicValue(use_dynamic); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1256 | } |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1257 | if (m_dynamic_value) |
| 1258 | return m_dynamic_value->GetSP(); |
| 1259 | else |
| 1260 | return ValueObjectSP(); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1261 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1262 | |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1263 | bool |
| 1264 | ValueObject::GetBaseClassPath (Stream &s) |
| 1265 | { |
| 1266 | if (IsBaseClass()) |
| 1267 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1268 | bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1269 | 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 | |
| 1284 | ValueObject * |
| 1285 | ValueObject::GetNonBaseClassParent() |
| 1286 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1287 | if (GetParent()) |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1288 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1289 | if (GetParent()->IsBaseClass()) |
| 1290 | return GetParent()->GetNonBaseClassParent(); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1291 | else |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1292 | return GetParent(); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1293 | } |
| 1294 | return NULL; |
| 1295 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1296 | |
| 1297 | void |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1298 | ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1299 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1300 | const bool is_deref_of_parent = IsDereferenceOfParent (); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1301 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1302 | 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 Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1308 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1309 | ValueObject* parent = GetParent(); |
| 1310 | |
| 1311 | if (parent) |
| 1312 | parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1313 | |
| 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 Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1319 | |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1320 | if (!IsBaseClass()) |
| 1321 | { |
| 1322 | if (!is_deref_of_parent) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1323 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1324 | ValueObject *non_base_class_parent = GetNonBaseClassParent(); |
| 1325 | if (non_base_class_parent) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1326 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1327 | 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 Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1332 | if(parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers) |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1333 | { |
| 1334 | s.PutCString("->"); |
| 1335 | } |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1336 | 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 Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1347 | } |
| 1348 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1349 | } |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1350 | |
| 1351 | const char *name = GetName().GetCString(); |
| 1352 | if (name) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1353 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1354 | if (qualify_cxx_base_classes) |
| 1355 | { |
| 1356 | if (GetBaseClassPath (s)) |
| 1357 | s.PutCString("::"); |
| 1358 | } |
| 1359 | s.PutCString(name); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1360 | } |
| 1361 | } |
| 1362 | } |
| 1363 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1364 | if (is_deref_of_parent && epformat == eDereferencePointers) { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1365 | s.PutChar(')'); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1366 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1367 | } |
| 1368 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1369 | void |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1370 | ValueObject::DumpValueObject |
| 1371 | ( |
| 1372 | Stream &s, |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1373 | 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 Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1381 | lldb::DynamicValueType use_dynamic, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1382 | bool scope_already_checked, |
| 1383 | bool flat_output |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1384 | ) |
| 1385 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 1386 | if (valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1387 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 1388 | bool update_success = valobj->UpdateValueIfNeeded (); |
| 1389 | |
| 1390 | if (update_success && use_dynamic != lldb::eNoDynamicValues) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1391 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1392 | ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1393 | if (dynamic_value) |
| 1394 | valobj = dynamic_value; |
| 1395 | } |
| 1396 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1397 | clang_type_t clang_type = valobj->GetClangType(); |
| 1398 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1399 | const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL)); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1400 | const char *err_cstr = NULL; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1401 | const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren); |
| 1402 | const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1403 | |
| 1404 | const bool print_valobj = flat_output == false || has_value; |
| 1405 | |
| 1406 | if (print_valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1407 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1408 | if (show_location) |
| 1409 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1410 | s.Printf("%s: ", valobj->GetLocationAsCString()); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1411 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1412 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1413 | s.Indent(); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1414 | |
Greg Clayton | 7c8a966 | 2010-11-02 01:50:16 +0000 | [diff] [blame] | 1415 | // Always show the type for the top level items. |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1416 | if (show_types || (curr_depth == 0 && !flat_output)) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1417 | s.Printf("(%s) ", valobj->GetTypeName().AsCString("<invalid type>")); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1418 | |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1419 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1420 | if (flat_output) |
| 1421 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1422 | // 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 Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1425 | 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 Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1433 | if (!scope_already_checked && !valobj->IsInScope()) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1434 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 1435 | err_cstr = "out of scope"; |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1436 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1439 | const char *val_cstr = NULL; |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1440 | const char *sum_cstr = NULL; |
| 1441 | SummaryFormat* entry = valobj->m_last_summary_format.get(); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1442 | |
| 1443 | if (err_cstr == NULL) |
| 1444 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1445 | val_cstr = valobj->GetValueAsCString(); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1446 | err_cstr = valobj->GetError().AsCString(); |
| 1447 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1448 | |
| 1449 | if (err_cstr) |
| 1450 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 1451 | s.Printf (" <%s>\n", err_cstr); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1452 | } |
| 1453 | else |
| 1454 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1455 | const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1456 | if (print_valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1457 | { |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1458 | |
| 1459 | sum_cstr = valobj->GetSummaryAsCString(); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1460 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1461 | // 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 Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1465 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1466 | 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 Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1477 | |
| 1478 | if (use_objc) |
| 1479 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1480 | const char *object_desc = valobj->GetObjectDescription(); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1481 | if (object_desc) |
| 1482 | s.Printf(" %s\n", object_desc); |
| 1483 | else |
Sean Callanan | 672ad94 | 2010-10-23 00:18:49 +0000 | [diff] [blame] | 1484 | s.Printf (" [no Objective-C description available]\n"); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1485 | return; |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1486 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1487 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1488 | |
| 1489 | if (curr_depth < max_depth) |
| 1490 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1491 | // 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 Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1506 | AddressType ptr_address_type; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1507 | 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 Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1522 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1523 | if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr)) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1524 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1525 | const uint32_t num_children = valobj->GetNumChildren(); |
| 1526 | if (num_children) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1527 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1528 | if (flat_output) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1529 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1530 | if (print_valobj) |
| 1531 | s.EOL(); |
| 1532 | } |
| 1533 | else |
| 1534 | { |
| 1535 | if (print_valobj) |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 1536 | s.PutCString(is_ref ? ": {\n" : " {\n"); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1537 | 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 Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1546 | child_sp.get(), |
| 1547 | NULL, |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1548 | (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1549 | curr_depth + 1, |
| 1550 | max_depth, |
| 1551 | show_types, |
| 1552 | show_location, |
| 1553 | false, |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1554 | use_dynamic, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1555 | true, |
| 1556 | flat_output); |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | if (!flat_output) |
| 1561 | { |
| 1562 | s.IndentLess(); |
| 1563 | s.Indent("}\n"); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1564 | } |
| 1565 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1566 | else if (has_children) |
| 1567 | { |
| 1568 | // Aggregate, no children... |
| 1569 | if (print_valobj) |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1570 | s.PutCString(" {}\n"); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1571 | } |
| 1572 | else |
| 1573 | { |
| 1574 | if (print_valobj) |
| 1575 | s.EOL(); |
| 1576 | } |
| 1577 | |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1578 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1579 | else |
| 1580 | { |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1581 | s.EOL(); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1582 | } |
| 1583 | } |
| 1584 | else |
| 1585 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1586 | if (has_children && print_valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1587 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1588 | s.PutCString("{...}\n"); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1589 | } |
| 1590 | } |
| 1591 | } |
| 1592 | } |
| 1593 | } |
| 1594 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1595 | |
| 1596 | ValueObjectSP |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1597 | ValueObject::CreateConstantValue (const ConstString &name) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1598 | { |
| 1599 | ValueObjectSP valobj_sp; |
| 1600 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1601 | if (UpdateValueIfNeeded() && m_error.Success()) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1602 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1603 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 1604 | if (exe_scope) |
| 1605 | { |
| 1606 | ExecutionContext exe_ctx; |
| 1607 | exe_scope->CalculateExecutionContext(exe_ctx); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1608 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1609 | clang::ASTContext *ast = GetClangAST (); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1610 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1611 | DataExtractor data; |
| 1612 | data.SetByteOrder (m_data.GetByteOrder()); |
| 1613 | data.SetAddressByteSize(m_data.GetAddressByteSize()); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1614 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1615 | m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1616 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1617 | valobj_sp = ValueObjectConstResult::Create (exe_scope, |
| 1618 | ast, |
| 1619 | GetClangType(), |
| 1620 | name, |
| 1621 | data); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1622 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1623 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1624 | |
| 1625 | if (!valobj_sp) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1626 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1627 | valobj_sp = ValueObjectConstResult::Create (NULL, m_error); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1628 | } |
| 1629 | return valobj_sp; |
| 1630 | } |
| 1631 | |
| 1632 | lldb::ValueObjectSP |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1633 | ValueObject::Dereference (Error &error) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1634 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1635 | if (m_deref_valobj) |
| 1636 | return m_deref_valobj->GetSP(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1637 | |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1638 | const bool is_pointer_type = IsPointerType(); |
| 1639 | if (is_pointer_type) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1640 | { |
| 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 Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1649 | bool child_is_deref_of_parent = false; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1650 | 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 Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 1654 | |
| 1655 | ExecutionContext exe_ctx; |
| 1656 | GetExecutionContextScope()->CalculateExecutionContext (exe_ctx); |
| 1657 | |
| 1658 | child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx, |
| 1659 | clang_ast, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1660 | 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 Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1670 | child_is_base_class, |
| 1671 | child_is_deref_of_parent); |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 1672 | if (child_clang_type && child_byte_size) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1673 | { |
| 1674 | ConstString child_name; |
| 1675 | if (!child_name_str.empty()) |
| 1676 | child_name.SetCString (child_name_str.c_str()); |
| 1677 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1678 | 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 Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1688 | } |
| 1689 | } |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1690 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1691 | if (m_deref_valobj) |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1692 | { |
| 1693 | error.Clear(); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1694 | return m_deref_valobj->GetSP(); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1695 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1696 | else |
| 1697 | { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1698 | StreamString strm; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1699 | GetExpressionPath(strm, true); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1700 | |
| 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 Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1705 | return ValueObjectSP(); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1706 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1707 | } |
| 1708 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1709 | lldb::ValueObjectSP |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1710 | ValueObject::AddressOf (Error &error) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1711 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1712 | if (m_addr_of_valobj_sp) |
| 1713 | return m_addr_of_valobj_sp; |
| 1714 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1715 | AddressType address_type = eAddressTypeInvalid; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1716 | const bool scalar_is_load_address = false; |
| 1717 | lldb::addr_t addr = GetAddressOf (address_type, scalar_is_load_address); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1718 | error.Clear(); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1719 | if (addr != LLDB_INVALID_ADDRESS) |
| 1720 | { |
| 1721 | switch (address_type) |
| 1722 | { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1723 | default: |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1724 | case eAddressTypeInvalid: |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1725 | { |
| 1726 | StreamString expr_path_strm; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1727 | GetExpressionPath(expr_path_strm, true); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1728 | error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str()); |
| 1729 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1730 | break; |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1731 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1732 | 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 Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1742 | 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 Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1749 | } |
| 1750 | } |
| 1751 | break; |
| 1752 | } |
| 1753 | } |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1754 | return m_addr_of_valobj_sp; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 1757 | |
| 1758 | lldb::ValueObjectSP |
| 1759 | ValueObject::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 | |
| 1778 | lldb::ValueObjectSP |
| 1779 | ValueObject::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 Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1799 | ValueObject::EvaluationPoint::EvaluationPoint () : |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 1800 | m_thread_id (LLDB_INVALID_UID), |
| 1801 | m_stop_id (0) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1802 | { |
| 1803 | } |
| 1804 | |
| 1805 | ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected): |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1806 | m_needs_update (true), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 1807 | m_first_update (true), |
| 1808 | m_thread_id (LLDB_INVALID_UID), |
| 1809 | m_stop_id (0) |
| 1810 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1811 | { |
| 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 | |
| 1866 | ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) : |
| 1867 | m_exe_scope (rhs.m_exe_scope), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 1868 | m_needs_update(true), |
| 1869 | m_first_update(true), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1870 | 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 Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1874 | m_stop_id (0) |
| 1875 | { |
| 1876 | } |
| 1877 | |
| 1878 | ValueObject::EvaluationPoint::~EvaluationPoint () |
| 1879 | { |
| 1880 | } |
| 1881 | |
| 1882 | ExecutionContextScope * |
| 1883 | ValueObject::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 | |
| 1897 | bool |
| 1898 | ValueObject::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 Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1913 | uint32_t cur_stop_id = m_process_sp->GetStopID(); |
| 1914 | if (m_stop_id == cur_stop_id) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1915 | return false; |
| 1916 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1917 | // 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 Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1923 | 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 Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame^] | 1933 | { |
| 1934 | //SetInvalid(); |
| 1935 | m_exe_scope = m_process_sp.get(); |
| 1936 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1937 | else |
| 1938 | { |
| 1939 | m_exe_scope = our_thread; |
| 1940 | |
| 1941 | if (m_stack_id.IsValid()) |
| 1942 | { |
| 1943 | StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get(); |
| 1944 | if (our_frame == NULL) |
| 1945 | SetInvalid(); |
| 1946 | else |
| 1947 | m_exe_scope = our_frame; |
| 1948 | } |
| 1949 | } |
| 1950 | } |
| 1951 | return true; |
| 1952 | } |
| 1953 | |
Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 1954 | void |
| 1955 | ValueObject::EvaluationPoint::SetUpdated () |
| 1956 | { |
| 1957 | m_first_update = false; |
| 1958 | m_needs_update = false; |
| 1959 | if (m_process_sp) |
| 1960 | m_stop_id = m_process_sp->GetStopID(); |
| 1961 | } |
| 1962 | |
| 1963 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1964 | bool |
| 1965 | ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope) |
| 1966 | { |
| 1967 | if (!IsValid()) |
| 1968 | return false; |
| 1969 | |
| 1970 | bool needs_update = false; |
| 1971 | m_exe_scope = NULL; |
| 1972 | |
| 1973 | // The target has to be non-null, and the |
| 1974 | Target *target = exe_scope->CalculateTarget(); |
| 1975 | if (target != NULL) |
| 1976 | { |
| 1977 | Target *old_target = m_target_sp.get(); |
| 1978 | assert (target == old_target); |
| 1979 | Process *process = exe_scope->CalculateProcess(); |
| 1980 | if (process != NULL) |
| 1981 | { |
| 1982 | // FOR NOW - assume you can't update variable objects across process boundaries. |
| 1983 | Process *old_process = m_process_sp.get(); |
| 1984 | assert (process == old_process); |
| 1985 | |
| 1986 | lldb::user_id_t stop_id = process->GetStopID(); |
| 1987 | if (stop_id != m_stop_id) |
| 1988 | { |
| 1989 | needs_update = true; |
| 1990 | m_stop_id = stop_id; |
| 1991 | } |
| 1992 | // See if we're switching the thread or stack context. If no thread is given, this is |
| 1993 | // being evaluated in a global context. |
| 1994 | Thread *thread = exe_scope->CalculateThread(); |
| 1995 | if (thread != NULL) |
| 1996 | { |
| 1997 | lldb::user_id_t new_thread_index = thread->GetIndexID(); |
| 1998 | if (new_thread_index != m_thread_id) |
| 1999 | { |
| 2000 | needs_update = true; |
| 2001 | m_thread_id = new_thread_index; |
| 2002 | m_stack_id.Clear(); |
| 2003 | } |
| 2004 | |
| 2005 | StackFrame *new_frame = exe_scope->CalculateStackFrame(); |
| 2006 | if (new_frame != NULL) |
| 2007 | { |
| 2008 | if (new_frame->GetStackID() != m_stack_id) |
| 2009 | { |
| 2010 | needs_update = true; |
| 2011 | m_stack_id = new_frame->GetStackID(); |
| 2012 | } |
| 2013 | } |
| 2014 | else |
| 2015 | { |
| 2016 | m_stack_id.Clear(); |
| 2017 | needs_update = true; |
| 2018 | } |
| 2019 | } |
| 2020 | else |
| 2021 | { |
| 2022 | // If this had been given a thread, and now there is none, we should update. |
| 2023 | // Otherwise we don't have to do anything. |
| 2024 | if (m_thread_id != LLDB_INVALID_UID) |
| 2025 | { |
| 2026 | m_thread_id = LLDB_INVALID_UID; |
| 2027 | m_stack_id.Clear(); |
| 2028 | needs_update = true; |
| 2029 | } |
| 2030 | } |
| 2031 | } |
| 2032 | else |
| 2033 | { |
| 2034 | // If there is no process, then we don't need to update anything. |
| 2035 | // But if we're switching from having a process to not, we should try to update. |
| 2036 | if (m_process_sp.get() != NULL) |
| 2037 | { |
| 2038 | needs_update = true; |
| 2039 | m_process_sp.reset(); |
| 2040 | m_thread_id = LLDB_INVALID_UID; |
| 2041 | m_stack_id.Clear(); |
| 2042 | } |
| 2043 | } |
| 2044 | } |
| 2045 | else |
| 2046 | { |
| 2047 | // If there's no target, nothing can change so we don't need to update anything. |
| 2048 | // But if we're switching from having a target to not, we should try to update. |
| 2049 | if (m_target_sp.get() != NULL) |
| 2050 | { |
| 2051 | needs_update = true; |
| 2052 | m_target_sp.reset(); |
| 2053 | m_process_sp.reset(); |
| 2054 | m_thread_id = LLDB_INVALID_UID; |
| 2055 | m_stack_id.Clear(); |
| 2056 | } |
| 2057 | } |
| 2058 | if (!m_needs_update) |
| 2059 | m_needs_update = needs_update; |
| 2060 | |
| 2061 | return needs_update; |
| 2062 | } |