2010-06-09 00:52:24 +08:00
|
|
|
//===-- Mangled.cpp ---------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include <cxxabi.h>
|
2012-08-04 09:36:57 +08:00
|
|
|
//#include "lldb/Core/cxa_demangle.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-04 07:26:12 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/ConstString.h"
|
|
|
|
#include "lldb/Core/Mangled.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"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Stream.h"
|
|
|
|
#include "lldb/Core/Timer.h"
|
2010-06-09 16:50:27 +08:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2012-07-19 04:47:40 +08:00
|
|
|
static inline bool
|
|
|
|
cstring_is_mangled (const char *s)
|
|
|
|
{
|
|
|
|
if (s)
|
|
|
|
return s[0] == '_' && s[1] == 'Z';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
#pragma mark Mangled
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Default constructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Mangled::Mangled () :
|
|
|
|
m_mangled(),
|
|
|
|
m_demangled()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-19 04:47:40 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Constructor with an optional string and a boolean indicating if it is
|
|
|
|
// the mangled version.
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Mangled::Mangled (const ConstString &s, bool mangled) :
|
|
|
|
m_mangled(),
|
|
|
|
m_demangled()
|
|
|
|
{
|
|
|
|
if (s)
|
|
|
|
SetValue(s, mangled);
|
|
|
|
}
|
|
|
|
|
2012-07-19 07:18:10 +08:00
|
|
|
Mangled::Mangled (const ConstString &s) :
|
2012-07-19 04:47:40 +08:00
|
|
|
m_mangled(),
|
|
|
|
m_demangled()
|
|
|
|
{
|
|
|
|
if (s)
|
|
|
|
SetValue(s);
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Mangled::~Mangled ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Convert to pointer operator. This allows code to check any Mangled
|
|
|
|
// objects to see if they contain anything valid using code such as:
|
|
|
|
//
|
|
|
|
// Mangled mangled(...);
|
|
|
|
// if (mangled)
|
|
|
|
// { ...
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Mangled::operator void* () const
|
|
|
|
{
|
|
|
|
return (m_mangled) ? const_cast<Mangled*>(this) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Logical NOT operator. This allows code to check any Mangled
|
|
|
|
// objects to see if they are invalid using code such as:
|
|
|
|
//
|
|
|
|
// Mangled mangled(...);
|
|
|
|
// if (!file_spec)
|
|
|
|
// { ...
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
Mangled::operator! () const
|
|
|
|
{
|
|
|
|
return !m_mangled;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Clear the mangled and demangled values.
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
Mangled::Clear ()
|
|
|
|
{
|
|
|
|
m_mangled.Clear();
|
|
|
|
m_demangled.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Compare the the string values.
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int
|
|
|
|
Mangled::Compare (const Mangled& a, const Mangled& b)
|
|
|
|
{
|
2010-09-15 08:13:44 +08:00
|
|
|
return ConstString::Compare(a.GetName(ePreferMangled), a.GetName(ePreferMangled));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Set the string value in this objects. If "mangled" is true, then
|
|
|
|
// the mangled named is set with the new value in "s", else the
|
|
|
|
// demangled name is set.
|
|
|
|
//----------------------------------------------------------------------
|
2012-07-19 04:47:40 +08:00
|
|
|
void
|
|
|
|
Mangled::SetValue (const ConstString &s, bool mangled)
|
|
|
|
{
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
if (mangled)
|
|
|
|
{
|
|
|
|
m_demangled.Clear();
|
|
|
|
m_mangled = s;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_demangled = s;
|
|
|
|
m_mangled.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_demangled.Clear();
|
|
|
|
m_mangled.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Mangled::SetValue (const ConstString &name)
|
|
|
|
{
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
if (cstring_is_mangled(name.GetCString()))
|
|
|
|
{
|
|
|
|
m_demangled.Clear();
|
|
|
|
m_mangled = name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_demangled = name;
|
|
|
|
m_mangled.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_demangled.Clear();
|
|
|
|
m_mangled.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Generate the demangled name on demand using this accessor. Code in
|
|
|
|
// this class will need to use this accessor if it wishes to decode
|
|
|
|
// the demangled name. The result is cached and will be kept until a
|
|
|
|
// new string value is supplied to this object, or until the end of the
|
|
|
|
// object's lifetime.
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
const ConstString&
|
|
|
|
Mangled::GetDemangledName () const
|
|
|
|
{
|
|
|
|
// Check to make sure we have a valid mangled name and that we
|
|
|
|
// haven't already decoded our mangled name.
|
|
|
|
if (m_mangled && !m_demangled)
|
|
|
|
{
|
|
|
|
// We need to generate and cache the demangled name.
|
|
|
|
Timer scoped_timer (__PRETTY_FUNCTION__,
|
|
|
|
"Mangled::GetDemangledName (m_mangled = %s)",
|
|
|
|
m_mangled.GetCString());
|
|
|
|
|
2012-07-19 04:47:40 +08:00
|
|
|
// Don't bother running anything that isn't mangled
|
|
|
|
const char *mangled_cstr = m_mangled.GetCString();
|
|
|
|
if (cstring_is_mangled(mangled_cstr))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-06-10 06:34:34 +08:00
|
|
|
if (!m_mangled.GetMangledCounterpart(m_demangled))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-04 07:26:12 +08:00
|
|
|
// We didn't already mangle this name, demangle it and if all goes well
|
|
|
|
// add it to our map.
|
2012-07-19 04:47:40 +08:00
|
|
|
char *demangled_name = abi::__cxa_demangle (mangled_cstr, NULL, NULL, NULL);
|
2012-08-04 09:36:57 +08:00
|
|
|
//char *demangled_name = lldb_cxxabiv1::__cxa_demangle (mangled_cstr, NULL, NULL, NULL);
|
2010-09-04 07:26:12 +08:00
|
|
|
|
|
|
|
if (demangled_name)
|
|
|
|
{
|
2011-06-10 06:34:34 +08:00
|
|
|
m_demangled.SetCStringWithMangledCounterpart(demangled_name, m_mangled);
|
2010-09-04 07:26:12 +08:00
|
|
|
free (demangled_name);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2010-12-15 12:27:04 +08:00
|
|
|
if (!m_demangled)
|
|
|
|
{
|
|
|
|
// Set the demangled string to the empty string to indicate we
|
|
|
|
// tried to parse it once and failed.
|
|
|
|
m_demangled.SetCString("");
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_demangled;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
Mangled::NameMatches (const RegularExpression& regex) const
|
|
|
|
{
|
|
|
|
if (m_mangled && regex.Execute (m_mangled.AsCString()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (GetDemangledName() && regex.Execute (m_demangled.AsCString()))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Get the demangled name if there is one, else return the mangled name.
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
const ConstString&
|
2010-09-15 06:03:00 +08:00
|
|
|
Mangled::GetName (Mangled::NamePreference preference) const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-15 07:44:49 +08:00
|
|
|
if (preference == ePreferDemangled)
|
2010-09-15 06:03:00 +08:00
|
|
|
{
|
2010-09-15 07:48:44 +08:00
|
|
|
// Call the accessor to make sure we get a demangled name in case
|
|
|
|
// it hasn't been demangled yet...
|
|
|
|
if (GetDemangledName())
|
|
|
|
return m_demangled;
|
2010-09-15 07:44:49 +08:00
|
|
|
return m_mangled;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-15 07:48:44 +08:00
|
|
|
if (m_mangled)
|
|
|
|
return m_mangled;
|
|
|
|
return GetDemangledName();
|
2010-09-15 06:03:00 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Dump a Mangled object to stream "s". We don't force our
|
|
|
|
// demangled name to be computed currently (we don't use the accessor).
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
Mangled::Dump (Stream *s) const
|
|
|
|
{
|
|
|
|
if (m_mangled)
|
|
|
|
{
|
|
|
|
*s << ", mangled = " << m_mangled;
|
|
|
|
}
|
|
|
|
if (m_demangled)
|
|
|
|
{
|
|
|
|
const char * demangled = m_demangled.AsCString();
|
|
|
|
s->Printf(", demangled = %s", demangled[0] ? demangled : "<error>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Dumps a debug version of this string with extra object and state
|
|
|
|
// information to stream "s".
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
Mangled::DumpDebug (Stream *s) const
|
|
|
|
{
|
|
|
|
s->Printf("%*p: Mangled mangled = ", (int)sizeof(void*) * 2, this);
|
|
|
|
m_mangled.DumpDebug(s);
|
|
|
|
s->Printf(", demangled = ");
|
|
|
|
m_demangled.DumpDebug(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Return the size in byte that this object takes in memory. The size
|
|
|
|
// includes the size of the objects it owns, and not the strings that
|
|
|
|
// it references because they are shared strings.
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
size_t
|
|
|
|
Mangled::MemorySize () const
|
|
|
|
{
|
|
|
|
return m_mangled.MemorySize() + m_demangled.MemorySize();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Dump OBJ to the supplied stream S.
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Stream&
|
|
|
|
operator << (Stream& s, const Mangled& obj)
|
|
|
|
{
|
|
|
|
if (obj.GetMangledName())
|
|
|
|
s << "mangled = '" << obj.GetMangledName() << "'";
|
|
|
|
|
|
|
|
const ConstString& demangled = obj.GetDemangledName();
|
|
|
|
if (demangled)
|
|
|
|
s << ", demangled = '" << demangled << '\'';
|
|
|
|
else
|
|
|
|
s << ", demangled = <error>";
|
|
|
|
return s;
|
|
|
|
}
|