Use the assign (dbx) and the set variable (gdb) commands to change the value associated with a variable, memory address, or expression that is accessible according to the scope and visibility rules of the language. The expression can be any expression that is valid in the current context.
modifying_command
: assign target = expression
| patch target = expression
modifying_command
: set [ variable ] expression
The set variable command evaluates the specified expression. If expression includes assignment operator, it executes like all other operators. This is the way to change memory.
The only difference between the set variable and the print commands is printing the value - the set variable does not print anything.
The variable can be omitted if the beginning of expression does not confuse the debugger, for example, does not look like a valid subcommand for the set command.
The following example shows how to deposit the value 5 into the data member _data of a C++ object:
(idb) print node->_data
2
(idb) assign node->_data = 5
(idb) print node->_data
5
(idb) print node->_data
$2 = 2
(idb) set variable node->_data = 5
(idb) print node->_data
$3 = 5
The following example shows how to change the value associated with a variable and the value associated with an expression:
(idb) print *node
class CompoundNode {
_fdata = 12.3450003;
_data = 5; // class IntNode
_nextNode = 0x0; // class IntNode::Node
}
(idb) assign node->_data = -32
(idb) assign node->_fdata = 3.14 * 4.5
(idb) assign node->_nextNode = _firstNode
(idb) print *node
class CompoundNode {
_fdata = 14.1300001;
_data = -32; // class IntNode
_nextNode = 0x805e5e0; // class IntNode::Node
}
(idb) print *node
$6 = {<IntNode> = {<Node> = {_nextNode = 0x0}, _data = 5}, _fdata = 12.345}
(idb) set variable node->_data = -32
(idb) set variable node->_fdata = 3.14 * 4.5
(idb) set variable node->_nextNode = _firstNode
(idb) print *node
$7 = {<IntNode> = {<Node> = {_nextNode = 0x805e5e0}, _data = -32}, _fdata = 14.13}
For C++, use the assign (dbx) and the set variable (gdb) commands to modify static and object data members in a class, and variables declared as reference types, type const, or type static. You cannot change the address referred to by a reference type, but you can change the value at that address.
assign [classname::]member = ["filename"] `expression
assign [object.]member = ["filename"] `expression
Do not use the assign (dbx) and the set variable (gdb) commands to change the PC. When you change the PC, no adjustment to the contents of registers or memory is made. Because most instructions change registers or memory in ways that can impact the meaning of the application, changing the PC is very likely to cause your application to do incorrect calculations and arrive at the wrong answer. Access violations and other errors and signals may result from changing the value in the PC.