Article View: gnu.gdb.bug
Article #8776Type Declaration/Printing Bug
From: Peter_Stout
Date: Sun, 06 Dec 1992 21:12
Date: Sun, 06 Dec 1992 21:12
172 lines
7956 bytes
7956 bytes
I have run into a bug in GDB 4.5 on a Decstation 5000/20 running Mach
3.0 (MK77 + UX39). It is not able to print structs that contain a
void pointer as the first field. Also, ptype does not print the type
definition correctly. The 'bug' exists in both a locally modified
version built using a 'Mach configuration' and in a version that I
believe was built using GCC 2.1/2.2 and the distributed 'decstation'
configuration. I used the latter version to produce the log included
below.
I have enclosed a sample program and a log of GDB session that
demonstrate the bug. The sample program was compiled with GCC 2.3.2 and
the following command: gcc -ansi -Wall -g -o foo foo.c
I have also enclosed a partial dump of the program's symbol table.
I suspect that GDB is guessing that a struct with a void * as the first
member is an 'enum' rather than 'struct'. This is based on the code in
parse_symbol in the file gdb/mipsread.c. Here is the code fragment from
mipsread.c for GDB versions 4.5.
/* First count the number of fields. */
for (tsym = sh+1; tsym->st != stEnd; tsym++)
if (tsym->st == stMember) {
if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
/* If the type of the member is Nil (or Void)
assume the tag is an enumeration. */
if (tsym->index == indexNil)
type_code = TYPE_CODE_ENUM;
else {
ecoff_swap_tir_in (bigend,
&ax[tsym->index].a_ti,
&tir);
if (tir.bt == btNil || tir.bt == btVoid)
type_code = TYPE_CODE_ENUM;
}
nfields++;
if (tsym->value > max_value)
max_value = tsym->value;
}
After calling ecoff_swap_tir_in it checks whether the base type of the file
is btNil. The nm-dump reports the void pointer fields as 'btNil *'. Should
the code in parse_symbol be checking for a type qualifier?
If I have correctly figured out the problem, it still exists in version 4.7.
Peter Stout
(pds@cs.cmu.edu)
----- Begin Program
typedef struct queue {
void *p1;
void *p2;
} queue_t;
typedef struct _foo {
char *p1;
void *p2;
} foo_t;
typedef struct _bar {
void *p1;
char *p2;
} bar_t;
typedef struct _baz {
char *p1;
char *p2;
} baz_t;
void main(int argc, char **argv)
{
extern volatile void exit(int);
queue_t q;
foo_t foo;
bar_t bar;
baz_t baz;
char temp[16] = "\001\002\004\010";
q.p1 = temp;
foo.p2 = &temp[1];
bar.p1 = &temp[2];
baz.p2 = &temp[3];
exit(*(char *)q.p1 + *(char *)foo.p2 + *(char *)bar.p1 + *baz.p2);
}
----- End Program
----- Begin Log
pds:pds> /usr/misc/bin/gdb foo
GDB is free software and you are welcome to distribute copies of it
under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.5, Copyright 1992 Free Software Foundation, Inc...
(gdb) ptype queue_t
type = struct queue {
struct queue p1;
struct queue p2;
}
(gdb) ptype foo
No symbol "foo" in current context.
(gdb) ptype foo_t
type = struct _foo {
char *p1;
void *p2;
}
(gdb) ptype bar_t
type = struct _bar {
struct _bar p1;
struct _bar p2;
}
(gdb) ptype baz_t
type = struct _baz {
char *p1;
char *p2;
}
(gdb) quit
If you attempt to print a variable of type queue_t or bar_t GDB goes
into (infinite) recursion until you type ^C.
----- End Log
----- Begin Symbol Table (nm -a -p foo)
Symbols from foo:
Name Value Class Type Size Indx Section
../../../../../src/mk/user/libmach/mips/crt0.ss|00000000|File |ref=7 | | 0|Text
__start |00400140|Proc |end=6 btNil | | 1|Text
$32 |00400194|Label | | | 2|Text
$33 |004001c0|Label | | | 3|Text
$34 |004001e4|Label | | | 4|Text
__start |000000bc|End |ref=1 | | 5|Text
../../../../../src/mk/user/libmach/mips/crt0.ss|00000000|End |ref=0 | | 6|Text
foo.c |00000000|File |ref=40 | | 7|Text
queue |00000008|Block |ref=12 | | 8|Info
p1 |00000000|Member |btNil * | | 9|Info
p2 |00000020|Member |btNil * | | 10|Info
|00000000|End |ref=8 | | 11|Info
queue_t |00000000|Typdef |struct queue | | 12|Info
_foo |00000008|Block |ref=17 | | 13|Info
p1 |00000000|Member |char * | | 14|Info
p2 |00000020|Member |btNil * | | 15|Info
|00000000|End |ref=13 | | 16|Info
foo_t |00000000|Typdef |struct _foo | | 17|Info
_bar |00000008|Block |ref=22 | | 18|Info
p1 |00000000|Member |btNil * | | 19|Info
p2 |00000020|Member |char * | | 20|Info
|00000000|End |ref=18 | | 21|Info
bar_t |00000000|Typdef |struct _bar | | 22|Info
_baz |00000008|Block |ref=27 | | 23|Info
p1 |00000000|Member |char * | | 24|Info
p2 |00000020|Member |char * | | 25|Info
|00000000|End |ref=23 | | 26|Info
baz_t |00000000|Typdef |struct _baz | | 27|Info
main |00400200|Proc |end=32 btNil | | 28|Text
argc |00000000|Param |int | | 29|Abs
argv |00000004|Param |char ** | | 30|Abs
|0000001c|Block |ref=38 | | 31|Text
q |ffffffc8|Local |struct queue | | 32|Abs
foo |ffffffd0|Local |struct _foo | | 33|Abs
bar |ffffffd8|Local |struct _bar | | 34|Abs
baz |ffffffe0|Local |struct _baz | | 35|Abs
temp |ffffffe8|Local |char [16] | | 36|Abs
|000000b4|End |ref=31 | | 37|Text
main |000000c8|End |ref=28 | | 38|Text
foo.c |00000000|End |ref=7 | | 39|Text
symbols for libgcc and libc deleted.
----- End Symbol Table
Technical Details
Message-ID:
<21976.723676364@PDS.MACH.CS.CMU.EDU>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.cmu.edu!Peter_StoutShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5053,ca5e0008cd0a365,start X-Google-Attributes: gidf5053,public X-Google-ArrivalTime: 1992-12-06 21:03:37 PST Newsgroups: gnu.gdb.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.cmu.edu!Peter_Stout From: Peter_Stout@cs.cmu.edu Subject: Type Declaration/Printing Bug Message-ID: <21976.723676364@PDS.MACH.CS.CMU.EDU> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Sun, 6 Dec 1992 21:12:44 GMT Approved: bug-gdb@prep.ai.mit.edu Lines: 173