src/share/vm/utilities/elfFile.cpp
Print this page
*** 94,104 ****
ELFDATANONE != hdr.e_ident[EI_DATA]);
}
bool ElfFile::load_tables() {
assert(m_file, "file not open");
! assert(m_status == Decoder::no_error, "already in error");
// read elf file header
if (fread(&m_elfHdr, sizeof(m_elfHdr), 1, m_file) != 1) {
m_status = Decoder::file_invalid;
return false;
--- 94,104 ----
ELFDATANONE != hdr.e_ident[EI_DATA]);
}
bool ElfFile::load_tables() {
assert(m_file, "file not open");
! assert(!Decoder::is_error(m_status), "already in error");
// read elf file header
if (fread(&m_elfHdr, sizeof(m_elfHdr), 1, m_file) != 1) {
m_status = Decoder::file_invalid;
return false;
*** 110,120 ****
}
// walk elf file's section headers, and load string tables
Elf_Shdr shdr;
if (!fseek(m_file, m_elfHdr.e_shoff, SEEK_SET)) {
! if (m_status != Decoder::no_error) return false;
for (int index = 0; index < m_elfHdr.e_shnum; index ++) {
if (fread((void*)&shdr, sizeof(Elf_Shdr), 1, m_file) != 1) {
m_status = Decoder::file_invalid;
return false;
--- 110,120 ----
}
// walk elf file's section headers, and load string tables
Elf_Shdr shdr;
if (!fseek(m_file, m_elfHdr.e_shoff, SEEK_SET)) {
! if (Decoder::is_error(m_status)) return false;
for (int index = 0; index < m_elfHdr.e_shnum; index ++) {
if (fread((void*)&shdr, sizeof(Elf_Shdr), 1, m_file) != 1) {
m_status = Decoder::file_invalid;
return false;
*** 138,173 ****
}
}
return true;
}
! const char* ElfFile::decode(address addr, int* offset) {
// something already went wrong, just give up
! if (m_status != Decoder::no_error) {
! return NULL;
}
-
ElfSymbolTable* symbol_table = m_symbol_tables;
int string_table_index;
int pos_in_string_table;
int off = INT_MAX;
bool found_symbol = false;
while (symbol_table != NULL) {
! if (Decoder::no_error == symbol_table->lookup(addr, &string_table_index, &pos_in_string_table, &off)) {
found_symbol = true;
}
symbol_table = symbol_table->m_next;
}
! if (!found_symbol) return NULL;
ElfStringTable* string_table = get_string_table(string_table_index);
if (string_table == NULL) {
m_status = Decoder::file_invalid;
! return NULL;
}
if (offset) *offset = off;
! return string_table->string_at(pos_in_string_table);
}
void ElfFile::add_symbol_table(ElfSymbolTable* table) {
if (m_symbol_tables == NULL) {
--- 138,174 ----
}
}
return true;
}
! bool ElfFile::decode(address addr, char* buf, int buflen, int* offset) {
// something already went wrong, just give up
! if (Decoder::is_error(m_status)) {
! return false;
}
ElfSymbolTable* symbol_table = m_symbol_tables;
int string_table_index;
int pos_in_string_table;
int off = INT_MAX;
bool found_symbol = false;
while (symbol_table != NULL) {
! if (symbol_table->lookup(addr, &string_table_index, &pos_in_string_table, &off)) {
found_symbol = true;
}
symbol_table = symbol_table->m_next;
}
! if (!found_symbol) return false;
ElfStringTable* string_table = get_string_table(string_table_index);
+
if (string_table == NULL) {
m_status = Decoder::file_invalid;
! return false;
}
if (offset) *offset = off;
!
! return string_table->string_at(pos_in_string_table, buf, buflen);
}
void ElfFile::add_symbol_table(ElfSymbolTable* table) {
if (m_symbol_tables == NULL) {