src/share/vm/utilities/elfFile.cpp

changeset 3430
d7e3846464d0
parent 3156
f08d439fab8c
child 3900
d2a62e0f25eb
     1.1 --- a/src/share/vm/utilities/elfFile.cpp	Wed Jan 11 17:58:26 2012 -0500
     1.2 +++ b/src/share/vm/utilities/elfFile.cpp	Tue Jan 17 13:08:52 2012 -0500
     1.3 @@ -44,7 +44,7 @@
     1.4    m_string_tables = NULL;
     1.5    m_symbol_tables = NULL;
     1.6    m_next = NULL;
     1.7 -  m_status = Decoder::no_error;
     1.8 +  m_status = NullDecoder::no_error;
     1.9  
    1.10    int len = strlen(filepath) + 1;
    1.11    m_filepath = (const char*)os::malloc(len * sizeof(char));
    1.12 @@ -54,10 +54,10 @@
    1.13      if (m_file != NULL) {
    1.14        load_tables();
    1.15      } else {
    1.16 -      m_status = Decoder::file_not_found;
    1.17 +      m_status = NullDecoder::file_not_found;
    1.18      }
    1.19    } else {
    1.20 -    m_status = Decoder::out_of_memory;
    1.21 +    m_status = NullDecoder::out_of_memory;
    1.22    }
    1.23  }
    1.24  
    1.25 @@ -96,41 +96,41 @@
    1.26  
    1.27  bool ElfFile::load_tables() {
    1.28    assert(m_file, "file not open");
    1.29 -  assert(m_status == Decoder::no_error, "already in error");
    1.30 +  assert(!NullDecoder::is_error(m_status), "already in error");
    1.31  
    1.32    // read elf file header
    1.33    if (fread(&m_elfHdr, sizeof(m_elfHdr), 1, m_file) != 1) {
    1.34 -    m_status = Decoder::file_invalid;
    1.35 +    m_status = NullDecoder::file_invalid;
    1.36      return false;
    1.37    }
    1.38  
    1.39    if (!is_elf_file(m_elfHdr)) {
    1.40 -    m_status = Decoder::file_invalid;
    1.41 +    m_status = NullDecoder::file_invalid;
    1.42      return false;
    1.43    }
    1.44  
    1.45    // walk elf file's section headers, and load string tables
    1.46    Elf_Shdr shdr;
    1.47    if (!fseek(m_file, m_elfHdr.e_shoff, SEEK_SET)) {
    1.48 -    if (m_status != Decoder::no_error) return false;
    1.49 +    if (NullDecoder::is_error(m_status)) return false;
    1.50  
    1.51      for (int index = 0; index < m_elfHdr.e_shnum; index ++) {
    1.52        if (fread((void*)&shdr, sizeof(Elf_Shdr), 1, m_file) != 1) {
    1.53 -        m_status = Decoder::file_invalid;
    1.54 +        m_status = NullDecoder::file_invalid;
    1.55          return false;
    1.56        }
    1.57        // string table
    1.58        if (shdr.sh_type == SHT_STRTAB) {
    1.59          ElfStringTable* table = new (std::nothrow) ElfStringTable(m_file, shdr, index);
    1.60          if (table == NULL) {
    1.61 -          m_status = Decoder::out_of_memory;
    1.62 +          m_status = NullDecoder::out_of_memory;
    1.63            return false;
    1.64          }
    1.65          add_string_table(table);
    1.66        } else if (shdr.sh_type == SHT_SYMTAB || shdr.sh_type == SHT_DYNSYM) {
    1.67          ElfSymbolTable* table = new (std::nothrow) ElfSymbolTable(m_file, shdr);
    1.68          if (table == NULL) {
    1.69 -          m_status = Decoder::out_of_memory;
    1.70 +          m_status = NullDecoder::out_of_memory;
    1.71            return false;
    1.72          }
    1.73          add_symbol_table(table);
    1.74 @@ -140,32 +140,33 @@
    1.75    return true;
    1.76  }
    1.77  
    1.78 -const char* ElfFile::decode(address addr, int* offset) {
    1.79 +bool ElfFile::decode(address addr, char* buf, int buflen, int* offset) {
    1.80    // something already went wrong, just give up
    1.81 -  if (m_status != Decoder::no_error) {
    1.82 -    return NULL;
    1.83 +  if (NullDecoder::is_error(m_status)) {
    1.84 +    return false;
    1.85    }
    1.86 -
    1.87    ElfSymbolTable* symbol_table = m_symbol_tables;
    1.88    int string_table_index;
    1.89    int pos_in_string_table;
    1.90    int off = INT_MAX;
    1.91    bool found_symbol = false;
    1.92    while (symbol_table != NULL) {
    1.93 -    if (Decoder::no_error == symbol_table->lookup(addr, &string_table_index, &pos_in_string_table, &off)) {
    1.94 +    if (symbol_table->lookup(addr, &string_table_index, &pos_in_string_table, &off)) {
    1.95        found_symbol = true;
    1.96      }
    1.97      symbol_table = symbol_table->m_next;
    1.98    }
    1.99 -  if (!found_symbol) return NULL;
   1.100 +  if (!found_symbol) return false;
   1.101  
   1.102    ElfStringTable* string_table = get_string_table(string_table_index);
   1.103 +
   1.104    if (string_table == NULL) {
   1.105 -    m_status = Decoder::file_invalid;
   1.106 -    return NULL;
   1.107 +    m_status = NullDecoder::file_invalid;
   1.108 +    return false;
   1.109    }
   1.110    if (offset) *offset = off;
   1.111 -  return string_table->string_at(pos_in_string_table);
   1.112 +
   1.113 +  return string_table->string_at(pos_in_string_table, buf, buflen);
   1.114  }
   1.115  
   1.116  

mercurial