This is the mail archive of the gdb-prs@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]
Other format: [Raw text]

pending/1004: [PATCH]: Add expected type to hand_function_call


>Number:         1004
>Category:       pending
>Synopsis:       [PATCH]:  Add expected type to hand_function_call
>Confidential:   yes
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   unknown
>Arrival-Date:   Fri Jan 31 05:58:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        
>Organization:
>Environment:
>Description:
 This is a multi-part message in MIME format.
 --------------060701000307000307040006
 Content-Type: text/plain; charset=us-ascii; format=flowed
 Content-Transfer-Encoding: 7bit
 
 This patch adds a parameter to hand_function_call that can be used to 
 check the type of the function return. This is used often with 
 Objective-C as this information is known by the runtime and can be used 
 to check the validity of the function.
 
 
 --------------060701000307000307040006
 Content-Type: text/plain;
  name="objc15.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="objc15.patch"
 
 2002-11-24  Adam Fedor  <fedor@gnu.org>
 
 	* valops.c (find_function_addr): Make non-static.
 	(hand_function_call): Add expect_type arg, use it to check
 	return type of function (updated by Klee Dienes  <kdienes@apple.com>).
 	(call_function_by_hand): Update for change in hand_function_call.
 	(call_function_by_hand_expecting_type): New function.
 	* value.h (find_function_addr,
 	call_function_by_hand_expecting_type): Declare.
 
 Index: valops.c
 ===================================================================
 RCS file: /cvs/src/src/gdb/valops.c,v
 retrieving revision 1.79
 diff -u -p -r1.79 valops.c
 --- valops.c	7 Nov 2002 02:45:27 -0000	1.79
 +++ valops.c	25 Nov 2002 02:50:17 -0000
 @@ -48,7 +48,6 @@ extern int overload_debug;
  static int typecmp (int staticp, int varargs, int nargs,
  		    struct field t1[], struct value *t2[]);
  
 -static CORE_ADDR find_function_addr (struct value *, struct type **);
  static struct value *value_arg_coerce (struct value *, struct type *, int);
  
  
 @@ -1228,7 +1227,7 @@ value_arg_coerce (struct value *arg, str
  /* Determine a function's address and its return type from its value.
     Calls error() if the function is not valid for calling.  */
  
 -static CORE_ADDR
 +CORE_ADDR
  find_function_addr (struct value *function, struct type **retval_type)
  {
    register struct type *ftype = check_typedef (VALUE_TYPE (function));
 @@ -1296,7 +1295,8 @@ find_function_addr (struct value *functi
     ARGS is modified to contain coerced values. */
  
  static struct value *
 -hand_function_call (struct value *function, int nargs, struct value **args)
 +hand_function_call (struct value *function, struct type *expect_type,
 +                    int nargs, struct value **args)
  {
    register CORE_ADDR sp;
    register int i;
 @@ -1342,6 +1342,17 @@ hand_function_call (struct value *functi
    if (!target_has_execution)
      noprocess ();
  
 +  funaddr = find_function_addr (function, &value_type);
 +  CHECK_TYPEDEF (value_type);
 +
 +  if ((value_type == NULL) || (TYPE_CODE (value_type) == TYPE_CODE_ERROR))
 +    value_type = expect_type;
 +
 +  if ((value_type == NULL) || (TYPE_CODE (value_type) == TYPE_CODE_ERROR))
 +    error ("Unable to call function at 0x%lx: no return type information available.\n"
 +           "To call this function anyway, you can cast the return type explicitly (e.g. 'print (float) fabs (3.0)')",
 +           (unsigned long) funaddr);
 +
    /* Create a cleanup chain that contains the retbuf (buffer
       containing the register values).  This chain is create BEFORE the
       inf_status chain so that the inferior status can cleaned up
 @@ -1428,9 +1439,6 @@ hand_function_call (struct value *functi
       a SIZEOF_DUMMY1 (via SIZEOF_CALL_DUMMY_WORDS) such that all local
       alignment requirements are met.  */
  
 -  funaddr = find_function_addr (function, &value_type);
 -  CHECK_TYPEDEF (value_type);
 -
    {
      struct block *b = block_for_pc (funaddr);
      /* If compiled without -g, assume GCC 2.  */
 @@ -1891,7 +1899,22 @@ call_function_by_hand (struct value *fun
  {
    if (CALL_DUMMY_P)
      {
 -      return hand_function_call (function, nargs, args);
 +      return hand_function_call (function, NULL, nargs, args);
 +    }
 +  else
 +    {
 +      error ("Cannot invoke functions on this machine.");
 +    }
 +}
 +
 +struct value *
 +call_function_by_hand_expecting_type (struct value *function, 
 +				      struct type *expect_type,
 +                                      int nargs, struct value **args)
 +{
 +  if (CALL_DUMMY_P)
 +    {
 +      return hand_function_call (function, expect_type, nargs, args);
      }
    else
      {
 Index: value.h
 ===================================================================
 RCS file: /cvs/src/src/gdb/value.h,v
 retrieving revision 1.37
 diff -u -p -r1.37 value.h
 --- value.h	14 Oct 2002 02:02:42 -0000	1.37
 +++ value.h	25 Nov 2002 02:50:17 -0000
 @@ -548,6 +548,10 @@ extern struct value *value_slice (struct
  extern struct value *call_function_by_hand (struct value *, int,
  					    struct value **);
  
 +extern struct value *call_function_by_hand_expecting_type (struct value *,
 +						       struct type *, int,
 +						       struct value **);
 +
  extern int default_coerce_float_to_double (struct type *, struct type *);
  
  extern int standard_coerce_float_to_double (struct type *, struct type *);
 @@ -565,6 +569,8 @@ extern struct value *value_allocate_spac
  extern CORE_ADDR default_push_arguments (int nargs, struct value ** args,
  					 CORE_ADDR sp, int struct_return,
  					 CORE_ADDR struct_addr);
 +
 +extern CORE_ADDR find_function_addr (struct value *, struct type **);
  
  extern struct value *value_of_local (const char *name, int complain);
  
 
 --------------060701000307000307040006--
 
 
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:


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