Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

stop by code and then run it step by step

Posted on 2000-04-06
8
Medium Priority
?
209 Views
Last Modified: 2010-05-19
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)
0
Comment
Question by:username1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 150 total points
ID: 2689349
There is no C++ feature to do this.

However, on x86  computers (IBM compatible) there is an interrupt that is usually used to signal the debugger to stop the program.  This is int 3.  If you place a statement like

if (somecondition)
    _asm int 3;

and run the program under the debugger, when the int 3 is executed the debugger should stop the program at that point and allow you to single-step.  

(Note you may need 0,1, or 2 underscores before the "asm".)

Let me know if you have any questions.
0
 
LVL 86

Expert Comment

by:jkr
ID: 2689351
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...
0
 

Author Comment

by:username1
ID: 2689398
Hi jkr,

I have just tried to insert the function
DebugBreak()
without success. It was not be recognised by the C++.....
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:jkr
ID: 2689427
Hmm, 'DebugBreak()' is defined in winbase.h - did you #include it? (BTW: It mainly expands to '__asm{ int 3};', which nietod already mentioned)
0
 
LVL 22

Expert Comment

by:nietod
ID: 2689460
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.
0
 

Author Comment

by:username1
ID: 2689472
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?
0
 

Author Comment

by:username1
ID: 2689565
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.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2689685
>> 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.)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question