This is the mail archive of the
gdb-prs@sources.redhat.com
mailing list for the GDB project.
gdb/506: Member references in a C structure (Linux)
- From: eldo dot tony at wipro dot com
- To: gdb-gnats at sources dot redhat dot com
- Cc: mahesh dot hirehal at wipro dot com
- Date: 23 Apr 2002 11:18:42 -0000
- Subject: gdb/506: Member references in a C structure (Linux)
- Reply-to: eldo dot tony at wipro dot com
>Number: 506
>Category: gdb
>Synopsis: Member references in a C structure (Linux)
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Apr 23 04:28:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: eldo.tony@wipro.com
>Release: GNU gdb 5.1
>Organization:
>Environment:
Linux 2.2.4
GCC 2.95.3
This GDB was configured as "i386-slackware-linux"
>Description:
The GNU Debugger (Version 5.1) is giving a segmentation fault for a particular case of member referencing in a C structure.
See the program below.
struct house_det {
int num;
};
typedef struct house_det house;
main() {
int get_num( house);
house h1= {10};
int temp;
temp=get_num(h1);
return;
}
int get_num(house temp)
{
return(temp.num);
}
While debugging the above program (with the GUI window on Linux), the following behavior is observed.
After setting a watch expression inside the function "get_num" for the structure member "temp.num", when the control returns to the 'main' function a segmentation fault occurs. I think this is because 'temp' is an integer variable in main(), while it is a structure in the function get_num().
However, if I try to set a watch on 'temp.num' in main(), I get a warning, GDB detects a wrong dereference.
Is this a bug ?
>How-To-Repeat:
While debugging the above program (with the GUI window on Linux), the following behavior is observed.
After setting a watch expression inside the function "get_num" for the structure member "temp.num", when the control returns to the 'main' function a segmentation fault occurs.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="t.c"
Content-Disposition: inline; filename="t.c"
/* GDB gives segmentation fault */
struct house_det {
int num;
};
typedef struct house_det house;
main() {
int get_num( house);
house h1= {10};
int temp;
temp=get_num(h1);
return;
}
int get_num(house temp)
{
int a=0;
a++;
return(temp.num);
}