Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I print the full value of a long string in gdb?

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 whole string?

like image 972
John Carter Avatar asked Oct 24 '08 12:10

John Carter


People also ask

How to print long string in GDB?

When GDB starts, this limit is set to 200. Setting number-of-elements to zero means that the printing is unlimited. Nowadays you might also need "set print repeats 0", otherwise GDB will omit repeated elements of the string/array. You may also need to "set max-value-size unlimited".

What does print do in GDB?

The usual way to examine data in your program is with the print command (abbreviated p ), or its synonym inspect . It evaluates and prints the value of an expression of the language your program is written in (see section Using GDB with Different Languages).

What does l do in GDB?

To print lines from a source file, use the list command (abbreviated l ). By default, ten lines are printed. There are several ways to specify what part of the file you want to print.


1 Answers

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.
like image 131
John Carter Avatar answered Oct 08 '22 09:10

John Carter