Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

invisible namespace using idb

wangchu_ustc
Beginner
458 Views
Hi, I am a new user and I could not figure out this simple problem. Hopefully someone can help me with a quick answer:

In the debugger, how do I print out variables embedded in another namespace included with 'using' directive. For example,

#################################################

double z = 3.1215;

namespace aa {
int x = -1;
}

int main() {
using namespace aa;
int y = 0;
y = y + x + z;
std::cout << "Hello, y is " << y << std::endl;
return y;
}
#################################################

In the debugger, I could print out the local variable y, the global variable z, but not the embeded variable x in the namespace aa

(idb) print y
0
(idb) print ::z
3.1215000000000002
(idb) print aa::x
Symbol "aa" is not defined.
No class or namespace visible for aa

I also tried ::aa::x, "test.cpp"`aa`x, but none of them works. Am I doing something stupid?

BTW, I am using Linux Application Debugger for 32-bit applications, Version 8.1-7, Build 20050128.
0 Kudos
4 Replies
Intel_C_Intel
Employee
458 Views
Hi, please rest assured that you're not do anything stupid. This appears to be missing or broken support for C++ namespaces.
I'll look into this further and then get back to you here with an explanation (and a workaround if at all possible).
Thanks,
-- Gordon
0 Kudos
Intel_C_Intel
Employee
458 Views
As it turns out, the Intel Compilers do not yet produce detailed debug information for namespaces. This is something that's currently planned for a future release.
The Intel Debugger does contain partial support for this though. Currently, if you compile with g++ 3.2 or later, you can ask IDB to "print aa::x" and get what you expect.
What's yet to be provided is support for namespace "using" declarations, whereby "x" would be visible without having to specify the "aa::" prefix.
Once the debug information is available for this, it's likely that IDB will be enhanced to take good advantage of it.
I hope that helps. Please let me know if there's something more you need at this time.
Thanks again,
-- G
0 Kudos
wangchu_ustc
Beginner
458 Views
Hi, thanks for looking into this.

I tried what you suggested: use a gcc compiler
(gcc version 3.4.3 20041212 (Red Hat 3.4.3-9.EL4) )to compile the source code test.cpp and read ./a.out with idb. However, I still could not get it work and it is the same error message.

g++ -gdwarf-2 test.cpp
idb a.out

(idb) print aa::x
No symbol "aa" in current context.
No class or namespace visible for aa
cannot evaluate aa::x

Can you reproduce it on your system? Is there any additional flags I should add for compiling in order to provide detailed info on namespace?

Chu
0 Kudos
Intel_C_Intel
Employee
458 Views
Chu,
I just tried this with g++ 3.4.3 and got the same as you.
I did notice that:
(idb) whatis aa
namespace aa
(idb) whereis "^x$"
"test.cpp"`aa::x
(idb) p aa::x
Evaluating 'aa::x' failed!
So, when idb searches it's internal symbol table, it sees the entry; but it's unable to resolve the reference from a standard expression. That's broken. I'll file an internal problem report on your behalf.
BTW, I also tried it with gdb and that seemed to work fine.
Thanks,
-- G
0 Kudos
Reply