I am currently fiddling around with some c libraries without documentation. I am wondering if it is at all possible to retrieve more metadata, such as parameters and return values, outside of what is provided by calling nm -D
or objdump -T filename | grep text
. I'm not sure if this is possible, but if it is, it saves me from hunting down whoever was in charge of the library!
Edit: I'd like to be able to do this without reading machine code if possible. It appears that there are some solutions that allow me to do so easily if I was an expert at machine code, but since I am not and do not have the current desire to jump down that rabbit hole, I'm really hoping there is another way.
Best Answer
A very similar question was asked on Stack Overflow: How to extract function prototype from an ELF file?
In short: generally you can't. If the executable (or shared library) doesn't have debug information, the information on the number and type of arguments is not stored in the executable.
If the shared object file does have debug information, then you should be able to extract the information with
readelf -wi
, or by using a debugger.For example, I've got an ELF executable that contains a function
int foo(char a, long b)
, compiled with debug info. GDB tells me:And
readelf -wi
(a bit cryptic, you'll have to match up the entries yourself) has:Note that for C++, the symbols you see with
nm
carry more information (unless they've been declaredextern "C"
- the number and type of parameters must be available to the linker to handle overloading. But the return type information isn't there either. (But the symbols are mangled -c++filt
can be used to demangle.)Compiling the same source file as C++ gives the following output for
nm a.out | c++filt
: