home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
pascal
/
library
/
dos
/
bix
/
debug.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1986-11-01
|
3KB
|
99 lines
{TITLE: Turbo-IBM-PCDOS-Debugging aid}
type sstring = string[80];
alfa = string[10];
unsigned = integer;
{----------------------------------------------------------------}
{ Returns as a short string the hexadecimal representation of "w." }
function hex(w : unsigned) : alfa;
const digs : array[0..15] of char = '0123456789ABCDEF';
begin
hex := digs[hi(w) shr 4] + digs[hi(w) and 15] +
digs[lo(w) shr 4] + digs[lo(w) and 15]
end;
{----------------------------------------------------------------}
{ Sounds the speaker at a frequency of "freq" for "len" ms. }
procedure beep(freq, len : integer);
begin
sound(freq);
delay(len);
nosound
end;
{----------------------------------------------------------------}
{ Returns value of Stack Segment Register (SS) (which is <>
SSeg!). }
function STSeg : unsigned;
const ss : unsigned = 0;
begin
inline($8C/$D0/$2E/$A3/ss); { MOV AX,SS : MOV CS:[*],AX }
STSeg := ss
end;
{----------------------------------------------------------------}
{ Returns the offset into the stack segment of the "n"'th frame on
the stack. The calling procedure's frame is numbered 0. "N" may
be either positive or negative (depending on your view of the
stack).}
function frameoffset(n : integer) : unsigned;
const _n : unsigned = 0;
_bp : unsigned = 0;
begin
_n := succ(abs(n));
inline($2E/$8B/$0E/_n/ { MOV CX,CS:[*] }
$89/$EB/ { MOV BX,BP }
$36/$8B/$1F/ { TOPLOOP: MOV BX,SS:[BX] } { ; Old BP at BP+0 }
$E2/$FB/ { LOOP TOPLOOP }
$2E/$89/$1E/_bp); { MOV CS:[*],BX }
frameoffset := _bp
end;
{----------------------------------------------------------------}
{ Returns the return address stored in the "n"'th stack frame. }
function returnaddress(n : integer) : unsigned;
begin
returnaddress := memw[STSeg:frameoffset(n)+2]
end;
{----------------------------------------------------------------}
{ Clears the screen and prints out the error message "msg"
followed by up to "max" currently active return addresses. }
{ A check is made for hex 0000 to see if the bottom of the stack
is reached. The -4 is so that the address printed is the
beginning of the call instruction. }
procedure fatal(msg : sstring);
const max = 10; { Maximum number of addresses to print }
var i : integer;
begin
clrscr;
{ Print out error message }
writeln(con,'FATAL ERROR: '+msg);
{ Print out runtime stack }
write(con,'CUR ADDRS = [ ');
for i := 1 to max do
if returnaddress(i) <> 0000 then
begin
write(con,hex(returnaddress(i)-4),' ');
if i = max then write(con,'... ')
end;
writeln(con,']');
{ Sound the horn }
beep(3000,500);
{ Halt the program }
halt
end;