Now, if you restart the program, it will be reloaded symbols

git-svn-id: svn://kolibrios.org@3675 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
GerdtR 2013-06-17 20:21:18 +00:00
parent f828457410
commit 11e927c0c3
8 changed files with 7735 additions and 5979 deletions

View File

@ -0,0 +1,38 @@
Description
===========
Kolibri debugger - simple user mode debugger
TODO
====
See inline 'TODO' comments
Also long term goals:
1. Commands history and navigation
2. Command autocompletion
3. Save memory block into file
4. Gdb remote protocol support (gdb-stub)
5. Live assembly
6. Improve disassembly engine
7. Split out context handling and kernel interface
8. Split out commands handler and tables in cmd.inc
8. Restrurize and refactor data section
9. Add disassembler listing export into file
10. Record trace log
11. Improve FPU/MMX/SSE/AVX debugging
12. Document disassembly engine deeply
13. Add tips for insufficient code sequences
Hacking
=======
If you want improve or change some features see files description:
1. mtdbg.asm - Main loop, events handling, data container
2. gui.inc - GUI implementation
3. disasm.inc - Disassembler engine
4. disasm_tbl.inc - Instruction tables for disassembler engine
5. parser.inc - Parser and evaluator of expressions

View File

@ -0,0 +1,101 @@
; TODO: add both visual and command modes
; scan and build command line
scan_cmdline:
pusha
cmp [cmdline_len], cmdline_width
jae waitevent
push eax
call clear_cmdline_end
pop eax
mov edi, cmdline
mov ecx, [cmdline_len]
add edi, ecx
lea esi, [edi-1]
sub ecx, [cmdline_pos]
std
rep movsb
cld
stosb
inc [cmdline_len]
call draw_cmdline_end
inc [cmdline_pos]
call draw_cursor
jmp waitevent
.backspace:
cmp [cmdline_pos], 0
jz waitevent
dec [cmdline_pos]
.delchar:
call clear_cmdline_end
mov edi, [cmdline_pos]
dec [cmdline_len]
mov ecx, [cmdline_len]
sub ecx, edi
add edi, cmdline
lea esi, [edi+1]
rep movsb
call draw_cmdline_end
call draw_cursor
jmp waitevent
.del:
mov eax, [cmdline_pos]
cmp eax, [cmdline_len]
jae waitevent
jmp .delchar
.left:
cmp [cmdline_pos], 0
jz waitevent
call hide_cursor
dec [cmdline_pos]
call draw_cursor
jmp waitevent
.right:
mov eax, [cmdline_pos]
cmp eax, [cmdline_len]
jae waitevent
call hide_cursor
inc [cmdline_pos]
call draw_cursor
jmp waitevent
.home:
call hide_cursor
and [cmdline_pos], 0
call draw_cursor
jmp waitevent
.end:
call hide_cursor
mov eax, [cmdline_len]
mov [cmdline_pos], eax
call draw_cursor
.up:
.down:
jmp waitevent
;; We also trying to execute previous command, if empty command_line
.enter:
mov ecx, [cmdline_len]
cmp ecx, 0
jg .exec_cur
mov cl, byte [cmdline_prev]
cmp cl, 0
jz waitevent
.exec_prev:
mov esi, cmdline_prev
jmp .exec
.exec_cur:
mov esi, cmdline
.exec:
mov byte [esi+ecx], 0
and [cmdline_pos], 0
push esi
call clear_cmdline_end
call draw_cursor
pop esi
and [cmdline_len], 0
; skip leading spaces
call skip_spaces
cmp al, 0
jz waitevent
; vim: ft= fasm

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,70 @@
disasm_table_1:
dd cop22, cop22, cop22, cop22, cop21, cop21, cop0, cop0 ; 0x
dd cop22, cop22, cop22, cop22, cop21, cop21, cop0, cF
dd cop22, cop22, cop22, cop22, cop21, cop21, cop0, cop0 ; 1x
dd cop22, cop22, cop22, cop22, cop21, cop21, cop0, cop0
dd cop22, cop22, cop22, cop22, cop21, cop21, cseges,cop0 ; 2x
dd cop22, cop22, cop22, cop22, cop21, cop21, csegcs,cop0
dd cop22, cop22, cop22, cop22, cop21, cop21, csegss,cop0 ; 3x
dd cop22, cop22, cop22, cop22, cop21, cop21, csegds,cop0
dd cinc1, cinc1, cinc1, cinc1, cinc1, cinc1, cinc1, cinc1 ; 4x
dd cdec1, cdec1, cdec1, cdec1, cdec1, cdec1, cdec1, cdec1
dd cpush1,cpush1,cpush1,cpush1,cpush1,cpush1,cpush1,cpush1 ; 5x
dd cpop1, cpop1, cpop1, cpop1, cpop1, cpop1, cpop1, cpop1
dd cop0, cop0, cbound,carpl, csegfs,cseggs,c66, c67 ; 6x
dd cpush21,cimul1,cpush22,cimul1,cunk,cunk, cunk, cunk
dd cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1 ; 7x
dd cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1, cjcc1
dd cop23, cop23, cop23, cop23, cop22, cop22, cop22, cop22 ; 8x
dd cop22, cop22, cop22, cop22, cunk, cop22, cunk, cpop2
dd cop0, cxchg1,cxchg1,cxchg1,cxchg1,cxchg1,cxchg1,cxchg1 ; 9x
dd ccbw, ccwd, ccallf,cop0, cop0, cop0, cop0, cop0
dd cmov3, cmov3, cmov3, cmov3, cop0, cop0, cop0, cop0 ; Ax
dd cop21, cop21, cop0, cop0, cop0, cop0, cop0, cop0
dd cmov11,cmov11,cmov11,cmov11,cmov11,cmov11,cmov11,cmov11 ; Bx
dd cmov12,cmov12,cmov12,cmov12,cmov12,cmov12,cmov12,cmov12
dd cshift1,cshift1,cret2,cop0, cunk, cunk, cmov2, cmov2 ; Cx
dd center,cop0, cunk, cunk, cop0, cint, cunk, cunk
dd cshift2,cshift2,cshift3,cshift3,caam,caad,cunk, cxlat ; Dx
dd cD8, cD9, cDA, cDB, cDC, cDD, cDE, cDF
dd cloopnz,cloopz,cloop,cjcxz, cunk, cunk, cunk, cunk ; Ex
dd ccall1,cjmp1, cunk, cjmp2, cunk, cunk, cunk, cunk
dd clock, cunk, crepnz,crep, cunk, cop0, cop1, cop1 ; Fx
dd cop0, cop0, cop0, cop0, cop0, cop0, cop1, cop1
disasm_table_2:
dd cunk, cunk, cunk, cunk, cunk, cop0_F,cop0_F,cunk ; 0x
dd cunk, cunk, cunk, cunk, cunk, cunk, cunk, cunk
dd cunk, cunk, cunk, cunk, cunk, cunk, cunk, cunk ; 1x
dd cunk, cunk, cunk, cunk, cunk, cunk, cunk, cunk
dd cunk, cunk, cunk, cunk, cunk, cunk, cunk, cunk ; 2x
dd cunk, cunk, cunk, cunk, cunk, cunk, cunk, csse1
dd cunk, crdtsc,cunk, cunk, cop0_F,cunk, cunk, cunk ; 3x
dd cunk, cunk, cunk, cunk, cunk, cunk, cunk, cunk
dd cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc ; 4x
dd cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc,cmovcc
dd cunk, cunk, cunk, cunk, csse1, csse1, cunk, cunk ; 5x
dd csse1, cunk, cunk, cunk, cunk, cunk, cunk, cunk
dd cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn ; 6x
dd cpcmn, cpcmn, cpcmn, cpcmn, cunk, cunk, cmovd1,cmovq1
dd cunk, cpshift,cpshift,cpshift,cpcmn,cpcmn,cpcmn,cemms ; 7x
dd cunk, cunk, cunk, cunk, cunk, cunk, cmovd2,cmovq2
dd cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2 ; 8x
dd cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2, cjcc2
dd csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc ; 9x
dd csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc,csetcc
dd cunk, cunk, ccpuid,cbtx2, cshld, cshld, cunk, cunk ; Ax
dd cunk, cunk, cunk, cbtx2, cshrd, cshrd, cgrp15,cop22
dd ccmpxchg,ccmpxchg,cunk,cbtx2,cunk, cunk, cmovzx,cmovzx ; Bx
dd cunk, cunk, cbtx1, cbtx2, cbsf, cbsr, cmovsx,cmovsx
dd cunk, cunk, csse1, cunk, cunk, cunk, cunk, ccmpxchg8b ; Cx
dd cbswap,cbswap,cbswap,cbswap,cbswap,cbswap,cbswap,cbswap
dd csse2, cpsrlw,cpsrlw,cpsrlq,cpcmn, cpcmn, cunk, cunk ; Dx
dd cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn
dd cpcmn, cpsraw,cpsrad,cpcmn, cpcmn, cpcmn, cunk, cunk ; Ex
dd cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn
dd cunk, cpsllw,cpslld,cpsllq,cpcmn, cpcmn, cpcmn, cunk ; Fx
dd cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cpcmn, cunk
; vim: ft=fasm tabstop=4

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,403 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EXPRESSION PARSER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
token_end equ 1
token_reg equ 2
token_hex equ 3
token_add equ 4
token_sub equ 5
token_mul equ 6
token_div equ 7
token_lp equ 8
token_rp equ 9
token_err equ -1
;-----------------------------------------------------------------------------
; Check if byte - some kind of instruction prefix
is_prefix:
cmp al, 0x64 ; fs:
jz .ret
cmp al, 0x65 ; gs:
jz .ret
cmp al, 0x66 ; use16/32
jz .ret
cmp al, 0x67 ; addr16/32
jz .ret
cmp al, 0xF0 ; lock
jz .ret
cmp al, 0xF2 ; repnz
jz .ret
cmp al, 0xF3 ; rep(z)
jz .ret
cmp al, 0x2E ; cs:
jz .ret
cmp al, 0x36 ; ss:
jz .ret
cmp al, 0x3E ; ds:
jz .ret
cmp al, 0x26 ; es:
.ret:
ret
;-----------------------------------------------------------------------------
; Check if byte is hex digit
is_hex_digit:
cmp al, '0'
jb .no
cmp al, '9'
jbe .09
cmp al, 'A'
jb .no
cmp al, 'F'
jbe .AF
cmp al, 'a'
jb .no
cmp al, 'f'
jbe .af
.no:
stc
ret
.09:
sub al, '0'
; clc
ret
.AF:
sub al, 'A'-10
; clc
ret
.af:
sub al, 'a'-10
; clc
ret
;-----------------------------------------------------------------------------
; Find register in the table
find_reg:
mov edi, reg_table
.findreg:
movzx ecx, byte [edi]
stc
jecxz .regnotfound
inc edi
push esi edi ecx
@@:
lodsb
or al, 20h
scasb
loopz @b
pop ecx edi esi
lea edi, [edi+ecx+1]
jnz .findreg
movzx edi, byte [edi-1]
add esi, ecx
.regnotfound:
ret
;-----------------------------------------------------------------------------
; Tokenize expressions
expr_get_token:
lodsb
cmp al, 0
jz .end_token
cmp al, ' '
jbe expr_get_token
cmp al, '+'
jz .add
cmp al, '-'
jz .sub
cmp al, '*'
jz .mul
cmp al, '/'
jz .div
cmp al, '('
jz .lp
cmp al, ')'
jnz .notsign
.rp:
mov al, token_rp
ret
.div:
mov al, token_div
ret
.end_token:
mov al, token_end
ret
.add:
mov al, token_add
ret
.sub:
mov al, token_sub
ret
.mul:
mov al, token_mul
ret
.lp:
mov al, token_lp
ret
.notsign:
dec esi
call find_reg
jc .regnotfound
mov al, token_reg
ret
.regnotfound:
; test for symbol
push esi
@@:
lodsb
cmp al, ' '
ja @b
push eax
mov byte [esi], 0
xchg esi, [esp+4]
call find_symbol_name
mov edi, eax
pop eax
xchg esi, [esp]
mov byte [esi], al
jc @f
add esp, 4
mov al, token_hex
ret
@@:
pop esi
; test for hex number
xor ecx, ecx
xor edi, edi
xor eax, eax
@@:
lodsb
call is_hex_digit
jc @f
shl edi, 4
or edi, eax
inc ecx
jmp @b
@@:
dec esi
jecxz .err
cmp ecx, 8
ja .err
mov al, token_hex
ret
.err:
mov al, token_err
mov esi, aParseError
ret
;-----------------------------------------------------------------------------
expr_read2:
cmp al, token_hex
jz .hex
cmp al, token_reg
jz .reg
cmp al, token_lp
jz .lp
mov al, token_err
mov esi, aParseError
ret
.hex:
mov ebp, edi
.ret:
jmp expr_get_token
.reg:
cmp edi, 24
jz .eip
sub edi, 4
jb .8lo
sub edi, 4
jb .8hi
sub edi, 8
jb .16
mov ebp, [_eax+edi*4]
jmp .ret
.16:
movzx ebp, word [_eax+(edi+8)*4]
jmp .ret
.8lo:
movzx ebp, byte [_eax+(edi+4)*4]
jmp .ret
.8hi:
movzx ebp, byte [_eax+(edi+4)*4+1]
jmp .ret
.eip:
mov ebp, [_eip]
jmp .ret
.lp:
call expr_get_token
call expr_read0
cmp al, token_err
jz @f
cmp al, token_rp
jz expr_get_token
mov al, token_err
mov esi, aParseError
@@:
ret
;-----------------------------------------------------------------------------
expr_read1:
call expr_read2
.1:
cmp al, token_mul
jz .mul
cmp al, token_div
jz .div
ret
.mul:
push ebp
call expr_get_token
call expr_read2
pop edx
; ebp := edx*ebp
imul ebp, edx
jmp .1
.div:
push ebp
call expr_get_token
call expr_read2
pop edx
; ebp := edx/ebp
test ebp, ebp
jz .div0
push eax
xor eax, eax
xchg eax, edx
div ebp
xchg eax, ebp
pop eax
jmp .1
.div0:
mov al, token_err
mov esi, aDivByZero
ret
;-----------------------------------------------------------------------------
expr_read0:
xor ebp, ebp
cmp al, token_add
jz .add
cmp al, token_sub
jz .sub
call expr_read1
.1:
cmp al, token_add
jz .add
cmp al, token_sub
jz .sub
ret
.add:
push ebp
call expr_get_token
call expr_read1
pop edx
; ebp := edx+ebp
add ebp, edx
jmp .1
.sub:
push ebp
call expr_get_token
call expr_read1
pop edx
; ebp := edx-ebp
xchg edx, ebp
sub ebp, edx
jmp .1
;-----------------------------------------------------------------------------
; in: esi->expression
; out: CF=1 if error
; CF=0 and ebp=value if ok
calc_expression:
call expr_get_token
call expr_read0
cmp al, token_end
jz .end
cmp al, token_err
jz @f
mov esi, aParseError
@@:
call put_message
stc
ret
.end:
clc
ret
;-----------------------------------------------------------------------------
get_arg:
lodsb
cmp al, ' '
ja get_arg
mov byte [esi-1], 0
cmp al, 0
jnz .skip_spaces
dec esi
.skip_spaces:
lodsb
cmp al, 0
jz @f
cmp al, ' '
jbe .skip_spaces
@@:
dec esi
ret
; vim: ft=fasm tabstop=4

View File

@ -1,14 +1,17 @@
; ‘®àâ¨à®¢ª  dword'®¢ ¢ ª®«¨ç¥á⢥ ecx ¯®  ¤à¥áã edx, äã­ªæ¨ï áà ¢­¥­¨ï ¢ ebx ; Sorting bunch of dwords, count = ecx, locating at address = edx,
; <EFBFBD> §àãè ¥â eax, ecx, esi, edi ; comparison function at ebx
; Destroy content of eax, ecx, esi, edi
sort: sort:
jecxz .done jecxz .done
mov eax, ecx mov eax, ecx
@@: @@:
push eax push eax
call .restore call .restore
pop eax pop eax
dec eax dec eax
jnz @b jnz @b
@@: @@:
cmp ecx, 1 cmp ecx, 1
jz .done jz .done
@ -19,6 +22,7 @@ sort:
mov eax, 1 mov eax, 1
call .restore call .restore
jmp @b jmp @b
.done: .done:
ret ret
@ -34,7 +38,7 @@ sort:
.restore: .restore:
lea esi, [eax+eax] lea esi, [eax+eax]
cmp esi, ecx cmp esi, ecx
ja .doner ja .donerr
push esi push esi
mov esi, [edx+esi*4-4] mov esi, [edx+esi*4-4]
mov edi, [edx+eax*4-4] mov edi, [edx+eax*4-4]
@ -42,13 +46,14 @@ sort:
pop esi pop esi
ja .need_xchg ja .need_xchg
cmp esi, ecx cmp esi, ecx
jae .doner jae .donerr
push esi push esi
mov esi, [edx+esi*4] mov esi, [edx+esi*4]
mov edi, [edx+eax*4-4] mov edi, [edx+eax*4-4]
call ebx call ebx
pop esi pop esi
jbe .doner jbe .donerr
.need_xchg: .need_xchg:
cmp esi, ecx cmp esi, ecx
jz .do_xchg jz .do_xchg
@ -58,10 +63,15 @@ sort:
call ebx call ebx
pop esi pop esi
sbb esi, -1 sbb esi, -1
.do_xchg: .do_xchg:
mov edi, eax mov edi, eax
call .exchange call .exchange
mov eax, esi mov eax, esi
jmp .restore jmp .restore
.doner:
.donerr:
ret ret
; vim: ft=fasm tabstop=4