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 | |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 32 | #include "lldb/Interpreter/ScriptInterpreterPython.h" |
| 33 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 34 | #include "lldb/Symbol/ClangASTType.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | #include "lldb/Symbol/ClangASTContext.h" |
| 36 | #include "lldb/Symbol/Type.h" |
| 37 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 38 | #include "lldb/Target/ExecutionContext.h" |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 39 | #include "lldb/Target/LanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | #include "lldb/Target/Process.h" |
| 41 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 42 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | #include "lldb/Target/Thread.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 45 | #include "lldb/Utility/RefCounter.h" |
| 46 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | using namespace lldb; |
| 48 | using namespace lldb_private; |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 49 | using namespace lldb_utility; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | |
| 51 | static lldb::user_id_t g_value_obj_uid = 0; |
| 52 | |
| 53 | //---------------------------------------------------------------------- |
| 54 | // ValueObject constructor |
| 55 | //---------------------------------------------------------------------- |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 56 | ValueObject::ValueObject (ValueObject &parent) : |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | UserID (++g_value_obj_uid), // Unique identifier for every value object |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 58 | m_parent (&parent), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 59 | m_update_point (parent.GetUpdatePoint ()), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | m_name (), |
| 61 | m_data (), |
| 62 | m_value (), |
| 63 | m_error (), |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 64 | m_value_str (), |
| 65 | m_old_value_str (), |
| 66 | m_location_str (), |
| 67 | m_summary_str (), |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 68 | m_object_desc_str (), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 69 | m_manager(parent.GetManager()), |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 70 | m_children (), |
| 71 | m_synthetic_children (), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 72 | m_dynamic_value (NULL), |
| 73 | m_deref_valobj(NULL), |
Greg Clayton | 32c4085 | 2010-10-06 03:09:11 +0000 | [diff] [blame] | 74 | m_format (eFormatDefault), |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 75 | m_value_is_valid (false), |
| 76 | m_value_did_change (false), |
| 77 | m_children_count_valid (false), |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 78 | m_old_value_valid (false), |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 79 | m_pointers_point_to_load_addrs (false), |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 80 | m_is_deref_of_parent (false), |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 81 | m_is_array_item_for_pointer(false), |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 82 | m_is_bitfield_for_scalar(false), |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 83 | m_last_format_mgr_revision(0), |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 84 | m_last_value_format(), |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 85 | m_last_summary_format(), |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 86 | m_forced_summary_format(), |
| 87 | m_dump_printable_counter(0) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 88 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 89 | m_manager->ManageObject(this); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | //---------------------------------------------------------------------- |
| 93 | // ValueObject constructor |
| 94 | //---------------------------------------------------------------------- |
| 95 | ValueObject::ValueObject (ExecutionContextScope *exe_scope) : |
| 96 | UserID (++g_value_obj_uid), // Unique identifier for every value object |
| 97 | m_parent (NULL), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 98 | m_update_point (exe_scope), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 99 | m_name (), |
| 100 | m_data (), |
| 101 | m_value (), |
| 102 | m_error (), |
| 103 | m_value_str (), |
| 104 | m_old_value_str (), |
| 105 | m_location_str (), |
| 106 | m_summary_str (), |
| 107 | m_object_desc_str (), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 108 | m_manager(), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 109 | m_children (), |
| 110 | m_synthetic_children (), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 111 | m_dynamic_value (NULL), |
| 112 | m_deref_valobj(NULL), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 113 | m_format (eFormatDefault), |
| 114 | m_value_is_valid (false), |
| 115 | m_value_did_change (false), |
| 116 | m_children_count_valid (false), |
| 117 | m_old_value_valid (false), |
| 118 | m_pointers_point_to_load_addrs (false), |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 119 | m_is_deref_of_parent (false), |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 120 | m_is_array_item_for_pointer(false), |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 121 | m_is_bitfield_for_scalar(false), |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 122 | m_last_format_mgr_revision(0), |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 123 | m_last_value_format(), |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 124 | m_last_summary_format(), |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 125 | m_forced_summary_format(), |
| 126 | m_dump_printable_counter(0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 127 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 128 | m_manager = new ValueObjectManager(); |
| 129 | m_manager->ManageObject (this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | //---------------------------------------------------------------------- |
| 133 | // Destructor |
| 134 | //---------------------------------------------------------------------- |
| 135 | ValueObject::~ValueObject () |
| 136 | { |
| 137 | } |
| 138 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 139 | bool |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 140 | ValueObject::UpdateValueIfNeeded (bool update_format) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 141 | { |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 142 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 143 | if (update_format) |
| 144 | UpdateFormatsIfNeeded(); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 145 | |
Greg Clayton | b71f384 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 146 | // If this is a constant value, then our success is predicated on whether |
| 147 | // we have an error or not |
| 148 | if (GetIsConstant()) |
| 149 | return m_error.Success(); |
| 150 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 151 | bool first_update = m_update_point.IsFirstEvaluation(); |
| 152 | |
| 153 | if (m_update_point.NeedsUpdating()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 154 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 155 | m_update_point.SetUpdated(); |
| 156 | |
| 157 | // Save the old value using swap to avoid a string copy which |
| 158 | // also will clear our m_value_str |
| 159 | if (m_value_str.empty()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 160 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 161 | m_old_value_valid = false; |
| 162 | } |
| 163 | else |
| 164 | { |
| 165 | m_old_value_valid = true; |
| 166 | m_old_value_str.swap (m_value_str); |
| 167 | m_value_str.clear(); |
| 168 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 169 | |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 170 | ClearUserVisibleData(); |
| 171 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 172 | const bool value_was_valid = GetValueIsValid(); |
| 173 | SetValueDidChange (false); |
Greg Clayton | 73b953b | 2010-08-28 00:08:07 +0000 | [diff] [blame] | 174 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 175 | m_error.Clear(); |
Greg Clayton | 73b953b | 2010-08-28 00:08:07 +0000 | [diff] [blame] | 176 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 177 | // Call the pure virtual function to update the value |
| 178 | bool success = UpdateValue (); |
| 179 | |
| 180 | SetValueIsValid (success); |
| 181 | |
| 182 | if (first_update) |
| 183 | SetValueDidChange (false); |
| 184 | else if (!m_value_did_change && success == false) |
| 185 | { |
| 186 | // The value wasn't gotten successfully, so we mark this |
| 187 | // as changed if the value used to be valid and now isn't |
| 188 | SetValueDidChange (value_was_valid); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | return m_error.Success(); |
| 192 | } |
| 193 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 194 | void |
| 195 | ValueObject::UpdateFormatsIfNeeded() |
| 196 | { |
| 197 | /*printf("CHECKING FOR UPDATES. I am at revision %d, while the format manager is at revision %d\n", |
| 198 | m_last_format_mgr_revision, |
| 199 | Debugger::ValueFormats::GetCurrentRevision());*/ |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 200 | if (HasCustomSummaryFormat() && m_update_point.GetUpdateID() != m_user_id_of_forced_summary) |
| 201 | { |
| 202 | ClearCustomSummaryFormat(); |
| 203 | m_summary_str.clear(); |
| 204 | } |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 205 | if (m_last_format_mgr_revision != Debugger::ValueFormats::GetCurrentRevision()) |
| 206 | { |
| 207 | if (m_last_summary_format.get()) |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 208 | m_last_summary_format.reset((StringSummaryFormat*)NULL); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 209 | if (m_last_value_format.get()) |
| 210 | m_last_value_format.reset((ValueFormat*)NULL); |
| 211 | Debugger::ValueFormats::Get(*this, m_last_value_format); |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 212 | // to find a summary we look for a direct summary, then if there is none |
| 213 | // we look for a regex summary. if there is none we look for a system |
| 214 | // summary (direct), and if also that fails, we look for a system |
| 215 | // regex summary |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 216 | if (!Debugger::SummaryFormats::Get(*this, m_last_summary_format)) |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 217 | if (!Debugger::RegexSummaryFormats::Get(*this, m_last_summary_format)) |
| 218 | if (!Debugger::SystemSummaryFormats::Get(*this, m_last_summary_format)) |
| 219 | Debugger::SystemRegexSummaryFormats::Get(*this, m_last_summary_format); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 220 | m_last_format_mgr_revision = Debugger::ValueFormats::GetCurrentRevision(); |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 221 | |
| 222 | ClearUserVisibleData(); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 226 | DataExtractor & |
| 227 | ValueObject::GetDataExtractor () |
| 228 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 229 | UpdateValueIfNeeded(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 230 | return m_data; |
| 231 | } |
| 232 | |
| 233 | const Error & |
Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame] | 234 | ValueObject::GetError() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 235 | { |
Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame] | 236 | UpdateValueIfNeeded(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 237 | return m_error; |
| 238 | } |
| 239 | |
| 240 | const ConstString & |
| 241 | ValueObject::GetName() const |
| 242 | { |
| 243 | return m_name; |
| 244 | } |
| 245 | |
| 246 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 247 | ValueObject::GetLocationAsCString () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 248 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 249 | if (UpdateValueIfNeeded()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 250 | { |
| 251 | if (m_location_str.empty()) |
| 252 | { |
| 253 | StreamString sstr; |
| 254 | |
| 255 | switch (m_value.GetValueType()) |
| 256 | { |
| 257 | default: |
| 258 | break; |
| 259 | |
| 260 | case Value::eValueTypeScalar: |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 261 | if (m_value.GetContextType() == Value::eContextTypeRegisterInfo) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 262 | { |
| 263 | RegisterInfo *reg_info = m_value.GetRegisterInfo(); |
| 264 | if (reg_info) |
| 265 | { |
| 266 | if (reg_info->name) |
| 267 | m_location_str = reg_info->name; |
| 268 | else if (reg_info->alt_name) |
| 269 | m_location_str = reg_info->alt_name; |
| 270 | break; |
| 271 | } |
| 272 | } |
| 273 | m_location_str = "scalar"; |
| 274 | break; |
| 275 | |
| 276 | case Value::eValueTypeLoadAddress: |
| 277 | case Value::eValueTypeFileAddress: |
| 278 | case Value::eValueTypeHostAddress: |
| 279 | { |
| 280 | uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2; |
| 281 | sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS)); |
| 282 | m_location_str.swap(sstr.GetString()); |
| 283 | } |
| 284 | break; |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | return m_location_str.c_str(); |
| 289 | } |
| 290 | |
| 291 | Value & |
| 292 | ValueObject::GetValue() |
| 293 | { |
| 294 | return m_value; |
| 295 | } |
| 296 | |
| 297 | const Value & |
| 298 | ValueObject::GetValue() const |
| 299 | { |
| 300 | return m_value; |
| 301 | } |
| 302 | |
| 303 | bool |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 304 | ValueObject::ResolveValue (Scalar &scalar) |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 305 | { |
| 306 | ExecutionContext exe_ctx; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 307 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 308 | if (exe_scope) |
| 309 | exe_scope->CalculateExecutionContext(exe_ctx); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 310 | scalar = m_value.ResolveValue(&exe_ctx, GetClangAST ()); |
| 311 | return scalar.IsValid(); |
| 312 | } |
| 313 | |
| 314 | bool |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 315 | ValueObject::GetValueIsValid () const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 316 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 317 | return m_value_is_valid; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | |
| 321 | void |
| 322 | ValueObject::SetValueIsValid (bool b) |
| 323 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 324 | m_value_is_valid = b; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | bool |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 328 | ValueObject::GetValueDidChange () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 329 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 330 | GetValueAsCString (); |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 331 | return m_value_did_change; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | void |
| 335 | ValueObject::SetValueDidChange (bool value_changed) |
| 336 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 337 | m_value_did_change = value_changed; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | ValueObjectSP |
| 341 | ValueObject::GetChildAtIndex (uint32_t idx, bool can_create) |
| 342 | { |
| 343 | ValueObjectSP child_sp; |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 344 | // We may need to update our value if we are dynamic |
| 345 | if (IsPossibleDynamicType ()) |
| 346 | UpdateValueIfNeeded(); |
| 347 | if (idx < GetNumChildren()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 348 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 349 | // Check if we have already made the child value object? |
| 350 | if (can_create && m_children[idx] == NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 351 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 352 | // No we haven't created the child at this index, so lets have our |
| 353 | // subclass do it and cache the result for quick future access. |
| 354 | m_children[idx] = CreateChildAtIndex (idx, false, 0); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 355 | } |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 356 | |
| 357 | if (m_children[idx] != NULL) |
| 358 | return m_children[idx]->GetSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 359 | } |
| 360 | return child_sp; |
| 361 | } |
| 362 | |
| 363 | uint32_t |
| 364 | ValueObject::GetIndexOfChildWithName (const ConstString &name) |
| 365 | { |
| 366 | bool omit_empty_base_classes = true; |
| 367 | return ClangASTContext::GetIndexOfChildWithName (GetClangAST(), |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 368 | GetClangType(), |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 369 | name.GetCString(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 370 | omit_empty_base_classes); |
| 371 | } |
| 372 | |
| 373 | ValueObjectSP |
| 374 | ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create) |
| 375 | { |
Greg Clayton | 710dd5a | 2011-01-08 20:28:42 +0000 | [diff] [blame] | 376 | // 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] | 377 | // classes (which really aren't part of the expression path), so we |
| 378 | // 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] | 379 | ValueObjectSP child_sp; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 380 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 381 | // We may need to update our value if we are dynamic |
| 382 | if (IsPossibleDynamicType ()) |
| 383 | UpdateValueIfNeeded(); |
| 384 | |
| 385 | std::vector<uint32_t> child_indexes; |
| 386 | clang::ASTContext *clang_ast = GetClangAST(); |
| 387 | void *clang_type = GetClangType(); |
| 388 | bool omit_empty_base_classes = true; |
| 389 | const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast, |
| 390 | clang_type, |
| 391 | name.GetCString(), |
| 392 | omit_empty_base_classes, |
| 393 | child_indexes); |
| 394 | if (num_child_indexes > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 395 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 396 | std::vector<uint32_t>::const_iterator pos = child_indexes.begin (); |
| 397 | std::vector<uint32_t>::const_iterator end = child_indexes.end (); |
| 398 | |
| 399 | child_sp = GetChildAtIndex(*pos, can_create); |
| 400 | for (++pos; pos != end; ++pos) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 401 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 402 | if (child_sp) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 403 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 404 | ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create)); |
| 405 | child_sp = new_child_sp; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 406 | } |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 407 | else |
| 408 | { |
| 409 | child_sp.reset(); |
| 410 | } |
| 411 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | return child_sp; |
| 415 | } |
| 416 | |
| 417 | |
| 418 | uint32_t |
| 419 | ValueObject::GetNumChildren () |
| 420 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 421 | if (!m_children_count_valid) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 422 | { |
| 423 | SetNumChildren (CalculateNumChildren()); |
| 424 | } |
| 425 | return m_children.size(); |
| 426 | } |
| 427 | void |
| 428 | ValueObject::SetNumChildren (uint32_t num_children) |
| 429 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 430 | m_children_count_valid = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 431 | m_children.resize(num_children); |
| 432 | } |
| 433 | |
| 434 | void |
| 435 | ValueObject::SetName (const char *name) |
| 436 | { |
| 437 | m_name.SetCString(name); |
| 438 | } |
| 439 | |
| 440 | void |
| 441 | ValueObject::SetName (const ConstString &name) |
| 442 | { |
| 443 | m_name = name; |
| 444 | } |
| 445 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 446 | ValueObject * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 447 | ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index) |
| 448 | { |
Jim Ingham | 2eec487 | 2011-05-07 00:10:58 +0000 | [diff] [blame] | 449 | ValueObject *valobj = NULL; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 450 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 451 | bool omit_empty_base_classes = true; |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 452 | bool ignore_array_bounds = synthetic_array_member; |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 453 | std::string child_name_str; |
| 454 | uint32_t child_byte_size = 0; |
| 455 | int32_t child_byte_offset = 0; |
| 456 | uint32_t child_bitfield_bit_size = 0; |
| 457 | uint32_t child_bitfield_bit_offset = 0; |
| 458 | bool child_is_base_class = false; |
| 459 | bool child_is_deref_of_parent = false; |
| 460 | |
| 461 | const bool transparent_pointers = synthetic_array_member == false; |
| 462 | clang::ASTContext *clang_ast = GetClangAST(); |
| 463 | clang_type_t clang_type = GetClangType(); |
| 464 | clang_type_t child_clang_type; |
| 465 | |
| 466 | ExecutionContext exe_ctx; |
| 467 | GetExecutionContextScope()->CalculateExecutionContext (exe_ctx); |
| 468 | |
| 469 | child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx, |
| 470 | clang_ast, |
| 471 | GetName().GetCString(), |
| 472 | clang_type, |
| 473 | idx, |
| 474 | transparent_pointers, |
| 475 | omit_empty_base_classes, |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 476 | ignore_array_bounds, |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 477 | child_name_str, |
| 478 | child_byte_size, |
| 479 | child_byte_offset, |
| 480 | child_bitfield_bit_size, |
| 481 | child_bitfield_bit_offset, |
| 482 | child_is_base_class, |
| 483 | child_is_deref_of_parent); |
| 484 | if (child_clang_type && child_byte_size) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 485 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 486 | if (synthetic_index) |
| 487 | child_byte_offset += child_byte_size * synthetic_index; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 488 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 489 | ConstString child_name; |
| 490 | if (!child_name_str.empty()) |
| 491 | child_name.SetCString (child_name_str.c_str()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 492 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 493 | valobj = new ValueObjectChild (*this, |
| 494 | clang_ast, |
| 495 | child_clang_type, |
| 496 | child_name, |
| 497 | child_byte_size, |
| 498 | child_byte_offset, |
| 499 | child_bitfield_bit_size, |
| 500 | child_bitfield_bit_offset, |
| 501 | child_is_base_class, |
| 502 | child_is_deref_of_parent); |
| 503 | if (m_pointers_point_to_load_addrs) |
| 504 | valobj->SetPointersPointToLoadAddrs (m_pointers_point_to_load_addrs); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 505 | } |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 506 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 507 | return valobj; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 511 | ValueObject::GetSummaryAsCString () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 512 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 513 | if (UpdateValueIfNeeded ()) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 514 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 515 | if (m_summary_str.empty()) |
| 516 | { |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 517 | SummaryFormat *summary_format = GetSummaryFormat().get(); |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 518 | |
| 519 | if (summary_format) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 520 | { |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 521 | m_summary_str = summary_format->FormatObject(GetSP()); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 522 | } |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 523 | else |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 524 | { |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 525 | clang_type_t clang_type = GetClangType(); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 526 | |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 527 | // Do some default printout for function pointers |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 528 | if (clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 529 | { |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 530 | StreamString sstr; |
| 531 | clang_type_t elem_or_pointee_clang_type; |
| 532 | const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, |
| 533 | GetClangAST(), |
| 534 | &elem_or_pointee_clang_type)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 535 | |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 536 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 537 | if (exe_scope) |
| 538 | { |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 539 | if (ClangASTContext::IsFunctionPointerType (clang_type)) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 540 | { |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 541 | AddressType func_ptr_address_type = eAddressTypeInvalid; |
| 542 | lldb::addr_t func_ptr_address = GetPointerValue (func_ptr_address_type, true); |
| 543 | |
| 544 | if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS) |
| 545 | { |
| 546 | switch (func_ptr_address_type) |
| 547 | { |
| 548 | case eAddressTypeInvalid: |
| 549 | case eAddressTypeFile: |
| 550 | break; |
| 551 | |
| 552 | case eAddressTypeLoad: |
| 553 | { |
| 554 | Address so_addr; |
| 555 | Target *target = exe_scope->CalculateTarget(); |
| 556 | if (target && target->GetSectionLoadList().IsEmpty() == false) |
| 557 | { |
| 558 | if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr)) |
| 559 | { |
| 560 | so_addr.Dump (&sstr, |
| 561 | exe_scope, |
| 562 | Address::DumpStyleResolvedDescription, |
| 563 | Address::DumpStyleSectionNameOffset); |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | break; |
| 568 | |
| 569 | case eAddressTypeHost: |
| 570 | break; |
| 571 | } |
| 572 | } |
| 573 | if (sstr.GetSize() > 0) |
| 574 | { |
| 575 | m_summary_str.assign (1, '('); |
| 576 | m_summary_str.append (sstr.GetData(), sstr.GetSize()); |
| 577 | m_summary_str.append (1, ')'); |
| 578 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 579 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | if (m_summary_str.empty()) |
| 586 | return NULL; |
| 587 | return m_summary_str.c_str(); |
| 588 | } |
| 589 | |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 590 | bool |
| 591 | ValueObject::IsCStringContainer(bool check_pointer) |
| 592 | { |
| 593 | clang_type_t elem_or_pointee_clang_type; |
| 594 | const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(), |
| 595 | GetClangAST(), |
| 596 | &elem_or_pointee_clang_type)); |
| 597 | bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) && |
| 598 | ClangASTContext::IsCharType (elem_or_pointee_clang_type)); |
| 599 | if (!is_char_arr_ptr) |
| 600 | return false; |
| 601 | if (!check_pointer) |
| 602 | return true; |
| 603 | if (type_flags.Test(ClangASTContext::eTypeIsArray)) |
| 604 | return true; |
| 605 | lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS; |
| 606 | AddressType cstr_address_type = eAddressTypeInvalid; |
| 607 | cstr_address = GetAddressOf (cstr_address_type, true); |
| 608 | return (cstr_address != LLDB_INVALID_ADDRESS); |
| 609 | } |
| 610 | |
| 611 | void |
| 612 | ValueObject::ReadPointedString(Stream& s, |
| 613 | Error& error, |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 614 | uint32_t max_length, |
| 615 | bool honor_array, |
| 616 | lldb::Format item_format) |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 617 | { |
| 618 | |
| 619 | if (max_length == 0) |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 620 | max_length = 128; // FIXME this should be a setting, or a formatting parameter |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 621 | |
| 622 | clang_type_t clang_type = GetClangType(); |
| 623 | clang_type_t elem_or_pointee_clang_type; |
| 624 | const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, |
| 625 | GetClangAST(), |
| 626 | &elem_or_pointee_clang_type)); |
| 627 | if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) && |
| 628 | ClangASTContext::IsCharType (elem_or_pointee_clang_type)) |
| 629 | { |
| 630 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 631 | if (exe_scope) |
| 632 | { |
| 633 | Target *target = exe_scope->CalculateTarget(); |
| 634 | if (target != NULL) |
| 635 | { |
| 636 | lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS; |
| 637 | AddressType cstr_address_type = eAddressTypeInvalid; |
| 638 | |
| 639 | size_t cstr_len = 0; |
| 640 | bool capped_data = false; |
| 641 | if (type_flags.Test (ClangASTContext::eTypeIsArray)) |
| 642 | { |
| 643 | // We have an array |
| 644 | cstr_len = ClangASTContext::GetArraySize (clang_type); |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 645 | if (cstr_len > max_length) |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 646 | { |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 647 | capped_data = true; |
| 648 | cstr_len = max_length; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 649 | } |
| 650 | cstr_address = GetAddressOf (cstr_address_type, true); |
| 651 | } |
| 652 | else |
| 653 | { |
| 654 | // We have a pointer |
| 655 | cstr_address = GetPointerValue (cstr_address_type, true); |
| 656 | } |
| 657 | if (cstr_address != LLDB_INVALID_ADDRESS) |
| 658 | { |
| 659 | Address cstr_so_addr (NULL, cstr_address); |
| 660 | DataExtractor data; |
| 661 | size_t bytes_read = 0; |
| 662 | std::vector<char> data_buffer; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 663 | bool prefer_file_cache = false; |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 664 | if (cstr_len > 0 && honor_array) |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 665 | { |
| 666 | data_buffer.resize(cstr_len); |
| 667 | data.SetData (&data_buffer.front(), data_buffer.size(), lldb::endian::InlHostByteOrder()); |
| 668 | bytes_read = target->ReadMemory (cstr_so_addr, |
| 669 | prefer_file_cache, |
| 670 | &data_buffer.front(), |
| 671 | cstr_len, |
| 672 | error); |
| 673 | if (bytes_read > 0) |
| 674 | { |
| 675 | s << '"'; |
| 676 | data.Dump (&s, |
| 677 | 0, // Start offset in "data" |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 678 | item_format, |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 679 | 1, // Size of item (1 byte for a char!) |
| 680 | bytes_read, // How many bytes to print? |
| 681 | UINT32_MAX, // num per line |
| 682 | LLDB_INVALID_ADDRESS,// base address |
| 683 | 0, // bitfield bit size |
| 684 | 0); // bitfield bit offset |
| 685 | if (capped_data) |
| 686 | s << "..."; |
| 687 | s << '"'; |
| 688 | } |
| 689 | } |
| 690 | else |
| 691 | { |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 692 | cstr_len = max_length; |
| 693 | const size_t k_max_buf_size = 64; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 694 | data_buffer.resize (k_max_buf_size + 1); |
| 695 | // NULL terminate in case we don't get the entire C string |
| 696 | data_buffer.back() = '\0'; |
| 697 | |
| 698 | s << '"'; |
| 699 | |
| 700 | data.SetData (&data_buffer.front(), data_buffer.size(), endian::InlHostByteOrder()); |
| 701 | while ((bytes_read = target->ReadMemory (cstr_so_addr, |
| 702 | prefer_file_cache, |
| 703 | &data_buffer.front(), |
| 704 | k_max_buf_size, |
| 705 | error)) > 0) |
| 706 | { |
| 707 | size_t len = strlen(&data_buffer.front()); |
| 708 | if (len == 0) |
| 709 | break; |
| 710 | if (len > bytes_read) |
| 711 | len = bytes_read; |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 712 | if (len > cstr_len) |
| 713 | len = cstr_len; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 714 | |
| 715 | data.Dump (&s, |
| 716 | 0, // Start offset in "data" |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 717 | item_format, |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 718 | 1, // Size of item (1 byte for a char!) |
| 719 | len, // How many bytes to print? |
| 720 | UINT32_MAX, // num per line |
| 721 | LLDB_INVALID_ADDRESS,// base address |
| 722 | 0, // bitfield bit size |
| 723 | 0); // bitfield bit offset |
| 724 | |
| 725 | if (len < k_max_buf_size) |
| 726 | break; |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 727 | if (len >= cstr_len) |
| 728 | { |
| 729 | s << "..."; |
| 730 | break; |
| 731 | } |
| 732 | cstr_len -= len; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 733 | cstr_so_addr.Slide (k_max_buf_size); |
| 734 | } |
| 735 | s << '"'; |
| 736 | } |
| 737 | } |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | else |
| 742 | { |
| 743 | error.SetErrorString("impossible to read a string from this object"); |
| 744 | } |
| 745 | } |
| 746 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 747 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 748 | ValueObject::GetObjectDescription () |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 749 | { |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 750 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 751 | if (!UpdateValueIfNeeded ()) |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 752 | return NULL; |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 753 | |
| 754 | if (!m_object_desc_str.empty()) |
| 755 | return m_object_desc_str.c_str(); |
| 756 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 757 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 758 | if (exe_scope == NULL) |
| 759 | return NULL; |
| 760 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 761 | Process *process = exe_scope->CalculateProcess(); |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 762 | if (process == NULL) |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 763 | return NULL; |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 764 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 765 | StreamString s; |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 766 | |
| 767 | lldb::LanguageType language = GetObjectRuntimeLanguage(); |
| 768 | LanguageRuntime *runtime = process->GetLanguageRuntime(language); |
| 769 | |
Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 770 | if (runtime == NULL) |
| 771 | { |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 772 | // 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] | 773 | clang_type_t opaque_qual_type = GetClangType(); |
| 774 | if (opaque_qual_type != NULL) |
| 775 | { |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 776 | bool is_signed; |
| 777 | if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed) |
| 778 | || ClangASTContext::IsPointerType (opaque_qual_type)) |
| 779 | { |
Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 780 | runtime = process->GetLanguageRuntime(lldb::eLanguageTypeObjC); |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 781 | } |
Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 782 | } |
| 783 | } |
| 784 | |
Jim Ingham | 8d543de | 2011-03-31 23:01:21 +0000 | [diff] [blame] | 785 | if (runtime && runtime->GetObjectDescription(s, *this)) |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 786 | { |
| 787 | m_object_desc_str.append (s.GetData()); |
| 788 | } |
Sean Callanan | 672ad94 | 2010-10-23 00:18:49 +0000 | [diff] [blame] | 789 | |
| 790 | if (m_object_desc_str.empty()) |
| 791 | return NULL; |
| 792 | else |
| 793 | return m_object_desc_str.c_str(); |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 794 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 795 | |
| 796 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 797 | ValueObject::GetValueAsCString () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 798 | { |
| 799 | // 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] | 800 | if (ClangASTContext::IsAggregateType (GetClangType()) == false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 801 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 802 | if (UpdateValueIfNeeded()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 803 | { |
| 804 | if (m_value_str.empty()) |
| 805 | { |
| 806 | const Value::ContextType context_type = m_value.GetContextType(); |
| 807 | |
| 808 | switch (context_type) |
| 809 | { |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 810 | case Value::eContextTypeClangType: |
| 811 | case Value::eContextTypeLLDBType: |
| 812 | case Value::eContextTypeVariable: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 813 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 814 | clang_type_t clang_type = GetClangType (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 815 | if (clang_type) |
| 816 | { |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 817 | if (m_last_value_format) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 818 | { |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 819 | m_value_str = m_last_value_format->FormatObject(GetSP()); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 820 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 821 | else |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 822 | { |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 823 | StreamString sstr; |
| 824 | Format format = GetFormat(); |
| 825 | if (format == eFormatDefault) |
| 826 | format = (m_is_bitfield_for_scalar ? eFormatUnsigned : |
| 827 | ClangASTType::GetFormat(clang_type)); |
| 828 | |
| 829 | if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST |
| 830 | clang_type, // The clang type to display |
| 831 | &sstr, |
| 832 | format, // Format to display this type with |
| 833 | m_data, // Data to extract from |
| 834 | 0, // Byte offset into "m_data" |
| 835 | GetByteSize(), // Byte size of item in "m_data" |
| 836 | GetBitfieldBitSize(), // Bitfield bit size |
| 837 | GetBitfieldBitOffset())) // Bitfield bit offset |
| 838 | m_value_str.swap(sstr.GetString()); |
| 839 | else |
| 840 | { |
| 841 | m_error.SetErrorStringWithFormat ("unsufficient data for value (only %u of %u bytes available)", |
| 842 | m_data.GetByteSize(), |
| 843 | GetByteSize()); |
| 844 | m_value_str.clear(); |
| 845 | } |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 846 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | break; |
| 850 | |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 851 | case Value::eContextTypeRegisterInfo: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 852 | { |
| 853 | const RegisterInfo *reg_info = m_value.GetRegisterInfo(); |
| 854 | if (reg_info) |
| 855 | { |
| 856 | StreamString reg_sstr; |
| 857 | m_data.Dump(®_sstr, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0); |
| 858 | m_value_str.swap(reg_sstr.GetString()); |
| 859 | } |
| 860 | } |
| 861 | break; |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 862 | |
| 863 | default: |
| 864 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 865 | } |
| 866 | } |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 867 | |
| 868 | if (!m_value_did_change && m_old_value_valid) |
| 869 | { |
| 870 | // The value was gotten successfully, so we consider the |
| 871 | // value as changed if the value string differs |
| 872 | SetValueDidChange (m_old_value_str != m_value_str); |
| 873 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 874 | } |
| 875 | } |
| 876 | if (m_value_str.empty()) |
| 877 | return NULL; |
| 878 | return m_value_str.c_str(); |
| 879 | } |
| 880 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 881 | const char * |
| 882 | ValueObject::GetPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display, |
| 883 | lldb::Format custom_format) |
| 884 | { |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 885 | |
| 886 | RefCounter ref(&m_dump_printable_counter); |
| 887 | |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 888 | if (custom_format != lldb::eFormatInvalid) |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 889 | SetFormat(custom_format); |
| 890 | |
| 891 | const char * return_value; |
| 892 | |
| 893 | switch(val_obj_display) |
| 894 | { |
| 895 | case eDisplayValue: |
| 896 | return_value = GetValueAsCString(); |
| 897 | break; |
| 898 | case eDisplaySummary: |
| 899 | return_value = GetSummaryAsCString(); |
| 900 | break; |
| 901 | case eDisplayLanguageSpecific: |
| 902 | return_value = GetObjectDescription(); |
| 903 | break; |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 904 | case eDisplayLocation: |
| 905 | return_value = GetLocationAsCString(); |
| 906 | break; |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 907 | } |
| 908 | |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 909 | // this code snippet might lead to endless recursion, thus we use a RefCounter here to |
| 910 | // check that we are not looping endlessly |
| 911 | if (!return_value && (m_dump_printable_counter < 3)) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 912 | { |
| 913 | // try to pick the other choice |
| 914 | if (val_obj_display == eDisplayValue) |
| 915 | return_value = GetSummaryAsCString(); |
| 916 | else if (val_obj_display == eDisplaySummary) |
| 917 | return_value = GetValueAsCString(); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 918 | } |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 919 | |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 920 | return (return_value ? return_value : "<error>"); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 921 | |
| 922 | } |
| 923 | |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 924 | bool |
| 925 | ValueObject::DumpPrintableRepresentation(Stream& s, |
| 926 | ValueObjectRepresentationStyle val_obj_display, |
| 927 | lldb::Format custom_format) |
| 928 | { |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 929 | |
| 930 | clang_type_t elem_or_pointee_type; |
| 931 | Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type)); |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 932 | |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 933 | if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) |
| 934 | && val_obj_display == ValueObject::eDisplayValue) |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 935 | { |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 936 | // when being asked to get a printable display an array or pointer type directly, |
| 937 | // try to "do the right thing" |
| 938 | |
| 939 | if (IsCStringContainer(true) && |
| 940 | (custom_format == lldb::eFormatCString || |
| 941 | custom_format == lldb::eFormatCharArray || |
| 942 | custom_format == lldb::eFormatChar || |
| 943 | custom_format == lldb::eFormatVectorOfChar)) // print char[] & char* directly |
| 944 | { |
| 945 | Error error; |
| 946 | ReadPointedString(s, |
| 947 | error, |
| 948 | 0, |
| 949 | (custom_format == lldb::eFormatVectorOfChar) || |
| 950 | (custom_format == lldb::eFormatCharArray)); |
| 951 | return !error.Fail(); |
| 952 | } |
| 953 | |
| 954 | if (custom_format == lldb::eFormatEnum) |
| 955 | return false; |
| 956 | |
| 957 | // this only works for arrays, because I have no way to know when |
| 958 | // the pointed memory ends, and no special \0 end of data marker |
| 959 | if (flags.Test(ClangASTContext::eTypeIsArray)) |
| 960 | { |
| 961 | if ((custom_format == lldb::eFormatBytes) || |
| 962 | (custom_format == lldb::eFormatBytesWithASCII)) |
| 963 | { |
| 964 | uint32_t count = GetNumChildren(); |
| 965 | |
| 966 | s << '['; |
| 967 | for (uint32_t low = 0; low < count; low++) |
| 968 | { |
| 969 | |
| 970 | if (low) |
| 971 | s << ','; |
| 972 | |
| 973 | ValueObjectSP child = GetChildAtIndex(low,true); |
| 974 | if (!child.get()) |
| 975 | { |
| 976 | s << "<error>"; |
| 977 | continue; |
| 978 | } |
| 979 | child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format); |
| 980 | } |
| 981 | |
| 982 | s << ']'; |
| 983 | |
| 984 | return true; |
| 985 | } |
| 986 | |
| 987 | if ((custom_format == lldb::eFormatVectorOfChar) || |
| 988 | (custom_format == lldb::eFormatVectorOfFloat32) || |
| 989 | (custom_format == lldb::eFormatVectorOfFloat64) || |
| 990 | (custom_format == lldb::eFormatVectorOfSInt16) || |
| 991 | (custom_format == lldb::eFormatVectorOfSInt32) || |
| 992 | (custom_format == lldb::eFormatVectorOfSInt64) || |
| 993 | (custom_format == lldb::eFormatVectorOfSInt8) || |
| 994 | (custom_format == lldb::eFormatVectorOfUInt128) || |
| 995 | (custom_format == lldb::eFormatVectorOfUInt16) || |
| 996 | (custom_format == lldb::eFormatVectorOfUInt32) || |
| 997 | (custom_format == lldb::eFormatVectorOfUInt64) || |
| 998 | (custom_format == lldb::eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly |
| 999 | { |
| 1000 | uint32_t count = GetNumChildren(); |
| 1001 | |
| 1002 | lldb::Format format = FormatManager::GetSingleItemFormat(custom_format); |
| 1003 | |
| 1004 | s << '['; |
| 1005 | for (uint32_t low = 0; low < count; low++) |
| 1006 | { |
| 1007 | |
| 1008 | if (low) |
| 1009 | s << ','; |
| 1010 | |
| 1011 | ValueObjectSP child = GetChildAtIndex(low,true); |
| 1012 | if (!child.get()) |
| 1013 | { |
| 1014 | s << "<error>"; |
| 1015 | continue; |
| 1016 | } |
| 1017 | child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format); |
| 1018 | } |
| 1019 | |
| 1020 | s << ']'; |
| 1021 | |
| 1022 | return true; |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | if ((custom_format == lldb::eFormatBoolean) || |
| 1027 | (custom_format == lldb::eFormatBinary) || |
| 1028 | (custom_format == lldb::eFormatChar) || |
| 1029 | (custom_format == lldb::eFormatCharPrintable) || |
| 1030 | (custom_format == lldb::eFormatComplexFloat) || |
| 1031 | (custom_format == lldb::eFormatDecimal) || |
| 1032 | (custom_format == lldb::eFormatHex) || |
| 1033 | (custom_format == lldb::eFormatFloat) || |
| 1034 | (custom_format == lldb::eFormatOctal) || |
| 1035 | (custom_format == lldb::eFormatOSType) || |
| 1036 | (custom_format == lldb::eFormatUnicode16) || |
| 1037 | (custom_format == lldb::eFormatUnicode32) || |
| 1038 | (custom_format == lldb::eFormatUnsigned) || |
| 1039 | (custom_format == lldb::eFormatPointer) || |
| 1040 | (custom_format == lldb::eFormatComplexInteger) || |
| 1041 | (custom_format == lldb::eFormatComplex) || |
| 1042 | (custom_format == lldb::eFormatDefault)) // use the [] operator |
| 1043 | return false; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1044 | } |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1045 | const char *targetvalue = GetPrintableRepresentation(val_obj_display, custom_format); |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 1046 | if (targetvalue) |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1047 | s.PutCString(targetvalue); |
| 1048 | bool var_success = (targetvalue != NULL); |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 1049 | if (custom_format != eFormatInvalid) |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1050 | SetFormat(eFormatDefault); |
| 1051 | return var_success; |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1054 | addr_t |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1055 | ValueObject::GetAddressOf (AddressType &address_type, bool scalar_is_load_address) |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1056 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1057 | if (!UpdateValueIfNeeded()) |
| 1058 | return LLDB_INVALID_ADDRESS; |
| 1059 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1060 | switch (m_value.GetValueType()) |
| 1061 | { |
| 1062 | case Value::eValueTypeScalar: |
| 1063 | if (scalar_is_load_address) |
| 1064 | { |
| 1065 | address_type = eAddressTypeLoad; |
| 1066 | return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 1067 | } |
| 1068 | break; |
| 1069 | |
| 1070 | case Value::eValueTypeLoadAddress: |
| 1071 | case Value::eValueTypeFileAddress: |
| 1072 | case Value::eValueTypeHostAddress: |
| 1073 | { |
| 1074 | address_type = m_value.GetValueAddressType (); |
| 1075 | return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 1076 | } |
| 1077 | break; |
| 1078 | } |
| 1079 | address_type = eAddressTypeInvalid; |
| 1080 | return LLDB_INVALID_ADDRESS; |
| 1081 | } |
| 1082 | |
| 1083 | addr_t |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1084 | ValueObject::GetPointerValue (AddressType &address_type, bool scalar_is_load_address) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1085 | { |
| 1086 | lldb::addr_t address = LLDB_INVALID_ADDRESS; |
| 1087 | address_type = eAddressTypeInvalid; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1088 | |
| 1089 | if (!UpdateValueIfNeeded()) |
| 1090 | return address; |
| 1091 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1092 | switch (m_value.GetValueType()) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1093 | { |
| 1094 | case Value::eValueTypeScalar: |
| 1095 | if (scalar_is_load_address) |
| 1096 | { |
| 1097 | address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 1098 | address_type = eAddressTypeLoad; |
| 1099 | } |
| 1100 | break; |
| 1101 | |
| 1102 | case Value::eValueTypeLoadAddress: |
| 1103 | case Value::eValueTypeFileAddress: |
| 1104 | case Value::eValueTypeHostAddress: |
| 1105 | { |
| 1106 | uint32_t data_offset = 0; |
| 1107 | address = m_data.GetPointer(&data_offset); |
| 1108 | address_type = m_value.GetValueAddressType(); |
| 1109 | if (address_type == eAddressTypeInvalid) |
| 1110 | address_type = eAddressTypeLoad; |
| 1111 | } |
| 1112 | break; |
| 1113 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1114 | |
| 1115 | if (m_pointers_point_to_load_addrs) |
| 1116 | address_type = eAddressTypeLoad; |
| 1117 | |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1118 | return address; |
| 1119 | } |
| 1120 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1121 | bool |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1122 | ValueObject::SetValueFromCString (const char *value_str) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1123 | { |
| 1124 | // Make sure our value is up to date first so that our location and location |
| 1125 | // type is valid. |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1126 | if (!UpdateValueIfNeeded()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1127 | return false; |
| 1128 | |
| 1129 | uint32_t count = 0; |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1130 | lldb::Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1131 | |
| 1132 | char *end = NULL; |
Greg Clayton | b132097 | 2010-07-14 00:18:15 +0000 | [diff] [blame] | 1133 | const size_t byte_size = GetByteSize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1134 | switch (encoding) |
| 1135 | { |
| 1136 | case eEncodingInvalid: |
| 1137 | return false; |
| 1138 | |
| 1139 | case eEncodingUint: |
| 1140 | if (byte_size > sizeof(unsigned long long)) |
| 1141 | { |
| 1142 | return false; |
| 1143 | } |
| 1144 | else |
| 1145 | { |
| 1146 | unsigned long long ull_val = strtoull(value_str, &end, 0); |
| 1147 | if (end && *end != '\0') |
| 1148 | return false; |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 1149 | m_value.GetScalar() = ull_val; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1150 | // Limit the bytes in our m_data appropriately. |
| 1151 | m_value.GetScalar().GetData (m_data, byte_size); |
| 1152 | } |
| 1153 | break; |
| 1154 | |
| 1155 | case eEncodingSint: |
| 1156 | if (byte_size > sizeof(long long)) |
| 1157 | { |
| 1158 | return false; |
| 1159 | } |
| 1160 | else |
| 1161 | { |
| 1162 | long long sll_val = strtoll(value_str, &end, 0); |
| 1163 | if (end && *end != '\0') |
| 1164 | return false; |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 1165 | m_value.GetScalar() = sll_val; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1166 | // Limit the bytes in our m_data appropriately. |
| 1167 | m_value.GetScalar().GetData (m_data, byte_size); |
| 1168 | } |
| 1169 | break; |
| 1170 | |
| 1171 | case eEncodingIEEE754: |
| 1172 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1173 | const off_t byte_offset = GetByteOffset(); |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1174 | 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] | 1175 | if (dst != NULL) |
| 1176 | { |
| 1177 | // We are decoding a float into host byte order below, so make |
| 1178 | // sure m_data knows what it contains. |
Greg Clayton | 7fb56d0 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 1179 | m_data.SetByteOrder(lldb::endian::InlHostByteOrder()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1180 | const size_t converted_byte_size = ClangASTContext::ConvertStringToFloatValue ( |
| 1181 | GetClangAST(), |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1182 | GetClangType(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1183 | value_str, |
| 1184 | dst, |
| 1185 | byte_size); |
| 1186 | |
| 1187 | if (converted_byte_size == byte_size) |
| 1188 | { |
| 1189 | } |
| 1190 | } |
| 1191 | } |
| 1192 | break; |
| 1193 | |
| 1194 | case eEncodingVector: |
| 1195 | return false; |
| 1196 | |
| 1197 | default: |
| 1198 | return false; |
| 1199 | } |
| 1200 | |
| 1201 | // If we have made it here the value is in m_data and we should write it |
| 1202 | // out to the target |
| 1203 | return Write (); |
| 1204 | } |
| 1205 | |
| 1206 | bool |
| 1207 | ValueObject::Write () |
| 1208 | { |
| 1209 | // Clear the update ID so the next time we try and read the value |
| 1210 | // we try and read it again. |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1211 | m_update_point.SetNeedsUpdate(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1212 | |
| 1213 | // TODO: when Value has a method to write a value back, call it from here. |
| 1214 | return false; |
| 1215 | |
| 1216 | } |
| 1217 | |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1218 | lldb::LanguageType |
| 1219 | ValueObject::GetObjectRuntimeLanguage () |
| 1220 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1221 | clang_type_t opaque_qual_type = GetClangType(); |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1222 | if (opaque_qual_type == NULL) |
| 1223 | return lldb::eLanguageTypeC; |
| 1224 | |
| 1225 | // If the type is a reference, then resolve it to what it refers to first: |
| 1226 | clang::QualType qual_type (clang::QualType::getFromOpaquePtr(opaque_qual_type).getNonReferenceType()); |
| 1227 | if (qual_type->isAnyPointerType()) |
| 1228 | { |
| 1229 | if (qual_type->isObjCObjectPointerType()) |
| 1230 | return lldb::eLanguageTypeObjC; |
| 1231 | |
| 1232 | clang::QualType pointee_type (qual_type->getPointeeType()); |
| 1233 | if (pointee_type->getCXXRecordDeclForPointerType() != NULL) |
| 1234 | return lldb::eLanguageTypeC_plus_plus; |
| 1235 | if (pointee_type->isObjCObjectOrInterfaceType()) |
| 1236 | return lldb::eLanguageTypeObjC; |
| 1237 | if (pointee_type->isObjCClassType()) |
| 1238 | return lldb::eLanguageTypeObjC; |
| 1239 | } |
| 1240 | else |
| 1241 | { |
| 1242 | if (ClangASTContext::IsObjCClassType (opaque_qual_type)) |
| 1243 | return lldb::eLanguageTypeObjC; |
Johnny Chen | d440bcc | 2010-09-28 16:10:54 +0000 | [diff] [blame] | 1244 | if (ClangASTContext::IsCXXClassType (opaque_qual_type)) |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1245 | return lldb::eLanguageTypeC_plus_plus; |
| 1246 | } |
| 1247 | |
| 1248 | return lldb::eLanguageTypeC; |
| 1249 | } |
| 1250 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1251 | void |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1252 | ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1253 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1254 | m_synthetic_children[key] = valobj; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | ValueObjectSP |
| 1258 | ValueObject::GetSyntheticChild (const ConstString &key) const |
| 1259 | { |
| 1260 | ValueObjectSP synthetic_child_sp; |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1261 | std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1262 | if (pos != m_synthetic_children.end()) |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1263 | synthetic_child_sp = pos->second->GetSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1264 | return synthetic_child_sp; |
| 1265 | } |
| 1266 | |
| 1267 | bool |
| 1268 | ValueObject::IsPointerType () |
| 1269 | { |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1270 | return ClangASTContext::IsPointerType (GetClangType()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 1273 | bool |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 1274 | ValueObject::IsArrayType () |
| 1275 | { |
| 1276 | return ClangASTContext::IsArrayType (GetClangType()); |
| 1277 | } |
| 1278 | |
| 1279 | bool |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1280 | ValueObject::IsScalarType () |
| 1281 | { |
| 1282 | return ClangASTContext::IsScalarType (GetClangType()); |
| 1283 | } |
| 1284 | |
| 1285 | bool |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 1286 | ValueObject::IsIntegerType (bool &is_signed) |
| 1287 | { |
| 1288 | return ClangASTContext::IsIntegerType (GetClangType(), is_signed); |
| 1289 | } |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1290 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1291 | bool |
| 1292 | ValueObject::IsPointerOrReferenceType () |
| 1293 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 1294 | return ClangASTContext::IsPointerOrReferenceType (GetClangType()); |
| 1295 | } |
| 1296 | |
| 1297 | bool |
| 1298 | ValueObject::IsPossibleCPlusPlusDynamicType () |
| 1299 | { |
| 1300 | return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1301 | } |
| 1302 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 1303 | bool |
| 1304 | ValueObject::IsPossibleDynamicType () |
| 1305 | { |
| 1306 | return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType()); |
| 1307 | } |
| 1308 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1309 | ValueObjectSP |
| 1310 | ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create) |
| 1311 | { |
| 1312 | ValueObjectSP synthetic_child_sp; |
| 1313 | if (IsPointerType ()) |
| 1314 | { |
| 1315 | char index_str[64]; |
| 1316 | snprintf(index_str, sizeof(index_str), "[%i]", index); |
| 1317 | ConstString index_const_str(index_str); |
| 1318 | // Check if we have already created a synthetic array member in this |
| 1319 | // valid object. If we have we will re-use it. |
| 1320 | synthetic_child_sp = GetSyntheticChild (index_const_str); |
| 1321 | if (!synthetic_child_sp) |
| 1322 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1323 | ValueObject *synthetic_child; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1324 | // We haven't made a synthetic array member for INDEX yet, so |
| 1325 | // lets make one and cache it for any future reference. |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1326 | synthetic_child = CreateChildAtIndex(0, true, index); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1327 | |
| 1328 | // Cache the value if we got one back... |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1329 | if (synthetic_child) |
| 1330 | { |
| 1331 | AddSyntheticChild(index_const_str, synthetic_child); |
| 1332 | synthetic_child_sp = synthetic_child->GetSP(); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1333 | synthetic_child_sp->SetName(index_str); |
| 1334 | synthetic_child_sp->m_is_array_item_for_pointer = true; |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1335 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | return synthetic_child_sp; |
| 1339 | } |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1340 | |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 1341 | // This allows you to create an array member using and index |
| 1342 | // that doesn't not fall in the normal bounds of the array. |
| 1343 | // Many times structure can be defined as: |
| 1344 | // struct Collection |
| 1345 | // { |
| 1346 | // uint32_t item_count; |
| 1347 | // Item item_array[0]; |
| 1348 | // }; |
| 1349 | // The size of the "item_array" is 1, but many times in practice |
| 1350 | // there are more items in "item_array". |
| 1351 | |
| 1352 | ValueObjectSP |
| 1353 | ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create) |
| 1354 | { |
| 1355 | ValueObjectSP synthetic_child_sp; |
| 1356 | if (IsArrayType ()) |
| 1357 | { |
| 1358 | char index_str[64]; |
| 1359 | snprintf(index_str, sizeof(index_str), "[%i]", index); |
| 1360 | ConstString index_const_str(index_str); |
| 1361 | // Check if we have already created a synthetic array member in this |
| 1362 | // valid object. If we have we will re-use it. |
| 1363 | synthetic_child_sp = GetSyntheticChild (index_const_str); |
| 1364 | if (!synthetic_child_sp) |
| 1365 | { |
| 1366 | ValueObject *synthetic_child; |
| 1367 | // We haven't made a synthetic array member for INDEX yet, so |
| 1368 | // lets make one and cache it for any future reference. |
| 1369 | synthetic_child = CreateChildAtIndex(0, true, index); |
| 1370 | |
| 1371 | // Cache the value if we got one back... |
| 1372 | if (synthetic_child) |
| 1373 | { |
| 1374 | AddSyntheticChild(index_const_str, synthetic_child); |
| 1375 | synthetic_child_sp = synthetic_child->GetSP(); |
| 1376 | synthetic_child_sp->SetName(index_str); |
| 1377 | synthetic_child_sp->m_is_array_item_for_pointer = true; |
| 1378 | } |
| 1379 | } |
| 1380 | } |
| 1381 | return synthetic_child_sp; |
| 1382 | } |
| 1383 | |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1384 | ValueObjectSP |
| 1385 | ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create) |
| 1386 | { |
| 1387 | ValueObjectSP synthetic_child_sp; |
| 1388 | if (IsScalarType ()) |
| 1389 | { |
| 1390 | char index_str[64]; |
| 1391 | snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to); |
| 1392 | ConstString index_const_str(index_str); |
| 1393 | // Check if we have already created a synthetic array member in this |
| 1394 | // valid object. If we have we will re-use it. |
| 1395 | synthetic_child_sp = GetSyntheticChild (index_const_str); |
| 1396 | if (!synthetic_child_sp) |
| 1397 | { |
| 1398 | ValueObjectChild *synthetic_child; |
| 1399 | // We haven't made a synthetic array member for INDEX yet, so |
| 1400 | // lets make one and cache it for any future reference. |
| 1401 | synthetic_child = new ValueObjectChild(*this, |
| 1402 | GetClangAST(), |
| 1403 | GetClangType(), |
| 1404 | index_const_str, |
| 1405 | GetByteSize(), |
| 1406 | 0, |
| 1407 | to-from+1, |
| 1408 | from, |
| 1409 | false, |
| 1410 | false); |
| 1411 | |
| 1412 | // Cache the value if we got one back... |
| 1413 | if (synthetic_child) |
| 1414 | { |
| 1415 | AddSyntheticChild(index_const_str, synthetic_child); |
| 1416 | synthetic_child_sp = synthetic_child->GetSP(); |
| 1417 | synthetic_child_sp->SetName(index_str); |
| 1418 | synthetic_child_sp->m_is_bitfield_for_scalar = true; |
| 1419 | } |
| 1420 | } |
| 1421 | } |
| 1422 | return synthetic_child_sp; |
| 1423 | } |
| 1424 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1425 | void |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1426 | ValueObject::CalculateDynamicValue (lldb::DynamicValueType use_dynamic) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1427 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1428 | if (use_dynamic == lldb::eNoDynamicValues) |
| 1429 | return; |
| 1430 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1431 | if (!m_dynamic_value && !IsDynamic()) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1432 | { |
| 1433 | Process *process = m_update_point.GetProcess(); |
| 1434 | bool worth_having_dynamic_value = false; |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1435 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1436 | |
| 1437 | // FIXME: Process should have some kind of "map over Runtimes" so we don't have to |
| 1438 | // hard code this everywhere. |
| 1439 | lldb::LanguageType known_type = GetObjectRuntimeLanguage(); |
| 1440 | if (known_type != lldb::eLanguageTypeUnknown && known_type != lldb::eLanguageTypeC) |
| 1441 | { |
| 1442 | LanguageRuntime *runtime = process->GetLanguageRuntime (known_type); |
| 1443 | if (runtime) |
| 1444 | worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this); |
| 1445 | } |
| 1446 | else |
| 1447 | { |
| 1448 | LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeC_plus_plus); |
| 1449 | if (cpp_runtime) |
| 1450 | worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this); |
| 1451 | |
| 1452 | if (!worth_having_dynamic_value) |
| 1453 | { |
| 1454 | LanguageRuntime *objc_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeObjC); |
| 1455 | if (objc_runtime) |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1456 | worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | if (worth_having_dynamic_value) |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1461 | m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1462 | |
| 1463 | // if (worth_having_dynamic_value) |
| 1464 | // printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager); |
| 1465 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1466 | } |
| 1467 | } |
| 1468 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1469 | ValueObjectSP |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1470 | ValueObject::GetDynamicValue (DynamicValueType use_dynamic) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1471 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1472 | if (use_dynamic == lldb::eNoDynamicValues) |
| 1473 | return ValueObjectSP(); |
| 1474 | |
| 1475 | if (!IsDynamic() && m_dynamic_value == NULL) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1476 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1477 | CalculateDynamicValue(use_dynamic); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1478 | } |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1479 | if (m_dynamic_value) |
| 1480 | return m_dynamic_value->GetSP(); |
| 1481 | else |
| 1482 | return ValueObjectSP(); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1483 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1484 | |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1485 | bool |
| 1486 | ValueObject::GetBaseClassPath (Stream &s) |
| 1487 | { |
| 1488 | if (IsBaseClass()) |
| 1489 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1490 | bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1491 | clang_type_t clang_type = GetClangType(); |
| 1492 | std::string cxx_class_name; |
| 1493 | bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name); |
| 1494 | if (this_had_base_class) |
| 1495 | { |
| 1496 | if (parent_had_base_class) |
| 1497 | s.PutCString("::"); |
| 1498 | s.PutCString(cxx_class_name.c_str()); |
| 1499 | } |
| 1500 | return parent_had_base_class || this_had_base_class; |
| 1501 | } |
| 1502 | return false; |
| 1503 | } |
| 1504 | |
| 1505 | |
| 1506 | ValueObject * |
| 1507 | ValueObject::GetNonBaseClassParent() |
| 1508 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1509 | if (GetParent()) |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1510 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1511 | if (GetParent()->IsBaseClass()) |
| 1512 | return GetParent()->GetNonBaseClassParent(); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1513 | else |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1514 | return GetParent(); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1515 | } |
| 1516 | return NULL; |
| 1517 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1518 | |
| 1519 | void |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1520 | ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1521 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1522 | const bool is_deref_of_parent = IsDereferenceOfParent (); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1523 | |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 1524 | if (is_deref_of_parent && epformat == eDereferencePointers) { |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1525 | // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely |
| 1526 | // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName. |
| 1527 | // the eHonorPointers mode is meant to produce strings in this latter format |
| 1528 | s.PutCString("*("); |
| 1529 | } |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1530 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1531 | ValueObject* parent = GetParent(); |
| 1532 | |
| 1533 | if (parent) |
| 1534 | parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1535 | |
| 1536 | // if we are a deref_of_parent just because we are synthetic array |
| 1537 | // members made up to allow ptr[%d] syntax to work in variable |
| 1538 | // printing, then add our name ([%d]) to the expression path |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 1539 | if (m_is_array_item_for_pointer && epformat == eHonorPointers) |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1540 | s.PutCString(m_name.AsCString()); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1541 | |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1542 | if (!IsBaseClass()) |
| 1543 | { |
| 1544 | if (!is_deref_of_parent) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1545 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1546 | ValueObject *non_base_class_parent = GetNonBaseClassParent(); |
| 1547 | if (non_base_class_parent) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1548 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1549 | clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType(); |
| 1550 | if (non_base_class_parent_clang_type) |
| 1551 | { |
| 1552 | const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL); |
| 1553 | |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 1554 | if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers) |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1555 | { |
| 1556 | s.PutCString("->"); |
| 1557 | } |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1558 | else |
| 1559 | { |
| 1560 | if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer) |
| 1561 | { |
| 1562 | s.PutCString("->"); |
| 1563 | } |
| 1564 | else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) && |
| 1565 | !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray)) |
| 1566 | { |
| 1567 | s.PutChar('.'); |
| 1568 | } |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1569 | } |
| 1570 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1571 | } |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1572 | |
| 1573 | const char *name = GetName().GetCString(); |
| 1574 | if (name) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1575 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1576 | if (qualify_cxx_base_classes) |
| 1577 | { |
| 1578 | if (GetBaseClassPath (s)) |
| 1579 | s.PutCString("::"); |
| 1580 | } |
| 1581 | s.PutCString(name); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1582 | } |
| 1583 | } |
| 1584 | } |
| 1585 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1586 | if (is_deref_of_parent && epformat == eDereferencePointers) { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1587 | s.PutChar(')'); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1588 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1591 | lldb::ValueObjectSP |
| 1592 | ValueObject::GetValueForExpressionPath(const char* expression, |
| 1593 | const char** first_unparsed, |
| 1594 | ExpressionPathScanEndReason* reason_to_stop, |
| 1595 | ExpressionPathEndResultType* final_value_type, |
| 1596 | const GetValueForExpressionPathOptions& options, |
| 1597 | ExpressionPathAftermath* final_task_on_target) |
| 1598 | { |
| 1599 | |
| 1600 | const char* dummy_first_unparsed; |
| 1601 | ExpressionPathScanEndReason dummy_reason_to_stop; |
| 1602 | ExpressionPathEndResultType dummy_final_value_type; |
| 1603 | ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing; |
| 1604 | |
| 1605 | ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression, |
| 1606 | first_unparsed ? first_unparsed : &dummy_first_unparsed, |
| 1607 | reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, |
| 1608 | final_value_type ? final_value_type : &dummy_final_value_type, |
| 1609 | options, |
| 1610 | final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); |
| 1611 | |
| 1612 | if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing) |
| 1613 | { |
| 1614 | return ret_val; |
| 1615 | } |
| 1616 | if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects |
| 1617 | { |
| 1618 | if (*final_task_on_target == ValueObject::eDereference) |
| 1619 | { |
| 1620 | Error error; |
| 1621 | ValueObjectSP final_value = ret_val->Dereference(error); |
| 1622 | if (error.Fail() || !final_value.get()) |
| 1623 | { |
| 1624 | *reason_to_stop = ValueObject::eDereferencingFailed; |
| 1625 | *final_value_type = ValueObject::eInvalid; |
| 1626 | return ValueObjectSP(); |
| 1627 | } |
| 1628 | else |
| 1629 | { |
| 1630 | *final_task_on_target = ValueObject::eNothing; |
| 1631 | return final_value; |
| 1632 | } |
| 1633 | } |
| 1634 | if (*final_task_on_target == ValueObject::eTakeAddress) |
| 1635 | { |
| 1636 | Error error; |
| 1637 | ValueObjectSP final_value = ret_val->AddressOf(error); |
| 1638 | if (error.Fail() || !final_value.get()) |
| 1639 | { |
| 1640 | *reason_to_stop = ValueObject::eTakingAddressFailed; |
| 1641 | *final_value_type = ValueObject::eInvalid; |
| 1642 | return ValueObjectSP(); |
| 1643 | } |
| 1644 | else |
| 1645 | { |
| 1646 | *final_task_on_target = ValueObject::eNothing; |
| 1647 | return final_value; |
| 1648 | } |
| 1649 | } |
| 1650 | } |
| 1651 | return ret_val; // final_task_on_target will still have its original value, so you know I did not do it |
| 1652 | } |
| 1653 | |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1654 | int |
| 1655 | ValueObject::GetValuesForExpressionPath(const char* expression, |
| 1656 | lldb::ValueObjectListSP& list, |
| 1657 | const char** first_unparsed, |
| 1658 | ExpressionPathScanEndReason* reason_to_stop, |
| 1659 | ExpressionPathEndResultType* final_value_type, |
| 1660 | const GetValueForExpressionPathOptions& options, |
| 1661 | ExpressionPathAftermath* final_task_on_target) |
| 1662 | { |
| 1663 | const char* dummy_first_unparsed; |
| 1664 | ExpressionPathScanEndReason dummy_reason_to_stop; |
| 1665 | ExpressionPathEndResultType dummy_final_value_type; |
| 1666 | ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing; |
| 1667 | |
| 1668 | ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression, |
| 1669 | first_unparsed ? first_unparsed : &dummy_first_unparsed, |
| 1670 | reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, |
| 1671 | final_value_type ? final_value_type : &dummy_final_value_type, |
| 1672 | options, |
| 1673 | final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); |
| 1674 | |
| 1675 | if (!ret_val.get()) // if there are errors, I add nothing to the list |
| 1676 | return 0; |
| 1677 | |
| 1678 | if (*reason_to_stop != eArrayRangeOperatorMet) |
| 1679 | { |
| 1680 | // I need not expand a range, just post-process the final value and return |
| 1681 | if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing) |
| 1682 | { |
| 1683 | list->Append(ret_val); |
| 1684 | return 1; |
| 1685 | } |
| 1686 | if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects |
| 1687 | { |
| 1688 | if (*final_task_on_target == ValueObject::eDereference) |
| 1689 | { |
| 1690 | Error error; |
| 1691 | ValueObjectSP final_value = ret_val->Dereference(error); |
| 1692 | if (error.Fail() || !final_value.get()) |
| 1693 | { |
| 1694 | *reason_to_stop = ValueObject::eDereferencingFailed; |
| 1695 | *final_value_type = ValueObject::eInvalid; |
| 1696 | return 0; |
| 1697 | } |
| 1698 | else |
| 1699 | { |
| 1700 | *final_task_on_target = ValueObject::eNothing; |
| 1701 | list->Append(final_value); |
| 1702 | return 1; |
| 1703 | } |
| 1704 | } |
| 1705 | if (*final_task_on_target == ValueObject::eTakeAddress) |
| 1706 | { |
| 1707 | Error error; |
| 1708 | ValueObjectSP final_value = ret_val->AddressOf(error); |
| 1709 | if (error.Fail() || !final_value.get()) |
| 1710 | { |
| 1711 | *reason_to_stop = ValueObject::eTakingAddressFailed; |
| 1712 | *final_value_type = ValueObject::eInvalid; |
| 1713 | return 0; |
| 1714 | } |
| 1715 | else |
| 1716 | { |
| 1717 | *final_task_on_target = ValueObject::eNothing; |
| 1718 | list->Append(final_value); |
| 1719 | return 1; |
| 1720 | } |
| 1721 | } |
| 1722 | } |
| 1723 | } |
| 1724 | else |
| 1725 | { |
| 1726 | return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed, |
| 1727 | first_unparsed ? first_unparsed : &dummy_first_unparsed, |
| 1728 | ret_val, |
| 1729 | list, |
| 1730 | reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, |
| 1731 | final_value_type ? final_value_type : &dummy_final_value_type, |
| 1732 | options, |
| 1733 | final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); |
| 1734 | } |
| 1735 | // in any non-covered case, just do the obviously right thing |
| 1736 | list->Append(ret_val); |
| 1737 | return 1; |
| 1738 | } |
| 1739 | |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1740 | lldb::ValueObjectSP |
| 1741 | ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr, |
| 1742 | const char** first_unparsed, |
| 1743 | ExpressionPathScanEndReason* reason_to_stop, |
| 1744 | ExpressionPathEndResultType* final_result, |
| 1745 | const GetValueForExpressionPathOptions& options, |
| 1746 | ExpressionPathAftermath* what_next) |
| 1747 | { |
| 1748 | ValueObjectSP root = GetSP(); |
| 1749 | |
| 1750 | if (!root.get()) |
| 1751 | return ValueObjectSP(); |
| 1752 | |
| 1753 | *first_unparsed = expression_cstr; |
| 1754 | |
| 1755 | while (true) |
| 1756 | { |
| 1757 | |
| 1758 | const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr |
| 1759 | |
| 1760 | lldb::clang_type_t root_clang_type = root->GetClangType(); |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1761 | lldb::clang_type_t pointee_clang_type; |
| 1762 | Flags root_clang_type_info,pointee_clang_type_info; |
| 1763 | |
| 1764 | root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type)); |
| 1765 | if (pointee_clang_type) |
| 1766 | pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL)); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1767 | |
| 1768 | if (!expression_cstr || *expression_cstr == '\0') |
| 1769 | { |
| 1770 | *reason_to_stop = ValueObject::eEndOfString; |
| 1771 | return root; |
| 1772 | } |
| 1773 | |
| 1774 | switch (*expression_cstr) |
| 1775 | { |
| 1776 | case '-': |
| 1777 | { |
| 1778 | if (options.m_check_dot_vs_arrow_syntax && |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1779 | root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) ) // if you are trying to use -> on a non-pointer and I must catch the error |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1780 | { |
| 1781 | *first_unparsed = expression_cstr; |
| 1782 | *reason_to_stop = ValueObject::eArrowInsteadOfDot; |
| 1783 | *final_result = ValueObject::eInvalid; |
| 1784 | return ValueObjectSP(); |
| 1785 | } |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1786 | if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden |
| 1787 | root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) && |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1788 | options.m_no_fragile_ivar) |
| 1789 | { |
| 1790 | *first_unparsed = expression_cstr; |
| 1791 | *reason_to_stop = ValueObject::eFragileIVarNotAllowed; |
| 1792 | *final_result = ValueObject::eInvalid; |
| 1793 | return ValueObjectSP(); |
| 1794 | } |
| 1795 | if (expression_cstr[1] != '>') |
| 1796 | { |
| 1797 | *first_unparsed = expression_cstr; |
| 1798 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 1799 | *final_result = ValueObject::eInvalid; |
| 1800 | return ValueObjectSP(); |
| 1801 | } |
| 1802 | expression_cstr++; // skip the - |
| 1803 | } |
| 1804 | case '.': // or fallthrough from -> |
| 1805 | { |
| 1806 | if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' && |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1807 | root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if you are trying to use . on a pointer and I must catch the error |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1808 | { |
| 1809 | *first_unparsed = expression_cstr; |
| 1810 | *reason_to_stop = ValueObject::eDotInsteadOfArrow; |
| 1811 | *final_result = ValueObject::eInvalid; |
| 1812 | return ValueObjectSP(); |
| 1813 | } |
| 1814 | expression_cstr++; // skip . |
| 1815 | const char *next_separator = strpbrk(expression_cstr+1,"-.["); |
| 1816 | ConstString child_name; |
| 1817 | if (!next_separator) // if no other separator just expand this last layer |
| 1818 | { |
| 1819 | child_name.SetCString (expression_cstr); |
| 1820 | root = root->GetChildMemberWithName(child_name, true); |
| 1821 | if (root.get()) // we know we are done, so just return |
| 1822 | { |
| 1823 | *first_unparsed = '\0'; |
| 1824 | *reason_to_stop = ValueObject::eEndOfString; |
| 1825 | *final_result = ValueObject::ePlain; |
| 1826 | return root; |
| 1827 | } |
| 1828 | else |
| 1829 | { |
| 1830 | *first_unparsed = expression_cstr; |
| 1831 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 1832 | *final_result = ValueObject::eInvalid; |
| 1833 | return ValueObjectSP(); |
| 1834 | } |
| 1835 | } |
| 1836 | else // other layers do expand |
| 1837 | { |
| 1838 | child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr); |
| 1839 | root = root->GetChildMemberWithName(child_name, true); |
| 1840 | if (root.get()) // store the new root and move on |
| 1841 | { |
| 1842 | *first_unparsed = next_separator; |
| 1843 | *final_result = ValueObject::ePlain; |
| 1844 | continue; |
| 1845 | } |
| 1846 | else |
| 1847 | { |
| 1848 | *first_unparsed = expression_cstr; |
| 1849 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 1850 | *final_result = ValueObject::eInvalid; |
| 1851 | return ValueObjectSP(); |
| 1852 | } |
| 1853 | } |
| 1854 | break; |
| 1855 | } |
| 1856 | case '[': |
| 1857 | { |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1858 | if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T* |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1859 | { |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1860 | if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong! |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1861 | { |
| 1862 | *first_unparsed = expression_cstr; |
| 1863 | *reason_to_stop = ValueObject::eRangeOperatorInvalid; |
| 1864 | *final_result = ValueObject::eInvalid; |
| 1865 | return ValueObjectSP(); |
| 1866 | } |
| 1867 | else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields |
| 1868 | { |
| 1869 | *first_unparsed = expression_cstr; |
| 1870 | *reason_to_stop = ValueObject::eRangeOperatorNotAllowed; |
| 1871 | *final_result = ValueObject::eInvalid; |
| 1872 | return ValueObjectSP(); |
| 1873 | } |
| 1874 | } |
| 1875 | if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays |
| 1876 | { |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1877 | if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1878 | { |
| 1879 | *first_unparsed = expression_cstr; |
| 1880 | *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; |
| 1881 | *final_result = ValueObject::eInvalid; |
| 1882 | return ValueObjectSP(); |
| 1883 | } |
| 1884 | else // even if something follows, we cannot expand unbounded ranges, just let the caller do it |
| 1885 | { |
| 1886 | *first_unparsed = expression_cstr+2; |
| 1887 | *reason_to_stop = ValueObject::eArrayRangeOperatorMet; |
| 1888 | *final_result = ValueObject::eUnboundedRange; |
| 1889 | return root; |
| 1890 | } |
| 1891 | } |
| 1892 | const char *separator_position = ::strchr(expression_cstr+1,'-'); |
| 1893 | const char *close_bracket_position = ::strchr(expression_cstr+1,']'); |
| 1894 | if (!close_bracket_position) // if there is no ], this is a syntax error |
| 1895 | { |
| 1896 | *first_unparsed = expression_cstr; |
| 1897 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 1898 | *final_result = ValueObject::eInvalid; |
| 1899 | return ValueObjectSP(); |
| 1900 | } |
| 1901 | if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N] |
| 1902 | { |
| 1903 | char *end = NULL; |
| 1904 | unsigned long index = ::strtoul (expression_cstr+1, &end, 0); |
| 1905 | if (!end || end != close_bracket_position) // if something weird is in our way return an error |
| 1906 | { |
| 1907 | *first_unparsed = expression_cstr; |
| 1908 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 1909 | *final_result = ValueObject::eInvalid; |
| 1910 | return ValueObjectSP(); |
| 1911 | } |
| 1912 | if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays |
| 1913 | { |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1914 | if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1915 | { |
| 1916 | *first_unparsed = expression_cstr+2; |
| 1917 | *reason_to_stop = ValueObject::eArrayRangeOperatorMet; |
| 1918 | *final_result = ValueObject::eUnboundedRange; |
| 1919 | return root; |
| 1920 | } |
| 1921 | else |
| 1922 | { |
| 1923 | *first_unparsed = expression_cstr; |
| 1924 | *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; |
| 1925 | *final_result = ValueObject::eInvalid; |
| 1926 | return ValueObjectSP(); |
| 1927 | } |
| 1928 | } |
| 1929 | // from here on we do have a valid index |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1930 | if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1931 | { |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 1932 | ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true); |
| 1933 | if (!child_valobj_sp) |
| 1934 | child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true); |
| 1935 | if (child_valobj_sp) |
| 1936 | { |
| 1937 | root = child_valobj_sp; |
| 1938 | *first_unparsed = end+1; // skip ] |
| 1939 | *final_result = ValueObject::ePlain; |
| 1940 | continue; |
| 1941 | } |
| 1942 | else |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1943 | { |
| 1944 | *first_unparsed = expression_cstr; |
| 1945 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 1946 | *final_result = ValueObject::eInvalid; |
| 1947 | return ValueObjectSP(); |
| 1948 | } |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1949 | } |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1950 | else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1951 | { |
| 1952 | if (*what_next == ValueObject::eDereference && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1953 | pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1954 | { |
| 1955 | Error error; |
| 1956 | root = root->Dereference(error); |
| 1957 | if (error.Fail() || !root.get()) |
| 1958 | { |
| 1959 | *first_unparsed = expression_cstr; |
| 1960 | *reason_to_stop = ValueObject::eDereferencingFailed; |
| 1961 | *final_result = ValueObject::eInvalid; |
| 1962 | return ValueObjectSP(); |
| 1963 | } |
| 1964 | else |
| 1965 | { |
| 1966 | *what_next = eNothing; |
| 1967 | continue; |
| 1968 | } |
| 1969 | } |
| 1970 | else |
| 1971 | { |
| 1972 | root = root->GetSyntheticArrayMemberFromPointer(index, true); |
| 1973 | if (!root.get()) |
| 1974 | { |
| 1975 | *first_unparsed = expression_cstr; |
| 1976 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 1977 | *final_result = ValueObject::eInvalid; |
| 1978 | return ValueObjectSP(); |
| 1979 | } |
| 1980 | else |
| 1981 | { |
| 1982 | *first_unparsed = end+1; // skip ] |
| 1983 | *final_result = ValueObject::ePlain; |
| 1984 | continue; |
| 1985 | } |
| 1986 | } |
| 1987 | } |
| 1988 | else /*if (ClangASTContext::IsScalarType(root_clang_type))*/ |
| 1989 | { |
| 1990 | root = root->GetSyntheticBitFieldChild(index, index, true); |
| 1991 | if (!root.get()) |
| 1992 | { |
| 1993 | *first_unparsed = expression_cstr; |
| 1994 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 1995 | *final_result = ValueObject::eInvalid; |
| 1996 | return ValueObjectSP(); |
| 1997 | } |
| 1998 | else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing |
| 1999 | { |
| 2000 | *first_unparsed = end+1; // skip ] |
| 2001 | *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet; |
| 2002 | *final_result = ValueObject::eBitfield; |
| 2003 | return root; |
| 2004 | } |
| 2005 | } |
| 2006 | } |
| 2007 | else // we have a low and a high index |
| 2008 | { |
| 2009 | char *end = NULL; |
| 2010 | unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0); |
| 2011 | if (!end || end != separator_position) // if something weird is in our way return an error |
| 2012 | { |
| 2013 | *first_unparsed = expression_cstr; |
| 2014 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2015 | *final_result = ValueObject::eInvalid; |
| 2016 | return ValueObjectSP(); |
| 2017 | } |
| 2018 | unsigned long index_higher = ::strtoul (separator_position+1, &end, 0); |
| 2019 | if (!end || end != close_bracket_position) // if something weird is in our way return an error |
| 2020 | { |
| 2021 | *first_unparsed = expression_cstr; |
| 2022 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2023 | *final_result = ValueObject::eInvalid; |
| 2024 | return ValueObjectSP(); |
| 2025 | } |
| 2026 | if (index_lower > index_higher) // swap indices if required |
| 2027 | { |
| 2028 | unsigned long temp = index_lower; |
| 2029 | index_lower = index_higher; |
| 2030 | index_higher = temp; |
| 2031 | } |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2032 | if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2033 | { |
| 2034 | root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true); |
| 2035 | if (!root.get()) |
| 2036 | { |
| 2037 | *first_unparsed = expression_cstr; |
| 2038 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2039 | *final_result = ValueObject::eInvalid; |
| 2040 | return ValueObjectSP(); |
| 2041 | } |
| 2042 | else |
| 2043 | { |
| 2044 | *first_unparsed = end+1; // skip ] |
| 2045 | *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet; |
| 2046 | *final_result = ValueObject::eBitfield; |
| 2047 | return root; |
| 2048 | } |
| 2049 | } |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2050 | else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2051 | *what_next == ValueObject::eDereference && |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2052 | pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2053 | { |
| 2054 | Error error; |
| 2055 | root = root->Dereference(error); |
| 2056 | if (error.Fail() || !root.get()) |
| 2057 | { |
| 2058 | *first_unparsed = expression_cstr; |
| 2059 | *reason_to_stop = ValueObject::eDereferencingFailed; |
| 2060 | *final_result = ValueObject::eInvalid; |
| 2061 | return ValueObjectSP(); |
| 2062 | } |
| 2063 | else |
| 2064 | { |
| 2065 | *what_next = ValueObject::eNothing; |
| 2066 | continue; |
| 2067 | } |
| 2068 | } |
| 2069 | else |
| 2070 | { |
| 2071 | *first_unparsed = expression_cstr; |
| 2072 | *reason_to_stop = ValueObject::eArrayRangeOperatorMet; |
| 2073 | *final_result = ValueObject::eBoundedRange; |
| 2074 | return root; |
| 2075 | } |
| 2076 | } |
| 2077 | break; |
| 2078 | } |
| 2079 | default: // some non-separator is in the way |
| 2080 | { |
| 2081 | *first_unparsed = expression_cstr; |
| 2082 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2083 | *final_result = ValueObject::eInvalid; |
| 2084 | return ValueObjectSP(); |
| 2085 | break; |
| 2086 | } |
| 2087 | } |
| 2088 | } |
| 2089 | } |
| 2090 | |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2091 | int |
| 2092 | ValueObject::ExpandArraySliceExpression(const char* expression_cstr, |
| 2093 | const char** first_unparsed, |
| 2094 | lldb::ValueObjectSP root, |
| 2095 | lldb::ValueObjectListSP& list, |
| 2096 | ExpressionPathScanEndReason* reason_to_stop, |
| 2097 | ExpressionPathEndResultType* final_result, |
| 2098 | const GetValueForExpressionPathOptions& options, |
| 2099 | ExpressionPathAftermath* what_next) |
| 2100 | { |
| 2101 | if (!root.get()) |
| 2102 | return 0; |
| 2103 | |
| 2104 | *first_unparsed = expression_cstr; |
| 2105 | |
| 2106 | while (true) |
| 2107 | { |
| 2108 | |
| 2109 | const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr |
| 2110 | |
| 2111 | lldb::clang_type_t root_clang_type = root->GetClangType(); |
| 2112 | lldb::clang_type_t pointee_clang_type; |
| 2113 | Flags root_clang_type_info,pointee_clang_type_info; |
| 2114 | |
| 2115 | root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type)); |
| 2116 | if (pointee_clang_type) |
| 2117 | pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL)); |
| 2118 | |
| 2119 | if (!expression_cstr || *expression_cstr == '\0') |
| 2120 | { |
| 2121 | *reason_to_stop = ValueObject::eEndOfString; |
| 2122 | list->Append(root); |
| 2123 | return 1; |
| 2124 | } |
| 2125 | |
| 2126 | switch (*expression_cstr) |
| 2127 | { |
| 2128 | case '[': |
| 2129 | { |
| 2130 | if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T* |
| 2131 | { |
| 2132 | if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong! |
| 2133 | { |
| 2134 | *first_unparsed = expression_cstr; |
| 2135 | *reason_to_stop = ValueObject::eRangeOperatorInvalid; |
| 2136 | *final_result = ValueObject::eInvalid; |
| 2137 | return 0; |
| 2138 | } |
| 2139 | else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields |
| 2140 | { |
| 2141 | *first_unparsed = expression_cstr; |
| 2142 | *reason_to_stop = ValueObject::eRangeOperatorNotAllowed; |
| 2143 | *final_result = ValueObject::eInvalid; |
| 2144 | return 0; |
| 2145 | } |
| 2146 | } |
| 2147 | if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays |
| 2148 | { |
| 2149 | if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) |
| 2150 | { |
| 2151 | *first_unparsed = expression_cstr; |
| 2152 | *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; |
| 2153 | *final_result = ValueObject::eInvalid; |
| 2154 | return 0; |
| 2155 | } |
| 2156 | else // expand this into list |
| 2157 | { |
| 2158 | int max_index = root->GetNumChildren() - 1; |
| 2159 | for (int index = 0; index < max_index; index++) |
| 2160 | { |
| 2161 | ValueObjectSP child = |
| 2162 | root->GetChildAtIndex(index, true); |
| 2163 | list->Append(child); |
| 2164 | } |
| 2165 | *first_unparsed = expression_cstr+2; |
| 2166 | *reason_to_stop = ValueObject::eRangeOperatorExpanded; |
| 2167 | *final_result = ValueObject::eValueObjectList; |
| 2168 | return max_index; // tell me number of items I added to the VOList |
| 2169 | } |
| 2170 | } |
| 2171 | const char *separator_position = ::strchr(expression_cstr+1,'-'); |
| 2172 | const char *close_bracket_position = ::strchr(expression_cstr+1,']'); |
| 2173 | if (!close_bracket_position) // if there is no ], this is a syntax error |
| 2174 | { |
| 2175 | *first_unparsed = expression_cstr; |
| 2176 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2177 | *final_result = ValueObject::eInvalid; |
| 2178 | return 0; |
| 2179 | } |
| 2180 | if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N] |
| 2181 | { |
| 2182 | char *end = NULL; |
| 2183 | unsigned long index = ::strtoul (expression_cstr+1, &end, 0); |
| 2184 | if (!end || end != close_bracket_position) // if something weird is in our way return an error |
| 2185 | { |
| 2186 | *first_unparsed = expression_cstr; |
| 2187 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2188 | *final_result = ValueObject::eInvalid; |
| 2189 | return 0; |
| 2190 | } |
| 2191 | if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays |
| 2192 | { |
| 2193 | if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) |
| 2194 | { |
| 2195 | int max_index = root->GetNumChildren() - 1; |
| 2196 | for (int index = 0; index < max_index; index++) |
| 2197 | { |
| 2198 | ValueObjectSP child = |
| 2199 | root->GetChildAtIndex(index, true); |
| 2200 | list->Append(child); |
| 2201 | } |
| 2202 | *first_unparsed = expression_cstr+2; |
| 2203 | *reason_to_stop = ValueObject::eRangeOperatorExpanded; |
| 2204 | *final_result = ValueObject::eValueObjectList; |
| 2205 | return max_index; // tell me number of items I added to the VOList |
| 2206 | } |
| 2207 | else |
| 2208 | { |
| 2209 | *first_unparsed = expression_cstr; |
| 2210 | *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; |
| 2211 | *final_result = ValueObject::eInvalid; |
| 2212 | return 0; |
| 2213 | } |
| 2214 | } |
| 2215 | // from here on we do have a valid index |
| 2216 | if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) |
| 2217 | { |
| 2218 | root = root->GetChildAtIndex(index, true); |
| 2219 | if (!root.get()) |
| 2220 | { |
| 2221 | *first_unparsed = expression_cstr; |
| 2222 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2223 | *final_result = ValueObject::eInvalid; |
| 2224 | return 0; |
| 2225 | } |
| 2226 | else |
| 2227 | { |
| 2228 | list->Append(root); |
| 2229 | *first_unparsed = end+1; // skip ] |
| 2230 | *reason_to_stop = ValueObject::eRangeOperatorExpanded; |
| 2231 | *final_result = ValueObject::eValueObjectList; |
| 2232 | return 1; |
| 2233 | } |
| 2234 | } |
| 2235 | else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) |
| 2236 | { |
| 2237 | if (*what_next == ValueObject::eDereference && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield |
| 2238 | pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) |
| 2239 | { |
| 2240 | Error error; |
| 2241 | root = root->Dereference(error); |
| 2242 | if (error.Fail() || !root.get()) |
| 2243 | { |
| 2244 | *first_unparsed = expression_cstr; |
| 2245 | *reason_to_stop = ValueObject::eDereferencingFailed; |
| 2246 | *final_result = ValueObject::eInvalid; |
| 2247 | return 0; |
| 2248 | } |
| 2249 | else |
| 2250 | { |
| 2251 | *what_next = eNothing; |
| 2252 | continue; |
| 2253 | } |
| 2254 | } |
| 2255 | else |
| 2256 | { |
| 2257 | root = root->GetSyntheticArrayMemberFromPointer(index, true); |
| 2258 | if (!root.get()) |
| 2259 | { |
| 2260 | *first_unparsed = expression_cstr; |
| 2261 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2262 | *final_result = ValueObject::eInvalid; |
| 2263 | return 0; |
| 2264 | } |
| 2265 | else |
| 2266 | { |
| 2267 | list->Append(root); |
| 2268 | *first_unparsed = end+1; // skip ] |
| 2269 | *reason_to_stop = ValueObject::eRangeOperatorExpanded; |
| 2270 | *final_result = ValueObject::eValueObjectList; |
| 2271 | return 1; |
| 2272 | } |
| 2273 | } |
| 2274 | } |
| 2275 | else /*if (ClangASTContext::IsScalarType(root_clang_type))*/ |
| 2276 | { |
| 2277 | root = root->GetSyntheticBitFieldChild(index, index, true); |
| 2278 | if (!root.get()) |
| 2279 | { |
| 2280 | *first_unparsed = expression_cstr; |
| 2281 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2282 | *final_result = ValueObject::eInvalid; |
| 2283 | return 0; |
| 2284 | } |
| 2285 | else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing |
| 2286 | { |
| 2287 | list->Append(root); |
| 2288 | *first_unparsed = end+1; // skip ] |
| 2289 | *reason_to_stop = ValueObject::eRangeOperatorExpanded; |
| 2290 | *final_result = ValueObject::eValueObjectList; |
| 2291 | return 1; |
| 2292 | } |
| 2293 | } |
| 2294 | } |
| 2295 | else // we have a low and a high index |
| 2296 | { |
| 2297 | char *end = NULL; |
| 2298 | unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0); |
| 2299 | if (!end || end != separator_position) // if something weird is in our way return an error |
| 2300 | { |
| 2301 | *first_unparsed = expression_cstr; |
| 2302 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2303 | *final_result = ValueObject::eInvalid; |
| 2304 | return 0; |
| 2305 | } |
| 2306 | unsigned long index_higher = ::strtoul (separator_position+1, &end, 0); |
| 2307 | if (!end || end != close_bracket_position) // if something weird is in our way return an error |
| 2308 | { |
| 2309 | *first_unparsed = expression_cstr; |
| 2310 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2311 | *final_result = ValueObject::eInvalid; |
| 2312 | return 0; |
| 2313 | } |
| 2314 | if (index_lower > index_higher) // swap indices if required |
| 2315 | { |
| 2316 | unsigned long temp = index_lower; |
| 2317 | index_lower = index_higher; |
| 2318 | index_higher = temp; |
| 2319 | } |
| 2320 | if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars |
| 2321 | { |
| 2322 | root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true); |
| 2323 | if (!root.get()) |
| 2324 | { |
| 2325 | *first_unparsed = expression_cstr; |
| 2326 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2327 | *final_result = ValueObject::eInvalid; |
| 2328 | return 0; |
| 2329 | } |
| 2330 | else |
| 2331 | { |
| 2332 | list->Append(root); |
| 2333 | *first_unparsed = end+1; // skip ] |
| 2334 | *reason_to_stop = ValueObject::eRangeOperatorExpanded; |
| 2335 | *final_result = ValueObject::eValueObjectList; |
| 2336 | return 1; |
| 2337 | } |
| 2338 | } |
| 2339 | else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield |
| 2340 | *what_next == ValueObject::eDereference && |
| 2341 | pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) |
| 2342 | { |
| 2343 | Error error; |
| 2344 | root = root->Dereference(error); |
| 2345 | if (error.Fail() || !root.get()) |
| 2346 | { |
| 2347 | *first_unparsed = expression_cstr; |
| 2348 | *reason_to_stop = ValueObject::eDereferencingFailed; |
| 2349 | *final_result = ValueObject::eInvalid; |
| 2350 | return 0; |
| 2351 | } |
| 2352 | else |
| 2353 | { |
| 2354 | *what_next = ValueObject::eNothing; |
| 2355 | continue; |
| 2356 | } |
| 2357 | } |
| 2358 | else |
| 2359 | { |
| 2360 | for (int index = index_lower; |
| 2361 | index <= index_higher; index++) |
| 2362 | { |
| 2363 | ValueObjectSP child = |
| 2364 | root->GetChildAtIndex(index, true); |
| 2365 | list->Append(child); |
| 2366 | } |
| 2367 | *first_unparsed = end+1; |
| 2368 | *reason_to_stop = ValueObject::eRangeOperatorExpanded; |
| 2369 | *final_result = ValueObject::eValueObjectList; |
| 2370 | return index_higher-index_lower+1; // tell me number of items I added to the VOList |
| 2371 | } |
| 2372 | } |
| 2373 | break; |
| 2374 | } |
| 2375 | default: // some non-[ separator, or something entirely wrong, is in the way |
| 2376 | { |
| 2377 | *first_unparsed = expression_cstr; |
| 2378 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2379 | *final_result = ValueObject::eInvalid; |
| 2380 | return 0; |
| 2381 | break; |
| 2382 | } |
| 2383 | } |
| 2384 | } |
| 2385 | } |
| 2386 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2387 | void |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2388 | ValueObject::DumpValueObject |
| 2389 | ( |
| 2390 | Stream &s, |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2391 | ValueObject *valobj, |
| 2392 | const char *root_valobj_name, |
| 2393 | uint32_t ptr_depth, |
| 2394 | uint32_t curr_depth, |
| 2395 | uint32_t max_depth, |
| 2396 | bool show_types, |
| 2397 | bool show_location, |
| 2398 | bool use_objc, |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 2399 | lldb::DynamicValueType use_dynamic, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2400 | bool scope_already_checked, |
Enrico Granata | 0c5ef69 | 2011-07-16 01:22:04 +0000 | [diff] [blame] | 2401 | bool flat_output, |
| 2402 | uint32_t omit_summary_depth |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2403 | ) |
| 2404 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 2405 | if (valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2406 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 2407 | bool update_success = valobj->UpdateValueIfNeeded (); |
| 2408 | |
| 2409 | if (update_success && use_dynamic != lldb::eNoDynamicValues) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2410 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 2411 | ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2412 | if (dynamic_value) |
| 2413 | valobj = dynamic_value; |
| 2414 | } |
| 2415 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2416 | clang_type_t clang_type = valobj->GetClangType(); |
| 2417 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2418 | const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL)); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2419 | const char *err_cstr = NULL; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2420 | const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren); |
| 2421 | const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2422 | |
| 2423 | const bool print_valobj = flat_output == false || has_value; |
| 2424 | |
| 2425 | if (print_valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2426 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2427 | if (show_location) |
| 2428 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2429 | s.Printf("%s: ", valobj->GetLocationAsCString()); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2430 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2431 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2432 | s.Indent(); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2433 | |
Greg Clayton | 7c8a966 | 2010-11-02 01:50:16 +0000 | [diff] [blame] | 2434 | // Always show the type for the top level items. |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2435 | if (show_types || (curr_depth == 0 && !flat_output)) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2436 | s.Printf("(%s) ", valobj->GetTypeName().AsCString("<invalid type>")); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2437 | |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2438 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2439 | if (flat_output) |
| 2440 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2441 | // If we are showing types, also qualify the C++ base classes |
| 2442 | const bool qualify_cxx_base_classes = show_types; |
| 2443 | valobj->GetExpressionPath(s, qualify_cxx_base_classes); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2444 | s.PutCString(" ="); |
| 2445 | } |
| 2446 | else |
| 2447 | { |
| 2448 | const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString(""); |
| 2449 | s.Printf ("%s =", name_cstr); |
| 2450 | } |
| 2451 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2452 | if (!scope_already_checked && !valobj->IsInScope()) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2453 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 2454 | err_cstr = "out of scope"; |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2455 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2456 | } |
| 2457 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2458 | const char *val_cstr = NULL; |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2459 | const char *sum_cstr = NULL; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2460 | SummaryFormat* entry = valobj->GetSummaryFormat().get(); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2461 | |
Enrico Granata | 0c5ef69 | 2011-07-16 01:22:04 +0000 | [diff] [blame] | 2462 | if (omit_summary_depth > 0) |
| 2463 | entry = NULL; |
| 2464 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2465 | if (err_cstr == NULL) |
| 2466 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2467 | val_cstr = valobj->GetValueAsCString(); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2468 | err_cstr = valobj->GetError().AsCString(); |
| 2469 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2470 | |
| 2471 | if (err_cstr) |
| 2472 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 2473 | s.Printf (" <%s>\n", err_cstr); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2474 | } |
| 2475 | else |
| 2476 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2477 | const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2478 | if (print_valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2479 | { |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2480 | |
Enrico Granata | 0c5ef69 | 2011-07-16 01:22:04 +0000 | [diff] [blame] | 2481 | sum_cstr = (omit_summary_depth == 0) ? valobj->GetSummaryAsCString() : NULL; |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2482 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2483 | // We must calculate this value in realtime because entry might alter this variable's value |
| 2484 | // (e.g. by saying ${var%fmt}) and render precached values useless |
| 2485 | if (val_cstr && (!entry || entry->DoesPrintValue() || !sum_cstr)) |
| 2486 | s.Printf(" %s", valobj->GetValueAsCString()); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2487 | |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 2488 | if (sum_cstr) |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 2489 | { |
| 2490 | // for some reason, using %@ (ObjC description) in a summary string, makes |
| 2491 | // us believe we need to reset ourselves, thus invalidating the content of |
| 2492 | // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty |
| 2493 | // let us recalculate it! |
| 2494 | if (sum_cstr[0] == '\0') |
| 2495 | s.Printf(" %s", valobj->GetSummaryAsCString()); |
| 2496 | else |
| 2497 | s.Printf(" %s", sum_cstr); |
| 2498 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2499 | |
| 2500 | if (use_objc) |
| 2501 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2502 | const char *object_desc = valobj->GetObjectDescription(); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2503 | if (object_desc) |
| 2504 | s.Printf(" %s\n", object_desc); |
| 2505 | else |
Sean Callanan | 672ad94 | 2010-10-23 00:18:49 +0000 | [diff] [blame] | 2506 | s.Printf (" [no Objective-C description available]\n"); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2507 | return; |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 2508 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2509 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2510 | |
| 2511 | if (curr_depth < max_depth) |
| 2512 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2513 | // We will show children for all concrete types. We won't show |
| 2514 | // pointer contents unless a pointer depth has been specified. |
| 2515 | // We won't reference contents unless the reference is the |
| 2516 | // root object (depth of zero). |
| 2517 | bool print_children = true; |
| 2518 | |
| 2519 | // Use a new temporary pointer depth in case we override the |
| 2520 | // current pointer depth below... |
| 2521 | uint32_t curr_ptr_depth = ptr_depth; |
| 2522 | |
| 2523 | const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer); |
| 2524 | if (is_ptr || is_ref) |
| 2525 | { |
| 2526 | // We have a pointer or reference whose value is an address. |
| 2527 | // Make sure that address is not NULL |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 2528 | AddressType ptr_address_type; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2529 | if (valobj->GetPointerValue (ptr_address_type, true) == 0) |
| 2530 | print_children = false; |
| 2531 | |
| 2532 | else if (is_ref && curr_depth == 0) |
| 2533 | { |
| 2534 | // If this is the root object (depth is zero) that we are showing |
| 2535 | // and it is a reference, and no pointer depth has been supplied |
| 2536 | // print out what it references. Don't do this at deeper depths |
| 2537 | // otherwise we can end up with infinite recursion... |
| 2538 | curr_ptr_depth = 1; |
| 2539 | } |
| 2540 | |
| 2541 | if (curr_ptr_depth == 0) |
| 2542 | print_children = false; |
| 2543 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2544 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 2545 | if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr)) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2546 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2547 | const uint32_t num_children = valobj->GetNumChildren(); |
| 2548 | if (num_children) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2549 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2550 | if (flat_output) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2551 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2552 | if (print_valobj) |
| 2553 | s.EOL(); |
| 2554 | } |
| 2555 | else |
| 2556 | { |
| 2557 | if (print_valobj) |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 2558 | s.PutCString(is_ref ? ": {\n" : " {\n"); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2559 | s.IndentMore(); |
| 2560 | } |
| 2561 | |
| 2562 | for (uint32_t idx=0; idx<num_children; ++idx) |
| 2563 | { |
| 2564 | ValueObjectSP child_sp(valobj->GetChildAtIndex(idx, true)); |
| 2565 | if (child_sp.get()) |
| 2566 | { |
| 2567 | DumpValueObject (s, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2568 | child_sp.get(), |
| 2569 | NULL, |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2570 | (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2571 | curr_depth + 1, |
| 2572 | max_depth, |
| 2573 | show_types, |
| 2574 | show_location, |
| 2575 | false, |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2576 | use_dynamic, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2577 | true, |
Enrico Granata | 0c5ef69 | 2011-07-16 01:22:04 +0000 | [diff] [blame] | 2578 | flat_output, |
| 2579 | omit_summary_depth > 1 ? omit_summary_depth - 1 : 0); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2580 | } |
| 2581 | } |
| 2582 | |
| 2583 | if (!flat_output) |
| 2584 | { |
| 2585 | s.IndentLess(); |
| 2586 | s.Indent("}\n"); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2587 | } |
| 2588 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2589 | else if (has_children) |
| 2590 | { |
| 2591 | // Aggregate, no children... |
| 2592 | if (print_valobj) |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2593 | s.PutCString(" {}\n"); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2594 | } |
| 2595 | else |
| 2596 | { |
| 2597 | if (print_valobj) |
| 2598 | s.EOL(); |
| 2599 | } |
| 2600 | |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2601 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2602 | else |
| 2603 | { |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2604 | s.EOL(); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2605 | } |
| 2606 | } |
| 2607 | else |
| 2608 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2609 | if (has_children && print_valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2610 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2611 | s.PutCString("{...}\n"); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2612 | } |
| 2613 | } |
| 2614 | } |
| 2615 | } |
| 2616 | } |
| 2617 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2618 | |
| 2619 | ValueObjectSP |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2620 | ValueObject::CreateConstantValue (const ConstString &name) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2621 | { |
| 2622 | ValueObjectSP valobj_sp; |
| 2623 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2624 | if (UpdateValueIfNeeded() && m_error.Success()) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2625 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2626 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 2627 | if (exe_scope) |
| 2628 | { |
| 2629 | ExecutionContext exe_ctx; |
| 2630 | exe_scope->CalculateExecutionContext(exe_ctx); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2631 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2632 | clang::ASTContext *ast = GetClangAST (); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2633 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2634 | DataExtractor data; |
| 2635 | data.SetByteOrder (m_data.GetByteOrder()); |
| 2636 | data.SetAddressByteSize(m_data.GetAddressByteSize()); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2637 | |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 2638 | m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule()); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2639 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2640 | valobj_sp = ValueObjectConstResult::Create (exe_scope, |
| 2641 | ast, |
| 2642 | GetClangType(), |
| 2643 | name, |
| 2644 | data); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2645 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2646 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2647 | |
| 2648 | if (!valobj_sp) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2649 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2650 | valobj_sp = ValueObjectConstResult::Create (NULL, m_error); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2651 | } |
| 2652 | return valobj_sp; |
| 2653 | } |
| 2654 | |
| 2655 | lldb::ValueObjectSP |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 2656 | ValueObject::Dereference (Error &error) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2657 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2658 | if (m_deref_valobj) |
| 2659 | return m_deref_valobj->GetSP(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2660 | |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2661 | const bool is_pointer_type = IsPointerType(); |
| 2662 | if (is_pointer_type) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2663 | { |
| 2664 | bool omit_empty_base_classes = true; |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 2665 | bool ignore_array_bounds = false; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2666 | |
| 2667 | std::string child_name_str; |
| 2668 | uint32_t child_byte_size = 0; |
| 2669 | int32_t child_byte_offset = 0; |
| 2670 | uint32_t child_bitfield_bit_size = 0; |
| 2671 | uint32_t child_bitfield_bit_offset = 0; |
| 2672 | bool child_is_base_class = false; |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2673 | bool child_is_deref_of_parent = false; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2674 | const bool transparent_pointers = false; |
| 2675 | clang::ASTContext *clang_ast = GetClangAST(); |
| 2676 | clang_type_t clang_type = GetClangType(); |
| 2677 | clang_type_t child_clang_type; |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 2678 | |
| 2679 | ExecutionContext exe_ctx; |
| 2680 | GetExecutionContextScope()->CalculateExecutionContext (exe_ctx); |
| 2681 | |
| 2682 | child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx, |
| 2683 | clang_ast, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2684 | GetName().GetCString(), |
| 2685 | clang_type, |
| 2686 | 0, |
| 2687 | transparent_pointers, |
| 2688 | omit_empty_base_classes, |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 2689 | ignore_array_bounds, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2690 | child_name_str, |
| 2691 | child_byte_size, |
| 2692 | child_byte_offset, |
| 2693 | child_bitfield_bit_size, |
| 2694 | child_bitfield_bit_offset, |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2695 | child_is_base_class, |
| 2696 | child_is_deref_of_parent); |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 2697 | if (child_clang_type && child_byte_size) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2698 | { |
| 2699 | ConstString child_name; |
| 2700 | if (!child_name_str.empty()) |
| 2701 | child_name.SetCString (child_name_str.c_str()); |
| 2702 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2703 | m_deref_valobj = new ValueObjectChild (*this, |
| 2704 | clang_ast, |
| 2705 | child_clang_type, |
| 2706 | child_name, |
| 2707 | child_byte_size, |
| 2708 | child_byte_offset, |
| 2709 | child_bitfield_bit_size, |
| 2710 | child_bitfield_bit_offset, |
| 2711 | child_is_base_class, |
| 2712 | child_is_deref_of_parent); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2713 | } |
| 2714 | } |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2715 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2716 | if (m_deref_valobj) |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2717 | { |
| 2718 | error.Clear(); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2719 | return m_deref_valobj->GetSP(); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2720 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2721 | else |
| 2722 | { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2723 | StreamString strm; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2724 | GetExpressionPath(strm, true); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2725 | |
| 2726 | if (is_pointer_type) |
| 2727 | error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str()); |
| 2728 | else |
| 2729 | 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] | 2730 | return ValueObjectSP(); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2731 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2732 | } |
| 2733 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2734 | lldb::ValueObjectSP |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2735 | ValueObject::AddressOf (Error &error) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2736 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2737 | if (m_addr_of_valobj_sp) |
| 2738 | return m_addr_of_valobj_sp; |
| 2739 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 2740 | AddressType address_type = eAddressTypeInvalid; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2741 | const bool scalar_is_load_address = false; |
| 2742 | lldb::addr_t addr = GetAddressOf (address_type, scalar_is_load_address); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2743 | error.Clear(); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2744 | if (addr != LLDB_INVALID_ADDRESS) |
| 2745 | { |
| 2746 | switch (address_type) |
| 2747 | { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2748 | default: |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2749 | case eAddressTypeInvalid: |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2750 | { |
| 2751 | StreamString expr_path_strm; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2752 | GetExpressionPath(expr_path_strm, true); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2753 | error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str()); |
| 2754 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2755 | break; |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 2756 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2757 | case eAddressTypeFile: |
| 2758 | case eAddressTypeLoad: |
| 2759 | case eAddressTypeHost: |
| 2760 | { |
| 2761 | clang::ASTContext *ast = GetClangAST(); |
| 2762 | clang_type_t clang_type = GetClangType(); |
| 2763 | if (ast && clang_type) |
| 2764 | { |
| 2765 | std::string name (1, '&'); |
| 2766 | name.append (m_name.AsCString("")); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2767 | m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(), |
| 2768 | ast, |
| 2769 | ClangASTContext::CreatePointerType (ast, clang_type), |
| 2770 | ConstString (name.c_str()), |
| 2771 | addr, |
| 2772 | eAddressTypeInvalid, |
| 2773 | m_data.GetAddressByteSize()); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2774 | } |
| 2775 | } |
| 2776 | break; |
| 2777 | } |
| 2778 | } |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2779 | return m_addr_of_valobj_sp; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2780 | } |
| 2781 | |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 2782 | |
| 2783 | lldb::ValueObjectSP |
| 2784 | ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type) |
| 2785 | { |
| 2786 | lldb::ValueObjectSP valobj_sp; |
| 2787 | AddressType address_type; |
| 2788 | const bool scalar_is_load_address = true; |
| 2789 | lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address); |
| 2790 | |
| 2791 | if (ptr_value != LLDB_INVALID_ADDRESS) |
| 2792 | { |
| 2793 | Address ptr_addr (NULL, ptr_value); |
| 2794 | |
| 2795 | valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(), |
| 2796 | name, |
| 2797 | ptr_addr, |
| 2798 | clang_ast_type); |
| 2799 | } |
| 2800 | return valobj_sp; |
| 2801 | } |
| 2802 | |
| 2803 | lldb::ValueObjectSP |
| 2804 | ValueObject::CastPointerType (const char *name, TypeSP &type_sp) |
| 2805 | { |
| 2806 | lldb::ValueObjectSP valobj_sp; |
| 2807 | AddressType address_type; |
| 2808 | const bool scalar_is_load_address = true; |
| 2809 | lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address); |
| 2810 | |
| 2811 | if (ptr_value != LLDB_INVALID_ADDRESS) |
| 2812 | { |
| 2813 | Address ptr_addr (NULL, ptr_value); |
| 2814 | |
| 2815 | valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(), |
| 2816 | name, |
| 2817 | ptr_addr, |
| 2818 | type_sp); |
| 2819 | } |
| 2820 | return valobj_sp; |
| 2821 | } |
| 2822 | |
| 2823 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2824 | ValueObject::EvaluationPoint::EvaluationPoint () : |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 2825 | m_thread_id (LLDB_INVALID_UID), |
| 2826 | m_stop_id (0) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2827 | { |
| 2828 | } |
| 2829 | |
| 2830 | ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected): |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2831 | m_needs_update (true), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 2832 | m_first_update (true), |
Jim Ingham | 89b6109 | 2011-07-06 17:42:14 +0000 | [diff] [blame] | 2833 | m_thread_id (LLDB_INVALID_THREAD_ID), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 2834 | m_stop_id (0) |
| 2835 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2836 | { |
| 2837 | ExecutionContext exe_ctx; |
| 2838 | ExecutionContextScope *computed_exe_scope = exe_scope; // If use_selected is true, we may find a better scope, |
| 2839 | // and if so we want to cache that not the original. |
| 2840 | if (exe_scope) |
| 2841 | exe_scope->CalculateExecutionContext(exe_ctx); |
| 2842 | if (exe_ctx.target != NULL) |
| 2843 | { |
| 2844 | m_target_sp = exe_ctx.target->GetSP(); |
| 2845 | |
| 2846 | if (exe_ctx.process == NULL) |
| 2847 | m_process_sp = exe_ctx.target->GetProcessSP(); |
| 2848 | else |
| 2849 | m_process_sp = exe_ctx.process->GetSP(); |
| 2850 | |
| 2851 | if (m_process_sp != NULL) |
| 2852 | { |
| 2853 | m_stop_id = m_process_sp->GetStopID(); |
| 2854 | Thread *thread = NULL; |
| 2855 | |
| 2856 | if (exe_ctx.thread == NULL) |
| 2857 | { |
| 2858 | if (use_selected) |
| 2859 | { |
| 2860 | thread = m_process_sp->GetThreadList().GetSelectedThread().get(); |
| 2861 | if (thread) |
| 2862 | computed_exe_scope = thread; |
| 2863 | } |
| 2864 | } |
| 2865 | else |
| 2866 | thread = exe_ctx.thread; |
| 2867 | |
| 2868 | if (thread != NULL) |
| 2869 | { |
| 2870 | m_thread_id = thread->GetIndexID(); |
| 2871 | if (exe_ctx.frame == NULL) |
| 2872 | { |
| 2873 | if (use_selected) |
| 2874 | { |
| 2875 | StackFrame *frame = exe_ctx.thread->GetSelectedFrame().get(); |
| 2876 | if (frame) |
| 2877 | { |
| 2878 | m_stack_id = frame->GetStackID(); |
| 2879 | computed_exe_scope = frame; |
| 2880 | } |
| 2881 | } |
| 2882 | } |
| 2883 | else |
| 2884 | m_stack_id = exe_ctx.frame->GetStackID(); |
| 2885 | } |
| 2886 | } |
| 2887 | } |
| 2888 | m_exe_scope = computed_exe_scope; |
| 2889 | } |
| 2890 | |
| 2891 | ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) : |
| 2892 | m_exe_scope (rhs.m_exe_scope), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 2893 | m_needs_update(true), |
| 2894 | m_first_update(true), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2895 | m_target_sp (rhs.m_target_sp), |
| 2896 | m_process_sp (rhs.m_process_sp), |
| 2897 | m_thread_id (rhs.m_thread_id), |
| 2898 | m_stack_id (rhs.m_stack_id), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2899 | m_stop_id (0) |
| 2900 | { |
| 2901 | } |
| 2902 | |
| 2903 | ValueObject::EvaluationPoint::~EvaluationPoint () |
| 2904 | { |
| 2905 | } |
| 2906 | |
| 2907 | ExecutionContextScope * |
| 2908 | ValueObject::EvaluationPoint::GetExecutionContextScope () |
| 2909 | { |
| 2910 | // We have to update before giving out the scope, or we could be handing out stale pointers. |
| 2911 | SyncWithProcessState(); |
| 2912 | |
| 2913 | return m_exe_scope; |
| 2914 | } |
| 2915 | |
| 2916 | // This function checks the EvaluationPoint against the current process state. If the current |
| 2917 | // state matches the evaluation point, or the evaluation point is already invalid, then we return |
| 2918 | // false, meaning "no change". If the current state is different, we update our state, and return |
| 2919 | // true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so |
| 2920 | // future calls to NeedsUpdate will return true. |
| 2921 | |
| 2922 | bool |
| 2923 | ValueObject::EvaluationPoint::SyncWithProcessState() |
| 2924 | { |
| 2925 | // If we're already invalid, we don't need to do anything, and nothing has changed: |
| 2926 | if (m_stop_id == LLDB_INVALID_UID) |
| 2927 | { |
| 2928 | // Can't update with an invalid state. |
| 2929 | m_needs_update = false; |
| 2930 | return false; |
| 2931 | } |
| 2932 | |
| 2933 | // If we don't have a process nothing can change. |
| 2934 | if (!m_process_sp) |
| 2935 | return false; |
| 2936 | |
| 2937 | // If our stop id is the current stop ID, nothing has changed: |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2938 | uint32_t cur_stop_id = m_process_sp->GetStopID(); |
| 2939 | if (m_stop_id == cur_stop_id) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2940 | return false; |
| 2941 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2942 | // If the current stop id is 0, either we haven't run yet, or the process state has been cleared. |
| 2943 | // In either case, we aren't going to be able to sync with the process state. |
| 2944 | if (cur_stop_id == 0) |
| 2945 | return false; |
| 2946 | |
| 2947 | m_stop_id = cur_stop_id; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2948 | m_needs_update = true; |
| 2949 | m_exe_scope = m_process_sp.get(); |
| 2950 | |
| 2951 | // Something has changed, so we will return true. Now make sure the thread & frame still exist, and if either |
| 2952 | // doesn't, mark ourselves as invalid. |
| 2953 | |
| 2954 | if (m_thread_id != LLDB_INVALID_THREAD_ID) |
| 2955 | { |
| 2956 | Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get(); |
| 2957 | if (our_thread == NULL) |
Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame] | 2958 | { |
Jim Ingham | 89b6109 | 2011-07-06 17:42:14 +0000 | [diff] [blame] | 2959 | SetInvalid(); |
Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame] | 2960 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2961 | else |
| 2962 | { |
| 2963 | m_exe_scope = our_thread; |
| 2964 | |
| 2965 | if (m_stack_id.IsValid()) |
| 2966 | { |
| 2967 | StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get(); |
| 2968 | if (our_frame == NULL) |
| 2969 | SetInvalid(); |
| 2970 | else |
| 2971 | m_exe_scope = our_frame; |
| 2972 | } |
| 2973 | } |
| 2974 | } |
| 2975 | return true; |
| 2976 | } |
| 2977 | |
Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 2978 | void |
| 2979 | ValueObject::EvaluationPoint::SetUpdated () |
| 2980 | { |
| 2981 | m_first_update = false; |
| 2982 | m_needs_update = false; |
| 2983 | if (m_process_sp) |
| 2984 | m_stop_id = m_process_sp->GetStopID(); |
| 2985 | } |
| 2986 | |
| 2987 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2988 | bool |
| 2989 | ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope) |
| 2990 | { |
| 2991 | if (!IsValid()) |
| 2992 | return false; |
| 2993 | |
| 2994 | bool needs_update = false; |
| 2995 | m_exe_scope = NULL; |
| 2996 | |
| 2997 | // The target has to be non-null, and the |
| 2998 | Target *target = exe_scope->CalculateTarget(); |
| 2999 | if (target != NULL) |
| 3000 | { |
| 3001 | Target *old_target = m_target_sp.get(); |
| 3002 | assert (target == old_target); |
| 3003 | Process *process = exe_scope->CalculateProcess(); |
| 3004 | if (process != NULL) |
| 3005 | { |
| 3006 | // FOR NOW - assume you can't update variable objects across process boundaries. |
| 3007 | Process *old_process = m_process_sp.get(); |
| 3008 | assert (process == old_process); |
| 3009 | |
| 3010 | lldb::user_id_t stop_id = process->GetStopID(); |
| 3011 | if (stop_id != m_stop_id) |
| 3012 | { |
| 3013 | needs_update = true; |
| 3014 | m_stop_id = stop_id; |
| 3015 | } |
| 3016 | // See if we're switching the thread or stack context. If no thread is given, this is |
| 3017 | // being evaluated in a global context. |
| 3018 | Thread *thread = exe_scope->CalculateThread(); |
| 3019 | if (thread != NULL) |
| 3020 | { |
| 3021 | lldb::user_id_t new_thread_index = thread->GetIndexID(); |
| 3022 | if (new_thread_index != m_thread_id) |
| 3023 | { |
| 3024 | needs_update = true; |
| 3025 | m_thread_id = new_thread_index; |
| 3026 | m_stack_id.Clear(); |
| 3027 | } |
| 3028 | |
| 3029 | StackFrame *new_frame = exe_scope->CalculateStackFrame(); |
| 3030 | if (new_frame != NULL) |
| 3031 | { |
| 3032 | if (new_frame->GetStackID() != m_stack_id) |
| 3033 | { |
| 3034 | needs_update = true; |
| 3035 | m_stack_id = new_frame->GetStackID(); |
| 3036 | } |
| 3037 | } |
| 3038 | else |
| 3039 | { |
| 3040 | m_stack_id.Clear(); |
| 3041 | needs_update = true; |
| 3042 | } |
| 3043 | } |
| 3044 | else |
| 3045 | { |
| 3046 | // If this had been given a thread, and now there is none, we should update. |
| 3047 | // Otherwise we don't have to do anything. |
| 3048 | if (m_thread_id != LLDB_INVALID_UID) |
| 3049 | { |
| 3050 | m_thread_id = LLDB_INVALID_UID; |
| 3051 | m_stack_id.Clear(); |
| 3052 | needs_update = true; |
| 3053 | } |
| 3054 | } |
| 3055 | } |
| 3056 | else |
| 3057 | { |
| 3058 | // If there is no process, then we don't need to update anything. |
| 3059 | // But if we're switching from having a process to not, we should try to update. |
| 3060 | if (m_process_sp.get() != NULL) |
| 3061 | { |
| 3062 | needs_update = true; |
| 3063 | m_process_sp.reset(); |
| 3064 | m_thread_id = LLDB_INVALID_UID; |
| 3065 | m_stack_id.Clear(); |
| 3066 | } |
| 3067 | } |
| 3068 | } |
| 3069 | else |
| 3070 | { |
| 3071 | // If there's no target, nothing can change so we don't need to update anything. |
| 3072 | // But if we're switching from having a target to not, we should try to update. |
| 3073 | if (m_target_sp.get() != NULL) |
| 3074 | { |
| 3075 | needs_update = true; |
| 3076 | m_target_sp.reset(); |
| 3077 | m_process_sp.reset(); |
| 3078 | m_thread_id = LLDB_INVALID_UID; |
| 3079 | m_stack_id.Clear(); |
| 3080 | } |
| 3081 | } |
| 3082 | if (!m_needs_update) |
| 3083 | m_needs_update = needs_update; |
| 3084 | |
| 3085 | return needs_update; |
| 3086 | } |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 3087 | |
| 3088 | void |
| 3089 | ValueObject::ClearUserVisibleData() |
| 3090 | { |
| 3091 | m_location_str.clear(); |
| 3092 | m_value_str.clear(); |
| 3093 | m_summary_str.clear(); |
| 3094 | m_object_desc_str.clear(); |
| 3095 | } |