hotspot/src/share/vm/utilities/decoder_elf.cpp
author brutisso
Thu, 31 May 2012 21:10:33 +0200
changeset 12781 dd6480eea079
parent 11483 4d3f4bca0019
child 13963 e5b53c306fb5
permissions -rw-r--r--
7172279: G1: Clean up TraceGen0Time and TraceGen1Time data gathering Summary: Simplify code, remove unused code, remove ExitAfterGCNum Reviewed-by: huntch, johnc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
     1
/*
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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"
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    29
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    30
ElfDecoder::~ElfDecoder() {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    31
  if (_opened_elf_files != NULL) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    32
    delete _opened_elf_files;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    33
    _opened_elf_files = NULL;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    34
  }
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
bool ElfDecoder::decode(address addr, char *buf, int buflen, int* offset, const char* filepath) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    38
  assert(filepath, "null file path");
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    39
  assert(buf != NULL && buflen > 0, "Invalid buffer");
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    40
  if (has_error()) return false;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    41
  ElfFile* file = get_elf_file(filepath);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    42
  if (file == NULL) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    43
    return false;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    44
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    45
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    46
  if (!file->decode(addr, buf, buflen, offset)) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    47
    return false;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    48
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    49
  if (buf[0] != '\0') {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    50
    demangle(buf, buf, buflen);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    51
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    52
  return true;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    53
}
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    54
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    55
ElfFile* ElfDecoder::get_elf_file(const char* filepath) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    56
  ElfFile* file;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    57
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    58
  file = _opened_elf_files;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    59
  while (file != NULL) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    60
    if (file->same_elf_file(filepath)) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    61
      return file;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    62
    }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    63
    file = file->next();
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    64
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    65
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    66
  file = new (std::nothrow)ElfFile(filepath);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    67
  if (file != NULL) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    68
    if (_opened_elf_files != NULL) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    69
      file->set_next(_opened_elf_files);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    70
    }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    71
    _opened_elf_files = file;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    72
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    73
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    74
  return file;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    75
}
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents:
diff changeset
    76
#endif