This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
what does print /s do?
- From: dave_rodgman at fastmail dot co dot uk
- To: gdb at sourceware dot org
- Date: Fri, 21 Nov 2008 17:10:10 +0000
- Subject: what does print /s do?
Hi,
I'm having trouble understanding exactly what print /s is intended to
do. I've read the manual, and it says:
(from http://sourceware.org/gdb/current/onlinedocs/gdb_10.html#SEC70)
> Regard as a string, if possible. With this format, pointers to single-byte data are displayed as null-terminated strings and
> arrays of single-byte data are displayed as fixed-length strings. Other values are displayed in their natural types.
>
> Without this format, GDB displays pointers to and arrays of char, unsigned char, and signed char as strings. Single-byte
> members of a vector are displayed as an integer array.
I have two questions:
1. What is the distinction between "pointer to single-byte data" and
"pointers to and arrays of char, unsigned char, and signed char"?
Or is this just poorly worded?
2. Under what circumstances does supplying or not supplying /s make a
difference to the output? I can't find a case where it makes a
difference. For example, when printing a pointer-to-char (here, "string"
is a char array)
(gdb) p /s string
$14 = "abc"
(gdb) p string
$15 = "abc"
If I attempt to do the inverse, i.e., use /s to force interpreting a
non-ptr-to-char as a string, /s is ignored:
(gdb) p /s (int *)string
$16 = (int *) 0x804a018
(gdb) p (int *)string
$17 = (int *) 0x804a018
thanks
Dave
--
dave_rodgman@fastmail.co.uk