You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to show arguments for functions inside a dynamically loaded libraries using
dlopen?
How to Reproduce
libexample.c
#include<stdio.h>voidsay_hello(intx) {
printf("Hello from the shared library! x = %d\n", x);
}
main.c
#include<stdio.h>#include<dlfcn.h>voidsay_hello_no_dlopen(intx){
printf("Hello, World! x = %d\n", x);
printf("This function is not a dynamically loaded function\n\n");
}
intmain() {
inty=333;
say_hello_no_dlopen(y);
// Load the shared libraryvoid*handle=dlopen("./libexample.so", RTLD_LAZY);
if (!handle) {
fprintf(stderr, "Error: %s\n", dlerror());
return1;
}
// Clear any existing errordlerror();
// Get the function pointervoid (*say_hello)(int) = (void (*)(int))dlsym(handle, "say_hello");
constchar*error=dlerror();
if (error) {
fprintf(stderr, "Error: %s\n", error);
dlclose(handle);
return1;
}
// Call the functionsay_hello(777);
// Close the shared librarydlclose(handle);
return0;
}
Hello, World! x = 333
This function is not a dynamically loaded function
Hello from the shared library! x = 777
Uftrace:
uftrace -a ./main
Results:
As you can see,
the function named 'say_hello_no_dlopen()' prints the argument (of int 333) just fine,
while the dlopened function say_hello prints no argument.
Do you know how to fix this issue?
The text was updated successfully, but these errors were encountered:
Is there a way to show arguments for functions inside a dynamically loaded libraries using
dlopen?
How to Reproduce
libexample.c
main.c
Compile and Run:
Results:
Uftrace:
Results:
As you can see,
the function named 'say_hello_no_dlopen()' prints the argument (of int 333) just fine,
while the dlopened function say_hello prints no argument.
Do you know how to fix this issue?
The text was updated successfully, but these errors were encountered: