aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine/programloader.cpp
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-22 22:05:19 +0100
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-02-22 22:05:19 +0100
commitb7c2d05a1a83dd91052ca6df20c2f60c802e773e (patch)
tree9dae0d407c0848b9f703bbbc37278d445e04158b /qtmips_machine/programloader.cpp
parent372af906107bceed8a174d5aa907034d35cfe760 (diff)
downloadqtmips-b7c2d05a1a83dd91052ca6df20c2f60c802e773e.tar.gz
qtmips-b7c2d05a1a83dd91052ca6df20c2f60c802e773e.tar.bz2
qtmips-b7c2d05a1a83dd91052ca6df20c2f60c802e773e.zip
Add support for goto to selected symbol address.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_machine/programloader.cpp')
-rw-r--r--qtmips_machine/programloader.cpp33
1 files changed, 33 insertions, 0 deletions
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;
+}