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

@ -27,7 +27,10 @@ if COLOR_THEME eq MOVIEOS
COLOR_TXT_NORMAL = 0xffffff
COLOR_TXT_INACTIVE = 0x8f7948
COLOR_TXT_CHANGED = 0xec9300
COLOR_TXT_LABEL = 0x22b14c
COLOR_TXT_SELECTED = 0x1d272f
COLOR_TXT_ADDR = 0xec9300
COLOR_TXT_BREAKPOINT = 0xec9300
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_INACTIVE = 0x808080 ; grey
COLOR_TXT_CHANGED = 0x00AA00 ; green
COLOR_TXT_LABEL = COLOR_TXT_NORMAL
COLOR_TXT_SELECTED = 0xFFFFFF ; white
COLOR_TXT_ADDR = COLOR_TXT_NORMAL
COLOR_TXT_BREAKPOINT = COLOR_TXT_NORMAL
else ; BLACK ON WHITE
@ -49,7 +55,10 @@ else ; BLACK ON WHITE
COLOR_TXT_NORMAL = 0x000000 ; black
COLOR_TXT_INACTIVE = 0x808080 ; grey
COLOR_TXT_CHANGED = 0x00AA00 ; green
COLOR_TXT_LABEL = COLOR_TXT_NORMAL
COLOR_TXT_SELECTED = 0xFFFFFF ; white
COLOR_TXT_ADDR = COLOR_TXT_NORMAL
COLOR_TXT_BREAKPOINT = COLOR_TXT_NORMAL
end if
@ -1309,7 +1318,7 @@ draw_disasm:
sub esi, edx
; normal color
; was 0x40000000
mov ecx, (COLOR_TXT_NORMAL or 0x40000000)
mov ecx, (COLOR_TXT_LABEL or 0x40000000)
mov al, 4
; draw a text string in the window with color COLOR_TXT_NORMAL in ecx
mcall
@ -1337,11 +1346,8 @@ draw_disasm:
call disasm_instr
pop ebp
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 esi, COLOR_TXT_NORMAL
mov ebx, data_x_pos*10000h + data_x_size
mov ecx, [disasm_cur_str]
imul ecx, 10*10000h
@ -1350,27 +1356,19 @@ draw_disasm:
pushad
call find_enabled_breakpoint
popad
jnz .nored
; setting up background color for breakpoint
; was 0xFF0000 - red
jnz .nobp
mov edx, COLOR_BG_BREAKPOINT
mov esi, COLOR_TXT_BREAKPOINT
.nobp:
.nored:
mov eax, [_eip]
cmp eax, ebp
jnz .noblue
; setting up background color for selected text
; (current running instruction)
; was 0x0000FF - blue
jnz .notcurrent
mov edx, COLOR_BG_SELECTED
; setting up selected text color
; (current running instruction)
; was 0xFFFFFF - white
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
; color in edx
mcall 13
@ -1384,24 +1382,26 @@ draw_disasm:
mcall 47, 80100h, ebp
;mov al, 4
lea ebx, [edx+8*6*10000h]
; copy color value from esi
mov ecx, esi
mov ecx, esi ; text color
push 2
pop esi
mov edx, aColon
; draw a text string in the window, color in ecx
; draw the colon
mcall 4
push 9
pop edi
lea edx, [ebx+2*6*10000h]
mov esi, ecx
mov ecx, ebp
sub ecx, [disasm_start_pos]
add ecx, disasm_buffer
mov esi, COLOR_TXT_ADDR
mov eax, [_eip]
cmp eax, ebp
jnz @f
mov esi, COLOR_TXT_SELECTED
@@:
.drawhex:
;mov al, 47
;mov ebx, 20101h
; draw a number in the window, color in esi
mcall 47, 20101h
add edx, 6*3*10000h
@ -1426,10 +1426,9 @@ draw_disasm:
mov edx, aDots
; draw a text string in the window, color in ecx
mcall 4
; copy color value from ecx
mov esi, ecx
.hexdone:
pop esi
xor eax, eax
mov edi, disasm_string
mov edx, edi

View File

@ -1,4 +1,4 @@
COLOR_THEME equ BLACK_ON_WHITE
COLOR_THEME fix BLACK_ON_WHITE
format binary as ""
@ -305,7 +305,15 @@ do_reload:
mov byte[ecx+4], 0
pop 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
@@:
; now test for packed progs
cmp [disasm_buf_size], 100h
@ -1941,411 +1949,9 @@ OnUnpack:
jmp .x1
;-----------------------------------------------------------------------------
; Working with program symbols
;
; TODO: split to symbols.inc
; Include Symbol parser
include 'sort.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 'symbols.inc'
;-----------------------------------------------------------------------------
; Include disassembler engine
@ -2357,9 +1963,8 @@ include 'disasm.inc'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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'
newline db 10,0
prompt db '> ',0
@ -2692,6 +2297,7 @@ regs_strs:
db 'ESP='
db 'EIP='
db 'EFLAGS='
fpu_strs:
db 'ST0='
db 'ST1='
@ -2701,6 +2307,7 @@ fpu_strs:
db 'ST5='
db 'ST6='
db 'ST7='
mmx_strs:
db 'MM0='
db 'MM1='
@ -2813,6 +2420,7 @@ curarg dd ?
cmdline_prev rb cmdline_width+1
was_temp_break db ?
symbol_section db ?
dbgbufsize dd ?
dbgbuflen dd ?

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