home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Atari / Gnu / gdb36p4s.zoo / valops.c < prev    next >
C/C++ Source or Header  |  1993-04-02  |  34KB  |  1,270 lines

  1. /* Perform non-arithmetic operations on values, for GDB.
  2.    Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. GDB is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GDB is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GDB; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "stdio.h"
  21. #include "defs.h"
  22. #include "param.h"
  23. #include "symtab.h"
  24. #include "value.h"
  25. #include "frame.h"
  26. #include "inferior.h"
  27.  
  28. /* Cast value ARG2 to type TYPE and return as a value.
  29.    More general than a C cast: accepts any two types of the same length,
  30.    and if ARG2 is an lvalue it can be cast into anything at all.  */
  31.  
  32. value
  33. value_cast (type, arg2)
  34.      struct type *type;
  35.      register value arg2;
  36. {
  37.   register enum type_code code1;
  38.   register enum type_code code2;
  39.   register int scalar;
  40.  
  41.   /* Coerce arrays but not enums.  Enums will work as-is
  42.      and coercing them would cause an infinite recursion.  */
  43.   if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_ENUM)
  44.     COERCE_ARRAY (arg2);
  45.  
  46.   code1 = TYPE_CODE (type);
  47.   code2 = TYPE_CODE (VALUE_TYPE (arg2));
  48.   scalar = (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_FLT
  49.         || code2 == TYPE_CODE_ENUM);
  50.  
  51.   if (code1 == TYPE_CODE_FLT && scalar)
  52.     return value_from_double (type, value_as_double (arg2));
  53.   else if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_ENUM)
  54.        && (scalar || code2 == TYPE_CODE_PTR))
  55.     return value_from_long (type, value_as_long (arg2));
  56.   else if (TYPE_LENGTH (type) == TYPE_LENGTH (VALUE_TYPE (arg2)))
  57.     {
  58.       VALUE_TYPE (arg2) = type;
  59.       return arg2;
  60.     }
  61.   else if (VALUE_LVAL (arg2) == lval_memory)
  62.     {
  63.       return value_at (type, VALUE_ADDRESS (arg2) + VALUE_OFFSET (arg2));
  64.     }
  65.   else
  66.     error ("Invalid cast.");
  67. }
  68.  
  69. /* Create a value of type TYPE that is zero, and return it.  */
  70.  
  71. value
  72. value_zero (type, lv)
  73.      struct type *type;
  74.      enum lval_type lv;
  75. {
  76.   register value val = allocate_value (type);
  77.  
  78.   bzero (VALUE_CONTENTS (val), TYPE_LENGTH (type));
  79.   VALUE_LVAL (val) = lv;
  80.  
  81.   return val;
  82. }
  83.  
  84. /* Return the value with a specified type located at specified address.  */
  85.  
  86. value
  87. value_at (type, addr)
  88.      struct type *type;
  89.      CORE_ADDR addr;
  90. {
  91.   register value val = allocate_value (type);
  92.   int temp;
  93.  
  94.   temp = read_memory (addr, VALUE_CONTENTS (val), TYPE_LENGTH (type));
  95.   if (temp)
  96.     {
  97.       if (have_inferior_p ())
  98.     print_sys_errmsg ("ptrace", temp);
  99.       /* Actually, address between addr and addr + len was out of bounds. */
  100.       error ("Cannot read memory: address 0x%x out of bounds.", addr);
  101.     }
  102.  
  103.   VALUE_LVAL (val) = lval_memory;
  104.   VALUE_ADDRESS (val) = addr;
  105.  
  106.   return val;
  107. }
  108.  
  109. /* Store the contents of FROMVAL into the location of TOVAL.
  110.    Return a new value with the location of TOVAL and contents of FROMVAL.  */
  111.  
  112. value
  113. value_assign (toval, fromval)
  114.      register value toval, fromval;
  115. {
  116.   register struct type *type = VALUE_TYPE (toval);
  117.   register value val;
  118.   char raw_buffer[MAX_REGISTER_RAW_SIZE];
  119.   char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
  120.   int use_buffer = 0;
  121.  
  122.   extern CORE_ADDR find_saved_register ();
  123.  
  124.   COERCE_ARRAY (fromval);
  125.  
  126.   if (VALUE_LVAL (toval) != lval_internalvar)
  127.     fromval = value_cast (type, fromval);
  128.  
  129.   /* If TOVAL is a special machine register requiring conversion
  130.      of program values to a special raw format,
  131.      convert FROMVAL's contents now, with result in `raw_buffer',
  132.      and set USE_BUFFER to the number of bytes to write.  */
  133.  
  134.   if (VALUE_REGNO (toval) >= 0
  135.       && REGISTER_CONVERTIBLE (VALUE_REGNO (toval)))
  136.     {
  137.       int regno = VALUE_REGNO (toval);
  138.       if (VALUE_TYPE (fromval) != REGISTER_VIRTUAL_TYPE (regno))
  139.     fromval = value_cast (REGISTER_VIRTUAL_TYPE (regno), fromval);
  140.       bcopy (VALUE_CONTENTS (fromval), virtual_buffer,
  141.          REGISTER_VIRTUAL_SIZE (regno));
  142.       REGISTER_CONVERT_TO_RAW (regno, virtual_buffer, raw_buffer);
  143.       use_buffer = REGISTER_RAW_SIZE (regno);
  144.     }
  145.  
  146.   switch (VALUE_LVAL (toval))
  147.     {
  148.     case lval_internalvar:
  149.       set_internalvar (VALUE_INTERNALVAR (toval), fromval);
  150.       break;
  151.  
  152.     case lval_internalvar_component:
  153.       set_internalvar_component (VALUE_INTERNALVAR (toval),
  154.                  VALUE_OFFSET (toval),
  155.                  VALUE_BITPOS (toval),
  156.                  VALUE_BITSIZE (toval),
  157.                  fromval);
  158.       break;
  159.  
  160.     case lval_memory:
  161.       if (VALUE_BITSIZE (toval))
  162.     {
  163.       int val;
  164.       read_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  165.                &val, sizeof val);
  166.       modify_field (&val, (int) value_as_long (fromval),
  167.             VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
  168.       write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  169.             &val, sizeof val);
  170.     }
  171.       else if (use_buffer)
  172.     write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  173.               raw_buffer, use_buffer);
  174.       else
  175.     write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  176.               VALUE_CONTENTS (fromval), TYPE_LENGTH (type));
  177.       break;
  178.  
  179.     case lval_register:
  180.       if (VALUE_BITSIZE (toval))
  181.     {
  182.       int val;
  183.  
  184.       read_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  185.                    &val, sizeof val);
  186.       modify_field (&val, (int) value_as_long (fromval),
  187.             VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
  188.       write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  189.                 &val, sizeof val);
  190.     }
  191.       else if (use_buffer)
  192.     write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  193.                   raw_buffer, use_buffer);
  194.       else
  195.     write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
  196.                   VALUE_CONTENTS (fromval), TYPE_LENGTH (type));
  197.       break;
  198.  
  199.     case lval_reg_frame_relative:
  200.       {
  201.     /* value is stored in a series of registers in the frame
  202.        specified by the structure.  Copy that value out, modify
  203.        it, and copy it back in.  */
  204.     int amount_to_copy = (VALUE_BITSIZE (toval) ? 1 : TYPE_LENGTH (type));
  205.     int reg_size = REGISTER_RAW_SIZE (VALUE_FRAME_REGNUM (toval));
  206.     int byte_offset = VALUE_OFFSET (toval) % reg_size;
  207.     int reg_offset = VALUE_OFFSET (toval) / reg_size;
  208.     int amount_copied;
  209.     char *buffer = (char *) alloca (amount_to_copy);
  210.     int regno;
  211.     FRAME frame;
  212.     CORE_ADDR addr;
  213.  
  214.     /* Figure out which frame this is in currently.  */
  215.     for (frame = get_current_frame ();
  216.          frame && FRAME_FP (frame) != VALUE_FRAME (toval);
  217.          frame = get_prev_frame (frame))
  218.       ;
  219.  
  220.     if (!frame)
  221.       error ("Value being assigned to is no longer active.");
  222.  
  223.     amount_to_copy += (reg_size - amount_to_copy % reg_size);
  224.  
  225.     /* Copy it out.  */
  226.     for ((regno = VALUE_FRAME_REGNUM (toval) + reg_offset,
  227.           amount_copied = 0);
  228.          amount_copied < amount_to_copy;
  229.          amount_copied += reg_size, regno++)
  230.       {
  231.         addr = find_saved_register (frame, regno);
  232.         if (addr == 0)
  233.           read_register_bytes (REGISTER_BYTE (regno),
  234.                    buffer + amount_copied,
  235.                    reg_size);
  236.         else
  237.           read_memory (addr, buffer + amount_copied, reg_size);
  238.       }
  239.  
  240.     /* Modify what needs to be modified.  */
  241.     if (VALUE_BITSIZE (toval))
  242.       modify_field (buffer + byte_offset,
  243.             (int) value_as_long (fromval),
  244.             VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
  245.     else if (use_buffer)
  246.       bcopy (raw_buffer, buffer + byte_offset, use_buffer);
  247.     else
  248.       bcopy (VALUE_CONTENTS (fromval), buffer + byte_offset,
  249.          TYPE_LENGTH (type));
  250.  
  251.     /* Copy it back.  */
  252.     for ((regno = VALUE_FRAME_REGNUM (toval) + reg_offset,
  253.           amount_copied = 0);
  254.          amount_copied < amount_to_copy;
  255.          amount_copied += reg_size, regno++)
  256.       {
  257.         addr = find_saved_register (frame, regno);
  258.         if (addr == 0)
  259.           write_register_bytes (REGISTER_BYTE (regno),
  260.                     buffer + amount_copied,
  261.                     reg_size);
  262.         else
  263.           write_memory (addr, buffer + amount_copied, reg_size);
  264.       }
  265.       }
  266.       break;
  267.     
  268.  
  269.     default:
  270.       error ("Left side of = operation is not an lvalue.");
  271.     }
  272.  
  273.   /* Return a value just like TOVAL except with the contents of FROMVAL
  274.      (except in the case of the type if TOVAL is an internalvar).  */
  275.  
  276.   if (VALUE_LVAL (toval) == lval_internalvar
  277.       || VALUE_LVAL (toval) == lval_internalvar_component)
  278.     {
  279.       type = VALUE_TYPE (fromval);
  280.     }
  281.  
  282.   val = allocate_value (type);
  283.   bcopy (toval, val, VALUE_CONTENTS (val) - (char *) val);
  284.   bcopy (VALUE_CONTENTS (fromval), VALUE_CONTENTS (val), TYPE_LENGTH (type));
  285.   VALUE_TYPE (val) = type;
  286.   
  287.   return val;
  288. }
  289.  
  290. /* Extend a value VAL to COUNT repetitions of its type.  */
  291.  
  292. value
  293. value_repeat (arg1, count)
  294.      value arg1;
  295.      int count;
  296. {
  297.   register value val;
  298.  
  299.   if (VALUE_LVAL (arg1) != lval_memory)
  300.     error ("Only values in memory can be extended with '@'.");
  301.   if (count < 1)
  302.     error ("Invalid number %d of repetitions.", count);
  303.  
  304.   val = allocate_repeat_value (VALUE_TYPE (arg1), count);
  305.  
  306.   read_memory (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1),
  307.            VALUE_CONTENTS (val),
  308.            TYPE_LENGTH (VALUE_TYPE (val)) * count);
  309.   VALUE_LVAL (val) = lval_memory;
  310.   VALUE_ADDRESS (val) = VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1);
  311.  
  312.   return val;
  313. }
  314.  
  315. value
  316. value_of_variable (var)
  317.      struct symbol *var;
  318. {
  319.   return read_var_value (var, (FRAME) 0);
  320. }
  321.  
  322. /* Given a value which is an array, return a value which is
  323.    a pointer to its first element.  */
  324.  
  325. value
  326. value_coerce_array (arg1)
  327.      value arg1;
  328. {
  329.   register struct type *type;
  330.   register value val;
  331.  
  332.   if (VALUE_LVAL (arg1) != lval_memory)
  333.     error ("Attempt to take address of value not located in memory.");
  334.  
  335.   /* Get type of elements.  */
  336.   if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY)
  337.     type = TYPE_TARGET_TYPE (VALUE_TYPE (arg1));
  338.   else
  339.     /* A phony array made by value_repeat.
  340.        Its type is the type of the elements, not an array type.  */
  341.     type = VALUE_TYPE (arg1);
  342.  
  343.   /* Get the type of the result.  */
  344.   type = lookup_pointer_type (type);
  345.   val = value_from_long (builtin_type_long,
  346.                (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
  347.   VALUE_TYPE (val) = type;
  348.   return val;
  349. }
  350.  
  351. /* Return a pointer value for the object for which ARG1 is the contents.  */
  352.  
  353. value
  354. value_addr (arg1)
  355.      value arg1;
  356. {
  357.   register struct type *type;
  358.   register value val, arg1_coerced;
  359.  
  360.   /* Taking the address of an array is really a no-op
  361.      once the array is coerced to a pointer to its first element.  */
  362.   arg1_coerced = arg1;
  363.   COERCE_ARRAY (arg1_coerced);
  364.   if (arg1 != arg1_coerced)
  365.     return arg1_coerced;
  366.  
  367.   if (VALUE_LVAL (arg1) != lval_memory)
  368.     error ("Attempt to take address of value not located in memory.");
  369.  
  370.   /* Get the type of the result.  */
  371.   type = lookup_pointer_type (VALUE_TYPE (arg1));
  372.   val = value_from_long (builtin_type_long,
  373.         (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
  374.   VALUE_TYPE (val) = type;
  375.   return val;
  376. }
  377.  
  378. /* Given a value of a pointer type, apply the C unary * operator to it.  */
  379.  
  380. value
  381. value_ind (arg1)
  382.      value arg1;
  383. {
  384.   /* Must do this before COERCE_ARRAY, otherwise an infinite loop
  385.      will result */
  386.   if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF)
  387.     return value_at (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)),
  388.              (CORE_ADDR) value_as_long (arg1));
  389.  
  390.   COERCE_ARRAY (arg1);
  391.  
  392.   if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_MEMBER)
  393.     error ("not implemented: member types in value_ind");
  394.  
  395.   /* Allow * on an integer so we can cast it to whatever we want.
  396.      This returns an int, which seems like the most C-like thing
  397.      to do.  "long long" variables are rare enough that
  398.      BUILTIN_TYPE_LONGEST would seem to be a mistake.  */
  399.   if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_INT)
  400.     return value_at (builtin_type_int,
  401.              (CORE_ADDR) value_as_long (arg1));
  402.   else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR)
  403.     return value_at (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)),
  404.              (CORE_ADDR) value_as_long (arg1));
  405.   else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF)
  406.     return value_at (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)),
  407.              (CORE_ADDR) value_as_long (arg1));
  408.   error ("Attempt to take contents of a non-pointer value.");
  409. }
  410.  
  411. /* Pushing small parts of stack frames.  */
  412.  
  413. /* Push one word (the size of object that a register holds).  */
  414.  
  415. CORE_ADDR
  416. push_word (sp, buffer)
  417.      CORE_ADDR sp;
  418.      REGISTER_TYPE buffer;
  419. {
  420.   register int len = sizeof (REGISTER_TYPE);
  421.  
  422. #if 1 INNER_THAN 2
  423.   sp -= len;
  424.   write_memory (sp, &buffer, len);
  425. #else /* stack grows upward */
  426.   write_memory (sp, &buffer, len);
  427.   sp += len;
  428. #endif /* stack grows upward */
  429.  
  430.   return sp;
  431. }
  432.  
  433. /* Push LEN bytes with data at BUFFER.  */
  434.  
  435. CORE_ADDR
  436. push_bytes (sp, buffer, len)
  437.      CORE_ADDR sp;
  438.      char *buffer;
  439.      int len;
  440. {
  441. #if 1 INNER_THAN 2
  442.   sp -= len;
  443.   write_memory (sp, buffer, len);
  444. #else /* stack grows upward */
  445.   write_memory (sp, buffer, len);
  446.   sp += len;
  447. #endif /* stack grows upward */
  448.  
  449.   return sp;
  450. }
  451.  
  452. /* Push onto the stack the specified value VALUE.  */
  453.  
  454. CORE_ADDR
  455. value_push (sp, arg)
  456.      register CORE_ADDR sp;
  457.      value arg;
  458. {
  459.   register int len = TYPE_LENGTH (VALUE_TYPE (arg));
  460.  
  461. #if 1 INNER_THAN 2
  462.   sp -= len;
  463.   write_memory (sp, VALUE_CONTENTS (arg), len);
  464. #else /* stack grows upward */
  465.   write_memory (sp, VALUE_CONTENTS (arg), len);
  466.   sp += len;
  467. #endif /* stack grows upward */
  468.  
  469.   return sp;
  470. }
  471.  
  472. /* Perform the standard coercions that are specified
  473.    for arguments to be passed to C functions.  */
  474.  
  475. value
  476. value_arg_coerce (arg)
  477.      value arg;
  478. {
  479.   register struct type *type;
  480.  
  481.   COERCE_ENUM (arg);
  482.  
  483.   type = VALUE_TYPE (arg);
  484.  
  485. #ifdef atarist
  486.   if (gcc_mshort)
  487.     {
  488.       if (TYPE_CODE (type) == TYPE_CODE_INT
  489.       && TYPE_LENGTH (type) < sizeof (short))
  490.     return value_cast (builtin_type_short, arg);
  491.     }
  492.   else
  493. #endif
  494.   if (TYPE_CODE (type) == TYPE_CODE_INT
  495.       && TYPE_LENGTH (type) < sizeof (int))
  496.     return value_cast (builtin_type_int, arg);
  497.  
  498.   if (type == builtin_type_float)
  499.     return value_cast (builtin_type_double, arg);
  500.  
  501.   return arg;
  502. }
  503.  
  504. /* Push the value ARG, first coercing it as an argument
  505.    to a C function.  */
  506.  
  507. CORE_ADDR
  508. value_arg_push (sp, arg)
  509.      register CORE_ADDR sp;
  510.      value arg;
  511. {
  512.   return value_push (sp, value_arg_coerce (arg));
  513. }
  514.  
  515. /* Perform a function call in the inferior.
  516.    ARGS is a vector of values of arguments (NARGS of them).
  517.    FUNCTION is a value, the function to be called.
  518.    Returns a value representing what the function returned.
  519.    May fail to return, if a breakpoint or signal is hit
  520.    during the execution of the function.  */
  521.  
  522. value
  523. call_function (function, nargs, args)
  524.      value function;
  525.      int nargs;
  526.      value *args;
  527. {
  528.   register CORE_ADDR sp;
  529.   register int i;
  530.   CORE_ADDR start_sp;
  531.   static REGISTER_TYPE dummy[] = CALL_DUMMY;
  532.   REGISTER_TYPE dummy1[sizeof dummy / sizeof (REGISTER_TYPE)];
  533.   CORE_ADDR old_sp;
  534.   struct type *value_type;
  535.   unsigned char struct_return;
  536.   CORE_ADDR struct_addr;
  537.   struct inferior_status inf_status;
  538.   struct cleanup *old_chain;
  539.  
  540.   if (!have_inferior_p ())
  541.     error ("Cannot invoke functions if the inferior is not running.");
  542.  
  543.   save_inferior_status (&inf_status, 1);
  544.   old_chain = make_cleanup (restore_inferior_status, &inf_status);
  545.  
  546.   /* PUSH_DUMMY_FRAME is responsible for saving the inferior registers
  547.      (and POP_FRAME for restoring them).  (At least on most machines)
  548.      they are saved on the stack in the inferior.  */
  549.   PUSH_DUMMY_FRAME;
  550.  
  551.   old_sp = sp = read_register (SP_REGNUM);
  552.  
  553. #if 1 INNER_THAN 2        /* Stack grows down */
  554.   sp -= sizeof dummy;
  555.   start_sp = sp;
  556. #else                /* Stack grows up */
  557.   start_sp = sp;
  558.   sp += sizeof dummy;
  559. #endif
  560.  
  561.   {
  562.     register CORE_ADDR funaddr;
  563.     register struct type *ftype = VALUE_TYPE (function);
  564.     register enum type_code code = TYPE_CODE (ftype);
  565.  
  566.     /* If it's a member function, just look at the function
  567.        part of it.  */
  568.  
  569.     /* Determine address to call.  */
  570.     if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD)
  571.       {
  572.     funaddr = VALUE_ADDRESS (function);
  573.     value_type = TYPE_TARGET_TYPE (ftype);
  574.       }
  575.     else if (code == TYPE_CODE_PTR)
  576.       {
  577.     funaddr = value_as_long (function);
  578.     if (TYPE_CODE (TYPE_TARGET_TYPE (ftype)) == TYPE_CODE_FUNC
  579.         || TYPE_CODE (TYPE_TARGET_TYPE (ftype)) == TYPE_CODE_METHOD)
  580.       value_type = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype));
  581.     else
  582.       value_type = builtin_type_int;
  583.       }
  584.     else if (code == TYPE_CODE_INT)
  585.       {
  586.     /* Handle the case of functions lacking debugging info.
  587.        Their values are characters since their addresses are char */
  588.     if (TYPE_LENGTH (ftype) == 1)
  589.       funaddr = value_as_long (value_addr (function));
  590.     else
  591.       /* Handle integer used as address of a function.  */
  592.       funaddr = value_as_long (function);
  593.  
  594.     value_type = builtin_type_int;
  595.       }
  596.     else
  597.       error ("Invalid data type for function to be called.");
  598.  
  599.     /* Are we returning a value using a structure return or a normal
  600.        value return? */
  601.  
  602.     struct_return = using_struct_return (function, funaddr, value_type);
  603.  
  604.     /* Create a call sequence customized for this function
  605.        and the number of arguments for it.  */
  606.     bcopy (dummy, dummy1, sizeof dummy);
  607.     FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, value_type);
  608.   }
  609.  
  610. #ifndef CANNOT_EXECUTE_STACK
  611.   write_memory (start_sp, dummy1, sizeof dummy);
  612.  
  613. #else
  614.   /* Convex Unix prohibits executing in the stack segment. */
  615.   /* Hope there is empty room at the top of the text segment. */
  616.   {
  617.     extern CORE_ADDR text_end;
  618.     static checked = 0;
  619.     if (!checked)
  620.       for (start_sp = text_end - sizeof dummy; start_sp < text_end; ++start_sp)
  621.     if (read_memory_integer (start_sp, 1) != 0)
  622.       error ("text segment full -- no place to put call");
  623.     checked = 1;
  624.     sp = old_sp;
  625.     start_sp = text_end - sizeof dummy;
  626.     write_memory (start_sp, dummy1, sizeof dummy);
  627.   }
  628. #endif /* CANNOT_EXECUTE_STACK */
  629. #ifdef STACK_ALIGN
  630.   /* If stack grows down, we must leave a hole at the top. */
  631.   {
  632.     int len = 0;
  633.  
  634.     /* Reserve space for the return structure to be written on the
  635.        stack, if necessary */
  636.  
  637.     if (struct_return)
  638.       len += TYPE_LENGTH (value_type);
  639.     
  640.     for (i = nargs - 1; i >= 0; i--)
  641.       len += TYPE_LENGTH (VALUE_TYPE (value_arg_coerce (args[i])));
  642. #ifdef CALL_DUMMY_STACK_ADJUST
  643.     len += CALL_DUMMY_STACK_ADJUST;
  644. #endif
  645. #if 1 INNER_THAN 2
  646.     sp -= STACK_ALIGN (len) - len;
  647. #else
  648.     sp += STACK_ALIGN (len) - len;
  649. #endif
  650.   }
  651. #endif /* STACK_ALIGN */
  652.  
  653.     /* Reserve space for the return structure to be written on the
  654.        stack, if necessary */
  655.  
  656.     if (struct_return)
  657.       {
  658. #if 1 INNER_THAN 2
  659.     sp -= TYPE_LENGTH (value_type);
  660.     struct_addr = sp;
  661. #else
  662.     struct_addr = sp;
  663.     sp += TYPE_LENGTH (value_type);
  664. #endif
  665.       }
  666.     
  667.   for (i = nargs - 1; i >= 0; i--)
  668.     sp = value_arg_push (sp, args[i]);
  669.  
  670. #ifdef CALL_DUMMY_STACK_ADJUST
  671. #if 1 INNER_THAN 2
  672.   sp -= CALL_DUMMY_STACK_ADJUST;
  673. #else
  674.   sp += CALL_DUMMY_STACK_ADJUST;
  675. #endif
  676. #endif /* CALL_DUMMY_STACK_ADJUST */
  677.  
  678.   /* Store the address at which the structure is supposed to be
  679.      written.  Note that this (and the code which reserved the space
  680.      above) assumes that gcc was used to compile this function.  Since
  681.      it doesn't cost us anything but space and if the function is pcc
  682.      it will ignore this value, we will make that assumption.
  683.  
  684.      Also note that on some machines (like the sparc) pcc uses this
  685.      convention in a slightly twisted way also.  */
  686.  
  687.   if (struct_return)
  688.     STORE_STRUCT_RETURN (struct_addr, sp);
  689.  
  690.   /* Write the stack pointer.  This is here because the statement above
  691.      might fool with it */
  692.   write_register (SP_REGNUM, sp);
  693.  
  694.   /* Figure out the value returned by the function.  */
  695.   {
  696.     char retbuf[REGISTER_BYTES];
  697.  
  698.     /* Execute the stack dummy routine, calling FUNCTION.
  699.        When it is done, discard the empty frame
  700.        after storing the contents of all regs into retbuf.  */
  701.     run_stack_dummy (start_sp + CALL_DUMMY_START_OFFSET, retbuf);
  702.  
  703.     do_cleanups (old_chain);
  704.  
  705.     return value_being_returned (value_type, retbuf, struct_return);
  706.   }
  707. }
  708.  
  709. /* Create a value for a string constant:
  710.    Call the function malloc in the inferior to get space for it,
  711.    then copy the data into that space
  712.    and then return the address with type char *.
  713.    PTR points to the string constant data; LEN is number of characters.  */
  714.  
  715. value
  716. value_string (ptr, len)
  717.      char *ptr;
  718.      int len;
  719. {
  720.   register value val;
  721.   register struct symbol *sym;
  722.   value blocklen;
  723.   register char *copy = (char *) alloca (len + 1);
  724.   char *i = ptr;
  725.   register char *o = copy, *ibeg = ptr;
  726.   register int c;
  727.  
  728.   /* Copy the string into COPY, processing escapes.
  729.      We could not conveniently process them in expread
  730.      because the string there wants to be a substring of the input.  */
  731.  
  732.   while (i - ibeg < len)
  733.     {
  734.       c = *i++;
  735.       if (c == '\\')
  736.     {
  737.       c = parse_escape (&i);
  738.       if (c == -1)
  739.         continue;
  740.     }
  741.       *o++ = c;
  742.     }
  743.   *o = 0;
  744.  
  745.   /* Get the length of the string after escapes are processed.  */
  746.  
  747.   len = o - copy;
  748.  
  749.   /* Find the address of malloc in the inferior.  */
  750.  
  751.   sym = lookup_symbol ("malloc", 0, VAR_NAMESPACE, 0);
  752.   if (sym != 0)
  753.     {
  754.       if (SYMBOL_CLASS (sym) != LOC_BLOCK)
  755.     error ("\"malloc\" exists in this program but is not a function.");
  756.       val = value_of_variable (sym);
  757.     }
  758.   else
  759.     {
  760.       register int i;
  761.       for (i = 0; i < misc_function_count; i++)
  762.     if (!strcmp (misc_function_vector[i].name, "malloc"))
  763.       break;
  764.       if (i < misc_function_count)
  765.     val = value_from_long (builtin_type_long,
  766.                  (LONGEST) misc_function_vector[i].address);
  767.       else
  768.     error ("String constants require the program to have a function \"malloc\".");
  769.     }
  770.  
  771.   blocklen = value_from_long (builtin_type_int, (LONGEST) (len + 1));
  772.   val = call_function (val, 1, &blocklen);
  773.   if (value_zerop (val))
  774.     error ("No memory available for string constant.");
  775.   write_memory ((CORE_ADDR) value_as_long (val), copy, len + 1);
  776.   VALUE_TYPE (val) = lookup_pointer_type (builtin_type_char);
  777.   return val;
  778. }
  779.  
  780. /* Given ARG1, a value of type (pointer to a)* structure/union,
  781.    extract the component named NAME from the ultimate target structure/union
  782.    and return it as a value with its appropriate type.
  783.    ERR is used in the error message if ARG1's type is wrong.
  784.  
  785.    C++: ARGS is a list of argument types to aid in the selection of
  786.    an appropriate method. Also, handle derived types.
  787.  
  788.    STATIC_MEMFUNCP, if non-NULL, points to a caller-supplied location
  789.    where the truthvalue of whether the function that was resolved was
  790.    a static member function or not.
  791.  
  792.    ERR is an error message to be printed in case the field is not found.  */
  793.  
  794. value
  795. value_struct_elt (arg1, args, name, static_memfuncp, err)
  796.      register value arg1, *args;
  797.      char *name;
  798.      int *static_memfuncp;
  799.      char *err;
  800. {
  801.   register struct type *t;
  802.   register int i;
  803.   int found = 0;
  804.  
  805.   struct type *baseclass;
  806.  
  807.   COERCE_ARRAY (arg1);
  808.  
  809.   t = VALUE_TYPE (arg1);
  810.  
  811.   /* Follow pointers until we get to a non-pointer.  */
  812.  
  813.   while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
  814.     {
  815.       arg1 = value_ind (arg1);
  816.       COERCE_ARRAY (arg1);
  817.       t = VALUE_TYPE (arg1);
  818.     }
  819.  
  820.   if (TYPE_CODE (t) == TYPE_CODE_MEMBER)
  821.     error ("not implemented: member type in value_struct_elt");
  822.  
  823.   if (TYPE_CODE (t) != TYPE_CODE_STRUCT
  824.       && TYPE_CODE (t) != TYPE_CODE_UNION)
  825.     error ("Attempt to extract a component of a value that is not a %s.", err);
  826.  
  827.   baseclass = t;
  828.  
  829.   /* Assume it's not, unless we see that it is.  */
  830.   if (static_memfuncp)
  831.     *static_memfuncp =0;
  832.  
  833.   if (!args)
  834.     {
  835.       /* if there are no arguments ...do this...  */
  836.  
  837.       /* Try as a variable first, because if we succeed, there
  838.      is less work to be done.  */
  839.       while (t)
  840.     {
  841.       check_stub_type (t);
  842.  
  843.       for (i = TYPE_NFIELDS (t) - 1; i >= 0; i--)
  844.         {
  845.           char *t_field_name = TYPE_FIELD_NAME (t, i);
  846.           if (t_field_name && !strcmp (t_field_name, name))
  847.         {
  848.           found = 1;
  849.           break;
  850.         }
  851.         }
  852.  
  853.       if (i >= 0)
  854.         return TYPE_FIELD_STATIC (t, i)
  855.           ? value_static_field (t, name, i) : value_field (arg1, i);
  856.  
  857.       if (TYPE_N_BASECLASSES (t) == 0)
  858.         break;
  859.  
  860.       t = TYPE_BASECLASS (t, 1);
  861.       VALUE_TYPE (arg1) = t; /* side effect! */
  862.     }
  863.  
  864.       /* C++: If it was not found as a data field, then try to
  865.          return it as a pointer to a method.  */
  866.       t = baseclass;
  867.       VALUE_TYPE (arg1) = t;    /* side effect! */
  868.  
  869.       if (destructor_name_p (name, t))
  870.     error ("use `info method' command to print out value of destructor");
  871.  
  872.       while (t)
  873.     {
  874.       for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i)
  875.         {
  876.           if (! strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name))
  877.         {
  878.           error ("use `info method' command to print value of method \"%s\"", name);
  879.         }
  880.         }
  881.  
  882.       if (TYPE_N_BASECLASSES (t) == 0)
  883.         break;
  884.  
  885.       t = TYPE_BASECLASS (t, 1);
  886.     }
  887.  
  888.       if (found == 0)
  889.     error ("There is no field named %s.", name);
  890.       return 0;
  891.     }
  892.  
  893.   if (destructor_name_p (name, t))
  894.     {
  895.       if (!args[1])
  896.     {
  897.       /* destructors are a special case.  */
  898.       return (value)value_fn_field (arg1, 0,
  899.                     TYPE_FN_FIELDLIST_LENGTH (t, 0));
  900.     }
  901.       else
  902.     {
  903.       error ("destructor should not have any argument");
  904.     }
  905.     }
  906.  
  907.   /*   This following loop is for methods with arguments.  */
  908.   while (t)
  909.     {
  910.       check_stub_type (t);
  911.  
  912.       /* Look up as method first, because that is where we
  913.      expect to find it first.  */
  914.       for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; i--)
  915.     {
  916.       struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
  917.  
  918.       if (!strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name))
  919.         {
  920.           int j;
  921.           struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
  922.  
  923.           found = 1;
  924.           for (j = TYPE_FN_FIELDLIST_LENGTH (t, i) - 1; j >= 0; --j)
  925.         {
  926.           if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f, j)) & TYPE_FLAG_STUB)
  927.             check_stub_method (t, i, j);
  928.           if (!typecmp (TYPE_FN_FIELD_STATIC_P (f, j),
  929.                 TYPE_FN_FIELD_ARGS (f, j), args))
  930.             {
  931.               if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
  932.             return (value)value_virtual_fn_field (arg1, f, j, t);
  933.               if (TYPE_FN_FIELD_STATIC_P (f, j) && static_memfuncp)
  934.             *static_memfuncp = 1;
  935.               return (value)value_fn_field (arg1, i, j);
  936.             }
  937.         }
  938.         }
  939.     }
  940.  
  941.       if (TYPE_N_BASECLASSES (t) == 0)
  942.     break;
  943.       
  944.       t = TYPE_BASECLASS (t, 1);
  945.       VALUE_TYPE (arg1) = t;    /* side effect! */
  946.     }
  947.  
  948.   if (found)
  949.     {
  950.       error ("Structure method %s not defined for arglist.", name);
  951.       return 0;
  952.     }
  953.   else
  954.     {
  955.       /* See if user tried to invoke data as function */
  956.       t = baseclass;
  957.       while (t)
  958.     {
  959.  
  960.       /* minimal-debug: we don't need to do a check_stub_type here,
  961.          we will have been through all the baseclasses already. */
  962.  
  963.       for (i = TYPE_NFIELDS (t) - 1; i >= 0; i--)
  964.         {
  965.           char *t_field_name = TYPE_FIELD_NAME (t, i);
  966.           if (t_field_name && !strcmp (t_field_name, name))
  967.         {
  968.           found = 1;
  969.           break;
  970.         }
  971.         }
  972.  
  973.       if (i >= 0)
  974.         return TYPE_FIELD_STATIC (t, i)
  975.           ? value_static_field (t, name, i) : value_field (arg1, i);
  976.  
  977.       if (TYPE_N_BASECLASSES (t) == 0)
  978.         break;
  979.  
  980.       t = TYPE_BASECLASS (t, 1);
  981.       VALUE_TYPE (arg1) = t; /* side effect! */
  982.     }
  983.       error ("Structure has no component named %s.", name);
  984.     }
  985. }
  986.  
  987. /* C++: return 1 is NAME is a legitimate name for the destructor
  988.    of type TYPE.  If TYPE does not have a destructor, or
  989.    if NAME is inappropriate for TYPE, an error is signaled.  */
  990. int
  991. destructor_name_p (name, type)
  992.      char *name;
  993.      struct type *type;
  994. {
  995.   /* destructors are a special case.  */
  996.   char *dname = type_name_no_tag (type);
  997.  
  998.   if (name[0] == '~')
  999.     {
  1000.       if (! TYPE_HAS_DESTRUCTOR (type))
  1001.     error ("type `%s' does not have destructor defined", dname);
  1002.       if (strcmp (dname, name+1))
  1003.     error ("destructor specification error");
  1004.       else
  1005.     return 1;
  1006.     }
  1007.   return 0;
  1008. }
  1009.  
  1010. /* C++: Given ARG1, a value of type (pointer to a)* structure/union,
  1011.    return 1 if the component named NAME from the ultimate
  1012.    target structure/union is defined, otherwise, return 0.  */
  1013.  
  1014. int
  1015. check_field (arg1, name)
  1016.      register value arg1;
  1017.      char *name;
  1018. {
  1019.   register struct type *t;
  1020.   register int i;
  1021.   int found = 0;
  1022.  
  1023.   struct type *baseclass;
  1024.  
  1025.   COERCE_ARRAY (arg1);
  1026.  
  1027.   t = VALUE_TYPE (arg1);
  1028.  
  1029.   /* Follow pointers until we get to a non-pointer.  */
  1030.  
  1031.   while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
  1032.     t = TYPE_TARGET_TYPE (t);
  1033.  
  1034.   if (TYPE_CODE (t) == TYPE_CODE_MEMBER)
  1035.     error ("not implemented: member type in check_field");
  1036.  
  1037.   if (TYPE_CODE (t) != TYPE_CODE_STRUCT
  1038.       && TYPE_CODE (t) != TYPE_CODE_UNION)
  1039.     error ("Internal error: `this' is not an aggregate");
  1040.  
  1041.   baseclass = t;
  1042.  
  1043.   while (t)
  1044.     {
  1045.       for (i = TYPE_NFIELDS (t) - 1; i >= 0; i--)
  1046.     {
  1047.       char *t_field_name = TYPE_FIELD_NAME (t, i);
  1048.       if (t_field_name && !strcmp (t_field_name, name))
  1049.         {
  1050.           return 1;
  1051.         }
  1052.     }
  1053.       if (TYPE_N_BASECLASSES (t) == 0)
  1054.     break;
  1055.  
  1056.       t = TYPE_BASECLASS (t, 1);
  1057.     }
  1058.  
  1059.   /* C++: If it was not found as a data field, then try to
  1060.      return it as a pointer to a method.  */
  1061.   t = baseclass;
  1062.   VALUE_TYPE (arg1) = t;    /* side effect! */
  1063.  
  1064.   /* Destructors are a special case.  */
  1065.   if (destructor_name_p (name, t))
  1066.     return 1;
  1067.  
  1068.   while (t)
  1069.     {
  1070.       for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i)
  1071.     {
  1072.       if (!strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name))
  1073.         return 1;
  1074.     }
  1075.  
  1076.       if (TYPE_N_BASECLASSES (t) == 0)
  1077.     break;
  1078.  
  1079.       t = TYPE_BASECLASS (t, 1);
  1080.     }
  1081.   return 0;
  1082. }
  1083.  
  1084. /* C++: Given an aggregate type DOMAIN, and a member name NAME,
  1085.    return the address of this member as a pointer to member
  1086.    type.  If INTYPE is non-null, then it will be the type
  1087.    of the member we are looking for.  This will help us resolve
  1088.    pointers to member functions.  */
  1089.  
  1090. value
  1091. value_struct_elt_for_address (domain, intype, name)
  1092.      struct type *domain, *intype;
  1093.      char *name;
  1094. {
  1095.   register struct type *t = domain;
  1096.   register int i;
  1097.   int found = 0;
  1098.   value v;
  1099.  
  1100.   struct type *baseclass;
  1101.  
  1102.   if (TYPE_CODE (t) != TYPE_CODE_STRUCT
  1103.       && TYPE_CODE (t) != TYPE_CODE_UNION)
  1104.     error ("Internal error: non-aggregate type to value_struct_elt_for_address");
  1105.  
  1106.   baseclass = t;
  1107.  
  1108.   while (t)
  1109.     {
  1110.       for (i = TYPE_NFIELDS (t) - 1; i >= 0; i--)
  1111.     {
  1112.       char *t_field_name = TYPE_FIELD_NAME (t, i);
  1113.       if (t_field_name && !strcmp (t_field_name, name))
  1114.         {
  1115.           if (TYPE_FIELD_PACKED (t, i))
  1116.         error ("pointers to bitfield members not allowed");
  1117.  
  1118.           v = value_from_long (builtin_type_int,
  1119.                    (LONGEST) (TYPE_FIELD_BITPOS (t, i) >> 3));
  1120.           VALUE_TYPE (v) = lookup_pointer_type (
  1121.               lookup_member_type (TYPE_FIELD_TYPE (t, i), baseclass));
  1122.           return v;
  1123.         }
  1124.     }
  1125.  
  1126.       if (TYPE_N_BASECLASSES (t) == 0)
  1127.     break;
  1128.  
  1129.       t = TYPE_BASECLASS (t, 1);
  1130.     }
  1131.  
  1132.   /* C++: If it was not found as a data field, then try to
  1133.      return it as a pointer to a method.  */
  1134.   t = baseclass;
  1135.  
  1136.   /* Destructors are a special case.  */
  1137.   if (destructor_name_p (name, t))
  1138.     {
  1139.       error ("pointers to destructors not implemented yet");
  1140.     }
  1141.  
  1142.   /* Perform all necessary dereferencing.  */
  1143.   while (intype && TYPE_CODE (intype) == TYPE_CODE_PTR)
  1144.     intype = TYPE_TARGET_TYPE (intype);
  1145.  
  1146.   while (t)
  1147.     {
  1148.       for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i)
  1149.     {
  1150.       if (!strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name))
  1151.         {
  1152.           int j = TYPE_FN_FIELDLIST_LENGTH (t, i);
  1153.           struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
  1154.  
  1155.           if (intype == 0 && j > 1)
  1156.         error ("non-unique member `%s' requires type instantiation", name);
  1157.           if (intype)
  1158.         {
  1159.           while (j--)
  1160.             if (TYPE_FN_FIELD_TYPE (f, j) == intype)
  1161.               break;
  1162.           if (j < 0)
  1163.             error ("no member function matches that type instantiation");
  1164.         }
  1165.           else
  1166.         j = 0;
  1167.  
  1168.           if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
  1169.         {
  1170.           v = value_from_long (builtin_type_long,
  1171.                        (LONGEST) TYPE_FN_FIELD_VOFFSET (f, j));
  1172.         }
  1173.           else
  1174.         {
  1175.           struct symbol *s = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
  1176.                             0, VAR_NAMESPACE, 0);
  1177.           v = locate_var_value (s, 0);
  1178.         }
  1179.           VALUE_TYPE (v) = lookup_pointer_type (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j), baseclass));
  1180.           return v;
  1181.         }
  1182.     }
  1183.  
  1184.       if (TYPE_N_BASECLASSES (t) == 0)
  1185.     break;
  1186.  
  1187.       t = TYPE_BASECLASS (t, 1);
  1188.     }
  1189.   return 0;
  1190. }
  1191.  
  1192. /* Compare two argument lists and return the position in which they differ,
  1193.    or zero if equal.
  1194.  
  1195.    STATICP is nonzero if the T1 argument list came from a
  1196.    static member function.
  1197.  
  1198.    For non-static member functions, we ignore the first argument,
  1199.    which is the type of the instance variable.  This is because we want
  1200.    to handle calls with objects from derived classes.  This is not
  1201.    entirely correct: we should actually check to make sure that a
  1202.    requested operation is type secure, shouldn't we?  */
  1203.  
  1204. int
  1205. typecmp (staticp, t1, t2)
  1206.      int staticp;
  1207.      struct type *t1[];
  1208.      value t2[];
  1209. {
  1210.   int i;
  1211.  
  1212.   if (staticp && t1 == 0)
  1213.     return t2[1] != 0;
  1214.   if (t1 == 0)
  1215.     return 1;
  1216.   if (t1[0]->code == TYPE_CODE_VOID) return 0;
  1217.   if (t1[!staticp] == 0) return 0;
  1218.   for (i = !staticp; t1[i] && t1[i]->code != TYPE_CODE_VOID; i++)
  1219.     {
  1220.       if (! t2[i]
  1221.       || t1[i]->code != t2[i]->type->code
  1222.       || t1[i]->target_type != t2[i]->type->target_type)
  1223.     return i+1;
  1224.     }
  1225.   if (!t1[i]) return 0;
  1226.   return t2[i] ? i+1 : 0;
  1227. }
  1228.  
  1229. /* C++: return the value of the class instance variable, if one exists.
  1230.    Flag COMPLAIN signals an error if the request is made in an
  1231.    inappropriate context.  */
  1232. value
  1233. value_of_this (complain)
  1234.      int complain;
  1235. {
  1236.   extern FRAME selected_frame;
  1237.   struct symbol *func, *sym;
  1238.   char *funname = 0;
  1239.   struct block *b;
  1240.   int i;
  1241.  
  1242.   if (selected_frame == 0)
  1243.     if (complain)
  1244.       error ("no frame selected");
  1245.     else return 0;
  1246.  
  1247.   func = get_frame_function (selected_frame);
  1248.   if (func)
  1249.     funname = SYMBOL_NAME (func);
  1250.   else
  1251.     if (complain)
  1252.       error ("no `this' in nameless context");
  1253.     else return 0;
  1254.  
  1255.   b = SYMBOL_BLOCK_VALUE (func);
  1256.   i = BLOCK_NSYMS (b);
  1257.   if (i <= 0)
  1258.     if (complain)
  1259.       error ("no args, no `this'");
  1260.     else return 0;
  1261.  
  1262.   sym = BLOCK_SYM (b, 0);
  1263.   if (strncmp ("$this", SYMBOL_NAME (sym), 5))
  1264.     if (complain)
  1265.       error ("current stack frame not in method");
  1266.     else return 0;
  1267.  
  1268.   return read_var_value (sym, selected_frame);
  1269. }
  1270.