GDB (xrefs)
/tmp/gdb-7.10/gdb/valarith.c
Go to the documentation of this file.
1 /* Perform arithmetic and other operations on values, for GDB.
2 
3  Copyright (C) 1986-2015 Free Software Foundation, Inc.
4 
5  This file is part of GDB.
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #include "defs.h"
21 #include "value.h"
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "expression.h"
25 #include "target.h"
26 #include "language.h"
27 #include "doublest.h"
28 #include "dfp.h"
29 #include <math.h>
30 #include "infcall.h"
31 
32 /* Define whether or not the C operator '/' truncates towards zero for
33  differently signed operands (truncation direction is undefined in C). */
34 
35 #ifndef TRUNCATION_TOWARDS_ZERO
36 #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
37 #endif
38 
39 void _initialize_valarith (void);
40 
41 
42 /* Given a pointer, return the size of its target.
43  If the pointer type is void *, then return 1.
44  If the target type is incomplete, then error out.
45  This isn't a general purpose function, but just a
46  helper for value_ptradd. */
47 
48 static LONGEST
49 find_size_for_pointer_math (struct type *ptr_type)
50 {
51  LONGEST sz = -1;
52  struct type *ptr_target;
53 
54  gdb_assert (TYPE_CODE (ptr_type) == TYPE_CODE_PTR);
55  ptr_target = check_typedef (TYPE_TARGET_TYPE (ptr_type));
56 
57  sz = TYPE_LENGTH (ptr_target);
58  if (sz == 0)
59  {
60  if (TYPE_CODE (ptr_type) == TYPE_CODE_VOID)
61  sz = 1;
62  else
63  {
64  const char *name;
65 
66  name = TYPE_NAME (ptr_target);
67  if (name == NULL)
68  name = TYPE_TAG_NAME (ptr_target);
69  if (name == NULL)
70  error (_("Cannot perform pointer math on incomplete types, "
71  "try casting to a known type, or void *."));
72  else
73  error (_("Cannot perform pointer math on incomplete type \"%s\", "
74  "try casting to a known type, or void *."), name);
75  }
76  }
77  return sz;
78 }
79 
80 /* Given a pointer ARG1 and an integral value ARG2, return the
81  result of C-style pointer arithmetic ARG1 + ARG2. */
82 
83 struct value *
84 value_ptradd (struct value *arg1, LONGEST arg2)
85 {
86  struct type *valptrtype;
87  LONGEST sz;
88  struct value *result;
89 
90  arg1 = coerce_array (arg1);
91  valptrtype = check_typedef (value_type (arg1));
92  sz = find_size_for_pointer_math (valptrtype);
93 
94  result = value_from_pointer (valptrtype,
95  value_as_address (arg1) + sz * arg2);
96  if (VALUE_LVAL (result) != lval_internalvar)
97  set_value_component_location (result, arg1);
98  return result;
99 }
100 
101 /* Given two compatible pointer values ARG1 and ARG2, return the
102  result of C-style pointer arithmetic ARG1 - ARG2. */
103 
104 LONGEST
105 value_ptrdiff (struct value *arg1, struct value *arg2)
106 {
107  struct type *type1, *type2;
108  LONGEST sz;
109 
110  arg1 = coerce_array (arg1);
111  arg2 = coerce_array (arg2);
112  type1 = check_typedef (value_type (arg1));
113  type2 = check_typedef (value_type (arg2));
114 
115  gdb_assert (TYPE_CODE (type1) == TYPE_CODE_PTR);
116  gdb_assert (TYPE_CODE (type2) == TYPE_CODE_PTR);
117 
120  error (_("First argument of `-' is a pointer and "
121  "second argument is neither\n"
122  "an integer nor a pointer of the same type."));
123 
124  sz = TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1)));
125  if (sz == 0)
126  {
127  warning (_("Type size unknown, assuming 1. "
128  "Try casting to a known type, or void *."));
129  sz = 1;
130  }
131 
132  return (value_as_long (arg1) - value_as_long (arg2)) / sz;
133 }
134 
135 /* Return the value of ARRAY[IDX].
136 
137  ARRAY may be of type TYPE_CODE_ARRAY or TYPE_CODE_STRING. If the
138  current language supports C-style arrays, it may also be TYPE_CODE_PTR.
139 
140  See comments in value_coerce_array() for rationale for reason for
141  doing lower bounds adjustment here rather than there.
142  FIXME: Perhaps we should validate that the index is valid and if
143  verbosity is set, warn about invalid indices (but still use them). */
144 
145 struct value *
146 value_subscript (struct value *array, LONGEST index)
147 {
148  int c_style = current_language->c_style_arrays;
149  struct type *tarray;
150 
151  array = coerce_ref (array);
152  tarray = check_typedef (value_type (array));
153 
154  if (TYPE_CODE (tarray) == TYPE_CODE_ARRAY
155  || TYPE_CODE (tarray) == TYPE_CODE_STRING)
156  {
157  struct type *range_type = TYPE_INDEX_TYPE (tarray);
158  LONGEST lowerbound, upperbound;
159 
160  get_discrete_bounds (range_type, &lowerbound, &upperbound);
161  if (VALUE_LVAL (array) != lval_memory)
162  return value_subscripted_rvalue (array, index, lowerbound);
163 
164  if (c_style == 0)
165  {
166  if (index >= lowerbound && index <= upperbound)
167  return value_subscripted_rvalue (array, index, lowerbound);
168  /* Emit warning unless we have an array of unknown size.
169  An array of unknown size has lowerbound 0 and upperbound -1. */
170  if (upperbound > -1)
171  warning (_("array or string index out of range"));
172  /* fall doing C stuff */
173  c_style = 1;
174  }
175 
176  index -= lowerbound;
177  array = value_coerce_array (array);
178  }
179 
180  if (c_style)
181  return value_ind (value_ptradd (array, index));
182  else
183  error (_("not an array or string"));
184 }
185 
186 /* Return the value of EXPR[IDX], expr an aggregate rvalue
187  (eg, a vector register). This routine used to promote floats
188  to doubles, but no longer does. */
189 
190 struct value *
191 value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
192 {
193  struct type *array_type = check_typedef (value_type (array));
194  struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
195  unsigned int elt_size = TYPE_LENGTH (elt_type);
196  unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
197  struct value *v;
198 
199  if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
200  && elt_offs >= TYPE_LENGTH (array_type)))
201  error (_("no such vector element"));
202 
203  if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
204  v = allocate_value_lazy (elt_type);
205  else
206  {
207  v = allocate_value (elt_type);
209  array, value_embedded_offset (array) + elt_offs,
210  elt_size);
211  }
212 
213  set_value_component_location (v, array);
214  VALUE_REGNUM (v) = VALUE_REGNUM (array);
215  VALUE_FRAME_ID (v) = VALUE_FRAME_ID (array);
216  set_value_offset (v, value_offset (array) + elt_offs);
217  return v;
218 }
219 
220 
221 /* Check to see if either argument is a structure, or a reference to
222  one. This is called so we know whether to go ahead with the normal
223  binop or look for a user defined function instead.
224 
225  For now, we do not overload the `=' operator. */
226 
227 int
229  struct type *type1, struct type *type2)
230 {
231  if (op == BINOP_ASSIGN || op == BINOP_CONCAT)
232  return 0;
233 
234  type1 = check_typedef (type1);
235  if (TYPE_CODE (type1) == TYPE_CODE_REF)
236  type1 = check_typedef (TYPE_TARGET_TYPE (type1));
237 
238  type2 = check_typedef (type2);
239  if (TYPE_CODE (type2) == TYPE_CODE_REF)
240  type2 = check_typedef (TYPE_TARGET_TYPE (type2));
241 
242  return (TYPE_CODE (type1) == TYPE_CODE_STRUCT
243  || TYPE_CODE (type2) == TYPE_CODE_STRUCT);
244 }
245 
246 /* Check to see if either argument is a structure, or a reference to
247  one. This is called so we know whether to go ahead with the normal
248  binop or look for a user defined function instead.
249 
250  For now, we do not overload the `=' operator. */
251 
252 int
254  struct value *arg1, struct value *arg2)
255 {
256  return binop_types_user_defined_p (op, value_type (arg1), value_type (arg2));
257 }
258 
259 /* Check to see if argument is a structure. This is called so
260  we know whether to go ahead with the normal unop or look for a
261  user defined function instead.
262 
263  For now, we do not overload the `&' operator. */
264 
265 int
266 unop_user_defined_p (enum exp_opcode op, struct value *arg1)
267 {
268  struct type *type1;
269 
270  if (op == UNOP_ADDR)
271  return 0;
272  type1 = check_typedef (value_type (arg1));
273  if (TYPE_CODE (type1) == TYPE_CODE_REF)
274  type1 = check_typedef (TYPE_TARGET_TYPE (type1));
275  return TYPE_CODE (type1) == TYPE_CODE_STRUCT;
276 }
277 
278 /* Try to find an operator named OPERATOR which takes NARGS arguments
279  specified in ARGS. If the operator found is a static member operator
280  *STATIC_MEMFUNP will be set to 1, and otherwise 0.
281  The search if performed through find_overload_match which will handle
282  member operators, non member operators, operators imported implicitly or
283  explicitly, and perform correct overload resolution in all of the above
284  situations or combinations thereof. */
285 
286 static struct value *
287 value_user_defined_cpp_op (struct value **args, int nargs, char *oper,
288  int *static_memfuncp, enum noside noside)
289 {
290 
291  struct symbol *symp = NULL;
292  struct value *valp = NULL;
293 
294  find_overload_match (args, nargs, oper, BOTH /* could be method */,
295  &args[0] /* objp */,
296  NULL /* pass NULL symbol since symbol is unknown */,
297  &valp, &symp, static_memfuncp, 0, noside);
298 
299  if (valp)
300  return valp;
301 
302  if (symp)
303  {
304  /* This is a non member function and does not
305  expect a reference as its first argument
306  rather the explicit structure. */
307  args[0] = value_ind (args[0]);
308  return value_of_variable (symp, 0);
309  }
310 
311  error (_("Could not find %s."), oper);
312 }
313 
314 /* Lookup user defined operator NAME. Return a value representing the
315  function, otherwise return NULL. */
316 
317 static struct value *
318 value_user_defined_op (struct value **argp, struct value **args, char *name,
319  int *static_memfuncp, int nargs, enum noside noside)
320 {
321  struct value *result = NULL;
322 
324  {
325  result = value_user_defined_cpp_op (args, nargs, name, static_memfuncp,
326  noside);
327  }
328  else
329  result = value_struct_elt (argp, args, name, static_memfuncp,
330  "structure");
331 
332  return result;
333 }
334 
335 /* We know either arg1 or arg2 is a structure, so try to find the right
336  user defined function. Create an argument vector that calls
337  arg1.operator @ (arg1,arg2) and return that value (where '@' is any
338  binary operator which is legal for GNU C++).
339 
340  OP is the operatore, and if it is BINOP_ASSIGN_MODIFY, then OTHEROP
341  is the opcode saying how to modify it. Otherwise, OTHEROP is
342  unused. */
343 
344 struct value *
345 value_x_binop (struct value *arg1, struct value *arg2, enum exp_opcode op,
346  enum exp_opcode otherop, enum noside noside)
347 {
348  struct value **argvec;
349  char *ptr;
350  char tstr[13];
351  int static_memfuncp;
352 
353  arg1 = coerce_ref (arg1);
354  arg2 = coerce_ref (arg2);
355 
356  /* now we know that what we have to do is construct our
357  arg vector and find the right function to call it with. */
358 
360  error (_("Can't do that binary op on that type")); /* FIXME be explicit */
361 
362  argvec = (struct value **) alloca (sizeof (struct value *) * 4);
363  argvec[1] = value_addr (arg1);
364  argvec[2] = arg2;
365  argvec[3] = 0;
366 
367  /* Make the right function name up. */
368  strcpy (tstr, "operator__");
369  ptr = tstr + 8;
370  switch (op)
371  {
372  case BINOP_ADD:
373  strcpy (ptr, "+");
374  break;
375  case BINOP_SUB:
376  strcpy (ptr, "-");
377  break;
378  case BINOP_MUL:
379  strcpy (ptr, "*");
380  break;
381  case BINOP_DIV:
382  strcpy (ptr, "/");
383  break;
384  case BINOP_REM:
385  strcpy (ptr, "%");
386  break;
387  case BINOP_LSH:
388  strcpy (ptr, "<<");
389  break;
390  case BINOP_RSH:
391  strcpy (ptr, ">>");
392  break;
393  case BINOP_BITWISE_AND:
394  strcpy (ptr, "&");
395  break;
396  case BINOP_BITWISE_IOR:
397  strcpy (ptr, "|");
398  break;
399  case BINOP_BITWISE_XOR:
400  strcpy (ptr, "^");
401  break;
402  case BINOP_LOGICAL_AND:
403  strcpy (ptr, "&&");
404  break;
405  case BINOP_LOGICAL_OR:
406  strcpy (ptr, "||");
407  break;
408  case BINOP_MIN:
409  strcpy (ptr, "<?");
410  break;
411  case BINOP_MAX:
412  strcpy (ptr, ">?");
413  break;
414  case BINOP_ASSIGN:
415  strcpy (ptr, "=");
416  break;
417  case BINOP_ASSIGN_MODIFY:
418  switch (otherop)
419  {
420  case BINOP_ADD:
421  strcpy (ptr, "+=");
422  break;
423  case BINOP_SUB:
424  strcpy (ptr, "-=");
425  break;
426  case BINOP_MUL:
427  strcpy (ptr, "*=");
428  break;
429  case BINOP_DIV:
430  strcpy (ptr, "/=");
431  break;
432  case BINOP_REM:
433  strcpy (ptr, "%=");
434  break;
435  case BINOP_BITWISE_AND:
436  strcpy (ptr, "&=");
437  break;
438  case BINOP_BITWISE_IOR:
439  strcpy (ptr, "|=");
440  break;
441  case BINOP_BITWISE_XOR:
442  strcpy (ptr, "^=");
443  break;
444  case BINOP_MOD: /* invalid */
445  default:
446  error (_("Invalid binary operation specified."));
447  }
448  break;
449  case BINOP_SUBSCRIPT:
450  strcpy (ptr, "[]");
451  break;
452  case BINOP_EQUAL:
453  strcpy (ptr, "==");
454  break;
455  case BINOP_NOTEQUAL:
456  strcpy (ptr, "!=");
457  break;
458  case BINOP_LESS:
459  strcpy (ptr, "<");
460  break;
461  case BINOP_GTR:
462  strcpy (ptr, ">");
463  break;
464  case BINOP_GEQ:
465  strcpy (ptr, ">=");
466  break;
467  case BINOP_LEQ:
468  strcpy (ptr, "<=");
469  break;
470  case BINOP_MOD: /* invalid */
471  default:
472  error (_("Invalid binary operation specified."));
473  }
474 
475  argvec[0] = value_user_defined_op (&arg1, argvec + 1, tstr,
476  &static_memfuncp, 2, noside);
477 
478  if (argvec[0])
479  {
480  if (static_memfuncp)
481  {
482  argvec[1] = argvec[0];
483  argvec++;
484  }
485  if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_XMETHOD)
486  {
487  /* Static xmethods are not supported yet. */
488  gdb_assert (static_memfuncp == 0);
489  if (noside == EVAL_AVOID_SIDE_EFFECTS)
490  {
491  struct type *return_type
492  = result_type_of_xmethod (argvec[0], 2, argvec + 1);
493 
494  if (return_type == NULL)
495  error (_("Xmethod is missing return type."));
496  return value_zero (return_type, VALUE_LVAL (arg1));
497  }
498  return call_xmethod (argvec[0], 2, argvec + 1);
499  }
500  if (noside == EVAL_AVOID_SIDE_EFFECTS)
501  {
502  struct type *return_type;
503 
504  return_type
505  = TYPE_TARGET_TYPE (check_typedef (value_type (argvec[0])));
506  return value_zero (return_type, VALUE_LVAL (arg1));
507  }
508  return call_function_by_hand (argvec[0], 2 - static_memfuncp,
509  argvec + 1);
510  }
512  _("member function %s not found"), tstr);
513 #ifdef lint
514  return call_function_by_hand (argvec[0], 2 - static_memfuncp, argvec + 1);
515 #endif
516 }
517 
518 /* We know that arg1 is a structure, so try to find a unary user
519  defined operator that matches the operator in question.
520  Create an argument vector that calls arg1.operator @ (arg1)
521  and return that value (where '@' is (almost) any unary operator which
522  is legal for GNU C++). */
523 
524 struct value *
525 value_x_unop (struct value *arg1, enum exp_opcode op, enum noside noside)
526 {
527  struct gdbarch *gdbarch = get_type_arch (value_type (arg1));
528  struct value **argvec;
529  char *ptr;
530  char tstr[13], mangle_tstr[13];
531  int static_memfuncp, nargs;
532 
533  arg1 = coerce_ref (arg1);
534 
535  /* now we know that what we have to do is construct our
536  arg vector and find the right function to call it with. */
537 
539  error (_("Can't do that unary op on that type")); /* FIXME be explicit */
540 
541  argvec = (struct value **) alloca (sizeof (struct value *) * 4);
542  argvec[1] = value_addr (arg1);
543  argvec[2] = 0;
544 
545  nargs = 1;
546 
547  /* Make the right function name up. */
548  strcpy (tstr, "operator__");
549  ptr = tstr + 8;
550  strcpy (mangle_tstr, "__");
551  switch (op)
552  {
553  case UNOP_PREINCREMENT:
554  strcpy (ptr, "++");
555  break;
556  case UNOP_PREDECREMENT:
557  strcpy (ptr, "--");
558  break;
559  case UNOP_POSTINCREMENT:
560  strcpy (ptr, "++");
561  argvec[2] = value_from_longest (builtin_type (gdbarch)->builtin_int, 0);
562  argvec[3] = 0;
563  nargs ++;
564  break;
565  case UNOP_POSTDECREMENT:
566  strcpy (ptr, "--");
567  argvec[2] = value_from_longest (builtin_type (gdbarch)->builtin_int, 0);
568  argvec[3] = 0;
569  nargs ++;
570  break;
571  case UNOP_LOGICAL_NOT:
572  strcpy (ptr, "!");
573  break;
574  case UNOP_COMPLEMENT:
575  strcpy (ptr, "~");
576  break;
577  case UNOP_NEG:
578  strcpy (ptr, "-");
579  break;
580  case UNOP_PLUS:
581  strcpy (ptr, "+");
582  break;
583  case UNOP_IND:
584  strcpy (ptr, "*");
585  break;
586  case STRUCTOP_PTR:
587  strcpy (ptr, "->");
588  break;
589  default:
590  error (_("Invalid unary operation specified."));
591  }
592 
593  argvec[0] = value_user_defined_op (&arg1, argvec + 1, tstr,
594  &static_memfuncp, nargs, noside);
595 
596  if (argvec[0])
597  {
598  if (static_memfuncp)
599  {
600  argvec[1] = argvec[0];
601  nargs --;
602  argvec++;
603  }
604  if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_XMETHOD)
605  {
606  /* Static xmethods are not supported yet. */
607  gdb_assert (static_memfuncp == 0);
608  if (noside == EVAL_AVOID_SIDE_EFFECTS)
609  {
610  struct type *return_type
611  = result_type_of_xmethod (argvec[0], 1, argvec + 1);
612 
613  if (return_type == NULL)
614  error (_("Xmethod is missing return type."));
615  return value_zero (return_type, VALUE_LVAL (arg1));
616  }
617  return call_xmethod (argvec[0], 1, argvec + 1);
618  }
619  if (noside == EVAL_AVOID_SIDE_EFFECTS)
620  {
621  struct type *return_type;
622 
623  return_type
624  = TYPE_TARGET_TYPE (check_typedef (value_type (argvec[0])));
625  return value_zero (return_type, VALUE_LVAL (arg1));
626  }
627  return call_function_by_hand (argvec[0], nargs, argvec + 1);
628  }
630  _("member function %s not found"), tstr);
631 
632  return 0; /* For lint -- never reached */
633 }
634 
635 
636 /* Concatenate two values with the following conditions:
637 
638  (1) Both values must be either bitstring values or character string
639  values and the resulting value consists of the concatenation of
640  ARG1 followed by ARG2.
641 
642  or
643 
644  One value must be an integer value and the other value must be
645  either a bitstring value or character string value, which is
646  to be repeated by the number of times specified by the integer
647  value.
648 
649 
650  (2) Boolean values are also allowed and are treated as bit string
651  values of length 1.
652 
653  (3) Character values are also allowed and are treated as character
654  string values of length 1. */
655 
656 struct value *
657 value_concat (struct value *arg1, struct value *arg2)
658 {
659  struct value *inval1;
660  struct value *inval2;
661  struct value *outval = NULL;
662  int inval1len, inval2len;
663  int count, idx;
664  char *ptr;
665  char inchar;
666  struct type *type1 = check_typedef (value_type (arg1));
667  struct type *type2 = check_typedef (value_type (arg2));
668  struct type *char_type;
669 
670  /* First figure out if we are dealing with two values to be concatenated
671  or a repeat count and a value to be repeated. INVAL1 is set to the
672  first of two concatenated values, or the repeat count. INVAL2 is set
673  to the second of the two concatenated values or the value to be
674  repeated. */
675 
676  if (TYPE_CODE (type2) == TYPE_CODE_INT)
677  {
678  struct type *tmp = type1;
679 
680  type1 = tmp;
681  tmp = type2;
682  inval1 = arg2;
683  inval2 = arg1;
684  }
685  else
686  {
687  inval1 = arg1;
688  inval2 = arg2;
689  }
690 
691  /* Now process the input values. */
692 
693  if (TYPE_CODE (type1) == TYPE_CODE_INT)
694  {
695  /* We have a repeat count. Validate the second value and then
696  construct a value repeated that many times. */
697  if (TYPE_CODE (type2) == TYPE_CODE_STRING
698  || TYPE_CODE (type2) == TYPE_CODE_CHAR)
699  {
700  struct cleanup *back_to;
701 
702  count = longest_to_int (value_as_long (inval1));
703  inval2len = TYPE_LENGTH (type2);
704  ptr = (char *) xmalloc (count * inval2len);
705  back_to = make_cleanup (xfree, ptr);
706  if (TYPE_CODE (type2) == TYPE_CODE_CHAR)
707  {
708  char_type = type2;
709 
710  inchar = (char) unpack_long (type2,
711  value_contents (inval2));
712  for (idx = 0; idx < count; idx++)
713  {
714  *(ptr + idx) = inchar;
715  }
716  }
717  else
718  {
719  char_type = TYPE_TARGET_TYPE (type2);
720 
721  for (idx = 0; idx < count; idx++)
722  {
723  memcpy (ptr + (idx * inval2len), value_contents (inval2),
724  inval2len);
725  }
726  }
727  outval = value_string (ptr, count * inval2len, char_type);
728  do_cleanups (back_to);
729  }
730  else if (TYPE_CODE (type2) == TYPE_CODE_BOOL)
731  {
732  error (_("unimplemented support for boolean repeats"));
733  }
734  else
735  {
736  error (_("can't repeat values of that type"));
737  }
738  }
739  else if (TYPE_CODE (type1) == TYPE_CODE_STRING
740  || TYPE_CODE (type1) == TYPE_CODE_CHAR)
741  {
742  struct cleanup *back_to;
743 
744  /* We have two character strings to concatenate. */
745  if (TYPE_CODE (type2) != TYPE_CODE_STRING
746  && TYPE_CODE (type2) != TYPE_CODE_CHAR)
747  {
748  error (_("Strings can only be concatenated with other strings."));
749  }
750  inval1len = TYPE_LENGTH (type1);
751  inval2len = TYPE_LENGTH (type2);
752  ptr = (char *) xmalloc (inval1len + inval2len);
753  back_to = make_cleanup (xfree, ptr);
754  if (TYPE_CODE (type1) == TYPE_CODE_CHAR)
755  {
756  char_type = type1;
757 
758  *ptr = (char) unpack_long (type1, value_contents (inval1));
759  }
760  else
761  {
762  char_type = TYPE_TARGET_TYPE (type1);
763 
764  memcpy (ptr, value_contents (inval1), inval1len);
765  }
766  if (TYPE_CODE (type2) == TYPE_CODE_CHAR)
767  {
768  *(ptr + inval1len) =
769  (char) unpack_long (type2, value_contents (inval2));
770  }
771  else
772  {
773  memcpy (ptr + inval1len, value_contents (inval2), inval2len);
774  }
775  outval = value_string (ptr, inval1len + inval2len, char_type);
776  do_cleanups (back_to);
777  }
778  else if (TYPE_CODE (type1) == TYPE_CODE_BOOL)
779  {
780  /* We have two bitstrings to concatenate. */
781  if (TYPE_CODE (type2) != TYPE_CODE_BOOL)
782  {
783  error (_("Booleans can only be concatenated "
784  "with other bitstrings or booleans."));
785  }
786  error (_("unimplemented support for boolean concatenation."));
787  }
788  else
789  {
790  /* We don't know how to concatenate these operands. */
791  error (_("illegal operands for concatenation."));
792  }
793  return (outval);
794 }
795 
796 /* Integer exponentiation: V1**V2, where both arguments are
797  integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
798 
799 static LONGEST
801 {
802  if (v2 < 0)
803  {
804  if (v1 == 0)
805  error (_("Attempt to raise 0 to negative power."));
806  else
807  return 0;
808  }
809  else
810  {
811  /* The Russian Peasant's Algorithm. */
812  LONGEST v;
813 
814  v = 1;
815  for (;;)
816  {
817  if (v2 & 1L)
818  v *= v1;
819  v2 >>= 1;
820  if (v2 == 0)
821  return v;
822  v1 *= v1;
823  }
824  }
825 }
826 
827 /* Integer exponentiation: V1**V2, where both arguments are
828  integers. Requires V1 != 0 if V2 < 0. Returns 1 for 0 ** 0. */
829 
830 static ULONGEST
832 {
833  if (v2 < 0)
834  {
835  if (v1 == 0)
836  error (_("Attempt to raise 0 to negative power."));
837  else
838  return 0;
839  }
840  else
841  {
842  /* The Russian Peasant's Algorithm. */
843  ULONGEST v;
844 
845  v = 1;
846  for (;;)
847  {
848  if (v2 & 1L)
849  v *= v1;
850  v2 >>= 1;
851  if (v2 == 0)
852  return v;
853  v1 *= v1;
854  }
855  }
856 }
857 
858 /* Obtain decimal value of arguments for binary operation, converting from
859  other types if one of them is not decimal floating point. */
860 static void
861 value_args_as_decimal (struct value *arg1, struct value *arg2,
862  gdb_byte *x, int *len_x, enum bfd_endian *byte_order_x,
863  gdb_byte *y, int *len_y, enum bfd_endian *byte_order_y)
864 {
865  struct type *type1, *type2;
866 
867  type1 = check_typedef (value_type (arg1));
868  type2 = check_typedef (value_type (arg2));
869 
870  /* At least one of the arguments must be of decimal float type. */
872  || TYPE_CODE (type2) == TYPE_CODE_DECFLOAT);
873 
874  if (TYPE_CODE (type1) == TYPE_CODE_FLT
875  || TYPE_CODE (type2) == TYPE_CODE_FLT)
876  /* The DFP extension to the C language does not allow mixing of
877  * decimal float types with other float types in expressions
878  * (see WDTR 24732, page 12). */
879  error (_("Mixing decimal floating types with "
880  "other floating types is not allowed."));
881 
882  /* Obtain decimal value of arg1, converting from other types
883  if necessary. */
884 
885  if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT)
886  {
887  *byte_order_x = gdbarch_byte_order (get_type_arch (type1));
888  *len_x = TYPE_LENGTH (type1);
889  memcpy (x, value_contents (arg1), *len_x);
890  }
891  else if (is_integral_type (type1))
892  {
893  *byte_order_x = gdbarch_byte_order (get_type_arch (type2));
894  *len_x = TYPE_LENGTH (type2);
895  decimal_from_integral (arg1, x, *len_x, *byte_order_x);
896  }
897  else
898  error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1),
899  TYPE_NAME (type2));
900 
901  /* Obtain decimal value of arg2, converting from other types
902  if necessary. */
903 
904  if (TYPE_CODE (type2) == TYPE_CODE_DECFLOAT)
905  {
906  *byte_order_y = gdbarch_byte_order (get_type_arch (type2));
907  *len_y = TYPE_LENGTH (type2);
908  memcpy (y, value_contents (arg2), *len_y);
909  }
910  else if (is_integral_type (type2))
911  {
912  *byte_order_y = gdbarch_byte_order (get_type_arch (type1));
913  *len_y = TYPE_LENGTH (type1);
914  decimal_from_integral (arg2, y, *len_y, *byte_order_y);
915  }
916  else
917  error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1),
918  TYPE_NAME (type2));
919 }
920 
921 /* Perform a binary operation on two operands which have reasonable
922  representations as integers or floats. This includes booleans,
923  characters, integers, or floats.
924  Does not support addition and subtraction on pointers;
925  use value_ptradd, value_ptrsub or value_ptrdiff for those operations. */
926 
927 static struct value *
928 scalar_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
929 {
930  struct value *val;
931  struct type *type1, *type2, *result_type;
932 
933  arg1 = coerce_ref (arg1);
934  arg2 = coerce_ref (arg2);
935 
936  type1 = check_typedef (value_type (arg1));
937  type2 = check_typedef (value_type (arg2));
938 
939  if ((TYPE_CODE (type1) != TYPE_CODE_FLT
940  && TYPE_CODE (type1) != TYPE_CODE_DECFLOAT
941  && !is_integral_type (type1))
942  || (TYPE_CODE (type2) != TYPE_CODE_FLT
943  && TYPE_CODE (type2) != TYPE_CODE_DECFLOAT
944  && !is_integral_type (type2)))
945  error (_("Argument to arithmetic operation not a number or boolean."));
946 
947  if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT
948  || TYPE_CODE (type2) == TYPE_CODE_DECFLOAT)
949  {
950  int len_v1, len_v2, len_v;
951  enum bfd_endian byte_order_v1, byte_order_v2, byte_order_v;
952  gdb_byte v1[16], v2[16];
953  gdb_byte v[16];
954 
955  /* If only one type is decimal float, use its type.
956  Otherwise use the bigger type. */
957  if (TYPE_CODE (type1) != TYPE_CODE_DECFLOAT)
958  result_type = type2;
959  else if (TYPE_CODE (type2) != TYPE_CODE_DECFLOAT)
960  result_type = type1;
961  else if (TYPE_LENGTH (type2) > TYPE_LENGTH (type1))
962  result_type = type2;
963  else
964  result_type = type1;
965 
966  len_v = TYPE_LENGTH (result_type);
967  byte_order_v = gdbarch_byte_order (get_type_arch (result_type));
968 
969  value_args_as_decimal (arg1, arg2, v1, &len_v1, &byte_order_v1,
970  v2, &len_v2, &byte_order_v2);
971 
972  switch (op)
973  {
974  case BINOP_ADD:
975  case BINOP_SUB:
976  case BINOP_MUL:
977  case BINOP_DIV:
978  case BINOP_EXP:
979  decimal_binop (op, v1, len_v1, byte_order_v1,
980  v2, len_v2, byte_order_v2,
981  v, len_v, byte_order_v);
982  break;
983 
984  default:
985  error (_("Operation not valid for decimal floating point number."));
986  }
987 
988  val = value_from_decfloat (result_type, v);
989  }
990  else if (TYPE_CODE (type1) == TYPE_CODE_FLT
991  || TYPE_CODE (type2) == TYPE_CODE_FLT)
992  {
993  /* FIXME-if-picky-about-floating-accuracy: Should be doing this
994  in target format. real.c in GCC probably has the necessary
995  code. */
996  DOUBLEST v1, v2, v = 0;
997 
998  v1 = value_as_double (arg1);
999  v2 = value_as_double (arg2);
1000 
1001  switch (op)
1002  {
1003  case BINOP_ADD:
1004  v = v1 + v2;
1005  break;
1006 
1007  case BINOP_SUB:
1008  v = v1 - v2;
1009  break;
1010 
1011  case BINOP_MUL:
1012  v = v1 * v2;
1013  break;
1014 
1015  case BINOP_DIV:
1016  v = v1 / v2;
1017  break;
1018 
1019  case BINOP_EXP:
1020  errno = 0;
1021  v = pow (v1, v2);
1022  if (errno)
1023  error (_("Cannot perform exponentiation: %s"),
1024  safe_strerror (errno));
1025  break;
1026 
1027  case BINOP_MIN:
1028  v = v1 < v2 ? v1 : v2;
1029  break;
1030 
1031  case BINOP_MAX:
1032  v = v1 > v2 ? v1 : v2;
1033  break;
1034 
1035  default:
1036  error (_("Integer-only operation on floating point number."));
1037  }
1038 
1039  /* If only one type is float, use its type.
1040  Otherwise use the bigger type. */
1041  if (TYPE_CODE (type1) != TYPE_CODE_FLT)
1042  result_type = type2;
1043  else if (TYPE_CODE (type2) != TYPE_CODE_FLT)
1044  result_type = type1;
1045  else if (TYPE_LENGTH (type2) > TYPE_LENGTH (type1))
1046  result_type = type2;
1047  else
1048  result_type = type1;
1049 
1050  val = allocate_value (result_type);
1052  }
1053  else if (TYPE_CODE (type1) == TYPE_CODE_BOOL
1054  || TYPE_CODE (type2) == TYPE_CODE_BOOL)
1055  {
1056  LONGEST v1, v2, v = 0;
1057 
1058  v1 = value_as_long (arg1);
1059  v2 = value_as_long (arg2);
1060 
1061  switch (op)
1062  {
1063  case BINOP_BITWISE_AND:
1064  v = v1 & v2;
1065  break;
1066 
1067  case BINOP_BITWISE_IOR:
1068  v = v1 | v2;
1069  break;
1070 
1071  case BINOP_BITWISE_XOR:
1072  v = v1 ^ v2;
1073  break;
1074 
1075  case BINOP_EQUAL:
1076  v = v1 == v2;
1077  break;
1078 
1079  case BINOP_NOTEQUAL:
1080  v = v1 != v2;
1081  break;
1082 
1083  default:
1084  error (_("Invalid operation on booleans."));
1085  }
1086 
1087  result_type = type1;
1088 
1089  val = allocate_value (result_type);
1091  TYPE_LENGTH (result_type),
1092  gdbarch_byte_order (get_type_arch (result_type)),
1093  v);
1094  }
1095  else
1096  /* Integral operations here. */
1097  {
1098  /* Determine type length of the result, and if the operation should
1099  be done unsigned. For exponentiation and shift operators,
1100  use the length and type of the left operand. Otherwise,
1101  use the signedness of the operand with the greater length.
1102  If both operands are of equal length, use unsigned operation
1103  if one of the operands is unsigned. */
1104  if (op == BINOP_RSH || op == BINOP_LSH || op == BINOP_EXP)
1105  result_type = type1;
1106  else if (TYPE_LENGTH (type1) > TYPE_LENGTH (type2))
1107  result_type = type1;
1108  else if (TYPE_LENGTH (type2) > TYPE_LENGTH (type1))
1109  result_type = type2;
1110  else if (TYPE_UNSIGNED (type1))
1111  result_type = type1;
1112  else if (TYPE_UNSIGNED (type2))
1113  result_type = type2;
1114  else
1115  result_type = type1;
1116 
1117  if (TYPE_UNSIGNED (result_type))
1118  {
1119  LONGEST v2_signed = value_as_long (arg2);
1120  ULONGEST v1, v2, v = 0;
1121 
1122  v1 = (ULONGEST) value_as_long (arg1);
1123  v2 = (ULONGEST) v2_signed;
1124 
1125  switch (op)
1126  {
1127  case BINOP_ADD:
1128  v = v1 + v2;
1129  break;
1130 
1131  case BINOP_SUB:
1132  v = v1 - v2;
1133  break;
1134 
1135  case BINOP_MUL:
1136  v = v1 * v2;
1137  break;
1138 
1139  case BINOP_DIV:
1140  case BINOP_INTDIV:
1141  if (v2 != 0)
1142  v = v1 / v2;
1143  else
1144  error (_("Division by zero"));
1145  break;
1146 
1147  case BINOP_EXP:
1148  v = uinteger_pow (v1, v2_signed);
1149  break;
1150 
1151  case BINOP_REM:
1152  if (v2 != 0)
1153  v = v1 % v2;
1154  else
1155  error (_("Division by zero"));
1156  break;
1157 
1158  case BINOP_MOD:
1159  /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1160  v1 mod 0 has a defined value, v1. */
1161  if (v2 == 0)
1162  {
1163  v = v1;
1164  }
1165  else
1166  {
1167  v = v1 / v2;
1168  /* Note floor(v1/v2) == v1/v2 for unsigned. */
1169  v = v1 - (v2 * v);
1170  }
1171  break;
1172 
1173  case BINOP_LSH:
1174  v = v1 << v2;
1175  break;
1176 
1177  case BINOP_RSH:
1178  v = v1 >> v2;
1179  break;
1180 
1181  case BINOP_BITWISE_AND:
1182  v = v1 & v2;
1183  break;
1184 
1185  case BINOP_BITWISE_IOR:
1186  v = v1 | v2;
1187  break;
1188 
1189  case BINOP_BITWISE_XOR:
1190  v = v1 ^ v2;
1191  break;
1192 
1193  case BINOP_LOGICAL_AND:
1194  v = v1 && v2;
1195  break;
1196 
1197  case BINOP_LOGICAL_OR:
1198  v = v1 || v2;
1199  break;
1200 
1201  case BINOP_MIN:
1202  v = v1 < v2 ? v1 : v2;
1203  break;
1204 
1205  case BINOP_MAX:
1206  v = v1 > v2 ? v1 : v2;
1207  break;
1208 
1209  case BINOP_EQUAL:
1210  v = v1 == v2;
1211  break;
1212 
1213  case BINOP_NOTEQUAL:
1214  v = v1 != v2;
1215  break;
1216 
1217  case BINOP_LESS:
1218  v = v1 < v2;
1219  break;
1220 
1221  case BINOP_GTR:
1222  v = v1 > v2;
1223  break;
1224 
1225  case BINOP_LEQ:
1226  v = v1 <= v2;
1227  break;
1228 
1229  case BINOP_GEQ:
1230  v = v1 >= v2;
1231  break;
1232 
1233  default:
1234  error (_("Invalid binary operation on numbers."));
1235  }
1236 
1237  val = allocate_value (result_type);
1239  TYPE_LENGTH (value_type (val)),
1241  (get_type_arch (result_type)),
1242  v);
1243  }
1244  else
1245  {
1246  LONGEST v1, v2, v = 0;
1247 
1248  v1 = value_as_long (arg1);
1249  v2 = value_as_long (arg2);
1250 
1251  switch (op)
1252  {
1253  case BINOP_ADD:
1254  v = v1 + v2;
1255  break;
1256 
1257  case BINOP_SUB:
1258  v = v1 - v2;
1259  break;
1260 
1261  case BINOP_MUL:
1262  v = v1 * v2;
1263  break;
1264 
1265  case BINOP_DIV:
1266  case BINOP_INTDIV:
1267  if (v2 != 0)
1268  v = v1 / v2;
1269  else
1270  error (_("Division by zero"));
1271  break;
1272 
1273  case BINOP_EXP:
1274  v = integer_pow (v1, v2);
1275  break;
1276 
1277  case BINOP_REM:
1278  if (v2 != 0)
1279  v = v1 % v2;
1280  else
1281  error (_("Division by zero"));
1282  break;
1283 
1284  case BINOP_MOD:
1285  /* Knuth 1.2.4, integer only. Note that unlike the C '%' op,
1286  X mod 0 has a defined value, X. */
1287  if (v2 == 0)
1288  {
1289  v = v1;
1290  }
1291  else
1292  {
1293  v = v1 / v2;
1294  /* Compute floor. */
1295  if (TRUNCATION_TOWARDS_ZERO && (v < 0) && ((v1 % v2) != 0))
1296  {
1297  v--;
1298  }
1299  v = v1 - (v2 * v);
1300  }
1301  break;
1302 
1303  case BINOP_LSH:
1304  v = v1 << v2;
1305  break;
1306 
1307  case BINOP_RSH:
1308  v = v1 >> v2;
1309  break;
1310 
1311  case BINOP_BITWISE_AND:
1312  v = v1 & v2;
1313  break;
1314 
1315  case BINOP_BITWISE_IOR:
1316  v = v1 | v2;
1317  break;
1318 
1319  case BINOP_BITWISE_XOR:
1320  v = v1 ^ v2;
1321  break;
1322 
1323  case BINOP_LOGICAL_AND:
1324  v = v1 && v2;
1325  break;
1326 
1327  case BINOP_LOGICAL_OR:
1328  v = v1 || v2;
1329  break;
1330 
1331  case BINOP_MIN:
1332  v = v1 < v2 ? v1 : v2;
1333  break;
1334 
1335  case BINOP_MAX:
1336  v = v1 > v2 ? v1 : v2;
1337  break;
1338 
1339  case BINOP_EQUAL:
1340  v = v1 == v2;
1341  break;
1342 
1343  case BINOP_NOTEQUAL:
1344  v = v1 != v2;
1345  break;
1346 
1347  case BINOP_LESS:
1348  v = v1 < v2;
1349  break;
1350 
1351  case BINOP_GTR:
1352  v = v1 > v2;
1353  break;
1354 
1355  case BINOP_LEQ:
1356  v = v1 <= v2;
1357  break;
1358 
1359  case BINOP_GEQ:
1360  v = v1 >= v2;
1361  break;
1362 
1363  default:
1364  error (_("Invalid binary operation on numbers."));
1365  }
1366 
1367  val = allocate_value (result_type);
1369  TYPE_LENGTH (value_type (val)),
1371  (get_type_arch (result_type)),
1372  v);
1373  }
1374  }
1375 
1376  return val;
1377 }
1378 
1379 /* Widen a scalar value SCALAR_VALUE to vector type VECTOR_TYPE by
1380  replicating SCALAR_VALUE for each element of the vector. Only scalar
1381  types that can be cast to the type of one element of the vector are
1382  acceptable. The newly created vector value is returned upon success,
1383  otherwise an error is thrown. */
1384 
1385 struct value *
1386 value_vector_widen (struct value *scalar_value, struct type *vector_type)
1387 {
1388  /* Widen the scalar to a vector. */
1389  struct type *eltype, *scalar_type;
1390  struct value *val, *elval;
1391  LONGEST low_bound, high_bound;
1392  int i;
1393 
1394  CHECK_TYPEDEF (vector_type);
1395 
1396  gdb_assert (TYPE_CODE (vector_type) == TYPE_CODE_ARRAY
1397  && TYPE_VECTOR (vector_type));
1398 
1399  if (!get_array_bounds (vector_type, &low_bound, &high_bound))
1400  error (_("Could not determine the vector bounds"));
1401 
1402  eltype = check_typedef (TYPE_TARGET_TYPE (vector_type));
1403  elval = value_cast (eltype, scalar_value);
1404 
1405  scalar_type = check_typedef (value_type (scalar_value));
1406 
1407  /* If we reduced the length of the scalar then check we didn't loose any
1408  important bits. */
1409  if (TYPE_LENGTH (eltype) < TYPE_LENGTH (scalar_type)
1410  && !value_equal (elval, scalar_value))
1411  error (_("conversion of scalar to vector involves truncation"));
1412 
1413  val = allocate_value (vector_type);
1414  for (i = 0; i < high_bound - low_bound + 1; i++)
1415  /* Duplicate the contents of elval into the destination vector. */
1416  memcpy (value_contents_writeable (val) + (i * TYPE_LENGTH (eltype)),
1417  value_contents_all (elval), TYPE_LENGTH (eltype));
1418 
1419  return val;
1420 }
1421 
1422 /* Performs a binary operation on two vector operands by calling scalar_binop
1423  for each pair of vector components. */
1424 
1425 static struct value *
1426 vector_binop (struct value *val1, struct value *val2, enum exp_opcode op)
1427 {
1428  struct value *val, *tmp, *mark;
1429  struct type *type1, *type2, *eltype1, *eltype2;
1430  int t1_is_vec, t2_is_vec, elsize, i;
1431  LONGEST low_bound1, high_bound1, low_bound2, high_bound2;
1432 
1433  type1 = check_typedef (value_type (val1));
1434  type2 = check_typedef (value_type (val2));
1435 
1436  t1_is_vec = (TYPE_CODE (type1) == TYPE_CODE_ARRAY
1437  && TYPE_VECTOR (type1)) ? 1 : 0;
1438  t2_is_vec = (TYPE_CODE (type2) == TYPE_CODE_ARRAY
1439  && TYPE_VECTOR (type2)) ? 1 : 0;
1440 
1441  if (!t1_is_vec || !t2_is_vec)
1442  error (_("Vector operations are only supported among vectors"));
1443 
1444  if (!get_array_bounds (type1, &low_bound1, &high_bound1)
1445  || !get_array_bounds (type2, &low_bound2, &high_bound2))
1446  error (_("Could not determine the vector bounds"));
1447 
1448  eltype1 = check_typedef (TYPE_TARGET_TYPE (type1));
1449  eltype2 = check_typedef (TYPE_TARGET_TYPE (type2));
1450  elsize = TYPE_LENGTH (eltype1);
1451 
1452  if (TYPE_CODE (eltype1) != TYPE_CODE (eltype2)
1453  || elsize != TYPE_LENGTH (eltype2)
1454  || TYPE_UNSIGNED (eltype1) != TYPE_UNSIGNED (eltype2)
1455  || low_bound1 != low_bound2 || high_bound1 != high_bound2)
1456  error (_("Cannot perform operation on vectors with different types"));
1457 
1458  val = allocate_value (type1);
1459  mark = value_mark ();
1460  for (i = 0; i < high_bound1 - low_bound1 + 1; i++)
1461  {
1462  tmp = value_binop (value_subscript (val1, i),
1463  value_subscript (val2, i), op);
1464  memcpy (value_contents_writeable (val) + i * elsize,
1465  value_contents_all (tmp),
1466  elsize);
1467  }
1468  value_free_to_mark (mark);
1469 
1470  return val;
1471 }
1472 
1473 /* Perform a binary operation on two operands. */
1474 
1475 struct value *
1476 value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
1477 {
1478  struct value *val;
1479  struct type *type1 = check_typedef (value_type (arg1));
1480  struct type *type2 = check_typedef (value_type (arg2));
1481  int t1_is_vec = (TYPE_CODE (type1) == TYPE_CODE_ARRAY
1482  && TYPE_VECTOR (type1));
1483  int t2_is_vec = (TYPE_CODE (type2) == TYPE_CODE_ARRAY
1484  && TYPE_VECTOR (type2));
1485 
1486  if (!t1_is_vec && !t2_is_vec)
1487  val = scalar_binop (arg1, arg2, op);
1488  else if (t1_is_vec && t2_is_vec)
1489  val = vector_binop (arg1, arg2, op);
1490  else
1491  {
1492  /* Widen the scalar operand to a vector. */
1493  struct value **v = t1_is_vec ? &arg2 : &arg1;
1494  struct type *t = t1_is_vec ? type2 : type1;
1495 
1496  if (TYPE_CODE (t) != TYPE_CODE_FLT
1497  && TYPE_CODE (t) != TYPE_CODE_DECFLOAT
1498  && !is_integral_type (t))
1499  error (_("Argument to operation not a number or boolean."));
1500 
1501  /* Replicate the scalar value to make a vector value. */
1502  *v = value_vector_widen (*v, t1_is_vec ? type1 : type2);
1503 
1504  val = vector_binop (arg1, arg2, op);
1505  }
1506 
1507  return val;
1508 }
1509 
1510 /* Simulate the C operator ! -- return 1 if ARG1 contains zero. */
1511 
1512 int
1513 value_logical_not (struct value *arg1)
1514 {
1515  int len;
1516  const gdb_byte *p;
1517  struct type *type1;
1518 
1519  arg1 = coerce_array (arg1);
1520  type1 = check_typedef (value_type (arg1));
1521 
1522  if (TYPE_CODE (type1) == TYPE_CODE_FLT)
1523  return 0 == value_as_double (arg1);
1524  else if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT)
1525  return decimal_is_zero (value_contents (arg1), TYPE_LENGTH (type1),
1526  gdbarch_byte_order (get_type_arch (type1)));
1527 
1528  len = TYPE_LENGTH (type1);
1529  p = value_contents (arg1);
1530 
1531  while (--len >= 0)
1532  {
1533  if (*p++)
1534  break;
1535  }
1536 
1537  return len < 0;
1538 }
1539 
1540 /* Perform a comparison on two string values (whose content are not
1541  necessarily null terminated) based on their length. */
1542 
1543 static int
1544 value_strcmp (struct value *arg1, struct value *arg2)
1545 {
1546  int len1 = TYPE_LENGTH (value_type (arg1));
1547  int len2 = TYPE_LENGTH (value_type (arg2));
1548  const gdb_byte *s1 = value_contents (arg1);
1549  const gdb_byte *s2 = value_contents (arg2);
1550  int i, len = len1 < len2 ? len1 : len2;
1551 
1552  for (i = 0; i < len; i++)
1553  {
1554  if (s1[i] < s2[i])
1555  return -1;
1556  else if (s1[i] > s2[i])
1557  return 1;
1558  else
1559  continue;
1560  }
1561 
1562  if (len1 < len2)
1563  return -1;
1564  else if (len1 > len2)
1565  return 1;
1566  else
1567  return 0;
1568 }
1569 
1570 /* Simulate the C operator == by returning a 1
1571  iff ARG1 and ARG2 have equal contents. */
1572 
1573 int
1574 value_equal (struct value *arg1, struct value *arg2)
1575 {
1576  int len;
1577  const gdb_byte *p1;
1578  const gdb_byte *p2;
1579  struct type *type1, *type2;
1580  enum type_code code1;
1581  enum type_code code2;
1582  int is_int1, is_int2;
1583 
1584  arg1 = coerce_array (arg1);
1585  arg2 = coerce_array (arg2);
1586 
1587  type1 = check_typedef (value_type (arg1));
1588  type2 = check_typedef (value_type (arg2));
1589  code1 = TYPE_CODE (type1);
1590  code2 = TYPE_CODE (type2);
1591  is_int1 = is_integral_type (type1);
1592  is_int2 = is_integral_type (type2);
1593 
1594  if (is_int1 && is_int2)
1595  return longest_to_int (value_as_long (value_binop (arg1, arg2,
1596  BINOP_EQUAL)));
1597  else if ((code1 == TYPE_CODE_FLT || is_int1)
1598  && (code2 == TYPE_CODE_FLT || is_int2))
1599  {
1600  /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1601  `long double' values are returned in static storage (m68k). */
1602  DOUBLEST d = value_as_double (arg1);
1603 
1604  return d == value_as_double (arg2);
1605  }
1606  else if ((code1 == TYPE_CODE_DECFLOAT || is_int1)
1607  && (code2 == TYPE_CODE_DECFLOAT || is_int2))
1608  {
1609  gdb_byte v1[16], v2[16];
1610  int len_v1, len_v2;
1611  enum bfd_endian byte_order_v1, byte_order_v2;
1612 
1613  value_args_as_decimal (arg1, arg2, v1, &len_v1, &byte_order_v1,
1614  v2, &len_v2, &byte_order_v2);
1615 
1616  return decimal_compare (v1, len_v1, byte_order_v1,
1617  v2, len_v2, byte_order_v2) == 0;
1618  }
1619 
1620  /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1621  is bigger. */
1622  else if (code1 == TYPE_CODE_PTR && is_int2)
1623  return value_as_address (arg1) == (CORE_ADDR) value_as_long (arg2);
1624  else if (code2 == TYPE_CODE_PTR && is_int1)
1625  return (CORE_ADDR) value_as_long (arg1) == value_as_address (arg2);
1626 
1627  else if (code1 == code2
1628  && ((len = (int) TYPE_LENGTH (type1))
1629  == (int) TYPE_LENGTH (type2)))
1630  {
1631  p1 = value_contents (arg1);
1632  p2 = value_contents (arg2);
1633  while (--len >= 0)
1634  {
1635  if (*p1++ != *p2++)
1636  break;
1637  }
1638  return len < 0;
1639  }
1640  else if (code1 == TYPE_CODE_STRING && code2 == TYPE_CODE_STRING)
1641  {
1642  return value_strcmp (arg1, arg2) == 0;
1643  }
1644  else
1645  {
1646  error (_("Invalid type combination in equality test."));
1647  return 0; /* For lint -- never reached. */
1648  }
1649 }
1650 
1651 /* Compare values based on their raw contents. Useful for arrays since
1652  value_equal coerces them to pointers, thus comparing just the address
1653  of the array instead of its contents. */
1654 
1655 int
1656 value_equal_contents (struct value *arg1, struct value *arg2)
1657 {
1658  struct type *type1, *type2;
1659 
1660  type1 = check_typedef (value_type (arg1));
1661  type2 = check_typedef (value_type (arg2));
1662 
1663  return (TYPE_CODE (type1) == TYPE_CODE (type2)
1664  && TYPE_LENGTH (type1) == TYPE_LENGTH (type2)
1665  && memcmp (value_contents (arg1), value_contents (arg2),
1666  TYPE_LENGTH (type1)) == 0);
1667 }
1668 
1669 /* Simulate the C operator < by returning 1
1670  iff ARG1's contents are less than ARG2's. */
1671 
1672 int
1673 value_less (struct value *arg1, struct value *arg2)
1674 {
1675  enum type_code code1;
1676  enum type_code code2;
1677  struct type *type1, *type2;
1678  int is_int1, is_int2;
1679 
1680  arg1 = coerce_array (arg1);
1681  arg2 = coerce_array (arg2);
1682 
1683  type1 = check_typedef (value_type (arg1));
1684  type2 = check_typedef (value_type (arg2));
1685  code1 = TYPE_CODE (type1);
1686  code2 = TYPE_CODE (type2);
1687  is_int1 = is_integral_type (type1);
1688  is_int2 = is_integral_type (type2);
1689 
1690  if (is_int1 && is_int2)
1691  return longest_to_int (value_as_long (value_binop (arg1, arg2,
1692  BINOP_LESS)));
1693  else if ((code1 == TYPE_CODE_FLT || is_int1)
1694  && (code2 == TYPE_CODE_FLT || is_int2))
1695  {
1696  /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
1697  `long double' values are returned in static storage (m68k). */
1698  DOUBLEST d = value_as_double (arg1);
1699 
1700  return d < value_as_double (arg2);
1701  }
1702  else if ((code1 == TYPE_CODE_DECFLOAT || is_int1)
1703  && (code2 == TYPE_CODE_DECFLOAT || is_int2))
1704  {
1705  gdb_byte v1[16], v2[16];
1706  int len_v1, len_v2;
1707  enum bfd_endian byte_order_v1, byte_order_v2;
1708 
1709  value_args_as_decimal (arg1, arg2, v1, &len_v1, &byte_order_v1,
1710  v2, &len_v2, &byte_order_v2);
1711 
1712  return decimal_compare (v1, len_v1, byte_order_v1,
1713  v2, len_v2, byte_order_v2) == -1;
1714  }
1715  else if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
1716  return value_as_address (arg1) < value_as_address (arg2);
1717 
1718  /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
1719  is bigger. */
1720  else if (code1 == TYPE_CODE_PTR && is_int2)
1721  return value_as_address (arg1) < (CORE_ADDR) value_as_long (arg2);
1722  else if (code2 == TYPE_CODE_PTR && is_int1)
1723  return (CORE_ADDR) value_as_long (arg1) < value_as_address (arg2);
1724  else if (code1 == TYPE_CODE_STRING && code2 == TYPE_CODE_STRING)
1725  return value_strcmp (arg1, arg2) < 0;
1726  else
1727  {
1728  error (_("Invalid type combination in ordering comparison."));
1729  return 0;
1730  }
1731 }
1732 
1733 /* The unary operators +, - and ~. They free the argument ARG1. */
1734 
1735 struct value *
1736 value_pos (struct value *arg1)
1737 {
1738  struct type *type;
1739 
1740  arg1 = coerce_ref (arg1);
1741  type = check_typedef (value_type (arg1));
1742 
1743  if (TYPE_CODE (type) == TYPE_CODE_FLT)
1744  return value_from_double (type, value_as_double (arg1));
1745  else if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
1746  return value_from_decfloat (type, value_contents (arg1));
1747  else if (is_integral_type (type))
1748  {
1749  return value_from_longest (type, value_as_long (arg1));
1750  }
1751  else if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type))
1752  {
1753  struct value *val = allocate_value (type);
1754 
1755  memcpy (value_contents_raw (val), value_contents (arg1),
1756  TYPE_LENGTH (type));
1757  return val;
1758  }
1759  else
1760  {
1761  error (_("Argument to positive operation not a number."));
1762  return 0; /* For lint -- never reached. */
1763  }
1764 }
1765 
1766 struct value *
1767 value_neg (struct value *arg1)
1768 {
1769  struct type *type;
1770 
1771  arg1 = coerce_ref (arg1);
1772  type = check_typedef (value_type (arg1));
1773 
1774  if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
1775  {
1776  struct value *val = allocate_value (type);
1777  int len = TYPE_LENGTH (type);
1778  gdb_byte decbytes[16]; /* a decfloat is at most 128 bits long. */
1779 
1780  memcpy (decbytes, value_contents (arg1), len);
1781 
1782  if (gdbarch_byte_order (get_type_arch (type)) == BFD_ENDIAN_LITTLE)
1783  decbytes[len-1] = decbytes[len - 1] | 0x80;
1784  else
1785  decbytes[0] = decbytes[0] | 0x80;
1786 
1787  memcpy (value_contents_raw (val), decbytes, len);
1788  return val;
1789  }
1790  else if (TYPE_CODE (type) == TYPE_CODE_FLT)
1791  return value_from_double (type, -value_as_double (arg1));
1792  else if (is_integral_type (type))
1793  {
1794  return value_from_longest (type, -value_as_long (arg1));
1795  }
1796  else if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type))
1797  {
1798  struct value *tmp, *val = allocate_value (type);
1799  struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type));
1800  int i;
1801  LONGEST low_bound, high_bound;
1802 
1803  if (!get_array_bounds (type, &low_bound, &high_bound))
1804  error (_("Could not determine the vector bounds"));
1805 
1806  for (i = 0; i < high_bound - low_bound + 1; i++)
1807  {
1808  tmp = value_neg (value_subscript (arg1, i));
1809  memcpy (value_contents_writeable (val) + i * TYPE_LENGTH (eltype),
1810  value_contents_all (tmp), TYPE_LENGTH (eltype));
1811  }
1812  return val;
1813  }
1814  else
1815  {
1816  error (_("Argument to negate operation not a number."));
1817  return 0; /* For lint -- never reached. */
1818  }
1819 }
1820 
1821 struct value *
1822 value_complement (struct value *arg1)
1823 {
1824  struct type *type;
1825  struct value *val;
1826 
1827  arg1 = coerce_ref (arg1);
1828  type = check_typedef (value_type (arg1));
1829 
1830  if (is_integral_type (type))
1831  val = value_from_longest (type, ~value_as_long (arg1));
1832  else if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type))
1833  {
1834  struct value *tmp;
1835  struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type));
1836  int i;
1837  LONGEST low_bound, high_bound;
1838 
1839  if (!get_array_bounds (type, &low_bound, &high_bound))
1840  error (_("Could not determine the vector bounds"));
1841 
1842  val = allocate_value (type);
1843  for (i = 0; i < high_bound - low_bound + 1; i++)
1844  {
1845  tmp = value_complement (value_subscript (arg1, i));
1846  memcpy (value_contents_writeable (val) + i * TYPE_LENGTH (eltype),
1847  value_contents_all (tmp), TYPE_LENGTH (eltype));
1848  }
1849  }
1850  else
1851  error (_("Argument to complement operation not an integer, boolean."));
1852 
1853  return val;
1854 }
1855 
1856 /* The INDEX'th bit of SET value whose value_type is TYPE,
1857  and whose value_contents is valaddr.
1858  Return -1 if out of range, -2 other error. */
1859 
1860 int
1861 value_bit_index (struct type *type, const gdb_byte *valaddr, int index)
1862 {
1863  struct gdbarch *gdbarch = get_type_arch (type);
1864  LONGEST low_bound, high_bound;
1865  LONGEST word;
1866  unsigned rel_index;
1867  struct type *range = TYPE_INDEX_TYPE (type);
1868 
1869  if (get_discrete_bounds (range, &low_bound, &high_bound) < 0)
1870  return -2;
1871  if (index < low_bound || index > high_bound)
1872  return -1;
1873  rel_index = index - low_bound;
1874  word = extract_unsigned_integer (valaddr + (rel_index / TARGET_CHAR_BIT), 1,
1875  gdbarch_byte_order (gdbarch));
1876  rel_index %= TARGET_CHAR_BIT;
1877  if (gdbarch_bits_big_endian (gdbarch))
1878  rel_index = TARGET_CHAR_BIT - 1 - rel_index;
1879  return (word >> rel_index) & 1;
1880 }
1881 
1882 int
1883 value_in (struct value *element, struct value *set)
1884 {
1885  int member;
1886  struct type *settype = check_typedef (value_type (set));
1887  struct type *eltype = check_typedef (value_type (element));
1888 
1889  if (TYPE_CODE (eltype) == TYPE_CODE_RANGE)
1890  eltype = TYPE_TARGET_TYPE (eltype);
1891  if (TYPE_CODE (settype) != TYPE_CODE_SET)
1892  error (_("Second argument of 'IN' has wrong type"));
1893  if (TYPE_CODE (eltype) != TYPE_CODE_INT
1894  && TYPE_CODE (eltype) != TYPE_CODE_CHAR
1895  && TYPE_CODE (eltype) != TYPE_CODE_ENUM
1896  && TYPE_CODE (eltype) != TYPE_CODE_BOOL)
1897  error (_("First argument of 'IN' has wrong type"));
1898  member = value_bit_index (settype, value_contents (set),
1899  value_as_long (element));
1900  if (member < 0)
1901  error (_("First argument of 'IN' not in range"));
1902  return member;
1903 }
1904 
1905 void
1907 {
1908 }
struct value * value_zero(struct type *type, enum lval_type lv)
Definition: valops.c:842
ULONGEST extract_unsigned_integer(const gdb_byte *, int, enum bfd_endian)
Definition: findvar.c:84
struct value * value_mark(void)
Definition: value.c:1499
type_code
Definition: gdbtypes.h:85
struct value * value_subscripted_rvalue(struct value *array, LONGEST index, int lowerbound)
Definition: valarith.c:191
struct value * call_function_by_hand(struct value *function, int nargs, struct value **args)
Definition: infcall.c:488
static LONGEST integer_pow(LONGEST v1, LONGEST v2)
Definition: valarith.c:800
struct value * value_addr(struct value *arg1)
Definition: valops.c:1472
#define VALUE_FRAME_ID(val)
Definition: value.h:436
void value_free_to_mark(struct value *mark)
Definition: value.c:1551
struct value * value_subscript(struct value *array, LONGEST index)
Definition: valarith.c:146
int value_equal_contents(struct value *arg1, struct value *arg2)
Definition: valarith.c:1656
bfd_vma CORE_ADDR
Definition: common-types.h:41
noside
Definition: expression.h:122
void value_contents_copy(struct value *dst, int dst_offset, struct value *src, int src_offset, int length)
Definition: value.c:1295
void xfree(void *)
Definition: common-utils.c:97
int value_offset(const struct value *value)
Definition: value.c:1032
void store_signed_integer(gdb_byte *, int, enum bfd_endian, LONGEST)
Definition: findvar.c:184
LONGEST value_as_long(struct value *val)
Definition: value.c:2654
void warning(const char *fmt,...)
Definition: errors.c:26
struct value * value_coerce_array(struct value *arg1)
Definition: valops.c:1436
#define TYPE_NAME(thistype)
Definition: gdbtypes.h:1227
LONGEST value_ptrdiff(struct value *arg1, struct value *arg2)
Definition: valarith.c:105
struct value * call_xmethod(struct value *method, int argc, struct value **argv)
Definition: value.c:2639
struct value * allocate_value_lazy(struct type *type)
Definition: value.c:913
int binop_types_user_defined_p(enum exp_opcode op, struct type *type1, struct type *type2)
Definition: valarith.c:228
int value_in(struct value *element, struct value *set)
Definition: valarith.c:1883
struct value * coerce_ref(struct value *arg)
Definition: value.c:3688
static int value_strcmp(struct value *arg1, struct value *arg2)
Definition: valarith.c:1544
struct value * value_ind(struct value *arg1)
Definition: valops.c:1533
enum language la_language
Definition: language.h:152
struct value * value_pos(struct value *arg1)
Definition: valarith.c:1736
#define _(String)
Definition: gdb_locale.h:40
struct value * value_string(char *ptr, ssize_t len, struct type *char_type)
Definition: valops.c:1665
static void value_args_as_decimal(struct value *arg1, struct value *arg2, gdb_byte *x, int *len_x, enum bfd_endian *byte_order_x, gdb_byte *y, int *len_y, enum bfd_endian *byte_order_y)
Definition: valarith.c:861
#define VALUE_LVAL(val)
Definition: value.h:411
struct value * allocate_value(struct type *type)
Definition: value.c:962
void store_unsigned_integer(gdb_byte *, int, enum bfd_endian, ULONGEST)
Definition: findvar.c:212
int longest_to_int(LONGEST)
Definition: valprint.c:1054
Definition: value.h:751
struct value * value_ptradd(struct value *arg1, LONGEST arg2)
Definition: valarith.c:84
const char *const name
Definition: aarch64-tdep.c:68
struct value * value_struct_elt(struct value **argp, struct value **args, const char *name, int *static_memfuncp, const char *err)
Definition: valops.c:2128
struct type * check_typedef(struct type *type)
Definition: gdbtypes.c:2217
struct type * result_type_of_xmethod(struct value *method, int argc, struct value **argv)
Definition: value.c:2627
const gdb_byte * value_contents(struct value *value)
Definition: value.c:1329
static ULONGEST uinteger_pow(ULONGEST v1, LONGEST v2)
Definition: valarith.c:831
struct value * value_from_decfloat(struct type *type, const gdb_byte *dec)
Definition: value.c:3580
int value_lazy(struct value *value)
Definition: value.c:1305
void decimal_binop(enum exp_opcode op, const gdb_byte *x, int len_x, enum bfd_endian byte_order_x, const gdb_byte *y, int len_y, enum bfd_endian byte_order_y, gdb_byte *result, int len_result, enum bfd_endian byte_order_result)
Definition: dfp.c:269
const gdb_byte * value_contents_all(struct value *value)
Definition: value.c:1188
#define TYPE_VECTOR(t)
Definition: gdbtypes.h:287
double DOUBLEST
Definition: doublest.h:24
int is_integral_type(struct type *t)
Definition: gdbtypes.c:2690
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1420
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
Definition: cleanups.c:117
static LONGEST find_size_for_pointer_math(struct type *ptr_type)
Definition: valarith.c:49
#define TARGET_CHAR_BIT
Definition: host-defs.h:29
Definition: gdbtypes.h:749
const char * word
Definition: symtab.h:1448
#define VALUE_REGNUM(val)
Definition: value.h:440
int decimal_is_zero(const gdb_byte *x, int len, enum bfd_endian byte_order)
Definition: dfp.c:320
struct gdbarch * get_type_arch(const struct type *type)
Definition: gdbtypes.c:232
gdb_byte * value_contents_writeable(struct value *value)
Definition: value.c:1338
struct value * coerce_array(struct value *arg)
Definition: value.c:3713
static const char * type
Definition: language.c:103
#define gdb_assert(expr)
Definition: gdb_assert.h:33
struct value * value_from_longest(struct type *type, LONGEST num)
Definition: value.c:3464
void set_value_offset(struct value *value, int offset)
Definition: value.c:1037
struct value * value_cast(struct type *type, struct value *arg2)
Definition: valops.c:351
#define TRUNCATION_TOWARDS_ZERO
Definition: valarith.c:36
Definition: value.c:65
static struct value * value_user_defined_cpp_op(struct value **args, int nargs, char *oper, int *static_memfuncp, enum noside noside)
Definition: valarith.c:287
char c_style_arrays
Definition: language.h:291
#define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype)
Definition: gdbtypes.h:1282
struct value * value_from_double(struct type *type, DOUBLEST num)
Definition: value.c:3563
int value_equal(struct value *arg1, struct value *arg2)
Definition: valarith.c:1574
void * xmalloc(YYSIZE_T)
LONGEST unpack_long(struct type *type, const gdb_byte *valaddr)
Definition: value.c:2797
int value_bit_index(struct type *type, const gdb_byte *valaddr, int index)
Definition: valarith.c:1861
#define TYPE_UNSIGNED(t)
Definition: gdbtypes.h:233
int find_overload_match(struct value **args, int nargs, const char *name, enum oload_search_type method, struct value **objp, struct symbol *fsym, struct value **valp, struct symbol **symp, int *staticp, const int no_adl, const enum noside noside)
Definition: valops.c:2462
Definition: value.c:172
bfd_byte gdb_byte
Definition: common-types.h:38
struct value * value_from_pointer(struct type *type, CORE_ADDR addr)
Definition: value.c:3490
const struct language_defn * current_language
Definition: language.c:85
#define TYPE_TARGET_TYPE(thistype)
Definition: gdbtypes.h:1229
int decimal_compare(const gdb_byte *x, int len_x, enum bfd_endian byte_order_x, const gdb_byte *y, int len_y, enum bfd_endian byte_order_y)
Definition: dfp.c:335
struct value * value_neg(struct value *arg1)
Definition: valarith.c:1767
#define TYPE_CODE(thistype)
Definition: gdbtypes.h:1240
#define TYPE_INDEX_TYPE(type)
Definition: gdbtypes.h:1244
struct value * value_of_variable(struct symbol *var, const struct block *b)
Definition: valops.c:1291
char * safe_strerror(int)
void decimal_from_integral(struct value *from, gdb_byte *to, int len, enum bfd_endian byte_order)
Definition: dfp.c:209
static struct value * vector_binop(struct value *val1, struct value *val2, enum exp_opcode op)
Definition: valarith.c:1426
int value_less(struct value *arg1, struct value *arg2)
Definition: valarith.c:1673
struct value * value_complement(struct value *arg1)
Definition: valarith.c:1822
exp_opcode
Definition: expression.h:43
#define CHECK_TYPEDEF(TYPE)
Definition: gdbtypes.h:1817
int value_logical_not(struct value *arg1)
Definition: valarith.c:1513
struct value * value_vector_widen(struct value *scalar_value, struct type *vector_type)
Definition: valarith.c:1386
struct value * value_binop(struct value *arg1, struct value *arg2, enum exp_opcode op)
Definition: valarith.c:1476
#define TYPE_TAG_NAME(type)
Definition: gdbtypes.h:1228
int binop_user_defined_p(enum exp_opcode op, struct value *arg1, struct value *arg2)
Definition: valarith.c:253
int gdbarch_bits_big_endian(struct gdbarch *gdbarch)
Definition: gdbarch.c:1456
unsigned long long ULONGEST
Definition: common-types.h:53
int value_embedded_offset(struct value *value)
Definition: value.c:1388
struct value * value_x_unop(struct value *arg1, enum exp_opcode op, enum noside noside)
Definition: valarith.c:525
struct type * value_type(const struct value *value)
Definition: value.c:1021
Definition: ia64-tdep.c:84
Definition: symtab.h:703
CORE_ADDR value_as_address(struct value *val)
Definition: value.c:2679
gdb_byte * value_contents_raw(struct value *value)
Definition: value.c:1084
#define TYPE_LENGTH(thistype)
Definition: gdbtypes.h:1237
struct value * value_x_binop(struct value *arg1, struct value *arg2, enum exp_opcode op, enum exp_opcode otherop, enum noside noside)
Definition: valarith.c:345
int unop_user_defined_p(enum exp_opcode op, struct value *arg1)
Definition: valarith.c:266
static struct value * value_user_defined_op(struct value **argp, struct value **args, char *name, int *static_memfuncp, int nargs, enum noside noside)
Definition: valarith.c:318
int get_array_bounds(struct type *type, LONGEST *low_bound, LONGEST *high_bound)
Definition: gdbtypes.c:978
static struct value * scalar_binop(struct value *arg1, struct value *arg2, enum exp_opcode op)
Definition: valarith.c:928
int get_discrete_bounds(struct type *type, LONGEST *lowp, LONGEST *highp)
Definition: gdbtypes.c:899
void error(const char *fmt,...)
Definition: errors.c:38
DOUBLEST value_as_double(struct value *val)
Definition: value.c:2664
void store_typed_floating(void *addr, const struct type *type, DOUBLEST val)
Definition: doublest.c:830
void _initialize_valarith(void)
Definition: valarith.c:1906
void throw_error(enum errors error, const char *fmt,...)
long long LONGEST
Definition: common-types.h:52
struct value * value_concat(struct value *arg1, struct value *arg2)
Definition: valarith.c:657
void do_cleanups(struct cleanup *old_chain)
Definition: cleanups.c:175
void set_value_component_location(struct value *component, const struct value *whole)
Definition: value.c:1761
const ULONGEST const LONGEST len
Definition: target.h:309