Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] stabs: remember types that cross reference another type
@ 2003-10-31 20:08 Joel Brobecker
  2003-11-03 18:16 ` Daniel Jacobowitz
  2003-11-03 22:59 ` Joel Brobecker
  0 siblings, 2 replies; 7+ messages in thread
From: Joel Brobecker @ 2003-10-31 20:08 UTC (permalink / raw)
  To: gdb-patches

Hello,

We encountered the following problem when using GNAT to compile
the following pasted at the end of this message. Sorry the program
is in Ada instead of C, but I couldn't reproduce it with C.

The problem is when the user tries to print the type of My_Str.
GDB should return a string, but instead we got:

        Attempt to take contents of a non-pointer value

After investigating, I found that the stabs generated by the compiler
contained the following entries:

        .stabs "s5:(0,97)=xsstring___XUP:",128,0,5,-476
        .stabs "R6b:(0,97)",128,0,12,-484

(R6b is a variable that GDB ends up using in place of My_Str for reasons
that are related to the encoding used by GNAT).

So when GDB reads the type information for R6b, it finds that it is
of type number (0,97), which should mean the same type as s5.
Unfortunately, GDB forgot to save a reference to the type associated
to type (0,97) in the type_vector when processing the type of variable
named "s5". So later on, when GDB tries to compute the type of "R6b",
it doesn't find type (0,97) and therefore assumes it will be defined
later, and hence creates a empty type object which it hopes will be 
filled in later.

As a consequence, when the ada mode tries to print the type of R6b,
it trips over the unexpected symbol type code, and bails out with
the error message above.

The attached patch fixes this particular case.

2003-10-31  J. Brobecker  <brobecker@gnat.com>

        * stabsread.c (read_type): Save a reference to types that are defined
        as cross references to other types.

Tested on x86-linux, no regression.

Ok to apply?

-- 
Joel

<<
with Ada.Strings.Unbounded;

procedure Parse is
   type String_Ptr is access String;
   S5 : String_Ptr := new String'("Hello");

   function Foos return String is
   begin
      return "string";
   end Foos;

   My_Str : String := Foos;

   Ustring : Ada.Strings.Unbounded.Unbounded_String;  -- STOP

begin
   null;
end Parse;
>>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFA] stabs: remember types that cross reference another type
  2003-10-31 20:08 [RFA] stabs: remember types that cross reference another type Joel Brobecker
@ 2003-11-03 18:16 ` Daniel Jacobowitz
  2003-11-03 22:59 ` Joel Brobecker
  1 sibling, 0 replies; 7+ messages in thread
From: Daniel Jacobowitz @ 2003-11-03 18:16 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On Fri, Oct 31, 2003 at 12:08:51PM -0800, Joel Brobecker wrote:
> Hello,
> 
> We encountered the following problem when using GNAT to compile
> the following pasted at the end of this message. Sorry the program
> is in Ada instead of C, but I couldn't reproduce it with C.
> 
> The problem is when the user tries to print the type of My_Str.
> GDB should return a string, but instead we got:
> 
>         Attempt to take contents of a non-pointer value
> 
> After investigating, I found that the stabs generated by the compiler
> contained the following entries:
> 
>         .stabs "s5:(0,97)=xsstring___XUP:",128,0,5,-476
>         .stabs "R6b:(0,97)",128,0,12,-484
> 
> (R6b is a variable that GDB ends up using in place of My_Str for reasons
> that are related to the encoding used by GNAT).
> 
> So when GDB reads the type information for R6b, it finds that it is
> of type number (0,97), which should mean the same type as s5.
> Unfortunately, GDB forgot to save a reference to the type associated
> to type (0,97) in the type_vector when processing the type of variable
> named "s5". So later on, when GDB tries to compute the type of "R6b",
> it doesn't find type (0,97) and therefore assumes it will be defined
> later, and hence creates a empty type object which it hopes will be 
> filled in later.
> 
> As a consequence, when the ada mode tries to print the type of R6b,
> it trips over the unexpected symbol type code, and bails out with
> the error message above.
> 
> The attached patch fixes this particular case.
> 
> 2003-10-31  J. Brobecker  <brobecker@gnat.com>
> 
>         * stabsread.c (read_type): Save a reference to types that are defined
>         as cross references to other types.
> 
> Tested on x86-linux, no regression.
> 
> Ok to apply?

No patch?

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFA] stabs: remember types that cross reference another type
  2003-10-31 20:08 [RFA] stabs: remember types that cross reference another type Joel Brobecker
  2003-11-03 18:16 ` Daniel Jacobowitz
@ 2003-11-03 22:59 ` Joel Brobecker
  2003-12-04  5:20   ` Elena Zannoni
  1 sibling, 1 reply; 7+ messages in thread
From: Joel Brobecker @ 2003-11-03 22:59 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 2038 bytes --]

[Rhaaaa, resending, with the patch this time. Thanks Daniel!]

Hello,

We encountered the following problem when using GNAT to compile
the following pasted at the end of this message. Sorry the program
is in Ada instead of C, but I couldn't reproduce it with C.

The problem is when the user tries to print the type of My_Str.
GDB should return a string, but instead we got:

        Attempt to take contents of a non-pointer value

After investigating, I found that the stabs generated by the compiler
contained the following entries:

        .stabs "s5:(0,97)=xsstring___XUP:",128,0,5,-476
        .stabs "R6b:(0,97)",128,0,12,-484

(R6b is a variable that GDB ends up using in place of My_Str for reasons
that are related to the encoding used by GNAT).

So when GDB reads the type information for R6b, it finds that it is
of type number (0,97), which should mean the same type as s5.
Unfortunately, GDB forgot to save a reference to the type associated
to type (0,97) in the type_vector when processing the type of variable
named "s5". So later on, when GDB tries to compute the type of "R6b",
it doesn't find type (0,97) and therefore assumes it will be defined
later, and hence creates a empty type object which it hopes will be 
filled in later.

As a consequence, when the ada mode tries to print the type of R6b,
it trips over the unexpected symbol type code, and bails out with
the error message above.

The attached patch fixes this particular case.

2003-10-31  J. Brobecker  <brobecker@gnat.com>

        * stabsread.c (read_type): Save a reference to types that are defined
        as cross references to other types.

Tested on x86-linux, no regression.

Ok to apply?

-- 
Joel

<<
with Ada.Strings.Unbounded;

procedure Parse is
   type String_Ptr is access String;
   S5 : String_Ptr := new String'("Hello");

   function Foos return String is
   begin
      return "string";
   end Foos;

   My_Str : String := Foos;

   Ustring : Ada.Strings.Unbounded.Unbounded_String;  -- STOP

begin
   null;
end Parse;
>>

-- 
Joel

[-- Attachment #2: stabsread.c.diff --]
[-- Type: text/plain, Size: 508 bytes --]

Index: stabsread.c
===================================================================
RCS file: /cvs/src/src/gdb/stabsread.c,v
retrieving revision 1.65
diff -u -p -r1.65 stabsread.c
--- stabsread.c	6 Oct 2003 19:27:12 -0000	1.65
+++ stabsread.c	3 Nov 2003 22:58:09 -0000
@@ -1852,6 +1852,8 @@ again:
 		{
 		  obstack_free (&objfile->type_obstack, type_name);
 		  type = SYMBOL_TYPE (sym);
+	          if (typenums[0] != -1)
+	            *dbx_lookup_type (typenums) = type;
 		  return type;
 		}
 	    }

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFA] stabs: remember types that cross reference another type
  2003-11-03 22:59 ` Joel Brobecker
@ 2003-12-04  5:20   ` Elena Zannoni
  2003-12-05  0:22     ` Joel Brobecker
  0 siblings, 1 reply; 7+ messages in thread
From: Elena Zannoni @ 2003-12-04  5:20 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

Joel Brobecker writes:
 > [Rhaaaa, resending, with the patch this time. Thanks Daniel!]
 > 
 > Hello,
 > 
 > We encountered the following problem when using GNAT to compile
 > the following pasted at the end of this message. Sorry the program
 > is in Ada instead of C, but I couldn't reproduce it with C.
 > 
 > The problem is when the user tries to print the type of My_Str.
 > GDB should return a string, but instead we got:
 > 
 >         Attempt to take contents of a non-pointer value
 > 
 > After investigating, I found that the stabs generated by the compiler
 > contained the following entries:
 > 
 >         .stabs "s5:(0,97)=xsstring___XUP:",128,0,5,-476
 >         .stabs "R6b:(0,97)",128,0,12,-484
 > 
 > (R6b is a variable that GDB ends up using in place of My_Str for reasons
 > that are related to the encoding used by GNAT).
 > 
 > So when GDB reads the type information for R6b, it finds that it is
 > of type number (0,97), which should mean the same type as s5.
 > Unfortunately, GDB forgot to save a reference to the type associated
 > to type (0,97) in the type_vector when processing the type of variable
 > named "s5". So later on, when GDB tries to compute the type of "R6b",
 > it doesn't find type (0,97) and therefore assumes it will be defined
 > later, and hence creates a empty type object which it hopes will be 
 > filled in later.
 > 
 > As a consequence, when the ada mode tries to print the type of R6b,
 > it trips over the unexpected symbol type code, and bails out with
 > the error message above.
 > 
 > The attached patch fixes this particular case.
 > 
 > 2003-10-31  J. Brobecker  <brobecker@gnat.com>
 > 
 >         * stabsread.c (read_type): Save a reference to types that are defined
 >         as cross references to other types.
 > 
 > Tested on x86-linux, no regression.
 > 
 > Ok to apply?
 > 


Yes, but the comment before that loop you are changing needs some
revamping. Reading it, it really looks like it is a useless/obsoleted
thing we are doing here, while now it's not the case anymore. I mean,
it is useful.

elena


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFA] stabs: remember types that cross reference another type
  2003-12-04  5:20   ` Elena Zannoni
@ 2003-12-05  0:22     ` Joel Brobecker
  2003-12-05  0:27       ` Elena Zannoni
  0 siblings, 1 reply; 7+ messages in thread
From: Joel Brobecker @ 2003-12-05  0:22 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: gdb-patches

> Yes, but the comment before that loop you are changing needs some
> revamping. Reading it, it really looks like it is a useless/obsoleted
> thing we are doing here, while now it's not the case anymore. I mean,
> it is useful.

yes, I agree. I am not sure how much information to keep though.
Would the following be ok?

  /* If this type has already been declared, then reuse the same type
     rather than allocating a new one.  This saves some memory.  */

The current comment is:

        /* Now check to see whether the type has already been
           declared.  This was written for arrays of cross-referenced
           types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
           sure it is not necessary anymore.  But it might be a good
           idea, to save a little memory.  */

-- 
Joel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFA] stabs: remember types that cross reference another type
  2003-12-05  0:22     ` Joel Brobecker
@ 2003-12-05  0:27       ` Elena Zannoni
  2003-12-05  0:47         ` Joel Brobecker
  0 siblings, 1 reply; 7+ messages in thread
From: Elena Zannoni @ 2003-12-05  0:27 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: Elena Zannoni, gdb-patches

Joel Brobecker writes:
 > > Yes, but the comment before that loop you are changing needs some
 > > revamping. Reading it, it really looks like it is a useless/obsoleted
 > > thing we are doing here, while now it's not the case anymore. I mean,
 > > it is useful.
 > 
 > yes, I agree. I am not sure how much information to keep though.
 > Would the following be ok?
 > 

yep

elena


 >   /* If this type has already been declared, then reuse the same type
 >      rather than allocating a new one.  This saves some memory.  */
 > 
 > The current comment is:
 > 
 >         /* Now check to see whether the type has already been
 >            declared.  This was written for arrays of cross-referenced
 >            types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
 >            sure it is not necessary anymore.  But it might be a good
 >            idea, to save a little memory.  */
 > 
 > -- 
 > Joel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFA] stabs: remember types that cross reference another type
  2003-12-05  0:27       ` Elena Zannoni
@ 2003-12-05  0:47         ` Joel Brobecker
  0 siblings, 0 replies; 7+ messages in thread
From: Joel Brobecker @ 2003-12-05  0:47 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 261 bytes --]

> yep

Great!

For the record, here is the patch I ended up committing.

2003-12-04  J. Brobecker  <brobecker@gnat.com>

        * stabsread.c (read_type): Save a reference to types that are defined
        as cross references to other types.

Thanks,
-- 
Joel

[-- Attachment #2: stabsread.c.diff --]
[-- Type: text/plain, Size: 1106 bytes --]

Index: stabsread.c
===================================================================
RCS file: /cvs/src/src/gdb/stabsread.c,v
retrieving revision 1.68
diff -u -p -r1.68 stabsread.c
--- stabsread.c	15 Nov 2003 21:49:30 -0000	1.68
+++ stabsread.c	5 Dec 2003 00:31:35 -0000
@@ -1564,11 +1564,9 @@ again:
 	  *pp = from + 1;
 	}
 
-	/* Now check to see whether the type has already been
-	   declared.  This was written for arrays of cross-referenced
-	   types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
-	   sure it is not necessary anymore.  But it might be a good
-	   idea, to save a little memory.  */
+        /* If this type has already been declared, then reuse the same
+           type, rather than allocating a new one.  This saves some
+           memory.  */
 
 	for (ppt = file_symbols; ppt; ppt = ppt->next)
 	  for (i = 0; i < ppt->nsyms; i++)
@@ -1582,6 +1580,8 @@ again:
 		{
 		  obstack_free (&objfile->type_obstack, type_name);
 		  type = SYMBOL_TYPE (sym);
+	          if (typenums[0] != -1)
+	            *dbx_lookup_type (typenums) = type;
 		  return type;
 		}
 	    }

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-12-05  0:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-31 20:08 [RFA] stabs: remember types that cross reference another type Joel Brobecker
2003-11-03 18:16 ` Daniel Jacobowitz
2003-11-03 22:59 ` Joel Brobecker
2003-12-04  5:20   ` Elena Zannoni
2003-12-05  0:22     ` Joel Brobecker
2003-12-05  0:27       ` Elena Zannoni
2003-12-05  0:47         ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox