tags:

views:

663

answers:

2

On a large C application, I have set a hardware watchpoint on a memory address as follows:

(gdb) watch *0x12F5D58
Hardware watchpoint 3: *0x12F5D58

As you can see, it's a hardware watchpoint, not software, which would explain the slowness.

Now the application running time under debugger has changed from less than ten seconds to one hour and counting. The watchpoint has triggered three times so far, the first time after 15 minutes when the memory page containing the address was made readable by sbrk. Surely during those 15 minutes the watchpoint should have been efficient since the memory page was inaccessible? And that still does not explain, why it's so slow afterwards.

The platform is x86_64 and the GDB versions are Ubuntu 9.10 package:

$ gdb --version
GNU gdb (GDB) 7.0-ubuntu
[...]

and stock GDB 7.1 built from sources:

$ gdb-7.1 --version
GNU gdb (GDB) 7.1

Thanks in advance for any ideas as what might be the cause or how to fix/work around it.

EDIT: removed cast

EDIT: gdb 7.1

+3  A: 

It's most likely because you're casting it each time. Try this:

(gdb) watch *0x12F5D58

Another option is that you have too many hardware watchpoints set, so gdb is forced to use software watchpoints. Try checking how many watchpoints you have using:

(gdb) info break

and see if you can disable some watchpoints.

Nathan Fellman
Can gdb really dereference an integer literal, without needing to know what type to dereference as? That's not a valid C expression, at least ...
unwind
Yes, it can. I do it all the time.
Nathan Fellman
To my surprise (I thought GDB only accepts C expressions) "watch *0x12F5DF8" works, but is as slow as the previous version.
Laurynas Biveinis
Re. another option, I don't have too many of *points, I am testng with two (disabled) breakpoints and a single watchpoint.
Laurynas Biveinis
what happens if you *delete* the breakpoints instead of *disabling* them?
Nathan Fellman
With just the watchpoint and everything else deleted, performance still is the same.
Laurynas Biveinis
Then I have no more ideas.
Nathan Fellman
Thanks for your ideas (and for *0xABCDABCD syntax)
Laurynas Biveinis
What's your platform? Maybe GDB is reporting it's using a hardware watchpoint but falls back to software.
Joseph Garvin
@Joseph: judging from the fact that he's using Ubuntu, I naturally assumed he was on x86.
Nathan Fellman
x86_64. Sorry I forgot to mention.
Laurynas Biveinis
By the way, you can probably also dereference constants in C as well, if you know where your data is located.
Nathan Fellman
+2  A: 

I've actually had trouble with hardware watchpoints in GDB 7.x.x., which is not acceptable since watchpoints are a necessity in my job.

On advice from a co-worker, I downloaded the source for 6.7.1 and built it locally. Watchpoints work much better now.

Might be worth a try.

alesplin
Interesting. I will try this out.
Laurynas Biveinis
GDB 6.7.1 is missing a feature where one can use watchpoints on memory address that is inaccessible at the watchpoint setup time. It is possible to enable it at the right time, but this will be more involved, I will try later. I have also tried just released GDB 7.1, same problem as with 7.0.
Laurynas Biveinis
with conditional breakpoints and breakpoint commands you might be able to work around that without too much trouble.
alesplin