更改 gdb 显示未初始化数据的方式

发布于 2025-01-13 03:37:12 字数 160 浏览 0 评论 0原文

我正在调试一个程序,该程序声明了一个包含 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酸甜透明夹心 2025-01-20 03:37:12

有什么方法可以改变 gdb 显示未初始化变量的方式吗?

不。GDB

不知道内存位置是否已分配。对于 GDB 来说,它只是位,并且它不能根据位的值来自何处(它不知道)来不同地显示位。

PS 实际上,通过仪器跟踪位的状态是可能的(clang -fsanitize=memory -fsanitize-memory-track-origins ...),但这是一件相当昂贵的事情。

还要考虑尽管分配了内存,但内存仍可能保持未初始化状态:

int buf[5];                     // uninitialized memory declared
int k = buf[0];                 // k is still uninitialized
 
int *ip = malloc(sizeof(buf));  // uninitialized memory created
memcpy(buf, ip, sizeof(buf));   // buf is still uninitialized, despite being written to
int j = buf[0];                 // j is still uninitialized

Is there any way to change the way that gdb presents uninitialized variables?

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:

int buf[5];                     // uninitialized memory declared
int k = buf[0];                 // k is still uninitialized
 
int *ip = malloc(sizeof(buf));  // uninitialized memory created
memcpy(buf, ip, sizeof(buf));   // buf is still uninitialized, despite being written to
int j = buf[0];                 // j is still uninitialized
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文