Reputation: 148
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.
Upvotes: 1
Views: 287
Reputation: 213754
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
Upvotes: 1