Remove dead code for handling DWARF pubnames

Summary:
LLDB doesn't use this code, the code has no tests, and the code does suspicious
things like hashing pointers to strings instead of the strings themselves.

Subscribers: sanjoy, mgorny, JDevlieghere

Differential Revision: https://reviews.llvm.org/D43202

llvm-svn: 324925
This commit is contained in:
Adrian McCarthy 2018-02-12 19:19:04 +00:00
parent e4fcb00290
commit fbfdd53ad1
7 changed files with 0 additions and 540 deletions

View File

@ -17,8 +17,6 @@ add_lldb_library(lldbPluginSymbolFileDWARF PLUGIN
DWARFDebugMacro.cpp
DWARFDebugMacinfo.cpp
DWARFDebugMacinfoEntry.cpp
DWARFDebugPubnames.cpp
DWARFDebugPubnamesSet.cpp
DWARFDebugRanges.cpp
DWARFDeclContext.cpp
DWARFDefines.cpp

View File

@ -1,255 +0,0 @@
//===-- DWARFDebugPubnames.cpp ----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "DWARFDebugPubnames.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/Timer.h"
#include "DWARFCompileUnit.h"
#include "DWARFDIECollection.h"
#include "DWARFDebugInfo.h"
#include "DWARFFormValue.h"
#include "LogChannelDWARF.h"
#include "SymbolFileDWARF.h"
using namespace lldb;
using namespace lldb_private;
DWARFDebugPubnames::DWARFDebugPubnames() : m_sets() {}
bool DWARFDebugPubnames::Extract(const DWARFDataExtractor &data) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat,
"DWARFDebugPubnames::Extract (byte_size = %" PRIu64 ")",
(uint64_t)data.GetByteSize());
Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_PUBNAMES));
if (log)
log->Printf("DWARFDebugPubnames::Extract (byte_size = %" PRIu64 ")",
(uint64_t)data.GetByteSize());
if (data.ValidOffset(0)) {
lldb::offset_t offset = 0;
DWARFDebugPubnamesSet set;
while (data.ValidOffset(offset)) {
if (set.Extract(data, &offset)) {
m_sets.push_back(set);
offset = set.GetOffsetOfNextEntry();
} else
break;
}
if (log)
Dump(log);
return true;
}
return false;
}
bool DWARFDebugPubnames::GeneratePubnames(SymbolFileDWARF *dwarf2Data) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat,
"DWARFDebugPubnames::GeneratePubnames (data = %p)",
static_cast<void *>(dwarf2Data));
Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_PUBNAMES));
if (log)
log->Printf("DWARFDebugPubnames::GeneratePubnames (data = %p)",
static_cast<void *>(dwarf2Data));
m_sets.clear();
DWARFDebugInfo *debug_info = dwarf2Data->DebugInfo();
if (debug_info) {
uint32_t cu_idx = 0;
const uint32_t num_compile_units = dwarf2Data->GetNumCompileUnits();
for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
DWARFCompileUnit *cu = debug_info->GetCompileUnitAtIndex(cu_idx);
DWARFFormValue::FixedFormSizes fixed_form_sizes =
DWARFFormValue::GetFixedFormSizesForAddressSize(
cu->GetAddressByteSize(), cu->IsDWARF64());
bool clear_dies = cu->ExtractDIEsIfNeeded(false) > 1;
DWARFDIECollection dies;
const size_t die_count = cu->AppendDIEsWithTag(DW_TAG_subprogram, dies) +
cu->AppendDIEsWithTag(DW_TAG_variable, dies);
dw_offset_t cu_offset = cu->GetOffset();
DWARFDebugPubnamesSet pubnames_set(DW_INVALID_OFFSET, cu_offset,
cu->GetNextCompileUnitOffset() -
cu_offset);
size_t die_idx;
for (die_idx = 0; die_idx < die_count; ++die_idx) {
DWARFDIE die = dies.GetDIEAtIndex(die_idx);
DWARFAttributes attributes;
const char *name = NULL;
const char *mangled = NULL;
bool add_die = false;
const size_t num_attributes = die.GetDIE()->GetAttributes(
die.GetCU(), fixed_form_sizes, attributes);
if (num_attributes > 0) {
uint32_t i;
dw_tag_t tag = die.Tag();
for (i = 0; i < num_attributes; ++i) {
dw_attr_t attr = attributes.AttributeAtIndex(i);
DWARFFormValue form_value;
switch (attr) {
case DW_AT_name:
if (attributes.ExtractFormValueAtIndex(i, form_value))
name = form_value.AsCString();
break;
case DW_AT_MIPS_linkage_name:
case DW_AT_linkage_name:
if (attributes.ExtractFormValueAtIndex(i, form_value))
mangled = form_value.AsCString();
break;
case DW_AT_low_pc:
case DW_AT_ranges:
case DW_AT_entry_pc:
if (tag == DW_TAG_subprogram)
add_die = true;
break;
case DW_AT_location:
if (tag == DW_TAG_variable) {
DWARFDIE parent_die = die.GetParent();
while (parent_die) {
switch (parent_die.Tag()) {
case DW_TAG_subprogram:
case DW_TAG_lexical_block:
case DW_TAG_inlined_subroutine:
// Even if this is a function level static, we don't add it.
// We could theoretically
// add these if we wanted to by introspecting into the
// DW_AT_location and seeing
// if the location describes a hard coded address, but we
// don't want the performance
// penalty of that right now.
add_die = false;
parent_die.Clear(); // Terminate the while loop.
break;
case DW_TAG_compile_unit:
add_die = true;
parent_die.Clear(); // Terminate the while loop.
break;
default:
parent_die =
parent_die.GetParent(); // Keep going in the while loop.
break;
}
}
}
break;
}
}
}
if (add_die && (name || mangled)) {
pubnames_set.AddDescriptor(die.GetCompileUnitRelativeOffset(),
mangled ? mangled : name);
}
}
if (pubnames_set.NumDescriptors() > 0) {
m_sets.push_back(pubnames_set);
}
// Keep memory down by clearing DIEs if this generate function
// caused them to be parsed
if (clear_dies)
cu->ClearDIEs(true);
}
}
if (m_sets.empty())
return false;
if (log)
Dump(log);
return true;
}
bool DWARFDebugPubnames::GeneratePubBaseTypes(SymbolFileDWARF *dwarf2Data) {
m_sets.clear();
DWARFDebugInfo *debug_info = dwarf2Data->DebugInfo();
if (debug_info) {
uint32_t cu_idx = 0;
const uint32_t num_compile_units = dwarf2Data->GetNumCompileUnits();
for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
DWARFCompileUnit *cu = debug_info->GetCompileUnitAtIndex(cu_idx);
DWARFDIECollection dies;
const size_t die_count = cu->AppendDIEsWithTag(DW_TAG_base_type, dies);
dw_offset_t cu_offset = cu->GetOffset();
DWARFDebugPubnamesSet pubnames_set(DW_INVALID_OFFSET, cu_offset,
cu->GetNextCompileUnitOffset() -
cu_offset);
size_t die_idx;
for (die_idx = 0; die_idx < die_count; ++die_idx) {
DWARFDIE die = dies.GetDIEAtIndex(die_idx);
const char *name = die.GetName();
if (name)
pubnames_set.AddDescriptor(die.GetCompileUnitRelativeOffset(), name);
}
if (pubnames_set.NumDescriptors() > 0) {
m_sets.push_back(pubnames_set);
}
}
}
return !m_sets.empty();
}
void DWARFDebugPubnames::Dump(Log *s) const {
if (m_sets.empty())
s->PutCString("< EMPTY >\n");
else {
const_iterator pos;
const_iterator end = m_sets.end();
for (pos = m_sets.begin(); pos != end; ++pos)
(*pos).Dump(s);
}
}
bool DWARFDebugPubnames::Find(const char *name, bool ignore_case,
std::vector<dw_offset_t> &die_offsets) const {
const_iterator pos;
const_iterator end = m_sets.end();
die_offsets.clear();
for (pos = m_sets.begin(); pos != end; ++pos) {
(*pos).Find(name, ignore_case, die_offsets);
}
return !die_offsets.empty();
}
bool DWARFDebugPubnames::Find(const RegularExpression &regex,
std::vector<dw_offset_t> &die_offsets) const {
const_iterator pos;
const_iterator end = m_sets.end();
die_offsets.clear();
for (pos = m_sets.begin(); pos != end; ++pos) {
(*pos).Find(regex, die_offsets);
}
return !die_offsets.empty();
}

View File

@ -1,40 +0,0 @@
//===-- DWARFDebugPubnames.h ------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef SymbolFileDWARF_DWARFDebugPubnames_h_
#define SymbolFileDWARF_DWARFDebugPubnames_h_
#include "SymbolFileDWARF.h"
#include <list>
#include "DWARFDebugPubnamesSet.h"
class DWARFDebugPubnames {
public:
DWARFDebugPubnames();
bool Extract(const lldb_private::DWARFDataExtractor &data);
bool GeneratePubnames(SymbolFileDWARF *dwarf2Data);
bool GeneratePubBaseTypes(SymbolFileDWARF *dwarf2Data);
void Dump(lldb_private::Log *s) const;
bool Find(const char *name, bool ignore_case,
std::vector<dw_offset_t> &die_offset_coll) const;
bool Find(const lldb_private::RegularExpression &regex,
std::vector<dw_offset_t> &die_offsets) const;
protected:
typedef std::list<DWARFDebugPubnamesSet> collection;
typedef collection::iterator iterator;
typedef collection::const_iterator const_iterator;
collection m_sets;
};
#endif // SymbolFileDWARF_DWARFDebugPubnames_h_

View File

@ -1,146 +0,0 @@
//===-- DWARFDebugPubnamesSet.cpp -------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "DWARFDebugPubnamesSet.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/RegularExpression.h"
#include "SymbolFileDWARF.h"
using namespace lldb_private;
DWARFDebugPubnamesSet::DWARFDebugPubnamesSet()
: m_offset(DW_INVALID_OFFSET), m_header(), m_descriptors(),
m_name_to_descriptor_index() {}
DWARFDebugPubnamesSet::DWARFDebugPubnamesSet(dw_offset_t debug_aranges_offset,
dw_offset_t cu_die_offset,
dw_offset_t cu_die_length)
: m_offset(debug_aranges_offset), m_header(), m_descriptors(),
m_name_to_descriptor_index() {
m_header.length =
10; // set the length to only include the header right for now
m_header.version = 2; // The DWARF version number
m_header.die_offset = cu_die_offset; // compile unit .debug_info offset
m_header.die_length = cu_die_length; // compile unit .debug_info length
}
void DWARFDebugPubnamesSet::AddDescriptor(dw_offset_t cu_rel_offset,
const char *name) {
if (name && name[0]) {
// Adjust our header length
m_header.length += strlen(name) + 1 + sizeof(dw_offset_t);
Descriptor pubnameDesc(cu_rel_offset, name);
m_descriptors.push_back(pubnameDesc);
}
}
void DWARFDebugPubnamesSet::Clear() {
m_offset = DW_INVALID_OFFSET;
m_header.length = 10;
m_header.version = 2;
m_header.die_offset = DW_INVALID_OFFSET;
m_header.die_length = 0;
m_descriptors.clear();
}
//----------------------------------------------------------------------
// InitNameIndexes
//----------------------------------------------------------------------
void DWARFDebugPubnamesSet::InitNameIndexes() const {
// Create the name index vector to be able to quickly search by name
const size_t count = m_descriptors.size();
for (uint32_t idx = 0; idx < count; ++idx) {
const char *name = m_descriptors[idx].name.c_str();
if (name && name[0])
m_name_to_descriptor_index.insert(
cstr_to_index_mmap::value_type(name, idx));
}
}
bool DWARFDebugPubnamesSet::Extract(const DWARFDataExtractor &data,
lldb::offset_t *offset_ptr) {
if (data.ValidOffset(*offset_ptr)) {
m_descriptors.clear();
m_offset = *offset_ptr;
m_header.length = data.GetDWARFInitialLength(offset_ptr);
m_header.version = data.GetU16(offset_ptr);
m_header.die_offset = data.GetDWARFOffset(offset_ptr);
m_header.die_length = data.GetDWARFOffset(offset_ptr);
Descriptor pubnameDesc;
while (data.ValidOffset(*offset_ptr)) {
pubnameDesc.offset = data.GetDWARFOffset(offset_ptr);
if (pubnameDesc.offset) {
const char *name = data.GetCStr(offset_ptr);
if (name && name[0]) {
pubnameDesc.name = name;
m_descriptors.push_back(pubnameDesc);
}
} else
break; // We are done if we get a zero 4 byte offset
}
return !m_descriptors.empty();
}
return false;
}
dw_offset_t DWARFDebugPubnamesSet::GetOffsetOfNextEntry() const {
return m_offset + m_header.length + 4;
}
void DWARFDebugPubnamesSet::Dump(Log *log) const {
log->Printf("Pubnames Header: length = 0x%8.8x, version = 0x%4.4x, "
"die_offset = 0x%8.8x, die_length = 0x%8.8x",
m_header.length, m_header.version, m_header.die_offset,
m_header.die_length);
bool verbose = log->GetVerbose();
DescriptorConstIter pos;
DescriptorConstIter end = m_descriptors.end();
for (pos = m_descriptors.begin(); pos != end; ++pos) {
if (verbose)
log->Printf("0x%8.8x + 0x%8.8x = 0x%8.8x: %s", pos->offset,
m_header.die_offset, pos->offset + m_header.die_offset,
pos->name.c_str());
else
log->Printf("0x%8.8x: %s", pos->offset + m_header.die_offset,
pos->name.c_str());
}
}
void DWARFDebugPubnamesSet::Find(
const char *name, bool ignore_case,
std::vector<dw_offset_t> &die_offset_coll) const {
if (!m_descriptors.empty() && m_name_to_descriptor_index.empty())
InitNameIndexes();
std::pair<cstr_to_index_mmap::const_iterator,
cstr_to_index_mmap::const_iterator>
range(m_name_to_descriptor_index.equal_range(name));
for (cstr_to_index_mmap::const_iterator pos = range.first;
pos != range.second; ++pos)
die_offset_coll.push_back(m_header.die_offset +
m_descriptors[(*pos).second].offset);
}
void DWARFDebugPubnamesSet::Find(
const RegularExpression &regex,
std::vector<dw_offset_t> &die_offset_coll) const {
DescriptorConstIter pos;
DescriptorConstIter end = m_descriptors.end();
for (pos = m_descriptors.begin(); pos != end; ++pos) {
if (regex.Execute(pos->name))
die_offset_coll.push_back(m_header.die_offset + pos->offset);
}
}

View File

@ -1,95 +0,0 @@
//===-- DWARFDebugPubnamesSet.h ---------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef SymbolFileDWARF_DWARFDebugPubnamesSet_h_
#define SymbolFileDWARF_DWARFDebugPubnamesSet_h_
#include "SymbolFileDWARF.h"
#include <map>
#include <string>
#include <vector>
#if __cplusplus >= 201103L || defined(_MSC_VER)
#include <unordered_map>
#else
#include <ext/hash_map>
#endif
#include "lldb/Core/STLUtils.h"
class DWARFDebugPubnamesSet {
public:
struct Header {
uint32_t length; // length of the set of entries for this compilation unit,
// not including the length field itself
uint16_t version; // The DWARF version number
uint32_t die_offset; // compile unit .debug_info offset
uint32_t die_length; // compile unit .debug_info length
Header()
: length(10), version(2), die_offset(DW_INVALID_OFFSET), die_length(0) {
}
};
struct Descriptor {
Descriptor() : offset(), name() {}
Descriptor(dw_offset_t the_offset, const char *the_name)
: offset(the_offset), name(the_name ? the_name : "") {}
dw_offset_t offset;
std::string name;
};
DWARFDebugPubnamesSet();
DWARFDebugPubnamesSet(dw_offset_t debug_aranges_offset,
dw_offset_t cu_die_offset, dw_offset_t die_length);
dw_offset_t GetOffset() const { return m_offset; }
void SetOffset(dw_offset_t offset) { m_offset = offset; }
DWARFDebugPubnamesSet::Header &GetHeader() { return m_header; }
const DWARFDebugPubnamesSet::Header &GetHeader() const { return m_header; }
const DWARFDebugPubnamesSet::Descriptor *GetDescriptor(uint32_t i) const {
if (i < m_descriptors.size())
return &m_descriptors[i];
return NULL;
}
uint32_t NumDescriptors() const { return m_descriptors.size(); }
void AddDescriptor(dw_offset_t cu_rel_offset, const char *name);
void Clear();
bool Extract(const lldb_private::DWARFDataExtractor &debug_pubnames_data,
lldb::offset_t *offset_ptr);
void Dump(lldb_private::Log *s) const;
void InitNameIndexes() const;
void Find(const char *name, bool ignore_case,
std::vector<dw_offset_t> &die_offset_coll) const;
void Find(const lldb_private::RegularExpression &regex,
std::vector<dw_offset_t> &die_offsets) const;
dw_offset_t GetOffsetOfNextEntry() const;
protected:
typedef std::vector<Descriptor> DescriptorColl;
typedef DescriptorColl::iterator DescriptorIter;
typedef DescriptorColl::const_iterator DescriptorConstIter;
dw_offset_t m_offset;
Header m_header;
#if __cplusplus >= 201103L || defined(_MSC_VER)
typedef std::unordered_multimap<const char *, uint32_t,
std::hash<const char *>,
CStringEqualBinaryPredicate>
cstr_to_index_mmap;
#else
typedef __gnu_cxx::hash_multimap<const char *, uint32_t,
__gnu_cxx::hash<const char *>,
CStringEqualBinaryPredicate>
cstr_to_index_mmap;
#endif
DescriptorColl m_descriptors;
mutable cstr_to_index_mmap m_name_to_descriptor_index;
};
#endif // SymbolFileDWARF_DWARFDebugPubnamesSet_h_

View File

@ -65,7 +65,6 @@
#include "DWARFDebugInfo.h"
#include "DWARFDebugLine.h"
#include "DWARFDebugMacro.h"
#include "DWARFDebugPubnames.h"
#include "DWARFDebugRanges.h"
#include "DWARFDeclContext.h"
#include "DWARFFormValue.h"

View File

@ -54,7 +54,6 @@ class DWARFDebugAranges;
class DWARFDebugInfo;
class DWARFDebugInfoEntry;
class DWARFDebugLine;
class DWARFDebugPubnames;
class DWARFDebugRanges;
class DWARFDeclContext;
class DWARFDIECollection;