Page 1 of 1
Different behavior in debugger vs. EXE file
Posted: Thu Dec 11, 2014 5:56 pm
by ebs
I know that my question is very vague and long-winded, but please bear with me...
I have a Windows program developed in PB 4.50. I know that's ancient, but I need libraries not available for newer versions.
The program uses an SQLite database to store portions of EDI files, using PB's built-in SQLite library.
My problem is this:
When running the program in the PB debugger, it works fine. I read and import over 625 files without a problem.
There are no "CallDebugger" statements, so the program runs at full speed (discounting the effects of the debugger).
Running the same program as an executable, it always fails during the file import with a Windows error code 0xc0000005.
It does fail on a particular file, but there's nothing wrong with the file and rerunning the program will import the file without error.
I am running Windows XP SP3 (again ancient, I know...). I have never seen this behavior before. Could it be related to the SQLite library in PB?
Can anyone suggest something I can try when creating the executable to see if I can fix this?
Thanks,
Eric
Re: Different behavior in debugger vs. EXE file
Posted: Thu Dec 11, 2014 8:10 pm
by freak
Search your code for 'Debug' statements containing code that may be needed even without the debugger.
Example:
Without debugger, the entire Debug line is not compiled including the OpenFile() call. So the exe will never open the file and crash later when trying to access the file. This is a common source for such "it works with the debugger only" problems.
Re: Different behavior in debugger vs. EXE file
Posted: Thu Dec 11, 2014 8:36 pm
by Shield
It might also be a problem with memory corruption / memory access that just happens not to lead
to a crash (although probably still occurs) when the debugger is compiled-in.
Maybe the purifier helps?
Re: Different behavior in debugger vs. EXE file
Posted: Thu Dec 11, 2014 8:41 pm
by ebs
Hi freak and shield,
@freak: I try very hard not to do that! I checked and there are no "Debug..." statements in the code.
However, I have found something very interesting. I normally use Gnozal's jaPBe to develop my PB programs.
If I compile the program using the standard PB IDE (using the same PB 4.50 compiler), the executable works!
The executables are the same size, but a file comparison does show one difference: about 300 bytes at the end of the file.
The jaPBE executable has data there, where the PB executable has all zeros. I don't know what that means,
but it certainly sound like it could be the source of the "Access Violation" error.
Right now, the most important thing is that I can make an executable that works.
If I have some time, I may try to figure out what the differences are in the executables.
@shield: I will give the Purifier a try and see if it finds anything.
Thanks for your suggestions.
Regards,
Eric
Re: Different behavior in debugger vs. EXE file
Posted: Mon Sep 21, 2015 9:17 am
by coder14
freak wrote:Search your code for 'Debug' statements containing code that may be needed even without the debugger.
Example:
Without debugger, the entire Debug line is not compiled including the OpenFile() call. So the exe will never open the file and crash later when trying to access the file. This is a common source for such "it works with the debugger only" problems.
Hello freak. My apologies for bumping old thread. I am facing the same problem.
The C library is long (not mine) which opens and modifies some files and then writes a new file. Only one function is set in the
extern "C" scope but it also calls other functions in the library too. The library is compiled with Code::Blocks and GCC (I tried with VS2013 but I was not able to clear some compiler errors).
When I import the main function and call it in PureBasic, it works from the IDE
only when the debugger is on AND the function is called with the DEBUG statement. The function is working and the the new file is written perfectly.
If I call it directly without the
DEBUG statement, it runs and the new file is written but the file is corrupted (not properly written).
Please see my this post:
http://www.purebasic.fr/english/viewtop ... 89#p472289
What special effect does the DEBUG statement contain that is causing this behavior?
PLEASE HELP. Thank you.
EDIT:Because Code::Blocks cannot compile to 64bit I am using PureBasic 5.31 32bit on my Windows 8.1 64bit.
Re: Different behavior in debugger vs. EXE file
Posted: Tue Sep 22, 2015 5:10 am
by coder14
coder14 wrote:When I import the main function and call it in PureBasic, it works from the IDE only when the debugger is on AND the function is called with the DEBUG statement. The function is working and the the new file is written perfectly.
If I call it directly without the DEBUG statement, it runs and the new file is written but the file is corrupted (not properly written).
For the benefit of other readers: user TI994A suggested a solution for this issue that works for me.
Please see it here:
http://www.purebasic.fr/english/viewtop ... 12#p472412