This is the mail archive of the gdb-prs@sources.redhat.com 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]

symtab/1830: debugging static local variables gives wrong results


>Number:         1830
>Category:       symtab
>Synopsis:       debugging static local variables gives wrong results
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 16 17:18:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Manfred.Neugebauer@siemens.com
>Release:        gdb 6.2.1
>Organization:
>Environment:
cygwin / Windows XP, remote debuging
>Description:
Hallo,

We use the gnu tools for an embedded realtime kernel in a host-target configuration. Here we have a problem when we want to view a static local variable (actually using gdb 6.2.1). Here is the example:

static int myGlobalFlag1 = 5;
static int myGlobalFlag2 = 0;

void myFunction()
{
	static int myLocalFlag1 = 7;
	static int myLocalFlag2 = 0;
}

When you use global or static local variable these variables are either part of the ".data" section (initialization value not "0") or part of the ".bss" section (initialization value == "0"). I can see the global variables ("GlobalFlag1" and "GlobalFlag2") correctly. The same is true for "myLocalFlag1". However, "myLocalFlag2" is shown with a value taken from the ".data" section and not from the ".bss" section. Both sections are relocated during startup of the debug session during the built-up of the remote connection with the "qOffset" command.

I tried to debug this problem and found the following hints:

In source file dbxread.c there is the function read_ofile_symtab(). Here the various symbols are read (fill_symbuf()) and then processed in process_one_symbol(). static local variables within the data section have the type "N_STSYM". static local variables within the .bss section should have the type "N_LCSYM" but they havae "N_STSYM". I don't know why these variables don't have the correct type, since the object file shows them in the .bss section. I did not find where this type is set during the reading from the object file (any hint?).

All global variables (.bss or .data, type N_GSYM) do also have an identical type, but the address calculation of those variables gets a flag to do the specific calculation later (see line 903 in file stabsread.c). I wonder why this can't be done with static local variables.

Since I don't have a very deep knowledge about the gdb sources, I tried a different workaround (see attachment). in process_one_symbol() (file dbxread.c) and the case N_STSYM I search for the symbol and its section (this is a little complicated since those names are not seen directly).

The tests showed a positive result, although there are some limitations in this approach (a static local variable with the same name is initialized with "0" and != "0" in different functions may not be shown correctly).

Bug reports 1344 and 1350 describe a similar problem. So I hope we can make some progress in this area.

Manfred.

>How-To-Repeat:
take a simple program with static local variables.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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