8306672: support offset in dll_address_to_library_name on AIX

Reviewed-by: stuefe, clanger, mbaesken
This commit is contained in:
JoKern65 2023-04-28 13:07:53 +00:00 committed by Matthias Baesken
parent 83a98c66f1
commit 5d9baa2f93
3 changed files with 40 additions and 4 deletions

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021 SAP SE. All rights reserved.
* Copyright (c) 2012, 2023 SAP SE. 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
@ -1077,7 +1077,17 @@ bool os::dll_address_to_library_name(address addr, char* buf,
return false;
}
return AixSymbols::get_module_name(addr, buf, buflen);
address base = nullptr;
if (!AixSymbols::get_module_name_and_base(addr, buf, buflen, &base)
|| base == nullptr) {
return false;
}
assert(addr >= base && addr <= base + INT_MAX, "address not in library text range");
if (offset != nullptr) {
*offset = addr - base;
}
return true;
}
// Loads .dll/.so and in case of error it checks if .dll/.so was built

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2019 SAP SE. All rights reserved.
* Copyright (c) 2012, 2023 SAP SE. 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
@ -278,6 +278,24 @@ bool AixSymbols::get_module_name(address pc,
return false;
}
bool AixSymbols::get_module_name_and_base(address pc,
char* p_name, size_t namelen,
address* p_base) {
if (p_base && p_name && namelen > 0) {
p_name[0] = '\0';
loaded_module_t lm;
if (LoadedLibraries::find_for_text_address(pc, &lm)) {
strncpy(p_name, lm.shortname, namelen);
p_name[namelen - 1] = '\0';
*p_base = (address) lm.text;
return true;
}
}
return false;
}
// Special implementation of dladdr for Aix based on LoadedLibraries
// Note: dladdr returns non-zero for ok, 0 for error!
// Note: dladdr is not posix, but a non-standard GNU extension. So this tries to

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2015 SAP SE. All rights reserved.
* Copyright (c) 2012, 2023 SAP SE. 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
@ -83,6 +83,14 @@ class AixSymbols {
char* p_name, size_t namelen // [out] module name
);
// Given a program counter, returns the name of the module (library and module) the pc points to
// and the base address of the module the pc points to
static bool get_module_name_and_base (
address pc, // [in] program counter
char* p_name, size_t namelen, // [out] module name
address* p_base // [out] base address of library
);
};
class AixNativeCallstack {