There is a third option: the x command, which allows you to set a different limit for the specific command instead of changing a global setting. To print the first 300 characters of a string you can use x/300s your_string
. The output might be a bit harder to read. For example printing a SQL query results in:
(gdb) x/300sb stmt.c_str() 0x9cd948: "SELECT article.r"... 0x9cd958: "owid FROM articl"... ..
As long as your program's in a sane state, you can also call (void)puts(your_string)
to print it to stdout. Same principle applies to all functions available to the debugger, actually.
The printf
command will print the complete strings:
(gdb) printf "%s\n", string
As long as your program's in a sane state, you can also call (void)puts(your_string)
to print it to stdout. Same principle applies to all functions available to the debugger, actually.
Using set elements ...
isn't always the best way. It would be useful if there were a distinct set string-elements ...
.
So, I use these functions in my .gdbinit:
define pstr
ptype $arg0._M_dataplus._M_p
printf "[%d] = %s\n", $arg0._M_string_length, $arg0._M_dataplus._M_p
end
define pcstr
ptype $arg0
printf "[%d] = %s\n", strlen($arg0), $arg0
end
Caveats:
There is a third option: the x command, which allows you to set a different limit for the specific command instead of changing a global setting. To print the first 300 characters of a string you can use x/300s your_string
. The output might be a bit harder to read. For example printing a SQL query results in:
(gdb) x/300sb stmt.c_str() 0x9cd948: "SELECT article.r"... 0x9cd958: "owid FROM articl"... ..
Just to complete it:
(gdb) p (char[10]) *($ebx)
$87 = "asdfasdfe\n"
You must give a length, but may change the representation of that string:
(gdb) p/x (char[10]) *($ebx)
$90 = {0x61,
0x73,
0x64,
0x66,
0x61,
0x73,
0x64,
0x66,
0x65,
0xa}
This may be useful if you want to debug by their values
As long as your program's in a sane state, you can also call (void)puts(your_string)
to print it to stdout. Same principle applies to all functions available to the debugger, actually.
Using set elements ...
isn't always the best way. It would be useful if there were a distinct set string-elements ...
.
So, I use these functions in my .gdbinit:
define pstr
ptype $arg0._M_dataplus._M_p
printf "[%d] = %s\n", $arg0._M_string_length, $arg0._M_dataplus._M_p
end
define pcstr
ptype $arg0
printf "[%d] = %s\n", strlen($arg0), $arg0
end
Caveats:
Just to complete it:
(gdb) p (char[10]) *($ebx)
$87 = "asdfasdfe\n"
You must give a length, but may change the representation of that string:
(gdb) p/x (char[10]) *($ebx)
$90 = {0x61,
0x73,
0x64,
0x66,
0x61,
0x73,
0x64,
0x66,
0x65,
0xa}
This may be useful if you want to debug by their values
The printf
command will print the complete strings:
(gdb) printf "%s\n", string
As long as your program's in a sane state, you can also call (void)puts(your_string)
to print it to stdout. Same principle applies to all functions available to the debugger, actually.
Source: Stackoverflow.com