1

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?

sfrehse
  • 1,062
  • 9
  • 22
Hamish_Fernsby
  • 558
  • 1
  • 7
  • 28
  • In Release builds, many breakpoints _cannot_ be hit, because that code is inlined. Either debug a Debug build (or non-optimized Release, if that makes sense for your context), or set breakpoints at places that _cannot_ be inlined and step from there, or learn to read assembly and set breakpoints there. – Johann Gerell Nov 18 '14 at 17:05
  • The formcreate method is only called once and isn't marked inline. I can't imagine it would be automatically inlined by the compiler? – Hamish_Fernsby Nov 18 '14 at 18:48
  • By "marking", I assume you mean _declare_ - if you _had_ declared it `inline`, it would still only be a _hint_ - the compiler almost always knows better than the developer when something ought to be inlined or not. That said, please paste the `formcreate` function and we'll most likely be able to tell if it is likely to be inlined or not. – Johann Gerell Nov 18 '14 at 19:45
  • Thanks Johann, I have added the code to the original question – Hamish_Fernsby Nov 18 '14 at 20:33

1 Answers1

5

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:

Community
  • 1
  • 1
manlio
  • 18,345
  • 14
  • 76
  • 126