Different behavior in debugger vs. EXE file

Everything else that doesn't fall into one of the other PB categories.
ebs
Enthusiast
Enthusiast
Posts: 557
Joined: Fri Apr 25, 2003 11:08 pm

Different behavior in debugger vs. EXE file

Post 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
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Different behavior in debugger vs. EXE file

Post by freak »

Search your code for 'Debug' statements containing code that may be needed even without the debugger.

Example:

Code: Select all

Debug OpenFile(...)
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.
quidquid Latine dictum sit altum videtur
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Different behavior in debugger vs. EXE file

Post 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?
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
ebs
Enthusiast
Enthusiast
Posts: 557
Joined: Fri Apr 25, 2003 11:08 pm

Re: Different behavior in debugger vs. EXE file

Post 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
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: Different behavior in debugger vs. EXE file

Post by coder14 »

freak wrote:Search your code for 'Debug' statements containing code that may be needed even without the debugger.

Example:

Code: Select all

Debug OpenFile(...)
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.
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: Different behavior in debugger vs. EXE file

Post 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
Post Reply