Tuesday, June 9, 2009

Printing whole string in GDB

In GDB generally to print the value of the variable ,we use print or just p .
But for the strings or arrays of large size , it wont print whole string or array.
we have to do some modifications.

By default GDB will print upto 200 characters ,if the string is very large.
To change this there is command in GDB

set print elements number-of-elements

Set a limit on how many elements of an array GDB will print. If GDB is printing a large array, it stops printing after it has printed the number of elements set by the set print elements command. This limit also applies to the display of strings. Setting number-of-elements to zero means that the printing is unlimited.
e.g.

(gdb) set print element 20
(gdb)

next time it will print upto 20 characters

(gdb) set print element 50
(gdb)

next time it will print upto 20 characters

(gdb) set print element 0
(gdb)

next time it will print whole array or string

No comments:

Popular Posts