Setting breakpoint using debug registers

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Vinay
Posts: 8
Joined: Thu Jun 14, 2012 2:35 am

Setting breakpoint using debug registers

Post by Vinay »

I went through the specifications of debug registers in intel manuals...It says we can stop the program execution by setting either instruction break point or data breakpoint.. I tried both but breakpoints are not being hit..
I have mentioned the following specification relevant to this..

Say i am setting 4 instruction breakpoints..
DR0 = 0xfffe58a0
DR1 = 0xfffe6860
DR2 = 0xfffe67c0
DR3 = 0xfffe0c68

Debug registers DR4 and DR5 are reserved. So i am not using them.
DR6 is status register, i am not setting it.

After going through the specs, i am setting DR7 = 0x000007FF(I have enables all instruction breakpoints).

But during program execution i am not able to hit the these instruction breakpoints. Its true with data breakpoints also.

Please guide and any help would be appreciated :)
Last edited by Vinay on Tue Jun 19, 2012 3:08 am, edited 1 time in total.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Setting breakpoint using debug registers

Post by Combuster »

Have you tried it on real hardware? The VMs generally lack support for it altogether and Bochs need a compile-time switch to support it.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Vinay
Posts: 8
Joined: Thu Jun 14, 2012 2:35 am

Re: Setting breakpoint using debug registers

Post by Vinay »

Yes, i have tried it on real hardware..
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Setting breakpoint using debug registers

Post by qw »

This may sound like a dumb question but are you sure that your code is actually executing at the given addresses?

BTW The first two addresses have nine xdigits instead of eight.
Vinay
Posts: 8
Joined: Thu Jun 14, 2012 2:35 am

Re: Setting breakpoint using debug registers

Post by Vinay »

Yes, i am sure that the code is executing at the addresses specified..

Sorry for mentioning wrong DR0 and DR1.. Didn't notice while posting.
It should be
DR0 = 0xfffe58a0
DR1 = 0xfffe6860
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Setting breakpoint using debug registers

Post by iansjack »

Are those addresses that you are putting in the debug registers physical addresses?
Vinay
Posts: 8
Joined: Thu Jun 14, 2012 2:35 am

Re: Setting breakpoint using debug registers

Post by Vinay »

These are linear addresses...
Since i am not using paging, linear address is same as physical address...
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Setting breakpoint using debug registers

Post by iansjack »

A really silly question, no doubt, but you don't mention your exception handler. Are you sure this is set up correctly?
Vinay
Posts: 8
Joined: Thu Jun 14, 2012 2:35 am

Re: Setting breakpoint using debug registers

Post by Vinay »

Yes everything is set up properly...
I have manually set breakpoint at DB handler also...its not hitting
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Setting breakpoint using debug registers

Post by iansjack »

The only other potential problem that I can think of is that the registers aren't pointing to the first byte of the instruction (including any prefix).
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Setting breakpoint using debug registers

Post by Combuster »

are you sure that your code is actually executing at the given addresses
i am sure that the code is executing at the addresses specified
i am not using paging
0xfffe58a0
That's definitely not your code. It's BIOS space. What are you trying to do there?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Vinay
Posts: 8
Joined: Thu Jun 14, 2012 2:35 am

Re: Setting breakpoint using debug registers

Post by Vinay »

Thanks for the replies...I am still not able to find solution, this is my code only which i have for micro controller operation..
jbemmel
Member
Member
Posts: 53
Joined: Fri May 11, 2012 11:54 am

Re: Setting breakpoint using debug registers

Post by jbemmel »

Did you try inserting a debug breakpoint instruction (int3) in your code, to test if your debug handler gets called?
It's a different exception vector (#BP 3 instead of #DB 1), but it's easier to setup and very similar
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Setting breakpoint using debug registers

Post by JamesM »

Vinay wrote:Thanks for the replies...I am still not able to find solution, this is my code only which i have for micro controller operation..
If you're not using paging, then like Combuster said that address is in the BIOS region. Are you certain that it points to the *first byte* of a valid instruction? And that the CPU isn't operating in real mode by that point?
Vinay
Posts: 8
Joined: Thu Jun 14, 2012 2:35 am

Re: Setting breakpoint using debug registers

Post by Vinay »

I am sure that CPU is operating in protected mode, and now my query is how to check it points to the first byte of the instruction?
Post Reply