Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB hardware watchpoint very slow - why?

Tags:

gdb

watchpoint

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

like image 911
Laurynas Biveinis Avatar asked Mar 15 '10 09:03

Laurynas Biveinis


People also ask

What is hardware watchpoint?

Hardware watchpoints - allow execution to halt when a read or write access is made to a data variable address. Count Event - can be used to measure clock cycles between two points in the code. Data Access Count - can be used to determine the number of times a data variable address has been accessed.

What is the difference between breakpoint and watchpoint?

A watchpoint is similar to a breakpoint, but it is the address of a data access that is monitored rather than an instruction being executed. You specify a global variable or a memory address to monitor. Watchpoints are sometimes known as data breakpoints, emphasizing that they are data dependent.

How do I delete a watchpoint in GDB?

Simply quit GDB, and all breakpoints and watchpoints will be gone. Or do (gdb) delete (without specifying a break point), and confirm that you want to delete all.


1 Answers

I discovered that watching a large character buffer was very slow, whereas watching a character in that buffer was very fast.

e.g.

static char buf[1024];
static char* buf_address = &buf;

watch buf_address - excruciatingly slow.

watch *buf_address - very fast.

like image 142
Charlie Avatar answered Oct 14 '22 03:10

Charlie