From d8e3c254e371f296f8e4d0aae5baf7ab6f7c35a6 Mon Sep 17 00:00:00 2001 From: strange Date: Sat, 26 Dec 2009 15:26:03 -0800 Subject: [PATCH] Continued adding onto AbbrevParser and Tag. Nothing special . . . --- src/monitor/dwarf/AbbrevParser.cpp | 5 ++++- src/monitor/dwarf/Tag.cpp | 42 ++++++++++++++++++++++++++++++++++++++ src/monitor/dwarf/Tag.h | 6 +++++- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/monitor/dwarf/AbbrevParser.cpp b/src/monitor/dwarf/AbbrevParser.cpp index 05c76a1..23156ac 100644 --- a/src/monitor/dwarf/AbbrevParser.cpp +++ b/src/monitor/dwarf/AbbrevParser.cpp @@ -7,7 +7,10 @@ namespace DWARF { AbbrevParser::AbbrevParser(Misc::SmartPointer elf_parser) { Misc::SmartPointer abbrev_data = elf_parser->get_section(".debug_abbrev")->get_content(); - + tag_list.push_back(new Tag("NULL spaceholder tag")); + while(abbrev_data->get_size()) { + tag_list.push_back(Tag::parse_from(abbrev_data)); + } } AbbrevParser::~AbbrevParser() { diff --git a/src/monitor/dwarf/Tag.cpp b/src/monitor/dwarf/Tag.cpp index 1fa0196..faae05d 100644 --- a/src/monitor/dwarf/Tag.cpp +++ b/src/monitor/dwarf/Tag.cpp @@ -1,9 +1,51 @@ +#include + #include "Tag.h" +#include "Parser.h" namespace Aesalon { namespace Monitor { namespace DWARF { +Misc::SmartPointer Tag::parse_from(Misc::SmartPointer block) { + Word tag_type = Parser::parse_uleb128(block); + + Misc::SmartPointer tag; + + /* If the tag type is 0, then the tag is a NULL tag (section 7.5.2, paragraph 2). */ + if(tag_type == 0x00) return new Tag("NULL parsed tag"); + + std::string tag_type_string = ""; + std::map tag_type_map; + /* NOTE: these are from the DWARF 3 documentation (Figure 18). */ + /* TODO: complete this list. */ + /* TODO: find a better way to encapsulate these values. */ + tag_type_map[0x01] = "DW_TAG_array_type"; + tag_type_map[0x02] = "DW_TAG_class_type"; + tag_type_map[0x03] = "DW_TAG_entry_type"; + tag_type_map[0x04] = "DW_TAG_enumeration_type"; + tag_type_map[0x05] = "DW_TAG_formal_parameter"; + tag_type_map[0x08] = "DW_TAG_imported_declaration"; + tag_type_map[0x0a] = "DW_TAG_label"; + tag_type_map[0x0b] = "DW_TAG_lexical_block"; + tag_type_map[0x0d] = "DW_TAG_member"; + tag_type_map[0x0f] = "DW_TAG_pointer_type"; + tag_type_map[0x10] = "DW_TAG_reference_type"; + tag_type_map[0x11] = "DW_TAG_compile_unit"; + tag_type_map[0x12] = "DW_TAG_string_type"; + tag_type_map[0x13] = "DW_TAG_structure_type"; + tag_type_map[0x15] = "DW_TAG_subroutine_type"; + tag_type_map[0x16] = "DW_TAG_typedef"; + + tag_type_string = tag_type_map[tag_type]; + + tag = new Tag(tag_type_string); + + std::cout << "New Tag parsed, type is \"" << tag_type_string << "\"\n"; + + return tag; +} + } // namespace DWARF } // namespace Monitor } // namespace Aesalon diff --git a/src/monitor/dwarf/Tag.h b/src/monitor/dwarf/Tag.h index 21944ce..821eeff 100644 --- a/src/monitor/dwarf/Tag.h +++ b/src/monitor/dwarf/Tag.h @@ -8,9 +8,13 @@ namespace Monitor { namespace DWARF { class Tag { +private: + std::string type; public: - Tag() {} + Tag(std::string type) : type(type) {} virtual ~Tag() {} + + static Misc::SmartPointer parse_from(Misc::SmartPointer block); }; } // namespace DWARF -- 2.11.4.GIT