mtdbg: Check ebp for 0 instead of check initial esp

Signed-off-by: Max Logaev <maxlogaev@proton.me>
This commit is contained in:
2026-01-16 19:28:44 +03:00
parent 495f08d665
commit cc66bfd864

View File

@@ -240,10 +240,6 @@ do_reload:
mov ecx, (ctx_end-context)/4
rep movsd
; Save initial stack pointer
mov ecx, [_esp]
mov [start_esp], ecx
; activate debugger window
pop ecx
mcall 18, 3
@@ -1156,8 +1152,8 @@ OnDump:
; Print Backtrace
struct STACK_FRAME
_ebp rd 1
_eip rd 1
prev_frame rd 1
ret_addr rd 1
ends
OnBacktrace:
@@ -1189,12 +1185,6 @@ OnBacktrace:
test ebp, ebp
jz .done
; The frame must be within the stack
mov eax, [start_esp]
sub eax, sizeof.STACK_FRAME
cmp ebp, eax
ja .done
mov edi, stack_frame_dump
.next:
@@ -1203,24 +1193,29 @@ OnBacktrace:
mov esi, read_mem_err
jz .exit
; The address of the previous frame must be less than the current one
mov eax, [edi + STACK_FRAME.prev_frame]
test eax, eax
jz .done
; Save stack_frame_dump
push edi
; Save EBP
; Save previous frame
push ebp
; Save EIP
mov eax, [edi + STACK_FRAME._eip]
; Save return address
mov eax, [edi + STACK_FRAME.ret_addr]
push eax
; Print EBP and EIP
; Print frame address and return address
push eax ; pop in put_message_nodraw
push ebp ; pop in put_message_nodraw
mov esi, aBacktraceFmt
call put_message_nodraw
; Restore EIP
; Restore return address
pop eax
; Find symbol by EIP
; Find symbol by return address
call find_near_symbol
test esi, esi
jz .print_stub
@@ -1238,23 +1233,17 @@ OnBacktrace:
mov esi, newline
call put_message_nodraw
; Restore EBP
; Restore previous frame
pop ebp
; Restore stack_frame_dump
pop edi
; The address of the next frame must be greater than the previous one
cmp [edi + STACK_FRAME._ebp], ebp
jbe .done
; The address of the previous frame must be greater than the current one.
cmp [edi + STACK_FRAME.prev_frame], ebp
jna .done
; The frame must be within the stack
mov eax, [start_esp]
sub eax, sizeof.STACK_FRAME
cmp [edi + STACK_FRAME._ebp], eax
ja .done
; Set next frame
mov ebp, [edi + STACK_FRAME._ebp]
; Set previous frame
mov ebp, [edi + STACK_FRAME.prev_frame]
dec [bt_depth]
jnz .next
@@ -2628,7 +2617,6 @@ disasm_cur_pos dd ?
disasm_cur_str dd ?
disasm_string rb 256
start_esp rd 1
stack_frame_dump rb sizeof.STACK_FRAME
bt_depth rd 1
prev_bt_sym rd 1