The debugger has a concept of current source file, so you do not have to explicitly specify a source file in many commands. Whenever the process stops, the current source file is set to the source file for the code currently executing. The commands up, down, class (dbx), and file (dbx) also set the current source file.
GDB Mode
In the GDB mode, the current file can be changed using the list command, for example:
(idb) run
Starting program: /home/user/examples/x_solarSystem
Breakpoint 1, main () at /home/user/examples/solarSystemSrc/main/solarSystem.cxx:114
114 unsigned int j = 1; // for scoping examples
(idb) info source
Current source file is /home/user/examples/solarSystemSrc/main/solarSystem.cxx
(idb)
(idb) list 36,+10
36 Moon *enceladus = new Moon("Enceladus", 238, 260, saturn);
37 Moon *tethys = new Moon("Tethys", 295, 530, saturn);
38 Moon *dione = new Moon("Dione", 377, 560, saturn);
39 Moon *rhea = new Moon("Rhea", 527, 765, saturn);
40 Moon *titan = new Moon("Titan", 1222, 2575, saturn);
41 Moon *hyperion = new Moon("Hyperion", 1481, 143, saturn);
42 Moon *iapetus = new Moon("Iapetus", 3561, 730, saturn);
43
44 Planet *uranus = new Planet("Uranus", 2870990, sun);
45 Moon *miranda = new Moon("Miranda", 130, 236, uranus);
(idb) list star.cxx:36,+10
36 void Star::printBody(unsigned int i) const
37 {
38 std::cout << "(" << i << ") Star [" << name()
39 << "], class [" << stellarClassName(classification())
40 << ((int)subclassification()) << "]" << std::endl;
41 }
42
43 StellarClass Star::classification() const
44 {
45 return _classification;
(idb) break 38
Breakpoint 2 at 0x8054526: file /home/user/examples/solarSystemSrc/star.cxx, line 38.
(idb) continue
Continuing.
Breakpoint 2, Star::printBody (this=0x8067550, i=1) at /home/user/examples/solarSystemSrc/star.cxx:38
38 std::cout << "(" << i << ") Star [" << name()
(idb) info source
Current source file is star.cxx
(idb) list solarSystem.cxx:36,+10
36 Moon *enceladus = new Moon("Enceladus", 238, 260, saturn);
37 Moon *tethys = new Moon("Tethys", 295, 530, saturn);
38 Moon *dione = new Moon("Dione", 377, 560, saturn);
39 Moon *rhea = new Moon("Rhea", 527, 765, saturn);
40 Moon *titan = new Moon("Titan", 1222, 2575, saturn);
41 Moon *hyperion = new Moon("Hyperion", 1481, 143, saturn);
42 Moon *iapetus = new Moon("Iapetus", 3561, 730, saturn);
43
44 Planet *uranus = new Planet("Uranus", 2870990, sun);
45 Moon *miranda = new Moon("Miranda", 130, 236, uranus);
(idb) info source
Current source file is solarSystem.cxx
DBX Mode
You can see and modify the current source file selection:
select_source_file_command
: fileexpr [ expression ]
Use the file command without a file name to display the name of the current file scope. Include the file name to change the file scope. Change the file scope to set a breakpoint in a function not in the file currently being executed.
To see source code for or set a breakpoint in a function not in the file currently being executed, use the file command to set the file scope.
If the file name is not a literal, use the fileexpr command. For example, if you have a script that calculates a file name in a debugger variable or in a routine that returns a file name as a string, you can use fileexpr to set the file.
The following example uses the file command to set the debugger file scope to a file different from the main program, and then stops at line number 26 in that file. This example also shows the fileexpr command setting the current scope back to the original file, which is solarSystem.cxx.
(idb) run
[1] stopped at [int main(void):114 0x080569f8]
114 unsigned int j = 1; // for scoping examples
(idb) file
/home/user/examples/solarSystemSrc/main/solarSystem.cxx
(idb) set $originalFile = "solarSystem.cxx"
(idb) list 36:10
36 Moon *enceladus = new Moon("Enceladus", 238, 260, saturn);
37 Moon *tethys = new Moon("Tethys", 295, 530, saturn);
38 Moon *dione = new Moon("Dione", 377, 560, saturn);
39 Moon *rhea = new Moon("Rhea", 527, 765, saturn);
40 Moon *titan = new Moon("Titan", 1222, 2575, saturn);
41 Moon *hyperion = new Moon("Hyperion", 1481, 143, saturn);
42 Moon *iapetus = new Moon("Iapetus", 3561, 730, saturn);
43
44 Planet *uranus = new Planet("Uranus", 2870990, sun);
45 Moon *miranda = new Moon("Miranda", 130, 236, uranus);
(idb) file star.cxx
(idb) list 36:10
36 void Star::printBody(unsigned int i) const
37 {
38 std::cout << "(" << i << ") Star [" << name()
39 << "], class [" << stellarClassName(classification())
40 << ((int)subclassification()) << "]" << std::endl;
41 }
42
43 StellarClass Star::classification() const
44 {
45 return _classification;
(idb) stop at 38
[#2: stop at "/home/user/examples/solarSystemSrc/star.cxx":38]
(idb) cont
[2] stopped at [virtual void Star::printBody(unsigned int) const:38 0x08054526]
38 std::cout << "(" << i << ") Star [" << name()
(idb) file
/home/user/examples/solarSystemSrc/main/solarSystem.cxx
(idb) fileexpr $originalFile
(idb) file
/home/user/examples/solarSystemSrc/main/solarSystem.cxx
(idb) list 36:10
36 Moon *enceladus = new Moon("Enceladus", 238, 260, saturn);
37 Moon *tethys = new Moon("Tethys", 295, 530, saturn);
38 Moon *dione = new Moon("Dione", 377, 560, saturn);
39 Moon *rhea = new Moon("Rhea", 527, 765, saturn);
40 Moon *titan = new Moon("Titan", 1222, 2575, saturn);
41 Moon *hyperion = new Moon("Hyperion", 1481, 143, saturn);
42 Moon *iapetus = new Moon("Iapetus", 3561, 730, saturn);
43
44 Planet *uranus = new Planet("Uranus", 2870990, sun);
45 Moon *miranda = new Moon("Miranda", 130, 236, uranus);