2

I am using ubuntu 12.04. I have used so far anjuta and codelite as IDE's for C++ school projects. However, with both of them I have encountered one problem: After starting the debugger, everything works fine till I try to add an array at watches' section. It does not display anything and when I try to continue debugging it freezes and I have to stop the debug session. I have to mention that watching variables works well.

Thank you,

LE: Actually, the debug function freezes only in case of large arrays...it may be a bug of codelite then. Any opinion?

Popa Mihai
  • 21
  • 4

1 Answers1

2

I have to mention that watching variables works well.

When you set the watchpoint on a variable, GDB probably says Hardware watchpoint N (but your IDE may be hiding that message).

When you set a watchpoint on anything larger than 8 bytes on x86 processor, GDB can not set a hardware watchpoint (because x86 hardware doesn't support such watchpoints). GDB sets a software watchpoint instead. Software watchpoints are implemented as follows:

  1. single-step the program
  2. did values change? No -> go to step 1. Yes: stop.

Software watchpoints are really slow. If you watch your system with top, you'll likely discover that GDB is consuming 100% CPU.

If you really need to watch an entire array, this answer shows how that can be done with valgrind.

Community
  • 1
  • 1
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Modern hardware supports watching max of 16 bytes, not word. – Daniel Sep 14 '12 at 17:00
  • It really consumes 100% CPU, it takes about one minute going to the next instruction. Thank you a lot! – Popa Mihai Sep 14 '12 at 17:05
  • @Dani Citation needed. According to http://en.wikipedia.org/wiki/X86_debug_register, the maximum size for a watchpoint is 8 bytes; I've updated the answer. – Employed Russian Sep 14 '12 at 17:14
  • @EmployedRussian: From that page: "enable the four address breakpoint conditions", "each breakpoint ... specifies whether they watch ... one (00b), two (01b), eight (10b) or four (11b) bytes". Actually its 32 bytes, I didn't know the eight ones existed. – Daniel Sep 14 '12 at 18:01
  • @Dani It's *bytes*, not words. – Employed Russian Sep 14 '12 at 18:23
  • @EmployedRussian: 4 drs * 8 bytes = 32 bytes – Daniel Sep 14 '12 at 19:28
  • @Dani A *single* GDB hardware watchpoint can watch up to 8 bytes. I don't believe GDB will set 2 `DR`s if you ask it to watch 16 bytes, but I could be wrong. – Employed Russian Sep 14 '12 at 19:52