Finding a Function by its Symbol

This one is from the live of a C++ programmer.
As you might remember, I am working on the CUV Library for CUDA programming in Python.
The library uses quite a lot of templates and meta-programming. Since we want to have all functionality in Python, we need to instantiate all the templates.
After some refactoring, I got the helpful error message
_cuv_python.so: undefined symbol: _ZN3cuv6detail20apply_binary_functorINS_6vectorIfNS_16dev_memory_spaceEjEES4_NS2_IhS3_jEEhEEvRT_RKT0_RKT1_RKNS_13BinaryFunctorERKiRKT2_SL_

Ah, right. That one.

Well, often it is possible to guess which function this is about. But since the instantiations are not so straight-forward, I had no idea which function that was. So I wanted to look that up somehow.

I tried to google how to find the corresponding function, but without much success. Probably I was missing the right keywords.
After some fiddling around, I finally got it:

Load your program/library in gdb.
You can get a list of all symbols in the file with
(gdb) info file
 
This is somewhat different than the output of nm, since it gives you the right addresses of the symbols. Find you symbol in the table - I used gdb's logging function for that, maybe there is an easier way.
Then a quick
(gdb) info symbol <ADDRESS>
gives you the full function declaration with all template arguments and whatnot.
That made me very happy :)

So I hope this helps some frustrated programmers who - like me - always have to search for the function they forgot to instantiate.

Comments

Popular posts from this blog

Machine Learning Cheat Sheet (for scikit-learn)

A Wordcloud in Python

MNIST for ever....

Python things you never need: Empty lambda functions