aboutsummaryrefslogtreecommitdiff
path: root/src/share/vm/utilities/elfFile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/share/vm/utilities/elfFile.cpp')
-rw-r--r--src/share/vm/utilities/elfFile.cpp39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/share/vm/utilities/elfFile.cpp b/src/share/vm/utilities/elfFile.cpp
index 2db1f71e0..2e4b68302 100644
--- a/src/share/vm/utilities/elfFile.cpp
+++ b/src/share/vm/utilities/elfFile.cpp
@@ -44,7 +44,7 @@ ElfFile::ElfFile(const char* filepath) {
m_string_tables = NULL;
m_symbol_tables = NULL;
m_next = NULL;
- m_status = Decoder::no_error;
+ m_status = NullDecoder::no_error;
int len = strlen(filepath) + 1;
m_filepath = (const char*)os::malloc(len * sizeof(char));
@@ -54,10 +54,10 @@ ElfFile::ElfFile(const char* filepath) {
if (m_file != NULL) {
load_tables();
} else {
- m_status = Decoder::file_not_found;
+ m_status = NullDecoder::file_not_found;
}
} else {
- m_status = Decoder::out_of_memory;
+ m_status = NullDecoder::out_of_memory;
}
}
@@ -96,41 +96,41 @@ bool ElfFile::is_elf_file(Elf_Ehdr& hdr) {
bool ElfFile::load_tables() {
assert(m_file, "file not open");
- assert(m_status == Decoder::no_error, "already in error");
+ assert(!NullDecoder::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;
+ m_status = NullDecoder::file_invalid;
return false;
}
if (!is_elf_file(m_elfHdr)) {
- m_status = Decoder::file_invalid;
+ m_status = NullDecoder::file_invalid;
return false;
}
// 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;
+ if (NullDecoder::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;
+ m_status = NullDecoder::file_invalid;
return false;
}
// string table
if (shdr.sh_type == SHT_STRTAB) {
ElfStringTable* table = new (std::nothrow) ElfStringTable(m_file, shdr, index);
if (table == NULL) {
- m_status = Decoder::out_of_memory;
+ m_status = NullDecoder::out_of_memory;
return false;
}
add_string_table(table);
} else if (shdr.sh_type == SHT_SYMTAB || shdr.sh_type == SHT_DYNSYM) {
ElfSymbolTable* table = new (std::nothrow) ElfSymbolTable(m_file, shdr);
if (table == NULL) {
- m_status = Decoder::out_of_memory;
+ m_status = NullDecoder::out_of_memory;
return false;
}
add_symbol_table(table);
@@ -140,32 +140,33 @@ bool ElfFile::load_tables() {
return true;
}
-const char* ElfFile::decode(address addr, int* offset) {
+bool ElfFile::decode(address addr, char* buf, int buflen, int* offset) {
// something already went wrong, just give up
- if (m_status != Decoder::no_error) {
- return NULL;
+ if (NullDecoder::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 (Decoder::no_error == symbol_table->lookup(addr, &string_table_index, &pos_in_string_table, &off)) {
+ 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 NULL;
+ if (!found_symbol) return false;
ElfStringTable* string_table = get_string_table(string_table_index);
+
if (string_table == NULL) {
- m_status = Decoder::file_invalid;
- return NULL;
+ m_status = NullDecoder::file_invalid;
+ return false;
}
if (offset) *offset = off;
- return string_table->string_at(pos_in_string_table);
+
+ return string_table->string_at(pos_in_string_table, buf, buflen);
}