Thread: Visual Studio C++ debugging

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248

    Visual Studio C++ debugging

    Hi guys,

    I'm having this very weird problem : I compile my code and create the executable with all debug options 'on' (.pdb file is written) , then I launch the executable and debug my code.
    At a certain point, I jump from one .cpp file to another (by simple pushing 'F11' to go into the called function). And there it steps through the code on lines without code! It enters the function on the wrong line, it seems like it skips function calls, it quits the function even before 'return'...

    The problem occurs only with one .cpp file, however it seems occurs for all member functions implemented in that file.

    It just cannot be the class right ?

    The code is compiled without optimizations (/Od), no inline expansion, debug information (/Z7) (the .pdb is being created).

    Thanks a lot for your help!!

    Mark

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Try a complete rebuild of the project (all source modules).
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    Try a complete rebuild of the project (all source modules).
    Yeah already did couple of times. Even changed name of files, .lib (created) etc.


    When i take a look at the disassembled code, I notice that (with the function causing my troubles) there is a whole bunch of assembler instructions just before the opening '{' , which is not the case with other functions in other .cpp files.

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Which version of the compiler are you using? MSVS has had this bug numerous times in various versions.

  5. #5
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    Which version of the compiler are you using? MSVS has had this bug numerous times in various versions.
    VisualStudio 2008 : version 9.307... (SP) . See the attached file for precise version info.

    In the mean time, I also tried to look at the '.i' file, i.e., the intermediate file generated by the preprocessor. It contains about half a million lines !


    The disassembled code seems weird (a whole bunch of assembler code right before the opening bracket) :

    Code:
    void myClass::myFunction(int mode)  // virtual member function
    00681FB0  push        ebp  
    00681FB1  mov         ebp,esp 
    00681FB3  push        0FFFFFFFFh 
    00681FB5  push        offset __ehhandler$?TraceRays@PanthereV2@@UAEXH@Z (98D1D6h) 
    00681FBA  mov         eax,dword ptr fs:[00000000h] 
    00681FC0  push        eax  
    00681FC1  sub         esp,1ECh 
    00681FC7  push        esi  
    00681FC8  push        edi  
    00681FC9  push        ecx  
    00681FCA  lea         edi,[ebp-1F8h] 
    00681FD0  mov         ecx,7Bh 
    00681FD5  mov         eax,0CCCCCCCCh 
    00681FDA  rep stos    dword ptr es:[edi] 
    00681FDC  pop         ecx  
    00681FDD  mov         eax,dword ptr [___security_cookie (0AF4AF0h)] 
    00681FE2  xor         eax,ebp 
    00681FE4  mov         dword ptr [ebp-10h],eax 
    00681FE7  push        eax  
    00681FE8  lea         eax,[ebp-0Ch] 
    00681FEB  mov         dword ptr fs:[00000000h],eax 
    00681FF1  mov         dword ptr [ebp-14h],ecx 
    {
    Last edited by MarkZWEERS; 01-20-2011 at 03:48 AM. Reason: attach version info

  6. #6
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    The problem seems to be solved by a (more than necessary) reorganization of the code files.

    But honestly, it cannot be a complex #include spaghetti which makes the debugger fail ?!

    At least tnx a lot for your answers.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > The disassembled code seems weird (a whole bunch of assembler code right before the opening bracket) :
    Most of that you get with various compiler options. Perhaps you mistakenly specified that one file be build with different flags.

    > 00681FC1 sub esp,1ECh
    This is your traditional reserve some space on the stack, by adjusting the stack pointer.

    > 00681FD5 mov eax,0CCCCCCCCh
    This bit of code is filling all the local variables with a magic number, to assist with detecting "use before initialisation"

    > 00681FDD mov eax,dword ptr [___security_cookie (0AF4AF0h)]
    This bit of code is placing a guard on the stack to detect buffer overruns (or deliberate stack smashing). If this value is changed, the program will abort.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Ok well the bug I am talking about is fixed in 2008 so that probably is not the issue. You can still encounter it in applications that use both unmanaged and managed code but not usually in pure unmanaged code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM