Time for a major overhaul of aesalon, again.
[aesalon.git] / src / monitor / elf / Parser.cpp
blob7a0ad48a2503370ed27eb961eef9f1e15f637704
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <fcntl.h>
5 #include <iostream>
7 #include "Parser.h"
9 namespace Aesalon {
10 namespace Monitor {
11 namespace ELF {
13 Parser::Parser(std::string filename) : filename(filename) {
14 std::cout << "ELF::Parser::Parser(): filename is \"" << filename << "\"\n";
15 file_fd = open(filename.c_str(), O_RDONLY);
17 header = new Header(file_fd);
19 lseek(file_fd, header->get_section_header_offset(), SEEK_SET);
21 for(std::size_t x = 0; x < header->get_num_sections(); x ++) {
22 section_list.push_back(new Section(file_fd));
25 /* Remove the first section, since, according to the standard, it is "reserved and should be all zeros" */
26 /*section_list.erase(section_list.begin());*/
28 string_table = section_list[header->get_string_table_index()];
30 string_table->read_content();
32 for(section_list_t::iterator i = section_list.begin(); i != section_list.end(); i ++) {
33 Byte *p = string_table->get_content()->get_data();
34 p += (*i)->get_name_offset();
36 /*std::cout << "Section, name is \"" << (char *)p << "\'\n";*/
38 (*i)->set_name((char *)p);
41 symbol_parser = new SymbolParser(this);
44 Parser::~Parser() {
45 close(file_fd);
48 Misc::SmartPointer<Section> Parser::get_section(std::string name) const {
49 for(section_list_t::const_iterator i = section_list.begin(); i != section_list.end(); i ++) {
50 if((*i)->get_name() == name) return *i;
52 return NULL;
55 Misc::SmartPointer<Symbol> Parser::get_symbol(std::string name) const {
56 return symbol_parser->get_symbol(name);
59 } // namespace ELF
60 } // namespace Monitor
61 } // namespace Aesalon