src/hotspot/share/utilities/elfStringTable.cpp
author mr
Tue, 29 Oct 2019 13:52:04 -0700
changeset 58850 f4290bf1cc21
parent 51334 cc2c79d22508
permissions -rw-r--r--
8233137: runtime/ErrorHandling/VeryEarlyAssertTest.java fails after 8232080 Reviewed-by: stuefe, iignatyev, mchung
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: 47765
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
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    29
#include "jvm.h"
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    30
#include "memory/allocation.inline.hpp"
9403
6f3c6231c20a 7036747: 7017009 reappeared, problem with ElfStringTable
zgu
parents: 7447
diff changeset
    31
#include "runtime/os.hpp"
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    32
#include "utilities/elfStringTable.hpp"
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    33
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    34
// We will try to load whole string table into memory if we can.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    35
// Otherwise, fallback to more expensive file operation.
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    36
ElfStringTable::ElfStringTable(FILE* const file, Elf_Shdr& shdr, int index) :
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 48975
diff changeset
    37
  _next(NULL), _index(index), _section(file, shdr), _fd(file) {
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    38
  _status = _section.status();
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    39
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    40
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    41
ElfStringTable::~ElfStringTable() {
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    42
  if (_next != NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    43
    delete _next;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    44
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    45
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    46
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    47
bool ElfStringTable::string_at(size_t pos, char* buf, int buflen) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    48
  if (NullDecoder::is_error(get_status())) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    49
    return false;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    50
  }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    51
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    52
  assert(buflen > 0, "no buffer");
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    53
  if (pos >= _section.section_header()->sh_size) {
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    54
    return false;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    55
  }
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    56
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    57
  const char* data = (const char*)_section.section_data();
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    58
  if (data != NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    59
    jio_snprintf(buf, buflen, "%s", data + pos);
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    60
    return true;
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    61
  } else {  // no cache data, read from file instead
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    62
    const Elf_Shdr* const shdr = _section.section_header();
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    63
    MarkedFileReader mfd(_fd);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    64
    if (mfd.has_mark() &&
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    65
      mfd.set_position(shdr->sh_offset + pos) &&
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    66
      mfd.read((void*)buf, size_t(buflen))) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    67
      buf[buflen - 1] = '\0';
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    68
      return true;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    69
    } else {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    70
      // put it in error state to avoid retry
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47765
diff changeset
    71
      _status = NullDecoder::file_invalid;
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    72
      return false;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    73
    }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    74
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    75
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    76
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 13963
diff changeset
    77
#endif // !_WINDOWS && !__APPLE__