This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: problem printing global variables in a shared library


"Rajeev Bhaskaran" <rajeevb@gmail.com> writes:
> I am using gdb 6.5 to debug programs on linux 2.6.14-7, PQ3(MPC8555E) processor.
>
> The global variables(initialized) in a shared library are printed
> incorrectly(junk) by gdb print command.
> Printing the same variables from program being debugged using printf,
> displays the correct value.
> The same problem is noticed while printing values of "errno" global
> variable.

Hi, Rajeev.  Could you install GDB 6.6, and see if the problem is
still there?

You might try having your program print the variable's address, and
then asking GDB to do the same ('print &x'), and see if they agree.

Be careful with 'errno'; it's not an ordinary variable.  It needs to
have a distinct value in every thread, so it is often a macro that
expands to an expression containing a function call (like
'(*__errno_location ())'), or a __thread variable.

> If the global variable in shared library is declared as a static type,
> it is displayed correctly by gdb.

Static variables in shared libraries are handled differently than
global variables, since the main executable can't provide its own
definition of static variables, but it can provide its own definitions
of global variables, which the shared library must use instead of its
own.

> Code optimization is turned off while debugging.

This is a good thing to do, although usually optimization doesn't do
much with global variables.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]