Use the which command to determine which declaration an identifier resolves to. The which command shows the fully qualified scope information for the instance of the specified expression visible from the current scope.
The scope information of a variable usually consists of the name of the source file that contains the function in which the variable is declared, the name of that function, and the name of the variable. The components of the scope information are separated by back-quotes (`).
which_command
: which which_name
which_name
| ( identifier_or_typedef_name )
The following example shows how to use the whereis and which commands to determine a variable's scope:
(idb) where 4
>0 0x080553fd in ((Planet*)0x806e298)->Planet::printBody(i=2) "/home/user/examples/solarSystemSrc/planet.cxx":19
#1 0x0804d697 in ((HeavenlyBody*)0x806e298)->HeavenlyBody::printBodyAndItsSatellites(i=2) "/home/user/examples/solarSystemSrc/heavenlyBody.cxx":62
#2 0x0804d6d2 in ((HeavenlyBody*)0x806e168)->HeavenlyBody::printBodyAndItsSatellites(i=1) "/home/user/examples/solarSystemSrc/heavenlyBody.cxx":68
#3 0x08058bf2 in main() "/home/user/examples/solarSystemSrc/main/solarSystem.cxx":120
(idb) which i
"/home/user/examples/solarSystemSrc/planet.cxx"`Planet::printBody(unsigned int)`i
(idb) assign i = 10
(idb) print i
10
(idb) whereis i
"/home/user/examples/solarSystemSrc/heavenlyBody.cxx"`HeavenlyBody::printBodyAndItsSatellites(unsigned int)`i
"/home/user/examples/solarSystemSrc/heavenlyBody.cxx"`HeavenlyBody::printBodyAndItsSatellites(unsigned int)`i
"/home/user/examples/solarSystemSrc/heavenlyBody.cxx"`HeavenlyBody::satelliteNumber(class HeavenlyBody*)`i
"/home/user/examples/solarSystemSrc/main/solarSystem.cxx"`main`i
"/home/user/examples/solarSystemSrc/main/solarSystem.cxx"`printBiggestMoons`i
"/home/user/examples/solarSystemSrc/main/solarSystem.cxx"`trackBiggestMoons(class Moon*)`i
"/home/user/examples/solarSystemSrc/planet.cxx"`Moon::printBody(unsigned int)`i
"/home/user/examples/solarSystemSrc/planet.cxx"`Planet::printBody(unsigned int)`i
"/home/user/examples/solarSystemSrc/star.cxx"`Star::printBody(unsigned int)`i
(idb) func HeavenlyBody::printBodyAndItsSatellites
void HeavenlyBody::printBodyAndItsSatellites(unsigned int) in /home/user/examples/solarSystemSrc/heavenlyBody.cxx line No. 62:
62 printBody(i); {static int somethingToReturnTo; somethingToReturnTo++; }
(idb) which i
"/home/user/examples/solarSystemSrc/heavenlyBody.cxx"`HeavenlyBody::printBodyAndItsSatellites(unsigned int)`i
(idb) print i
2