C++ breakpoints are ignored / missed - c++

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?

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:
Quality Central
Delphi: why breakpoints from time to time are not usable (green highlighted line on IDE)?

Related

Setting a protobuf item's value replaces a previously set variable as well

I have created a simple Protobuf based config file and have been using it without any issues until now. The issue is that I added two new items to my settings (Config.proto) and now whatever value I set for the last variable is reflected in the previous one.
The following snapshot demonstrates this better. As you can see below, the value of fv_shape_predictor_path and fv_eyenet_path depend solely on order of being set. the one that is set last changes the others value.
I made sure the cpp files related to Config.proto are built afresh. I also tested this under Linux and there it works just fine. It seems its only happening in windows! it also doesn't affect any other items in the same settings. its just these two new ones.
I have no idea what is causing this or how to go about it. For reference this is how the protobuf looks like:
syntax = "proto3";
package FVConfig;
message Config {
FV Configuration = 4 ;
message FAN_MODELS_WEIGHTS{
string fan_2DFAN_4 = 1;
string fan_3DFAN_4 = 2;
string fan_depth = 3;
}
message S3FD_MODELS_WEIGHTS{
string s3fd = 1;
}
message DLIB_MODELS_WEIGHTS{
string dlib_default = 1;
}
message MTCNN_MODELS_WEIGHTS {
string mt_onet = 1;
string mt_pnet = 2;
string mt_rnet = 3;
}
message FV_MODEL_WEIGHTS {
string r18 = 1;
string r50 = 2;
string r101 = 3;
repeated ModelContainer new_models_weights = 4;
message ModelContainer{
string model_name = 1;
string model_weight_path = 2;
string description = 3;
}
}
message FV {
MTCNNDetectorSettings mtcnn = 1 ;
FaceVerificationSettings fv = 2 ;
}
message MTCNNDetectorSettings {
Settings settings = 1;
MTCNN_MODELS_WEIGHTS model_weights = 4;
message Settings {
string mt_device = 2;
int32 mt_webcam_source = 100;
int32 mt_upper_threshold = 600;
int32 mt_hop = 700;
}
}
message FaceVerificationSettings {
Settings settings = 1;
FV_MODEL_WEIGHTS model_weights = 2;
message Settings {
string fv_model_name = 1;
string fv_model_checkpoint_path = 2;
bool fv_rebuild_cache = 3;
bool fv_short_circut = 6;
bool fv_accumulate_score = 7;
string fv_config_file_path = 10;
string fv_img_bank_folder_root = 11;
string fv_cache_folder = 12;
string fv_postfix = 13;
string fv_device = 14;
int32 fv_idle_interval = 15;
bool fv_show_dbg_info = 16;
// these are the new ones
string fv_shape_predictor_path = 17;
string fv_eyenet_path = 18;
}
}
} //end of Config message
What am I missing here? How should I be going about this? Restarting Windows and Visual Studio didn't do any good either. I'm using protobuf 3.11.4 both on Linux and Windows.
This issue seems to only exist in the Windows version of Protobuf 3.11.4 (didn't test with any newer version though).
Basically what happened was that I use to first create a Config object and initialize it with some default values. When I added these two entries to my Config.proto, I forgot to also add an initialization entry like other entries, thinking I'm fine with the default (which I assumed would be "").
This doesn't pose any issues under Linux/G++ and the program builds and runs just fine and works as intended. However under Windows this results in the behavior you just witnessed i.e. setting any of those newly added entries, would also set the other entries values. So basically I either had to create a whole new Config object or had to explicitly set their values when using the load_default_config.
To be more concrete this is the snippet I used for setting some default values in my Protobuf configs.
These reside in a separate header called Utility.h:
inline FVConfig::Config load_default_config()
{
FVConfig::Config baseCfg;
auto config = baseCfg.mutable_configuration();
load_fv_default_settings(config->mutable_fv());
load_mtcnn_default_settings(config->mutable_mtcnn());
return baseCfg;
}
inline void load_fv_default_settings(FVConfig::Config_FaceVerificationSettings* fv)
{
fv->mutable_settings()->set_fv_config_file_path(fv::config_file_path);
fv->mutable_settings()->set_fv_device(fv::device);
fv->mutable_settings()->set_fv_rebuild_cache(fv::rebuild_cache);
...
// these two lines were missing previously and to my surprise, this was indeed
// the cause of the weird behavior.
fv->mutable_settings()->set_fv_shape_predictor_path(fv::shape_predictor_path);
fv->mutable_settings()->set_fv_eyenet_path(fv::eyenet_path);
auto new_model_list = fv->mutable_model_weights()->mutable_new_models_weights()->Add();
new_model_list->set_model_name("r18");
new_model_list->set_description("default");
new_model_list->set_model_weight_path(fv::model_weights_r18);
}
inline void load_mtcnn_default_settings(FVConfig::Config_MTCNNDetectorSettings* mt)
{
mt->mutable_settings()->set_mt_device(mtcnn::device);
mt->mutable_settings()->set_mt_hop(mtcnn::hop);
....
}
Not sure this counts as a bug in Protobuf, or my wrong approach here.

MinGW: Modify internet proxy options

I am trying to modify the proxy settings in C++ without using visual C++. I found this:
const wchar_t* proxyName = pnt.wc_str(); // pnt is a wxString declared earlier in the code.
INTERNET_PER_CONN_OPTION_LIST OptionList;
INTERNET_PER_CONN_OPTION Option[3];
unsigned long listSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);
Option[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
Option[1].dwOption = INTERNET_PER_CONN_FLAGS;
Option[2].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
OptionList.dwSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);
OptionList.pszConnection = NULL;
OptionList.dwOptionCount = 3;
OptionList.dwOptionError = 0;
DWORD proxyType = PROXY_TYPE_DIRECT;
if (proxyName)
{
if (proxyName[0])
{
proxyType = PROXY_TYPE_PROXY;
}
}
Option[0].Value.pszValue = (LPWSTR)proxyName;
Option[1].Value.dwValue = proxyType;
if (on)
{
Option[2].Value.pszValue = (LPWSTR)L"";
}
else
{
Option[2].Value.pszValue = (LPWSTR)L"";
}
OptionList.pOptions = Option;
if (!InternetSetOption(0, INTERNET_OPTION_PER_CONNECTION_OPTION, &OptionList, listSize))
{
// handle error
}
InternetSetOption(0, INTERNET_OPTION_PROXY_SETTINGS_CHANGED, NULL, NULL);
However because I have to use MinGW and MinGW's wininet.h is very different, I get "'INTERNET_PER_CONN_OPTION_LIST' was not declared in this scope" among other "not declared" messages. In all my searching I have not found anything on it, thanks to visual c++ being so prominent. I found this but it has almost no views, doesn't have any answers, and has not been touched almost a month and it's not even quite what I am looking for. I can't seem to find any documentation either. Any ideas? Thanks in advanced!

how to run this bakefile (.bkl)

I have the following bakefile (WinSparkle.bkl)
toolsets = vs2008 vs2010 vs2012 vs2013;
if ( $toolset == vs2008 )
SUFFIX = "";
if ( $toolset == vs2010 )
SUFFIX = "-2010";
if ( $toolset == vs2012 )
SUFFIX = "-2012";
if ( $toolset == vs2013 )
SUFFIX = "-2013";
vs2008.solutionfile = WinSparkle$(SUFFIX).sln;
vs2010.solutionfile = WinSparkle$(SUFFIX).sln;
vs2012.solutionfile = WinSparkle$(SUFFIX).sln;
vs2013.solutionfile = WinSparkle$(SUFFIX).sln;
// Common settings:
win32-crt-linkage = static;
archs = x86 x86_64;
defines += _CRT_SECURE_NO_WARNINGS;
// Build binaries compatible with Windows XP (SP3) -- it's still useful for
// installer stuff like WinSparkle.dll
vs2012.option.Configuration.PlatformToolset = v110_xp;
vs2013.option.Configuration.PlatformToolset = v120_xp;
if ( $(config) == Release ) {
vs2008.option.VCCLCompilerTool.Optimization = 1;
vs2008.option.VCCLCompilerTool.FavorSizeOrSpeed = 2;
vs2008.option.VCCLCompilerTool.WholeProgramOptimization = true;
vs2008.option.VCCLCompilerTool.StringPooling = true;
vs2008.option.VCLinkerTool.LinkTimeCodeGeneration = 1;
vs2010.option.Configuration.WholeProgramOptimization = true;
vs2010.option.ClCompile.Optimization = MinSpace;
vs2010.option.ClCompile.FavorSizeOrSpeed = Size;
vs2010.option.ClCompile.WholeProgramOptimization = true;
vs2010.option.ClCompile.StringPooling = true;
vs2010.option.ClCompile.FunctionLevelLinking = true;
vs2010.option.Link.OptimizeReferences = true;
vs2010.option.Link.EnableCOMDATFolding = true;
vs2010.option.Link.LinkTimeCodeGeneration = UseLinkTimeCodeGeneration;
vs2012.option.Configuration.WholeProgramOptimization = true;
vs2012.option.ClCompile.Optimization = MinSpace;
vs2012.option.ClCompile.FavorSizeOrSpeed = Size;
vs2012.option.ClCompile.WholeProgramOptimization = true;
vs2012.option.ClCompile.StringPooling = true;
vs2012.option.ClCompile.FunctionLevelLinking = true;
vs2012.option.Link.OptimizeReferences = true;
vs2012.option.Link.EnableCOMDATFolding = true;
vs2012.option.Link.LinkTimeCodeGeneration = UseLinkTimeCodeGeneration;
vs2013.option.Configuration.WholeProgramOptimization = true;
vs2013.option.ClCompile.Optimization = MinSpace;
vs2013.option.ClCompile.FavorSizeOrSpeed = Size;
vs2013.option.ClCompile.WholeProgramOptimization = true;
vs2013.option.ClCompile.StringPooling = true;
vs2013.option.ClCompile.FunctionLevelLinking = true;
vs2013.option.Link.OptimizeReferences = true;
vs2013.option.Link.EnableCOMDATFolding = true;
vs2013.option.Link.LinkTimeCodeGeneration = UseLinkTimeCodeGeneration;
}
// 3rd party library dependencies:
submodule 3rdparty/dependencies.bkl;
shared-library WinSparkle {
vs2008.projectfile = $(id)$(SUFFIX).vcproj;
vs2010.projectfile = $(id)$(SUFFIX).vcxproj;
vs2012.projectfile = $(id)$(SUFFIX).vcxproj;
vs2013.projectfile = $(id)$(SUFFIX).vcxproj;
defines += XML_STATIC;
includedirs += 3rdparty/expat/lib;
deps += WinSparkle_expat;
includedirs += 3rdparty/wxWidgets_setup_h 3rdparty/wxWidgets/include;
deps += WinSparkle_wx;
libs += comctl32 kernel32 user32 comctl32 rpcrt4 version wininet;
defines += BUILDING_WIN_SPARKLE;
// Public API headers:
headers {
include/winsparkle.h
include/winsparkle-version.h
}
includedirs += include;
// Private headers:
headers {
src/appcast.h
src/appcontroller.h
src/download.h
src/error.h
src/settings.h
src/threads.h
src/ui.h
src/updatechecker.h
src/updatedownloader.h
src/utils.h
}
sources {
src/appcast.cpp
src/appcontroller.cpp
src/dll_api.cpp
src/dllmain.cpp
src/download.cpp
src/error.cpp
src/settings.cpp
src/threads.cpp
src/ui.cpp
src/updatechecker.cpp
src/updatedownloader.cpp
src/winsparkle.rc
}
}
submodule examples/examples.bkl;
I downloaded bakefile for windows and installed it. Then I did the following
C:\winsparkle>bakefile -f msvc WinSparkle.bkl
file:///C:/winsparkle/WinSparkle.bkl:2:
parser
error :
Start tag expected, '<' not found
toolsets = vs2008 vs2010 vs2012 vs2013;
^
error: file 'C:\winsparkle\WinSparkle.bkl' is invalid
Any suggestions on what might be going wrong ??
If you want to regenerate the projects for some reason, you'll need Bakefile 1.x, not 0.2.x: https://github.com/vslavik/bakefile. Or just use the projects included in the repository.

mfc sdi application cdocument dosave error 0xFEEEFEEE

in my MFC SDI application, i'm trying to override CDocument::DoSave to save my document. I'm using a third part component (TxTextControl) to build a text control. When i save the document, the file is created, but after about one minute my app crashes rising read access error 0xFEEEFEEE, in ole32.dll.
This is my code, txtCtrl is my component:
BOOL CEditorTxDoc::DoSave(LPCTSTR lpszPathName, BOOL bReplace)
{
CString path, nome;
VARIANT vt1, vt2, vt3;
POSITION pos = GetFirstViewPosition();
CEditorTxView *pView = (CEditorTxView*)this->GetNextView(pos);
VariantInit(&vt1);
vt1.vt = VT_INT;
vt1.intVal = -1;
VariantInit(&vt2);
vt2.vt = VT_INT;
vt2.intVal = 3;
VariantInit(&vt3);
vt3.vt = VT_BOOL;
vt3.boolVal = FALSE;
if (lpszPathName == NULL) {
CFileDialog fSaveDlg(FALSE);
fSaveDlg.m_pOFN->lpstrFilter = _T("File Tx (*.tx)");
fSaveDlg.m_pOFN->lpstrDefExt = _T("tx");
fSaveDlg.m_pOFN->lpstrTitle = _T("Salva documento");
fSaveDlg.m_pOFN->lpstrInitialDir = _T("c:");
if(fSaveDlg.DoModal()==IDOK)
{
path = fSaveDlg.GetPathName();
nome = fSaveDlg.GetFileName();
pView->txtCtrl.Save(path, vt1, vt2, vt3);
SetTitle(nome);
SetModifiedFlag(FALSE);
SetPathName(path);
}
} else {
pView->txtCtrl.Save(GetPathName(), vt1, vt2, vt3);
SetModifiedFlag(FALSE);
}
return TRUE;
}
Magic debug values:
FEEEFEEE Used by Microsoft's HeapFree() to mark freed heap memory
That is, the problem comes up from the fact that the code deals with released memory as if it is still alive. To isolate the issue to specific code fragment, debug and use call stack information at the time of exception.

Segmentation fault occurs only under release configuration

For some odd reason, my application likes to break on me when I switch to release and run it outside of my debugger. Here's what works for me, and here's what doesn't
(Qt Creator is the IDE)
Debugging with debug configuration - ok
Running with debug configuration - ok
Debugging with release configuration - ok
Running with release configuration - application crash
My UI is one project, and the core for some stuff as a separate dependency. On Windows (compiling with MSVCC), I hit a menu button, which eventually calls down to a function. In that function, the app breaks on adding a new element to a vector. e.g:
str *x = new str();
str *y = new str();
/* ...set some of x & y's members... */
vector.push_back(x); // works fine
vector.push_back(y); // causes crash
If I comment out the line vector.push_back(y);, the app continues no problem until the app leaves the event scope (i.e. the end of OnMenuButtonClick). On OS X, it's similar to the issue of adding an element to a vector, except I have:
std::vector<foo *> SomeFunction()
{
std::vector<foo *> returningVector;
/* do stuff */
std::vector<foo *> goo = GetFooObjects();
for (int i = 0; i < goo.size(); i++)
{
returningVector.push_back(goo[i]); // breaks here
}
}
So what are some causes of this strange behavior without a debugger attached and not under debug configuration? I've checked to make sure all of my variables are initialized, so I'm stumped. If you want to view the code above, the first part can be located here, and the second part here. Please forgive anything you see as "bad", and if you have suggestions that you just can't contain, then please do message me on GitHub.
Edit:
I looked more into it, and found out exactly what's causing the problem, but don't know how to fix it. This is the function where my app crashes (on OS X):
vector<Drive *> Drive::GetFATXDrives( bool HardDisks )
{
vector<Drive *> Return;
if (HardDisks)
{
vector<DISK_DRIVE_INFORMATION> Disks = GetPhysicalDisks();
for (int i = 0; i < (int)Disks.size(); i++)
{
DISK_DRIVE_INFORMATION ddi = Disks.at(i);
// First, try reading the disk way
Streams::xDeviceStream* DS = NULL;
try
{
char path[0x200] = {0};
wcstombs(path, ddi.Path, wcslen(ddi.Path));
DS = new Streams::xDeviceStream(ddi.Path);
}
catch (xException& e)
{
continue;
}
if (DS == NULL || DS->Length() == 0 || DS->Length() < HddOffsets::Data)
{
// Disk is not of valid length
continue;
}
DS->SetPosition(HddOffsets::Data);
// Read the FATX partition magic
int Magic = DS->ReadInt32();
// Close the stream
DS->Close();
// Compare the magic we read to the *actual* FATX magic
if (Magic == FatxMagic)
{
Drive *d = new Drive(Disks.at(i).Path, Disks.at(i).FriendlyName, false);
Return.push_back(d);
}
}
}
vector<Drive *> LogicalDisks = GetLogicalPartitions();
for (int i = 0; i < (int)LogicalDisks.size(); i++)
{
Return.push_back(LogicalDisks.at(i));
}
return Return;
}
If I change if (HardDisks) to if (HardDisks = false), the app works just fine. So, I looked into that scope and discovered that after vector<DISK_DRIVE_INFORMATION> Disks = GetPhysicalDisks();, the heap gets corrupt or something like that. I noticed this because in the debugger, after that function is called, my HardDisks bool changes to "false", which wasn't what it was before.
Here is GetPhysicalDisks:
vector<Drive::DISK_DRIVE_INFORMATION> Drive::GetPhysicalDisks( void )
{
// RIGHT AFTER this vector is initialized, everything goes to hell
vector<Drive::DISK_DRIVE_INFORMATION> ReturnVector;
DIR *dir;
dirent *ent;
dir = opendir("/dev/");
if (dir != NULL)
{
// Read the shit
while ((ent = readdir(dir)) != NULL)
{
// Check the directory name, and if it starts with "disk" then keep it!
QRegExp exp("disk*");
exp.setPatternSyntax(QRegExp::Wildcard);
exp.setCaseSensitivity(Qt::CaseInsensitive);
if (exp.exactMatch(ent->d_name))
{
DISK_DRIVE_INFORMATION curdir;
memset(curdir.FriendlyName, 0, sizeof(curdir.FriendlyName));
memset(curdir.Path, 0, sizeof(curdir.Path));
char diskPath[0x50] = {0};
sprintf(diskPath, "/dev/r%s", ent->d_name);
mbstowcs(curdir.Path, diskPath, strlen(diskPath));
int device;
if ((device = open(diskPath, O_RDONLY)) > 0)
{
#ifdef __linux
hd_driveid hd;
if (!ioctl(device, HDIO_GET_IDENTITY, &hd))
{
swprintf(curdir.FriendlyName, strlen(hd) * 2, L"%hs", hd.model);
}
#elif defined __APPLE__
mbstowcs(curdir.FriendlyName, ent->d_name, strlen(ent->d_name));
#endif
ReturnVector.push_back(curdir);
}
}
}
}
return ReturnVector;
}
While this isn't a real answer as to what happened, I did find a way to fix the problem. Looking at my edit above, I edited my Drive::GetFATXDrives function like so:
vector<Drive *> Drive::GetFATXDrives( bool HardDisks )
{
// Initialize Disks vector up here
vector<DISK_DRIVE_INFORMATION> Disks;
// Call the function to get the hard disks
if (HardDisks)
Drive::GetPhysicalDisks(Disks);
vector<Drive *> ReturnVector;
if (HardDisks)
{
Streams::xDeviceStream* DS = NULL;
for (int i = 0; i < (int)Disks.size(); i++)
{
/* ... */
}
if (DS)
{
DS->Close();
delete DS;
}
}
vector<Drive *> LogicalDisks = GetLogicalPartitions();
for (int i = 0; i < LogicalDisks.size(); i++)
{
ReturnVector.push_back(LogicalDisks[i]);
}
return ReturnVector;
}
And my Drive::GetPhysicalDisks function now takes a vector<DISK_DRIVE_INFORMATION> reference instead of returning one. Seemed to make my program work just fine after that.