Use the set variable (gdb) and the assign (dbx) 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.
GDB Mode
modifying_command
: set [ variable ] expression
The set variable command evaluates the specified expression. If the expression includes the assignment operator ("="), that operator will be evaluated (as all operators in expressions are) and the assignment will be done. 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.
DBX Mode
modifying_command
: assign target = expression
| patch target = expression
The following example shows how to deposit the value 5 into the data member _data of a C++ object:
GDB Mode
(idb) print node->_data
$2 = 2
(idb) set variable node->_data = 5
(idb) print node->_data
$3 = 5
DBX Mode
(idb) print node->_data
2
(idb) assign node->_data = 5
(idb) print node->_data
5
The following example shows how to change the value associated with a variable and the value associated with an expression:
GDB Mode
(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 = 0x805c4e8}, _data = -32}, _fdata = 14.13}
DBX Mode
(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 = 0x805c4e8; // class IntNode::Node
}
For C++, use the set variable (gdb) and the assign (dbx) 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 set variable (gdb) and the assign (dbx) 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.