During debugging in lldb I can get the address of global function without any problems. For instance, I have the following code:
#include <iostream>
void globalDoWork()
{
std::cout << "Global do work call\n";
}
struct Dummy
{
static void doWork()
{
std::cout << "Do work call\n";
}
};
int main(int argc, char* argv[])
{
globalDoWork();
Dummy::doWork();
std::cout << "global: " << (void*)&(globalDoWork) << "\n";
std::cout << "static: " << (void*)&(Dummy::doWork) << "\n";
return 0;
}
After build executable I run this program under lldb:
Process 10759 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
frame #0: 0x00000001000011a7 ex43`main(argc=1, argv=0x00007ffeefbff8f0) at ex43.cpp:21:15
18 globalDoWork();
19 Dummy::doWork();
20
-> 21 std::cout << "global: " << (void*)&(globalDoWork) << "\n";
22 std::cout << "static: " << (void*)&(Dummy::doWork) << "\n";
23
24 return 0;
Target 0: (ex43) stopped.
(lldb) p globalDoWork
(void (*)()) $0 = 0x0000000100001100 (ex43`globalDoWork() at ex43.cpp:4)
(lldb) next
global: 0x100001100
And get the address, but I can not the same action with class static member function:
static: 0x100001220
Process 10765 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
frame #0: 0x0000000100001208 ex43`main(argc=1, argv=0x00007ffeefbff8f0) at ex43.cpp:24:5
21 std::cout << "global: " << (void*)&(globalDoWork) << "\n";
22 std::cout << "static: " << (void*)&(Dummy::doWork) << "\n";
23
-> 24 return 0;
25 }
Target 0: (ex43) stopped.
(lldb) p Dummy::doWork
error: supposed to interpret, but failed: Interpreter couldn't resolve a value during execution
(lldb) p (void*)&(Dummy::doWork)
error: supposed to interpret, but failed: Interpreter couldn't resolve a value during execution
What's the problem? How I can do it?
Interesting. Calling the function works:
(lldb) expr Dummy::doWork()
Do work call
But we aren't getting the value of the static method as a function pointer out correctly. Please file a bug about this with http://bugs.llvm.org.
Note, lldb does have simpler ways of finding the address of a symbol, if that's all you wanted to do. That's the job of the image lookup
command:
(lldb) image lookup -n Dummy::doWork
1 match found in /tmp/dowork:
Address: dowork[0x0000000100001100] (dowork.__TEXT.__text + 304)
Summary: dowork`Dummy::doWork() at dowork.cpp:11