Detect uninitialized memory in gdb

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Detect uninitialized memory in gdb

Sourceware - gdb list mailing list
Greetings.

Suppose I have the following codes:

struct X { ... };

void g(struct X *x_p);

void f()
{
   struct X x_var;
   g(&x_var);
}

In the function of g,  I want to check the data where x_p point to,
however it is possible that it is not initialized like above code. So
do we have a way to detect that the memory x_p point to is not
initialized or not in gdb?

Best Regards
Andy Fan
Reply | Threaded
Open this post in threaded view
|

Re: Detect uninitialized memory in gdb

Sourceware - gdb list mailing list
On Tue, Mar 31, 2020 at 1:08 AM Andy Fan via Gdb <[hidden email]> wrote:

>
> Greetings.
>
> Suppose I have the following codes:
>
> struct X { ... };
>
> void g(struct X *x_p);
>
> void f()
> {
>    struct X x_var;
>    g(&x_var);
> }
>
> In the function of g,  I want to check the data where x_p point to,
> however it is possible that it is not initialized like above code. So
> do we have a way to detect that the memory x_p point to is not
> initialized or not in gdb?

No, it's not really possible with GDB. You want a tool like Valgrind
or Address Sanitizer.

Christian
Reply | Threaded
Open this post in threaded view
|

Re: Detect uninitialized memory in gdb

Sourceware - gdb list mailing list
On Wed, Apr 1, 2020 at 2:48 AM Christian Biesinger <[hidden email]>
wrote:

> On Tue, Mar 31, 2020 at 1:08 AM Andy Fan via Gdb <[hidden email]>
> wrote:
> >
> > Greetings.
> >
> > Suppose I have the following codes:
> >
> > struct X { ... };
> >
> > void g(struct X *x_p);
> >
> > void f()
> > {
> >    struct X x_var;
> >    g(&x_var);
> > }
> >
> > In the function of g,  I want to check the data where x_p point to,
> > however it is possible that it is not initialized like above code. So
> > do we have a way to detect that the memory x_p point to is not
> > initialized or not in gdb?
>
> No, it's not really possible with GDB. You want a tool like Valgrind
> or Address Sanitizer.
>
> Thank you for your reply Christian.   Just because I want to call gdb
script after I know it is initialized,  so Valgrind is not my option now.

Best Regards
Andy Fan