2010-06-09 00:52:24 +08:00
|
|
|
//===-- VariableList.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/VariableList.h"
|
2010-10-11 07:55:27 +08:00
|
|
|
|
|
|
|
#include "lldb/Core/RegularExpression.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/Block.h"
|
|
|
|
#include "lldb/Symbol/Function.h"
|
|
|
|
#include "lldb/Symbol/CompileUnit.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// VariableList constructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
VariableList::VariableList() :
|
|
|
|
m_variables()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
VariableList::~VariableList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-11 07:55:27 +08:00
|
|
|
VariableList::AddVariable(const VariableSP &var_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-11 07:55:27 +08:00
|
|
|
m_variables.push_back(var_sp);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-10-11 07:55:27 +08:00
|
|
|
bool
|
|
|
|
VariableList::AddVariableIfUnique (const lldb::VariableSP &var_sp)
|
|
|
|
{
|
|
|
|
if (FindVariableIndex (var_sp) == UINT32_MAX)
|
|
|
|
{
|
|
|
|
m_variables.push_back(var_sp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
VariableList::AddVariables(VariableList *variable_list)
|
|
|
|
{
|
|
|
|
std::copy( variable_list->m_variables.begin(), // source begin
|
|
|
|
variable_list->m_variables.end(), // source end
|
|
|
|
back_inserter(m_variables)); // destination
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VariableList::Clear()
|
|
|
|
{
|
|
|
|
m_variables.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
VariableSP
|
|
|
|
VariableList::GetVariableAtIndex(uint32_t idx)
|
|
|
|
{
|
2010-10-11 07:55:27 +08:00
|
|
|
VariableSP var_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (idx < m_variables.size())
|
2010-10-11 07:55:27 +08:00
|
|
|
var_sp = m_variables[idx];
|
|
|
|
return var_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-10-11 07:55:27 +08:00
|
|
|
uint32_t
|
|
|
|
VariableList::FindVariableIndex (const VariableSP &var_sp)
|
|
|
|
{
|
|
|
|
iterator pos, end = m_variables.end();
|
|
|
|
for (pos = m_variables.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
if (pos->get() == var_sp.get())
|
|
|
|
return std::distance (m_variables.begin(), pos);
|
|
|
|
}
|
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
VariableSP
|
|
|
|
VariableList::FindVariable(const ConstString& name)
|
|
|
|
{
|
|
|
|
VariableSP var_sp;
|
|
|
|
iterator pos, end = m_variables.end();
|
|
|
|
for (pos = m_variables.begin(); pos != end; ++pos)
|
|
|
|
{
|
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 ((*pos)->NameMatches(name))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
var_sp = (*pos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return var_sp;
|
|
|
|
}
|
|
|
|
|
2010-10-11 07:55:27 +08:00
|
|
|
size_t
|
|
|
|
VariableList::AppendVariablesIfUnique (const RegularExpression& regex, VariableList &var_list, size_t& total_matches)
|
|
|
|
{
|
|
|
|
const size_t initial_size = var_list.GetSize();
|
|
|
|
iterator pos, end = m_variables.end();
|
|
|
|
for (pos = m_variables.begin(); pos != end; ++pos)
|
|
|
|
{
|
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 ((*pos)->NameMatches (regex))
|
2010-10-11 07:55:27 +08:00
|
|
|
{
|
|
|
|
// Note the total matches found
|
|
|
|
total_matches++;
|
|
|
|
// Only add this variable if it isn't already in the "var_list"
|
|
|
|
var_list.AddVariableIfUnique (*pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Return the number of new unique variables added to "var_list"
|
|
|
|
return var_list.GetSize() - initial_size;
|
|
|
|
}
|
|
|
|
|
2010-09-02 10:59:18 +08:00
|
|
|
uint32_t
|
|
|
|
VariableList::FindIndexForVariable (Variable* variable)
|
|
|
|
{
|
|
|
|
VariableSP var_sp;
|
|
|
|
iterator pos;
|
|
|
|
const iterator begin = m_variables.begin();
|
|
|
|
const iterator end = m_variables.end();
|
|
|
|
for (pos = m_variables.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
if ((*pos).get() == variable)
|
|
|
|
return std::distance (begin, pos);
|
|
|
|
}
|
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
size_t
|
|
|
|
VariableList::MemorySize() const
|
|
|
|
{
|
|
|
|
size_t mem_size = sizeof(VariableList);
|
|
|
|
const_iterator pos, end = m_variables.end();
|
|
|
|
for (pos = m_variables.begin(); pos != end; ++pos)
|
|
|
|
mem_size += (*pos)->MemorySize();
|
|
|
|
return mem_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
VariableList::GetSize() const
|
|
|
|
{
|
|
|
|
return m_variables.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VariableList::Dump(Stream *s, bool show_context) const
|
|
|
|
{
|
|
|
|
// s.Printf("%.*p: ", (int)sizeof(void*) * 2, this);
|
|
|
|
// s.Indent();
|
|
|
|
// s << "VariableList\n";
|
|
|
|
|
|
|
|
const_iterator pos, end = m_variables.end();
|
|
|
|
for (pos = m_variables.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
(*pos)->Dump(s, show_context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|