1 /* SystemTap probe support for GDB.
3 Copyright (C) 2012-2014 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
21 #include "stap-probe.h"
26 #include "arch-utils.h"
29 #include "filenames.h"
31 #include "exceptions.h"
34 #include "complaints.h"
35 #include "cli/cli-utils.h"
37 #include "user-regs.h"
38 #include "parser-defs.h"
44 /* The name of the SystemTap section where we will find information about
47 #define STAP_BASE_SECTION_NAME ".stapsdt.base"
49 /* Forward declaration. */
51 static const struct probe_ops stap_probe_ops
;
53 /* Should we display debug information for the probe's argument expression
56 static unsigned int stap_expression_debug
= 0;
58 /* The various possibilities of bitness defined for a probe's argument.
62 - STAP_ARG_BITNESS_UNDEFINED: The user hasn't specified the bitness.
63 - STAP_ARG_BITNESS_8BIT_UNSIGNED: argument string starts with `1@'.
64 - STAP_ARG_BITNESS_8BIT_SIGNED: argument string starts with `-1@'.
65 - STAP_ARG_BITNESS_16BIT_UNSIGNED: argument string starts with `2@'.
66 - STAP_ARG_BITNESS_16BIT_SIGNED: argument string starts with `-2@'.
67 - STAP_ARG_BITNESS_32BIT_UNSIGNED: argument string starts with `4@'.
68 - STAP_ARG_BITNESS_32BIT_SIGNED: argument string starts with `-4@'.
69 - STAP_ARG_BITNESS_64BIT_UNSIGNED: argument string starts with `8@'.
70 - STAP_ARG_BITNESS_64BIT_SIGNED: argument string starts with `-8@'. */
74 STAP_ARG_BITNESS_UNDEFINED
,
75 STAP_ARG_BITNESS_8BIT_UNSIGNED
,
76 STAP_ARG_BITNESS_8BIT_SIGNED
,
77 STAP_ARG_BITNESS_16BIT_UNSIGNED
,
78 STAP_ARG_BITNESS_16BIT_SIGNED
,
79 STAP_ARG_BITNESS_32BIT_UNSIGNED
,
80 STAP_ARG_BITNESS_32BIT_SIGNED
,
81 STAP_ARG_BITNESS_64BIT_UNSIGNED
,
82 STAP_ARG_BITNESS_64BIT_SIGNED
,
85 /* The following structure represents a single argument for the probe. */
89 /* The bitness of this argument. */
90 enum stap_arg_bitness bitness
;
92 /* The corresponding `struct type *' to the bitness. */
95 /* The argument converted to an internal GDB expression. */
96 struct expression
*aexpr
;
99 typedef struct stap_probe_arg stap_probe_arg_s
;
100 DEF_VEC_O (stap_probe_arg_s
);
104 /* Generic information about the probe. This shall be the first element
105 of this struct, in order to maintain binary compatibility with the
106 `struct probe' and be able to fully abstract it. */
109 /* If the probe has a semaphore associated, then this is the value of
110 it, relative to SECT_OFF_DATA. */
113 /* One if the arguments have been parsed. */
114 unsigned int args_parsed
: 1;
120 /* Information about each argument. This is an array of `stap_probe_arg',
121 with each entry representing one argument. */
122 VEC (stap_probe_arg_s
) *vec
;
127 /* When parsing the arguments, we have to establish different precedences
128 for the various kinds of asm operators. This enumeration represents those
131 This logic behind this is available at
132 <http://sourceware.org/binutils/docs/as/Infix-Ops.html#Infix-Ops>, or using
133 the command "info '(as)Infix Ops'". */
135 enum stap_operand_prec
137 /* Lowest precedence, used for non-recognized operands or for the beginning
138 of the parsing process. */
139 STAP_OPERAND_PREC_NONE
= 0,
141 /* Precedence of logical OR. */
142 STAP_OPERAND_PREC_LOGICAL_OR
,
144 /* Precedence of logical AND. */
145 STAP_OPERAND_PREC_LOGICAL_AND
,
147 /* Precedence of additive (plus, minus) and comparative (equal, less,
148 greater-than, etc) operands. */
149 STAP_OPERAND_PREC_ADD_CMP
,
151 /* Precedence of bitwise operands (bitwise OR, XOR, bitwise AND,
153 STAP_OPERAND_PREC_BITWISE
,
155 /* Precedence of multiplicative operands (multiplication, division,
156 remainder, left shift and right shift). */
157 STAP_OPERAND_PREC_MUL
160 static void stap_parse_argument_1 (struct stap_parse_info
*p
, int has_lhs
,
161 enum stap_operand_prec prec
);
163 static void stap_parse_argument_conditionally (struct stap_parse_info
*p
);
165 /* Returns 1 if *S is an operator, zero otherwise. */
167 static int stap_is_operator (const char *op
);
170 show_stapexpressiondebug (struct ui_file
*file
, int from_tty
,
171 struct cmd_list_element
*c
, const char *value
)
173 fprintf_filtered (file
, _("SystemTap Probe expression debugging is %s.\n"),
177 /* Returns the operator precedence level of OP, or STAP_OPERAND_PREC_NONE
178 if the operator code was not recognized. */
180 static enum stap_operand_prec
181 stap_get_operator_prec (enum exp_opcode op
)
185 case BINOP_LOGICAL_OR
:
186 return STAP_OPERAND_PREC_LOGICAL_OR
;
188 case BINOP_LOGICAL_AND
:
189 return STAP_OPERAND_PREC_LOGICAL_AND
;
199 return STAP_OPERAND_PREC_ADD_CMP
;
201 case BINOP_BITWISE_IOR
:
202 case BINOP_BITWISE_AND
:
203 case BINOP_BITWISE_XOR
:
204 case UNOP_LOGICAL_NOT
:
205 return STAP_OPERAND_PREC_BITWISE
;
212 return STAP_OPERAND_PREC_MUL
;
215 return STAP_OPERAND_PREC_NONE
;
219 /* Given S, read the operator in it and fills the OP pointer with its code.
220 Return 1 on success, zero if the operator was not recognized. */
222 static enum exp_opcode
223 stap_get_opcode (const char **s
)
278 op
= BINOP_BITWISE_IOR
;
282 op
= BINOP_LOGICAL_OR
;
287 op
= BINOP_BITWISE_AND
;
291 op
= BINOP_LOGICAL_AND
;
296 op
= BINOP_BITWISE_XOR
;
300 op
= UNOP_LOGICAL_NOT
;
312 gdb_assert (**s
== '=');
317 internal_error (__FILE__
, __LINE__
,
318 _("Invalid opcode in expression `%s' for SystemTap"
325 /* Given the bitness of the argument, represented by B, return the
326 corresponding `struct type *'. */
329 stap_get_expected_argument_type (struct gdbarch
*gdbarch
,
330 enum stap_arg_bitness b
)
334 case STAP_ARG_BITNESS_UNDEFINED
:
335 if (gdbarch_addr_bit (gdbarch
) == 32)
336 return builtin_type (gdbarch
)->builtin_uint32
;
338 return builtin_type (gdbarch
)->builtin_uint64
;
340 case STAP_ARG_BITNESS_8BIT_UNSIGNED
:
341 return builtin_type (gdbarch
)->builtin_uint8
;
343 case STAP_ARG_BITNESS_8BIT_SIGNED
:
344 return builtin_type (gdbarch
)->builtin_int8
;
346 case STAP_ARG_BITNESS_16BIT_UNSIGNED
:
347 return builtin_type (gdbarch
)->builtin_uint16
;
349 case STAP_ARG_BITNESS_16BIT_SIGNED
:
350 return builtin_type (gdbarch
)->builtin_int16
;
352 case STAP_ARG_BITNESS_32BIT_SIGNED
:
353 return builtin_type (gdbarch
)->builtin_int32
;
355 case STAP_ARG_BITNESS_32BIT_UNSIGNED
:
356 return builtin_type (gdbarch
)->builtin_uint32
;
358 case STAP_ARG_BITNESS_64BIT_SIGNED
:
359 return builtin_type (gdbarch
)->builtin_int64
;
361 case STAP_ARG_BITNESS_64BIT_UNSIGNED
:
362 return builtin_type (gdbarch
)->builtin_uint64
;
365 internal_error (__FILE__
, __LINE__
,
366 _("Undefined bitness for probe."));
371 /* Helper function to check for a generic list of prefixes. GDBARCH
372 is the current gdbarch being used. S is the expression being
373 analyzed. If R is not NULL, it will be used to return the found
374 prefix. PREFIXES is the list of expected prefixes.
376 This function does a case-insensitive match.
378 Return 1 if any prefix has been found, zero otherwise. */
381 stap_is_generic_prefix (struct gdbarch
*gdbarch
, const char *s
,
382 const char **r
, const char *const *prefixes
)
384 const char *const *p
;
386 if (prefixes
== NULL
)
394 for (p
= prefixes
; *p
!= NULL
; ++p
)
395 if (strncasecmp (s
, *p
, strlen (*p
)) == 0)
406 /* Return 1 if S points to a register prefix, zero otherwise. For a
407 description of the arguments, look at stap_is_generic_prefix. */
410 stap_is_register_prefix (struct gdbarch
*gdbarch
, const char *s
,
413 const char *const *t
= gdbarch_stap_register_prefixes (gdbarch
);
415 return stap_is_generic_prefix (gdbarch
, s
, r
, t
);
418 /* Return 1 if S points to a register indirection prefix, zero
419 otherwise. For a description of the arguments, look at
420 stap_is_generic_prefix. */
423 stap_is_register_indirection_prefix (struct gdbarch
*gdbarch
, const char *s
,
426 const char *const *t
= gdbarch_stap_register_indirection_prefixes (gdbarch
);
428 return stap_is_generic_prefix (gdbarch
, s
, r
, t
);
431 /* Return 1 if S points to an integer prefix, zero otherwise. For a
432 description of the arguments, look at stap_is_generic_prefix.
434 This function takes care of analyzing whether we are dealing with
435 an expected integer prefix, or, if there is no integer prefix to be
436 expected, whether we are dealing with a digit. It does a
437 case-insensitive match. */
440 stap_is_integer_prefix (struct gdbarch
*gdbarch
, const char *s
,
443 const char *const *t
= gdbarch_stap_integer_prefixes (gdbarch
);
444 const char *const *p
;
448 /* A NULL value here means that integers do not have a prefix.
449 We just check for a digit then. */
456 for (p
= t
; *p
!= NULL
; ++p
)
458 size_t len
= strlen (*p
);
460 if ((len
== 0 && isdigit (*s
))
461 || (len
> 0 && strncasecmp (s
, *p
, len
) == 0))
463 /* Integers may or may not have a prefix. The "len == 0"
464 check covers the case when integers do not have a prefix
465 (therefore, we just check if we have a digit). The call
466 to "strncasecmp" covers the case when they have a
478 /* Helper function to check for a generic list of suffixes. If we are
479 not expecting any suffixes, then it just returns 1. If we are
480 expecting at least one suffix, then it returns 1 if a suffix has
481 been found, zero otherwise. GDBARCH is the current gdbarch being
482 used. S is the expression being analyzed. If R is not NULL, it
483 will be used to return the found suffix. SUFFIXES is the list of
484 expected suffixes. This function does a case-insensitive
488 stap_generic_check_suffix (struct gdbarch
*gdbarch
, const char *s
,
489 const char **r
, const char *const *suffixes
)
491 const char *const *p
;
494 if (suffixes
== NULL
)
502 for (p
= suffixes
; *p
!= NULL
; ++p
)
503 if (strncasecmp (s
, *p
, strlen (*p
)) == 0)
515 /* Return 1 if S points to an integer suffix, zero otherwise. For a
516 description of the arguments, look at
517 stap_generic_check_suffix. */
520 stap_check_integer_suffix (struct gdbarch
*gdbarch
, const char *s
,
523 const char *const *p
= gdbarch_stap_integer_suffixes (gdbarch
);
525 return stap_generic_check_suffix (gdbarch
, s
, r
, p
);
528 /* Return 1 if S points to a register suffix, zero otherwise. For a
529 description of the arguments, look at
530 stap_generic_check_suffix. */
533 stap_check_register_suffix (struct gdbarch
*gdbarch
, const char *s
,
536 const char *const *p
= gdbarch_stap_register_suffixes (gdbarch
);
538 return stap_generic_check_suffix (gdbarch
, s
, r
, p
);
541 /* Return 1 if S points to a register indirection suffix, zero
542 otherwise. For a description of the arguments, look at
543 stap_generic_check_suffix. */
546 stap_check_register_indirection_suffix (struct gdbarch
*gdbarch
, const char *s
,
549 const char *const *p
= gdbarch_stap_register_indirection_suffixes (gdbarch
);
551 return stap_generic_check_suffix (gdbarch
, s
, r
, p
);
554 /* Function responsible for parsing a register operand according to
555 SystemTap parlance. Assuming:
559 RIP = register indirection prefix
560 RIS = register indirection suffix
562 Then a register operand can be:
564 [RIP] [RP] REGISTER [RS] [RIS]
566 This function takes care of a register's indirection, displacement and
567 direct access. It also takes into consideration the fact that some
568 registers are named differently inside and outside GDB, e.g., PPC's
569 general-purpose registers are represented by integers in the assembly
570 language (e.g., `15' is the 15th general-purpose register), but inside
571 GDB they have a prefix (the letter `r') appended. */
574 stap_parse_register_operand (struct stap_parse_info
*p
)
576 /* Simple flag to indicate whether we have seen a minus signal before
579 /* Flags to indicate whether this register access is being displaced and/or
581 int disp_p
= 0, indirect_p
= 0;
582 struct gdbarch
*gdbarch
= p
->gdbarch
;
583 /* Needed to generate the register name as a part of an expression. */
585 /* Variables used to extract the register name from the probe's
590 const char *gdb_reg_prefix
= gdbarch_stap_gdb_register_prefix (gdbarch
);
591 int gdb_reg_prefix_len
= gdb_reg_prefix
? strlen (gdb_reg_prefix
) : 0;
592 const char *gdb_reg_suffix
= gdbarch_stap_gdb_register_suffix (gdbarch
);
593 int gdb_reg_suffix_len
= gdb_reg_suffix
? strlen (gdb_reg_suffix
) : 0;
594 const char *reg_prefix
;
595 const char *reg_ind_prefix
;
596 const char *reg_suffix
;
597 const char *reg_ind_suffix
;
599 /* Checking for a displacement argument. */
602 /* If it's a plus sign, we don't need to do anything, just advance the
613 if (isdigit (*p
->arg
))
615 /* The value of the displacement. */
620 displacement
= strtol (p
->arg
, &endp
, 10);
623 /* Generating the expression for the displacement. */
624 write_exp_elt_opcode (&p
->pstate
, OP_LONG
);
625 write_exp_elt_type (&p
->pstate
, builtin_type (gdbarch
)->builtin_long
);
626 write_exp_elt_longcst (&p
->pstate
, displacement
);
627 write_exp_elt_opcode (&p
->pstate
, OP_LONG
);
629 write_exp_elt_opcode (&p
->pstate
, UNOP_NEG
);
632 /* Getting rid of register indirection prefix. */
633 if (stap_is_register_indirection_prefix (gdbarch
, p
->arg
, ®_ind_prefix
))
636 p
->arg
+= strlen (reg_ind_prefix
);
639 if (disp_p
&& !indirect_p
)
640 error (_("Invalid register displacement syntax on expression `%s'."),
643 /* Getting rid of register prefix. */
644 if (stap_is_register_prefix (gdbarch
, p
->arg
, ®_prefix
))
645 p
->arg
+= strlen (reg_prefix
);
647 /* Now we should have only the register name. Let's extract it and get
648 the associated number. */
651 /* We assume the register name is composed by letters and numbers. */
652 while (isalnum (*p
->arg
))
655 len
= p
->arg
- start
;
657 regname
= alloca (len
+ gdb_reg_prefix_len
+ gdb_reg_suffix_len
+ 1);
660 /* We only add the GDB's register prefix/suffix if we are dealing with
661 a numeric register. */
662 if (gdb_reg_prefix
&& isdigit (*start
))
664 strncpy (regname
, gdb_reg_prefix
, gdb_reg_prefix_len
);
665 strncpy (regname
+ gdb_reg_prefix_len
, start
, len
);
668 strncpy (regname
+ gdb_reg_prefix_len
+ len
,
669 gdb_reg_suffix
, gdb_reg_suffix_len
);
671 len
+= gdb_reg_prefix_len
+ gdb_reg_suffix_len
;
674 strncpy (regname
, start
, len
);
678 /* Is this a valid register name? */
679 if (user_reg_map_name_to_regnum (gdbarch
, regname
, len
) == -1)
680 error (_("Invalid register name `%s' on expression `%s'."),
681 regname
, p
->saved_arg
);
683 write_exp_elt_opcode (&p
->pstate
, OP_REGISTER
);
686 write_exp_string (&p
->pstate
, str
);
687 write_exp_elt_opcode (&p
->pstate
, OP_REGISTER
);
692 write_exp_elt_opcode (&p
->pstate
, BINOP_ADD
);
694 /* Casting to the expected type. */
695 write_exp_elt_opcode (&p
->pstate
, UNOP_CAST
);
696 write_exp_elt_type (&p
->pstate
, lookup_pointer_type (p
->arg_type
));
697 write_exp_elt_opcode (&p
->pstate
, UNOP_CAST
);
699 write_exp_elt_opcode (&p
->pstate
, UNOP_IND
);
702 /* Getting rid of the register name suffix. */
703 if (stap_check_register_suffix (gdbarch
, p
->arg
, ®_suffix
))
704 p
->arg
+= strlen (reg_suffix
);
706 error (_("Missing register name suffix on expression `%s'."),
709 /* Getting rid of the register indirection suffix. */
712 if (stap_check_register_indirection_suffix (gdbarch
, p
->arg
,
714 p
->arg
+= strlen (reg_ind_suffix
);
716 error (_("Missing indirection suffix on expression `%s'."),
721 /* This function is responsible for parsing a single operand.
723 A single operand can be:
725 - an unary operation (e.g., `-5', `~2', or even with subexpressions
727 - a register displacement, which will be treated as a register
728 operand (e.g., `-4(%eax)' on x86)
729 - a numeric constant, or
730 - a register operand (see function `stap_parse_register_operand')
732 The function also calls special-handling functions to deal with
733 unrecognized operands, allowing arch-specific parsers to be
737 stap_parse_single_operand (struct stap_parse_info
*p
)
739 struct gdbarch
*gdbarch
= p
->gdbarch
;
740 const char *int_prefix
= NULL
;
742 /* We first try to parse this token as a "special token". */
743 if (gdbarch_stap_parse_special_token_p (gdbarch
))
744 if (gdbarch_stap_parse_special_token (gdbarch
, p
) != 0)
746 /* If the return value of the above function is not zero,
747 it means it successfully parsed the special token.
749 If it is NULL, we try to parse it using our method. */
753 if (*p
->arg
== '-' || *p
->arg
== '~' || *p
->arg
== '+')
756 /* We use this variable to do a lookahead. */
757 const char *tmp
= p
->arg
;
760 /* Skipping signal. */
763 /* This is an unary operation. Here is a list of allowed tokens
767 - number (from register displacement)
768 - subexpression (beginning with `(')
770 We handle the register displacement here, and the other cases
772 if (p
->inside_paren_p
)
773 tmp
= skip_spaces_const (tmp
);
775 while (isdigit (*tmp
))
777 /* We skip the digit here because we are only interested in
778 knowing what kind of unary operation this is. The digit
779 will be handled by one of the functions that will be
780 called below ('stap_parse_argument_conditionally' or
781 'stap_parse_register_operand'). */
786 if (has_digit
&& stap_is_register_indirection_prefix (gdbarch
, tmp
,
789 /* If we are here, it means it is a displacement. The only
790 operations allowed here are `-' and `+'. */
792 error (_("Invalid operator `%c' for register displacement "
793 "on expression `%s'."), c
, p
->saved_arg
);
795 stap_parse_register_operand (p
);
799 /* This is not a displacement. We skip the operator, and
800 deal with it when the recursion returns. */
802 stap_parse_argument_conditionally (p
);
804 write_exp_elt_opcode (&p
->pstate
, UNOP_NEG
);
806 write_exp_elt_opcode (&p
->pstate
, UNOP_COMPLEMENT
);
809 else if (isdigit (*p
->arg
))
811 /* A temporary variable, needed for lookahead. */
812 const char *tmp
= p
->arg
;
816 /* We can be dealing with a numeric constant, or with a register
818 number
= strtol (tmp
, &endp
, 10);
821 if (p
->inside_paren_p
)
822 tmp
= skip_spaces_const (tmp
);
824 /* If "stap_is_integer_prefix" returns true, it means we can
825 accept integers without a prefix here. But we also need to
826 check whether the next token (i.e., "tmp") is not a register
827 indirection prefix. */
828 if (stap_is_integer_prefix (gdbarch
, p
->arg
, NULL
)
829 && !stap_is_register_indirection_prefix (gdbarch
, tmp
, NULL
))
831 const char *int_suffix
;
833 /* We are dealing with a numeric constant. */
834 write_exp_elt_opcode (&p
->pstate
, OP_LONG
);
835 write_exp_elt_type (&p
->pstate
,
836 builtin_type (gdbarch
)->builtin_long
);
837 write_exp_elt_longcst (&p
->pstate
, number
);
838 write_exp_elt_opcode (&p
->pstate
, OP_LONG
);
842 if (stap_check_integer_suffix (gdbarch
, p
->arg
, &int_suffix
))
843 p
->arg
+= strlen (int_suffix
);
845 error (_("Invalid constant suffix on expression `%s'."),
848 else if (stap_is_register_indirection_prefix (gdbarch
, tmp
, NULL
))
849 stap_parse_register_operand (p
);
851 error (_("Unknown numeric token on expression `%s'."),
854 else if (stap_is_integer_prefix (gdbarch
, p
->arg
, &int_prefix
))
856 /* We are dealing with a numeric constant. */
859 const char *int_suffix
;
861 p
->arg
+= strlen (int_prefix
);
862 number
= strtol (p
->arg
, &endp
, 10);
865 write_exp_elt_opcode (&p
->pstate
, OP_LONG
);
866 write_exp_elt_type (&p
->pstate
, builtin_type (gdbarch
)->builtin_long
);
867 write_exp_elt_longcst (&p
->pstate
, number
);
868 write_exp_elt_opcode (&p
->pstate
, OP_LONG
);
870 if (stap_check_integer_suffix (gdbarch
, p
->arg
, &int_suffix
))
871 p
->arg
+= strlen (int_suffix
);
873 error (_("Invalid constant suffix on expression `%s'."),
876 else if (stap_is_register_prefix (gdbarch
, p
->arg
, NULL
)
877 || stap_is_register_indirection_prefix (gdbarch
, p
->arg
, NULL
))
878 stap_parse_register_operand (p
);
880 error (_("Operator `%c' not recognized on expression `%s'."),
881 *p
->arg
, p
->saved_arg
);
884 /* This function parses an argument conditionally, based on single or
885 non-single operands. A non-single operand would be a parenthesized
886 expression (e.g., `(2 + 1)'), and a single operand is anything that
887 starts with `-', `~', `+' (i.e., unary operators), a digit, or
888 something recognized by `gdbarch_stap_is_single_operand'. */
891 stap_parse_argument_conditionally (struct stap_parse_info
*p
)
893 gdb_assert (gdbarch_stap_is_single_operand_p (p
->gdbarch
));
895 if (*p
->arg
== '-' || *p
->arg
== '~' || *p
->arg
== '+' /* Unary. */
897 || gdbarch_stap_is_single_operand (p
->gdbarch
, p
->arg
))
898 stap_parse_single_operand (p
);
899 else if (*p
->arg
== '(')
901 /* We are dealing with a parenthesized operand. It means we
902 have to parse it as it was a separate expression, without
903 left-side or precedence. */
905 p
->arg
= skip_spaces_const (p
->arg
);
908 stap_parse_argument_1 (p
, 0, STAP_OPERAND_PREC_NONE
);
912 error (_("Missign close-paren on expression `%s'."),
916 if (p
->inside_paren_p
)
917 p
->arg
= skip_spaces_const (p
->arg
);
920 error (_("Cannot parse expression `%s'."), p
->saved_arg
);
923 /* Helper function for `stap_parse_argument'. Please, see its comments to
924 better understand what this function does. */
927 stap_parse_argument_1 (struct stap_parse_info
*p
, int has_lhs
,
928 enum stap_operand_prec prec
)
930 /* This is an operator-precedence parser.
932 We work with left- and right-sides of expressions, and
933 parse them depending on the precedence of the operators
936 gdb_assert (p
->arg
!= NULL
);
938 if (p
->inside_paren_p
)
939 p
->arg
= skip_spaces_const (p
->arg
);
943 /* We were called without a left-side, either because this is the
944 first call, or because we were called to parse a parenthesized
945 expression. It doesn't really matter; we have to parse the
946 left-side in order to continue the process. */
947 stap_parse_argument_conditionally (p
);
950 /* Start to parse the right-side, and to "join" left and right sides
951 depending on the operation specified.
953 This loop shall continue until we run out of characters in the input,
954 or until we find a close-parenthesis, which means that we've reached
955 the end of a sub-expression. */
956 while (*p
->arg
!= '\0' && *p
->arg
!= ')' && !isspace (*p
->arg
))
958 const char *tmp_exp_buf
;
959 enum exp_opcode opcode
;
960 enum stap_operand_prec cur_prec
;
962 if (!stap_is_operator (p
->arg
))
963 error (_("Invalid operator `%c' on expression `%s'."), *p
->arg
,
966 /* We have to save the current value of the expression buffer because
967 the `stap_get_opcode' modifies it in order to get the current
968 operator. If this operator's precedence is lower than PREC, we
969 should return and not advance the expression buffer pointer. */
970 tmp_exp_buf
= p
->arg
;
971 opcode
= stap_get_opcode (&tmp_exp_buf
);
973 cur_prec
= stap_get_operator_prec (opcode
);
976 /* If the precedence of the operator that we are seeing now is
977 lower than the precedence of the first operator seen before
978 this parsing process began, it means we should stop parsing
983 p
->arg
= tmp_exp_buf
;
984 if (p
->inside_paren_p
)
985 p
->arg
= skip_spaces_const (p
->arg
);
987 /* Parse the right-side of the expression. */
988 stap_parse_argument_conditionally (p
);
990 /* While we still have operators, try to parse another
991 right-side, but using the current right-side as a left-side. */
992 while (*p
->arg
!= '\0' && stap_is_operator (p
->arg
))
994 enum exp_opcode lookahead_opcode
;
995 enum stap_operand_prec lookahead_prec
;
997 /* Saving the current expression buffer position. The explanation
998 is the same as above. */
999 tmp_exp_buf
= p
->arg
;
1000 lookahead_opcode
= stap_get_opcode (&tmp_exp_buf
);
1001 lookahead_prec
= stap_get_operator_prec (lookahead_opcode
);
1003 if (lookahead_prec
<= prec
)
1005 /* If we are dealing with an operator whose precedence is lower
1006 than the first one, just abandon the attempt. */
1010 /* Parse the right-side of the expression, but since we already
1011 have a left-side at this point, set `has_lhs' to 1. */
1012 stap_parse_argument_1 (p
, 1, lookahead_prec
);
1015 write_exp_elt_opcode (&p
->pstate
, opcode
);
1019 /* Parse a probe's argument.
1023 LP = literal integer prefix
1024 LS = literal integer suffix
1026 RP = register prefix
1027 RS = register suffix
1029 RIP = register indirection prefix
1030 RIS = register indirection suffix
1032 This routine assumes that arguments' tokens are of the form:
1035 - [RP] REGISTER [RS]
1036 - [RIP] [RP] REGISTER [RS] [RIS]
1037 - If we find a number without LP, we try to parse it as a literal integer
1038 constant (if LP == NULL), or as a register displacement.
1039 - We count parenthesis, and only skip whitespaces if we are inside them.
1040 - If we find an operator, we skip it.
1042 This function can also call a special function that will try to match
1043 unknown tokens. It will return 1 if the argument has been parsed
1044 successfully, or zero otherwise. */
1046 static struct expression
*
1047 stap_parse_argument (const char **arg
, struct type
*atype
,
1048 struct gdbarch
*gdbarch
)
1050 struct stap_parse_info p
;
1051 struct cleanup
*back_to
;
1053 /* We need to initialize the expression buffer, in order to begin
1054 our parsing efforts. The language here does not matter, since we
1055 are using our own parser. */
1056 initialize_expout (&p
.pstate
, 10, current_language
, gdbarch
);
1057 back_to
= make_cleanup (free_current_contents
, &p
.pstate
.expout
);
1062 p
.gdbarch
= gdbarch
;
1063 p
.inside_paren_p
= 0;
1065 stap_parse_argument_1 (&p
, 0, STAP_OPERAND_PREC_NONE
);
1067 discard_cleanups (back_to
);
1069 gdb_assert (p
.inside_paren_p
== 0);
1071 /* Casting the final expression to the appropriate type. */
1072 write_exp_elt_opcode (&p
.pstate
, UNOP_CAST
);
1073 write_exp_elt_type (&p
.pstate
, atype
);
1074 write_exp_elt_opcode (&p
.pstate
, UNOP_CAST
);
1076 reallocate_expout (&p
.pstate
);
1078 p
.arg
= skip_spaces_const (p
.arg
);
1081 /* We can safely return EXPOUT here. */
1082 return p
.pstate
.expout
;
1085 /* Function which parses an argument string from PROBE, correctly splitting
1086 the arguments and storing their information in properly ways.
1088 Consider the following argument string (x86 syntax):
1092 We have two arguments, `%eax' and `$10', both with 32-bit unsigned bitness.
1093 This function basically handles them, properly filling some structures with
1094 this information. */
1097 stap_parse_probe_arguments (struct stap_probe
*probe
, struct gdbarch
*gdbarch
)
1101 gdb_assert (!probe
->args_parsed
);
1102 cur
= probe
->args_u
.text
;
1103 probe
->args_parsed
= 1;
1104 probe
->args_u
.vec
= NULL
;
1106 if (cur
== NULL
|| *cur
== '\0' || *cur
== ':')
1109 while (*cur
!= '\0')
1111 struct stap_probe_arg arg
;
1112 enum stap_arg_bitness b
;
1114 struct expression
*expr
;
1116 memset (&arg
, 0, sizeof (arg
));
1118 /* We expect to find something like:
1122 Where `N' can be [+,-][1,2,4,8]. This is not mandatory, so
1123 we check it here. If we don't find it, go to the next
1125 if ((cur
[0] == '-' && isdigit (cur
[1]) && cur
[2] == '@')
1126 || (isdigit (cur
[0]) && cur
[1] == '@'))
1130 /* Discard the `-'. */
1135 /* Defining the bitness. */
1139 b
= (got_minus
? STAP_ARG_BITNESS_8BIT_SIGNED
1140 : STAP_ARG_BITNESS_8BIT_UNSIGNED
);
1144 b
= (got_minus
? STAP_ARG_BITNESS_16BIT_SIGNED
1145 : STAP_ARG_BITNESS_16BIT_UNSIGNED
);
1149 b
= (got_minus
? STAP_ARG_BITNESS_32BIT_SIGNED
1150 : STAP_ARG_BITNESS_32BIT_UNSIGNED
);
1154 b
= (got_minus
? STAP_ARG_BITNESS_64BIT_SIGNED
1155 : STAP_ARG_BITNESS_64BIT_UNSIGNED
);
1160 /* We have an error, because we don't expect anything
1161 except 1, 2, 4 and 8. */
1162 warning (_("unrecognized bitness %s%c' for probe `%s'"),
1163 got_minus
? "`-" : "`", *cur
, probe
->p
.name
);
1170 /* Discard the number and the `@' sign. */
1174 arg
.bitness
= STAP_ARG_BITNESS_UNDEFINED
;
1176 arg
.atype
= stap_get_expected_argument_type (gdbarch
, arg
.bitness
);
1178 expr
= stap_parse_argument (&cur
, arg
.atype
, gdbarch
);
1180 if (stap_expression_debug
)
1181 dump_raw_expression (expr
, gdb_stdlog
,
1182 "before conversion to prefix form");
1184 prefixify_expression (expr
);
1186 if (stap_expression_debug
)
1187 dump_prefix_expression (expr
, gdb_stdlog
);
1191 /* Start it over again. */
1192 cur
= skip_spaces_const (cur
);
1194 VEC_safe_push (stap_probe_arg_s
, probe
->args_u
.vec
, &arg
);
1198 /* Implementation of the get_probe_address method. */
1201 stap_get_probe_address (struct probe
*probe
, struct objfile
*objfile
)
1203 return probe
->address
+ ANOFFSET (objfile
->section_offsets
,
1204 SECT_OFF_DATA (objfile
));
1207 /* Given PROBE, returns the number of arguments present in that probe's
1211 stap_get_probe_argument_count (struct probe
*probe_generic
,
1212 struct frame_info
*frame
)
1214 struct stap_probe
*probe
= (struct stap_probe
*) probe_generic
;
1215 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1217 gdb_assert (probe_generic
->pops
== &stap_probe_ops
);
1219 if (!probe
->args_parsed
)
1221 if (can_evaluate_probe_arguments (probe_generic
))
1222 stap_parse_probe_arguments (probe
, gdbarch
);
1225 static int have_warned_stap_incomplete
= 0;
1227 if (!have_warned_stap_incomplete
)
1230 "The SystemTap SDT probe support is not fully implemented on this target;\n"
1231 "you will not be able to inspect the arguments of the probes.\n"
1232 "Please report a bug against GDB requesting a port to this target."));
1233 have_warned_stap_incomplete
= 1;
1236 /* Marking the arguments as "already parsed". */
1237 probe
->args_u
.vec
= NULL
;
1238 probe
->args_parsed
= 1;
1242 gdb_assert (probe
->args_parsed
);
1243 return VEC_length (stap_probe_arg_s
, probe
->args_u
.vec
);
1246 /* Return 1 if OP is a valid operator inside a probe argument, or zero
1250 stap_is_operator (const char *op
)
1275 /* We didn't find any operator. */
1282 static struct stap_probe_arg
*
1283 stap_get_arg (struct stap_probe
*probe
, unsigned n
, struct gdbarch
*gdbarch
)
1285 if (!probe
->args_parsed
)
1286 stap_parse_probe_arguments (probe
, gdbarch
);
1288 return VEC_index (stap_probe_arg_s
, probe
->args_u
.vec
, n
);
1291 /* Implement the `can_evaluate_probe_arguments' method of probe_ops. */
1294 stap_can_evaluate_probe_arguments (struct probe
*probe_generic
)
1296 struct stap_probe
*stap_probe
= (struct stap_probe
*) probe_generic
;
1297 struct gdbarch
*gdbarch
= stap_probe
->p
.arch
;
1299 /* For SystemTap probes, we have to guarantee that the method
1300 stap_is_single_operand is defined on gdbarch. If it is not, then it
1301 means that argument evaluation is not implemented on this target. */
1302 return gdbarch_stap_is_single_operand_p (gdbarch
);
1305 /* Evaluate the probe's argument N (indexed from 0), returning a value
1306 corresponding to it. Assertion is thrown if N does not exist. */
1308 static struct value
*
1309 stap_evaluate_probe_argument (struct probe
*probe_generic
, unsigned n
,
1310 struct frame_info
*frame
)
1312 struct stap_probe
*stap_probe
= (struct stap_probe
*) probe_generic
;
1313 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1314 struct stap_probe_arg
*arg
;
1317 gdb_assert (probe_generic
->pops
== &stap_probe_ops
);
1319 arg
= stap_get_arg (stap_probe
, n
, gdbarch
);
1320 return evaluate_subexp_standard (arg
->atype
, arg
->aexpr
, &pos
, EVAL_NORMAL
);
1323 /* Compile the probe's argument N (indexed from 0) to agent expression.
1324 Assertion is thrown if N does not exist. */
1327 stap_compile_to_ax (struct probe
*probe_generic
, struct agent_expr
*expr
,
1328 struct axs_value
*value
, unsigned n
)
1330 struct stap_probe
*stap_probe
= (struct stap_probe
*) probe_generic
;
1331 struct stap_probe_arg
*arg
;
1332 union exp_element
*pc
;
1334 gdb_assert (probe_generic
->pops
== &stap_probe_ops
);
1336 arg
= stap_get_arg (stap_probe
, n
, expr
->gdbarch
);
1338 pc
= arg
->aexpr
->elts
;
1339 gen_expr (arg
->aexpr
, &pc
, expr
, value
);
1341 require_rvalue (expr
, value
);
1342 value
->type
= arg
->atype
;
1345 /* Destroy (free) the data related to PROBE. PROBE memory itself is not feed
1346 as it is allocated on an obstack. */
1349 stap_probe_destroy (struct probe
*probe_generic
)
1351 struct stap_probe
*probe
= (struct stap_probe
*) probe_generic
;
1353 gdb_assert (probe_generic
->pops
== &stap_probe_ops
);
1355 if (probe
->args_parsed
)
1357 struct stap_probe_arg
*arg
;
1360 for (ix
= 0; VEC_iterate (stap_probe_arg_s
, probe
->args_u
.vec
, ix
, arg
);
1363 VEC_free (stap_probe_arg_s
, probe
->args_u
.vec
);
1369 /* This is called to compute the value of one of the $_probe_arg*
1370 convenience variables. */
1372 static struct value
*
1373 compute_probe_arg (struct gdbarch
*arch
, struct internalvar
*ivar
,
1376 struct frame_info
*frame
= get_selected_frame (_("No frame selected"));
1377 CORE_ADDR pc
= get_frame_pc (frame
);
1378 int sel
= (int) (uintptr_t) data
;
1379 struct bound_probe pc_probe
;
1380 const struct sym_probe_fns
*pc_probe_fns
;
1383 /* SEL == -1 means "_probe_argc". */
1384 gdb_assert (sel
>= -1);
1386 pc_probe
= find_probe_by_pc (pc
);
1387 if (pc_probe
.probe
== NULL
)
1388 error (_("No SystemTap probe at PC %s"), core_addr_to_string (pc
));
1390 n_args
= get_probe_argument_count (pc_probe
.probe
, frame
);
1392 return value_from_longest (builtin_type (arch
)->builtin_int
, n_args
);
1395 error (_("Invalid probe argument %d -- probe has %u arguments available"),
1398 return evaluate_probe_argument (pc_probe
.probe
, sel
, frame
);
1401 /* This is called to compile one of the $_probe_arg* convenience
1402 variables into an agent expression. */
1405 compile_probe_arg (struct internalvar
*ivar
, struct agent_expr
*expr
,
1406 struct axs_value
*value
, void *data
)
1408 CORE_ADDR pc
= expr
->scope
;
1409 int sel
= (int) (uintptr_t) data
;
1410 struct bound_probe pc_probe
;
1411 const struct sym_probe_fns
*pc_probe_fns
;
1413 struct frame_info
*frame
= get_selected_frame (NULL
);
1415 /* SEL == -1 means "_probe_argc". */
1416 gdb_assert (sel
>= -1);
1418 pc_probe
= find_probe_by_pc (pc
);
1419 if (pc_probe
.probe
== NULL
)
1420 error (_("No SystemTap probe at PC %s"), core_addr_to_string (pc
));
1422 n_args
= get_probe_argument_count (pc_probe
.probe
, frame
);
1426 value
->kind
= axs_rvalue
;
1427 value
->type
= builtin_type (expr
->gdbarch
)->builtin_int
;
1428 ax_const_l (expr
, n_args
);
1432 gdb_assert (sel
>= 0);
1434 error (_("Invalid probe argument %d -- probe has %d arguments available"),
1437 pc_probe
.probe
->pops
->compile_to_ax (pc_probe
.probe
, expr
, value
, sel
);
1442 /* Set or clear a SystemTap semaphore. ADDRESS is the semaphore's
1443 address. SET is zero if the semaphore should be cleared, or one
1444 if it should be set. This is a helper function for `stap_semaphore_down'
1445 and `stap_semaphore_up'. */
1448 stap_modify_semaphore (CORE_ADDR address
, int set
, struct gdbarch
*gdbarch
)
1450 gdb_byte bytes
[sizeof (LONGEST
)];
1451 /* The ABI specifies "unsigned short". */
1452 struct type
*type
= builtin_type (gdbarch
)->builtin_unsigned_short
;
1458 /* Swallow errors. */
1459 if (target_read_memory (address
, bytes
, TYPE_LENGTH (type
)) != 0)
1461 warning (_("Could not read the value of a SystemTap semaphore."));
1465 value
= extract_unsigned_integer (bytes
, TYPE_LENGTH (type
),
1466 gdbarch_byte_order (gdbarch
));
1467 /* Note that we explicitly don't worry about overflow or
1474 store_unsigned_integer (bytes
, TYPE_LENGTH (type
),
1475 gdbarch_byte_order (gdbarch
), value
);
1477 if (target_write_memory (address
, bytes
, TYPE_LENGTH (type
)) != 0)
1478 warning (_("Could not write the value of a SystemTap semaphore."));
1481 /* Set a SystemTap semaphore. SEM is the semaphore's address. Semaphores
1482 act as reference counters, so calls to this function must be paired with
1483 calls to `stap_semaphore_down'.
1485 This function and `stap_semaphore_down' race with another tool changing
1486 the probes, but that is too rare to care. */
1489 stap_set_semaphore (struct probe
*probe_generic
, struct objfile
*objfile
,
1490 struct gdbarch
*gdbarch
)
1492 struct stap_probe
*probe
= (struct stap_probe
*) probe_generic
;
1495 gdb_assert (probe_generic
->pops
== &stap_probe_ops
);
1497 addr
= (probe
->sem_addr
1498 + ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
)));
1499 stap_modify_semaphore (addr
, 1, gdbarch
);
1502 /* Clear a SystemTap semaphore. SEM is the semaphore's address. */
1505 stap_clear_semaphore (struct probe
*probe_generic
, struct objfile
*objfile
,
1506 struct gdbarch
*gdbarch
)
1508 struct stap_probe
*probe
= (struct stap_probe
*) probe_generic
;
1511 gdb_assert (probe_generic
->pops
== &stap_probe_ops
);
1513 addr
= (probe
->sem_addr
1514 + ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
)));
1515 stap_modify_semaphore (addr
, 0, gdbarch
);
1518 /* Implementation of `$_probe_arg*' set of variables. */
1520 static const struct internalvar_funcs probe_funcs
=
1527 /* Helper function that parses the information contained in a
1528 SystemTap's probe. Basically, the information consists in:
1530 - Probe's PC address;
1531 - Link-time section address of `.stapsdt.base' section;
1532 - Link-time address of the semaphore variable, or ZERO if the
1533 probe doesn't have an associated semaphore;
1534 - Probe's provider name;
1536 - Probe's argument format
1538 This function returns 1 if the handling was successful, and zero
1542 handle_stap_probe (struct objfile
*objfile
, struct sdt_note
*el
,
1543 VEC (probe_p
) **probesp
, CORE_ADDR base
)
1545 bfd
*abfd
= objfile
->obfd
;
1546 int size
= bfd_get_arch_size (abfd
) / 8;
1547 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1548 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
1550 const char *probe_args
= NULL
;
1551 struct stap_probe
*ret
;
1553 ret
= obstack_alloc (&objfile
->per_bfd
->storage_obstack
, sizeof (*ret
));
1554 ret
->p
.pops
= &stap_probe_ops
;
1555 ret
->p
.arch
= gdbarch
;
1557 /* Provider and the name of the probe. */
1558 ret
->p
.provider
= (char *) &el
->data
[3 * size
];
1559 ret
->p
.name
= memchr (ret
->p
.provider
, '\0',
1560 (char *) el
->data
+ el
->size
- ret
->p
.provider
);
1561 /* Making sure there is a name. */
1562 if (ret
->p
.name
== NULL
)
1564 complaint (&symfile_complaints
, _("corrupt probe name when "
1566 objfile_name (objfile
));
1568 /* There is no way to use a probe without a name or a provider, so
1569 returning zero here makes sense. */
1575 /* Retrieving the probe's address. */
1576 ret
->p
.address
= extract_typed_address (&el
->data
[0], ptr_type
);
1578 /* Link-time sh_addr of `.stapsdt.base' section. */
1579 base_ref
= extract_typed_address (&el
->data
[size
], ptr_type
);
1581 /* Semaphore address. */
1582 ret
->sem_addr
= extract_typed_address (&el
->data
[2 * size
], ptr_type
);
1584 ret
->p
.address
+= base
- base_ref
;
1585 if (ret
->sem_addr
!= 0)
1586 ret
->sem_addr
+= base
- base_ref
;
1588 /* Arguments. We can only extract the argument format if there is a valid
1589 name for this probe. */
1590 probe_args
= memchr (ret
->p
.name
, '\0',
1591 (char *) el
->data
+ el
->size
- ret
->p
.name
);
1593 if (probe_args
!= NULL
)
1596 if (probe_args
== NULL
1597 || (memchr (probe_args
, '\0', (char *) el
->data
+ el
->size
- ret
->p
.name
)
1598 != el
->data
+ el
->size
- 1))
1600 complaint (&symfile_complaints
, _("corrupt probe argument when "
1602 objfile_name (objfile
));
1603 /* If the argument string is NULL, it means some problem happened with
1604 it. So we return 0. */
1608 ret
->args_parsed
= 0;
1609 ret
->args_u
.text
= (void *) probe_args
;
1611 /* Successfully created probe. */
1612 VEC_safe_push (probe_p
, *probesp
, (struct probe
*) ret
);
1615 /* Helper function which tries to find the base address of the SystemTap
1616 base section named STAP_BASE_SECTION_NAME. */
1619 get_stap_base_address_1 (bfd
*abfd
, asection
*sect
, void *obj
)
1621 asection
**ret
= obj
;
1623 if ((sect
->flags
& (SEC_DATA
| SEC_ALLOC
| SEC_HAS_CONTENTS
))
1624 && sect
->name
&& !strcmp (sect
->name
, STAP_BASE_SECTION_NAME
))
1628 /* Helper function which iterates over every section in the BFD file,
1629 trying to find the base address of the SystemTap base section.
1630 Returns 1 if found (setting BASE to the proper value), zero otherwise. */
1633 get_stap_base_address (bfd
*obfd
, bfd_vma
*base
)
1635 asection
*ret
= NULL
;
1637 bfd_map_over_sections (obfd
, get_stap_base_address_1
, (void *) &ret
);
1641 complaint (&symfile_complaints
, _("could not obtain base address for "
1642 "SystemTap section on objfile `%s'."),
1653 /* Helper function for `elf_get_probes', which gathers information about all
1654 SystemTap probes from OBJFILE. */
1657 stap_get_probes (VEC (probe_p
) **probesp
, struct objfile
*objfile
)
1659 /* If we are here, then this is the first time we are parsing the
1660 SystemTap probe's information. We basically have to count how many
1661 probes the objfile has, and then fill in the necessary information
1663 bfd
*obfd
= objfile
->obfd
;
1665 struct sdt_note
*iter
;
1666 unsigned save_probesp_len
= VEC_length (probe_p
, *probesp
);
1668 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
1670 /* This is a .debug file, not the objfile itself. */
1674 if (elf_tdata (obfd
)->sdt_note_head
== NULL
)
1676 /* There isn't any probe here. */
1680 if (!get_stap_base_address (obfd
, &base
))
1682 /* There was an error finding the base address for the section.
1683 Just return NULL. */
1687 /* Parsing each probe's information. */
1688 for (iter
= elf_tdata (obfd
)->sdt_note_head
;
1692 /* We first have to handle all the information about the
1693 probe which is present in the section. */
1694 handle_stap_probe (objfile
, iter
, probesp
, base
);
1697 if (save_probesp_len
== VEC_length (probe_p
, *probesp
))
1699 /* If we are here, it means we have failed to parse every known
1701 complaint (&symfile_complaints
, _("could not parse SystemTap probe(s) "
1708 stap_probe_is_linespec (const char **linespecp
)
1710 static const char *const keywords
[] = { "-pstap", "-probe-stap", NULL
};
1712 return probe_is_linespec_by_keyword (linespecp
, keywords
);
1716 stap_gen_info_probes_table_header (VEC (info_probe_column_s
) **heads
)
1718 info_probe_column_s stap_probe_column
;
1720 stap_probe_column
.field_name
= "semaphore";
1721 stap_probe_column
.print_name
= _("Semaphore");
1723 VEC_safe_push (info_probe_column_s
, *heads
, &stap_probe_column
);
1727 stap_gen_info_probes_table_values (struct probe
*probe_generic
,
1728 VEC (const_char_ptr
) **ret
)
1730 struct stap_probe
*probe
= (struct stap_probe
*) probe_generic
;
1731 struct gdbarch
*gdbarch
;
1732 const char *val
= NULL
;
1734 gdb_assert (probe_generic
->pops
== &stap_probe_ops
);
1736 gdbarch
= probe
->p
.arch
;
1738 if (probe
->sem_addr
!= 0)
1739 val
= print_core_address (gdbarch
, probe
->sem_addr
);
1741 VEC_safe_push (const_char_ptr
, *ret
, val
);
1744 /* SystemTap probe_ops. */
1746 static const struct probe_ops stap_probe_ops
=
1748 stap_probe_is_linespec
,
1750 stap_get_probe_address
,
1751 stap_get_probe_argument_count
,
1752 stap_can_evaluate_probe_arguments
,
1753 stap_evaluate_probe_argument
,
1756 stap_clear_semaphore
,
1758 stap_gen_info_probes_table_header
,
1759 stap_gen_info_probes_table_values
,
1762 /* Implementation of the `info probes stap' command. */
1765 info_probes_stap_command (char *arg
, int from_tty
)
1767 info_probes_for_ops (arg
, from_tty
, &stap_probe_ops
);
1770 void _initialize_stap_probe (void);
1773 _initialize_stap_probe (void)
1775 VEC_safe_push (probe_ops_cp
, all_probe_ops
, &stap_probe_ops
);
1777 add_setshow_zuinteger_cmd ("stap-expression", class_maintenance
,
1778 &stap_expression_debug
,
1779 _("Set SystemTap expression debugging."),
1780 _("Show SystemTap expression debugging."),
1781 _("When non-zero, the internal representation "
1782 "of SystemTap expressions will be printed."),
1784 show_stapexpressiondebug
,
1785 &setdebuglist
, &showdebuglist
);
1787 create_internalvar_type_lazy ("_probe_argc", &probe_funcs
,
1788 (void *) (uintptr_t) -1);
1789 create_internalvar_type_lazy ("_probe_arg0", &probe_funcs
,
1790 (void *) (uintptr_t) 0);
1791 create_internalvar_type_lazy ("_probe_arg1", &probe_funcs
,
1792 (void *) (uintptr_t) 1);
1793 create_internalvar_type_lazy ("_probe_arg2", &probe_funcs
,
1794 (void *) (uintptr_t) 2);
1795 create_internalvar_type_lazy ("_probe_arg3", &probe_funcs
,
1796 (void *) (uintptr_t) 3);
1797 create_internalvar_type_lazy ("_probe_arg4", &probe_funcs
,
1798 (void *) (uintptr_t) 4);
1799 create_internalvar_type_lazy ("_probe_arg5", &probe_funcs
,
1800 (void *) (uintptr_t) 5);
1801 create_internalvar_type_lazy ("_probe_arg6", &probe_funcs
,
1802 (void *) (uintptr_t) 6);
1803 create_internalvar_type_lazy ("_probe_arg7", &probe_funcs
,
1804 (void *) (uintptr_t) 7);
1805 create_internalvar_type_lazy ("_probe_arg8", &probe_funcs
,
1806 (void *) (uintptr_t) 8);
1807 create_internalvar_type_lazy ("_probe_arg9", &probe_funcs
,
1808 (void *) (uintptr_t) 9);
1809 create_internalvar_type_lazy ("_probe_arg10", &probe_funcs
,
1810 (void *) (uintptr_t) 10);
1811 create_internalvar_type_lazy ("_probe_arg11", &probe_funcs
,
1812 (void *) (uintptr_t) 11);
1814 add_cmd ("stap", class_info
, info_probes_stap_command
,
1816 Show information about SystemTap static probes.\n\
1817 Usage: info probes stap [PROVIDER [NAME [OBJECT]]]\n\
1818 Each argument is a regular expression, used to select probes.\n\
1819 PROVIDER matches probe provider names.\n\
1820 NAME matches the probe names.\n\
1821 OBJECT matches the executable or shared library name."),
1822 info_probes_cmdlist_get ());