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