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


Hi Jim,

Thanks for your suggestion. But same problem is noticed with gdb version 6.6.

When I try to print the address of variable, they are different
Program prints address as 0xffefc0c. But gdb prints address as  0xffde000

Also if the variable is referenced in the main program(which loads the
shared lib), it works perfect.
(I mean there is no discrepency in values printed by gdb/program)

Regards,
Rajeev

PS: I somehow did not receive your below reply on time. Today I
happened to notice while browsing on some other topic.

From: Jim Blandy <jimb at codesourcery dot com>
To: "Rajeev Bhaskaran" <rajeevb at gmail dot com>
Cc: gdb at sourceware dot org
Date: Tue, 10 Apr 2007 16:09:33 -0700
Subject: Re: problem printing global variables in a shared library
References: <139b5f180703302342r3ade1f63qb62feb7c785747ac@mail.gmail.com>

--------------------------------------------------------------------------------

"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]