1 /*
2 * Copyright (c) 2012, 2013 SAP SE. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "asm/assembler.hpp"
26 #include "compiler/disassembler.hpp"
27 #include "loadlib_aix.hpp"
28 #include "memory/allocation.hpp"
29 #include "memory/allocation.inline.hpp"
30 #include "misc_aix.hpp"
31 #include "porting_aix.hpp"
32 #include "runtime/os.hpp"
33 #include "runtime/thread.hpp"
34 #include "utilities/align.hpp"
35 #include "utilities/debug.hpp"
36
37 #include <demangle.h>
38 #include <sys/debug.h>
39 #include <pthread.h>
40 #include <ucontext.h>
41
42 //////////////////////////////////
43 // Provide implementation for dladdr based on LoadedLibraries pool and
44 // traceback table scan
45
46 // Search traceback table in stack,
47 // return procedure name from trace back table.
48 #define MAX_FUNC_SEARCH_LEN 0x10000
49
50 #define PTRDIFF_BYTES(p1,p2) (((ptrdiff_t)p1) - ((ptrdiff_t)p2))
51
52 // Typedefs for stackslots, stack pointers, pointers to op codes.
53 typedef unsigned long stackslot_t;
54 typedef stackslot_t* stackptr_t;
55 typedef unsigned int* codeptr_t;
56
57 // Unfortunately, the interface of dladdr makes the implementator
220 pc2 += (*pc2) + 1; // don't care
221
222 CHECK_POINTER_READABLE(pc2)
223
224 //
225 // return function name if it exists.
226 //
227 if (p_name && namelen > 0) {
228 if (tb->tb.name_present) {
229 // Copy name from text because it may not be zero terminated.
230 const short l = MIN2<short>(*((short*)pc2), namelen - 1);
231 // Be very careful.
232 int i = 0; char* const p = (char*)pc2 + sizeof(short);
233 while (i < l && os::is_readable_pointer(p + i)) {
234 p_name[i] = p[i];
235 i++;
236 }
237 p_name[i] = '\0';
238
239 // If it is a C++ name, try and demangle it using the Demangle interface (see demangle.h).
240 if (demangle) {
241 char* rest;
242 Name* const name = Demangle(p_name, rest);
243 if (name) {
244 const char* const demangled_name = name->Text();
245 if (demangled_name) {
246 strncpy(p_name, demangled_name, namelen-1);
247 p_name[namelen-1] = '\0';
248 }
249 delete name;
250 }
251 }
252 } else {
253 strncpy(p_name, "<nameless function>", namelen-1);
254 p_name[namelen-1] = '\0';
255 }
256 }
257
258 // Return traceback table, if user wants it.
259 if (p_tb) {
260 (*p_tb) = tb;
261 }
262
263 return true;
264
265 }
266
267 bool AixSymbols::get_module_name(address pc,
268 char* p_name, size_t namelen) {
269
270 if (p_name && namelen > 0) {
271 p_name[0] = '\0';
|
1 /*
2 * Copyright (c) 2012, 2019 SAP SE. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "asm/assembler.hpp"
26 #include "compiler/disassembler.hpp"
27 #include "loadlib_aix.hpp"
28 #include "memory/allocation.hpp"
29 #include "memory/allocation.inline.hpp"
30 #include "misc_aix.hpp"
31 #include "porting_aix.hpp"
32 #include "runtime/os.hpp"
33 #include "runtime/thread.hpp"
34 #include "utilities/align.hpp"
35 #include "utilities/debug.hpp"
36
37 // distinguish old xlc and xlclang++, where
38 // <ibmdemangle.h> is suggested but not found in GA release (might come with a fix)
39 #if defined(__clang__)
40 #define DISABLE_DEMANGLE
41 // #include <ibmdemangle.h>
42 #else
43 #include <demangle.h>
44 #endif
45
46 #include <sys/debug.h>
47 #include <pthread.h>
48 #include <ucontext.h>
49
50 //////////////////////////////////
51 // Provide implementation for dladdr based on LoadedLibraries pool and
52 // traceback table scan
53
54 // Search traceback table in stack,
55 // return procedure name from trace back table.
56 #define MAX_FUNC_SEARCH_LEN 0x10000
57
58 #define PTRDIFF_BYTES(p1,p2) (((ptrdiff_t)p1) - ((ptrdiff_t)p2))
59
60 // Typedefs for stackslots, stack pointers, pointers to op codes.
61 typedef unsigned long stackslot_t;
62 typedef stackslot_t* stackptr_t;
63 typedef unsigned int* codeptr_t;
64
65 // Unfortunately, the interface of dladdr makes the implementator
228 pc2 += (*pc2) + 1; // don't care
229
230 CHECK_POINTER_READABLE(pc2)
231
232 //
233 // return function name if it exists.
234 //
235 if (p_name && namelen > 0) {
236 if (tb->tb.name_present) {
237 // Copy name from text because it may not be zero terminated.
238 const short l = MIN2<short>(*((short*)pc2), namelen - 1);
239 // Be very careful.
240 int i = 0; char* const p = (char*)pc2 + sizeof(short);
241 while (i < l && os::is_readable_pointer(p + i)) {
242 p_name[i] = p[i];
243 i++;
244 }
245 p_name[i] = '\0';
246
247 // If it is a C++ name, try and demangle it using the Demangle interface (see demangle.h).
248 #ifndef DISABLE_DEMANGLE
249 if (demangle) {
250 char* rest;
251 Name* const name = Demangle(p_name, rest);
252 if (name) {
253 const char* const demangled_name = name->Text();
254 if (demangled_name) {
255 strncpy(p_name, demangled_name, namelen-1);
256 p_name[namelen-1] = '\0';
257 }
258 delete name;
259 }
260 }
261 #endif
262 } else {
263 strncpy(p_name, "<nameless function>", namelen-1);
264 p_name[namelen-1] = '\0';
265 }
266 }
267
268 // Return traceback table, if user wants it.
269 if (p_tb) {
270 (*p_tb) = tb;
271 }
272
273 return true;
274
275 }
276
277 bool AixSymbols::get_module_name(address pc,
278 char* p_name, size_t namelen) {
279
280 if (p_name && namelen > 0) {
281 p_name[0] = '\0';
|