Skip to content

Commit 6d21e56

Browse files
v2.0
1 parent 205925d commit 6d21e56

5 files changed

Lines changed: 146 additions & 70 deletions

File tree

DEBUG.TXT

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@
858858
its tty i/o it calls out to the "loader" program, which is responsible to
859859
route those calls to the OS or handle them on its own.
860860

861-
Once loaded, DebugR can debug programs running in both ring-0 and ring-3
861+
Once loaded, DebugR can debug programs running in both ring-0 and ring-3
862862
protected-mode. Since it doesn't use DOS or BIOS, a few commands implemented
863863
in the standard Debug/X aren't available: DM, DX, L, N, Q, W, Xx. OTOH, DebugR
864864
has a few special commands:
@@ -874,14 +874,17 @@
874874

875875
Vectors that can be trapped are vectors 0, 1, 3, 6, 0Dh and 0Eh.
876876

877-
At the debugger prompt, when an address is to be parsed, the prefix '%' will
877+
At the debugger prompt, when an address is to be parsed, the prefix '%' will
878878
tell the debugger to interpret the following offset as linear address.
879+
For the a(ssemble and u(nassemble) commands, one may precede the segment part
880+
of the range argument with a '$' to make DebugR interpret it as real-mode
881+
address and translate the segment to a selector.
879882

880-
Some GPFs occuring in non-privileged code are not handled by DebugR: CLI/STI
883+
Some GPFs occuring in non-privileged code are not handled by DebugR: CLI/STI
881884
executed by programs with IOPL 0; trapped IN/INS/OUT/OUTS instructions; INT XX
882885
with DPL==0 in the IDT.
883886

884-
DebugR understand commandline option -m, that will instruct it to assume that
887+
DebugR understand commandline option -m, that will instruct it to assume that
885888
exception and IRQ vectors ( interrupts 08-0Fh ) do not overlap.
886889

887890

HISTORY.TXT

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -261,35 +261,37 @@
261261
intercepted protected-mode int 21h and refuses to quit.
262262
- another variant - DEBUGXV - may be created. It allows to flip video
263263
screen between debugger and debuggee.
264-
2.00 [3 December 2022]
265-
- ensure the correct video page is used when debugger has to display
266-
something if the InDOS flag is set AND page swapping is active.
267-
- DEBUGX: hook into protected-mode debug interface Int 41h and make
268-
debugger visible there.
269-
- DEBUGX: restore hooked protected-mode interrupts when client
270-
terminates.
271-
- DEBUGXV: break if SYSREQ is pressed.
264+
2.00 [5 December 2022]
272265
- fixed: routine int21ah9 did use DOS, even if InDos flag was set.
273-
- DEBUGX: added cmdline option /2.
274-
- mktables.c: fixed, didn't generate a valid debugtbl.inc.
275266
- fixed: reading stdin from file wasn't fully MS Debug compatible.
276-
- DI cmd may be activated for standard DEBUG.COM.
277-
- added a "boot" variant of the debugger - it's supposed to be loaded
278-
before DOS by boot loader code.
279267
- fixed: correctly handle tabs if output is via BIOS.
280-
- added a ring0 variant of the debugger - DebugR.bin.
268+
- fixed L/W cmds: error msg for read/write drive was crumbled since
269+
v1.18.
270+
- ensured the correct video page is used when debugger has to display
271+
something if the InDOS flag is set AND page swapping is active.
272+
- mktables.c fix: didn't generate a valid debugtbl.inc.
273+
- added a "boot" variant of the debugger - DebugB.bin.
274+
- added a ring0 (PL0) variant of the debugger - DebugR.bin.
275+
- DI cmd may be activated for standard DEBUG.COM.
276+
- DEBUGX fix: restore hooked protected-mode interrupts when client
277+
terminates.
281278
- DEBUGX fix: c & s cmds finally work with 32-bit offsets.
282279
- DEBUGX fix, e cmd: generate a GPF if no data alias can be found for
283280
a code segment ( instead of silently skip the write ).
284281
- DEBUGX fix: disassembly of [CS:IP] in register dump may have caused
285282
a GPF in debugger if the memory address was beyond seg limit - 3.
286-
- fix L/W cmds: error msg for read/write drive was crumbled since v1.18.
287-
- DEBUGX fix, g cmd: if multiple breakpoints with different segment parts
288-
were set in protected-mode, hazardous writes may have happened.
283+
- DEBUGX fix, g cmd: if multiple breakpoints with different segment
284+
parts were set in protected-mode, hazardous writes may have happened.
285+
- DEBUGX fix, m cmd: '$' qualifier for the source address segment was
286+
rejected.
287+
- DEBUGX fix, c & m cmds: if both source and destination segment parts
288+
were readonly, the scratch selector was used twice.
289+
- DEBUGX: added cmdline option /2.
290+
- DEBUGX: hook into protected-mode debug interface Int 41h and make
291+
debugger visible there.
289292
- DEBUGX, a & e cmd: usage of scratch descriptor for readonly segments
290293
now hidden, so the displayed address' segment part isn't changed.
291294
- DEBUGX, a & d cmd: default segments are no longer automatically
292295
converted to selectors during initial switch to protected-mode.
293-
- DEBUGX fix, m cmd: '$' qualifier for the source address segment was
294-
rejected.
295296
- DEBUGX: exceptions 0dh/0eh are set/reset on debugger entry/exit.
297+
- DEBUGXV: stop in debugger if SYSREQ is pressed.

src/DEBUG.ASM

Lines changed: 83 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -930,9 +930,13 @@ prompt1 db @CatStr(!',%PROMPT,!')
930930
else
931931
prompt1 db '-' ;main prompt
932932
endif
933+
933934
prompt2 db ':' ;prompt for register value
934-
if ?DPMI
935+
936+
if ?PM
937+
if ?DPMI
935938
db '!'
939+
endif
936940
prompt3 db '#' ;protected-mode prompt
937941
endif
938942

@@ -1388,19 +1392,6 @@ _DATA ends
13881392

13891393
endif
13901394

1391-
if EXCCSIP
1392-
_DATA segment
1393-
if EXCCSEIP
1394-
intexceip label dword
1395-
endif
1396-
intexcip dw 0 ;IP if internal exception
1397-
if EXCCSEIP
1398-
dw 0
1399-
endif
1400-
intexccs dw 0 ;CS if internal exception
1401-
_DATA ends
1402-
endif
1403-
14041395
if ?DPMI
14051396

14061397
intcall proto stdcall :word, :word
@@ -1911,10 +1902,14 @@ if LCMDFILE
19111902
@@:
19121903
endif
19131904
mov cx,1
1905+
ife ?PM
1906+
mov dx,offset prompt1
1907+
else
1908+
if ?DPMI
19141909
mov dx,offset prompt1
1915-
if ?DPMI
19161910
call ispm_dbe ; debuggee in rm/pm?
19171911
jz @F
1912+
endif
19181913
mov dx,offset prompt3
19191914
@@:
19201915
endif
@@ -5129,7 +5124,8 @@ endif
51295124
;--- E/SI=src offset, E/DX=end src
51305125

51315126
dd2:
5132-
mov [lastcmd],offset lastddd
5127+
; mov [lastcmd],offset lastddd
5128+
mov [lastcmd],offset d_cmd
51335129
call prephack ;set up for faking int vectors 23 and 24
51345130
dd_loop:
51355131
; mov ax,[d_addr+4]
@@ -5782,7 +5778,9 @@ if ?DPMI
57825778
pop dx ;get old MSW
57835779
endif
57845780

5781+
ife RING0
57855782
@dprintf "g_cmd: run returned, [spadjust]=%X, [spsav]=%lX", [spadjust], dword ptr ds:[SPSAV]
5783+
endif
57865784

57875785
if ?PM
57885786
call getcsattr
@@ -7178,6 +7176,36 @@ error:
71787176

71797177
IsWriteableBX endp
71807178

7179+
if RING0
7180+
7181+
;--- hack to make 'u' work with a real-mode segment
7182+
7183+
setscratchsel proc
7184+
pushad
7185+
mov bp, sp
7186+
sub sp, 6
7187+
sgdt [bp-6]
7188+
pop ax
7189+
pop eax
7190+
movzx ebx, [scratchsel]
7191+
add ebx, eax
7192+
movzx eax, word ptr [bp+5*4] ;get DX
7193+
shl eax, 4
7194+
push ds
7195+
mov ds, [wFlat]
7196+
mov word ptr [ebx+0], -1
7197+
mov word ptr [ebx+2], ax
7198+
shr eax, 16
7199+
mov byte ptr [ebx+4], al
7200+
mov word ptr [ebx+5], 9Bh
7201+
mov byte ptr [ebx+7], ah
7202+
pop ds
7203+
popad
7204+
mov bx, [scratchsel]
7205+
ret
7206+
setscratchsel endp
7207+
endif
7208+
71817209
if ?DPMI
71827210
setrmsegm:
71837211
.286
@@ -8183,7 +8211,8 @@ t_cmd proc
81838211
cmp ax,'tm'
81848212
jz tm_cmd
81858213
tt0:
8186-
mov [lastcmd], offset tt0
8214+
; mov [lastcmd], offset tt0
8215+
mov [lastcmd], offset t_cmd
81878216
call parse_pt ;process arguments
81888217
@@:
81898218
push cx
@@ -8365,8 +8394,9 @@ endif
83658394

83668395
trace1 endp
83678396

8368-
;--- test if memory at CS:E/IP can be written to
8397+
;--- test if memory at CS:E/IP can be written to.
83698398
;--- return C if not
8399+
;--- used by T cmd.
83708400
;--- IN: CX=offset for (E)IP
83718401

83728402
iswriteablecseip proc
@@ -8412,7 +8442,7 @@ ctos_1:
84128442
clear_tf_onstack endp
84138443

84148444
;--- Print message about unexpected interrupt, dump registers, and end
8415-
;--- command. This code is also used by the G and P commands.
8445+
;--- command. This code is used by G, P and T cmds.
84168446

84178447
ue_int:
84188448
mov dl, [run_int]
@@ -8427,17 +8457,21 @@ endif
84278457
@@:
84288458
jmp cmdloop ;back to the start
84298459

8460+
;--- "unexpected" exception in real-mode inside debugger
8461+
84308462
ife RING0
84318463
if CATCHINT07 or CATCHINT0C or CATCHINT0D
84328464
ue_intxx:
84338465
if EXCCSIP
8434-
pop cs:[intexcip]
8435-
pop cs:[intexccs]
8466+
pop cx
8467+
pop dx
84368468
endif
84378469
push cs
84388470
pop ss
84398471
mov sp,cs:[top_sp]
8440-
push ax
8472+
push cx ; ip
8473+
push dx ; cs
8474+
push ax ; msg
84418475

84428476
;--- fall thru
84438477

@@ -8447,8 +8481,8 @@ endif
84478481

84488482
if ?PM or CATCHINT07 or CATCHINT0C or CATCHINT0D
84498483

8450-
;--- unexpected exception occured inside debugger
8451-
;--- [SP] = msg
8484+
;--- "unexpected" exception occured inside debugger
8485+
;--- [SP] = msg, cs, [e]ip
84528486

84538487
ue_intx proc
84548488
cld
@@ -8472,15 +8506,15 @@ if EXCCSIP
84728506
mov di,offset line_out
84738507
mov si,offset excloc ; "CS:IP="
84748508
call copystring
8475-
mov ax, [intexccs]
8509+
pop ax
84768510
call hexword
84778511
mov al,':'
84788512
stosb
84798513
if EXCCSEIP
8480-
mov eax, [intexceip]
8514+
pop eax
84818515
call hexdword
84828516
else
8483-
mov ax, [intexcip]
8517+
pop ax
84848518
call hexword
84858519
endif
84868520
call putsline
@@ -8493,7 +8527,8 @@ endif
84938527
;--- U command - disassemble.
84948528

84958529
u_cmd proc
8496-
mov [lastcmd],offset lastuu
8530+
; mov [lastcmd],offset lastuu
8531+
mov [lastcmd],offset u_cmd
84978532
cmp al,CR
84988533
je lastuu ;if no address was given
84998534
sizeprfX ;xor ecx, ecx
@@ -10685,8 +10720,9 @@ glfbx_2:
1068510720
getlenforbx endp
1068610721

1068710722
; getrange - Get address range from input line.
10688-
; a range consists of either start and end address
10689-
; or a start address, a 'L' and a length.
10723+
; a range consists of:
10724+
; 1. a start address: [segment:]start-offset
10725+
; 2. an end-offset or a 'L' followed by a length.
1069010726
; Entry AL First character of range
1069110727
; SI Address of next character
1069210728
; BX Default segment to use
@@ -10801,6 +10837,23 @@ if ?PM
1080110837
mov bx, cs:[wFlat]
1080210838
jmp ga3
1080310839
@@:
10840+
;--- hack for a/u cmds: allow to enter a real-mode address.
10841+
;--- since the debugger cannot handle v86-mode exceptions yet,
10842+
;--- this hack allows to at least (dis)assemble real-mode code parts.
10843+
cmp al, '$'
10844+
jnz normseg
10845+
cmp [lastcmd], offset u_cmd ; u cmd?
10846+
jz @F
10847+
cmp [errret], offset cmdloop; a cmd?
10848+
jz normseg
10849+
@@:
10850+
lodsb
10851+
call getword
10852+
cmp al,':'
10853+
jnz errorj2
10854+
call setscratchsel ; set BX to scratchsel
10855+
jmp ga3
10856+
normseg:
1080410857
endif
1080510858
endif
1080610859
call getofsforbx

src/TRAPD.INC

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ excxx_16:
4646
cmp [bInDbg],0 ;did the exception occur inside DEBUG?
4747
jz isdebuggee16
4848
if EXCCSIP
49-
mov [intexcip], ax
50-
mov [intexccs], bx
49+
mov si, bx
5150
endif
5251
mov [bp].EXFR16.rIP,offset ue_intx
5352
mov bx, [top_sp]
54-
sub bx, 2
55-
mov [bx], di
53+
sub bx, 3*2
54+
mov [bx+0], di
55+
if EXCCSIP
56+
mov [bx+2], si
57+
mov [bx+4], ax
58+
endif
5659
mov [bp].EXFR16.rSP, bx
5760
and byte ptr [bp].EXFR16.rFL+1, not 1 ;reset TF
5861
pop ax
@@ -128,19 +131,30 @@ exc_xx:
128131
if EXCCSIP
129132
;--- it's assumed that an exception in DEBUG is always in 16-bit code,
130133
;--- but this isn't necessarily true, since the debuggee may have hooked
131-
;--- exceptions. Since v2.0, this is less probably, because DebugX will
134+
;--- exceptions. Since v2.0, this is less probable, because DebugX will
132135
;--- always restore exception handlers 0D/0E on entry.
133-
if EXCCSEIP
134-
mov [intexceip], eax
135-
else
136-
mov [intexcip], ax
137-
endif
138-
mov [intexccs], bx
136+
mov si, bx
139137
endif
140138
mov [ebp].EXFR32.rEIP,offset ue_intx
141139
movzx ebx,[top_sp]
140+
if EXCCSIP
141+
if EXCCSEIP
142+
sub bx, 2*2+4
143+
else
144+
sub bx, 3*2
145+
endif
146+
else
142147
sub bx, 2
143-
mov [bx], di
148+
endif
149+
mov [bx+0], di ; msg
150+
if EXCCSIP
151+
mov [bx+2], si ; cs
152+
if EXCCSEIP
153+
mov [bx+4], eax
154+
else
155+
mov [bx+4], ax
156+
endif
157+
endif
144158
mov [ebp].EXFR32.rESP, ebx
145159
and byte ptr [ebp].EXFR32.rEFL+1, not 1 ;reset TF
146160
pop ax

0 commit comments

Comments
 (0)