views:

5979

answers:

2

I want to print the full length of a C-string in GDB. By default it's being abbreviated, how do I force GDB to print the string in full?

+21  A: 
set print elements 0

From the GDB manual:

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. When GDB starts, this limit is set to 200. Setting number-of-elements to zero means that the printing is unlimited.

therefromhere
+10  A: 

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.

DusK
This answer is even better than "set print elements 0" (for my purposes) because it respects the newline/carriage return chars instead of escaping them.
mhenry1384