mtdbg: Added binary search near symbol
Signed-off-by: Max Logaev <maxlogaev@proton.me>
This commit is contained in:
@@ -467,28 +467,65 @@ find_symbol_name:
|
||||
ret
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
;
|
||||
; Find the nearest symol using binary search
|
||||
;
|
||||
; in: eax - addres
|
||||
; in: eax - target addres
|
||||
; out: esi - symbol name
|
||||
; destroys: ebx, edx
|
||||
; destroys: ebx, ecx, edx, edi, ebp
|
||||
;
|
||||
find_near_symbol:
|
||||
mov ebx, [symbols]
|
||||
mov ecx, [num_symbols]
|
||||
xor esi, esi
|
||||
mov edi, [symbols]
|
||||
|
||||
xor esi, esi ; Result
|
||||
mov ecx, esi ; Left
|
||||
mov edx, [num_symbols] ; Right
|
||||
dec edx
|
||||
js .end
|
||||
|
||||
.next:
|
||||
dec ecx
|
||||
js .end
|
||||
; If the first address is already greater than the target
|
||||
mov ebp, [edi + ecx * sizeof.DEBUG_SYMBOL]
|
||||
cmp [ebp + DEBUG_SYMBOL.addr], eax
|
||||
ja .end
|
||||
|
||||
; The symbols have already been sorted:
|
||||
; from smallest address to the largest.
|
||||
; Therefore, checking addresses from the end.
|
||||
mov edx, [ebx + ecx * sizeof.DEBUG_SYMBOL]
|
||||
cmp eax, [edx + DEBUG_SYMBOL.addr]
|
||||
jb .next
|
||||
; If the last address is less than or equal to the target
|
||||
mov ebp, [edi + edx * sizeof.DEBUG_SYMBOL]
|
||||
cmp [ebp + DEBUG_SYMBOL.addr], eax
|
||||
jbe .found
|
||||
|
||||
mov esi, edx
|
||||
.loop:
|
||||
cmp ecx, edx
|
||||
ja .end
|
||||
|
||||
; Calc middle:
|
||||
mov ebx, edx ; Middle
|
||||
sub ebx, ecx ; (right - left)
|
||||
shr ebx, 1 ; / 2
|
||||
add ebx, ecx ; + left
|
||||
|
||||
; Equal
|
||||
mov ebp, [edi + ebx * sizeof.DEBUG_SYMBOL]
|
||||
cmp [ebp + DEBUG_SYMBOL.addr], eax
|
||||
jz .found
|
||||
jb .update_left
|
||||
|
||||
; Update right
|
||||
mov edx, ebx
|
||||
dec edx
|
||||
jmp .loop
|
||||
|
||||
.update_left:
|
||||
; Save potential result
|
||||
mov esi, ebp
|
||||
add esi, DEBUG_SYMBOL.string
|
||||
|
||||
; Update left
|
||||
mov ecx, ebx
|
||||
inc ecx
|
||||
jmp .loop
|
||||
|
||||
.found:
|
||||
mov esi, ebp
|
||||
add esi, DEBUG_SYMBOL.string
|
||||
|
||||
.end:
|
||||
|
||||
Reference in New Issue
Block a user