Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to view anonymous namespace variables' values in debugger?

How to view anonymous namespace variables' values in debugger?

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingdata-structurestutorialquestion
9 Posts 5 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tim Finer
    wrote on last edited by
    #1

    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

    C J D 3 Replies Last reply
    0
    • T Tim Finer

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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

      T 1 Reply Last reply
      0
      • C Christian Graus

        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

        T Offline
        T Offline
        Tim Finer
        wrote on last edited by
        #3

        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.

        C 1 Reply Last reply
        0
        • T Tim Finer

          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.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • T Tim Finer

            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

            J Offline
            J Offline
            jbarton
            wrote on last edited by
            #5

            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

            T 1 Reply Last reply
            0
            • J jbarton

              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

              T Offline
              T Offline
              Tim Finer
              wrote on last edited by
              #6

              Thanks so much for your help! I had totally overlooked using the disassembly window! I was also able to cast a pointer to a structure too: *(SaveParams*)(0x007b1280) Again, thanks! Best Regards, Tim

              1 Reply Last reply
              0
              • T Tim Finer

                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

                D Offline
                D Offline
                dshatilov
                wrote on last edited by
                #7

                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

                Richard DeemingR 1 Reply Last reply
                0
                • D dshatilov

                  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

                  Richard DeemingR Offline
                  Richard DeemingR Offline
                  Richard Deeming
                  wrote on last edited by
                  #8

                  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

                  "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                  D 1 Reply Last reply
                  0
                  • Richard DeemingR Richard Deeming

                    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

                    D Offline
                    D Offline
                    dshatilov
                    wrote on last edited by
                    #9

                    it's just help for other :)

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups