2012-04-27 Sergio Durigan Junior <sergiodj@redhat.com>
[deliverable/binutils-gdb.git] / gdb / stap-probe.c
CommitLineData
55aa24fb
SDJ
1/* SystemTap probe support for GDB.
2
3 Copyright (C) 2012 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 "stap-probe.h"
22#include "probe.h"
23#include "vec.h"
24#include "ui-out.h"
25#include "objfiles.h"
26#include "arch-utils.h"
27#include "command.h"
28#include "gdbcmd.h"
29#include "filenames.h"
30#include "value.h"
31#include "exceptions.h"
32#include "ax.h"
33#include "ax-gdb.h"
34#include "complaints.h"
35#include "cli/cli-utils.h"
36#include "linespec.h"
37#include "user-regs.h"
38#include "parser-defs.h"
39#include "language.h"
40#include "elf-bfd.h"
41
42#include <ctype.h>
43
44/* The name of the SystemTap section where we will find information about
45 the probes. */
46
47#define STAP_BASE_SECTION_NAME ".stapsdt.base"
48
49/* Forward declaration. */
50
51static const struct probe_ops stap_probe_ops;
52
53/* Should we display debug information for the probe's argument expression
54 parsing? */
55
56static int stap_expression_debug = 0;
57
58/* The various possibilities of bitness defined for a probe's argument.
59
60 The relationship is:
61
62 - STAP_ARG_BITNESS_UNDEFINED: The user hasn't specified the bitness.
63 - STAP_ARG_BITNESS_32BIT_UNSIGNED: argument string starts with `4@'.
64 - STAP_ARG_BITNESS_32BIT_SIGNED: argument string starts with `-4@'.
65 - STAP_ARG_BITNESS_64BIT_UNSIGNED: argument string starts with `8@'.
66 - STAP_ARG_BITNESS_64BIT_SIGNED: argument string starts with `-8@'. */
67
68enum stap_arg_bitness
69{
70 STAP_ARG_BITNESS_UNDEFINED,
71 STAP_ARG_BITNESS_32BIT_UNSIGNED,
72 STAP_ARG_BITNESS_32BIT_SIGNED,
73 STAP_ARG_BITNESS_64BIT_UNSIGNED,
74 STAP_ARG_BITNESS_64BIT_SIGNED,
75};
76
77/* The following structure represents a single argument for the probe. */
78
79struct stap_probe_arg
80{
81 /* The bitness of this argument. */
82 enum stap_arg_bitness bitness;
83
84 /* The corresponding `struct type *' to the bitness. */
85 struct type *atype;
86
87 /* The argument converted to an internal GDB expression. */
88 struct expression *aexpr;
89};
90
91typedef struct stap_probe_arg stap_probe_arg_s;
92DEF_VEC_O (stap_probe_arg_s);
93
94struct stap_probe
95{
96 /* Generic information about the probe. This shall be the first element
97 of this struct, in order to maintain binary compatibility with the
98 `struct probe' and be able to fully abstract it. */
99 struct probe p;
100
101 /* If the probe has a semaphore associated, then this is the value of
102 it. */
103 CORE_ADDR sem_addr;
104
105 unsigned int args_parsed : 1;
106 union
107 {
108 const char *text;
109
110 /* Information about each argument. This is an array of `stap_probe_arg',
111 with each entry representing one argument. */
112 VEC (stap_probe_arg_s) *vec;
113 }
114 args_u;
115};
116
117/* When parsing the arguments, we have to establish different precedences
118 for the various kinds of asm operators. This enumeration represents those
119 precedences.
120
121 This logic behind this is available at
122 <http://sourceware.org/binutils/docs/as/Infix-Ops.html#Infix-Ops>, or using
123 the command "info '(as)Infix Ops'". */
124
125enum stap_operand_prec
126{
127 /* Lowest precedence, used for non-recognized operands or for the beginning
128 of the parsing process. */
129 STAP_OPERAND_PREC_NONE = 0,
130
131 /* Precedence of logical OR. */
132 STAP_OPERAND_PREC_LOGICAL_OR,
133
134 /* Precedence of logical AND. */
135 STAP_OPERAND_PREC_LOGICAL_AND,
136
137 /* Precedence of additive (plus, minus) and comparative (equal, less,
138 greater-than, etc) operands. */
139 STAP_OPERAND_PREC_ADD_CMP,
140
141 /* Precedence of bitwise operands (bitwise OR, XOR, bitwise AND,
142 logical NOT). */
143 STAP_OPERAND_PREC_BITWISE,
144
145 /* Precedence of multiplicative operands (multiplication, division,
146 remainder, left shift and right shift). */
147 STAP_OPERAND_PREC_MUL
148};
149
150static void stap_parse_argument_1 (struct stap_parse_info *p, int has_lhs,
151 enum stap_operand_prec prec);
152
153static void stap_parse_argument_conditionally (struct stap_parse_info *p);
154
155/* Returns 1 if *S is an operator, zero otherwise. */
156
157static int stap_is_operator (char op);
158
159static void
160show_stapexpressiondebug (struct ui_file *file, int from_tty,
161 struct cmd_list_element *c, const char *value)
162{
163 fprintf_filtered (file, _("SystemTap Probe expression debugging is %s.\n"),
164 value);
165}
166
167/* Returns the operator precedence level of OP, or STAP_OPERAND_PREC_NONE
168 if the operator code was not recognized. */
169
170static enum stap_operand_prec
171stap_get_operator_prec (enum exp_opcode op)
172{
173 switch (op)
174 {
175 case BINOP_LOGICAL_OR:
176 return STAP_OPERAND_PREC_LOGICAL_OR;
177
178 case BINOP_LOGICAL_AND:
179 return STAP_OPERAND_PREC_LOGICAL_AND;
180
181 case BINOP_ADD:
182 case BINOP_SUB:
183 case BINOP_EQUAL:
184 case BINOP_NOTEQUAL:
185 case BINOP_LESS:
186 case BINOP_LEQ:
187 case BINOP_GTR:
188 case BINOP_GEQ:
189 return STAP_OPERAND_PREC_ADD_CMP;
190
191 case BINOP_BITWISE_IOR:
192 case BINOP_BITWISE_AND:
193 case BINOP_BITWISE_XOR:
194 case UNOP_LOGICAL_NOT:
195 return STAP_OPERAND_PREC_BITWISE;
196
197 case BINOP_MUL:
198 case BINOP_DIV:
199 case BINOP_REM:
200 case BINOP_LSH:
201 case BINOP_RSH:
202 return STAP_OPERAND_PREC_MUL;
203
204 default:
205 return STAP_OPERAND_PREC_NONE;
206 }
207}
208
209/* Given S, read the operator in it and fills the OP pointer with its code.
210 Return 1 on success, zero if the operator was not recognized. */
211
212static int
213stap_get_opcode (const char **s, enum exp_opcode *op)
214{
215 const char c = **s;
216 int ret = 1;
217
218 *s += 1;
219
220 switch (c)
221 {
222 case '*':
223 *op = BINOP_MUL;
224 break;
225
226 case '/':
227 *op = BINOP_DIV;
228 break;
229
230 case '%':
231 *op = BINOP_REM;
232 break;
233
234 case '<':
235 *op = BINOP_LESS;
236 if (**s == '<')
237 {
238 *s += 1;
239 *op = BINOP_LSH;
240 }
241 else if (**s == '=')
242 {
243 *s += 1;
244 *op = BINOP_LEQ;
245 }
246 else if (**s == '>')
247 {
248 *s += 1;
249 *op = BINOP_NOTEQUAL;
250 }
251 break;
252
253 case '>':
254 *op = BINOP_GTR;
255 if (**s == '>')
256 {
257 *s += 1;
258 *op = BINOP_RSH;
259 }
260 else if (**s == '=')
261 {
262 *s += 1;
263 *op = BINOP_GEQ;
264 }
265 break;
266
267 case '|':
268 *op = BINOP_BITWISE_IOR;
269 if (**s == '|')
270 {
271 *s += 1;
272 *op = BINOP_LOGICAL_OR;
273 }
274 break;
275
276 case '&':
277 *op = BINOP_BITWISE_AND;
278 if (**s == '&')
279 {
280 *s += 1;
281 *op = BINOP_LOGICAL_AND;
282 }
283 break;
284
285 case '^':
286 *op = BINOP_BITWISE_XOR;
287 break;
288
289 case '!':
290 *op = UNOP_LOGICAL_NOT;
291 break;
292
293 case '+':
294 *op = BINOP_ADD;
295 break;
296
297 case '-':
298 *op = BINOP_SUB;
299 break;
300
301 case '=':
302 if (**s != '=')
303 {
304 ret = 0;
305 break;
306 }
307 *op = BINOP_EQUAL;
308 break;
309
310 default:
311 /* We didn't find any operator. */
312 *s -= 1;
313 return 0;
314 }
315
316 return ret;
317}
318
319/* Given the bitness of the argument, represented by B, return the
320 corresponding `struct type *'. */
321
322static struct type *
323stap_get_expected_argument_type (struct gdbarch *gdbarch,
324 enum stap_arg_bitness b)
325{
326 switch (b)
327 {
328 case STAP_ARG_BITNESS_UNDEFINED:
329 if (gdbarch_addr_bit (gdbarch) == 32)
330 return builtin_type (gdbarch)->builtin_uint32;
331 else
332 return builtin_type (gdbarch)->builtin_uint64;
333
334 case STAP_ARG_BITNESS_32BIT_SIGNED:
335 return builtin_type (gdbarch)->builtin_int32;
336
337 case STAP_ARG_BITNESS_32BIT_UNSIGNED:
338 return builtin_type (gdbarch)->builtin_uint32;
339
340 case STAP_ARG_BITNESS_64BIT_SIGNED:
341 return builtin_type (gdbarch)->builtin_int64;
342
343 case STAP_ARG_BITNESS_64BIT_UNSIGNED:
344 return builtin_type (gdbarch)->builtin_uint64;
345
346 default:
347 internal_error (__FILE__, __LINE__,
348 _("Undefined bitness for probe."));
349 break;
350 }
351}
352
353/* Function responsible for parsing a register operand according to
354 SystemTap parlance. Assuming:
355
356 RP = register prefix
357 RS = register suffix
358 RIP = register indirection prefix
359 RIS = register indirection suffix
360
361 Then a register operand can be:
362
363 [RIP] [RP] REGISTER [RS] [RIS]
364
365 This function takes care of a register's indirection, displacement and
366 direct access. It also takes into consideration the fact that some
367 registers are named differently inside and outside GDB, e.g., PPC's
368 general-purpose registers are represented by integers in the assembly
369 language (e.g., `15' is the 15th general-purpose register), but inside
370 GDB they have a prefix (the letter `r') appended. */
371
372static void
373stap_parse_register_operand (struct stap_parse_info *p)
374{
375 /* Simple flag to indicate whether we have seen a minus signal before
376 certain number. */
377 int got_minus = 0;
378
379 /* Flags to indicate whether this register access is being displaced and/or
380 indirected. */
381 int disp_p = 0, indirect_p = 0;
382 struct gdbarch *gdbarch = p->gdbarch;
383
384 /* Needed to generate the register name as a part of an expression. */
385 struct stoken str;
386
387 /* Variables used to extract the register name from the probe's
388 argument. */
389 const char *start;
390 char *regname;
391 int len;
392
393 /* Prefixes for the parser. */
394 const char *reg_prefix = gdbarch_stap_register_prefix (gdbarch);
395 const char *reg_ind_prefix
396 = gdbarch_stap_register_indirection_prefix (gdbarch);
397 const char *gdb_reg_prefix = gdbarch_stap_gdb_register_prefix (gdbarch);
398 int reg_prefix_len = reg_prefix ? strlen (reg_prefix) : 0;
399 int reg_ind_prefix_len = reg_ind_prefix ? strlen (reg_ind_prefix) : 0;
400 int gdb_reg_prefix_len = gdb_reg_prefix ? strlen (gdb_reg_prefix) : 0;
401
402 /* Suffixes for the parser. */
403 const char *reg_suffix = gdbarch_stap_register_suffix (gdbarch);
404 const char *reg_ind_suffix
405 = gdbarch_stap_register_indirection_suffix (gdbarch);
406 const char *gdb_reg_suffix = gdbarch_stap_gdb_register_suffix (gdbarch);
407 int reg_suffix_len = reg_suffix ? strlen (reg_suffix) : 0;
408 int reg_ind_suffix_len = reg_ind_suffix ? strlen (reg_ind_suffix) : 0;
409 int gdb_reg_suffix_len = gdb_reg_suffix ? strlen (gdb_reg_suffix) : 0;
410
411 /* Checking for a displacement argument. */
412 if (*p->arg == '+')
413 {
414 /* If it's a plus sign, we don't need to do anything, just advance the
415 pointer. */
416 ++p->arg;
417 }
418
419 if (*p->arg == '-')
420 {
421 got_minus = 1;
422 ++p->arg;
423 }
424
425 if (isdigit (*p->arg))
426 {
427 /* The value of the displacement. */
428 long displacement;
429
430 disp_p = 1;
431 displacement = strtol (p->arg, (char **) &p->arg, 10);
432
433 /* Generating the expression for the displacement. */
434 write_exp_elt_opcode (OP_LONG);
435 write_exp_elt_type (builtin_type (gdbarch)->builtin_long);
436 write_exp_elt_longcst (displacement);
437 write_exp_elt_opcode (OP_LONG);
438 if (got_minus)
439 write_exp_elt_opcode (UNOP_NEG);
440 }
441
442 /* Getting rid of register indirection prefix. */
443 if (reg_ind_prefix
444 && strncmp (p->arg, reg_ind_prefix, reg_ind_prefix_len) == 0)
445 {
446 indirect_p = 1;
447 p->arg += reg_ind_prefix_len;
448 }
449
450 if (disp_p && !indirect_p)
451 error (_("Invalid register displacement syntax on expression `%s'."),
452 p->saved_arg);
453
454 /* Getting rid of register prefix. */
455 if (reg_prefix && strncmp (p->arg, reg_prefix, reg_prefix_len) == 0)
456 p->arg += reg_prefix_len;
457
458 /* Now we should have only the register name. Let's extract it and get
459 the associated number. */
460 start = p->arg;
461
462 /* We assume the register name is composed by letters and numbers. */
463 while (isalnum (*p->arg))
464 ++p->arg;
465
466 len = p->arg - start;
467
468 regname = alloca (len + gdb_reg_prefix_len + gdb_reg_suffix_len + 1);
469 regname[0] = '\0';
470
471 /* We only add the GDB's register prefix/suffix if we are dealing with
472 a numeric register. */
473 if (gdb_reg_prefix && isdigit (*start))
474 {
475 strncpy (regname, gdb_reg_prefix, gdb_reg_prefix_len);
476 strncpy (regname + gdb_reg_prefix_len, start, len);
477
478 if (gdb_reg_suffix)
479 strncpy (regname + gdb_reg_prefix_len + len,
480 gdb_reg_suffix, gdb_reg_suffix_len);
481
482 len += gdb_reg_prefix_len + gdb_reg_suffix_len;
483 }
484 else
485 strncpy (regname, start, len);
486
487 regname[len] = '\0';
488
489 /* Is this a valid register name? */
490 if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
491 error (_("Invalid register name `%s' on expression `%s'."),
492 regname, p->saved_arg);
493
494 write_exp_elt_opcode (OP_REGISTER);
495 str.ptr = regname;
496 str.length = len;
497 write_exp_string (str);
498 write_exp_elt_opcode (OP_REGISTER);
499
500 if (indirect_p)
501 {
502 if (disp_p)
503 write_exp_elt_opcode (BINOP_ADD);
504
505 /* Casting to the expected type. */
506 write_exp_elt_opcode (UNOP_CAST);
507 write_exp_elt_type (lookup_pointer_type (p->arg_type));
508 write_exp_elt_opcode (UNOP_CAST);
509
510 write_exp_elt_opcode (UNOP_IND);
511 }
512
513 /* Getting rid of the register name suffix. */
514 if (reg_suffix)
515 {
516 if (strncmp (p->arg, reg_suffix, reg_suffix_len) != 0)
517 error (_("Missing register name suffix `%s' on expression `%s'."),
518 reg_suffix, p->saved_arg);
519
520 p->arg += reg_suffix_len;
521 }
522
523 /* Getting rid of the register indirection suffix. */
524 if (indirect_p && reg_ind_suffix)
525 {
526 if (strncmp (p->arg, reg_ind_suffix, reg_ind_suffix_len) != 0)
527 error (_("Missing indirection suffix `%s' on expression `%s'."),
528 reg_ind_suffix, p->saved_arg);
529
530 p->arg += reg_ind_suffix_len;
531 }
532}
533
534/* This function is responsible for parsing a single operand.
535
536 A single operand can be:
537
538 - an unary operation (e.g., `-5', `~2', or even with subexpressions
539 like `-(2 + 1)')
540 - a register displacement, which will be treated as a register
541 operand (e.g., `-4(%eax)' on x86)
542 - a numeric constant, or
543 - a register operand (see function `stap_parse_register_operand')
544
545 The function also calls special-handling functions to deal with
546 unrecognized operands, allowing arch-specific parsers to be
547 created. */
548
549static void
550stap_parse_single_operand (struct stap_parse_info *p)
551{
552 struct gdbarch *gdbarch = p->gdbarch;
553
554 /* Prefixes for the parser. */
555 const char *const_prefix = gdbarch_stap_integer_prefix (gdbarch);
556 const char *reg_prefix = gdbarch_stap_register_prefix (gdbarch);
557 const char *reg_ind_prefix
558 = gdbarch_stap_register_indirection_prefix (gdbarch);
559 int const_prefix_len = const_prefix ? strlen (const_prefix) : 0;
560 int reg_prefix_len = reg_prefix ? strlen (reg_prefix) : 0;
561 int reg_ind_prefix_len = reg_ind_prefix ? strlen (reg_ind_prefix) : 0;
562
563 /* Suffixes for the parser. */
564 const char *const_suffix = gdbarch_stap_integer_suffix (gdbarch);
565 const char *reg_suffix = gdbarch_stap_register_suffix (gdbarch);
566 const char *reg_ind_suffix
567 = gdbarch_stap_register_indirection_suffix (gdbarch);
568 int const_suffix_len = const_suffix ? strlen (const_suffix) : 0;
569 int reg_suffix_len = reg_suffix ? strlen (reg_suffix) : 0;
570 int reg_ind_suffix_len = reg_ind_suffix ? strlen (reg_ind_suffix) : 0;
571
572 /* We first try to parse this token as a "special token". */
573 if (gdbarch_stap_parse_special_token_p (gdbarch))
574 {
575 int ret = gdbarch_stap_parse_special_token (gdbarch, p);
576
577 if (ret)
578 {
579 /* If the return value of the above function is not zero,
580 it means it successfully parsed the special token.
581
582 If it is NULL, we try to parse it using our method. */
583 return;
584 }
585 }
586
587 if (*p->arg == '-' || *p->arg == '~' || *p->arg == '+')
588 {
589 char c = *p->arg;
590 int number;
591
592 /* We use this variable to do a lookahead. */
593 const char *tmp = p->arg;
594
595 ++tmp;
596
597 /* This is an unary operation. Here is a list of allowed tokens
598 here:
599
600 - numeric literal;
601 - number (from register displacement)
602 - subexpression (beginning with `(')
603
604 We handle the register displacement here, and the other cases
605 recursively. */
606 if (p->inside_paren_p)
607 tmp = skip_spaces_const (tmp);
608
609 if (isdigit (*tmp))
610 number = strtol (tmp, (char **) &tmp, 10);
611
612 if (!reg_ind_prefix
613 || strncmp (tmp, reg_ind_prefix, reg_ind_prefix_len) != 0)
614 {
615 /* This is not a displacement. We skip the operator, and deal
616 with it later. */
617 ++p->arg;
618 stap_parse_argument_conditionally (p);
619 if (c == '-')
620 write_exp_elt_opcode (UNOP_NEG);
621 else if (c == '~')
622 write_exp_elt_opcode (UNOP_COMPLEMENT);
623 }
624 else
625 {
626 /* If we are here, it means it is a displacement. The only
627 operations allowed here are `-' and `+'. */
628 if (c == '~')
629 error (_("Invalid operator `%c' for register displacement "
630 "on expression `%s'."), c, p->saved_arg);
631
632 stap_parse_register_operand (p);
633 }
634 }
635 else if (isdigit (*p->arg))
636 {
637 /* A temporary variable, needed for lookahead. */
638 const char *tmp = p->arg;
639 long number;
640
641 /* We can be dealing with a numeric constant (if `const_prefix' is
642 NULL), or with a register displacement. */
643 number = strtol (tmp, (char **) &tmp, 10);
644
645 if (p->inside_paren_p)
646 tmp = skip_spaces_const (tmp);
647 if (!const_prefix && reg_ind_prefix
648 && strncmp (tmp, reg_ind_prefix, reg_ind_prefix_len) != 0)
649 {
650 /* We are dealing with a numeric constant. */
651 write_exp_elt_opcode (OP_LONG);
652 write_exp_elt_type (builtin_type (gdbarch)->builtin_long);
653 write_exp_elt_longcst (number);
654 write_exp_elt_opcode (OP_LONG);
655
656 p->arg = tmp;
657
658 if (const_suffix)
659 {
660 if (strncmp (p->arg, const_suffix, const_suffix_len) == 0)
661 p->arg += const_suffix_len;
662 else
663 error (_("Invalid constant suffix on expression `%s'."),
664 p->saved_arg);
665 }
666 }
667 else if (reg_ind_prefix
668 && strncmp (tmp, reg_ind_prefix, reg_ind_prefix_len) == 0)
669 stap_parse_register_operand (p);
670 else
671 error (_("Unknown numeric token on expression `%s'."),
672 p->saved_arg);
673 }
674 else if (const_prefix
675 && strncmp (p->arg, const_prefix, const_prefix_len) == 0)
676 {
677 /* We are dealing with a numeric constant. */
678 long number;
679
680 p->arg += const_prefix_len;
681 number = strtol (p->arg, (char **) &p->arg, 10);
682
683 write_exp_elt_opcode (OP_LONG);
684 write_exp_elt_type (builtin_type (gdbarch)->builtin_long);
685 write_exp_elt_longcst (number);
686 write_exp_elt_opcode (OP_LONG);
687
688 if (const_suffix)
689 {
690 if (strncmp (p->arg, const_suffix, const_suffix_len) == 0)
691 p->arg += const_suffix_len;
692 else
693 error (_("Invalid constant suffix on expression `%s'."),
694 p->saved_arg);
695 }
696 }
697 else if ((reg_prefix
698 && strncmp (p->arg, reg_prefix, reg_prefix_len) == 0)
699 || (reg_ind_prefix
700 && strncmp (p->arg, reg_ind_prefix, reg_ind_prefix_len) == 0))
701 stap_parse_register_operand (p);
702 else
703 error (_("Operator `%c' not recognized on expression `%s'."),
704 *p->arg, p->saved_arg);
705}
706
707/* This function parses an argument conditionally, based on single or
708 non-single operands. A non-single operand would be a parenthesized
709 expression (e.g., `(2 + 1)'), and a single operand is anything that
710 starts with `-', `~', `+' (i.e., unary operators), a digit, or
711 something recognized by `gdbarch_stap_is_single_operand'. */
712
713static void
714stap_parse_argument_conditionally (struct stap_parse_info *p)
715{
716 if (*p->arg == '-' || *p->arg == '~' || *p->arg == '+' /* Unary. */
717 || isdigit (*p->arg)
718 || gdbarch_stap_is_single_operand (p->gdbarch, p->arg))
719 stap_parse_single_operand (p);
720 else if (*p->arg == '(')
721 {
722 /* We are dealing with a parenthesized operand. It means we
723 have to parse it as it was a separate expression, without
724 left-side or precedence. */
725 ++p->arg;
726 p->arg = skip_spaces_const (p->arg);
727 ++p->inside_paren_p;
728
729 stap_parse_argument_1 (p, 0, STAP_OPERAND_PREC_NONE);
730
731 --p->inside_paren_p;
732 if (*p->arg != ')')
733 error (_("Missign close-paren on expression `%s'."),
734 p->saved_arg);
735
736 ++p->arg;
737 if (p->inside_paren_p)
738 p->arg = skip_spaces_const (p->arg);
739 }
740 else
741 error (_("Cannot parse expression `%s'."), p->saved_arg);
742}
743
744/* Helper function for `stap_parse_argument'. Please, see its comments to
745 better understand what this function does. */
746
747static void
748stap_parse_argument_1 (struct stap_parse_info *p, int has_lhs,
749 enum stap_operand_prec prec)
750{
751 /* This is an operator-precedence parser.
752
753 We work with left- and right-sides of expressions, and
754 parse them depending on the precedence of the operators
755 we find. */
756
757 if (p->inside_paren_p)
758 p->arg = skip_spaces_const (p->arg);
759
760 if (!has_lhs)
761 {
762 /* We were called without a left-side, either because this is the
763 first call, or because we were called to parse a parenthesized
764 expression. It doesn't really matter; we have to parse the
765 left-side in order to continue the process. */
766 stap_parse_argument_conditionally (p);
767 }
768
769 /* Start to parse the right-side, and to "join" left and right sides
770 depending on the operation specified.
771
772 This loop shall continue until we run out of characters in the input,
773 or until we find a close-parenthesis, which means that we've reached
774 the end of a sub-expression. */
775 while (p->arg && *p->arg && *p->arg != ')' && !isspace (*p->arg))
776 {
777 const char *tmp_exp_buf;
778 enum exp_opcode opcode;
779 enum stap_operand_prec cur_prec;
780
781 if (!stap_is_operator (*p->arg))
782 error (_("Invalid operator `%c' on expression `%s'."), *p->arg,
783 p->saved_arg);
784
785 /* We have to save the current value of the expression buffer because
786 the `stap_get_opcode' modifies it in order to get the current
787 operator. If this operator's precedence is lower than PREC, we
788 should return and not advance the expression buffer pointer. */
789 tmp_exp_buf = p->arg;
790 stap_get_opcode (&tmp_exp_buf, &opcode);
791
792 cur_prec = stap_get_operator_prec (opcode);
793 if (cur_prec < prec)
794 {
795 /* If the precedence of the operator that we are seeing now is
796 lower than the precedence of the first operator seen before
797 this parsing process began, it means we should stop parsing
798 and return. */
799 break;
800 }
801
802 p->arg = tmp_exp_buf;
803 if (p->inside_paren_p)
804 p->arg = skip_spaces_const (p->arg);
805
806 /* Parse the right-side of the expression. */
807 stap_parse_argument_conditionally (p);
808
809 /* While we still have operators, try to parse another
810 right-side, but using the current right-side as a left-side. */
811 while (*p->arg && stap_is_operator (*p->arg))
812 {
813 enum exp_opcode lookahead_opcode;
814 enum stap_operand_prec lookahead_prec;
815
816 /* Saving the current expression buffer position. The explanation
817 is the same as above. */
818 tmp_exp_buf = p->arg;
819 stap_get_opcode (&tmp_exp_buf, &lookahead_opcode);
820 lookahead_prec = stap_get_operator_prec (lookahead_opcode);
821
822 if (lookahead_prec <= prec)
823 {
824 /* If we are dealing with an operator whose precedence is lower
825 than the first one, just abandon the attempt. */
826 break;
827 }
828
829 /* Parse the right-side of the expression, but since we already
830 have a left-side at this point, set `has_lhs' to 1. */
831 stap_parse_argument_1 (p, 1, lookahead_prec);
832 }
833
834 write_exp_elt_opcode (opcode);
835 }
836}
837
838/* Parse a probe's argument.
839
840 Assuming that:
841
842 LP = literal integer prefix
843 LS = literal integer suffix
844
845 RP = register prefix
846 RS = register suffix
847
848 RIP = register indirection prefix
849 RIS = register indirection suffix
850
851 This routine assumes that arguments' tokens are of the form:
852
853 - [LP] NUMBER [LS]
854 - [RP] REGISTER [RS]
855 - [RIP] [RP] REGISTER [RS] [RIS]
856 - If we find a number without LP, we try to parse it as a literal integer
857 constant (if LP == NULL), or as a register displacement.
858 - We count parenthesis, and only skip whitespaces if we are inside them.
859 - If we find an operator, we skip it.
860
861 This function can also call a special function that will try to match
862 unknown tokens. It will return 1 if the argument has been parsed
863 successfully, or zero otherwise. */
864
865static struct expression *
866stap_parse_argument (const char **arg, struct type *atype,
867 struct gdbarch *gdbarch)
868{
869 struct stap_parse_info p;
870 volatile struct gdb_exception e;
871 struct cleanup *back_to;
872
873 /* We need to initialize the expression buffer, in order to begin
874 our parsing efforts. The language here does not matter, since we
875 are using our own parser. */
876 initialize_expout (10, current_language, gdbarch);
877 back_to = make_cleanup (free_current_contents, &expout);
878
879 p.saved_arg = *arg;
880 p.arg = *arg;
881 p.arg_type = atype;
882 p.gdbarch = gdbarch;
883 p.inside_paren_p = 0;
884
885 stap_parse_argument_1 (&p, 0, STAP_OPERAND_PREC_NONE);
886
887 discard_cleanups (back_to);
888
889 gdb_assert (p.inside_paren_p == 0);
890
891 /* Casting the final expression to the appropriate type. */
892 write_exp_elt_opcode (UNOP_CAST);
893 write_exp_elt_type (atype);
894 write_exp_elt_opcode (UNOP_CAST);
895
896 reallocate_expout ();
897
898 p.arg = skip_spaces_const (p.arg);
899 *arg = p.arg;
900
901 return expout;
902}
903
904/* Function which parses an argument string from PROBE, correctly splitting
905 the arguments and storing their information in properly ways.
906
907 Consider the following argument string (x86 syntax):
908
909 `4@%eax 4@$10'
910
911 We have two arguments, `%eax' and `$10', both with 32-bit unsigned bitness.
912 This function basically handles them, properly filling some structures with
913 this information. */
914
915static void
916stap_parse_probe_arguments (struct stap_probe *probe, struct objfile *objfile)
917{
918 const char *cur;
919 struct gdbarch *gdbarch = get_objfile_arch (objfile);
920
921 gdb_assert (!probe->args_parsed);
922 cur = probe->args_u.text;
923 probe->args_parsed = 1;
924 probe->args_u.vec = NULL;
925
926 if (!cur || !*cur || *cur == ':')
927 return;
928
929 while (*cur)
930 {
931 struct stap_probe_arg arg;
932 enum stap_arg_bitness b;
933 int got_minus = 0;
934 struct expression *expr;
935
936 memset (&arg, 0, sizeof (arg));
937
938 /* We expect to find something like:
939
940 N@OP
941
942 Where `N' can be [+,-][4,8]. This is not mandatory, so
943 we check it here. If we don't find it, go to the next
944 state. */
945 if ((*cur == '-' && cur[1] && cur[2] != '@')
946 && cur[1] != '@')
947 arg.bitness = STAP_ARG_BITNESS_UNDEFINED;
948 else
949 {
950 if (*cur == '-')
951 {
952 /* Discard the `-'. */
953 ++cur;
954 got_minus = 1;
955 }
956
957 if (*cur == '4')
958 b = (got_minus ? STAP_ARG_BITNESS_32BIT_SIGNED
959 : STAP_ARG_BITNESS_32BIT_UNSIGNED);
960 else if (*cur == '8')
961 b = (got_minus ? STAP_ARG_BITNESS_64BIT_SIGNED
962 : STAP_ARG_BITNESS_64BIT_UNSIGNED);
963 else
964 {
965 /* We have an error, because we don't expect anything
966 except 4 and 8. */
967 complaint (&symfile_complaints,
968 _("unrecognized bitness `%c' for probe `%s'"),
969 *cur, probe->p.name);
970 return;
971 }
972
973 arg.bitness = b;
974 arg.atype = stap_get_expected_argument_type (gdbarch, b);
975
976 /* Discard the number and the `@' sign. */
977 cur += 2;
978 }
979
980 expr = stap_parse_argument (&cur, arg.atype, gdbarch);
981
982 if (stap_expression_debug)
983 dump_raw_expression (expr, gdb_stdlog,
984 "before conversion to prefix form");
985
986 prefixify_expression (expr);
987
988 if (stap_expression_debug)
989 dump_prefix_expression (expr, gdb_stdlog);
990
991 arg.aexpr = expr;
992
993 /* Start it over again. */
994 cur = skip_spaces_const (cur);
995
996 VEC_safe_push (stap_probe_arg_s, probe->args_u.vec, &arg);
997 }
998}
999
1000/* Given PROBE, returns the number of arguments present in that probe's
1001 argument string. */
1002
1003static unsigned
1004stap_get_probe_argument_count (struct probe *probe_generic,
1005 struct objfile *objfile)
1006{
1007 struct stap_probe *probe = (struct stap_probe *) probe_generic;
1008
1009 gdb_assert (probe_generic->pops == &stap_probe_ops);
1010
1011 if (!probe->args_parsed)
1012 stap_parse_probe_arguments (probe, objfile);
1013
1014 gdb_assert (probe->args_parsed);
1015 return VEC_length (stap_probe_arg_s, probe->args_u.vec);
1016}
1017
1018/* Return 1 if OP is a valid operator inside a probe argument, or zero
1019 otherwise. */
1020
1021static int
1022stap_is_operator (char op)
1023{
1024 return (op == '+' || op == '-' || op == '*' || op == '/'
1025 || op == '>' || op == '<' || op == '!' || op == '^'
1026 || op == '|' || op == '&' || op == '%' || op == '=');
1027}
1028
1029static struct stap_probe_arg *
1030stap_get_arg (struct stap_probe *probe, struct objfile *objfile, unsigned n)
1031{
1032 if (!probe->args_parsed)
1033 stap_parse_probe_arguments (probe, objfile);
1034
1035 return VEC_index (stap_probe_arg_s, probe->args_u.vec, n);
1036}
1037
1038/* Evaluate the probe's argument N (indexed from 0), returning a value
1039 corresponding to it. Assertion is thrown if N does not exist. */
1040
1041static struct value *
1042stap_evaluate_probe_argument (struct probe *probe_generic,
1043 struct objfile *objfile, unsigned n)
1044{
1045 struct stap_probe *stap_probe = (struct stap_probe *) probe_generic;
1046 struct stap_probe_arg *arg;
1047 int pos = 0;
1048
1049 gdb_assert (probe_generic->pops == &stap_probe_ops);
1050
1051 arg = stap_get_arg (stap_probe, objfile, n);
1052 return evaluate_subexp_standard (arg->atype, arg->aexpr, &pos, EVAL_NORMAL);
1053}
1054
1055/* Compile the probe's argument N (indexed from 0) to agent expression.
1056 Assertion is thrown if N does not exist. */
1057
1058static void
1059stap_compile_to_ax (struct probe *probe_generic, struct objfile *objfile,
1060 struct agent_expr *expr, struct axs_value *value,
1061 unsigned n)
1062{
1063 struct stap_probe *stap_probe = (struct stap_probe *) probe_generic;
1064 struct stap_probe_arg *arg;
1065 union exp_element *pc;
1066
1067 gdb_assert (probe_generic->pops == &stap_probe_ops);
1068
1069 arg = stap_get_arg (stap_probe, objfile, n);
1070
1071 pc = arg->aexpr->elts;
1072 gen_expr (arg->aexpr, &pc, expr, value);
1073
1074 require_rvalue (expr, value);
1075 value->type = arg->atype;
1076}
1077
1078/* Destroy (free) the data related to PROBE. PROBE memory itself is not feed
1079 as it is allocated from OBJFILE_OBSTACK. */
1080
1081static void
1082stap_probe_destroy (struct probe *probe_generic)
1083{
1084 struct stap_probe *probe = (struct stap_probe *) probe_generic;
1085
1086 gdb_assert (probe_generic->pops == &stap_probe_ops);
1087
1088 if (probe->args_parsed)
1089 {
1090 struct stap_probe_arg *arg;
1091 int ix;
1092
1093 for (ix = 0; VEC_iterate (stap_probe_arg_s, probe->args_u.vec, ix, arg);
1094 ++ix)
1095 xfree (arg->aexpr);
1096 VEC_free (stap_probe_arg_s, probe->args_u.vec);
1097 }
1098}
1099
1100\f
1101
1102/* This is called to compute the value of one of the $_probe_arg*
1103 convenience variables. */
1104
1105static struct value *
1106compute_probe_arg (struct gdbarch *arch, struct internalvar *ivar,
1107 void *data)
1108{
1109 struct frame_info *frame = get_selected_frame (_("No frame selected"));
1110 CORE_ADDR pc = get_frame_pc (frame);
1111 int sel = (int) (uintptr_t) data;
1112 struct objfile *objfile;
1113 struct probe *pc_probe;
1114 unsigned n_args;
1115
1116 /* SEL == -1 means "_probe_argc". */
1117 gdb_assert (sel >= -1);
1118
1119 pc_probe = find_probe_by_pc (pc, &objfile);
1120 if (pc_probe == NULL)
1121 error (_("No SystemTap probe at PC %s"), core_addr_to_string (pc));
1122
1123 n_args
1124 = objfile->sf->sym_probe_fns->sym_get_probe_argument_count (objfile,
1125 pc_probe);
1126 if (sel == -1)
1127 return value_from_longest (builtin_type (arch)->builtin_int, n_args);
1128
1129 if (sel >= n_args)
1130 error (_("Invalid probe argument %d -- probe has %u arguments available"),
1131 sel, n_args);
1132
1133 return objfile->sf->sym_probe_fns->sym_evaluate_probe_argument (objfile,
1134 pc_probe,
1135 sel);
1136}
1137
1138/* This is called to compile one of the $_probe_arg* convenience
1139 variables into an agent expression. */
1140
1141static void
1142compile_probe_arg (struct internalvar *ivar, struct agent_expr *expr,
1143 struct axs_value *value, void *data)
1144{
1145 CORE_ADDR pc = expr->scope;
1146 int sel = (int) (uintptr_t) data;
1147 struct objfile *objfile;
1148 struct probe *pc_probe;
1149 int n_probes;
1150
1151 /* SEL == -1 means "_probe_argc". */
1152 gdb_assert (sel >= -1);
1153
1154 pc_probe = find_probe_by_pc (pc, &objfile);
1155 if (pc_probe == NULL)
1156 error (_("No SystemTap probe at PC %s"), core_addr_to_string (pc));
1157
1158 n_probes
1159 = objfile->sf->sym_probe_fns->sym_get_probe_argument_count (objfile,
1160 pc_probe);
1161 if (sel == -1)
1162 {
1163 value->kind = axs_rvalue;
1164 value->type = builtin_type (expr->gdbarch)->builtin_int;
1165 ax_const_l (expr, n_probes);
1166 return;
1167 }
1168
1169 gdb_assert (sel >= 0);
1170 if (sel >= n_probes)
1171 error (_("Invalid probe argument %d -- probe has %d arguments available"),
1172 sel, n_probes);
1173
1174 objfile->sf->sym_probe_fns->sym_compile_to_ax (objfile, pc_probe,
1175 expr, value, sel);
1176}
1177
1178\f
1179
1180/* Set or clear a SystemTap semaphore. ADDRESS is the semaphore's
1181 address. SET is zero if the semaphore should be cleared, or one
1182 if it should be set. This is a helper function for `stap_semaphore_down'
1183 and `stap_semaphore_up'. */
1184
1185static void
1186stap_modify_semaphore (CORE_ADDR address, int set, struct gdbarch *gdbarch)
1187{
1188 gdb_byte bytes[sizeof (LONGEST)];
1189 /* The ABI specifies "unsigned short". */
1190 struct type *type = builtin_type (gdbarch)->builtin_unsigned_short;
1191 ULONGEST value;
1192
1193 if (address == 0)
1194 return;
1195
1196 /* Swallow errors. */
1197 if (target_read_memory (address, bytes, TYPE_LENGTH (type)) != 0)
1198 {
1199 warning (_("Could not read the value of a SystemTap semaphore."));
1200 return;
1201 }
1202
1203 value = extract_unsigned_integer (bytes, TYPE_LENGTH (type),
1204 gdbarch_byte_order (gdbarch));
1205 /* Note that we explicitly don't worry about overflow or
1206 underflow. */
1207 if (set)
1208 ++value;
1209 else
1210 --value;
1211
1212 store_unsigned_integer (bytes, TYPE_LENGTH (type),
1213 gdbarch_byte_order (gdbarch), value);
1214
1215 if (target_write_memory (address, bytes, TYPE_LENGTH (type)) != 0)
1216 warning (_("Could not write the value of a SystemTap semaphore."));
1217}
1218
1219/* Set a SystemTap semaphore. SEM is the semaphore's address. Semaphores
1220 act as reference counters, so calls to this function must be paired with
1221 calls to `stap_semaphore_down'.
1222
1223 This function and `stap_semaphore_down' race with another tool changing
1224 the probes, but that is too rare to care. */
1225
1226static void
1227stap_set_semaphore (struct probe *probe_generic, struct gdbarch *gdbarch)
1228{
1229 struct stap_probe *probe = (struct stap_probe *) probe_generic;
1230
1231 gdb_assert (probe_generic->pops == &stap_probe_ops);
1232
1233 stap_modify_semaphore (probe->sem_addr, 1, gdbarch);
1234}
1235
1236/* Clear a SystemTap semaphore. SEM is the semaphore's address. */
1237
1238static void
1239stap_clear_semaphore (struct probe *probe_generic, struct gdbarch *gdbarch)
1240{
1241 struct stap_probe *probe = (struct stap_probe *) probe_generic;
1242
1243 gdb_assert (probe_generic->pops == &stap_probe_ops);
1244
1245 stap_modify_semaphore (probe->sem_addr, 0, gdbarch);
1246}
1247
1248/* Implementation of `$_probe_arg*' set of variables. */
1249
1250static const struct internalvar_funcs probe_funcs =
1251{
1252 compute_probe_arg,
1253 compile_probe_arg,
1254 NULL
1255};
1256
1257/* Helper function that parses the information contained in a
1258 SystemTap's probe. Basically, the information consists in:
1259
1260 - Probe's PC address;
1261 - Link-time section address of `.stapsdt.base' section;
1262 - Link-time address of the semaphore variable, or ZERO if the
1263 probe doesn't have an associated semaphore;
1264 - Probe's provider name;
1265 - Probe's name;
1266 - Probe's argument format
1267
1268 This function returns 1 if the handling was successful, and zero
1269 otherwise. */
1270
1271static void
1272handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
1273 VEC (probe_p) **probesp, CORE_ADDR base)
1274{
1275 bfd *abfd = objfile->obfd;
1276 int size = bfd_get_arch_size (abfd) / 8;
1277 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1278 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1279 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
1280 CORE_ADDR base_ref;
1281 const char *probe_args = NULL;
1282 struct stap_probe *ret;
1283
1284 ret = obstack_alloc (&objfile->objfile_obstack, sizeof (*ret));
1285 ret->p.pops = &stap_probe_ops;
1286
1287 /* Provider and the name of the probe. */
1288 ret->p.provider = &el->data[3 * size];
1289 ret->p.name = memchr (ret->p.provider, '\0',
1290 (char *) el->data + el->size - ret->p.provider);
1291 /* Making sure there is a name. */
1292 if (!ret->p.name)
1293 {
1294 complaint (&symfile_complaints, _("corrupt probe name when "
1295 "reading `%s'"), objfile->name);
1296
1297 /* There is no way to use a probe without a name or a provider, so
1298 returning zero here makes sense. */
1299 return;
1300 }
1301 else
1302 ++ret->p.name;
1303
1304 /* Retrieving the probe's address. */
1305 ret->p.address = extract_typed_address (&el->data[0], ptr_type);
1306
1307 /* Link-time sh_addr of `.stapsdt.base' section. */
1308 base_ref = extract_typed_address (&el->data[size], ptr_type);
1309
1310 /* Semaphore address. */
1311 ret->sem_addr = extract_typed_address (&el->data[2 * size], ptr_type);
1312
1313 ret->p.address += (ANOFFSET (objfile->section_offsets,
1314 SECT_OFF_TEXT (objfile))
1315 + base - base_ref);
1316 if (ret->sem_addr)
1317 ret->sem_addr += (ANOFFSET (objfile->section_offsets,
1318 SECT_OFF_DATA (objfile))
1319 + base - base_ref);
1320
1321 /* Arguments. We can only extract the argument format if there is a valid
1322 name for this probe. */
1323 probe_args = memchr (ret->p.name, '\0',
1324 (char *) el->data + el->size - ret->p.name);
1325
1326 if (probe_args != NULL)
1327 ++probe_args;
1328
1329 if (probe_args == NULL || (memchr (probe_args, '\0',
1330 (char *) el->data + el->size - ret->p.name)
1331 != el->data + el->size - 1))
1332 {
1333 complaint (&symfile_complaints, _("corrupt probe argument when "
1334 "reading `%s'"), objfile->name);
1335 /* If the argument string is NULL, it means some problem happened with
1336 it. So we return 0. */
1337 return;
1338 }
1339
1340 ret->args_parsed = 0;
1341 ret->args_u.text = (void *) probe_args;
1342
1343 /* Successfully created probe. */
1344 VEC_safe_push (probe_p, *probesp, (struct probe *) ret);
1345}
1346
1347/* Helper function which tries to find the base address of the SystemTap
1348 base section named STAP_BASE_SECTION_NAME. */
1349
1350static void
1351get_stap_base_address_1 (bfd *abfd, asection *sect, void *obj)
1352{
1353 asection **ret = obj;
1354
1355 if ((sect->flags & (SEC_DATA | SEC_ALLOC | SEC_HAS_CONTENTS))
1356 && sect->name && !strcmp (sect->name, STAP_BASE_SECTION_NAME))
1357 *ret = sect;
1358}
1359
1360/* Helper function which iterates over every section in the BFD file,
1361 trying to find the base address of the SystemTap base section.
1362 Returns 1 if found (setting BASE to the proper value), zero otherwise. */
1363
1364static int
1365get_stap_base_address (bfd *obfd, bfd_vma *base)
1366{
1367 asection *ret = NULL;
1368
1369 bfd_map_over_sections (obfd, get_stap_base_address_1, (void *) &ret);
1370
1371 if (!ret)
1372 {
1373 complaint (&symfile_complaints, _("could not obtain base address for "
1374 "SystemTap section on objfile `%s'."),
1375 obfd->filename);
1376 return 0;
1377 }
1378
1379 if (base)
1380 *base = ret->vma;
1381
1382 return 1;
1383}
1384
1385/* Helper function for `elf_get_probes', which gathers information about all
1386 SystemTap probes from OBJFILE. */
1387
1388static void
1389stap_get_probes (VEC (probe_p) **probesp, struct objfile *objfile)
1390{
1391 /* If we are here, then this is the first time we are parsing the
1392 SystemTap probe's information. We basically have to count how many
1393 probes the objfile has, and then fill in the necessary information
1394 for each one. */
1395 bfd *obfd = objfile->obfd;
1396 bfd_vma base;
1397 struct sdt_note *iter;
1398 unsigned save_probesp_len = VEC_length (probe_p, *probesp);
1399
1400 if (!elf_tdata (obfd)->sdt_note_head)
1401 {
1402 /* There isn't any probe here. */
1403 return;
1404 }
1405
1406 if (!get_stap_base_address (obfd, &base))
1407 {
1408 /* There was an error finding the base address for the section.
1409 Just return NULL. */
1410 return;
1411 }
1412
1413 /* Parsing each probe's information. */
1414 for (iter = elf_tdata (obfd)->sdt_note_head; iter; iter = iter->next)
1415 {
1416 /* We first have to handle all the information about the
1417 probe which is present in the section. */
1418 handle_stap_probe (objfile, iter, probesp, base);
1419 }
1420
1421 if (save_probesp_len == VEC_length (probe_p, *probesp))
1422 {
1423 /* If we are here, it means we have failed to parse every known
1424 probe. */
1425 complaint (&symfile_complaints, _("could not parse SystemTap probe(s) "
1426 "from inferior"));
1427 return;
1428 }
1429}
1430
1431static void
1432stap_relocate (struct probe *probe_generic, CORE_ADDR delta)
1433{
1434 struct stap_probe *probe = (struct stap_probe *) probe_generic;
1435
1436 gdb_assert (probe_generic->pops == &stap_probe_ops);
1437
1438 probe->p.address += delta;
1439 if (probe->sem_addr)
1440 probe->sem_addr += delta;
1441}
1442
1443static int
1444stap_probe_is_linespec (const char **linespecp)
1445{
1446 static const char *const keywords[] = { "-pstap", "-probe-stap", NULL };
1447
1448 return probe_is_linespec_by_keyword (linespecp, keywords);
1449}
1450
1451static void
1452stap_gen_info_probes_table_header (VEC (info_probe_column_s) **heads)
1453{
1454 info_probe_column_s stap_probe_column;
1455
1456 stap_probe_column.field_name = "semaphore";
1457 stap_probe_column.print_name = _("Semaphore");
1458
1459 VEC_safe_push (info_probe_column_s, *heads, &stap_probe_column);
1460}
1461
1462static void
1463stap_gen_info_probes_table_values (struct probe *probe_generic,
1464 struct objfile *objfile,
1465 VEC (const_char_ptr) **ret)
1466{
1467 struct stap_probe *probe = (struct stap_probe *) probe_generic;
1468 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1469 const char *val = NULL;
1470
1471 gdb_assert (probe_generic->pops == &stap_probe_ops);
1472
1473 if (probe->sem_addr)
1474 val = print_core_address (gdbarch, probe->sem_addr);
1475
1476 VEC_safe_push (const_char_ptr, *ret, val);
1477}
1478
1479/* SystemTap probe_ops. */
1480
1481static const struct probe_ops stap_probe_ops =
1482{
1483 stap_probe_is_linespec,
1484 stap_get_probes,
1485 stap_relocate,
1486 stap_get_probe_argument_count,
1487 stap_evaluate_probe_argument,
1488 stap_compile_to_ax,
1489 stap_set_semaphore,
1490 stap_clear_semaphore,
1491 stap_probe_destroy,
1492 stap_gen_info_probes_table_header,
1493 stap_gen_info_probes_table_values,
1494};
1495
1496/* Implementation of the `info probes stap' command. */
1497
1498static void
1499info_probes_stap_command (char *arg, int from_tty)
1500{
1501 info_probes_for_ops (arg, from_tty, &stap_probe_ops);
1502}
1503
1504void _initialize_stap_probe (void);
1505
1506void
1507_initialize_stap_probe (void)
1508{
1509 VEC_safe_push (probe_ops_cp, all_probe_ops, &stap_probe_ops);
1510
1511 add_setshow_zinteger_cmd ("stap-expression", class_maintenance,
1512 &stap_expression_debug,
1513 _("Set SystemTap expression debugging."),
1514 _("Show SystemTap expression debugging."),
1515 _("When non-zero, the internal representation "
1516 "of SystemTap expressions will be printed."),
1517 NULL,
1518 show_stapexpressiondebug,
1519 &setdebuglist, &showdebuglist);
1520
1521 create_internalvar_type_lazy ("_probe_argc", &probe_funcs,
1522 (void *) (uintptr_t) -1);
1523 create_internalvar_type_lazy ("_probe_arg0", &probe_funcs,
1524 (void *) (uintptr_t) 0);
1525 create_internalvar_type_lazy ("_probe_arg1", &probe_funcs,
1526 (void *) (uintptr_t) 1);
1527 create_internalvar_type_lazy ("_probe_arg2", &probe_funcs,
1528 (void *) (uintptr_t) 2);
1529 create_internalvar_type_lazy ("_probe_arg3", &probe_funcs,
1530 (void *) (uintptr_t) 3);
1531 create_internalvar_type_lazy ("_probe_arg4", &probe_funcs,
1532 (void *) (uintptr_t) 4);
1533 create_internalvar_type_lazy ("_probe_arg5", &probe_funcs,
1534 (void *) (uintptr_t) 5);
1535 create_internalvar_type_lazy ("_probe_arg6", &probe_funcs,
1536 (void *) (uintptr_t) 6);
1537 create_internalvar_type_lazy ("_probe_arg7", &probe_funcs,
1538 (void *) (uintptr_t) 7);
1539 create_internalvar_type_lazy ("_probe_arg8", &probe_funcs,
1540 (void *) (uintptr_t) 8);
1541 create_internalvar_type_lazy ("_probe_arg9", &probe_funcs,
1542 (void *) (uintptr_t) 9);
1543 create_internalvar_type_lazy ("_probe_arg10", &probe_funcs,
1544 (void *) (uintptr_t) 10);
1545 create_internalvar_type_lazy ("_probe_arg11", &probe_funcs,
1546 (void *) (uintptr_t) 11);
1547
1548 add_cmd ("stap", class_info, info_probes_stap_command,
1549 _("\
1550Show information about SystemTap static probes.\n\
1551Usage: info probes stap [PROVIDER [NAME [OBJECT]]]\n\
1552Each argument is a regular expression, used to select probes.\n\
1553PROVIDER matches probe provider names.\n\
1554NAME matches the probe names.\n\
1555OBJECT matches the executable or shared library name."),
1556 info_probes_cmdlist_get ());
1557
1558}
This page took 0.075361 seconds and 4 git commands to generate.