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