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 | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 22 | #include "lldb/Core/DataVisualization.h" |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 23 | #include "lldb/Core/Debugger.h" |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 24 | #include "lldb/Core/Log.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Core/StreamString.h" |
| 26 | #include "lldb/Core/ValueObjectChild.h" |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 27 | #include "lldb/Core/ValueObjectConstResult.h" |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 28 | #include "lldb/Core/ValueObjectDynamicValue.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Core/ValueObjectList.h" |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 30 | #include "lldb/Core/ValueObjectMemory.h" |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 31 | #include "lldb/Core/ValueObjectSyntheticFilter.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | |
Greg Clayton | 7fb56d0 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 33 | #include "lldb/Host/Endian.h" |
| 34 | |
Enrico Granata | 61a80ba | 2011-08-12 16:42:31 +0000 | [diff] [blame] | 35 | #include "lldb/Interpreter/CommandInterpreter.h" |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 36 | #include "lldb/Interpreter/ScriptInterpreterPython.h" |
| 37 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 38 | #include "lldb/Symbol/ClangASTType.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | #include "lldb/Symbol/ClangASTContext.h" |
| 40 | #include "lldb/Symbol/Type.h" |
| 41 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 42 | #include "lldb/Target/ExecutionContext.h" |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 43 | #include "lldb/Target/LanguageRuntime.h" |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 44 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | #include "lldb/Target/Process.h" |
| 46 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 47 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | #include "lldb/Target/Thread.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 50 | #include "lldb/Utility/RefCounter.h" |
| 51 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | using namespace lldb; |
| 53 | using namespace lldb_private; |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 54 | using namespace lldb_utility; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 55 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 56 | static user_id_t g_value_obj_uid = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | |
| 58 | //---------------------------------------------------------------------- |
| 59 | // ValueObject constructor |
| 60 | //---------------------------------------------------------------------- |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 61 | ValueObject::ValueObject (ValueObject &parent) : |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | UserID (++g_value_obj_uid), // Unique identifier for every value object |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 63 | m_parent (&parent), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 64 | m_update_point (parent.GetUpdatePoint ()), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | m_name (), |
| 66 | m_data (), |
| 67 | m_value (), |
| 68 | m_error (), |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 69 | m_value_str (), |
| 70 | m_old_value_str (), |
| 71 | m_location_str (), |
| 72 | m_summary_str (), |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 73 | m_object_desc_str (), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 74 | m_manager(parent.GetManager()), |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 75 | m_children (), |
| 76 | m_synthetic_children (), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 77 | m_dynamic_value (NULL), |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 78 | m_synthetic_value(NULL), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 79 | m_deref_valobj(NULL), |
Greg Clayton | 32c4085 | 2010-10-06 03:09:11 +0000 | [diff] [blame] | 80 | m_format (eFormatDefault), |
Enrico Granata | 9df29e3 | 2011-07-19 20:57:44 +0000 | [diff] [blame] | 81 | m_last_format_mgr_revision(0), |
Enrico Granata | d8b5fce | 2011-08-02 23:12:24 +0000 | [diff] [blame] | 82 | m_last_format_mgr_dynamic(parent.m_last_format_mgr_dynamic), |
Enrico Granata | 9df29e3 | 2011-07-19 20:57:44 +0000 | [diff] [blame] | 83 | m_last_summary_format(), |
| 84 | m_forced_summary_format(), |
| 85 | m_last_value_format(), |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 86 | m_last_synthetic_filter(), |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 87 | m_user_id_of_forced_summary(), |
Daniel Dunbar | a08823f | 2011-10-31 22:50:49 +0000 | [diff] [blame] | 88 | m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid), |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 89 | m_value_is_valid (false), |
| 90 | m_value_did_change (false), |
| 91 | m_children_count_valid (false), |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 92 | m_old_value_valid (false), |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 93 | m_is_deref_of_parent (false), |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 94 | m_is_array_item_for_pointer(false), |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 95 | m_is_bitfield_for_scalar(false), |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 96 | m_is_expression_path_child(false), |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 97 | m_is_child_at_offset(false), |
Greg Clayton | 48ca8b8 | 2012-01-07 20:58:07 +0000 | [diff] [blame] | 98 | m_is_getting_summary(false) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 99 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 100 | m_manager->ManageObject(this); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | //---------------------------------------------------------------------- |
| 104 | // ValueObject constructor |
| 105 | //---------------------------------------------------------------------- |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 106 | ValueObject::ValueObject (ExecutionContextScope *exe_scope, |
| 107 | AddressType child_ptr_or_ref_addr_type) : |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 108 | UserID (++g_value_obj_uid), // Unique identifier for every value object |
| 109 | m_parent (NULL), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 110 | m_update_point (exe_scope), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 111 | m_name (), |
| 112 | m_data (), |
| 113 | m_value (), |
| 114 | m_error (), |
| 115 | m_value_str (), |
| 116 | m_old_value_str (), |
| 117 | m_location_str (), |
| 118 | m_summary_str (), |
| 119 | m_object_desc_str (), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 120 | m_manager(), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 121 | m_children (), |
| 122 | m_synthetic_children (), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 123 | m_dynamic_value (NULL), |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 124 | m_synthetic_value(NULL), |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 125 | m_deref_valobj(NULL), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 126 | m_format (eFormatDefault), |
Enrico Granata | 9df29e3 | 2011-07-19 20:57:44 +0000 | [diff] [blame] | 127 | m_last_format_mgr_revision(0), |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 128 | m_last_format_mgr_dynamic(eNoDynamicValues), |
Enrico Granata | 9df29e3 | 2011-07-19 20:57:44 +0000 | [diff] [blame] | 129 | m_last_summary_format(), |
| 130 | m_forced_summary_format(), |
| 131 | m_last_value_format(), |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 132 | m_last_synthetic_filter(), |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 133 | m_user_id_of_forced_summary(), |
Daniel Dunbar | a08823f | 2011-10-31 22:50:49 +0000 | [diff] [blame] | 134 | m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 135 | m_value_is_valid (false), |
| 136 | m_value_did_change (false), |
| 137 | m_children_count_valid (false), |
| 138 | m_old_value_valid (false), |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 139 | m_is_deref_of_parent (false), |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 140 | m_is_array_item_for_pointer(false), |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 141 | m_is_bitfield_for_scalar(false), |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 142 | m_is_expression_path_child(false), |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 143 | m_is_child_at_offset(false), |
Greg Clayton | 48ca8b8 | 2012-01-07 20:58:07 +0000 | [diff] [blame] | 144 | m_is_getting_summary(false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 146 | m_manager = new ValueObjectManager(); |
| 147 | m_manager->ManageObject (this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | //---------------------------------------------------------------------- |
| 151 | // Destructor |
| 152 | //---------------------------------------------------------------------- |
| 153 | ValueObject::~ValueObject () |
| 154 | { |
| 155 | } |
| 156 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 157 | bool |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 158 | ValueObject::UpdateValueIfNeeded (bool update_format) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 159 | { |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 160 | return UpdateValueIfNeeded(m_last_format_mgr_dynamic, update_format); |
| 161 | } |
| 162 | |
| 163 | bool |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 164 | ValueObject::UpdateValueIfNeeded (DynamicValueType use_dynamic, bool update_format) |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 165 | { |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 166 | |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 167 | bool did_change_formats = false; |
| 168 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 169 | if (update_format) |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 170 | did_change_formats = UpdateFormatsIfNeeded(use_dynamic); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 171 | |
Greg Clayton | b71f384 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 172 | // If this is a constant value, then our success is predicated on whether |
| 173 | // we have an error or not |
| 174 | if (GetIsConstant()) |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 175 | { |
| 176 | // if you were asked to update your formatters, but did not get a chance to do it |
| 177 | // clear your own values (this serves the purpose of faking a stop-id for frozen |
| 178 | // objects (which are regarded as constant, but could have changes behind their backs |
| 179 | // because of the frozen-pointer depth limit) |
| 180 | // TODO: decouple summary from value and then remove this code and only force-clear the summary |
| 181 | if (update_format && !did_change_formats) |
| 182 | m_summary_str.clear(); |
Greg Clayton | b71f384 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 183 | return m_error.Success(); |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 184 | } |
Greg Clayton | b71f384 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 185 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 186 | bool first_update = m_update_point.IsFirstEvaluation(); |
| 187 | |
| 188 | if (m_update_point.NeedsUpdating()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 189 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 190 | m_update_point.SetUpdated(); |
| 191 | |
| 192 | // Save the old value using swap to avoid a string copy which |
| 193 | // also will clear our m_value_str |
| 194 | if (m_value_str.empty()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 195 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 196 | m_old_value_valid = false; |
| 197 | } |
| 198 | else |
| 199 | { |
| 200 | m_old_value_valid = true; |
| 201 | m_old_value_str.swap (m_value_str); |
| 202 | m_value_str.clear(); |
| 203 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 204 | |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 205 | ClearUserVisibleData(); |
| 206 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 207 | const bool value_was_valid = GetValueIsValid(); |
| 208 | SetValueDidChange (false); |
Greg Clayton | 73b953b | 2010-08-28 00:08:07 +0000 | [diff] [blame] | 209 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 210 | m_error.Clear(); |
Greg Clayton | 73b953b | 2010-08-28 00:08:07 +0000 | [diff] [blame] | 211 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 212 | // Call the pure virtual function to update the value |
| 213 | bool success = UpdateValue (); |
| 214 | |
| 215 | SetValueIsValid (success); |
| 216 | |
| 217 | if (first_update) |
| 218 | SetValueDidChange (false); |
| 219 | else if (!m_value_did_change && success == false) |
| 220 | { |
| 221 | // The value wasn't gotten successfully, so we mark this |
| 222 | // as changed if the value used to be valid and now isn't |
| 223 | SetValueDidChange (value_was_valid); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | return m_error.Success(); |
| 227 | } |
| 228 | |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 229 | bool |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 230 | ValueObject::UpdateFormatsIfNeeded(DynamicValueType use_dynamic) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 231 | { |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 232 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); |
| 233 | if (log) |
| 234 | log->Printf("checking for FormatManager revisions. VO named %s is at revision %d, while the format manager is at revision %d", |
| 235 | GetName().GetCString(), |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 236 | m_last_format_mgr_revision, |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 237 | DataVisualization::GetCurrentRevision()); |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 238 | |
| 239 | bool any_change = false; |
| 240 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 241 | if (HasCustomSummaryFormat() && m_update_point.GetModID() != m_user_id_of_forced_summary) |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 242 | { |
| 243 | ClearCustomSummaryFormat(); |
Enrico Granata | 855cd90 | 2011-09-06 22:59:55 +0000 | [diff] [blame] | 244 | |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 245 | any_change = true; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 246 | } |
Enrico Granata | 855cd90 | 2011-09-06 22:59:55 +0000 | [diff] [blame] | 247 | |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 248 | if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) || |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 249 | m_last_format_mgr_dynamic != use_dynamic) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 250 | { |
Enrico Granata | 78d0638 | 2011-09-09 23:33:14 +0000 | [diff] [blame] | 251 | SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues)); |
| 252 | SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, use_dynamic)); |
| 253 | SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, use_dynamic)); |
Enrico Granata | 1490c6f | 2011-07-19 02:34:21 +0000 | [diff] [blame] | 254 | |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 255 | m_last_format_mgr_revision = DataVisualization::GetCurrentRevision(); |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 256 | m_last_format_mgr_dynamic = use_dynamic; |
Enrico Granata | 855cd90 | 2011-09-06 22:59:55 +0000 | [diff] [blame] | 257 | |
| 258 | any_change = true; |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 259 | } |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 260 | |
| 261 | return any_change; |
| 262 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 265 | void |
| 266 | ValueObject::SetNeedsUpdate () |
| 267 | { |
| 268 | m_update_point.SetNeedsUpdate(); |
| 269 | // We have to clear the value string here so ConstResult children will notice if their values are |
| 270 | // changed by hand (i.e. with SetValueAsCString). |
| 271 | m_value_str.clear(); |
| 272 | } |
| 273 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 274 | DataExtractor & |
| 275 | ValueObject::GetDataExtractor () |
| 276 | { |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 277 | UpdateValueIfNeeded(false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 278 | return m_data; |
| 279 | } |
| 280 | |
| 281 | const Error & |
Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame] | 282 | ValueObject::GetError() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 283 | { |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 284 | UpdateValueIfNeeded(false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 285 | return m_error; |
| 286 | } |
| 287 | |
| 288 | const ConstString & |
| 289 | ValueObject::GetName() const |
| 290 | { |
| 291 | return m_name; |
| 292 | } |
| 293 | |
| 294 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 295 | ValueObject::GetLocationAsCString () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 296 | { |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 297 | if (UpdateValueIfNeeded(false)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 298 | { |
| 299 | if (m_location_str.empty()) |
| 300 | { |
| 301 | StreamString sstr; |
| 302 | |
| 303 | switch (m_value.GetValueType()) |
| 304 | { |
| 305 | default: |
| 306 | break; |
| 307 | |
| 308 | case Value::eValueTypeScalar: |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 309 | if (m_value.GetContextType() == Value::eContextTypeRegisterInfo) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 310 | { |
| 311 | RegisterInfo *reg_info = m_value.GetRegisterInfo(); |
| 312 | if (reg_info) |
| 313 | { |
| 314 | if (reg_info->name) |
| 315 | m_location_str = reg_info->name; |
| 316 | else if (reg_info->alt_name) |
| 317 | m_location_str = reg_info->alt_name; |
| 318 | break; |
| 319 | } |
| 320 | } |
| 321 | m_location_str = "scalar"; |
| 322 | break; |
| 323 | |
| 324 | case Value::eValueTypeLoadAddress: |
| 325 | case Value::eValueTypeFileAddress: |
| 326 | case Value::eValueTypeHostAddress: |
| 327 | { |
| 328 | uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2; |
| 329 | sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS)); |
| 330 | m_location_str.swap(sstr.GetString()); |
| 331 | } |
| 332 | break; |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | return m_location_str.c_str(); |
| 337 | } |
| 338 | |
| 339 | Value & |
| 340 | ValueObject::GetValue() |
| 341 | { |
| 342 | return m_value; |
| 343 | } |
| 344 | |
| 345 | const Value & |
| 346 | ValueObject::GetValue() const |
| 347 | { |
| 348 | return m_value; |
| 349 | } |
| 350 | |
| 351 | bool |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 352 | ValueObject::ResolveValue (Scalar &scalar) |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 353 | { |
Enrico Granata | 6fd87d5 | 2011-08-04 01:41:02 +0000 | [diff] [blame] | 354 | if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything |
| 355 | { |
| 356 | ExecutionContext exe_ctx; |
| 357 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 358 | if (exe_scope) |
| 359 | exe_scope->CalculateExecutionContext(exe_ctx); |
Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 360 | Value tmp_value(m_value); |
| 361 | scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ()); |
Greg Clayton | dcad502 | 2011-12-29 01:26:56 +0000 | [diff] [blame] | 362 | if (scalar.IsValid()) |
| 363 | { |
| 364 | const uint32_t bitfield_bit_size = GetBitfieldBitSize(); |
| 365 | if (bitfield_bit_size) |
| 366 | return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset()); |
| 367 | return true; |
| 368 | } |
Enrico Granata | 6fd87d5 | 2011-08-04 01:41:02 +0000 | [diff] [blame] | 369 | } |
Greg Clayton | dcad502 | 2011-12-29 01:26:56 +0000 | [diff] [blame] | 370 | return false; |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | bool |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 374 | ValueObject::GetValueIsValid () const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 375 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 376 | return m_value_is_valid; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | |
| 380 | void |
| 381 | ValueObject::SetValueIsValid (bool b) |
| 382 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 383 | m_value_is_valid = b; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | bool |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 387 | ValueObject::GetValueDidChange () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 388 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 389 | GetValueAsCString (); |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 390 | return m_value_did_change; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | void |
| 394 | ValueObject::SetValueDidChange (bool value_changed) |
| 395 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 396 | m_value_did_change = value_changed; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | ValueObjectSP |
| 400 | ValueObject::GetChildAtIndex (uint32_t idx, bool can_create) |
| 401 | { |
| 402 | ValueObjectSP child_sp; |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 403 | // We may need to update our value if we are dynamic |
| 404 | if (IsPossibleDynamicType ()) |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 405 | UpdateValueIfNeeded(false); |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 406 | if (idx < GetNumChildren()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 407 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 408 | // Check if we have already made the child value object? |
| 409 | if (can_create && m_children[idx] == NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 410 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 411 | // No we haven't created the child at this index, so lets have our |
| 412 | // subclass do it and cache the result for quick future access. |
| 413 | m_children[idx] = CreateChildAtIndex (idx, false, 0); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 414 | } |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 415 | |
| 416 | if (m_children[idx] != NULL) |
| 417 | return m_children[idx]->GetSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 418 | } |
| 419 | return child_sp; |
| 420 | } |
| 421 | |
| 422 | uint32_t |
| 423 | ValueObject::GetIndexOfChildWithName (const ConstString &name) |
| 424 | { |
| 425 | bool omit_empty_base_classes = true; |
| 426 | return ClangASTContext::GetIndexOfChildWithName (GetClangAST(), |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 427 | GetClangType(), |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 428 | name.GetCString(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 429 | omit_empty_base_classes); |
| 430 | } |
| 431 | |
| 432 | ValueObjectSP |
| 433 | ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create) |
| 434 | { |
Greg Clayton | 710dd5a | 2011-01-08 20:28:42 +0000 | [diff] [blame] | 435 | // 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] | 436 | // classes (which really aren't part of the expression path), so we |
| 437 | // 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] | 438 | ValueObjectSP child_sp; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 439 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 440 | // We may need to update our value if we are dynamic |
| 441 | if (IsPossibleDynamicType ()) |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 442 | UpdateValueIfNeeded(false); |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 443 | |
| 444 | std::vector<uint32_t> child_indexes; |
| 445 | clang::ASTContext *clang_ast = GetClangAST(); |
| 446 | void *clang_type = GetClangType(); |
| 447 | bool omit_empty_base_classes = true; |
| 448 | const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast, |
| 449 | clang_type, |
| 450 | name.GetCString(), |
| 451 | omit_empty_base_classes, |
| 452 | child_indexes); |
| 453 | if (num_child_indexes > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 454 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 455 | std::vector<uint32_t>::const_iterator pos = child_indexes.begin (); |
| 456 | std::vector<uint32_t>::const_iterator end = child_indexes.end (); |
| 457 | |
| 458 | child_sp = GetChildAtIndex(*pos, can_create); |
| 459 | for (++pos; pos != end; ++pos) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 460 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 461 | if (child_sp) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 462 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 463 | ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create)); |
| 464 | child_sp = new_child_sp; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 465 | } |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 466 | else |
| 467 | { |
| 468 | child_sp.reset(); |
| 469 | } |
| 470 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 471 | } |
| 472 | } |
| 473 | return child_sp; |
| 474 | } |
| 475 | |
| 476 | |
| 477 | uint32_t |
| 478 | ValueObject::GetNumChildren () |
| 479 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 480 | if (!m_children_count_valid) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 481 | { |
| 482 | SetNumChildren (CalculateNumChildren()); |
| 483 | } |
| 484 | return m_children.size(); |
| 485 | } |
| 486 | void |
| 487 | ValueObject::SetNumChildren (uint32_t num_children) |
| 488 | { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 489 | m_children_count_valid = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 490 | m_children.resize(num_children); |
| 491 | } |
| 492 | |
| 493 | void |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 494 | ValueObject::SetName (const ConstString &name) |
| 495 | { |
| 496 | m_name = name; |
| 497 | } |
| 498 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 499 | ValueObject * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 500 | ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index) |
| 501 | { |
Jim Ingham | 2eec487 | 2011-05-07 00:10:58 +0000 | [diff] [blame] | 502 | ValueObject *valobj = NULL; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 503 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 504 | bool omit_empty_base_classes = true; |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 505 | bool ignore_array_bounds = synthetic_array_member; |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 506 | std::string child_name_str; |
| 507 | uint32_t child_byte_size = 0; |
| 508 | int32_t child_byte_offset = 0; |
| 509 | uint32_t child_bitfield_bit_size = 0; |
| 510 | uint32_t child_bitfield_bit_offset = 0; |
| 511 | bool child_is_base_class = false; |
| 512 | bool child_is_deref_of_parent = false; |
| 513 | |
| 514 | const bool transparent_pointers = synthetic_array_member == false; |
| 515 | clang::ASTContext *clang_ast = GetClangAST(); |
| 516 | clang_type_t clang_type = GetClangType(); |
| 517 | clang_type_t child_clang_type; |
| 518 | |
| 519 | ExecutionContext exe_ctx; |
| 520 | GetExecutionContextScope()->CalculateExecutionContext (exe_ctx); |
| 521 | |
| 522 | child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx, |
| 523 | clang_ast, |
| 524 | GetName().GetCString(), |
| 525 | clang_type, |
| 526 | idx, |
| 527 | transparent_pointers, |
| 528 | omit_empty_base_classes, |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 529 | ignore_array_bounds, |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 530 | child_name_str, |
| 531 | child_byte_size, |
| 532 | child_byte_offset, |
| 533 | child_bitfield_bit_size, |
| 534 | child_bitfield_bit_offset, |
| 535 | child_is_base_class, |
| 536 | child_is_deref_of_parent); |
| 537 | if (child_clang_type && child_byte_size) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 538 | { |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 539 | if (synthetic_index) |
| 540 | child_byte_offset += child_byte_size * synthetic_index; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 541 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 542 | ConstString child_name; |
| 543 | if (!child_name_str.empty()) |
| 544 | child_name.SetCString (child_name_str.c_str()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 545 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 546 | valobj = new ValueObjectChild (*this, |
| 547 | clang_ast, |
| 548 | child_clang_type, |
| 549 | child_name, |
| 550 | child_byte_size, |
| 551 | child_byte_offset, |
| 552 | child_bitfield_bit_size, |
| 553 | child_bitfield_bit_offset, |
| 554 | child_is_base_class, |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 555 | child_is_deref_of_parent, |
| 556 | eAddressTypeInvalid); |
| 557 | //if (valobj) |
| 558 | // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid); |
| 559 | } |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 560 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 561 | return valobj; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 565 | ValueObject::GetSummaryAsCString () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 566 | { |
Greg Clayton | 48ca8b8 | 2012-01-07 20:58:07 +0000 | [diff] [blame] | 567 | // Watch for recursion which can happen with summary strings and other |
| 568 | // variable formatting options. |
| 569 | if (m_is_getting_summary) |
| 570 | return NULL; |
| 571 | |
| 572 | m_is_getting_summary = true; |
| 573 | |
Enrico Granata | d8b5fce | 2011-08-02 23:12:24 +0000 | [diff] [blame] | 574 | if (UpdateValueIfNeeded (true)) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 575 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 576 | if (m_summary_str.empty()) |
| 577 | { |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame^] | 578 | TypeSummaryImpl *summary_format = GetSummaryFormat().get(); |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 579 | |
| 580 | if (summary_format) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 581 | { |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 582 | m_summary_str = summary_format->FormatObject(GetSP()); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 583 | } |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 584 | else |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 585 | { |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 586 | clang_type_t clang_type = GetClangType(); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 587 | |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 588 | // Do some default printout for function pointers |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 589 | if (clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 590 | { |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 591 | StreamString sstr; |
| 592 | clang_type_t elem_or_pointee_clang_type; |
| 593 | const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, |
| 594 | GetClangAST(), |
| 595 | &elem_or_pointee_clang_type)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 596 | |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 597 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 598 | if (exe_scope) |
| 599 | { |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 600 | if (ClangASTContext::IsFunctionPointerType (clang_type)) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 601 | { |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 602 | AddressType func_ptr_address_type = eAddressTypeInvalid; |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 603 | addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type); |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 604 | if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS) |
| 605 | { |
| 606 | switch (func_ptr_address_type) |
| 607 | { |
| 608 | case eAddressTypeInvalid: |
| 609 | case eAddressTypeFile: |
| 610 | break; |
| 611 | |
| 612 | case eAddressTypeLoad: |
| 613 | { |
| 614 | Address so_addr; |
| 615 | Target *target = exe_scope->CalculateTarget(); |
| 616 | if (target && target->GetSectionLoadList().IsEmpty() == false) |
| 617 | { |
| 618 | if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr)) |
| 619 | { |
| 620 | so_addr.Dump (&sstr, |
| 621 | exe_scope, |
| 622 | Address::DumpStyleResolvedDescription, |
| 623 | Address::DumpStyleSectionNameOffset); |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | break; |
| 628 | |
| 629 | case eAddressTypeHost: |
| 630 | break; |
| 631 | } |
| 632 | } |
| 633 | if (sstr.GetSize() > 0) |
| 634 | { |
| 635 | m_summary_str.assign (1, '('); |
| 636 | m_summary_str.append (sstr.GetData(), sstr.GetSize()); |
| 637 | m_summary_str.append (1, ')'); |
| 638 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 639 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | } |
Greg Clayton | 48ca8b8 | 2012-01-07 20:58:07 +0000 | [diff] [blame] | 645 | m_is_getting_summary = false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 646 | if (m_summary_str.empty()) |
| 647 | return NULL; |
| 648 | return m_summary_str.c_str(); |
| 649 | } |
| 650 | |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 651 | bool |
| 652 | ValueObject::IsCStringContainer(bool check_pointer) |
| 653 | { |
| 654 | clang_type_t elem_or_pointee_clang_type; |
| 655 | const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(), |
| 656 | GetClangAST(), |
| 657 | &elem_or_pointee_clang_type)); |
| 658 | bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) && |
| 659 | ClangASTContext::IsCharType (elem_or_pointee_clang_type)); |
| 660 | if (!is_char_arr_ptr) |
| 661 | return false; |
| 662 | if (!check_pointer) |
| 663 | return true; |
| 664 | if (type_flags.Test(ClangASTContext::eTypeIsArray)) |
| 665 | return true; |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 666 | addr_t cstr_address = LLDB_INVALID_ADDRESS; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 667 | AddressType cstr_address_type = eAddressTypeInvalid; |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 668 | cstr_address = GetAddressOf (true, &cstr_address_type); |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 669 | return (cstr_address != LLDB_INVALID_ADDRESS); |
| 670 | } |
| 671 | |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 672 | size_t |
| 673 | ValueObject::GetPointeeData (DataExtractor& data, |
| 674 | uint32_t item_idx, |
| 675 | uint32_t item_count) |
| 676 | { |
| 677 | if (!IsPointerType() && !IsArrayType()) |
| 678 | return 0; |
| 679 | |
| 680 | if (item_count == 0) |
| 681 | return 0; |
| 682 | |
| 683 | uint32_t stride = 0; |
| 684 | |
| 685 | ClangASTType type(GetClangAST(), |
| 686 | GetClangType()); |
| 687 | |
| 688 | const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) : |
| 689 | ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride))); |
| 690 | |
| 691 | const uint64_t bytes = item_count * item_type_size; |
| 692 | |
| 693 | const uint64_t offset = item_idx * item_type_size; |
| 694 | |
| 695 | if (item_idx == 0 && item_count == 1) // simply a deref |
| 696 | { |
| 697 | if (IsPointerType()) |
| 698 | { |
| 699 | Error error; |
| 700 | ValueObjectSP pointee_sp = Dereference(error); |
| 701 | if (error.Fail() || pointee_sp.get() == NULL) |
| 702 | return 0; |
| 703 | return pointee_sp->GetDataExtractor().Copy(data); |
| 704 | } |
| 705 | else |
| 706 | { |
| 707 | ValueObjectSP child_sp = GetChildAtIndex(0, true); |
| 708 | if (child_sp.get() == NULL) |
| 709 | return 0; |
| 710 | return child_sp->GetDataExtractor().Copy(data); |
| 711 | } |
| 712 | return true; |
| 713 | } |
| 714 | else /* (items > 1) */ |
| 715 | { |
| 716 | Error error; |
| 717 | lldb_private::DataBufferHeap* heap_buf_ptr = NULL; |
| 718 | lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap()); |
| 719 | |
| 720 | AddressType addr_type; |
| 721 | lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type); |
| 722 | |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 723 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 724 | |
| 725 | |
| 726 | switch (addr_type) |
| 727 | { |
| 728 | case eAddressTypeFile: |
| 729 | { |
| 730 | Module* module = GetModule(); |
| 731 | if (module) |
| 732 | { |
| 733 | Address so_addr; |
| 734 | module->ResolveFileAddress(addr, so_addr); |
| 735 | if (exe_scope) |
| 736 | { |
| 737 | Target* target = exe_scope->CalculateTarget(); |
| 738 | if (target) |
| 739 | { |
| 740 | heap_buf_ptr->SetByteSize(bytes); |
| 741 | size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error); |
| 742 | if (error.Success()) |
| 743 | { |
| 744 | data.SetData(data_sp); |
| 745 | return bytes_read; |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | break; |
| 752 | case eAddressTypeLoad: |
| 753 | if (exe_scope) |
| 754 | { |
| 755 | Process *process = exe_scope->CalculateProcess(); |
| 756 | if (process) |
| 757 | { |
| 758 | heap_buf_ptr->SetByteSize(bytes); |
| 759 | size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error); |
| 760 | if (error.Success()) |
| 761 | { |
| 762 | data.SetData(data_sp); |
| 763 | return bytes_read; |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | break; |
| 768 | case eAddressTypeHost: |
| 769 | { |
| 770 | heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes); |
| 771 | data.SetData(data_sp); |
| 772 | return bytes; |
| 773 | } |
| 774 | break; |
| 775 | case eAddressTypeInvalid: |
| 776 | default: |
| 777 | break; |
| 778 | } |
| 779 | } |
| 780 | return 0; |
| 781 | } |
| 782 | |
| 783 | size_t |
| 784 | ValueObject::GetData (DataExtractor& data) |
| 785 | { |
| 786 | UpdateValueIfNeeded(false); |
| 787 | ExecutionContext exe_ctx; |
| 788 | GetExecutionContextScope()->CalculateExecutionContext(exe_ctx); |
| 789 | Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule()); |
| 790 | if (error.Fail()) |
| 791 | return 0; |
| 792 | data.SetAddressByteSize(m_data.GetAddressByteSize()); |
| 793 | data.SetByteOrder(m_data.GetByteOrder()); |
| 794 | return data.GetByteSize(); |
| 795 | } |
| 796 | |
| 797 | // will compute strlen(str), but without consuming more than |
| 798 | // maxlen bytes out of str (this serves the purpose of reading |
| 799 | // chunks of a string without having to worry about |
| 800 | // missing NULL terminators in the chunk) |
| 801 | // of course, if strlen(str) > maxlen, the function will return |
| 802 | // maxlen_value (which should be != maxlen, because that allows you |
| 803 | // to know whether strlen(str) == maxlen or strlen(str) > maxlen) |
| 804 | static uint32_t |
| 805 | strlen_or_inf (const char* str, |
| 806 | uint32_t maxlen, |
| 807 | uint32_t maxlen_value) |
| 808 | { |
| 809 | uint32_t len = 0; |
Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 810 | if (str) |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 811 | { |
Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 812 | while(*str) |
| 813 | { |
| 814 | len++;str++; |
| 815 | if (len > maxlen) |
| 816 | return maxlen_value; |
| 817 | } |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 818 | } |
| 819 | return len; |
| 820 | } |
| 821 | |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 822 | void |
| 823 | ValueObject::ReadPointedString(Stream& s, |
| 824 | Error& error, |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 825 | uint32_t max_length, |
| 826 | bool honor_array, |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 827 | Format item_format) |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 828 | { |
| 829 | |
| 830 | if (max_length == 0) |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 831 | max_length = GetUpdatePoint().GetTargetSP()->GetMaximumSizeOfStringSummary(); |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 832 | |
| 833 | clang_type_t clang_type = GetClangType(); |
| 834 | clang_type_t elem_or_pointee_clang_type; |
| 835 | const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, |
| 836 | GetClangAST(), |
| 837 | &elem_or_pointee_clang_type)); |
| 838 | if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) && |
| 839 | ClangASTContext::IsCharType (elem_or_pointee_clang_type)) |
| 840 | { |
| 841 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 842 | if (exe_scope) |
| 843 | { |
| 844 | Target *target = exe_scope->CalculateTarget(); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 845 | if (target == NULL) |
| 846 | { |
| 847 | s << "<no target to read from>"; |
| 848 | } |
| 849 | else |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 850 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 851 | addr_t cstr_address = LLDB_INVALID_ADDRESS; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 852 | AddressType cstr_address_type = eAddressTypeInvalid; |
| 853 | |
| 854 | size_t cstr_len = 0; |
| 855 | bool capped_data = false; |
| 856 | if (type_flags.Test (ClangASTContext::eTypeIsArray)) |
| 857 | { |
| 858 | // We have an array |
| 859 | cstr_len = ClangASTContext::GetArraySize (clang_type); |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 860 | if (cstr_len > max_length) |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 861 | { |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 862 | capped_data = true; |
| 863 | cstr_len = max_length; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 864 | } |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 865 | cstr_address = GetAddressOf (true, &cstr_address_type); |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 866 | } |
| 867 | else |
| 868 | { |
| 869 | // We have a pointer |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 870 | cstr_address = GetPointerValue (&cstr_address_type); |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 871 | } |
Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 872 | if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS) |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 873 | { |
| 874 | Address cstr_so_addr (NULL, cstr_address); |
| 875 | DataExtractor data; |
| 876 | size_t bytes_read = 0; |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 877 | if (cstr_len > 0 && honor_array) |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 878 | { |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 879 | // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host |
| 880 | // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this |
| 881 | GetPointeeData(data, 0, cstr_len); |
| 882 | |
Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 883 | if ((bytes_read = data.GetByteSize()) > 0) |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 884 | { |
| 885 | s << '"'; |
| 886 | data.Dump (&s, |
| 887 | 0, // Start offset in "data" |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 888 | item_format, |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 889 | 1, // Size of item (1 byte for a char!) |
| 890 | bytes_read, // How many bytes to print? |
| 891 | UINT32_MAX, // num per line |
| 892 | LLDB_INVALID_ADDRESS,// base address |
| 893 | 0, // bitfield bit size |
| 894 | 0); // bitfield bit offset |
| 895 | if (capped_data) |
| 896 | s << "..."; |
| 897 | s << '"'; |
| 898 | } |
| 899 | } |
| 900 | else |
| 901 | { |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 902 | cstr_len = max_length; |
| 903 | const size_t k_max_buf_size = 64; |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 904 | |
| 905 | size_t offset = 0; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 906 | |
Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 907 | int cstr_len_displayed = -1; |
| 908 | bool capped_cstr = false; |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 909 | // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host |
| 910 | // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this |
Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 911 | while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0) |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 912 | { |
Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 913 | const char *cstr = data.PeekCStr(0); |
| 914 | size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1); |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 915 | if (len > k_max_buf_size) |
| 916 | len = k_max_buf_size; |
Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 917 | if (cstr && cstr_len_displayed < 0) |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 918 | s << '"'; |
Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 919 | |
| 920 | if (cstr_len_displayed < 0) |
| 921 | cstr_len_displayed = len; |
| 922 | |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 923 | if (len == 0) |
| 924 | break; |
Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 925 | cstr_len_displayed += len; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 926 | if (len > bytes_read) |
| 927 | len = bytes_read; |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 928 | if (len > cstr_len) |
| 929 | len = cstr_len; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 930 | |
| 931 | data.Dump (&s, |
| 932 | 0, // Start offset in "data" |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 933 | item_format, |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 934 | 1, // Size of item (1 byte for a char!) |
| 935 | len, // How many bytes to print? |
| 936 | UINT32_MAX, // num per line |
| 937 | LLDB_INVALID_ADDRESS,// base address |
| 938 | 0, // bitfield bit size |
| 939 | 0); // bitfield bit offset |
| 940 | |
| 941 | if (len < k_max_buf_size) |
| 942 | break; |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 943 | |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 944 | if (len >= cstr_len) |
Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 945 | { |
| 946 | capped_cstr = true; |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 947 | break; |
Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 948 | } |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 949 | |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 950 | cstr_len -= len; |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 951 | offset += len; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 952 | } |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 953 | |
Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 954 | if (cstr_len_displayed >= 0) |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 955 | { |
| 956 | s << '"'; |
Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 957 | if (capped_cstr) |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 958 | s << "..."; |
| 959 | } |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 960 | } |
| 961 | } |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | else |
| 966 | { |
| 967 | error.SetErrorString("impossible to read a string from this object"); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 968 | s << "<not a string object>"; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 969 | } |
| 970 | } |
| 971 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 972 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 973 | ValueObject::GetObjectDescription () |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 974 | { |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 975 | |
Enrico Granata | d8b5fce | 2011-08-02 23:12:24 +0000 | [diff] [blame] | 976 | if (!UpdateValueIfNeeded (true)) |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 977 | return NULL; |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 978 | |
| 979 | if (!m_object_desc_str.empty()) |
| 980 | return m_object_desc_str.c_str(); |
| 981 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 982 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 983 | if (exe_scope == NULL) |
| 984 | return NULL; |
| 985 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 986 | Process *process = exe_scope->CalculateProcess(); |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 987 | if (process == NULL) |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 988 | return NULL; |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 989 | |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 990 | StreamString s; |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 991 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 992 | LanguageType language = GetObjectRuntimeLanguage(); |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 993 | LanguageRuntime *runtime = process->GetLanguageRuntime(language); |
| 994 | |
Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 995 | if (runtime == NULL) |
| 996 | { |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 997 | // 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] | 998 | clang_type_t opaque_qual_type = GetClangType(); |
| 999 | if (opaque_qual_type != NULL) |
| 1000 | { |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 1001 | bool is_signed; |
| 1002 | if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed) |
| 1003 | || ClangASTContext::IsPointerType (opaque_qual_type)) |
| 1004 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1005 | runtime = process->GetLanguageRuntime(eLanguageTypeObjC); |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 1006 | } |
Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 1007 | } |
| 1008 | } |
| 1009 | |
Jim Ingham | 8d543de | 2011-03-31 23:01:21 +0000 | [diff] [blame] | 1010 | if (runtime && runtime->GetObjectDescription(s, *this)) |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 1011 | { |
| 1012 | m_object_desc_str.append (s.GetData()); |
| 1013 | } |
Sean Callanan | 672ad94 | 2010-10-23 00:18:49 +0000 | [diff] [blame] | 1014 | |
| 1015 | if (m_object_desc_str.empty()) |
| 1016 | return NULL; |
| 1017 | else |
| 1018 | return m_object_desc_str.c_str(); |
Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 1019 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1020 | |
| 1021 | const char * |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1022 | ValueObject::GetValueAsCString () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1023 | { |
| 1024 | // 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] | 1025 | if (ClangASTContext::IsAggregateType (GetClangType()) == false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1026 | { |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1027 | if (UpdateValueIfNeeded(true)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1028 | { |
| 1029 | if (m_value_str.empty()) |
| 1030 | { |
| 1031 | const Value::ContextType context_type = m_value.GetContextType(); |
| 1032 | |
| 1033 | switch (context_type) |
| 1034 | { |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1035 | case Value::eContextTypeClangType: |
| 1036 | case Value::eContextTypeLLDBType: |
| 1037 | case Value::eContextTypeVariable: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1038 | { |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1039 | lldb::Format my_format = GetFormat(); |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1040 | clang_type_t clang_type = GetClangType (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1041 | if (clang_type) |
| 1042 | { |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1043 | if (m_format == lldb::eFormatDefault) |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 1044 | { |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1045 | if (m_last_value_format) |
| 1046 | my_format = m_last_value_format->GetFormat(); |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 1047 | else |
| 1048 | { |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1049 | if (m_is_bitfield_for_scalar) |
| 1050 | my_format = eFormatUnsigned; |
| 1051 | else |
| 1052 | my_format = ClangASTType::GetFormat(clang_type); |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 1053 | } |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 1054 | } |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1055 | StreamString sstr; |
| 1056 | if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST |
| 1057 | clang_type, // The clang type to display |
| 1058 | &sstr, |
| 1059 | my_format, // Format to display this type with |
| 1060 | m_data, // Data to extract from |
| 1061 | 0, // Byte offset into "m_data" |
| 1062 | GetByteSize(), // Byte size of item in "m_data" |
| 1063 | GetBitfieldBitSize(), // Bitfield bit size |
Greg Clayton | 5009f9d | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 1064 | GetBitfieldBitOffset(), |
| 1065 | GetExecutionContextScope())) // Bitfield bit offset |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1066 | m_value_str.swap(sstr.GetString()); |
| 1067 | else |
| 1068 | { |
Jason Molenda | 7e589a6 | 2011-09-20 00:26:08 +0000 | [diff] [blame] | 1069 | m_error.SetErrorStringWithFormat ("unsufficient data for value (only %lu of %lu bytes available)", |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1070 | m_data.GetByteSize(), |
| 1071 | GetByteSize()); |
| 1072 | m_value_str.clear(); |
| 1073 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1074 | } |
| 1075 | } |
| 1076 | break; |
| 1077 | |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1078 | case Value::eContextTypeRegisterInfo: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1079 | { |
| 1080 | const RegisterInfo *reg_info = m_value.GetRegisterInfo(); |
| 1081 | if (reg_info) |
| 1082 | { |
Jim Ingham | 6657d09 | 2012-01-19 21:10:56 +0000 | [diff] [blame] | 1083 | lldb::Format my_format = GetFormat(); |
| 1084 | if (m_format == lldb::eFormatDefault) |
| 1085 | { |
| 1086 | if (m_last_value_format) |
| 1087 | my_format = m_last_value_format->GetFormat(); |
| 1088 | else |
| 1089 | my_format = reg_info->format; |
| 1090 | } |
| 1091 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1092 | StreamString reg_sstr; |
Jim Ingham | 6657d09 | 2012-01-19 21:10:56 +0000 | [diff] [blame] | 1093 | m_data.Dump(®_sstr, 0, my_format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0, GetExecutionContextScope()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1094 | m_value_str.swap(reg_sstr.GetString()); |
| 1095 | } |
| 1096 | } |
| 1097 | break; |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1098 | |
| 1099 | default: |
| 1100 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1101 | } |
| 1102 | } |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 1103 | |
| 1104 | if (!m_value_did_change && m_old_value_valid) |
| 1105 | { |
| 1106 | // The value was gotten successfully, so we consider the |
| 1107 | // value as changed if the value string differs |
| 1108 | SetValueDidChange (m_old_value_str != m_value_str); |
| 1109 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1110 | } |
| 1111 | } |
| 1112 | if (m_value_str.empty()) |
| 1113 | return NULL; |
| 1114 | return m_value_str.c_str(); |
| 1115 | } |
| 1116 | |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1117 | // if > 8bytes, 0 is returned. this method should mostly be used |
| 1118 | // to read address values out of pointers |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1119 | uint64_t |
| 1120 | ValueObject::GetValueAsUnsigned (uint64_t fail_value) |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1121 | { |
| 1122 | // If our byte size is zero this is an aggregate type that has children |
| 1123 | if (ClangASTContext::IsAggregateType (GetClangType()) == false) |
| 1124 | { |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1125 | Scalar scalar; |
| 1126 | if (ResolveValue (scalar)) |
| 1127 | return scalar.GetRawBits64(fail_value); |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1128 | } |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1129 | return fail_value; |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
Enrico Granata | 5dfd49c | 2011-08-04 02:34:29 +0000 | [diff] [blame] | 1132 | bool |
| 1133 | ValueObject::GetPrintableRepresentation(Stream& s, |
| 1134 | ValueObjectRepresentationStyle val_obj_display, |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1135 | Format custom_format) |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1136 | { |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1137 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1138 | if (custom_format != eFormatInvalid) |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1139 | SetFormat(custom_format); |
| 1140 | |
| 1141 | const char * return_value; |
Enrico Granata | cd1c023 | 2011-08-04 23:37:18 +0000 | [diff] [blame] | 1142 | std::string alloc_mem; |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1143 | |
| 1144 | switch(val_obj_display) |
| 1145 | { |
| 1146 | case eDisplayValue: |
| 1147 | return_value = GetValueAsCString(); |
| 1148 | break; |
Greg Clayton | 48ca8b8 | 2012-01-07 20:58:07 +0000 | [diff] [blame] | 1149 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1150 | case eDisplaySummary: |
Greg Clayton | 48ca8b8 | 2012-01-07 20:58:07 +0000 | [diff] [blame] | 1151 | return_value = GetSummaryAsCString(); |
| 1152 | break; |
| 1153 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1154 | case eDisplayLanguageSpecific: |
| 1155 | return_value = GetObjectDescription(); |
| 1156 | break; |
Greg Clayton | 48ca8b8 | 2012-01-07 20:58:07 +0000 | [diff] [blame] | 1157 | |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 1158 | case eDisplayLocation: |
| 1159 | return_value = GetLocationAsCString(); |
| 1160 | break; |
Greg Clayton | 48ca8b8 | 2012-01-07 20:58:07 +0000 | [diff] [blame] | 1161 | |
Enrico Granata | 5dfd49c | 2011-08-04 02:34:29 +0000 | [diff] [blame] | 1162 | case eDisplayChildrenCount: |
Greg Clayton | 48ca8b8 | 2012-01-07 20:58:07 +0000 | [diff] [blame] | 1163 | { |
| 1164 | alloc_mem.resize(512); |
| 1165 | return_value = &alloc_mem[0]; |
| 1166 | int count = GetNumChildren(); |
| 1167 | snprintf((char*)return_value, 512, "%d", count); |
| 1168 | } |
Enrico Granata | 5dfd49c | 2011-08-04 02:34:29 +0000 | [diff] [blame] | 1169 | break; |
Greg Clayton | 48ca8b8 | 2012-01-07 20:58:07 +0000 | [diff] [blame] | 1170 | |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1171 | case eDisplayType: |
| 1172 | return_value = GetTypeName().AsCString(); |
| 1173 | break; |
Greg Clayton | 48ca8b8 | 2012-01-07 20:58:07 +0000 | [diff] [blame] | 1174 | |
Enrico Granata | 5dfd49c | 2011-08-04 02:34:29 +0000 | [diff] [blame] | 1175 | default: |
| 1176 | break; |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
Enrico Granata | 855cd90 | 2011-09-06 22:59:55 +0000 | [diff] [blame] | 1179 | if (!return_value) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1180 | { |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1181 | if (val_obj_display == eDisplayValue) |
Enrico Granata | 855cd90 | 2011-09-06 22:59:55 +0000 | [diff] [blame] | 1182 | return_value = GetSummaryAsCString(); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1183 | else if (val_obj_display == eDisplaySummary) |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1184 | { |
| 1185 | if (ClangASTContext::IsAggregateType (GetClangType()) == true) |
| 1186 | { |
Enrico Granata | 5dfd49c | 2011-08-04 02:34:29 +0000 | [diff] [blame] | 1187 | // this thing has no value, and it seems to have no summary |
| 1188 | // some combination of unitialized data and other factors can also |
Enrico Granata | 855cd90 | 2011-09-06 22:59:55 +0000 | [diff] [blame] | 1189 | // raise this condition, so let's print a nice generic description |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1190 | { |
| 1191 | alloc_mem.resize(684); |
| 1192 | return_value = &alloc_mem[0]; |
| 1193 | snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString()); |
| 1194 | } |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1195 | } |
| 1196 | else |
| 1197 | return_value = GetValueAsCString(); |
| 1198 | } |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1199 | } |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1200 | |
Enrico Granata | 5dfd49c | 2011-08-04 02:34:29 +0000 | [diff] [blame] | 1201 | if (return_value) |
| 1202 | s.PutCString(return_value); |
| 1203 | else |
Enrico Granata | 88da35f | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 1204 | { |
| 1205 | if (m_error.Fail()) |
| 1206 | s.Printf("<%s>", m_error.AsCString()); |
| 1207 | else if (val_obj_display == eDisplaySummary) |
| 1208 | s.PutCString("<no summary available>"); |
| 1209 | else if (val_obj_display == eDisplayValue) |
| 1210 | s.PutCString("<no value available>"); |
| 1211 | else if (val_obj_display == eDisplayLanguageSpecific) |
| 1212 | s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description |
| 1213 | else |
| 1214 | s.PutCString("<no printable representation>"); |
| 1215 | } |
Enrico Granata | 5dfd49c | 2011-08-04 02:34:29 +0000 | [diff] [blame] | 1216 | |
| 1217 | // we should only return false here if we could not do *anything* |
| 1218 | // even if we have an error message as output, that's a success |
| 1219 | // from our callers' perspective, so return true |
| 1220 | return true; |
| 1221 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1224 | // if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep |
| 1225 | // this call up to date by returning true for your new special cases. We will eventually move |
| 1226 | // to checking this call result before trying to display special cases |
| 1227 | bool |
| 1228 | ValueObject::HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display, |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1229 | Format custom_format) |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1230 | { |
| 1231 | clang_type_t elem_or_pointee_type; |
| 1232 | Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type)); |
| 1233 | |
| 1234 | if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) |
| 1235 | && val_obj_display == ValueObject::eDisplayValue) |
| 1236 | { |
| 1237 | if (IsCStringContainer(true) && |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1238 | (custom_format == eFormatCString || |
| 1239 | custom_format == eFormatCharArray || |
| 1240 | custom_format == eFormatChar || |
| 1241 | custom_format == eFormatVectorOfChar)) |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1242 | return true; |
| 1243 | |
| 1244 | if (flags.Test(ClangASTContext::eTypeIsArray)) |
| 1245 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1246 | if ((custom_format == eFormatBytes) || |
| 1247 | (custom_format == eFormatBytesWithASCII)) |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1248 | return true; |
| 1249 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1250 | if ((custom_format == eFormatVectorOfChar) || |
| 1251 | (custom_format == eFormatVectorOfFloat32) || |
| 1252 | (custom_format == eFormatVectorOfFloat64) || |
| 1253 | (custom_format == eFormatVectorOfSInt16) || |
| 1254 | (custom_format == eFormatVectorOfSInt32) || |
| 1255 | (custom_format == eFormatVectorOfSInt64) || |
| 1256 | (custom_format == eFormatVectorOfSInt8) || |
| 1257 | (custom_format == eFormatVectorOfUInt128) || |
| 1258 | (custom_format == eFormatVectorOfUInt16) || |
| 1259 | (custom_format == eFormatVectorOfUInt32) || |
| 1260 | (custom_format == eFormatVectorOfUInt64) || |
| 1261 | (custom_format == eFormatVectorOfUInt8)) |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1262 | return true; |
| 1263 | } |
| 1264 | } |
| 1265 | return false; |
| 1266 | } |
| 1267 | |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1268 | bool |
| 1269 | ValueObject::DumpPrintableRepresentation(Stream& s, |
| 1270 | ValueObjectRepresentationStyle val_obj_display, |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1271 | Format custom_format, |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1272 | bool only_special) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1273 | { |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1274 | |
| 1275 | clang_type_t elem_or_pointee_type; |
| 1276 | Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type)); |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1277 | |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1278 | if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) |
| 1279 | && val_obj_display == ValueObject::eDisplayValue) |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1280 | { |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1281 | // when being asked to get a printable display an array or pointer type directly, |
| 1282 | // try to "do the right thing" |
| 1283 | |
| 1284 | if (IsCStringContainer(true) && |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1285 | (custom_format == eFormatCString || |
| 1286 | custom_format == eFormatCharArray || |
| 1287 | custom_format == eFormatChar || |
| 1288 | custom_format == eFormatVectorOfChar)) // print char[] & char* directly |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1289 | { |
| 1290 | Error error; |
| 1291 | ReadPointedString(s, |
| 1292 | error, |
| 1293 | 0, |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1294 | (custom_format == eFormatVectorOfChar) || |
| 1295 | (custom_format == eFormatCharArray)); |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1296 | return !error.Fail(); |
| 1297 | } |
| 1298 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1299 | if (custom_format == eFormatEnum) |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1300 | return false; |
| 1301 | |
| 1302 | // this only works for arrays, because I have no way to know when |
| 1303 | // the pointed memory ends, and no special \0 end of data marker |
| 1304 | if (flags.Test(ClangASTContext::eTypeIsArray)) |
| 1305 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1306 | if ((custom_format == eFormatBytes) || |
| 1307 | (custom_format == eFormatBytesWithASCII)) |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1308 | { |
| 1309 | uint32_t count = GetNumChildren(); |
| 1310 | |
| 1311 | s << '['; |
| 1312 | for (uint32_t low = 0; low < count; low++) |
| 1313 | { |
| 1314 | |
| 1315 | if (low) |
| 1316 | s << ','; |
| 1317 | |
| 1318 | ValueObjectSP child = GetChildAtIndex(low,true); |
| 1319 | if (!child.get()) |
| 1320 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1321 | s << "<invalid child>"; |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1322 | continue; |
| 1323 | } |
| 1324 | child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format); |
| 1325 | } |
| 1326 | |
| 1327 | s << ']'; |
| 1328 | |
| 1329 | return true; |
| 1330 | } |
| 1331 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1332 | if ((custom_format == eFormatVectorOfChar) || |
| 1333 | (custom_format == eFormatVectorOfFloat32) || |
| 1334 | (custom_format == eFormatVectorOfFloat64) || |
| 1335 | (custom_format == eFormatVectorOfSInt16) || |
| 1336 | (custom_format == eFormatVectorOfSInt32) || |
| 1337 | (custom_format == eFormatVectorOfSInt64) || |
| 1338 | (custom_format == eFormatVectorOfSInt8) || |
| 1339 | (custom_format == eFormatVectorOfUInt128) || |
| 1340 | (custom_format == eFormatVectorOfUInt16) || |
| 1341 | (custom_format == eFormatVectorOfUInt32) || |
| 1342 | (custom_format == eFormatVectorOfUInt64) || |
| 1343 | (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1344 | { |
| 1345 | uint32_t count = GetNumChildren(); |
| 1346 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1347 | Format format = FormatManager::GetSingleItemFormat(custom_format); |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1348 | |
| 1349 | s << '['; |
| 1350 | for (uint32_t low = 0; low < count; low++) |
| 1351 | { |
| 1352 | |
| 1353 | if (low) |
| 1354 | s << ','; |
| 1355 | |
| 1356 | ValueObjectSP child = GetChildAtIndex(low,true); |
| 1357 | if (!child.get()) |
| 1358 | { |
Enrico Granata | e992a08 | 2011-07-22 17:03:19 +0000 | [diff] [blame] | 1359 | s << "<invalid child>"; |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1360 | continue; |
| 1361 | } |
| 1362 | child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format); |
| 1363 | } |
| 1364 | |
| 1365 | s << ']'; |
| 1366 | |
| 1367 | return true; |
| 1368 | } |
| 1369 | } |
| 1370 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1371 | if ((custom_format == eFormatBoolean) || |
| 1372 | (custom_format == eFormatBinary) || |
| 1373 | (custom_format == eFormatChar) || |
| 1374 | (custom_format == eFormatCharPrintable) || |
| 1375 | (custom_format == eFormatComplexFloat) || |
| 1376 | (custom_format == eFormatDecimal) || |
| 1377 | (custom_format == eFormatHex) || |
| 1378 | (custom_format == eFormatFloat) || |
| 1379 | (custom_format == eFormatOctal) || |
| 1380 | (custom_format == eFormatOSType) || |
| 1381 | (custom_format == eFormatUnicode16) || |
| 1382 | (custom_format == eFormatUnicode32) || |
| 1383 | (custom_format == eFormatUnsigned) || |
| 1384 | (custom_format == eFormatPointer) || |
| 1385 | (custom_format == eFormatComplexInteger) || |
| 1386 | (custom_format == eFormatComplex) || |
| 1387 | (custom_format == eFormatDefault)) // use the [] operator |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1388 | return false; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1389 | } |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1390 | |
| 1391 | if (only_special) |
| 1392 | return false; |
| 1393 | |
Enrico Granata | 5dfd49c | 2011-08-04 02:34:29 +0000 | [diff] [blame] | 1394 | bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format); |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 1395 | if (custom_format != eFormatInvalid) |
Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1396 | SetFormat(eFormatDefault); |
| 1397 | return var_success; |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1400 | addr_t |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1401 | ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type) |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1402 | { |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1403 | if (!UpdateValueIfNeeded(false)) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1404 | return LLDB_INVALID_ADDRESS; |
| 1405 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1406 | switch (m_value.GetValueType()) |
| 1407 | { |
| 1408 | case Value::eValueTypeScalar: |
| 1409 | if (scalar_is_load_address) |
| 1410 | { |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1411 | if(address_type) |
| 1412 | *address_type = eAddressTypeLoad; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1413 | return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 1414 | } |
| 1415 | break; |
| 1416 | |
| 1417 | case Value::eValueTypeLoadAddress: |
| 1418 | case Value::eValueTypeFileAddress: |
| 1419 | case Value::eValueTypeHostAddress: |
| 1420 | { |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1421 | if(address_type) |
| 1422 | *address_type = m_value.GetValueAddressType (); |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1423 | return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 1424 | } |
| 1425 | break; |
| 1426 | } |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1427 | if (address_type) |
| 1428 | *address_type = eAddressTypeInvalid; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1429 | return LLDB_INVALID_ADDRESS; |
| 1430 | } |
| 1431 | |
| 1432 | addr_t |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1433 | ValueObject::GetPointerValue (AddressType *address_type) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1434 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1435 | addr_t address = LLDB_INVALID_ADDRESS; |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1436 | if(address_type) |
| 1437 | *address_type = eAddressTypeInvalid; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1438 | |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1439 | if (!UpdateValueIfNeeded(false)) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1440 | return address; |
| 1441 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1442 | switch (m_value.GetValueType()) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1443 | { |
| 1444 | case Value::eValueTypeScalar: |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1445 | address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1446 | break; |
| 1447 | |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1448 | case Value::eValueTypeHostAddress: |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1449 | case Value::eValueTypeLoadAddress: |
| 1450 | case Value::eValueTypeFileAddress: |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1451 | { |
| 1452 | uint32_t data_offset = 0; |
| 1453 | address = m_data.GetPointer(&data_offset); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1454 | } |
| 1455 | break; |
| 1456 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1457 | |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1458 | if (address_type) |
| 1459 | *address_type = GetAddressTypeOfChildren(); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1460 | |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1461 | return address; |
| 1462 | } |
| 1463 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1464 | bool |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1465 | ValueObject::SetValueFromCString (const char *value_str) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1466 | { |
| 1467 | // Make sure our value is up to date first so that our location and location |
| 1468 | // type is valid. |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1469 | if (!UpdateValueIfNeeded(false)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1470 | return false; |
| 1471 | |
| 1472 | uint32_t count = 0; |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1473 | Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1474 | |
Greg Clayton | b132097 | 2010-07-14 00:18:15 +0000 | [diff] [blame] | 1475 | const size_t byte_size = GetByteSize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1476 | |
Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 1477 | Value::ValueType value_type = m_value.GetValueType(); |
| 1478 | |
| 1479 | if (value_type == Value::eValueTypeScalar) |
| 1480 | { |
| 1481 | // If the value is already a scalar, then let the scalar change itself: |
| 1482 | m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size); |
| 1483 | } |
| 1484 | else if (byte_size <= Scalar::GetMaxByteSize()) |
| 1485 | { |
| 1486 | // If the value fits in a scalar, then make a new scalar and again let the |
| 1487 | // scalar code do the conversion, then figure out where to put the new value. |
| 1488 | Scalar new_scalar; |
| 1489 | Error error; |
| 1490 | error = new_scalar.SetValueFromCString (value_str, encoding, byte_size); |
| 1491 | if (error.Success()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1492 | { |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1493 | switch (value_type) |
| 1494 | { |
Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 1495 | case Value::eValueTypeLoadAddress: |
| 1496 | { |
| 1497 | // If it is a load address, then the scalar value is the storage location |
| 1498 | // of the data, and we have to shove this value down to that load location. |
| 1499 | ProcessSP process_sp = GetUpdatePoint().GetProcessSP(); |
| 1500 | if (process_sp) |
| 1501 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1502 | addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS); |
Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 1503 | size_t bytes_written = process_sp->WriteScalarToMemory (target_addr, |
| 1504 | new_scalar, |
| 1505 | byte_size, |
| 1506 | error); |
| 1507 | if (!error.Success() || bytes_written != byte_size) |
| 1508 | return false; |
| 1509 | } |
| 1510 | } |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1511 | break; |
Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 1512 | case Value::eValueTypeHostAddress: |
| 1513 | { |
| 1514 | // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data. |
| 1515 | DataExtractor new_data; |
| 1516 | new_data.SetByteOrder (m_data.GetByteOrder()); |
| 1517 | |
| 1518 | DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0)); |
| 1519 | m_data.SetData(buffer_sp, 0); |
| 1520 | bool success = new_scalar.GetData(new_data); |
| 1521 | if (success) |
| 1522 | { |
| 1523 | new_data.CopyByteOrderedData(0, |
| 1524 | byte_size, |
| 1525 | const_cast<uint8_t *>(m_data.GetDataStart()), |
| 1526 | byte_size, |
| 1527 | m_data.GetByteOrder()); |
| 1528 | } |
| 1529 | m_value.GetScalar() = (uintptr_t)m_data.GetDataStart(); |
| 1530 | |
| 1531 | } |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1532 | break; |
Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 1533 | case Value::eValueTypeFileAddress: |
| 1534 | case Value::eValueTypeScalar: |
| 1535 | break; |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1536 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1537 | } |
| 1538 | else |
| 1539 | { |
Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 1540 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1541 | } |
Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 1542 | } |
| 1543 | else |
| 1544 | { |
| 1545 | // We don't support setting things bigger than a scalar at present. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1546 | return false; |
| 1547 | } |
Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 1548 | |
| 1549 | // If we have reached this point, then we have successfully changed the value. |
| 1550 | SetNeedsUpdate(); |
| 1551 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1554 | bool |
| 1555 | ValueObject::GetDeclaration (Declaration &decl) |
| 1556 | { |
| 1557 | decl.Clear(); |
| 1558 | return false; |
| 1559 | } |
| 1560 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1561 | LanguageType |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1562 | ValueObject::GetObjectRuntimeLanguage () |
| 1563 | { |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1564 | return ClangASTType::GetMinimumLanguage (GetClangAST(), |
| 1565 | GetClangType()); |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1568 | void |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1569 | ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1570 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1571 | m_synthetic_children[key] = valobj; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | ValueObjectSP |
| 1575 | ValueObject::GetSyntheticChild (const ConstString &key) const |
| 1576 | { |
| 1577 | ValueObjectSP synthetic_child_sp; |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1578 | std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1579 | if (pos != m_synthetic_children.end()) |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1580 | synthetic_child_sp = pos->second->GetSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1581 | return synthetic_child_sp; |
| 1582 | } |
| 1583 | |
| 1584 | bool |
| 1585 | ValueObject::IsPointerType () |
| 1586 | { |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1587 | return ClangASTContext::IsPointerType (GetClangType()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1588 | } |
| 1589 | |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 1590 | bool |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 1591 | ValueObject::IsArrayType () |
| 1592 | { |
| 1593 | return ClangASTContext::IsArrayType (GetClangType()); |
| 1594 | } |
| 1595 | |
| 1596 | bool |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1597 | ValueObject::IsScalarType () |
| 1598 | { |
| 1599 | return ClangASTContext::IsScalarType (GetClangType()); |
| 1600 | } |
| 1601 | |
| 1602 | bool |
Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 1603 | ValueObject::IsIntegerType (bool &is_signed) |
| 1604 | { |
| 1605 | return ClangASTContext::IsIntegerType (GetClangType(), is_signed); |
| 1606 | } |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1607 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1608 | bool |
| 1609 | ValueObject::IsPointerOrReferenceType () |
| 1610 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 1611 | return ClangASTContext::IsPointerOrReferenceType (GetClangType()); |
| 1612 | } |
| 1613 | |
| 1614 | bool |
| 1615 | ValueObject::IsPossibleCPlusPlusDynamicType () |
| 1616 | { |
| 1617 | return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 1620 | bool |
| 1621 | ValueObject::IsPossibleDynamicType () |
| 1622 | { |
| 1623 | return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType()); |
| 1624 | } |
| 1625 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1626 | ValueObjectSP |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1627 | ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create) |
| 1628 | { |
| 1629 | if (IsArrayType()) |
| 1630 | return GetSyntheticArrayMemberFromArray(index, can_create); |
| 1631 | |
| 1632 | if (IsPointerType()) |
| 1633 | return GetSyntheticArrayMemberFromPointer(index, can_create); |
| 1634 | |
| 1635 | return ValueObjectSP(); |
| 1636 | |
| 1637 | } |
| 1638 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1639 | ValueObjectSP |
| 1640 | ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create) |
| 1641 | { |
| 1642 | ValueObjectSP synthetic_child_sp; |
| 1643 | if (IsPointerType ()) |
| 1644 | { |
| 1645 | char index_str[64]; |
| 1646 | snprintf(index_str, sizeof(index_str), "[%i]", index); |
| 1647 | ConstString index_const_str(index_str); |
| 1648 | // Check if we have already created a synthetic array member in this |
| 1649 | // valid object. If we have we will re-use it. |
| 1650 | synthetic_child_sp = GetSyntheticChild (index_const_str); |
| 1651 | if (!synthetic_child_sp) |
| 1652 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1653 | ValueObject *synthetic_child; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1654 | // We haven't made a synthetic array member for INDEX yet, so |
| 1655 | // lets make one and cache it for any future reference. |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1656 | synthetic_child = CreateChildAtIndex(0, true, index); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1657 | |
| 1658 | // Cache the value if we got one back... |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1659 | if (synthetic_child) |
| 1660 | { |
| 1661 | AddSyntheticChild(index_const_str, synthetic_child); |
| 1662 | synthetic_child_sp = synthetic_child->GetSP(); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1663 | synthetic_child_sp->SetName(ConstString(index_str)); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1664 | synthetic_child_sp->m_is_array_item_for_pointer = true; |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1665 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1666 | } |
| 1667 | } |
| 1668 | return synthetic_child_sp; |
| 1669 | } |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1670 | |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 1671 | // This allows you to create an array member using and index |
| 1672 | // that doesn't not fall in the normal bounds of the array. |
| 1673 | // Many times structure can be defined as: |
| 1674 | // struct Collection |
| 1675 | // { |
| 1676 | // uint32_t item_count; |
| 1677 | // Item item_array[0]; |
| 1678 | // }; |
| 1679 | // The size of the "item_array" is 1, but many times in practice |
| 1680 | // there are more items in "item_array". |
| 1681 | |
| 1682 | ValueObjectSP |
| 1683 | ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create) |
| 1684 | { |
| 1685 | ValueObjectSP synthetic_child_sp; |
| 1686 | if (IsArrayType ()) |
| 1687 | { |
| 1688 | char index_str[64]; |
| 1689 | snprintf(index_str, sizeof(index_str), "[%i]", index); |
| 1690 | ConstString index_const_str(index_str); |
| 1691 | // Check if we have already created a synthetic array member in this |
| 1692 | // valid object. If we have we will re-use it. |
| 1693 | synthetic_child_sp = GetSyntheticChild (index_const_str); |
| 1694 | if (!synthetic_child_sp) |
| 1695 | { |
| 1696 | ValueObject *synthetic_child; |
| 1697 | // We haven't made a synthetic array member for INDEX yet, so |
| 1698 | // lets make one and cache it for any future reference. |
| 1699 | synthetic_child = CreateChildAtIndex(0, true, index); |
| 1700 | |
| 1701 | // Cache the value if we got one back... |
| 1702 | if (synthetic_child) |
| 1703 | { |
| 1704 | AddSyntheticChild(index_const_str, synthetic_child); |
| 1705 | synthetic_child_sp = synthetic_child->GetSP(); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1706 | synthetic_child_sp->SetName(ConstString(index_str)); |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 1707 | synthetic_child_sp->m_is_array_item_for_pointer = true; |
| 1708 | } |
| 1709 | } |
| 1710 | } |
| 1711 | return synthetic_child_sp; |
| 1712 | } |
| 1713 | |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1714 | ValueObjectSP |
| 1715 | ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create) |
| 1716 | { |
| 1717 | ValueObjectSP synthetic_child_sp; |
| 1718 | if (IsScalarType ()) |
| 1719 | { |
| 1720 | char index_str[64]; |
| 1721 | snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to); |
| 1722 | ConstString index_const_str(index_str); |
| 1723 | // Check if we have already created a synthetic array member in this |
| 1724 | // valid object. If we have we will re-use it. |
| 1725 | synthetic_child_sp = GetSyntheticChild (index_const_str); |
| 1726 | if (!synthetic_child_sp) |
| 1727 | { |
| 1728 | ValueObjectChild *synthetic_child; |
| 1729 | // We haven't made a synthetic array member for INDEX yet, so |
| 1730 | // lets make one and cache it for any future reference. |
| 1731 | synthetic_child = new ValueObjectChild(*this, |
| 1732 | GetClangAST(), |
| 1733 | GetClangType(), |
| 1734 | index_const_str, |
| 1735 | GetByteSize(), |
| 1736 | 0, |
| 1737 | to-from+1, |
| 1738 | from, |
| 1739 | false, |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1740 | false, |
| 1741 | eAddressTypeInvalid); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1742 | |
| 1743 | // Cache the value if we got one back... |
| 1744 | if (synthetic_child) |
| 1745 | { |
| 1746 | AddSyntheticChild(index_const_str, synthetic_child); |
| 1747 | synthetic_child_sp = synthetic_child->GetSP(); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1748 | synthetic_child_sp->SetName(ConstString(index_str)); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1749 | synthetic_child_sp->m_is_bitfield_for_scalar = true; |
| 1750 | } |
| 1751 | } |
| 1752 | } |
| 1753 | return synthetic_child_sp; |
| 1754 | } |
| 1755 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1756 | ValueObjectSP |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1757 | ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create) |
| 1758 | { |
| 1759 | ValueObjectSP synthetic_child_sp; |
| 1760 | if (IsArrayType () || IsPointerType ()) |
| 1761 | { |
| 1762 | char index_str[64]; |
| 1763 | snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to); |
| 1764 | ConstString index_const_str(index_str); |
| 1765 | // Check if we have already created a synthetic array member in this |
| 1766 | // valid object. If we have we will re-use it. |
| 1767 | synthetic_child_sp = GetSyntheticChild (index_const_str); |
| 1768 | if (!synthetic_child_sp) |
| 1769 | { |
| 1770 | ValueObjectSynthetic *synthetic_child; |
| 1771 | |
| 1772 | // We haven't made a synthetic array member for INDEX yet, so |
| 1773 | // lets make one and cache it for any future reference. |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame^] | 1774 | SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags()); |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1775 | view->AddRange(from,to); |
| 1776 | SyntheticChildrenSP view_sp(view); |
| 1777 | synthetic_child = new ValueObjectSynthetic(*this, view_sp); |
| 1778 | |
| 1779 | // Cache the value if we got one back... |
| 1780 | if (synthetic_child) |
| 1781 | { |
| 1782 | AddSyntheticChild(index_const_str, synthetic_child); |
| 1783 | synthetic_child_sp = synthetic_child->GetSP(); |
| 1784 | synthetic_child_sp->SetName(ConstString(index_str)); |
| 1785 | synthetic_child_sp->m_is_bitfield_for_scalar = true; |
| 1786 | } |
| 1787 | } |
| 1788 | } |
| 1789 | return synthetic_child_sp; |
| 1790 | } |
| 1791 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1792 | ValueObjectSP |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1793 | ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create) |
| 1794 | { |
| 1795 | |
| 1796 | ValueObjectSP synthetic_child_sp; |
| 1797 | |
| 1798 | char name_str[64]; |
| 1799 | snprintf(name_str, sizeof(name_str), "@%i", offset); |
| 1800 | ConstString name_const_str(name_str); |
| 1801 | |
| 1802 | // Check if we have already created a synthetic array member in this |
| 1803 | // valid object. If we have we will re-use it. |
| 1804 | synthetic_child_sp = GetSyntheticChild (name_const_str); |
| 1805 | |
| 1806 | if (synthetic_child_sp.get()) |
| 1807 | return synthetic_child_sp; |
| 1808 | |
| 1809 | if (!can_create) |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1810 | return ValueObjectSP(); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1811 | |
| 1812 | ValueObjectChild *synthetic_child = new ValueObjectChild(*this, |
| 1813 | type.GetASTContext(), |
| 1814 | type.GetOpaqueQualType(), |
| 1815 | name_const_str, |
| 1816 | type.GetTypeByteSize(), |
| 1817 | offset, |
| 1818 | 0, |
| 1819 | 0, |
| 1820 | false, |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1821 | false, |
| 1822 | eAddressTypeInvalid); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1823 | if (synthetic_child) |
| 1824 | { |
| 1825 | AddSyntheticChild(name_const_str, synthetic_child); |
| 1826 | synthetic_child_sp = synthetic_child->GetSP(); |
| 1827 | synthetic_child_sp->SetName(name_const_str); |
| 1828 | synthetic_child_sp->m_is_child_at_offset = true; |
| 1829 | } |
| 1830 | return synthetic_child_sp; |
| 1831 | } |
| 1832 | |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 1833 | // your expression path needs to have a leading . or -> |
| 1834 | // (unless it somehow "looks like" an array, in which case it has |
| 1835 | // a leading [ symbol). while the [ is meaningful and should be shown |
| 1836 | // to the user, . and -> are just parser design, but by no means |
| 1837 | // added information for the user.. strip them off |
| 1838 | static const char* |
| 1839 | SkipLeadingExpressionPathSeparators(const char* expression) |
| 1840 | { |
| 1841 | if (!expression || !expression[0]) |
| 1842 | return expression; |
| 1843 | if (expression[0] == '.') |
| 1844 | return expression+1; |
| 1845 | if (expression[0] == '-' && expression[1] == '>') |
| 1846 | return expression+2; |
| 1847 | return expression; |
| 1848 | } |
| 1849 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1850 | ValueObjectSP |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 1851 | ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create) |
| 1852 | { |
| 1853 | ValueObjectSP synthetic_child_sp; |
| 1854 | ConstString name_const_string(expression); |
| 1855 | // Check if we have already created a synthetic array member in this |
| 1856 | // valid object. If we have we will re-use it. |
| 1857 | synthetic_child_sp = GetSyntheticChild (name_const_string); |
| 1858 | if (!synthetic_child_sp) |
| 1859 | { |
| 1860 | // We haven't made a synthetic array member for expression yet, so |
| 1861 | // lets make one and cache it for any future reference. |
| 1862 | synthetic_child_sp = GetValueForExpressionPath(expression); |
| 1863 | |
| 1864 | // Cache the value if we got one back... |
| 1865 | if (synthetic_child_sp.get()) |
| 1866 | { |
| 1867 | AddSyntheticChild(name_const_string, synthetic_child_sp.get()); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1868 | synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression))); |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 1869 | synthetic_child_sp->m_is_expression_path_child = true; |
| 1870 | } |
| 1871 | } |
| 1872 | return synthetic_child_sp; |
| 1873 | } |
| 1874 | |
| 1875 | void |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1876 | ValueObject::CalculateSyntheticValue (SyntheticValueType use_synthetic) |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 1877 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1878 | if (use_synthetic == eNoSyntheticFilter) |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 1879 | return; |
| 1880 | |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1881 | UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 1882 | |
| 1883 | if (m_last_synthetic_filter.get() == NULL) |
| 1884 | return; |
| 1885 | |
Enrico Granata | a37a065 | 2011-07-24 00:14:56 +0000 | [diff] [blame] | 1886 | if (m_synthetic_value == NULL) |
| 1887 | m_synthetic_value = new ValueObjectSynthetic(*this, m_last_synthetic_filter); |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 1888 | |
| 1889 | } |
| 1890 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1891 | void |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1892 | ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1893 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1894 | if (use_dynamic == eNoDynamicValues) |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1895 | return; |
| 1896 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1897 | if (!m_dynamic_value && !IsDynamic()) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1898 | { |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1899 | Process *process = m_update_point.GetProcessSP().get(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1900 | bool worth_having_dynamic_value = false; |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1901 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1902 | |
| 1903 | // FIXME: Process should have some kind of "map over Runtimes" so we don't have to |
| 1904 | // hard code this everywhere. |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1905 | LanguageType known_type = GetObjectRuntimeLanguage(); |
| 1906 | if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1907 | { |
| 1908 | LanguageRuntime *runtime = process->GetLanguageRuntime (known_type); |
| 1909 | if (runtime) |
| 1910 | worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this); |
| 1911 | } |
| 1912 | else |
| 1913 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1914 | LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1915 | if (cpp_runtime) |
| 1916 | worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this); |
| 1917 | |
| 1918 | if (!worth_having_dynamic_value) |
| 1919 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1920 | LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1921 | if (objc_runtime) |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1922 | worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | if (worth_having_dynamic_value) |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1927 | m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1928 | |
| 1929 | // if (worth_having_dynamic_value) |
| 1930 | // printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager); |
| 1931 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1932 | } |
| 1933 | } |
| 1934 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1935 | ValueObjectSP |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1936 | ValueObject::GetDynamicValue (DynamicValueType use_dynamic) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1937 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1938 | if (use_dynamic == eNoDynamicValues) |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1939 | return ValueObjectSP(); |
| 1940 | |
| 1941 | if (!IsDynamic() && m_dynamic_value == NULL) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1942 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1943 | CalculateDynamicValue(use_dynamic); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1944 | } |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1945 | if (m_dynamic_value) |
| 1946 | return m_dynamic_value->GetSP(); |
| 1947 | else |
| 1948 | return ValueObjectSP(); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1949 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 1950 | |
Jim Ingham | 60dbabb | 2011-12-08 19:44:08 +0000 | [diff] [blame] | 1951 | ValueObjectSP |
| 1952 | ValueObject::GetStaticValue() |
| 1953 | { |
| 1954 | return GetSP(); |
| 1955 | } |
| 1956 | |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 1957 | // GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic |
| 1958 | // or we do not really want a dynamic VO. this method instead returns this object |
| 1959 | // itself when making it synthetic has no meaning. this makes it much simpler |
| 1960 | // to replace the SyntheticValue for the ValueObject |
| 1961 | ValueObjectSP |
| 1962 | ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic) |
| 1963 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1964 | if (use_synthetic == eNoSyntheticFilter) |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 1965 | return GetSP(); |
| 1966 | |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1967 | UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 1968 | |
| 1969 | if (m_last_synthetic_filter.get() == NULL) |
| 1970 | return GetSP(); |
| 1971 | |
| 1972 | CalculateSyntheticValue(use_synthetic); |
| 1973 | |
| 1974 | if (m_synthetic_value) |
| 1975 | return m_synthetic_value->GetSP(); |
| 1976 | else |
| 1977 | return GetSP(); |
| 1978 | } |
| 1979 | |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1980 | bool |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 1981 | ValueObject::HasSyntheticValue() |
| 1982 | { |
| 1983 | UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); |
| 1984 | |
| 1985 | if (m_last_synthetic_filter.get() == NULL) |
| 1986 | return false; |
| 1987 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1988 | CalculateSyntheticValue(eUseSyntheticFilter); |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 1989 | |
| 1990 | if (m_synthetic_value) |
| 1991 | return true; |
| 1992 | else |
| 1993 | return false; |
| 1994 | } |
| 1995 | |
| 1996 | bool |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 1997 | ValueObject::GetBaseClassPath (Stream &s) |
| 1998 | { |
| 1999 | if (IsBaseClass()) |
| 2000 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2001 | bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2002 | clang_type_t clang_type = GetClangType(); |
| 2003 | std::string cxx_class_name; |
| 2004 | bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name); |
| 2005 | if (this_had_base_class) |
| 2006 | { |
| 2007 | if (parent_had_base_class) |
| 2008 | s.PutCString("::"); |
| 2009 | s.PutCString(cxx_class_name.c_str()); |
| 2010 | } |
| 2011 | return parent_had_base_class || this_had_base_class; |
| 2012 | } |
| 2013 | return false; |
| 2014 | } |
| 2015 | |
| 2016 | |
| 2017 | ValueObject * |
| 2018 | ValueObject::GetNonBaseClassParent() |
| 2019 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2020 | if (GetParent()) |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2021 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2022 | if (GetParent()->IsBaseClass()) |
| 2023 | return GetParent()->GetNonBaseClassParent(); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2024 | else |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2025 | return GetParent(); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2026 | } |
| 2027 | return NULL; |
| 2028 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2029 | |
| 2030 | void |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2031 | ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2032 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2033 | const bool is_deref_of_parent = IsDereferenceOfParent (); |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2034 | |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 2035 | if (is_deref_of_parent && epformat == eDereferencePointers) |
| 2036 | { |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2037 | // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely |
| 2038 | // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName. |
| 2039 | // the eHonorPointers mode is meant to produce strings in this latter format |
| 2040 | s.PutCString("*("); |
| 2041 | } |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2042 | |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2043 | ValueObject* parent = GetParent(); |
| 2044 | |
| 2045 | if (parent) |
| 2046 | parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 2047 | |
| 2048 | // if we are a deref_of_parent just because we are synthetic array |
| 2049 | // members made up to allow ptr[%d] syntax to work in variable |
| 2050 | // printing, then add our name ([%d]) to the expression path |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 2051 | if (m_is_array_item_for_pointer && epformat == eHonorPointers) |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 2052 | s.PutCString(m_name.AsCString()); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2053 | |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2054 | if (!IsBaseClass()) |
| 2055 | { |
| 2056 | if (!is_deref_of_parent) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2057 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2058 | ValueObject *non_base_class_parent = GetNonBaseClassParent(); |
| 2059 | if (non_base_class_parent) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2060 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2061 | clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType(); |
| 2062 | if (non_base_class_parent_clang_type) |
| 2063 | { |
| 2064 | const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL); |
| 2065 | |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 2066 | if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers) |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2067 | { |
| 2068 | s.PutCString("->"); |
| 2069 | } |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2070 | else |
| 2071 | { |
| 2072 | if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer) |
| 2073 | { |
| 2074 | s.PutCString("->"); |
| 2075 | } |
| 2076 | else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) && |
| 2077 | !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray)) |
| 2078 | { |
| 2079 | s.PutChar('.'); |
| 2080 | } |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2081 | } |
| 2082 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2083 | } |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2084 | |
| 2085 | const char *name = GetName().GetCString(); |
| 2086 | if (name) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2087 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2088 | if (qualify_cxx_base_classes) |
| 2089 | { |
| 2090 | if (GetBaseClassPath (s)) |
| 2091 | s.PutCString("::"); |
| 2092 | } |
| 2093 | s.PutCString(name); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2094 | } |
| 2095 | } |
| 2096 | } |
| 2097 | |
Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 2098 | if (is_deref_of_parent && epformat == eDereferencePointers) |
| 2099 | { |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2100 | s.PutChar(')'); |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2101 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2104 | ValueObjectSP |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2105 | ValueObject::GetValueForExpressionPath(const char* expression, |
| 2106 | const char** first_unparsed, |
| 2107 | ExpressionPathScanEndReason* reason_to_stop, |
| 2108 | ExpressionPathEndResultType* final_value_type, |
| 2109 | const GetValueForExpressionPathOptions& options, |
| 2110 | ExpressionPathAftermath* final_task_on_target) |
| 2111 | { |
| 2112 | |
| 2113 | const char* dummy_first_unparsed; |
| 2114 | ExpressionPathScanEndReason dummy_reason_to_stop; |
| 2115 | ExpressionPathEndResultType dummy_final_value_type; |
| 2116 | ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing; |
| 2117 | |
| 2118 | ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression, |
| 2119 | first_unparsed ? first_unparsed : &dummy_first_unparsed, |
| 2120 | reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, |
| 2121 | final_value_type ? final_value_type : &dummy_final_value_type, |
| 2122 | options, |
| 2123 | final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); |
| 2124 | |
| 2125 | if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing) |
| 2126 | { |
| 2127 | return ret_val; |
| 2128 | } |
| 2129 | if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects |
| 2130 | { |
| 2131 | if (*final_task_on_target == ValueObject::eDereference) |
| 2132 | { |
| 2133 | Error error; |
| 2134 | ValueObjectSP final_value = ret_val->Dereference(error); |
| 2135 | if (error.Fail() || !final_value.get()) |
| 2136 | { |
| 2137 | *reason_to_stop = ValueObject::eDereferencingFailed; |
| 2138 | *final_value_type = ValueObject::eInvalid; |
| 2139 | return ValueObjectSP(); |
| 2140 | } |
| 2141 | else |
| 2142 | { |
| 2143 | *final_task_on_target = ValueObject::eNothing; |
| 2144 | return final_value; |
| 2145 | } |
| 2146 | } |
| 2147 | if (*final_task_on_target == ValueObject::eTakeAddress) |
| 2148 | { |
| 2149 | Error error; |
| 2150 | ValueObjectSP final_value = ret_val->AddressOf(error); |
| 2151 | if (error.Fail() || !final_value.get()) |
| 2152 | { |
| 2153 | *reason_to_stop = ValueObject::eTakingAddressFailed; |
| 2154 | *final_value_type = ValueObject::eInvalid; |
| 2155 | return ValueObjectSP(); |
| 2156 | } |
| 2157 | else |
| 2158 | { |
| 2159 | *final_task_on_target = ValueObject::eNothing; |
| 2160 | return final_value; |
| 2161 | } |
| 2162 | } |
| 2163 | } |
| 2164 | return ret_val; // final_task_on_target will still have its original value, so you know I did not do it |
| 2165 | } |
| 2166 | |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2167 | int |
| 2168 | ValueObject::GetValuesForExpressionPath(const char* expression, |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2169 | ValueObjectListSP& list, |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2170 | const char** first_unparsed, |
| 2171 | ExpressionPathScanEndReason* reason_to_stop, |
| 2172 | ExpressionPathEndResultType* final_value_type, |
| 2173 | const GetValueForExpressionPathOptions& options, |
| 2174 | ExpressionPathAftermath* final_task_on_target) |
| 2175 | { |
| 2176 | const char* dummy_first_unparsed; |
| 2177 | ExpressionPathScanEndReason dummy_reason_to_stop; |
| 2178 | ExpressionPathEndResultType dummy_final_value_type; |
| 2179 | ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing; |
| 2180 | |
| 2181 | ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression, |
| 2182 | first_unparsed ? first_unparsed : &dummy_first_unparsed, |
| 2183 | reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, |
| 2184 | final_value_type ? final_value_type : &dummy_final_value_type, |
| 2185 | options, |
| 2186 | final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); |
| 2187 | |
| 2188 | if (!ret_val.get()) // if there are errors, I add nothing to the list |
| 2189 | return 0; |
| 2190 | |
| 2191 | if (*reason_to_stop != eArrayRangeOperatorMet) |
| 2192 | { |
| 2193 | // I need not expand a range, just post-process the final value and return |
| 2194 | if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing) |
| 2195 | { |
| 2196 | list->Append(ret_val); |
| 2197 | return 1; |
| 2198 | } |
| 2199 | if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects |
| 2200 | { |
| 2201 | if (*final_task_on_target == ValueObject::eDereference) |
| 2202 | { |
| 2203 | Error error; |
| 2204 | ValueObjectSP final_value = ret_val->Dereference(error); |
| 2205 | if (error.Fail() || !final_value.get()) |
| 2206 | { |
| 2207 | *reason_to_stop = ValueObject::eDereferencingFailed; |
| 2208 | *final_value_type = ValueObject::eInvalid; |
| 2209 | return 0; |
| 2210 | } |
| 2211 | else |
| 2212 | { |
| 2213 | *final_task_on_target = ValueObject::eNothing; |
| 2214 | list->Append(final_value); |
| 2215 | return 1; |
| 2216 | } |
| 2217 | } |
| 2218 | if (*final_task_on_target == ValueObject::eTakeAddress) |
| 2219 | { |
| 2220 | Error error; |
| 2221 | ValueObjectSP final_value = ret_val->AddressOf(error); |
| 2222 | if (error.Fail() || !final_value.get()) |
| 2223 | { |
| 2224 | *reason_to_stop = ValueObject::eTakingAddressFailed; |
| 2225 | *final_value_type = ValueObject::eInvalid; |
| 2226 | return 0; |
| 2227 | } |
| 2228 | else |
| 2229 | { |
| 2230 | *final_task_on_target = ValueObject::eNothing; |
| 2231 | list->Append(final_value); |
| 2232 | return 1; |
| 2233 | } |
| 2234 | } |
| 2235 | } |
| 2236 | } |
| 2237 | else |
| 2238 | { |
| 2239 | return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed, |
| 2240 | first_unparsed ? first_unparsed : &dummy_first_unparsed, |
| 2241 | ret_val, |
| 2242 | list, |
| 2243 | reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, |
| 2244 | final_value_type ? final_value_type : &dummy_final_value_type, |
| 2245 | options, |
| 2246 | final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); |
| 2247 | } |
| 2248 | // in any non-covered case, just do the obviously right thing |
| 2249 | list->Append(ret_val); |
| 2250 | return 1; |
| 2251 | } |
| 2252 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2253 | ValueObjectSP |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2254 | ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr, |
| 2255 | const char** first_unparsed, |
| 2256 | ExpressionPathScanEndReason* reason_to_stop, |
| 2257 | ExpressionPathEndResultType* final_result, |
| 2258 | const GetValueForExpressionPathOptions& options, |
| 2259 | ExpressionPathAftermath* what_next) |
| 2260 | { |
| 2261 | ValueObjectSP root = GetSP(); |
| 2262 | |
| 2263 | if (!root.get()) |
| 2264 | return ValueObjectSP(); |
| 2265 | |
| 2266 | *first_unparsed = expression_cstr; |
| 2267 | |
| 2268 | while (true) |
| 2269 | { |
| 2270 | |
| 2271 | const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr |
| 2272 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2273 | clang_type_t root_clang_type = root->GetClangType(); |
| 2274 | clang_type_t pointee_clang_type; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2275 | Flags root_clang_type_info,pointee_clang_type_info; |
| 2276 | |
| 2277 | root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type)); |
| 2278 | if (pointee_clang_type) |
| 2279 | pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL)); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2280 | |
| 2281 | if (!expression_cstr || *expression_cstr == '\0') |
| 2282 | { |
| 2283 | *reason_to_stop = ValueObject::eEndOfString; |
| 2284 | return root; |
| 2285 | } |
| 2286 | |
| 2287 | switch (*expression_cstr) |
| 2288 | { |
| 2289 | case '-': |
| 2290 | { |
| 2291 | if (options.m_check_dot_vs_arrow_syntax && |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2292 | 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] | 2293 | { |
| 2294 | *first_unparsed = expression_cstr; |
| 2295 | *reason_to_stop = ValueObject::eArrowInsteadOfDot; |
| 2296 | *final_result = ValueObject::eInvalid; |
| 2297 | return ValueObjectSP(); |
| 2298 | } |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2299 | if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden |
| 2300 | root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) && |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2301 | options.m_no_fragile_ivar) |
| 2302 | { |
| 2303 | *first_unparsed = expression_cstr; |
| 2304 | *reason_to_stop = ValueObject::eFragileIVarNotAllowed; |
| 2305 | *final_result = ValueObject::eInvalid; |
| 2306 | return ValueObjectSP(); |
| 2307 | } |
| 2308 | if (expression_cstr[1] != '>') |
| 2309 | { |
| 2310 | *first_unparsed = expression_cstr; |
| 2311 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2312 | *final_result = ValueObject::eInvalid; |
| 2313 | return ValueObjectSP(); |
| 2314 | } |
| 2315 | expression_cstr++; // skip the - |
| 2316 | } |
| 2317 | case '.': // or fallthrough from -> |
| 2318 | { |
| 2319 | if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' && |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2320 | 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] | 2321 | { |
| 2322 | *first_unparsed = expression_cstr; |
| 2323 | *reason_to_stop = ValueObject::eDotInsteadOfArrow; |
| 2324 | *final_result = ValueObject::eInvalid; |
| 2325 | return ValueObjectSP(); |
| 2326 | } |
| 2327 | expression_cstr++; // skip . |
| 2328 | const char *next_separator = strpbrk(expression_cstr+1,"-.["); |
| 2329 | ConstString child_name; |
| 2330 | if (!next_separator) // if no other separator just expand this last layer |
| 2331 | { |
| 2332 | child_name.SetCString (expression_cstr); |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2333 | ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true); |
| 2334 | |
| 2335 | if (child_valobj_sp.get()) // we know we are done, so just return |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2336 | { |
| 2337 | *first_unparsed = '\0'; |
| 2338 | *reason_to_stop = ValueObject::eEndOfString; |
| 2339 | *final_result = ValueObject::ePlain; |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2340 | return child_valobj_sp; |
| 2341 | } |
| 2342 | else if (options.m_no_synthetic_children == false) // let's try with synthetic children |
| 2343 | { |
Greg Clayton | 4c3b8fb | 2011-12-02 22:48:25 +0000 | [diff] [blame] | 2344 | child_valobj_sp = root->GetSyntheticValue(eNoSyntheticFilter)->GetChildMemberWithName(child_name, true); |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP, |
| 2348 | // so we hit the "else" branch, and return an error |
| 2349 | if(child_valobj_sp.get()) // if it worked, just return |
| 2350 | { |
| 2351 | *first_unparsed = '\0'; |
| 2352 | *reason_to_stop = ValueObject::eEndOfString; |
| 2353 | *final_result = ValueObject::ePlain; |
| 2354 | return child_valobj_sp; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2355 | } |
| 2356 | else |
| 2357 | { |
| 2358 | *first_unparsed = expression_cstr; |
| 2359 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2360 | *final_result = ValueObject::eInvalid; |
| 2361 | return ValueObjectSP(); |
| 2362 | } |
| 2363 | } |
| 2364 | else // other layers do expand |
| 2365 | { |
| 2366 | child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr); |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2367 | ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true); |
| 2368 | if (child_valobj_sp.get()) // store the new root and move on |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2369 | { |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2370 | root = child_valobj_sp; |
| 2371 | *first_unparsed = next_separator; |
| 2372 | *final_result = ValueObject::ePlain; |
| 2373 | continue; |
| 2374 | } |
| 2375 | else if (options.m_no_synthetic_children == false) // let's try with synthetic children |
| 2376 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2377 | child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true); |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP, |
| 2381 | // so we hit the "else" branch, and return an error |
| 2382 | if(child_valobj_sp.get()) // if it worked, move on |
| 2383 | { |
| 2384 | root = child_valobj_sp; |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2385 | *first_unparsed = next_separator; |
| 2386 | *final_result = ValueObject::ePlain; |
| 2387 | continue; |
| 2388 | } |
| 2389 | else |
| 2390 | { |
| 2391 | *first_unparsed = expression_cstr; |
| 2392 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2393 | *final_result = ValueObject::eInvalid; |
| 2394 | return ValueObjectSP(); |
| 2395 | } |
| 2396 | } |
| 2397 | break; |
| 2398 | } |
| 2399 | case '[': |
| 2400 | { |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2401 | 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] | 2402 | { |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 2403 | if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar... |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2404 | { |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 2405 | if (options.m_no_synthetic_children) // ...only chance left is synthetic |
| 2406 | { |
| 2407 | *first_unparsed = expression_cstr; |
| 2408 | *reason_to_stop = ValueObject::eRangeOperatorInvalid; |
| 2409 | *final_result = ValueObject::eInvalid; |
| 2410 | return ValueObjectSP(); |
| 2411 | } |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2412 | } |
| 2413 | else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields |
| 2414 | { |
| 2415 | *first_unparsed = expression_cstr; |
| 2416 | *reason_to_stop = ValueObject::eRangeOperatorNotAllowed; |
| 2417 | *final_result = ValueObject::eInvalid; |
| 2418 | return ValueObjectSP(); |
| 2419 | } |
| 2420 | } |
| 2421 | if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays |
| 2422 | { |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2423 | if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2424 | { |
| 2425 | *first_unparsed = expression_cstr; |
| 2426 | *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; |
| 2427 | *final_result = ValueObject::eInvalid; |
| 2428 | return ValueObjectSP(); |
| 2429 | } |
| 2430 | else // even if something follows, we cannot expand unbounded ranges, just let the caller do it |
| 2431 | { |
| 2432 | *first_unparsed = expression_cstr+2; |
| 2433 | *reason_to_stop = ValueObject::eArrayRangeOperatorMet; |
| 2434 | *final_result = ValueObject::eUnboundedRange; |
| 2435 | return root; |
| 2436 | } |
| 2437 | } |
| 2438 | const char *separator_position = ::strchr(expression_cstr+1,'-'); |
| 2439 | const char *close_bracket_position = ::strchr(expression_cstr+1,']'); |
| 2440 | if (!close_bracket_position) // if there is no ], this is a syntax error |
| 2441 | { |
| 2442 | *first_unparsed = expression_cstr; |
| 2443 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2444 | *final_result = ValueObject::eInvalid; |
| 2445 | return ValueObjectSP(); |
| 2446 | } |
| 2447 | if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N] |
| 2448 | { |
| 2449 | char *end = NULL; |
| 2450 | unsigned long index = ::strtoul (expression_cstr+1, &end, 0); |
| 2451 | if (!end || end != close_bracket_position) // if something weird is in our way return an error |
| 2452 | { |
| 2453 | *first_unparsed = expression_cstr; |
| 2454 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2455 | *final_result = ValueObject::eInvalid; |
| 2456 | return ValueObjectSP(); |
| 2457 | } |
| 2458 | if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays |
| 2459 | { |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2460 | if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2461 | { |
| 2462 | *first_unparsed = expression_cstr+2; |
| 2463 | *reason_to_stop = ValueObject::eArrayRangeOperatorMet; |
| 2464 | *final_result = ValueObject::eUnboundedRange; |
| 2465 | return root; |
| 2466 | } |
| 2467 | else |
| 2468 | { |
| 2469 | *first_unparsed = expression_cstr; |
| 2470 | *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; |
| 2471 | *final_result = ValueObject::eInvalid; |
| 2472 | return ValueObjectSP(); |
| 2473 | } |
| 2474 | } |
| 2475 | // from here on we do have a valid index |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2476 | if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2477 | { |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 2478 | ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true); |
| 2479 | if (!child_valobj_sp) |
| 2480 | child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true); |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 2481 | if (!child_valobj_sp) |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2482 | if (root->HasSyntheticValue() && root->GetSyntheticValue(eUseSyntheticFilter)->GetNumChildren() > index) |
| 2483 | child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true); |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 2484 | if (child_valobj_sp) |
| 2485 | { |
| 2486 | root = child_valobj_sp; |
| 2487 | *first_unparsed = end+1; // skip ] |
| 2488 | *final_result = ValueObject::ePlain; |
| 2489 | continue; |
| 2490 | } |
| 2491 | else |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2492 | { |
| 2493 | *first_unparsed = expression_cstr; |
| 2494 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2495 | *final_result = ValueObject::eInvalid; |
| 2496 | return ValueObjectSP(); |
| 2497 | } |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2498 | } |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2499 | else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2500 | { |
| 2501 | 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] | 2502 | pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2503 | { |
| 2504 | Error error; |
| 2505 | root = root->Dereference(error); |
| 2506 | if (error.Fail() || !root.get()) |
| 2507 | { |
| 2508 | *first_unparsed = expression_cstr; |
| 2509 | *reason_to_stop = ValueObject::eDereferencingFailed; |
| 2510 | *final_result = ValueObject::eInvalid; |
| 2511 | return ValueObjectSP(); |
| 2512 | } |
| 2513 | else |
| 2514 | { |
| 2515 | *what_next = eNothing; |
| 2516 | continue; |
| 2517 | } |
| 2518 | } |
| 2519 | else |
| 2520 | { |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 2521 | if (ClangASTType::GetMinimumLanguage(root->GetClangAST(), |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2522 | root->GetClangType()) == eLanguageTypeObjC |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 2523 | && |
| 2524 | ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false |
| 2525 | && |
| 2526 | root->HasSyntheticValue() |
| 2527 | && |
| 2528 | options.m_no_synthetic_children == false) |
| 2529 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2530 | root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true); |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 2531 | } |
| 2532 | else |
| 2533 | root = root->GetSyntheticArrayMemberFromPointer(index, true); |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2534 | if (!root.get()) |
| 2535 | { |
| 2536 | *first_unparsed = expression_cstr; |
| 2537 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2538 | *final_result = ValueObject::eInvalid; |
| 2539 | return ValueObjectSP(); |
| 2540 | } |
| 2541 | else |
| 2542 | { |
| 2543 | *first_unparsed = end+1; // skip ] |
| 2544 | *final_result = ValueObject::ePlain; |
| 2545 | continue; |
| 2546 | } |
| 2547 | } |
| 2548 | } |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 2549 | else if (ClangASTContext::IsScalarType(root_clang_type)) |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2550 | { |
| 2551 | root = root->GetSyntheticBitFieldChild(index, index, true); |
| 2552 | if (!root.get()) |
| 2553 | { |
| 2554 | *first_unparsed = expression_cstr; |
| 2555 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2556 | *final_result = ValueObject::eInvalid; |
| 2557 | return ValueObjectSP(); |
| 2558 | } |
| 2559 | else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing |
| 2560 | { |
| 2561 | *first_unparsed = end+1; // skip ] |
| 2562 | *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet; |
| 2563 | *final_result = ValueObject::eBitfield; |
| 2564 | return root; |
| 2565 | } |
| 2566 | } |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2567 | else if (root->HasSyntheticValue() && options.m_no_synthetic_children == false) |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 2568 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2569 | root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true); |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 2570 | if (!root.get()) |
| 2571 | { |
| 2572 | *first_unparsed = expression_cstr; |
| 2573 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2574 | *final_result = ValueObject::eInvalid; |
| 2575 | return ValueObjectSP(); |
| 2576 | } |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2577 | else |
| 2578 | { |
| 2579 | *first_unparsed = end+1; // skip ] |
| 2580 | *final_result = ValueObject::ePlain; |
| 2581 | continue; |
| 2582 | } |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 2583 | } |
| 2584 | else |
| 2585 | { |
| 2586 | *first_unparsed = expression_cstr; |
| 2587 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2588 | *final_result = ValueObject::eInvalid; |
| 2589 | return ValueObjectSP(); |
| 2590 | } |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2591 | } |
| 2592 | else // we have a low and a high index |
| 2593 | { |
| 2594 | char *end = NULL; |
| 2595 | unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0); |
| 2596 | if (!end || end != separator_position) // if something weird is in our way return an error |
| 2597 | { |
| 2598 | *first_unparsed = expression_cstr; |
| 2599 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2600 | *final_result = ValueObject::eInvalid; |
| 2601 | return ValueObjectSP(); |
| 2602 | } |
| 2603 | unsigned long index_higher = ::strtoul (separator_position+1, &end, 0); |
| 2604 | if (!end || end != close_bracket_position) // if something weird is in our way return an error |
| 2605 | { |
| 2606 | *first_unparsed = expression_cstr; |
| 2607 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2608 | *final_result = ValueObject::eInvalid; |
| 2609 | return ValueObjectSP(); |
| 2610 | } |
| 2611 | if (index_lower > index_higher) // swap indices if required |
| 2612 | { |
| 2613 | unsigned long temp = index_lower; |
| 2614 | index_lower = index_higher; |
| 2615 | index_higher = temp; |
| 2616 | } |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2617 | 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] | 2618 | { |
| 2619 | root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true); |
| 2620 | if (!root.get()) |
| 2621 | { |
| 2622 | *first_unparsed = expression_cstr; |
| 2623 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2624 | *final_result = ValueObject::eInvalid; |
| 2625 | return ValueObjectSP(); |
| 2626 | } |
| 2627 | else |
| 2628 | { |
| 2629 | *first_unparsed = end+1; // skip ] |
| 2630 | *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet; |
| 2631 | *final_result = ValueObject::eBitfield; |
| 2632 | return root; |
| 2633 | } |
| 2634 | } |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2635 | 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] | 2636 | *what_next == ValueObject::eDereference && |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2637 | pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) |
Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2638 | { |
| 2639 | Error error; |
| 2640 | root = root->Dereference(error); |
| 2641 | if (error.Fail() || !root.get()) |
| 2642 | { |
| 2643 | *first_unparsed = expression_cstr; |
| 2644 | *reason_to_stop = ValueObject::eDereferencingFailed; |
| 2645 | *final_result = ValueObject::eInvalid; |
| 2646 | return ValueObjectSP(); |
| 2647 | } |
| 2648 | else |
| 2649 | { |
| 2650 | *what_next = ValueObject::eNothing; |
| 2651 | continue; |
| 2652 | } |
| 2653 | } |
| 2654 | else |
| 2655 | { |
| 2656 | *first_unparsed = expression_cstr; |
| 2657 | *reason_to_stop = ValueObject::eArrayRangeOperatorMet; |
| 2658 | *final_result = ValueObject::eBoundedRange; |
| 2659 | return root; |
| 2660 | } |
| 2661 | } |
| 2662 | break; |
| 2663 | } |
| 2664 | default: // some non-separator is in the way |
| 2665 | { |
| 2666 | *first_unparsed = expression_cstr; |
| 2667 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2668 | *final_result = ValueObject::eInvalid; |
| 2669 | return ValueObjectSP(); |
| 2670 | break; |
| 2671 | } |
| 2672 | } |
| 2673 | } |
| 2674 | } |
| 2675 | |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2676 | int |
| 2677 | ValueObject::ExpandArraySliceExpression(const char* expression_cstr, |
| 2678 | const char** first_unparsed, |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2679 | ValueObjectSP root, |
| 2680 | ValueObjectListSP& list, |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2681 | ExpressionPathScanEndReason* reason_to_stop, |
| 2682 | ExpressionPathEndResultType* final_result, |
| 2683 | const GetValueForExpressionPathOptions& options, |
| 2684 | ExpressionPathAftermath* what_next) |
| 2685 | { |
| 2686 | if (!root.get()) |
| 2687 | return 0; |
| 2688 | |
| 2689 | *first_unparsed = expression_cstr; |
| 2690 | |
| 2691 | while (true) |
| 2692 | { |
| 2693 | |
| 2694 | const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr |
| 2695 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2696 | clang_type_t root_clang_type = root->GetClangType(); |
| 2697 | clang_type_t pointee_clang_type; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2698 | Flags root_clang_type_info,pointee_clang_type_info; |
| 2699 | |
| 2700 | root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type)); |
| 2701 | if (pointee_clang_type) |
| 2702 | pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL)); |
| 2703 | |
| 2704 | if (!expression_cstr || *expression_cstr == '\0') |
| 2705 | { |
| 2706 | *reason_to_stop = ValueObject::eEndOfString; |
| 2707 | list->Append(root); |
| 2708 | return 1; |
| 2709 | } |
| 2710 | |
| 2711 | switch (*expression_cstr) |
| 2712 | { |
| 2713 | case '[': |
| 2714 | { |
| 2715 | if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T* |
| 2716 | { |
| 2717 | if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong! |
| 2718 | { |
| 2719 | *first_unparsed = expression_cstr; |
| 2720 | *reason_to_stop = ValueObject::eRangeOperatorInvalid; |
| 2721 | *final_result = ValueObject::eInvalid; |
| 2722 | return 0; |
| 2723 | } |
| 2724 | else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields |
| 2725 | { |
| 2726 | *first_unparsed = expression_cstr; |
| 2727 | *reason_to_stop = ValueObject::eRangeOperatorNotAllowed; |
| 2728 | *final_result = ValueObject::eInvalid; |
| 2729 | return 0; |
| 2730 | } |
| 2731 | } |
| 2732 | if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays |
| 2733 | { |
| 2734 | if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) |
| 2735 | { |
| 2736 | *first_unparsed = expression_cstr; |
| 2737 | *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; |
| 2738 | *final_result = ValueObject::eInvalid; |
| 2739 | return 0; |
| 2740 | } |
| 2741 | else // expand this into list |
| 2742 | { |
| 2743 | int max_index = root->GetNumChildren() - 1; |
| 2744 | for (int index = 0; index < max_index; index++) |
| 2745 | { |
| 2746 | ValueObjectSP child = |
| 2747 | root->GetChildAtIndex(index, true); |
| 2748 | list->Append(child); |
| 2749 | } |
| 2750 | *first_unparsed = expression_cstr+2; |
| 2751 | *reason_to_stop = ValueObject::eRangeOperatorExpanded; |
| 2752 | *final_result = ValueObject::eValueObjectList; |
| 2753 | return max_index; // tell me number of items I added to the VOList |
| 2754 | } |
| 2755 | } |
| 2756 | const char *separator_position = ::strchr(expression_cstr+1,'-'); |
| 2757 | const char *close_bracket_position = ::strchr(expression_cstr+1,']'); |
| 2758 | if (!close_bracket_position) // if there is no ], this is a syntax error |
| 2759 | { |
| 2760 | *first_unparsed = expression_cstr; |
| 2761 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2762 | *final_result = ValueObject::eInvalid; |
| 2763 | return 0; |
| 2764 | } |
| 2765 | if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N] |
| 2766 | { |
| 2767 | char *end = NULL; |
| 2768 | unsigned long index = ::strtoul (expression_cstr+1, &end, 0); |
| 2769 | if (!end || end != close_bracket_position) // if something weird is in our way return an error |
| 2770 | { |
| 2771 | *first_unparsed = expression_cstr; |
| 2772 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2773 | *final_result = ValueObject::eInvalid; |
| 2774 | return 0; |
| 2775 | } |
| 2776 | if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays |
| 2777 | { |
| 2778 | if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) |
| 2779 | { |
| 2780 | int max_index = root->GetNumChildren() - 1; |
| 2781 | for (int index = 0; index < max_index; index++) |
| 2782 | { |
| 2783 | ValueObjectSP child = |
| 2784 | root->GetChildAtIndex(index, true); |
| 2785 | list->Append(child); |
| 2786 | } |
| 2787 | *first_unparsed = expression_cstr+2; |
| 2788 | *reason_to_stop = ValueObject::eRangeOperatorExpanded; |
| 2789 | *final_result = ValueObject::eValueObjectList; |
| 2790 | return max_index; // tell me number of items I added to the VOList |
| 2791 | } |
| 2792 | else |
| 2793 | { |
| 2794 | *first_unparsed = expression_cstr; |
| 2795 | *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; |
| 2796 | *final_result = ValueObject::eInvalid; |
| 2797 | return 0; |
| 2798 | } |
| 2799 | } |
| 2800 | // from here on we do have a valid index |
| 2801 | if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) |
| 2802 | { |
| 2803 | root = root->GetChildAtIndex(index, true); |
| 2804 | if (!root.get()) |
| 2805 | { |
| 2806 | *first_unparsed = expression_cstr; |
| 2807 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2808 | *final_result = ValueObject::eInvalid; |
| 2809 | return 0; |
| 2810 | } |
| 2811 | else |
| 2812 | { |
| 2813 | list->Append(root); |
| 2814 | *first_unparsed = end+1; // skip ] |
| 2815 | *reason_to_stop = ValueObject::eRangeOperatorExpanded; |
| 2816 | *final_result = ValueObject::eValueObjectList; |
| 2817 | return 1; |
| 2818 | } |
| 2819 | } |
| 2820 | else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) |
| 2821 | { |
| 2822 | 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 |
| 2823 | pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) |
| 2824 | { |
| 2825 | Error error; |
| 2826 | root = root->Dereference(error); |
| 2827 | if (error.Fail() || !root.get()) |
| 2828 | { |
| 2829 | *first_unparsed = expression_cstr; |
| 2830 | *reason_to_stop = ValueObject::eDereferencingFailed; |
| 2831 | *final_result = ValueObject::eInvalid; |
| 2832 | return 0; |
| 2833 | } |
| 2834 | else |
| 2835 | { |
| 2836 | *what_next = eNothing; |
| 2837 | continue; |
| 2838 | } |
| 2839 | } |
| 2840 | else |
| 2841 | { |
| 2842 | root = root->GetSyntheticArrayMemberFromPointer(index, true); |
| 2843 | if (!root.get()) |
| 2844 | { |
| 2845 | *first_unparsed = expression_cstr; |
| 2846 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2847 | *final_result = ValueObject::eInvalid; |
| 2848 | return 0; |
| 2849 | } |
| 2850 | else |
| 2851 | { |
| 2852 | list->Append(root); |
| 2853 | *first_unparsed = end+1; // skip ] |
| 2854 | *reason_to_stop = ValueObject::eRangeOperatorExpanded; |
| 2855 | *final_result = ValueObject::eValueObjectList; |
| 2856 | return 1; |
| 2857 | } |
| 2858 | } |
| 2859 | } |
| 2860 | else /*if (ClangASTContext::IsScalarType(root_clang_type))*/ |
| 2861 | { |
| 2862 | root = root->GetSyntheticBitFieldChild(index, index, true); |
| 2863 | if (!root.get()) |
| 2864 | { |
| 2865 | *first_unparsed = expression_cstr; |
| 2866 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2867 | *final_result = ValueObject::eInvalid; |
| 2868 | return 0; |
| 2869 | } |
| 2870 | else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing |
| 2871 | { |
| 2872 | list->Append(root); |
| 2873 | *first_unparsed = end+1; // skip ] |
| 2874 | *reason_to_stop = ValueObject::eRangeOperatorExpanded; |
| 2875 | *final_result = ValueObject::eValueObjectList; |
| 2876 | return 1; |
| 2877 | } |
| 2878 | } |
| 2879 | } |
| 2880 | else // we have a low and a high index |
| 2881 | { |
| 2882 | char *end = NULL; |
| 2883 | unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0); |
| 2884 | if (!end || end != separator_position) // if something weird is in our way return an error |
| 2885 | { |
| 2886 | *first_unparsed = expression_cstr; |
| 2887 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2888 | *final_result = ValueObject::eInvalid; |
| 2889 | return 0; |
| 2890 | } |
| 2891 | unsigned long index_higher = ::strtoul (separator_position+1, &end, 0); |
| 2892 | if (!end || end != close_bracket_position) // if something weird is in our way return an error |
| 2893 | { |
| 2894 | *first_unparsed = expression_cstr; |
| 2895 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2896 | *final_result = ValueObject::eInvalid; |
| 2897 | return 0; |
| 2898 | } |
| 2899 | if (index_lower > index_higher) // swap indices if required |
| 2900 | { |
| 2901 | unsigned long temp = index_lower; |
| 2902 | index_lower = index_higher; |
| 2903 | index_higher = temp; |
| 2904 | } |
| 2905 | if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars |
| 2906 | { |
| 2907 | root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true); |
| 2908 | if (!root.get()) |
| 2909 | { |
| 2910 | *first_unparsed = expression_cstr; |
| 2911 | *reason_to_stop = ValueObject::eNoSuchChild; |
| 2912 | *final_result = ValueObject::eInvalid; |
| 2913 | return 0; |
| 2914 | } |
| 2915 | else |
| 2916 | { |
| 2917 | list->Append(root); |
| 2918 | *first_unparsed = end+1; // skip ] |
| 2919 | *reason_to_stop = ValueObject::eRangeOperatorExpanded; |
| 2920 | *final_result = ValueObject::eValueObjectList; |
| 2921 | return 1; |
| 2922 | } |
| 2923 | } |
| 2924 | 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 |
| 2925 | *what_next == ValueObject::eDereference && |
| 2926 | pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) |
| 2927 | { |
| 2928 | Error error; |
| 2929 | root = root->Dereference(error); |
| 2930 | if (error.Fail() || !root.get()) |
| 2931 | { |
| 2932 | *first_unparsed = expression_cstr; |
| 2933 | *reason_to_stop = ValueObject::eDereferencingFailed; |
| 2934 | *final_result = ValueObject::eInvalid; |
| 2935 | return 0; |
| 2936 | } |
| 2937 | else |
| 2938 | { |
| 2939 | *what_next = ValueObject::eNothing; |
| 2940 | continue; |
| 2941 | } |
| 2942 | } |
| 2943 | else |
| 2944 | { |
Johnny Chen | 4480530 | 2011-07-19 19:48:13 +0000 | [diff] [blame] | 2945 | for (unsigned long index = index_lower; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2946 | index <= index_higher; index++) |
| 2947 | { |
| 2948 | ValueObjectSP child = |
| 2949 | root->GetChildAtIndex(index, true); |
| 2950 | list->Append(child); |
| 2951 | } |
| 2952 | *first_unparsed = end+1; |
| 2953 | *reason_to_stop = ValueObject::eRangeOperatorExpanded; |
| 2954 | *final_result = ValueObject::eValueObjectList; |
| 2955 | return index_higher-index_lower+1; // tell me number of items I added to the VOList |
| 2956 | } |
| 2957 | } |
| 2958 | break; |
| 2959 | } |
| 2960 | default: // some non-[ separator, or something entirely wrong, is in the way |
| 2961 | { |
| 2962 | *first_unparsed = expression_cstr; |
| 2963 | *reason_to_stop = ValueObject::eUnexpectedSymbol; |
| 2964 | *final_result = ValueObject::eInvalid; |
| 2965 | return 0; |
| 2966 | break; |
| 2967 | } |
| 2968 | } |
| 2969 | } |
| 2970 | } |
| 2971 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2972 | void |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2973 | ValueObject::DumpValueObject |
| 2974 | ( |
| 2975 | Stream &s, |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2976 | ValueObject *valobj, |
| 2977 | const char *root_valobj_name, |
| 2978 | uint32_t ptr_depth, |
| 2979 | uint32_t curr_depth, |
| 2980 | uint32_t max_depth, |
| 2981 | bool show_types, |
| 2982 | bool show_location, |
| 2983 | bool use_objc, |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2984 | DynamicValueType use_dynamic, |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 2985 | bool use_synth, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2986 | bool scope_already_checked, |
Enrico Granata | 0c5ef69 | 2011-07-16 01:22:04 +0000 | [diff] [blame] | 2987 | bool flat_output, |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 2988 | uint32_t omit_summary_depth, |
Greg Clayton | 6efba4f | 2012-01-26 21:08:30 +0000 | [diff] [blame] | 2989 | bool ignore_cap, |
| 2990 | Format format_override // Normally the format is in the valobj, but we might want to override this |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2991 | ) |
| 2992 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 2993 | if (valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2994 | { |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 2995 | bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true); |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 2996 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2997 | if (update_success && use_dynamic != eNoDynamicValues) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2998 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 2999 | ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 3000 | if (dynamic_value) |
| 3001 | valobj = dynamic_value; |
| 3002 | } |
| 3003 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3004 | clang_type_t clang_type = valobj->GetClangType(); |
| 3005 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 3006 | const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL)); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3007 | const char *err_cstr = NULL; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 3008 | const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren); |
| 3009 | const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3010 | |
| 3011 | const bool print_valobj = flat_output == false || has_value; |
| 3012 | |
| 3013 | if (print_valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3014 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3015 | if (show_location) |
| 3016 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3017 | s.Printf("%s: ", valobj->GetLocationAsCString()); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3018 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3019 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3020 | s.Indent(); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3021 | |
Greg Clayton | 7c8a966 | 2010-11-02 01:50:16 +0000 | [diff] [blame] | 3022 | // Always show the type for the top level items. |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 3023 | if (show_types || (curr_depth == 0 && !flat_output)) |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 3024 | { |
Enrico Granata | 9910bc8 | 2011-08-03 02:18:51 +0000 | [diff] [blame] | 3025 | const char* typeName = valobj->GetTypeName().AsCString("<invalid type>"); |
| 3026 | s.Printf("(%s", typeName); |
| 3027 | // only show dynamic types if the user really wants to see types |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3028 | if (show_types && use_dynamic != eNoDynamicValues && |
Enrico Granata | 9910bc8 | 2011-08-03 02:18:51 +0000 | [diff] [blame] | 3029 | (/*strstr(typeName, "id") == typeName ||*/ |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3030 | ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC)) |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 3031 | { |
| 3032 | Process* process = valobj->GetUpdatePoint().GetProcessSP().get(); |
| 3033 | if (process == NULL) |
Enrico Granata | 9910bc8 | 2011-08-03 02:18:51 +0000 | [diff] [blame] | 3034 | s.Printf(", dynamic type: unknown) "); |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 3035 | else |
| 3036 | { |
| 3037 | ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime(); |
| 3038 | if (runtime == NULL) |
Enrico Granata | 9910bc8 | 2011-08-03 02:18:51 +0000 | [diff] [blame] | 3039 | s.Printf(", dynamic type: unknown) "); |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 3040 | else |
| 3041 | { |
| 3042 | ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj); |
| 3043 | if (!runtime->IsValidISA(isa)) |
Enrico Granata | 9910bc8 | 2011-08-03 02:18:51 +0000 | [diff] [blame] | 3044 | s.Printf(", dynamic type: unknown) "); |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 3045 | else |
| 3046 | s.Printf(", dynamic type: %s) ", |
| 3047 | runtime->GetActualTypeName(isa).GetCString()); |
| 3048 | } |
| 3049 | } |
| 3050 | } |
| 3051 | else |
| 3052 | s.Printf(") "); |
| 3053 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3054 | |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3055 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3056 | if (flat_output) |
| 3057 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3058 | // If we are showing types, also qualify the C++ base classes |
| 3059 | const bool qualify_cxx_base_classes = show_types; |
| 3060 | valobj->GetExpressionPath(s, qualify_cxx_base_classes); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3061 | s.PutCString(" ="); |
| 3062 | } |
| 3063 | else |
| 3064 | { |
| 3065 | const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString(""); |
| 3066 | s.Printf ("%s =", name_cstr); |
| 3067 | } |
| 3068 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3069 | if (!scope_already_checked && !valobj->IsInScope()) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3070 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 3071 | err_cstr = "out of scope"; |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3072 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3073 | } |
| 3074 | |
Greg Clayton | 6efba4f | 2012-01-26 21:08:30 +0000 | [diff] [blame] | 3075 | std::string value_str; |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3076 | const char *val_cstr = NULL; |
Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 3077 | const char *sum_cstr = NULL; |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame^] | 3078 | TypeSummaryImpl* entry = valobj->GetSummaryFormat().get(); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3079 | |
Enrico Granata | 0c5ef69 | 2011-07-16 01:22:04 +0000 | [diff] [blame] | 3080 | if (omit_summary_depth > 0) |
| 3081 | entry = NULL; |
| 3082 | |
Greg Clayton | 6efba4f | 2012-01-26 21:08:30 +0000 | [diff] [blame] | 3083 | Format orig_format = kNumFormats; |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3084 | if (err_cstr == NULL) |
| 3085 | { |
Greg Clayton | 6efba4f | 2012-01-26 21:08:30 +0000 | [diff] [blame] | 3086 | if (format_override != eFormatDefault) |
| 3087 | { |
| 3088 | orig_format = valobj->GetFormat(); |
| 3089 | valobj->SetFormat (format_override); |
| 3090 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3091 | val_cstr = valobj->GetValueAsCString(); |
Greg Clayton | 6efba4f | 2012-01-26 21:08:30 +0000 | [diff] [blame] | 3092 | if (val_cstr) |
| 3093 | { |
| 3094 | // Cache the value in our own storage as running summaries might |
| 3095 | // change our value from underneath us |
| 3096 | value_str = val_cstr; |
| 3097 | } |
| 3098 | if (orig_format != kNumFormats && orig_format != format_override) |
| 3099 | { |
| 3100 | valobj->SetFormat (orig_format); |
| 3101 | orig_format = kNumFormats; |
| 3102 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3103 | err_cstr = valobj->GetError().AsCString(); |
| 3104 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3105 | |
| 3106 | if (err_cstr) |
| 3107 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 3108 | s.Printf (" <%s>\n", err_cstr); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3109 | } |
| 3110 | else |
| 3111 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 3112 | const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3113 | if (print_valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3114 | { |
Greg Clayton | 6efba4f | 2012-01-26 21:08:30 +0000 | [diff] [blame] | 3115 | if (omit_summary_depth == 0) |
| 3116 | sum_cstr = valobj->GetSummaryAsCString(); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3117 | |
Greg Clayton | 6efba4f | 2012-01-26 21:08:30 +0000 | [diff] [blame] | 3118 | // Make sure we have a value and make sure the summary didn't |
| 3119 | // specify that the value should not be printed |
| 3120 | if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL)) |
| 3121 | s.Printf(" %s", value_str.c_str()); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3122 | |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 3123 | if (sum_cstr) |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 3124 | { |
| 3125 | // for some reason, using %@ (ObjC description) in a summary string, makes |
| 3126 | // us believe we need to reset ourselves, thus invalidating the content of |
| 3127 | // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty |
| 3128 | // let us recalculate it! |
| 3129 | if (sum_cstr[0] == '\0') |
| 3130 | s.Printf(" %s", valobj->GetSummaryAsCString()); |
| 3131 | else |
| 3132 | s.Printf(" %s", sum_cstr); |
| 3133 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3134 | |
| 3135 | if (use_objc) |
| 3136 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3137 | const char *object_desc = valobj->GetObjectDescription(); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3138 | if (object_desc) |
| 3139 | s.Printf(" %s\n", object_desc); |
| 3140 | else |
Sean Callanan | 672ad94 | 2010-10-23 00:18:49 +0000 | [diff] [blame] | 3141 | s.Printf (" [no Objective-C description available]\n"); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3142 | return; |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 3143 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3144 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3145 | |
| 3146 | if (curr_depth < max_depth) |
| 3147 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 3148 | // We will show children for all concrete types. We won't show |
| 3149 | // pointer contents unless a pointer depth has been specified. |
| 3150 | // We won't reference contents unless the reference is the |
| 3151 | // root object (depth of zero). |
| 3152 | bool print_children = true; |
| 3153 | |
| 3154 | // Use a new temporary pointer depth in case we override the |
| 3155 | // current pointer depth below... |
| 3156 | uint32_t curr_ptr_depth = ptr_depth; |
| 3157 | |
| 3158 | const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer); |
| 3159 | if (is_ptr || is_ref) |
| 3160 | { |
| 3161 | // We have a pointer or reference whose value is an address. |
| 3162 | // Make sure that address is not NULL |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 3163 | AddressType ptr_address_type; |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 3164 | if (valobj->GetPointerValue (&ptr_address_type) == 0) |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 3165 | print_children = false; |
| 3166 | |
| 3167 | else if (is_ref && curr_depth == 0) |
| 3168 | { |
| 3169 | // If this is the root object (depth is zero) that we are showing |
| 3170 | // and it is a reference, and no pointer depth has been supplied |
| 3171 | // print out what it references. Don't do this at deeper depths |
| 3172 | // otherwise we can end up with infinite recursion... |
| 3173 | curr_ptr_depth = 1; |
| 3174 | } |
| 3175 | |
| 3176 | if (curr_ptr_depth == 0) |
| 3177 | print_children = false; |
| 3178 | } |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3179 | |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 3180 | if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr)) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3181 | { |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 3182 | ValueObjectSP synth_valobj = valobj->GetSyntheticValue(use_synth ? |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3183 | eUseSyntheticFilter : |
| 3184 | eNoSyntheticFilter); |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 3185 | uint32_t num_children = synth_valobj->GetNumChildren(); |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 3186 | bool print_dotdotdot = false; |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3187 | if (num_children) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3188 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3189 | if (flat_output) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3190 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3191 | if (print_valobj) |
| 3192 | s.EOL(); |
| 3193 | } |
| 3194 | else |
| 3195 | { |
| 3196 | if (print_valobj) |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 3197 | s.PutCString(is_ref ? ": {\n" : " {\n"); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3198 | s.IndentMore(); |
| 3199 | } |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 3200 | |
| 3201 | uint32_t max_num_children = valobj->GetUpdatePoint().GetTargetSP()->GetMaximumNumberOfChildrenToDisplay(); |
| 3202 | |
| 3203 | if (num_children > max_num_children && !ignore_cap) |
| 3204 | { |
| 3205 | num_children = max_num_children; |
| 3206 | print_dotdotdot = true; |
| 3207 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3208 | |
| 3209 | for (uint32_t idx=0; idx<num_children; ++idx) |
| 3210 | { |
Enrico Granata | c482a19 | 2011-08-17 22:13:59 +0000 | [diff] [blame] | 3211 | ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true)); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3212 | if (child_sp.get()) |
| 3213 | { |
| 3214 | DumpValueObject (s, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3215 | child_sp.get(), |
| 3216 | NULL, |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 3217 | (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3218 | curr_depth + 1, |
| 3219 | max_depth, |
| 3220 | show_types, |
| 3221 | show_location, |
| 3222 | false, |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 3223 | use_dynamic, |
Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 3224 | use_synth, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3225 | true, |
Enrico Granata | 0c5ef69 | 2011-07-16 01:22:04 +0000 | [diff] [blame] | 3226 | flat_output, |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 3227 | omit_summary_depth > 1 ? omit_summary_depth - 1 : 0, |
Greg Clayton | 6efba4f | 2012-01-26 21:08:30 +0000 | [diff] [blame] | 3228 | ignore_cap, |
| 3229 | format_override); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3230 | } |
| 3231 | } |
| 3232 | |
| 3233 | if (!flat_output) |
| 3234 | { |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 3235 | if (print_dotdotdot) |
Enrico Granata | 61a80ba | 2011-08-12 16:42:31 +0000 | [diff] [blame] | 3236 | { |
| 3237 | valobj->GetUpdatePoint().GetTargetSP()->GetDebugger().GetCommandInterpreter().ChildrenTruncated(); |
Enrico Granata | 22c55d1 | 2011-08-12 02:00:06 +0000 | [diff] [blame] | 3238 | s.Indent("...\n"); |
Enrico Granata | 61a80ba | 2011-08-12 16:42:31 +0000 | [diff] [blame] | 3239 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3240 | s.IndentLess(); |
| 3241 | s.Indent("}\n"); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3242 | } |
| 3243 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3244 | else if (has_children) |
| 3245 | { |
| 3246 | // Aggregate, no children... |
| 3247 | if (print_valobj) |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 3248 | s.PutCString(" {}\n"); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3249 | } |
| 3250 | else |
| 3251 | { |
| 3252 | if (print_valobj) |
| 3253 | s.EOL(); |
| 3254 | } |
| 3255 | |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3256 | } |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3257 | else |
| 3258 | { |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3259 | s.EOL(); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3260 | } |
| 3261 | } |
| 3262 | else |
| 3263 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3264 | if (has_children && print_valobj) |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3265 | { |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3266 | s.PutCString("{...}\n"); |
Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3267 | } |
| 3268 | } |
| 3269 | } |
| 3270 | } |
| 3271 | } |
| 3272 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3273 | |
| 3274 | ValueObjectSP |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3275 | ValueObject::CreateConstantValue (const ConstString &name) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3276 | { |
| 3277 | ValueObjectSP valobj_sp; |
| 3278 | |
Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 3279 | if (UpdateValueIfNeeded(false) && m_error.Success()) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3280 | { |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3281 | ExecutionContextScope *exe_scope = GetExecutionContextScope(); |
| 3282 | if (exe_scope) |
| 3283 | { |
| 3284 | ExecutionContext exe_ctx; |
| 3285 | exe_scope->CalculateExecutionContext(exe_ctx); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3286 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3287 | clang::ASTContext *ast = GetClangAST (); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3288 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3289 | DataExtractor data; |
| 3290 | data.SetByteOrder (m_data.GetByteOrder()); |
| 3291 | data.SetAddressByteSize(m_data.GetAddressByteSize()); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3292 | |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 3293 | m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule()); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3294 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 3295 | valobj_sp = ValueObjectConstResult::Create (exe_scope, |
| 3296 | ast, |
| 3297 | GetClangType(), |
| 3298 | name, |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 3299 | data, |
| 3300 | GetAddressOf()); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3301 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3302 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3303 | |
| 3304 | if (!valobj_sp) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3305 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 3306 | valobj_sp = ValueObjectConstResult::Create (NULL, m_error); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3307 | } |
| 3308 | return valobj_sp; |
| 3309 | } |
| 3310 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3311 | ValueObjectSP |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 3312 | ValueObject::Dereference (Error &error) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3313 | { |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 3314 | if (m_deref_valobj) |
| 3315 | return m_deref_valobj->GetSP(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 3316 | |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3317 | const bool is_pointer_type = IsPointerType(); |
| 3318 | if (is_pointer_type) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3319 | { |
| 3320 | bool omit_empty_base_classes = true; |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 3321 | bool ignore_array_bounds = false; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3322 | |
| 3323 | std::string child_name_str; |
| 3324 | uint32_t child_byte_size = 0; |
| 3325 | int32_t child_byte_offset = 0; |
| 3326 | uint32_t child_bitfield_bit_size = 0; |
| 3327 | uint32_t child_bitfield_bit_offset = 0; |
| 3328 | bool child_is_base_class = false; |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 3329 | bool child_is_deref_of_parent = false; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3330 | const bool transparent_pointers = false; |
| 3331 | clang::ASTContext *clang_ast = GetClangAST(); |
| 3332 | clang_type_t clang_type = GetClangType(); |
| 3333 | clang_type_t child_clang_type; |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 3334 | |
| 3335 | ExecutionContext exe_ctx; |
| 3336 | GetExecutionContextScope()->CalculateExecutionContext (exe_ctx); |
| 3337 | |
| 3338 | child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx, |
| 3339 | clang_ast, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3340 | GetName().GetCString(), |
| 3341 | clang_type, |
| 3342 | 0, |
| 3343 | transparent_pointers, |
| 3344 | omit_empty_base_classes, |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 3345 | ignore_array_bounds, |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3346 | child_name_str, |
| 3347 | child_byte_size, |
| 3348 | child_byte_offset, |
| 3349 | child_bitfield_bit_size, |
| 3350 | child_bitfield_bit_offset, |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 3351 | child_is_base_class, |
| 3352 | child_is_deref_of_parent); |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 3353 | if (child_clang_type && child_byte_size) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3354 | { |
| 3355 | ConstString child_name; |
| 3356 | if (!child_name_str.empty()) |
| 3357 | child_name.SetCString (child_name_str.c_str()); |
| 3358 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 3359 | m_deref_valobj = new ValueObjectChild (*this, |
| 3360 | clang_ast, |
| 3361 | child_clang_type, |
| 3362 | child_name, |
| 3363 | child_byte_size, |
| 3364 | child_byte_offset, |
| 3365 | child_bitfield_bit_size, |
| 3366 | child_bitfield_bit_offset, |
| 3367 | child_is_base_class, |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 3368 | child_is_deref_of_parent, |
| 3369 | eAddressTypeInvalid); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3370 | } |
| 3371 | } |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3372 | |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 3373 | if (m_deref_valobj) |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3374 | { |
| 3375 | error.Clear(); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 3376 | return m_deref_valobj->GetSP(); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3377 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3378 | else |
| 3379 | { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3380 | StreamString strm; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3381 | GetExpressionPath(strm, true); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3382 | |
| 3383 | if (is_pointer_type) |
| 3384 | error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str()); |
| 3385 | else |
| 3386 | 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] | 3387 | return ValueObjectSP(); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3388 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3389 | } |
| 3390 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3391 | ValueObjectSP |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3392 | ValueObject::AddressOf (Error &error) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3393 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 3394 | if (m_addr_of_valobj_sp) |
| 3395 | return m_addr_of_valobj_sp; |
| 3396 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 3397 | AddressType address_type = eAddressTypeInvalid; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3398 | const bool scalar_is_load_address = false; |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 3399 | addr_t addr = GetAddressOf (scalar_is_load_address, &address_type); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3400 | error.Clear(); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3401 | if (addr != LLDB_INVALID_ADDRESS) |
| 3402 | { |
| 3403 | switch (address_type) |
| 3404 | { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3405 | default: |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3406 | case eAddressTypeInvalid: |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3407 | { |
| 3408 | StreamString expr_path_strm; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3409 | GetExpressionPath(expr_path_strm, true); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3410 | error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str()); |
| 3411 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3412 | break; |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3413 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3414 | case eAddressTypeFile: |
| 3415 | case eAddressTypeLoad: |
| 3416 | case eAddressTypeHost: |
| 3417 | { |
| 3418 | clang::ASTContext *ast = GetClangAST(); |
| 3419 | clang_type_t clang_type = GetClangType(); |
| 3420 | if (ast && clang_type) |
| 3421 | { |
| 3422 | std::string name (1, '&'); |
| 3423 | name.append (m_name.AsCString("")); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 3424 | m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(), |
| 3425 | ast, |
| 3426 | ClangASTContext::CreatePointerType (ast, clang_type), |
| 3427 | ConstString (name.c_str()), |
| 3428 | addr, |
| 3429 | eAddressTypeInvalid, |
| 3430 | m_data.GetAddressByteSize()); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3431 | } |
| 3432 | } |
| 3433 | break; |
| 3434 | } |
| 3435 | } |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 3436 | return m_addr_of_valobj_sp; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3437 | } |
| 3438 | |
Greg Clayton | 9a142cf | 2012-02-03 05:34:10 +0000 | [diff] [blame] | 3439 | ValueObjectSP |
| 3440 | ValueObject::Cast (const ClangASTType &clang_ast_type) |
| 3441 | { |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 3442 | return ValueObjectCast::Create (*this, GetName(), clang_ast_type); |
Greg Clayton | 9a142cf | 2012-02-03 05:34:10 +0000 | [diff] [blame] | 3443 | } |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3444 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3445 | ValueObjectSP |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3446 | ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type) |
| 3447 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3448 | ValueObjectSP valobj_sp; |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3449 | AddressType address_type; |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 3450 | addr_t ptr_value = GetPointerValue (&address_type); |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3451 | |
| 3452 | if (ptr_value != LLDB_INVALID_ADDRESS) |
| 3453 | { |
| 3454 | Address ptr_addr (NULL, ptr_value); |
| 3455 | |
| 3456 | valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(), |
| 3457 | name, |
| 3458 | ptr_addr, |
| 3459 | clang_ast_type); |
| 3460 | } |
| 3461 | return valobj_sp; |
| 3462 | } |
| 3463 | |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3464 | ValueObjectSP |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3465 | ValueObject::CastPointerType (const char *name, TypeSP &type_sp) |
| 3466 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3467 | ValueObjectSP valobj_sp; |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3468 | AddressType address_type; |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 3469 | addr_t ptr_value = GetPointerValue (&address_type); |
Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3470 | |
| 3471 | if (ptr_value != LLDB_INVALID_ADDRESS) |
| 3472 | { |
| 3473 | Address ptr_addr (NULL, ptr_value); |
| 3474 | |
| 3475 | valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(), |
| 3476 | name, |
| 3477 | ptr_addr, |
| 3478 | type_sp); |
| 3479 | } |
| 3480 | return valobj_sp; |
| 3481 | } |
| 3482 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3483 | ValueObject::EvaluationPoint::EvaluationPoint () : |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 3484 | ExecutionContextScope(), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 3485 | m_thread_id (LLDB_INVALID_UID), |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3486 | m_mod_id () |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3487 | { |
| 3488 | } |
| 3489 | |
| 3490 | ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected): |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 3491 | ExecutionContextScope (), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3492 | m_needs_update (true), |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 3493 | m_first_update (true), |
Jim Ingham | 89b6109 | 2011-07-06 17:42:14 +0000 | [diff] [blame] | 3494 | m_thread_id (LLDB_INVALID_THREAD_ID), |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3495 | m_mod_id () |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 3496 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3497 | { |
| 3498 | ExecutionContext exe_ctx; |
Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 3499 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3500 | if (exe_scope) |
| 3501 | exe_scope->CalculateExecutionContext(exe_ctx); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 3502 | Target *target = exe_ctx.GetTargetPtr(); |
| 3503 | if (target != NULL) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3504 | { |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3505 | m_target_sp = target->shared_from_this(); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 3506 | m_process_sp = exe_ctx.GetProcessSP(); |
| 3507 | if (!m_process_sp) |
| 3508 | m_process_sp = target->GetProcessSP(); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3509 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 3510 | if (m_process_sp) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3511 | { |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3512 | m_mod_id = m_process_sp->GetModID(); |
| 3513 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 3514 | Thread *thread = exe_ctx.GetThreadPtr(); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3515 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 3516 | if (thread == NULL) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3517 | { |
| 3518 | if (use_selected) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3519 | thread = m_process_sp->GetThreadList().GetSelectedThread().get(); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3520 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3521 | |
| 3522 | if (thread != NULL) |
| 3523 | { |
| 3524 | m_thread_id = thread->GetIndexID(); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 3525 | |
| 3526 | StackFrame *frame = exe_ctx.GetFramePtr(); |
| 3527 | if (frame == NULL) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3528 | { |
| 3529 | if (use_selected) |
| 3530 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 3531 | frame = thread->GetSelectedFrame().get(); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3532 | if (frame) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3533 | m_stack_id = frame->GetStackID(); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3534 | } |
| 3535 | } |
| 3536 | else |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 3537 | m_stack_id = frame->GetStackID(); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3538 | } |
| 3539 | } |
| 3540 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3541 | } |
| 3542 | |
| 3543 | ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) : |
Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 3544 | m_needs_update(true), |
| 3545 | m_first_update(true), |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3546 | m_target_sp (rhs.m_target_sp), |
| 3547 | m_process_sp (rhs.m_process_sp), |
| 3548 | m_thread_id (rhs.m_thread_id), |
| 3549 | m_stack_id (rhs.m_stack_id), |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3550 | m_mod_id () |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3551 | { |
| 3552 | } |
| 3553 | |
| 3554 | ValueObject::EvaluationPoint::~EvaluationPoint () |
| 3555 | { |
| 3556 | } |
| 3557 | |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 3558 | Target * |
| 3559 | ValueObject::EvaluationPoint::CalculateTarget () |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3560 | { |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 3561 | return m_target_sp.get(); |
| 3562 | } |
| 3563 | |
| 3564 | Process * |
| 3565 | ValueObject::EvaluationPoint::CalculateProcess () |
| 3566 | { |
| 3567 | return m_process_sp.get(); |
| 3568 | } |
| 3569 | |
| 3570 | Thread * |
| 3571 | ValueObject::EvaluationPoint::CalculateThread () |
| 3572 | { |
| 3573 | ExecutionContextScope *exe_scope; |
Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 3574 | SyncWithProcessState(exe_scope); |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 3575 | if (exe_scope) |
| 3576 | return exe_scope->CalculateThread(); |
| 3577 | else |
| 3578 | return NULL; |
| 3579 | } |
| 3580 | |
| 3581 | StackFrame * |
| 3582 | ValueObject::EvaluationPoint::CalculateStackFrame () |
| 3583 | { |
| 3584 | ExecutionContextScope *exe_scope; |
| 3585 | SyncWithProcessState(exe_scope); |
| 3586 | if (exe_scope) |
| 3587 | return exe_scope->CalculateStackFrame(); |
| 3588 | else |
| 3589 | return NULL; |
| 3590 | } |
| 3591 | |
| 3592 | void |
| 3593 | ValueObject::EvaluationPoint::CalculateExecutionContext (ExecutionContext &exe_ctx) |
| 3594 | { |
| 3595 | ExecutionContextScope *exe_scope; |
| 3596 | SyncWithProcessState(exe_scope); |
| 3597 | if (exe_scope) |
| 3598 | return exe_scope->CalculateExecutionContext (exe_ctx); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3599 | } |
| 3600 | |
| 3601 | // This function checks the EvaluationPoint against the current process state. If the current |
| 3602 | // state matches the evaluation point, or the evaluation point is already invalid, then we return |
| 3603 | // false, meaning "no change". If the current state is different, we update our state, and return |
| 3604 | // true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so |
| 3605 | // future calls to NeedsUpdate will return true. |
Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 3606 | // exe_scope will be set to the current execution context scope. |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3607 | |
| 3608 | bool |
Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 3609 | ValueObject::EvaluationPoint::SyncWithProcessState(ExecutionContextScope *&exe_scope) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3610 | { |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 3611 | |
| 3612 | // Start with the target, if it is NULL, then we're obviously not going to get any further: |
| 3613 | exe_scope = m_target_sp.get(); |
| 3614 | |
| 3615 | if (exe_scope == NULL) |
| 3616 | return false; |
| 3617 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3618 | // If we don't have a process nothing can change. |
| 3619 | if (!m_process_sp) |
| 3620 | return false; |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 3621 | |
| 3622 | exe_scope = m_process_sp.get(); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3623 | |
| 3624 | // If our stop id is the current stop ID, nothing has changed: |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3625 | ProcessModID current_mod_id = m_process_sp->GetModID(); |
| 3626 | |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 3627 | // If the current stop id is 0, either we haven't run yet, or the process state has been cleared. |
| 3628 | // In either case, we aren't going to be able to sync with the process state. |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3629 | if (current_mod_id.GetStopID() == 0) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 3630 | return false; |
Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 3631 | |
| 3632 | bool changed; |
| 3633 | |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 3634 | if (m_mod_id.IsValid()) |
| 3635 | { |
| 3636 | if (m_mod_id == current_mod_id) |
| 3637 | { |
Jim Ingham | 5cfbe4a | 2012-01-12 22:42:34 +0000 | [diff] [blame] | 3638 | // Everything is already up to date in this object, no need to |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 3639 | // update the execution context scope. |
Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 3640 | changed = false; |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 3641 | } |
Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 3642 | else |
| 3643 | { |
| 3644 | m_mod_id = current_mod_id; |
| 3645 | m_needs_update = true; |
| 3646 | changed = true; |
| 3647 | } |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 3648 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3649 | |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 3650 | // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated. |
| 3651 | // That way we'll be sure to return a valid exe_scope. |
| 3652 | // If we used to have a thread or a frame but can't find it anymore, then mark ourselves as invalid. |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3653 | |
| 3654 | if (m_thread_id != LLDB_INVALID_THREAD_ID) |
| 3655 | { |
| 3656 | Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get(); |
| 3657 | if (our_thread == NULL) |
Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame] | 3658 | { |
Jim Ingham | 89b6109 | 2011-07-06 17:42:14 +0000 | [diff] [blame] | 3659 | SetInvalid(); |
Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame] | 3660 | } |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3661 | else |
| 3662 | { |
Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 3663 | exe_scope = our_thread; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3664 | |
| 3665 | if (m_stack_id.IsValid()) |
| 3666 | { |
| 3667 | StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get(); |
| 3668 | if (our_frame == NULL) |
| 3669 | SetInvalid(); |
| 3670 | else |
Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 3671 | exe_scope = our_frame; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3672 | } |
| 3673 | } |
| 3674 | } |
Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 3675 | return changed; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3676 | } |
| 3677 | |
Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 3678 | void |
| 3679 | ValueObject::EvaluationPoint::SetUpdated () |
| 3680 | { |
Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 3681 | if (m_process_sp) |
| 3682 | m_mod_id = m_process_sp->GetModID(); |
Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 3683 | m_first_update = false; |
| 3684 | m_needs_update = false; |
Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 3685 | } |
| 3686 | |
| 3687 | |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3688 | bool |
| 3689 | ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope) |
| 3690 | { |
| 3691 | if (!IsValid()) |
| 3692 | return false; |
| 3693 | |
| 3694 | bool needs_update = false; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3695 | |
| 3696 | // The target has to be non-null, and the |
| 3697 | Target *target = exe_scope->CalculateTarget(); |
| 3698 | if (target != NULL) |
| 3699 | { |
| 3700 | Target *old_target = m_target_sp.get(); |
| 3701 | assert (target == old_target); |
| 3702 | Process *process = exe_scope->CalculateProcess(); |
| 3703 | if (process != NULL) |
| 3704 | { |
| 3705 | // FOR NOW - assume you can't update variable objects across process boundaries. |
| 3706 | Process *old_process = m_process_sp.get(); |
| 3707 | assert (process == old_process); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3708 | ProcessModID current_mod_id = process->GetModID(); |
| 3709 | if (m_mod_id != current_mod_id) |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3710 | { |
| 3711 | needs_update = true; |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3712 | m_mod_id = current_mod_id; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3713 | } |
| 3714 | // See if we're switching the thread or stack context. If no thread is given, this is |
| 3715 | // being evaluated in a global context. |
| 3716 | Thread *thread = exe_scope->CalculateThread(); |
| 3717 | if (thread != NULL) |
| 3718 | { |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3719 | user_id_t new_thread_index = thread->GetIndexID(); |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3720 | if (new_thread_index != m_thread_id) |
| 3721 | { |
| 3722 | needs_update = true; |
| 3723 | m_thread_id = new_thread_index; |
| 3724 | m_stack_id.Clear(); |
| 3725 | } |
| 3726 | |
| 3727 | StackFrame *new_frame = exe_scope->CalculateStackFrame(); |
| 3728 | if (new_frame != NULL) |
| 3729 | { |
| 3730 | if (new_frame->GetStackID() != m_stack_id) |
| 3731 | { |
| 3732 | needs_update = true; |
| 3733 | m_stack_id = new_frame->GetStackID(); |
| 3734 | } |
| 3735 | } |
| 3736 | else |
| 3737 | { |
| 3738 | m_stack_id.Clear(); |
| 3739 | needs_update = true; |
| 3740 | } |
| 3741 | } |
| 3742 | else |
| 3743 | { |
| 3744 | // If this had been given a thread, and now there is none, we should update. |
| 3745 | // Otherwise we don't have to do anything. |
| 3746 | if (m_thread_id != LLDB_INVALID_UID) |
| 3747 | { |
| 3748 | m_thread_id = LLDB_INVALID_UID; |
| 3749 | m_stack_id.Clear(); |
| 3750 | needs_update = true; |
| 3751 | } |
| 3752 | } |
| 3753 | } |
| 3754 | else |
| 3755 | { |
| 3756 | // If there is no process, then we don't need to update anything. |
| 3757 | // But if we're switching from having a process to not, we should try to update. |
| 3758 | if (m_process_sp.get() != NULL) |
| 3759 | { |
| 3760 | needs_update = true; |
| 3761 | m_process_sp.reset(); |
| 3762 | m_thread_id = LLDB_INVALID_UID; |
| 3763 | m_stack_id.Clear(); |
| 3764 | } |
| 3765 | } |
| 3766 | } |
| 3767 | else |
| 3768 | { |
| 3769 | // If there's no target, nothing can change so we don't need to update anything. |
| 3770 | // But if we're switching from having a target to not, we should try to update. |
| 3771 | if (m_target_sp.get() != NULL) |
| 3772 | { |
| 3773 | needs_update = true; |
| 3774 | m_target_sp.reset(); |
| 3775 | m_process_sp.reset(); |
| 3776 | m_thread_id = LLDB_INVALID_UID; |
| 3777 | m_stack_id.Clear(); |
| 3778 | } |
| 3779 | } |
| 3780 | if (!m_needs_update) |
| 3781 | m_needs_update = needs_update; |
| 3782 | |
| 3783 | return needs_update; |
| 3784 | } |
Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 3785 | |
| 3786 | void |
| 3787 | ValueObject::ClearUserVisibleData() |
| 3788 | { |
| 3789 | m_location_str.clear(); |
| 3790 | m_value_str.clear(); |
| 3791 | m_summary_str.clear(); |
| 3792 | m_object_desc_str.clear(); |
Greg Clayton | 48ca8b8 | 2012-01-07 20:58:07 +0000 | [diff] [blame] | 3793 | m_is_getting_summary = false; |
Johnny Chen | 4480530 | 2011-07-19 19:48:13 +0000 | [diff] [blame] | 3794 | } |
Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 3795 | |
| 3796 | SymbolContextScope * |
| 3797 | ValueObject::GetSymbolContextScope() |
| 3798 | { |
| 3799 | if (m_parent) |
| 3800 | { |
| 3801 | if (!m_parent->IsPointerOrReferenceType()) |
| 3802 | return m_parent->GetSymbolContextScope(); |
| 3803 | } |
| 3804 | return NULL; |
| 3805 | } |