C++ breakpoints are ignored / missed

3.4k views Asked by At

I'm trying to run some C++ code someone gave me. At first there was a broken link to an istream file, which I fixed by adding the include path:

C:\Program Files (x86)\Embarcadero\RAD Studio\7.0\include\dinkumware

The code now compiles but it doesn't stop at any breakpoints, for example those in the formcreate:

// Initialise the form and read in the module and inverter names.
void __fastcall TMain::FormCreate(TObject *Sender)
{
    ifstream inits;
    ifstream inverters;
    ifstream modules;
    char line[1000];
    AnsiString FTO;
    inits.open("PVSM.ini", ios::in);
    if (inits.is_open())
    {
            inits.getline(line,1000);
            AnsiString parmm(line);
            ModDir = parmm.SubString(1,parmm.Pos(" ")-1);
            inits.getline(line,1000);
            AnsiString parmi(line);
            InvDir = parmi.SubString(1,parmi.Pos(" ")-1);
            inits.getline(line,1000);
            AnsiString parmt(line);
            MetDir = parmt.SubString(1,parmt.Pos(" ")-1);
            inits.getline(line,1000);
            AnsiString parms(line);
            ShdDir = parms.SubString(1,parms.Pos(" ")-1);
            inits.getline(line,1000);
            AnsiString parmx(line);
            ExpDir = parmx.SubString(1,parmx.Pos(" ")-1);
    }
    else    // Should never get here, but if ini file missing use defaults
    {
        ModDir = "C://";
        InvDir = "C://";
        MetDir = "C://";
        ShdDir = "C://";
    }
    inits.close();
    FTO = InvDir + "inverters.data";
    inverters.open(FTO.c_str(), ios::in);
    if (inverters.is_open())
    {
            while ( inverters.getline(line,1000) )
            {
               AnsiString inverter(line);
               IVBox->Items->Add(inverter);
            }
    }
    inverters.close();
    FTO = ModDir + "modules.data";
    modules.open(FTO.c_str(), ios::in);
    if (modules.is_open())
    {
            while ( modules.getline(line,1000) )
            {
               AnsiString module(line);
               ModBox->Items->Add(module);
            }
    }
    modules.close();
    CMod = 1;
    CStr = 1;
    CCell = 1;
    nStore = 0;
    grid = true;
    pasan = false;
    debug = false;
    calc = false;
    cell = false;
    module = false;
    array1 = false;
    inv = false;
    PV = true;
    Parray = false;
    Pcurve = false;
    LastType = 'X';
    CurrTp = -1;  //* Not currently set
    AllSame = true;
    LdMeteo = false;
    mpp = true;
}

It just opens the form as if it was run from the .exe file, except it shows

Compiling MyProject.cbproj (Release configuration).... Success

in the message bar

I've tried switching from release to debug mode, tried changing the output directories so it compiles new .obj files. No success.

I'm running Rad studio 2010, it was originally written in XE5, but I think this is an issue with folder structure rather than IDE version?

Any suggestions?

1

There are 1 answers

0
manlio On BEST ANSWER

Some ideas (from various sources) that may or may not be useful to you:

  • make sure that you're using the Debug configuration and do a Build of the project, not just a Compile: switching back to debug configuration and doing a compile after a release build isn't enough
  • in your project options for Win32(Debug) make sure that the following options are set to the correct values

    • [C++ Compiler] → [Debugging] → [Debug information] = True;
    • [C++ Compiler] → [Debugging] → [Debug line number information] = True;
    • [C++ Compiler] → [Optimizations] → [Disable all optimizations] = True;
    • [C++ Compiler] → [Optimizations] → [Generate fastest possible code] = False;
    • [C++ Linker] → [Full Debug information] = True;
    • [Delphi Compiler] → [Optimization] = False;
    • [Delphi Compiler] → [Use debug .dcus] = True;

    (e.g. the default configuration template for MDI application is wrong)

  • delete all the .pch, .# and .tds files and let the compiler recreate
  • if you are running the IDE under VirtualBox consider that some versions have problem with breakpoints (v4.3.x)

As a last resort you could try { _asm { int 3 } } to simulate a breakpoint.

Also take a look at: