c - Confused by gdb print ptr vs print "%s" -
1167 ptr = (void*)getcwd(cwd, max_path_length-1); (gdb) n 1168 if (!ptr) { (gdb) print ptr $1 = 0xbff2d96c "/media/mmc-sd/partition1/aaaaaaaaaaa" (gdb) print &cwd $2 = (char (*)[3500]) 0xbff2d96c (gdb) print strlen(cwd) $3 = 36 (gdb) print "%s",cwd $4 = "/media/mmc-sd/partition1/aaaaaaaaaaa", '\0' <repeats 912 times>, "��o�001\000\000\000\000��027\000\000\000�3����el鷠3�000��027\000\000\000\000\000\000\000\027\000\000\000\000��/�027\000\000\000�3����n����\230���鷠3�000��027\000\000\000\000\000\000\000��000\000\000\000\001\000\000\000��m鷠3����\000\000\000\000.\231�027��w\005\b\001\000"... (gdb) print "%s", ptr $5 = 0xbff2d96c "/media/mmc-sd/partition1/aaaaaaaaaaa" (gdb) quit
why ptr printing string correctly cwd not; affects program , crashes if try use cwd...
[edit: turns out crash caused stupid buffer overflow on var... grr...not gdb, print question still valid]
the reason cwd
printed differently in gdb
because gdb
knows ptr
char *
(i guess) , cwd
array of length 3500
(as shown in output). when printing ptr
prints pointer value (and service string points to) , when printing cwd
prints whole array.
i don't see reason why using cwd
instead of ptr
lead problems, need see code sure.
Comments
Post a Comment