| 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" |
| 18 | |
| 19 | // Project includes |
| 20 | #include "lldb/Core/DataBufferHeap.h" |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Debugger.h" |
| Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 22 | #include "lldb/Core/Log.h" |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 23 | #include "lldb/Core/Module.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Core/StreamString.h" |
| Enrico Granata | 21fd13f | 2012-10-27 02:05:48 +0000 | [diff] [blame] | 25 | #include "lldb/Core/ValueObjectCast.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | |
| Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 33 | #include "lldb/DataFormatters/DataVisualization.h" |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 34 | #include "lldb/DataFormatters/StringPrinter.h" |
| Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 35 | #include "lldb/DataFormatters/ValueObjectPrinter.h" |
| Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 36 | |
| Sean Callanan | 30e3397 | 2015-09-03 00:48:23 +0000 | [diff] [blame] | 37 | #include "Plugins/ExpressionParser/Clang/ClangExpressionVariable.h" |
| Sean Callanan | 4dbb271 | 2015-09-25 20:35:58 +0000 | [diff] [blame] | 38 | #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h" |
| Enrico Granata | 0c10a85 | 2014-12-08 23:13:56 +0000 | [diff] [blame] | 39 | |
| Greg Clayton | 7fb56d0 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 40 | #include "lldb/Host/Endian.h" |
| 41 | |
| Enrico Granata | 61a80ba | 2011-08-12 16:42:31 +0000 | [diff] [blame] | 42 | #include "lldb/Interpreter/CommandInterpreter.h" |
| Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 43 | |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 44 | #include "lldb/Symbol/CompilerType.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | #include "lldb/Symbol/ClangASTContext.h" |
| Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 46 | #include "lldb/Symbol/CompileUnit.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | #include "lldb/Symbol/Type.h" |
| 48 | |
| Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 49 | #include "lldb/Target/ExecutionContext.h" |
| Enrico Granata | 407b5c6 | 2015-11-02 21:52:05 +0000 | [diff] [blame] | 50 | #include "lldb/Target/Language.h" |
| Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 51 | #include "lldb/Target/LanguageRuntime.h" |
| Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 52 | #include "lldb/Target/ObjCLanguageRuntime.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | #include "lldb/Target/Process.h" |
| 54 | #include "lldb/Target/RegisterContext.h" |
| Greg Clayton | d5944cd | 2013-12-06 01:12:00 +0000 | [diff] [blame] | 55 | #include "lldb/Target/SectionLoadList.h" |
| Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 56 | #include "lldb/Target/Target.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | #include "lldb/Target/Thread.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | |
| 59 | using namespace lldb; |
| 60 | using namespace lldb_private; |
| Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 61 | using namespace lldb_utility; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 63 | static user_id_t g_value_obj_uid = 0; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | |
| 65 | //---------------------------------------------------------------------- |
| 66 | // ValueObject constructor |
| 67 | //---------------------------------------------------------------------- |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 68 | ValueObject::ValueObject (ValueObject &parent) : |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | UserID (++g_value_obj_uid), // Unique identifier for every value object |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 70 | m_parent (&parent), |
| Enrico Granata | 4873e52 | 2013-04-11 22:48:58 +0000 | [diff] [blame] | 71 | m_root (NULL), |
| Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 72 | m_update_point (parent.GetUpdatePoint ()), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | m_name (), |
| 74 | m_data (), |
| 75 | m_value (), |
| 76 | m_error (), |
| Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 77 | m_value_str (), |
| 78 | m_old_value_str (), |
| 79 | m_location_str (), |
| 80 | m_summary_str (), |
| Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 81 | m_object_desc_str (), |
| Enrico Granata | 744794a | 2014-09-05 21:46:22 +0000 | [diff] [blame] | 82 | m_validation_result(), |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 83 | m_manager(parent.GetManager()), |
| Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 84 | m_children (), |
| 85 | m_synthetic_children (), |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 86 | m_dynamic_value (NULL), |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 87 | m_synthetic_value(NULL), |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 88 | m_deref_valobj(NULL), |
| Greg Clayton | 32c4085 | 2010-10-06 03:09:11 +0000 | [diff] [blame] | 89 | m_format (eFormatDefault), |
| Enrico Granata | b294fd2 | 2013-05-31 19:18:19 +0000 | [diff] [blame] | 90 | m_last_format (eFormatDefault), |
| Enrico Granata | 9df29e3 | 2011-07-19 20:57:44 +0000 | [diff] [blame] | 91 | m_last_format_mgr_revision(0), |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 92 | m_type_summary_sp(), |
| 93 | m_type_format_sp(), |
| 94 | m_synthetic_children_sp(), |
| Enrico Granata | 744794a | 2014-09-05 21:46:22 +0000 | [diff] [blame] | 95 | m_type_validator_sp(), |
| Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 96 | m_user_id_of_forced_summary(), |
| Daniel Dunbar | a08823f | 2011-10-31 22:50:49 +0000 | [diff] [blame] | 97 | m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid), |
| Sean Callanan | 7375f3e | 2014-12-09 21:18:59 +0000 | [diff] [blame] | 98 | m_value_checksum(), |
| Enrico Granata | ed3228a | 2015-01-21 01:47:13 +0000 | [diff] [blame] | 99 | m_preferred_display_language(lldb::eLanguageTypeUnknown), |
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 100 | m_language_flags(0), |
| Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 101 | m_value_is_valid (false), |
| 102 | m_value_did_change (false), |
| 103 | m_children_count_valid (false), |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 104 | m_old_value_valid (false), |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 105 | m_is_deref_of_parent (false), |
| Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 106 | m_is_array_item_for_pointer(false), |
| Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 107 | m_is_bitfield_for_scalar(false), |
| Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 108 | m_is_child_at_offset(false), |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 109 | m_is_getting_summary(false), |
| Enrico Granata | e29df23 | 2014-12-09 19:51:20 +0000 | [diff] [blame] | 110 | m_did_calculate_complete_objc_class_type(false), |
| 111 | m_is_synthetic_children_generated(parent.m_is_synthetic_children_generated) |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 112 | { |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 113 | m_manager->ManageObject(this); |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | //---------------------------------------------------------------------- |
| 117 | // ValueObject constructor |
| 118 | //---------------------------------------------------------------------- |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 119 | ValueObject::ValueObject (ExecutionContextScope *exe_scope, |
| 120 | AddressType child_ptr_or_ref_addr_type) : |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 121 | UserID (++g_value_obj_uid), // Unique identifier for every value object |
| 122 | m_parent (NULL), |
| Enrico Granata | 4873e52 | 2013-04-11 22:48:58 +0000 | [diff] [blame] | 123 | m_root (NULL), |
| Stephen Wilson | 71c21d1 | 2011-04-11 19:41:40 +0000 | [diff] [blame] | 124 | m_update_point (exe_scope), |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 125 | m_name (), |
| 126 | m_data (), |
| 127 | m_value (), |
| 128 | m_error (), |
| 129 | m_value_str (), |
| 130 | m_old_value_str (), |
| 131 | m_location_str (), |
| 132 | m_summary_str (), |
| 133 | m_object_desc_str (), |
| Enrico Granata | 744794a | 2014-09-05 21:46:22 +0000 | [diff] [blame] | 134 | m_validation_result(), |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 135 | m_manager(), |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 136 | m_children (), |
| 137 | m_synthetic_children (), |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 138 | m_dynamic_value (NULL), |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 139 | m_synthetic_value(NULL), |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 140 | m_deref_valobj(NULL), |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 141 | m_format (eFormatDefault), |
| Enrico Granata | b294fd2 | 2013-05-31 19:18:19 +0000 | [diff] [blame] | 142 | m_last_format (eFormatDefault), |
| Enrico Granata | 9df29e3 | 2011-07-19 20:57:44 +0000 | [diff] [blame] | 143 | m_last_format_mgr_revision(0), |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 144 | m_type_summary_sp(), |
| 145 | m_type_format_sp(), |
| 146 | m_synthetic_children_sp(), |
| Enrico Granata | 744794a | 2014-09-05 21:46:22 +0000 | [diff] [blame] | 147 | m_type_validator_sp(), |
| Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 148 | m_user_id_of_forced_summary(), |
| Daniel Dunbar | a08823f | 2011-10-31 22:50:49 +0000 | [diff] [blame] | 149 | m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type), |
| Sean Callanan | 7375f3e | 2014-12-09 21:18:59 +0000 | [diff] [blame] | 150 | m_value_checksum(), |
| Enrico Granata | ed3228a | 2015-01-21 01:47:13 +0000 | [diff] [blame] | 151 | m_preferred_display_language(lldb::eLanguageTypeUnknown), |
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 152 | m_language_flags(0), |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 153 | m_value_is_valid (false), |
| 154 | m_value_did_change (false), |
| 155 | m_children_count_valid (false), |
| 156 | m_old_value_valid (false), |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 157 | m_is_deref_of_parent (false), |
| Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 158 | m_is_array_item_for_pointer(false), |
| Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 159 | m_is_bitfield_for_scalar(false), |
| Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 160 | m_is_child_at_offset(false), |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 161 | m_is_getting_summary(false), |
| Enrico Granata | e29df23 | 2014-12-09 19:51:20 +0000 | [diff] [blame] | 162 | m_did_calculate_complete_objc_class_type(false), |
| 163 | m_is_synthetic_children_generated(false) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 164 | { |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 165 | m_manager = new ValueObjectManager(); |
| 166 | m_manager->ManageObject (this); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | //---------------------------------------------------------------------- |
| 170 | // Destructor |
| 171 | //---------------------------------------------------------------------- |
| 172 | ValueObject::~ValueObject () |
| 173 | { |
| 174 | } |
| 175 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 176 | bool |
| Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 177 | ValueObject::UpdateValueIfNeeded (bool update_format) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 178 | { |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 179 | |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 180 | bool did_change_formats = false; |
| 181 | |
| Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 182 | if (update_format) |
| Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 183 | did_change_formats = UpdateFormatsIfNeeded(); |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 184 | |
| Greg Clayton | b71f384 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 185 | // If this is a constant value, then our success is predicated on whether |
| 186 | // we have an error or not |
| 187 | if (GetIsConstant()) |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 188 | { |
| Enrico Granata | b1c6c48 | 2013-10-09 00:33:55 +0000 | [diff] [blame] | 189 | // if you are constant, things might still have changed behind your back |
| 190 | // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself) |
| 191 | // in this case, your value has not changed, but "computed" entries might have, so you might now have |
| 192 | // a different summary, or a different object description. clear these so we will recompute them |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 193 | if (update_format && !did_change_formats) |
| Enrico Granata | b1c6c48 | 2013-10-09 00:33:55 +0000 | [diff] [blame] | 194 | ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription); |
| Greg Clayton | b71f384 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 195 | return m_error.Success(); |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 196 | } |
| Greg Clayton | b71f384 | 2010-10-05 03:13:51 +0000 | [diff] [blame] | 197 | |
| Sean Callanan | 7375f3e | 2014-12-09 21:18:59 +0000 | [diff] [blame] | 198 | bool first_update = IsChecksumEmpty(); |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 199 | |
| Enrico Granata | bb642e5 | 2015-05-16 01:27:00 +0000 | [diff] [blame] | 200 | if (NeedsUpdating()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 201 | { |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 202 | m_update_point.SetUpdated(); |
| 203 | |
| 204 | // Save the old value using swap to avoid a string copy which |
| 205 | // also will clear our m_value_str |
| 206 | if (m_value_str.empty()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 207 | { |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 208 | m_old_value_valid = false; |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | m_old_value_valid = true; |
| 213 | m_old_value_str.swap (m_value_str); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 214 | ClearUserVisibleData(eClearUserVisibleDataItemsValue); |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 215 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 216 | |
| Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 217 | ClearUserVisibleData(); |
| 218 | |
| Greg Clayton | efbc7d2 | 2012-03-09 04:23:44 +0000 | [diff] [blame] | 219 | if (IsInScope()) |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 220 | { |
| Greg Clayton | efbc7d2 | 2012-03-09 04:23:44 +0000 | [diff] [blame] | 221 | const bool value_was_valid = GetValueIsValid(); |
| 222 | SetValueDidChange (false); |
| 223 | |
| 224 | m_error.Clear(); |
| 225 | |
| 226 | // Call the pure virtual function to update the value |
| Sean Callanan | 7375f3e | 2014-12-09 21:18:59 +0000 | [diff] [blame] | 227 | |
| 228 | bool need_compare_checksums = false; |
| 229 | llvm::SmallVector<uint8_t, 16> old_checksum; |
| 230 | |
| 231 | if (!first_update && CanProvideValue()) |
| 232 | { |
| 233 | need_compare_checksums = true; |
| 234 | old_checksum.resize(m_value_checksum.size()); |
| 235 | std::copy(m_value_checksum.begin(), m_value_checksum.end(), old_checksum.begin()); |
| 236 | } |
| 237 | |
| Greg Clayton | efbc7d2 | 2012-03-09 04:23:44 +0000 | [diff] [blame] | 238 | bool success = UpdateValue (); |
| 239 | |
| 240 | SetValueIsValid (success); |
| 241 | |
| Sean Callanan | 7375f3e | 2014-12-09 21:18:59 +0000 | [diff] [blame] | 242 | if (success) |
| 243 | { |
| 244 | const uint64_t max_checksum_size = 128; |
| 245 | m_data.Checksum(m_value_checksum, |
| 246 | max_checksum_size); |
| 247 | } |
| 248 | else |
| 249 | { |
| 250 | need_compare_checksums = false; |
| 251 | m_value_checksum.clear(); |
| 252 | } |
| 253 | |
| Enrico Granata | 20c321c | 2015-01-08 19:11:43 +0000 | [diff] [blame] | 254 | assert (!need_compare_checksums || (!old_checksum.empty() && !m_value_checksum.empty())); |
| 255 | |
| Greg Clayton | efbc7d2 | 2012-03-09 04:23:44 +0000 | [diff] [blame] | 256 | if (first_update) |
| 257 | SetValueDidChange (false); |
| 258 | else if (!m_value_did_change && success == false) |
| 259 | { |
| 260 | // The value wasn't gotten successfully, so we mark this |
| 261 | // as changed if the value used to be valid and now isn't |
| 262 | SetValueDidChange (value_was_valid); |
| 263 | } |
| Sean Callanan | 7375f3e | 2014-12-09 21:18:59 +0000 | [diff] [blame] | 264 | else if (need_compare_checksums) |
| 265 | { |
| 266 | SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], m_value_checksum.size())); |
| 267 | } |
| 268 | |
| Greg Clayton | efbc7d2 | 2012-03-09 04:23:44 +0000 | [diff] [blame] | 269 | } |
| 270 | else |
| 271 | { |
| 272 | m_error.SetErrorString("out of scope"); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 273 | } |
| 274 | } |
| 275 | return m_error.Success(); |
| 276 | } |
| 277 | |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 278 | bool |
| Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 279 | ValueObject::UpdateFormatsIfNeeded() |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 280 | { |
| Enrico Granata | 4edfef4 | 2015-10-06 17:55:14 +0000 | [diff] [blame] | 281 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS)); |
| Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 282 | if (log) |
| Enrico Granata | d228483 | 2012-10-17 22:23:56 +0000 | [diff] [blame] | 283 | log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d", |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 284 | GetName().GetCString(), static_cast<void*>(this), |
| 285 | m_last_format_mgr_revision, |
| 286 | DataVisualization::GetCurrentRevision()); |
| 287 | |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 288 | bool any_change = false; |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 289 | |
| Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 290 | if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision())) |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 291 | { |
| Enrico Granata | a0db6ed | 2014-04-09 21:06:11 +0000 | [diff] [blame] | 292 | m_last_format_mgr_revision = DataVisualization::GetCurrentRevision(); |
| 293 | any_change = true; |
| 294 | |
| Enrico Granata | 852cc95 | 2013-10-08 19:03:22 +0000 | [diff] [blame] | 295 | SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues)); |
| Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 296 | SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType())); |
| Jason Molenda | 7a9a72b | 2012-05-16 00:38:08 +0000 | [diff] [blame] | 297 | #ifndef LLDB_DISABLE_PYTHON |
| Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 298 | SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType())); |
| Jason Molenda | 7a9a72b | 2012-05-16 00:38:08 +0000 | [diff] [blame] | 299 | #endif |
| Enrico Granata | 744794a | 2014-09-05 21:46:22 +0000 | [diff] [blame] | 300 | SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType())); |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 301 | } |
| Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 302 | |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 303 | return any_change; |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 306 | void |
| 307 | ValueObject::SetNeedsUpdate () |
| 308 | { |
| 309 | m_update_point.SetNeedsUpdate(); |
| 310 | // We have to clear the value string here so ConstResult children will notice if their values are |
| 311 | // changed by hand (i.e. with SetValueAsCString). |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 312 | ClearUserVisibleData(eClearUserVisibleDataItemsValue); |
| Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| Enrico Granata | 13ac0e2 | 2012-10-17 19:03:34 +0000 | [diff] [blame] | 315 | void |
| Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 316 | ValueObject::ClearDynamicTypeInformation () |
| Enrico Granata | 13ac0e2 | 2012-10-17 19:03:34 +0000 | [diff] [blame] | 317 | { |
| Enrico Granata | 38c5463 | 2013-10-30 00:04:29 +0000 | [diff] [blame] | 318 | m_children_count_valid = false; |
| Enrico Granata | 13ac0e2 | 2012-10-17 19:03:34 +0000 | [diff] [blame] | 319 | m_did_calculate_complete_objc_class_type = false; |
| Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 320 | m_last_format_mgr_revision = 0; |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 321 | m_override_type = CompilerType(); |
| Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 322 | SetValueFormat(lldb::TypeFormatImplSP()); |
| 323 | SetSummaryFormat(lldb::TypeSummaryImplSP()); |
| 324 | SetSyntheticChildren(lldb::SyntheticChildrenSP()); |
| Enrico Granata | 13ac0e2 | 2012-10-17 19:03:34 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 327 | CompilerType |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 328 | ValueObject::MaybeCalculateCompleteType () |
| 329 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 330 | CompilerType compiler_type(GetCompilerTypeImpl()); |
| Sean Callanan | 356e17c | 2012-03-30 02:04:38 +0000 | [diff] [blame] | 331 | |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 332 | if (m_did_calculate_complete_objc_class_type) |
| 333 | { |
| 334 | if (m_override_type.IsValid()) |
| 335 | return m_override_type; |
| 336 | else |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 337 | return compiler_type; |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 340 | CompilerType class_type; |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 341 | bool is_pointer_type = false; |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 342 | |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 343 | if (ClangASTContext::IsObjCObjectPointerType(compiler_type, &class_type)) |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 344 | { |
| 345 | is_pointer_type = true; |
| 346 | } |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 347 | else if (ClangASTContext::IsObjCObjectOrInterfaceType(compiler_type)) |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 348 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 349 | class_type = compiler_type; |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 350 | } |
| 351 | else |
| 352 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 353 | return compiler_type; |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | m_did_calculate_complete_objc_class_type = true; |
| 357 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 358 | if (class_type) |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 359 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 360 | ConstString class_name (class_type.GetConstTypeName()); |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 361 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 362 | if (class_name) |
| 363 | { |
| 364 | ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP()); |
| 365 | |
| 366 | if (process_sp) |
| 367 | { |
| 368 | ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime()); |
| 369 | |
| 370 | if (objc_language_runtime) |
| 371 | { |
| 372 | TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name); |
| 373 | |
| 374 | if (complete_objc_class_type_sp) |
| 375 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 376 | CompilerType complete_class(complete_objc_class_type_sp->GetFullCompilerType ()); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 377 | |
| 378 | if (complete_class.GetCompleteType()) |
| 379 | { |
| 380 | if (is_pointer_type) |
| 381 | { |
| 382 | m_override_type = complete_class.GetPointerType(); |
| 383 | } |
| 384 | else |
| 385 | { |
| 386 | m_override_type = complete_class; |
| 387 | } |
| 388 | |
| 389 | if (m_override_type.IsValid()) |
| 390 | return m_override_type; |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | } |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 396 | } |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 397 | return compiler_type; |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 400 | CompilerType |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 401 | ValueObject::GetCompilerType () |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 402 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 403 | return MaybeCalculateCompleteType(); |
| Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 406 | TypeImpl |
| 407 | ValueObject::GetTypeImpl () |
| 408 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 409 | return TypeImpl(GetCompilerType()); |
| Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 412 | DataExtractor & |
| 413 | ValueObject::GetDataExtractor () |
| 414 | { |
| Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 415 | UpdateValueIfNeeded(false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 416 | return m_data; |
| 417 | } |
| 418 | |
| 419 | const Error & |
| Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame] | 420 | ValueObject::GetError() |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 421 | { |
| Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 422 | UpdateValueIfNeeded(false); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 423 | return m_error; |
| 424 | } |
| 425 | |
| 426 | const ConstString & |
| 427 | ValueObject::GetName() const |
| 428 | { |
| 429 | return m_name; |
| 430 | } |
| 431 | |
| 432 | const char * |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 433 | ValueObject::GetLocationAsCString () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 434 | { |
| Enrico Granata | 82fabf8 | 2013-04-30 20:45:04 +0000 | [diff] [blame] | 435 | return GetLocationAsCStringImpl(m_value, |
| 436 | m_data); |
| 437 | } |
| 438 | |
| 439 | const char * |
| 440 | ValueObject::GetLocationAsCStringImpl (const Value& value, |
| 441 | const DataExtractor& data) |
| 442 | { |
| Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 443 | if (UpdateValueIfNeeded(false)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 444 | { |
| 445 | if (m_location_str.empty()) |
| 446 | { |
| 447 | StreamString sstr; |
| Enrico Granata | 82fabf8 | 2013-04-30 20:45:04 +0000 | [diff] [blame] | 448 | |
| 449 | Value::ValueType value_type = value.GetValueType(); |
| 450 | |
| 451 | switch (value_type) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 452 | { |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 453 | case Value::eValueTypeScalar: |
| Greg Clayton | 0665a0f | 2012-10-30 18:18:43 +0000 | [diff] [blame] | 454 | case Value::eValueTypeVector: |
| Enrico Granata | 82fabf8 | 2013-04-30 20:45:04 +0000 | [diff] [blame] | 455 | if (value.GetContextType() == Value::eContextTypeRegisterInfo) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 456 | { |
| Enrico Granata | 82fabf8 | 2013-04-30 20:45:04 +0000 | [diff] [blame] | 457 | RegisterInfo *reg_info = value.GetRegisterInfo(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 458 | if (reg_info) |
| 459 | { |
| 460 | if (reg_info->name) |
| 461 | m_location_str = reg_info->name; |
| 462 | else if (reg_info->alt_name) |
| 463 | m_location_str = reg_info->alt_name; |
| Enrico Granata | 82fabf8 | 2013-04-30 20:45:04 +0000 | [diff] [blame] | 464 | if (m_location_str.empty()) |
| 465 | m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar"; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 466 | } |
| 467 | } |
| Enrico Granata | 82fabf8 | 2013-04-30 20:45:04 +0000 | [diff] [blame] | 468 | if (m_location_str.empty()) |
| 469 | m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar"; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 470 | break; |
| 471 | |
| 472 | case Value::eValueTypeLoadAddress: |
| 473 | case Value::eValueTypeFileAddress: |
| 474 | case Value::eValueTypeHostAddress: |
| 475 | { |
| Enrico Granata | 82fabf8 | 2013-04-30 20:45:04 +0000 | [diff] [blame] | 476 | uint32_t addr_nibble_size = data.GetAddressByteSize() * 2; |
| 477 | sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS)); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 478 | m_location_str.swap(sstr.GetString()); |
| 479 | } |
| 480 | break; |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | return m_location_str.c_str(); |
| 485 | } |
| 486 | |
| 487 | Value & |
| 488 | ValueObject::GetValue() |
| 489 | { |
| 490 | return m_value; |
| 491 | } |
| 492 | |
| 493 | const Value & |
| 494 | ValueObject::GetValue() const |
| 495 | { |
| 496 | return m_value; |
| 497 | } |
| 498 | |
| 499 | bool |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 500 | ValueObject::ResolveValue (Scalar &scalar) |
| Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 501 | { |
| Enrico Granata | 6fd87d5 | 2011-08-04 01:41:02 +0000 | [diff] [blame] | 502 | if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything |
| 503 | { |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 504 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 505 | Value tmp_value(m_value); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 506 | scalar = tmp_value.ResolveValue(&exe_ctx); |
| Greg Clayton | dcad502 | 2011-12-29 01:26:56 +0000 | [diff] [blame] | 507 | if (scalar.IsValid()) |
| 508 | { |
| 509 | const uint32_t bitfield_bit_size = GetBitfieldBitSize(); |
| 510 | if (bitfield_bit_size) |
| 511 | return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset()); |
| 512 | return true; |
| 513 | } |
| Enrico Granata | 6fd87d5 | 2011-08-04 01:41:02 +0000 | [diff] [blame] | 514 | } |
| Greg Clayton | dcad502 | 2011-12-29 01:26:56 +0000 | [diff] [blame] | 515 | return false; |
| Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | bool |
| Jim Ingham | 98e6daf | 2015-10-31 00:02:18 +0000 | [diff] [blame] | 519 | ValueObject::IsLogicalTrue (Error& error) |
| 520 | { |
| Enrico Granata | 407b5c6 | 2015-11-02 21:52:05 +0000 | [diff] [blame] | 521 | if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage())) |
| 522 | { |
| 523 | LazyBool is_logical_true = language->IsLogicalTrue(*this, error); |
| 524 | switch (is_logical_true) |
| 525 | { |
| 526 | case eLazyBoolYes: |
| 527 | case eLazyBoolNo: |
| 528 | return (is_logical_true == true); |
| 529 | case eLazyBoolCalculate: |
| Enrico Granata | 407b5c6 | 2015-11-02 21:52:05 +0000 | [diff] [blame] | 530 | break; |
| 531 | } |
| 532 | } |
| 533 | |
| Jim Ingham | 98e6daf | 2015-10-31 00:02:18 +0000 | [diff] [blame] | 534 | Scalar scalar_value; |
| 535 | |
| 536 | if (!ResolveValue (scalar_value)) |
| 537 | { |
| 538 | error.SetErrorString("failed to get a scalar result"); |
| 539 | return false; |
| 540 | } |
| 541 | |
| 542 | bool ret; |
| 543 | if (scalar_value.ULongLong(1) == 0) |
| 544 | ret = false; |
| 545 | else |
| 546 | ret = true; |
| 547 | error.Clear(); |
| 548 | return ret; |
| 549 | } |
| 550 | |
| 551 | bool |
| Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 552 | ValueObject::GetValueIsValid () const |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 553 | { |
| Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 554 | return m_value_is_valid; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | |
| 558 | void |
| 559 | ValueObject::SetValueIsValid (bool b) |
| 560 | { |
| Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 561 | m_value_is_valid = b; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | bool |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 565 | ValueObject::GetValueDidChange () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 566 | { |
| Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 567 | return m_value_did_change; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | void |
| 571 | ValueObject::SetValueDidChange (bool value_changed) |
| 572 | { |
| Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 573 | m_value_did_change = value_changed; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | ValueObjectSP |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 577 | ValueObject::GetChildAtIndex (size_t idx, bool can_create) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 578 | { |
| 579 | ValueObjectSP child_sp; |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 580 | // We may need to update our value if we are dynamic |
| 581 | if (IsPossibleDynamicType ()) |
| Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 582 | UpdateValueIfNeeded(false); |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 583 | if (idx < GetNumChildren()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 584 | { |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 585 | // Check if we have already made the child value object? |
| Enrico Granata | 9d60f60 | 2012-03-09 03:09:58 +0000 | [diff] [blame] | 586 | if (can_create && !m_children.HasChildAtIndex(idx)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 587 | { |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 588 | // No we haven't created the child at this index, so lets have our |
| 589 | // subclass do it and cache the result for quick future access. |
| Enrico Granata | 9d60f60 | 2012-03-09 03:09:58 +0000 | [diff] [blame] | 590 | m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0)); |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 591 | } |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 592 | |
| Enrico Granata | 9d60f60 | 2012-03-09 03:09:58 +0000 | [diff] [blame] | 593 | ValueObject* child = m_children.GetChildAtIndex(idx); |
| 594 | if (child != NULL) |
| 595 | return child->GetSP(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 596 | } |
| 597 | return child_sp; |
| 598 | } |
| 599 | |
| Enrico Granata | 3309d88 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 600 | ValueObjectSP |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 601 | ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs, |
| 602 | size_t* index_of_error) |
| Enrico Granata | 3309d88 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 603 | { |
| 604 | if (idxs.size() == 0) |
| 605 | return GetSP(); |
| 606 | ValueObjectSP root(GetSP()); |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 607 | for (size_t idx : idxs) |
| Enrico Granata | 3309d88 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 608 | { |
| 609 | root = root->GetChildAtIndex(idx, true); |
| 610 | if (!root) |
| 611 | { |
| 612 | if (index_of_error) |
| 613 | *index_of_error = idx; |
| 614 | return root; |
| 615 | } |
| 616 | } |
| 617 | return root; |
| 618 | } |
| 619 | |
| 620 | ValueObjectSP |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 621 | ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs, |
| 622 | size_t* index_of_error) |
| Enrico Granata | 3309d88 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 623 | { |
| 624 | if (idxs.size() == 0) |
| 625 | return GetSP(); |
| 626 | ValueObjectSP root(GetSP()); |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 627 | for (std::pair<size_t, bool> idx : idxs) |
| Enrico Granata | 3309d88 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 628 | { |
| 629 | root = root->GetChildAtIndex(idx.first, idx.second); |
| 630 | if (!root) |
| 631 | { |
| 632 | if (index_of_error) |
| 633 | *index_of_error = idx.first; |
| 634 | return root; |
| 635 | } |
| 636 | } |
| 637 | return root; |
| 638 | } |
| 639 | |
| 640 | lldb::ValueObjectSP |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 641 | ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs, |
| 642 | size_t* index_of_error) |
| Enrico Granata | 3309d88 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 643 | { |
| 644 | if (idxs.size() == 0) |
| 645 | return GetSP(); |
| 646 | ValueObjectSP root(GetSP()); |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 647 | for (size_t idx : idxs) |
| Enrico Granata | 3309d88 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 648 | { |
| 649 | root = root->GetChildAtIndex(idx, true); |
| 650 | if (!root) |
| 651 | { |
| 652 | if (index_of_error) |
| 653 | *index_of_error = idx; |
| 654 | return root; |
| 655 | } |
| 656 | } |
| 657 | return root; |
| 658 | } |
| 659 | |
| 660 | lldb::ValueObjectSP |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 661 | ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs, |
| 662 | size_t* index_of_error) |
| Enrico Granata | 3309d88 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 663 | { |
| 664 | if (idxs.size() == 0) |
| 665 | return GetSP(); |
| 666 | ValueObjectSP root(GetSP()); |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 667 | for (std::pair<size_t, bool> idx : idxs) |
| Enrico Granata | 3309d88 | 2013-01-12 01:00:22 +0000 | [diff] [blame] | 668 | { |
| 669 | root = root->GetChildAtIndex(idx.first, idx.second); |
| 670 | if (!root) |
| 671 | { |
| 672 | if (index_of_error) |
| 673 | *index_of_error = idx.first; |
| 674 | return root; |
| 675 | } |
| 676 | } |
| 677 | return root; |
| 678 | } |
| 679 | |
| Enrico Granata | e2e220a | 2013-09-12 00:48:47 +0000 | [diff] [blame] | 680 | lldb::ValueObjectSP |
| 681 | ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names, |
| 682 | ConstString* name_of_error) |
| 683 | { |
| 684 | if (names.size() == 0) |
| 685 | return GetSP(); |
| 686 | ValueObjectSP root(GetSP()); |
| 687 | for (ConstString name : names) |
| 688 | { |
| 689 | root = root->GetChildMemberWithName(name, true); |
| 690 | if (!root) |
| 691 | { |
| 692 | if (name_of_error) |
| 693 | *name_of_error = name; |
| 694 | return root; |
| 695 | } |
| 696 | } |
| 697 | return root; |
| 698 | } |
| 699 | |
| 700 | lldb::ValueObjectSP |
| 701 | ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names, |
| 702 | ConstString* name_of_error) |
| 703 | { |
| 704 | if (names.size() == 0) |
| 705 | return GetSP(); |
| 706 | ValueObjectSP root(GetSP()); |
| 707 | for (ConstString name : names) |
| 708 | { |
| 709 | root = root->GetChildMemberWithName(name, true); |
| 710 | if (!root) |
| 711 | { |
| 712 | if (name_of_error) |
| 713 | *name_of_error = name; |
| 714 | return root; |
| 715 | } |
| 716 | } |
| 717 | return root; |
| 718 | } |
| 719 | |
| 720 | lldb::ValueObjectSP |
| 721 | ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names, |
| 722 | ConstString* name_of_error) |
| 723 | { |
| 724 | if (names.size() == 0) |
| 725 | return GetSP(); |
| 726 | ValueObjectSP root(GetSP()); |
| 727 | for (std::pair<ConstString, bool> name : names) |
| 728 | { |
| 729 | root = root->GetChildMemberWithName(name.first, name.second); |
| 730 | if (!root) |
| 731 | { |
| 732 | if (name_of_error) |
| 733 | *name_of_error = name.first; |
| 734 | return root; |
| 735 | } |
| 736 | } |
| 737 | return root; |
| 738 | } |
| 739 | |
| 740 | lldb::ValueObjectSP |
| 741 | ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names, |
| 742 | ConstString* name_of_error) |
| 743 | { |
| 744 | if (names.size() == 0) |
| 745 | return GetSP(); |
| 746 | ValueObjectSP root(GetSP()); |
| 747 | for (std::pair<ConstString, bool> name : names) |
| 748 | { |
| 749 | root = root->GetChildMemberWithName(name.first, name.second); |
| 750 | if (!root) |
| 751 | { |
| 752 | if (name_of_error) |
| 753 | *name_of_error = name.first; |
| 754 | return root; |
| 755 | } |
| 756 | } |
| 757 | return root; |
| 758 | } |
| 759 | |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 760 | size_t |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 761 | ValueObject::GetIndexOfChildWithName (const ConstString &name) |
| 762 | { |
| 763 | bool omit_empty_base_classes = true; |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 764 | return GetCompilerType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | ValueObjectSP |
| 768 | ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create) |
| 769 | { |
| Greg Clayton | 710dd5a | 2011-01-08 20:28:42 +0000 | [diff] [blame] | 770 | // 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] | 771 | // classes (which really aren't part of the expression path), so we |
| 772 | // 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] | 773 | ValueObjectSP child_sp; |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 774 | |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 775 | // We may need to update our value if we are dynamic |
| 776 | if (IsPossibleDynamicType ()) |
| Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 777 | UpdateValueIfNeeded(false); |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 778 | |
| 779 | std::vector<uint32_t> child_indexes; |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 780 | bool omit_empty_base_classes = true; |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 781 | const size_t num_child_indexes = GetCompilerType().GetIndexOfChildMemberWithName (name.GetCString(), |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 782 | omit_empty_base_classes, |
| 783 | child_indexes); |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 784 | if (num_child_indexes > 0) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 785 | { |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 786 | std::vector<uint32_t>::const_iterator pos = child_indexes.begin (); |
| 787 | std::vector<uint32_t>::const_iterator end = child_indexes.end (); |
| 788 | |
| 789 | child_sp = GetChildAtIndex(*pos, can_create); |
| 790 | for (++pos; pos != end; ++pos) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 791 | { |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 792 | if (child_sp) |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 793 | { |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 794 | ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create)); |
| 795 | child_sp = new_child_sp; |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 796 | } |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 797 | else |
| 798 | { |
| 799 | child_sp.reset(); |
| 800 | } |
| 801 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | return child_sp; |
| 805 | } |
| 806 | |
| 807 | |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 808 | size_t |
| Siva Chandra | 9ac7a6c | 2015-10-21 19:28:08 +0000 | [diff] [blame] | 809 | ValueObject::GetNumChildren (uint32_t max) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 810 | { |
| Enrico Granata | c5bc412 | 2012-03-27 02:35:13 +0000 | [diff] [blame] | 811 | UpdateValueIfNeeded(); |
| Siva Chandra | 9ac7a6c | 2015-10-21 19:28:08 +0000 | [diff] [blame] | 812 | |
| 813 | if (max < UINT32_MAX) |
| 814 | { |
| 815 | if (m_children_count_valid) |
| 816 | { |
| 817 | size_t children_count = m_children.GetChildrenCount(); |
| 818 | return children_count <= max ? children_count : max; |
| 819 | } |
| 820 | else |
| 821 | return CalculateNumChildren(max); |
| 822 | } |
| 823 | |
| Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 824 | if (!m_children_count_valid) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 825 | { |
| 826 | SetNumChildren (CalculateNumChildren()); |
| 827 | } |
| Enrico Granata | 9d60f60 | 2012-03-09 03:09:58 +0000 | [diff] [blame] | 828 | return m_children.GetChildrenCount(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 829 | } |
| Greg Clayton | 4a79207 | 2012-10-23 01:50:10 +0000 | [diff] [blame] | 830 | |
| 831 | bool |
| 832 | ValueObject::MightHaveChildren() |
| 833 | { |
| Enrico Granata | db8142b | 2012-10-23 02:07:54 +0000 | [diff] [blame] | 834 | bool has_children = false; |
| Greg Clayton | 2452ab7 | 2013-02-08 22:02:02 +0000 | [diff] [blame] | 835 | const uint32_t type_info = GetTypeInfo(); |
| 836 | if (type_info) |
| Greg Clayton | 4a79207 | 2012-10-23 01:50:10 +0000 | [diff] [blame] | 837 | { |
| Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 838 | if (type_info & (eTypeHasChildren | |
| 839 | eTypeIsPointer | |
| 840 | eTypeIsReference)) |
| Greg Clayton | 4a79207 | 2012-10-23 01:50:10 +0000 | [diff] [blame] | 841 | has_children = true; |
| 842 | } |
| 843 | else |
| 844 | { |
| 845 | has_children = GetNumChildren () > 0; |
| 846 | } |
| 847 | return has_children; |
| 848 | } |
| 849 | |
| 850 | // Should only be called by ValueObject::GetNumChildren() |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 851 | void |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 852 | ValueObject::SetNumChildren (size_t num_children) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 853 | { |
| Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 854 | m_children_count_valid = true; |
| Enrico Granata | 9d60f60 | 2012-03-09 03:09:58 +0000 | [diff] [blame] | 855 | m_children.SetChildrenCount(num_children); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | void |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 859 | ValueObject::SetName (const ConstString &name) |
| 860 | { |
| 861 | m_name = name; |
| 862 | } |
| 863 | |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 864 | ValueObject * |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 865 | ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 866 | { |
| Jim Ingham | 2eec487 | 2011-05-07 00:10:58 +0000 | [diff] [blame] | 867 | ValueObject *valobj = NULL; |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 868 | |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 869 | bool omit_empty_base_classes = true; |
| Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 870 | bool ignore_array_bounds = synthetic_array_member; |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 871 | std::string child_name_str; |
| 872 | uint32_t child_byte_size = 0; |
| 873 | int32_t child_byte_offset = 0; |
| 874 | uint32_t child_bitfield_bit_size = 0; |
| 875 | uint32_t child_bitfield_bit_offset = 0; |
| 876 | bool child_is_base_class = false; |
| 877 | bool child_is_deref_of_parent = false; |
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 878 | uint64_t language_flags = 0; |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 879 | |
| 880 | const bool transparent_pointers = synthetic_array_member == false; |
| Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 881 | CompilerType child_compiler_type; |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 882 | |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 883 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 884 | |
| Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 885 | child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex (&exe_ctx, |
| 886 | idx, |
| 887 | transparent_pointers, |
| 888 | omit_empty_base_classes, |
| 889 | ignore_array_bounds, |
| 890 | child_name_str, |
| 891 | child_byte_size, |
| 892 | child_byte_offset, |
| 893 | child_bitfield_bit_size, |
| 894 | child_bitfield_bit_offset, |
| 895 | child_is_base_class, |
| 896 | child_is_deref_of_parent, |
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 897 | this, |
| 898 | language_flags); |
| Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 899 | if (child_compiler_type) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 900 | { |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 901 | if (synthetic_index) |
| 902 | child_byte_offset += child_byte_size * synthetic_index; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 903 | |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 904 | ConstString child_name; |
| 905 | if (!child_name_str.empty()) |
| 906 | child_name.SetCString (child_name_str.c_str()); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 907 | |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 908 | valobj = new ValueObjectChild (*this, |
| Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 909 | child_compiler_type, |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 910 | child_name, |
| 911 | child_byte_size, |
| 912 | child_byte_offset, |
| 913 | child_bitfield_bit_size, |
| 914 | child_bitfield_bit_offset, |
| 915 | child_is_base_class, |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 916 | child_is_deref_of_parent, |
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 917 | eAddressTypeInvalid, |
| 918 | language_flags); |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 919 | //if (valobj) |
| 920 | // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid); |
| 921 | } |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 922 | |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 923 | return valobj; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 924 | } |
| 925 | |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 926 | bool |
| 927 | ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr, |
| Enrico Granata | 31fda93 | 2015-10-07 01:41:23 +0000 | [diff] [blame] | 928 | std::string& destination, |
| 929 | lldb::LanguageType lang) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 930 | { |
| Enrico Granata | 31fda93 | 2015-10-07 01:41:23 +0000 | [diff] [blame] | 931 | return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions().SetLanguage(lang)); |
| Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | bool |
| 935 | ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr, |
| 936 | std::string& destination, |
| 937 | const TypeSummaryOptions& options) |
| 938 | { |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 939 | destination.clear(); |
| Enrico Granata | 31fda93 | 2015-10-07 01:41:23 +0000 | [diff] [blame] | 940 | |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 941 | // ideally we would like to bail out if passing NULL, but if we do so |
| 942 | // we end up not providing the summary for function pointers anymore |
| 943 | if (/*summary_ptr == NULL ||*/ m_is_getting_summary) |
| 944 | return false; |
| Greg Clayton | 48ca8b8 | 2012-01-07 20:58:07 +0000 | [diff] [blame] | 945 | |
| 946 | m_is_getting_summary = true; |
| Enrico Granata | f18c03e | 2012-04-04 17:34:10 +0000 | [diff] [blame] | 947 | |
| Enrico Granata | 31fda93 | 2015-10-07 01:41:23 +0000 | [diff] [blame] | 948 | TypeSummaryOptions actual_options(options); |
| 949 | |
| 950 | if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown) |
| 951 | actual_options.SetLanguage(GetPreferredDisplayLanguage()); |
| 952 | |
| Enrico Granata | f18c03e | 2012-04-04 17:34:10 +0000 | [diff] [blame] | 953 | // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other |
| 954 | // information that we might care to see in a crash log. might be useful in very specific situations though. |
| 955 | /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s", |
| Enrico Granata | 31fda93 | 2015-10-07 01:41:23 +0000 | [diff] [blame] | 956 | GetTypeName().GetCString(), |
| 957 | GetName().GetCString(), |
| 958 | summary_ptr->GetDescription().c_str());*/ |
| Enrico Granata | f18c03e | 2012-04-04 17:34:10 +0000 | [diff] [blame] | 959 | |
| Enrico Granata | ff0f23d | 2014-12-10 02:00:45 +0000 | [diff] [blame] | 960 | if (UpdateValueIfNeeded (false) && summary_ptr) |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 961 | { |
| Enrico Granata | ff0f23d | 2014-12-10 02:00:45 +0000 | [diff] [blame] | 962 | if (HasSyntheticValue()) |
| 963 | m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#}) |
| Enrico Granata | 31fda93 | 2015-10-07 01:41:23 +0000 | [diff] [blame] | 964 | summary_ptr->FormatObject(this, destination, actual_options); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 965 | } |
| Greg Clayton | 48ca8b8 | 2012-01-07 20:58:07 +0000 | [diff] [blame] | 966 | m_is_getting_summary = false; |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 967 | return !destination.empty(); |
| 968 | } |
| 969 | |
| 970 | const char * |
| Enrico Granata | 31fda93 | 2015-10-07 01:41:23 +0000 | [diff] [blame] | 971 | ValueObject::GetSummaryAsCString (lldb::LanguageType lang) |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 972 | { |
| 973 | if (UpdateValueIfNeeded(true) && m_summary_str.empty()) |
| 974 | { |
| Enrico Granata | 31fda93 | 2015-10-07 01:41:23 +0000 | [diff] [blame] | 975 | TypeSummaryOptions summary_options; |
| 976 | summary_options.SetLanguage(lang); |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 977 | GetSummaryAsCString(GetSummaryFormat().get(), |
| Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 978 | m_summary_str, |
| Enrico Granata | 31fda93 | 2015-10-07 01:41:23 +0000 | [diff] [blame] | 979 | summary_options); |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 980 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 981 | if (m_summary_str.empty()) |
| 982 | return NULL; |
| 983 | return m_summary_str.c_str(); |
| 984 | } |
| 985 | |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 986 | bool |
| Enrico Granata | 49bfafb | 2014-11-18 23:36:25 +0000 | [diff] [blame] | 987 | ValueObject::GetSummaryAsCString (std::string& destination, |
| 988 | const TypeSummaryOptions& options) |
| 989 | { |
| 990 | return GetSummaryAsCString(GetSummaryFormat().get(), |
| Enrico Granata | 31fda93 | 2015-10-07 01:41:23 +0000 | [diff] [blame] | 991 | destination, |
| 992 | options); |
| Enrico Granata | 49bfafb | 2014-11-18 23:36:25 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | bool |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 996 | ValueObject::IsCStringContainer(bool check_pointer) |
| 997 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 998 | CompilerType pointee_or_element_compiler_type; |
| 999 | const Flags type_flags (GetTypeInfo (&pointee_or_element_compiler_type)); |
| Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 1000 | bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) && |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 1001 | pointee_or_element_compiler_type.IsCharType ()); |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1002 | if (!is_char_arr_ptr) |
| 1003 | return false; |
| 1004 | if (!check_pointer) |
| 1005 | return true; |
| Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 1006 | if (type_flags.Test(eTypeIsArray)) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1007 | return true; |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1008 | addr_t cstr_address = LLDB_INVALID_ADDRESS; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1009 | AddressType cstr_address_type = eAddressTypeInvalid; |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1010 | cstr_address = GetAddressOf (true, &cstr_address_type); |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1011 | return (cstr_address != LLDB_INVALID_ADDRESS); |
| 1012 | } |
| 1013 | |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1014 | size_t |
| 1015 | ValueObject::GetPointeeData (DataExtractor& data, |
| 1016 | uint32_t item_idx, |
| 1017 | uint32_t item_count) |
| 1018 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 1019 | CompilerType pointee_or_element_compiler_type; |
| 1020 | const uint32_t type_info = GetTypeInfo (&pointee_or_element_compiler_type); |
| Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 1021 | const bool is_pointer_type = type_info & eTypeIsPointer; |
| 1022 | const bool is_array_type = type_info & eTypeIsArray; |
| Greg Clayton | 2452ab7 | 2013-02-08 22:02:02 +0000 | [diff] [blame] | 1023 | if (!(is_pointer_type || is_array_type)) |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1024 | return 0; |
| 1025 | |
| 1026 | if (item_count == 0) |
| 1027 | return 0; |
| 1028 | |
| Enrico Granata | 951bdd5 | 2015-01-28 01:09:45 +0000 | [diff] [blame] | 1029 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 1030 | |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 1031 | const uint64_t item_type_size = pointee_or_element_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope()); |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1032 | const uint64_t bytes = item_count * item_type_size; |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1033 | const uint64_t offset = item_idx * item_type_size; |
| 1034 | |
| 1035 | if (item_idx == 0 && item_count == 1) // simply a deref |
| 1036 | { |
| Greg Clayton | 2452ab7 | 2013-02-08 22:02:02 +0000 | [diff] [blame] | 1037 | if (is_pointer_type) |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1038 | { |
| 1039 | Error error; |
| 1040 | ValueObjectSP pointee_sp = Dereference(error); |
| 1041 | if (error.Fail() || pointee_sp.get() == NULL) |
| 1042 | return 0; |
| Sean Callanan | 866e91c | 2014-02-28 22:27:53 +0000 | [diff] [blame] | 1043 | return pointee_sp->GetData(data, error); |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1044 | } |
| 1045 | else |
| 1046 | { |
| 1047 | ValueObjectSP child_sp = GetChildAtIndex(0, true); |
| 1048 | if (child_sp.get() == NULL) |
| 1049 | return 0; |
| Sean Callanan | 866e91c | 2014-02-28 22:27:53 +0000 | [diff] [blame] | 1050 | Error error; |
| 1051 | return child_sp->GetData(data, error); |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1052 | } |
| 1053 | return true; |
| 1054 | } |
| 1055 | else /* (items > 1) */ |
| 1056 | { |
| 1057 | Error error; |
| 1058 | lldb_private::DataBufferHeap* heap_buf_ptr = NULL; |
| 1059 | lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap()); |
| 1060 | |
| 1061 | AddressType addr_type; |
| Greg Clayton | 2452ab7 | 2013-02-08 22:02:02 +0000 | [diff] [blame] | 1062 | lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type); |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1063 | |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1064 | switch (addr_type) |
| 1065 | { |
| 1066 | case eAddressTypeFile: |
| 1067 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1068 | ModuleSP module_sp (GetModule()); |
| 1069 | if (module_sp) |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1070 | { |
| Enrico Granata | 9c2efe3 | 2012-08-07 01:49:34 +0000 | [diff] [blame] | 1071 | addr = addr + offset; |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1072 | Address so_addr; |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1073 | module_sp->ResolveFileAddress(addr, so_addr); |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1074 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 1075 | Target* target = exe_ctx.GetTargetPtr(); |
| 1076 | if (target) |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1077 | { |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1078 | heap_buf_ptr->SetByteSize(bytes); |
| 1079 | size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error); |
| 1080 | if (error.Success()) |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1081 | { |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1082 | data.SetData(data_sp); |
| 1083 | return bytes_read; |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | } |
| 1087 | } |
| 1088 | break; |
| 1089 | case eAddressTypeLoad: |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1090 | { |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1091 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 1092 | Process *process = exe_ctx.GetProcessPtr(); |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1093 | if (process) |
| 1094 | { |
| 1095 | heap_buf_ptr->SetByteSize(bytes); |
| 1096 | size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error); |
| Enrico Granata | 5e1480c | 2013-10-30 17:52:44 +0000 | [diff] [blame] | 1097 | if (error.Success() || bytes_read > 0) |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1098 | { |
| 1099 | data.SetData(data_sp); |
| 1100 | return bytes_read; |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | break; |
| 1105 | case eAddressTypeHost: |
| 1106 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1107 | const uint64_t max_bytes = GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope()); |
| Greg Clayton | 2452ab7 | 2013-02-08 22:02:02 +0000 | [diff] [blame] | 1108 | if (max_bytes > offset) |
| 1109 | { |
| 1110 | size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes); |
| Siva Chandra | e32f2b5 | 2015-05-05 00:41:35 +0000 | [diff] [blame] | 1111 | addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| Enrico Granata | 7339b9d | 2015-11-03 02:34:43 +0000 | [diff] [blame] | 1112 | if (addr == 0 || addr == LLDB_INVALID_ADDRESS) |
| Siva Chandra | e32f2b5 | 2015-05-05 00:41:35 +0000 | [diff] [blame] | 1113 | break; |
| Greg Clayton | 2452ab7 | 2013-02-08 22:02:02 +0000 | [diff] [blame] | 1114 | heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read); |
| 1115 | data.SetData(data_sp); |
| 1116 | return bytes_read; |
| 1117 | } |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1118 | } |
| 1119 | break; |
| 1120 | case eAddressTypeInvalid: |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1121 | break; |
| 1122 | } |
| 1123 | } |
| 1124 | return 0; |
| 1125 | } |
| 1126 | |
| Greg Clayton | faac111 | 2013-03-14 18:31:44 +0000 | [diff] [blame] | 1127 | uint64_t |
| Sean Callanan | 866e91c | 2014-02-28 22:27:53 +0000 | [diff] [blame] | 1128 | ValueObject::GetData (DataExtractor& data, Error &error) |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1129 | { |
| 1130 | UpdateValueIfNeeded(false); |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1131 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| Sean Callanan | 866e91c | 2014-02-28 22:27:53 +0000 | [diff] [blame] | 1132 | error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get()); |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1133 | if (error.Fail()) |
| Sean Callanan | ed185ab | 2013-04-19 19:47:32 +0000 | [diff] [blame] | 1134 | { |
| 1135 | if (m_data.GetByteSize()) |
| 1136 | { |
| 1137 | data = m_data; |
| 1138 | return data.GetByteSize(); |
| 1139 | } |
| 1140 | else |
| 1141 | { |
| 1142 | return 0; |
| 1143 | } |
| 1144 | } |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1145 | data.SetAddressByteSize(m_data.GetAddressByteSize()); |
| 1146 | data.SetByteOrder(m_data.GetByteOrder()); |
| 1147 | return data.GetByteSize(); |
| 1148 | } |
| 1149 | |
| Sean Callanan | 389823e | 2013-04-13 01:21:23 +0000 | [diff] [blame] | 1150 | bool |
| 1151 | ValueObject::SetData (DataExtractor &data, Error &error) |
| 1152 | { |
| 1153 | error.Clear(); |
| 1154 | // Make sure our value is up to date first so that our location and location |
| 1155 | // type is valid. |
| 1156 | if (!UpdateValueIfNeeded(false)) |
| 1157 | { |
| 1158 | error.SetErrorString("unable to read value"); |
| 1159 | return false; |
| 1160 | } |
| 1161 | |
| 1162 | uint64_t count = 0; |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1163 | const Encoding encoding = GetCompilerType().GetEncoding(count); |
| Sean Callanan | 389823e | 2013-04-13 01:21:23 +0000 | [diff] [blame] | 1164 | |
| 1165 | const size_t byte_size = GetByteSize(); |
| 1166 | |
| 1167 | Value::ValueType value_type = m_value.GetValueType(); |
| 1168 | |
| 1169 | switch (value_type) |
| 1170 | { |
| 1171 | case Value::eValueTypeScalar: |
| 1172 | { |
| 1173 | Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size); |
| 1174 | |
| 1175 | if (!set_error.Success()) |
| 1176 | { |
| 1177 | error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString()); |
| 1178 | return false; |
| 1179 | } |
| 1180 | } |
| 1181 | break; |
| 1182 | case Value::eValueTypeLoadAddress: |
| 1183 | { |
| 1184 | // If it is a load address, then the scalar value is the storage location |
| 1185 | // of the data, and we have to shove this value down to that load location. |
| 1186 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 1187 | Process *process = exe_ctx.GetProcessPtr(); |
| 1188 | if (process) |
| 1189 | { |
| 1190 | addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 1191 | size_t bytes_written = process->WriteMemory(target_addr, |
| 1192 | data.GetDataStart(), |
| 1193 | byte_size, |
| 1194 | error); |
| 1195 | if (!error.Success()) |
| 1196 | return false; |
| 1197 | if (bytes_written != byte_size) |
| 1198 | { |
| 1199 | error.SetErrorString("unable to write value to memory"); |
| 1200 | return false; |
| 1201 | } |
| 1202 | } |
| 1203 | } |
| 1204 | break; |
| 1205 | case Value::eValueTypeHostAddress: |
| 1206 | { |
| 1207 | // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data. |
| 1208 | DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0)); |
| 1209 | m_data.SetData(buffer_sp, 0); |
| 1210 | data.CopyByteOrderedData (0, |
| 1211 | byte_size, |
| 1212 | const_cast<uint8_t *>(m_data.GetDataStart()), |
| 1213 | byte_size, |
| 1214 | m_data.GetByteOrder()); |
| 1215 | m_value.GetScalar() = (uintptr_t)m_data.GetDataStart(); |
| 1216 | } |
| 1217 | break; |
| 1218 | case Value::eValueTypeFileAddress: |
| 1219 | case Value::eValueTypeVector: |
| 1220 | break; |
| 1221 | } |
| 1222 | |
| 1223 | // If we have reached this point, then we have successfully changed the value. |
| 1224 | SetNeedsUpdate(); |
| 1225 | return true; |
| 1226 | } |
| 1227 | |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1228 | // will compute strlen(str), but without consuming more than |
| 1229 | // maxlen bytes out of str (this serves the purpose of reading |
| 1230 | // chunks of a string without having to worry about |
| 1231 | // missing NULL terminators in the chunk) |
| 1232 | // of course, if strlen(str) > maxlen, the function will return |
| 1233 | // maxlen_value (which should be != maxlen, because that allows you |
| 1234 | // to know whether strlen(str) == maxlen or strlen(str) > maxlen) |
| 1235 | static uint32_t |
| 1236 | strlen_or_inf (const char* str, |
| 1237 | uint32_t maxlen, |
| 1238 | uint32_t maxlen_value) |
| 1239 | { |
| 1240 | uint32_t len = 0; |
| Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 1241 | if (str) |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1242 | { |
| Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 1243 | while(*str) |
| 1244 | { |
| 1245 | len++;str++; |
| Greg Clayton | 2452ab7 | 2013-02-08 22:02:02 +0000 | [diff] [blame] | 1246 | if (len >= maxlen) |
| Greg Clayton | 8dd5c17 | 2011-10-05 22:19:51 +0000 | [diff] [blame] | 1247 | return maxlen_value; |
| 1248 | } |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1249 | } |
| 1250 | return len; |
| 1251 | } |
| 1252 | |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1253 | static bool |
| 1254 | CopyStringDataToBufferSP(const StreamString& source, |
| 1255 | lldb::DataBufferSP& destination) |
| 1256 | { |
| 1257 | destination.reset(new DataBufferHeap(source.GetSize()+1,0)); |
| 1258 | memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize()); |
| 1259 | return true; |
| 1260 | } |
| 1261 | |
| Enrico Granata | b766292 | 2015-11-04 00:02:08 +0000 | [diff] [blame] | 1262 | std::pair<size_t,bool> |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1263 | ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp, |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1264 | Error& error, |
| 1265 | uint32_t max_length, |
| 1266 | bool honor_array, |
| 1267 | Format item_format) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1268 | { |
| Enrico Granata | b766292 | 2015-11-04 00:02:08 +0000 | [diff] [blame] | 1269 | bool was_capped = false; |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1270 | StreamString s; |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1271 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 1272 | Target* target = exe_ctx.GetTargetPtr(); |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1273 | |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1274 | if (!target) |
| 1275 | { |
| 1276 | s << "<no target to read from>"; |
| 1277 | error.SetErrorString("no target to read from"); |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1278 | CopyStringDataToBufferSP(s, buffer_sp); |
| Enrico Granata | b766292 | 2015-11-04 00:02:08 +0000 | [diff] [blame] | 1279 | return {0,was_capped}; |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | if (max_length == 0) |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1283 | max_length = target->GetMaximumSizeOfStringSummary(); |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1284 | |
| Enrico Granata | ea2bc0f | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 1285 | size_t bytes_read = 0; |
| 1286 | size_t total_bytes_read = 0; |
| 1287 | |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 1288 | CompilerType compiler_type = GetCompilerType(); |
| 1289 | CompilerType elem_or_pointee_compiler_type; |
| 1290 | const Flags type_flags (GetTypeInfo (&elem_or_pointee_compiler_type)); |
| Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 1291 | if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) && |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 1292 | elem_or_pointee_compiler_type.IsCharType ()) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1293 | { |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1294 | addr_t cstr_address = LLDB_INVALID_ADDRESS; |
| 1295 | AddressType cstr_address_type = eAddressTypeInvalid; |
| 1296 | |
| 1297 | size_t cstr_len = 0; |
| 1298 | bool capped_data = false; |
| Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 1299 | if (type_flags.Test (eTypeIsArray)) |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1300 | { |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1301 | // We have an array |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1302 | uint64_t array_size = 0; |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 1303 | if (compiler_type.IsArrayType(NULL, &array_size, NULL)) |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1304 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1305 | cstr_len = array_size; |
| 1306 | if (cstr_len > max_length) |
| 1307 | { |
| 1308 | capped_data = true; |
| 1309 | cstr_len = max_length; |
| 1310 | } |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1311 | } |
| 1312 | cstr_address = GetAddressOf (true, &cstr_address_type); |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1313 | } |
| 1314 | else |
| 1315 | { |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1316 | // We have a pointer |
| 1317 | cstr_address = GetPointerValue (&cstr_address_type); |
| 1318 | } |
| 1319 | |
| 1320 | if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS) |
| 1321 | { |
| 1322 | s << "<invalid address>"; |
| 1323 | error.SetErrorString("invalid address"); |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1324 | CopyStringDataToBufferSP(s, buffer_sp); |
| Enrico Granata | b766292 | 2015-11-04 00:02:08 +0000 | [diff] [blame] | 1325 | return {0,was_capped}; |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1326 | } |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1327 | |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1328 | Address cstr_so_addr (cstr_address); |
| 1329 | DataExtractor data; |
| 1330 | if (cstr_len > 0 && honor_array) |
| 1331 | { |
| 1332 | // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host |
| 1333 | // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this |
| 1334 | GetPointeeData(data, 0, cstr_len); |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1335 | |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1336 | if ((bytes_read = data.GetByteSize()) > 0) |
| 1337 | { |
| 1338 | total_bytes_read = bytes_read; |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1339 | for (size_t offset = 0; offset < bytes_read; offset++) |
| 1340 | s.Printf("%c", *data.PeekData(offset, 1)); |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1341 | if (capped_data) |
| Enrico Granata | b766292 | 2015-11-04 00:02:08 +0000 | [diff] [blame] | 1342 | was_capped = true; |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | else |
| 1346 | { |
| 1347 | cstr_len = max_length; |
| 1348 | const size_t k_max_buf_size = 64; |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1349 | |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1350 | size_t offset = 0; |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1351 | |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1352 | int cstr_len_displayed = -1; |
| 1353 | bool capped_cstr = false; |
| 1354 | // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host |
| 1355 | // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this |
| 1356 | while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1357 | { |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1358 | total_bytes_read += bytes_read; |
| 1359 | const char *cstr = data.PeekCStr(0); |
| 1360 | size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1); |
| 1361 | if (len > k_max_buf_size) |
| 1362 | len = k_max_buf_size; |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1363 | |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1364 | if (cstr_len_displayed < 0) |
| 1365 | cstr_len_displayed = len; |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1366 | |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1367 | if (len == 0) |
| 1368 | break; |
| 1369 | cstr_len_displayed += len; |
| 1370 | if (len > bytes_read) |
| 1371 | len = bytes_read; |
| 1372 | if (len > cstr_len) |
| 1373 | len = cstr_len; |
| 1374 | |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1375 | for (size_t offset = 0; offset < bytes_read; offset++) |
| 1376 | s.Printf("%c", *data.PeekData(offset, 1)); |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1377 | |
| 1378 | if (len < k_max_buf_size) |
| 1379 | break; |
| 1380 | |
| 1381 | if (len >= cstr_len) |
| Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1382 | { |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1383 | capped_cstr = true; |
| 1384 | break; |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1385 | } |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1386 | |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1387 | cstr_len -= len; |
| 1388 | offset += len; |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1389 | } |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1390 | |
| 1391 | if (cstr_len_displayed >= 0) |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1392 | { |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1393 | if (capped_cstr) |
| Enrico Granata | b766292 | 2015-11-04 00:02:08 +0000 | [diff] [blame] | 1394 | was_capped = true; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1395 | } |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1396 | } |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1397 | } |
| 1398 | else |
| 1399 | { |
| Enrico Granata | 7e0db2a | 2013-02-28 22:01:33 +0000 | [diff] [blame] | 1400 | error.SetErrorString("not a string object"); |
| Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1401 | s << "<not a string object>"; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1402 | } |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1403 | CopyStringDataToBufferSP(s, buffer_sp); |
| Enrico Granata | b766292 | 2015-11-04 00:02:08 +0000 | [diff] [blame] | 1404 | return {total_bytes_read,was_capped}; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1405 | } |
| 1406 | |
| Enrico Granata | 744794a | 2014-09-05 21:46:22 +0000 | [diff] [blame] | 1407 | std::pair<TypeValidatorResult, std::string> |
| 1408 | ValueObject::GetValidationStatus () |
| 1409 | { |
| 1410 | if (!UpdateValueIfNeeded(true)) |
| 1411 | return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems |
| 1412 | |
| 1413 | if (m_validation_result.hasValue()) |
| 1414 | return m_validation_result.getValue(); |
| 1415 | |
| 1416 | if (!m_type_validator_sp) |
| 1417 | return {TypeValidatorResult::Success,""}; // no validator no failure |
| 1418 | |
| 1419 | auto outcome = m_type_validator_sp->FormatObject(this); |
| 1420 | |
| 1421 | return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue(); |
| 1422 | } |
| 1423 | |
| Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 1424 | const char * |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1425 | ValueObject::GetObjectDescription () |
| Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 1426 | { |
| Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1427 | |
| Enrico Granata | d8b5fce | 2011-08-02 23:12:24 +0000 | [diff] [blame] | 1428 | if (!UpdateValueIfNeeded (true)) |
| Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 1429 | return NULL; |
| Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 1430 | |
| 1431 | if (!m_object_desc_str.empty()) |
| 1432 | return m_object_desc_str.c_str(); |
| 1433 | |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1434 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 1435 | Process *process = exe_ctx.GetProcessPtr(); |
| Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1436 | if (process == NULL) |
| Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 1437 | return NULL; |
| Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1438 | |
| Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 1439 | StreamString s; |
| Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1440 | |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1441 | LanguageType language = GetObjectRuntimeLanguage(); |
| Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 1442 | LanguageRuntime *runtime = process->GetLanguageRuntime(language); |
| 1443 | |
| Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 1444 | if (runtime == NULL) |
| 1445 | { |
| Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 1446 | // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway... |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 1447 | CompilerType compiler_type = GetCompilerType(); |
| 1448 | if (compiler_type) |
| Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 1449 | { |
| Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 1450 | bool is_signed; |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 1451 | if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType ()) |
| Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 1452 | { |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1453 | runtime = process->GetLanguageRuntime(eLanguageTypeObjC); |
| Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 1454 | } |
| Jim Ingham | a2cf263 | 2010-12-23 02:29:54 +0000 | [diff] [blame] | 1455 | } |
| 1456 | } |
| 1457 | |
| Jim Ingham | 8d543de | 2011-03-31 23:01:21 +0000 | [diff] [blame] | 1458 | if (runtime && runtime->GetObjectDescription(s, *this)) |
| Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 1459 | { |
| 1460 | m_object_desc_str.append (s.GetData()); |
| 1461 | } |
| Sean Callanan | 672ad94 | 2010-10-23 00:18:49 +0000 | [diff] [blame] | 1462 | |
| 1463 | if (m_object_desc_str.empty()) |
| 1464 | return NULL; |
| 1465 | else |
| 1466 | return m_object_desc_str.c_str(); |
| Jim Ingham | 53c47f1 | 2010-09-10 23:12:17 +0000 | [diff] [blame] | 1467 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1468 | |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 1469 | bool |
| Enrico Granata | 4939b98 | 2013-12-22 09:24:22 +0000 | [diff] [blame] | 1470 | ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format, |
| 1471 | std::string& destination) |
| 1472 | { |
| 1473 | if (UpdateValueIfNeeded(false)) |
| 1474 | return format.FormatObject(this,destination); |
| 1475 | else |
| 1476 | return false; |
| 1477 | } |
| 1478 | |
| 1479 | bool |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 1480 | ValueObject::GetValueAsCString (lldb::Format format, |
| 1481 | std::string& destination) |
| 1482 | { |
| Enrico Granata | 30f287f | 2013-12-28 08:44:02 +0000 | [diff] [blame] | 1483 | return GetValueAsCString(TypeFormatImpl_Format(format),destination); |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 1484 | } |
| 1485 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1486 | const char * |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1487 | ValueObject::GetValueAsCString () |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1488 | { |
| Enrico Granata | b294fd2 | 2013-05-31 19:18:19 +0000 | [diff] [blame] | 1489 | if (UpdateValueIfNeeded(true)) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1490 | { |
| Enrico Granata | 4939b98 | 2013-12-22 09:24:22 +0000 | [diff] [blame] | 1491 | lldb::TypeFormatImplSP format_sp; |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 1492 | lldb::Format my_format = GetFormat(); |
| Enrico Granata | c953a6a | 2012-12-11 02:17:22 +0000 | [diff] [blame] | 1493 | if (my_format == lldb::eFormatDefault) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1494 | { |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 1495 | if (m_type_format_sp) |
| Enrico Granata | 4939b98 | 2013-12-22 09:24:22 +0000 | [diff] [blame] | 1496 | format_sp = m_type_format_sp; |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 1497 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1498 | { |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 1499 | if (m_is_bitfield_for_scalar) |
| 1500 | my_format = eFormatUnsigned; |
| 1501 | else |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1502 | { |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 1503 | if (m_value.GetContextType() == Value::eContextTypeRegisterInfo) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1504 | { |
| 1505 | const RegisterInfo *reg_info = m_value.GetRegisterInfo(); |
| 1506 | if (reg_info) |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 1507 | my_format = reg_info->format; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1508 | } |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 1509 | else |
| 1510 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1511 | my_format = GetValue().GetCompilerType().GetFormat(); |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 1512 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1513 | } |
| 1514 | } |
| 1515 | } |
| Enrico Granata | b294fd2 | 2013-05-31 19:18:19 +0000 | [diff] [blame] | 1516 | if (my_format != m_last_format || m_value_str.empty()) |
| Enrico Granata | 297e69f | 2012-03-06 23:21:16 +0000 | [diff] [blame] | 1517 | { |
| Enrico Granata | b294fd2 | 2013-05-31 19:18:19 +0000 | [diff] [blame] | 1518 | m_last_format = my_format; |
| Enrico Granata | 4939b98 | 2013-12-22 09:24:22 +0000 | [diff] [blame] | 1519 | if (!format_sp) |
| Enrico Granata | 30f287f | 2013-12-28 08:44:02 +0000 | [diff] [blame] | 1520 | format_sp.reset(new TypeFormatImpl_Format(my_format)); |
| Enrico Granata | 4939b98 | 2013-12-22 09:24:22 +0000 | [diff] [blame] | 1521 | if (GetValueAsCString(*format_sp.get(), m_value_str)) |
| Enrico Granata | 297e69f | 2012-03-06 23:21:16 +0000 | [diff] [blame] | 1522 | { |
| Enrico Granata | b294fd2 | 2013-05-31 19:18:19 +0000 | [diff] [blame] | 1523 | if (!m_value_did_change && m_old_value_valid) |
| 1524 | { |
| 1525 | // The value was gotten successfully, so we consider the |
| 1526 | // value as changed if the value string differs |
| 1527 | SetValueDidChange (m_old_value_str != m_value_str); |
| 1528 | } |
| Enrico Granata | 297e69f | 2012-03-06 23:21:16 +0000 | [diff] [blame] | 1529 | } |
| 1530 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1531 | } |
| 1532 | if (m_value_str.empty()) |
| 1533 | return NULL; |
| 1534 | return m_value_str.c_str(); |
| 1535 | } |
| 1536 | |
| Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1537 | // if > 8bytes, 0 is returned. this method should mostly be used |
| 1538 | // to read address values out of pointers |
| Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1539 | uint64_t |
| Johnny Chen | 3f476c4 | 2012-06-05 19:37:43 +0000 | [diff] [blame] | 1540 | ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success) |
| Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1541 | { |
| 1542 | // If our byte size is zero this is an aggregate type that has children |
| Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 1543 | if (CanProvideValue()) |
| Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1544 | { |
| Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1545 | Scalar scalar; |
| 1546 | if (ResolveValue (scalar)) |
| Johnny Chen | 3f476c4 | 2012-06-05 19:37:43 +0000 | [diff] [blame] | 1547 | { |
| 1548 | if (success) |
| 1549 | *success = true; |
| Enrico Granata | 48ea80f | 2012-10-24 20:24:39 +0000 | [diff] [blame] | 1550 | return scalar.ULongLong(fail_value); |
| Johnny Chen | 3f476c4 | 2012-06-05 19:37:43 +0000 | [diff] [blame] | 1551 | } |
| 1552 | // fallthrough, otherwise... |
| Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1553 | } |
| Johnny Chen | 3f476c4 | 2012-06-05 19:37:43 +0000 | [diff] [blame] | 1554 | |
| 1555 | if (success) |
| 1556 | *success = false; |
| Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1557 | return fail_value; |
| Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
| Enrico Granata | d7373f6 | 2013-10-31 18:57:50 +0000 | [diff] [blame] | 1560 | int64_t |
| 1561 | ValueObject::GetValueAsSigned (int64_t fail_value, bool *success) |
| 1562 | { |
| 1563 | // If our byte size is zero this is an aggregate type that has children |
| Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 1564 | if (CanProvideValue()) |
| Enrico Granata | d7373f6 | 2013-10-31 18:57:50 +0000 | [diff] [blame] | 1565 | { |
| 1566 | Scalar scalar; |
| 1567 | if (ResolveValue (scalar)) |
| 1568 | { |
| 1569 | if (success) |
| 1570 | *success = true; |
| Tamas Berghammer | 5a9919f | 2015-01-23 10:54:21 +0000 | [diff] [blame] | 1571 | return scalar.SLongLong(fail_value); |
| Enrico Granata | d7373f6 | 2013-10-31 18:57:50 +0000 | [diff] [blame] | 1572 | } |
| 1573 | // fallthrough, otherwise... |
| 1574 | } |
| 1575 | |
| 1576 | if (success) |
| 1577 | *success = false; |
| Tamas Berghammer | 5a9919f | 2015-01-23 10:54:21 +0000 | [diff] [blame] | 1578 | return fail_value; |
| Enrico Granata | d7373f6 | 2013-10-31 18:57:50 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
| Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1581 | // if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep |
| 1582 | // this call up to date by returning true for your new special cases. We will eventually move |
| 1583 | // to checking this call result before trying to display special cases |
| 1584 | bool |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1585 | ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display, |
| 1586 | Format custom_format) |
| Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1587 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1588 | Flags flags(GetTypeInfo()); |
| Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 1589 | if (flags.AnySet(eTypeIsArray | eTypeIsPointer) |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1590 | && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) |
| Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1591 | { |
| 1592 | if (IsCStringContainer(true) && |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1593 | (custom_format == eFormatCString || |
| 1594 | custom_format == eFormatCharArray || |
| 1595 | custom_format == eFormatChar || |
| 1596 | custom_format == eFormatVectorOfChar)) |
| Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1597 | return true; |
| 1598 | |
| Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 1599 | if (flags.Test(eTypeIsArray)) |
| Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1600 | { |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1601 | if ((custom_format == eFormatBytes) || |
| 1602 | (custom_format == eFormatBytesWithASCII)) |
| Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1603 | return true; |
| 1604 | |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1605 | if ((custom_format == eFormatVectorOfChar) || |
| 1606 | (custom_format == eFormatVectorOfFloat32) || |
| 1607 | (custom_format == eFormatVectorOfFloat64) || |
| 1608 | (custom_format == eFormatVectorOfSInt16) || |
| 1609 | (custom_format == eFormatVectorOfSInt32) || |
| 1610 | (custom_format == eFormatVectorOfSInt64) || |
| 1611 | (custom_format == eFormatVectorOfSInt8) || |
| 1612 | (custom_format == eFormatVectorOfUInt128) || |
| 1613 | (custom_format == eFormatVectorOfUInt16) || |
| 1614 | (custom_format == eFormatVectorOfUInt32) || |
| 1615 | (custom_format == eFormatVectorOfUInt64) || |
| 1616 | (custom_format == eFormatVectorOfUInt8)) |
| Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1617 | return true; |
| 1618 | } |
| 1619 | } |
| 1620 | return false; |
| 1621 | } |
| 1622 | |
| Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1623 | bool |
| 1624 | ValueObject::DumpPrintableRepresentation(Stream& s, |
| 1625 | ValueObjectRepresentationStyle val_obj_display, |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1626 | Format custom_format, |
| Enrico Granata | 0dba9b3 | 2014-01-08 01:36:59 +0000 | [diff] [blame] | 1627 | PrintableRepresentationSpecialCases special, |
| 1628 | bool do_dump_error) |
| Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1629 | { |
| Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1630 | |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1631 | Flags flags(GetTypeInfo()); |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1632 | |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1633 | bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow); |
| 1634 | bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly); |
| 1635 | |
| 1636 | if (allow_special) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1637 | { |
| Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 1638 | if (flags.AnySet(eTypeIsArray | eTypeIsPointer) |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1639 | && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) |
| Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1640 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1641 | // when being asked to get a printable display an array or pointer type directly, |
| 1642 | // try to "do the right thing" |
| 1643 | |
| 1644 | if (IsCStringContainer(true) && |
| 1645 | (custom_format == eFormatCString || |
| 1646 | custom_format == eFormatCharArray || |
| 1647 | custom_format == eFormatChar || |
| 1648 | custom_format == eFormatVectorOfChar)) // print char[] & char* directly |
| Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1649 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1650 | Error error; |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1651 | lldb::DataBufferSP buffer_sp; |
| Enrico Granata | b766292 | 2015-11-04 00:02:08 +0000 | [diff] [blame] | 1652 | std::pair<size_t, bool> read_string = ReadPointedString(buffer_sp, |
| 1653 | error, |
| 1654 | 0, |
| 1655 | (custom_format == eFormatVectorOfChar) || |
| 1656 | (custom_format == eFormatCharArray)); |
| Enrico Granata | ac49453 | 2015-09-09 22:30:24 +0000 | [diff] [blame] | 1657 | lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions options(*this); |
| Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1658 | options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults |
| 1659 | options.SetStream(&s); |
| 1660 | options.SetPrefixToken(0); |
| 1661 | options.SetQuote('"'); |
| 1662 | options.SetSourceSize(buffer_sp->GetByteSize()); |
| Enrico Granata | b766292 | 2015-11-04 00:02:08 +0000 | [diff] [blame] | 1663 | options.SetIsTruncated(read_string.second); |
| Enrico Granata | ac49453 | 2015-09-09 22:30:24 +0000 | [diff] [blame] | 1664 | formatters::StringPrinter::ReadBufferAndDumpToStream<lldb_private::formatters::StringPrinter::StringElementType::ASCII>(options); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1665 | return !error.Fail(); |
| Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1666 | } |
| 1667 | |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1668 | if (custom_format == eFormatEnum) |
| 1669 | return false; |
| 1670 | |
| 1671 | // this only works for arrays, because I have no way to know when |
| 1672 | // the pointed memory ends, and no special \0 end of data marker |
| Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 1673 | if (flags.Test(eTypeIsArray)) |
| Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1674 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1675 | if ((custom_format == eFormatBytes) || |
| 1676 | (custom_format == eFormatBytesWithASCII)) |
| Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1677 | { |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1678 | const size_t count = GetNumChildren(); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1679 | |
| 1680 | s << '['; |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1681 | for (size_t low = 0; low < count; low++) |
| Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1682 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1683 | |
| 1684 | if (low) |
| 1685 | s << ','; |
| 1686 | |
| 1687 | ValueObjectSP child = GetChildAtIndex(low,true); |
| 1688 | if (!child.get()) |
| 1689 | { |
| 1690 | s << "<invalid child>"; |
| 1691 | continue; |
| 1692 | } |
| 1693 | child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format); |
| 1694 | } |
| 1695 | |
| 1696 | s << ']'; |
| 1697 | |
| 1698 | return true; |
| 1699 | } |
| Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1700 | |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1701 | if ((custom_format == eFormatVectorOfChar) || |
| 1702 | (custom_format == eFormatVectorOfFloat32) || |
| 1703 | (custom_format == eFormatVectorOfFloat64) || |
| 1704 | (custom_format == eFormatVectorOfSInt16) || |
| 1705 | (custom_format == eFormatVectorOfSInt32) || |
| 1706 | (custom_format == eFormatVectorOfSInt64) || |
| 1707 | (custom_format == eFormatVectorOfSInt8) || |
| 1708 | (custom_format == eFormatVectorOfUInt128) || |
| 1709 | (custom_format == eFormatVectorOfUInt16) || |
| 1710 | (custom_format == eFormatVectorOfUInt32) || |
| 1711 | (custom_format == eFormatVectorOfUInt64) || |
| 1712 | (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly |
| 1713 | { |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1714 | const size_t count = GetNumChildren(); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1715 | |
| 1716 | Format format = FormatManager::GetSingleItemFormat(custom_format); |
| 1717 | |
| 1718 | s << '['; |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1719 | for (size_t low = 0; low < count; low++) |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1720 | { |
| 1721 | |
| 1722 | if (low) |
| 1723 | s << ','; |
| 1724 | |
| 1725 | ValueObjectSP child = GetChildAtIndex(low,true); |
| 1726 | if (!child.get()) |
| 1727 | { |
| 1728 | s << "<invalid child>"; |
| 1729 | continue; |
| 1730 | } |
| 1731 | child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format); |
| 1732 | } |
| 1733 | |
| 1734 | s << ']'; |
| 1735 | |
| 1736 | return true; |
| 1737 | } |
| Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1738 | } |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1739 | |
| 1740 | if ((custom_format == eFormatBoolean) || |
| 1741 | (custom_format == eFormatBinary) || |
| 1742 | (custom_format == eFormatChar) || |
| 1743 | (custom_format == eFormatCharPrintable) || |
| 1744 | (custom_format == eFormatComplexFloat) || |
| 1745 | (custom_format == eFormatDecimal) || |
| 1746 | (custom_format == eFormatHex) || |
| Enrico Granata | 7ec18e3 | 2012-08-09 19:33:34 +0000 | [diff] [blame] | 1747 | (custom_format == eFormatHexUppercase) || |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1748 | (custom_format == eFormatFloat) || |
| 1749 | (custom_format == eFormatOctal) || |
| 1750 | (custom_format == eFormatOSType) || |
| 1751 | (custom_format == eFormatUnicode16) || |
| 1752 | (custom_format == eFormatUnicode32) || |
| 1753 | (custom_format == eFormatUnsigned) || |
| 1754 | (custom_format == eFormatPointer) || |
| 1755 | (custom_format == eFormatComplexInteger) || |
| 1756 | (custom_format == eFormatComplex) || |
| 1757 | (custom_format == eFormatDefault)) // use the [] operator |
| 1758 | return false; |
| Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1759 | } |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 1760 | } |
| Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 1761 | |
| 1762 | if (only_special) |
| 1763 | return false; |
| 1764 | |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1765 | bool var_success = false; |
| 1766 | |
| 1767 | { |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1768 | const char *cstr = NULL; |
| Enrico Granata | 2c75f11 | 2013-06-21 00:04:51 +0000 | [diff] [blame] | 1769 | |
| 1770 | // this is a local stream that we are using to ensure that the data pointed to by cstr survives |
| 1771 | // long enough for us to copy it to its destination - it is necessary to have this temporary storage |
| 1772 | // area for cases where our desired output is not backed by some other longer-term storage |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1773 | StreamString strm; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1774 | |
| Enrico Granata | 465f4bc | 2014-02-15 01:24:44 +0000 | [diff] [blame] | 1775 | if (custom_format != eFormatInvalid) |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1776 | SetFormat(custom_format); |
| 1777 | |
| 1778 | switch(val_obj_display) |
| 1779 | { |
| 1780 | case eValueObjectRepresentationStyleValue: |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1781 | cstr = GetValueAsCString(); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1782 | break; |
| 1783 | |
| 1784 | case eValueObjectRepresentationStyleSummary: |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1785 | cstr = GetSummaryAsCString(); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1786 | break; |
| 1787 | |
| 1788 | case eValueObjectRepresentationStyleLanguageSpecific: |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1789 | cstr = GetObjectDescription(); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1790 | break; |
| 1791 | |
| 1792 | case eValueObjectRepresentationStyleLocation: |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1793 | cstr = GetLocationAsCString(); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1794 | break; |
| 1795 | |
| 1796 | case eValueObjectRepresentationStyleChildrenCount: |
| Deepak Panickal | 99fbc07 | 2014-03-03 15:39:47 +0000 | [diff] [blame] | 1797 | strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren()); |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1798 | cstr = strm.GetString().c_str(); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1799 | break; |
| 1800 | |
| 1801 | case eValueObjectRepresentationStyleType: |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1802 | cstr = GetTypeName().AsCString(); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1803 | break; |
| Enrico Granata | 2c75f11 | 2013-06-21 00:04:51 +0000 | [diff] [blame] | 1804 | |
| 1805 | case eValueObjectRepresentationStyleName: |
| 1806 | cstr = GetName().AsCString(); |
| 1807 | break; |
| 1808 | |
| 1809 | case eValueObjectRepresentationStyleExpressionPath: |
| 1810 | GetExpressionPath(strm, false); |
| 1811 | cstr = strm.GetString().c_str(); |
| 1812 | break; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1813 | } |
| 1814 | |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1815 | if (!cstr) |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1816 | { |
| 1817 | if (val_obj_display == eValueObjectRepresentationStyleValue) |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1818 | cstr = GetSummaryAsCString(); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1819 | else if (val_obj_display == eValueObjectRepresentationStyleSummary) |
| 1820 | { |
| Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 1821 | if (!CanProvideValue()) |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1822 | { |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1823 | strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString()); |
| 1824 | cstr = strm.GetString().c_str(); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1825 | } |
| 1826 | else |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1827 | cstr = GetValueAsCString(); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1828 | } |
| 1829 | } |
| 1830 | |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1831 | if (cstr) |
| 1832 | s.PutCString(cstr); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1833 | else |
| 1834 | { |
| 1835 | if (m_error.Fail()) |
| Enrico Granata | 0dba9b3 | 2014-01-08 01:36:59 +0000 | [diff] [blame] | 1836 | { |
| 1837 | if (do_dump_error) |
| 1838 | s.Printf("<%s>", m_error.AsCString()); |
| 1839 | else |
| 1840 | return false; |
| 1841 | } |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1842 | else if (val_obj_display == eValueObjectRepresentationStyleSummary) |
| 1843 | s.PutCString("<no summary available>"); |
| 1844 | else if (val_obj_display == eValueObjectRepresentationStyleValue) |
| 1845 | s.PutCString("<no value available>"); |
| 1846 | else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific) |
| 1847 | s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description |
| 1848 | else |
| 1849 | s.PutCString("<no printable representation>"); |
| 1850 | } |
| 1851 | |
| 1852 | // we should only return false here if we could not do *anything* |
| 1853 | // even if we have an error message as output, that's a success |
| 1854 | // from our callers' perspective, so return true |
| 1855 | var_success = true; |
| Enrico Granata | 465f4bc | 2014-02-15 01:24:44 +0000 | [diff] [blame] | 1856 | |
| 1857 | if (custom_format != eFormatInvalid) |
| 1858 | SetFormat(eFormatDefault); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
| Enrico Granata | f4efecd | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1861 | return var_success; |
| Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1862 | } |
| 1863 | |
| Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1864 | addr_t |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1865 | ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type) |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1866 | { |
| Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1867 | if (!UpdateValueIfNeeded(false)) |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1868 | return LLDB_INVALID_ADDRESS; |
| 1869 | |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1870 | switch (m_value.GetValueType()) |
| 1871 | { |
| 1872 | case Value::eValueTypeScalar: |
| Greg Clayton | 0665a0f | 2012-10-30 18:18:43 +0000 | [diff] [blame] | 1873 | case Value::eValueTypeVector: |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1874 | if (scalar_is_load_address) |
| 1875 | { |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1876 | if(address_type) |
| 1877 | *address_type = eAddressTypeLoad; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1878 | return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 1879 | } |
| 1880 | break; |
| 1881 | |
| 1882 | case Value::eValueTypeLoadAddress: |
| 1883 | case Value::eValueTypeFileAddress: |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1884 | { |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1885 | if(address_type) |
| 1886 | *address_type = m_value.GetValueAddressType (); |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1887 | return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 1888 | } |
| 1889 | break; |
| Siva Chandra | a3747a9 | 2015-05-04 19:43:34 +0000 | [diff] [blame] | 1890 | case Value::eValueTypeHostAddress: |
| Siva Chandra | e32f2b5 | 2015-05-05 00:41:35 +0000 | [diff] [blame] | 1891 | { |
| 1892 | if(address_type) |
| 1893 | *address_type = m_value.GetValueAddressType (); |
| 1894 | return LLDB_INVALID_ADDRESS; |
| 1895 | } |
| Siva Chandra | a3747a9 | 2015-05-04 19:43:34 +0000 | [diff] [blame] | 1896 | break; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1897 | } |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1898 | if (address_type) |
| 1899 | *address_type = eAddressTypeInvalid; |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1900 | return LLDB_INVALID_ADDRESS; |
| 1901 | } |
| 1902 | |
| 1903 | addr_t |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1904 | ValueObject::GetPointerValue (AddressType *address_type) |
| Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1905 | { |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 1906 | addr_t address = LLDB_INVALID_ADDRESS; |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1907 | if(address_type) |
| 1908 | *address_type = eAddressTypeInvalid; |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1909 | |
| Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1910 | if (!UpdateValueIfNeeded(false)) |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1911 | return address; |
| 1912 | |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 1913 | switch (m_value.GetValueType()) |
| Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1914 | { |
| 1915 | case Value::eValueTypeScalar: |
| Greg Clayton | 0665a0f | 2012-10-30 18:18:43 +0000 | [diff] [blame] | 1916 | case Value::eValueTypeVector: |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1917 | address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1918 | break; |
| 1919 | |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1920 | case Value::eValueTypeHostAddress: |
| Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1921 | case Value::eValueTypeLoadAddress: |
| 1922 | case Value::eValueTypeFileAddress: |
| Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1923 | { |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1924 | lldb::offset_t data_offset = 0; |
| Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1925 | address = m_data.GetPointer(&data_offset); |
| Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1926 | } |
| 1927 | break; |
| 1928 | } |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1929 | |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 1930 | if (address_type) |
| 1931 | *address_type = GetAddressTypeOfChildren(); |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1932 | |
| Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 1933 | return address; |
| 1934 | } |
| 1935 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1936 | bool |
| Enrico Granata | 07a4ac2 | 2012-05-08 21:25:06 +0000 | [diff] [blame] | 1937 | ValueObject::SetValueFromCString (const char *value_str, Error& error) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1938 | { |
| Enrico Granata | 07a4ac2 | 2012-05-08 21:25:06 +0000 | [diff] [blame] | 1939 | error.Clear(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1940 | // Make sure our value is up to date first so that our location and location |
| 1941 | // type is valid. |
| Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 1942 | if (!UpdateValueIfNeeded(false)) |
| Enrico Granata | 07a4ac2 | 2012-05-08 21:25:06 +0000 | [diff] [blame] | 1943 | { |
| 1944 | error.SetErrorString("unable to read value"); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1945 | return false; |
| Enrico Granata | 07a4ac2 | 2012-05-08 21:25:06 +0000 | [diff] [blame] | 1946 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1947 | |
| Greg Clayton | faac111 | 2013-03-14 18:31:44 +0000 | [diff] [blame] | 1948 | uint64_t count = 0; |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1949 | const Encoding encoding = GetCompilerType().GetEncoding (count); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1950 | |
| Greg Clayton | b132097 | 2010-07-14 00:18:15 +0000 | [diff] [blame] | 1951 | const size_t byte_size = GetByteSize(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1952 | |
| Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 1953 | Value::ValueType value_type = m_value.GetValueType(); |
| 1954 | |
| 1955 | if (value_type == Value::eValueTypeScalar) |
| 1956 | { |
| 1957 | // If the value is already a scalar, then let the scalar change itself: |
| 1958 | m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size); |
| 1959 | } |
| Sagar Thakur | 8536fd1 | 2015-08-20 09:12:46 +0000 | [diff] [blame] | 1960 | else if (byte_size <= 16) |
| Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 1961 | { |
| 1962 | // If the value fits in a scalar, then make a new scalar and again let the |
| 1963 | // scalar code do the conversion, then figure out where to put the new value. |
| 1964 | Scalar new_scalar; |
| Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 1965 | error = new_scalar.SetValueFromCString (value_str, encoding, byte_size); |
| 1966 | if (error.Success()) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1967 | { |
| Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1968 | switch (value_type) |
| 1969 | { |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1970 | case Value::eValueTypeLoadAddress: |
| Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 1971 | { |
| 1972 | // If it is a load address, then the scalar value is the storage location |
| 1973 | // of the data, and we have to shove this value down to that load location. |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1974 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 1975 | Process *process = exe_ctx.GetProcessPtr(); |
| 1976 | if (process) |
| Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 1977 | { |
| Enrico Granata | 48ea80f | 2012-10-24 20:24:39 +0000 | [diff] [blame] | 1978 | addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1979 | size_t bytes_written = process->WriteScalarToMemory (target_addr, |
| 1980 | new_scalar, |
| 1981 | byte_size, |
| 1982 | error); |
| Enrico Granata | 07a4ac2 | 2012-05-08 21:25:06 +0000 | [diff] [blame] | 1983 | if (!error.Success()) |
| 1984 | return false; |
| 1985 | if (bytes_written != byte_size) |
| 1986 | { |
| 1987 | error.SetErrorString("unable to write value to memory"); |
| 1988 | return false; |
| 1989 | } |
| Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 1990 | } |
| 1991 | } |
| Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1992 | break; |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 1993 | case Value::eValueTypeHostAddress: |
| Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 1994 | { |
| 1995 | // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data. |
| 1996 | DataExtractor new_data; |
| 1997 | new_data.SetByteOrder (m_data.GetByteOrder()); |
| 1998 | |
| 1999 | DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0)); |
| 2000 | m_data.SetData(buffer_sp, 0); |
| 2001 | bool success = new_scalar.GetData(new_data); |
| 2002 | if (success) |
| 2003 | { |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 2004 | new_data.CopyByteOrderedData (0, |
| 2005 | byte_size, |
| 2006 | const_cast<uint8_t *>(m_data.GetDataStart()), |
| 2007 | byte_size, |
| 2008 | m_data.GetByteOrder()); |
| Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 2009 | } |
| 2010 | m_value.GetScalar() = (uintptr_t)m_data.GetDataStart(); |
| 2011 | |
| 2012 | } |
| Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 2013 | break; |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 2014 | case Value::eValueTypeFileAddress: |
| 2015 | case Value::eValueTypeScalar: |
| Greg Clayton | 0665a0f | 2012-10-30 18:18:43 +0000 | [diff] [blame] | 2016 | case Value::eValueTypeVector: |
| 2017 | break; |
| Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 2018 | } |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2019 | } |
| 2020 | else |
| 2021 | { |
| Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 2022 | return false; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2023 | } |
| Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 2024 | } |
| 2025 | else |
| 2026 | { |
| 2027 | // We don't support setting things bigger than a scalar at present. |
| Enrico Granata | 07a4ac2 | 2012-05-08 21:25:06 +0000 | [diff] [blame] | 2028 | error.SetErrorString("unable to write aggregate data type"); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2029 | return false; |
| 2030 | } |
| Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 2031 | |
| 2032 | // If we have reached this point, then we have successfully changed the value. |
| 2033 | SetNeedsUpdate(); |
| 2034 | return true; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
| Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 2037 | bool |
| 2038 | ValueObject::GetDeclaration (Declaration &decl) |
| 2039 | { |
| 2040 | decl.Clear(); |
| 2041 | return false; |
| 2042 | } |
| 2043 | |
| Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 2044 | ConstString |
| 2045 | ValueObject::GetTypeName() |
| 2046 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2047 | return GetCompilerType().GetConstTypeName(); |
| Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | ConstString |
| Enrico Granata | e8daa2f | 2014-05-17 19:14:17 +0000 | [diff] [blame] | 2051 | ValueObject::GetDisplayTypeName() |
| 2052 | { |
| 2053 | return GetTypeName(); |
| 2054 | } |
| 2055 | |
| 2056 | ConstString |
| Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 2057 | ValueObject::GetQualifiedTypeName() |
| 2058 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2059 | return GetCompilerType().GetConstQualifiedTypeName(); |
| Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2063 | LanguageType |
| Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 2064 | ValueObject::GetObjectRuntimeLanguage () |
| 2065 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2066 | return GetCompilerType().GetMinimumLanguage (); |
| Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 2067 | } |
| 2068 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2069 | void |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2070 | ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2071 | { |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2072 | m_synthetic_children[key] = valobj; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | ValueObjectSP |
| 2076 | ValueObject::GetSyntheticChild (const ConstString &key) const |
| 2077 | { |
| 2078 | ValueObjectSP synthetic_child_sp; |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2079 | std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2080 | if (pos != m_synthetic_children.end()) |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2081 | synthetic_child_sp = pos->second->GetSP(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2082 | return synthetic_child_sp; |
| 2083 | } |
| 2084 | |
| Greg Clayton | 2452ab7 | 2013-02-08 22:02:02 +0000 | [diff] [blame] | 2085 | uint32_t |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 2086 | ValueObject::GetTypeInfo (CompilerType *pointee_or_element_compiler_type) |
| Greg Clayton | 2452ab7 | 2013-02-08 22:02:02 +0000 | [diff] [blame] | 2087 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 2088 | return GetCompilerType().GetTypeInfo (pointee_or_element_compiler_type); |
| Greg Clayton | 2452ab7 | 2013-02-08 22:02:02 +0000 | [diff] [blame] | 2089 | } |
| 2090 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2091 | bool |
| 2092 | ValueObject::IsPointerType () |
| 2093 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2094 | return GetCompilerType().IsPointerType(); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
| Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 2097 | bool |
| Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 2098 | ValueObject::IsArrayType () |
| 2099 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2100 | return GetCompilerType().IsArrayType (NULL, NULL, NULL); |
| Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | bool |
| Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 2104 | ValueObject::IsScalarType () |
| 2105 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2106 | return GetCompilerType().IsScalarType (); |
| Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | bool |
| Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 2110 | ValueObject::IsIntegerType (bool &is_signed) |
| 2111 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2112 | return GetCompilerType().IsIntegerType (is_signed); |
| Jim Ingham | b7603bb | 2011-03-18 00:05:18 +0000 | [diff] [blame] | 2113 | } |
| Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2114 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2115 | bool |
| 2116 | ValueObject::IsPointerOrReferenceType () |
| 2117 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2118 | return GetCompilerType().IsPointerOrReferenceType (); |
| Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | bool |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 2122 | ValueObject::IsPossibleDynamicType () |
| 2123 | { |
| Enrico Granata | fd4c84e | 2012-05-21 16:51:35 +0000 | [diff] [blame] | 2124 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 2125 | Process *process = exe_ctx.GetProcessPtr(); |
| 2126 | if (process) |
| 2127 | return process->IsPossibleDynamicValue(*this); |
| 2128 | else |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2129 | return GetCompilerType().IsPossibleDynamicType (NULL, true, true); |
| Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 2130 | } |
| 2131 | |
| Enrico Granata | 9e7b388 | 2012-12-13 23:50:33 +0000 | [diff] [blame] | 2132 | bool |
| Enrico Granata | 560558e | 2015-02-11 02:35:39 +0000 | [diff] [blame] | 2133 | ValueObject::IsRuntimeSupportValue () |
| 2134 | { |
| 2135 | Process *process(GetProcessSP().get()); |
| 2136 | if (process) |
| 2137 | { |
| 2138 | LanguageRuntime *runtime = process->GetLanguageRuntime(GetObjectRuntimeLanguage()); |
| 2139 | if (!runtime) |
| 2140 | runtime = process->GetObjCLanguageRuntime(); |
| 2141 | if (runtime) |
| 2142 | return runtime->IsRuntimeSupportValue(*this); |
| 2143 | } |
| 2144 | return false; |
| 2145 | } |
| 2146 | |
| 2147 | bool |
| Enrico Granata | 608d67c | 2015-11-10 22:39:15 +0000 | [diff] [blame^] | 2148 | ValueObject::IsNilReference () |
| Enrico Granata | 9e7b388 | 2012-12-13 23:50:33 +0000 | [diff] [blame] | 2149 | { |
| Enrico Granata | 608d67c | 2015-11-10 22:39:15 +0000 | [diff] [blame^] | 2150 | if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage())) |
| 2151 | { |
| 2152 | return language->IsNilReference(*this); |
| 2153 | } |
| 2154 | return false; |
| 2155 | } |
| 2156 | |
| 2157 | bool |
| 2158 | ValueObject::IsUninitializedReference () |
| 2159 | { |
| 2160 | if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage())) |
| 2161 | { |
| 2162 | return language->IsUninitializedReference(*this); |
| 2163 | } |
| 2164 | return false; |
| Enrico Granata | 9e7b388 | 2012-12-13 23:50:33 +0000 | [diff] [blame] | 2165 | } |
| 2166 | |
| Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 2167 | // This allows you to create an array member using and index |
| 2168 | // that doesn't not fall in the normal bounds of the array. |
| 2169 | // Many times structure can be defined as: |
| 2170 | // struct Collection |
| 2171 | // { |
| 2172 | // uint32_t item_count; |
| 2173 | // Item item_array[0]; |
| 2174 | // }; |
| 2175 | // The size of the "item_array" is 1, but many times in practice |
| 2176 | // there are more items in "item_array". |
| 2177 | |
| 2178 | ValueObjectSP |
| Bruce Mitchener | 11d8636 | 2015-02-26 23:55:39 +0000 | [diff] [blame] | 2179 | ValueObject::GetSyntheticArrayMember (size_t index, bool can_create) |
| Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 2180 | { |
| 2181 | ValueObjectSP synthetic_child_sp; |
| Bruce Mitchener | 11d8636 | 2015-02-26 23:55:39 +0000 | [diff] [blame] | 2182 | if (IsPointerType () || IsArrayType()) |
| Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 2183 | { |
| 2184 | char index_str[64]; |
| Deepak Panickal | 99fbc07 | 2014-03-03 15:39:47 +0000 | [diff] [blame] | 2185 | snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index); |
| Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 2186 | ConstString index_const_str(index_str); |
| 2187 | // Check if we have already created a synthetic array member in this |
| 2188 | // valid object. If we have we will re-use it. |
| 2189 | synthetic_child_sp = GetSyntheticChild (index_const_str); |
| 2190 | if (!synthetic_child_sp) |
| 2191 | { |
| 2192 | ValueObject *synthetic_child; |
| 2193 | // We haven't made a synthetic array member for INDEX yet, so |
| 2194 | // lets make one and cache it for any future reference. |
| 2195 | synthetic_child = CreateChildAtIndex(0, true, index); |
| Bruce Mitchener | 11d8636 | 2015-02-26 23:55:39 +0000 | [diff] [blame] | 2196 | |
| Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 2197 | // Cache the value if we got one back... |
| 2198 | if (synthetic_child) |
| 2199 | { |
| 2200 | AddSyntheticChild(index_const_str, synthetic_child); |
| 2201 | synthetic_child_sp = synthetic_child->GetSP(); |
| Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2202 | synthetic_child_sp->SetName(ConstString(index_str)); |
| Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 2203 | synthetic_child_sp->m_is_array_item_for_pointer = true; |
| 2204 | } |
| 2205 | } |
| 2206 | } |
| 2207 | return synthetic_child_sp; |
| 2208 | } |
| 2209 | |
| Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 2210 | ValueObjectSP |
| 2211 | ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create) |
| 2212 | { |
| 2213 | ValueObjectSP synthetic_child_sp; |
| 2214 | if (IsScalarType ()) |
| 2215 | { |
| 2216 | char index_str[64]; |
| 2217 | snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to); |
| 2218 | ConstString index_const_str(index_str); |
| 2219 | // Check if we have already created a synthetic array member in this |
| 2220 | // valid object. If we have we will re-use it. |
| 2221 | synthetic_child_sp = GetSyntheticChild (index_const_str); |
| 2222 | if (!synthetic_child_sp) |
| 2223 | { |
| Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 2224 | // We haven't made a synthetic array member for INDEX yet, so |
| 2225 | // lets make one and cache it for any future reference. |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2226 | ValueObjectChild *synthetic_child = new ValueObjectChild (*this, |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 2227 | GetCompilerType(), |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2228 | index_const_str, |
| 2229 | GetByteSize(), |
| 2230 | 0, |
| 2231 | to-from+1, |
| 2232 | from, |
| 2233 | false, |
| 2234 | false, |
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 2235 | eAddressTypeInvalid, |
| 2236 | 0); |
| Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 2237 | |
| 2238 | // Cache the value if we got one back... |
| 2239 | if (synthetic_child) |
| 2240 | { |
| 2241 | AddSyntheticChild(index_const_str, synthetic_child); |
| 2242 | synthetic_child_sp = synthetic_child->GetSP(); |
| Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2243 | synthetic_child_sp->SetName(ConstString(index_str)); |
| Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 2244 | synthetic_child_sp->m_is_bitfield_for_scalar = true; |
| 2245 | } |
| 2246 | } |
| 2247 | } |
| 2248 | return synthetic_child_sp; |
| 2249 | } |
| 2250 | |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2251 | ValueObjectSP |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2252 | ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create) |
| Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2253 | { |
| 2254 | |
| 2255 | ValueObjectSP synthetic_child_sp; |
| 2256 | |
| 2257 | char name_str[64]; |
| 2258 | snprintf(name_str, sizeof(name_str), "@%i", offset); |
| 2259 | ConstString name_const_str(name_str); |
| 2260 | |
| 2261 | // Check if we have already created a synthetic array member in this |
| 2262 | // valid object. If we have we will re-use it. |
| 2263 | synthetic_child_sp = GetSyntheticChild (name_const_str); |
| 2264 | |
| 2265 | if (synthetic_child_sp.get()) |
| 2266 | return synthetic_child_sp; |
| 2267 | |
| 2268 | if (!can_create) |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2269 | return ValueObjectSP(); |
| Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2270 | |
| Enrico Granata | 951bdd5 | 2015-01-28 01:09:45 +0000 | [diff] [blame] | 2271 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 2272 | |
| Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2273 | ValueObjectChild *synthetic_child = new ValueObjectChild(*this, |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2274 | type, |
| Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2275 | name_const_str, |
| Greg Clayton | 526ae04 | 2015-02-12 00:34:25 +0000 | [diff] [blame] | 2276 | type.GetByteSize(exe_ctx.GetBestExecutionContextScope()), |
| Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2277 | offset, |
| 2278 | 0, |
| 2279 | 0, |
| 2280 | false, |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 2281 | false, |
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 2282 | eAddressTypeInvalid, |
| 2283 | 0); |
| Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2284 | if (synthetic_child) |
| 2285 | { |
| 2286 | AddSyntheticChild(name_const_str, synthetic_child); |
| 2287 | synthetic_child_sp = synthetic_child->GetSP(); |
| 2288 | synthetic_child_sp->SetName(name_const_str); |
| 2289 | synthetic_child_sp->m_is_child_at_offset = true; |
| 2290 | } |
| 2291 | return synthetic_child_sp; |
| 2292 | } |
| 2293 | |
| Enrico Granata | 32556cd | 2014-08-26 20:54:04 +0000 | [diff] [blame] | 2294 | ValueObjectSP |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 2295 | ValueObject::GetSyntheticBase (uint32_t offset, const CompilerType& type, bool can_create) |
| Enrico Granata | 32556cd | 2014-08-26 20:54:04 +0000 | [diff] [blame] | 2296 | { |
| 2297 | ValueObjectSP synthetic_child_sp; |
| 2298 | |
| 2299 | char name_str[64]; |
| 2300 | snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>")); |
| 2301 | ConstString name_const_str(name_str); |
| 2302 | |
| 2303 | // Check if we have already created a synthetic array member in this |
| 2304 | // valid object. If we have we will re-use it. |
| 2305 | synthetic_child_sp = GetSyntheticChild (name_const_str); |
| 2306 | |
| 2307 | if (synthetic_child_sp.get()) |
| 2308 | return synthetic_child_sp; |
| 2309 | |
| 2310 | if (!can_create) |
| 2311 | return ValueObjectSP(); |
| 2312 | |
| Enrico Granata | 32556cd | 2014-08-26 20:54:04 +0000 | [diff] [blame] | 2313 | const bool is_base_class = true; |
| 2314 | |
| Enrico Granata | 951bdd5 | 2015-01-28 01:09:45 +0000 | [diff] [blame] | 2315 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 2316 | |
| Enrico Granata | 32556cd | 2014-08-26 20:54:04 +0000 | [diff] [blame] | 2317 | ValueObjectChild *synthetic_child = new ValueObjectChild(*this, |
| 2318 | type, |
| 2319 | name_const_str, |
| Greg Clayton | 526ae04 | 2015-02-12 00:34:25 +0000 | [diff] [blame] | 2320 | type.GetByteSize(exe_ctx.GetBestExecutionContextScope()), |
| Enrico Granata | 32556cd | 2014-08-26 20:54:04 +0000 | [diff] [blame] | 2321 | offset, |
| 2322 | 0, |
| 2323 | 0, |
| 2324 | is_base_class, |
| 2325 | false, |
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 2326 | eAddressTypeInvalid, |
| 2327 | 0); |
| Enrico Granata | 32556cd | 2014-08-26 20:54:04 +0000 | [diff] [blame] | 2328 | if (synthetic_child) |
| 2329 | { |
| 2330 | AddSyntheticChild(name_const_str, synthetic_child); |
| 2331 | synthetic_child_sp = synthetic_child->GetSP(); |
| 2332 | synthetic_child_sp->SetName(name_const_str); |
| 2333 | } |
| 2334 | return synthetic_child_sp; |
| 2335 | } |
| 2336 | |
| 2337 | |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 2338 | // your expression path needs to have a leading . or -> |
| 2339 | // (unless it somehow "looks like" an array, in which case it has |
| 2340 | // a leading [ symbol). while the [ is meaningful and should be shown |
| 2341 | // to the user, . and -> are just parser design, but by no means |
| 2342 | // added information for the user.. strip them off |
| 2343 | static const char* |
| 2344 | SkipLeadingExpressionPathSeparators(const char* expression) |
| 2345 | { |
| 2346 | if (!expression || !expression[0]) |
| 2347 | return expression; |
| 2348 | if (expression[0] == '.') |
| 2349 | return expression+1; |
| 2350 | if (expression[0] == '-' && expression[1] == '>') |
| 2351 | return expression+2; |
| 2352 | return expression; |
| 2353 | } |
| 2354 | |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2355 | ValueObjectSP |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 2356 | ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create) |
| 2357 | { |
| 2358 | ValueObjectSP synthetic_child_sp; |
| 2359 | ConstString name_const_string(expression); |
| 2360 | // Check if we have already created a synthetic array member in this |
| 2361 | // valid object. If we have we will re-use it. |
| 2362 | synthetic_child_sp = GetSyntheticChild (name_const_string); |
| 2363 | if (!synthetic_child_sp) |
| 2364 | { |
| 2365 | // We haven't made a synthetic array member for expression yet, so |
| 2366 | // lets make one and cache it for any future reference. |
| Enrico Granata | df31a8a | 2012-08-02 17:34:05 +0000 | [diff] [blame] | 2367 | synthetic_child_sp = GetValueForExpressionPath(expression, |
| 2368 | NULL, NULL, NULL, |
| Enrico Granata | ef238c1 | 2015-03-12 22:30:58 +0000 | [diff] [blame] | 2369 | GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None)); |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 2370 | |
| 2371 | // Cache the value if we got one back... |
| 2372 | if (synthetic_child_sp.get()) |
| 2373 | { |
| Enrico Granata | ea2bc0f | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 2374 | // FIXME: this causes a "real" child to end up with its name changed to the contents of expression |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 2375 | AddSyntheticChild(name_const_string, synthetic_child_sp.get()); |
| Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2376 | synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression))); |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 2377 | } |
| 2378 | } |
| 2379 | return synthetic_child_sp; |
| 2380 | } |
| 2381 | |
| 2382 | void |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2383 | ValueObject::CalculateSyntheticValue (bool use_synthetic) |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 2384 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2385 | if (use_synthetic == false) |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 2386 | return; |
| 2387 | |
| Enrico Granata | c5bc412 | 2012-03-27 02:35:13 +0000 | [diff] [blame] | 2388 | TargetSP target_sp(GetTargetSP()); |
| Enrico Granata | 5d5f60c | 2013-09-24 22:58:37 +0000 | [diff] [blame] | 2389 | if (target_sp && target_sp->GetEnableSyntheticValue() == false) |
| Enrico Granata | c5bc412 | 2012-03-27 02:35:13 +0000 | [diff] [blame] | 2390 | { |
| 2391 | m_synthetic_value = NULL; |
| 2392 | return; |
| 2393 | } |
| 2394 | |
| Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 2395 | lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp); |
| 2396 | |
| Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 2397 | if (!UpdateFormatsIfNeeded() && m_synthetic_value) |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2398 | return; |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 2399 | |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 2400 | if (m_synthetic_children_sp.get() == NULL) |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 2401 | return; |
| 2402 | |
| Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 2403 | if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value) |
| 2404 | return; |
| 2405 | |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2406 | m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp); |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 2407 | } |
| 2408 | |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2409 | void |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2410 | ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic) |
| Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 2411 | { |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2412 | if (use_dynamic == eNoDynamicValues) |
| Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 2413 | return; |
| 2414 | |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2415 | if (!m_dynamic_value && !IsDynamic()) |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2416 | { |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 2417 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 2418 | Process *process = exe_ctx.GetProcessPtr(); |
| Enrico Granata | fd4c84e | 2012-05-21 16:51:35 +0000 | [diff] [blame] | 2419 | if (process && process->IsPossibleDynamicValue(*this)) |
| Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 2420 | { |
| 2421 | ClearDynamicTypeInformation (); |
| Enrico Granata | fd4c84e | 2012-05-21 16:51:35 +0000 | [diff] [blame] | 2422 | m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic); |
| Enrico Granata | e3e9151 | 2012-10-22 18:18:36 +0000 | [diff] [blame] | 2423 | } |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2424 | } |
| 2425 | } |
| 2426 | |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2427 | ValueObjectSP |
| Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 2428 | ValueObject::GetDynamicValue (DynamicValueType use_dynamic) |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2429 | { |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2430 | if (use_dynamic == eNoDynamicValues) |
| Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 2431 | return ValueObjectSP(); |
| 2432 | |
| 2433 | if (!IsDynamic() && m_dynamic_value == NULL) |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2434 | { |
| Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 2435 | CalculateDynamicValue(use_dynamic); |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2436 | } |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 2437 | if (m_dynamic_value) |
| 2438 | return m_dynamic_value->GetSP(); |
| 2439 | else |
| 2440 | return ValueObjectSP(); |
| Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 2441 | } |
| Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2442 | |
| Jim Ingham | 60dbabb | 2011-12-08 19:44:08 +0000 | [diff] [blame] | 2443 | ValueObjectSP |
| 2444 | ValueObject::GetStaticValue() |
| 2445 | { |
| 2446 | return GetSP(); |
| 2447 | } |
| 2448 | |
| Enrico Granata | 886147f | 2012-05-08 18:47:08 +0000 | [diff] [blame] | 2449 | lldb::ValueObjectSP |
| 2450 | ValueObject::GetNonSyntheticValue () |
| 2451 | { |
| 2452 | return GetSP(); |
| 2453 | } |
| 2454 | |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 2455 | ValueObjectSP |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2456 | ValueObject::GetSyntheticValue (bool use_synthetic) |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 2457 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2458 | if (use_synthetic == false) |
| 2459 | return ValueObjectSP(); |
| 2460 | |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 2461 | CalculateSyntheticValue(use_synthetic); |
| 2462 | |
| 2463 | if (m_synthetic_value) |
| 2464 | return m_synthetic_value->GetSP(); |
| 2465 | else |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2466 | return ValueObjectSP(); |
| Enrico Granata | d55546b | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 2467 | } |
| 2468 | |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2469 | bool |
| Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 2470 | ValueObject::HasSyntheticValue() |
| 2471 | { |
| Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 2472 | UpdateFormatsIfNeeded(); |
| Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 2473 | |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 2474 | if (m_synthetic_children_sp.get() == NULL) |
| Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 2475 | return false; |
| 2476 | |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2477 | CalculateSyntheticValue(true); |
| Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 2478 | |
| 2479 | if (m_synthetic_value) |
| 2480 | return true; |
| 2481 | else |
| 2482 | return false; |
| 2483 | } |
| 2484 | |
| 2485 | bool |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2486 | ValueObject::GetBaseClassPath (Stream &s) |
| 2487 | { |
| 2488 | if (IsBaseClass()) |
| 2489 | { |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2490 | bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s); |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 2491 | CompilerType compiler_type = GetCompilerType(); |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2492 | std::string cxx_class_name; |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 2493 | bool this_had_base_class = ClangASTContext::GetCXXClassName (compiler_type, cxx_class_name); |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2494 | if (this_had_base_class) |
| 2495 | { |
| 2496 | if (parent_had_base_class) |
| 2497 | s.PutCString("::"); |
| 2498 | s.PutCString(cxx_class_name.c_str()); |
| 2499 | } |
| 2500 | return parent_had_base_class || this_had_base_class; |
| 2501 | } |
| 2502 | return false; |
| 2503 | } |
| 2504 | |
| 2505 | |
| 2506 | ValueObject * |
| 2507 | ValueObject::GetNonBaseClassParent() |
| 2508 | { |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2509 | if (GetParent()) |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2510 | { |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2511 | if (GetParent()->IsBaseClass()) |
| 2512 | return GetParent()->GetNonBaseClassParent(); |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2513 | else |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2514 | return GetParent(); |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2515 | } |
| 2516 | return NULL; |
| 2517 | } |
| Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2518 | |
| Enrico Granata | a3c8f04 | 2014-08-19 22:29:08 +0000 | [diff] [blame] | 2519 | |
| 2520 | bool |
| 2521 | ValueObject::IsBaseClass (uint32_t& depth) |
| 2522 | { |
| 2523 | if (!IsBaseClass()) |
| 2524 | { |
| 2525 | depth = 0; |
| 2526 | return false; |
| 2527 | } |
| 2528 | if (GetParent()) |
| 2529 | { |
| 2530 | GetParent()->IsBaseClass(depth); |
| 2531 | depth = depth + 1; |
| 2532 | return true; |
| 2533 | } |
| 2534 | // TODO: a base of no parent? weird.. |
| 2535 | depth = 1; |
| 2536 | return true; |
| 2537 | } |
| 2538 | |
| Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 2539 | void |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2540 | ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat) |
| Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2541 | { |
| Enrico Granata | 986fa5f | 2014-12-09 21:41:16 +0000 | [diff] [blame] | 2542 | // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways |
| 2543 | // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return |
| 2544 | // something that can hopefully be used in expression |
| 2545 | if (m_is_synthetic_children_generated) |
| 2546 | { |
| 2547 | UpdateValueIfNeeded(); |
| 2548 | |
| 2549 | if (m_value.GetValueType() == Value::eValueTypeLoadAddress) |
| 2550 | { |
| 2551 | if (IsPointerOrReferenceType()) |
| 2552 | { |
| 2553 | s.Printf("((%s)0x%" PRIx64 ")", |
| 2554 | GetTypeName().AsCString("void"), |
| 2555 | GetValueAsUnsigned(0)); |
| 2556 | return; |
| 2557 | } |
| 2558 | else |
| 2559 | { |
| 2560 | uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); |
| 2561 | if (load_addr != LLDB_INVALID_ADDRESS) |
| 2562 | { |
| 2563 | s.Printf("(*( (%s *)0x%" PRIx64 "))", |
| 2564 | GetTypeName().AsCString("void"), |
| 2565 | load_addr); |
| 2566 | return; |
| 2567 | } |
| 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | if (CanProvideValue()) |
| 2572 | { |
| 2573 | s.Printf("((%s)%s)", |
| 2574 | GetTypeName().AsCString("void"), |
| 2575 | GetValueAsCString()); |
| 2576 | return; |
| 2577 | } |
| 2578 | |
| 2579 | return; |
| 2580 | } |
| 2581 | |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2582 | const bool is_deref_of_parent = IsDereferenceOfParent (); |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2583 | |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2584 | if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers) |
| Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 2585 | { |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2586 | // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely |
| 2587 | // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName. |
| 2588 | // the eHonorPointers mode is meant to produce strings in this latter format |
| 2589 | s.PutCString("*("); |
| 2590 | } |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2591 | |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2592 | ValueObject* parent = GetParent(); |
| 2593 | |
| 2594 | if (parent) |
| 2595 | parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat); |
| Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 2596 | |
| 2597 | // if we are a deref_of_parent just because we are synthetic array |
| 2598 | // members made up to allow ptr[%d] syntax to work in variable |
| 2599 | // printing, then add our name ([%d]) to the expression path |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2600 | if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers) |
| Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 2601 | s.PutCString(m_name.AsCString()); |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2602 | |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2603 | if (!IsBaseClass()) |
| 2604 | { |
| 2605 | if (!is_deref_of_parent) |
| Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2606 | { |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2607 | ValueObject *non_base_class_parent = GetNonBaseClassParent(); |
| 2608 | if (non_base_class_parent) |
| Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2609 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 2610 | CompilerType non_base_class_parent_compiler_type = non_base_class_parent->GetCompilerType(); |
| 2611 | if (non_base_class_parent_compiler_type) |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2612 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2613 | if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers) |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2614 | { |
| 2615 | s.PutCString("->"); |
| 2616 | } |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2617 | else |
| 2618 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 2619 | const uint32_t non_base_class_parent_type_info = non_base_class_parent_compiler_type.GetTypeInfo(); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2620 | |
| Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 2621 | if (non_base_class_parent_type_info & eTypeIsPointer) |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2622 | { |
| 2623 | s.PutCString("->"); |
| 2624 | } |
| Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 2625 | else if ((non_base_class_parent_type_info & eTypeHasChildren) && |
| 2626 | !(non_base_class_parent_type_info & eTypeIsArray)) |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2627 | { |
| 2628 | s.PutChar('.'); |
| 2629 | } |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2630 | } |
| 2631 | } |
| Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2632 | } |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2633 | |
| 2634 | const char *name = GetName().GetCString(); |
| 2635 | if (name) |
| Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2636 | { |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2637 | if (qualify_cxx_base_classes) |
| 2638 | { |
| 2639 | if (GetBaseClassPath (s)) |
| 2640 | s.PutCString("::"); |
| 2641 | } |
| 2642 | s.PutCString(name); |
| Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2643 | } |
| 2644 | } |
| 2645 | } |
| 2646 | |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2647 | if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers) |
| Enrico Granata | 85933ed | 2011-08-18 16:38:26 +0000 | [diff] [blame] | 2648 | { |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 2649 | s.PutChar(')'); |
| Enrico Granata | 4becb37 | 2011-06-29 22:27:15 +0000 | [diff] [blame] | 2650 | } |
| Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2651 | } |
| 2652 | |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2653 | ValueObjectSP |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2654 | ValueObject::GetValueForExpressionPath(const char* expression, |
| 2655 | const char** first_unparsed, |
| 2656 | ExpressionPathScanEndReason* reason_to_stop, |
| 2657 | ExpressionPathEndResultType* final_value_type, |
| 2658 | const GetValueForExpressionPathOptions& options, |
| 2659 | ExpressionPathAftermath* final_task_on_target) |
| 2660 | { |
| 2661 | |
| 2662 | const char* dummy_first_unparsed; |
| Enrico Granata | ea2bc0f | 2013-02-21 19:57:10 +0000 | [diff] [blame] | 2663 | ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown; |
| 2664 | ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2665 | ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2666 | |
| 2667 | ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression, |
| 2668 | first_unparsed ? first_unparsed : &dummy_first_unparsed, |
| 2669 | reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, |
| 2670 | final_value_type ? final_value_type : &dummy_final_value_type, |
| 2671 | options, |
| 2672 | final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); |
| 2673 | |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2674 | if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing) |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2675 | return ret_val; |
| Enrico Granata | 385ad4e | 2012-03-03 00:45:57 +0000 | [diff] [blame] | 2676 | |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2677 | if (ret_val.get() && ((final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress of plain objects |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2678 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2679 | if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference) |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2680 | { |
| 2681 | Error error; |
| 2682 | ValueObjectSP final_value = ret_val->Dereference(error); |
| 2683 | if (error.Fail() || !final_value.get()) |
| 2684 | { |
| Enrico Granata | 385ad4e | 2012-03-03 00:45:57 +0000 | [diff] [blame] | 2685 | if (reason_to_stop) |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2686 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed; |
| Enrico Granata | 385ad4e | 2012-03-03 00:45:57 +0000 | [diff] [blame] | 2687 | if (final_value_type) |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2688 | *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2689 | return ValueObjectSP(); |
| 2690 | } |
| 2691 | else |
| 2692 | { |
| Enrico Granata | 385ad4e | 2012-03-03 00:45:57 +0000 | [diff] [blame] | 2693 | if (final_task_on_target) |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2694 | *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2695 | return final_value; |
| 2696 | } |
| 2697 | } |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2698 | if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress) |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2699 | { |
| 2700 | Error error; |
| 2701 | ValueObjectSP final_value = ret_val->AddressOf(error); |
| 2702 | if (error.Fail() || !final_value.get()) |
| 2703 | { |
| Enrico Granata | 385ad4e | 2012-03-03 00:45:57 +0000 | [diff] [blame] | 2704 | if (reason_to_stop) |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2705 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed; |
| Enrico Granata | 385ad4e | 2012-03-03 00:45:57 +0000 | [diff] [blame] | 2706 | if (final_value_type) |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2707 | *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2708 | return ValueObjectSP(); |
| 2709 | } |
| 2710 | else |
| 2711 | { |
| Enrico Granata | 385ad4e | 2012-03-03 00:45:57 +0000 | [diff] [blame] | 2712 | if (final_task_on_target) |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2713 | *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2714 | return final_value; |
| 2715 | } |
| 2716 | } |
| 2717 | } |
| 2718 | return ret_val; // final_task_on_target will still have its original value, so you know I did not do it |
| 2719 | } |
| 2720 | |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2721 | int |
| 2722 | ValueObject::GetValuesForExpressionPath(const char* expression, |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2723 | ValueObjectListSP& list, |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2724 | const char** first_unparsed, |
| 2725 | ExpressionPathScanEndReason* reason_to_stop, |
| 2726 | ExpressionPathEndResultType* final_value_type, |
| 2727 | const GetValueForExpressionPathOptions& options, |
| 2728 | ExpressionPathAftermath* final_task_on_target) |
| 2729 | { |
| 2730 | const char* dummy_first_unparsed; |
| 2731 | ExpressionPathScanEndReason dummy_reason_to_stop; |
| 2732 | ExpressionPathEndResultType dummy_final_value_type; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2733 | ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2734 | |
| 2735 | ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression, |
| 2736 | first_unparsed ? first_unparsed : &dummy_first_unparsed, |
| 2737 | reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, |
| 2738 | final_value_type ? final_value_type : &dummy_final_value_type, |
| 2739 | options, |
| 2740 | final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); |
| 2741 | |
| 2742 | if (!ret_val.get()) // if there are errors, I add nothing to the list |
| 2743 | return 0; |
| 2744 | |
| Enrico Granata | 86ea8d8 | 2012-03-29 01:34:34 +0000 | [diff] [blame] | 2745 | if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2746 | { |
| 2747 | // I need not expand a range, just post-process the final value and return |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2748 | if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2749 | { |
| 2750 | list->Append(ret_val); |
| 2751 | return 1; |
| 2752 | } |
| Enrico Granata | 86ea8d8 | 2012-03-29 01:34:34 +0000 | [diff] [blame] | 2753 | if (ret_val.get() && (final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain) // I can only deref and takeaddress of plain objects |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2754 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2755 | if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2756 | { |
| 2757 | Error error; |
| 2758 | ValueObjectSP final_value = ret_val->Dereference(error); |
| 2759 | if (error.Fail() || !final_value.get()) |
| 2760 | { |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 2761 | if (reason_to_stop) |
| 2762 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed; |
| 2763 | if (final_value_type) |
| 2764 | *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2765 | return 0; |
| 2766 | } |
| 2767 | else |
| 2768 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2769 | *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2770 | list->Append(final_value); |
| 2771 | return 1; |
| 2772 | } |
| 2773 | } |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2774 | if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2775 | { |
| 2776 | Error error; |
| 2777 | ValueObjectSP final_value = ret_val->AddressOf(error); |
| 2778 | if (error.Fail() || !final_value.get()) |
| 2779 | { |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 2780 | if (reason_to_stop) |
| 2781 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed; |
| 2782 | if (final_value_type) |
| 2783 | *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2784 | return 0; |
| 2785 | } |
| 2786 | else |
| 2787 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2788 | *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2789 | list->Append(final_value); |
| 2790 | return 1; |
| 2791 | } |
| 2792 | } |
| 2793 | } |
| 2794 | } |
| 2795 | else |
| 2796 | { |
| 2797 | return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed, |
| 2798 | first_unparsed ? first_unparsed : &dummy_first_unparsed, |
| 2799 | ret_val, |
| 2800 | list, |
| 2801 | reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, |
| 2802 | final_value_type ? final_value_type : &dummy_final_value_type, |
| 2803 | options, |
| 2804 | final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); |
| 2805 | } |
| 2806 | // in any non-covered case, just do the obviously right thing |
| 2807 | list->Append(ret_val); |
| 2808 | return 1; |
| 2809 | } |
| 2810 | |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 2811 | ValueObjectSP |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2812 | ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr, |
| 2813 | const char** first_unparsed, |
| 2814 | ExpressionPathScanEndReason* reason_to_stop, |
| 2815 | ExpressionPathEndResultType* final_result, |
| 2816 | const GetValueForExpressionPathOptions& options, |
| 2817 | ExpressionPathAftermath* what_next) |
| 2818 | { |
| 2819 | ValueObjectSP root = GetSP(); |
| 2820 | |
| 2821 | if (!root.get()) |
| 2822 | return ValueObjectSP(); |
| 2823 | |
| 2824 | *first_unparsed = expression_cstr; |
| 2825 | |
| 2826 | while (true) |
| 2827 | { |
| 2828 | |
| 2829 | const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr |
| 2830 | |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 2831 | CompilerType root_compiler_type = root->GetCompilerType(); |
| 2832 | CompilerType pointee_compiler_type; |
| 2833 | Flags pointee_compiler_type_info; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2834 | |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 2835 | Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type)); |
| 2836 | if (pointee_compiler_type) |
| 2837 | pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo()); |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2838 | |
| 2839 | if (!expression_cstr || *expression_cstr == '\0') |
| 2840 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2841 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2842 | return root; |
| 2843 | } |
| 2844 | |
| 2845 | switch (*expression_cstr) |
| 2846 | { |
| 2847 | case '-': |
| 2848 | { |
| 2849 | if (options.m_check_dot_vs_arrow_syntax && |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 2850 | root_compiler_type_info.Test(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] | 2851 | { |
| 2852 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2853 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot; |
| 2854 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2855 | return ValueObjectSP(); |
| 2856 | } |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 2857 | if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden |
| 2858 | root_compiler_type_info.Test(eTypeIsPointer) && |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2859 | options.m_no_fragile_ivar) |
| 2860 | { |
| 2861 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2862 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed; |
| 2863 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2864 | return ValueObjectSP(); |
| 2865 | } |
| 2866 | if (expression_cstr[1] != '>') |
| 2867 | { |
| 2868 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2869 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 2870 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2871 | return ValueObjectSP(); |
| 2872 | } |
| 2873 | expression_cstr++; // skip the - |
| 2874 | } |
| 2875 | case '.': // or fallthrough from -> |
| 2876 | { |
| 2877 | if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' && |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 2878 | root_compiler_type_info.Test(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] | 2879 | { |
| 2880 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2881 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow; |
| 2882 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2883 | return ValueObjectSP(); |
| 2884 | } |
| 2885 | expression_cstr++; // skip . |
| 2886 | const char *next_separator = strpbrk(expression_cstr+1,"-.["); |
| 2887 | ConstString child_name; |
| 2888 | if (!next_separator) // if no other separator just expand this last layer |
| 2889 | { |
| 2890 | child_name.SetCString (expression_cstr); |
| Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2891 | ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true); |
| 2892 | |
| 2893 | 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] | 2894 | { |
| Daniel Malea | a85e6b6 | 2012-12-07 22:21:08 +0000 | [diff] [blame] | 2895 | *first_unparsed = ""; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2896 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString; |
| 2897 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2898 | return child_valobj_sp; |
| 2899 | } |
| Enrico Granata | ef238c1 | 2015-03-12 22:30:58 +0000 | [diff] [blame] | 2900 | else |
| Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2901 | { |
| Enrico Granata | ef238c1 | 2015-03-12 22:30:58 +0000 | [diff] [blame] | 2902 | switch (options.m_synthetic_children_traversal) |
| Enrico Granata | df31a8a | 2012-08-02 17:34:05 +0000 | [diff] [blame] | 2903 | { |
| Enrico Granata | ef238c1 | 2015-03-12 22:30:58 +0000 | [diff] [blame] | 2904 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None: |
| 2905 | break; |
| 2906 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic: |
| 2907 | if (root->IsSynthetic()) |
| 2908 | { |
| 2909 | child_valobj_sp = root->GetNonSyntheticValue(); |
| 2910 | if (child_valobj_sp.get()) |
| 2911 | child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 2912 | } |
| 2913 | break; |
| 2914 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic: |
| 2915 | if (!root->IsSynthetic()) |
| 2916 | { |
| 2917 | child_valobj_sp = root->GetSyntheticValue(); |
| 2918 | if (child_valobj_sp.get()) |
| 2919 | child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 2920 | } |
| 2921 | break; |
| 2922 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both: |
| 2923 | if (root->IsSynthetic()) |
| 2924 | { |
| 2925 | child_valobj_sp = root->GetNonSyntheticValue(); |
| 2926 | if (child_valobj_sp.get()) |
| 2927 | child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 2928 | } |
| 2929 | else |
| 2930 | { |
| 2931 | child_valobj_sp = root->GetSyntheticValue(); |
| 2932 | if (child_valobj_sp.get()) |
| 2933 | child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 2934 | } |
| 2935 | break; |
| Enrico Granata | df31a8a | 2012-08-02 17:34:05 +0000 | [diff] [blame] | 2936 | } |
| Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2937 | } |
| 2938 | |
| 2939 | // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP, |
| 2940 | // so we hit the "else" branch, and return an error |
| 2941 | if(child_valobj_sp.get()) // if it worked, just return |
| 2942 | { |
| Daniel Malea | a85e6b6 | 2012-12-07 22:21:08 +0000 | [diff] [blame] | 2943 | *first_unparsed = ""; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2944 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString; |
| 2945 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2946 | return child_valobj_sp; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2947 | } |
| 2948 | else |
| 2949 | { |
| 2950 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2951 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 2952 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2953 | return ValueObjectSP(); |
| 2954 | } |
| 2955 | } |
| 2956 | else // other layers do expand |
| 2957 | { |
| 2958 | child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr); |
| Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2959 | ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true); |
| 2960 | if (child_valobj_sp.get()) // store the new root and move on |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 2961 | { |
| Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2962 | root = child_valobj_sp; |
| 2963 | *first_unparsed = next_separator; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 2964 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2965 | continue; |
| 2966 | } |
| Enrico Granata | ef238c1 | 2015-03-12 22:30:58 +0000 | [diff] [blame] | 2967 | else |
| Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 2968 | { |
| Enrico Granata | ef238c1 | 2015-03-12 22:30:58 +0000 | [diff] [blame] | 2969 | switch (options.m_synthetic_children_traversal) |
| Enrico Granata | df31a8a | 2012-08-02 17:34:05 +0000 | [diff] [blame] | 2970 | { |
| Enrico Granata | ef238c1 | 2015-03-12 22:30:58 +0000 | [diff] [blame] | 2971 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None: |
| 2972 | break; |
| 2973 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic: |
| 2974 | if (root->IsSynthetic()) |
| 2975 | { |
| 2976 | child_valobj_sp = root->GetNonSyntheticValue(); |
| 2977 | if (child_valobj_sp.get()) |
| 2978 | child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 2979 | } |
| 2980 | break; |
| 2981 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic: |
| 2982 | if (!root->IsSynthetic()) |
| 2983 | { |
| 2984 | child_valobj_sp = root->GetSyntheticValue(); |
| 2985 | if (child_valobj_sp.get()) |
| 2986 | child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 2987 | } |
| 2988 | break; |
| 2989 | case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both: |
| 2990 | if (root->IsSynthetic()) |
| 2991 | { |
| 2992 | child_valobj_sp = root->GetNonSyntheticValue(); |
| 2993 | if (child_valobj_sp.get()) |
| 2994 | child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 2995 | } |
| 2996 | else |
| 2997 | { |
| 2998 | child_valobj_sp = root->GetSyntheticValue(); |
| 2999 | if (child_valobj_sp.get()) |
| 3000 | child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 3001 | } |
| 3002 | break; |
| Enrico Granata | df31a8a | 2012-08-02 17:34:05 +0000 | [diff] [blame] | 3003 | } |
| Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 3004 | } |
| 3005 | |
| 3006 | // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP, |
| 3007 | // so we hit the "else" branch, and return an error |
| 3008 | if(child_valobj_sp.get()) // if it worked, move on |
| 3009 | { |
| 3010 | root = child_valobj_sp; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3011 | *first_unparsed = next_separator; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3012 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3013 | continue; |
| 3014 | } |
| 3015 | else |
| 3016 | { |
| 3017 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3018 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 3019 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3020 | return ValueObjectSP(); |
| 3021 | } |
| 3022 | } |
| 3023 | break; |
| 3024 | } |
| 3025 | case '[': |
| 3026 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3027 | if (!root_compiler_type_info.Test(eTypeIsArray) && !root_compiler_type_info.Test(eTypeIsPointer) && !root_compiler_type_info.Test(eTypeIsVector)) // if this is not a T[] nor a T* |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3028 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3029 | if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even a scalar... |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3030 | { |
| Enrico Granata | ef238c1 | 2015-03-12 22:30:58 +0000 | [diff] [blame] | 3031 | if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None) // ...only chance left is synthetic |
| Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 3032 | { |
| 3033 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3034 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid; |
| 3035 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 3036 | return ValueObjectSP(); |
| 3037 | } |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3038 | } |
| 3039 | else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields |
| 3040 | { |
| 3041 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3042 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed; |
| 3043 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3044 | return ValueObjectSP(); |
| 3045 | } |
| 3046 | } |
| 3047 | if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays |
| 3048 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3049 | if (!root_compiler_type_info.Test(eTypeIsArray)) |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3050 | { |
| 3051 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3052 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; |
| 3053 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3054 | return ValueObjectSP(); |
| 3055 | } |
| 3056 | else // even if something follows, we cannot expand unbounded ranges, just let the caller do it |
| 3057 | { |
| 3058 | *first_unparsed = expression_cstr+2; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3059 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet; |
| 3060 | *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3061 | return root; |
| 3062 | } |
| 3063 | } |
| 3064 | const char *separator_position = ::strchr(expression_cstr+1,'-'); |
| 3065 | const char *close_bracket_position = ::strchr(expression_cstr+1,']'); |
| 3066 | if (!close_bracket_position) // if there is no ], this is a syntax error |
| 3067 | { |
| 3068 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3069 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 3070 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3071 | return ValueObjectSP(); |
| 3072 | } |
| 3073 | if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N] |
| 3074 | { |
| 3075 | char *end = NULL; |
| 3076 | unsigned long index = ::strtoul (expression_cstr+1, &end, 0); |
| 3077 | if (!end || end != close_bracket_position) // if something weird is in our way return an error |
| 3078 | { |
| 3079 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3080 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 3081 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3082 | return ValueObjectSP(); |
| 3083 | } |
| 3084 | if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays |
| 3085 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3086 | if (root_compiler_type_info.Test(eTypeIsArray)) |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3087 | { |
| 3088 | *first_unparsed = expression_cstr+2; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3089 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet; |
| 3090 | *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3091 | return root; |
| 3092 | } |
| 3093 | else |
| 3094 | { |
| 3095 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3096 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; |
| 3097 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3098 | return ValueObjectSP(); |
| 3099 | } |
| 3100 | } |
| 3101 | // from here on we do have a valid index |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3102 | if (root_compiler_type_info.Test(eTypeIsArray)) |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3103 | { |
| Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 3104 | ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true); |
| 3105 | if (!child_valobj_sp) |
| Bruce Mitchener | 11d8636 | 2015-02-26 23:55:39 +0000 | [diff] [blame] | 3106 | child_valobj_sp = root->GetSyntheticArrayMember(index, true); |
| Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 3107 | if (!child_valobj_sp) |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3108 | if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index) |
| 3109 | child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true); |
| Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 3110 | if (child_valobj_sp) |
| 3111 | { |
| 3112 | root = child_valobj_sp; |
| 3113 | *first_unparsed = end+1; // skip ] |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3114 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 3115 | continue; |
| 3116 | } |
| 3117 | else |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3118 | { |
| 3119 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3120 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 3121 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3122 | return ValueObjectSP(); |
| 3123 | } |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3124 | } |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3125 | else if (root_compiler_type_info.Test(eTypeIsPointer)) |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3126 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3127 | if (*what_next == ValueObject::eExpressionPathAftermathDereference && // 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 |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3128 | pointee_compiler_type_info.Test(eTypeIsScalar)) |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3129 | { |
| 3130 | Error error; |
| 3131 | root = root->Dereference(error); |
| 3132 | if (error.Fail() || !root.get()) |
| 3133 | { |
| 3134 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3135 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed; |
| 3136 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3137 | return ValueObjectSP(); |
| 3138 | } |
| 3139 | else |
| 3140 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3141 | *what_next = eExpressionPathAftermathNothing; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3142 | continue; |
| 3143 | } |
| 3144 | } |
| 3145 | else |
| 3146 | { |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3147 | if (root->GetCompilerType().GetMinimumLanguage() == eLanguageTypeObjC |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3148 | && pointee_compiler_type_info.AllClear(eTypeIsPointer) |
| Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 3149 | && root->HasSyntheticValue() |
| Enrico Granata | ef238c1 | 2015-03-12 22:30:58 +0000 | [diff] [blame] | 3150 | && (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic || |
| 3151 | options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both)) |
| Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 3152 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3153 | root = root->GetSyntheticValue()->GetChildAtIndex(index, true); |
| Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 3154 | } |
| 3155 | else |
| Bruce Mitchener | 11d8636 | 2015-02-26 23:55:39 +0000 | [diff] [blame] | 3156 | root = root->GetSyntheticArrayMember(index, true); |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3157 | if (!root.get()) |
| 3158 | { |
| 3159 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3160 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 3161 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3162 | return ValueObjectSP(); |
| 3163 | } |
| 3164 | else |
| 3165 | { |
| 3166 | *first_unparsed = end+1; // skip ] |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3167 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3168 | continue; |
| 3169 | } |
| 3170 | } |
| 3171 | } |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3172 | else if (root_compiler_type_info.Test(eTypeIsScalar)) |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3173 | { |
| 3174 | root = root->GetSyntheticBitFieldChild(index, index, true); |
| 3175 | if (!root.get()) |
| 3176 | { |
| 3177 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3178 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 3179 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3180 | return ValueObjectSP(); |
| 3181 | } |
| 3182 | else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing |
| 3183 | { |
| 3184 | *first_unparsed = end+1; // skip ] |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3185 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet; |
| 3186 | *final_result = ValueObject::eExpressionPathEndResultTypeBitfield; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3187 | return root; |
| 3188 | } |
| 3189 | } |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3190 | else if (root_compiler_type_info.Test(eTypeIsVector)) |
| Enrico Granata | 08a1bb8 | 2013-06-19 00:00:45 +0000 | [diff] [blame] | 3191 | { |
| 3192 | root = root->GetChildAtIndex(index, true); |
| 3193 | if (!root.get()) |
| 3194 | { |
| 3195 | *first_unparsed = expression_cstr; |
| 3196 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 3197 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| 3198 | return ValueObjectSP(); |
| 3199 | } |
| 3200 | else |
| 3201 | { |
| 3202 | *first_unparsed = end+1; // skip ] |
| 3203 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| 3204 | continue; |
| 3205 | } |
| 3206 | } |
| Enrico Granata | ef238c1 | 2015-03-12 22:30:58 +0000 | [diff] [blame] | 3207 | else if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic || |
| 3208 | options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both) |
| Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 3209 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3210 | if (root->HasSyntheticValue()) |
| 3211 | root = root->GetSyntheticValue(); |
| 3212 | else if (!root->IsSynthetic()) |
| 3213 | { |
| 3214 | *first_unparsed = expression_cstr; |
| 3215 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing; |
| 3216 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| 3217 | return ValueObjectSP(); |
| 3218 | } |
| 3219 | // if we are here, then root itself is a synthetic VO.. should be good to go |
| 3220 | |
| Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 3221 | if (!root.get()) |
| 3222 | { |
| 3223 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3224 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing; |
| 3225 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| 3226 | return ValueObjectSP(); |
| 3227 | } |
| 3228 | root = root->GetChildAtIndex(index, true); |
| 3229 | if (!root.get()) |
| 3230 | { |
| 3231 | *first_unparsed = expression_cstr; |
| 3232 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 3233 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 3234 | return ValueObjectSP(); |
| 3235 | } |
| Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 3236 | else |
| 3237 | { |
| 3238 | *first_unparsed = end+1; // skip ] |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3239 | *final_result = ValueObject::eExpressionPathEndResultTypePlain; |
| Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 3240 | continue; |
| 3241 | } |
| Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 3242 | } |
| 3243 | else |
| 3244 | { |
| 3245 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3246 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 3247 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 3248 | return ValueObjectSP(); |
| 3249 | } |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3250 | } |
| 3251 | else // we have a low and a high index |
| 3252 | { |
| 3253 | char *end = NULL; |
| 3254 | unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0); |
| 3255 | if (!end || end != separator_position) // if something weird is in our way return an error |
| 3256 | { |
| 3257 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3258 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 3259 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3260 | return ValueObjectSP(); |
| 3261 | } |
| 3262 | unsigned long index_higher = ::strtoul (separator_position+1, &end, 0); |
| 3263 | if (!end || end != close_bracket_position) // if something weird is in our way return an error |
| 3264 | { |
| 3265 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3266 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 3267 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3268 | return ValueObjectSP(); |
| 3269 | } |
| 3270 | if (index_lower > index_higher) // swap indices if required |
| 3271 | { |
| 3272 | unsigned long temp = index_lower; |
| 3273 | index_lower = index_higher; |
| 3274 | index_higher = temp; |
| 3275 | } |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3276 | if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3277 | { |
| 3278 | root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true); |
| 3279 | if (!root.get()) |
| 3280 | { |
| 3281 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3282 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 3283 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3284 | return ValueObjectSP(); |
| 3285 | } |
| 3286 | else |
| 3287 | { |
| 3288 | *first_unparsed = end+1; // skip ] |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3289 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet; |
| 3290 | *final_result = ValueObject::eExpressionPathEndResultTypeBitfield; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3291 | return root; |
| 3292 | } |
| 3293 | } |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3294 | else if (root_compiler_type_info.Test(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 | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3295 | *what_next == ValueObject::eExpressionPathAftermathDereference && |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3296 | pointee_compiler_type_info.Test(eTypeIsScalar)) |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3297 | { |
| 3298 | Error error; |
| 3299 | root = root->Dereference(error); |
| 3300 | if (error.Fail() || !root.get()) |
| 3301 | { |
| 3302 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3303 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed; |
| 3304 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3305 | return ValueObjectSP(); |
| 3306 | } |
| 3307 | else |
| 3308 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3309 | *what_next = ValueObject::eExpressionPathAftermathNothing; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3310 | continue; |
| 3311 | } |
| 3312 | } |
| 3313 | else |
| 3314 | { |
| 3315 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3316 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet; |
| 3317 | *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3318 | return root; |
| 3319 | } |
| 3320 | } |
| 3321 | break; |
| 3322 | } |
| 3323 | default: // some non-separator is in the way |
| 3324 | { |
| 3325 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3326 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 3327 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | fc7a7f3 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 3328 | return ValueObjectSP(); |
| 3329 | break; |
| 3330 | } |
| 3331 | } |
| 3332 | } |
| 3333 | } |
| 3334 | |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3335 | int |
| 3336 | ValueObject::ExpandArraySliceExpression(const char* expression_cstr, |
| 3337 | const char** first_unparsed, |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3338 | ValueObjectSP root, |
| 3339 | ValueObjectListSP& list, |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3340 | ExpressionPathScanEndReason* reason_to_stop, |
| 3341 | ExpressionPathEndResultType* final_result, |
| 3342 | const GetValueForExpressionPathOptions& options, |
| 3343 | ExpressionPathAftermath* what_next) |
| 3344 | { |
| 3345 | if (!root.get()) |
| 3346 | return 0; |
| 3347 | |
| 3348 | *first_unparsed = expression_cstr; |
| 3349 | |
| 3350 | while (true) |
| 3351 | { |
| 3352 | |
| 3353 | const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr |
| 3354 | |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3355 | CompilerType root_compiler_type = root->GetCompilerType(); |
| 3356 | CompilerType pointee_compiler_type; |
| 3357 | Flags pointee_compiler_type_info; |
| 3358 | Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type)); |
| 3359 | if (pointee_compiler_type) |
| 3360 | pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo()); |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3361 | |
| 3362 | if (!expression_cstr || *expression_cstr == '\0') |
| 3363 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3364 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3365 | list->Append(root); |
| 3366 | return 1; |
| 3367 | } |
| 3368 | |
| 3369 | switch (*expression_cstr) |
| 3370 | { |
| 3371 | case '[': |
| 3372 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3373 | if (!root_compiler_type_info.Test(eTypeIsArray) && !root_compiler_type_info.Test(eTypeIsPointer)) // if this is not a T[] nor a T* |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3374 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3375 | if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong! |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3376 | { |
| 3377 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3378 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid; |
| 3379 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3380 | return 0; |
| 3381 | } |
| 3382 | else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields |
| 3383 | { |
| 3384 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3385 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed; |
| 3386 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3387 | return 0; |
| 3388 | } |
| 3389 | } |
| 3390 | if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays |
| 3391 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3392 | if (!root_compiler_type_info.Test(eTypeIsArray)) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3393 | { |
| 3394 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3395 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; |
| 3396 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3397 | return 0; |
| 3398 | } |
| 3399 | else // expand this into list |
| 3400 | { |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3401 | const size_t max_index = root->GetNumChildren() - 1; |
| 3402 | for (size_t index = 0; index < max_index; index++) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3403 | { |
| 3404 | ValueObjectSP child = |
| 3405 | root->GetChildAtIndex(index, true); |
| 3406 | list->Append(child); |
| 3407 | } |
| 3408 | *first_unparsed = expression_cstr+2; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3409 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; |
| 3410 | *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3411 | return max_index; // tell me number of items I added to the VOList |
| 3412 | } |
| 3413 | } |
| 3414 | const char *separator_position = ::strchr(expression_cstr+1,'-'); |
| 3415 | const char *close_bracket_position = ::strchr(expression_cstr+1,']'); |
| 3416 | if (!close_bracket_position) // if there is no ], this is a syntax error |
| 3417 | { |
| 3418 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3419 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 3420 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3421 | return 0; |
| 3422 | } |
| 3423 | if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N] |
| 3424 | { |
| 3425 | char *end = NULL; |
| 3426 | unsigned long index = ::strtoul (expression_cstr+1, &end, 0); |
| 3427 | if (!end || end != close_bracket_position) // if something weird is in our way return an error |
| 3428 | { |
| 3429 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3430 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 3431 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3432 | return 0; |
| 3433 | } |
| 3434 | if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays |
| 3435 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3436 | if (root_compiler_type_info.Test(eTypeIsArray)) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3437 | { |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3438 | const size_t max_index = root->GetNumChildren() - 1; |
| 3439 | for (size_t index = 0; index < max_index; index++) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3440 | { |
| 3441 | ValueObjectSP child = |
| 3442 | root->GetChildAtIndex(index, true); |
| 3443 | list->Append(child); |
| 3444 | } |
| 3445 | *first_unparsed = expression_cstr+2; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3446 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; |
| 3447 | *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3448 | return max_index; // tell me number of items I added to the VOList |
| 3449 | } |
| 3450 | else |
| 3451 | { |
| 3452 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3453 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; |
| 3454 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3455 | return 0; |
| 3456 | } |
| 3457 | } |
| 3458 | // from here on we do have a valid index |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3459 | if (root_compiler_type_info.Test(eTypeIsArray)) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3460 | { |
| 3461 | root = root->GetChildAtIndex(index, true); |
| 3462 | if (!root.get()) |
| 3463 | { |
| 3464 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3465 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 3466 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3467 | return 0; |
| 3468 | } |
| 3469 | else |
| 3470 | { |
| 3471 | list->Append(root); |
| 3472 | *first_unparsed = end+1; // skip ] |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3473 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; |
| 3474 | *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3475 | return 1; |
| 3476 | } |
| 3477 | } |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3478 | else if (root_compiler_type_info.Test(eTypeIsPointer)) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3479 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3480 | if (*what_next == ValueObject::eExpressionPathAftermathDereference && // 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 |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3481 | pointee_compiler_type_info.Test(eTypeIsScalar)) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3482 | { |
| 3483 | Error error; |
| 3484 | root = root->Dereference(error); |
| 3485 | if (error.Fail() || !root.get()) |
| 3486 | { |
| 3487 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3488 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed; |
| 3489 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3490 | return 0; |
| 3491 | } |
| 3492 | else |
| 3493 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3494 | *what_next = eExpressionPathAftermathNothing; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3495 | continue; |
| 3496 | } |
| 3497 | } |
| 3498 | else |
| 3499 | { |
| Bruce Mitchener | 11d8636 | 2015-02-26 23:55:39 +0000 | [diff] [blame] | 3500 | root = root->GetSyntheticArrayMember(index, true); |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3501 | if (!root.get()) |
| 3502 | { |
| 3503 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3504 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 3505 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3506 | return 0; |
| 3507 | } |
| 3508 | else |
| 3509 | { |
| 3510 | list->Append(root); |
| 3511 | *first_unparsed = end+1; // skip ] |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3512 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; |
| 3513 | *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3514 | return 1; |
| 3515 | } |
| 3516 | } |
| 3517 | } |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3518 | else /*if (ClangASTContext::IsScalarType(root_compiler_type))*/ |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3519 | { |
| 3520 | root = root->GetSyntheticBitFieldChild(index, index, true); |
| 3521 | if (!root.get()) |
| 3522 | { |
| 3523 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3524 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 3525 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3526 | return 0; |
| 3527 | } |
| 3528 | else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing |
| 3529 | { |
| 3530 | list->Append(root); |
| 3531 | *first_unparsed = end+1; // skip ] |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3532 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; |
| 3533 | *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3534 | return 1; |
| 3535 | } |
| 3536 | } |
| 3537 | } |
| 3538 | else // we have a low and a high index |
| 3539 | { |
| 3540 | char *end = NULL; |
| 3541 | unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0); |
| 3542 | if (!end || end != separator_position) // if something weird is in our way return an error |
| 3543 | { |
| 3544 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3545 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 3546 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3547 | return 0; |
| 3548 | } |
| 3549 | unsigned long index_higher = ::strtoul (separator_position+1, &end, 0); |
| 3550 | if (!end || end != close_bracket_position) // if something weird is in our way return an error |
| 3551 | { |
| 3552 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3553 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 3554 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3555 | return 0; |
| 3556 | } |
| 3557 | if (index_lower > index_higher) // swap indices if required |
| 3558 | { |
| 3559 | unsigned long temp = index_lower; |
| 3560 | index_lower = index_higher; |
| 3561 | index_higher = temp; |
| 3562 | } |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3563 | if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3564 | { |
| 3565 | root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true); |
| 3566 | if (!root.get()) |
| 3567 | { |
| 3568 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3569 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; |
| 3570 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3571 | return 0; |
| 3572 | } |
| 3573 | else |
| 3574 | { |
| 3575 | list->Append(root); |
| 3576 | *first_unparsed = end+1; // skip ] |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3577 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; |
| 3578 | *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3579 | return 1; |
| 3580 | } |
| 3581 | } |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3582 | else if (root_compiler_type_info.Test(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 | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3583 | *what_next == ValueObject::eExpressionPathAftermathDereference && |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3584 | pointee_compiler_type_info.Test(eTypeIsScalar)) |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3585 | { |
| 3586 | Error error; |
| 3587 | root = root->Dereference(error); |
| 3588 | if (error.Fail() || !root.get()) |
| 3589 | { |
| 3590 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3591 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed; |
| 3592 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3593 | return 0; |
| 3594 | } |
| 3595 | else |
| 3596 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3597 | *what_next = ValueObject::eExpressionPathAftermathNothing; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3598 | continue; |
| 3599 | } |
| 3600 | } |
| 3601 | else |
| 3602 | { |
| Johnny Chen | 4480530 | 2011-07-19 19:48:13 +0000 | [diff] [blame] | 3603 | for (unsigned long index = index_lower; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3604 | index <= index_higher; index++) |
| 3605 | { |
| 3606 | ValueObjectSP child = |
| 3607 | root->GetChildAtIndex(index, true); |
| 3608 | list->Append(child); |
| 3609 | } |
| 3610 | *first_unparsed = end+1; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3611 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; |
| 3612 | *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3613 | return index_higher-index_lower+1; // tell me number of items I added to the VOList |
| 3614 | } |
| 3615 | } |
| 3616 | break; |
| 3617 | } |
| 3618 | default: // some non-[ separator, or something entirely wrong, is in the way |
| 3619 | { |
| 3620 | *first_unparsed = expression_cstr; |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 3621 | *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; |
| 3622 | *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; |
| Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 3623 | return 0; |
| 3624 | break; |
| 3625 | } |
| 3626 | } |
| 3627 | } |
| 3628 | } |
| 3629 | |
| Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 3630 | void |
| 3631 | ValueObject::LogValueObject (Log *log) |
| Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3632 | { |
| Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 3633 | if (log) |
| Enrico Granata | d595733 | 2015-06-03 20:43:54 +0000 | [diff] [blame] | 3634 | return LogValueObject (log, DumpValueObjectOptions(*this)); |
| Greg Clayton | 1d3afba | 2010-10-05 00:00:42 +0000 | [diff] [blame] | 3635 | } |
| 3636 | |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 3637 | void |
| Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 3638 | ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options) |
| Greg Clayton | f830dbb | 2012-03-22 18:15:37 +0000 | [diff] [blame] | 3639 | { |
| Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 3640 | if (log) |
| Greg Clayton | f830dbb | 2012-03-22 18:15:37 +0000 | [diff] [blame] | 3641 | { |
| 3642 | StreamString s; |
| Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 3643 | Dump (s, options); |
| Greg Clayton | f830dbb | 2012-03-22 18:15:37 +0000 | [diff] [blame] | 3644 | if (s.GetSize()) |
| 3645 | log->PutCString(s.GetData()); |
| 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | void |
| Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 3650 | ValueObject::Dump (Stream &s) |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 3651 | { |
| Enrico Granata | d595733 | 2015-06-03 20:43:54 +0000 | [diff] [blame] | 3652 | Dump (s, DumpValueObjectOptions(*this)); |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 3653 | } |
| 3654 | |
| 3655 | void |
| Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 3656 | ValueObject::Dump (Stream &s, |
| 3657 | const DumpValueObjectOptions& options) |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 3658 | { |
| Enrico Granata | 4d93b8c | 2013-09-30 19:11:51 +0000 | [diff] [blame] | 3659 | ValueObjectPrinter printer(this,&s,options); |
| 3660 | printer.PrintValueObject(); |
| Enrico Granata | 0c489f5 | 2012-03-01 04:24:26 +0000 | [diff] [blame] | 3661 | } |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3662 | |
| 3663 | ValueObjectSP |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3664 | ValueObject::CreateConstantValue (const ConstString &name) |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3665 | { |
| 3666 | ValueObjectSP valobj_sp; |
| 3667 | |
| Enrico Granata | c3e320a | 2011-08-02 17:27:39 +0000 | [diff] [blame] | 3668 | if (UpdateValueIfNeeded(false) && m_error.Success()) |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3669 | { |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3670 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3671 | |
| 3672 | DataExtractor data; |
| 3673 | data.SetByteOrder (m_data.GetByteOrder()); |
| 3674 | data.SetAddressByteSize(m_data.GetAddressByteSize()); |
| 3675 | |
| Enrico Granata | 9f1e204 | 2012-04-24 22:15:37 +0000 | [diff] [blame] | 3676 | if (IsBitfield()) |
| 3677 | { |
| 3678 | Value v(Scalar(GetValueAsUnsigned(UINT64_MAX))); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 3679 | m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get()); |
| Enrico Granata | 9f1e204 | 2012-04-24 22:15:37 +0000 | [diff] [blame] | 3680 | } |
| 3681 | else |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 3682 | m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get()); |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3683 | |
| 3684 | valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3685 | GetCompilerType(), |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3686 | name, |
| 3687 | data, |
| 3688 | GetAddressOf()); |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3689 | } |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3690 | |
| 3691 | if (!valobj_sp) |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3692 | { |
| Greg Clayton | eeb1565 | 2013-12-10 23:16:40 +0000 | [diff] [blame] | 3693 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 3694 | valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error); |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3695 | } |
| 3696 | return valobj_sp; |
| 3697 | } |
| 3698 | |
| Enrico Granata | 538a88a | 2014-10-09 18:24:30 +0000 | [diff] [blame] | 3699 | ValueObjectSP |
| 3700 | ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue, |
| 3701 | bool synthValue) |
| 3702 | { |
| 3703 | ValueObjectSP result_sp(GetSP()); |
| 3704 | |
| 3705 | switch (dynValue) |
| 3706 | { |
| 3707 | case lldb::eDynamicCanRunTarget: |
| 3708 | case lldb::eDynamicDontRunTarget: |
| 3709 | { |
| 3710 | if (!result_sp->IsDynamic()) |
| 3711 | { |
| 3712 | if (result_sp->GetDynamicValue(dynValue)) |
| 3713 | result_sp = result_sp->GetDynamicValue(dynValue); |
| 3714 | } |
| 3715 | } |
| 3716 | break; |
| 3717 | case lldb::eNoDynamicValues: |
| Enrico Granata | 538a88a | 2014-10-09 18:24:30 +0000 | [diff] [blame] | 3718 | { |
| 3719 | if (result_sp->IsDynamic()) |
| 3720 | { |
| 3721 | if (result_sp->GetStaticValue()) |
| 3722 | result_sp = result_sp->GetStaticValue(); |
| 3723 | } |
| 3724 | } |
| 3725 | break; |
| 3726 | } |
| 3727 | |
| 3728 | if (synthValue) |
| 3729 | { |
| 3730 | if (!result_sp->IsSynthetic()) |
| 3731 | { |
| 3732 | if (result_sp->GetSyntheticValue()) |
| 3733 | result_sp = result_sp->GetSyntheticValue(); |
| 3734 | } |
| 3735 | } |
| 3736 | else |
| 3737 | { |
| 3738 | if (result_sp->IsSynthetic()) |
| 3739 | { |
| 3740 | if (result_sp->GetNonSyntheticValue()) |
| 3741 | result_sp = result_sp->GetNonSyntheticValue(); |
| 3742 | } |
| 3743 | } |
| 3744 | |
| 3745 | return result_sp; |
| 3746 | } |
| 3747 | |
| Greg Clayton | 759e744 | 2014-07-19 00:12:57 +0000 | [diff] [blame] | 3748 | lldb::addr_t |
| 3749 | ValueObject::GetCPPVTableAddress (AddressType &address_type) |
| 3750 | { |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 3751 | CompilerType pointee_type; |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 3752 | CompilerType this_type(GetCompilerType()); |
| Greg Clayton | 759e744 | 2014-07-19 00:12:57 +0000 | [diff] [blame] | 3753 | uint32_t type_info = this_type.GetTypeInfo(&pointee_type); |
| 3754 | if (type_info) |
| 3755 | { |
| 3756 | bool ptr_or_ref = false; |
| Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 3757 | if (type_info & (eTypeIsPointer | eTypeIsReference)) |
| Greg Clayton | 759e744 | 2014-07-19 00:12:57 +0000 | [diff] [blame] | 3758 | { |
| 3759 | ptr_or_ref = true; |
| 3760 | type_info = pointee_type.GetTypeInfo(); |
| 3761 | } |
| 3762 | |
| Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 3763 | const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus; |
| Greg Clayton | 759e744 | 2014-07-19 00:12:57 +0000 | [diff] [blame] | 3764 | if ((type_info & cpp_class) == cpp_class) |
| 3765 | { |
| 3766 | if (ptr_or_ref) |
| 3767 | { |
| 3768 | address_type = GetAddressTypeOfChildren(); |
| 3769 | return GetValueAsUnsigned(LLDB_INVALID_ADDRESS); |
| 3770 | } |
| 3771 | else |
| 3772 | return GetAddressOf (false, &address_type); |
| 3773 | } |
| 3774 | } |
| 3775 | |
| 3776 | address_type = eAddressTypeInvalid; |
| 3777 | return LLDB_INVALID_ADDRESS; |
| 3778 | } |
| 3779 | |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3780 | ValueObjectSP |
| Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 3781 | ValueObject::Dereference (Error &error) |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3782 | { |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 3783 | if (m_deref_valobj) |
| 3784 | return m_deref_valobj->GetSP(); |
| Chaoren Lin | d7bdc27 | 2015-07-31 00:35:40 +0000 | [diff] [blame] | 3785 | |
| 3786 | const bool is_pointer_or_reference_type = IsPointerOrReferenceType(); |
| 3787 | if (is_pointer_or_reference_type) |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3788 | { |
| 3789 | bool omit_empty_base_classes = true; |
| Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 3790 | bool ignore_array_bounds = false; |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3791 | |
| 3792 | std::string child_name_str; |
| 3793 | uint32_t child_byte_size = 0; |
| 3794 | int32_t child_byte_offset = 0; |
| 3795 | uint32_t child_bitfield_bit_size = 0; |
| 3796 | uint32_t child_bitfield_bit_offset = 0; |
| 3797 | bool child_is_base_class = false; |
| Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 3798 | bool child_is_deref_of_parent = false; |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3799 | const bool transparent_pointers = false; |
| Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 3800 | CompilerType compiler_type = GetCompilerType(); |
| 3801 | CompilerType child_compiler_type; |
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 3802 | uint64_t language_flags; |
| Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 3803 | |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3804 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| Chaoren Lin | d7bdc27 | 2015-07-31 00:35:40 +0000 | [diff] [blame] | 3805 | |
| Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 3806 | child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex (&exe_ctx, |
| 3807 | 0, |
| 3808 | transparent_pointers, |
| 3809 | omit_empty_base_classes, |
| 3810 | ignore_array_bounds, |
| 3811 | child_name_str, |
| 3812 | child_byte_size, |
| 3813 | child_byte_offset, |
| 3814 | child_bitfield_bit_size, |
| 3815 | child_bitfield_bit_offset, |
| 3816 | child_is_base_class, |
| 3817 | child_is_deref_of_parent, |
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 3818 | this, |
| 3819 | language_flags); |
| Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 3820 | if (child_compiler_type && child_byte_size) |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3821 | { |
| 3822 | ConstString child_name; |
| 3823 | if (!child_name_str.empty()) |
| 3824 | child_name.SetCString (child_name_str.c_str()); |
| 3825 | |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 3826 | m_deref_valobj = new ValueObjectChild (*this, |
| Bruce Mitchener | 4ad8334 | 2015-09-21 16:48:48 +0000 | [diff] [blame] | 3827 | child_compiler_type, |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 3828 | child_name, |
| 3829 | child_byte_size, |
| 3830 | child_byte_offset, |
| 3831 | child_bitfield_bit_size, |
| 3832 | child_bitfield_bit_offset, |
| 3833 | child_is_base_class, |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 3834 | child_is_deref_of_parent, |
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 3835 | eAddressTypeInvalid, |
| 3836 | language_flags); |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3837 | } |
| 3838 | } |
| Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3839 | |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 3840 | if (m_deref_valobj) |
| Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3841 | { |
| 3842 | error.Clear(); |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 3843 | return m_deref_valobj->GetSP(); |
| Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3844 | } |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3845 | else |
| 3846 | { |
| Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3847 | StreamString strm; |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3848 | GetExpressionPath(strm, true); |
| Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3849 | |
| Chaoren Lin | d7bdc27 | 2015-07-31 00:35:40 +0000 | [diff] [blame] | 3850 | if (is_pointer_or_reference_type) |
| Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3851 | error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str()); |
| 3852 | else |
| Chaoren Lin | d7bdc27 | 2015-07-31 00:35:40 +0000 | [diff] [blame] | 3853 | error.SetErrorStringWithFormat("not a pointer or reference type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str()); |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 3854 | return ValueObjectSP(); |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3855 | } |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3856 | } |
| 3857 | |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3858 | ValueObjectSP |
| Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3859 | ValueObject::AddressOf (Error &error) |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3860 | { |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 3861 | if (m_addr_of_valobj_sp) |
| 3862 | return m_addr_of_valobj_sp; |
| 3863 | |
| Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 3864 | AddressType address_type = eAddressTypeInvalid; |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3865 | const bool scalar_is_load_address = false; |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 3866 | addr_t addr = GetAddressOf (scalar_is_load_address, &address_type); |
| Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3867 | error.Clear(); |
| Siva Chandra | a3747a9 | 2015-05-04 19:43:34 +0000 | [diff] [blame] | 3868 | if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost) |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3869 | { |
| 3870 | switch (address_type) |
| 3871 | { |
| 3872 | case eAddressTypeInvalid: |
| Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3873 | { |
| 3874 | StreamString expr_path_strm; |
| Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3875 | GetExpressionPath(expr_path_strm, true); |
| Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3876 | error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str()); |
| 3877 | } |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3878 | break; |
| Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3879 | |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3880 | case eAddressTypeFile: |
| 3881 | case eAddressTypeLoad: |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3882 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3883 | CompilerType compiler_type = GetCompilerType(); |
| 3884 | if (compiler_type) |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3885 | { |
| 3886 | std::string name (1, '&'); |
| 3887 | name.append (m_name.AsCString("")); |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3888 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 3889 | m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3890 | compiler_type.GetPointerType(), |
| Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 3891 | ConstString (name.c_str()), |
| 3892 | addr, |
| 3893 | eAddressTypeInvalid, |
| 3894 | m_data.GetAddressByteSize()); |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3895 | } |
| 3896 | } |
| 3897 | break; |
| Siva Chandra | a3747a9 | 2015-05-04 19:43:34 +0000 | [diff] [blame] | 3898 | default: |
| 3899 | break; |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3900 | } |
| 3901 | } |
| Sean Callanan | ed185ab | 2013-04-19 19:47:32 +0000 | [diff] [blame] | 3902 | else |
| 3903 | { |
| 3904 | StreamString expr_path_strm; |
| 3905 | GetExpressionPath(expr_path_strm, true); |
| 3906 | error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str()); |
| 3907 | } |
| 3908 | |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 3909 | return m_addr_of_valobj_sp; |
| Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3910 | } |
| 3911 | |
| Greg Clayton | 9a142cf | 2012-02-03 05:34:10 +0000 | [diff] [blame] | 3912 | ValueObjectSP |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3913 | ValueObject::Cast (const CompilerType &compiler_type) |
| Greg Clayton | 9a142cf | 2012-02-03 05:34:10 +0000 | [diff] [blame] | 3914 | { |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3915 | return ValueObjectCast::Create (*this, GetName(), compiler_type); |
| Greg Clayton | 9a142cf | 2012-02-03 05:34:10 +0000 | [diff] [blame] | 3916 | } |
| Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3917 | |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3918 | ValueObjectSP |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3919 | ValueObject::CastPointerType (const char *name, CompilerType &compiler_type) |
| Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3920 | { |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3921 | ValueObjectSP valobj_sp; |
| Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3922 | AddressType address_type; |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 3923 | addr_t ptr_value = GetPointerValue (&address_type); |
| Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3924 | |
| 3925 | if (ptr_value != LLDB_INVALID_ADDRESS) |
| 3926 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3927 | Address ptr_addr (ptr_value); |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3928 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 3929 | valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(), |
| Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3930 | name, |
| 3931 | ptr_addr, |
| Bruce Mitchener | 3ad353f | 2015-09-24 03:54:50 +0000 | [diff] [blame] | 3932 | compiler_type); |
| Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3933 | } |
| 3934 | return valobj_sp; |
| 3935 | } |
| 3936 | |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3937 | ValueObjectSP |
| Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3938 | ValueObject::CastPointerType (const char *name, TypeSP &type_sp) |
| 3939 | { |
| Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 3940 | ValueObjectSP valobj_sp; |
| Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3941 | AddressType address_type; |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 3942 | addr_t ptr_value = GetPointerValue (&address_type); |
| Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3943 | |
| 3944 | if (ptr_value != LLDB_INVALID_ADDRESS) |
| 3945 | { |
| Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 3946 | Address ptr_addr (ptr_value); |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3947 | ExecutionContext exe_ctx (GetExecutionContextRef()); |
| 3948 | valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(), |
| Greg Clayton | b2dcc36 | 2011-05-05 23:32:56 +0000 | [diff] [blame] | 3949 | name, |
| 3950 | ptr_addr, |
| 3951 | type_sp); |
| 3952 | } |
| 3953 | return valobj_sp; |
| 3954 | } |
| 3955 | |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3956 | ValueObject::EvaluationPoint::EvaluationPoint () : |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3957 | m_mod_id(), |
| 3958 | m_exe_ctx_ref(), |
| Sean Callanan | 7375f3e | 2014-12-09 21:18:59 +0000 | [diff] [blame] | 3959 | m_needs_update (true) |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3960 | { |
| 3961 | } |
| 3962 | |
| 3963 | ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected): |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3964 | m_mod_id(), |
| 3965 | m_exe_ctx_ref(), |
| Sean Callanan | 7375f3e | 2014-12-09 21:18:59 +0000 | [diff] [blame] | 3966 | m_needs_update (true) |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3967 | { |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3968 | ExecutionContext exe_ctx(exe_scope); |
| 3969 | TargetSP target_sp (exe_ctx.GetTargetSP()); |
| 3970 | if (target_sp) |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3971 | { |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3972 | m_exe_ctx_ref.SetTargetSP (target_sp); |
| 3973 | ProcessSP process_sp (exe_ctx.GetProcessSP()); |
| 3974 | if (!process_sp) |
| 3975 | process_sp = target_sp->GetProcessSP(); |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3976 | |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3977 | if (process_sp) |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3978 | { |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3979 | m_mod_id = process_sp->GetModID(); |
| 3980 | m_exe_ctx_ref.SetProcessSP (process_sp); |
| Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3981 | |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3982 | ThreadSP thread_sp (exe_ctx.GetThreadSP()); |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3983 | |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3984 | if (!thread_sp) |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3985 | { |
| 3986 | if (use_selected) |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3987 | thread_sp = process_sp->GetThreadList().GetSelectedThread(); |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3988 | } |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3989 | |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3990 | if (thread_sp) |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3991 | { |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3992 | m_exe_ctx_ref.SetThreadSP(thread_sp); |
| Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 3993 | |
| Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 3994 | StackFrameSP frame_sp (exe_ctx.GetFrameSP()); |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3995 | if (!frame_sp) |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3996 | { |
| 3997 | if (use_selected) |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 3998 | frame_sp = thread_sp->GetSelectedFrame(); |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 3999 | } |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 4000 | if (frame_sp) |
| 4001 | m_exe_ctx_ref.SetFrameSP(frame_sp); |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 4002 | } |
| 4003 | } |
| 4004 | } |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 4005 | } |
| 4006 | |
| 4007 | ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) : |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 4008 | m_mod_id(), |
| 4009 | m_exe_ctx_ref(rhs.m_exe_ctx_ref), |
| Sean Callanan | 7375f3e | 2014-12-09 21:18:59 +0000 | [diff] [blame] | 4010 | m_needs_update (true) |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 4011 | { |
| 4012 | } |
| 4013 | |
| 4014 | ValueObject::EvaluationPoint::~EvaluationPoint () |
| 4015 | { |
| 4016 | } |
| 4017 | |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 4018 | // This function checks the EvaluationPoint against the current process state. If the current |
| 4019 | // state matches the evaluation point, or the evaluation point is already invalid, then we return |
| 4020 | // false, meaning "no change". If the current state is different, we update our state, and return |
| 4021 | // true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so |
| 4022 | // future calls to NeedsUpdate will return true. |
| Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 4023 | // exe_scope will be set to the current execution context scope. |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 4024 | |
| 4025 | bool |
| Enrico Granata | bb642e5 | 2015-05-16 01:27:00 +0000 | [diff] [blame] | 4026 | ValueObject::EvaluationPoint::SyncWithProcessState(bool accept_invalid_exe_ctx) |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 4027 | { |
| Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 4028 | // Start with the target, if it is NULL, then we're obviously not going to get any further: |
| Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4029 | const bool thread_and_frame_only_if_stopped = true; |
| 4030 | ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped)); |
| Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 4031 | |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 4032 | if (exe_ctx.GetTargetPtr() == NULL) |
| Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 4033 | return false; |
| 4034 | |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 4035 | // If we don't have a process nothing can change. |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 4036 | Process *process = exe_ctx.GetProcessPtr(); |
| 4037 | if (process == NULL) |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 4038 | return false; |
| Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 4039 | |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 4040 | // If our stop id is the current stop ID, nothing has changed: |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 4041 | ProcessModID current_mod_id = process->GetModID(); |
| Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4042 | |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 4043 | // If the current stop id is 0, either we haven't run yet, or the process state has been cleared. |
| 4044 | // 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] | 4045 | if (current_mod_id.GetStopID() == 0) |
| Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 4046 | return false; |
| Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 4047 | |
| Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 4048 | bool changed = false; |
| 4049 | const bool was_valid = m_mod_id.IsValid(); |
| 4050 | if (was_valid) |
| Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 4051 | { |
| 4052 | if (m_mod_id == current_mod_id) |
| 4053 | { |
| Jim Ingham | 5cfbe4a | 2012-01-12 22:42:34 +0000 | [diff] [blame] | 4054 | // Everything is already up to date in this object, no need to |
| Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 4055 | // update the execution context scope. |
| Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 4056 | changed = false; |
| Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 4057 | } |
| Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 4058 | else |
| 4059 | { |
| 4060 | m_mod_id = current_mod_id; |
| 4061 | m_needs_update = true; |
| 4062 | changed = true; |
| 4063 | } |
| Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 4064 | } |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 4065 | |
| Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 4066 | // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated. |
| 4067 | // That way we'll be sure to return a valid exe_scope. |
| 4068 | // 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] | 4069 | |
| Enrico Granata | bb642e5 | 2015-05-16 01:27:00 +0000 | [diff] [blame] | 4070 | if (!accept_invalid_exe_ctx) |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 4071 | { |
| Enrico Granata | bb642e5 | 2015-05-16 01:27:00 +0000 | [diff] [blame] | 4072 | if (m_exe_ctx_ref.HasThreadRef()) |
| Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame] | 4073 | { |
| Enrico Granata | bb642e5 | 2015-05-16 01:27:00 +0000 | [diff] [blame] | 4074 | ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP()); |
| 4075 | if (thread_sp) |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 4076 | { |
| Enrico Granata | bb642e5 | 2015-05-16 01:27:00 +0000 | [diff] [blame] | 4077 | if (m_exe_ctx_ref.HasFrameRef()) |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 4078 | { |
| Enrico Granata | bb642e5 | 2015-05-16 01:27:00 +0000 | [diff] [blame] | 4079 | StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP()); |
| 4080 | if (!frame_sp) |
| 4081 | { |
| 4082 | // We used to have a frame, but now it is gone |
| 4083 | SetInvalid(); |
| 4084 | changed = was_valid; |
| 4085 | } |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 4086 | } |
| 4087 | } |
| Enrico Granata | bb642e5 | 2015-05-16 01:27:00 +0000 | [diff] [blame] | 4088 | else |
| 4089 | { |
| 4090 | // We used to have a thread, but now it is gone |
| 4091 | SetInvalid(); |
| 4092 | changed = was_valid; |
| 4093 | } |
| Greg Clayton | 262f80d | 2011-07-06 16:49:27 +0000 | [diff] [blame] | 4094 | } |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 4095 | } |
| Enrico Granata | bb642e5 | 2015-05-16 01:27:00 +0000 | [diff] [blame] | 4096 | |
| Jim Ingham | 9ee0115 | 2011-12-10 01:49:43 +0000 | [diff] [blame] | 4097 | return changed; |
| Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 4098 | } |
| 4099 | |
| Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 4100 | void |
| 4101 | ValueObject::EvaluationPoint::SetUpdated () |
| 4102 | { |
| Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 4103 | ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP()); |
| 4104 | if (process_sp) |
| 4105 | m_mod_id = process_sp->GetModID(); |
| Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 4106 | m_needs_update = false; |
| Jim Ingham | 61be090 | 2011-05-02 18:13:59 +0000 | [diff] [blame] | 4107 | } |
| 4108 | |
| 4109 | |
| Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 4110 | |
| 4111 | void |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 4112 | ValueObject::ClearUserVisibleData(uint32_t clear_mask) |
| Enrico Granata | f2bbf71 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 4113 | { |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 4114 | if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue) |
| 4115 | m_value_str.clear(); |
| 4116 | |
| 4117 | if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation) |
| 4118 | m_location_str.clear(); |
| 4119 | |
| 4120 | if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary) |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 4121 | m_summary_str.clear(); |
| Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 4122 | |
| 4123 | if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription) |
| 4124 | m_object_desc_str.clear(); |
| 4125 | |
| 4126 | if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren) |
| 4127 | { |
| 4128 | if (m_synthetic_value) |
| 4129 | m_synthetic_value = NULL; |
| 4130 | } |
| Enrico Granata | 744794a | 2014-09-05 21:46:22 +0000 | [diff] [blame] | 4131 | |
| 4132 | if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator) |
| 4133 | m_validation_result.reset(); |
| Johnny Chen | 4480530 | 2011-07-19 19:48:13 +0000 | [diff] [blame] | 4134 | } |
| Enrico Granata | 9128ee2 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 4135 | |
| 4136 | SymbolContextScope * |
| 4137 | ValueObject::GetSymbolContextScope() |
| 4138 | { |
| 4139 | if (m_parent) |
| 4140 | { |
| 4141 | if (!m_parent->IsPointerOrReferenceType()) |
| 4142 | return m_parent->GetSymbolContextScope(); |
| 4143 | } |
| 4144 | return NULL; |
| 4145 | } |
| Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 4146 | |
| 4147 | lldb::ValueObjectSP |
| 4148 | ValueObject::CreateValueObjectFromExpression (const char* name, |
| 4149 | const char* expression, |
| 4150 | const ExecutionContext& exe_ctx) |
| 4151 | { |
| Enrico Granata | 972be53 | 2014-12-17 21:18:43 +0000 | [diff] [blame] | 4152 | return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions()); |
| 4153 | } |
| 4154 | |
| 4155 | |
| 4156 | lldb::ValueObjectSP |
| 4157 | ValueObject::CreateValueObjectFromExpression (const char* name, |
| 4158 | const char* expression, |
| 4159 | const ExecutionContext& exe_ctx, |
| 4160 | const EvaluateExpressionOptions& options) |
| 4161 | { |
| Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 4162 | lldb::ValueObjectSP retval_sp; |
| 4163 | lldb::TargetSP target_sp(exe_ctx.GetTargetSP()); |
| 4164 | if (!target_sp) |
| 4165 | return retval_sp; |
| 4166 | if (!expression || !*expression) |
| 4167 | return retval_sp; |
| 4168 | target_sp->EvaluateExpression (expression, |
| 4169 | exe_ctx.GetFrameSP().get(), |
| Enrico Granata | 972be53 | 2014-12-17 21:18:43 +0000 | [diff] [blame] | 4170 | retval_sp, |
| 4171 | options); |
| Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 4172 | if (retval_sp && name && *name) |
| 4173 | retval_sp->SetName(ConstString(name)); |
| 4174 | return retval_sp; |
| 4175 | } |
| 4176 | |
| 4177 | lldb::ValueObjectSP |
| 4178 | ValueObject::CreateValueObjectFromAddress (const char* name, |
| 4179 | uint64_t address, |
| 4180 | const ExecutionContext& exe_ctx, |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4181 | CompilerType type) |
| Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 4182 | { |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4183 | if (type) |
| Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 4184 | { |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4185 | CompilerType pointer_type(type.GetPointerType()); |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4186 | if (pointer_type) |
| 4187 | { |
| 4188 | lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t))); |
| 4189 | lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), |
| 4190 | pointer_type, |
| 4191 | ConstString(name), |
| 4192 | buffer, |
| Enrico Granata | 972be53 | 2014-12-17 21:18:43 +0000 | [diff] [blame] | 4193 | exe_ctx.GetByteOrder(), |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4194 | exe_ctx.GetAddressByteSize())); |
| 4195 | if (ptr_result_valobj_sp) |
| 4196 | { |
| 4197 | ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress); |
| 4198 | Error err; |
| 4199 | ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err); |
| 4200 | if (ptr_result_valobj_sp && name && *name) |
| 4201 | ptr_result_valobj_sp->SetName(ConstString(name)); |
| 4202 | } |
| 4203 | return ptr_result_valobj_sp; |
| 4204 | } |
| Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 4205 | } |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4206 | return lldb::ValueObjectSP(); |
| Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 4207 | } |
| 4208 | |
| 4209 | lldb::ValueObjectSP |
| 4210 | ValueObject::CreateValueObjectFromData (const char* name, |
| Enrico Granata | 7ca1c76 | 2014-03-31 23:02:25 +0000 | [diff] [blame] | 4211 | const DataExtractor& data, |
| Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 4212 | const ExecutionContext& exe_ctx, |
| Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 4213 | CompilerType type) |
| Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 4214 | { |
| 4215 | lldb::ValueObjectSP new_value_sp; |
| 4216 | new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), |
| Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 4217 | type, |
| Enrico Granata | b2698cd | 2012-09-13 18:27:09 +0000 | [diff] [blame] | 4218 | ConstString(name), |
| 4219 | data, |
| 4220 | LLDB_INVALID_ADDRESS); |
| 4221 | new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad); |
| 4222 | if (new_value_sp && name && *name) |
| 4223 | new_value_sp->SetName(ConstString(name)); |
| 4224 | return new_value_sp; |
| 4225 | } |
| Enrico Granata | 4873e52 | 2013-04-11 22:48:58 +0000 | [diff] [blame] | 4226 | |
| 4227 | ModuleSP |
| 4228 | ValueObject::GetModule () |
| 4229 | { |
| 4230 | ValueObject* root(GetRoot()); |
| 4231 | if (root != this) |
| 4232 | return root->GetModule(); |
| 4233 | return lldb::ModuleSP(); |
| 4234 | } |
| 4235 | |
| 4236 | ValueObject* |
| 4237 | ValueObject::GetRoot () |
| 4238 | { |
| 4239 | if (m_root) |
| 4240 | return m_root; |
| Enrico Granata | de61eba | 2015-01-22 03:07:34 +0000 | [diff] [blame] | 4241 | return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool { |
| 4242 | return (vo->m_parent != nullptr); |
| 4243 | })); |
| 4244 | } |
| 4245 | |
| 4246 | ValueObject* |
| 4247 | ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f) |
| 4248 | { |
| 4249 | ValueObject* vo = this; |
| 4250 | while (vo) |
| Enrico Granata | 4873e52 | 2013-04-11 22:48:58 +0000 | [diff] [blame] | 4251 | { |
| Enrico Granata | de61eba | 2015-01-22 03:07:34 +0000 | [diff] [blame] | 4252 | if (f(vo) == false) |
| 4253 | break; |
| 4254 | vo = vo->m_parent; |
| Enrico Granata | 4873e52 | 2013-04-11 22:48:58 +0000 | [diff] [blame] | 4255 | } |
| Enrico Granata | de61eba | 2015-01-22 03:07:34 +0000 | [diff] [blame] | 4256 | return vo; |
| Enrico Granata | 4873e52 | 2013-04-11 22:48:58 +0000 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | AddressType |
| 4260 | ValueObject::GetAddressTypeOfChildren() |
| 4261 | { |
| 4262 | if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid) |
| 4263 | { |
| 4264 | ValueObject* root(GetRoot()); |
| 4265 | if (root != this) |
| 4266 | return root->GetAddressTypeOfChildren(); |
| 4267 | } |
| 4268 | return m_address_type_of_ptr_or_ref_children; |
| 4269 | } |
| 4270 | |
| 4271 | lldb::DynamicValueType |
| 4272 | ValueObject::GetDynamicValueType () |
| 4273 | { |
| 4274 | ValueObject* with_dv_info = this; |
| 4275 | while (with_dv_info) |
| 4276 | { |
| 4277 | if (with_dv_info->HasDynamicValueTypeInfo()) |
| 4278 | return with_dv_info->GetDynamicValueTypeImpl(); |
| 4279 | with_dv_info = with_dv_info->m_parent; |
| 4280 | } |
| 4281 | return lldb::eNoDynamicValues; |
| 4282 | } |
| Enrico Granata | 39d5141 | 2013-05-31 17:43:40 +0000 | [diff] [blame] | 4283 | |
| Enrico Granata | 4873e52 | 2013-04-11 22:48:58 +0000 | [diff] [blame] | 4284 | lldb::Format |
| 4285 | ValueObject::GetFormat () const |
| 4286 | { |
| 4287 | const ValueObject* with_fmt_info = this; |
| 4288 | while (with_fmt_info) |
| 4289 | { |
| 4290 | if (with_fmt_info->m_format != lldb::eFormatDefault) |
| 4291 | return with_fmt_info->m_format; |
| 4292 | with_fmt_info = with_fmt_info->m_parent; |
| 4293 | } |
| 4294 | return m_format; |
| 4295 | } |
| Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 4296 | |
| Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 4297 | lldb::LanguageType |
| 4298 | ValueObject::GetPreferredDisplayLanguage () |
| 4299 | { |
| Enrico Granata | ed3228a | 2015-01-21 01:47:13 +0000 | [diff] [blame] | 4300 | lldb::LanguageType type = m_preferred_display_language; |
| 4301 | if (m_preferred_display_language == lldb::eLanguageTypeUnknown) |
| Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 4302 | { |
| Enrico Granata | ed3228a | 2015-01-21 01:47:13 +0000 | [diff] [blame] | 4303 | if (GetRoot()) |
| Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 4304 | { |
| Enrico Granata | ed3228a | 2015-01-21 01:47:13 +0000 | [diff] [blame] | 4305 | if (GetRoot() == this) |
| Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 4306 | { |
| Enrico Granata | ed3228a | 2015-01-21 01:47:13 +0000 | [diff] [blame] | 4307 | if (StackFrameSP frame_sp = GetFrameSP()) |
| 4308 | { |
| 4309 | const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit)); |
| 4310 | if (CompileUnit* cu = sc.comp_unit) |
| 4311 | type = cu->GetLanguage(); |
| 4312 | } |
| 4313 | } |
| 4314 | else |
| 4315 | { |
| 4316 | type = GetRoot()->GetPreferredDisplayLanguage(); |
| Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 4317 | } |
| 4318 | } |
| Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 4319 | } |
| Enrico Granata | ed3228a | 2015-01-21 01:47:13 +0000 | [diff] [blame] | 4320 | return (m_preferred_display_language = type); // only compute it once |
| 4321 | } |
| 4322 | |
| 4323 | void |
| 4324 | ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt) |
| 4325 | { |
| 4326 | m_preferred_display_language = lt; |
| Enrico Granata | c1247f5 | 2014-11-06 21:23:20 +0000 | [diff] [blame] | 4327 | } |
| 4328 | |
| Enrico Granata | 73e8c4d | 2015-10-07 02:36:35 +0000 | [diff] [blame] | 4329 | void |
| 4330 | ValueObject::SetPreferredDisplayLanguageIfNeeded (lldb::LanguageType lt) |
| 4331 | { |
| 4332 | if (m_preferred_display_language == lldb::eLanguageTypeUnknown) |
| 4333 | SetPreferredDisplayLanguage(lt); |
| 4334 | } |
| 4335 | |
| Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 4336 | bool |
| 4337 | ValueObject::CanProvideValue () |
| 4338 | { |
| Sean Callanan | 7375f3e | 2014-12-09 21:18:59 +0000 | [diff] [blame] | 4339 | // we need to support invalid types as providers of values because some bare-board |
| 4340 | // debugging scenarios have no notion of types, but still manage to have raw numeric |
| 4341 | // values for things like registers. sigh. |
| Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 4342 | const CompilerType &type(GetCompilerType()); |
| Sean Callanan | 7375f3e | 2014-12-09 21:18:59 +0000 | [diff] [blame] | 4343 | return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue)); |
| 4344 | } |
| 4345 | |
| 4346 | bool |
| 4347 | ValueObject::IsChecksumEmpty () |
| 4348 | { |
| 4349 | return m_value_checksum.empty(); |
| Enrico Granata | d07cfd3 | 2014-10-08 18:27:36 +0000 | [diff] [blame] | 4350 | } |
| Enrico Granata | 0c10a85 | 2014-12-08 23:13:56 +0000 | [diff] [blame] | 4351 | |
| 4352 | ValueObjectSP |
| 4353 | ValueObject::Persist () |
| 4354 | { |
| 4355 | if (!UpdateValueIfNeeded()) |
| 4356 | return nullptr; |
| 4357 | |
| 4358 | TargetSP target_sp(GetTargetSP()); |
| 4359 | if (!target_sp) |
| 4360 | return nullptr; |
| 4361 | |
| Sean Callanan | b92bd75 | 2015-10-01 16:28:02 +0000 | [diff] [blame] | 4362 | PersistentExpressionState *persistent_state = target_sp->GetPersistentExpressionStateForLanguage(GetPreferredDisplayLanguage()); |
| Sean Callanan | 8f1f9a1 | 2015-09-30 19:57:57 +0000 | [diff] [blame] | 4363 | |
| 4364 | if (!persistent_state) |
| 4365 | return nullptr; |
| 4366 | |
| 4367 | ConstString name(persistent_state->GetNextPersistentVariableName()); |
| Enrico Granata | 0c10a85 | 2014-12-08 23:13:56 +0000 | [diff] [blame] | 4368 | |
| Sean Callanan | 9301ec1 | 2015-10-01 23:07:06 +0000 | [diff] [blame] | 4369 | ValueObjectSP const_result_sp = ValueObjectConstResult::Create (target_sp.get(), GetValue(), name); |
| 4370 | |
| 4371 | ExpressionVariableSP clang_var_sp = persistent_state->CreatePersistentVariable(const_result_sp); |
| 4372 | clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp; |
| 4373 | clang_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference; |
| Enrico Granata | 0c10a85 | 2014-12-08 23:13:56 +0000 | [diff] [blame] | 4374 | |
| 4375 | return clang_var_sp->GetValueObject(); |
| 4376 | } |
| Enrico Granata | e29df23 | 2014-12-09 19:51:20 +0000 | [diff] [blame] | 4377 | |
| 4378 | bool |
| 4379 | ValueObject::IsSyntheticChildrenGenerated () |
| 4380 | { |
| 4381 | return m_is_synthetic_children_generated; |
| 4382 | } |
| 4383 | |
| 4384 | void |
| 4385 | ValueObject::SetSyntheticChildrenGenerated (bool b) |
| 4386 | { |
| 4387 | m_is_synthetic_children_generated = b; |
| 4388 | } |
| Enrico Granata | dc62ffd | 2015-11-09 19:27:34 +0000 | [diff] [blame] | 4389 | |
| 4390 | uint64_t |
| 4391 | ValueObject::GetLanguageFlags () |
| 4392 | { |
| 4393 | return m_language_flags; |
| 4394 | } |
| 4395 | |
| 4396 | void |
| 4397 | ValueObject::SetLanguageFlags (uint64_t flags) |
| 4398 | { |
| 4399 | m_language_flags = flags; |
| 4400 | } |