One of my most troublesome bits of code has been to resolve numeric memory locations into useful descriptions of the code that lived there. Many of my tools squirt thousands of these memory locations from the device to the debugger, and I later present them to the programmer. They’re useless if I can’t convert from the memory location to something the programmer can understand: the function name and source code location.
| Before |
68363625 |
| After |
CMyObject::MyFunc c:\TestExe\TestExe.cpp Line 345 |
(Even a non-programmer can see that the “after” results are likely to be more useful for any techie.)
In the autumn I tried, in vain, for weeks to find a “nice” way to perform this conversion. I tried dozens of potential methods in increasing desperation. Each branch on this tree is something I tried, or a reason why it didn’t work:

The last method I tried – and the one which worked – was a Microsoft library. It’s called dbghelp.dll, and performed this conversion. But it had some problems:
- It’s slow
- It has to load big databases of symbol information, using lots of memory
- It’s hard to use from Java tools like those I’m developing
- It could conflict with Carbide’s own debugger
- It would only work on the Symbian OS emulator, running under Windows
Because of that, the code was complex and I didn’t properly trust it.
Nokia came to my rescue.
At the pluginfest back in January, Ken Ryall from Nokia offered to make an API available within Carbide to perform this conversion on my behalf. (API = application programming interface, essentially a means to provide access to somebody else’s code). The theory being that Nokia’s debugger code already has routines to perform this conversion – it’s just that independent plug-in developers like myself didn’t have access to it.
Well, in the past couple of Carbide beta releases, he’s done it. And it works. I expect I owe him (or somebody) a few beers, but other than that, Nokia have just done it out of the goodness of their hearts, and because they want to encourage third-party plug-in developers like Macrobug.
Thanks Nokia, and Ken specifically!
Now, for the techies, here’s how to use it:
ICDITarget cdit = ((CDebugTarget)dt).getCDITarget();
if (cdit instanceof ICDIAddressToSource) {
IMappedSourceLocation loc;
try {
loc = ((ICDIAddressToSource)cdit).getSourceForAddress(address);
} catch (CDIException e) {
throw new SymbolResolutionException(e);
}
}
The resulting ‘loc’ contains everything you need.
Ken is contributing this as a standard part of Eclipse CDT, so it should even be available outside Carbide.c++. Woohoo!