⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 valops.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 4 页
字号:
valuevalue_struct_elt (argp, args, name, static_memfuncp, err)     register value *argp, *args;     char *name;     int *static_memfuncp;     char *err;{  register struct type *t;  value v;  COERCE_ARRAY (*argp);  t = VALUE_TYPE (*argp);  /* Follow pointers until we get to a non-pointer.  */  while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)    {      *argp = value_ind (*argp);      /* Don't coerce fn pointer to fn and then back again!  */      if (TYPE_CODE (VALUE_TYPE (*argp)) != TYPE_CODE_FUNC)	COERCE_ARRAY (*argp);      t = VALUE_TYPE (*argp);    }  if (TYPE_CODE (t) == TYPE_CODE_MEMBER)    error ("not implemented: member type in value_struct_elt");  if (   TYPE_CODE (t) != TYPE_CODE_STRUCT      && TYPE_CODE (t) != TYPE_CODE_UNION)    error ("Attempt to extract a component of a value that is not a %s.", err);  /* Assume it's not, unless we see that it is.  */  if (static_memfuncp)    *static_memfuncp =0;  if (!args)    {      /* if there are no arguments ...do this...  */      /* Try as a field first, because if we succeed, there	 is less work to be done.  */      v = search_struct_field (name, *argp, 0, t, 0);      if (v)	return v;      /* C++: If it was not found as a data field, then try to         return it as a pointer to a method.  */      if (destructor_name_p (name, t))	error ("Cannot get value of destructor");      v = search_struct_method (name, argp, args, 0, static_memfuncp, t);      if (v == 0)	{	  if (TYPE_NFN_FIELDS (t))	    error ("There is no member or method named %s.", name);	  else	    error ("There is no member named %s.", name);	}      return v;    }  if (destructor_name_p (name, t))    {      if (!args[1])	{	  /* destructors are a special case.  */	  return (value)value_fn_field (NULL, TYPE_FN_FIELDLIST1 (t, 0),					TYPE_FN_FIELDLIST_LENGTH (t, 0),					0, 0);	}      else	{	  error ("destructor should not have any argument");	}    }  else    v = search_struct_method (name, argp, args, 0, static_memfuncp, t);  if (v == 0)    {      /* See if user tried to invoke data as function.  If so,	 hand it back.  If it's not callable (i.e., a pointer to function),	 gdb should give an error.  */      v = search_struct_field (name, *argp, 0, t, 0);    }  if (!v)    error ("Structure has no component named %s.", name);  return v;}/* C++: return 1 is NAME is a legitimate name for the destructor   of type TYPE.  If TYPE does not have a destructor, or   if NAME is inappropriate for TYPE, an error is signaled.  */intdestructor_name_p (name, type)     const char *name;     const struct type *type;{  /* destructors are a special case.  */  if (name[0] == '~')    {      char *dname = type_name_no_tag (type);      if (strcmp (dname, name+1))	error ("name of destructor must equal name of class");      else	return 1;    }  return 0;}/* Helper function for check_field: Given TYPE, a structure/union,   return 1 if the component named NAME from the ultimate   target structure/union is defined, otherwise, return 0. */static intcheck_field_in (type, name)     register struct type *type;     const char *name;{  register int i;  for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)    {      char *t_field_name = TYPE_FIELD_NAME (type, i);      if (t_field_name && !strcmp (t_field_name, name))	return 1;    }  /* C++: If it was not found as a data field, then try to     return it as a pointer to a method.  */  /* Destructors are a special case.  */  if (destructor_name_p (name, type))    return 1;  for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)    {      if (!strcmp (TYPE_FN_FIELDLIST_NAME (type, i), name))	return 1;    }  for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)    if (check_field_in (TYPE_BASECLASS (type, i), name))      return 1;        return 0;}/* C++: Given ARG1, a value of type (pointer to a)* structure/union,   return 1 if the component named NAME from the ultimate   target structure/union is defined, otherwise, return 0.  */intcheck_field (arg1, name)     register value arg1;     const char *name;{  register struct type *t;  COERCE_ARRAY (arg1);  t = VALUE_TYPE (arg1);  /* Follow pointers until we get to a non-pointer.  */  while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)    t = TYPE_TARGET_TYPE (t);  if (TYPE_CODE (t) == TYPE_CODE_MEMBER)    error ("not implemented: member type in check_field");  if (   TYPE_CODE (t) != TYPE_CODE_STRUCT      && TYPE_CODE (t) != TYPE_CODE_UNION)    error ("Internal error: `this' is not an aggregate");  return check_field_in (t, name);}/* C++: Given an aggregate type CURTYPE, and a member name NAME,   return the address of this member as a "pointer to member"   type.  If INTYPE is non-null, then it will be the type   of the member we are looking for.  This will help us resolve   "pointers to member functions".  This function is used   to resolve user expressions of the form "DOMAIN::NAME".  */valuevalue_struct_elt_for_reference (domain, offset, curtype, name, intype)     struct type *domain, *curtype, *intype;     int offset;     char *name;{  register struct type *t = curtype;  register int i;  value v;  if (   TYPE_CODE (t) != TYPE_CODE_STRUCT      && TYPE_CODE (t) != TYPE_CODE_UNION)    error ("Internal error: non-aggregate type to value_struct_elt_for_reference");  for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); i--)    {      char *t_field_name = TYPE_FIELD_NAME (t, i);            if (t_field_name && !strcmp (t_field_name, name))	{	  if (TYPE_FIELD_STATIC (t, i))	    {	      char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (t, i);	      struct symbol *sym =		lookup_symbol (phys_name, 0, VAR_NAMESPACE, 0, NULL);	      if (! sym)		error (	    "Internal error: could not find physical static variable named %s",		       phys_name);	      return value_at (SYMBOL_TYPE (sym),			       (CORE_ADDR)SYMBOL_BLOCK_VALUE (sym));	    }	  if (TYPE_FIELD_PACKED (t, i))	    error ("pointers to bitfield members not allowed");	  	  return value_from_longest	    (lookup_reference_type (lookup_member_type (TYPE_FIELD_TYPE (t, i),							domain)),	     offset + (LONGEST) (TYPE_FIELD_BITPOS (t, i) >> 3));	}    }  /* C++: If it was not found as a data field, then try to     return it as a pointer to a method.  */  /* Destructors are a special case.  */  if (destructor_name_p (name, t))    {      error ("member pointers to destructors not implemented yet");    }  /* Perform all necessary dereferencing.  */  while (intype && TYPE_CODE (intype) == TYPE_CODE_PTR)    intype = TYPE_TARGET_TYPE (intype);  for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i)    {      if (!strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name))	{	  int j = TYPE_FN_FIELDLIST_LENGTH (t, i);	  struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);	  	  if (intype == 0 && j > 1)	    error ("non-unique member `%s' requires type instantiation", name);	  if (intype)	    {	      while (j--)		if (TYPE_FN_FIELD_TYPE (f, j) == intype)		  break;	      if (j < 0)		error ("no member function matches that type instantiation");	    }	  else	    j = 0;	  	  if (TYPE_FN_FIELD_STUB (f, j))	    check_stub_method (t, i, j);	  if (TYPE_FN_FIELD_VIRTUAL_P (f, j))	    {	      return value_from_longest		(lookup_reference_type		 (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j),				      domain)),		 (LONGEST) METHOD_PTR_FROM_VOFFSET		  (TYPE_FN_FIELD_VOFFSET (f, j)));	    }	  else	    {	      struct symbol *s = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),						0, VAR_NAMESPACE, 0, NULL);	      if (s == NULL)		{		  v = 0;		}	      else		{		  v = read_var_value (s, 0);#if 0		  VALUE_TYPE (v) = lookup_reference_type		    (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j),					 domain));#endif		}	      return v;	    }	}    }  for (i = TYPE_N_BASECLASSES (t) - 1; i >= 0; i--)    {      value v;      int base_offset;      if (BASETYPE_VIA_VIRTUAL (t, i))	base_offset = 0;      else	base_offset = TYPE_BASECLASS_BITPOS (t, i) / 8;      v = value_struct_elt_for_reference (domain,					  offset + base_offset,					  TYPE_BASECLASS (t, i),					  name,					  intype);      if (v)	return v;    }  return 0;}/* Compare two argument lists and return the position in which they differ,   or zero if equal.   STATICP is nonzero if the T1 argument list came from a   static member function.   For non-static member functions, we ignore the first argument,   which is the type of the instance variable.  This is because we want   to handle calls with objects from derived classes.  This is not   entirely correct: we should actually check to make sure that a   requested operation is type secure, shouldn't we?  FIXME.  */inttypecmp (staticp, t1, t2)     int staticp;     struct type *t1[];     value t2[];{  int i;  if (t2 == 0)    return 1;  if (staticp && t1 == 0)    return t2[1] != 0;  if (t1 == 0)    return 1;  if (t1[0]->code == TYPE_CODE_VOID) return 0;  if (t1[!staticp] == 0) return 0;  for (i = !staticp; t1[i] && t1[i]->code != TYPE_CODE_VOID; i++)    {      if (! t2[i]	  || t1[i]->code != t2[i]->type->code/* Too pessimistic:  || t1[i]->target_type != t2[i]->type->target_type */ )	return i+1;    }  if (!t1[i]) return 0;  return t2[i] ? i+1 : 0;}/* C++: return the value of the class instance variable, if one exists.   Flag COMPLAIN signals an error if the request is made in an   inappropriate context.  */valuevalue_of_this (complain)     int complain;{  extern FRAME selected_frame;  struct symbol *func, *sym;  struct block *b;  int i;  static const char funny_this[] = "this";  value this;  if (selected_frame == 0)    if (complain)      error ("no frame selected");    else return 0;  func = get_frame_function (selected_frame);  if (!func)    {      if (complain)	error ("no `this' in nameless context");      else return 0;    }  b = SYMBOL_BLOCK_VALUE (func);  i = BLOCK_NSYMS (b);  if (i <= 0)    if (complain)      error ("no args, no `this'");    else return 0;  /* Calling lookup_block_symbol is necessary to get the LOC_REGISTER     symbol instead of the LOC_ARG one (if both exist).  */  sym = lookup_block_symbol (b, funny_this, VAR_NAMESPACE);  if (sym == NULL)    {      if (complain)	error ("current stack frame not in method");      else	return NULL;    }  this = read_var_value (sym, selected_frame);  if (this == 0 && complain)    error ("`this' argument at unknown address");  return this;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -