8079473: allow demangling to be optional in dll_address_to_function_name
Summary: add a demangling boolean argument to dll_address_to_function_name and decode
Reviewed-by: dholmes, simonis
--- a/hotspot/src/os/aix/vm/decoder_aix.hpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/os/aix/vm/decoder_aix.hpp Tue Jun 16 11:58:25 2015 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright 2013 SAP AG. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -38,8 +38,8 @@
virtual bool demangle(const char* symbol, char* buf, int buflen) { return false; } // demangled by getFuncName
- virtual bool decode(address addr, char* buf, int buflen, int* offset, const char* modulepath) {
- return (::getFuncName((codeptr_t)addr, buf, buflen, offset, 0, 0, 0) == 0);
+ virtual bool decode(address addr, char* buf, int buflen, int* offset, const char* modulepath, bool demangle) {
+ return (::getFuncName((codeptr_t)addr, buf, buflen, offset, 0, 0, 0, demangle) == 0);
}
virtual bool decode(address addr, char *buf, int buflen, int* offset, const void *base) {
ShouldNotReachHere();
--- a/hotspot/src/os/aix/vm/os_aix.cpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/os/aix/vm/os_aix.cpp Tue Jun 16 11:58:25 2015 +0200
@@ -1439,7 +1439,8 @@
}
bool os::dll_address_to_function_name(address addr, char *buf,
- int buflen, int *offset) {
+ int buflen, int *offset,
+ bool demangle) {
if (offset) {
*offset = -1;
}
@@ -1454,7 +1455,7 @@
}
// Go through Decoder::decode to call getFuncName which reads the name from the traceback table.
- return Decoder::decode(addr, buf, buflen, offset);
+ return Decoder::decode(addr, buf, buflen, offset, demangle);
}
static int getModuleName(codeptr_t pc, // [in] program counter
--- a/hotspot/src/os/aix/vm/porting_aix.cpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/os/aix/vm/porting_aix.cpp Tue Jun 16 11:58:25 2015 +0200
@@ -114,7 +114,8 @@
int* p_displacement, // [out] optional: displacement (-1 if not available)
const struct tbtable** p_tb, // [out] optional: ptr to traceback table to get further
// information (NULL if not available)
- char* p_errmsg, size_t errmsglen // [out] optional: user provided buffer for error messages
+ char* p_errmsg, size_t errmsglen,// [out] optional: user provided buffer for error messages
+ bool demangle // [in] whether to demangle the name
) {
struct tbtable* tb = 0;
unsigned int searchcount = 0;
@@ -216,15 +217,17 @@
p_name[0] = '\0';
// If it is a C++ name, try and demangle it using the Demangle interface (see demangle.h).
- char* rest;
- Name* const name = Demangle(buf, rest);
- if (name) {
- const char* const demangled_name = name->Text();
- if (demangled_name) {
- strncpy(p_name, demangled_name, namelen-1);
- p_name[namelen-1] = '\0';
+ if (demangle) {
+ char* rest;
+ Name* const name = Demangle(buf, rest);
+ if (name) {
+ const char* const demangled_name = name->Text();
+ if (demangled_name) {
+ strncpy(p_name, demangled_name, namelen-1);
+ p_name[namelen-1] = '\0';
+ }
+ delete name;
}
- delete name;
}
// Fallback: if demangling did not work, just provide the unmangled name.
@@ -325,7 +328,7 @@
int displacement = 0;
if (getFuncName((codeptr_t) p, funcname, sizeof(funcname), &displacement,
- NULL, NULL, 0) == 0) {
+ NULL, NULL, 0, true /* demangle */) == 0) {
if (funcname[0] != '\0') {
const char* const interned = dladdr_fixed_strings.intern(funcname);
info->dli_sname = interned;
--- a/hotspot/src/os/aix/vm/porting_aix.hpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/os/aix/vm/porting_aix.hpp Tue Jun 16 11:58:25 2015 +0200
@@ -87,7 +87,8 @@
char* p_name, size_t namelen, // [out] optional: user provided buffer for the function name
int* p_displacement, // [out] optional: displacement
const struct tbtable** p_tb, // [out] optional: ptr to traceback table to get further information
- char* p_errmsg, size_t errmsglen // [out] optional: user provided buffer for error messages
+ char* p_errmsg, size_t errmsglen,// [out] optional: user provided buffer for error messages
+ bool demangle = true // [in] whether to demangle the name
);
// -------------------------------------------------------------------------
--- a/hotspot/src/os/bsd/vm/decoder_machO.hpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/os/bsd/vm/decoder_machO.hpp Tue Jun 16 11:58:25 2015 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,7 @@
virtual bool decode(address pc, char* buf, int buflen, int* offset,
const void* base);
virtual bool decode(address pc, char* buf, int buflen, int* offset,
- const char* module_path = NULL) {
+ const char* module_path, bool demangle) {
ShouldNotReachHere();
return false;
}
--- a/hotspot/src/os/bsd/vm/os_bsd.cpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/os/bsd/vm/os_bsd.cpp Tue Jun 16 11:58:25 2015 +0200
@@ -1339,7 +1339,8 @@
#define MACH_MAXSYMLEN 256
bool os::dll_address_to_function_name(address addr, char *buf,
- int buflen, int *offset) {
+ int buflen, int *offset,
+ bool demangle) {
// buf is not optional, but offset is optional
assert(buf != NULL, "sanity check");
@@ -1349,7 +1350,7 @@
if (dladdr((void*)addr, &dlinfo) != 0) {
// see if we have a matching symbol
if (dlinfo.dli_saddr != NULL && dlinfo.dli_sname != NULL) {
- if (!Decoder::demangle(dlinfo.dli_sname, buf, buflen)) {
+ if (!(demangle && Decoder::demangle(dlinfo.dli_sname, buf, buflen))) {
jio_snprintf(buf, buflen, "%s", dlinfo.dli_sname);
}
if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr;
@@ -1358,15 +1359,16 @@
// no matching symbol so try for just file info
if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != NULL) {
if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase),
- buf, buflen, offset, dlinfo.dli_fname)) {
+ buf, buflen, offset, dlinfo.dli_fname, demangle)) {
return true;
}
}
// Handle non-dynamic manually:
if (dlinfo.dli_fbase != NULL &&
- Decoder::decode(addr, localbuf, MACH_MAXSYMLEN, offset, dlinfo.dli_fbase)) {
- if (!Decoder::demangle(localbuf, buf, buflen)) {
+ Decoder::decode(addr, localbuf, MACH_MAXSYMLEN, offset,
+ dlinfo.dli_fbase)) {
+ if (!(demangle && Decoder::demangle(localbuf, buf, buflen))) {
jio_snprintf(buf, buflen, "%s", localbuf);
}
return true;
--- a/hotspot/src/os/linux/vm/os_linux.cpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/os/linux/vm/os_linux.cpp Tue Jun 16 11:58:25 2015 +0200
@@ -1623,7 +1623,8 @@
}
bool os::dll_address_to_function_name(address addr, char *buf,
- int buflen, int *offset) {
+ int buflen, int *offset,
+ bool demangle) {
// buf is not optional, but offset is optional
assert(buf != NULL, "sanity check");
@@ -1632,7 +1633,7 @@
if (dladdr((void*)addr, &dlinfo) != 0) {
// see if we have a matching symbol
if (dlinfo.dli_saddr != NULL && dlinfo.dli_sname != NULL) {
- if (!Decoder::demangle(dlinfo.dli_sname, buf, buflen)) {
+ if (!(demangle && Decoder::demangle(dlinfo.dli_sname, buf, buflen))) {
jio_snprintf(buf, buflen, "%s", dlinfo.dli_sname);
}
if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr;
@@ -1641,7 +1642,7 @@
// no matching symbol so try for just file info
if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != NULL) {
if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase),
- buf, buflen, offset, dlinfo.dli_fname)) {
+ buf, buflen, offset, dlinfo.dli_fname, demangle)) {
return true;
}
}
--- a/hotspot/src/os/solaris/vm/os_solaris.cpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/os/solaris/vm/os_solaris.cpp Tue Jun 16 11:58:25 2015 +0200
@@ -1627,7 +1627,8 @@
static dladdr1_func_type dladdr1_func = NULL;
bool os::dll_address_to_function_name(address addr, char *buf,
- int buflen, int * offset) {
+ int buflen, int * offset,
+ bool demangle) {
// buf is not optional, but offset is optional
assert(buf != NULL, "sanity check");
@@ -1655,7 +1656,7 @@
if (dlinfo.dli_saddr != NULL &&
(char *)dlinfo.dli_saddr + info->st_size > (char *)addr) {
if (dlinfo.dli_sname != NULL) {
- if (!Decoder::demangle(dlinfo.dli_sname, buf, buflen)) {
+ if (!(demangle && Decoder::demangle(dlinfo.dli_sname, buf, buflen))) {
jio_snprintf(buf, buflen, "%s", dlinfo.dli_sname);
}
if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr;
@@ -1665,7 +1666,7 @@
// no matching symbol so try for just file info
if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != NULL) {
if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase),
- buf, buflen, offset, dlinfo.dli_fname)) {
+ buf, buflen, offset, dlinfo.dli_fname, demangle)) {
return true;
}
}
@@ -1679,7 +1680,7 @@
if (dladdr((void *)addr, &dlinfo) != 0) {
// see if we have a matching symbol
if (dlinfo.dli_saddr != NULL && dlinfo.dli_sname != NULL) {
- if (!Decoder::demangle(dlinfo.dli_sname, buf, buflen)) {
+ if (!(demangle && Decoder::demangle(dlinfo.dli_sname, buf, buflen))) {
jio_snprintf(buf, buflen, dlinfo.dli_sname);
}
if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr;
@@ -1688,7 +1689,7 @@
// no matching symbol so try for just file info
if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != NULL) {
if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase),
- buf, buflen, offset, dlinfo.dli_fname)) {
+ buf, buflen, offset, dlinfo.dli_fname, demangle)) {
return true;
}
}
--- a/hotspot/src/os/windows/vm/decoder_windows.cpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/os/windows/vm/decoder_windows.cpp Tue Jun 16 11:58:25 2015 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -162,7 +162,7 @@
// current function and comparing the result
address addr = (address)Decoder::demangle;
char buf[MAX_PATH];
- if (decode(addr, buf, sizeof(buf), NULL)) {
+ if (decode(addr, buf, sizeof(buf), NULL, NULL, true /* demangle */)) {
_can_decode_in_vm = !strcmp(buf, "Decoder::demangle");
}
}
@@ -187,7 +187,7 @@
}
-bool WindowsDecoder::decode(address addr, char *buf, int buflen, int* offset, const char* modulepath) {
+bool WindowsDecoder::decode(address addr, char *buf, int buflen, int* offset, const char* modulepath, bool demangle_name) {
if (_pfnSymGetSymFromAddr64 != NULL) {
PIMAGEHLP_SYMBOL64 pSymbol;
char symbolInfo[MAX_PATH + sizeof(IMAGEHLP_SYMBOL64)];
@@ -197,7 +197,7 @@
DWORD64 displacement;
if (_pfnSymGetSymFromAddr64(::GetCurrentProcess(), (DWORD64)addr, &displacement, pSymbol)) {
if (buf != NULL) {
- if (demangle(pSymbol->Name, buf, buflen)) {
+ if (!(demangle_name && demangle(pSymbol->Name, buf, buflen))) {
jio_snprintf(buf, buflen, "%s", pSymbol->Name);
}
}
--- a/hotspot/src/os/windows/vm/decoder_windows.hpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/os/windows/vm/decoder_windows.hpp Tue Jun 16 11:58:25 2015 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -60,7 +60,7 @@
bool can_decode_C_frame_in_vm() const;
bool demangle(const char* symbol, char *buf, int buflen);
- bool decode(address addr, char *buf, int buflen, int* offset, const char* modulepath = NULL);
+ bool decode(address addr, char *buf, int buflen, int* offset, const char* modulepath, bool demangle);
bool decode(address addr, char *buf, int buflen, int* offset, const void* base) {
ShouldNotReachHere();
return false;
--- a/hotspot/src/os/windows/vm/os_windows.cpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/os/windows/vm/os_windows.cpp Tue Jun 16 11:58:25 2015 +0200
@@ -1369,11 +1369,12 @@
}
bool os::dll_address_to_function_name(address addr, char *buf,
- int buflen, int *offset) {
+ int buflen, int *offset,
+ bool demangle) {
// buf is not optional, but offset is optional
assert(buf != NULL, "sanity check");
- if (Decoder::decode(addr, buf, buflen, offset)) {
+ if (Decoder::decode(addr, buf, buflen, offset, demangle)) {
return true;
}
if (offset != NULL) *offset = -1;
--- a/hotspot/src/share/vm/runtime/os.hpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/share/vm/runtime/os.hpp Tue Jun 16 11:58:25 2015 +0200
@@ -539,7 +539,8 @@
// If function name is not found, buf[0] is set to '\0' and offset is
// set to -1 (if offset is non-NULL).
static bool dll_address_to_function_name(address addr, char* buf,
- int buflen, int* offset);
+ int buflen, int* offset,
+ bool demangle = true);
// Locate DLL/DSO. On success, full path of the library is copied to
// buf, and offset is optionally set to be the distance between addr
--- a/hotspot/src/share/vm/utilities/decoder.cpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/share/vm/utilities/decoder.cpp Tue Jun 16 11:58:25 2015 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -102,7 +102,7 @@
return _shared_decoder_lock;
}
-bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath) {
+bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath, bool demangle) {
assert(_shared_decoder_lock != NULL, "Just check");
bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
@@ -110,7 +110,7 @@
get_error_handler_instance(): get_shared_instance();
assert(decoder != NULL, "null decoder");
- return decoder->decode(addr, buf, buflen, offset, modulepath);
+ return decoder->decode(addr, buf, buflen, offset, modulepath, demangle);
}
bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) {
--- a/hotspot/src/share/vm/utilities/decoder.hpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/share/vm/utilities/decoder.hpp Tue Jun 16 11:58:25 2015 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -46,8 +46,12 @@
// decode an pc address to corresponding function name and an offset from the beginning of
// the function
+ //
+ // Note: the 'base' variant does not demangle names. The
+ // demangling that was done systematically in the 'modulepath' variant
+ // is now optional.
virtual bool decode(address pc, char* buf, int buflen, int* offset,
- const char* modulepath = NULL) = 0;
+ const char* modulepath = NULL, bool demangle = true) = 0;
virtual bool decode(address pc, char* buf, int buflen, int* offset, const void* base) = 0;
// demangle a C++ symbol
@@ -81,7 +85,7 @@
~NullDecoder() {};
virtual bool decode(address pc, char* buf, int buflen, int* offset,
- const char* modulepath = NULL) {
+ const char* modulepath, bool demangle) {
return false;
}
@@ -101,7 +105,10 @@
class Decoder : AllStatic {
public:
- static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL);
+ static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL, bool demangle = true);
+ static bool decode(address pc, char* buf, int buflen, int* offset, bool demangle) {
+ return decode(pc, buf, buflen, offset, (const char*) NULL, demangle);
+ }
static bool decode(address pc, char* buf, int buflen, int* offset, const void* base);
static bool demangle(const char* symbol, char* buf, int buflen);
static bool can_decode_C_frame_in_vm();
--- a/hotspot/src/share/vm/utilities/decoder_elf.cpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/share/vm/utilities/decoder_elf.cpp Tue Jun 16 11:58:25 2015 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -34,7 +34,7 @@
}
}
-bool ElfDecoder::decode(address addr, char *buf, int buflen, int* offset, const char* filepath) {
+bool ElfDecoder::decode(address addr, char *buf, int buflen, int* offset, const char* filepath, bool demangle_name) {
assert(filepath, "null file path");
assert(buf != NULL && buflen > 0, "Invalid buffer");
if (has_error()) return false;
@@ -46,7 +46,7 @@
if (!file->decode(addr, buf, buflen, offset)) {
return false;
}
- if (buf[0] != '\0') {
+ if (demangle_name && (buf[0] != '\0')) {
demangle(buf, buf, buflen);
}
return true;
--- a/hotspot/src/share/vm/utilities/decoder_elf.hpp Mon Jun 15 14:33:51 2015 -0700
+++ b/hotspot/src/share/vm/utilities/decoder_elf.hpp Tue Jun 16 11:58:25 2015 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,7 @@
bool can_decode_C_frame_in_vm() const { return true; }
bool demangle(const char* symbol, char *buf, int buflen);
- bool decode(address addr, char *buf, int buflen, int* offset, const char* filepath = NULL);
+ bool decode(address addr, char *buf, int buflen, int* offset, const char* filepath, bool demangle);
bool decode(address addr, char *buf, int buflen, int* offset, const void *base) {
ShouldNotReachHere();
return false;