2010-06-09 00:52:24 +08:00
|
|
|
//===-- Variable.cpp --------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#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"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Stream.h"
|
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
|
|
|
#include "lldb/Core/RegularExpression.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-09-16 07:44:17 +08:00
|
|
|
#include "lldb/Symbol/CompilerDecl.h"
|
|
|
|
#include "lldb/Symbol/CompilerDeclContext.h"
|
2015-07-09 06:32:23 +08:00
|
|
|
#include "lldb/Symbol/CompileUnit.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-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
2010-09-15 07:36:40 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Variable constructor
|
|
|
|
//----------------------------------------------------------------------
|
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
|
|
|
Variable::Variable (lldb::user_id_t uid,
|
|
|
|
const char *name,
|
|
|
|
const char *mangled, // The mangled or fully qualified name of the variable.
|
|
|
|
const lldb::SymbolFileTypeSP &symfile_type_sp,
|
|
|
|
ValueType scope,
|
|
|
|
SymbolContextScope *context,
|
2016-02-25 20:23:37 +08:00
|
|
|
const RangeList& scope_range,
|
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
|
|
|
Declaration* decl_ptr,
|
|
|
|
const DWARFExpression& location,
|
|
|
|
bool external,
|
|
|
|
bool artificial,
|
|
|
|
bool static_member) :
|
2010-06-09 00:52:24 +08:00
|
|
|
UserID(uid),
|
|
|
|
m_name(name),
|
2015-03-25 02:32:27 +08:00
|
|
|
m_mangled (ConstString(mangled)),
|
2011-12-08 10:13:16 +08:00
|
|
|
m_symfile_type_sp(symfile_type_sp),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_scope(scope),
|
2010-08-31 02:11:35 +08:00
|
|
|
m_owner_scope(context),
|
2016-02-25 20:23:37 +08:00
|
|
|
m_scope_range(scope_range),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_declaration(decl_ptr),
|
|
|
|
m_location(location),
|
|
|
|
m_external(external),
|
2015-08-19 06:46:57 +08:00
|
|
|
m_artificial(artificial),
|
|
|
|
m_static_member(static_member)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Variable::~Variable()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-07-09 06:32:23 +08:00
|
|
|
lldb::LanguageType
|
|
|
|
Variable::GetLanguage () const
|
|
|
|
{
|
|
|
|
SymbolContext variable_sc;
|
|
|
|
m_owner_scope->CalculateSymbolContext(&variable_sc);
|
|
|
|
if (variable_sc.comp_unit)
|
|
|
|
return variable_sc.comp_unit->GetLanguage();
|
|
|
|
return lldb::eLanguageTypeUnknown;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2015-07-09 06:32:23 +08:00
|
|
|
|
|
|
|
ConstString
|
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
|
|
|
Variable::GetName() const
|
|
|
|
{
|
2015-07-09 18:57:54 +08:00
|
|
|
ConstString name = m_mangled.GetName(GetLanguage());
|
|
|
|
if (name)
|
|
|
|
return 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
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
2015-09-16 07:44:17 +08:00
|
|
|
ConstString
|
|
|
|
Variable::GetUnqualifiedName() const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-09 06:32:23 +08:00
|
|
|
bool
|
|
|
|
Variable::NameMatches (const ConstString &name) const
|
|
|
|
{
|
|
|
|
if (m_name == name)
|
|
|
|
return true;
|
|
|
|
SymbolContext variable_sc;
|
|
|
|
m_owner_scope->CalculateSymbolContext(&variable_sc);
|
|
|
|
|
|
|
|
LanguageType language = eLanguageTypeUnknown;
|
|
|
|
if (variable_sc.comp_unit)
|
|
|
|
language = variable_sc.comp_unit->GetLanguage();
|
|
|
|
return m_mangled.NameMatches (name, language);
|
|
|
|
}
|
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
|
|
|
bool
|
|
|
|
Variable::NameMatches (const RegularExpression& regex) const
|
|
|
|
{
|
|
|
|
if (regex.Execute (m_name.AsCString()))
|
|
|
|
return true;
|
2015-07-09 06:32:23 +08:00
|
|
|
if (m_mangled)
|
|
|
|
return m_mangled.NameMatches (regex, GetLanguage());
|
|
|
|
return false;
|
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
|
|
|
Type *
|
|
|
|
Variable::GetType()
|
|
|
|
{
|
|
|
|
if (m_symfile_type_sp)
|
|
|
|
return m_symfile_type_sp->GetType();
|
2014-04-20 21:17:36 +08:00
|
|
|
return nullptr;
|
2011-12-08 10:13:16 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +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));
|
2010-06-09 00:52:24 +08:00
|
|
|
s->Indent();
|
|
|
|
*s << "Variable" << (const UserID&)*this;
|
|
|
|
|
|
|
|
if (m_name)
|
|
|
|
*s << ", name = \"" << m_name << "\"";
|
|
|
|
|
2011-12-08 10:13:16 +08:00
|
|
|
if (m_symfile_type_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-12-08 10:13:16 +08:00
|
|
|
Type *type = m_symfile_type_sp->GetType();
|
|
|
|
if (type)
|
|
|
|
{
|
|
|
|
*s << ", type = {" << type->GetID() << "} " << (void*)type << " (";
|
|
|
|
type->DumpTypeName(s);
|
|
|
|
s->PutChar(')');
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_scope != eValueTypeInvalid)
|
|
|
|
{
|
|
|
|
s->PutCString(", scope = ");
|
|
|
|
switch (m_scope)
|
|
|
|
{
|
|
|
|
case eValueTypeVariableGlobal: s->PutCString(m_external ? "global" : "static"); break;
|
|
|
|
case eValueTypeVariableArgument: s->PutCString("parameter"); break;
|
|
|
|
case eValueTypeVariableLocal: s->PutCString("local"); break;
|
|
|
|
default: *s << "??? (" << m_scope << ')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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(" )");
|
|
|
|
}
|
|
|
|
|
2010-09-15 13:51:24 +08:00
|
|
|
bool show_fullpaths = false;
|
|
|
|
m_declaration.Dump(s, show_fullpaths);
|
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();
|
|
|
|
}
|
2014-04-20 21:17:36 +08:00
|
|
|
ABI *abi = nullptr;
|
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)
|
|
|
|
abi = ABI::FindPlugin (module_sp->GetArchitecture()).get();
|
2011-09-02 09:15:17 +08:00
|
|
|
}
|
|
|
|
m_location.GetDescription(s, lldb::eDescriptionLevelBrief, loclist_base_addr, abi);
|
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;
|
2011-07-11 03:21:23 +08:00
|
|
|
|
|
|
|
dumped_declaration_info = sc.DumpStopContext (s,
|
2014-04-20 21:17:36 +08:00
|
|
|
nullptr,
|
2011-07-11 03:21:23 +08:00
|
|
|
Address(),
|
|
|
|
show_fullpaths,
|
|
|
|
show_module,
|
2014-10-11 07:07:36 +08:00
|
|
|
show_inlined_frames,
|
2015-02-14 07:24:21 +08:00
|
|
|
show_function_arguments,
|
|
|
|
show_function_name);
|
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);
|
|
|
|
}
|
|
|
|
|
2015-09-16 07:44:17 +08:00
|
|
|
CompilerDeclContext
|
|
|
|
Variable::GetDeclContext ()
|
|
|
|
{
|
|
|
|
Type *type = GetType();
|
2016-04-12 08:06:27 +08:00
|
|
|
if (type)
|
|
|
|
return type->GetSymbolFile()->GetDeclContextContainingUID(GetID());
|
|
|
|
return CompilerDeclContext();
|
2015-09-16 07:44:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CompilerDecl
|
|
|
|
Variable::GetDecl ()
|
|
|
|
{
|
|
|
|
Type *type = GetType();
|
2016-05-24 02:30:59 +08:00
|
|
|
return type ? type->GetSymbolFile()->GetDeclForUID(GetID()) : CompilerDecl();
|
2015-09-16 07:44:17 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
Variable::CalculateSymbolContext (SymbolContext *sc)
|
|
|
|
{
|
2010-08-31 02:11:35 +08:00
|
|
|
if (m_owner_scope)
|
2015-01-15 10:59:20 +08:00
|
|
|
{
|
2010-08-31 02:11:35 +08:00
|
|
|
m_owner_scope->CalculateSymbolContext(sc);
|
2015-01-15 10:59:20 +08:00
|
|
|
sc->variable = this;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2013-02-23 12:12:47 +08:00
|
|
|
sc->Clear(false);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-11-04 17:33:30 +08:00
|
|
|
Variable::LocationIsValidForFrame (StackFrame *frame)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-05-30 08:49:24 +08:00
|
|
|
// Is the variable is described by a single location?
|
|
|
|
if (!m_location.IsLocationList())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-05-30 08:49:24 +08:00
|
|
|
// Yes it is, the location is valid.
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
2011-05-30 08:49:24 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-05-30 08:49:24 +08:00
|
|
|
if (frame)
|
|
|
|
{
|
|
|
|
Function *function = frame->GetSymbolContext(eSymbolContextFunction).function;
|
|
|
|
if (function)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-18 13:35:26 +08:00
|
|
|
TargetSP target_sp (frame->CalculateTarget());
|
|
|
|
|
|
|
|
addr_t loclist_base_load_addr = 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;
|
2010-06-09 00:52:24 +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-05-30 08:49:24 +08:00
|
|
|
return m_location.LocationListContainsAddress (loclist_base_load_addr,
|
2012-02-18 13:35:26 +08:00
|
|
|
frame->GetFrameCodeAddress().GetLoadAddress (target_sp.get()));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2011-05-30 08:49:24 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-11 13:12:02 +08:00
|
|
|
bool
|
|
|
|
Variable::LocationIsValidForAddress (const Address &address)
|
|
|
|
{
|
|
|
|
// Be sure to resolve the address to section offset prior to
|
|
|
|
// calling this function.
|
|
|
|
if (address.IsSectionOffset())
|
|
|
|
{
|
|
|
|
SymbolContext sc;
|
|
|
|
CalculateSymbolContext(&sc);
|
2012-02-24 09:59:29 +08:00
|
|
|
if (sc.module_sp == address.GetModule())
|
2011-07-11 13:12:02 +08:00
|
|
|
{
|
|
|
|
// Is the variable is described by a single location?
|
|
|
|
if (!m_location.IsLocationList())
|
|
|
|
{
|
|
|
|
// Yes it is, the location is valid.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc.function)
|
|
|
|
{
|
|
|
|
addr_t loclist_base_file_addr = sc.function->GetAddressRange().GetBaseAddress().GetFileAddress();
|
|
|
|
if (loclist_base_file_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
|
|
|
// It is a location list. We just need to tell if the location
|
|
|
|
// list contains the current address when converted to a load
|
|
|
|
// address
|
|
|
|
return m_location.LocationListContainsAddress (loclist_base_file_addr,
|
|
|
|
address.GetFileAddress());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-30 08:49:24 +08:00
|
|
|
bool
|
2013-11-04 17:33:30 +08:00
|
|
|
Variable::IsInScope (StackFrame *frame)
|
2011-05-30 08:49:24 +08:00
|
|
|
{
|
|
|
|
switch (m_scope)
|
|
|
|
{
|
|
|
|
case eValueTypeRegister:
|
|
|
|
case eValueTypeRegisterSet:
|
2014-04-20 21:17:36 +08:00
|
|
|
return frame != nullptr;
|
2011-05-30 08:49:24 +08:00
|
|
|
|
|
|
|
case eValueTypeConstResult:
|
|
|
|
case eValueTypeVariableGlobal:
|
|
|
|
case eValueTypeVariableStatic:
|
2011-07-10 04:12:33 +08:00
|
|
|
return true;
|
|
|
|
|
2011-05-30 08:49:24 +08:00
|
|
|
case eValueTypeVariableArgument:
|
|
|
|
case eValueTypeVariableLocal:
|
|
|
|
if (frame)
|
2010-06-09 00:52:24 +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 = frame->GetSymbolContext(eSymbolContextBlock).block;
|
|
|
|
if (deepest_frame_block)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
SymbolContext variable_sc;
|
|
|
|
CalculateSymbolContext (&variable_sc);
|
2016-02-25 20:23:37 +08:00
|
|
|
|
2011-05-30 08:49:24 +08:00
|
|
|
// Check for static or global variable defined at the compile unit
|
|
|
|
// level that wasn't defined in a block
|
2014-04-20 21:17:36 +08:00
|
|
|
if (variable_sc.block == nullptr)
|
2016-02-25 20:23:37 +08:00
|
|
|
return true;
|
2011-05-30 08:49:24 +08:00
|
|
|
|
2016-02-25 20:23:37 +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;
|
|
|
|
|
|
|
|
// If no scope range is specified then it means that the scope is the same as the
|
|
|
|
// scope of the enclosing lexical block.
|
|
|
|
if (m_scope_range.IsEmpty())
|
2010-09-14 10:20:48 +08:00
|
|
|
return true;
|
2016-02-25 20:23:37 +08:00
|
|
|
|
|
|
|
addr_t file_address = frame->GetFrameCodeAddress().GetFileAddress();
|
|
|
|
return m_scope_range.FindEntryThatContains(file_address) != nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-09 05:46:14 +08:00
|
|
|
Error
|
|
|
|
Variable::GetValuesForVariableExpressionPath (const char *variable_expr_path,
|
|
|
|
ExecutionContextScope *scope,
|
|
|
|
GetVariableCallback callback,
|
|
|
|
void *baton,
|
|
|
|
VariableList &variable_list,
|
|
|
|
ValueObjectList &valobj_list)
|
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
if (variable_expr_path && callback)
|
|
|
|
{
|
|
|
|
switch (variable_expr_path[0])
|
|
|
|
{
|
|
|
|
case '*':
|
|
|
|
{
|
|
|
|
error = Variable::GetValuesForVariableExpressionPath (variable_expr_path + 1,
|
|
|
|
scope,
|
|
|
|
callback,
|
|
|
|
baton,
|
|
|
|
variable_list,
|
|
|
|
valobj_list);
|
|
|
|
if (error.Success())
|
|
|
|
{
|
|
|
|
for (uint32_t i=0; i<valobj_list.GetSize(); )
|
|
|
|
{
|
|
|
|
Error tmp_error;
|
|
|
|
ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(i)->Dereference(tmp_error));
|
|
|
|
if (tmp_error.Fail())
|
|
|
|
{
|
|
|
|
variable_list.RemoveVariableAtIndex (i);
|
|
|
|
valobj_list.RemoveValueObjectAtIndex (i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
valobj_list.SetValueObjectAtIndex (i, valobj_sp);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetErrorString ("unknown error");
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '&':
|
|
|
|
{
|
|
|
|
error = Variable::GetValuesForVariableExpressionPath (variable_expr_path + 1,
|
|
|
|
scope,
|
|
|
|
callback,
|
|
|
|
baton,
|
|
|
|
variable_list,
|
|
|
|
valobj_list);
|
|
|
|
if (error.Success())
|
|
|
|
{
|
|
|
|
for (uint32_t i=0; i<valobj_list.GetSize(); )
|
|
|
|
{
|
|
|
|
Error tmp_error;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.SetErrorString ("unknown error");
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2013-04-04 05:37:16 +08:00
|
|
|
static RegularExpression g_regex ("^([A-Za-z_:][A-Za-z_0-9:]*)(.*)");
|
|
|
|
RegularExpression::Match regex_match(1);
|
|
|
|
if (g_regex.Execute(variable_expr_path, ®ex_match))
|
2011-07-09 05:46:14 +08:00
|
|
|
{
|
|
|
|
std::string variable_name;
|
2013-04-04 05:37:16 +08:00
|
|
|
if (regex_match.GetMatchAtIndex(variable_expr_path, 1, variable_name))
|
2011-07-09 05:46:14 +08:00
|
|
|
{
|
|
|
|
variable_list.Clear();
|
|
|
|
if (callback (baton, variable_name.c_str(), variable_list))
|
|
|
|
{
|
|
|
|
uint32_t i=0;
|
|
|
|
while (i < variable_list.GetSize())
|
|
|
|
{
|
|
|
|
VariableSP var_sp (variable_list.GetVariableAtIndex (i));
|
|
|
|
ValueObjectSP valobj_sp;
|
|
|
|
if (var_sp)
|
|
|
|
{
|
|
|
|
ValueObjectSP variable_valobj_sp(ValueObjectVariable::Create (scope, var_sp));
|
|
|
|
if (variable_valobj_sp)
|
|
|
|
{
|
2013-05-21 00:50:51 +08:00
|
|
|
const char *variable_sub_expr_path = variable_expr_path + variable_name.size();
|
|
|
|
if (*variable_sub_expr_path)
|
2011-07-09 05:46:14 +08:00
|
|
|
{
|
2014-04-20 21:17:36 +08:00
|
|
|
const char* first_unparsed = nullptr;
|
2011-07-09 05:46:14 +08:00
|
|
|
ValueObject::ExpressionPathScanEndReason reason_to_stop;
|
|
|
|
ValueObject::ExpressionPathEndResultType final_value_type;
|
|
|
|
ValueObject::GetValueForExpressionPathOptions options;
|
|
|
|
ValueObject::ExpressionPathAftermath final_task_on_target;
|
|
|
|
|
2013-05-21 00:50:51 +08:00
|
|
|
valobj_sp = variable_valobj_sp->GetValueForExpressionPath (variable_sub_expr_path,
|
2011-07-09 05:46:14 +08:00
|
|
|
&first_unparsed,
|
|
|
|
&reason_to_stop,
|
|
|
|
&final_value_type,
|
|
|
|
options,
|
|
|
|
&final_task_on_target);
|
|
|
|
if (!valobj_sp)
|
|
|
|
{
|
|
|
|
error.SetErrorStringWithFormat ("invalid expression path '%s' for variable '%s'",
|
2013-05-21 00:50:51 +08:00
|
|
|
variable_sub_expr_path,
|
2011-07-09 05:46:14 +08:00
|
|
|
var_sp->GetName().GetCString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Just the name of a variable with no extras
|
|
|
|
valobj_sp = variable_valobj_sp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!var_sp || !valobj_sp)
|
|
|
|
{
|
|
|
|
variable_list.RemoveVariableAtIndex (i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
valobj_list.Append(valobj_sp);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (variable_list.GetSize() > 0)
|
|
|
|
{
|
|
|
|
error.Clear();
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-21 00:52:10 +08:00
|
|
|
error.SetErrorStringWithFormat ("unable to extract a variable name from '%s'", variable_expr_path);
|
2011-07-09 05:46:14 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error.SetErrorString ("unknown error");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2011-07-11 13:12:02 +08:00
|
|
|
bool
|
|
|
|
Variable::DumpLocationForAddress (Stream *s, const Address &address)
|
|
|
|
{
|
|
|
|
// Be sure to resolve the address to section offset prior to
|
|
|
|
// calling this function.
|
|
|
|
if (address.IsSectionOffset())
|
|
|
|
{
|
|
|
|
SymbolContext sc;
|
|
|
|
CalculateSymbolContext(&sc);
|
2012-02-24 09:59:29 +08:00
|
|
|
if (sc.module_sp == address.GetModule())
|
2011-07-11 13:12:02 +08:00
|
|
|
{
|
2014-04-20 21:17:36 +08:00
|
|
|
ABI *abi = nullptr;
|
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)
|
|
|
|
abi = ABI::FindPlugin (module_sp->GetArchitecture()).get();
|
2011-09-02 09:15:17 +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,
|
2011-09-02 09:15:17 +08:00
|
|
|
file_addr,
|
|
|
|
abi);
|
2011-07-11 13:12:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_location.DumpLocationForAddress (s,
|
|
|
|
eDescriptionLevelBrief,
|
|
|
|
LLDB_INVALID_ADDRESS,
|
2011-09-02 09:15:17 +08:00
|
|
|
file_addr,
|
|
|
|
abi);
|
2011-07-11 13:12:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-05-15 07:43:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2013-11-04 17:33:30 +08:00
|
|
|
PrivateAutoComplete (StackFrame *frame,
|
2013-05-15 07:43:18 +08:00
|
|
|
const std::string &partial_path,
|
|
|
|
const std::string &prefix_path, // Anything that has been resolved already will be in here
|
2015-09-24 11:54:50 +08:00
|
|
|
const CompilerType& compiler_type,
|
2013-05-15 07:43:18 +08:00
|
|
|
StringList &matches,
|
|
|
|
bool &word_complete);
|
|
|
|
|
|
|
|
static void
|
2013-11-04 17:33:30 +08:00
|
|
|
PrivateAutoCompleteMembers (StackFrame *frame,
|
2013-05-15 07:43:18 +08:00
|
|
|
const std::string &partial_member_name,
|
|
|
|
const std::string &partial_path,
|
|
|
|
const std::string &prefix_path, // Anything that has been resolved already will be in here
|
2015-09-24 11:54:50 +08:00
|
|
|
const CompilerType& compiler_type,
|
2013-05-15 07:43:18 +08:00
|
|
|
StringList &matches,
|
|
|
|
bool &word_complete);
|
|
|
|
|
|
|
|
static void
|
2013-11-04 17:33:30 +08:00
|
|
|
PrivateAutoCompleteMembers (StackFrame *frame,
|
2013-05-15 07:43:18 +08:00
|
|
|
const std::string &partial_member_name,
|
|
|
|
const std::string &partial_path,
|
|
|
|
const std::string &prefix_path, // Anything that has been resolved already will be in here
|
2015-09-24 11:54:50 +08:00
|
|
|
const CompilerType& compiler_type,
|
2013-05-15 07:43:18 +08:00
|
|
|
StringList &matches,
|
|
|
|
bool &word_complete)
|
|
|
|
{
|
|
|
|
|
|
|
|
// We are in a type parsing child members
|
2015-09-24 11:54:50 +08:00
|
|
|
const uint32_t num_bases = compiler_type.GetNumDirectBaseClasses();
|
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);
|
2013-05-15 07:43:18 +08:00
|
|
|
|
|
|
|
PrivateAutoCompleteMembers (frame,
|
|
|
|
partial_member_name,
|
|
|
|
partial_path,
|
|
|
|
prefix_path,
|
|
|
|
base_class_type.GetCanonicalType(),
|
|
|
|
matches,
|
|
|
|
word_complete);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2013-05-15 07:43:18 +08:00
|
|
|
|
|
|
|
PrivateAutoCompleteMembers (frame,
|
|
|
|
partial_member_name,
|
|
|
|
partial_path,
|
|
|
|
prefix_path,
|
|
|
|
vbase_class_type.GetCanonicalType(),
|
|
|
|
matches,
|
|
|
|
word_complete);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We are in a type parsing child members
|
2015-09-24 11:54:50 +08:00
|
|
|
const uint32_t num_fields = compiler_type.GetNumFields();
|
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;
|
|
|
|
|
2015-09-24 11:54:50 +08:00
|
|
|
CompilerType member_compiler_type = compiler_type.GetFieldAtIndex (i, member_name, nullptr, nullptr, nullptr);
|
2013-05-15 07:43:18 +08:00
|
|
|
|
|
|
|
if (partial_member_name.empty() ||
|
|
|
|
member_name.find(partial_member_name) == 0)
|
|
|
|
{
|
|
|
|
if (member_name == partial_member_name)
|
|
|
|
{
|
|
|
|
PrivateAutoComplete (frame,
|
|
|
|
partial_path,
|
|
|
|
prefix_path + member_name, // Anything that has been resolved already will be in here
|
2015-09-24 11:54:50 +08:00
|
|
|
member_compiler_type.GetCanonicalType(),
|
2013-05-15 07:43:18 +08:00
|
|
|
matches,
|
|
|
|
word_complete);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
matches.AppendString (prefix_path + member_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-04 17:33:30 +08:00
|
|
|
PrivateAutoComplete (StackFrame *frame,
|
2013-05-15 07:43:18 +08:00
|
|
|
const std::string &partial_path,
|
|
|
|
const std::string &prefix_path, // Anything that has been resolved already will be in here
|
2015-09-24 11:54:50 +08:00
|
|
|
const CompilerType& compiler_type,
|
2013-05-15 07:43:18 +08:00
|
|
|
StringList &matches,
|
|
|
|
bool &word_complete)
|
|
|
|
{
|
|
|
|
// printf ("\nPrivateAutoComplete()\n\tprefix_path = '%s'\n\tpartial_path = '%s'\n", prefix_path.c_str(), partial_path.c_str());
|
|
|
|
std::string remaining_partial_path;
|
|
|
|
|
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:
|
|
|
|
{
|
|
|
|
matches.AppendString (prefix_path);
|
|
|
|
word_complete = matches.GetSize() == 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eTypeClassClass:
|
|
|
|
case eTypeClassStruct:
|
|
|
|
case eTypeClassUnion:
|
|
|
|
if (prefix_path.back() != '.')
|
|
|
|
matches.AppendString (prefix_path + '.');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eTypeClassObjCObject:
|
|
|
|
case eTypeClassObjCInterface:
|
|
|
|
break;
|
|
|
|
case eTypeClassObjCObjectPointer:
|
|
|
|
case eTypeClassPointer:
|
|
|
|
{
|
|
|
|
bool omit_empty_base_classes = true;
|
2015-09-24 11:54:50 +08:00
|
|
|
if (compiler_type.GetNumChildren (omit_empty_base_classes) > 0)
|
2013-05-15 07:43:18 +08:00
|
|
|
matches.AppendString (prefix_path + "->");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
matches.AppendString (prefix_path);
|
|
|
|
word_complete = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (frame)
|
|
|
|
{
|
|
|
|
const bool get_file_globals = true;
|
|
|
|
|
|
|
|
VariableList *variable_list = frame->GetVariableList(get_file_globals);
|
|
|
|
|
2013-10-09 10:39:26 +08:00
|
|
|
if (variable_list)
|
2013-05-15 07:43:18 +08:00
|
|
|
{
|
2013-10-09 10:39:26 +08:00
|
|
|
const size_t num_variables = variable_list->GetSize();
|
|
|
|
for (size_t i=0; i<num_variables; ++i)
|
|
|
|
{
|
|
|
|
Variable *variable = variable_list->GetVariableAtIndex(i).get();
|
|
|
|
matches.AppendString (variable->GetName().AsCString());
|
|
|
|
}
|
2013-05-15 07:43:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char ch = partial_path[0];
|
|
|
|
switch (ch)
|
|
|
|
{
|
|
|
|
case '*':
|
|
|
|
if (prefix_path.empty())
|
|
|
|
{
|
|
|
|
PrivateAutoComplete (frame,
|
|
|
|
partial_path.substr(1),
|
|
|
|
std::string("*"),
|
2015-09-24 11:54:50 +08:00
|
|
|
compiler_type,
|
2013-05-15 07:43:18 +08:00
|
|
|
matches,
|
|
|
|
word_complete);
|
|
|
|
}
|
|
|
|
break;
|
2011-07-11 13:12:02 +08:00
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
case '&':
|
|
|
|
if (prefix_path.empty())
|
|
|
|
{
|
|
|
|
PrivateAutoComplete (frame,
|
|
|
|
partial_path.substr(1),
|
|
|
|
std::string("&"),
|
2015-09-24 11:54:50 +08:00
|
|
|
compiler_type,
|
2013-05-15 07:43:18 +08:00
|
|
|
matches,
|
|
|
|
word_complete);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '-':
|
|
|
|
if (partial_path[1] == '>' && !prefix_path.empty())
|
|
|
|
{
|
|
|
|
switch (type_class)
|
|
|
|
{
|
|
|
|
case lldb::eTypeClassPointer:
|
|
|
|
{
|
2015-09-24 11:54:50 +08:00
|
|
|
CompilerType pointee_type(compiler_type.GetPointeeType());
|
2013-05-15 07:43:18 +08:00
|
|
|
if (partial_path[2])
|
|
|
|
{
|
|
|
|
// If there is more after the "->", then search deeper
|
|
|
|
PrivateAutoComplete (frame,
|
|
|
|
partial_path.substr(2),
|
|
|
|
prefix_path + "->",
|
|
|
|
pointee_type.GetCanonicalType(),
|
|
|
|
matches,
|
|
|
|
word_complete);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Nothing after the "->", so list all members
|
|
|
|
PrivateAutoCompleteMembers (frame,
|
|
|
|
std::string(),
|
|
|
|
std::string(),
|
|
|
|
prefix_path + "->",
|
|
|
|
pointee_type.GetCanonicalType(),
|
|
|
|
matches,
|
|
|
|
word_complete);
|
|
|
|
}
|
|
|
|
}
|
2016-02-26 09:20:20 +08:00
|
|
|
break;
|
2013-05-15 07:43:18 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '.':
|
2015-09-24 11:54:50 +08:00
|
|
|
if (compiler_type.IsValid())
|
2013-05-15 07:43:18 +08:00
|
|
|
{
|
|
|
|
switch (type_class)
|
|
|
|
{
|
|
|
|
case lldb::eTypeClassUnion:
|
|
|
|
case lldb::eTypeClassStruct:
|
|
|
|
case lldb::eTypeClassClass:
|
|
|
|
if (partial_path[1])
|
|
|
|
{
|
|
|
|
// If there is more after the ".", then search deeper
|
|
|
|
PrivateAutoComplete (frame,
|
|
|
|
partial_path.substr(1),
|
|
|
|
prefix_path + ".",
|
2015-09-24 11:54:50 +08:00
|
|
|
compiler_type,
|
2013-05-15 07:43:18 +08:00
|
|
|
matches,
|
|
|
|
word_complete);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Nothing after the ".", so list all members
|
|
|
|
PrivateAutoCompleteMembers (frame,
|
|
|
|
std::string(),
|
|
|
|
partial_path,
|
|
|
|
prefix_path + ".",
|
2015-09-24 11:54:50 +08:00
|
|
|
compiler_type,
|
2013-05-15 07:43:18 +08:00
|
|
|
matches,
|
|
|
|
word_complete);
|
|
|
|
}
|
2016-02-26 09:20:20 +08:00
|
|
|
break;
|
2013-05-15 07:43:18 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
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 == '$')
|
|
|
|
{
|
|
|
|
++pos;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string token(partial_path, 0, pos);
|
|
|
|
remaining_partial_path = partial_path.substr(pos);
|
|
|
|
|
2015-09-24 11:54:50 +08:00
|
|
|
if (compiler_type.IsValid())
|
2013-05-15 07:43:18 +08:00
|
|
|
{
|
|
|
|
PrivateAutoCompleteMembers (frame,
|
|
|
|
token,
|
|
|
|
remaining_partial_path,
|
|
|
|
prefix_path,
|
2015-09-24 11:54:50 +08:00
|
|
|
compiler_type,
|
2013-05-15 07:43:18 +08:00
|
|
|
matches,
|
|
|
|
word_complete);
|
|
|
|
}
|
|
|
|
else if (frame)
|
|
|
|
{
|
|
|
|
// We haven't found our variable yet
|
|
|
|
const bool get_file_globals = true;
|
|
|
|
|
|
|
|
VariableList *variable_list = frame->GetVariableList(get_file_globals);
|
|
|
|
|
2013-12-21 16:44:28 +08:00
|
|
|
if (!variable_list)
|
|
|
|
break;
|
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
const size_t num_variables = variable_list->GetSize();
|
|
|
|
for (size_t i=0; i<num_variables; ++i)
|
|
|
|
{
|
|
|
|
Variable *variable = variable_list->GetVariableAtIndex(i).get();
|
2013-12-21 16:44:28 +08:00
|
|
|
|
|
|
|
if (!variable)
|
|
|
|
continue;
|
|
|
|
|
2013-05-15 07:43:18 +08:00
|
|
|
const char *variable_name = variable->GetName().AsCString();
|
|
|
|
if (strstr(variable_name, token.c_str()) == variable_name)
|
|
|
|
{
|
|
|
|
if (strcmp (variable_name, token.c_str()) == 0)
|
|
|
|
{
|
|
|
|
Type *variable_type = variable->GetType();
|
|
|
|
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
|
2015-09-24 11:54:50 +08:00
|
|
|
variable_compiler_type.GetCanonicalType(),
|
2013-05-15 07:43:18 +08:00
|
|
|
matches,
|
|
|
|
word_complete);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
matches.AppendString (prefix_path + variable_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (remaining_partial_path.empty())
|
|
|
|
{
|
|
|
|
matches.AppendString (prefix_path + variable_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
Variable::AutoComplete (const ExecutionContext &exe_ctx,
|
|
|
|
const char *partial_path_cstr,
|
|
|
|
StringList &matches,
|
|
|
|
bool &word_complete)
|
|
|
|
{
|
|
|
|
word_complete = false;
|
|
|
|
std::string partial_path;
|
|
|
|
std::string prefix_path;
|
2015-09-24 11:54:50 +08:00
|
|
|
CompilerType compiler_type;
|
2013-05-15 07:43:18 +08:00
|
|
|
if (partial_path_cstr && partial_path_cstr[0])
|
|
|
|
partial_path = partial_path_cstr;
|
|
|
|
|
|
|
|
PrivateAutoComplete (exe_ctx.GetFramePtr(),
|
|
|
|
partial_path,
|
|
|
|
prefix_path,
|
2015-09-24 11:54:50 +08:00
|
|
|
compiler_type,
|
2013-05-15 07:43:18 +08:00
|
|
|
matches,
|
|
|
|
word_complete);
|
|
|
|
|
|
|
|
return matches.GetSize();
|
2011-07-11 13:12:02 +08:00
|
|
|
}
|
|
|
|
|