From b7c2d05a1a83dd91052ca6df20c2f60c802e773e Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Fri, 22 Feb 2019 22:05:19 +0100 Subject: Add support for goto to selected symbol address. Signed-off-by: Pavel Pisa --- qtmips_machine/programloader.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'qtmips_machine/programloader.cpp') diff --git a/qtmips_machine/programloader.cpp b/qtmips_machine/programloader.cpp index 750fd00..859bab4 100644 --- a/qtmips_machine/programloader.cpp +++ b/qtmips_machine/programloader.cpp @@ -130,3 +130,36 @@ std::uint32_t ProgramLoader::end() { std::uint32_t ProgramLoader::get_executable_entry() { return executable_entry; } + +SymbolTable *ProgramLoader::get_symbol_table() { + SymbolTable *p_st = new SymbolTable(); + Elf_Scn *scn = NULL; + GElf_Shdr shdr; + Elf_Data *data; + int count, ii; + + elf_version(EV_CURRENT); + + while (1) { + if ((scn = elf_nextscn(this->elf, scn)) == NULL) + return p_st; + gelf_getshdr(scn, &shdr); + if (shdr.sh_type == SHT_SYMTAB) { + /* found a symbol table, go print it. */ + break; + } + } + + data = elf_getdata(scn, NULL); + count = shdr.sh_size / shdr.sh_entsize; + + /* rettrieve the symbol names */ + for (ii = 0; ii < count; ++ii) { + GElf_Sym sym; + gelf_getsym(data, ii, &sym); + p_st->add_symbol(elf_strptr(elf, shdr.sh_link, sym.st_name), + sym.st_value, sym.st_size, sym.st_info, sym.st_other); + } + + return p_st; +} -- cgit v1.2.3