Starting the Debugger. Simple Debugging

Before you start the debugger, make sure that you have correctly set the size information for your terminal; otherwise, the debugger's command line editing support may act unpredictably. For example, if your terminal is 25x80, you may need to set the following:

% stty rows 25 ; setenv LINES 25

% stty cols 80 ; setenv COLS 80

There are four basic alternatives for running the debugger on a process (see examples below):

  1. Have the debugger create the process using the shell command line to identify the executable to run. (dbx) (gdb)
  2. Have the debugger create the process using the debugger commands to identify the executable to run. (dbx) (gdb)
  3. Have the debugger attach to a running process using the shell command line to identify the process and the executable file that process is running. (dbx) (gdb)
  4. Have the debugger attach to a running process using the debugger commands to identify the process and the executable file that process is running. (dbx) (gdb)

DBX Mode

Intel IDB starts operating in DBX mode by default, so you do not have to specify any special options in the shell command line.

Examples:

1. Creating the process using the shell command line.

 % idb a.out

Intel(R) Debugger for ..., Version ..., Build ...

------------------

object file name: a.out

Reading symbolic information ...done

(idb) stop in main

[#1: stop in int main(void) ]

(idb) run

 

2. Creating the process using the debugger commands.

% idb

Intel(R) Debugger for ..., Version ..., Build ...

------------------

(idb) load a.out

Reading symbolic information ...done

(idb) stop in main

[#1: stop in int main(void) ]

(idb) run

 

3. Attaching to a running process using the shell command line.

% ./a.out &

[1] 27859

% jobs

[1]+  Running                 ./a.out &

% idb a.out -pid 27859

Intel(R) Debugger for ..., Version ..., Build ...

------------------

Reading symbolic information ...done

Attached to process id 27859  ....

 

Press Ctrl+C to interrupt the process.

4. Attaching to the process using the debugger commands.

% ./a.out &

[1] 27859

% jobs

[1]+  Running                 ./a.out &

% idb

Intel(R) Debugger for ..., Version ..., Build ...

------------------

(idb) attach 27859 a.out

Reading symbolic information ...done

Attached to process id 27859  ....

 

Press Ctrl+C to interrupt the process.

GDB Mode

To start the debugger in the GDB mode, specify the -gdb option in the shell command line.

Examples:

1. Creating the process using the shell command line.

% idb -gdb a.out

Intel(R) Debugger for ..., Version ..., Build ...

------------------

object file name: a.out

Reading symbols from a.out...done

(idb) break main

Breakpoint 1 at 0x80484f6: file qwerty.c, line 9.

(idb) run

 

2. Creating the process using the debugger commands.

% idb -gdb

Intel(R) Debugger for ..., Version ..., Build ...

-------------------

(idb) file a.out

Reading symbols from a.out...done.

(idb) break main

Breakpoint 1 at 0x80484f6: file qwerty.c, line 9.

(idb) run

 

3. Attaching to a running process using the shell command line.

% ./a.out &

[1] 27859

% jobs

[1]+  Running                 ./a.out &

% idb -gdb a.out -pid 27859

Intel(R) Debugger for ..., Version ..., Build ...

------------------

object file name: a.out

Reading symbols from a.out...done.

Attached to process id 27859  ....

 

Press Ctrl+C to interrupt the process.

4. Attaching to the process using the debugger commands.

% ./a.out &

[1] 27859

% jobs

[1]+  Running                 ./a.out &

% idb -gdb

Intel(R) Debugger for ..., Version ..., Build ...

(idb) file a.out

Reading symbols from a.out...done.

(idb) attach 27859

Attached to process id 27859  ....

 

Press Ctrl+C to interrupt the process.

Note:

In the case of Fortran, routine main at which your program stops is not your main program unit. Rather, it is a main routine supplied by the Fortran system that performs some initialization and then calls your code. Just step forward using the step command a couple of times (probably twice) and you will soon step into your code.

Note:

If you want full compatibility with GDB output, you need to set the debugger variable $gdb_compatible_output to 1. Otherwise, IDB will produce the extended GDB output in some cases.

See Attaching to a Running Program for the information about how to obtain the PID of a program.