Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print whole string verbatim in gdb

Tags:

c

debugging

gdb

I'm printing a string(char *) in gdb

(gdb) p l
l=0x9aa1f48 "up2 129104596496602200 19 0 0 3 0 eth1 XX :001CB",'0' <repeats 12 times>, "DC"

Is there a setting to have p print the whole string and not fill inn the "repeats ... ". While at it - also extend the default printable length of a string, p seems to cut off if the string is quite long.

like image 376
nos Avatar asked Feb 12 '10 15:02

nos


2 Answers

set print repeats 0

Example:

(gdb) p "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
$6 = 'a' <repeats 30 times>
(gdb) set print repeats 0
(gdb) p "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
$7 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
(gdb) set print repeats 10
(gdb) p "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
$8 = 'a' <repeats 30 times>
like image 173
kennytm Avatar answered Oct 01 '22 21:10

kennytm


Use gdb's printf command like this:

(gdb) printf "%s\n", a
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

instead of

(gdb) p a  
$1 = 'a' <repeats 32 times>
like image 24
Todd Hayton Avatar answered Oct 01 '22 21:10

Todd Hayton