Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATH] Change is_pascal_string_type args
@ 2002-05-02  4:18 Pierre Muller
  2002-05-02 11:11 ` Michael Snyder
  0 siblings, 1 reply; 3+ messages in thread
From: Pierre Muller @ 2002-05-02  4:18 UTC (permalink / raw)
  To: gdb-patches


The following patch is only to prepare for the 
next patch for p-exp.y that will enhance the field
search for pascal expressions.

It adds a new argument that can contain
a pointer to the name of the field containing the 
chars of the string.
If the type is a pascal string the retruned value is now
the char array field index plus one.
(to avoid a zero if some new pascal compiler
use the first field to contain the char array one day...)



ChangeLog entry:

2002-05-02  Pierre Muller  <muller@ics.u-strasbg.fr>

	* p-lang.h (is_pascal_string_type): Declaration changed,
	new sixth argument of type char ** added.
	* p-lang.c (is_pascal_string_type): Implementation 
	changed. Args length_pos, length_size, string_pos, char_size
	can now be NULL. New argument arrayname set to the field
	name of the char array. Return value set to char array
	field index plus one.

	* p-valprint.c (pascal_val_print): Adapt to new declaration of 
	is_pascal_string_type function.






Index: p-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/p-lang.c,v
retrieving revision 1.5
diff -u -p -r1.5 p-lang.c
--- p-lang.c	13 Feb 2002 18:49:30 -0000	1.5
+++ p-lang.c	2 May 2002 11:12:00 -0000
@@ -44,7 +44,8 @@ extern void _initialize_pascal_language 
     but this does not happen for Free Pascal nor for GPC.  */
  int
  is_pascal_string_type (struct type *type,int *length_pos,
-                       int * length_size, int *string_pos, int *char_size)
+                       int *length_size, int *string_pos, int *char_size,
+		       char **arrayname)
  {
    if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
      {
@@ -54,11 +55,17 @@ is_pascal_string_type (struct type *type
            && strcmp (TYPE_FIELDS (type)[0].name, "length") == 0 
            && strcmp (TYPE_FIELDS (type)[1].name, "st") == 0)
          {
-          *length_pos = TYPE_FIELD_BITPOS (type, 0) / TARGET_CHAR_BIT;
-          *length_size = TYPE_FIELD_TYPE (type, 0)->length;
-          *string_pos = TYPE_FIELD_BITPOS (type, 1) / TARGET_CHAR_BIT;
-          *char_size = 1;
-          return 1;
+          if (length_pos)
+	    *length_pos = TYPE_FIELD_BITPOS (type, 0) / TARGET_CHAR_BIT;
+          if (length_size)
+	    *length_size = TYPE_FIELD_TYPE (type, 0)->length;
+          if (string_pos)
+	    *string_pos = TYPE_FIELD_BITPOS (type, 1) / TARGET_CHAR_BIT;
+          if (char_size)
+	    *char_size = 1;
+ 	  if (arrayname)
+	    *arrayname = TYPE_FIELDS (type)[1].name;
+         return 2;
          };
        /* GNU pascal strings.  */
        /* Three fields: Capacity, length and schema$ or _p_schema.  */
@@ -66,12 +73,18 @@ is_pascal_string_type (struct type *type
            && strcmp (TYPE_FIELDS (type)[0].name, "Capacity") == 0
            && strcmp (TYPE_FIELDS (type)[1].name, "length") == 0)
          {
-          *length_pos = TYPE_FIELD_BITPOS (type, 1) / TARGET_CHAR_BIT;
-          *length_size = TYPE_FIELD_TYPE (type, 1)->length;
-          *string_pos = TYPE_FIELD_BITPOS (type, 2) / TARGET_CHAR_BIT;
+          if (length_pos)
+	    *length_pos = TYPE_FIELD_BITPOS (type, 1) / TARGET_CHAR_BIT;
+          if (length_size)
+	    *length_size = TYPE_FIELD_TYPE (type, 1)->length;
+          if (string_pos)
+	    *string_pos = TYPE_FIELD_BITPOS (type, 2) / TARGET_CHAR_BIT;
            /* FIXME: how can I detect wide chars in GPC ?? */
-          *char_size = 1;
-          return 1;
+          if (char_size)
+	    *char_size = 1;
+ 	  if (arrayname)
+	    *arrayname = TYPE_FIELDS (type)[2].name;
+         return 3;
          };
      }
    return 0;
Index: p-lang.h
===================================================================
RCS file: /cvs/src/src/gdb/p-lang.h,v
retrieving revision 1.3
diff -u -p -r1.3 p-lang.h
--- p-lang.h	9 Nov 2001 09:48:09 -0000	1.3
+++ p-lang.h	2 May 2002 11:12:00 -0000
@@ -38,7 +38,8 @@ extern void pascal_type_print_method_arg
  
  /* These are in p-lang.c: */
  
-extern int is_pascal_string_type (struct type *, int *, int *, int *, int*);
+extern int 
+  is_pascal_string_type (struct type *, int *, int *, int *, int *, char **);
  
  extern void pascal_printchar (int, struct ui_file *);
  
Index: p-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/p-valprint.c,v
retrieving revision 1.9
diff -u -p -r1.9 p-valprint.c
--- p-valprint.c	8 Jan 2002 02:09:31 -0000	1.9
+++ p-valprint.c	2 May 2002 11:12:01 -0000
@@ -190,8 +190,8 @@ pascal_val_print (struct type *type, cha
  	     as GDB does not recognize stabs pascal strings
  	     Pascal strings are mapped to records
  	     with lowercase names PM  */
-          if (is_pascal_string_type (elttype, &length_pos,
-                                     &length_size, &string_pos, &char_size)
+          if (is_pascal_string_type (elttype, &length_pos, &length_size,
+                                     &string_pos, &char_size, NULL)
  	      && addr != 0)
  	    {
  	      ULONGEST string_length;
@@ -320,7 +320,7 @@ pascal_val_print (struct type *type, cha
        else
  	{
            if (is_pascal_string_type (type, &length_pos, &length_size,
-                                     &string_pos, &char_size))
+                                     &string_pos, &char_size, NULL))
  	    {
  	      len = extract_unsigned_integer (valaddr + embedded_offset + length_pos, length_size);
  	      LA_PRINT_STRING (stream, valaddr + embedded_offset + string_pos, len, char_size, 0);



Pierre Muller
Institut Charles Sadron
6,rue Boussingault
F 67083 STRASBOURG CEDEX (France)
mailto:muller@ics.u-strasbg.fr
Phone : (33)-3-88-41-40-07  Fax : (33)-3-88-41-40-99


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

* Re: [PATH] Change is_pascal_string_type args
  2002-05-02  4:18 [PATH] Change is_pascal_string_type args Pierre Muller
@ 2002-05-02 11:11 ` Michael Snyder
  2002-05-03  0:49   ` Pierre Muller
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Snyder @ 2002-05-02 11:11 UTC (permalink / raw)
  To: Pierre Muller; +Cc: gdb-patches

Pierre Muller wrote:
> 
> The following patch is only to prepare for the
> next patch for p-exp.y that will enhance the field
> search for pascal expressions.
> 
> It adds a new argument that can contain
> a pointer to the name of the field containing the
> chars of the string.
> If the type is a pascal string the retruned value is now
> the char array field index plus one.
> (to avoid a zero if some new pascal compiler
> use the first field to contain the char array one day...)

Pierre, aren't you the Pascal maintainer for gdb?
Seems like you could be approving some of these changes
yourself, since they affect only Pascal.

 
> ChangeLog entry:
> 
> 2002-05-02  Pierre Muller  <muller@ics.u-strasbg.fr>
> 
>         * p-lang.h (is_pascal_string_type): Declaration changed,
>         new sixth argument of type char ** added.
>         * p-lang.c (is_pascal_string_type): Implementation
>         changed. Args length_pos, length_size, string_pos, char_size
>         can now be NULL. New argument arrayname set to the field
>         name of the char array. Return value set to char array
>         field index plus one.
> 
>         * p-valprint.c (pascal_val_print): Adapt to new declaration of
>         is_pascal_string_type function.
> 
> Index: p-lang.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/p-lang.c,v
> retrieving revision 1.5
> diff -u -p -r1.5 p-lang.c
> --- p-lang.c    13 Feb 2002 18:49:30 -0000      1.5
> +++ p-lang.c    2 May 2002 11:12:00 -0000
> @@ -44,7 +44,8 @@ extern void _initialize_pascal_language
>      but this does not happen for Free Pascal nor for GPC.  */
>   int
>   is_pascal_string_type (struct type *type,int *length_pos,
> -                       int * length_size, int *string_pos, int *char_size)
> +                       int *length_size, int *string_pos, int *char_size,
> +                      char **arrayname)
>   {
>     if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
>       {
> @@ -54,11 +55,17 @@ is_pascal_string_type (struct type *type
>             && strcmp (TYPE_FIELDS (type)[0].name, "length") == 0
>             && strcmp (TYPE_FIELDS (type)[1].name, "st") == 0)
>           {
> -          *length_pos = TYPE_FIELD_BITPOS (type, 0) / TARGET_CHAR_BIT;
> -          *length_size = TYPE_FIELD_TYPE (type, 0)->length;
> -          *string_pos = TYPE_FIELD_BITPOS (type, 1) / TARGET_CHAR_BIT;
> -          *char_size = 1;
> -          return 1;
> +          if (length_pos)
> +           *length_pos = TYPE_FIELD_BITPOS (type, 0) / TARGET_CHAR_BIT;
> +          if (length_size)
> +           *length_size = TYPE_FIELD_TYPE (type, 0)->length;
> +          if (string_pos)
> +           *string_pos = TYPE_FIELD_BITPOS (type, 1) / TARGET_CHAR_BIT;
> +          if (char_size)
> +           *char_size = 1;
> +         if (arrayname)
> +           *arrayname = TYPE_FIELDS (type)[1].name;
> +         return 2;
>           };
>         /* GNU pascal strings.  */
>         /* Three fields: Capacity, length and schema$ or _p_schema.  */
> @@ -66,12 +73,18 @@ is_pascal_string_type (struct type *type
>             && strcmp (TYPE_FIELDS (type)[0].name, "Capacity") == 0
>             && strcmp (TYPE_FIELDS (type)[1].name, "length") == 0)
>           {
> -          *length_pos = TYPE_FIELD_BITPOS (type, 1) / TARGET_CHAR_BIT;
> -          *length_size = TYPE_FIELD_TYPE (type, 1)->length;
> -          *string_pos = TYPE_FIELD_BITPOS (type, 2) / TARGET_CHAR_BIT;
> +          if (length_pos)
> +           *length_pos = TYPE_FIELD_BITPOS (type, 1) / TARGET_CHAR_BIT;
> +          if (length_size)
> +           *length_size = TYPE_FIELD_TYPE (type, 1)->length;
> +          if (string_pos)
> +           *string_pos = TYPE_FIELD_BITPOS (type, 2) / TARGET_CHAR_BIT;
>             /* FIXME: how can I detect wide chars in GPC ?? */
> -          *char_size = 1;
> -          return 1;
> +          if (char_size)
> +           *char_size = 1;
> +         if (arrayname)
> +           *arrayname = TYPE_FIELDS (type)[2].name;
> +         return 3;
>           };
>       }
>     return 0;
> Index: p-lang.h
> ===================================================================
> RCS file: /cvs/src/src/gdb/p-lang.h,v
> retrieving revision 1.3
> diff -u -p -r1.3 p-lang.h
> --- p-lang.h    9 Nov 2001 09:48:09 -0000       1.3
> +++ p-lang.h    2 May 2002 11:12:00 -0000
> @@ -38,7 +38,8 @@ extern void pascal_type_print_method_arg
> 
>   /* These are in p-lang.c: */
> 
> -extern int is_pascal_string_type (struct type *, int *, int *, int *, int*);
> +extern int
> +  is_pascal_string_type (struct type *, int *, int *, int *, int *, char **);
> 
>   extern void pascal_printchar (int, struct ui_file *);
> 
> Index: p-valprint.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/p-valprint.c,v
> retrieving revision 1.9
> diff -u -p -r1.9 p-valprint.c
> --- p-valprint.c        8 Jan 2002 02:09:31 -0000       1.9
> +++ p-valprint.c        2 May 2002 11:12:01 -0000
> @@ -190,8 +190,8 @@ pascal_val_print (struct type *type, cha
>              as GDB does not recognize stabs pascal strings
>              Pascal strings are mapped to records
>              with lowercase names PM  */
> -          if (is_pascal_string_type (elttype, &length_pos,
> -                                     &length_size, &string_pos, &char_size)
> +          if (is_pascal_string_type (elttype, &length_pos, &length_size,
> +                                     &string_pos, &char_size, NULL)
>               && addr != 0)
>             {
>               ULONGEST string_length;
> @@ -320,7 +320,7 @@ pascal_val_print (struct type *type, cha
>         else
>         {
>             if (is_pascal_string_type (type, &length_pos, &length_size,
> -                                     &string_pos, &char_size))
> +                                     &string_pos, &char_size, NULL))
>             {
>               len = extract_unsigned_integer (valaddr + embedded_offset + length_pos, length_size);
>               LA_PRINT_STRING (stream, valaddr + embedded_offset + string_pos, len, char_size, 0);
> 
> Pierre Muller
> Institut Charles Sadron
> 6,rue Boussingault
> F 67083 STRASBOURG CEDEX (France)
> mailto:muller@ics.u-strasbg.fr
> Phone : (33)-3-88-41-40-07  Fax : (33)-3-88-41-40-99


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

* Re: [PATH] Change is_pascal_string_type args
  2002-05-02 11:11 ` Michael Snyder
@ 2002-05-03  0:49   ` Pierre Muller
  0 siblings, 0 replies; 3+ messages in thread
From: Pierre Muller @ 2002-05-03  0:49 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches

At 19:58 02/05/2002 , Michael Snyder a écrit:
>Pierre Muller wrote:
> > 
> > The following patch is only to prepare for the
> > next patch for p-exp.y that will enhance the field
> > search for pascal expressions.
> > 
> > It adds a new argument that can contain
> > a pointer to the name of the field containing the
> > chars of the string.
> > If the type is a pascal string the retruned value is now
> > the char array field index plus one.
> > (to avoid a zero if some new pascal compiler
> > use the first field to contain the char array one day...)
>
>Pierre, aren't you the Pascal maintainer for gdb?
>Seems like you could be approving some of these changes
>yourself, since they affect only Pascal.

Of course, this are committed patches
I made a mistake on the title of that mail,
it should be [PATCH] of course.

The only thing that I did not commit yet is the 
big p-exp.y patch which I sent as a RFC.
This is mainly because I wanted to know the
comments of the other developppers, 
as the method that I used in p-exp.y to be
able to follow the current type of an expression
should be usable by other expression parser.

If we implement it for all languages,
then we should be able to get a completer that works correctly 
for all structure fields.

After applying this patch, my goal is to submit
a patch to completer.c and symtab.c
that will allow to complete
if 
X is a record variable of type
  TRECT = record
    real,imaginary : longint;
end;
in C 
     struct {
         int real, imaginary;
     } TRECT;
then

print X.R'Tab'
would expand to 
print X.REAL
(or more precisely to
X.Real for GPC compiled code and X.REAL for Freee Pascal related code).



Pierre Muller
Institut Charles Sadron
6,rue Boussingault
F 67083 STRASBOURG CEDEX (France)
mailto:muller@ics.u-strasbg.fr
Phone : (33)-3-88-41-40-07  Fax : (33)-3-88-41-40-99


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

end of thread, other threads:[~2002-05-03  7:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-02  4:18 [PATH] Change is_pascal_string_type args Pierre Muller
2002-05-02 11:11 ` Michael Snyder
2002-05-03  0:49   ` Pierre Muller

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