Introduce OP_VAR_MSYM_VALUE
[deliverable/binutils-gdb.git] / gdb / ax-gdb.c
1 /* GDB-specific functions for operating on agent expressions.
2
3 Copyright (C) 1998-2017 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 "symfile.h"
23 #include "gdbtypes.h"
24 #include "language.h"
25 #include "value.h"
26 #include "expression.h"
27 #include "command.h"
28 #include "gdbcmd.h"
29 #include "frame.h"
30 #include "target.h"
31 #include "ax.h"
32 #include "ax-gdb.h"
33 #include "block.h"
34 #include "regcache.h"
35 #include "user-regs.h"
36 #include "dictionary.h"
37 #include "breakpoint.h"
38 #include "tracepoint.h"
39 #include "cp-support.h"
40 #include "arch-utils.h"
41 #include "cli/cli-utils.h"
42 #include "linespec.h"
43 #include "location.h"
44 #include "objfiles.h"
45
46 #include "valprint.h"
47 #include "c-lang.h"
48
49 #include "format.h"
50
51 /* To make sense of this file, you should read doc/agentexpr.texi.
52 Then look at the types and enums in ax-gdb.h. For the code itself,
53 look at gen_expr, towards the bottom; that's the main function that
54 looks at the GDB expressions and calls everything else to generate
55 code.
56
57 I'm beginning to wonder whether it wouldn't be nicer to internally
58 generate trees, with types, and then spit out the bytecode in
59 linear form afterwards; we could generate fewer `swap', `ext', and
60 `zero_ext' bytecodes that way; it would make good constant folding
61 easier, too. But at the moment, I think we should be willing to
62 pay for the simplicity of this code with less-than-optimal bytecode
63 strings.
64
65 Remember, "GBD" stands for "Great Britain, Dammit!" So be careful. */
66 \f
67
68
69 /* Prototypes for local functions. */
70
71 /* There's a standard order to the arguments of these functions:
72 union exp_element ** --- pointer into expression
73 struct agent_expr * --- agent expression buffer to generate code into
74 struct axs_value * --- describes value left on top of stack */
75
76 static struct value *const_var_ref (struct symbol *var);
77 static struct value *const_expr (union exp_element **pc);
78 static struct value *maybe_const_expr (union exp_element **pc);
79
80 static void gen_traced_pop (struct agent_expr *, struct axs_value *);
81
82 static void gen_sign_extend (struct agent_expr *, struct type *);
83 static void gen_extend (struct agent_expr *, struct type *);
84 static void gen_fetch (struct agent_expr *, struct type *);
85 static void gen_left_shift (struct agent_expr *, int);
86
87
88 static void gen_frame_args_address (struct agent_expr *);
89 static void gen_frame_locals_address (struct agent_expr *);
90 static void gen_offset (struct agent_expr *ax, int offset);
91 static void gen_sym_offset (struct agent_expr *, struct symbol *);
92 static void gen_var_ref (struct agent_expr *ax, struct axs_value *value,
93 struct symbol *var);
94
95
96 static void gen_int_literal (struct agent_expr *ax,
97 struct axs_value *value,
98 LONGEST k, struct type *type);
99
100 static void gen_usual_unary (struct agent_expr *ax, struct axs_value *value);
101 static int type_wider_than (struct type *type1, struct type *type2);
102 static struct type *max_type (struct type *type1, struct type *type2);
103 static void gen_conversion (struct agent_expr *ax,
104 struct type *from, struct type *to);
105 static int is_nontrivial_conversion (struct type *from, struct type *to);
106 static void gen_usual_arithmetic (struct agent_expr *ax,
107 struct axs_value *value1,
108 struct axs_value *value2);
109 static void gen_integral_promotions (struct agent_expr *ax,
110 struct axs_value *value);
111 static void gen_cast (struct agent_expr *ax,
112 struct axs_value *value, struct type *type);
113 static void gen_scale (struct agent_expr *ax,
114 enum agent_op op, struct type *type);
115 static void gen_ptradd (struct agent_expr *ax, struct axs_value *value,
116 struct axs_value *value1, struct axs_value *value2);
117 static void gen_ptrsub (struct agent_expr *ax, struct axs_value *value,
118 struct axs_value *value1, struct axs_value *value2);
119 static void gen_ptrdiff (struct agent_expr *ax, struct axs_value *value,
120 struct axs_value *value1, struct axs_value *value2,
121 struct type *result_type);
122 static void gen_binop (struct agent_expr *ax,
123 struct axs_value *value,
124 struct axs_value *value1,
125 struct axs_value *value2,
126 enum agent_op op,
127 enum agent_op op_unsigned, int may_carry,
128 const char *name);
129 static void gen_logical_not (struct agent_expr *ax, struct axs_value *value,
130 struct type *result_type);
131 static void gen_complement (struct agent_expr *ax, struct axs_value *value);
132 static void gen_deref (struct axs_value *);
133 static void gen_address_of (struct axs_value *);
134 static void gen_bitfield_ref (struct agent_expr *ax, struct axs_value *value,
135 struct type *type, int start, int end);
136 static void gen_primitive_field (struct agent_expr *ax,
137 struct axs_value *value,
138 int offset, int fieldno, struct type *type);
139 static int gen_struct_ref_recursive (struct agent_expr *ax,
140 struct axs_value *value,
141 const char *field, int offset,
142 struct type *type);
143 static void gen_struct_ref (struct agent_expr *ax,
144 struct axs_value *value,
145 const char *field,
146 const char *operator_name,
147 const char *operand_name);
148 static void gen_static_field (struct agent_expr *ax, struct axs_value *value,
149 struct type *type, int fieldno);
150 static void gen_repeat (struct expression *exp, union exp_element **pc,
151 struct agent_expr *ax, struct axs_value *value);
152 static void gen_sizeof (struct expression *exp, union exp_element **pc,
153 struct agent_expr *ax, struct axs_value *value,
154 struct type *size_type);
155 static void gen_expr_binop_rest (struct expression *exp,
156 enum exp_opcode op, union exp_element **pc,
157 struct agent_expr *ax,
158 struct axs_value *value,
159 struct axs_value *value1,
160 struct axs_value *value2);
161
162 static void agent_command (char *exp, int from_tty);
163 \f
164
165 /* Detecting constant expressions. */
166
167 /* If the variable reference at *PC is a constant, return its value.
168 Otherwise, return zero.
169
170 Hey, Wally! How can a variable reference be a constant?
171
172 Well, Beav, this function really handles the OP_VAR_VALUE operator,
173 not specifically variable references. GDB uses OP_VAR_VALUE to
174 refer to any kind of symbolic reference: function names, enum
175 elements, and goto labels are all handled through the OP_VAR_VALUE
176 operator, even though they're constants. It makes sense given the
177 situation.
178
179 Gee, Wally, don'cha wonder sometimes if data representations that
180 subvert commonly accepted definitions of terms in favor of heavily
181 context-specific interpretations are really just a tool of the
182 programming hegemony to preserve their power and exclude the
183 proletariat? */
184
185 static struct value *
186 const_var_ref (struct symbol *var)
187 {
188 struct type *type = SYMBOL_TYPE (var);
189
190 switch (SYMBOL_CLASS (var))
191 {
192 case LOC_CONST:
193 return value_from_longest (type, (LONGEST) SYMBOL_VALUE (var));
194
195 case LOC_LABEL:
196 return value_from_pointer (type, (CORE_ADDR) SYMBOL_VALUE_ADDRESS (var));
197
198 default:
199 return 0;
200 }
201 }
202
203
204 /* If the expression starting at *PC has a constant value, return it.
205 Otherwise, return zero. If we return a value, then *PC will be
206 advanced to the end of it. If we return zero, *PC could be
207 anywhere. */
208 static struct value *
209 const_expr (union exp_element **pc)
210 {
211 enum exp_opcode op = (*pc)->opcode;
212 struct value *v1;
213
214 switch (op)
215 {
216 case OP_LONG:
217 {
218 struct type *type = (*pc)[1].type;
219 LONGEST k = (*pc)[2].longconst;
220
221 (*pc) += 4;
222 return value_from_longest (type, k);
223 }
224
225 case OP_VAR_VALUE:
226 {
227 struct value *v = const_var_ref ((*pc)[2].symbol);
228
229 (*pc) += 4;
230 return v;
231 }
232
233 /* We could add more operators in here. */
234
235 case UNOP_NEG:
236 (*pc)++;
237 v1 = const_expr (pc);
238 if (v1)
239 return value_neg (v1);
240 else
241 return 0;
242
243 default:
244 return 0;
245 }
246 }
247
248
249 /* Like const_expr, but guarantee also that *PC is undisturbed if the
250 expression is not constant. */
251 static struct value *
252 maybe_const_expr (union exp_element **pc)
253 {
254 union exp_element *tentative_pc = *pc;
255 struct value *v = const_expr (&tentative_pc);
256
257 /* If we got a value, then update the real PC. */
258 if (v)
259 *pc = tentative_pc;
260
261 return v;
262 }
263 \f
264
265 /* Generating bytecode from GDB expressions: general assumptions */
266
267 /* Here are a few general assumptions made throughout the code; if you
268 want to make a change that contradicts one of these, then you'd
269 better scan things pretty thoroughly.
270
271 - We assume that all values occupy one stack element. For example,
272 sometimes we'll swap to get at the left argument to a binary
273 operator. If we decide that void values should occupy no stack
274 elements, or that synthetic arrays (whose size is determined at
275 run time, created by the `@' operator) should occupy two stack
276 elements (address and length), then this will cause trouble.
277
278 - We assume the stack elements are infinitely wide, and that we
279 don't have to worry what happens if the user requests an
280 operation that is wider than the actual interpreter's stack.
281 That is, it's up to the interpreter to handle directly all the
282 integer widths the user has access to. (Woe betide the language
283 with bignums!)
284
285 - We don't support side effects. Thus, we don't have to worry about
286 GCC's generalized lvalues, function calls, etc.
287
288 - We don't support floating point. Many places where we switch on
289 some type don't bother to include cases for floating point; there
290 may be even more subtle ways this assumption exists. For
291 example, the arguments to % must be integers.
292
293 - We assume all subexpressions have a static, unchanging type. If
294 we tried to support convenience variables, this would be a
295 problem.
296
297 - All values on the stack should always be fully zero- or
298 sign-extended.
299
300 (I wasn't sure whether to choose this or its opposite --- that
301 only addresses are assumed extended --- but it turns out that
302 neither convention completely eliminates spurious extend
303 operations (if everything is always extended, then you have to
304 extend after add, because it could overflow; if nothing is
305 extended, then you end up producing extends whenever you change
306 sizes), and this is simpler.) */
307 \f
308
309 /* Scan for all static fields in the given class, including any base
310 classes, and generate tracing bytecodes for each. */
311
312 static void
313 gen_trace_static_fields (struct agent_expr *ax,
314 struct type *type)
315 {
316 int i, nbases = TYPE_N_BASECLASSES (type);
317 struct axs_value value;
318
319 type = check_typedef (type);
320
321 for (i = TYPE_NFIELDS (type) - 1; i >= nbases; i--)
322 {
323 if (field_is_static (&TYPE_FIELD (type, i)))
324 {
325 gen_static_field (ax, &value, type, i);
326 if (value.optimized_out)
327 continue;
328 switch (value.kind)
329 {
330 case axs_lvalue_memory:
331 {
332 /* Initialize the TYPE_LENGTH if it is a typedef. */
333 check_typedef (value.type);
334 ax_const_l (ax, TYPE_LENGTH (value.type));
335 ax_simple (ax, aop_trace);
336 }
337 break;
338
339 case axs_lvalue_register:
340 /* We don't actually need the register's value to be pushed,
341 just note that we need it to be collected. */
342 ax_reg_mask (ax, value.u.reg);
343
344 default:
345 break;
346 }
347 }
348 }
349
350 /* Now scan through base classes recursively. */
351 for (i = 0; i < nbases; i++)
352 {
353 struct type *basetype = check_typedef (TYPE_BASECLASS (type, i));
354
355 gen_trace_static_fields (ax, basetype);
356 }
357 }
358
359 /* Trace the lvalue on the stack, if it needs it. In either case, pop
360 the value. Useful on the left side of a comma, and at the end of
361 an expression being used for tracing. */
362 static void
363 gen_traced_pop (struct agent_expr *ax, struct axs_value *value)
364 {
365 int string_trace = 0;
366 if (ax->trace_string
367 && TYPE_CODE (value->type) == TYPE_CODE_PTR
368 && c_textual_element_type (check_typedef (TYPE_TARGET_TYPE (value->type)),
369 's'))
370 string_trace = 1;
371
372 if (ax->tracing)
373 switch (value->kind)
374 {
375 case axs_rvalue:
376 if (string_trace)
377 {
378 ax_const_l (ax, ax->trace_string);
379 ax_simple (ax, aop_tracenz);
380 }
381 else
382 /* We don't trace rvalues, just the lvalues necessary to
383 produce them. So just dispose of this value. */
384 ax_simple (ax, aop_pop);
385 break;
386
387 case axs_lvalue_memory:
388 {
389 /* Initialize the TYPE_LENGTH if it is a typedef. */
390 check_typedef (value->type);
391
392 if (string_trace)
393 {
394 gen_fetch (ax, value->type);
395 ax_const_l (ax, ax->trace_string);
396 ax_simple (ax, aop_tracenz);
397 }
398 else
399 {
400 /* There's no point in trying to use a trace_quick bytecode
401 here, since "trace_quick SIZE pop" is three bytes, whereas
402 "const8 SIZE trace" is also three bytes, does the same
403 thing, and the simplest code which generates that will also
404 work correctly for objects with large sizes. */
405 ax_const_l (ax, TYPE_LENGTH (value->type));
406 ax_simple (ax, aop_trace);
407 }
408 }
409 break;
410
411 case axs_lvalue_register:
412 /* We don't actually need the register's value to be on the
413 stack, and the target will get heartburn if the register is
414 larger than will fit in a stack, so just mark it for
415 collection and be done with it. */
416 ax_reg_mask (ax, value->u.reg);
417
418 /* But if the register points to a string, assume the value
419 will fit on the stack and push it anyway. */
420 if (string_trace)
421 {
422 ax_reg (ax, value->u.reg);
423 ax_const_l (ax, ax->trace_string);
424 ax_simple (ax, aop_tracenz);
425 }
426 break;
427 }
428 else
429 /* If we're not tracing, just pop the value. */
430 ax_simple (ax, aop_pop);
431
432 /* To trace C++ classes with static fields stored elsewhere. */
433 if (ax->tracing
434 && (TYPE_CODE (value->type) == TYPE_CODE_STRUCT
435 || TYPE_CODE (value->type) == TYPE_CODE_UNION))
436 gen_trace_static_fields (ax, value->type);
437 }
438 \f
439
440
441 /* Generating bytecode from GDB expressions: helper functions */
442
443 /* Assume that the lower bits of the top of the stack is a value of
444 type TYPE, and the upper bits are zero. Sign-extend if necessary. */
445 static void
446 gen_sign_extend (struct agent_expr *ax, struct type *type)
447 {
448 /* Do we need to sign-extend this? */
449 if (!TYPE_UNSIGNED (type))
450 ax_ext (ax, TYPE_LENGTH (type) * TARGET_CHAR_BIT);
451 }
452
453
454 /* Assume the lower bits of the top of the stack hold a value of type
455 TYPE, and the upper bits are garbage. Sign-extend or truncate as
456 needed. */
457 static void
458 gen_extend (struct agent_expr *ax, struct type *type)
459 {
460 int bits = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
461
462 /* I just had to. */
463 ((TYPE_UNSIGNED (type) ? ax_zero_ext : ax_ext) (ax, bits));
464 }
465
466
467 /* Assume that the top of the stack contains a value of type "pointer
468 to TYPE"; generate code to fetch its value. Note that TYPE is the
469 target type, not the pointer type. */
470 static void
471 gen_fetch (struct agent_expr *ax, struct type *type)
472 {
473 if (ax->tracing)
474 {
475 /* Record the area of memory we're about to fetch. */
476 ax_trace_quick (ax, TYPE_LENGTH (type));
477 }
478
479 if (TYPE_CODE (type) == TYPE_CODE_RANGE)
480 type = TYPE_TARGET_TYPE (type);
481
482 switch (TYPE_CODE (type))
483 {
484 case TYPE_CODE_PTR:
485 case TYPE_CODE_REF:
486 case TYPE_CODE_RVALUE_REF:
487 case TYPE_CODE_ENUM:
488 case TYPE_CODE_INT:
489 case TYPE_CODE_CHAR:
490 case TYPE_CODE_BOOL:
491 /* It's a scalar value, so we know how to dereference it. How
492 many bytes long is it? */
493 switch (TYPE_LENGTH (type))
494 {
495 case 8 / TARGET_CHAR_BIT:
496 ax_simple (ax, aop_ref8);
497 break;
498 case 16 / TARGET_CHAR_BIT:
499 ax_simple (ax, aop_ref16);
500 break;
501 case 32 / TARGET_CHAR_BIT:
502 ax_simple (ax, aop_ref32);
503 break;
504 case 64 / TARGET_CHAR_BIT:
505 ax_simple (ax, aop_ref64);
506 break;
507
508 /* Either our caller shouldn't have asked us to dereference
509 that pointer (other code's fault), or we're not
510 implementing something we should be (this code's fault).
511 In any case, it's a bug the user shouldn't see. */
512 default:
513 internal_error (__FILE__, __LINE__,
514 _("gen_fetch: strange size"));
515 }
516
517 gen_sign_extend (ax, type);
518 break;
519
520 default:
521 /* Our caller requested us to dereference a pointer from an unsupported
522 type. Error out and give callers a chance to handle the failure
523 gracefully. */
524 error (_("gen_fetch: Unsupported type code `%s'."),
525 TYPE_NAME (type));
526 }
527 }
528
529
530 /* Generate code to left shift the top of the stack by DISTANCE bits, or
531 right shift it by -DISTANCE bits if DISTANCE < 0. This generates
532 unsigned (logical) right shifts. */
533 static void
534 gen_left_shift (struct agent_expr *ax, int distance)
535 {
536 if (distance > 0)
537 {
538 ax_const_l (ax, distance);
539 ax_simple (ax, aop_lsh);
540 }
541 else if (distance < 0)
542 {
543 ax_const_l (ax, -distance);
544 ax_simple (ax, aop_rsh_unsigned);
545 }
546 }
547 \f
548
549
550 /* Generating bytecode from GDB expressions: symbol references */
551
552 /* Generate code to push the base address of the argument portion of
553 the top stack frame. */
554 static void
555 gen_frame_args_address (struct agent_expr *ax)
556 {
557 int frame_reg;
558 LONGEST frame_offset;
559
560 gdbarch_virtual_frame_pointer (ax->gdbarch,
561 ax->scope, &frame_reg, &frame_offset);
562 ax_reg (ax, frame_reg);
563 gen_offset (ax, frame_offset);
564 }
565
566
567 /* Generate code to push the base address of the locals portion of the
568 top stack frame. */
569 static void
570 gen_frame_locals_address (struct agent_expr *ax)
571 {
572 int frame_reg;
573 LONGEST frame_offset;
574
575 gdbarch_virtual_frame_pointer (ax->gdbarch,
576 ax->scope, &frame_reg, &frame_offset);
577 ax_reg (ax, frame_reg);
578 gen_offset (ax, frame_offset);
579 }
580
581
582 /* Generate code to add OFFSET to the top of the stack. Try to
583 generate short and readable code. We use this for getting to
584 variables on the stack, and structure members. If we were
585 programming in ML, it would be clearer why these are the same
586 thing. */
587 static void
588 gen_offset (struct agent_expr *ax, int offset)
589 {
590 /* It would suffice to simply push the offset and add it, but this
591 makes it easier to read positive and negative offsets in the
592 bytecode. */
593 if (offset > 0)
594 {
595 ax_const_l (ax, offset);
596 ax_simple (ax, aop_add);
597 }
598 else if (offset < 0)
599 {
600 ax_const_l (ax, -offset);
601 ax_simple (ax, aop_sub);
602 }
603 }
604
605
606 /* In many cases, a symbol's value is the offset from some other
607 address (stack frame, base register, etc.) Generate code to add
608 VAR's value to the top of the stack. */
609 static void
610 gen_sym_offset (struct agent_expr *ax, struct symbol *var)
611 {
612 gen_offset (ax, SYMBOL_VALUE (var));
613 }
614
615
616 /* Generate code for a variable reference to AX. The variable is the
617 symbol VAR. Set VALUE to describe the result. */
618
619 static void
620 gen_var_ref (struct agent_expr *ax, struct axs_value *value, struct symbol *var)
621 {
622 /* Dereference any typedefs. */
623 value->type = check_typedef (SYMBOL_TYPE (var));
624 value->optimized_out = 0;
625
626 if (SYMBOL_COMPUTED_OPS (var) != NULL)
627 {
628 SYMBOL_COMPUTED_OPS (var)->tracepoint_var_ref (var, ax, value);
629 return;
630 }
631
632 /* I'm imitating the code in read_var_value. */
633 switch (SYMBOL_CLASS (var))
634 {
635 case LOC_CONST: /* A constant, like an enum value. */
636 ax_const_l (ax, (LONGEST) SYMBOL_VALUE (var));
637 value->kind = axs_rvalue;
638 break;
639
640 case LOC_LABEL: /* A goto label, being used as a value. */
641 ax_const_l (ax, (LONGEST) SYMBOL_VALUE_ADDRESS (var));
642 value->kind = axs_rvalue;
643 break;
644
645 case LOC_CONST_BYTES:
646 internal_error (__FILE__, __LINE__,
647 _("gen_var_ref: LOC_CONST_BYTES "
648 "symbols are not supported"));
649
650 /* Variable at a fixed location in memory. Easy. */
651 case LOC_STATIC:
652 /* Push the address of the variable. */
653 ax_const_l (ax, SYMBOL_VALUE_ADDRESS (var));
654 value->kind = axs_lvalue_memory;
655 break;
656
657 case LOC_ARG: /* var lives in argument area of frame */
658 gen_frame_args_address (ax);
659 gen_sym_offset (ax, var);
660 value->kind = axs_lvalue_memory;
661 break;
662
663 case LOC_REF_ARG: /* As above, but the frame slot really
664 holds the address of the variable. */
665 gen_frame_args_address (ax);
666 gen_sym_offset (ax, var);
667 /* Don't assume any particular pointer size. */
668 gen_fetch (ax, builtin_type (ax->gdbarch)->builtin_data_ptr);
669 value->kind = axs_lvalue_memory;
670 break;
671
672 case LOC_LOCAL: /* var lives in locals area of frame */
673 gen_frame_locals_address (ax);
674 gen_sym_offset (ax, var);
675 value->kind = axs_lvalue_memory;
676 break;
677
678 case LOC_TYPEDEF:
679 error (_("Cannot compute value of typedef `%s'."),
680 SYMBOL_PRINT_NAME (var));
681 break;
682
683 case LOC_BLOCK:
684 ax_const_l (ax, BLOCK_START (SYMBOL_BLOCK_VALUE (var)));
685 value->kind = axs_rvalue;
686 break;
687
688 case LOC_REGISTER:
689 /* Don't generate any code at all; in the process of treating
690 this as an lvalue or rvalue, the caller will generate the
691 right code. */
692 value->kind = axs_lvalue_register;
693 value->u.reg
694 = SYMBOL_REGISTER_OPS (var)->register_number (var, ax->gdbarch);
695 break;
696
697 /* A lot like LOC_REF_ARG, but the pointer lives directly in a
698 register, not on the stack. Simpler than LOC_REGISTER
699 because it's just like any other case where the thing
700 has a real address. */
701 case LOC_REGPARM_ADDR:
702 ax_reg (ax,
703 SYMBOL_REGISTER_OPS (var)->register_number (var, ax->gdbarch));
704 value->kind = axs_lvalue_memory;
705 break;
706
707 case LOC_UNRESOLVED:
708 {
709 struct bound_minimal_symbol msym
710 = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (var), NULL, NULL);
711
712 if (!msym.minsym)
713 error (_("Couldn't resolve symbol `%s'."), SYMBOL_PRINT_NAME (var));
714
715 /* Push the address of the variable. */
716 ax_const_l (ax, BMSYMBOL_VALUE_ADDRESS (msym));
717 value->kind = axs_lvalue_memory;
718 }
719 break;
720
721 case LOC_COMPUTED:
722 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
723
724 case LOC_OPTIMIZED_OUT:
725 /* Flag this, but don't say anything; leave it up to callers to
726 warn the user. */
727 value->optimized_out = 1;
728 break;
729
730 default:
731 error (_("Cannot find value of botched symbol `%s'."),
732 SYMBOL_PRINT_NAME (var));
733 break;
734 }
735 }
736
737 /* Generate code for a minimal symbol variable reference to AX. The
738 variable is the symbol MINSYM, of OBJFILE. Set VALUE to describe
739 the result. */
740
741 static void
742 gen_msym_var_ref (agent_expr *ax, axs_value *value,
743 minimal_symbol *msymbol, objfile *objf)
744 {
745 CORE_ADDR address;
746 type *t = find_minsym_type_and_address (msymbol, objf, &address);
747 value->type = t;
748 value->optimized_out = false;
749 ax_const_l (ax, address);
750 value->kind = axs_lvalue_memory;
751 }
752
753 \f
754
755
756 /* Generating bytecode from GDB expressions: literals */
757
758 static void
759 gen_int_literal (struct agent_expr *ax, struct axs_value *value, LONGEST k,
760 struct type *type)
761 {
762 ax_const_l (ax, k);
763 value->kind = axs_rvalue;
764 value->type = check_typedef (type);
765 }
766 \f
767
768
769 /* Generating bytecode from GDB expressions: unary conversions, casts */
770
771 /* Take what's on the top of the stack (as described by VALUE), and
772 try to make an rvalue out of it. Signal an error if we can't do
773 that. */
774 void
775 require_rvalue (struct agent_expr *ax, struct axs_value *value)
776 {
777 /* Only deal with scalars, structs and such may be too large
778 to fit in a stack entry. */
779 value->type = check_typedef (value->type);
780 if (TYPE_CODE (value->type) == TYPE_CODE_ARRAY
781 || TYPE_CODE (value->type) == TYPE_CODE_STRUCT
782 || TYPE_CODE (value->type) == TYPE_CODE_UNION
783 || TYPE_CODE (value->type) == TYPE_CODE_FUNC)
784 error (_("Value not scalar: cannot be an rvalue."));
785
786 switch (value->kind)
787 {
788 case axs_rvalue:
789 /* It's already an rvalue. */
790 break;
791
792 case axs_lvalue_memory:
793 /* The top of stack is the address of the object. Dereference. */
794 gen_fetch (ax, value->type);
795 break;
796
797 case axs_lvalue_register:
798 /* There's nothing on the stack, but value->u.reg is the
799 register number containing the value.
800
801 When we add floating-point support, this is going to have to
802 change. What about SPARC register pairs, for example? */
803 ax_reg (ax, value->u.reg);
804 gen_extend (ax, value->type);
805 break;
806 }
807
808 value->kind = axs_rvalue;
809 }
810
811
812 /* Assume the top of the stack is described by VALUE, and perform the
813 usual unary conversions. This is motivated by ANSI 6.2.2, but of
814 course GDB expressions are not ANSI; they're the mishmash union of
815 a bunch of languages. Rah.
816
817 NOTE! This function promises to produce an rvalue only when the
818 incoming value is of an appropriate type. In other words, the
819 consumer of the value this function produces may assume the value
820 is an rvalue only after checking its type.
821
822 The immediate issue is that if the user tries to use a structure or
823 union as an operand of, say, the `+' operator, we don't want to try
824 to convert that structure to an rvalue; require_rvalue will bomb on
825 structs and unions. Rather, we want to simply pass the struct
826 lvalue through unchanged, and let `+' raise an error. */
827
828 static void
829 gen_usual_unary (struct agent_expr *ax, struct axs_value *value)
830 {
831 /* We don't have to generate any code for the usual integral
832 conversions, since values are always represented as full-width on
833 the stack. Should we tweak the type? */
834
835 /* Some types require special handling. */
836 switch (TYPE_CODE (value->type))
837 {
838 /* Functions get converted to a pointer to the function. */
839 case TYPE_CODE_FUNC:
840 value->type = lookup_pointer_type (value->type);
841 value->kind = axs_rvalue; /* Should always be true, but just in case. */
842 break;
843
844 /* Arrays get converted to a pointer to their first element, and
845 are no longer an lvalue. */
846 case TYPE_CODE_ARRAY:
847 {
848 struct type *elements = TYPE_TARGET_TYPE (value->type);
849
850 value->type = lookup_pointer_type (elements);
851 value->kind = axs_rvalue;
852 /* We don't need to generate any code; the address of the array
853 is also the address of its first element. */
854 }
855 break;
856
857 /* Don't try to convert structures and unions to rvalues. Let the
858 consumer signal an error. */
859 case TYPE_CODE_STRUCT:
860 case TYPE_CODE_UNION:
861 return;
862 }
863
864 /* If the value is an lvalue, dereference it. */
865 require_rvalue (ax, value);
866 }
867
868
869 /* Return non-zero iff the type TYPE1 is considered "wider" than the
870 type TYPE2, according to the rules described in gen_usual_arithmetic. */
871 static int
872 type_wider_than (struct type *type1, struct type *type2)
873 {
874 return (TYPE_LENGTH (type1) > TYPE_LENGTH (type2)
875 || (TYPE_LENGTH (type1) == TYPE_LENGTH (type2)
876 && TYPE_UNSIGNED (type1)
877 && !TYPE_UNSIGNED (type2)));
878 }
879
880
881 /* Return the "wider" of the two types TYPE1 and TYPE2. */
882 static struct type *
883 max_type (struct type *type1, struct type *type2)
884 {
885 return type_wider_than (type1, type2) ? type1 : type2;
886 }
887
888
889 /* Generate code to convert a scalar value of type FROM to type TO. */
890 static void
891 gen_conversion (struct agent_expr *ax, struct type *from, struct type *to)
892 {
893 /* Perhaps there is a more graceful way to state these rules. */
894
895 /* If we're converting to a narrower type, then we need to clear out
896 the upper bits. */
897 if (TYPE_LENGTH (to) < TYPE_LENGTH (from))
898 gen_extend (ax, to);
899
900 /* If the two values have equal width, but different signednesses,
901 then we need to extend. */
902 else if (TYPE_LENGTH (to) == TYPE_LENGTH (from))
903 {
904 if (TYPE_UNSIGNED (from) != TYPE_UNSIGNED (to))
905 gen_extend (ax, to);
906 }
907
908 /* If we're converting to a wider type, and becoming unsigned, then
909 we need to zero out any possible sign bits. */
910 else if (TYPE_LENGTH (to) > TYPE_LENGTH (from))
911 {
912 if (TYPE_UNSIGNED (to))
913 gen_extend (ax, to);
914 }
915 }
916
917
918 /* Return non-zero iff the type FROM will require any bytecodes to be
919 emitted to be converted to the type TO. */
920 static int
921 is_nontrivial_conversion (struct type *from, struct type *to)
922 {
923 agent_expr_up ax (new agent_expr (NULL, 0));
924 int nontrivial;
925
926 /* Actually generate the code, and see if anything came out. At the
927 moment, it would be trivial to replicate the code in
928 gen_conversion here, but in the future, when we're supporting
929 floating point and the like, it may not be. Doing things this
930 way allows this function to be independent of the logic in
931 gen_conversion. */
932 gen_conversion (ax.get (), from, to);
933 nontrivial = ax->len > 0;
934 return nontrivial;
935 }
936
937
938 /* Generate code to perform the "usual arithmetic conversions" (ANSI C
939 6.2.1.5) for the two operands of an arithmetic operator. This
940 effectively finds a "least upper bound" type for the two arguments,
941 and promotes each argument to that type. *VALUE1 and *VALUE2
942 describe the values as they are passed in, and as they are left. */
943 static void
944 gen_usual_arithmetic (struct agent_expr *ax, struct axs_value *value1,
945 struct axs_value *value2)
946 {
947 /* Do the usual binary conversions. */
948 if (TYPE_CODE (value1->type) == TYPE_CODE_INT
949 && TYPE_CODE (value2->type) == TYPE_CODE_INT)
950 {
951 /* The ANSI integral promotions seem to work this way: Order the
952 integer types by size, and then by signedness: an n-bit
953 unsigned type is considered "wider" than an n-bit signed
954 type. Promote to the "wider" of the two types, and always
955 promote at least to int. */
956 struct type *target = max_type (builtin_type (ax->gdbarch)->builtin_int,
957 max_type (value1->type, value2->type));
958
959 /* Deal with value2, on the top of the stack. */
960 gen_conversion (ax, value2->type, target);
961
962 /* Deal with value1, not on the top of the stack. Don't
963 generate the `swap' instructions if we're not actually going
964 to do anything. */
965 if (is_nontrivial_conversion (value1->type, target))
966 {
967 ax_simple (ax, aop_swap);
968 gen_conversion (ax, value1->type, target);
969 ax_simple (ax, aop_swap);
970 }
971
972 value1->type = value2->type = check_typedef (target);
973 }
974 }
975
976
977 /* Generate code to perform the integral promotions (ANSI 6.2.1.1) on
978 the value on the top of the stack, as described by VALUE. Assume
979 the value has integral type. */
980 static void
981 gen_integral_promotions (struct agent_expr *ax, struct axs_value *value)
982 {
983 const struct builtin_type *builtin = builtin_type (ax->gdbarch);
984
985 if (!type_wider_than (value->type, builtin->builtin_int))
986 {
987 gen_conversion (ax, value->type, builtin->builtin_int);
988 value->type = builtin->builtin_int;
989 }
990 else if (!type_wider_than (value->type, builtin->builtin_unsigned_int))
991 {
992 gen_conversion (ax, value->type, builtin->builtin_unsigned_int);
993 value->type = builtin->builtin_unsigned_int;
994 }
995 }
996
997
998 /* Generate code for a cast to TYPE. */
999 static void
1000 gen_cast (struct agent_expr *ax, struct axs_value *value, struct type *type)
1001 {
1002 /* GCC does allow casts to yield lvalues, so this should be fixed
1003 before merging these changes into the trunk. */
1004 require_rvalue (ax, value);
1005 /* Dereference typedefs. */
1006 type = check_typedef (type);
1007
1008 switch (TYPE_CODE (type))
1009 {
1010 case TYPE_CODE_PTR:
1011 case TYPE_CODE_REF:
1012 case TYPE_CODE_RVALUE_REF:
1013 /* It's implementation-defined, and I'll bet this is what GCC
1014 does. */
1015 break;
1016
1017 case TYPE_CODE_ARRAY:
1018 case TYPE_CODE_STRUCT:
1019 case TYPE_CODE_UNION:
1020 case TYPE_CODE_FUNC:
1021 error (_("Invalid type cast: intended type must be scalar."));
1022
1023 case TYPE_CODE_ENUM:
1024 case TYPE_CODE_BOOL:
1025 /* We don't have to worry about the size of the value, because
1026 all our integral values are fully sign-extended, and when
1027 casting pointers we can do anything we like. Is there any
1028 way for us to know what GCC actually does with a cast like
1029 this? */
1030 break;
1031
1032 case TYPE_CODE_INT:
1033 gen_conversion (ax, value->type, type);
1034 break;
1035
1036 case TYPE_CODE_VOID:
1037 /* We could pop the value, and rely on everyone else to check
1038 the type and notice that this value doesn't occupy a stack
1039 slot. But for now, leave the value on the stack, and
1040 preserve the "value == stack element" assumption. */
1041 break;
1042
1043 default:
1044 error (_("Casts to requested type are not yet implemented."));
1045 }
1046
1047 value->type = type;
1048 }
1049 \f
1050
1051
1052 /* Generating bytecode from GDB expressions: arithmetic */
1053
1054 /* Scale the integer on the top of the stack by the size of the target
1055 of the pointer type TYPE. */
1056 static void
1057 gen_scale (struct agent_expr *ax, enum agent_op op, struct type *type)
1058 {
1059 struct type *element = TYPE_TARGET_TYPE (type);
1060
1061 if (TYPE_LENGTH (element) != 1)
1062 {
1063 ax_const_l (ax, TYPE_LENGTH (element));
1064 ax_simple (ax, op);
1065 }
1066 }
1067
1068
1069 /* Generate code for pointer arithmetic PTR + INT. */
1070 static void
1071 gen_ptradd (struct agent_expr *ax, struct axs_value *value,
1072 struct axs_value *value1, struct axs_value *value2)
1073 {
1074 gdb_assert (pointer_type (value1->type));
1075 gdb_assert (TYPE_CODE (value2->type) == TYPE_CODE_INT);
1076
1077 gen_scale (ax, aop_mul, value1->type);
1078 ax_simple (ax, aop_add);
1079 gen_extend (ax, value1->type); /* Catch overflow. */
1080 value->type = value1->type;
1081 value->kind = axs_rvalue;
1082 }
1083
1084
1085 /* Generate code for pointer arithmetic PTR - INT. */
1086 static void
1087 gen_ptrsub (struct agent_expr *ax, struct axs_value *value,
1088 struct axs_value *value1, struct axs_value *value2)
1089 {
1090 gdb_assert (pointer_type (value1->type));
1091 gdb_assert (TYPE_CODE (value2->type) == TYPE_CODE_INT);
1092
1093 gen_scale (ax, aop_mul, value1->type);
1094 ax_simple (ax, aop_sub);
1095 gen_extend (ax, value1->type); /* Catch overflow. */
1096 value->type = value1->type;
1097 value->kind = axs_rvalue;
1098 }
1099
1100
1101 /* Generate code for pointer arithmetic PTR - PTR. */
1102 static void
1103 gen_ptrdiff (struct agent_expr *ax, struct axs_value *value,
1104 struct axs_value *value1, struct axs_value *value2,
1105 struct type *result_type)
1106 {
1107 gdb_assert (pointer_type (value1->type));
1108 gdb_assert (pointer_type (value2->type));
1109
1110 if (TYPE_LENGTH (TYPE_TARGET_TYPE (value1->type))
1111 != TYPE_LENGTH (TYPE_TARGET_TYPE (value2->type)))
1112 error (_("\
1113 First argument of `-' is a pointer, but second argument is neither\n\
1114 an integer nor a pointer of the same type."));
1115
1116 ax_simple (ax, aop_sub);
1117 gen_scale (ax, aop_div_unsigned, value1->type);
1118 value->type = result_type;
1119 value->kind = axs_rvalue;
1120 }
1121
1122 static void
1123 gen_equal (struct agent_expr *ax, struct axs_value *value,
1124 struct axs_value *value1, struct axs_value *value2,
1125 struct type *result_type)
1126 {
1127 if (pointer_type (value1->type) || pointer_type (value2->type))
1128 ax_simple (ax, aop_equal);
1129 else
1130 gen_binop (ax, value, value1, value2,
1131 aop_equal, aop_equal, 0, "equal");
1132 value->type = result_type;
1133 value->kind = axs_rvalue;
1134 }
1135
1136 static void
1137 gen_less (struct agent_expr *ax, struct axs_value *value,
1138 struct axs_value *value1, struct axs_value *value2,
1139 struct type *result_type)
1140 {
1141 if (pointer_type (value1->type) || pointer_type (value2->type))
1142 ax_simple (ax, aop_less_unsigned);
1143 else
1144 gen_binop (ax, value, value1, value2,
1145 aop_less_signed, aop_less_unsigned, 0, "less than");
1146 value->type = result_type;
1147 value->kind = axs_rvalue;
1148 }
1149
1150 /* Generate code for a binary operator that doesn't do pointer magic.
1151 We set VALUE to describe the result value; we assume VALUE1 and
1152 VALUE2 describe the two operands, and that they've undergone the
1153 usual binary conversions. MAY_CARRY should be non-zero iff the
1154 result needs to be extended. NAME is the English name of the
1155 operator, used in error messages */
1156 static void
1157 gen_binop (struct agent_expr *ax, struct axs_value *value,
1158 struct axs_value *value1, struct axs_value *value2,
1159 enum agent_op op, enum agent_op op_unsigned,
1160 int may_carry, const char *name)
1161 {
1162 /* We only handle INT op INT. */
1163 if ((TYPE_CODE (value1->type) != TYPE_CODE_INT)
1164 || (TYPE_CODE (value2->type) != TYPE_CODE_INT))
1165 error (_("Invalid combination of types in %s."), name);
1166
1167 ax_simple (ax,
1168 TYPE_UNSIGNED (value1->type) ? op_unsigned : op);
1169 if (may_carry)
1170 gen_extend (ax, value1->type); /* catch overflow */
1171 value->type = value1->type;
1172 value->kind = axs_rvalue;
1173 }
1174
1175
1176 static void
1177 gen_logical_not (struct agent_expr *ax, struct axs_value *value,
1178 struct type *result_type)
1179 {
1180 if (TYPE_CODE (value->type) != TYPE_CODE_INT
1181 && TYPE_CODE (value->type) != TYPE_CODE_PTR)
1182 error (_("Invalid type of operand to `!'."));
1183
1184 ax_simple (ax, aop_log_not);
1185 value->type = result_type;
1186 }
1187
1188
1189 static void
1190 gen_complement (struct agent_expr *ax, struct axs_value *value)
1191 {
1192 if (TYPE_CODE (value->type) != TYPE_CODE_INT)
1193 error (_("Invalid type of operand to `~'."));
1194
1195 ax_simple (ax, aop_bit_not);
1196 gen_extend (ax, value->type);
1197 }
1198 \f
1199
1200
1201 /* Generating bytecode from GDB expressions: * & . -> @ sizeof */
1202
1203 /* Dereference the value on the top of the stack. */
1204 static void
1205 gen_deref (struct axs_value *value)
1206 {
1207 /* The caller should check the type, because several operators use
1208 this, and we don't know what error message to generate. */
1209 if (!pointer_type (value->type))
1210 internal_error (__FILE__, __LINE__,
1211 _("gen_deref: expected a pointer"));
1212
1213 /* We've got an rvalue now, which is a pointer. We want to yield an
1214 lvalue, whose address is exactly that pointer. So we don't
1215 actually emit any code; we just change the type from "Pointer to
1216 T" to "T", and mark the value as an lvalue in memory. Leave it
1217 to the consumer to actually dereference it. */
1218 value->type = check_typedef (TYPE_TARGET_TYPE (value->type));
1219 if (TYPE_CODE (value->type) == TYPE_CODE_VOID)
1220 error (_("Attempt to dereference a generic pointer."));
1221 value->kind = ((TYPE_CODE (value->type) == TYPE_CODE_FUNC)
1222 ? axs_rvalue : axs_lvalue_memory);
1223 }
1224
1225
1226 /* Produce the address of the lvalue on the top of the stack. */
1227 static void
1228 gen_address_of (struct axs_value *value)
1229 {
1230 /* Special case for taking the address of a function. The ANSI
1231 standard describes this as a special case, too, so this
1232 arrangement is not without motivation. */
1233 if (TYPE_CODE (value->type) == TYPE_CODE_FUNC)
1234 /* The value's already an rvalue on the stack, so we just need to
1235 change the type. */
1236 value->type = lookup_pointer_type (value->type);
1237 else
1238 switch (value->kind)
1239 {
1240 case axs_rvalue:
1241 error (_("Operand of `&' is an rvalue, which has no address."));
1242
1243 case axs_lvalue_register:
1244 error (_("Operand of `&' is in a register, and has no address."));
1245
1246 case axs_lvalue_memory:
1247 value->kind = axs_rvalue;
1248 value->type = lookup_pointer_type (value->type);
1249 break;
1250 }
1251 }
1252
1253 /* Generate code to push the value of a bitfield of a structure whose
1254 address is on the top of the stack. START and END give the
1255 starting and one-past-ending *bit* numbers of the field within the
1256 structure. */
1257 static void
1258 gen_bitfield_ref (struct agent_expr *ax, struct axs_value *value,
1259 struct type *type, int start, int end)
1260 {
1261 /* Note that ops[i] fetches 8 << i bits. */
1262 static enum agent_op ops[]
1263 = {aop_ref8, aop_ref16, aop_ref32, aop_ref64};
1264 static int num_ops = (sizeof (ops) / sizeof (ops[0]));
1265
1266 /* We don't want to touch any byte that the bitfield doesn't
1267 actually occupy; we shouldn't make any accesses we're not
1268 explicitly permitted to. We rely here on the fact that the
1269 bytecode `ref' operators work on unaligned addresses.
1270
1271 It takes some fancy footwork to get the stack to work the way
1272 we'd like. Say we're retrieving a bitfield that requires three
1273 fetches. Initially, the stack just contains the address:
1274 addr
1275 For the first fetch, we duplicate the address
1276 addr addr
1277 then add the byte offset, do the fetch, and shift and mask as
1278 needed, yielding a fragment of the value, properly aligned for
1279 the final bitwise or:
1280 addr frag1
1281 then we swap, and repeat the process:
1282 frag1 addr --- address on top
1283 frag1 addr addr --- duplicate it
1284 frag1 addr frag2 --- get second fragment
1285 frag1 frag2 addr --- swap again
1286 frag1 frag2 frag3 --- get third fragment
1287 Notice that, since the third fragment is the last one, we don't
1288 bother duplicating the address this time. Now we have all the
1289 fragments on the stack, and we can simply `or' them together,
1290 yielding the final value of the bitfield. */
1291
1292 /* The first and one-after-last bits in the field, but rounded down
1293 and up to byte boundaries. */
1294 int bound_start = (start / TARGET_CHAR_BIT) * TARGET_CHAR_BIT;
1295 int bound_end = (((end + TARGET_CHAR_BIT - 1)
1296 / TARGET_CHAR_BIT)
1297 * TARGET_CHAR_BIT);
1298
1299 /* current bit offset within the structure */
1300 int offset;
1301
1302 /* The index in ops of the opcode we're considering. */
1303 int op;
1304
1305 /* The number of fragments we generated in the process. Probably
1306 equal to the number of `one' bits in bytesize, but who cares? */
1307 int fragment_count;
1308
1309 /* Dereference any typedefs. */
1310 type = check_typedef (type);
1311
1312 /* Can we fetch the number of bits requested at all? */
1313 if ((end - start) > ((1 << num_ops) * 8))
1314 internal_error (__FILE__, __LINE__,
1315 _("gen_bitfield_ref: bitfield too wide"));
1316
1317 /* Note that we know here that we only need to try each opcode once.
1318 That may not be true on machines with weird byte sizes. */
1319 offset = bound_start;
1320 fragment_count = 0;
1321 for (op = num_ops - 1; op >= 0; op--)
1322 {
1323 /* number of bits that ops[op] would fetch */
1324 int op_size = 8 << op;
1325
1326 /* The stack at this point, from bottom to top, contains zero or
1327 more fragments, then the address. */
1328
1329 /* Does this fetch fit within the bitfield? */
1330 if (offset + op_size <= bound_end)
1331 {
1332 /* Is this the last fragment? */
1333 int last_frag = (offset + op_size == bound_end);
1334
1335 if (!last_frag)
1336 ax_simple (ax, aop_dup); /* keep a copy of the address */
1337
1338 /* Add the offset. */
1339 gen_offset (ax, offset / TARGET_CHAR_BIT);
1340
1341 if (ax->tracing)
1342 {
1343 /* Record the area of memory we're about to fetch. */
1344 ax_trace_quick (ax, op_size / TARGET_CHAR_BIT);
1345 }
1346
1347 /* Perform the fetch. */
1348 ax_simple (ax, ops[op]);
1349
1350 /* Shift the bits we have to their proper position.
1351 gen_left_shift will generate right shifts when the operand
1352 is negative.
1353
1354 A big-endian field diagram to ponder:
1355 byte 0 byte 1 byte 2 byte 3 byte 4 byte 5 byte 6 byte 7
1356 +------++------++------++------++------++------++------++------+
1357 xxxxAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCxxxxxxxxxxx
1358 ^ ^ ^ ^
1359 bit number 16 32 48 53
1360 These are bit numbers as supplied by GDB. Note that the
1361 bit numbers run from right to left once you've fetched the
1362 value!
1363
1364 A little-endian field diagram to ponder:
1365 byte 7 byte 6 byte 5 byte 4 byte 3 byte 2 byte 1 byte 0
1366 +------++------++------++------++------++------++------++------+
1367 xxxxxxxxxxxAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCxxxx
1368 ^ ^ ^ ^ ^
1369 bit number 48 32 16 4 0
1370
1371 In both cases, the most significant end is on the left
1372 (i.e. normal numeric writing order), which means that you
1373 don't go crazy thinking about `left' and `right' shifts.
1374
1375 We don't have to worry about masking yet:
1376 - If they contain garbage off the least significant end, then we
1377 must be looking at the low end of the field, and the right
1378 shift will wipe them out.
1379 - If they contain garbage off the most significant end, then we
1380 must be looking at the most significant end of the word, and
1381 the sign/zero extension will wipe them out.
1382 - If we're in the interior of the word, then there is no garbage
1383 on either end, because the ref operators zero-extend. */
1384 if (gdbarch_byte_order (ax->gdbarch) == BFD_ENDIAN_BIG)
1385 gen_left_shift (ax, end - (offset + op_size));
1386 else
1387 gen_left_shift (ax, offset - start);
1388
1389 if (!last_frag)
1390 /* Bring the copy of the address up to the top. */
1391 ax_simple (ax, aop_swap);
1392
1393 offset += op_size;
1394 fragment_count++;
1395 }
1396 }
1397
1398 /* Generate enough bitwise `or' operations to combine all the
1399 fragments we left on the stack. */
1400 while (fragment_count-- > 1)
1401 ax_simple (ax, aop_bit_or);
1402
1403 /* Sign- or zero-extend the value as appropriate. */
1404 ((TYPE_UNSIGNED (type) ? ax_zero_ext : ax_ext) (ax, end - start));
1405
1406 /* This is *not* an lvalue. Ugh. */
1407 value->kind = axs_rvalue;
1408 value->type = type;
1409 }
1410
1411 /* Generate bytecodes for field number FIELDNO of type TYPE. OFFSET
1412 is an accumulated offset (in bytes), will be nonzero for objects
1413 embedded in other objects, like C++ base classes. Behavior should
1414 generally follow value_primitive_field. */
1415
1416 static void
1417 gen_primitive_field (struct agent_expr *ax, struct axs_value *value,
1418 int offset, int fieldno, struct type *type)
1419 {
1420 /* Is this a bitfield? */
1421 if (TYPE_FIELD_PACKED (type, fieldno))
1422 gen_bitfield_ref (ax, value, TYPE_FIELD_TYPE (type, fieldno),
1423 (offset * TARGET_CHAR_BIT
1424 + TYPE_FIELD_BITPOS (type, fieldno)),
1425 (offset * TARGET_CHAR_BIT
1426 + TYPE_FIELD_BITPOS (type, fieldno)
1427 + TYPE_FIELD_BITSIZE (type, fieldno)));
1428 else
1429 {
1430 gen_offset (ax, offset
1431 + TYPE_FIELD_BITPOS (type, fieldno) / TARGET_CHAR_BIT);
1432 value->kind = axs_lvalue_memory;
1433 value->type = TYPE_FIELD_TYPE (type, fieldno);
1434 }
1435 }
1436
1437 /* Search for the given field in either the given type or one of its
1438 base classes. Return 1 if found, 0 if not. */
1439
1440 static int
1441 gen_struct_ref_recursive (struct agent_expr *ax, struct axs_value *value,
1442 const char *field, int offset, struct type *type)
1443 {
1444 int i, rslt;
1445 int nbases = TYPE_N_BASECLASSES (type);
1446
1447 type = check_typedef (type);
1448
1449 for (i = TYPE_NFIELDS (type) - 1; i >= nbases; i--)
1450 {
1451 const char *this_name = TYPE_FIELD_NAME (type, i);
1452
1453 if (this_name)
1454 {
1455 if (strcmp (field, this_name) == 0)
1456 {
1457 /* Note that bytecodes for the struct's base (aka
1458 "this") will have been generated already, which will
1459 be unnecessary but not harmful if the static field is
1460 being handled as a global. */
1461 if (field_is_static (&TYPE_FIELD (type, i)))
1462 {
1463 gen_static_field (ax, value, type, i);
1464 if (value->optimized_out)
1465 error (_("static field `%s' has been "
1466 "optimized out, cannot use"),
1467 field);
1468 return 1;
1469 }
1470
1471 gen_primitive_field (ax, value, offset, i, type);
1472 return 1;
1473 }
1474 #if 0 /* is this right? */
1475 if (this_name[0] == '\0')
1476 internal_error (__FILE__, __LINE__,
1477 _("find_field: anonymous unions not supported"));
1478 #endif
1479 }
1480 }
1481
1482 /* Now scan through base classes recursively. */
1483 for (i = 0; i < nbases; i++)
1484 {
1485 struct type *basetype = check_typedef (TYPE_BASECLASS (type, i));
1486
1487 rslt = gen_struct_ref_recursive (ax, value, field,
1488 offset + TYPE_BASECLASS_BITPOS (type, i)
1489 / TARGET_CHAR_BIT,
1490 basetype);
1491 if (rslt)
1492 return 1;
1493 }
1494
1495 /* Not found anywhere, flag so caller can complain. */
1496 return 0;
1497 }
1498
1499 /* Generate code to reference the member named FIELD of a structure or
1500 union. The top of the stack, as described by VALUE, should have
1501 type (pointer to a)* struct/union. OPERATOR_NAME is the name of
1502 the operator being compiled, and OPERAND_NAME is the kind of thing
1503 it operates on; we use them in error messages. */
1504 static void
1505 gen_struct_ref (struct agent_expr *ax, struct axs_value *value,
1506 const char *field, const char *operator_name,
1507 const char *operand_name)
1508 {
1509 struct type *type;
1510 int found;
1511
1512 /* Follow pointers until we reach a non-pointer. These aren't the C
1513 semantics, but they're what the normal GDB evaluator does, so we
1514 should at least be consistent. */
1515 while (pointer_type (value->type))
1516 {
1517 require_rvalue (ax, value);
1518 gen_deref (value);
1519 }
1520 type = check_typedef (value->type);
1521
1522 /* This must yield a structure or a union. */
1523 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1524 && TYPE_CODE (type) != TYPE_CODE_UNION)
1525 error (_("The left operand of `%s' is not a %s."),
1526 operator_name, operand_name);
1527
1528 /* And it must be in memory; we don't deal with structure rvalues,
1529 or structures living in registers. */
1530 if (value->kind != axs_lvalue_memory)
1531 error (_("Structure does not live in memory."));
1532
1533 /* Search through fields and base classes recursively. */
1534 found = gen_struct_ref_recursive (ax, value, field, 0, type);
1535
1536 if (!found)
1537 error (_("Couldn't find member named `%s' in struct/union/class `%s'"),
1538 field, TYPE_TAG_NAME (type));
1539 }
1540
1541 static int
1542 gen_namespace_elt (struct agent_expr *ax, struct axs_value *value,
1543 const struct type *curtype, char *name);
1544 static int
1545 gen_maybe_namespace_elt (struct agent_expr *ax, struct axs_value *value,
1546 const struct type *curtype, char *name);
1547
1548 static void
1549 gen_static_field (struct agent_expr *ax, struct axs_value *value,
1550 struct type *type, int fieldno)
1551 {
1552 if (TYPE_FIELD_LOC_KIND (type, fieldno) == FIELD_LOC_KIND_PHYSADDR)
1553 {
1554 ax_const_l (ax, TYPE_FIELD_STATIC_PHYSADDR (type, fieldno));
1555 value->kind = axs_lvalue_memory;
1556 value->type = TYPE_FIELD_TYPE (type, fieldno);
1557 value->optimized_out = 0;
1558 }
1559 else
1560 {
1561 const char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (type, fieldno);
1562 struct symbol *sym = lookup_symbol (phys_name, 0, VAR_DOMAIN, 0).symbol;
1563
1564 if (sym)
1565 {
1566 gen_var_ref (ax, value, sym);
1567
1568 /* Don't error if the value was optimized out, we may be
1569 scanning all static fields and just want to pass over this
1570 and continue with the rest. */
1571 }
1572 else
1573 {
1574 /* Silently assume this was optimized out; class printing
1575 will let the user know why the data is missing. */
1576 value->optimized_out = 1;
1577 }
1578 }
1579 }
1580
1581 static int
1582 gen_struct_elt_for_reference (struct agent_expr *ax, struct axs_value *value,
1583 struct type *type, char *fieldname)
1584 {
1585 struct type *t = type;
1586 int i;
1587
1588 if (TYPE_CODE (t) != TYPE_CODE_STRUCT
1589 && TYPE_CODE (t) != TYPE_CODE_UNION)
1590 internal_error (__FILE__, __LINE__,
1591 _("non-aggregate type to gen_struct_elt_for_reference"));
1592
1593 for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); i--)
1594 {
1595 const char *t_field_name = TYPE_FIELD_NAME (t, i);
1596
1597 if (t_field_name && strcmp (t_field_name, fieldname) == 0)
1598 {
1599 if (field_is_static (&TYPE_FIELD (t, i)))
1600 {
1601 gen_static_field (ax, value, t, i);
1602 if (value->optimized_out)
1603 error (_("static field `%s' has been "
1604 "optimized out, cannot use"),
1605 fieldname);
1606 return 1;
1607 }
1608 if (TYPE_FIELD_PACKED (t, i))
1609 error (_("pointers to bitfield members not allowed"));
1610
1611 /* FIXME we need a way to do "want_address" equivalent */
1612
1613 error (_("Cannot reference non-static field \"%s\""), fieldname);
1614 }
1615 }
1616
1617 /* FIXME add other scoped-reference cases here */
1618
1619 /* Do a last-ditch lookup. */
1620 return gen_maybe_namespace_elt (ax, value, type, fieldname);
1621 }
1622
1623 /* C++: Return the member NAME of the namespace given by the type
1624 CURTYPE. */
1625
1626 static int
1627 gen_namespace_elt (struct agent_expr *ax, struct axs_value *value,
1628 const struct type *curtype, char *name)
1629 {
1630 int found = gen_maybe_namespace_elt (ax, value, curtype, name);
1631
1632 if (!found)
1633 error (_("No symbol \"%s\" in namespace \"%s\"."),
1634 name, TYPE_TAG_NAME (curtype));
1635
1636 return found;
1637 }
1638
1639 /* A helper function used by value_namespace_elt and
1640 value_struct_elt_for_reference. It looks up NAME inside the
1641 context CURTYPE; this works if CURTYPE is a namespace or if CURTYPE
1642 is a class and NAME refers to a type in CURTYPE itself (as opposed
1643 to, say, some base class of CURTYPE). */
1644
1645 static int
1646 gen_maybe_namespace_elt (struct agent_expr *ax, struct axs_value *value,
1647 const struct type *curtype, char *name)
1648 {
1649 const char *namespace_name = TYPE_TAG_NAME (curtype);
1650 struct block_symbol sym;
1651
1652 sym = cp_lookup_symbol_namespace (namespace_name, name,
1653 block_for_pc (ax->scope),
1654 VAR_DOMAIN);
1655
1656 if (sym.symbol == NULL)
1657 return 0;
1658
1659 gen_var_ref (ax, value, sym.symbol);
1660
1661 if (value->optimized_out)
1662 error (_("`%s' has been optimized out, cannot use"),
1663 SYMBOL_PRINT_NAME (sym.symbol));
1664
1665 return 1;
1666 }
1667
1668
1669 static int
1670 gen_aggregate_elt_ref (struct agent_expr *ax, struct axs_value *value,
1671 struct type *type, char *field)
1672 {
1673 switch (TYPE_CODE (type))
1674 {
1675 case TYPE_CODE_STRUCT:
1676 case TYPE_CODE_UNION:
1677 return gen_struct_elt_for_reference (ax, value, type, field);
1678 break;
1679 case TYPE_CODE_NAMESPACE:
1680 return gen_namespace_elt (ax, value, type, field);
1681 break;
1682 default:
1683 internal_error (__FILE__, __LINE__,
1684 _("non-aggregate type in gen_aggregate_elt_ref"));
1685 }
1686
1687 return 0;
1688 }
1689
1690 /* Generate code for GDB's magical `repeat' operator.
1691 LVALUE @ INT creates an array INT elements long, and whose elements
1692 have the same type as LVALUE, located in memory so that LVALUE is
1693 its first element. For example, argv[0]@argc gives you the array
1694 of command-line arguments.
1695
1696 Unfortunately, because we have to know the types before we actually
1697 have a value for the expression, we can't implement this perfectly
1698 without changing the type system, having values that occupy two
1699 stack slots, doing weird things with sizeof, etc. So we require
1700 the right operand to be a constant expression. */
1701 static void
1702 gen_repeat (struct expression *exp, union exp_element **pc,
1703 struct agent_expr *ax, struct axs_value *value)
1704 {
1705 struct axs_value value1;
1706
1707 /* We don't want to turn this into an rvalue, so no conversions
1708 here. */
1709 gen_expr (exp, pc, ax, &value1);
1710 if (value1.kind != axs_lvalue_memory)
1711 error (_("Left operand of `@' must be an object in memory."));
1712
1713 /* Evaluate the length; it had better be a constant. */
1714 {
1715 struct value *v = const_expr (pc);
1716 int length;
1717
1718 if (!v)
1719 error (_("Right operand of `@' must be a "
1720 "constant, in agent expressions."));
1721 if (TYPE_CODE (value_type (v)) != TYPE_CODE_INT)
1722 error (_("Right operand of `@' must be an integer."));
1723 length = value_as_long (v);
1724 if (length <= 0)
1725 error (_("Right operand of `@' must be positive."));
1726
1727 /* The top of the stack is already the address of the object, so
1728 all we need to do is frob the type of the lvalue. */
1729 {
1730 /* FIXME-type-allocation: need a way to free this type when we are
1731 done with it. */
1732 struct type *array
1733 = lookup_array_range_type (value1.type, 0, length - 1);
1734
1735 value->kind = axs_lvalue_memory;
1736 value->type = array;
1737 }
1738 }
1739 }
1740
1741
1742 /* Emit code for the `sizeof' operator.
1743 *PC should point at the start of the operand expression; we advance it
1744 to the first instruction after the operand. */
1745 static void
1746 gen_sizeof (struct expression *exp, union exp_element **pc,
1747 struct agent_expr *ax, struct axs_value *value,
1748 struct type *size_type)
1749 {
1750 /* We don't care about the value of the operand expression; we only
1751 care about its type. However, in the current arrangement, the
1752 only way to find an expression's type is to generate code for it.
1753 So we generate code for the operand, and then throw it away,
1754 replacing it with code that simply pushes its size. */
1755 int start = ax->len;
1756
1757 gen_expr (exp, pc, ax, value);
1758
1759 /* Throw away the code we just generated. */
1760 ax->len = start;
1761
1762 ax_const_l (ax, TYPE_LENGTH (value->type));
1763 value->kind = axs_rvalue;
1764 value->type = size_type;
1765 }
1766 \f
1767
1768 /* Generating bytecode from GDB expressions: general recursive thingy */
1769
1770 /* XXX: i18n */
1771 /* A gen_expr function written by a Gen-X'er guy.
1772 Append code for the subexpression of EXPR starting at *POS_P to AX. */
1773 void
1774 gen_expr (struct expression *exp, union exp_element **pc,
1775 struct agent_expr *ax, struct axs_value *value)
1776 {
1777 /* Used to hold the descriptions of operand expressions. */
1778 struct axs_value value1, value2, value3;
1779 enum exp_opcode op = (*pc)[0].opcode, op2;
1780 int if1, go1, if2, go2, end;
1781 struct type *int_type = builtin_type (ax->gdbarch)->builtin_int;
1782
1783 /* If we're looking at a constant expression, just push its value. */
1784 {
1785 struct value *v = maybe_const_expr (pc);
1786
1787 if (v)
1788 {
1789 ax_const_l (ax, value_as_long (v));
1790 value->kind = axs_rvalue;
1791 value->type = check_typedef (value_type (v));
1792 return;
1793 }
1794 }
1795
1796 /* Otherwise, go ahead and generate code for it. */
1797 switch (op)
1798 {
1799 /* Binary arithmetic operators. */
1800 case BINOP_ADD:
1801 case BINOP_SUB:
1802 case BINOP_MUL:
1803 case BINOP_DIV:
1804 case BINOP_REM:
1805 case BINOP_LSH:
1806 case BINOP_RSH:
1807 case BINOP_SUBSCRIPT:
1808 case BINOP_BITWISE_AND:
1809 case BINOP_BITWISE_IOR:
1810 case BINOP_BITWISE_XOR:
1811 case BINOP_EQUAL:
1812 case BINOP_NOTEQUAL:
1813 case BINOP_LESS:
1814 case BINOP_GTR:
1815 case BINOP_LEQ:
1816 case BINOP_GEQ:
1817 (*pc)++;
1818 gen_expr (exp, pc, ax, &value1);
1819 gen_usual_unary (ax, &value1);
1820 gen_expr_binop_rest (exp, op, pc, ax, value, &value1, &value2);
1821 break;
1822
1823 case BINOP_LOGICAL_AND:
1824 (*pc)++;
1825 /* Generate the obvious sequence of tests and jumps. */
1826 gen_expr (exp, pc, ax, &value1);
1827 gen_usual_unary (ax, &value1);
1828 if1 = ax_goto (ax, aop_if_goto);
1829 go1 = ax_goto (ax, aop_goto);
1830 ax_label (ax, if1, ax->len);
1831 gen_expr (exp, pc, ax, &value2);
1832 gen_usual_unary (ax, &value2);
1833 if2 = ax_goto (ax, aop_if_goto);
1834 go2 = ax_goto (ax, aop_goto);
1835 ax_label (ax, if2, ax->len);
1836 ax_const_l (ax, 1);
1837 end = ax_goto (ax, aop_goto);
1838 ax_label (ax, go1, ax->len);
1839 ax_label (ax, go2, ax->len);
1840 ax_const_l (ax, 0);
1841 ax_label (ax, end, ax->len);
1842 value->kind = axs_rvalue;
1843 value->type = int_type;
1844 break;
1845
1846 case BINOP_LOGICAL_OR:
1847 (*pc)++;
1848 /* Generate the obvious sequence of tests and jumps. */
1849 gen_expr (exp, pc, ax, &value1);
1850 gen_usual_unary (ax, &value1);
1851 if1 = ax_goto (ax, aop_if_goto);
1852 gen_expr (exp, pc, ax, &value2);
1853 gen_usual_unary (ax, &value2);
1854 if2 = ax_goto (ax, aop_if_goto);
1855 ax_const_l (ax, 0);
1856 end = ax_goto (ax, aop_goto);
1857 ax_label (ax, if1, ax->len);
1858 ax_label (ax, if2, ax->len);
1859 ax_const_l (ax, 1);
1860 ax_label (ax, end, ax->len);
1861 value->kind = axs_rvalue;
1862 value->type = int_type;
1863 break;
1864
1865 case TERNOP_COND:
1866 (*pc)++;
1867 gen_expr (exp, pc, ax, &value1);
1868 gen_usual_unary (ax, &value1);
1869 /* For (A ? B : C), it's easiest to generate subexpression
1870 bytecodes in order, but if_goto jumps on true, so we invert
1871 the sense of A. Then we can do B by dropping through, and
1872 jump to do C. */
1873 gen_logical_not (ax, &value1, int_type);
1874 if1 = ax_goto (ax, aop_if_goto);
1875 gen_expr (exp, pc, ax, &value2);
1876 gen_usual_unary (ax, &value2);
1877 end = ax_goto (ax, aop_goto);
1878 ax_label (ax, if1, ax->len);
1879 gen_expr (exp, pc, ax, &value3);
1880 gen_usual_unary (ax, &value3);
1881 ax_label (ax, end, ax->len);
1882 /* This is arbitary - what if B and C are incompatible types? */
1883 value->type = value2.type;
1884 value->kind = value2.kind;
1885 break;
1886
1887 case BINOP_ASSIGN:
1888 (*pc)++;
1889 if ((*pc)[0].opcode == OP_INTERNALVAR)
1890 {
1891 char *name = internalvar_name ((*pc)[1].internalvar);
1892 struct trace_state_variable *tsv;
1893
1894 (*pc) += 3;
1895 gen_expr (exp, pc, ax, value);
1896 tsv = find_trace_state_variable (name);
1897 if (tsv)
1898 {
1899 ax_tsv (ax, aop_setv, tsv->number);
1900 if (ax->tracing)
1901 ax_tsv (ax, aop_tracev, tsv->number);
1902 }
1903 else
1904 error (_("$%s is not a trace state variable, "
1905 "may not assign to it"), name);
1906 }
1907 else
1908 error (_("May only assign to trace state variables"));
1909 break;
1910
1911 case BINOP_ASSIGN_MODIFY:
1912 (*pc)++;
1913 op2 = (*pc)[0].opcode;
1914 (*pc)++;
1915 (*pc)++;
1916 if ((*pc)[0].opcode == OP_INTERNALVAR)
1917 {
1918 char *name = internalvar_name ((*pc)[1].internalvar);
1919 struct trace_state_variable *tsv;
1920
1921 (*pc) += 3;
1922 tsv = find_trace_state_variable (name);
1923 if (tsv)
1924 {
1925 /* The tsv will be the left half of the binary operation. */
1926 ax_tsv (ax, aop_getv, tsv->number);
1927 if (ax->tracing)
1928 ax_tsv (ax, aop_tracev, tsv->number);
1929 /* Trace state variables are always 64-bit integers. */
1930 value1.kind = axs_rvalue;
1931 value1.type = builtin_type (ax->gdbarch)->builtin_long_long;
1932 /* Now do right half of expression. */
1933 gen_expr_binop_rest (exp, op2, pc, ax, value, &value1, &value2);
1934 /* We have a result of the binary op, set the tsv. */
1935 ax_tsv (ax, aop_setv, tsv->number);
1936 if (ax->tracing)
1937 ax_tsv (ax, aop_tracev, tsv->number);
1938 }
1939 else
1940 error (_("$%s is not a trace state variable, "
1941 "may not assign to it"), name);
1942 }
1943 else
1944 error (_("May only assign to trace state variables"));
1945 break;
1946
1947 /* Note that we need to be a little subtle about generating code
1948 for comma. In C, we can do some optimizations here because
1949 we know the left operand is only being evaluated for effect.
1950 However, if the tracing kludge is in effect, then we always
1951 need to evaluate the left hand side fully, so that all the
1952 variables it mentions get traced. */
1953 case BINOP_COMMA:
1954 (*pc)++;
1955 gen_expr (exp, pc, ax, &value1);
1956 /* Don't just dispose of the left operand. We might be tracing,
1957 in which case we want to emit code to trace it if it's an
1958 lvalue. */
1959 gen_traced_pop (ax, &value1);
1960 gen_expr (exp, pc, ax, value);
1961 /* It's the consumer's responsibility to trace the right operand. */
1962 break;
1963
1964 case OP_LONG: /* some integer constant */
1965 {
1966 struct type *type = (*pc)[1].type;
1967 LONGEST k = (*pc)[2].longconst;
1968
1969 (*pc) += 4;
1970 gen_int_literal (ax, value, k, type);
1971 }
1972 break;
1973
1974 case OP_VAR_VALUE:
1975 gen_var_ref (ax, value, (*pc)[2].symbol);
1976
1977 if (value->optimized_out)
1978 error (_("`%s' has been optimized out, cannot use"),
1979 SYMBOL_PRINT_NAME ((*pc)[2].symbol));
1980
1981 (*pc) += 4;
1982 break;
1983
1984 case OP_VAR_MSYM_VALUE:
1985 gen_msym_var_ref (ax, value, (*pc)[2].msymbol, (*pc)[1].objfile);
1986 (*pc) += 4;
1987 break;
1988
1989 case OP_REGISTER:
1990 {
1991 const char *name = &(*pc)[2].string;
1992 int reg;
1993
1994 (*pc) += 4 + BYTES_TO_EXP_ELEM ((*pc)[1].longconst + 1);
1995 reg = user_reg_map_name_to_regnum (ax->gdbarch, name, strlen (name));
1996 if (reg == -1)
1997 internal_error (__FILE__, __LINE__,
1998 _("Register $%s not available"), name);
1999 /* No support for tracing user registers yet. */
2000 if (reg >= gdbarch_num_regs (ax->gdbarch)
2001 + gdbarch_num_pseudo_regs (ax->gdbarch))
2002 error (_("'%s' is a user-register; "
2003 "GDB cannot yet trace user-register contents."),
2004 name);
2005 value->kind = axs_lvalue_register;
2006 value->u.reg = reg;
2007 value->type = register_type (ax->gdbarch, reg);
2008 }
2009 break;
2010
2011 case OP_INTERNALVAR:
2012 {
2013 struct internalvar *var = (*pc)[1].internalvar;
2014 const char *name = internalvar_name (var);
2015 struct trace_state_variable *tsv;
2016
2017 (*pc) += 3;
2018 tsv = find_trace_state_variable (name);
2019 if (tsv)
2020 {
2021 ax_tsv (ax, aop_getv, tsv->number);
2022 if (ax->tracing)
2023 ax_tsv (ax, aop_tracev, tsv->number);
2024 /* Trace state variables are always 64-bit integers. */
2025 value->kind = axs_rvalue;
2026 value->type = builtin_type (ax->gdbarch)->builtin_long_long;
2027 }
2028 else if (! compile_internalvar_to_ax (var, ax, value))
2029 error (_("$%s is not a trace state variable; GDB agent "
2030 "expressions cannot use convenience variables."), name);
2031 }
2032 break;
2033
2034 /* Weirdo operator: see comments for gen_repeat for details. */
2035 case BINOP_REPEAT:
2036 /* Note that gen_repeat handles its own argument evaluation. */
2037 (*pc)++;
2038 gen_repeat (exp, pc, ax, value);
2039 break;
2040
2041 case UNOP_CAST:
2042 {
2043 struct type *type = (*pc)[1].type;
2044
2045 (*pc) += 3;
2046 gen_expr (exp, pc, ax, value);
2047 gen_cast (ax, value, type);
2048 }
2049 break;
2050
2051 case UNOP_CAST_TYPE:
2052 {
2053 int offset;
2054 struct value *val;
2055 struct type *type;
2056
2057 ++*pc;
2058 offset = *pc - exp->elts;
2059 val = evaluate_subexp (NULL, exp, &offset, EVAL_AVOID_SIDE_EFFECTS);
2060 type = value_type (val);
2061 *pc = &exp->elts[offset];
2062
2063 gen_expr (exp, pc, ax, value);
2064 gen_cast (ax, value, type);
2065 }
2066 break;
2067
2068 case UNOP_MEMVAL:
2069 {
2070 struct type *type = check_typedef ((*pc)[1].type);
2071
2072 (*pc) += 3;
2073 gen_expr (exp, pc, ax, value);
2074
2075 /* If we have an axs_rvalue or an axs_lvalue_memory, then we
2076 already have the right value on the stack. For
2077 axs_lvalue_register, we must convert. */
2078 if (value->kind == axs_lvalue_register)
2079 require_rvalue (ax, value);
2080
2081 value->type = type;
2082 value->kind = axs_lvalue_memory;
2083 }
2084 break;
2085
2086 case UNOP_MEMVAL_TYPE:
2087 {
2088 int offset;
2089 struct value *val;
2090 struct type *type;
2091
2092 ++*pc;
2093 offset = *pc - exp->elts;
2094 val = evaluate_subexp (NULL, exp, &offset, EVAL_AVOID_SIDE_EFFECTS);
2095 type = value_type (val);
2096 *pc = &exp->elts[offset];
2097
2098 gen_expr (exp, pc, ax, value);
2099
2100 /* If we have an axs_rvalue or an axs_lvalue_memory, then we
2101 already have the right value on the stack. For
2102 axs_lvalue_register, we must convert. */
2103 if (value->kind == axs_lvalue_register)
2104 require_rvalue (ax, value);
2105
2106 value->type = type;
2107 value->kind = axs_lvalue_memory;
2108 }
2109 break;
2110
2111 case UNOP_PLUS:
2112 (*pc)++;
2113 /* + FOO is equivalent to 0 + FOO, which can be optimized. */
2114 gen_expr (exp, pc, ax, value);
2115 gen_usual_unary (ax, value);
2116 break;
2117
2118 case UNOP_NEG:
2119 (*pc)++;
2120 /* -FOO is equivalent to 0 - FOO. */
2121 gen_int_literal (ax, &value1, 0,
2122 builtin_type (ax->gdbarch)->builtin_int);
2123 gen_usual_unary (ax, &value1); /* shouldn't do much */
2124 gen_expr (exp, pc, ax, &value2);
2125 gen_usual_unary (ax, &value2);
2126 gen_usual_arithmetic (ax, &value1, &value2);
2127 gen_binop (ax, value, &value1, &value2, aop_sub, aop_sub, 1, "negation");
2128 break;
2129
2130 case UNOP_LOGICAL_NOT:
2131 (*pc)++;
2132 gen_expr (exp, pc, ax, value);
2133 gen_usual_unary (ax, value);
2134 gen_logical_not (ax, value, int_type);
2135 break;
2136
2137 case UNOP_COMPLEMENT:
2138 (*pc)++;
2139 gen_expr (exp, pc, ax, value);
2140 gen_usual_unary (ax, value);
2141 gen_integral_promotions (ax, value);
2142 gen_complement (ax, value);
2143 break;
2144
2145 case UNOP_IND:
2146 (*pc)++;
2147 gen_expr (exp, pc, ax, value);
2148 gen_usual_unary (ax, value);
2149 if (!pointer_type (value->type))
2150 error (_("Argument of unary `*' is not a pointer."));
2151 gen_deref (value);
2152 break;
2153
2154 case UNOP_ADDR:
2155 (*pc)++;
2156 gen_expr (exp, pc, ax, value);
2157 gen_address_of (value);
2158 break;
2159
2160 case UNOP_SIZEOF:
2161 (*pc)++;
2162 /* Notice that gen_sizeof handles its own operand, unlike most
2163 of the other unary operator functions. This is because we
2164 have to throw away the code we generate. */
2165 gen_sizeof (exp, pc, ax, value,
2166 builtin_type (ax->gdbarch)->builtin_int);
2167 break;
2168
2169 case STRUCTOP_STRUCT:
2170 case STRUCTOP_PTR:
2171 {
2172 int length = (*pc)[1].longconst;
2173 char *name = &(*pc)[2].string;
2174
2175 (*pc) += 4 + BYTES_TO_EXP_ELEM (length + 1);
2176 gen_expr (exp, pc, ax, value);
2177 if (op == STRUCTOP_STRUCT)
2178 gen_struct_ref (ax, value, name, ".", "structure or union");
2179 else if (op == STRUCTOP_PTR)
2180 gen_struct_ref (ax, value, name, "->",
2181 "pointer to a structure or union");
2182 else
2183 /* If this `if' chain doesn't handle it, then the case list
2184 shouldn't mention it, and we shouldn't be here. */
2185 internal_error (__FILE__, __LINE__,
2186 _("gen_expr: unhandled struct case"));
2187 }
2188 break;
2189
2190 case OP_THIS:
2191 {
2192 struct symbol *sym, *func;
2193 const struct block *b;
2194 const struct language_defn *lang;
2195
2196 b = block_for_pc (ax->scope);
2197 func = block_linkage_function (b);
2198 lang = language_def (SYMBOL_LANGUAGE (func));
2199
2200 sym = lookup_language_this (lang, b).symbol;
2201 if (!sym)
2202 error (_("no `%s' found"), lang->la_name_of_this);
2203
2204 gen_var_ref (ax, value, sym);
2205
2206 if (value->optimized_out)
2207 error (_("`%s' has been optimized out, cannot use"),
2208 SYMBOL_PRINT_NAME (sym));
2209
2210 (*pc) += 2;
2211 }
2212 break;
2213
2214 case OP_SCOPE:
2215 {
2216 struct type *type = (*pc)[1].type;
2217 int length = longest_to_int ((*pc)[2].longconst);
2218 char *name = &(*pc)[3].string;
2219 int found;
2220
2221 found = gen_aggregate_elt_ref (ax, value, type, name);
2222 if (!found)
2223 error (_("There is no field named %s"), name);
2224 (*pc) += 5 + BYTES_TO_EXP_ELEM (length + 1);
2225 }
2226 break;
2227
2228 case OP_TYPE:
2229 case OP_TYPEOF:
2230 case OP_DECLTYPE:
2231 error (_("Attempt to use a type name as an expression."));
2232
2233 default:
2234 error (_("Unsupported operator %s (%d) in expression."),
2235 op_name (exp, op), op);
2236 }
2237 }
2238
2239 /* This handles the middle-to-right-side of code generation for binary
2240 expressions, which is shared between regular binary operations and
2241 assign-modify (+= and friends) expressions. */
2242
2243 static void
2244 gen_expr_binop_rest (struct expression *exp,
2245 enum exp_opcode op, union exp_element **pc,
2246 struct agent_expr *ax, struct axs_value *value,
2247 struct axs_value *value1, struct axs_value *value2)
2248 {
2249 struct type *int_type = builtin_type (ax->gdbarch)->builtin_int;
2250
2251 gen_expr (exp, pc, ax, value2);
2252 gen_usual_unary (ax, value2);
2253 gen_usual_arithmetic (ax, value1, value2);
2254 switch (op)
2255 {
2256 case BINOP_ADD:
2257 if (TYPE_CODE (value1->type) == TYPE_CODE_INT
2258 && pointer_type (value2->type))
2259 {
2260 /* Swap the values and proceed normally. */
2261 ax_simple (ax, aop_swap);
2262 gen_ptradd (ax, value, value2, value1);
2263 }
2264 else if (pointer_type (value1->type)
2265 && TYPE_CODE (value2->type) == TYPE_CODE_INT)
2266 gen_ptradd (ax, value, value1, value2);
2267 else
2268 gen_binop (ax, value, value1, value2,
2269 aop_add, aop_add, 1, "addition");
2270 break;
2271 case BINOP_SUB:
2272 if (pointer_type (value1->type)
2273 && TYPE_CODE (value2->type) == TYPE_CODE_INT)
2274 gen_ptrsub (ax,value, value1, value2);
2275 else if (pointer_type (value1->type)
2276 && pointer_type (value2->type))
2277 /* FIXME --- result type should be ptrdiff_t */
2278 gen_ptrdiff (ax, value, value1, value2,
2279 builtin_type (ax->gdbarch)->builtin_long);
2280 else
2281 gen_binop (ax, value, value1, value2,
2282 aop_sub, aop_sub, 1, "subtraction");
2283 break;
2284 case BINOP_MUL:
2285 gen_binop (ax, value, value1, value2,
2286 aop_mul, aop_mul, 1, "multiplication");
2287 break;
2288 case BINOP_DIV:
2289 gen_binop (ax, value, value1, value2,
2290 aop_div_signed, aop_div_unsigned, 1, "division");
2291 break;
2292 case BINOP_REM:
2293 gen_binop (ax, value, value1, value2,
2294 aop_rem_signed, aop_rem_unsigned, 1, "remainder");
2295 break;
2296 case BINOP_LSH:
2297 gen_binop (ax, value, value1, value2,
2298 aop_lsh, aop_lsh, 1, "left shift");
2299 break;
2300 case BINOP_RSH:
2301 gen_binop (ax, value, value1, value2,
2302 aop_rsh_signed, aop_rsh_unsigned, 1, "right shift");
2303 break;
2304 case BINOP_SUBSCRIPT:
2305 {
2306 struct type *type;
2307
2308 if (binop_types_user_defined_p (op, value1->type, value2->type))
2309 {
2310 error (_("cannot subscript requested type: "
2311 "cannot call user defined functions"));
2312 }
2313 else
2314 {
2315 /* If the user attempts to subscript something that is not
2316 an array or pointer type (like a plain int variable for
2317 example), then report this as an error. */
2318 type = check_typedef (value1->type);
2319 if (TYPE_CODE (type) != TYPE_CODE_ARRAY
2320 && TYPE_CODE (type) != TYPE_CODE_PTR)
2321 {
2322 if (TYPE_NAME (type))
2323 error (_("cannot subscript something of type `%s'"),
2324 TYPE_NAME (type));
2325 else
2326 error (_("cannot subscript requested type"));
2327 }
2328 }
2329
2330 if (!is_integral_type (value2->type))
2331 error (_("Argument to arithmetic operation "
2332 "not a number or boolean."));
2333
2334 gen_ptradd (ax, value, value1, value2);
2335 gen_deref (value);
2336 break;
2337 }
2338 case BINOP_BITWISE_AND:
2339 gen_binop (ax, value, value1, value2,
2340 aop_bit_and, aop_bit_and, 0, "bitwise and");
2341 break;
2342
2343 case BINOP_BITWISE_IOR:
2344 gen_binop (ax, value, value1, value2,
2345 aop_bit_or, aop_bit_or, 0, "bitwise or");
2346 break;
2347
2348 case BINOP_BITWISE_XOR:
2349 gen_binop (ax, value, value1, value2,
2350 aop_bit_xor, aop_bit_xor, 0, "bitwise exclusive-or");
2351 break;
2352
2353 case BINOP_EQUAL:
2354 gen_equal (ax, value, value1, value2, int_type);
2355 break;
2356
2357 case BINOP_NOTEQUAL:
2358 gen_equal (ax, value, value1, value2, int_type);
2359 gen_logical_not (ax, value, int_type);
2360 break;
2361
2362 case BINOP_LESS:
2363 gen_less (ax, value, value1, value2, int_type);
2364 break;
2365
2366 case BINOP_GTR:
2367 ax_simple (ax, aop_swap);
2368 gen_less (ax, value, value1, value2, int_type);
2369 break;
2370
2371 case BINOP_LEQ:
2372 ax_simple (ax, aop_swap);
2373 gen_less (ax, value, value1, value2, int_type);
2374 gen_logical_not (ax, value, int_type);
2375 break;
2376
2377 case BINOP_GEQ:
2378 gen_less (ax, value, value1, value2, int_type);
2379 gen_logical_not (ax, value, int_type);
2380 break;
2381
2382 default:
2383 /* We should only list operators in the outer case statement
2384 that we actually handle in the inner case statement. */
2385 internal_error (__FILE__, __LINE__,
2386 _("gen_expr: op case sets don't match"));
2387 }
2388 }
2389 \f
2390
2391 /* Given a single variable and a scope, generate bytecodes to trace
2392 its value. This is for use in situations where we have only a
2393 variable's name, and no parsed expression; for instance, when the
2394 name comes from a list of local variables of a function. */
2395
2396 agent_expr_up
2397 gen_trace_for_var (CORE_ADDR scope, struct gdbarch *gdbarch,
2398 struct symbol *var, int trace_string)
2399 {
2400 agent_expr_up ax (new agent_expr (gdbarch, scope));
2401 struct axs_value value;
2402
2403 ax->tracing = 1;
2404 ax->trace_string = trace_string;
2405 gen_var_ref (ax.get (), &value, var);
2406
2407 /* If there is no actual variable to trace, flag it by returning
2408 an empty agent expression. */
2409 if (value.optimized_out)
2410 return agent_expr_up ();
2411
2412 /* Make sure we record the final object, and get rid of it. */
2413 gen_traced_pop (ax.get (), &value);
2414
2415 /* Oh, and terminate. */
2416 ax_simple (ax.get (), aop_end);
2417
2418 return ax;
2419 }
2420
2421 /* Generating bytecode from GDB expressions: driver */
2422
2423 /* Given a GDB expression EXPR, return bytecode to trace its value.
2424 The result will use the `trace' and `trace_quick' bytecodes to
2425 record the value of all memory touched by the expression. The
2426 caller can then use the ax_reqs function to discover which
2427 registers it relies upon. */
2428
2429 agent_expr_up
2430 gen_trace_for_expr (CORE_ADDR scope, struct expression *expr,
2431 int trace_string)
2432 {
2433 agent_expr_up ax (new agent_expr (expr->gdbarch, scope));
2434 union exp_element *pc;
2435 struct axs_value value;
2436
2437 pc = expr->elts;
2438 ax->tracing = 1;
2439 ax->trace_string = trace_string;
2440 value.optimized_out = 0;
2441 gen_expr (expr, &pc, ax.get (), &value);
2442
2443 /* Make sure we record the final object, and get rid of it. */
2444 gen_traced_pop (ax.get (), &value);
2445
2446 /* Oh, and terminate. */
2447 ax_simple (ax.get (), aop_end);
2448
2449 return ax;
2450 }
2451
2452 /* Given a GDB expression EXPR, return a bytecode sequence that will
2453 evaluate and return a result. The bytecodes will do a direct
2454 evaluation, using the current data on the target, rather than
2455 recording blocks of memory and registers for later use, as
2456 gen_trace_for_expr does. The generated bytecode sequence leaves
2457 the result of expression evaluation on the top of the stack. */
2458
2459 agent_expr_up
2460 gen_eval_for_expr (CORE_ADDR scope, struct expression *expr)
2461 {
2462 agent_expr_up ax (new agent_expr (expr->gdbarch, scope));
2463 union exp_element *pc;
2464 struct axs_value value;
2465
2466 pc = expr->elts;
2467 ax->tracing = 0;
2468 value.optimized_out = 0;
2469 gen_expr (expr, &pc, ax.get (), &value);
2470
2471 require_rvalue (ax.get (), &value);
2472
2473 /* Oh, and terminate. */
2474 ax_simple (ax.get (), aop_end);
2475
2476 return ax;
2477 }
2478
2479 agent_expr_up
2480 gen_trace_for_return_address (CORE_ADDR scope, struct gdbarch *gdbarch,
2481 int trace_string)
2482 {
2483 agent_expr_up ax (new agent_expr (gdbarch, scope));
2484 struct axs_value value;
2485
2486 ax->tracing = 1;
2487 ax->trace_string = trace_string;
2488
2489 gdbarch_gen_return_address (gdbarch, ax.get (), &value, scope);
2490
2491 /* Make sure we record the final object, and get rid of it. */
2492 gen_traced_pop (ax.get (), &value);
2493
2494 /* Oh, and terminate. */
2495 ax_simple (ax.get (), aop_end);
2496
2497 return ax;
2498 }
2499
2500 /* Given a collection of printf-style arguments, generate code to
2501 evaluate the arguments and pass everything to a special
2502 bytecode. */
2503
2504 agent_expr_up
2505 gen_printf (CORE_ADDR scope, struct gdbarch *gdbarch,
2506 CORE_ADDR function, LONGEST channel,
2507 const char *format, int fmtlen,
2508 struct format_piece *frags,
2509 int nargs, struct expression **exprs)
2510 {
2511 agent_expr_up ax (new agent_expr (gdbarch, scope));
2512 union exp_element *pc;
2513 struct axs_value value;
2514 int tem;
2515
2516 /* We're computing values, not doing side effects. */
2517 ax->tracing = 0;
2518
2519 /* Evaluate and push the args on the stack in reverse order,
2520 for simplicity of collecting them on the target side. */
2521 for (tem = nargs - 1; tem >= 0; --tem)
2522 {
2523 pc = exprs[tem]->elts;
2524 value.optimized_out = 0;
2525 gen_expr (exprs[tem], &pc, ax.get (), &value);
2526 require_rvalue (ax.get (), &value);
2527 }
2528
2529 /* Push function and channel. */
2530 ax_const_l (ax.get (), channel);
2531 ax_const_l (ax.get (), function);
2532
2533 /* Issue the printf bytecode proper. */
2534 ax_simple (ax.get (), aop_printf);
2535 ax_raw_byte (ax.get (), nargs);
2536 ax_string (ax.get (), format, fmtlen);
2537
2538 /* And terminate. */
2539 ax_simple (ax.get (), aop_end);
2540
2541 return ax;
2542 }
2543
2544 static void
2545 agent_eval_command_one (const char *exp, int eval, CORE_ADDR pc)
2546 {
2547 const char *arg;
2548 int trace_string = 0;
2549
2550 if (!eval)
2551 {
2552 if (*exp == '/')
2553 exp = decode_agent_options (exp, &trace_string);
2554 }
2555
2556 agent_expr_up agent;
2557
2558 arg = exp;
2559 if (!eval && strcmp (arg, "$_ret") == 0)
2560 {
2561 agent = gen_trace_for_return_address (pc, get_current_arch (),
2562 trace_string);
2563 }
2564 else
2565 {
2566 expression_up expr = parse_exp_1 (&arg, pc, block_for_pc (pc), 0);
2567
2568 if (eval)
2569 {
2570 gdb_assert (trace_string == 0);
2571 agent = gen_eval_for_expr (pc, expr.get ());
2572 }
2573 else
2574 agent = gen_trace_for_expr (pc, expr.get (), trace_string);
2575 }
2576
2577 ax_reqs (agent.get ());
2578 ax_print (gdb_stdout, agent.get ());
2579
2580 /* It would be nice to call ax_reqs here to gather some general info
2581 about the expression, and then print out the result. */
2582
2583 dont_repeat ();
2584 }
2585
2586 static void
2587 agent_command_1 (char *exp, int eval)
2588 {
2589 /* We don't deal with overlay debugging at the moment. We need to
2590 think more carefully about this. If you copy this code into
2591 another command, change the error message; the user shouldn't
2592 have to know anything about agent expressions. */
2593 if (overlay_debugging)
2594 error (_("GDB can't do agent expression translation with overlays."));
2595
2596 if (exp == 0)
2597 error_no_arg (_("expression to translate"));
2598
2599 if (check_for_argument (&exp, "-at", sizeof ("-at") - 1))
2600 {
2601 struct linespec_result canonical;
2602
2603 exp = skip_spaces (exp);
2604
2605 event_location_up location = new_linespec_location (&exp);
2606 decode_line_full (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
2607 (struct symtab *) NULL, 0, &canonical,
2608 NULL, NULL);
2609 exp = skip_spaces (exp);
2610 if (exp[0] == ',')
2611 {
2612 exp++;
2613 exp = skip_spaces (exp);
2614 }
2615 for (const auto &lsal : canonical.lsals)
2616 for (const auto &sal : lsal.sals)
2617 agent_eval_command_one (exp, eval, sal.pc);
2618 }
2619 else
2620 agent_eval_command_one (exp, eval, get_frame_pc (get_current_frame ()));
2621
2622 dont_repeat ();
2623 }
2624
2625 static void
2626 agent_command (char *exp, int from_tty)
2627 {
2628 agent_command_1 (exp, 0);
2629 }
2630
2631 /* Parse the given expression, compile it into an agent expression
2632 that does direct evaluation, and display the resulting
2633 expression. */
2634
2635 static void
2636 agent_eval_command (char *exp, int from_tty)
2637 {
2638 agent_command_1 (exp, 1);
2639 }
2640
2641 /* Parse the given expression, compile it into an agent expression
2642 that does a printf, and display the resulting expression. */
2643
2644 static void
2645 maint_agent_printf_command (char *exp, int from_tty)
2646 {
2647 struct cleanup *old_chain = 0;
2648 struct expression *argvec[100];
2649 struct frame_info *fi = get_current_frame (); /* need current scope */
2650 const char *cmdrest;
2651 const char *format_start, *format_end;
2652 struct format_piece *fpieces;
2653 int nargs;
2654
2655 /* We don't deal with overlay debugging at the moment. We need to
2656 think more carefully about this. If you copy this code into
2657 another command, change the error message; the user shouldn't
2658 have to know anything about agent expressions. */
2659 if (overlay_debugging)
2660 error (_("GDB can't do agent expression translation with overlays."));
2661
2662 if (exp == 0)
2663 error_no_arg (_("expression to translate"));
2664
2665 cmdrest = exp;
2666
2667 cmdrest = skip_spaces_const (cmdrest);
2668
2669 if (*cmdrest++ != '"')
2670 error (_("Must start with a format string."));
2671
2672 format_start = cmdrest;
2673
2674 fpieces = parse_format_string (&cmdrest);
2675
2676 old_chain = make_cleanup (free_format_pieces_cleanup, &fpieces);
2677
2678 format_end = cmdrest;
2679
2680 if (*cmdrest++ != '"')
2681 error (_("Bad format string, non-terminated '\"'."));
2682
2683 cmdrest = skip_spaces_const (cmdrest);
2684
2685 if (*cmdrest != ',' && *cmdrest != 0)
2686 error (_("Invalid argument syntax"));
2687
2688 if (*cmdrest == ',')
2689 cmdrest++;
2690 cmdrest = skip_spaces_const (cmdrest);
2691
2692 nargs = 0;
2693 while (*cmdrest != '\0')
2694 {
2695 const char *cmd1;
2696
2697 cmd1 = cmdrest;
2698 expression_up expr = parse_exp_1 (&cmd1, 0, (struct block *) 0, 1);
2699 argvec[nargs] = expr.release ();
2700 ++nargs;
2701 cmdrest = cmd1;
2702 if (*cmdrest == ',')
2703 ++cmdrest;
2704 /* else complain? */
2705 }
2706
2707
2708 agent_expr_up agent = gen_printf (get_frame_pc (fi), get_current_arch (),
2709 0, 0,
2710 format_start, format_end - format_start,
2711 fpieces, nargs, argvec);
2712 ax_reqs (agent.get ());
2713 ax_print (gdb_stdout, agent.get ());
2714
2715 /* It would be nice to call ax_reqs here to gather some general info
2716 about the expression, and then print out the result. */
2717
2718 do_cleanups (old_chain);
2719 dont_repeat ();
2720 }
2721 \f
2722
2723 /* Initialization code. */
2724
2725 void _initialize_ax_gdb (void);
2726 void
2727 _initialize_ax_gdb (void)
2728 {
2729 add_cmd ("agent", class_maintenance, agent_command,
2730 _("\
2731 Translate an expression into remote agent bytecode for tracing.\n\
2732 Usage: maint agent [-at location,] EXPRESSION\n\
2733 If -at is given, generate remote agent bytecode for this location.\n\
2734 If not, generate remote agent bytecode for current frame pc address."),
2735 &maintenancelist);
2736
2737 add_cmd ("agent-eval", class_maintenance, agent_eval_command,
2738 _("\
2739 Translate an expression into remote agent bytecode for evaluation.\n\
2740 Usage: maint agent-eval [-at location,] EXPRESSION\n\
2741 If -at is given, generate remote agent bytecode for this location.\n\
2742 If not, generate remote agent bytecode for current frame pc address."),
2743 &maintenancelist);
2744
2745 add_cmd ("agent-printf", class_maintenance, maint_agent_printf_command,
2746 _("Translate an expression into remote "
2747 "agent bytecode for evaluation and display the bytecodes."),
2748 &maintenancelist);
2749 }
This page took 0.08846 seconds and 5 git commands to generate.