This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [PATCH RFC] Problem with pascal objects.


At 14:06 01/12/00 , Pierre Muller a écrit:

>>--- origdb/valops.c     Sun Apr  9 15:02:10 2000
>>+++ gdb/valops.c        Fri Dec  1 10:30:30 2000
>>@@ -515,8 +515,13 @@
>>  {
>>    CORE_ADDR addr = VALUE_ADDRESS (val) + VALUE_OFFSET (val);
>>    int length = TYPE_LENGTH (VALUE_ENCLOSING_TYPE (val));
>>-
>>    struct type *type = VALUE_TYPE (val);
>>+  /* In some case the enclosing type end up smaller as the
>>+     type at least for pascal */
>>+  int blength = TYPE_LENGTH (type);
>>+  if (blength > length)
>>+    length = blength;
>>+
>>    if (GDB_TARGET_IS_D10V
>>        && TYPE_CODE (type) == TYPE_CODE_PTR
>>        && TYPE_TARGET_TYPE (type)
>
>   The patch is wrong because the allocated size is only length
>and thus if blength is greater than length we write past the allocated memory
>which is of course bad.
>
>    This means that I should reallocate a bigger memory part aready in 
> value_ind
>function.

   Trying deeper to find out where the bug really is,
I found out that this wrong size allocation is due to the following code in 
value_cast
However I don't really understand this code
that probably has to do with some C++ class magic I am not
aware of.

               /* Look in the type of the target to see if it contains the
                  type of the source as a superclass.  If so, we'll need to
                  offset the pointer rather than just change its type.
                  FIXME: This fails silently with virtual inheritance.  */
               if (TYPE_NAME (t2) != NULL)
                 {
                   v = search_struct_field (type_name_no_tag (t2),
                                        value_zero (t1, not_lval), 0, t1, 1);
                   if (v)
                     {
                       value_ptr v2 = value_ind (arg2);
                       VALUE_ADDRESS (v2) -= VALUE_ADDRESS (v)
                         + VALUE_OFFSET (v);

                       /* JYG: adjust the new pointer value and
                          embedded offset. */
                       v2->aligner.contents[0] -=  VALUE_EMBEDDED_OFFSET (v);
                       VALUE_EMBEDDED_OFFSET (v2) = 0;

                       v2 = value_addr (v2);
                       VALUE_TYPE (v2) = type;
+            if (current_language->la_language == language_pascal)
  +             VALUE_ENCLOSING_TYPE (arg2) = type;      /* pai: chk_val */
                       return v2;
                     }
                 }
             }

The two line marked with + seem to fix my problem
correctly  (in the sense that the memory allocation is correct then)
but maybe it would be even better to move the pascal check at a higher level.
Free Pascal can only have only single base object/class until now,
(I don't know the state for GPC).



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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]