Pages

Thursday, 10 May 2012

Printing source lines in GDB

list command is used to print the source code inside the gdb.

(gdb) list
1    #include
2    void main()
3    {
4        int x,y=5,z;
5        x=10;
6        z=x/y;
7        printf("Z=%d\n",z);
8    }
9   
10       
(gdb)
 


The list command with two comma-separated integer parameters will show code between those two line numbers,
example,
(gdb) list 2,6
2    void main()
3    {
4        int x,y=5,z;
5        x=10;
6        z=x/y;
(gdb)


By default GDB prints 10 source lines for the list command. Pressing an enter key will print another 10 lines.
We can change this size by set listsize command
syntax
          set listsize count

The command "show listsize" will show the number of source lines printed for the list command

(gdb) set listsize 15
(gdb) show listsize
Number of source lines gdb will list by default is 15.
(gdb)


No comments:

Post a Comment