[comp.sys.ibm.pc.misc] When CTRL+C doesn't work.

elee24@castle.ed.ac.uk (H Bruce) (09/11/90)

I am getting more distenchanted with my PC .......
I am implementing image processing algortihms (using Microsoft C 5.1).
Such algorithms consist of many nested loops.
When a bug in my code causes a loop never to exit the PC hangs.
This is not because DOS has crashed but beacuse the microprocessor cannot
be interrupted by CRTL+C or CTLR+BREAK.
This result is that the PC must be rebooted.
This is a very time consuming way to find bugs !
Does anyone know how I can interrupt the program ?

Putting "break=on" into my config.sys file makes no difference.


Thanks,

Henry Bruce.

mcdonald@aries.scs.uiuc.edu (Doug McDonald) (09/12/90)

In article <6241@castle.ed.ac.uk> elee24@castle.ed.ac.uk (H Bruce) writes:
>I am getting more distenchanted with my PC .......
>I am implementing image processing algortihms (using Microsoft C 5.1).
>Such algorithms consist of many nested loops.
>When a bug in my code causes a loop never to exit the PC hangs.
>This is not because DOS has crashed but beacuse the microprocessor cannot
>be interrupted by CRTL+C or CTLR+BREAK.
>This result is that the PC must be rebooted.
>This is a very time consuming way to find bugs !
>Does anyone know how I can interrupt the program ?
>
>Putting "break=on" into my config.sys file makes no difference.
>
>
>Thanks,
>
>Henry Bruce.

The following is a TSR that will break out of loops, even in the cases
you describe above. It will not always leave your PC in a useable state,
however, if the program it stops has done something strange, like
usurp interrupts. Basica or Gwbasic, for example, do this, as do
many network programs.

Uudecode this program and run in from you autoexec.bat. The command that
it uses to stop programs is control-alt-4 (hit control and alt, hold them 
down, then hit 4).

begin 0666 breakit.com
MZTV0`````/L&5U!14IRX``".P+\7!":*)?;$!'0FY&`\!74@]L0(=!N*R.1A
MBN`,@.9ABL3F8?JP(.8@^[`!M$S-(<^=6EE87P<N_RX#`;@``([`OR0`)HL%
G)HM=`KX#`8D$B5P"N```CL",V_J_)`"X!P$FB04FB5T"^[I/`<TG
 
end

Doug McDonald

ts@uwasa.fi (Timo Salmi LASK) (09/12/90)

In article <6241@castle.ed.ac.uk> elee24@castle.ed.ac.uk (H Bruce) writes:
>I am getting more distenchanted with my PC .......
>I am implementing image processing algortihms (using Microsoft C 5.1).
>Such algorithms consist of many nested loops.
>When a bug in my code causes a loop never to exit the PC hangs.
>This is not because DOS has crashed but beacuse the microprocessor cannot
>be interrupted by CRTL+C or CTLR+BREAK.
>This result is that the PC must be rebooted.
>This is a very time consuming way to find bugs !
>Does anyone know how I can interrupt the program ?

You'll need a break handler.  Unfortunately I don't no C, so I
cannot give you a C reference.  But the principle should not be
overly language dependent, and I know that there is a break handler
in Ohlsen & Stoker, Turbo Pascal Advance Techniques, Chapter 7.

...................................................................
Prof. Timo Salmi        (Moderating at anon. ftp site 128.214.12.3)
School of Business Studies, University of Vaasa, SF-65101, Finland
Internet: ts@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun

ching@brahms.amd.com (Mike Ching) (09/13/90)

In article <1990Sep11.194619.22306@uwasa.fi> ts@uwasa.fi (Timo Salmi LASK) writes:
>In article <6241@castle.ed.ac.uk> elee24@castle.ed.ac.uk (H Bruce) writes:
>>When a bug in my code causes a loop never to exit the PC hangs.
>>This is not because DOS has crashed but beacuse the microprocessor cannot
>>be interrupted by CRTL+C or CTLR+BREAK.
>You'll need a break handler.  Unfortunately I don't no C, so I

>cannot give you a C reference.  But the principle should not be
>overly language dependent, and I know that there is a break handler
>in Ohlsen & Stoker, Turbo Pascal Advance Techniques, Chapter 7.

I think CTRL-C is only checked during BIOS routines unless you program
something specifically to manage it. I'd suggest adding something like
kbhit() to the loop as a low effort solution.

Mike Ching

novak@uni2a.unige.ch (09/14/90)

> This is not because DOS has crashed but beacuse the microprocessor cannot
> be interrupted by CRTL+C or CTLR+BREAK.
> This result is that the PC must be rebooted.
> This is a very time consuming way to find bugs !
> Does anyone know how I can interrupt the program ?
> 
I have seen working a program called ABORT. It is a TSR which exits the current
program and returns to DOS. As far as I know, it works pretty well and does not
require much memory, but I do not know whether it works with C. It is a share-
ware or a public domain and should be on Simtel. Anyway, it is worth to try.

raymond@math.berkeley.edu (Raymond Chen) (09/15/90)

In article <6241@castle.ed.ac.uk> elee24@castle.ed.ac.uk (H Bruce) writes:
> This is a very time consuming way to find bugs !

Everybody seems to be missing the forest but for the trees here...

The real question is not about trapping Ctrl+C, but rather "How do I
debug my program if it gets caught in a tight loop?"

The answer is to run your program *under a debugger*.  You get lots of
other benefits, like being able to inspect variables at the point the
program hangs.  All the major compilers come with debuggers.  Use
them.