[Lldb-commits] [lldb] r184251 - Added the ability to get a list of types from a SBModule or SBCompileUnit. Sebastien Metrot wanted this, and sent a hollowed out patch. I filled in the blanks and did the low level implementation. The new functions are:
Greg Clayton
gclayton at apple.com
Tue Jun 18 15:51:06 PDT 2013
Author: gclayton
Date: Tue Jun 18 17:51:05 2013
New Revision: 184251
URL: http://llvm.org/viewvc/llvm-project?rev=184251&view=rev
Log:
Added the ability to get a list of types from a SBModule or SBCompileUnit. Sebastien Metrot wanted this, and sent a hollowed out patch. I filled in the blanks and did the low level implementation. The new functions are:
//------------------------------------------------------------------
/// Get all types matching \a type_mask from debug info in this
/// module.
///
/// @param[in] type_mask
/// A bitfield that consists of one or more bits logically OR'ed
/// together from the lldb::TypeClass enumeration. This allows
/// you to request only structure types, or only class, struct
/// and union types. Passing in lldb::eTypeClassAny will return
/// all types found in the debug information for this module.
///
/// @return
/// A list of types in this module that match \a type_mask
//------------------------------------------------------------------
lldb::SBTypeList
SBModule::GetTypes (uint32_t type_mask)
//------------------------------------------------------------------
/// Get all types matching \a type_mask from debug info in this
/// compile unit.
///
/// @param[in] type_mask
/// A bitfield that consists of one or more bits logically OR'ed
/// together from the lldb::TypeClass enumeration. This allows
/// you to request only structure types, or only class, struct
/// and union types. Passing in lldb::eTypeClassAny will return
/// all types found in the debug information for this compile
/// unit.
///
/// @return
/// A list of types in this compile unit that match \a type_mask
//------------------------------------------------------------------
lldb::SBTypeList
SBCompileUnit::GetTypes (uint32_t type_mask = lldb::eTypeClassAny);
This lets you request types by filling out a mask that contains one or more bits from the lldb::TypeClass enumerations, so you can only get the types you really want.
Modified:
lldb/trunk/include/lldb/API/SBCompileUnit.h
lldb/trunk/include/lldb/API/SBModule.h
lldb/trunk/include/lldb/API/SBType.h
lldb/trunk/include/lldb/Core/MappedHash.h
lldb/trunk/include/lldb/Core/UniqueCStringMap.h
lldb/trunk/include/lldb/Symbol/SymbolFile.h
lldb/trunk/include/lldb/Symbol/SymbolVendor.h
lldb/trunk/include/lldb/Symbol/Type.h
lldb/trunk/include/lldb/Symbol/TypeList.h
lldb/trunk/include/lldb/lldb-enumerations.h
lldb/trunk/scripts/Python/interface/SBCompileUnit.i
lldb/trunk/scripts/Python/interface/SBModule.i
lldb/trunk/source/API/SBCompileUnit.cpp
lldb/trunk/source/API/SBModule.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h
lldb/trunk/source/Symbol/SymbolVendor.cpp
lldb/trunk/source/Symbol/Type.cpp
lldb/trunk/source/Symbol/TypeList.cpp
Modified: lldb/trunk/include/lldb/API/SBCompileUnit.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBCompileUnit.h?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBCompileUnit.h (original)
+++ lldb/trunk/include/lldb/API/SBCompileUnit.h Tue Jun 18 17:51:05 2013
@@ -59,6 +59,24 @@ public:
uint32_t
FindSupportFileIndex (uint32_t start_idx, const SBFileSpec &sb_file, bool full);
+
+ //------------------------------------------------------------------
+ /// Get all types matching \a type_mask from debug info in this
+ /// compile unit.
+ ///
+ /// @param[in] type_mask
+ /// A bitfield that consists of one or more bits logically OR'ed
+ /// together from the lldb::TypeClass enumeration. This allows
+ /// you to request only structure types, or only class, struct
+ /// and union types. Passing in lldb::eTypeClassAny will return
+ /// all types found in the debug information for this compile
+ /// unit.
+ ///
+ /// @return
+ /// A list of types in this compile unit that match \a type_mask
+ //------------------------------------------------------------------
+ lldb::SBTypeList
+ GetTypes (uint32_t type_mask = lldb::eTypeClassAny);
bool
operator == (const lldb::SBCompileUnit &rhs) const;
Modified: lldb/trunk/include/lldb/API/SBModule.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBModule.h?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBModule.h (original)
+++ lldb/trunk/include/lldb/API/SBModule.h Tue Jun 18 17:51:05 2013
@@ -199,7 +199,24 @@ public:
lldb::SBType
GetBasicType(lldb::BasicType type);
-
+
+ //------------------------------------------------------------------
+ /// Get all types matching \a type_mask from debug info in this
+ /// module.
+ ///
+ /// @param[in] type_mask
+ /// A bitfield that consists of one or more bits logically OR'ed
+ /// together from the lldb::TypeClass enumeration. This allows
+ /// you to request only structure types, or only class, struct
+ /// and union types. Passing in lldb::eTypeClassAny will return
+ /// all types found in the debug information for this module.
+ ///
+ /// @return
+ /// A list of types in this module that match \a type_mask
+ //------------------------------------------------------------------
+ lldb::SBTypeList
+ GetTypes (uint32_t type_mask = lldb::eTypeClassAny);
+
//------------------------------------------------------------------
/// Get the module version numbers.
///
Modified: lldb/trunk/include/lldb/API/SBType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBType.h?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBType.h (original)
+++ lldb/trunk/include/lldb/API/SBType.h Tue Jun 18 17:51:05 2013
@@ -235,6 +235,8 @@ public:
private:
std::unique_ptr<lldb_private::TypeListImpl> m_opaque_ap;
+ friend class SBModule;
+ friend class SBCompileUnit;
};
Modified: lldb/trunk/include/lldb/Core/MappedHash.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/MappedHash.h?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/MappedHash.h (original)
+++ lldb/trunk/include/lldb/Core/MappedHash.h Tue Jun 18 17:51:05 2013
@@ -486,6 +486,10 @@ public:
virtual const char *
GetStringForKeyType (KeyType key) const = 0;
+
+ virtual bool
+ ReadHashData (uint32_t hash_data_offset,
+ HashData &hash_data) const = 0;
// This method must be implemented in any subclasses and it must try to
// read one "Pair" at the offset pointed to by the "hash_data_offset_ptr"
@@ -514,6 +518,27 @@ public:
return m_header;
}
+
+ void
+ ForEach (std::function <bool(const HashData &hash_data)> const &callback) const
+ {
+ const size_t num_hash_offsets = m_header.hashes_count;
+ for (size_t i=0; i<num_hash_offsets; ++i)
+ {
+ uint32_t hash_data_offset = GetHashDataOffset (i);
+ if (hash_data_offset != UINT32_MAX)
+ {
+ HashData hash_data;
+ if (ReadHashData (hash_data_offset, hash_data))
+ {
+ // If the callback returns false, then we are done and should stop
+ if (callback(hash_data) == false)
+ return;
+ }
+ }
+ }
+ }
+
protected:
// Implementation agnostic information
HeaderType m_header;
Modified: lldb/trunk/include/lldb/Core/UniqueCStringMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/UniqueCStringMap.h?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/UniqueCStringMap.h (original)
+++ lldb/trunk/include/lldb/Core/UniqueCStringMap.h Tue Jun 18 17:51:05 2013
@@ -121,6 +121,12 @@ public:
return false;
}
+ const char *
+ GetCStringAtIndexUnchecked (uint32_t idx) const
+ {
+ return m_map[idx].cstring;
+ }
+
// Use this function if you have simple types in your map that you
// can easily copy when accessing values by index.
T
Modified: lldb/trunk/include/lldb/Symbol/SymbolFile.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolFile.h?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolFile.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolFile.h Tue Jun 18 17:51:05 2013
@@ -140,6 +140,9 @@ public:
virtual uint32_t FindTypes (const SymbolContext& sc, const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, TypeList& types) = 0;
// virtual uint32_t FindTypes (const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, TypeList& types) = 0;
virtual TypeList * GetTypeList ();
+ virtual size_t GetTypes (lldb_private::SymbolContextScope *sc_scope,
+ uint32_t type_mask,
+ lldb_private::TypeList &type_list) = 0;
virtual ClangASTContext &
GetClangASTContext ();
virtual ClangNamespaceDecl
Modified: lldb/trunk/include/lldb/Symbol/SymbolVendor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolVendor.h?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolVendor.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolVendor.h Tue Jun 18 17:51:05 2013
@@ -153,6 +153,11 @@ public:
return m_type_list;
}
+ virtual size_t
+ GetTypes (lldb_private::SymbolContextScope *sc_scope,
+ uint32_t type_mask,
+ lldb_private::TypeList &type_list);
+
SymbolFile *
GetSymbolFile()
{
Modified: lldb/trunk/include/lldb/Symbol/Type.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Type.h?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Type.h (original)
+++ lldb/trunk/include/lldb/Symbol/Type.h Tue Jun 18 17:51:05 2013
@@ -474,6 +474,27 @@ public:
m_content.push_back(type);
}
+ class AppendVisitor
+ {
+ public:
+ AppendVisitor(TypeListImpl &type_list) :
+ m_type_list(type_list)
+ {
+ }
+
+ void
+ operator() (const lldb::TypeImplSP& type)
+ {
+ m_type_list.Append(type);
+ }
+
+ private:
+ TypeListImpl &m_type_list;
+ };
+
+ void
+ Append (const lldb_private::TypeList &type_list);
+
lldb::TypeImplSP
GetTypeAtIndex(size_t idx)
{
Modified: lldb/trunk/include/lldb/Symbol/TypeList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/TypeList.h?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/TypeList.h (original)
+++ lldb/trunk/include/lldb/Symbol/TypeList.h Tue Jun 18 17:51:05 2013
@@ -51,6 +51,12 @@ public:
lldb::TypeSP
GetTypeAtIndex(uint32_t idx);
+ void
+ ForEach (std::function <bool(const lldb::TypeSP &type_sp)> const &callback) const;
+
+ void
+ ForEach (std::function <bool(lldb::TypeSP &type_sp)> const &callback);
+
bool
RemoveTypeWithUID (lldb::user_id_t uid);
Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Tue Jun 18 17:51:05 2013
@@ -610,7 +610,7 @@ namespace lldb {
eTypeClassOther = (1u << 31),
// Define a mask that can be used for any type when finding types
eTypeClassAny = (0xffffffffu)
- }TypeClass;
+ } TypeClass;
typedef enum TemplateArgumentKind
{
Modified: lldb/trunk/scripts/Python/interface/SBCompileUnit.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBCompileUnit.i?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBCompileUnit.i (original)
+++ lldb/trunk/scripts/Python/interface/SBCompileUnit.i Tue Jun 18 17:51:05 2013
@@ -86,6 +86,26 @@ public:
uint32_t
FindSupportFileIndex (uint32_t start_idx, const SBFileSpec &sb_file, bool full);
+ %feature("docstring", "
+ //------------------------------------------------------------------
+ /// Get all types matching \a type_mask from debug info in this
+ /// compile unit.
+ ///
+ /// @param[in] type_mask
+ /// A bitfield that consists of one or more bits logically OR'ed
+ /// together from the lldb::TypeClass enumeration. This allows
+ /// you to request only structure types, or only class, struct
+ /// and union types. Passing in lldb::eTypeClassAny will return
+ /// all types found in the debug information for this compile
+ /// unit.
+ ///
+ /// @return
+ /// A list of types in this compile unit that match \a type_mask
+ //------------------------------------------------------------------
+ ") GetTypes;
+ lldb::SBTypeList
+ GetTypes (uint32_t type_mask = lldb::eTypeClassAny);
+
bool
GetDescription (lldb::SBStream &description);
Modified: lldb/trunk/scripts/Python/interface/SBModule.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBModule.i?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBModule.i (original)
+++ lldb/trunk/scripts/Python/interface/SBModule.i Tue Jun 18 17:51:05 2013
@@ -227,6 +227,25 @@ public:
%feature("docstring", "
//------------------------------------------------------------------
+ /// Get all types matching \a type_mask from debug info in this
+ /// module.
+ ///
+ /// @param[in] type_mask
+ /// A bitfield that consists of one or more bits logically OR'ed
+ /// together from the lldb::TypeClass enumeration. This allows
+ /// you to request only structure types, or only class, struct
+ /// and union types. Passing in lldb::eTypeClassAny will return
+ /// all types found in the debug information for this module.
+ ///
+ /// @return
+ /// A list of types in this module that match \a type_mask
+ //------------------------------------------------------------------
+ ") GetTypes;
+ lldb::SBTypeList
+ GetTypes (uint32_t type_mask = lldb::eTypeClassAny);
+
+ %feature("docstring", "
+ //------------------------------------------------------------------
/// Find global and static variables by name.
///
/// @param[in] target
Modified: lldb/trunk/source/API/SBCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCompileUnit.cpp?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/source/API/SBCompileUnit.cpp (original)
+++ lldb/trunk/source/API/SBCompileUnit.cpp Tue Jun 18 17:51:05 2013
@@ -10,10 +10,13 @@
#include "lldb/API/SBCompileUnit.h"
#include "lldb/API/SBLineEntry.h"
#include "lldb/API/SBStream.h"
+#include "lldb/Core/Log.h"
+#include "lldb/Core/Module.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/LineEntry.h"
#include "lldb/Symbol/LineTable.h"
-#include "lldb/Core/Log.h"
+#include "lldb/Symbol/SymbolVendor.h"
+#include "lldb/Symbol/Type.h"
using namespace lldb;
using namespace lldb_private;
@@ -148,12 +151,39 @@ SBCompileUnit::GetNumSupportFiles () con
{
if (m_opaque_ptr)
{
- FileSpecList& support_files = m_opaque_ptr->GetSupportFiles ();
- return support_files.GetSize();
+ FileSpecList& support_files = m_opaque_ptr->GetSupportFiles ();
+ return support_files.GetSize();
}
return 0;
}
+
+
+lldb::SBTypeList
+SBCompileUnit::GetTypes (uint32_t type_mask)
+{
+ SBTypeList sb_type_list;
+
+ if (m_opaque_ptr)
+ {
+ ModuleSP module_sp (m_opaque_ptr->GetModule());
+ if (module_sp)
+ {
+ SymbolVendor* vendor = module_sp->GetSymbolVendor();
+ if (vendor)
+ {
+ TypeList type_list;
+ vendor->GetTypes (m_opaque_ptr, type_mask, type_list);
+ sb_type_list.m_opaque_ap->Append(type_list);
+ }
+ }
+ }
+ return sb_type_list;
+}
+
+
+
+
SBFileSpec
SBCompileUnit::GetSupportFileAtIndex (uint32_t idx) const
{
@@ -162,9 +192,9 @@ SBCompileUnit::GetSupportFileAtIndex (ui
SBFileSpec sb_file_spec;
if (m_opaque_ptr)
{
- FileSpecList &support_files = m_opaque_ptr->GetSupportFiles ();
- FileSpec file_spec = support_files.GetFileSpecAtIndex(idx);
- sb_file_spec.SetFileSpec(file_spec);
+ FileSpecList &support_files = m_opaque_ptr->GetSupportFiles ();
+ FileSpec file_spec = support_files.GetFileSpecAtIndex(idx);
+ sb_file_spec.SetFileSpec(file_spec);
}
if (log)
Modified: lldb/trunk/source/API/SBModule.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBModule.cpp?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/source/API/SBModule.cpp (original)
+++ lldb/trunk/source/API/SBModule.cpp Tue Jun 18 17:51:05 2013
@@ -561,6 +561,24 @@ SBModule::FindTypes (const char *type)
return retval;
}
+lldb::SBTypeList
+SBModule::GetTypes (uint32_t type_mask)
+{
+ SBTypeList sb_type_list;
+
+ ModuleSP module_sp (GetSP ());
+ if (module_sp)
+ {
+ SymbolVendor* vendor = module_sp->GetSymbolVendor();
+ if (vendor)
+ {
+ TypeList type_list;
+ vendor->GetTypes (NULL, type_mask, type_list);
+ sb_type_list.m_opaque_ap->Append(type_list);
+ }
+ }
+ return sb_type_list;
+}
SBSection
SBModule::FindSection (const char *sect_name)
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h Tue Jun 18 17:51:05 2013
@@ -607,9 +607,30 @@ struct DWARFMappedHash
return m_string_table.PeekCStr (key);
}
+ virtual bool
+ ReadHashData (uint32_t hash_data_offset,
+ HashData &hash_data) const
+ {
+ lldb::offset_t offset = hash_data_offset;
+ offset += 4; // Skip string table offset that contains offset of hash name in .debug_str
+ const uint32_t count = m_data.GetU32 (&offset);
+ if (count > 0)
+ {
+ hash_data.resize(count);
+ for (uint32_t i=0; i<count; ++i)
+ {
+ if (!m_header.Read(m_data, &offset, hash_data[i]))
+ return false;
+ }
+ }
+ else
+ hash_data.clear();
+ return true;
+ }
+
virtual Result
GetHashDataForName (const char *name,
- lldb::offset_t* hash_data_offset_ptr,
+ lldb::offset_t* hash_data_offset_ptr,
Pair &pair) const
{
pair.key = m_data.GetU32 (hash_data_offset_ptr);
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp Tue Jun 18 17:51:05 2013
@@ -73,3 +73,15 @@ NameToDIE::Dump (Stream *s)
s->Printf("%p: {0x%8.8x} \"%s\"\n", cstr, m_map.GetValueAtIndexUnchecked(i), cstr);
}
}
+
+void
+NameToDIE::ForEach (std::function <bool(const char *name, uint32_t die_offset)> const &callback) const
+{
+ const uint32_t size = m_map.GetSize();
+ for (uint32_t i=0; i<size; ++i)
+ {
+ if (!callback(m_map.GetCStringAtIndexUnchecked(i),
+ m_map.GetValueAtIndexUnchecked (i)))
+ break;
+ }
+}
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h Tue Jun 18 17:51:05 2013
@@ -11,6 +11,9 @@
#define SymbolFileDWARF_NameToDIE_h_
#include "lldb/Core/UniqueCStringMap.h"
+
+#include <functional>
+
#include "lldb/lldb-defines.h"
class SymbolFileDWARF;
@@ -51,6 +54,9 @@ public:
uint32_t cu_end_offset,
DIEArray &info_array) const;
+ void
+ ForEach (std::function <bool(const char *name, uint32_t die_offset)> const &callback) const;
+
protected:
lldb_private::UniqueCStringMap<uint32_t> m_map;
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Tue Jun 18 17:51:05 2013
@@ -235,6 +235,187 @@ SymbolFileDWARF::GetTypeList ()
return m_obj_file->GetModule()->GetTypeList();
}
+void
+SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu,
+ const DWARFDebugInfoEntry *die,
+ dw_offset_t min_die_offset,
+ dw_offset_t max_die_offset,
+ uint32_t type_mask,
+ TypeSet &type_set)
+{
+ if (cu)
+ {
+ if (die)
+ {
+ const dw_offset_t die_offset = die->GetOffset();
+
+ if (die_offset >= max_die_offset)
+ return;
+
+ if (die_offset >= min_die_offset)
+ {
+ const dw_tag_t tag = die->Tag();
+
+ bool add_type = false;
+
+ switch (tag)
+ {
+ case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break;
+ case DW_TAG_unspecified_type:
+ case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break;
+ case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break;
+ case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break;
+ case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break;
+ case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break;
+ case DW_TAG_subroutine_type:
+ case DW_TAG_subprogram:
+ case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break;
+ case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break;
+ case DW_TAG_rvalue_reference_type:
+ case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break;
+ case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break;
+ case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break;
+ }
+
+ if (add_type)
+ {
+ const bool assert_not_being_parsed = true;
+ Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed);
+ if (type)
+ {
+ if (type_set.find(type) == type_set.end())
+ type_set.insert(type);
+ }
+ }
+ }
+
+ for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
+ child_die != NULL;
+ child_die = child_die->GetSibling())
+ {
+ GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set);
+ }
+ }
+ }
+}
+
+size_t
+SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope,
+ uint32_t type_mask,
+ TypeList &type_list)
+
+{
+ TypeSet type_set;
+
+ CompileUnit *comp_unit = NULL;
+ DWARFCompileUnit* dwarf_cu = NULL;
+ if (sc_scope)
+ comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
+
+ if (comp_unit)
+ {
+ dwarf_cu = GetDWARFCompileUnit(comp_unit);
+ if (dwarf_cu == 0)
+ return 0;
+ GetTypes (dwarf_cu,
+ dwarf_cu->DIE(),
+ dwarf_cu->GetOffset(),
+ dwarf_cu->GetNextCompileUnitOffset(),
+ type_mask,
+ type_set);
+ }
+ else
+ {
+ DWARFDebugInfo* info = DebugInfo();
+ if (info)
+ {
+ const size_t num_cus = info->GetNumCompileUnits();
+ for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx)
+ {
+ dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
+ if (dwarf_cu)
+ {
+ GetTypes (dwarf_cu,
+ dwarf_cu->DIE(),
+ 0,
+ UINT32_MAX,
+ type_mask,
+ type_set);
+ }
+ }
+ }
+ }
+// if (m_using_apple_tables)
+// {
+// DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get();
+// if (apple_types)
+// {
+// apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool {
+//
+// for (auto die_info: die_info_array)
+// {
+// bool add_type = TagMatchesTypeMask (type_mask, 0);
+// if (!add_type)
+// {
+// dw_tag_t tag = die_info.tag;
+// if (tag == 0)
+// {
+// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL);
+// tag = die->Tag();
+// }
+// add_type = TagMatchesTypeMask (type_mask, tag);
+// }
+// if (add_type)
+// {
+// Type *type = ResolveTypeUID(die_info.offset);
+//
+// if (type_set.find(type) == type_set.end())
+// type_set.insert(type);
+// }
+// }
+// return true; // Keep iterating
+// });
+// }
+// }
+// else
+// {
+// if (!m_indexed)
+// Index ();
+//
+// m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool {
+//
+// bool add_type = TagMatchesTypeMask (type_mask, 0);
+//
+// if (!add_type)
+// {
+// const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL);
+// if (die)
+// {
+// const dw_tag_t tag = die->Tag();
+// add_type = TagMatchesTypeMask (type_mask, tag);
+// }
+// }
+//
+// if (add_type)
+// {
+// Type *type = ResolveTypeUID(die_offset);
+//
+// if (type_set.find(type) == type_set.end())
+// type_set.insert(type);
+// }
+// return true; // Keep iterating
+// });
+// }
+
+ size_t num_types_added = 0;
+ for (Type *type : type_set)
+ {
+ type_list.Insert (type->shared_from_this());
+ ++num_types_added;
+ }
+ return num_types_added;
+}
+
//----------------------------------------------------------------------
// Gets the first parent that is a lexical block, function or inlined
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Tue Jun 18 17:51:05 2013
@@ -14,6 +14,7 @@
// C++ Includes
#include <list>
#include <map>
+#include <set>
#include <vector>
// Other libraries and framework includes
@@ -121,6 +122,10 @@ public:
virtual uint32_t FindTypes (const lldb_private::SymbolContext& sc, const lldb_private::ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, lldb_private::TypeList& types);
virtual lldb_private::TypeList *
GetTypeList ();
+ virtual size_t GetTypes (lldb_private::SymbolContextScope *sc_scope,
+ uint32_t type_mask,
+ lldb_private::TypeList &type_list);
+
virtual lldb_private::ClangASTContext &
GetClangASTContext ();
@@ -545,6 +550,16 @@ protected:
bool
FixupAddress (lldb_private::Address &addr);
+ typedef std::set<lldb_private::Type *> TypeSet;
+
+ void
+ GetTypes (DWARFCompileUnit* dwarf_cu,
+ const DWARFDebugInfoEntry *die,
+ dw_offset_t min_die_offset,
+ dw_offset_t max_die_offset,
+ uint32_t type_mask,
+ TypeSet &type_set);
+
lldb::ModuleWP m_debug_map_module_wp;
SymbolFileDWARFDebugMap * m_debug_map_symfile;
clang::TranslationUnitDecl * m_clang_tu_decl;
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp Tue Jun 18 17:51:05 2013
@@ -1120,6 +1120,43 @@ SymbolFileDWARFDebugMap::FindFunctions (
return sc_list.GetSize() - initial_size;
}
+size_t
+SymbolFileDWARFDebugMap::GetTypes (SymbolContextScope *sc_scope,
+ uint32_t type_mask,
+ TypeList &type_list)
+{
+ Timer scoped_timer (__PRETTY_FUNCTION__,
+ "SymbolFileDWARFDebugMap::GetTypes (type_mask = 0x%8.8x)",
+ type_mask);
+
+
+ uint32_t initial_size = type_list.GetSize();
+ SymbolFileDWARF *oso_dwarf = NULL;
+ if (sc_scope)
+ {
+ SymbolContext sc;
+ sc_scope->CalculateSymbolContext(&sc);
+
+ CompileUnitInfo *cu_info = GetCompUnitInfo (sc);
+ if (cu_info)
+ {
+ oso_dwarf = GetSymbolFileByCompUnitInfo (cu_info);
+ if (oso_dwarf)
+ oso_dwarf->GetTypes (sc_scope, type_mask, type_list);
+ }
+ }
+ else
+ {
+ uint32_t oso_idx = 0;
+ while ((oso_dwarf = GetSymbolFileByOSOIndex (oso_idx++)) != NULL)
+ {
+ oso_dwarf->GetTypes (sc_scope, type_mask, type_list);
+ }
+ }
+ return type_list.GetSize() - initial_size;
+}
+
+
TypeSP
SymbolFileDWARFDebugMap::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &die_decl_ctx)
{
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h Tue Jun 18 17:51:05 2013
@@ -85,9 +85,12 @@ public:
virtual uint32_t FindFunctions (const lldb_private::RegularExpression& regex, bool include_inlines, bool append, lldb_private::SymbolContextList& sc_list);
virtual uint32_t FindTypes (const lldb_private::SymbolContext& sc, const lldb_private::ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, lldb_private::TypeList& types);
virtual lldb_private::ClangNamespaceDecl
- FindNamespace (const lldb_private::SymbolContext& sc,
- const lldb_private::ConstString &name,
- const lldb_private::ClangNamespaceDecl *parent_namespace_decl);
+ FindNamespace (const lldb_private::SymbolContext& sc,
+ const lldb_private::ConstString &name,
+ const lldb_private::ClangNamespaceDecl *parent_namespace_decl);
+ virtual size_t GetTypes (lldb_private::SymbolContextScope *sc_scope,
+ uint32_t type_mask,
+ lldb_private::TypeList &type_list);
//------------------------------------------------------------------
Modified: lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp Tue Jun 18 17:51:05 2013
@@ -60,6 +60,12 @@ SymbolFileSymtab::CreateInstance (Object
return new SymbolFileSymtab(obj_file);
}
+size_t
+SymbolFileSymtab::GetTypes (SymbolContextScope *sc_scope, uint32_t type_mask, lldb_private::TypeList &type_list)
+{
+ return 0;
+}
+
SymbolFileSymtab::SymbolFileSymtab(ObjectFile* obj_file) :
SymbolFile(obj_file),
m_source_indexes(),
Modified: lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h Tue Jun 18 17:51:05 2013
@@ -102,8 +102,10 @@ public:
virtual uint32_t
FindTypes (const lldb_private::SymbolContext& sc,const lldb_private::ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, lldb_private::TypeList& types);
-// virtual uint32_t
-// FindTypes(const lldb_private::SymbolContext& sc, const lldb_private::RegularExpression& regex, bool append, uint32_t max_matches, lldb_private::TypeList& types);
+ virtual size_t
+ GetTypes (lldb_private::SymbolContextScope *sc_scope,
+ uint32_t type_mask,
+ lldb_private::TypeList &type_list);
virtual lldb_private::ClangNamespaceDecl
FindNamespace (const lldb_private::SymbolContext& sc,
Modified: lldb/trunk/source/Symbol/SymbolVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolVendor.cpp?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolVendor.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolVendor.cpp Tue Jun 18 17:51:05 2013
@@ -352,6 +352,21 @@ SymbolVendor::FindTypes (const SymbolCon
return 0;
}
+size_t
+SymbolVendor::GetTypes (SymbolContextScope *sc_scope,
+ uint32_t type_mask,
+ lldb_private::TypeList &type_list)
+{
+ ModuleSP module_sp(GetModule());
+ if (module_sp)
+ {
+ lldb_private::Mutex::Locker locker(module_sp->GetMutex());
+ if (m_sym_file_ap.get())
+ return m_sym_file_ap->GetTypes (sc_scope, type_mask, type_list);
+ }
+ return 0;
+}
+
ClangNamespaceDecl
SymbolVendor::FindNamespace(const SymbolContext& sc, const ConstString &name, const ClangNamespaceDecl *parent_namespace_decl)
{
Modified: lldb/trunk/source/Symbol/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Type.cpp?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Type.cpp (original)
+++ lldb/trunk/source/Symbol/Type.cpp Tue Jun 18 17:51:05 2013
@@ -33,6 +33,33 @@
using namespace lldb;
using namespace lldb_private;
+class TypeAppendVisitor
+{
+public:
+ TypeAppendVisitor(TypeListImpl &type_list) :
+ m_type_list(type_list)
+ {
+ }
+
+ bool
+ operator() (const lldb::TypeSP& type)
+ {
+ m_type_list.Append(TypeImplSP(new TypeImpl(type)));
+ return true;
+ }
+
+private:
+ TypeListImpl &m_type_list;
+};
+
+void
+TypeListImpl::Append (const lldb_private::TypeList &type_list)
+{
+ TypeAppendVisitor cb(*this);
+ type_list.ForEach(cb);
+}
+
+
Type *
SymbolFileType::GetType ()
{
Modified: lldb/trunk/source/Symbol/TypeList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/TypeList.cpp?rev=184251&r1=184250&r2=184251&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/TypeList.cpp (original)
+++ lldb/trunk/source/Symbol/TypeList.cpp Tue Jun 18 17:51:05 2013
@@ -135,6 +135,27 @@ TypeList::GetTypeAtIndex(uint32_t idx)
return TypeSP();
}
+void
+TypeList::ForEach (std::function <bool(const lldb::TypeSP &type_sp)> const &callback) const
+{
+ for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)
+ {
+ if (!callback(pos->second))
+ break;
+ }
+}
+
+void
+TypeList::ForEach (std::function <bool(lldb::TypeSP &type_sp)> const &callback)
+{
+ for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)
+ {
+ if (!callback(pos->second))
+ break;
+ }
+}
+
+
bool
TypeList::RemoveTypeWithUID (user_id_t uid)
{
More information about the lldb-commits
mailing list