I am implementing some limited remote debugging functionality for an application written in C running on a Linux box. The goal is to communicate with the application and lookup the value of an arbitrary variable or run an arbitrary function.
I am able to lookup symbols through dlsym()
calls, but I am unable to determine if the address returned refers to a function or a variable. Is there a way to determine typing information via this symbol table?
First, provide a fallback dummy function in a separate namespace. Then determine the return type of the function-call, inside a template parameter. According to the return-type, determine if this is the fallback function or the wanted function.
A symbolic variable is a string of characters that you define as a symbol. Because the variable is a symbol, you can assign different values to it at different times.
Variable is basically nothing but the name of a memory location that we use for storing data. We can change the value of a variable in C or any other language, and we can also reuse it multiple times.
On on x86 platforms, you can check for the instructions used to set up the stack for a function if you can look into it's address space. It is typically:
push ebp
mov ebp, esp
I'm not positive about x64 platforms, however I think it is similar:
push rbp
mov rbp, rsp
This describes the C calling convention
Keep in mind however, compiler optimizations may optimize out these instructions. If you want this to work, you may have to add a flag to disable this optimization. I believe for GCC, -fno-omit-frame-pointer will do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With