Can''t put breakpoint in Release version but works in Debug version

Posted on 2005-05-05
Last Modified: 2012-05-05
  If I put the breakpoint in Release version and try to debug, the breakpoint is automatically getting removed (Not all of them. 1 or 2 places) but it works in Debug version. I am using Visual studio.NET for unmaged C++ code.

Thanks in advance
Question by:kiru
    LVL 86

    Expert Comment

    You'll need to add debugging information to your release build - enable that in your project settings.
    LVL 86

    Expert Comment

    See ("Turn on Generation of Debug Information for the Release Build"). This is VC6, but the prnciole appiles to more recent versions also.
    LVL 86

    Expert Comment

    Oh, and;en-us;291585 ("How to Create Debug Symbols for a Visual C++ Application") describes that for all versions.
    LVL 30

    Expert Comment

    Check for code that is not initializing variables to NULL values.

    The debug version will set variables to NULL or zero values, but the release version does not.

    Author Comment

    Thanks for the reply. I have Debug info enabled for Release version.
    I think my question is not clear.
    It is allowing me to put breakpoints but when I start debugging it is removing couple of them not all of them

    For ex.
    I put break points at Line1, Line3, Line 8, Line 10 etc When I press F5 it is removing the breakpoints at Line3 and Line 8.  When I start to step over Lines 3(Jumps from Line 2 to Line 4) & 8 are missed.
    But this deosn't happen with Debug version builds

    Hope I made it clear this time.

    LVL 86

    Expert Comment

    That's most likely because the optimizations the compiler performs in the release build don't allow to correctly correllate the source lines to the debug information. Turn off the optimizations before debugging the release version.

    Author Comment

     I set optimization as Disable and tried. Still same problem.

    Here is the Code.

    L1. LV_ITEM lvItem;
    L2. lvItem.iItem = item_index;
    L3. GetItem(&lvItem);

    L4. Row *row= reinterpret_cast<Row*> (lvItem.lParam);

    L5. delete prow;

    I put the breakpoint  L2 through L5. When I start to debug (release version) it removes the break point on L2 & L4. When I try to stepover from L3 to L4 it misses L4 and goes directly to L5 and crashes at L5.
    LVL 86

    Accepted Solution

    Hmm, that's strange - regarding the 'crash' - are you checking the return value of 'GetItem()', e.g.

    if (GetItem(&lvItem))
     Row *row= reinterpret_cast<Row*> (lvItem.lParam);

     delete prow;

    If 'GetItem()' returns 'FALSE', 'delete' will not have any valid data to delete.

    LVL 14

    Expert Comment

    No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
    I will leave the following recommendation for this question in the Cleanup topic area:

    Accept: jkr

    Any objections should be posted here in the next 4 days. After that time, the question will be closed.

    EE Cleanup Volunteer

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Article by: SunnyDark
    This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now