hotspot/src/share/vm/utilities/decoder.hpp
author never
Sun, 25 Sep 2011 16:03:29 -0700
changeset 10565 dc90c239f4ec
parent 7447 32c42d627f41
child 11483 4d3f4bca0019
permissions -rw-r--r--
7089790: integrate bsd-port changes Reviewed-by: kvn, twisti, jrose Contributed-by: Kurt Miller <kurt@intricatesoftware.com>, Greg Lewis <glewis@eyesbeyond.com>, Jung-uk Kim <jkim@freebsd.org>, Christos Zoulas <christos@zoulas.com>, Landon Fuller <landonf@plausible.coop>, The FreeBSD Foundation <board@freebsdfoundation.org>, Michael Franz <mvfranz@gmail.com>, Roger Hoover <rhoover@apple.com>, Alexander Strange <astrange@apple.com>
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
/*
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     2
 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
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
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    26
#ifndef __DECODER_HPP
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    27
#define __DECODER_HPP
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 "memory/allocation.hpp"
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    30
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    31
#ifdef _WINDOWS
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    32
#include <windows.h>
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    33
#include <imagehlp.h>
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    34
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    35
// functions needed for decoding symbols
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    36
typedef DWORD (WINAPI *pfn_SymSetOptions)(DWORD);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    37
typedef BOOL  (WINAPI *pfn_SymInitialize)(HANDLE, PCTSTR, BOOL);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    38
typedef BOOL  (WINAPI *pfn_SymGetSymFromAddr64)(HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    39
typedef DWORD (WINAPI *pfn_UndecorateSymbolName)(const char*, char*, DWORD, DWORD);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    40
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7447
diff changeset
    41
#elif defined(__APPLE__)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7447
diff changeset
    42
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    43
#else
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
class ElfFile;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    46
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    47
#endif // _WINDOWS
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    48
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    49
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    50
class Decoder: public StackObj {
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    51
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    52
 public:
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    53
  // status code for decoding native C frame
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    54
  enum decoder_status {
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    55
         no_error,             // successfully decoded frames
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    56
         out_of_memory,        // out of memory
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    57
         file_invalid,         // invalid elf file
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    58
         file_not_found,       // could not found symbol file (on windows), such as jvm.pdb or jvm.map
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    59
         helper_not_found,     // could not load dbghelp.dll (Windows only)
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    60
         helper_func_error,    // decoding functions not found (Windows only)
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    61
         helper_init_error,    // SymInitialize failed (Windows only)
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    62
         symbol_not_found      // could not find the symbol
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    63
  };
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    64
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    65
 public:
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    66
  Decoder() { initialize(); };
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    67
  ~Decoder() { uninitialize(); };
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    68
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    69
  static bool can_decode_C_frame_in_vm();
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    70
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    71
  static void initialize();
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    72
  static void uninitialize();
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
#ifdef _WINDOWS
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    75
  static decoder_status    decode(address addr, char *buf, int buflen, int *offset);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    76
#else
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    77
  static decoder_status    decode(address addr, const char* filepath, char *buf, int buflen, int *offset);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    78
#endif
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    79
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    80
  static bool              demangle(const char* symbol, char *buf, int buflen);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    81
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    82
  static decoder_status    get_status() { return _decoder_status; };
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    83
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7447
diff changeset
    84
#if !defined(_WINDOWS) && !defined(__APPLE__)
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    85
 private:
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    86
  static ElfFile*         get_elf_file(const char* filepath);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    87
#endif // _WINDOWS
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    88
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    89
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    90
 private:
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    91
  static decoder_status     _decoder_status;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    92
  static bool               _initialized;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    93
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    94
#ifdef _WINDOWS
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    95
  static HMODULE                   _dbghelp_handle;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    96
  static bool                      _can_decode_in_vm;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    97
  static pfn_SymGetSymFromAddr64   _pfnSymGetSymFromAddr64;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    98
  static pfn_UndecorateSymbolName  _pfnUndecorateSymbolName;
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7447
diff changeset
    99
#elif __APPLE__
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   100
#else
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   101
  static ElfFile*                  _opened_elf_files;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   102
#endif // _WINDOWS
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   103
};
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   104
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   105
#endif // __DECODER_HPP