watch (idb mode only)

Set a watchpoint on the specified variable or memory range.

Syntax

watch memory start-addr [, end-addr| :size] [access] [thread ID {,...}] [within funcname] [if cond] [commands]
watch variable lvalue [access] [thread ID {,...}] [within funcname] [if cond] [commands]

Parameters

lvalue

An expression that designates a memory location.

ID

A thread ID.

cond

A conditional expression.

commands

A list of debugger commands.

start-addr

The address at the start of the memory region.

end-addr

The address at the end of the memory region starting from start-addr.

size

The size of the memory region starting from start-addr.

funcname

The name of a function.

access

Possible values are:

write

read

changed  This mode detects writes that change the contents of the memory.

any  This mode detects both read and write.

Default value: write

Description

This command sets a write watchpoint on the specified variable or memory range. Watchpoints are also referred to as data breakpoints.

If varname is a pointer, watch variable varname watches the content of the pointer, not the memory that varname points to. Use watch memory *varname to watch the memory pointed to by varname.

You can use watchpoints to determine when a variable or memory location is read from, written to, or changed.

You can specify a variable whose memory is to be watched, or specify the memory directly. You can set the accesses that the debugger watches to those that:

If you specify a variable, the memory to be watched includes all of the memory for that variable, as determined by the variable's type.

If you specify memory directly in terms of its address, the memory to be watched is defined as follows:

To set a watchpoint such that the debugger breaks when it hits one or more specific threads, specify thread and one or more comma-separated thread IDs.

To set a watchpoint based on a conditional expression, specify if cond.

To run one or more commands upon hitting a watchpoint, specify commands.

If you specify within funcname, program execution breaks only when the access occurs in the specified function.

Example

The following example watches for write accesses to the variable _nextNode:

(idb) whatis _nextNode
class Node* Node::_nextNode 
(idb) print "sizeof(_nextNode) =", sizeof((_nextNode))
sizeof(_nextNode) = 4 
(idb) watch variable _nextNode write
[#3: watch variable _nextNode write] 

The following example watches the 4 bytes specified on the command line.

(idb) watch memory &_nextNode, ((long)&_nextNode) + 3 read
[#5: watch memory &_nextNode, ((long)&_nextNode) + 3 read]

The following example watches the 2 bytes specified on the command line for a change in contents.

(idb) watch memory &_nextNode : 2 changed [#6: stop memory&_nextNode : 2 changed]

If you specify the within modifier, then the debugger watches only those accesses that occur within the specified function, but not any function it calls. For example:

(idb) whatis t
int t 
(idb) watch variable t write within C::foo(void)
[#3: watch variable t write within void C::foo(void)] 
(idb) cont
Select from 
---------------------------------------------------- 
1 int C::foo(double*) 
2 void C::foo(float) 
3 void C::foo(int) 
4 void C::foo(void) 
5 None of the above 
---------------------------------------------------- 
5 
Value of <overloaded function> not completely specified 
foo is not a valid breakpoint address 
[3] Address 0x0804d5d0 was accessed at: 
void C::foo(void): src/x_overload.cxx 
[line 22, 0x08048789] foo+0x3: movl $0x0, 0x804d5d0 
0x0804d5d0: Old value = 0x0000000f 
0x0804d5d0: New value = 0x00000000 
[3] stopped at [void C::foo(void):22 0x08048793] 
22 void C::foo() { t = 0; state++; return; } 

Submit feedback on this help topic

Copyright © 1996-2010, Intel Corporation. All rights reserved.