author | prr |
Mon, 06 Nov 2017 10:11:19 -0800 (2017-11-06) | |
changeset 47717 | 4a00b088902e |
parent 47666 | 19219ec3f176 |
child 48975 | 2c35fd3c5789 |
permissions | -rw-r--r-- |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
1 |
/* |
47666 | 2 |
* Copyright (c) 1997, 2017, 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 |
|
11483 | 26 |
#ifndef SHARE_VM_UTILITIES_DECODER_HPP |
27 |
#define SHARE_VM_UTILITIES_DECODER_HPP |
|
7447
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" |
11483 | 30 |
#include "runtime/mutex.hpp" |
19952
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13340
diff
changeset
|
31 |
#include "runtime/mutexLocker.hpp" |
47086
2b35673f6297
8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
46630
diff
changeset
|
32 |
#include "utilities/ostream.hpp" |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
33 |
|
13195 | 34 |
class AbstractDecoder : public CHeapObj<mtInternal> { |
11483 | 35 |
public: |
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
31352
diff
changeset
|
36 |
virtual ~AbstractDecoder() {} |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
31352
diff
changeset
|
37 |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
38 |
// status code for decoding native C frame |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
39 |
enum decoder_status { |
11483 | 40 |
not_available = -10, // real decoder is not available |
41 |
no_error = 0, // successfully decoded frames |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
42 |
out_of_memory, // out of memory |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
43 |
file_invalid, // invalid elf file |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
44 |
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
|
45 |
helper_func_error, // decoding functions not found (Windows only) |
11483 | 46 |
helper_init_error // SymInitialize failed (Windows only) |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
47 |
}; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
48 |
|
11761 | 49 |
// decode an pc address to corresponding function name and an offset from the beginning of |
50 |
// the function |
|
31352
a6ab7217b5cc
8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents:
22234
diff
changeset
|
51 |
// |
a6ab7217b5cc
8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents:
22234
diff
changeset
|
52 |
// Note: the 'base' variant does not demangle names. The |
a6ab7217b5cc
8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents:
22234
diff
changeset
|
53 |
// demangling that was done systematically in the 'modulepath' variant |
a6ab7217b5cc
8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents:
22234
diff
changeset
|
54 |
// is now optional. |
11761 | 55 |
virtual bool decode(address pc, char* buf, int buflen, int* offset, |
31352
a6ab7217b5cc
8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents:
22234
diff
changeset
|
56 |
const char* modulepath = NULL, bool demangle = true) = 0; |
13340 | 57 |
virtual bool decode(address pc, char* buf, int buflen, int* offset, const void* base) = 0; |
58 |
||
11761 | 59 |
// demangle a C++ symbol |
60 |
virtual bool demangle(const char* symbol, char* buf, int buflen) = 0; |
|
61 |
||
62 |
virtual decoder_status status() const { |
|
63 |
return _decoder_status; |
|
64 |
} |
|
65 |
||
66 |
virtual bool has_error() const { |
|
67 |
return is_error(_decoder_status); |
|
68 |
} |
|
69 |
||
70 |
static bool is_error(decoder_status status) { |
|
71 |
return (status > 0); |
|
72 |
} |
|
73 |
||
74 |
protected: |
|
75 |
decoder_status _decoder_status; |
|
76 |
}; |
|
77 |
||
78 |
// Do nothing decoder |
|
79 |
class NullDecoder : public AbstractDecoder { |
|
80 |
public: |
|
11483 | 81 |
NullDecoder() { |
82 |
_decoder_status = not_available; |
|
83 |
} |
|
84 |
||
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
31352
diff
changeset
|
85 |
virtual ~NullDecoder() {}; |
11483 | 86 |
|
87 |
virtual bool decode(address pc, char* buf, int buflen, int* offset, |
|
31352
a6ab7217b5cc
8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents:
22234
diff
changeset
|
88 |
const char* modulepath, bool demangle) { |
11483 | 89 |
return false; |
90 |
} |
|
91 |
||
13340 | 92 |
virtual bool decode(address pc, char* buf, int buflen, int* offset, const void* base) { |
93 |
return false; |
|
94 |
} |
|
95 |
||
11483 | 96 |
virtual bool demangle(const char* symbol, char* buf, int buflen) { |
97 |
return false; |
|
98 |
} |
|
99 |
||
100 |
}; |
|
101 |
||
102 |
||
11761 | 103 |
class Decoder : AllStatic { |
11483 | 104 |
public: |
31352
a6ab7217b5cc
8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents:
22234
diff
changeset
|
105 |
static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL, bool demangle = true); |
a6ab7217b5cc
8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents:
22234
diff
changeset
|
106 |
static bool decode(address pc, char* buf, int buflen, int* offset, bool demangle) { |
a6ab7217b5cc
8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents:
22234
diff
changeset
|
107 |
return decode(pc, buf, buflen, offset, (const char*) NULL, demangle); |
a6ab7217b5cc
8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents:
22234
diff
changeset
|
108 |
} |
13340 | 109 |
static bool decode(address pc, char* buf, int buflen, int* offset, const void* base); |
11483 | 110 |
static bool demangle(const char* symbol, char* buf, int buflen); |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
111 |
|
47666 | 112 |
// Attempts to retrieve source file name and line number associated with a pc. |
113 |
// If buf != NULL, points to a buffer of size buflen which will receive the |
|
114 |
// file name. File name will be silently truncated if output buffer is too small. |
|
115 |
static bool get_source_info(address pc, char* buf, size_t buflen, int* line); |
|
47086
2b35673f6297
8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
46630
diff
changeset
|
116 |
|
2b35673f6297
8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
46630
diff
changeset
|
117 |
static void print_state_on(outputStream* st); |
2b35673f6297
8186349: [windows] Centralize dbghelp handling code
stuefe
parents:
46630
diff
changeset
|
118 |
|
11483 | 119 |
protected: |
11761 | 120 |
// shared decoder instance, _shared_instance_lock is needed |
121 |
static AbstractDecoder* get_shared_instance(); |
|
122 |
// a private instance for error handler. Error handler can be |
|
123 |
// triggered almost everywhere, including signal handler, where |
|
124 |
// no lock can be taken. So the shared decoder can not be used |
|
125 |
// in this scenario. |
|
126 |
static AbstractDecoder* get_error_handler_instance(); |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
127 |
|
11761 | 128 |
static AbstractDecoder* create_decoder(); |
11483 | 129 |
private: |
11761 | 130 |
static AbstractDecoder* _shared_decoder; |
131 |
static AbstractDecoder* _error_handler_decoder; |
|
132 |
static NullDecoder _do_nothing_decoder; |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
133 |
|
11483 | 134 |
protected: |
11761 | 135 |
static Mutex* _shared_decoder_lock; |
19952
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13340
diff
changeset
|
136 |
static Mutex* shared_decoder_lock(); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13340
diff
changeset
|
137 |
|
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13340
diff
changeset
|
138 |
friend class DecoderLocker; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13340
diff
changeset
|
139 |
}; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13340
diff
changeset
|
140 |
|
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13340
diff
changeset
|
141 |
class DecoderLocker : public MutexLockerEx { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13340
diff
changeset
|
142 |
AbstractDecoder* _decoder; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13340
diff
changeset
|
143 |
inline bool is_first_error_thread(); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13340
diff
changeset
|
144 |
public: |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13340
diff
changeset
|
145 |
DecoderLocker(); |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13340
diff
changeset
|
146 |
AbstractDecoder* decoder() { |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13340
diff
changeset
|
147 |
return _decoder; |
bc974e92f881
8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents:
13340
diff
changeset
|
148 |
} |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
149 |
}; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
150 |
|
11483 | 151 |
#endif // SHARE_VM_UTILITIES_DECODER_HPP |