LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   kdevelop, debugging - how to set a valid condition for a watchpoint? (https://www.linuxquestions.org/questions/programming-9/kdevelop-debugging-how-to-set-a-valid-condition-for-a-watchpoint-739456/)

onufry 07-11-2009 05:15 PM

kdevelop, debugging - how to set a valid condition for a watchpoint?
 
Hello,

I have a problem with debugging in kdevelop. I'm unable to set valid condition in the watchpoints condition field (the bottom breakpoint section). I tried everything that seemed sane to me:
a > 10.
(a > 10.)
if(a > 10.)
if a > 10.

'a' is the variable I have watchpoint for.

And as result I got all possible stops for any change of the variable in question.

I would be grateful for any help.
Onufry

onufry 07-12-2009 07:30 AM

ok - got sth working "around".

I put some code like:

Code:

if(a>10.){
//printf or sth done with 'a' so the compiler doesn't optimize by cuting out if statement
//line brakepoint
}



maybe this "watch for change" idea is completly wrong for floats. I tried in gdb (in the corect scoope):

Code:

awatch a
cond 1 a>10.0

And it did not work. :( I got 'hit' every time even before 'a' made past 10.

Best regards,
Onufry

ntubski 07-12-2009 02:52 PM

It looks like gdb ignores conditions on watchpoints. I think this could be a bug given the following paragraph from the gdb manual:
Quote:

Conditions are also accepted for watchpoints; you may not need them, since a watchpoint is inspecting the value of an expression anyhow--but it might be simpler, say, to just set a watchpoint on a variable name, and specify a condition that tests whether the new value is an interesting one.
You can use commands to simulate a condition:
Code:

commands <watchpoint number>
 silent
 if a > 10
  printf "hit watchpoint\na = %f\n", a
 else
  continue
 end
end


onufry 07-17-2009 12:54 PM

The solution with "commands" did not do anything at all (it only switched off printing "sth changed to a" in gdb) . I think there may be two problems:
1. sth is wrong with gdb (I am using gdb-6.8-r1)
or
2. I do sth horribly wrong somewhere else while debugging - for example: while setting a breakpoint ;]

the crude solution i used in the first place (by putting additional code inside the program) somehow worked - i have done what i had to do.

But thanks anyway. :)

Best regards,
onufry

ntubski 07-17-2009 01:32 PM

Quote:

1. sth is wrong with gdb (I am using gdb-6.8-r1)
Code:

$ gdb --version
GNU gdb 6.8-debian

I'd be surprised if that's the problem.

Anyways I thought of another workaround: you can do
Code:

watch (a > 10)? a : 0
Basically have the watched expression not change unless the condition is true.


All times are GMT -5. The time now is 05:49 PM.