Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- Variable.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/Symbol/Variable.h" |
| 11 | |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Module.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Stream.h" |
Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 14 | #include "lldb/Core/RegularExpression.h" |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 15 | #include "lldb/Core/ValueObject.h" |
| 16 | #include "lldb/Core/ValueObjectVariable.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Symbol/Block.h" |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 18 | #include "lldb/Symbol/CompilerDecl.h" |
| 19 | #include "lldb/Symbol/CompilerDeclContext.h" |
Greg Clayton | ddaf6a7 | 2015-07-08 22:32:23 +0000 | [diff] [blame] | 20 | #include "lldb/Symbol/CompileUnit.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/Function.h" |
| 22 | #include "lldb/Symbol/SymbolContext.h" |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 23 | #include "lldb/Symbol/SymbolFile.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Symbol/Type.h" |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 25 | #include "lldb/Symbol/VariableList.h" |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 26 | #include "lldb/Target/ABI.h" |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 27 | #include "lldb/Target/Process.h" |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 28 | #include "lldb/Target/RegisterContext.h" |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 29 | #include "lldb/Target/StackFrame.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Target/Thread.h" |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 31 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | |
| 33 | using namespace lldb; |
| 34 | using namespace lldb_private; |
| 35 | |
| 36 | //---------------------------------------------------------------------- |
| 37 | // Variable constructor |
| 38 | //---------------------------------------------------------------------- |
Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 39 | Variable::Variable |
| 40 | ( |
| 41 | lldb::user_id_t uid, |
| 42 | const char *name, |
Siva Chandra | 0783ab9 | 2015-03-24 18:32:27 +0000 | [diff] [blame] | 43 | const char *mangled, // The mangled or fully qualified name of the variable. |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 44 | const lldb::SymbolFileTypeSP &symfile_type_sp, |
Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 45 | ValueType scope, |
| 46 | SymbolContextScope *context, |
| 47 | Declaration* decl_ptr, |
| 48 | const DWARFExpression& location, |
| 49 | bool external, |
Paul Herman | 10bc1a4 | 2015-08-18 22:46:57 +0000 | [diff] [blame] | 50 | bool artificial, |
| 51 | bool static_member |
Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 52 | ) : |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | UserID(uid), |
| 54 | m_name(name), |
Siva Chandra | 0783ab9 | 2015-03-24 18:32:27 +0000 | [diff] [blame] | 55 | m_mangled (ConstString(mangled)), |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 56 | m_symfile_type_sp(symfile_type_sp), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | m_scope(scope), |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 58 | m_owner_scope(context), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | m_declaration(decl_ptr), |
| 60 | m_location(location), |
| 61 | m_external(external), |
Paul Herman | 10bc1a4 | 2015-08-18 22:46:57 +0000 | [diff] [blame] | 62 | m_artificial(artificial), |
| 63 | m_static_member(static_member) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | { |
| 65 | } |
| 66 | |
| 67 | //---------------------------------------------------------------------- |
| 68 | // Destructor |
| 69 | //---------------------------------------------------------------------- |
| 70 | Variable::~Variable() |
| 71 | { |
| 72 | } |
| 73 | |
Greg Clayton | ddaf6a7 | 2015-07-08 22:32:23 +0000 | [diff] [blame] | 74 | lldb::LanguageType |
| 75 | Variable::GetLanguage () const |
| 76 | { |
| 77 | SymbolContext variable_sc; |
| 78 | m_owner_scope->CalculateSymbolContext(&variable_sc); |
| 79 | if (variable_sc.comp_unit) |
| 80 | return variable_sc.comp_unit->GetLanguage(); |
| 81 | return lldb::eLanguageTypeUnknown; |
| 82 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 83 | |
Greg Clayton | ddaf6a7 | 2015-07-08 22:32:23 +0000 | [diff] [blame] | 84 | |
| 85 | |
| 86 | ConstString |
Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 87 | Variable::GetName() const |
| 88 | { |
Pavel Labath | 89ad594 | 2015-07-09 10:57:54 +0000 | [diff] [blame] | 89 | ConstString name = m_mangled.GetName(GetLanguage()); |
| 90 | if (name) |
| 91 | return name; |
Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 92 | return m_name; |
| 93 | } |
| 94 | |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 95 | ConstString |
| 96 | Variable::GetUnqualifiedName() const |
| 97 | { |
| 98 | return m_name; |
| 99 | } |
| 100 | |
| 101 | |
Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 102 | bool |
Greg Clayton | ddaf6a7 | 2015-07-08 22:32:23 +0000 | [diff] [blame] | 103 | Variable::NameMatches (const ConstString &name) const |
| 104 | { |
| 105 | if (m_name == name) |
| 106 | return true; |
| 107 | SymbolContext variable_sc; |
| 108 | m_owner_scope->CalculateSymbolContext(&variable_sc); |
| 109 | |
| 110 | LanguageType language = eLanguageTypeUnknown; |
| 111 | if (variable_sc.comp_unit) |
| 112 | language = variable_sc.comp_unit->GetLanguage(); |
| 113 | return m_mangled.NameMatches (name, language); |
| 114 | } |
| 115 | bool |
Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 116 | Variable::NameMatches (const RegularExpression& regex) const |
| 117 | { |
| 118 | if (regex.Execute (m_name.AsCString())) |
| 119 | return true; |
Greg Clayton | ddaf6a7 | 2015-07-08 22:32:23 +0000 | [diff] [blame] | 120 | if (m_mangled) |
| 121 | return m_mangled.NameMatches (regex, GetLanguage()); |
| 122 | return false; |
Greg Clayton | 83c5cd9 | 2010-11-14 22:13:40 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 125 | Type * |
| 126 | Variable::GetType() |
| 127 | { |
| 128 | if (m_symfile_type_sp) |
| 129 | return m_symfile_type_sp->GetType(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 130 | return nullptr; |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 133 | void |
| 134 | Variable::Dump(Stream *s, bool show_context) const |
| 135 | { |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 136 | s->Printf("%p: ", static_cast<const void*>(this)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 137 | s->Indent(); |
| 138 | *s << "Variable" << (const UserID&)*this; |
| 139 | |
| 140 | if (m_name) |
| 141 | *s << ", name = \"" << m_name << "\""; |
| 142 | |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 143 | if (m_symfile_type_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 144 | { |
Greg Clayton | d1767f0 | 2011-12-08 02:13:16 +0000 | [diff] [blame] | 145 | Type *type = m_symfile_type_sp->GetType(); |
| 146 | if (type) |
| 147 | { |
| 148 | *s << ", type = {" << type->GetID() << "} " << (void*)type << " ("; |
| 149 | type->DumpTypeName(s); |
| 150 | s->PutChar(')'); |
| 151 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | if (m_scope != eValueTypeInvalid) |
| 155 | { |
| 156 | s->PutCString(", scope = "); |
| 157 | switch (m_scope) |
| 158 | { |
| 159 | case eValueTypeVariableGlobal: s->PutCString(m_external ? "global" : "static"); break; |
| 160 | case eValueTypeVariableArgument: s->PutCString("parameter"); break; |
| 161 | case eValueTypeVariableLocal: s->PutCString("local"); break; |
| 162 | default: *s << "??? (" << m_scope << ')'; |
| 163 | } |
| 164 | } |
| 165 | |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 166 | if (show_context && m_owner_scope != nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 167 | { |
| 168 | s->PutCString(", context = ( "); |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 169 | m_owner_scope->DumpSymbolContext(s); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 170 | s->PutCString(" )"); |
| 171 | } |
| 172 | |
Greg Clayton | 6dbd398 | 2010-09-15 05:51:24 +0000 | [diff] [blame] | 173 | bool show_fullpaths = false; |
| 174 | m_declaration.Dump(s, show_fullpaths); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 175 | |
| 176 | if (m_location.IsValid()) |
| 177 | { |
| 178 | s->PutCString(", location = "); |
Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 179 | lldb::addr_t loclist_base_addr = LLDB_INVALID_ADDRESS; |
| 180 | if (m_location.IsLocationList()) |
| 181 | { |
| 182 | SymbolContext variable_sc; |
| 183 | m_owner_scope->CalculateSymbolContext(&variable_sc); |
| 184 | if (variable_sc.function) |
| 185 | loclist_base_addr = variable_sc.function->GetAddressRange().GetBaseAddress().GetFileAddress(); |
| 186 | } |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 187 | ABI *abi = nullptr; |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 188 | if (m_owner_scope) |
| 189 | { |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 190 | ModuleSP module_sp (m_owner_scope->CalculateSymbolContextModule()); |
| 191 | if (module_sp) |
| 192 | abi = ABI::FindPlugin (module_sp->GetArchitecture()).get(); |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 193 | } |
| 194 | m_location.GetDescription(s, lldb::eDescriptionLevelBrief, loclist_base_addr, abi); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | if (m_external) |
| 198 | s->PutCString(", external"); |
| 199 | |
| 200 | if (m_artificial) |
| 201 | s->PutCString(", artificial"); |
| 202 | |
| 203 | s->EOL(); |
| 204 | } |
| 205 | |
Greg Clayton | 45ba854 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 206 | bool |
| 207 | Variable::DumpDeclaration (Stream *s, bool show_fullpaths, bool show_module) |
| 208 | { |
| 209 | bool dumped_declaration_info = false; |
| 210 | if (m_owner_scope) |
| 211 | { |
| 212 | SymbolContext sc; |
| 213 | m_owner_scope->CalculateSymbolContext(&sc); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 214 | sc.block = nullptr; |
Greg Clayton | 45ba854 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 215 | sc.line_entry.Clear(); |
| 216 | bool show_inlined_frames = false; |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 217 | const bool show_function_arguments = true; |
Jason Molenda | c980fa9 | 2015-02-13 23:24:21 +0000 | [diff] [blame] | 218 | const bool show_function_name = true; |
Greg Clayton | 45ba854 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 219 | |
| 220 | dumped_declaration_info = sc.DumpStopContext (s, |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 221 | nullptr, |
Greg Clayton | 45ba854 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 222 | Address(), |
| 223 | show_fullpaths, |
| 224 | show_module, |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 225 | show_inlined_frames, |
Jason Molenda | c980fa9 | 2015-02-13 23:24:21 +0000 | [diff] [blame] | 226 | show_function_arguments, |
| 227 | show_function_name); |
Greg Clayton | 45ba854 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 228 | |
| 229 | if (sc.function) |
| 230 | s->PutChar(':'); |
| 231 | } |
| 232 | if (m_declaration.DumpStopContext (s, false)) |
| 233 | dumped_declaration_info = true; |
| 234 | return dumped_declaration_info; |
| 235 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 236 | |
| 237 | size_t |
| 238 | Variable::MemorySize() const |
| 239 | { |
| 240 | return sizeof(Variable); |
| 241 | } |
| 242 | |
Paul Herman | d628cbb | 2015-09-15 23:44:17 +0000 | [diff] [blame] | 243 | CompilerDeclContext |
| 244 | Variable::GetDeclContext () |
| 245 | { |
| 246 | Type *type = GetType(); |
| 247 | return type->GetSymbolFile()->GetDeclContextContainingUID(GetID()); |
| 248 | } |
| 249 | |
| 250 | CompilerDecl |
| 251 | Variable::GetDecl () |
| 252 | { |
| 253 | Type *type = GetType(); |
| 254 | CompilerDecl decl = type->GetSymbolFile()->GetDeclForUID(GetID()); |
| 255 | if (decl) |
| 256 | decl.GetTypeSystem()->DeclLinkToObject(decl.GetOpaqueDecl(), shared_from_this()); |
| 257 | return decl; |
| 258 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 259 | |
| 260 | void |
| 261 | Variable::CalculateSymbolContext (SymbolContext *sc) |
| 262 | { |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 263 | if (m_owner_scope) |
Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 264 | { |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 265 | m_owner_scope->CalculateSymbolContext(sc); |
Greg Clayton | 2501e5e | 2015-01-15 02:59:20 +0000 | [diff] [blame] | 266 | sc->variable = this; |
| 267 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 268 | else |
Greg Clayton | 7231035 | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 269 | sc->Clear(false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 272 | bool |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 273 | Variable::LocationIsValidForFrame (StackFrame *frame) |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 274 | { |
| 275 | // Is the variable is described by a single location? |
| 276 | if (!m_location.IsLocationList()) |
| 277 | { |
| 278 | // Yes it is, the location is valid. |
| 279 | return true; |
| 280 | } |
| 281 | |
| 282 | if (frame) |
| 283 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 284 | Function *function = frame->GetSymbolContext(eSymbolContextFunction).function; |
| 285 | if (function) |
| 286 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 287 | TargetSP target_sp (frame->CalculateTarget()); |
| 288 | |
| 289 | addr_t loclist_base_load_addr = function->GetAddressRange().GetBaseAddress().GetLoadAddress (target_sp.get()); |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 290 | if (loclist_base_load_addr == LLDB_INVALID_ADDRESS) |
| 291 | return false; |
| 292 | // It is a location list. We just need to tell if the location |
| 293 | // list contains the current address when converted to a load |
| 294 | // address |
| 295 | return m_location.LocationListContainsAddress (loclist_base_load_addr, |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 296 | frame->GetFrameCodeAddress().GetLoadAddress (target_sp.get())); |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | return false; |
| 300 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 301 | |
| 302 | bool |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 303 | Variable::LocationIsValidForAddress (const Address &address) |
| 304 | { |
| 305 | // Be sure to resolve the address to section offset prior to |
| 306 | // calling this function. |
| 307 | if (address.IsSectionOffset()) |
| 308 | { |
| 309 | SymbolContext sc; |
| 310 | CalculateSymbolContext(&sc); |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 311 | if (sc.module_sp == address.GetModule()) |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 312 | { |
| 313 | // Is the variable is described by a single location? |
| 314 | if (!m_location.IsLocationList()) |
| 315 | { |
| 316 | // Yes it is, the location is valid. |
| 317 | return true; |
| 318 | } |
| 319 | |
| 320 | if (sc.function) |
| 321 | { |
| 322 | addr_t loclist_base_file_addr = sc.function->GetAddressRange().GetBaseAddress().GetFileAddress(); |
| 323 | if (loclist_base_file_addr == LLDB_INVALID_ADDRESS) |
| 324 | return false; |
| 325 | // It is a location list. We just need to tell if the location |
| 326 | // list contains the current address when converted to a load |
| 327 | // address |
| 328 | return m_location.LocationListContainsAddress (loclist_base_file_addr, |
| 329 | address.GetFileAddress()); |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | bool |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 337 | Variable::IsInScope (StackFrame *frame) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 338 | { |
| 339 | switch (m_scope) |
| 340 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 341 | case eValueTypeRegister: |
| 342 | case eValueTypeRegisterSet: |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 343 | return frame != nullptr; |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 344 | |
| 345 | case eValueTypeConstResult: |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 346 | case eValueTypeVariableGlobal: |
| 347 | case eValueTypeVariableStatic: |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 348 | return true; |
| 349 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 350 | case eValueTypeVariableArgument: |
| 351 | case eValueTypeVariableLocal: |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 352 | if (frame) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 353 | { |
| 354 | // We don't have a location list, we just need to see if the block |
| 355 | // that this variable was defined in is currently |
Greg Clayton | 6f00abd | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 356 | Block *deepest_frame_block = frame->GetSymbolContext(eSymbolContextBlock).block; |
| 357 | if (deepest_frame_block) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 358 | { |
| 359 | SymbolContext variable_sc; |
| 360 | CalculateSymbolContext (&variable_sc); |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 361 | // Check for static or global variable defined at the compile unit |
| 362 | // level that wasn't defined in a block |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 363 | if (variable_sc.block == nullptr) |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 364 | return true; |
| 365 | |
Greg Clayton | 6f00abd | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 366 | if (variable_sc.block == deepest_frame_block) |
Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 367 | return true; |
Greg Clayton | 6f00abd | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 368 | return variable_sc.block->Contains (deepest_frame_block); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | break; |
| 372 | |
| 373 | default: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 374 | break; |
| 375 | } |
| 376 | return false; |
| 377 | } |
| 378 | |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 379 | Error |
| 380 | Variable::GetValuesForVariableExpressionPath (const char *variable_expr_path, |
| 381 | ExecutionContextScope *scope, |
| 382 | GetVariableCallback callback, |
| 383 | void *baton, |
| 384 | VariableList &variable_list, |
| 385 | ValueObjectList &valobj_list) |
| 386 | { |
| 387 | Error error; |
| 388 | if (variable_expr_path && callback) |
| 389 | { |
| 390 | switch (variable_expr_path[0]) |
| 391 | { |
| 392 | case '*': |
| 393 | { |
| 394 | error = Variable::GetValuesForVariableExpressionPath (variable_expr_path + 1, |
| 395 | scope, |
| 396 | callback, |
| 397 | baton, |
| 398 | variable_list, |
| 399 | valobj_list); |
| 400 | if (error.Success()) |
| 401 | { |
| 402 | for (uint32_t i=0; i<valobj_list.GetSize(); ) |
| 403 | { |
| 404 | Error tmp_error; |
| 405 | ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(i)->Dereference(tmp_error)); |
| 406 | if (tmp_error.Fail()) |
| 407 | { |
| 408 | variable_list.RemoveVariableAtIndex (i); |
| 409 | valobj_list.RemoveValueObjectAtIndex (i); |
| 410 | } |
| 411 | else |
| 412 | { |
| 413 | valobj_list.SetValueObjectAtIndex (i, valobj_sp); |
| 414 | ++i; |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | else |
| 419 | { |
| 420 | error.SetErrorString ("unknown error"); |
| 421 | } |
| 422 | return error; |
| 423 | } |
| 424 | break; |
| 425 | |
| 426 | case '&': |
| 427 | { |
| 428 | error = Variable::GetValuesForVariableExpressionPath (variable_expr_path + 1, |
| 429 | scope, |
| 430 | callback, |
| 431 | baton, |
| 432 | variable_list, |
| 433 | valobj_list); |
| 434 | if (error.Success()) |
| 435 | { |
| 436 | for (uint32_t i=0; i<valobj_list.GetSize(); ) |
| 437 | { |
| 438 | Error tmp_error; |
| 439 | ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(i)->AddressOf(tmp_error)); |
| 440 | if (tmp_error.Fail()) |
| 441 | { |
| 442 | variable_list.RemoveVariableAtIndex (i); |
| 443 | valobj_list.RemoveValueObjectAtIndex (i); |
| 444 | } |
| 445 | else |
| 446 | { |
| 447 | valobj_list.SetValueObjectAtIndex (i, valobj_sp); |
| 448 | ++i; |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | else |
| 453 | { |
| 454 | error.SetErrorString ("unknown error"); |
| 455 | } |
| 456 | return error; |
| 457 | } |
| 458 | break; |
| 459 | |
| 460 | default: |
| 461 | { |
Greg Clayton | bc43cab | 2013-04-03 21:37:16 +0000 | [diff] [blame] | 462 | static RegularExpression g_regex ("^([A-Za-z_:][A-Za-z_0-9:]*)(.*)"); |
| 463 | RegularExpression::Match regex_match(1); |
| 464 | if (g_regex.Execute(variable_expr_path, ®ex_match)) |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 465 | { |
| 466 | std::string variable_name; |
Greg Clayton | bc43cab | 2013-04-03 21:37:16 +0000 | [diff] [blame] | 467 | if (regex_match.GetMatchAtIndex(variable_expr_path, 1, variable_name)) |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 468 | { |
| 469 | variable_list.Clear(); |
| 470 | if (callback (baton, variable_name.c_str(), variable_list)) |
| 471 | { |
| 472 | uint32_t i=0; |
| 473 | while (i < variable_list.GetSize()) |
| 474 | { |
| 475 | VariableSP var_sp (variable_list.GetVariableAtIndex (i)); |
| 476 | ValueObjectSP valobj_sp; |
| 477 | if (var_sp) |
| 478 | { |
| 479 | ValueObjectSP variable_valobj_sp(ValueObjectVariable::Create (scope, var_sp)); |
| 480 | if (variable_valobj_sp) |
| 481 | { |
Greg Clayton | 958d4eb | 2013-05-20 16:50:51 +0000 | [diff] [blame] | 482 | const char *variable_sub_expr_path = variable_expr_path + variable_name.size(); |
| 483 | if (*variable_sub_expr_path) |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 484 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 485 | const char* first_unparsed = nullptr; |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 486 | ValueObject::ExpressionPathScanEndReason reason_to_stop; |
| 487 | ValueObject::ExpressionPathEndResultType final_value_type; |
| 488 | ValueObject::GetValueForExpressionPathOptions options; |
| 489 | ValueObject::ExpressionPathAftermath final_task_on_target; |
| 490 | |
Greg Clayton | 958d4eb | 2013-05-20 16:50:51 +0000 | [diff] [blame] | 491 | valobj_sp = variable_valobj_sp->GetValueForExpressionPath (variable_sub_expr_path, |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 492 | &first_unparsed, |
| 493 | &reason_to_stop, |
| 494 | &final_value_type, |
| 495 | options, |
| 496 | &final_task_on_target); |
| 497 | if (!valobj_sp) |
| 498 | { |
| 499 | error.SetErrorStringWithFormat ("invalid expression path '%s' for variable '%s'", |
Greg Clayton | 958d4eb | 2013-05-20 16:50:51 +0000 | [diff] [blame] | 500 | variable_sub_expr_path, |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 501 | var_sp->GetName().GetCString()); |
| 502 | } |
| 503 | } |
| 504 | else |
| 505 | { |
| 506 | // Just the name of a variable with no extras |
| 507 | valobj_sp = variable_valobj_sp; |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | if (!var_sp || !valobj_sp) |
| 513 | { |
| 514 | variable_list.RemoveVariableAtIndex (i); |
| 515 | } |
| 516 | else |
| 517 | { |
| 518 | valobj_list.Append(valobj_sp); |
| 519 | ++i; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | if (variable_list.GetSize() > 0) |
| 524 | { |
| 525 | error.Clear(); |
| 526 | return error; |
| 527 | } |
| 528 | } |
| 529 | } |
| 530 | } |
Greg Clayton | 885b4b7 | 2013-05-20 16:52:10 +0000 | [diff] [blame] | 531 | error.SetErrorStringWithFormat ("unable to extract a variable name from '%s'", variable_expr_path); |
Greg Clayton | 884fb69 | 2011-07-08 21:46:14 +0000 | [diff] [blame] | 532 | } |
| 533 | break; |
| 534 | } |
| 535 | } |
| 536 | error.SetErrorString ("unknown error"); |
| 537 | return error; |
| 538 | } |
| 539 | |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 540 | bool |
| 541 | Variable::DumpLocationForAddress (Stream *s, const Address &address) |
| 542 | { |
| 543 | // Be sure to resolve the address to section offset prior to |
| 544 | // calling this function. |
| 545 | if (address.IsSectionOffset()) |
| 546 | { |
| 547 | SymbolContext sc; |
| 548 | CalculateSymbolContext(&sc); |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 549 | if (sc.module_sp == address.GetModule()) |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 550 | { |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 551 | ABI *abi = nullptr; |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 552 | if (m_owner_scope) |
| 553 | { |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 554 | ModuleSP module_sp (m_owner_scope->CalculateSymbolContextModule()); |
| 555 | if (module_sp) |
| 556 | abi = ABI::FindPlugin (module_sp->GetArchitecture()).get(); |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 557 | } |
| 558 | |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 559 | const addr_t file_addr = address.GetFileAddress(); |
| 560 | if (sc.function) |
| 561 | { |
| 562 | if (sc.function->GetAddressRange().ContainsFileAddress(address)) |
| 563 | { |
| 564 | addr_t loclist_base_file_addr = sc.function->GetAddressRange().GetBaseAddress().GetFileAddress(); |
| 565 | if (loclist_base_file_addr == LLDB_INVALID_ADDRESS) |
| 566 | return false; |
| 567 | return m_location.DumpLocationForAddress (s, |
| 568 | eDescriptionLevelBrief, |
| 569 | loclist_base_file_addr, |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 570 | file_addr, |
| 571 | abi); |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | return m_location.DumpLocationForAddress (s, |
| 575 | eDescriptionLevelBrief, |
| 576 | LLDB_INVALID_ADDRESS, |
Greg Clayton | afacd14 | 2011-09-02 01:15:17 +0000 | [diff] [blame] | 577 | file_addr, |
| 578 | abi); |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | return false; |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 582 | } |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 583 | |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 584 | |
| 585 | static void |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 586 | PrivateAutoComplete (StackFrame *frame, |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 587 | const std::string &partial_path, |
| 588 | const std::string &prefix_path, // Anything that has been resolved already will be in here |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 589 | const CompilerType& clang_type, |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 590 | StringList &matches, |
| 591 | bool &word_complete); |
| 592 | |
| 593 | static void |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 594 | PrivateAutoCompleteMembers (StackFrame *frame, |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 595 | const std::string &partial_member_name, |
| 596 | const std::string &partial_path, |
| 597 | const std::string &prefix_path, // Anything that has been resolved already will be in here |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 598 | const CompilerType& clang_type, |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 599 | StringList &matches, |
| 600 | bool &word_complete); |
| 601 | |
| 602 | static void |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 603 | PrivateAutoCompleteMembers (StackFrame *frame, |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 604 | const std::string &partial_member_name, |
| 605 | const std::string &partial_path, |
| 606 | const std::string &prefix_path, // Anything that has been resolved already will be in here |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 607 | const CompilerType& clang_type, |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 608 | StringList &matches, |
| 609 | bool &word_complete) |
| 610 | { |
| 611 | |
| 612 | // We are in a type parsing child members |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 613 | const uint32_t num_bases = clang_type.GetNumDirectBaseClasses(); |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 614 | |
| 615 | if (num_bases > 0) |
| 616 | { |
| 617 | for (uint32_t i = 0; i < num_bases; ++i) |
| 618 | { |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 619 | CompilerType base_class_type = clang_type.GetDirectBaseClassAtIndex(i, nullptr); |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 620 | |
| 621 | PrivateAutoCompleteMembers (frame, |
| 622 | partial_member_name, |
| 623 | partial_path, |
| 624 | prefix_path, |
| 625 | base_class_type.GetCanonicalType(), |
| 626 | matches, |
| 627 | word_complete); |
| 628 | } |
| 629 | } |
| 630 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 631 | const uint32_t num_vbases = clang_type.GetNumVirtualBaseClasses(); |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 632 | |
| 633 | if (num_vbases > 0) |
| 634 | { |
| 635 | for (uint32_t i = 0; i < num_vbases; ++i) |
| 636 | { |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 637 | CompilerType vbase_class_type = clang_type.GetVirtualBaseClassAtIndex(i,nullptr); |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 638 | |
| 639 | PrivateAutoCompleteMembers (frame, |
| 640 | partial_member_name, |
| 641 | partial_path, |
| 642 | prefix_path, |
| 643 | vbase_class_type.GetCanonicalType(), |
| 644 | matches, |
| 645 | word_complete); |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | // We are in a type parsing child members |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 650 | const uint32_t num_fields = clang_type.GetNumFields(); |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 651 | |
| 652 | if (num_fields > 0) |
| 653 | { |
| 654 | for (uint32_t i = 0; i < num_fields; ++i) |
| 655 | { |
| 656 | std::string member_name; |
| 657 | |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 658 | CompilerType member_clang_type = clang_type.GetFieldAtIndex (i, member_name, nullptr, nullptr, nullptr); |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 659 | |
| 660 | if (partial_member_name.empty() || |
| 661 | member_name.find(partial_member_name) == 0) |
| 662 | { |
| 663 | if (member_name == partial_member_name) |
| 664 | { |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 665 | PrivateAutoComplete (frame, |
| 666 | partial_path, |
| 667 | prefix_path + member_name, // Anything that has been resolved already will be in here |
| 668 | member_clang_type.GetCanonicalType(), |
| 669 | matches, |
| 670 | word_complete); |
| 671 | } |
| 672 | else |
| 673 | { |
| 674 | matches.AppendString (prefix_path + member_name); |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | static void |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 682 | PrivateAutoComplete (StackFrame *frame, |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 683 | const std::string &partial_path, |
| 684 | const std::string &prefix_path, // Anything that has been resolved already will be in here |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 685 | const CompilerType& clang_type, |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 686 | StringList &matches, |
| 687 | bool &word_complete) |
| 688 | { |
| 689 | // printf ("\nPrivateAutoComplete()\n\tprefix_path = '%s'\n\tpartial_path = '%s'\n", prefix_path.c_str(), partial_path.c_str()); |
| 690 | std::string remaining_partial_path; |
| 691 | |
| 692 | const lldb::TypeClass type_class = clang_type.GetTypeClass(); |
| 693 | if (partial_path.empty()) |
| 694 | { |
| 695 | if (clang_type.IsValid()) |
| 696 | { |
| 697 | switch (type_class) |
| 698 | { |
| 699 | default: |
| 700 | case eTypeClassArray: |
| 701 | case eTypeClassBlockPointer: |
| 702 | case eTypeClassBuiltin: |
| 703 | case eTypeClassComplexFloat: |
| 704 | case eTypeClassComplexInteger: |
| 705 | case eTypeClassEnumeration: |
| 706 | case eTypeClassFunction: |
| 707 | case eTypeClassMemberPointer: |
| 708 | case eTypeClassReference: |
| 709 | case eTypeClassTypedef: |
| 710 | case eTypeClassVector: |
| 711 | { |
| 712 | matches.AppendString (prefix_path); |
| 713 | word_complete = matches.GetSize() == 1; |
| 714 | } |
| 715 | break; |
| 716 | |
| 717 | case eTypeClassClass: |
| 718 | case eTypeClassStruct: |
| 719 | case eTypeClassUnion: |
| 720 | if (prefix_path.back() != '.') |
| 721 | matches.AppendString (prefix_path + '.'); |
| 722 | break; |
| 723 | |
| 724 | case eTypeClassObjCObject: |
| 725 | case eTypeClassObjCInterface: |
| 726 | break; |
| 727 | case eTypeClassObjCObjectPointer: |
| 728 | case eTypeClassPointer: |
| 729 | { |
| 730 | bool omit_empty_base_classes = true; |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 731 | if (clang_type.GetNumChildren (omit_empty_base_classes) > 0) |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 732 | matches.AppendString (prefix_path + "->"); |
| 733 | else |
| 734 | { |
| 735 | matches.AppendString (prefix_path); |
| 736 | word_complete = true; |
| 737 | } |
| 738 | } |
| 739 | break; |
| 740 | } |
| 741 | } |
| 742 | else |
| 743 | { |
| 744 | if (frame) |
| 745 | { |
| 746 | const bool get_file_globals = true; |
| 747 | |
| 748 | VariableList *variable_list = frame->GetVariableList(get_file_globals); |
| 749 | |
Jason Molenda | a3a542f | 2013-10-09 02:39:26 +0000 | [diff] [blame] | 750 | if (variable_list) |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 751 | { |
Jason Molenda | a3a542f | 2013-10-09 02:39:26 +0000 | [diff] [blame] | 752 | const size_t num_variables = variable_list->GetSize(); |
| 753 | for (size_t i=0; i<num_variables; ++i) |
| 754 | { |
| 755 | Variable *variable = variable_list->GetVariableAtIndex(i).get(); |
| 756 | matches.AppendString (variable->GetName().AsCString()); |
| 757 | } |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | } |
| 761 | } |
| 762 | else |
| 763 | { |
| 764 | const char ch = partial_path[0]; |
| 765 | switch (ch) |
| 766 | { |
| 767 | case '*': |
| 768 | if (prefix_path.empty()) |
| 769 | { |
| 770 | PrivateAutoComplete (frame, |
| 771 | partial_path.substr(1), |
| 772 | std::string("*"), |
| 773 | clang_type, |
| 774 | matches, |
| 775 | word_complete); |
| 776 | } |
| 777 | break; |
| 778 | |
| 779 | case '&': |
| 780 | if (prefix_path.empty()) |
| 781 | { |
| 782 | PrivateAutoComplete (frame, |
| 783 | partial_path.substr(1), |
| 784 | std::string("&"), |
| 785 | clang_type, |
| 786 | matches, |
| 787 | word_complete); |
| 788 | } |
| 789 | break; |
| 790 | |
| 791 | case '-': |
| 792 | if (partial_path[1] == '>' && !prefix_path.empty()) |
| 793 | { |
| 794 | switch (type_class) |
| 795 | { |
| 796 | case lldb::eTypeClassPointer: |
| 797 | { |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 798 | CompilerType pointee_type(clang_type.GetPointeeType()); |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 799 | if (partial_path[2]) |
| 800 | { |
| 801 | // If there is more after the "->", then search deeper |
| 802 | PrivateAutoComplete (frame, |
| 803 | partial_path.substr(2), |
| 804 | prefix_path + "->", |
| 805 | pointee_type.GetCanonicalType(), |
| 806 | matches, |
| 807 | word_complete); |
| 808 | } |
| 809 | else |
| 810 | { |
| 811 | // Nothing after the "->", so list all members |
| 812 | PrivateAutoCompleteMembers (frame, |
| 813 | std::string(), |
| 814 | std::string(), |
| 815 | prefix_path + "->", |
| 816 | pointee_type.GetCanonicalType(), |
| 817 | matches, |
| 818 | word_complete); |
| 819 | } |
| 820 | } |
| 821 | default: |
| 822 | break; |
| 823 | } |
| 824 | } |
| 825 | break; |
| 826 | |
| 827 | case '.': |
| 828 | if (clang_type.IsValid()) |
| 829 | { |
| 830 | switch (type_class) |
| 831 | { |
| 832 | case lldb::eTypeClassUnion: |
| 833 | case lldb::eTypeClassStruct: |
| 834 | case lldb::eTypeClassClass: |
| 835 | if (partial_path[1]) |
| 836 | { |
| 837 | // If there is more after the ".", then search deeper |
| 838 | PrivateAutoComplete (frame, |
| 839 | partial_path.substr(1), |
| 840 | prefix_path + ".", |
| 841 | clang_type, |
| 842 | matches, |
| 843 | word_complete); |
| 844 | |
| 845 | } |
| 846 | else |
| 847 | { |
| 848 | // Nothing after the ".", so list all members |
| 849 | PrivateAutoCompleteMembers (frame, |
| 850 | std::string(), |
| 851 | partial_path, |
| 852 | prefix_path + ".", |
| 853 | clang_type, |
| 854 | matches, |
| 855 | word_complete); |
| 856 | } |
| 857 | default: |
| 858 | break; |
| 859 | } |
| 860 | } |
| 861 | break; |
| 862 | default: |
| 863 | if (isalpha(ch) || ch == '_' || ch == '$') |
| 864 | { |
| 865 | const size_t partial_path_len = partial_path.size(); |
| 866 | size_t pos = 1; |
| 867 | while (pos < partial_path_len) |
| 868 | { |
| 869 | const char curr_ch = partial_path[pos]; |
| 870 | if (isalnum(curr_ch) || curr_ch == '_' || curr_ch == '$') |
| 871 | { |
| 872 | ++pos; |
| 873 | continue; |
| 874 | } |
| 875 | break; |
| 876 | } |
| 877 | |
| 878 | std::string token(partial_path, 0, pos); |
| 879 | remaining_partial_path = partial_path.substr(pos); |
| 880 | |
| 881 | if (clang_type.IsValid()) |
| 882 | { |
| 883 | PrivateAutoCompleteMembers (frame, |
| 884 | token, |
| 885 | remaining_partial_path, |
| 886 | prefix_path, |
| 887 | clang_type, |
| 888 | matches, |
| 889 | word_complete); |
| 890 | } |
| 891 | else if (frame) |
| 892 | { |
| 893 | // We haven't found our variable yet |
| 894 | const bool get_file_globals = true; |
| 895 | |
| 896 | VariableList *variable_list = frame->GetVariableList(get_file_globals); |
| 897 | |
Enrico Granata | 16f35ea | 2013-12-21 08:44:28 +0000 | [diff] [blame] | 898 | if (!variable_list) |
| 899 | break; |
| 900 | |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 901 | const size_t num_variables = variable_list->GetSize(); |
| 902 | for (size_t i=0; i<num_variables; ++i) |
| 903 | { |
| 904 | Variable *variable = variable_list->GetVariableAtIndex(i).get(); |
Enrico Granata | 16f35ea | 2013-12-21 08:44:28 +0000 | [diff] [blame] | 905 | |
| 906 | if (!variable) |
| 907 | continue; |
| 908 | |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 909 | const char *variable_name = variable->GetName().AsCString(); |
| 910 | if (strstr(variable_name, token.c_str()) == variable_name) |
| 911 | { |
| 912 | if (strcmp (variable_name, token.c_str()) == 0) |
| 913 | { |
| 914 | Type *variable_type = variable->GetType(); |
| 915 | if (variable_type) |
| 916 | { |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 917 | CompilerType variable_clang_type (variable_type->GetForwardCompilerType ()); |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 918 | PrivateAutoComplete (frame, |
| 919 | remaining_partial_path, |
| 920 | prefix_path + token, // Anything that has been resolved already will be in here |
| 921 | variable_clang_type.GetCanonicalType(), |
| 922 | matches, |
| 923 | word_complete); |
| 924 | } |
| 925 | else |
| 926 | { |
| 927 | matches.AppendString (prefix_path + variable_name); |
| 928 | } |
| 929 | } |
| 930 | else if (remaining_partial_path.empty()) |
| 931 | { |
| 932 | matches.AppendString (prefix_path + variable_name); |
| 933 | } |
| 934 | } |
| 935 | } |
| 936 | } |
| 937 | } |
| 938 | break; |
| 939 | } |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | |
| 944 | |
| 945 | size_t |
| 946 | Variable::AutoComplete (const ExecutionContext &exe_ctx, |
| 947 | const char *partial_path_cstr, |
| 948 | StringList &matches, |
| 949 | bool &word_complete) |
| 950 | { |
| 951 | word_complete = false; |
| 952 | std::string partial_path; |
| 953 | std::string prefix_path; |
Greg Clayton | a1e5dc8 | 2015-08-11 22:53:00 +0000 | [diff] [blame] | 954 | CompilerType clang_type; |
Greg Clayton | f21fead | 2013-05-14 23:43:18 +0000 | [diff] [blame] | 955 | if (partial_path_cstr && partial_path_cstr[0]) |
| 956 | partial_path = partial_path_cstr; |
| 957 | |
| 958 | PrivateAutoComplete (exe_ctx.GetFramePtr(), |
| 959 | partial_path, |
| 960 | prefix_path, |
| 961 | clang_type, |
| 962 | matches, |
| 963 | word_complete); |
| 964 | |
| 965 | return matches.GetSize(); |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 966 | } |
| 967 | |