MTDBG 0.34: support for .map symbols file (such as generated by GCC), some GUI enhancements.

git-svn-id: svn://kolibrios.org@4886 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2014-04-23 19:59:17 +00:00
parent 11b7b3cd30
commit 113812d57f
3 changed files with 668 additions and 609 deletions

View File

@ -4,10 +4,10 @@
macro DrawRectangle x, y, w, h, color macro DrawRectangle x, y, w, h, color
{ {
mcall 13, x shl 16 + w, y shl 16 + 1, color ; top mcall 13, x shl 16 + w, y shl 16 + 1, color ; top
mcall , x shl 16 + 1, y shl 16 + h, color ; left mcall , x shl 16 + 1, y shl 16 + h, color ; left
mcall , (x+w) shl 16 +1, y shl 16 + (h+1), color ; right mcall , (x+w) shl 16 +1, y shl 16 + (h+1), color ; right
mcall , x shl 16 + w, (y+h) shl 16 + 1, color ; bottom mcall , x shl 16 + w, (y+h) shl 16 + 1, color ; bottom
} }
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
@ -27,7 +27,10 @@ if COLOR_THEME eq MOVIEOS
COLOR_TXT_NORMAL = 0xffffff COLOR_TXT_NORMAL = 0xffffff
COLOR_TXT_INACTIVE = 0x8f7948 COLOR_TXT_INACTIVE = 0x8f7948
COLOR_TXT_CHANGED = 0xec9300 COLOR_TXT_CHANGED = 0xec9300
COLOR_TXT_LABEL = 0x22b14c
COLOR_TXT_SELECTED = 0x1d272f COLOR_TXT_SELECTED = 0x1d272f
COLOR_TXT_ADDR = 0xec9300
COLOR_TXT_BREAKPOINT = 0xec9300
else if COLOR_THEME eq WHITE_ON_BLACK else if COLOR_THEME eq WHITE_ON_BLACK
@ -38,7 +41,10 @@ else if COLOR_THEME eq WHITE_ON_BLACK
COLOR_TXT_NORMAL = 0xFFFFFF ; white COLOR_TXT_NORMAL = 0xFFFFFF ; white
COLOR_TXT_INACTIVE = 0x808080 ; grey COLOR_TXT_INACTIVE = 0x808080 ; grey
COLOR_TXT_CHANGED = 0x00AA00 ; green COLOR_TXT_CHANGED = 0x00AA00 ; green
COLOR_TXT_LABEL = COLOR_TXT_NORMAL
COLOR_TXT_SELECTED = 0xFFFFFF ; white COLOR_TXT_SELECTED = 0xFFFFFF ; white
COLOR_TXT_ADDR = COLOR_TXT_NORMAL
COLOR_TXT_BREAKPOINT = COLOR_TXT_NORMAL
else ; BLACK ON WHITE else ; BLACK ON WHITE
@ -49,7 +55,10 @@ else ; BLACK ON WHITE
COLOR_TXT_NORMAL = 0x000000 ; black COLOR_TXT_NORMAL = 0x000000 ; black
COLOR_TXT_INACTIVE = 0x808080 ; grey COLOR_TXT_INACTIVE = 0x808080 ; grey
COLOR_TXT_CHANGED = 0x00AA00 ; green COLOR_TXT_CHANGED = 0x00AA00 ; green
COLOR_TXT_LABEL = COLOR_TXT_NORMAL
COLOR_TXT_SELECTED = 0xFFFFFF ; white COLOR_TXT_SELECTED = 0xFFFFFF ; white
COLOR_TXT_ADDR = COLOR_TXT_NORMAL
COLOR_TXT_BREAKPOINT = COLOR_TXT_NORMAL
end if end if
@ -1309,7 +1318,7 @@ draw_disasm:
sub esi, edx sub esi, edx
; normal color ; normal color
; was 0x40000000 ; was 0x40000000
mov ecx, (COLOR_TXT_NORMAL or 0x40000000) mov ecx, (COLOR_TXT_LABEL or 0x40000000)
mov al, 4 mov al, 4
; draw a text string in the window with color COLOR_TXT_NORMAL in ecx ; draw a text string in the window with color COLOR_TXT_NORMAL in ecx
mcall mcall
@ -1337,11 +1346,8 @@ draw_disasm:
call disasm_instr call disasm_instr
pop ebp pop ebp
jc .loopend jc .loopend
; setting up colors
; was 'xor esi, esi' - default color: black
mov esi, COLOR_TXT_NORMAL
; was 0xFFFFFF - default background: white
mov edx, COLOR_BG_NORMAL mov edx, COLOR_BG_NORMAL
mov esi, COLOR_TXT_NORMAL
mov ebx, data_x_pos*10000h + data_x_size mov ebx, data_x_pos*10000h + data_x_size
mov ecx, [disasm_cur_str] mov ecx, [disasm_cur_str]
imul ecx, 10*10000h imul ecx, 10*10000h
@ -1350,27 +1356,19 @@ draw_disasm:
pushad pushad
call find_enabled_breakpoint call find_enabled_breakpoint
popad popad
jnz .nored jnz .nobp
; setting up background color for breakpoint
; was 0xFF0000 - red
mov edx, COLOR_BG_BREAKPOINT mov edx, COLOR_BG_BREAKPOINT
mov esi, COLOR_TXT_BREAKPOINT
.nobp:
.nored:
mov eax, [_eip] mov eax, [_eip]
cmp eax, ebp cmp eax, ebp
jnz .noblue jnz .notcurrent
; setting up background color for selected text
; (current running instruction)
; was 0x0000FF - blue
mov edx, COLOR_BG_SELECTED mov edx, COLOR_BG_SELECTED
; setting up selected text color
; (current running instruction)
; was 0xFFFFFF - white
mov esi, COLOR_TXT_SELECTED mov esi, COLOR_TXT_SELECTED
.notcurrent:
push esi ; Save color value for disassembled text
.noblue:
;push 13
;pop eax
; draw container rectangle/box for disassembled text ; draw container rectangle/box for disassembled text
; color in edx ; color in edx
mcall 13 mcall 13
@ -1384,24 +1382,26 @@ draw_disasm:
mcall 47, 80100h, ebp mcall 47, 80100h, ebp
;mov al, 4 ;mov al, 4
lea ebx, [edx+8*6*10000h] lea ebx, [edx+8*6*10000h]
; copy color value from esi mov ecx, esi ; text color
mov ecx, esi
push 2 push 2
pop esi pop esi
mov edx, aColon mov edx, aColon
; draw a text string in the window, color in ecx ; draw the colon
mcall 4 mcall 4
push 9 push 9
pop edi pop edi
lea edx, [ebx+2*6*10000h] lea edx, [ebx+2*6*10000h]
mov esi, ecx
mov ecx, ebp mov ecx, ebp
sub ecx, [disasm_start_pos] sub ecx, [disasm_start_pos]
add ecx, disasm_buffer add ecx, disasm_buffer
mov esi, COLOR_TXT_ADDR
mov eax, [_eip]
cmp eax, ebp
jnz @f
mov esi, COLOR_TXT_SELECTED
@@:
.drawhex: .drawhex:
;mov al, 47
;mov ebx, 20101h
; draw a number in the window, color in esi ; draw a number in the window, color in esi
mcall 47, 20101h mcall 47, 20101h
add edx, 6*3*10000h add edx, 6*3*10000h
@ -1426,10 +1426,9 @@ draw_disasm:
mov edx, aDots mov edx, aDots
; draw a text string in the window, color in ecx ; draw a text string in the window, color in ecx
mcall 4 mcall 4
; copy color value from ecx
mov esi, ecx
.hexdone: .hexdone:
pop esi
xor eax, eax xor eax, eax
mov edi, disasm_string mov edi, disasm_string
mov edx, edi mov edx, edi
@ -1609,7 +1608,7 @@ draw_window:
mcall mcall
; registers frame ; registers frame
DrawRectangle (registers_x_pos-2), (registers_y_pos-2), (registers_x_size+3), (registers_y_size+3), COLOR_LINE DrawRectangle (registers_x_pos-2), (registers_y_pos-2), (registers_x_size+3), (registers_y_size+3), COLOR_LINE
; draw container rectangle/box for registers information window region ; draw container rectangle/box for registers information window region
; messages ; messages

View File

@ -1,4 +1,4 @@
COLOR_THEME equ BLACK_ON_WHITE COLOR_THEME fix BLACK_ON_WHITE
format binary as "" format binary as ""
@ -301,12 +301,20 @@ do_reload:
mov ecx, edi mov ecx, edi
@@: @@:
mov dword [ecx], '.dbg' mov dword[ecx], '.dbg'
mov byte [ecx+4], 0 mov byte[ecx+4], 0
pop esi pop esi
mov ebp, esi mov ebp, esi
push ecx esi
call OnLoadSymbols.silent ; Try to load .dbg file
pop esi ecx
xor eax, eax
cmp [num_symbols], eax
jne @f
mov dword[ecx], '.map' ; If failed, try .map file too
call OnLoadSymbols.silent call OnLoadSymbols.silent
@@:
; now test for packed progs ; now test for packed progs
cmp [disasm_buf_size], 100h cmp [disasm_buf_size], 100h
jz @f jz @f
@ -1941,411 +1949,9 @@ OnUnpack:
jmp .x1 jmp .x1
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
; Working with program symbols ; Include Symbol parser
;
; TODO: split to symbols.inc
include 'sort.inc' include 'symbols.inc'
; compare what? Add context-relative comment and name
compare:
cmpsd
jnz @f
cmp esi, edi
@@:
ret
; purpose of this function?
compare2:
cmpsd
@@:
cmpsb
jnz @f
cmp byte [esi-1], 0
jnz @b
cmp esi, edi
@@:
ret
free_symbols:
mov ecx, [symbols]
jecxz @f
mcall 68, 13
and [symbols], 0
and [num_symbols], 0
@@:
ret
;-----------------------------------------------------------------------------
; Load symbols event
OnLoadSymbols.fileerr:
test ebp, ebp
jz @f
mcall 68, 13, edi
ret
@@:
push eax
mcall 68, 13, edi
mov esi, aCannotLoadFile
call put_message_nodraw
pop eax
cmp eax, 0x20
jae .unk
mov esi, [load_err_msgs + eax*4]
test esi, esi
jnz put_message
.unk:
mov esi, unk_err_msg2
jmp put_message
OnLoadSymbols:
xor ebp, ebp
; load input file
mov esi, [curarg]
call free_symbols
.silent:
xor edi, edi
cmp [num_symbols], edi
jz @f
call free_symbols
;ret
@@:
mov ebx, fn70_attr_block
mov [ebx+21], esi
mcall 70
test eax, eax
jnz .fileerr
cmp dword [fileattr+36], edi
jnz .memerr
mov ecx, dword [fileattr+32]
mcall 68, 12
test eax, eax
jz .memerr
mov edi, eax
mov ebx, fn70_read_block
mov [ebx+12], ecx
mov [ebx+16], edi
mov [ebx+21], esi
mcall 70
test eax, eax
jnz .fileerr
; calculate memory requirements
lea edx, [ecx+edi-1] ; edx = EOF-1
mov esi, edi
xor ecx, ecx
.calcloop:
cmp esi, edx
jae .calcdone
cmp word [esi], '0x'
jnz .skipline
inc esi
inc esi
@@:
cmp esi, edx
jae .calcdone
lodsb
or al, 20h
sub al, '0'
cmp al, 9
jbe @b
sub al, 'a'-'0'-10
cmp al, 15
jbe @b
dec esi
@@:
cmp esi, edx
ja .calcdone
lodsb
cmp al, 20h
jz @b
jb .calcloop
cmp al, 9
jz @b
add ecx, 12+1
inc [num_symbols]
@@:
inc ecx
cmp esi, edx
ja .calcdone
lodsb
cmp al, 0xD
jz .calcloop
cmp al, 0xA
jz .calcloop
jmp @b
.skipline:
cmp esi, edx
jae .calcdone
lodsb
cmp al, 0xD
jz .calcloop
cmp al, 0xA
jz .calcloop
jmp .skipline
.calcdone:
mcall 68, 12
test eax, eax
jnz .memok
inc ebx
mov ecx, edi
mov al, 68
mcall
.memerr:
mov esi, aNoMemory
jmp put_message
.memok:
mov [symbols], eax
mov ebx, eax
push edi
mov esi, edi
mov edi, [num_symbols]
lea ebp, [eax+edi*4]
lea edi, [eax+edi*8]
; parse input data,
; esi->input, edx->EOF, ebx->ptrs, edi->names
.readloop:
cmp esi, edx
jae .readdone
cmp word [esi], '0x'
jnz .readline
inc esi
inc esi
xor eax, eax
xor ecx, ecx
@@:
shl ecx, 4
add ecx, eax
cmp esi, edx
jae .readdone
lodsb
or al, 20h
sub al, '0'
cmp al, 9
jbe @b
sub al, 'a'-'0'-10
cmp al, 15
jbe @b
dec esi
@@:
cmp esi, edx
ja .readdone
lodsb
cmp al, 20h
jz @b
jb .readloop
cmp al, 9
jz @b
mov dword [ebx], edi
add ebx, 4
mov dword [ebp], edi
add ebp, 4
mov dword [edi], ecx
add edi, 4
stosb
@@:
xor eax, eax
stosb
cmp esi, edx
ja .readdone
lodsb
cmp al, 0xD
jz .readloop
cmp al, 0xA
jz .readloop
mov byte [edi-1], al
jmp @b
.readline:
cmp esi, edx
jae .readdone
lodsb
cmp al, 0xD
jz .readloop
cmp al, 0xA
jz .readloop
jmp .readline
.readdone:
pop ecx
mcall 68, 13
mov ecx, [num_symbols]
mov edx, [symbols]
mov ebx, compare
call sort
mov ecx, [num_symbols]
lea edx, [edx+ecx*4]
mov ebx, compare2
call sort
mov esi, aSymbolsLoaded
call put_message
jmp draw_disasm.redraw
;-----------------------------------------------------------------------------
;
; in: EAX = address
; out: ESI, CF
find_symbol:
cmp [num_symbols], 0
jnz @f
.ret0:
xor esi, esi
stc
ret
@@:
push ebx ecx edx
xor edx, edx
mov esi, [symbols]
mov ecx, [num_symbols]
mov ebx, [esi]
cmp [ebx], eax
jz .donez
jb @f
pop edx ecx ebx
jmp .ret0
@@:
; invariant: symbols_addr[edx] < eax < symbols_addr[ecx]
; TODO: add meaningful label names
.0:
push edx
.1:
add edx, ecx
sar edx, 1
cmp edx, [esp]
jz .done2
mov ebx, [esi+edx*4]
cmp [ebx], eax
jz .done
ja .2
mov [esp], edx
jmp .1
.2:
mov ecx, edx
pop edx
jmp .0
.donecont:
dec edx
.done:
test edx, edx
jz @f
mov ebx, [esi+edx*4-4]
cmp [ebx], eax
jz .donecont
@@:
pop ecx
.donez:
mov esi, [esi+edx*4]
add esi, 4
pop edx ecx ebx
clc
ret
.done2:
lea esi, [esi+edx*4]
pop ecx edx ecx ebx
stc
ret
;-----------------------------------------------------------------------------
;
; in: esi->name
; out: if found: CF = 0, EAX = value
; otherwise CF = 1
find_symbol_name:
cmp [num_symbols], 0
jnz @f
.stc_ret:
stc
ret
@@:
push ebx ecx edx edi
push -1
pop edx
mov ebx, [symbols]
mov ecx, [num_symbols]
lea ebx, [ebx+ecx*4]
; invariant: symbols_name[edx] < name < symbols_name[ecx]
.0:
push edx
.1:
add edx, ecx
sar edx, 1
cmp edx, [esp]
jz .done2
call .cmp
jz .done
jb .2
mov [esp], edx
jmp .1
.2:
mov ecx, edx
pop edx
jmp .0
.done:
pop ecx
.donez:
mov eax, [ebx+edx*4]
mov eax, [eax]
pop edi edx ecx ebx
clc
ret
.done2:
pop edx edi edx ecx ebx
stc
ret
.cmp:
mov edi, [ebx+edx*4]
push esi
add edi, 4
@@:
cmpsb
jnz @f
cmp byte [esi-1], 0
jnz @b
@@:
pop esi
ret
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
; Include disassembler engine ; Include disassembler engine
@ -2356,10 +1962,9 @@ include 'disasm.inc'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
caption_str db 'Kolibri Debugger',0 caption_str db 'Kolibri Debugger',0
caption_len = $ - caption_str
begin_str db 'Kolibri Debugger, version 0.33',10 begin_str db 'Kolibri Debugger, version 0.34',10
db 'Hint: type "help" for help, "quit" to quit' db 'Hint: type "help" for help, "quit" to quit'
newline db 10,0 newline db 10,0
prompt db '> ',0 prompt db '> ',0
@ -2682,209 +2287,212 @@ flags_bits db 0,2,4,6,7,10,11
; Registers strings ; Registers strings
regs_strs: regs_strs:
db 'EAX=' db 'EAX='
db 'EBX=' db 'EBX='
db 'ECX=' db 'ECX='
db 'EDX=' db 'EDX='
db 'ESI=' db 'ESI='
db 'EDI=' db 'EDI='
db 'EBP=' db 'EBP='
db 'ESP=' db 'ESP='
db 'EIP=' db 'EIP='
db 'EFLAGS=' db 'EFLAGS='
fpu_strs:
db 'ST0='
db 'ST1='
db 'ST2='
db 'ST3='
db 'ST4='
db 'ST5='
db 'ST6='
db 'ST7='
mmx_strs:
db 'MM0='
db 'MM1='
db 'MM2='
db 'MM3='
db 'MM4='
db 'MM5='
db 'MM6='
db 'MM7='
sse_strs:
db '-XMM0-'
db '-XMM1-'
db '-XMM2-'
db '-XMM3-'
db '-XMM4-'
db '-XMM5-'
db '-XMM6-'
db '-XMM7-'
avx_strs:
db '-YMM0-'
db '-YMM1-'
db '-YMM2-'
db '-YMM3-'
db '-YMM4-'
db '-YMM5-'
db '-YMM6-'
db '-YMM7-'
debuggee_pid dd 0 fpu_strs:
bSuspended db 0 db 'ST0='
bAfterGo db 0 db 'ST1='
temp_break dd 0 db 'ST2='
reg_mode db 1 db 'ST3='
db 'ST4='
db 'ST5='
db 'ST6='
db 'ST7='
mmx_strs:
db 'MM0='
db 'MM1='
db 'MM2='
db 'MM3='
db 'MM4='
db 'MM5='
db 'MM6='
db 'MM7='
sse_strs:
db '-XMM0-'
db '-XMM1-'
db '-XMM2-'
db '-XMM3-'
db '-XMM4-'
db '-XMM5-'
db '-XMM6-'
db '-XMM7-'
avx_strs:
db '-YMM0-'
db '-YMM1-'
db '-YMM2-'
db '-YMM3-'
db '-YMM4-'
db '-YMM5-'
db '-YMM6-'
db '-YMM7-'
debuggee_pid dd 0
bSuspended db 0
bAfterGo db 0
temp_break dd 0
reg_mode db 1
include 'disasm_tbl.inc' include 'disasm_tbl.inc'
reg_table: reg_table:
db 2,'al',0 db 2,'al',0
db 2,'cl',1 db 2,'cl',1
db 2,'dl',2 db 2,'dl',2
db 2,'bl',3 db 2,'bl',3
db 2,'ah',4 db 2,'ah',4
db 2,'ch',5 db 2,'ch',5
db 2,'dh',6 db 2,'dh',6
db 2,'bh',7 db 2,'bh',7
db 2,'ax',8 db 2,'ax',8
db 2,'cx',9 db 2,'cx',9
db 2,'dx',10 db 2,'dx',10
db 2,'bx',11 db 2,'bx',11
db 2,'sp',12 db 2,'sp',12
db 2,'bp',13 db 2,'bp',13
db 2,'si',14 db 2,'si',14
db 2,'di',15 db 2,'di',15
db 3,'eax',16 db 3,'eax',16
db 3,'ecx',17 db 3,'ecx',17
db 3,'edx',18 db 3,'edx',18
db 3,'ebx',19 db 3,'ebx',19
db 3,'esp',20 db 3,'esp',20
db 3,'ebp',21 db 3,'ebp',21
db 3,'esi',22 db 3,'esi',22
db 3,'edi',23 db 3,'edi',23
db 3,'eip',24 db 3,'eip',24
db 0 db 0
IncludeIGlobals IncludeIGlobals
fn70_read_block: fn70_read_block:
dd 0 dd 0
dq 0 dq 0
dd ? dd ?
dd ? dd ?
db 0 db 0
dd ? dd ?
fn70_attr_block: fn70_attr_block:
dd 5 dd 5
dd 0,0,0 dd 0,0,0
dd fileattr dd fileattr
db 0 db 0
dd ? dd ?
fn70_load_block: fn70_load_block:
dd 7 dd 7
dd 1 dd 1
load_params dd 0 load_params dd 0
dd 0 dd 0
dd 0 dd 0
i_end: i_end:
loadname: loadname:
db 0 db 0
rb 255 rb 255
symbolsfile rb 260 symbolsfile rb 260
prgname_ptr dd ? prgname_ptr dd ?
prgname_len dd ? prgname_len dd ?
IncludeUGlobals IncludeUGlobals
dbgwnd dd ? dbgwnd dd ?
messages rb messages_height*messages_width messages rb messages_height*messages_width
messages_pos dd ? messages_pos dd ?
cmdline rb cmdline_width+1 cmdline rb cmdline_width+1
cmdline_len dd ? cmdline_len dd ?
cmdline_pos dd ? cmdline_pos dd ?
curarg dd ? curarg dd ?
cmdline_prev rb cmdline_width+1 cmdline_prev rb cmdline_width+1
was_temp_break db ? was_temp_break db ?
symbol_section db ?
dbgbufsize dd ? dbgbufsize dd ?
dbgbuflen dd ? dbgbuflen dd ?
dbgbuf rb 256 dbgbuf rb 256
fileattr rb 40 fileattr rb 40
needzerostart: needzerostart:
context: context:
_eip dd ? _eip dd ?
_eflags dd ? _eflags dd ?
_eax dd ? _eax dd ?
_ecx dd ? _ecx dd ?
_edx dd ? _edx dd ?
_ebx dd ? _ebx dd ?
_esp dd ? _esp dd ?
_ebp dd ? _ebp dd ?
_esi dd ? _esi dd ?
_edi dd ? _edi dd ?
oldcontext rb $-context oldcontext rb $-context
mmx_context: mmx_context:
_mm0 dq ? _mm0 dq ?
_mm1 dq ? _mm1 dq ?
_mm2 dq ? _mm2 dq ?
_mm3 dq ? _mm3 dq ?
_mm4 dq ? _mm4 dq ?
_mm5 dq ? _mm5 dq ?
_mm6 dq ? _mm6 dq ?
_mm7 dq ? _mm7 dq ?
oldmmxcontext rb $-mmx_context oldmmxcontext rb $-mmx_context
fpu_context: fpu_context:
_st0 dq ? _st0 dq ?
_st1 dq ? _st1 dq ?
_st2 dq ? _st2 dq ?
_st3 dq ? _st3 dq ?
_st4 dq ? _st4 dq ?
_st5 dq ? _st5 dq ?
_st6 dq ? _st6 dq ?
_st7 dq ? _st7 dq ?
oldfpucontext rb $-fpu_context oldfpucontext rb $-fpu_context
sse_context: sse_context:
_xmm0 dq 2 dup ? _xmm0 dq 2 dup ?
_xmm1 dq 2 dup ? _xmm1 dq 2 dup ?
_xmm2 dq 2 dup ? _xmm2 dq 2 dup ?
_xmm3 dq 2 dup ? _xmm3 dq 2 dup ?
_xmm4 dq 2 dup ? _xmm4 dq 2 dup ?
_xmm5 dq 2 dup ? _xmm5 dq 2 dup ?
_xmm6 dq 2 dup ? _xmm6 dq 2 dup ?
_xmm7 dq 2 dup ? _xmm7 dq 2 dup ?
oldssecontext rb $-sse_context oldssecontext rb $-sse_context
avx_context: avx_context:
_ymm0 dq 4 dup ? _ymm0 dq 4 dup ?
_ymm1 dq 4 dup ? _ymm1 dq 4 dup ?
_ymm2 dq 4 dup ? _ymm2 dq 4 dup ?
_ymm3 dq 4 dup ? _ymm3 dq 4 dup ?
_ymm4 dq 4 dup ? _ymm4 dq 4 dup ?
_ymm5 dq 4 dup ? _ymm5 dq 4 dup ?
_ymm6 dq 4 dup ? _ymm6 dq 4 dup ?
_ymm7 dq 4 dup ? _ymm7 dq 4 dup ?
oldavxcontext rb $-avx_context oldavxcontext rb $-avx_context
step_num dd 0 step_num dd 0
proc_num dd 0 proc_num dd 0
dumpread dd ? dumpread dd ?
dumppos dd ? dumppos dd ?
dumpdata rb dump_height*10h dumpdata rb dump_height*10h
; breakpoint structure: ; breakpoint structure:
; dword +0: address ; dword +0: address
@ -2896,25 +2504,25 @@ dumpdata rb dump_height*10h
; byte +5: overwritten byte ; byte +5: overwritten byte
; for DRx breaks: flags + (index shl 6) ; for DRx breaks: flags + (index shl 6)
breakpoints_n = 256 breakpoints_n = 256
breakpoints rb breakpoints_n*6 breakpoints rb breakpoints_n*6
drx_break rd 4 drx_break rd 4
disasm_buf_size dd ? disasm_buf_size dd ?
symbols dd ? symbols dd ?
num_symbols dd ? num_symbols dd ?
bReload db ? bReload db ?
needzeroend: needzeroend:
disasm_buffer rb 256 disasm_buffer rb 256
disasm_start_pos dd ? disasm_start_pos dd ?
disasm_cur_pos dd ? disasm_cur_pos dd ?
disasm_cur_str dd ? disasm_cur_str dd ?
disasm_string rb 256 disasm_string rb 256
i_param rb 256 i_param rb 256
; stack ; stack
align 400h align 400h

View File

@ -0,0 +1,452 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;; Working with program symbols ;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
include 'sort.inc'
; compare proc for sorter
compare:
cmpsd
jnz @f
cmp esi, edi
@@:
ret
; compare proc for sorter 2
compare2:
cmpsd
@@:
cmpsb
jnz @f
cmp byte [esi-1], 0
jnz @b
cmp esi, edi
@@:
ret
free_symbols:
mov ecx, [symbols]
jecxz @f
mcall 68, 13
and [symbols], 0
and [num_symbols], 0
@@:
ret
;-----------------------------------------------------------------------------
; Load symbols event
OnLoadSymbols.fileerr:
test ebp, ebp
jz @f
mcall 68, 13, edi
ret
@@:
push eax
mcall 68, 13, edi
mov esi, aCannotLoadFile
call put_message_nodraw
pop eax
cmp eax, 0x20
jae .unk
mov esi, [load_err_msgs + eax*4]
test esi, esi
jnz put_message
.unk:
mov esi, unk_err_msg2
jmp put_message
OnLoadSymbols:
xor ebp, ebp
; load input file
mov esi, [curarg]
call free_symbols
.silent:
; esi = ptr to symbols filename
xor edi, edi
cmp [num_symbols], edi ; Any previously loaded symbols?
je .loadfile
call free_symbols ; Yep, free them
.loadfile:
mov ebx, fn70_attr_block ; Get file attributes
mov [ebx+21], esi
mcall 70
test eax, eax
jnz .fileerr
cmp dword [fileattr+36], edi ; Is upper dword of filesize larger then 0?
jnz .memerr
mov ecx, dword [fileattr+32] ; Lower dword of filesize
mcall 68, 12 ; allocate the memory
test eax, eax
jz .memerr
mov edi, eax
mov ebx, fn70_read_block
mov [ebx+12], ecx
mov [ebx+16], edi
mov [ebx+21], esi
mcall 70 ; Read the file into the allocated buffer
test eax, eax
jnz .fileerr
; calculate memory requirements to load debug symbols
lea edx, [ecx+edi-1] ; edx = EOF-1
mov esi, edi
xor ecx, ecx
mov [symbol_section], 1 ;;;;;
.calcloop:
cmp esi, edx
jae .calcdone
cmp byte[esi], ' ' ; skip spaces at the beginning of a line
jne .not_space
inc esi
jmp .calcloop
.not_space:
cmp byte[esi], '.'
jne .not_section
inc esi
mov [symbol_section], 0
cmp dword[esi], 'text'
jne .skipline
inc [symbol_section]
jmp .skipline
.not_section:
cmp [symbol_section], 0
je .skipline
cmp word[esi], '0x'
jne .skipline
inc esi
inc esi
@@:
cmp esi, edx
jae .calcdone
lodsb
or al, 20h
sub al, '0'
cmp al, 9
jbe @b
sub al, 'a'-'0'-10
cmp al, 15
jbe @b
dec esi
@@:
cmp esi, edx
ja .calcdone
lodsb
cmp al, 20h
je @b
jb .calcloop
cmp al, 9
jz @b
add ecx, 12+1
inc [num_symbols]
@@:
inc ecx
cmp esi, edx
ja .calcdone
lodsb
cmp al, 0xD
jz .calcloop
cmp al, 0xA
jz .calcloop
jmp @b
.skipline:
cmp esi, edx
jae .calcdone
lodsb
cmp al, 0xD
jz .calcloop
cmp al, 0xA
jz .calcloop
jmp .skipline
.calcdone:
; Allocate memory to place the debug symbols in
mcall 68, 12
test eax, eax
jnz .memok
inc ebx
mov ecx, edi
mov al, 68
mcall
.memerr:
mov esi, aNoMemory
jmp put_message
.memok:
mov [symbols], eax
mov ebx, eax
push edi
mov esi, edi
mov edi, [num_symbols]
lea ebp, [eax+edi*4]
lea edi, [eax+edi*8]
; Actual loading of the debug symbols
; esi->input, edx->EOF, ebx->ptrs, edi->names
mov [symbol_section], 1 ;;;;;
.readloop:
cmp esi, edx
jae .readdone
cmp byte[esi], ' '
jne .not_space2
inc esi
jmp .readloop
.not_space2:
cmp byte[esi], '.'
jne .not_section2
inc esi
mov [symbol_section], 0
cmp dword[esi], 'text'
jne .readline
inc [symbol_section]
jmp .readline
.not_section2:
cmp [symbol_section], 0
je .readline
cmp word[esi], '0x'
jnz .readline
inc esi
inc esi
xor eax, eax
xor ecx, ecx
@@:
shl ecx, 4
add ecx, eax
cmp esi, edx
jae .readdone
lodsb
or al, 20h
sub al, '0'
cmp al, 9
jbe @b
sub al, 'a'-'0'-10
cmp al, 15
jbe @b
dec esi
@@:
cmp esi, edx
ja .readdone
lodsb
cmp al, 20h
jz @b
jb .readloop
cmp al, 9
jz @b
mov dword [ebx], edi
add ebx, 4
mov dword [ebp], edi
add ebp, 4
mov dword [edi], ecx
add edi, 4
stosb
@@:
xor eax, eax
stosb
cmp esi, edx
ja .readdone
lodsb
cmp al, 0xD
jz .readloop
cmp al, 0xA
jz .readloop
mov byte [edi-1], al
jmp @b
.readline:
cmp esi, edx
jae .readdone
lodsb
cmp al, 0xD
jz .readloop
cmp al, 0xA
jz .readloop
jmp .readline
.readdone:
pop ecx
mcall 68, 13
mov ecx, [num_symbols]
mov edx, [symbols]
mov ebx, compare
call sort
mov ecx, [num_symbols]
lea edx, [edx+ecx*4]
mov ebx, compare2
call sort
mov esi, aSymbolsLoaded
call put_message
jmp draw_disasm.redraw
;-----------------------------------------------------------------------------
;
; in: EAX = address
; out: ESI, CF
find_symbol:
cmp [num_symbols], 0
jnz @f
.ret0:
xor esi, esi
stc
ret
@@:
push ebx ecx edx
xor edx, edx
mov esi, [symbols]
mov ecx, [num_symbols]
mov ebx, [esi]
cmp [ebx], eax
jz .donez
jb @f
pop edx ecx ebx
jmp .ret0
@@:
; invariant: symbols_addr[edx] < eax < symbols_addr[ecx]
; TODO: add meaningful label names
.0:
push edx
.1:
add edx, ecx
sar edx, 1
cmp edx, [esp]
jz .done2
mov ebx, [esi+edx*4]
cmp [ebx], eax
jz .done
ja .2
mov [esp], edx
jmp .1
.2:
mov ecx, edx
pop edx
jmp .0
.donecont:
dec edx
.done:
test edx, edx
jz @f
mov ebx, [esi+edx*4-4]
cmp [ebx], eax
jz .donecont
@@:
pop ecx
.donez:
mov esi, [esi+edx*4]
add esi, 4
pop edx ecx ebx
clc
ret
.done2:
lea esi, [esi+edx*4]
pop ecx edx ecx ebx
stc
ret
;-----------------------------------------------------------------------------
;
; in: esi->name
; out: if found: CF = 0, EAX = value
; otherwise CF = 1
find_symbol_name:
cmp [num_symbols], 0
jnz @f
.stc_ret:
stc
ret
@@:
push ebx ecx edx edi
push -1
pop edx
mov ebx, [symbols]
mov ecx, [num_symbols]
lea ebx, [ebx+ecx*4]
; invariant: symbols_name[edx] < name < symbols_name[ecx]
.0:
push edx
.1:
add edx, ecx
sar edx, 1
cmp edx, [esp]
jz .done2
call .cmp
jz .done
jb .2
mov [esp], edx
jmp .1
.2:
mov ecx, edx
pop edx
jmp .0
.done:
pop ecx
.donez:
mov eax, [ebx+edx*4]
mov eax, [eax]
pop edi edx ecx ebx
clc
ret
.done2:
pop edx edi edx ecx ebx
stc
ret
.cmp:
mov edi, [ebx+edx*4]
push esi
add edi, 4
@@:
cmpsb
jnz @f
cmp byte [esi-1], 0
jnz @b
@@:
pop esi
ret