Set a debugger variable to a value.
set variable variable = [expression]
variable |
The variable to set. If variable starts with a dollar sign ($) then it is either a predefined register name or a debugger variable, either a predefined variable or a user variable. If variable does not start with a dollar sign ($), it is a variable in the program. |
expression |
The value for the variable. |
This command sets the values of a debugger 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.
The set variable command evaluates the specified expression. If the expression includes the assignment operator (=), the debugger evaluates that operator, as it does with all operators in expressions, and assigns the new value. The only difference between the set variable and the print commands is that set variable does not print anything, while print assigns the new value and displays the new value of the variable.
If you do not specify expression, debugger variables are set to void, while program variables do not change.
You can omit the keyword variable if the beginning of expression is unambiguous to the debugger. For example, if expression begins with the string height, the debugger interprets the command as the set height command.
For C++, use the set variable command 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.
Do not use the set variable command 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.
The following example shows how to deposit the value 5 into the data member _data of a C++ object:
(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 $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}
You can use the set variable command to alter the contents of memory specified by an address as shown in the following example:
(idb) set variable $address = &(node->_data) (idb) print $address $11 = (int *) 0x805c500 (idb) print *(int *)($address) $12 = -32 (idb) set variable *(int *)($address) = 1024 (idb) print *(int *)($address) $13 = 1024
Copyright © 2001-2011, Intel Corporation. All rights reserved.