Neitsa
September 18th, 2004, 11:44
Hello,
I'm currently coding a little debugger for my own knowledge, just to see how it works. I've successfully coded the Software breakpoint (BP) part, but I can't have a working Hardware BP working.
here's some code (coded with MASM) form the debugger loop:
Little explanation :
When the system BP (ntdll dbgBreakpoint) arise I set my Dr0 and Dr7 for my target.
Dr0 is a linear address
Dr7 is set to 401h
Now the strange things happens...it never breaks on my target program...
I was just wondering why. I've read the intel manual many times but maybe I've missed something (I'm not setting the Dr6 because I think there's no need to do it...)
I've extracted the Hardware BP part of my program in a fully working program. Attached is the program with source code in asm (with radasm project). There's also a little target that does nearly nothing... (just for testing purpose).
I've tried to set hardware BP on 0x401017 in my target.exe program but it never breaks...
Can someone help me ?
Thank you very much !
Regards, Neitsa.
[edit]
Finally solved, here's a working version :
I'm currently coding a little debugger for my own knowledge, just to see how it works. I've successfully coded the Software breakpoint (BP) part, but I can't have a working Hardware BP working.
here's some code (coded with MASM) form the debugger loop:
Code:
.elseif DebugEvent.dwDebugEventCode==EXCEPTION_DEBUG_EVENT
.if DebugEvent.u.Exception.pExceptionRecord.ExceptionCode==EXCEPTION_BREAKPOINT
.if DebugEvent.u.Exception.dwFirstChance != 0 ;first time break (ntdll.DbgBreakpoint)
;BP address (inputed by user)
push BPADDR
pop Context.iDr0
;set DR7
push 401h
pop Context.iDr7
mov Context.ContextFlags,CONTEXT_DEBUG_REGISTERS
invoke SetThreadContext,ProcessInfo.hThread,addr Context
.else
;other breakpoints /Display message
invoke MessageBox,NULL,addr szBPHere, addr szCaption,MB_OK
.endif
//cut
Little explanation :
When the system BP (ntdll dbgBreakpoint) arise I set my Dr0 and Dr7 for my target.
Dr0 is a linear address
Dr7 is set to 401h
Quote:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 bits of Dr7: -0 : L0 => Local breakpoint with Dr0 [set to 1] -10 : undocumented, set to 1 as intel manual stated -16/17 : R/W0 => set to 00 for Execution only - 18/19 : LEN0 => set to 00 for "1 byte length" as intel manuel stated I think threre's no need to set other bits field, thus Dr7 should be: 10000000001b = 0x401 |
Now the strange things happens...it never breaks on my target program...
I was just wondering why. I've read the intel manual many times but maybe I've missed something (I'm not setting the Dr6 because I think there's no need to do it...)
I've extracted the Hardware BP part of my program in a fully working program. Attached is the program with source code in asm (with radasm project). There's also a little target that does nearly nothing... (just for testing purpose).
I've tried to set hardware BP on 0x401017 in my target.exe program but it never breaks...
Can someone help me ?
Thank you very much !
Regards, Neitsa.
[edit]
Finally solved, here's a working version :