[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- Variable.cpp ------------------------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Symbol/Variable.h"
|
|
|
|
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2011-07-09 05:46:14 +08:00
|
|
|
#include "lldb/Core/ValueObject.h"
|
|
|
|
#include "lldb/Core/ValueObjectVariable.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/Block.h"
|
2015-07-09 06:32:23 +08:00
|
|
|
#include "lldb/Symbol/CompileUnit.h"
|
2015-09-16 07:44:17 +08:00
|
|
|
#include "lldb/Symbol/CompilerDecl.h"
|
|
|
|
#include "lldb/Symbol/CompilerDeclContext.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/Function.h"
|
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
2015-09-16 07:44:17 +08:00
|
|
|
#include "lldb/Symbol/SymbolFile.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/Type.h"
|
TypeSystem is now a plugin interface and removed any "ClangASTContext &Class::GetClangASTContext()" functions.
This cleans up type systems to be more pluggable. Prior to this we had issues:
- Module, SymbolFile, and many others has "ClangASTContext &GetClangASTContext()" functions. All have been switched over to use "TypeSystem *GetTypeSystemForLanguage()"
- Cleaned up any places that were using the GetClangASTContext() functions to use TypeSystem
- Cleaned up Module so that it no longer has dedicated type system member variables:
lldb::ClangASTContextUP m_ast; ///< The Clang AST context for this module.
lldb::GoASTContextUP m_go_ast; ///< The Go AST context for this module.
Now we have a type system map:
typedef std::map<lldb::LanguageType, lldb::TypeSystemSP> TypeSystemMap;
TypeSystemMap m_type_system_map; ///< A map of any type systems associated with this module
- Many places in code were using ClangASTContext static functions to place with CompilerType objects and add modifiers (const, volatile, restrict) and to make typedefs, L and R value references and more. These have been made into CompilerType functions that are abstract:
class CompilerType
{
...
//----------------------------------------------------------------------
// Return a new CompilerType that is a L value reference to this type if
// this type is valid and the type system supports L value references,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
GetLValueReferenceType () const;
//----------------------------------------------------------------------
// Return a new CompilerType that is a R value reference to this type if
// this type is valid and the type system supports R value references,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
GetRValueReferenceType () const;
//----------------------------------------------------------------------
// Return a new CompilerType adds a const modifier to this type if
// this type is valid and the type system supports const modifiers,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
AddConstModifier () const;
//----------------------------------------------------------------------
// Return a new CompilerType adds a volatile modifier to this type if
// this type is valid and the type system supports volatile modifiers,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
AddVolatileModifier () const;
//----------------------------------------------------------------------
// Return a new CompilerType adds a restrict modifier to this type if
// this type is valid and the type system supports restrict modifiers,
// else return an invalid type.
//----------------------------------------------------------------------
CompilerType
AddRestrictModifier () const;
//----------------------------------------------------------------------
// Create a typedef to this type using "name" as the name of the typedef
// this type is valid and the type system supports typedefs, else return
// an invalid type.
//----------------------------------------------------------------------
CompilerType
CreateTypedef (const char *name, const CompilerDeclContext &decl_ctx) const;
};
Other changes include:
- Removed "CompilerType TypeSystem::GetIntTypeFromBitSize(...)" and CompilerType TypeSystem::GetFloatTypeFromBitSize(...) and replaced it with "CompilerType TypeSystem::GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, size_t bit_size);"
- Fixed code in Type.h to not request the full type for a type for no good reason, just request the forward type and let the type expand as needed
llvm-svn: 247953
2015-09-18 06:23:34 +08:00
|
|
|
#include "lldb/Symbol/TypeSystem.h"
|
2011-07-09 05:46:14 +08:00
|
|
|
#include "lldb/Symbol/VariableList.h"
|
2011-09-02 09:15:17 +08:00
|
|
|
#include "lldb/Target/ABI.h"
|
2010-09-15 07:36:40 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
2010-08-25 05:05:24 +08:00
|
|
|
#include "lldb/Target/RegisterContext.h"
|
2013-11-04 17:33:30 +08:00
|
|
|
#include "lldb/Target/StackFrame.h"
|
2010-09-15 07:36:40 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/RegularExpression.h"
|
|
|
|
#include "lldb/Utility/Stream.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-11-17 09:37:42 +08:00
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2019-09-21 01:15:57 +08:00
|
|
|
Variable::Variable(lldb::user_id_t uid, const char *name, const char *mangled,
|
|
|
|
const lldb::SymbolFileTypeSP &symfile_type_sp,
|
|
|
|
ValueType scope, SymbolContextScope *context,
|
|
|
|
const RangeList &scope_range, Declaration *decl_ptr,
|
|
|
|
const DWARFExpression &location, bool external,
|
2020-10-14 08:00:32 +08:00
|
|
|
bool artificial, bool location_is_constant_data,
|
|
|
|
bool static_member)
|
2015-03-25 02:32:27 +08:00
|
|
|
: UserID(uid), m_name(name), m_mangled(ConstString(mangled)),
|
2011-12-08 10:13:16 +08:00
|
|
|
m_symfile_type_sp(symfile_type_sp), m_scope(scope),
|
2016-02-25 20:23:37 +08:00
|
|
|
m_owner_scope(context), m_scope_range(scope_range),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_declaration(decl_ptr), m_location(location), m_external(external),
|
2020-10-14 08:00:32 +08:00
|
|
|
m_artificial(artificial), m_loc_is_const_data(location_is_constant_data),
|
2018-12-11 08:15:03 +08:00
|
|
|
m_static_member(static_member) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
Variable::~Variable() {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb::LanguageType Variable::GetLanguage() const {
|
2019-07-23 04:14:18 +08:00
|
|
|
lldb::LanguageType lang = m_mangled.GuessLanguage();
|
|
|
|
if (lang != lldb::eLanguageTypeUnknown)
|
|
|
|
return lang;
|
|
|
|
|
|
|
|
if (auto *func = m_owner_scope->CalculateSymbolContextFunction()) {
|
2019-07-25 06:12:02 +08:00
|
|
|
if ((lang = func->GetLanguage()) != lldb::eLanguageTypeUnknown)
|
|
|
|
return lang;
|
|
|
|
} else if (auto *comp_unit =
|
|
|
|
m_owner_scope->CalculateSymbolContextCompileUnit()) {
|
|
|
|
if ((lang = comp_unit->GetLanguage()) != lldb::eLanguageTypeUnknown)
|
2019-07-23 04:14:18 +08:00
|
|
|
return lang;
|
|
|
|
}
|
|
|
|
|
2015-07-09 06:32:23 +08:00
|
|
|
return lldb::eLanguageTypeUnknown;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2015-07-09 06:32:23 +08:00
|
|
|
ConstString Variable::GetName() const {
|
2020-01-31 13:55:18 +08:00
|
|
|
ConstString name = m_mangled.GetName();
|
2015-07-09 18:57:54 +08:00
|
|
|
if (name)
|
2015-07-09 06:32:23 +08:00
|
|
|
return name;
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
2015-09-16 07:44:17 +08:00
|
|
|
ConstString Variable::GetUnqualifiedName() const { return m_name; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-03-07 05:22:25 +08:00
|
|
|
bool Variable::NameMatches(ConstString name) const {
|
2015-07-09 06:32:23 +08:00
|
|
|
if (m_name == name)
|
|
|
|
return true;
|
|
|
|
SymbolContext variable_sc;
|
|
|
|
m_owner_scope->CalculateSymbolContext(&variable_sc);
|
|
|
|
|
2020-01-31 13:55:18 +08:00
|
|
|
return m_mangled.NameMatches(name);
|
Just like functions can have a basename and a mangled/demangled name, variable
can too. So now the lldb_private::Variable class has support for this.
Variables now have support for having a basename ("i"), and a mangled name
("_ZN12_GLOBAL__N_11iE"), and a demangled name ("(anonymous namespace)::i").
Nowwhen searching for a variable by name, users might enter the fully qualified
name, or just the basename. So new test functions were added to the Variable
and Mangled classes as:
bool NameMatches (const ConstString &name);
bool NameMatches (const RegularExpression ®ex);
I also modified "ClangExpressionDeclMap::FindVariableInScope" to also search
for global variables that are not in the current file scope by first starting
with the current module, then moving on to all modules.
Fixed an issue in the DWARF parser that could cause a varaible to get parsed
more than once. Now, once we have parsed a VariableSP for a DIE, we cache
the result even if a variable wasn't made so we don't do any re-parsing. Some
DW_TAG_variable DIEs don't have locations, or are missing vital info that
stops a debugger from being able to display anything for it, we parse a NULL
variable shared pointer for these DIEs so we don't keep trying to reparse it.
llvm-svn: 119085
2010-11-15 06:13:40 +08:00
|
|
|
}
|
2015-09-16 07:44:17 +08:00
|
|
|
bool Variable::NameMatches(const RegularExpression ®ex) const {
|
|
|
|
if (regex.Execute(m_name.AsCString()))
|
|
|
|
return true;
|
|
|
|
if (m_mangled)
|
2020-01-31 13:55:18 +08:00
|
|
|
return m_mangled.NameMatches(regex);
|
2015-09-16 07:44:17 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-09 06:32:23 +08:00
|
|
|
Type *Variable::GetType() {
|
Just like functions can have a basename and a mangled/demangled name, variable
can too. So now the lldb_private::Variable class has support for this.
Variables now have support for having a basename ("i"), and a mangled name
("_ZN12_GLOBAL__N_11iE"), and a demangled name ("(anonymous namespace)::i").
Nowwhen searching for a variable by name, users might enter the fully qualified
name, or just the basename. So new test functions were added to the Variable
and Mangled classes as:
bool NameMatches (const ConstString &name);
bool NameMatches (const RegularExpression ®ex);
I also modified "ClangExpressionDeclMap::FindVariableInScope" to also search
for global variables that are not in the current file scope by first starting
with the current module, then moving on to all modules.
Fixed an issue in the DWARF parser that could cause a varaible to get parsed
more than once. Now, once we have parsed a VariableSP for a DIE, we cache
the result even if a variable wasn't made so we don't do any re-parsing. Some
DW_TAG_variable DIEs don't have locations, or are missing vital info that
stops a debugger from being able to display anything for it, we parse a NULL
variable shared pointer for these DIEs so we don't keep trying to reparse it.
llvm-svn: 119085
2010-11-15 06:13:40 +08:00
|
|
|
if (m_symfile_type_sp)
|
2015-07-09 06:32:23 +08:00
|
|
|
return m_symfile_type_sp->GetType();
|
|
|
|
return nullptr;
|
Just like functions can have a basename and a mangled/demangled name, variable
can too. So now the lldb_private::Variable class has support for this.
Variables now have support for having a basename ("i"), and a mangled name
("_ZN12_GLOBAL__N_11iE"), and a demangled name ("(anonymous namespace)::i").
Nowwhen searching for a variable by name, users might enter the fully qualified
name, or just the basename. So new test functions were added to the Variable
and Mangled classes as:
bool NameMatches (const ConstString &name);
bool NameMatches (const RegularExpression ®ex);
I also modified "ClangExpressionDeclMap::FindVariableInScope" to also search
for global variables that are not in the current file scope by first starting
with the current module, then moving on to all modules.
Fixed an issue in the DWARF parser that could cause a varaible to get parsed
more than once. Now, once we have parsed a VariableSP for a DIE, we cache
the result even if a variable wasn't made so we don't do any re-parsing. Some
DW_TAG_variable DIEs don't have locations, or are missing vital info that
stops a debugger from being able to display anything for it, we parse a NULL
variable shared pointer for these DIEs so we don't keep trying to reparse it.
llvm-svn: 119085
2010-11-15 06:13:40 +08:00
|
|
|
}
|
|
|
|
|
2011-12-08 10:13:16 +08:00
|
|
|
void Variable::Dump(Stream *s, bool show_context) const {
|
2014-04-04 12:06:10 +08:00
|
|
|
s->Printf("%p: ", static_cast<const void *>(this));
|
2011-12-08 10:13:16 +08:00
|
|
|
s->Indent();
|
2014-04-20 21:17:36 +08:00
|
|
|
*s << "Variable" << (const UserID &)*this;
|
2011-12-08 10:13:16 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_name)
|
|
|
|
*s << ", name = \"" << m_name << "\"";
|
|
|
|
|
|
|
|
if (m_symfile_type_sp) {
|
|
|
|
Type *type = m_symfile_type_sp->GetType();
|
2016-07-02 01:17:23 +08:00
|
|
|
if (type) {
|
2019-11-14 22:31:26 +08:00
|
|
|
s->Format(", type = {{{0:x-16}} {1} (", type->GetID(), type);
|
2011-12-08 10:13:16 +08:00
|
|
|
type->DumpTypeName(s);
|
2010-06-09 00:52:24 +08:00
|
|
|
s->PutChar(')');
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2014-04-20 21:17:36 +08:00
|
|
|
if (m_scope != eValueTypeInvalid) {
|
2010-06-09 00:52:24 +08:00
|
|
|
s->PutCString(", scope = ");
|
2010-08-31 02:11:35 +08:00
|
|
|
switch (m_scope) {
|
2011-05-30 08:49:24 +08:00
|
|
|
case eValueTypeVariableGlobal:
|
2010-08-31 02:11:35 +08:00
|
|
|
s->PutCString(m_external ? "global" : "static");
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2010-08-31 02:11:35 +08:00
|
|
|
case eValueTypeVariableArgument:
|
2016-07-02 01:17:23 +08:00
|
|
|
s->PutCString("parameter");
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
case eValueTypeVariableLocal:
|
|
|
|
s->PutCString("local");
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2016-07-02 01:17:23 +08:00
|
|
|
case eValueTypeVariableThreadLocal:
|
|
|
|
s->PutCString("thread local");
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
default:
|
2019-11-26 21:45:15 +08:00
|
|
|
s->AsRawOstream() << "??? (" << m_scope << ')';
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-04-20 21:17:36 +08:00
|
|
|
if (show_context && m_owner_scope != nullptr) {
|
2010-06-09 00:52:24 +08:00
|
|
|
s->PutCString(", context = ( ");
|
2010-08-31 02:11:35 +08:00
|
|
|
m_owner_scope->DumpSymbolContext(s);
|
2010-06-09 00:52:24 +08:00
|
|
|
s->PutCString(" )");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-09-15 13:51:24 +08:00
|
|
|
bool show_fullpaths = false;
|
|
|
|
m_declaration.Dump(s, show_fullpaths);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_location.IsValid()) {
|
|
|
|
s->PutCString(", location = ");
|
2010-09-14 10:20:48 +08:00
|
|
|
lldb::addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
|
|
|
|
if (m_location.IsLocationList()) {
|
|
|
|
SymbolContext variable_sc;
|
|
|
|
m_owner_scope->CalculateSymbolContext(&variable_sc);
|
|
|
|
if (variable_sc.function)
|
|
|
|
loclist_base_addr = variable_sc.function->GetAddressRange()
|
|
|
|
.GetBaseAddress()
|
|
|
|
.GetFileAddress();
|
|
|
|
}
|
2018-11-15 13:06:59 +08:00
|
|
|
ABISP abi;
|
2011-09-02 09:15:17 +08:00
|
|
|
if (m_owner_scope) {
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP module_sp(m_owner_scope->CalculateSymbolContextModule());
|
|
|
|
if (module_sp)
|
2018-11-15 13:06:59 +08:00
|
|
|
abi = ABI::FindPlugin(ProcessSP(), module_sp->GetArchitecture());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2011-09-02 09:15:17 +08:00
|
|
|
m_location.GetDescription(s, lldb::eDescriptionLevelBrief,
|
2018-11-15 13:06:59 +08:00
|
|
|
loclist_base_addr, abi.get());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (m_external)
|
|
|
|
s->PutCString(", external");
|
|
|
|
|
|
|
|
if (m_artificial)
|
|
|
|
s->PutCString(", artificial");
|
|
|
|
|
|
|
|
s->EOL();
|
|
|
|
}
|
|
|
|
|
2011-07-11 03:21:23 +08:00
|
|
|
bool Variable::DumpDeclaration(Stream *s, bool show_fullpaths,
|
|
|
|
bool show_module) {
|
|
|
|
bool dumped_declaration_info = false;
|
|
|
|
if (m_owner_scope) {
|
|
|
|
SymbolContext sc;
|
|
|
|
m_owner_scope->CalculateSymbolContext(&sc);
|
2014-04-20 21:17:36 +08:00
|
|
|
sc.block = nullptr;
|
2011-07-11 03:21:23 +08:00
|
|
|
sc.line_entry.Clear();
|
|
|
|
bool show_inlined_frames = false;
|
2014-10-11 07:07:36 +08:00
|
|
|
const bool show_function_arguments = true;
|
2015-02-14 07:24:21 +08:00
|
|
|
const bool show_function_name = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-11 03:21:23 +08:00
|
|
|
dumped_declaration_info = sc.DumpStopContext(
|
2014-10-11 07:07:36 +08:00
|
|
|
s, nullptr, Address(), show_fullpaths, show_module, show_inlined_frames,
|
2015-02-14 07:24:21 +08:00
|
|
|
show_function_arguments, show_function_name);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-11 03:21:23 +08:00
|
|
|
if (sc.function)
|
|
|
|
s->PutChar(':');
|
|
|
|
}
|
|
|
|
if (m_declaration.DumpStopContext(s, false))
|
|
|
|
dumped_declaration_info = true;
|
|
|
|
return dumped_declaration_info;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
size_t Variable::MemorySize() const { return sizeof(Variable); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
CompilerDeclContext Variable::GetDeclContext() {
|
2015-09-16 07:44:17 +08:00
|
|
|
Type *type = GetType();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (type)
|
|
|
|
return type->GetSymbolFile()->GetDeclContextContainingUID(GetID());
|
2016-04-12 08:06:27 +08:00
|
|
|
return CompilerDeclContext();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2015-09-16 07:44:17 +08:00
|
|
|
CompilerDecl Variable::GetDecl() {
|
|
|
|
Type *type = GetType();
|
2016-04-12 08:06:27 +08:00
|
|
|
return type ? type->GetSymbolFile()->GetDeclForUID(GetID()) : CompilerDecl();
|
2015-09-16 07:44:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Variable::CalculateSymbolContext(SymbolContext *sc) {
|
|
|
|
if (m_owner_scope) {
|
2016-05-24 02:30:59 +08:00
|
|
|
m_owner_scope->CalculateSymbolContext(sc);
|
|
|
|
sc->variable = this;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2016-05-24 02:30:59 +08:00
|
|
|
sc->Clear(false);
|
2015-09-16 07:44:17 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
bool Variable::LocationIsValidForFrame(StackFrame *frame) {
|
|
|
|
// Is the variable is described by a single location?
|
|
|
|
if (!m_location.IsLocationList()) {
|
|
|
|
// Yes it is, the location is valid.
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-05-30 08:49:24 +08:00
|
|
|
if (frame) {
|
|
|
|
Function *function =
|
2010-06-09 00:52:24 +08:00
|
|
|
frame->GetSymbolContext(eSymbolContextFunction).function;
|
2010-08-31 02:11:35 +08:00
|
|
|
if (function) {
|
|
|
|
TargetSP target_sp(frame->CalculateTarget());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-08-31 02:11:35 +08:00
|
|
|
addr_t loclist_base_load_addr =
|
2012-02-18 13:35:26 +08:00
|
|
|
function->GetAddressRange().GetBaseAddress().GetLoadAddress(
|
|
|
|
target_sp.get());
|
2010-09-14 10:20:48 +08:00
|
|
|
if (loclist_base_load_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
2018-05-01 00:49:04 +08:00
|
|
|
// It is a location list. We just need to tell if the location list
|
|
|
|
// contains the current address when converted to a load address
|
2010-08-31 02:11:35 +08:00
|
|
|
return m_location.LocationListContainsAddress(
|
2015-01-15 10:59:20 +08:00
|
|
|
loclist_base_load_addr,
|
|
|
|
frame->GetFrameCodeAddress().GetLoadAddress(target_sp.get()));
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-02-23 12:12:47 +08:00
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
bool Variable::LocationIsValidForAddress(const Address &address) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Be sure to resolve the address to section offset prior to calling this
|
|
|
|
// function.
|
2010-06-09 00:52:24 +08:00
|
|
|
if (address.IsSectionOffset()) {
|
2011-07-11 13:12:02 +08:00
|
|
|
SymbolContext sc;
|
|
|
|
CalculateSymbolContext(&sc);
|
2012-02-24 09:59:29 +08:00
|
|
|
if (sc.module_sp == address.GetModule()) {
|
2011-05-30 08:49:24 +08:00
|
|
|
// Is the variable is described by a single location?
|
|
|
|
if (!m_location.IsLocationList()) {
|
|
|
|
// Yes it is, the location is valid.
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-07-11 13:12:02 +08:00
|
|
|
if (sc.function) {
|
|
|
|
addr_t loclist_base_file_addr =
|
|
|
|
sc.function->GetAddressRange().GetBaseAddress().GetFileAddress();
|
|
|
|
if (loclist_base_file_addr == LLDB_INVALID_ADDRESS)
|
2010-09-14 10:20:48 +08:00
|
|
|
return false;
|
2018-05-01 00:49:04 +08:00
|
|
|
// It is a location list. We just need to tell if the location list
|
|
|
|
// contains the current address when converted to a load address
|
2011-07-11 13:12:02 +08:00
|
|
|
return m_location.LocationListContainsAddress(loclist_base_file_addr,
|
|
|
|
address.GetFileAddress());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-05-30 08:49:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-09-14 10:20:48 +08:00
|
|
|
return false;
|
2011-05-30 08:49:24 +08:00
|
|
|
}
|
|
|
|
|
2011-07-11 13:12:02 +08:00
|
|
|
bool Variable::IsInScope(StackFrame *frame) {
|
|
|
|
switch (m_scope) {
|
|
|
|
case eValueTypeRegister:
|
2011-05-30 08:49:24 +08:00
|
|
|
case eValueTypeRegisterSet:
|
2014-04-20 21:17:36 +08:00
|
|
|
return frame != nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-11 13:12:02 +08:00
|
|
|
case eValueTypeConstResult:
|
2011-05-30 08:49:24 +08:00
|
|
|
case eValueTypeVariableGlobal:
|
2011-07-11 13:12:02 +08:00
|
|
|
case eValueTypeVariableStatic:
|
|
|
|
case eValueTypeVariableThreadLocal:
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-11 13:12:02 +08:00
|
|
|
case eValueTypeVariableArgument:
|
2011-05-30 08:49:24 +08:00
|
|
|
case eValueTypeVariableLocal:
|
|
|
|
if (frame) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// We don't have a location list, we just need to see if the block that
|
|
|
|
// this variable was defined in is currently
|
2010-09-14 11:16:58 +08:00
|
|
|
Block *deepest_frame_block =
|
2011-07-11 13:12:02 +08:00
|
|
|
frame->GetSymbolContext(eSymbolContextBlock).block;
|
|
|
|
if (deepest_frame_block) {
|
|
|
|
SymbolContext variable_sc;
|
|
|
|
CalculateSymbolContext(&variable_sc);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-11 13:12:02 +08:00
|
|
|
// Check for static or global variable defined at the compile unit
|
|
|
|
// level that wasn't defined in a block
|
|
|
|
if (variable_sc.block == nullptr)
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-11 13:12:02 +08:00
|
|
|
// Check if the variable is valid in the current block
|
|
|
|
if (variable_sc.block != deepest_frame_block &&
|
|
|
|
!variable_sc.block->Contains(deepest_frame_block))
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-11 13:12:02 +08:00
|
|
|
// If no scope range is specified then it means that the scope is the
|
2018-05-01 00:49:04 +08:00
|
|
|
// same as the scope of the enclosing lexical block.
|
2011-07-11 13:12:02 +08:00
|
|
|
if (m_scope_range.IsEmpty())
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-11 13:12:02 +08:00
|
|
|
addr_t file_address = frame->GetFrameCodeAddress().GetFileAddress();
|
|
|
|
return m_scope_range.FindEntryThatContains(file_address) != nullptr;
|
|
|
|
}
|
|
|
|
}
|
2014-04-20 21:17:36 +08:00
|
|
|
break;
|
2011-07-10 04:12:33 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
default:
|
2010-09-14 11:16:58 +08:00
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status Variable::GetValuesForVariableExpressionPath(
|
2016-11-19 03:23:39 +08:00
|
|
|
llvm::StringRef variable_expr_path, ExecutionContextScope *scope,
|
2011-07-09 05:46:14 +08:00
|
|
|
GetVariableCallback callback, void *baton, VariableList &variable_list,
|
|
|
|
ValueObjectList &valobj_list) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-11-19 03:23:39 +08:00
|
|
|
if (!callback || variable_expr_path.empty()) {
|
|
|
|
error.SetErrorString("unknown error");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (variable_expr_path.front()) {
|
|
|
|
case '*':
|
|
|
|
error = Variable::GetValuesForVariableExpressionPath(
|
|
|
|
variable_expr_path.drop_front(), scope, callback, baton, variable_list,
|
|
|
|
valobj_list);
|
|
|
|
if (error.Fail()) {
|
|
|
|
error.SetErrorString("unknown error");
|
2011-07-09 05:46:14 +08:00
|
|
|
return error;
|
2016-11-19 03:23:39 +08:00
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < valobj_list.GetSize();) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status tmp_error;
|
2016-11-19 03:23:39 +08:00
|
|
|
ValueObjectSP valobj_sp(
|
|
|
|
valobj_list.GetValueObjectAtIndex(i)->Dereference(tmp_error));
|
|
|
|
if (tmp_error.Fail()) {
|
|
|
|
variable_list.RemoveVariableAtIndex(i);
|
|
|
|
valobj_list.RemoveValueObjectAtIndex(i);
|
2011-07-09 05:46:14 +08:00
|
|
|
} else {
|
2016-11-19 03:23:39 +08:00
|
|
|
valobj_list.SetValueObjectAtIndex(i, valobj_sp);
|
|
|
|
++i;
|
2011-07-09 05:46:14 +08:00
|
|
|
}
|
2016-11-19 03:23:39 +08:00
|
|
|
}
|
|
|
|
return error;
|
|
|
|
case '&': {
|
|
|
|
error = Variable::GetValuesForVariableExpressionPath(
|
|
|
|
variable_expr_path.drop_front(), scope, callback, baton, variable_list,
|
|
|
|
valobj_list);
|
|
|
|
if (error.Success()) {
|
|
|
|
for (uint32_t i = 0; i < valobj_list.GetSize();) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status tmp_error;
|
2016-11-19 03:23:39 +08:00
|
|
|
ValueObjectSP valobj_sp(
|
|
|
|
valobj_list.GetValueObjectAtIndex(i)->AddressOf(tmp_error));
|
|
|
|
if (tmp_error.Fail()) {
|
|
|
|
variable_list.RemoveVariableAtIndex(i);
|
|
|
|
valobj_list.RemoveValueObjectAtIndex(i);
|
|
|
|
} else {
|
|
|
|
valobj_list.SetValueObjectAtIndex(i, valobj_sp);
|
|
|
|
++i;
|
2011-07-09 05:46:14 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-11-19 03:23:39 +08:00
|
|
|
} else {
|
|
|
|
error.SetErrorString("unknown error");
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
static RegularExpression g_regex(
|
|
|
|
llvm::StringRef("^([A-Za-z_:][A-Za-z_0-9:]*)(.*)"));
|
2019-08-17 05:25:36 +08:00
|
|
|
llvm::SmallVector<llvm::StringRef, 2> matches;
|
2016-11-19 03:23:39 +08:00
|
|
|
variable_list.Clear();
|
2019-08-17 05:25:36 +08:00
|
|
|
if (!g_regex.Execute(variable_expr_path, &matches)) {
|
2013-05-21 00:52:10 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
2016-11-19 08:50:29 +08:00
|
|
|
"unable to extract a variable name from '%s'",
|
|
|
|
variable_expr_path.str().c_str());
|
2016-11-19 03:23:39 +08:00
|
|
|
return error;
|
|
|
|
}
|
2019-08-17 05:25:36 +08:00
|
|
|
std::string variable_name = matches[1].str();
|
2016-11-19 03:23:39 +08:00
|
|
|
if (!callback(baton, variable_name.c_str(), variable_list)) {
|
|
|
|
error.SetErrorString("unknown error");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
uint32_t i = 0;
|
|
|
|
while (i < variable_list.GetSize()) {
|
|
|
|
VariableSP var_sp(variable_list.GetVariableAtIndex(i));
|
|
|
|
ValueObjectSP valobj_sp;
|
|
|
|
if (!var_sp) {
|
|
|
|
variable_list.RemoveVariableAtIndex(i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ValueObjectSP variable_valobj_sp(
|
|
|
|
ValueObjectVariable::Create(scope, var_sp));
|
|
|
|
if (!variable_valobj_sp) {
|
|
|
|
variable_list.RemoveVariableAtIndex(i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::StringRef variable_sub_expr_path =
|
|
|
|
variable_expr_path.drop_front(variable_name.size());
|
|
|
|
if (!variable_sub_expr_path.empty()) {
|
|
|
|
valobj_sp = variable_valobj_sp->GetValueForExpressionPath(
|
2017-12-07 18:38:22 +08:00
|
|
|
variable_sub_expr_path);
|
2016-11-19 03:23:39 +08:00
|
|
|
if (!valobj_sp) {
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"invalid expression path '%s' for variable '%s'",
|
2016-11-19 08:50:29 +08:00
|
|
|
variable_sub_expr_path.str().c_str(),
|
|
|
|
var_sp->GetName().GetCString());
|
2016-11-19 03:23:39 +08:00
|
|
|
variable_list.RemoveVariableAtIndex(i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Just the name of a variable with no extras
|
|
|
|
valobj_sp = variable_valobj_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
valobj_list.Append(valobj_sp);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (variable_list.GetSize() > 0) {
|
|
|
|
error.Clear();
|
|
|
|
return error;
|
2011-07-09 05:46:14 +08:00
|
|
|
}
|
2016-11-19 03:23:39 +08:00
|
|
|
} break;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-09 05:46:14 +08:00
|
|
|
error.SetErrorString("unknown error");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2011-07-11 13:12:02 +08:00
|
|
|
bool Variable::DumpLocationForAddress(Stream *s, const Address &address) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Be sure to resolve the address to section offset prior to calling this
|
|
|
|
// function.
|
2011-07-11 13:12:02 +08:00
|
|
|
if (address.IsSectionOffset()) {
|
|
|
|
SymbolContext sc;
|
|
|
|
CalculateSymbolContext(&sc);
|
2012-02-24 09:59:29 +08:00
|
|
|
if (sc.module_sp == address.GetModule()) {
|
2018-11-15 13:06:59 +08:00
|
|
|
ABISP abi;
|
2011-09-02 09:15:17 +08:00
|
|
|
if (m_owner_scope) {
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP module_sp(m_owner_scope->CalculateSymbolContextModule());
|
|
|
|
if (module_sp)
|
2018-11-15 13:06:59 +08:00
|
|
|
abi = ABI::FindPlugin(ProcessSP(), module_sp->GetArchitecture());
|
2011-09-02 09:15:17 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-11 13:12:02 +08:00
|
|
|
const addr_t file_addr = address.GetFileAddress();
|
|
|
|
if (sc.function) {
|
|
|
|
if (sc.function->GetAddressRange().ContainsFileAddress(address)) {
|
|
|
|
addr_t loclist_base_file_addr =
|
|
|
|
sc.function->GetAddressRange().GetBaseAddress().GetFileAddress();
|
|
|
|
if (loclist_base_file_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
|
|
|
return m_location.DumpLocationForAddress(s, eDescriptionLevelBrief,
|
|
|
|
loclist_base_file_addr,
|
2018-11-15 13:06:59 +08:00
|
|
|
file_addr, abi.get());
|
2011-07-11 13:12:02 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2018-11-15 13:06:59 +08:00
|
|
|
return m_location.DumpLocationForAddress(s, eDescriptionLevelBrief,
|
|
|
|
LLDB_INVALID_ADDRESS, file_addr,
|
|
|
|
abi.get());
|
2011-07-11 13:12:02 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-11 13:12:02 +08:00
|
|
|
return false;
|
2013-05-15 07:43:18 +08:00
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
static void PrivateAutoComplete(
|
2016-11-17 09:37:42 +08:00
|
|
|
StackFrame *frame, llvm::StringRef partial_path,
|
|
|
|
const llvm::Twine
|
2013-05-15 07:43:18 +08:00
|
|
|
&prefix_path, // Anything that has been resolved already will be in here
|
2019-08-19 19:49:43 +08:00
|
|
|
const CompilerType &compiler_type, CompletionRequest &request);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
static void PrivateAutoCompleteMembers(
|
2013-05-15 07:43:18 +08:00
|
|
|
StackFrame *frame, const std::string &partial_member_name,
|
2016-11-17 09:37:42 +08:00
|
|
|
llvm::StringRef partial_path,
|
|
|
|
const llvm::Twine
|
2013-05-15 07:43:18 +08:00
|
|
|
&prefix_path, // Anything that has been resolved already will be in here
|
2019-08-19 19:49:43 +08:00
|
|
|
const CompilerType &compiler_type, CompletionRequest &request) {
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
// We are in a type parsing child members
|
2015-09-24 11:54:50 +08:00
|
|
|
const uint32_t num_bases = compiler_type.GetNumDirectBaseClasses();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
if (num_bases > 0) {
|
|
|
|
for (uint32_t i = 0; i < num_bases; ++i) {
|
2015-09-24 11:54:50 +08:00
|
|
|
CompilerType base_class_type =
|
|
|
|
compiler_type.GetDirectBaseClassAtIndex(i, nullptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-08-19 19:49:43 +08:00
|
|
|
PrivateAutoCompleteMembers(frame, partial_member_name, partial_path,
|
|
|
|
prefix_path,
|
|
|
|
base_class_type.GetCanonicalType(), request);
|
2013-05-15 07:43:18 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-05-15 07:43:18 +08:00
|
|
|
|
2015-09-24 11:54:50 +08:00
|
|
|
const uint32_t num_vbases = compiler_type.GetNumVirtualBaseClasses();
|
2013-05-15 07:43:18 +08:00
|
|
|
|
|
|
|
if (num_vbases > 0) {
|
|
|
|
for (uint32_t i = 0; i < num_vbases; ++i) {
|
2015-09-24 11:54:50 +08:00
|
|
|
CompilerType vbase_class_type =
|
|
|
|
compiler_type.GetVirtualBaseClassAtIndex(i, nullptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-08-19 19:49:43 +08:00
|
|
|
PrivateAutoCompleteMembers(frame, partial_member_name, partial_path,
|
|
|
|
prefix_path,
|
|
|
|
vbase_class_type.GetCanonicalType(), request);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
// We are in a type parsing child members
|
2015-09-24 11:54:50 +08:00
|
|
|
const uint32_t num_fields = compiler_type.GetNumFields();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
if (num_fields > 0) {
|
|
|
|
for (uint32_t i = 0; i < num_fields; ++i) {
|
|
|
|
std::string member_name;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-24 11:54:50 +08:00
|
|
|
CompilerType member_compiler_type = compiler_type.GetFieldAtIndex(
|
|
|
|
i, member_name, nullptr, nullptr, nullptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
if (partial_member_name.empty() ||
|
2020-04-01 02:56:24 +08:00
|
|
|
llvm::StringRef(member_name).startswith(partial_member_name)) {
|
2013-05-15 07:43:18 +08:00
|
|
|
if (member_name == partial_member_name) {
|
|
|
|
PrivateAutoComplete(
|
|
|
|
frame, partial_path,
|
|
|
|
prefix_path + member_name, // Anything that has been resolved
|
|
|
|
// already will be in here
|
2019-08-19 19:49:43 +08:00
|
|
|
member_compiler_type.GetCanonicalType(), request);
|
2013-05-15 07:43:18 +08:00
|
|
|
} else {
|
2019-08-19 19:49:43 +08:00
|
|
|
request.AddCompletion((prefix_path + member_name).str());
|
2013-05-15 07:43:18 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-05-15 07:43:18 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-05-15 07:43:18 +08:00
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
static void PrivateAutoComplete(
|
2016-11-17 09:37:42 +08:00
|
|
|
StackFrame *frame, llvm::StringRef partial_path,
|
|
|
|
const llvm::Twine
|
2013-05-15 07:43:18 +08:00
|
|
|
&prefix_path, // Anything that has been resolved already will be in here
|
2019-08-19 19:49:43 +08:00
|
|
|
const CompilerType &compiler_type, CompletionRequest &request) {
|
2013-05-15 07:43:18 +08:00
|
|
|
// printf ("\nPrivateAutoComplete()\n\tprefix_path = '%s'\n\tpartial_path =
|
|
|
|
// '%s'\n", prefix_path.c_str(), partial_path.c_str());
|
|
|
|
std::string remaining_partial_path;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-24 11:54:50 +08:00
|
|
|
const lldb::TypeClass type_class = compiler_type.GetTypeClass();
|
2013-05-15 07:43:18 +08:00
|
|
|
if (partial_path.empty()) {
|
2015-09-24 11:54:50 +08:00
|
|
|
if (compiler_type.IsValid()) {
|
2013-05-15 07:43:18 +08:00
|
|
|
switch (type_class) {
|
|
|
|
default:
|
|
|
|
case eTypeClassArray:
|
|
|
|
case eTypeClassBlockPointer:
|
|
|
|
case eTypeClassBuiltin:
|
|
|
|
case eTypeClassComplexFloat:
|
|
|
|
case eTypeClassComplexInteger:
|
|
|
|
case eTypeClassEnumeration:
|
|
|
|
case eTypeClassFunction:
|
|
|
|
case eTypeClassMemberPointer:
|
|
|
|
case eTypeClassReference:
|
|
|
|
case eTypeClassTypedef:
|
|
|
|
case eTypeClassVector: {
|
2019-08-19 19:49:43 +08:00
|
|
|
request.AddCompletion(prefix_path.str());
|
2013-05-15 07:43:18 +08:00
|
|
|
} break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
case eTypeClassClass:
|
|
|
|
case eTypeClassStruct:
|
|
|
|
case eTypeClassUnion:
|
2016-11-17 09:37:42 +08:00
|
|
|
if (prefix_path.str().back() != '.')
|
2019-08-19 19:49:43 +08:00
|
|
|
request.AddCompletion((prefix_path + ".").str());
|
2013-05-15 07:43:18 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
case eTypeClassObjCObject:
|
|
|
|
case eTypeClassObjCInterface:
|
|
|
|
break;
|
|
|
|
case eTypeClassObjCObjectPointer:
|
|
|
|
case eTypeClassPointer: {
|
|
|
|
bool omit_empty_base_classes = true;
|
2018-11-06 04:49:07 +08:00
|
|
|
if (compiler_type.GetNumChildren(omit_empty_base_classes, nullptr) > 0)
|
2019-08-19 19:49:43 +08:00
|
|
|
request.AddCompletion((prefix_path + "->").str());
|
2013-05-15 07:43:18 +08:00
|
|
|
else {
|
2019-08-19 19:49:43 +08:00
|
|
|
request.AddCompletion(prefix_path.str());
|
2013-05-15 07:43:18 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} break;
|
|
|
|
}
|
2013-05-15 07:43:18 +08:00
|
|
|
} else {
|
|
|
|
if (frame) {
|
|
|
|
const bool get_file_globals = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
VariableList *variable_list = frame->GetVariableList(get_file_globals);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-10-09 10:39:26 +08:00
|
|
|
if (variable_list) {
|
2019-11-25 22:03:46 +08:00
|
|
|
for (const VariableSP &var_sp : *variable_list)
|
|
|
|
request.AddCompletion(var_sp->GetName().AsCString());
|
2013-05-15 07:43:18 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-05-15 07:43:18 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const char ch = partial_path[0];
|
|
|
|
switch (ch) {
|
|
|
|
case '*':
|
2016-11-17 09:37:42 +08:00
|
|
|
if (prefix_path.str().empty()) {
|
|
|
|
PrivateAutoComplete(frame, partial_path.substr(1), "*", compiler_type,
|
2019-08-19 19:49:43 +08:00
|
|
|
request);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
case '&':
|
2016-11-17 09:37:42 +08:00
|
|
|
if (prefix_path.isTriviallyEmpty()) {
|
2013-05-21 00:52:10 +08:00
|
|
|
PrivateAutoComplete(frame, partial_path.substr(1), std::string("&"),
|
2019-08-19 19:49:43 +08:00
|
|
|
compiler_type, request);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
case '-':
|
2018-07-28 07:37:08 +08:00
|
|
|
if (partial_path.size() > 1 && partial_path[1] == '>' &&
|
|
|
|
!prefix_path.str().empty()) {
|
2013-05-15 07:43:18 +08:00
|
|
|
switch (type_class) {
|
|
|
|
case lldb::eTypeClassPointer: {
|
2015-09-24 11:54:50 +08:00
|
|
|
CompilerType pointee_type(compiler_type.GetPointeeType());
|
2018-07-28 07:37:08 +08:00
|
|
|
if (partial_path.size() > 2 && partial_path[2]) {
|
2013-05-15 07:43:18 +08:00
|
|
|
// If there is more after the "->", then search deeper
|
2019-08-19 19:49:43 +08:00
|
|
|
PrivateAutoComplete(frame, partial_path.substr(2),
|
|
|
|
prefix_path + "->",
|
|
|
|
pointee_type.GetCanonicalType(), request);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2013-05-15 07:43:18 +08:00
|
|
|
// Nothing after the "->", so list all members
|
|
|
|
PrivateAutoCompleteMembers(
|
|
|
|
frame, std::string(), std::string(), prefix_path + "->",
|
2019-08-19 19:49:43 +08:00
|
|
|
pointee_type.GetCanonicalType(), request);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
case '.':
|
|
|
|
if (compiler_type.IsValid()) {
|
|
|
|
switch (type_class) {
|
|
|
|
case lldb::eTypeClassUnion:
|
|
|
|
case lldb::eTypeClassStruct:
|
|
|
|
case lldb::eTypeClassClass:
|
2018-07-28 07:37:08 +08:00
|
|
|
if (partial_path.size() > 1 && partial_path[1]) {
|
2013-05-15 07:43:18 +08:00
|
|
|
// If there is more after the ".", then search deeper
|
|
|
|
PrivateAutoComplete(frame, partial_path.substr(1),
|
2019-08-19 19:49:43 +08:00
|
|
|
prefix_path + ".", compiler_type, request);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
} else {
|
2013-05-15 07:43:18 +08:00
|
|
|
// Nothing after the ".", so list all members
|
|
|
|
PrivateAutoCompleteMembers(frame, std::string(), partial_path,
|
|
|
|
prefix_path + ".", compiler_type,
|
2019-08-19 19:49:43 +08:00
|
|
|
request);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2013-05-15 07:43:18 +08:00
|
|
|
if (isalpha(ch) || ch == '_' || ch == '$') {
|
|
|
|
const size_t partial_path_len = partial_path.size();
|
|
|
|
size_t pos = 1;
|
|
|
|
while (pos < partial_path_len) {
|
|
|
|
const char curr_ch = partial_path[pos];
|
|
|
|
if (isalnum(curr_ch) || curr_ch == '_' || curr_ch == '$') {
|
2016-09-07 04:57:50 +08:00
|
|
|
++pos;
|
2013-05-15 07:43:18 +08:00
|
|
|
continue;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-01-29 03:23:46 +08:00
|
|
|
std::string token(std::string(partial_path), 0, pos);
|
|
|
|
remaining_partial_path = std::string(partial_path.substr(pos));
|
2011-07-11 13:12:02 +08:00
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
if (compiler_type.IsValid()) {
|
|
|
|
PrivateAutoCompleteMembers(frame, token, remaining_partial_path,
|
2019-08-19 19:49:43 +08:00
|
|
|
prefix_path, compiler_type, request);
|
2013-05-15 07:43:18 +08:00
|
|
|
} else if (frame) {
|
|
|
|
// We haven't found our variable yet
|
|
|
|
const bool get_file_globals = true;
|
|
|
|
|
|
|
|
VariableList *variable_list =
|
|
|
|
frame->GetVariableList(get_file_globals);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
if (!variable_list)
|
|
|
|
break;
|
|
|
|
|
2019-11-25 22:03:46 +08:00
|
|
|
for (VariableSP var_sp : *variable_list) {
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-11-25 22:03:46 +08:00
|
|
|
if (!var_sp)
|
2013-05-15 07:43:18 +08:00
|
|
|
continue;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-01-02 01:47:44 +08:00
|
|
|
llvm::StringRef variable_name = var_sp->GetName().GetStringRef();
|
|
|
|
if (variable_name.startswith(token)) {
|
|
|
|
if (variable_name == token) {
|
2019-11-25 22:03:46 +08:00
|
|
|
Type *variable_type = var_sp->GetType();
|
2013-05-15 07:43:18 +08:00
|
|
|
if (variable_type) {
|
2015-09-24 11:54:50 +08:00
|
|
|
CompilerType variable_compiler_type(
|
|
|
|
variable_type->GetForwardCompilerType());
|
2013-05-15 07:43:18 +08:00
|
|
|
PrivateAutoComplete(
|
|
|
|
frame, remaining_partial_path,
|
|
|
|
prefix_path + token, // Anything that has been resolved
|
|
|
|
// already will be in here
|
2019-08-19 19:49:43 +08:00
|
|
|
variable_compiler_type.GetCanonicalType(), request);
|
2013-05-15 07:43:18 +08:00
|
|
|
} else {
|
2019-08-19 19:49:43 +08:00
|
|
|
request.AddCompletion((prefix_path + variable_name).str());
|
2013-05-15 07:43:18 +08:00
|
|
|
}
|
|
|
|
} else if (remaining_partial_path.empty()) {
|
2019-08-19 19:49:43 +08:00
|
|
|
request.AddCompletion((prefix_path + variable_name).str());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-05-15 07:43:18 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-05-15 07:43:18 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
break;
|
2013-05-15 07:43:18 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-05-15 07:43:18 +08:00
|
|
|
}
|
|
|
|
|
[lldb][NFC] Remove WordComplete mode, make result array indexed from 0 and remove any undocumented/redundant return values
Summary:
We still have some leftovers of the old completion API in the internals of
LLDB that haven't been replaced by the new CompletionRequest. These leftovers
are:
* The return values (int/size_t) in all completion functions.
* Our result array that starts indexing at 1.
* `WordComplete` mode.
I didn't replace them back then because it's tricky to figure out what exactly they
are used for and the completion code is relatively untested. I finally got around
to writing more tests for the API and understanding the semantics, so I think it's
a good time to get rid of them.
A few words why those things should be removed/replaced:
* The return values are really cryptic, partly redundant and rarely documented.
They are also completely ignored by Xcode, so whatever information they contain will end up
breaking Xcode's completion mechanism. They are also partly impossible to even implement
as we assign negative values special meaning and our completion API sometimes returns size_t.
Completion functions are supposed to return -2 to rewrite the current line. We seem to use this
in some untested code path to expand the history repeat character to the full command, but
I haven't figured out why that doesn't work at the moment.
Completion functions return -1 to 'insert the completion character', but that isn't implemented
(even though we seem to activate this feature in LLDB sometimes).
All positive values have to match the number of results. This is obviously just redundant information
as the user can just look at the result list to get that information (which is what Xcode does).
* The result array that starts indexing at 1 is obviously unexpected. The first element of the array is
reserved for the common prefix of all completions (e.g. "foobar" and "footar" -> "foo"). The idea is
that we calculate this to make the life of the API caller easier, but obviously forcing people to have
1-based indices is not helpful (or even worse, forces them to manually copy the results to make it
0-based like Xcode has to do).
* The `WordComplete` mode indicates that LLDB should enter a space behind the completion. The
idea is that we let the top-level API know that we just provided a full completion. Interestingly we
`WordComplete` is just a single bool that somehow represents all N completions. And we always
provide full completions in LLDB, so in theory it should always be true.
The only use it currently serves is providing redundant information about whether we have a single
definitive completion or not (which we already know from the number of results we get).
This patch essentially removes `WordComplete` mode and makes the result array indexed from 0.
It also removes all return values from all internal completion functions. The only non-redundant information
they contain is about rewriting the current line (which is broken), so that functionality was moved
to the CompletionRequest API. So you can now do `addCompletion("blub", "description", CompletionMode::RewriteLine)`
to do the same.
For the SB API we emulate the old behaviour by making the array indexed from 1 again with the common
prefix at index 0. I didn't keep the special negative return codes as we either never sent them before (e.g. -2) or we
didn't even implement them in the Editline handler (e.g. -1).
I tried to keep this patch minimal and I'm aware we can probably now even further simplify a bunch of related code,
but I would prefer doing this in follow-up NFC commits
Reviewers: JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arphaman, abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D66536
llvm-svn: 369624
2019-08-22 15:41:23 +08:00
|
|
|
void Variable::AutoComplete(const ExecutionContext &exe_ctx,
|
|
|
|
CompletionRequest &request) {
|
2015-09-24 11:54:50 +08:00
|
|
|
CompilerType compiler_type;
|
2013-05-15 07:43:18 +08:00
|
|
|
|
2018-07-14 02:28:14 +08:00
|
|
|
PrivateAutoComplete(exe_ctx.GetFramePtr(), request.GetCursorArgumentPrefix(),
|
2019-08-19 19:49:43 +08:00
|
|
|
"", compiler_type, request);
|
2011-07-11 13:12:02 +08:00
|
|
|
}
|