Hi,
I’m trying to backtrace a function call in my software, libbacktrace
seems to be the qnx tool to do that. It’s not possible to simply link backtrace with -lbacktrace
as for some reason it does not get found. I’m not sure what the issue is here, I’ve decided to move forward and link libbacktrace
dynamically with dlopen
.
The library does get found and open by dlopen
, the function pointers get assigned as well, however when trying to call them bt_init_accessor_ptr(&acc, BT_SELF)
an error Invalid argumnts
is thrown. I’m really not sure whats going on. All the code is as below:
#include <backtrace.h>
typedef int (*bt_init_accessor_t)(bt_accessor_t *acc, bt_acc_type_t type);
typedef int (*bt_get_backtrace_t)(bt_accessor_t *acc, bt_addr_t *addrs, int len);
void report_vm_error(const char* file, int line, const char* error_msg, const char* detail_fmt, ...)
{
void* backtrace_handle = dlopen("/data/home/root/jdk/lib/libbacktrace.so", RTLD_NOW | RTLD_GLOBAL);
do
{
if (backtrace_handle == NULL)
{
fprintf(stderr, "report_vm_error::dlopen error: %s\n", dlerror());
break;
}
fprintf(stdout, "report_vm_error::dlopen successful!\n");
dlerror(); // clear errorrs
bt_init_accessor_t bt_init_accessor_ptr = (bt_init_accessor_t)dlsym(backtrace_handle, "bt_init_accessor");
char *err = dlerror();
if (err) {
printf("Could not resolve symbol bt_init_accessor: %s\n", err);
break;
}
dlerror(); // clear errorrs
bt_get_backtrace_t bt_get_backtrace_ptr = (bt_get_backtrace_t)dlsym(backtrace_handle, "bt_get_backtrace");
err = dlerror();
if (err) {
printf("Could not resolve symbol bt_get_backtrace: %s\n", err);
break;
}
bt_accessor_t acc;
if (bt_init_accessor_ptr(&acc, BT_SELF) == -1)
{
fprintf( stderr, "%s:%i %s (%i)%s\n", __FUNCTION__, __LINE__,
"bt_init_accessor", errno, os::strerror(errno));
break;
}
break;
}
while (true);
}
bt_init_accessor
is a function with a variable number of parameters, however only the two first are required when specyfing the flag BT_SELF
. The target system is aarch64le. The function output is as below:
report_vm_error::dlopen successful!
report_vm_error:216 bt_init_accessor (22)Invalid argument
Thanks for all the help!