Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print array contents to a file using gdb

I am debugging a while loop using conditional breakpoints in gdb. There are multiple large arrays that are getting created in while loop. I would like to print them in a file while debugging so that I can compare using diff later.

I am able to visualize content at the console using the following command :

(gdb) p *&ff[0]@10

where ff is my array. Kindly tell how I can redirect them to text file.

like image 952
Shreya Avatar asked Sep 08 '25 10:09

Shreya


1 Answers

You can use:

(gdb) set logging file large_array.txt
(gdb) set logging on

By default the logging file name is gdb.txt

You can find more details at: https://sourceware.org/gdb/onlinedocs/gdb/Logging-Output.html

There is also one WA gdb --args a.out arg1 ... |& tee gdb_out.txt

like image 59
Mohit Jain Avatar answered Sep 10 '25 01:09

Mohit Jain