简体   繁体   English

使用gdb将数组内容打印到文件中

[英]print array contents to a file using gdb

I am debugging a while loop using conditional breakpoints in . 我正在使用条件断点调试while循环。 There are multiple large arrays that are getting created in while loop. while循环中创建了多个大型数组。 I would like to print them in a file while debugging so that I can compare using diff later. 我想在调试时将它们打印在文件中,以便以后可以使用diff

I am able to visualize content at the console using the following command : 我可以使用以下命令在控制台上可视化内容:

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

where ff is my array. ff是我的数组。 Kindly tell how I can redirect them to text file. 请告诉我如何将它们重定向到文本文件。

You can use: 您可以使用:

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

By default the logging file name is gdb.txt 默认情况下,日志文件名是gdb.txt

You can find more details at: https://sourceware.org/gdb/onlinedocs/gdb/Logging-Output.html 您可以在以下位置找到更多详细信息: https : //sourceware.org/gdb/onlinedocs/gdb/Logging-Output.html

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

You set logging by using 您使用设置日志记录

(gdb) set logging on

after this, all command output will be output in a file called "gdb.txt". 此后,所有命令输出将输出到名为“ gdb.txt”的文件中。 You can find the array content in the file. 您可以在文件中找到阵列内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM