src/hotspot/share/utilities/elfFile.cpp
author naoto
Tue, 09 Jul 2019 08:05:38 -0700
changeset 55627 9c1885fb2a42
parent 51334 cc2c79d22508
permissions -rw-r--r--
8227127: Era designator not displayed correctly using the COMPAT provider Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     1
/*
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     4
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     8
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    13
 * accompanied this code).
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    14
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    18
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    21
 * questions.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    22
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    23
 */
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    24
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    25
#include "precompiled.hpp"
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    26
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 9403
diff changeset
    27
#if !defined(_WINDOWS) && !defined(__APPLE__)
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    28
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    29
#include <string.h>
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    30
#include <stdio.h>
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    31
#include <limits.h>
9403
6f3c6231c20a 7036747: 7017009 reappeared, problem with ElfStringTable
zgu
parents: 7447
diff changeset
    32
#include <new>
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    33
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    34
#include "logging/log.hpp"
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    35
#include "memory/allocation.inline.hpp"
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    36
#include "memory/resourceArea.hpp"
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    37
#include "utilities/decoder.hpp"
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    38
#include "utilities/elfFile.hpp"
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 15926
diff changeset
    39
#include "utilities/elfFuncDescTable.hpp"
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    40
#include "utilities/elfStringTable.hpp"
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    41
#include "utilities/elfSymbolTable.hpp"
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    42
#include "utilities/ostream.hpp"
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    43
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    44
// For test only, disable elf section cache and force to read from file directly.
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    45
bool ElfFile::_do_not_cache_elf_section = false;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    46
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    47
ElfSection::ElfSection(FILE* fd, const Elf_Shdr& hdr) : _section_data(NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    48
  _stat = load_section(fd, hdr);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    49
}
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    50
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    51
ElfSection::~ElfSection() {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    52
  if (_section_data != NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    53
    os::free(_section_data);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    54
  }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    55
}
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    56
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    57
NullDecoder::decoder_status ElfSection::load_section(FILE* const fd, const Elf_Shdr& shdr) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    58
  memcpy((void*)&_section_hdr, (const void*)&shdr, sizeof(shdr));
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    59
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    60
  if (ElfFile::_do_not_cache_elf_section) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    61
    log_debug(decoder)("Elf section cache is disabled");
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    62
    return NullDecoder::no_error;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    63
  }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    64
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    65
  _section_data = os::malloc(shdr.sh_size, mtInternal);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    66
  // No enough memory for caching. It is okay, we can try to read from
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    67
  // file instead.
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    68
  if (_section_data == NULL) return NullDecoder::no_error;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    69
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    70
  MarkedFileReader mfd(fd);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    71
  if (mfd.has_mark() &&
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    72
      mfd.set_position(shdr.sh_offset) &&
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    73
      mfd.read(_section_data, shdr.sh_size)) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    74
    return NullDecoder::no_error;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    75
  } else {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    76
    os::free(_section_data);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    77
    _section_data = NULL;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    78
    return NullDecoder::file_invalid;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    79
  }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    80
}
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    81
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    82
bool FileReader::read(void* buf, size_t size) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    83
  assert(buf != NULL, "no buffer");
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    84
  assert(size > 0, "no space");
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    85
  return fread(buf, size, 1, _fd) == 1;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    86
}
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    87
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    88
int FileReader::read_buffer(void* buf, size_t size) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    89
  assert(buf != NULL, "no buffer");
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    90
  assert(size > 0, "no space");
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    91
  return fread(buf, 1, size, _fd);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    92
}
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    93
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    94
bool FileReader::set_position(long offset) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    95
  return fseek(_fd, offset, SEEK_SET) == 0;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    96
}
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    97
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    98
MarkedFileReader::MarkedFileReader(FILE* fd) : FileReader(fd) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    99
  _marked_pos = ftell(fd);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   100
}
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   101
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   102
MarkedFileReader::~MarkedFileReader() {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   103
  if (_marked_pos != -1) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   104
    set_position(_marked_pos);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   105
  }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   106
}
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   107
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   108
ElfFile::ElfFile(const char* filepath) :
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 48975
diff changeset
   109
  _next(NULL), _filepath(NULL), _file(NULL),
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 48975
diff changeset
   110
  _symbol_tables(NULL), _string_tables(NULL), _shdr_string_table(NULL), _funcDesc_table(NULL),
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 48975
diff changeset
   111
  _status(NullDecoder::no_error) {
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   112
  memset(&_elfHdr, 0, sizeof(_elfHdr));
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   113
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   114
  int len = strlen(filepath) + 1;
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   115
  _filepath = (char*)os::malloc(len * sizeof(char), mtInternal);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   116
  if (_filepath == NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   117
    _status = NullDecoder::out_of_memory;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   118
    return;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   119
  }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   120
  strcpy(_filepath, filepath);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   121
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   122
  _status = parse_elf(filepath);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   123
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   124
  // we no longer need section header string table
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   125
  if (_shdr_string_table != NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   126
    delete _shdr_string_table;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   127
    _shdr_string_table = NULL;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   128
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   129
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   130
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   131
ElfFile::~ElfFile() {
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   132
  if (_shdr_string_table != NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   133
    delete _shdr_string_table;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   134
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   135
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   136
  cleanup_tables();
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   137
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   138
  if (_file != NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   139
    fclose(_file);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   140
  }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   141
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   142
  if (_filepath != NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   143
    os::free((void*)_filepath);
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   144
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   145
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   146
  if (_next != NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   147
    delete _next;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   148
  }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   149
}
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   150
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   151
void ElfFile::cleanup_tables() {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   152
  if (_string_tables != NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   153
    delete _string_tables;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   154
    _string_tables = NULL;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   155
  }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   156
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   157
  if (_symbol_tables != NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   158
    delete _symbol_tables;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   159
    _symbol_tables = NULL;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   160
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   161
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   162
  if (_funcDesc_table != NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   163
    delete _funcDesc_table;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   164
    _funcDesc_table = NULL;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   165
  }
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   166
}
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   167
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   168
NullDecoder::decoder_status ElfFile::parse_elf(const char* filepath) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   169
  assert(filepath, "null file path");
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   170
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   171
  _file = fopen(filepath, "r");
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   172
  if (_file != NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   173
    return load_tables();
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   174
  } else {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   175
    return NullDecoder::file_not_found;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   176
  }
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   177
}
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   178
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   179
//Check elf header to ensure the file is valid.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   180
bool ElfFile::is_elf_file(Elf_Ehdr& hdr) {
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   181
  return (ELFMAG0 == hdr.e_ident[EI_MAG0] &&
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   182
      ELFMAG1 == hdr.e_ident[EI_MAG1] &&
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   183
      ELFMAG2 == hdr.e_ident[EI_MAG2] &&
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   184
      ELFMAG3 == hdr.e_ident[EI_MAG3] &&
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   185
      ELFCLASSNONE != hdr.e_ident[EI_CLASS] &&
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   186
      ELFDATANONE != hdr.e_ident[EI_DATA]);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   187
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   188
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   189
NullDecoder::decoder_status ElfFile::load_tables() {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   190
  assert(_file, "file not open");
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   191
  assert(!NullDecoder::is_error(_status), "already in error");
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   192
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   193
  FileReader freader(fd());
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   194
  // read elf file header
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   195
  if (!freader.read(&_elfHdr, sizeof(_elfHdr))) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   196
    return NullDecoder::file_invalid;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   197
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   198
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   199
  // Check signature
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   200
  if (!is_elf_file(_elfHdr)) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   201
    return NullDecoder::file_invalid;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   202
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   203
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   204
  // walk elf file's section headers, and load string tables
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   205
  Elf_Shdr shdr;
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   206
  if (!freader.set_position(_elfHdr.e_shoff)) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   207
    return NullDecoder::file_invalid;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   208
  }
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   209
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   210
  for (int index = 0; index < _elfHdr.e_shnum; index ++) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   211
    if (!freader.read(&shdr, sizeof(shdr))) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   212
      return NullDecoder::file_invalid;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   213
    }
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 15926
diff changeset
   214
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   215
    if (shdr.sh_type == SHT_STRTAB) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   216
      // string tables
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   217
      ElfStringTable* table = new (std::nothrow) ElfStringTable(fd(), shdr, index);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   218
      if (table == NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   219
        return NullDecoder::out_of_memory;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   220
      }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   221
      if (index == _elfHdr.e_shstrndx) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   222
        assert(_shdr_string_table == NULL, "Only set once");
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   223
        _shdr_string_table = table;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   224
      } else {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   225
        add_string_table(table);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   226
      }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   227
    } else if (shdr.sh_type == SHT_SYMTAB || shdr.sh_type == SHT_DYNSYM) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   228
      // symbol tables
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   229
      ElfSymbolTable* table = new (std::nothrow) ElfSymbolTable(fd(), shdr);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   230
      if (table == NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   231
        return NullDecoder::out_of_memory;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   232
      }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   233
      add_symbol_table(table);
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 15926
diff changeset
   234
    }
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   235
  }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   236
#if defined(PPC64) && !defined(ABI_ELFv2)
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   237
  // Now read the .opd section wich contains the PPC64 function descriptor table.
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   238
  // The .opd section is only available on PPC64 (see for example:
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   239
  // http://refspecs.linuxfoundation.org/LSB_3.1.1/LSB-Core-PPC64/LSB-Core-PPC64/specialsections.html)
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   240
  // so this code should do no harm on other platforms but because of performance reasons we only
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   241
  // execute it on PPC64 platforms.
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   242
  // Notice that we can only find the .opd section after we have successfully read in the string
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   243
  // tables in the previous loop, because we need to query the name of each section which is
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   244
  // contained in one of the string tables (i.e. the one with the index m_elfHdr.e_shstrndx).
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   245
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   246
  // Reset the file pointer
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   247
  int sect_index = section_by_name(".opd", shdr);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   248
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   249
  if (sect_index == -1) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   250
    return NullDecoder::file_invalid;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   251
  }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   252
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   253
  _funcDesc_table = new (std::nothrow) ElfFuncDescTable(_file, shdr, sect_index);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   254
  if (_funcDesc_table == NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   255
      return NullDecoder::out_of_memory;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   256
  }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   257
#endif
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   258
  return NullDecoder::no_error;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   259
}
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   260
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   261
int ElfFile::section_by_name(const char* name, Elf_Shdr& hdr) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   262
  assert(name != NULL, "No section name");
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   263
  size_t len = strlen(name) + 1;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   264
  ResourceMark rm;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   265
  char* buf = NEW_RESOURCE_ARRAY(char, len);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   266
  if (buf == NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   267
    return -1;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   268
  }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   269
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   270
  assert(_shdr_string_table != NULL, "Section header string table should be loaded");
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   271
  ElfStringTable* const table = _shdr_string_table;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   272
  MarkedFileReader mfd(fd());
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   273
  if (!mfd.has_mark() || !mfd.set_position(_elfHdr.e_shoff)) return -1;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   274
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   275
  int sect_index = -1;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   276
  for (int index = 0; index < _elfHdr.e_shnum; index ++) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   277
    if (!mfd.read((void*)&hdr, sizeof(hdr))) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   278
      break;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   279
    }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   280
    if (table->string_at(hdr.sh_name, buf, len)) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   281
      if (strncmp(buf, name, len) == 0) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   282
        sect_index = index;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   283
        break;
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 15926
diff changeset
   284
      }
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 15926
diff changeset
   285
    }
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   286
  }
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   287
  return sect_index;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   288
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   289
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   290
bool ElfFile::decode(address addr, char* buf, int buflen, int* offset) {
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   291
  // something already went wrong, just give up
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   292
  if (NullDecoder::is_error(_status)) {
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   293
    return false;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   294
  }
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   295
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   296
  int string_table_index;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   297
  int pos_in_string_table;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   298
  int off = INT_MAX;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   299
  bool found_symbol = false;
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   300
  ElfSymbolTable* symbol_table = _symbol_tables;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   301
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   302
  while (symbol_table != NULL) {
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   303
    if (symbol_table->lookup(addr, &string_table_index, &pos_in_string_table, &off, _funcDesc_table)) {
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   304
      found_symbol = true;
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 15926
diff changeset
   305
      break;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   306
    }
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   307
    symbol_table = symbol_table->next();
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   308
  }
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   309
  if (!found_symbol) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   310
    return false;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   311
  }
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   312
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   313
  ElfStringTable* string_table = get_string_table(string_table_index);
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   314
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   315
  if (string_table == NULL) {
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   316
    _status = NullDecoder::file_invalid;
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   317
    return false;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   318
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   319
  if (offset) *offset = off;
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   320
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   321
  return string_table->string_at(pos_in_string_table, buf, buflen);
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   322
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   323
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   324
void ElfFile::add_symbol_table(ElfSymbolTable* table) {
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   325
  if (_symbol_tables == NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   326
    _symbol_tables = table;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   327
  } else {
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   328
    table->set_next(_symbol_tables);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   329
    _symbol_tables = table;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   330
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   331
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   332
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   333
void ElfFile::add_string_table(ElfStringTable* table) {
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   334
  if (_string_tables == NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   335
    _string_tables = table;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   336
  } else {
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   337
    table->set_next(_string_tables);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   338
    _string_tables = table;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   339
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   340
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   341
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   342
ElfStringTable* ElfFile::get_string_table(int index) {
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   343
  ElfStringTable* p = _string_tables;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   344
  while (p != NULL) {
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   345
    if (p->index() == index) return p;
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   346
    p = p->next();
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   347
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   348
  return NULL;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   349
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   350
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 15926
diff changeset
   351
#endif // !_WINDOWS && !__APPLE__