🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gdb.bug
Article #366

(none)

#366
From: Peggy Fieland
Date: Wed, 12 Aug 1992 20:33
116 lines
4657 bytes
Gdb-4.6 (also earlier versions) coredumps when command
"ptype mystruct.xx" is issued, where xx is not a member
of structure mystruct.

Here is test program:

#include <stdio.h>

struct ms
{
int i;
int j;
};

struct ms mystruct;

main()
{
mystruct.i = 5;
mystruct.j = 10;
printf ("%d %d\n", mystruct.i, mystruct.j);

}

Here is a sample debugging session:
cyclonic-tests% gdb46 struct
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.6, Copyright 1992 Free Software Foundation, Inc...
(gdb) b main
Breakpoint 1 at 0x229c: file struct.c, line 13.
(gdb) r
Starting program: /tmp_mnt/net/citron/home/citron/pfieland/gdb-4.6/tests/struct

Breakpoint 1, main () at struct.c:13
13      mystruct.i = 5;
(gdb) ptype mystruct.xx
Segmentation fault (core dumped)
cyclonic-tests%

cyclonic-tests% There is absolutely no warranty for GDB; type "show warranty" for details.
There: Command not found.
Software Foundation, Inc...
(gdb)type: Command not found.
cyclonic-tests% GDB 4.6, Copyright 1992 Free Software Foundation, Inc...
 b maiGDB: Command not found.
n
cyclonic-tests% (gdb) b main
Badly placed ()'s.
Bcyclonic-tests% Breakpoint 1 at 0x229c: file struct.c, line 13.
db)Breakpoint: Command not found.
cyclonic-tests% (gdb) r
Badly placed ()'s.
Scyclonic-tests% Starting program: /tmp_mnt/net/citron/home/citron/pfieland/gdb-4.6/tests/struct
Starting: Command not found.
acyclonic-tests%
cyclonic-tests% akpoint 1, main () at struct.c:13
Badly placed ()'s.
cyclonic-tests% 13      mystruct.i = 5;
(gd13: Command not found.
cyclonic-tests% (gdb) ptype mystruct.xx
Badly placed ()'s.
Scyclonic-tests% Segmentation fault (core dumped)
Badly placed ()'s.
-cyclonic-tests% tcyclonic-tests%
cyclonic-tests%: Command not found.
cyclonic-tests%
cyclonic-tests% gdb gdb46 core
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...
Warning: core file may not match specified executable file.
Core was generated by `gdb46'.
Program terminated with signal 11, Segmentation fault.
Cannot access memory at address 0x0.
#0  0x3f434 in check_stub_type (type=0x0) at ../../../gdb-4.6/gdb/gdbtypes.c:727
../../../gdb-4.6/gdb/gdbtypes.c:727: No such file or directory.
(gdb) bt
#0  0x3f434 in check_stub_type (type=0x0) at ../../../gdb-4.6/gdb/gdbtypes.c:727
#1  0x12b34 in allocate_value (type=0x0) at ../../../gdb-4.6/gdb/values.c:77
#2  0x185dc in value_zero (type=0x0, lv=lval_memory) at ../../../gdb-4.6/gdb/valops.c:131
#3  0x16270 in evaluate_subexp (expect_type=0x0, exp=0x153208, pos=0xf7fff94c,
    noside=EVAL_AVOID_SIDE_EFFECTS) at ../../../gdb-4.6/gdb/eval.c:441
#4  0x1569c in evaluate_type (exp=0x153208) at ../../../gdb-4.6/gdb/eval.c:153
#5  0x2580c in whatis_exp (exp=0x14500e "mystruct.xx", show=1) at ../../../gdb-4.6/gdb/printcmd.c:1073
#6  0x259dc in ptype_command (typename=0x14500e "mystruct.xx", from_tty=1)
    at ../../../gdb-4.6/gdb/printcmd.c:1137
#7  0x361c in execute_command (p=0x14500e "mystruct.xx", from_tty=1) at ../../../gdb-4.6/gdb/main.c:915
#8  0x38c0 in command_loop () at ../../../gdb-4.6/gdb/main.c:976
#9  0x33c0 in main (argc=2, argv=0xf7fffcbc) at ../../../gdb-4.6/gdb/main.c:853

Here is a fix:
*** /home/tools/gnu/gdb-4.6/gdb/valops.c	Mon Jul  6 13:11:19 1992
--- gdb-4.6/gdb/valops.c	Wed Aug 12 16:22:50 1992
***************
*** 130,136 ****
  {
    register value val = allocate_value (type);
  
!   memset (VALUE_CONTENTS (val), 0, TYPE_LENGTH (type));
    VALUE_LVAL (val) = lv;
  
    return val;
--- 135,144 ----
  {
    register value val = allocate_value (type);
  
! /* guard to prevent coredumping on dereference of a null type (caused when, say,
!    doing "ptype var.xx" where xx is not in struct var */
!   if (type != NULL)
!      memset (VALUE_CONTENTS (val), 0, TYPE_LENGTH (type));
    VALUE_LVAL (val) = lv;
  
    return val;
Technical Details
Message-ID: <9208122033.AA15669@citron.sw.stratus.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!citron.sw.stratus.com!pfieland

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gdb.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!citron.sw.stratus.com!pfieland
From: pfieland@citron.sw.stratus.com (Peggy Fieland)
Subject: (none)
Message-ID: <9208122033.AA15669@citron.sw.stratus.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Wed, 12 Aug 1992 20:33:04 GMT
Approved: bug-gdb@prep.ai.mit.edu
Lines: 117