How to view anonymous namespace variables' values in debugger?
-
Does anyone know hoew to do this? namespace { int anon; } void func() { // breakpoint on some code in here, // try to examine anon's value } I've tried typing in all kinds of things in the watch window, including `anonymous namespace'::anon (same prefix as anonymous namespace functions in the call stack). I've looked through msdn, searched google, tried to unmangle the name using a map, used windbg, but to no avail. If anyone knows the answer to this, please let me know. Thanks, Tim
-
Does anyone know hoew to do this? namespace { int anon; } void func() { // breakpoint on some code in here, // try to examine anon's value } I've tried typing in all kinds of things in the watch window, including `anonymous namespace'::anon (same prefix as anonymous namespace functions in the call stack). I've looked through msdn, searched google, tried to unmangle the name using a map, used windbg, but to no avail. If anyone knows the answer to this, please let me know. Thanks, Tim
Assuming that func can see the value, try setting a local variable to equal anon inside func, and then view it's value. I doubt you can see into the namespace directly, if 'anon' does not work. I would have expected it to, if the namespace is in scope where you are looking. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
-
Assuming that func can see the value, try setting a local variable to equal anon inside func, and then view it's value. I doubt you can see into the namespace directly, if 'anon' does not work. I would have expected it to, if the namespace is in scope where you are looking. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
I've done that before, but it's a real drag to have to do everywhere I'd like to look at a variable's value. Since the debugger can examine _all_ of the symbols in a module, it ought to be able to "see" anonymous variables. WinDbg can see it, but only by wildcarding everything.
-
I've done that before, but it's a real drag to have to do everywhere I'd like to look at a variable's value. Since the debugger can examine _all_ of the symbols in a module, it ought to be able to "see" anonymous variables. WinDbg can see it, but only by wildcarding everything.
I agree - your example is obviously contrived to show the problem and the real code is probably more painful than that to do this to. I don't know what the solution is, and if you find one, I'd love to hear it. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
-
Does anyone know hoew to do this? namespace { int anon; } void func() { // breakpoint on some code in here, // try to examine anon's value } I've tried typing in all kinds of things in the watch window, including `anonymous namespace'::anon (same prefix as anonymous namespace functions in the call stack). I've looked through msdn, searched google, tried to unmangle the name using a map, used windbg, but to no avail. If anyone knows the answer to this, please let me know. Thanks, Tim
Hi Tim, While I have not used this with variables in anonymous namespaces, you should be able to setup a watch variable by using the address of the variable. If you setup a breakpoint at a place that uses the variable, you can open the Disassembly window and find the address of the variable. I tried a sample program which did "cout << anon << endl;", and the disassembly showed: mov eax,['anonymous namespace'::anon (00476dc0)] The 00476dc0 is the address of the anon variable for my program. When you run this, it most likely will be a different address. Once you have the address of the variable, you can setup a watch for it as follows: * (int *) 0x476dc0 Substitute the address that you get for the 0x476dc0. This tells the debugger to treat the address as a pointer to int, and then dereferences it. If you want, you can use: (int *) 0x476dc0 You then get a plus sign which you need to expand to get to the value. For a single value, this isn't useful, but if you have an array, it can be very useful. For instance, if you had the following: namespace { int array[5] = {5,4,3,2,1}; } Once you find the address of the array in the debugger, you can display the array in a watch window as follows: ((int *) 0x476dc0),5 Again, replace address with the one found in the debugger. This will put a + next to the expression which will expand to 5 elements when clicked. Best regards, John
-
Hi Tim, While I have not used this with variables in anonymous namespaces, you should be able to setup a watch variable by using the address of the variable. If you setup a breakpoint at a place that uses the variable, you can open the Disassembly window and find the address of the variable. I tried a sample program which did "cout << anon << endl;", and the disassembly showed: mov eax,['anonymous namespace'::anon (00476dc0)] The 00476dc0 is the address of the anon variable for my program. When you run this, it most likely will be a different address. Once you have the address of the variable, you can setup a watch for it as follows: * (int *) 0x476dc0 Substitute the address that you get for the 0x476dc0. This tells the debugger to treat the address as a pointer to int, and then dereferences it. If you want, you can use: (int *) 0x476dc0 You then get a plus sign which you need to expand to get to the value. For a single value, this isn't useful, but if you have an array, it can be very useful. For instance, if you had the following: namespace { int array[5] = {5,4,3,2,1}; } Once you find the address of the array in the debugger, you can display the array in a watch window as follows: ((int *) 0x476dc0),5 Again, replace address with the one found in the debugger. This will put a + next to the expression which will expand to 5 elements when clicked. Best regards, John
-
Does anyone know hoew to do this? namespace { int anon; } void func() { // breakpoint on some code in here, // try to examine anon's value } I've tried typing in all kinds of things in the watch window, including `anonymous namespace'::anon (same prefix as anonymous namespace functions in the call stack). I've looked through msdn, searched google, tried to unmangle the name using a map, used windbg, but to no avail. If anyone knows the answer to this, please let me know. Thanks, Tim
In WinDBG:
>dt myapp!*anon
You will see somethin like that:
>myapp!?A0x423ba21e::anon
For search address for global variable, you should type:
x myapp!*anon*
You will see:
016255aa myapp!?A0x423ba21e::anon = [address]
Next, type:
>dt myapp!?A0x423ba21e::anon [address]
Note: anon will optimized in release build
-
In WinDBG:
>dt myapp!*anon
You will see somethin like that:
>myapp!?A0x423ba21e::anon
For search address for global variable, you should type:
x myapp!*anon*
You will see:
016255aa myapp!?A0x423ba21e::anon = [address]
Next, type:
>dt myapp!?A0x423ba21e::anon [address]
Note: anon will optimized in release build
Well done - you're only 14 years late! :doh: How long did it take you to read 7712 pages of this forum?
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Well done - you're only 14 years late! :doh: How long did it take you to read 7712 pages of this forum?
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer