更改 gdb 显示未初始化数据的方式
我正在调试一个程序,该程序声明了一个包含 1024 个元素的数组,但它直到很久以后才被初始化。每次我使用“info locals”时,它都会向我显示这个非常长的未初始化数据列表。有什么方法可以改变 gdb 呈现未初始化变量的方式吗?类似于 lot_data[1024]=UNINITIALIZED 的内容。
I'm debugging a program that declares an array with 1024 elements and it's not initialized until much later. Every time I use "info locals" it shows me this really long list of uninitialized data. Is there any way to change the way that gdb presents uninitialized variables? Something along the lines of lot_data[1024]=UNINITIALIZED.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不。GDB
不知道内存位置是否已分配。对于 GDB 来说,它只是位,并且它不能根据位的值来自何处(它不知道)来不同地显示位。
PS 实际上,通过仪器跟踪位的状态是可能的(
clang -fsanitize=memory -fsanitize-memory-track-origins ...
),但这是一件相当昂贵的事情。还要考虑尽管分配了内存,但内存仍可能保持未初始化状态:
No.
GDB doesn't know whether a memory location has been assigned or not. To GDB it's just bits, and it can't display bits differently depending on where their value came from (which it doesn't know).
P.S. Actually tracking the state of bits is possible with instrumentation (
clang -fsanitize=memory -fsanitize-memory-track-origins ...
), but is a fairly expensive thing to do.Also consider that memory can remain uninitialized despite being assigned: