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. C++ debuggin question - detect change in variable?

C++ debuggin question - detect change in variable?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++debugginghelp
3 Posts 3 Posters 0 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.
  • I Offline
    I Offline
    Indrawati
    wrote on last edited by
    #1

    Hi I have a short question about debugging in C++. Let's say I have a member variable that rarely changes, and in my program I suspect there's an invalid modification made to this variable that causes my program to crash. Is there a way to set up a debugger in such a way that it will trap when the variable is changed? Simple text find in the source files won't do, since more complex circumstances (e.g. int tmp[100]; memcpy(tmp, some_buffer, 101*sizeof(int) /*oooops*/); ) MAY also change the value of the variable if it's located right after tmp[99], and these kinds of error won't be detected by source files text find. Thanks!

    L 1 Reply Last reply
    0
    • I Indrawati

      Hi I have a short question about debugging in C++. Let's say I have a member variable that rarely changes, and in my program I suspect there's an invalid modification made to this variable that causes my program to crash. Is there a way to set up a debugger in such a way that it will trap when the variable is changed? Simple text find in the source files won't do, since more complex circumstances (e.g. int tmp[100]; memcpy(tmp, some_buffer, 101*sizeof(int) /*oooops*/); ) MAY also change the value of the variable if it's located right after tmp[99], and these kinds of error won't be detected by source files text find. Thanks!

      L Offline
      L Offline
      Lim Bio Liong
      wrote on last edited by
      #2

      Hello Indrawati, You've touched on one of my favourite debugging techniques. I assume that you are using Visual C++ 6.0. Do the following : 1. Put a breakpoint at the place where your member variable is first created, A good place would be when your object is instantiated. 2. Start to debug your app. 3. After your object has been created and initialized, select and highlight your member variable. 4. Press SHIFT+F9 to bring up the Quick Watch window. 5. You will see your member variable displayed on the edit box labelled "Expression". 6. Put a '&'symbol just infront of your member variable. The memory address of your member variable will appear on the value column. 7. Remember this memory address. 8. Now press CTRL-B to bring up the "Breakpoints" dialog box. 9. Select the "Data" tab in the "Breakpoints" dialog box. 10. In the edit box labelled "Ënter the expression to be evaluated", type in the memory address of your member variable. 11. In the "Enter the number of elements to watch in an array or structure" edit box, type in the number of bytes that your member variable would take up. 12. Click "OK". You now have a memory address breakpoint. Whenever the contents of this memory address changes (up the the number of bytes you specified in point 11), a message box will appear rto indicate to you that changes have occurred. Hope this advise will help you. Best Regards, Bio.

      D 1 Reply Last reply
      0
      • L Lim Bio Liong

        Hello Indrawati, You've touched on one of my favourite debugging techniques. I assume that you are using Visual C++ 6.0. Do the following : 1. Put a breakpoint at the place where your member variable is first created, A good place would be when your object is instantiated. 2. Start to debug your app. 3. After your object has been created and initialized, select and highlight your member variable. 4. Press SHIFT+F9 to bring up the Quick Watch window. 5. You will see your member variable displayed on the edit box labelled "Expression". 6. Put a '&'symbol just infront of your member variable. The memory address of your member variable will appear on the value column. 7. Remember this memory address. 8. Now press CTRL-B to bring up the "Breakpoints" dialog box. 9. Select the "Data" tab in the "Breakpoints" dialog box. 10. In the edit box labelled "Ënter the expression to be evaluated", type in the memory address of your member variable. 11. In the "Enter the number of elements to watch in an array or structure" edit box, type in the number of bytes that your member variable would take up. 12. Click "OK". You now have a memory address breakpoint. Whenever the contents of this memory address changes (up the the number of bytes you specified in point 11), a message box will appear rto indicate to you that changes have occurred. Hope this advise will help you. Best Regards, Bio.

        D Offline
        D Offline
        dharani
        wrote on last edited by
        #3

        :rose: Cool Bio ... Have been searching for this till now ... Dharani Babu S

        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