src/hotspot/share/utilities/decoder_elf.cpp
author mr
Tue, 29 Oct 2019 13:52:04 -0700
changeset 58850 f4290bf1cc21
parent 48157 7c4d43c26352
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:
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
     1
/*
31352
a6ab7217b5cc 8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents: 22857
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
     4
 *
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
     8
 *
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    13
 * accompanied this code).
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    14
 *
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    18
 *
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    21
 * questions.
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    22
 *
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    23
 */
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    24
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    25
#include "precompiled.hpp"
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    26
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    27
#if !defined(_WINDOWS) && !defined(__APPLE__)
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    28
#include "decoder_elf.hpp"
48157
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47216
diff changeset
    29
#include "memory/allocation.inline.hpp"
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    30
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    31
ElfDecoder::~ElfDecoder() {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    32
  if (_opened_elf_files != NULL) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    33
    delete _opened_elf_files;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    34
    _opened_elf_files = NULL;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    35
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    36
}
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    37
31352
a6ab7217b5cc 8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents: 22857
diff changeset
    38
bool ElfDecoder::decode(address addr, char *buf, int buflen, int* offset, const char* filepath, bool demangle_name) {
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    39
  assert(filepath, "null file path");
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    40
  assert(buf != NULL && buflen > 0, "Invalid buffer");
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    41
  if (has_error()) return false;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    42
  ElfFile* file = get_elf_file(filepath);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    43
  if (file == NULL) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    44
    return false;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    45
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    46
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    47
  if (!file->decode(addr, buf, buflen, offset)) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    48
    return false;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    49
  }
31352
a6ab7217b5cc 8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents: 22857
diff changeset
    50
  if (demangle_name && (buf[0] != '\0')) {
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    51
    demangle(buf, buf, buflen);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    52
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    53
  return true;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    54
}
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    55
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    56
ElfFile* ElfDecoder::get_elf_file(const char* filepath) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    57
  ElfFile* file;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    58
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    59
  file = _opened_elf_files;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    60
  while (file != NULL) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    61
    if (file->same_elf_file(filepath)) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    62
      return file;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    63
    }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    64
    file = file->next();
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    65
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    66
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    67
  file = new (std::nothrow)ElfFile(filepath);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    68
  if (file != NULL) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    69
    if (_opened_elf_files != NULL) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    70
      file->set_next(_opened_elf_files);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    71
    }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    72
    _opened_elf_files = file;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    73
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    74
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    75
  return file;
4d3f4bca0019 7071311: Decoder enhancement
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__