DWARFAbbreviationDeclaration.cpp revision 276479
198944Sobrien//===-- DWARFAbbreviationDeclaration.cpp ------------------------*- C++ -*-===//
298944Sobrien//
398944Sobrien//                     The LLVM Compiler Infrastructure
498944Sobrien//
598944Sobrien// This file is distributed under the University of Illinois Open Source
698944Sobrien// License. See LICENSE.TXT for details.
798944Sobrien//
898944Sobrien//===----------------------------------------------------------------------===//
998944Sobrien
1098944Sobrien#include "DWARFAbbreviationDeclaration.h"
1198944Sobrien
1298944Sobrien#include "lldb/Core/dwarf.h"
1398944Sobrien
1498944Sobrien#include "DWARFFormValue.h"
1598944Sobrien
1698944Sobrienusing namespace lldb_private;
1798944Sobrien
1898944SobrienDWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration() :
1998944Sobrien    m_code  (InvalidCode),
2098944Sobrien    m_tag   (0),
2198944Sobrien    m_has_children (0),
2298944Sobrien    m_attributes()
2398944Sobrien{
2498944Sobrien}
2598944Sobrien
2698944SobrienDWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration(dw_tag_t tag, uint8_t has_children) :
2798944Sobrien    m_code  (InvalidCode),
2898944Sobrien    m_tag   (tag),
2998944Sobrien    m_has_children (has_children),
3098944Sobrien    m_attributes()
3198944Sobrien{
3298944Sobrien}
3398944Sobrien
3498944Sobrienbool
3598944SobrienDWARFAbbreviationDeclaration::Extract(const DWARFDataExtractor& data, lldb::offset_t* offset_ptr)
3698944Sobrien{
3798944Sobrien    return Extract(data, offset_ptr, data.GetULEB128(offset_ptr));
3898944Sobrien}
3998944Sobrien
4098944Sobrienbool
4198944SobrienDWARFAbbreviationDeclaration::Extract(const DWARFDataExtractor& data, lldb::offset_t *offset_ptr, dw_uleb128_t code)
4298944Sobrien{
4398944Sobrien    m_code = code;
4498944Sobrien    m_attributes.clear();
4598944Sobrien    if (m_code)
4698944Sobrien    {
4798944Sobrien        m_tag = data.GetULEB128(offset_ptr);
4898944Sobrien        m_has_children = data.GetU8(offset_ptr);
4998944Sobrien
5098944Sobrien        while (data.ValidOffset(*offset_ptr))
5198944Sobrien        {
5298944Sobrien            dw_attr_t attr = data.GetULEB128(offset_ptr);
5398944Sobrien            dw_form_t form = data.GetULEB128(offset_ptr);
5498944Sobrien
5598944Sobrien            if (attr && form)
5698944Sobrien                m_attributes.push_back(DWARFAttribute(attr, form));
5798944Sobrien            else
5898944Sobrien                break;
5998944Sobrien        }
6098944Sobrien
6198944Sobrien        return m_tag != 0;
6298944Sobrien    }
6398944Sobrien    else
6498944Sobrien    {
6598944Sobrien        m_tag = 0;
6698944Sobrien        m_has_children = 0;
6798944Sobrien    }
6898944Sobrien
6998944Sobrien    return false;
7098944Sobrien}
7198944Sobrien
7298944Sobrien
7398944Sobrienvoid
7498944SobrienDWARFAbbreviationDeclaration::Dump(Stream *s)  const
7598944Sobrien{
7698944Sobrien//  *ostrm_ptr << std::setfill(' ') << std::dec << '[' << std::setw(3) << std::right << m_code << ']' << ' ' << std::setw(30) << std::left << DW_TAG_value_to_name(m_tag) << DW_CHILDREN_value_to_name(m_has_children) << std::endl;
7798944Sobrien//
7898944Sobrien//  DWARFAttribute::const_iterator pos;
7998944Sobrien//
8098944Sobrien//  for (pos = m_attributes.begin(); pos != m_attributes.end(); ++pos)
8198944Sobrien//      *ostrm_ptr << "      " << std::setw(29) << std::left << DW_AT_value_to_name(pos->attr()) << ' ' << DW_FORM_value_to_name(pos->form()) << std::endl;
8298944Sobrien//
8398944Sobrien//  *ostrm_ptr << std::endl;
8498944Sobrien}
8598944Sobrien
8698944Sobrien
8798944Sobrien
8898944Sobrienbool
8998944SobrienDWARFAbbreviationDeclaration::IsValid()
9098944Sobrien{
9198944Sobrien    return m_code != 0 && m_tag != 0;
9298944Sobrien}
9398944Sobrien
9498944Sobrien
9598944Sobrien
9698944Sobrienuint32_t
9798944SobrienDWARFAbbreviationDeclaration::FindAttributeIndex(dw_attr_t attr) const
9898944Sobrien{
9998944Sobrien    uint32_t i;
10098944Sobrien    const uint32_t kNumAttributes = m_attributes.size();
10198944Sobrien    for (i = 0; i < kNumAttributes; ++i)
10298944Sobrien    {
10398944Sobrien        if (m_attributes[i].get_attr() == attr)
10498944Sobrien            return i;
10598944Sobrien    }
10698944Sobrien    return DW_INVALID_INDEX;
10798944Sobrien}
10898944Sobrien
10998944Sobrien
11098944Sobrienbool
11198944SobrienDWARFAbbreviationDeclaration::operator == (const DWARFAbbreviationDeclaration& rhs) const
11298944Sobrien{
11398944Sobrien    return Tag()            == rhs.Tag()
11498944Sobrien        && HasChildren()    == rhs.HasChildren()
11598944Sobrien        && Attributes()     == rhs.Attributes();
11698944Sobrien}
11798944Sobrien
11898944Sobrien