GDB (xrefs)
Loading...
Searching...
No Matches
eval.c
Go to the documentation of this file.
1/* Evaluate expressions for GDB.
2
3 Copyright (C) 1986-2023 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 "symtab.h"
22#include "gdbtypes.h"
23#include "value.h"
24#include "expression.h"
25#include "target.h"
26#include "frame.h"
27#include "gdbthread.h"
28#include "language.h"
29#include "cp-abi.h"
30#include "infcall.h"
31#include "objc-lang.h"
32#include "block.h"
33#include "parser-defs.h"
34#include "cp-support.h"
35#include "ui-out.h"
36#include "regcache.h"
37#include "user-regs.h"
38#include "valprint.h"
39#include "gdbsupport/gdb_obstack.h"
40#include "objfiles.h"
41#include "typeprint.h"
42#include <ctype.h>
43#include "expop.h"
44#include "c-exp.h"
45#include "inferior.h"
46
47
48/* Parse the string EXP as a C expression, evaluate it,
49 and return the result as a number. */
50
51CORE_ADDR
52parse_and_eval_address (const char *exp)
53{
55
56 return value_as_address (expr->evaluate ());
57}
58
59/* Like parse_and_eval_address, but treats the value of the expression
60 as an integer, not an address, returns a LONGEST, not a CORE_ADDR. */
61LONGEST
62parse_and_eval_long (const char *exp)
63{
65
66 return value_as_long (expr->evaluate ());
67}
68
69struct value *
70parse_and_eval (const char *exp, parser_flags flags)
71{
72 expression_up expr = parse_expression (exp, nullptr, flags);
73
74 return expr->evaluate ();
75}
76
77/* Parse up to a comma (or to a closeparen)
78 in the string EXPP as an expression, evaluate it, and return the value.
79 EXPP is advanced to point to the comma. */
80
81struct value *
82parse_to_comma_and_eval (const char **expp)
83{
84 expression_up expr = parse_exp_1 (expp, 0, nullptr,
86
87 return expr->evaluate ();
88}
89
90
91/* See expression.h. */
92
93bool
95{
96 gdb_assert (objfile->separate_debug_objfile_backlink == nullptr);
97 return op->uses_objfile (objfile);
98}
99
100/* See expression.h. */
101
102struct value *
103expression::evaluate (struct type *expect_type, enum noside noside)
104{
105 gdb::optional<enable_thread_stack_temporaries> stack_temporaries;
106 if (target_has_execution () && inferior_ptid != null_ptid
109 stack_temporaries.emplace (inferior_thread ());
110
111 struct value *retval = op->evaluate (expect_type, this, noside);
112
113 if (stack_temporaries.has_value ()
115 retval = retval->non_lval ();
116
117 return retval;
118}
119
120/* Find the current value of a watchpoint on EXP. Return the value in
121 *VALP and *RESULTP and the chain of intermediate and final values
122 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
123 not need them.
124
125 If PRESERVE_ERRORS is true, then exceptions are passed through.
126 Otherwise, if PRESERVE_ERRORS is false, then if a memory error
127 occurs while evaluating the expression, *RESULTP will be set to
128 NULL. *RESULTP may be a lazy value, if the result could not be
129 read from memory. It is used to determine whether a value is
130 user-specified (we should watch the whole value) or intermediate
131 (we should watch only the bit used to locate the final value).
132
133 If the final value, or any intermediate value, could not be read
134 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
135 set to any referenced values. *VALP will never be a lazy value.
136 This is the value which we store in struct breakpoint.
137
138 If VAL_CHAIN is non-NULL, the values put into *VAL_CHAIN will be
139 released from the value chain. If VAL_CHAIN is NULL, all generated
140 values will be left on the value chain. */
141
142void
144 expr::operation *op,
145 struct value **valp, struct value **resultp,
146 std::vector<value_ref_ptr> *val_chain,
147 bool preserve_errors)
148{
149 struct value *mark, *new_mark, *result;
150
151 *valp = NULL;
152 if (resultp)
153 *resultp = NULL;
154 if (val_chain)
155 val_chain->clear ();
156
157 /* Evaluate the expression. */
158 mark = value_mark ();
159 result = NULL;
160
161 try
162 {
163 result = op->evaluate (nullptr, exp, EVAL_NORMAL);
164 }
165 catch (const gdb_exception &ex)
166 {
167 /* Ignore memory errors if we want watchpoints pointing at
168 inaccessible memory to still be created; otherwise, throw the
169 error to some higher catcher. */
170 switch (ex.error)
171 {
172 case MEMORY_ERROR:
173 if (!preserve_errors)
174 break;
175 /* Fall through. */
176 default:
177 throw;
178 break;
179 }
180 }
181
182 new_mark = value_mark ();
183 if (mark == new_mark)
184 return;
185 if (resultp)
186 *resultp = result;
187
188 /* Make sure it's not lazy, so that after the target stops again we
189 have a non-lazy previous value to compare with. */
190 if (result != NULL)
191 {
192 if (!result->lazy ())
193 *valp = result;
194 else
195 {
196
197 try
198 {
199 result->fetch_lazy ();
200 *valp = result;
201 }
202 catch (const gdb_exception_error &except)
203 {
204 }
205 }
206 }
207
208 if (val_chain)
209 {
210 /* Return the chain of intermediate values. We use this to
211 decide which addresses to watch. */
212 *val_chain = value_release_to_mark (mark);
213 }
214}
215
216/* Promote value ARG1 as appropriate before performing a unary operation
217 on this argument.
218 If the result is not appropriate for any particular language then it
219 needs to patch this function. */
220
221void
223 struct value **arg1)
224{
225 struct type *type1;
226
227 *arg1 = coerce_ref (*arg1);
228 type1 = check_typedef ((*arg1)->type ());
229
230 if (is_integral_type (type1))
231 {
232 switch (language->la_language)
233 {
234 default:
235 /* Perform integral promotion for ANSI C/C++.
236 If not appropriate for any particular language
237 it needs to modify this function. */
238 {
239 struct type *builtin_int = builtin_type (gdbarch)->builtin_int;
240
241 if (type1->length () < builtin_int->length ())
242 *arg1 = value_cast (builtin_int, *arg1);
243 }
244 break;
245 }
246 }
247}
248
249/* Promote values ARG1 and ARG2 as appropriate before performing a binary
250 operation on those two operands.
251 If the result is not appropriate for any particular language then it
252 needs to patch this function. */
253
254void
256 struct value **arg1, struct value **arg2)
257{
258 struct type *promoted_type = NULL;
259 struct type *type1;
260 struct type *type2;
261
262 *arg1 = coerce_ref (*arg1);
263 *arg2 = coerce_ref (*arg2);
264
265 type1 = check_typedef ((*arg1)->type ());
266 type2 = check_typedef ((*arg2)->type ());
267
268 if ((type1->code () != TYPE_CODE_FLT
269 && type1->code () != TYPE_CODE_DECFLOAT
270 && !is_integral_type (type1))
271 || (type2->code () != TYPE_CODE_FLT
272 && type2->code () != TYPE_CODE_DECFLOAT
273 && !is_integral_type (type2)))
274 return;
275
276 if (is_fixed_point_type (type1) || is_fixed_point_type (type2))
277 return;
278
279 if (type1->code () == TYPE_CODE_DECFLOAT
280 || type2->code () == TYPE_CODE_DECFLOAT)
281 {
282 /* No promotion required. */
283 }
284 else if (type1->code () == TYPE_CODE_FLT
285 || type2->code () == TYPE_CODE_FLT)
286 {
287 switch (language->la_language)
288 {
289 case language_c:
290 case language_cplus:
291 case language_asm:
292 case language_objc:
293 case language_opencl:
294 /* No promotion required. */
295 break;
296
297 default:
298 /* For other languages the result type is unchanged from gdb
299 version 6.7 for backward compatibility.
300 If either arg was long double, make sure that value is also long
301 double. Otherwise use double. */
302 if (type1->length () * 8 > gdbarch_double_bit (gdbarch)
303 || type2->length () * 8 > gdbarch_double_bit (gdbarch))
304 promoted_type = builtin_type (gdbarch)->builtin_long_double;
305 else
306 promoted_type = builtin_type (gdbarch)->builtin_double;
307 break;
308 }
309 }
310 else if (type1->code () == TYPE_CODE_BOOL
311 && type2->code () == TYPE_CODE_BOOL)
312 {
313 /* No promotion required. */
314 }
315 else
316 /* Integral operations here. */
317 /* FIXME: Also mixed integral/booleans, with result an integer. */
318 {
319 const struct builtin_type *builtin = builtin_type (gdbarch);
320 unsigned int promoted_len1 = type1->length ();
321 unsigned int promoted_len2 = type2->length ();
322 int is_unsigned1 = type1->is_unsigned ();
323 int is_unsigned2 = type2->is_unsigned ();
324 unsigned int result_len;
325 int unsigned_operation;
326
327 /* Determine type length and signedness after promotion for
328 both operands. */
329 if (promoted_len1 < builtin->builtin_int->length ())
330 {
331 is_unsigned1 = 0;
332 promoted_len1 = builtin->builtin_int->length ();
333 }
334 if (promoted_len2 < builtin->builtin_int->length ())
335 {
336 is_unsigned2 = 0;
337 promoted_len2 = builtin->builtin_int->length ();
338 }
339
340 if (promoted_len1 > promoted_len2)
341 {
342 unsigned_operation = is_unsigned1;
343 result_len = promoted_len1;
344 }
345 else if (promoted_len2 > promoted_len1)
346 {
347 unsigned_operation = is_unsigned2;
348 result_len = promoted_len2;
349 }
350 else
351 {
352 unsigned_operation = is_unsigned1 || is_unsigned2;
353 result_len = promoted_len1;
354 }
355
356 switch (language->la_language)
357 {
358 case language_opencl:
359 if (result_len
360 <= lookup_signed_typename (language, "int")->length())
361 {
362 promoted_type =
363 (unsigned_operation
366 }
367 else if (result_len
368 <= lookup_signed_typename (language, "long")->length())
369 {
370 promoted_type =
371 (unsigned_operation
374 }
375 break;
376 default:
377 if (result_len <= builtin->builtin_int->length ())
378 {
379 promoted_type = (unsigned_operation
380 ? builtin->builtin_unsigned_int
381 : builtin->builtin_int);
382 }
383 else if (result_len <= builtin->builtin_long->length ())
384 {
385 promoted_type = (unsigned_operation
386 ? builtin->builtin_unsigned_long
387 : builtin->builtin_long);
388 }
389 else if (result_len <= builtin->builtin_long_long->length ())
390 {
391 promoted_type = (unsigned_operation
393 : builtin->builtin_long_long);
394 }
395 else
396 {
397 promoted_type = (unsigned_operation
398 ? builtin->builtin_uint128
399 : builtin->builtin_int128);
400 }
401 break;
402 }
403 }
404
405 if (promoted_type)
406 {
407 /* Promote both operands to common type. */
408 *arg1 = value_cast (promoted_type, *arg1);
409 *arg2 = value_cast (promoted_type, *arg2);
410 }
411}
412
413static int
414ptrmath_type_p (const struct language_defn *lang, struct type *type)
415{
418 type = type->target_type ();
419
420 switch (type->code ())
421 {
422 case TYPE_CODE_PTR:
423 case TYPE_CODE_FUNC:
424 return 1;
425
426 case TYPE_CODE_ARRAY:
427 return type->is_vector () ? 0 : lang->c_style_arrays_p ();
428
429 default:
430 return 0;
431 }
432}
433
434/* Represents a fake method with the given parameter types. This is
435 used by the parser to construct a temporary "expected" type for
436 method overload resolution. FLAGS is used as instance flags of the
437 new type, in order to be able to make the new type represent a
438 const/volatile overload. */
439
441{
442public:
443 fake_method (type_instance_flags flags,
444 int num_types, struct type **param_types);
445 ~fake_method ();
446
447 /* The constructed type. */
448 struct type *type () { return &m_type; }
449
450private:
451 struct type m_type {};
453};
454
455fake_method::fake_method (type_instance_flags flags,
456 int num_types, struct type **param_types)
457{
458 struct type *type = &m_type;
459
461 type->set_length (1);
462 type->set_code (TYPE_CODE_METHOD);
463 TYPE_CHAIN (type) = type;
465 if (num_types > 0)
466 {
467 if (param_types[num_types - 1] == NULL)
468 {
469 --num_types;
470 type->set_has_varargs (true);
471 }
472 else if (check_typedef (param_types[num_types - 1])->code ()
473 == TYPE_CODE_VOID)
474 {
475 --num_types;
476 /* Caller should have ensured this. */
477 gdb_assert (num_types == 0);
478 type->set_is_prototyped (true);
479 }
480 }
481
482 /* We don't use TYPE_ZALLOC here to allocate space as TYPE is owned by
483 neither an objfile nor a gdbarch. As a result we must manually
484 allocate memory for auxiliary fields, and free the memory ourselves
485 when we are done with it. */
486 type->set_num_fields (num_types);
488 ((struct field *) xzalloc (sizeof (struct field) * num_types));
489
490 while (num_types-- > 0)
491 type->field (num_types).set_type (param_types[num_types]);
492}
493
495{
496 xfree (m_type.fields ());
497}
498
499namespace expr
500{
501
502value *
504 struct expression *exp,
505 enum noside noside)
506{
507 type_instance_flags flags = std::get<0> (m_storage);
508 std::vector<type *> &types = std::get<1> (m_storage);
509
510 fake_method fake_expect_type (flags, types.size (), types.data ());
511 return std::get<2> (m_storage)->evaluate (fake_expect_type.type (),
512 exp, noside);
513}
514
515}
516
517/* Helper for evaluating an OP_VAR_VALUE. */
518
519value *
521{
522 /* JYG: We used to just return value::zero of the symbol type if
523 we're asked to avoid side effects. Otherwise we return
524 value_of_variable (...). However I'm not sure if
525 value_of_variable () has any side effect. We need a full value
526 object returned here for whatis_exp () to call evaluate_type ()
527 and then pass the full value to value_rtti_target_type () if we
528 are dealing with a pointer or reference to a base class and print
529 object is on. */
530
531 struct value *ret = NULL;
532
533 try
534 {
535 ret = value_of_variable (var, blk);
536 }
537
538 catch (const gdb_exception_error &except)
539 {
541 throw;
542
543 ret = value::zero (var->type (), not_lval);
544 }
545
546 return ret;
547}
548
549namespace expr
550
551{
552
553value *
555 struct expression *exp,
556 enum noside noside)
557{
558 symbol *var = std::get<0> (m_storage).symbol;
559 if (var->type ()->code () == TYPE_CODE_ERROR)
561 return evaluate_var_value (noside, std::get<0> (m_storage).block, var);
562}
563
564} /* namespace expr */
565
566/* Helper for evaluating an OP_VAR_MSYM_VALUE. */
567
568value *
570 struct objfile *objfile, minimal_symbol *msymbol)
571{
572 CORE_ADDR address;
573 type *the_type = find_minsym_type_and_address (msymbol, objfile, &address);
574
575 if (noside == EVAL_AVOID_SIDE_EFFECTS && !the_type->is_gnu_ifunc ())
576 return value::zero (the_type, not_lval);
577 else
578 return value_at_lazy (the_type, address);
579}
580
581/* See expression.h. */
582
583value *
585 value *callee,
586 gdb::array_view<value *> argvec,
587 const char *function_name,
588 type *default_return_type)
589{
590 if (callee == NULL)
591 error (_("Cannot evaluate function -- may be inlined"));
593 {
594 /* If the return type doesn't look like a function type,
595 call an error. This can happen if somebody tries to turn
596 a variable into a function call. */
597
598 type *ftype = callee->type ();
599
600 if (ftype->code () == TYPE_CODE_INTERNAL_FUNCTION)
601 {
602 /* We don't know anything about what the internal
603 function might return, but we have to return
604 something. */
606 not_lval);
607 }
608 else if (ftype->code () == TYPE_CODE_XMETHOD)
609 {
610 type *return_type = callee->result_type_of_xmethod (argvec);
611
612 if (return_type == NULL)
613 error (_("Xmethod is missing return type."));
614 return value::zero (return_type, not_lval);
615 }
616 else if (ftype->code () == TYPE_CODE_FUNC
617 || ftype->code () == TYPE_CODE_METHOD)
618 {
619 if (ftype->is_gnu_ifunc ())
620 {
621 CORE_ADDR address = callee->address ();
622 type *resolved_type = find_gnu_ifunc_target_type (address);
623
624 if (resolved_type != NULL)
625 ftype = resolved_type;
626 }
627
628 type *return_type = ftype->target_type ();
629
630 if (return_type == NULL)
631 return_type = default_return_type;
632
633 if (return_type == NULL)
634 error_call_unknown_return_type (function_name);
635
636 return value::allocate (return_type);
637 }
638 else
639 error (_("Expression of type other than "
640 "\"Function returning ...\" used as function"));
641 }
642 switch (callee->type ()->code ())
643 {
644 case TYPE_CODE_INTERNAL_FUNCTION:
646 callee, argvec.size (), argvec.data ());
647 case TYPE_CODE_XMETHOD:
648 return callee->call_xmethod (argvec);
649 default:
650 return call_function_by_hand (callee, default_return_type, argvec);
651 }
652}
653
654namespace expr
655{
656
657value *
659 struct expression *exp,
660 enum noside noside,
661 const char *function_name,
662 const std::vector<operation_up> &args)
663{
664 std::vector<value *> vals (args.size ());
665
666 value *callee = evaluate_with_coercion (exp, noside);
667 struct type *type = callee->type ();
668 if (type->code () == TYPE_CODE_PTR)
669 type = type->target_type ();
670 for (int i = 0; i < args.size (); ++i)
671 {
672 if (i < type->num_fields ())
673 vals[i] = args[i]->evaluate (type->field (i).type (), exp, noside);
674 else
675 vals[i] = args[i]->evaluate_with_coercion (exp, noside);
676 }
677
678 return evaluate_subexp_do_call (exp, noside, callee, vals,
679 function_name, expect_type);
680}
681
682value *
684 struct expression *exp,
685 enum noside noside,
686 const std::vector<operation_up> &args)
687{
690 return operation::evaluate_funcall (expect_type, exp, noside, args);
691
692 std::vector<value *> argvec (args.size ());
693 for (int i = 0; i < args.size (); ++i)
694 argvec[i] = args[i]->evaluate_with_coercion (exp, noside);
695
696 struct symbol *symp;
697 find_overload_match (argvec, NULL, NON_METHOD,
698 NULL, std::get<0> (m_storage).symbol,
699 NULL, &symp, NULL, 0, noside);
700
701 if (symp->type ()->code () == TYPE_CODE_ERROR)
703 value *callee = evaluate_var_value (noside, std::get<0> (m_storage).block,
704 symp);
705
706 return evaluate_subexp_do_call (exp, noside, callee, argvec,
707 nullptr, expect_type);
708}
709
710value *
712 struct expression *exp,
713 enum noside noside,
714 const std::vector<operation_up> &args)
715{
718 return operation::evaluate_funcall (expect_type, exp, noside, args);
719
720 /* Unpack it locally so we can properly handle overload
721 resolution. */
722 const std::string &name = std::get<1> (m_storage);
723 struct type *type = std::get<0> (m_storage);
724
725 symbol *function = NULL;
726 const char *function_name = NULL;
727 std::vector<value *> argvec (1 + args.size ());
728 if (type->code () == TYPE_CODE_NAMESPACE)
729 {
730 function = cp_lookup_symbol_namespace (type->name (),
731 name.c_str (),
734 if (function == NULL)
735 error (_("No symbol \"%s\" in namespace \"%s\"."),
736 name.c_str (), type->name ());
737 }
738 else
739 {
740 gdb_assert (type->code () == TYPE_CODE_STRUCT
741 || type->code () == TYPE_CODE_UNION);
742 function_name = name.c_str ();
743
744 /* We need a properly typed value for method lookup. */
745 argvec[0] = value::zero (type, lval_memory);
746 }
747
748 for (int i = 0; i < args.size (); ++i)
749 argvec[i + 1] = args[i]->evaluate_with_coercion (exp, noside);
750 gdb::array_view<value *> arg_view = argvec;
751
752 value *callee = nullptr;
753 if (function_name != nullptr)
754 {
755 int static_memfuncp;
756
757 find_overload_match (arg_view, function_name, METHOD,
758 &argvec[0], nullptr, &callee, nullptr,
759 &static_memfuncp, 0, noside);
760 if (!static_memfuncp)
761 {
762 /* For the time being, we don't handle this. */
763 error (_("Call to overloaded function %s requires "
764 "`this' pointer"),
765 function_name);
766 }
767
768 arg_view = arg_view.slice (1);
769 }
770 else
771 {
772 symbol *symp;
773 arg_view = arg_view.slice (1);
774 find_overload_match (arg_view, nullptr,
775 NON_METHOD, nullptr, function,
776 nullptr, &symp, nullptr, 1, noside);
777 callee = value_of_variable (symp, get_selected_block (0));
778 }
779
780 return evaluate_subexp_do_call (exp, noside, callee, arg_view,
781 nullptr, expect_type);
782}
783
784value *
786 struct expression *exp,
787 enum noside noside,
788 const std::vector<operation_up> &args)
789{
790 /* First, evaluate the structure into lhs. */
791 value *lhs;
792 if (opcode () == STRUCTOP_MEMBER)
793 lhs = std::get<0> (m_storage)->evaluate_for_address (exp, noside);
794 else
795 lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
796
797 std::vector<value *> vals (args.size () + 1);
798 gdb::array_view<value *> val_view = vals;
799 /* If the function is a virtual function, then the aggregate
800 value (providing the structure) plays its part by providing
801 the vtable. Otherwise, it is just along for the ride: call
802 the function directly. */
803 value *rhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
804 value *callee;
805
806 type *a1_type = check_typedef (rhs->type ());
807 if (a1_type->code () == TYPE_CODE_METHODPTR)
808 {
810 callee = value::zero (a1_type->target_type (), not_lval);
811 else
812 callee = cplus_method_ptr_to_value (&lhs, rhs);
813
814 vals[0] = lhs;
815 }
816 else if (a1_type->code () == TYPE_CODE_MEMBERPTR)
817 {
818 struct type *type_ptr
820 struct type *target_type_ptr
821 = lookup_pointer_type (a1_type->target_type ());
822
823 /* Now, convert this value to an address. */
824 lhs = value_cast (type_ptr, lhs);
825
826 long mem_offset = value_as_long (rhs);
827
828 callee = value_from_pointer (target_type_ptr,
829 value_as_long (lhs) + mem_offset);
830 callee = value_ind (callee);
831
832 val_view = val_view.slice (1);
833 }
834 else
835 error (_("Non-pointer-to-member value used in pointer-to-member "
836 "construct"));
837
838 for (int i = 0; i < args.size (); ++i)
839 vals[i + 1] = args[i]->evaluate_with_coercion (exp, noside);
840
841 return evaluate_subexp_do_call (exp, noside, callee, val_view,
842 nullptr, expect_type);
843
844}
845
846value *
848 (struct type *expect_type, struct expression *exp, enum noside noside,
849 const std::vector<operation_up> &args)
850{
851 /* Allocate space for the function call arguments, Including space for a
852 `this' pointer at the start. */
853 std::vector<value *> vals (args.size () + 1);
854 /* First, evaluate the structure into vals[0]. */
855 enum exp_opcode op = opcode ();
856 if (op == STRUCTOP_STRUCT)
857 {
858 /* If v is a variable in a register, and the user types
859 v.method (), this will produce an error, because v has no
860 address.
861
862 A possible way around this would be to allocate a copy of
863 the variable on the stack, copy in the contents, call the
864 function, and copy out the contents. I.e. convert this
865 from call by reference to call by copy-return (or
866 whatever it's called). However, this does not work
867 because it is not the same: the method being called could
868 stash a copy of the address, and then future uses through
869 that address (after the method returns) would be expected
870 to use the variable itself, not some copy of it. */
871 vals[0] = std::get<0> (m_storage)->evaluate_for_address (exp, noside);
872 }
873 else
874 {
875 vals[0] = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
876 /* Check to see if the operator '->' has been overloaded.
877 If the operator has been overloaded replace vals[0] with the
878 value returned by the custom operator and continue
879 evaluation. */
880 while (unop_user_defined_p (op, vals[0]))
881 {
882 struct value *value = nullptr;
883 try
884 {
885 value = value_x_unop (vals[0], op, noside);
886 }
887 catch (const gdb_exception_error &except)
888 {
889 if (except.error == NOT_FOUND_ERROR)
890 break;
891 else
892 throw;
893 }
894
895 vals[0] = value;
896 }
897 }
898
899 /* Evaluate the arguments. The '+ 1' here is to allow for the `this'
900 pointer we placed into vals[0]. */
901 for (int i = 0; i < args.size (); ++i)
902 vals[i + 1] = args[i]->evaluate_with_coercion (exp, noside);
903
904 /* The array view includes the `this' pointer. */
905 gdb::array_view<value *> arg_view (vals);
906
907 int static_memfuncp;
908 value *callee;
909 const char *tstr = std::get<1> (m_storage).c_str ();
912 {
913 /* Language is C++, do some overload resolution before
914 evaluation. */
915 value *val0 = vals[0];
916 find_overload_match (arg_view, tstr, METHOD,
917 &val0, nullptr, &callee, nullptr,
918 &static_memfuncp, 0, noside);
919 vals[0] = val0;
920 }
921 else
922 /* Non-C++ case -- or no overload resolution. */
923 {
924 struct value *temp = vals[0];
925
926 callee = value_struct_elt (&temp, arg_view, tstr,
927 &static_memfuncp,
928 op == STRUCTOP_STRUCT
929 ? "structure" : "structure pointer");
930 /* value_struct_elt updates temp with the correct value of the
931 ``this'' pointer if necessary, so modify it to reflect any
932 ``this'' changes. */
933 vals[0] = value_from_longest (lookup_pointer_type (temp->type ()),
934 temp->address ()
935 + temp->embedded_offset ());
936 }
937
938 /* Take out `this' if needed. */
939 if (static_memfuncp)
940 arg_view = arg_view.slice (1);
941
942 return evaluate_subexp_do_call (exp, noside, callee, arg_view,
943 nullptr, expect_type);
944}
945
946/* Helper for structop_base_operation::complete which recursively adds
947 field and method names from TYPE, a struct or union type, to the
948 OUTPUT list. PREFIX is prepended to each result. */
949
950static void
952 const char *fieldname, int namelen, const char *prefix)
953{
954 int i;
955 int computed_type_name = 0;
956 const char *type_name = NULL;
957
959 for (i = 0; i < type->num_fields (); ++i)
960 {
961 if (i < TYPE_N_BASECLASSES (type))
963 output, fieldname, namelen, prefix);
964 else if (type->field (i).name ())
965 {
966 if (type->field (i).name ()[0] != '\0')
967 {
968 if (! strncmp (type->field (i).name (),
969 fieldname, namelen))
970 output.emplace_back (concat (prefix, type->field (i).name (),
971 nullptr));
972 }
973 else if (type->field (i).type ()->code () == TYPE_CODE_UNION)
974 {
975 /* Recurse into anonymous unions. */
977 output, fieldname, namelen, prefix);
978 }
979 }
980 }
981
982 for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
983 {
984 const char *name = TYPE_FN_FIELDLIST_NAME (type, i);
985
986 if (name && ! strncmp (name, fieldname, namelen))
987 {
988 if (!computed_type_name)
989 {
990 type_name = type->name ();
991 computed_type_name = 1;
992 }
993 /* Omit constructors from the completion list. */
994 if (!type_name || strcmp (type_name, name))
995 output.emplace_back (concat (prefix, name, nullptr));
996 }
997 }
998}
999
1000/* See expop.h. */
1001
1002bool
1004 completion_tracker &tracker,
1005 const char *prefix)
1006{
1007 const std::string &fieldname = std::get<1> (m_storage);
1008
1009 value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp,
1011 struct type *type = lhs->type ();
1012 for (;;)
1013 {
1016 break;
1017 type = type->target_type ();
1018 }
1019
1020 if (type->code () == TYPE_CODE_UNION
1021 || type->code () == TYPE_CODE_STRUCT)
1022 {
1023 completion_list result;
1024
1025 add_struct_fields (type, result, fieldname.c_str (),
1026 fieldname.length (), prefix);
1027 tracker.add_completions (std::move (result));
1028 return true;
1029 }
1030
1031 return false;
1032}
1033
1034} /* namespace expr */
1035
1036/* Return true if type is integral or reference to integral */
1037
1038static bool
1040{
1041 if (is_integral_type (type))
1042 return true;
1043
1045 return (type != nullptr
1048}
1049
1050/* Helper function that implements the body of OP_SCOPE. */
1051
1052struct value *
1053eval_op_scope (struct type *expect_type, struct expression *exp,
1054 enum noside noside,
1055 struct type *type, const char *string)
1056{
1057 struct value *arg1 = value_aggregate_elt (type, string, expect_type,
1058 0, noside);
1059 if (arg1 == NULL)
1060 error (_("There is no field named %s"), string);
1061 return arg1;
1062}
1063
1064/* Helper function that implements the body of OP_VAR_ENTRY_VALUE. */
1065
1066struct value *
1067eval_op_var_entry_value (struct type *expect_type, struct expression *exp,
1068 enum noside noside, symbol *sym)
1069{
1071 return value::zero (sym->type (), not_lval);
1072
1073 if (SYMBOL_COMPUTED_OPS (sym) == NULL
1074 || SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry == NULL)
1075 error (_("Symbol \"%s\" does not have any specific entry value"),
1076 sym->print_name ());
1077
1078 frame_info_ptr frame = get_selected_frame (NULL);
1079 return SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry (sym, frame);
1080}
1081
1082/* Helper function that implements the body of OP_VAR_MSYM_VALUE. */
1083
1084struct value *
1085eval_op_var_msym_value (struct type *expect_type, struct expression *exp,
1086 enum noside noside, bool outermost_p,
1087 bound_minimal_symbol msymbol)
1088{
1090 msymbol.minsym);
1091
1092 struct type *type = val->type ();
1093 if (type->code () == TYPE_CODE_ERROR
1094 && (noside != EVAL_AVOID_SIDE_EFFECTS || !outermost_p))
1095 error_unknown_type (msymbol.minsym->print_name ());
1096 return val;
1097}
1098
1099/* Helper function that implements the body of OP_FUNC_STATIC_VAR. */
1100
1101struct value *
1102eval_op_func_static_var (struct type *expect_type, struct expression *exp,
1103 enum noside noside,
1104 value *func, const char *var)
1105{
1106 CORE_ADDR addr = func->address ();
1107 const block *blk = block_for_pc (addr);
1108 struct block_symbol sym = lookup_symbol (var, blk, VAR_DOMAIN, NULL);
1109 if (sym.symbol == NULL)
1110 error (_("No symbol \"%s\" in specified context."), var);
1111 return evaluate_var_value (noside, sym.block, sym.symbol);
1112}
1113
1114/* Helper function that implements the body of OP_REGISTER. */
1115
1116struct value *
1117eval_op_register (struct type *expect_type, struct expression *exp,
1118 enum noside noside, const char *name)
1119{
1120 int regno;
1121 struct value *val;
1122
1124 name, strlen (name));
1125 if (regno == -1)
1126 error (_("Register $%s not available."), name);
1127
1128 /* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
1129 a value with the appropriate register type. Unfortunately,
1130 we don't have easy access to the type of user registers.
1131 So for these registers, we fetch the register value regardless
1132 of the evaluation mode. */
1134 && regno < gdbarch_num_cooked_regs (exp->gdbarch))
1135 val = value::zero (register_type (exp->gdbarch, regno), not_lval);
1136 else
1137 val = value_of_register (regno, get_selected_frame (NULL));
1138 if (val == NULL)
1139 error (_("Value of register %s not available."), name);
1140 else
1141 return val;
1142}
1143
1144namespace expr
1145{
1146
1147value *
1149 struct expression *exp,
1150 enum noside noside)
1151{
1152 const std::string &str = std::get<0> (m_storage);
1154 exp->gdbarch);
1155 return value_string (str.c_str (), str.size (), type);
1156}
1157
1158struct value *
1160 struct expression *exp,
1161 enum noside noside)
1162{
1163 struct value *array
1164 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
1165 struct value *low
1166 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
1167 struct value *upper
1168 = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
1169
1170 int lowbound = value_as_long (low);
1171 int upperbound = value_as_long (upper);
1172 return value_slice (array, lowbound, upperbound - lowbound + 1);
1173}
1174
1175} /* namespace expr */
1176
1177/* Helper function that implements the body of OP_OBJC_SELECTOR. */
1178
1179struct value *
1180eval_op_objc_selector (struct type *expect_type, struct expression *exp,
1181 enum noside noside,
1182 const char *sel)
1183{
1184 struct type *selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr;
1185 return value_from_longest (selector_type,
1186 lookup_child_selector (exp->gdbarch, sel));
1187}
1188
1189/* A helper function for STRUCTOP_STRUCT. */
1190
1191struct value *
1192eval_op_structop_struct (struct type *expect_type, struct expression *exp,
1193 enum noside noside,
1194 struct value *arg1, const char *string)
1195{
1196 struct value *arg3 = value_struct_elt (&arg1, {}, string,
1197 NULL, "structure");
1199 arg3 = value::zero (arg3->type (), arg3->lval ());
1200 return arg3;
1201}
1202
1203/* A helper function for STRUCTOP_PTR. */
1204
1205struct value *
1206eval_op_structop_ptr (struct type *expect_type, struct expression *exp,
1207 enum noside noside,
1208 struct value *arg1, const char *string)
1209{
1210 /* Check to see if operator '->' has been overloaded. If so replace
1211 arg1 with the value returned by evaluating operator->(). */
1212 while (unop_user_defined_p (STRUCTOP_PTR, arg1))
1213 {
1214 struct value *value = NULL;
1215 try
1216 {
1217 value = value_x_unop (arg1, STRUCTOP_PTR, noside);
1218 }
1219
1220 catch (const gdb_exception_error &except)
1221 {
1222 if (except.error == NOT_FOUND_ERROR)
1223 break;
1224 else
1225 throw;
1226 }
1227
1228 arg1 = value;
1229 }
1230
1231 /* JYG: if print object is on we need to replace the base type
1232 with rtti type in order to continue on with successful
1233 lookup of member / method only available in the rtti type. */
1234 {
1235 struct type *arg_type = arg1->type ();
1236 struct type *real_type;
1237 int full, using_enc;
1238 LONGEST top;
1239 struct value_print_options opts;
1240
1241 get_user_print_options (&opts);
1242 if (opts.objectprint && arg_type->target_type ()
1243 && (arg_type->target_type ()->code () == TYPE_CODE_STRUCT))
1244 {
1245 real_type = value_rtti_indirect_type (arg1, &full, &top,
1246 &using_enc);
1247 if (real_type)
1248 arg1 = value_cast (real_type, arg1);
1249 }
1250 }
1251
1252 struct value *arg3 = value_struct_elt (&arg1, {}, string,
1253 NULL, "structure pointer");
1255 arg3 = value::zero (arg3->type (), arg3->lval ());
1256 return arg3;
1257}
1258
1259/* A helper function for STRUCTOP_MEMBER. */
1260
1261struct value *
1262eval_op_member (struct type *expect_type, struct expression *exp,
1263 enum noside noside,
1264 struct value *arg1, struct value *arg2)
1265{
1266 long mem_offset;
1267
1268 struct value *arg3;
1269 struct type *type = check_typedef (arg2->type ());
1270 switch (type->code ())
1271 {
1272 case TYPE_CODE_METHODPTR:
1274 return value::zero (type->target_type (), not_lval);
1275 else
1276 {
1277 arg2 = cplus_method_ptr_to_value (&arg1, arg2);
1278 gdb_assert (arg2->type ()->code () == TYPE_CODE_PTR);
1279 return value_ind (arg2);
1280 }
1281
1282 case TYPE_CODE_MEMBERPTR:
1283 /* Now, convert these values to an address. */
1284 if (check_typedef (arg1->type ())->code () != TYPE_CODE_PTR)
1285 arg1 = value_addr (arg1);
1287 arg1, 1);
1288
1289 mem_offset = value_as_long (arg2);
1290
1292 value_as_long (arg1) + mem_offset);
1293 return value_ind (arg3);
1294
1295 default:
1296 error (_("non-pointer-to-member value used "
1297 "in pointer-to-member construct"));
1298 }
1299}
1300
1301/* A helper function for BINOP_ADD. */
1302
1303struct value *
1304eval_op_add (struct type *expect_type, struct expression *exp,
1305 enum noside noside,
1306 struct value *arg1, struct value *arg2)
1307{
1308 if (binop_user_defined_p (BINOP_ADD, arg1, arg2))
1309 return value_x_binop (arg1, arg2, BINOP_ADD, OP_NULL, noside);
1310 else if (ptrmath_type_p (exp->language_defn, arg1->type ())
1312 return value_ptradd (arg1, value_as_long (arg2));
1313 else if (ptrmath_type_p (exp->language_defn, arg2->type ())
1315 return value_ptradd (arg2, value_as_long (arg1));
1316 else
1317 {
1318 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
1319 return value_binop (arg1, arg2, BINOP_ADD);
1320 }
1321}
1322
1323/* A helper function for BINOP_SUB. */
1324
1325struct value *
1326eval_op_sub (struct type *expect_type, struct expression *exp,
1327 enum noside noside,
1328 struct value *arg1, struct value *arg2)
1329{
1330 if (binop_user_defined_p (BINOP_SUB, arg1, arg2))
1331 return value_x_binop (arg1, arg2, BINOP_SUB, OP_NULL, noside);
1332 else if (ptrmath_type_p (exp->language_defn, arg1->type ())
1333 && ptrmath_type_p (exp->language_defn, arg2->type ()))
1334 {
1335 /* FIXME -- should be ptrdiff_t */
1336 struct type *type = builtin_type (exp->gdbarch)->builtin_long;
1337 return value_from_longest (type, value_ptrdiff (arg1, arg2));
1338 }
1339 else if (ptrmath_type_p (exp->language_defn, arg1->type ())
1341 return value_ptradd (arg1, - value_as_long (arg2));
1342 else
1343 {
1344 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
1345 return value_binop (arg1, arg2, BINOP_SUB);
1346 }
1347}
1348
1349/* Helper function for several different binary operations. */
1350
1351struct value *
1352eval_op_binary (struct type *expect_type, struct expression *exp,
1353 enum noside noside, enum exp_opcode op,
1354 struct value *arg1, struct value *arg2)
1355{
1356 if (binop_user_defined_p (op, arg1, arg2))
1357 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1358 else
1359 {
1360 /* If EVAL_AVOID_SIDE_EFFECTS and we're dividing by zero,
1361 fudge arg2 to avoid division-by-zero, the caller is
1362 (theoretically) only looking for the type of the result. */
1364 /* ??? Do we really want to test for BINOP_MOD here?
1365 The implementation of value_binop gives it a well-defined
1366 value. */
1367 && (op == BINOP_DIV
1368 || op == BINOP_INTDIV
1369 || op == BINOP_REM
1370 || op == BINOP_MOD)
1371 && value_logical_not (arg2))
1372 {
1373 struct value *v_one;
1374
1375 v_one = value_one (arg2->type ());
1376 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &v_one);
1377 return value_binop (arg1, v_one, op);
1378 }
1379 else
1380 {
1381 /* For shift and integer exponentiation operations,
1382 only promote the first argument. */
1383 if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP)
1384 && is_integral_type (arg2->type ()))
1385 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
1386 else
1387 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
1388
1389 return value_binop (arg1, arg2, op);
1390 }
1391 }
1392}
1393
1394/* A helper function for BINOP_SUBSCRIPT. */
1395
1396struct value *
1397eval_op_subscript (struct type *expect_type, struct expression *exp,
1398 enum noside noside, enum exp_opcode op,
1399 struct value *arg1, struct value *arg2)
1400{
1401 if (binop_user_defined_p (op, arg1, arg2))
1402 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1403 else
1404 {
1405 /* If the user attempts to subscript something that is not an
1406 array or pointer type (like a plain int variable for example),
1407 then report this as an error. */
1408
1409 arg1 = coerce_ref (arg1);
1410 struct type *type = check_typedef (arg1->type ());
1411 if (type->code () != TYPE_CODE_ARRAY
1412 && type->code () != TYPE_CODE_PTR)
1413 {
1414 if (type->name ())
1415 error (_("cannot subscript something of type `%s'"),
1416 type->name ());
1417 else
1418 error (_("cannot subscript requested type"));
1419 }
1420
1422 return value::zero (type->target_type (), arg1->lval ());
1423 else
1424 return value_subscript (arg1, value_as_long (arg2));
1425 }
1426}
1427
1428/* A helper function for BINOP_EQUAL. */
1429
1430struct value *
1431eval_op_equal (struct type *expect_type, struct expression *exp,
1432 enum noside noside, enum exp_opcode op,
1433 struct value *arg1, struct value *arg2)
1434{
1435 if (binop_user_defined_p (op, arg1, arg2))
1436 {
1437 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1438 }
1439 else
1440 {
1441 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
1442 int tem = value_equal (arg1, arg2);
1443 struct type *type = language_bool_type (exp->language_defn,
1444 exp->gdbarch);
1445 return value_from_longest (type, (LONGEST) tem);
1446 }
1447}
1448
1449/* A helper function for BINOP_NOTEQUAL. */
1450
1451struct value *
1452eval_op_notequal (struct type *expect_type, struct expression *exp,
1453 enum noside noside, enum exp_opcode op,
1454 struct value *arg1, struct value *arg2)
1455{
1456 if (binop_user_defined_p (op, arg1, arg2))
1457 {
1458 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1459 }
1460 else
1461 {
1462 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
1463 int tem = value_equal (arg1, arg2);
1464 struct type *type = language_bool_type (exp->language_defn,
1465 exp->gdbarch);
1466 return value_from_longest (type, (LONGEST) ! tem);
1467 }
1468}
1469
1470/* A helper function for BINOP_LESS. */
1471
1472struct value *
1473eval_op_less (struct type *expect_type, struct expression *exp,
1474 enum noside noside, enum exp_opcode op,
1475 struct value *arg1, struct value *arg2)
1476{
1477 if (binop_user_defined_p (op, arg1, arg2))
1478 {
1479 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1480 }
1481 else
1482 {
1483 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
1484 int tem = value_less (arg1, arg2);
1485 struct type *type = language_bool_type (exp->language_defn,
1486 exp->gdbarch);
1487 return value_from_longest (type, (LONGEST) tem);
1488 }
1489}
1490
1491/* A helper function for BINOP_GTR. */
1492
1493struct value *
1494eval_op_gtr (struct type *expect_type, struct expression *exp,
1495 enum noside noside, enum exp_opcode op,
1496 struct value *arg1, struct value *arg2)
1497{
1498 if (binop_user_defined_p (op, arg1, arg2))
1499 {
1500 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1501 }
1502 else
1503 {
1504 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
1505 int tem = value_less (arg2, arg1);
1506 struct type *type = language_bool_type (exp->language_defn,
1507 exp->gdbarch);
1508 return value_from_longest (type, (LONGEST) tem);
1509 }
1510}
1511
1512/* A helper function for BINOP_GEQ. */
1513
1514struct value *
1515eval_op_geq (struct type *expect_type, struct expression *exp,
1516 enum noside noside, enum exp_opcode op,
1517 struct value *arg1, struct value *arg2)
1518{
1519 if (binop_user_defined_p (op, arg1, arg2))
1520 {
1521 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1522 }
1523 else
1524 {
1525 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
1526 int tem = value_less (arg2, arg1) || value_equal (arg1, arg2);
1527 struct type *type = language_bool_type (exp->language_defn,
1528 exp->gdbarch);
1529 return value_from_longest (type, (LONGEST) tem);
1530 }
1531}
1532
1533/* A helper function for BINOP_LEQ. */
1534
1535struct value *
1536eval_op_leq (struct type *expect_type, struct expression *exp,
1537 enum noside noside, enum exp_opcode op,
1538 struct value *arg1, struct value *arg2)
1539{
1540 if (binop_user_defined_p (op, arg1, arg2))
1541 {
1542 return value_x_binop (arg1, arg2, op, OP_NULL, noside);
1543 }
1544 else
1545 {
1546 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
1547 int tem = value_less (arg1, arg2) || value_equal (arg1, arg2);
1548 struct type *type = language_bool_type (exp->language_defn,
1549 exp->gdbarch);
1550 return value_from_longest (type, (LONGEST) tem);
1551 }
1552}
1553
1554/* A helper function for BINOP_REPEAT. */
1555
1556struct value *
1557eval_op_repeat (struct type *expect_type, struct expression *exp,
1558 enum noside noside, enum exp_opcode op,
1559 struct value *arg1, struct value *arg2)
1560{
1561 struct type *type = check_typedef (arg2->type ());
1562 if (type->code () != TYPE_CODE_INT
1563 && type->code () != TYPE_CODE_ENUM)
1564 error (_("Non-integral right operand for \"@\" operator."));
1566 {
1567 return allocate_repeat_value (arg1->type (),
1568 longest_to_int (value_as_long (arg2)));
1569 }
1570 else
1571 return value_repeat (arg1, longest_to_int (value_as_long (arg2)));
1572}
1573
1574/* A helper function for UNOP_PLUS. */
1575
1576struct value *
1577eval_op_plus (struct type *expect_type, struct expression *exp,
1578 enum noside noside, enum exp_opcode op,
1579 struct value *arg1)
1580{
1581 if (unop_user_defined_p (op, arg1))
1582 return value_x_unop (arg1, op, noside);
1583 else
1584 {
1585 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
1586 return value_pos (arg1);
1587 }
1588}
1589
1590/* A helper function for UNOP_NEG. */
1591
1592struct value *
1593eval_op_neg (struct type *expect_type, struct expression *exp,
1594 enum noside noside, enum exp_opcode op,
1595 struct value *arg1)
1596{
1597 if (unop_user_defined_p (op, arg1))
1598 return value_x_unop (arg1, op, noside);
1599 else
1600 {
1601 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
1602 return value_neg (arg1);
1603 }
1604}
1605
1606/* A helper function for UNOP_COMPLEMENT. */
1607
1608struct value *
1609eval_op_complement (struct type *expect_type, struct expression *exp,
1610 enum noside noside, enum exp_opcode op,
1611 struct value *arg1)
1612{
1613 if (unop_user_defined_p (UNOP_COMPLEMENT, arg1))
1614 return value_x_unop (arg1, UNOP_COMPLEMENT, noside);
1615 else
1616 {
1617 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
1618 return value_complement (arg1);
1619 }
1620}
1621
1622/* A helper function for UNOP_LOGICAL_NOT. */
1623
1624struct value *
1625eval_op_lognot (struct type *expect_type, struct expression *exp,
1626 enum noside noside, enum exp_opcode op,
1627 struct value *arg1)
1628{
1629 if (unop_user_defined_p (op, arg1))
1630 return value_x_unop (arg1, op, noside);
1631 else
1632 {
1633 struct type *type = language_bool_type (exp->language_defn,
1634 exp->gdbarch);
1635 return value_from_longest (type, (LONGEST) value_logical_not (arg1));
1636 }
1637}
1638
1639/* A helper function for UNOP_IND. */
1640
1641struct value *
1642eval_op_ind (struct type *expect_type, struct expression *exp,
1643 enum noside noside,
1644 struct value *arg1)
1645{
1646 struct type *type = check_typedef (arg1->type ());
1647 if (type->code () == TYPE_CODE_METHODPTR
1648 || type->code () == TYPE_CODE_MEMBERPTR)
1649 error (_("Attempt to dereference pointer "
1650 "to member without an object"));
1651 if (unop_user_defined_p (UNOP_IND, arg1))
1652 return value_x_unop (arg1, UNOP_IND, noside);
1653 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
1654 {
1655 type = check_typedef (arg1->type ());
1656
1657 /* If the type pointed to is dynamic then in order to resolve the
1658 dynamic properties we must actually dereference the pointer.
1659 There is a risk that this dereference will have side-effects
1660 in the inferior, but being able to print accurate type
1661 information seems worth the risk. */
1664 {
1666 /* In C you can dereference an array to get the 1st elt. */
1667 || type->code () == TYPE_CODE_ARRAY)
1668 return value::zero (type->target_type (),
1669 lval_memory);
1670 else if (type->code () == TYPE_CODE_INT)
1671 /* GDB allows dereferencing an int. */
1673 lval_memory);
1674 else
1675 error (_("Attempt to take contents of a non-pointer value."));
1676 }
1677 }
1678
1679 /* Allow * on an integer so we can cast it to whatever we want.
1680 This returns an int, which seems like the most C-like thing to
1681 do. "long long" variables are rare enough that
1682 BUILTIN_TYPE_LONGEST would seem to be a mistake. */
1683 if (type->code () == TYPE_CODE_INT)
1685 (CORE_ADDR) value_as_address (arg1));
1686 return value_ind (arg1);
1687}
1688
1689/* A helper function for UNOP_ALIGNOF. */
1690
1691struct value *
1692eval_op_alignof (struct type *expect_type, struct expression *exp,
1693 enum noside noside,
1694 struct value *arg1)
1695{
1696 struct type *type = arg1->type ();
1697 /* FIXME: This should be size_t. */
1698 struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
1699 ULONGEST align = type_align (type);
1700 if (align == 0)
1701 error (_("could not determine alignment of type"));
1702 return value_from_longest (size_type, align);
1703}
1704
1705/* A helper function for UNOP_MEMVAL. */
1706
1707struct value *
1708eval_op_memval (struct type *expect_type, struct expression *exp,
1709 enum noside noside,
1710 struct value *arg1, struct type *type)
1711{
1713 return value::zero (type, lval_memory);
1714 else
1715 return value_at_lazy (type, value_as_address (arg1));
1716}
1717
1718/* A helper function for UNOP_PREINCREMENT. */
1719
1720struct value *
1721eval_op_preinc (struct type *expect_type, struct expression *exp,
1722 enum noside noside, enum exp_opcode op,
1723 struct value *arg1)
1724{
1726 return arg1;
1727 else if (unop_user_defined_p (op, arg1))
1728 {
1729 return value_x_unop (arg1, op, noside);
1730 }
1731 else
1732 {
1733 struct value *arg2;
1734 if (ptrmath_type_p (exp->language_defn, arg1->type ()))
1735 arg2 = value_ptradd (arg1, 1);
1736 else
1737 {
1738 struct value *tmp = arg1;
1739
1740 arg2 = value_one (arg1->type ());
1741 binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
1742 arg2 = value_binop (tmp, arg2, BINOP_ADD);
1743 }
1744
1745 return value_assign (arg1, arg2);
1746 }
1747}
1748
1749/* A helper function for UNOP_PREDECREMENT. */
1750
1751struct value *
1752eval_op_predec (struct type *expect_type, struct expression *exp,
1753 enum noside noside, enum exp_opcode op,
1754 struct value *arg1)
1755{
1757 return arg1;
1758 else if (unop_user_defined_p (op, arg1))
1759 {
1760 return value_x_unop (arg1, op, noside);
1761 }
1762 else
1763 {
1764 struct value *arg2;
1765 if (ptrmath_type_p (exp->language_defn, arg1->type ()))
1766 arg2 = value_ptradd (arg1, -1);
1767 else
1768 {
1769 struct value *tmp = arg1;
1770
1771 arg2 = value_one (arg1->type ());
1772 binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
1773 arg2 = value_binop (tmp, arg2, BINOP_SUB);
1774 }
1775
1776 return value_assign (arg1, arg2);
1777 }
1778}
1779
1780/* A helper function for UNOP_POSTINCREMENT. */
1781
1782struct value *
1783eval_op_postinc (struct type *expect_type, struct expression *exp,
1784 enum noside noside, enum exp_opcode op,
1785 struct value *arg1)
1786{
1788 return arg1;
1789 else if (unop_user_defined_p (op, arg1))
1790 {
1791 return value_x_unop (arg1, op, noside);
1792 }
1793 else
1794 {
1795 struct value *arg3 = arg1->non_lval ();
1796 struct value *arg2;
1797
1798 if (ptrmath_type_p (exp->language_defn, arg1->type ()))
1799 arg2 = value_ptradd (arg1, 1);
1800 else
1801 {
1802 struct value *tmp = arg1;
1803
1804 arg2 = value_one (arg1->type ());
1805 binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
1806 arg2 = value_binop (tmp, arg2, BINOP_ADD);
1807 }
1808
1809 value_assign (arg1, arg2);
1810 return arg3;
1811 }
1812}
1813
1814/* A helper function for UNOP_POSTDECREMENT. */
1815
1816struct value *
1817eval_op_postdec (struct type *expect_type, struct expression *exp,
1818 enum noside noside, enum exp_opcode op,
1819 struct value *arg1)
1820{
1822 return arg1;
1823 else if (unop_user_defined_p (op, arg1))
1824 {
1825 return value_x_unop (arg1, op, noside);
1826 }
1827 else
1828 {
1829 struct value *arg3 = arg1->non_lval ();
1830 struct value *arg2;
1831
1832 if (ptrmath_type_p (exp->language_defn, arg1->type ()))
1833 arg2 = value_ptradd (arg1, -1);
1834 else
1835 {
1836 struct value *tmp = arg1;
1837
1838 arg2 = value_one (arg1->type ());
1839 binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
1840 arg2 = value_binop (tmp, arg2, BINOP_SUB);
1841 }
1842
1843 value_assign (arg1, arg2);
1844 return arg3;
1845 }
1846}
1847
1848/* A helper function for OP_TYPE. */
1849
1850struct value *
1851eval_op_type (struct type *expect_type, struct expression *exp,
1852 enum noside noside, struct type *type)
1853{
1855 return value::allocate (type);
1856 else
1857 error (_("Attempt to use a type name as an expression"));
1858}
1859
1860/* A helper function for BINOP_ASSIGN_MODIFY. */
1861
1862struct value *
1863eval_binop_assign_modify (struct type *expect_type, struct expression *exp,
1864 enum noside noside, enum exp_opcode op,
1865 struct value *arg1, struct value *arg2)
1866{
1868 return arg1;
1869 if (binop_user_defined_p (op, arg1, arg2))
1870 return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op, noside);
1871 else if (op == BINOP_ADD && ptrmath_type_p (exp->language_defn,
1872 arg1->type ())
1873 && is_integral_type (arg2->type ()))
1874 arg2 = value_ptradd (arg1, value_as_long (arg2));
1875 else if (op == BINOP_SUB && ptrmath_type_p (exp->language_defn,
1876 arg1->type ())
1877 && is_integral_type (arg2->type ()))
1878 arg2 = value_ptradd (arg1, - value_as_long (arg2));
1879 else
1880 {
1881 struct value *tmp = arg1;
1882
1883 /* For shift and integer exponentiation operations,
1884 only promote the first argument. */
1885 if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP)
1886 && is_integral_type (arg2->type ()))
1887 unop_promote (exp->language_defn, exp->gdbarch, &tmp);
1888 else
1889 binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
1890
1891 arg2 = value_binop (tmp, arg2, op);
1892 }
1893 return value_assign (arg1, arg2);
1894}
1895
1896/* Note that ARGS needs 2 empty slots up front and must end with a
1897 null pointer. */
1898static struct value *
1899eval_op_objc_msgcall (struct type *expect_type, struct expression *exp,
1900 enum noside noside, CORE_ADDR selector,
1901 value *target, gdb::array_view<value *> args)
1902{
1903 CORE_ADDR responds_selector = 0;
1904 CORE_ADDR method_selector = 0;
1905
1906 int struct_return = 0;
1907
1908 struct value *msg_send = NULL;
1909 struct value *msg_send_stret = NULL;
1910 int gnu_runtime = 0;
1911
1912 struct value *method = NULL;
1913 struct value *called_method = NULL;
1914
1915 struct type *selector_type = NULL;
1916 struct type *long_type;
1917 struct type *type;
1918
1919 struct value *ret = NULL;
1920 CORE_ADDR addr = 0;
1921
1922 value *argvec[5];
1923
1924 long_type = builtin_type (exp->gdbarch)->builtin_long;
1925 selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr;
1926
1927 if (value_as_long (target) == 0)
1928 return value_from_longest (long_type, 0);
1929
1930 if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0).minsym)
1931 gnu_runtime = 1;
1932
1933 /* Find the method dispatch (Apple runtime) or method lookup
1934 (GNU runtime) function for Objective-C. These will be used
1935 to lookup the symbol information for the method. If we
1936 can't find any symbol information, then we'll use these to
1937 call the method, otherwise we can call the method
1938 directly. The msg_send_stret function is used in the special
1939 case of a method that returns a structure (Apple runtime
1940 only). */
1941 if (gnu_runtime)
1942 {
1943 type = selector_type;
1944
1949
1950 msg_send = find_function_in_inferior ("objc_msg_lookup", NULL);
1951 msg_send_stret
1952 = find_function_in_inferior ("objc_msg_lookup", NULL);
1953
1954 msg_send = value_from_pointer (type, value_as_address (msg_send));
1955 msg_send_stret = value_from_pointer (type,
1956 value_as_address (msg_send_stret));
1957 }
1958 else
1959 {
1960 msg_send = find_function_in_inferior ("objc_msgSend", NULL);
1961 /* Special dispatcher for methods returning structs. */
1962 msg_send_stret
1963 = find_function_in_inferior ("objc_msgSend_stret", NULL);
1964 }
1965
1966 /* Verify the target object responds to this method. The
1967 standard top-level 'Object' class uses a different name for
1968 the verification method than the non-standard, but more
1969 often used, 'NSObject' class. Make sure we check for both. */
1970
1971 responds_selector
1972 = lookup_child_selector (exp->gdbarch, "respondsToSelector:");
1973 if (responds_selector == 0)
1974 responds_selector
1975 = lookup_child_selector (exp->gdbarch, "respondsTo:");
1976
1977 if (responds_selector == 0)
1978 error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
1979
1980 method_selector
1981 = lookup_child_selector (exp->gdbarch, "methodForSelector:");
1982 if (method_selector == 0)
1983 method_selector
1984 = lookup_child_selector (exp->gdbarch, "methodFor:");
1985
1986 if (method_selector == 0)
1987 error (_("no 'methodFor:' or 'methodForSelector:' method"));
1988
1989 /* Call the verification method, to make sure that the target
1990 class implements the desired method. */
1991
1992 argvec[0] = msg_send;
1993 argvec[1] = target;
1994 argvec[2] = value_from_longest (long_type, responds_selector);
1995 argvec[3] = value_from_longest (long_type, selector);
1996 argvec[4] = 0;
1997
1998 ret = call_function_by_hand (argvec[0], NULL, {argvec + 1, 3});
1999 if (gnu_runtime)
2000 {
2001 /* Function objc_msg_lookup returns a pointer. */
2002 argvec[0] = ret;
2003 ret = call_function_by_hand (argvec[0], NULL, {argvec + 1, 3});
2004 }
2005 if (value_as_long (ret) == 0)
2006 error (_("Target does not respond to this message selector."));
2007
2008 /* Call "methodForSelector:" method, to get the address of a
2009 function method that implements this selector for this
2010 class. If we can find a symbol at that address, then we
2011 know the return type, parameter types etc. (that's a good
2012 thing). */
2013
2014 argvec[0] = msg_send;
2015 argvec[1] = target;
2016 argvec[2] = value_from_longest (long_type, method_selector);
2017 argvec[3] = value_from_longest (long_type, selector);
2018 argvec[4] = 0;
2019
2020 ret = call_function_by_hand (argvec[0], NULL, {argvec + 1, 3});
2021 if (gnu_runtime)
2022 {
2023 argvec[0] = ret;
2024 ret = call_function_by_hand (argvec[0], NULL, {argvec + 1, 3});
2025 }
2026
2027 /* ret should now be the selector. */
2028
2029 addr = value_as_long (ret);
2030 if (addr)
2031 {
2032 struct symbol *sym = NULL;
2033
2034 /* The address might point to a function descriptor;
2035 resolve it to the actual code address instead. */
2037 (exp->gdbarch, addr, current_inferior ()->top_target ());
2038
2039 /* Is it a high_level symbol? */
2040 sym = find_pc_function (addr);
2041 if (sym != NULL)
2042 method = value_of_variable (sym, 0);
2043 }
2044
2045 /* If we found a method with symbol information, check to see
2046 if it returns a struct. Otherwise assume it doesn't. */
2047
2048 if (method)
2049 {
2050 CORE_ADDR funaddr;
2051 struct type *val_type;
2052
2053 funaddr = find_function_addr (method, &val_type);
2054
2055 block_for_pc (funaddr);
2056
2057 val_type = check_typedef (val_type);
2058
2059 if ((val_type == NULL)
2060 || (val_type->code () == TYPE_CODE_ERROR))
2061 {
2062 if (expect_type != NULL)
2063 val_type = expect_type;
2064 }
2065
2067 val_type);
2068 }
2069 else if (expect_type != NULL)
2070 {
2072 check_typedef (expect_type));
2073 }
2074
2075 /* Found a function symbol. Now we will substitute its
2076 value in place of the message dispatcher (obj_msgSend),
2077 so that we call the method directly instead of thru
2078 the dispatcher. The main reason for doing this is that
2079 we can now evaluate the return value and parameter values
2080 according to their known data types, in case we need to
2081 do things like promotion, dereferencing, special handling
2082 of structs and doubles, etc.
2083
2084 We want to use the type signature of 'method', but still
2085 jump to objc_msgSend() or objc_msgSend_stret() to better
2086 mimic the behavior of the runtime. */
2087
2088 if (method)
2089 {
2090 if (method->type ()->code () != TYPE_CODE_FUNC)
2091 error (_("method address has symbol information "
2092 "with non-function type; skipping"));
2093
2094 /* Create a function pointer of the appropriate type, and
2095 replace its value with the value of msg_send or
2096 msg_send_stret. We must use a pointer here, as
2097 msg_send and msg_send_stret are of pointer type, and
2098 the representation may be different on systems that use
2099 function descriptors. */
2100 if (struct_return)
2101 called_method
2103 value_as_address (msg_send_stret));
2104 else
2105 called_method
2107 value_as_address (msg_send));
2108 }
2109 else
2110 {
2111 if (struct_return)
2112 called_method = msg_send_stret;
2113 else
2114 called_method = msg_send;
2115 }
2116
2117
2119 {
2120 /* If the return type doesn't look like a function type,
2121 call an error. This can happen if somebody tries to
2122 turn a variable into a function call. This is here
2123 because people often want to call, eg, strcmp, which
2124 gdb doesn't know is a function. If gdb isn't asked for
2125 it's opinion (ie. through "whatis"), it won't offer
2126 it. */
2127
2128 struct type *callee_type = called_method->type ();
2129
2130 if (callee_type && callee_type->code () == TYPE_CODE_PTR)
2131 callee_type = callee_type->target_type ();
2132 callee_type = callee_type->target_type ();
2133
2134 if (callee_type)
2135 {
2136 if ((callee_type->code () == TYPE_CODE_ERROR) && expect_type)
2137 return value::allocate (expect_type);
2138 else
2139 return value::allocate (callee_type);
2140 }
2141 else
2142 error (_("Expression of type other than "
2143 "\"method returning ...\" used as a method"));
2144 }
2145
2146 /* Now depending on whether we found a symbol for the method,
2147 we will either call the runtime dispatcher or the method
2148 directly. */
2149
2150 args[0] = target;
2151 args[1] = value_from_longest (long_type, selector);
2152
2153 if (gnu_runtime && (method != NULL))
2154 {
2155 /* Function objc_msg_lookup returns a pointer. */
2156 struct type *tem_type = called_method->type ();
2157 tem_type = lookup_pointer_type (lookup_function_type (tem_type));
2158 called_method->deprecated_set_type (tem_type);
2159 called_method = call_function_by_hand (called_method, NULL, args);
2160 }
2161
2162 return call_function_by_hand (called_method, NULL, args);
2163}
2164
2165/* Helper function for MULTI_SUBSCRIPT. */
2166
2167static struct value *
2168eval_multi_subscript (struct type *expect_type, struct expression *exp,
2169 enum noside noside, value *arg1,
2170 gdb::array_view<value *> args)
2171{
2172 for (value *arg2 : args)
2173 {
2174 if (binop_user_defined_p (MULTI_SUBSCRIPT, arg1, arg2))
2175 {
2176 arg1 = value_x_binop (arg1, arg2, MULTI_SUBSCRIPT, OP_NULL, noside);
2177 }
2178 else
2179 {
2180 arg1 = coerce_ref (arg1);
2181 struct type *type = check_typedef (arg1->type ());
2182
2183 switch (type->code ())
2184 {
2185 case TYPE_CODE_PTR:
2186 case TYPE_CODE_ARRAY:
2187 case TYPE_CODE_STRING:
2188 arg1 = value_subscript (arg1, value_as_long (arg2));
2189 break;
2190
2191 default:
2192 if (type->name ())
2193 error (_("cannot subscript something of type `%s'"),
2194 type->name ());
2195 else
2196 error (_("cannot subscript requested type"));
2197 }
2198 }
2199 }
2200 return (arg1);
2201}
2202
2203namespace expr
2204{
2205
2206value *
2208 struct expression *exp,
2209 enum noside noside)
2210{
2211 enum noside sub_no_side = EVAL_NORMAL;
2212 struct type *selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr;
2213
2215 sub_no_side = EVAL_NORMAL;
2216 else
2217 sub_no_side = noside;
2218 value *target
2219 = std::get<1> (m_storage)->evaluate (selector_type, exp, sub_no_side);
2220
2221 if (value_as_long (target) == 0)
2222 sub_no_side = EVAL_AVOID_SIDE_EFFECTS;
2223 else
2224 sub_no_side = noside;
2225 std::vector<operation_up> &args = std::get<2> (m_storage);
2226 value **argvec = XALLOCAVEC (struct value *, args.size () + 3);
2227 argvec[0] = nullptr;
2228 argvec[1] = nullptr;
2229 for (int i = 0; i < args.size (); ++i)
2230 argvec[i + 2] = args[i]->evaluate_with_coercion (exp, sub_no_side);
2231 argvec[args.size () + 2] = nullptr;
2232
2233 return eval_op_objc_msgcall (expect_type, exp, noside, std::
2234 get<0> (m_storage), target,
2235 gdb::make_array_view (argvec,
2236 args.size () + 3));
2237}
2238
2239value *
2241 struct expression *exp,
2242 enum noside noside)
2243{
2244 value *arg1 = std::get<0> (m_storage)->evaluate_with_coercion (exp, noside);
2245 std::vector<operation_up> &values = std::get<1> (m_storage);
2246 value **argvec = XALLOCAVEC (struct value *, values.size ());
2247 for (int ix = 0; ix < values.size (); ++ix)
2248 argvec[ix] = values[ix]->evaluate_with_coercion (exp, noside);
2249 return eval_multi_subscript (expect_type, exp, noside, arg1,
2250 gdb::make_array_view (argvec, values.size ()));
2251}
2252
2253value *
2255 struct expression *exp,
2256 enum noside noside)
2257{
2258 value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
2259
2260 value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp,
2262
2263 if (binop_user_defined_p (BINOP_LOGICAL_AND, arg1, arg2))
2264 {
2265 arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
2266 return value_x_binop (arg1, arg2, BINOP_LOGICAL_AND, OP_NULL, noside);
2267 }
2268 else
2269 {
2270 bool tem = value_logical_not (arg1);
2271 if (!tem)
2272 {
2273 arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
2274 tem = value_logical_not (arg2);
2275 }
2276 struct type *type = language_bool_type (exp->language_defn,
2277 exp->gdbarch);
2278 return value_from_longest (type, !tem);
2279 }
2280}
2281
2282value *
2284 struct expression *exp,
2285 enum noside noside)
2286{
2287 value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
2288
2289 value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp,
2291
2292 if (binop_user_defined_p (BINOP_LOGICAL_OR, arg1, arg2))
2293 {
2294 arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
2295 return value_x_binop (arg1, arg2, BINOP_LOGICAL_OR, OP_NULL, noside);
2296 }
2297 else
2298 {
2299 bool tem = value_logical_not (arg1);
2300 if (tem)
2301 {
2302 arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
2303 tem = value_logical_not (arg2);
2304 }
2305
2306 struct type *type = language_bool_type (exp->language_defn,
2307 exp->gdbarch);
2308 return value_from_longest (type, !tem);
2309 }
2310}
2311
2312value *
2314 struct expression *exp,
2315 enum noside noside)
2316{
2317 std::vector<operation_up> &arg_ops = std::get<2> (m_storage);
2318 std::vector<value *> args (arg_ops.size ());
2319 for (int i = 0; i < arg_ops.size (); ++i)
2320 args[i] = arg_ops[i]->evaluate_with_coercion (exp, noside);
2321
2322 struct symbol *symp;
2323 find_overload_match (args, std::get<0> (m_storage).c_str (),
2324 NON_METHOD,
2325 nullptr, nullptr,
2326 nullptr, &symp, nullptr, 0, noside);
2327 if (symp->type ()->code () == TYPE_CODE_ERROR)
2328 error_unknown_type (symp->print_name ());
2329 value *callee = evaluate_var_value (noside, std::get<1> (m_storage), symp);
2330 return evaluate_subexp_do_call (exp, noside, callee, args,
2331 nullptr, expect_type);
2332
2333}
2334
2335/* This function evaluates brace-initializers (in C/C++) for
2336 structure types. */
2337
2338struct value *
2340 struct expression *exp,
2341 enum noside noside, int nargs)
2342{
2343 const std::vector<operation_up> &in_args = std::get<2> (m_storage);
2344 struct type *struct_type = check_typedef (struct_val->type ());
2345 struct type *field_type;
2346 int fieldno = -1;
2347
2348 int idx = 0;
2349 while (--nargs >= 0)
2350 {
2351 struct value *val = NULL;
2352 int bitpos, bitsize;
2353 bfd_byte *addr;
2354
2355 fieldno++;
2356 /* Skip static fields. */
2357 while (fieldno < struct_type->num_fields ()
2358 && struct_type->field (fieldno).is_static ())
2359 fieldno++;
2360 if (fieldno >= struct_type->num_fields ())
2361 error (_("too many initializers"));
2362 field_type = struct_type->field (fieldno).type ();
2363 if (field_type->code () == TYPE_CODE_UNION
2364 && struct_type->field (fieldno).name ()[0] == '0')
2365 error (_("don't know which variant you want to set"));
2366
2367 /* Here, struct_type is the type of the inner struct,
2368 while substruct_type is the type of the inner struct.
2369 These are the same for normal structures, but a variant struct
2370 contains anonymous union fields that contain substruct fields.
2371 The value fieldno is the index of the top-level (normal or
2372 anonymous union) field in struct_field, while the value
2373 subfieldno is the index of the actual real (named inner) field
2374 in substruct_type. */
2375
2376 field_type = struct_type->field (fieldno).type ();
2377 if (val == 0)
2378 val = in_args[idx++]->evaluate (field_type, exp, noside);
2379
2380 /* Now actually set the field in struct_val. */
2381
2382 /* Assign val to field fieldno. */
2383 if (val->type () != field_type)
2384 val = value_cast (field_type, val);
2385
2386 bitsize = struct_type->field (fieldno).bitsize ();
2387 bitpos = struct_type->field (fieldno).loc_bitpos ();
2388 addr = struct_val->contents_writeable ().data () + bitpos / 8;
2389 if (bitsize)
2390 modify_field (struct_type, addr,
2391 value_as_long (val), bitpos % 8, bitsize);
2392 else
2393 memcpy (addr, val->contents ().data (),
2394 val->type ()->length ());
2395
2396 }
2397 return struct_val;
2398}
2399
2400value *
2401array_operation::evaluate (struct type *expect_type,
2402 struct expression *exp,
2403 enum noside noside)
2404{
2405 const int provided_low_bound = std::get<0> (m_storage);
2406 const std::vector<operation_up> &in_args = std::get<2> (m_storage);
2407 const int nargs = std::get<1> (m_storage) - provided_low_bound + 1;
2408 struct type *type = expect_type ? check_typedef (expect_type) : nullptr;
2409
2410 if (expect_type != nullptr
2411 && type->code () == TYPE_CODE_STRUCT)
2412 {
2413 struct value *rec = value::allocate (expect_type);
2414
2415 memset (rec->contents_raw ().data (), '\0', type->length ());
2416 return evaluate_struct_tuple (rec, exp, noside, nargs);
2417 }
2418
2419 if (expect_type != nullptr
2420 && type->code () == TYPE_CODE_ARRAY)
2421 {
2422 struct type *range_type = type->index_type ();
2423 struct type *element_type = type->target_type ();
2424 struct value *array = value::allocate (expect_type);
2425 int element_size = check_typedef (element_type)->length ();
2426 LONGEST low_bound, high_bound;
2427
2428 if (!get_discrete_bounds (range_type, &low_bound, &high_bound))
2429 {
2430 low_bound = 0;
2431 high_bound = (type->length () / element_size) - 1;
2432 }
2433 if (low_bound + nargs - 1 > high_bound)
2434 error (_("Too many array elements"));
2435 memset (array->contents_raw ().data (), 0, expect_type->length ());
2436 for (int idx = 0; idx < nargs; ++idx)
2437 {
2438 struct value *element;
2439
2440 element = in_args[idx]->evaluate (element_type, exp, noside);
2441 if (element->type () != element_type)
2442 element = value_cast (element_type, element);
2443 memcpy (array->contents_raw ().data () + idx * element_size,
2444 element->contents ().data (),
2445 element_size);
2446 }
2447 return array;
2448 }
2449
2450 if (expect_type != nullptr
2451 && type->code () == TYPE_CODE_SET)
2452 {
2453 struct value *set = value::allocate (expect_type);
2454 gdb_byte *valaddr = set->contents_raw ().data ();
2455 struct type *element_type = type->index_type ();
2456 struct type *check_type = element_type;
2457 LONGEST low_bound, high_bound;
2458
2459 /* Get targettype of elementtype. */
2460 while (check_type->code () == TYPE_CODE_RANGE
2461 || check_type->code () == TYPE_CODE_TYPEDEF)
2462 check_type = check_type->target_type ();
2463
2464 if (!get_discrete_bounds (element_type, &low_bound, &high_bound))
2465 error (_("(power)set type with unknown size"));
2466 memset (valaddr, '\0', type->length ());
2467 for (int idx = 0; idx < nargs; idx++)
2468 {
2469 LONGEST range_low, range_high;
2470 struct type *range_low_type, *range_high_type;
2471 struct value *elem_val;
2472
2473 elem_val = in_args[idx]->evaluate (element_type, exp, noside);
2474 range_low_type = range_high_type = elem_val->type ();
2475 range_low = range_high = value_as_long (elem_val);
2476
2477 /* Check types of elements to avoid mixture of elements from
2478 different types. Also check if type of element is "compatible"
2479 with element type of powerset. */
2480 if (range_low_type->code () == TYPE_CODE_RANGE)
2481 range_low_type = range_low_type->target_type ();
2482 if (range_high_type->code () == TYPE_CODE_RANGE)
2483 range_high_type = range_high_type->target_type ();
2484 if ((range_low_type->code () != range_high_type->code ())
2485 || (range_low_type->code () == TYPE_CODE_ENUM
2486 && (range_low_type != range_high_type)))
2487 /* different element modes. */
2488 error (_("POWERSET tuple elements of different mode"));
2489 if ((check_type->code () != range_low_type->code ())
2490 || (check_type->code () == TYPE_CODE_ENUM
2491 && range_low_type != check_type))
2492 error (_("incompatible POWERSET tuple elements"));
2493 if (range_low > range_high)
2494 {
2495 warning (_("empty POWERSET tuple range"));
2496 continue;
2497 }
2498 if (range_low < low_bound || range_high > high_bound)
2499 error (_("POWERSET tuple element out of range"));
2500 range_low -= low_bound;
2501 range_high -= low_bound;
2502 for (; range_low <= range_high; range_low++)
2503 {
2504 int bit_index = (unsigned) range_low % TARGET_CHAR_BIT;
2505
2506 if (gdbarch_byte_order (exp->gdbarch) == BFD_ENDIAN_BIG)
2507 bit_index = TARGET_CHAR_BIT - 1 - bit_index;
2508 valaddr[(unsigned) range_low / TARGET_CHAR_BIT]
2509 |= 1 << bit_index;
2510 }
2511 }
2512 return set;
2513 }
2514
2515 std::vector<value *> argvec (nargs);
2516 for (int tem = 0; tem < nargs; tem++)
2517 {
2518 /* Ensure that array expressions are coerced into pointer
2519 objects. */
2520 argvec[tem] = in_args[tem]->evaluate_with_coercion (exp, noside);
2521 }
2522 return value_array (provided_low_bound, argvec);
2523}
2524
2525value *
2527 struct expression *exp,
2528 enum noside noside)
2529{
2530 value *old_value = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
2531 struct type *type = get_type ();
2532
2533 if (type->length () > old_value->type ()->length ())
2534 error (_("length type is larger than the value type"));
2535
2536 struct value *result = value::allocate (type);
2537 old_value->contents_copy (result, 0, 0, type->length ());
2538 return result;
2539}
2540
2541}
2542
2543
2544/* Helper for evaluate_subexp_for_address. */
2545
2546static value *
2548 value *x)
2549{
2551 {
2552 struct type *type = check_typedef (x->type ());
2553
2554 if (TYPE_IS_REFERENCE (type))
2556 not_lval);
2557 else if (x->lval () == lval_memory || value_must_coerce_to_target (x))
2558 return value::zero (lookup_pointer_type (x->type ()),
2559 not_lval);
2560 else
2561 error (_("Attempt to take address of "
2562 "value not located in memory."));
2563 }
2564 return value_addr (x);
2565}
2566
2567namespace expr
2568{
2569
2570value *
2572 struct expression *exp,
2573 enum noside noside)
2574{
2575 value *val = evaluate (expect_type, exp, noside);
2576 return value_cast (expect_type, val);
2577}
2578
2579value *
2581{
2582 value *val = evaluate (nullptr, exp, noside);
2583 return evaluate_subexp_for_address_base (exp, noside, val);
2584}
2585
2586value *
2588 enum noside noside)
2589{
2590 value *x = value_aggregate_elt (std::get<0> (m_storage),
2591 std::get<1> (m_storage).c_str (),
2592 NULL, 1, noside);
2593 if (x == NULL)
2594 error (_("There is no field named %s"), std::get<1> (m_storage).c_str ());
2595 return x;
2596}
2597
2598value *
2600 enum noside noside)
2601{
2602 value *x = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
2603
2604 /* We can't optimize out "&*" if there's a user-defined operator*. */
2605 if (unop_user_defined_p (UNOP_IND, x))
2606 {
2607 x = value_x_unop (x, UNOP_IND, noside);
2609 }
2610
2611 return coerce_array (x);
2612}
2613
2614value *
2616 enum noside noside)
2617{
2618 const bound_minimal_symbol &b = std::get<0> (m_storage);
2621 {
2622 struct type *type = lookup_pointer_type (val->type ());
2623 return value::zero (type, not_lval);
2624 }
2625 else
2626 return value_addr (val);
2627}
2628
2629value *
2631 enum noside noside)
2632{
2633 return value_cast (lookup_pointer_type (std::get<1> (m_storage)),
2634 std::get<0> (m_storage)->evaluate (nullptr, exp, noside));
2635}
2636
2637value *
2639 enum noside noside)
2640{
2641 value *typeval = std::get<0> (m_storage)->evaluate (nullptr, exp,
2643 struct type *type = typeval->type ();
2645 std::get<1> (m_storage)->evaluate (nullptr, exp, noside));
2646}
2647
2648value *
2650 enum noside noside)
2651{
2652 symbol *var = std::get<0> (m_storage).symbol;
2653
2654 /* C++: The "address" of a reference should yield the address
2655 * of the object pointed to. Let value_addr() deal with it. */
2656 if (TYPE_IS_REFERENCE (var->type ()))
2658
2660 {
2661 struct type *type = lookup_pointer_type (var->type ());
2662 enum address_class sym_class = var->aclass ();
2663
2664 if (sym_class == LOC_CONST
2665 || sym_class == LOC_CONST_BYTES
2666 || sym_class == LOC_REGISTER)
2667 error (_("Attempt to take address of register or constant."));
2668
2669 return value::zero (type, not_lval);
2670 }
2671 else
2672 return address_of_variable (var, std::get<0> (m_storage).block);
2673}
2674
2675value *
2677 enum noside noside)
2678{
2679 struct symbol *var = std::get<0> (m_storage).symbol;
2680 struct type *type = check_typedef (var->type ());
2681 if (type->code () == TYPE_CODE_ARRAY
2682 && !type->is_vector ()
2684 {
2685 struct value *val = address_of_variable (var,
2686 std::get<0> (m_storage).block);
2687 return value_cast (lookup_pointer_type (type->target_type ()), val);
2688 }
2689 return evaluate (nullptr, exp, noside);
2690}
2691
2692}
2693
2694/* Helper function for evaluating the size of a type. */
2695
2696static value *
2698{
2699 /* FIXME: This should be size_t. */
2700 struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
2701 /* $5.3.3/2 of the C++ Standard (n3290 draft) says of sizeof:
2702 "When applied to a reference or a reference type, the result is
2703 the size of the referenced type." */
2706 && (TYPE_IS_REFERENCE (type)))
2708 return value_from_longest (size_type, (LONGEST) type->length ());
2709}
2710
2711namespace expr
2712{
2713
2714value *
2716{
2717 value *val = evaluate (nullptr, exp, EVAL_AVOID_SIDE_EFFECTS);
2718 return evaluate_subexp_for_sizeof_base (exp, val->type ());
2719}
2720
2721value *
2723 enum noside noside)
2724
2725{
2726 const bound_minimal_symbol &b = std::get<0> (m_storage);
2728
2729 struct type *type = mval->type ();
2730 if (type->code () == TYPE_CODE_ERROR)
2732
2733 /* FIXME: This should be size_t. */
2734 struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
2735 return value_from_longest (size_type, type->length ());
2736}
2737
2738value *
2740 enum noside noside)
2741{
2742 if (noside == EVAL_NORMAL)
2743 {
2744 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
2746 struct type *type = check_typedef (val->type ());
2747 if (type->code () == TYPE_CODE_ARRAY)
2748 {
2750 if (type->code () == TYPE_CODE_ARRAY)
2751 {
2752 type = type->index_type ();
2753 /* Only re-evaluate the right hand side if the resulting type
2754 is a variable length type. */
2756 {
2757 val = evaluate (nullptr, exp, EVAL_NORMAL);
2758 /* FIXME: This should be size_t. */
2759 struct type *size_type
2761 return value_from_longest
2762 (size_type, (LONGEST) val->type ()->length ());
2763 }
2764 }
2765 }
2766 }
2767
2769}
2770
2771value *
2773 enum noside noside)
2774{
2775 value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
2777 struct type *type = check_typedef (val->type ());
2779 && type->code () != TYPE_CODE_ARRAY)
2780 error (_("Attempt to take contents of a non-pointer value."));
2781 type = type->target_type ();
2782 if (is_dynamic_type (type))
2783 type = value_ind (val)->type ();
2784 /* FIXME: This should be size_t. */
2785 struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
2786 return value_from_longest (size_type, (LONGEST) type->length ());
2787}
2788
2789value *
2791 enum noside noside)
2792{
2793 return evaluate_subexp_for_sizeof_base (exp, std::get<1> (m_storage));
2794}
2795
2796value *
2798 enum noside noside)
2799{
2800 value *typeval = std::get<0> (m_storage)->evaluate (nullptr, exp,
2802 return evaluate_subexp_for_sizeof_base (exp, typeval->type ());
2803}
2804
2805value *
2807 enum noside noside)
2808{
2809 struct type *type = std::get<0> (m_storage).symbol->type ();
2810 if (is_dynamic_type (type))
2811 {
2812 value *val = evaluate (nullptr, exp, EVAL_NORMAL);
2813 type = val->type ();
2814 if (type->code () == TYPE_CODE_ARRAY)
2815 {
2816 /* FIXME: This should be size_t. */
2817 struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
2819 return value::zero (size_type, not_lval);
2820 else if (is_dynamic_type (type->index_type ())
2821 && type->bounds ()->high.kind () == PROP_UNDEFINED)
2822 return value::allocate_optimized_out (size_type);
2823 }
2824 }
2826}
2827
2828value *
2830 struct expression *exp,
2831 enum noside noside)
2832{
2834 return value::zero (to_type, not_lval);
2835
2836 const bound_minimal_symbol &b = std::get<0> (m_storage);
2838
2839 val = value_cast (to_type, val);
2840
2841 /* Don't allow e.g. '&(int)var_with_no_debug_info'. */
2842 if (val->lval () == lval_memory)
2843 {
2844 if (val->lazy ())
2845 val->fetch_lazy ();
2846 val->set_lval (not_lval);
2847 }
2848 return val;
2849}
2850
2851value *
2853 struct expression *exp,
2854 enum noside noside)
2855{
2857 std::get<0> (m_storage).block,
2858 std::get<0> (m_storage).symbol);
2859
2860 val = value_cast (to_type, val);
2861
2862 /* Don't allow e.g. '&(int)var_with_no_debug_info'. */
2863 if (val->lval () == lval_memory)
2864 {
2865 if (val->lazy ())
2866 val->fetch_lazy ();
2867 val->set_lval (not_lval);
2868 }
2869 return val;
2870}
2871
2872}
2873
2874/* Parse a type expression in the string [P..P+LENGTH). */
2875
2876struct type *
2877parse_and_eval_type (const char *p, int length)
2878{
2879 char *tmp = (char *) alloca (length + 4);
2880
2881 tmp[0] = '(';
2882 memcpy (tmp + 1, p, length);
2883 tmp[length + 1] = ')';
2884 tmp[length + 2] = '0';
2885 tmp[length + 3] = '\0';
2888 = dynamic_cast<expr::unop_cast_operation *> (expr->op.get ());
2889 if (op == nullptr)
2890 error (_("Internal error in eval_type."));
2891 return op->get_type ();
2892}
const char *const name
void xfree(void *)
int code
Definition ada-lex.l:670
struct_return
Definition arm-tdep.h:84
const struct block * block_for_pc(CORE_ADDR pc)
Definition block.c:276
struct symbol * find_pc_function(CORE_ADDR pc)
Definition blockframe.c:150
struct type * find_gnu_ifunc_target_type(CORE_ADDR resolver_funaddr)
Definition blockframe.c:435
void add_completions(completion_list &&list)
Definition completer.c:1590
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition eval.c:2313
struct value * evaluate_struct_tuple(struct value *struct_val, struct expression *exp, enum noside noside, int nargs)
Definition eval.c:2339
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition eval.c:2401
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition expop.h:1261
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition eval.c:2254
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition eval.c:2283
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition eval.c:2240
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition eval.c:2207
virtual value * evaluate_for_address(struct expression *exp, enum noside noside)
Definition eval.c:2580
virtual value * evaluate_funcall(struct type *expect_type, struct expression *exp, enum noside noside, const std::vector< operation_up > &args)
Definition expression.h:131
virtual value * evaluate_with_coercion(struct expression *exp, enum noside noside)
Definition expression.h:105
virtual value * evaluate_for_sizeof(struct expression *exp, enum noside noside)
Definition eval.c:2715
virtual value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside)=0
virtual enum exp_opcode opcode() const =0
virtual value * evaluate_for_cast(struct type *expect_type, struct expression *exp, enum noside noside)
Definition eval.c:2571
value * evaluate_for_address(struct expression *exp, enum noside noside) override
Definition eval.c:2587
value * evaluate_funcall(struct type *expect_type, struct expression *exp, enum noside noside, const std::vector< operation_up > &args) override
Definition eval.c:711
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition eval.c:1148
value * evaluate_funcall(struct type *expect_type, struct expression *exp, enum noside noside, const std::vector< operation_up > &args) override
Definition eval.c:848
virtual bool complete(struct expression *exp, completion_tracker &tracker)
Definition expop.h:1014
value * evaluate_funcall(struct type *expect_type, struct expression *exp, enum noside noside, const std::vector< operation_up > &args) override
Definition eval.c:785
value * evaluate_for_sizeof(struct expression *exp, enum noside noside) override
Definition eval.c:2739
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition eval.c:1159
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition eval.c:503
struct type * get_type() const
Definition expop.h:2003
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition eval.c:2526
struct type * get_type() const
Definition expop.h:1970
value * evaluate_for_sizeof(struct expression *exp, enum noside noside) override
Definition eval.c:2772
value * evaluate_for_address(struct expression *exp, enum noside noside) override
Definition eval.c:2599
value * evaluate_for_sizeof(struct expression *exp, enum noside noside) override
Definition eval.c:2790
value * evaluate_for_address(struct expression *exp, enum noside noside) override
Definition eval.c:2630
value * evaluate_for_sizeof(struct expression *exp, enum noside noside) override
Definition eval.c:2797
value * evaluate_for_address(struct expression *exp, enum noside noside) override
Definition eval.c:2638
value * evaluate_for_sizeof(struct expression *exp, enum noside noside) override
Definition eval.c:2722
value * evaluate_for_address(struct expression *exp, enum noside noside) override
Definition eval.c:2615
value * evaluate_for_cast(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition eval.c:2829
value * evaluate_funcall(struct type *expect_type, struct expression *exp, enum noside noside, const std::vector< operation_up > &args) override
Definition eval.c:683
value * evaluate_for_cast(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition eval.c:2852
value * evaluate_for_sizeof(struct expression *exp, enum noside noside) override
Definition eval.c:2806
value * evaluate_with_coercion(struct expression *exp, enum noside noside) override
Definition eval.c:2676
value * evaluate_for_address(struct expression *exp, enum noside noside) override
Definition eval.c:2649
value * evaluate(struct type *expect_type, struct expression *exp, enum noside noside) override
Definition eval.c:554
~fake_method()
Definition eval.c:494
fake_method(type_instance_flags flags, int num_types, struct type **param_types)
Definition eval.c:455
struct type * type()
Definition eval.c:448
main_type m_main_type
Definition eval.c:452
std::vector< gdb::unique_xmalloc_ptr< char > > completion_list
Definition completer.h:70
struct value * cplus_method_ptr_to_value(struct value **this_p, struct value *method_ptr)
Definition cp-abi.c:165
struct block_symbol cp_lookup_symbol_namespace(const char *scope, const char *name, const struct block *block, const domain_enum domain)
int longest_to_int(LONGEST)
Definition valprint.c:1372
language
Definition defs.h:211
@ language_cplus
Definition defs.h:216
@ language_asm
Definition defs.h:221
@ language_opencl
Definition defs.h:223
@ language_c
Definition defs.h:213
@ language_objc
Definition defs.h:214
@ lval_memory
Definition defs.h:363
@ not_lval
Definition defs.h:361
struct value * eval_op_var_msym_value(struct type *expect_type, struct expression *exp, enum noside noside, bool outermost_p, bound_minimal_symbol msymbol)
Definition eval.c:1085
value * evaluate_var_value(enum noside noside, const block *blk, symbol *var)
Definition eval.c:520
struct value * eval_op_memval(struct type *expect_type, struct expression *exp, enum noside noside, struct value *arg1, struct type *type)
Definition eval.c:1708
struct value * eval_op_func_static_var(struct type *expect_type, struct expression *exp, enum noside noside, value *func, const char *var)
Definition eval.c:1102
struct value * eval_op_objc_selector(struct type *expect_type, struct expression *exp, enum noside noside, const char *sel)
Definition eval.c:1180
struct value * parse_and_eval(const char *exp, parser_flags flags)
Definition eval.c:70
static value * evaluate_subexp_for_sizeof_base(struct expression *exp, struct type *type)
Definition eval.c:2697
struct value * eval_op_var_entry_value(struct type *expect_type, struct expression *exp, enum noside noside, symbol *sym)
Definition eval.c:1067
struct value * eval_op_geq(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
Definition eval.c:1515
struct value * eval_op_preinc(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1)
Definition eval.c:1721
struct value * eval_op_postdec(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1)
Definition eval.c:1817
static bool is_integral_or_integral_reference(struct type *type)
Definition eval.c:1039
struct value * eval_op_less(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
Definition eval.c:1473
struct value * eval_op_lognot(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1)
Definition eval.c:1625
value * evaluate_subexp_do_call(expression *exp, enum noside noside, value *callee, gdb::array_view< value * > argvec, const char *function_name, type *default_return_type)
Definition eval.c:584
static value * evaluate_subexp_for_address_base(struct expression *exp, enum noside noside, value *x)
Definition eval.c:2547
struct value * eval_op_gtr(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
Definition eval.c:1494
struct value * eval_op_neg(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1)
Definition eval.c:1593
struct value * eval_op_notequal(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
Definition eval.c:1452
value * evaluate_var_msym_value(enum noside noside, struct objfile *objfile, minimal_symbol *msymbol)
Definition eval.c:569
struct value * eval_op_structop_ptr(struct type *expect_type, struct expression *exp, enum noside noside, struct value *arg1, const char *string)
Definition eval.c:1206
struct value * parse_to_comma_and_eval(const char **expp)
Definition eval.c:82
struct value * eval_op_alignof(struct type *expect_type, struct expression *exp, enum noside noside, struct value *arg1)
Definition eval.c:1692
struct value * eval_op_register(struct type *expect_type, struct expression *exp, enum noside noside, const char *name)
Definition eval.c:1117
struct value * eval_op_binary(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
Definition eval.c:1352
void binop_promote(const struct language_defn *language, struct gdbarch *gdbarch, struct value **arg1, struct value **arg2)
Definition eval.c:255
struct value * eval_op_complement(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1)
Definition eval.c:1609
struct value * eval_op_scope(struct type *expect_type, struct expression *exp, enum noside noside, struct type *type, const char *string)
Definition eval.c:1053
struct value * eval_op_add(struct type *expect_type, struct expression *exp, enum noside noside, struct value *arg1, struct value *arg2)
Definition eval.c:1304
LONGEST parse_and_eval_long(const char *exp)
Definition eval.c:62
struct value * eval_op_ind(struct type *expect_type, struct expression *exp, enum noside noside, struct value *arg1)
Definition eval.c:1642
static struct value * eval_multi_subscript(struct type *expect_type, struct expression *exp, enum noside noside, value *arg1, gdb::array_view< value * > args)
Definition eval.c:2168
void unop_promote(const struct language_defn *language, struct gdbarch *gdbarch, struct value **arg1)
Definition eval.c:222
static int ptrmath_type_p(const struct language_defn *lang, struct type *type)
Definition eval.c:414
struct value * eval_op_equal(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
Definition eval.c:1431
struct value * eval_op_structop_struct(struct type *expect_type, struct expression *exp, enum noside noside, struct value *arg1, const char *string)
Definition eval.c:1192
struct type * parse_and_eval_type(const char *p, int length)
Definition eval.c:2877
struct value * eval_op_plus(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1)
Definition eval.c:1577
struct value * eval_op_postinc(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1)
Definition eval.c:1783
struct value * eval_op_member(struct type *expect_type, struct expression *exp, enum noside noside, struct value *arg1, struct value *arg2)
Definition eval.c:1262
void fetch_subexp_value(struct expression *exp, expr::operation *op, struct value **valp, struct value **resultp, std::vector< value_ref_ptr > *val_chain, bool preserve_errors)
Definition eval.c:143
struct value * eval_op_leq(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
Definition eval.c:1536
CORE_ADDR parse_and_eval_address(const char *exp)
Definition eval.c:52
struct value * eval_op_predec(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1)
Definition eval.c:1752
struct value * eval_op_subscript(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
Definition eval.c:1397
struct value * eval_op_sub(struct type *expect_type, struct expression *exp, enum noside noside, struct value *arg1, struct value *arg2)
Definition eval.c:1326
struct value * eval_binop_assign_modify(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
Definition eval.c:1863
struct value * eval_op_type(struct type *expect_type, struct expression *exp, enum noside noside, struct type *type)
Definition eval.c:1851
struct value * eval_op_repeat(struct type *expect_type, struct expression *exp, enum noside noside, enum exp_opcode op, struct value *arg1, struct value *arg2)
Definition eval.c:1557
static struct value * eval_op_objc_msgcall(struct type *expect_type, struct expression *exp, enum noside noside, CORE_ADDR selector, value *target, gdb::array_view< value * > args)
Definition eval.c:1899
std::unique_ptr< expression > expression_up
Definition expression.h:241
@ PARSER_COMMA_TERMINATES
Definition expression.h:298
expression_up parse_expression(const char *, innermost_block_tracker *=nullptr, parser_flags flags=0)
Definition parse.c:458
exp_opcode
Definition expression.h:45
expression_up parse_exp_1(const char **, CORE_ADDR pc, const struct block *, parser_flags flags, innermost_block_tracker *=nullptr)
Definition parse.c:446
noside
Definition expression.h:56
@ EVAL_NORMAL
Definition expression.h:57
@ EVAL_AVOID_SIDE_EFFECTS
Definition expression.h:58
struct value * value_of_register(int regnum, frame_info_ptr frame)
Definition findvar.c:253
frame_info_ptr get_selected_frame(const char *message)
Definition frame.c:1888
const struct block * get_selected_block(CORE_ADDR *addr_in_block)
Definition stack.c:2570
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
CORE_ADDR gdbarch_convert_from_func_ptr_addr(struct gdbarch *gdbarch, CORE_ADDR addr, struct target_ops *targ)
Definition gdbarch.c:3135
int gdbarch_double_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1602
static int gdbarch_num_cooked_regs(gdbarch *arch)
Definition gdbarch.h:390
bool value_in_thread_stack_temporaries(struct value *, struct thread_info *thr)
Definition thread.c:785
struct thread_info * inferior_thread(void)
Definition thread.c:85
bool thread_stack_temporaries_enabled_p(struct thread_info *tp)
Definition thread.c:764
struct type * lookup_pointer_type(struct type *type)
Definition gdbtypes.c:430
int is_integral_type(struct type *t)
Definition gdbtypes.c:3654
int is_dynamic_type(struct type *type)
Definition gdbtypes.c:2140
bool get_discrete_bounds(struct type *type, LONGEST *lowp, LONGEST *highp)
Definition gdbtypes.c:1192
struct type * lookup_function_type(struct type *type)
Definition gdbtypes.c:567
struct type * lookup_unsigned_typename(const struct language_defn *language, const char *name)
Definition gdbtypes.c:1673
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
Definition gdbtypes.c:6168
int type_not_associated(const struct type *type)
Definition gdbtypes.c:4372
unsigned type_align(struct type *type)
Definition gdbtypes.c:3527
struct type * lookup_signed_typename(const struct language_defn *language, const char *name)
Definition gdbtypes.c:1685
bool is_fixed_point_type(struct type *type)
Definition gdbtypes.c:5861
int type_not_allocated(const struct type *type)
Definition gdbtypes.c:4361
struct type * check_typedef(struct type *type)
Definition gdbtypes.c:2966
#define TYPE_NFN_FIELDS(thistype)
Definition gdbtypes.h:1925
@ PROP_UNDEFINED
Definition gdbtypes.h:275
#define TYPE_CHAIN(thistype)
Definition gdbtypes.h:1870
#define TYPE_IS_REFERENCE(t)
Definition gdbtypes.h:139
#define TYPE_MAIN_TYPE(thistype)
Definition gdbtypes.h:1866
#define TYPE_SELF_TYPE(thistype)
Definition gdbtypes.h:1913
#define TYPE_BASECLASS(thistype, index)
Definition gdbtypes.h:1946
#define TYPE_FN_FIELDLIST_NAME(thistype, n)
Definition gdbtypes.h:1990
#define TYPE_N_BASECLASSES(thistype)
Definition gdbtypes.h:1947
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition gnu-nat.c:1861
unsigned short selector
Definition go32-nat.c:1
CORE_ADDR find_function_addr(struct value *function, struct type **retval_type, struct type **function_type)
Definition infcall.c:278
void error_call_unknown_return_type(const char *func_name)
Definition infcall.c:395
struct value * call_function_by_hand(struct value *function, type *default_return_type, gdb::array_view< value * > args)
Definition infcall.c:824
ptid_t inferior_ptid
Definition infcmd.c:74
struct inferior * current_inferior(void)
Definition inferior.c:55
struct type * language_bool_type(const struct language_defn *la, struct gdbarch *gdbarch)
Definition language.c:888
struct type * language_string_char_type(const struct language_defn *la, struct gdbarch *gdbarch)
Definition language.c:868
#define CAST_IS_CONVERSION(LANG)
Definition language.h:772
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition minsyms.c:363
type * find_minsym_type_and_address(minimal_symbol *msymbol, struct objfile *objfile, CORE_ADDR *address_p)
Definition minsyms.c:1638
Definition ada-exp.h:87
static void add_struct_fields(struct type *type, completion_list &output, const char *fieldname, int namelen, const char *prefix)
Definition eval.c:951
Definition aarch64.h:67
CORE_ADDR lookup_child_selector(struct gdbarch *gdbarch, const char *selname)
Definition objc-lang.c:140
#define prefix(a, b, R, do)
Definition ppc64-tdep.c:52
int value
Definition py-param.c:79
struct type * register_type(struct gdbarch *gdbarch, int regnum)
Definition regcache.c:158
void(* func)(remote_target *remote, char *)
enum var_types type
Definition scm-param.c:142
const struct block * block
Definition symtab.h:1537
struct symbol * symbol
Definition symtab.h:1533
Definition block.h:109
struct objfile * objfile
Definition minsyms.h:54
struct minimal_symbol * minsym
Definition minsyms.h:49
struct type * builtin_long_long
Definition gdbtypes.h:2096
struct type * builtin_double
Definition gdbtypes.h:2090
struct type * builtin_uint128
Definition gdbtypes.h:2124
struct type * builtin_long
Definition gdbtypes.h:2081
struct type * builtin_data_ptr
Definition gdbtypes.h:2135
struct type * builtin_long_double
Definition gdbtypes.h:2091
struct type * builtin_unsigned_long_long
Definition gdbtypes.h:2097
struct type * builtin_int
Definition gdbtypes.h:2080
struct type * builtin_unsigned_int
Definition gdbtypes.h:2085
struct type * builtin_int128
Definition gdbtypes.h:2123
struct type * builtin_unsigned_long
Definition gdbtypes.h:2086
dynamic_prop_kind kind() const
Definition gdbtypes.h:320
const struct language_defn * language_defn
Definition expression.h:235
struct value * evaluate(struct type *expect_type=nullptr, enum noside noside=EVAL_NORMAL)
Definition eval.c:103
expr::operation_up op
Definition expression.h:238
bool uses_objfile(struct objfile *objfile) const
Definition eval.c:94
struct gdbarch * gdbarch
Definition expression.h:237
void set_type(struct type *type)
Definition gdbtypes.h:552
LONGEST loc_bitpos() const
Definition gdbtypes.h:611
const char * name() const
Definition gdbtypes.h:557
unsigned int bitsize() const
Definition gdbtypes.h:577
struct type * type() const
Definition gdbtypes.h:547
bool is_static() const
Definition gdbtypes.h:593
const char * print_name() const
Definition symtab.h:475
enum language la_language
Definition language.h:275
virtual bool c_style_arrays_p() const
Definition language.h:605
struct objfile * separate_debug_objfile_backlink
Definition objfiles.h:830
struct dynamic_prop high
Definition gdbtypes.h:721
unsigned int flag_bound_evaluated
Definition gdbtypes.h:743
address_class aclass() const
Definition symtab.h:1274
struct type * type() const
Definition symtab.h:1331
symbol()
Definition symtab.h:1237
struct type * target_type() const
Definition gdbtypes.h:1037
type_code code() const
Definition gdbtypes.h:956
void set_is_prototyped(bool is_prototyped)
Definition gdbtypes.h:1164
void set_code(type_code code)
Definition gdbtypes.h:962
ULONGEST length() const
Definition gdbtypes.h:983
struct field & field(int idx) const
Definition gdbtypes.h:1012
void set_instance_flags(type_instance_flags flags)
Definition gdbtypes.h:1059
bool is_unsigned() const
Definition gdbtypes.h:1100
void set_has_varargs(bool has_varargs)
Definition gdbtypes.h:1177
bool is_gnu_ifunc() const
Definition gdbtypes.h:1216
bool is_vector() const
Definition gdbtypes.h:1186
void set_num_fields(unsigned int num_fields)
Definition gdbtypes.h:1000
unsigned int num_fields() const
Definition gdbtypes.h:994
void set_length(ULONGEST length)
Definition gdbtypes.h:988
bool is_pointer_or_reference() const
Definition gdbtypes.h:1431
range_bounds * bounds() const
Definition gdbtypes.h:1065
const char * name() const
Definition gdbtypes.h:968
type * index_type() const
Definition gdbtypes.h:1032
void set_fields(struct field *fields)
Definition gdbtypes.h:1019
Definition value.h:130
static struct value * zero(struct type *type, enum lval_type lv)
Definition value.c:3426
static struct value * allocate_optimized_out(struct type *type)
Definition value.c:997
void contents_copy(struct value *dst, LONGEST dst_offset, LONGEST src_offset, LONGEST length)
Definition value.c:1252
struct value * non_lval()
Definition value.c:1570
bool lazy() const
Definition value.h:265
gdb::array_view< gdb_byte > contents_writeable()
Definition value.c:1271
static struct value * allocate(struct type *type)
Definition value.c:957
void set_lval(lval_type val)
Definition value.h:336
LONGEST embedded_offset() const
Definition value.h:244
gdb::array_view< const gdb_byte > contents()
Definition value.c:1262
struct type * result_type_of_xmethod(gdb::array_view< value * > argv)
Definition value.c:2529
gdb::array_view< gdb_byte > contents_raw()
Definition value.c:1009
struct type * type() const
Definition value.h:180
struct value * call_xmethod(gdb::array_view< value * > argv)
Definition value.c:2540
enum lval_type lval() const
Definition value.h:332
void fetch_lazy()
Definition value.c:4001
CORE_ADDR address
Definition value.h:658
void deprecated_set_type(struct type *type)
Definition value.h:186
struct block_symbol lookup_symbol(const char *name, const struct block *block, domain_enum domain, struct field_of_this_result *is_a_field_of_this)
Definition symtab.c:1964
address_class
Definition symtab.h:968
@ LOC_REGISTER
Definition symtab.h:993
@ LOC_CONST
Definition symtab.h:975
@ LOC_CONST_BYTES
Definition symtab.h:1033
#define SYMBOL_COMPUTED_OPS(symbol)
Definition symtab.h:1543
@ VAR_DOMAIN
Definition symtab.h:910
bool target_has_execution(inferior *inf)
Definition target.c:201
void error_unknown_type(const char *sym_print_name)
Definition typeprint.c:427
int user_reg_map_name_to_regnum(struct gdbarch *gdbarch, const char *name, int len)
Definition user-regs.c:132
bool value_logical_not(struct value *arg1)
Definition valarith.c:1501
struct value * value_subscript(struct value *array, LONGEST index)
Definition valarith.c:141
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:396
struct value * value_neg(struct value *arg1)
Definition valarith.c:1722
struct value * value_x_unop(struct value *arg1, enum exp_opcode op, enum noside noside)
Definition valarith.c:572
struct value * value_complement(struct value *arg1)
Definition valarith.c:1770
struct value * value_pos(struct value *arg1)
Definition valarith.c:1704
int binop_user_defined_p(enum exp_opcode op, struct value *arg1, struct value *arg2)
Definition valarith.c:304
int value_equal(struct value *arg1, struct value *arg2)
Definition valarith.c:1559
int value_less(struct value *arg1, struct value *arg2)
Definition valarith.c:1648
struct value * value_ptradd(struct value *arg1, LONGEST arg2)
Definition valarith.c:79
LONGEST value_ptrdiff(struct value *arg1, struct value *arg2)
Definition valarith.c:100
struct value * value_binop(struct value *arg1, struct value *arg2, enum exp_opcode op)
Definition valarith.c:1464
int unop_user_defined_p(enum exp_opcode op, struct value *arg1)
Definition valarith.c:317
struct value * value_cast_pointers(struct type *type, struct value *arg2, int subclass_check)
Definition valops.c:296
struct value * value_at_lazy(struct type *type, CORE_ADDR addr, frame_info_ptr frame)
Definition valops.c:1036
bool overload_resolution
Definition valops.c:101
struct value * value_slice(struct value *array, int lowbound, int length)
Definition valops.c:4030
struct value * value_aggregate_elt(struct type *curtype, const char *name, struct type *expect_type, int want_address, enum noside noside)
Definition valops.c:3430
struct type * value_rtti_indirect_type(struct value *v, int *full, LONGEST *top, int *using_enc)
Definition valops.c:3849
struct value * value_one(struct type *type)
Definition valops.c:937
struct value * value_struct_elt(struct value **argp, gdb::optional< gdb::array_view< value * > > args, const char *name, int *static_memfuncp, const char *err)
Definition valops.c:2334
struct value * value_of_variable(struct symbol *var, const struct block *b)
Definition valops.c:1386
struct value * value_addr(struct value *arg1)
Definition valops.c:1551
struct value * value_repeat(struct value *arg1, int count)
Definition valops.c:1364
struct value * value_array(int lowbound, gdb::array_view< struct value * > elemvec)
Definition valops.c:1695
struct value * find_function_in_inferior(const char *name, struct objfile **objf_p)
Definition valops.c:117
struct value * value_cast(struct type *type, struct value *arg2)
Definition valops.c:403
struct value * value_assign(struct value *toval, struct value *fromval)
Definition valops.c:1085
bool value_must_coerce_to_target(struct value *val)
Definition valops.c:1449
struct value * value_ind(struct value *arg1)
Definition valops.c:1630
struct value * address_of_variable(struct symbol *var, const struct block *b)
Definition valops.c:1397
int find_overload_match(gdb::array_view< value * > args, 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:2710
struct value * value_string(const gdb_byte *ptr, ssize_t count, struct type *char_type)
Definition valops.c:1757
void get_user_print_options(struct value_print_options *opts)
Definition valprint.c:135
struct value * call_internal_function(struct gdbarch *gdbarch, const struct language_defn *language, struct value *func, int argc, struct value **argv)
Definition value.c:2318
CORE_ADDR value_as_address(struct value *val)
Definition value.c:2636
struct value * value_from_longest(struct type *type, LONGEST num)
Definition value.c:3438
struct value * coerce_ref(struct value *arg)
Definition value.c:3752
struct value * coerce_array(struct value *arg)
Definition value.c:3776
LONGEST value_as_long(struct value *val)
Definition value.c:2554
void modify_field(struct type *type, gdb_byte *addr, LONGEST fieldval, LONGEST bitpos, LONGEST bitsize)
Definition value.c:3280
std::vector< value_ref_ptr > value_release_to_mark(const struct value *mark)
Definition value.c:1475
struct value * value_from_pointer(struct type *type, CORE_ADDR addr)
Definition value.c:3500
struct value * value_mark(void)
Definition value.c:1414
int using_struct_return(struct gdbarch *gdbarch, struct value *function, struct type *value_type)
Definition value.c:3819
struct value * allocate_repeat_value(struct type *type, int count)
Definition value.c:966
@ METHOD
Definition value.h:1289
@ NON_METHOD
Definition value.h:1289