Link to home
Start Free TrialLog in
Avatar of username1
username1

asked on

stop by code and then run it step by step

Hi,

How to stop a program by its code
    if (...) {stop}
and then run the rest of it one step by one step?

(Borland C++5.02)
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jkr
You can issue a breakpoint by calling 'DebugBreak()' (which will actually emit a 'int 3' aka EXCEPTION_BREAKPOINT). This will bring up the debugger, and you'll be able to execute your code step-by-step...
Avatar of username1
username1

ASKER

Hi jkr,

I have just tried to insert the function
DebugBreak()
without success. It was not be recognised by the C++.....
Hmm, 'DebugBreak()' is defined in winbase.h - did you #include it? (BTW: It mainly expands to '__asm{ int 3};', which nietod already mentioned)
Although an advantage to DebugBreak() would be that it probably is made to work on non-x86 platforms too.   But one dissadvantage is that the debugger probably takes over inside the DebugBreak() function, and you probably have to step out of it to get back to your code.
Hi jkr,

after #include<winbaxe.h> I got error message:
winbase.h(199,21):Type mane expected
.........many errors........

--------------------------------

Hi nietod,

Thank you.
when you said "under the debugger", do you mean click the "debug" in the menu in the edit window or run a debug firstly then call the program?
Hi nietod,

Have you read the comment to you?

I try to compile my cpp with _asm int 3 and got error
Could not locate: TASM32.EXE

If can not copile to a exe file, I can not do:
run the debug firstly and then call a exe file.

Cheers.
>> winbase.h(199,21):Type mane expected
You probably can't include just <winbase.h>, you probalby need to include <windows.h>

>> I try to compile my cpp with _asm int 3 and got error
>> Could not locate: TASM32.EXE
Borland is annoying in this respect.  They don't support in-line assembly (_asm XXXX) unless you have installed their assembler.  This is sort of rediculious as they have to have an assembler built into their compiler.  But I guess the built-in one is not flexible enough or something.  If you have TASM, make sure it is installed correctly.  Otherwise you need to buy TASM--which this probably is not worth doing just for this, or use DebugBreak(), or just manualy set a breakpoint in the debugger (but this manual breakpoint won't be preserved between execution times of the debugger, but the int3 would be.)