8079473: allow demangling to be optional in dll_address_to_function_name
Add a demangling boolean argument to dll_address_to_function_name and decode Reviewed-by: dholmes, simonis
This commit is contained in:
parent
e720ad23ac
commit
a6a13b5344
@ -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 @@ class AIXDecoder: public AbstractDecoder {
|
||||
|
||||
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();
|
||||
|
@ -1439,7 +1439,8 @@ static address resolve_function_descriptor_to_code_pointer(address p) {
|
||||
}
|
||||
|
||||
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 @@ bool os::dll_address_to_function_name(address addr, char *buf,
|
||||
}
|
||||
|
||||
// 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
|
||||
|
@ -114,7 +114,8 @@ extern "C" int getFuncName(
|
||||
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 @@ extern "C" int getFuncName(
|
||||
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 dladdr(void* addr, Dl_info* info) {
|
||||
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;
|
||||
|
@ -87,7 +87,8 @@ int getFuncName(
|
||||
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
|
||||
);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
@ -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 @@ class MachODecoder : public AbstractDecoder {
|
||||
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;
|
||||
}
|
||||
|
@ -1339,7 +1339,8 @@ bool os::address_is_in_vm(address addr) {
|
||||
#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 @@ bool os::dll_address_to_function_name(address addr, char *buf,
|
||||
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 @@ bool os::dll_address_to_function_name(address addr, char *buf,
|
||||
// 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;
|
||||
|
@ -1623,7 +1623,8 @@ bool os::address_is_in_vm(address addr) {
|
||||
}
|
||||
|
||||
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 @@ bool os::dll_address_to_function_name(address addr, char *buf,
|
||||
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 @@ bool os::dll_address_to_function_name(address addr, char *buf,
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@ -1627,7 +1627,8 @@ typedef int (*dladdr1_func_type)(void *, Dl_info *, void **, int);
|
||||
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 @@ bool os::dll_address_to_function_name(address addr, char *buf,
|
||||
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 @@ bool os::dll_address_to_function_name(address addr, char *buf,
|
||||
// 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 @@ bool os::dll_address_to_function_name(address addr, char *buf,
|
||||
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 @@ bool os::dll_address_to_function_name(address addr, char *buf,
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@ -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 @@ void WindowsDecoder::initialize() {
|
||||
// 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::can_decode_C_frame_in_vm() const {
|
||||
}
|
||||
|
||||
|
||||
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 @@ bool WindowsDecoder::decode(address addr, char *buf, int buflen, int* offset, co
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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 @@ public:
|
||||
|
||||
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;
|
||||
|
@ -1369,11 +1369,12 @@ bool os::dll_address_to_library_name(address addr, char* buf,
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -539,7 +539,8 @@ class os: AllStatic {
|
||||
// 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
|
||||
|
@ -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 @@ Mutex* Decoder::shared_decoder_lock() {
|
||||
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 @@ bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const cha
|
||||
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) {
|
||||
|
@ -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 @@ public:
|
||||
|
||||
// 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 @@ public:
|
||||
~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 @@ public:
|
||||
|
||||
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();
|
||||
|
@ -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 @@ ElfDecoder::~ElfDecoder() {
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ bool ElfDecoder::decode(address addr, char *buf, int buflen, int* offset, const
|
||||
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;
|
||||
|
@ -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 @@ public:
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user