src/share/vm/utilities/decoder.hpp

changeset 2364
2d4762ec74af
child 3156
f08d439fab8c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/utilities/decoder.hpp	Sat Dec 11 13:20:56 2010 -0500
     1.3 @@ -0,0 +1,102 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +
    1.29 +#ifndef __DECODER_HPP
    1.30 +#define __DECODER_HPP
    1.31 +
    1.32 +#include "memory/allocation.hpp"
    1.33 +
    1.34 +#ifdef _WINDOWS
    1.35 +#include <windows.h>
    1.36 +#include <imagehlp.h>
    1.37 +
    1.38 +// functions needed for decoding symbols
    1.39 +typedef DWORD (WINAPI *pfn_SymSetOptions)(DWORD);
    1.40 +typedef BOOL  (WINAPI *pfn_SymInitialize)(HANDLE, PCTSTR, BOOL);
    1.41 +typedef BOOL  (WINAPI *pfn_SymGetSymFromAddr64)(HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64);
    1.42 +typedef DWORD (WINAPI *pfn_UndecorateSymbolName)(const char*, char*, DWORD, DWORD);
    1.43 +
    1.44 +#else
    1.45 +
    1.46 +class ElfFile;
    1.47 +
    1.48 +#endif // _WINDOWS
    1.49 +
    1.50 +
    1.51 +class Decoder: public StackObj {
    1.52 +
    1.53 + public:
    1.54 +  // status code for decoding native C frame
    1.55 +  enum decoder_status {
    1.56 +         no_error,             // successfully decoded frames
    1.57 +         out_of_memory,        // out of memory
    1.58 +         file_invalid,         // invalid elf file
    1.59 +         file_not_found,       // could not found symbol file (on windows), such as jvm.pdb or jvm.map
    1.60 +         helper_not_found,     // could not load dbghelp.dll (Windows only)
    1.61 +         helper_func_error,    // decoding functions not found (Windows only)
    1.62 +         helper_init_error,    // SymInitialize failed (Windows only)
    1.63 +         symbol_not_found      // could not find the symbol
    1.64 +  };
    1.65 +
    1.66 + public:
    1.67 +  Decoder() { initialize(); };
    1.68 +  ~Decoder() { uninitialize(); };
    1.69 +
    1.70 +  static bool can_decode_C_frame_in_vm();
    1.71 +
    1.72 +  static void initialize();
    1.73 +  static void uninitialize();
    1.74 +
    1.75 +#ifdef _WINDOWS
    1.76 +  static decoder_status    decode(address addr, char *buf, int buflen, int *offset);
    1.77 +#else
    1.78 +  static decoder_status    decode(address addr, const char* filepath, char *buf, int buflen, int *offset);
    1.79 +#endif
    1.80 +
    1.81 +  static bool              demangle(const char* symbol, char *buf, int buflen);
    1.82 +
    1.83 +  static decoder_status    get_status() { return _decoder_status; };
    1.84 +
    1.85 +#ifndef _WINDOWS
    1.86 + private:
    1.87 +  static ElfFile*         get_elf_file(const char* filepath);
    1.88 +#endif // _WINDOWS
    1.89 +
    1.90 +
    1.91 + private:
    1.92 +  static decoder_status     _decoder_status;
    1.93 +  static bool               _initialized;
    1.94 +
    1.95 +#ifdef _WINDOWS
    1.96 +  static HMODULE                   _dbghelp_handle;
    1.97 +  static bool                      _can_decode_in_vm;
    1.98 +  static pfn_SymGetSymFromAddr64   _pfnSymGetSymFromAddr64;
    1.99 +  static pfn_UndecorateSymbolName  _pfnUndecorateSymbolName;
   1.100 +#else
   1.101 +  static ElfFile*                  _opened_elf_files;
   1.102 +#endif // _WINDOWS
   1.103 +};
   1.104 +
   1.105 +#endif // __DECODER_HPP

mercurial