1 /* |
1 /* |
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
31 #include "runtime/mutexLocker.hpp" |
31 #include "runtime/mutexLocker.hpp" |
32 #include "utilities/ostream.hpp" |
32 #include "utilities/ostream.hpp" |
33 |
33 |
34 class AbstractDecoder : public CHeapObj<mtInternal> { |
34 class AbstractDecoder : public CHeapObj<mtInternal> { |
35 public: |
35 public: |
36 virtual ~AbstractDecoder() {} |
|
37 |
|
38 // status code for decoding native C frame |
36 // status code for decoding native C frame |
39 enum decoder_status { |
37 enum decoder_status { |
40 not_available = -10, // real decoder is not available |
38 not_available = -10, // real decoder is not available |
41 no_error = 0, // successfully decoded frames |
39 no_error = 0, // no error encountered |
42 out_of_memory, // out of memory |
40 out_of_memory, // out of memory |
43 file_invalid, // invalid elf file |
41 file_invalid, // invalid elf file |
44 file_not_found, // could not found symbol file (on windows), such as jvm.pdb or jvm.map |
42 file_not_found, // could not found symbol file (on windows), such as jvm.pdb or jvm.map |
45 helper_func_error, // decoding functions not found (Windows only) |
43 helper_func_error, // decoding functions not found (Windows only) |
46 helper_init_error // SymInitialize failed (Windows only) |
44 helper_init_error // SymInitialize failed (Windows only) |
47 }; |
45 }; |
|
46 |
|
47 protected: |
|
48 decoder_status _decoder_status; |
|
49 |
|
50 public: |
|
51 virtual ~AbstractDecoder() {} |
48 |
52 |
49 // decode an pc address to corresponding function name and an offset from the beginning of |
53 // decode an pc address to corresponding function name and an offset from the beginning of |
50 // the function |
54 // the function |
51 // |
55 // |
52 // Note: the 'base' variant does not demangle names. The |
56 // Note: the 'base' variant does not demangle names. The |
66 virtual bool has_error() const { |
70 virtual bool has_error() const { |
67 return is_error(_decoder_status); |
71 return is_error(_decoder_status); |
68 } |
72 } |
69 |
73 |
70 static bool is_error(decoder_status status) { |
74 static bool is_error(decoder_status status) { |
71 return (status > 0); |
75 return (status > no_error); |
72 } |
76 } |
73 |
|
74 protected: |
|
75 decoder_status _decoder_status; |
|
76 }; |
77 }; |
77 |
78 |
78 // Do nothing decoder |
79 // Do nothing decoder |
79 class NullDecoder : public AbstractDecoder { |
80 class NullDecoder : public AbstractDecoder { |
80 public: |
81 public: |
94 } |
95 } |
95 |
96 |
96 virtual bool demangle(const char* symbol, char* buf, int buflen) { |
97 virtual bool demangle(const char* symbol, char* buf, int buflen) { |
97 return false; |
98 return false; |
98 } |
99 } |
99 |
|
100 }; |
100 }; |
101 |
|
102 |
101 |
103 class Decoder : AllStatic { |
102 class Decoder : AllStatic { |
104 public: |
103 public: |
105 static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL, bool demangle = true); |
104 static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL, bool demangle = true); |
106 static bool decode(address pc, char* buf, int buflen, int* offset, bool demangle) { |
105 static bool decode(address pc, char* buf, int buflen, int* offset, bool demangle) { |