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"
33 #include "complaints.h"
34 #include "cli/cli-utils.h"
36 #include "user-regs.h"
37 #include "parser-defs.h"
43 /* The name of the SystemTap section where we will find information about
46 #define STAP_BASE_SECTION_NAME ".stapsdt.base"
48 /* Forward declaration. */
50 static const struct probe_ops stap_probe_ops
;
52 /* Should we display debug information for the probe's argument expression
55 static unsigned int stap_expression_debug
= 0;
57 /* The various possibilities of bitness defined for a probe's argument.
61 - STAP_ARG_BITNESS_UNDEFINED: The user hasn't specified the bitness.
62 - STAP_ARG_BITNESS_8BIT_UNSIGNED: argument string starts with `1@'.
63 - STAP_ARG_BITNESS_8BIT_SIGNED: argument string starts with `-1@'.
64 - STAP_ARG_BITNESS_16BIT_UNSIGNED: argument string starts with `2@'.
65 - STAP_ARG_BITNESS_16BIT_SIGNED: argument string starts with `-2@'.
66 - STAP_ARG_BITNESS_32BIT_UNSIGNED: argument string starts with `4@'.
67 - STAP_ARG_BITNESS_32BIT_SIGNED: argument string starts with `-4@'.
68 - STAP_ARG_BITNESS_64BIT_UNSIGNED: argument string starts with `8@'.
69 - STAP_ARG_BITNESS_64BIT_SIGNED: argument string starts with `-8@'. */
73 STAP_ARG_BITNESS_UNDEFINED
,
74 STAP_ARG_BITNESS_8BIT_UNSIGNED
,
75 STAP_ARG_BITNESS_8BIT_SIGNED
,
76 STAP_ARG_BITNESS_16BIT_UNSIGNED
,
77 STAP_ARG_BITNESS_16BIT_SIGNED
,
78 STAP_ARG_BITNESS_32BIT_UNSIGNED
,
79 STAP_ARG_BITNESS_32BIT_SIGNED
,
80 STAP_ARG_BITNESS_64BIT_UNSIGNED
,
81 STAP_ARG_BITNESS_64BIT_SIGNED
,
84 /* The following structure represents a single argument for the probe. */
88 /* The bitness of this argument. */
89 enum stap_arg_bitness bitness
;
91 /* The corresponding `struct type *' to the bitness. */
94 /* The argument converted to an internal GDB expression. */
95 struct expression
*aexpr
;
98 typedef struct stap_probe_arg stap_probe_arg_s
;
99 DEF_VEC_O (stap_probe_arg_s
);
103 /* Generic information about the probe. This shall be the first element
104 of this struct, in order to maintain binary compatibility with the
105 `struct probe' and be able to fully abstract it. */
108 /* If the probe has a semaphore associated, then this is the value of
109 it, relative to SECT_OFF_DATA. */
112 /* One if the arguments have been parsed. */
113 unsigned int args_parsed
: 1;
119 /* Information about each argument. This is an array of `stap_probe_arg',
120 with each entry representing one argument. */
121 VEC (stap_probe_arg_s
) *vec
;
126 /* When parsing the arguments, we have to establish different precedences
127 for the various kinds of asm operators. This enumeration represents those
130 This logic behind this is available at
131 <http://sourceware.org/binutils/docs/as/Infix-Ops.html#Infix-Ops>, or using
132 the command "info '(as)Infix Ops'". */
134 enum stap_operand_prec
136 /* Lowest precedence, used for non-recognized operands or for the beginning
137 of the parsing process. */
138 STAP_OPERAND_PREC_NONE
= 0,
140 /* Precedence of logical OR. */
141 STAP_OPERAND_PREC_LOGICAL_OR
,
143 /* Precedence of logical AND. */
144 STAP_OPERAND_PREC_LOGICAL_AND
,
146 /* Precedence of additive (plus, minus) and comparative (equal, less,
147 greater-than, etc) operands. */
148 STAP_OPERAND_PREC_ADD_CMP
,
150 /* Precedence of bitwise operands (bitwise OR, XOR, bitwise AND,
152 STAP_OPERAND_PREC_BITWISE
,
154 /* Precedence of multiplicative operands (multiplication, division,
155 remainder, left shift and right shift). */
156 STAP_OPERAND_PREC_MUL
159 static void stap_parse_argument_1 (struct stap_parse_info
*p
, int has_lhs
,
160 enum stap_operand_prec prec
);
162 static void stap_parse_argument_conditionally (struct stap_parse_info
*p
);
164 /* Returns 1 if *S is an operator, zero otherwise. */
166 static int stap_is_operator (const char *op
);
169 show_stapexpressiondebug (struct ui_file
*file
, int from_tty
,
170 struct cmd_list_element
*c
, const char *value
)
172 fprintf_filtered (file
, _("SystemTap Probe expression debugging is %s.\n"),
176 /* Returns the operator precedence level of OP, or STAP_OPERAND_PREC_NONE
177 if the operator code was not recognized. */
179 static enum stap_operand_prec
180 stap_get_operator_prec (enum exp_opcode op
)
184 case BINOP_LOGICAL_OR
:
185 return STAP_OPERAND_PREC_LOGICAL_OR
;
187 case BINOP_LOGICAL_AND
:
188 return STAP_OPERAND_PREC_LOGICAL_AND
;
198 return STAP_OPERAND_PREC_ADD_CMP
;
200 case BINOP_BITWISE_IOR
:
201 case BINOP_BITWISE_AND
:
202 case BINOP_BITWISE_XOR
:
203 case UNOP_LOGICAL_NOT
:
204 return STAP_OPERAND_PREC_BITWISE
;
211 return STAP_OPERAND_PREC_MUL
;
214 return STAP_OPERAND_PREC_NONE
;
218 /* Given S, read the operator in it and fills the OP pointer with its code.
219 Return 1 on success, zero if the operator was not recognized. */
221 static enum exp_opcode
222 stap_get_opcode (const char **s
)
277 op
= BINOP_BITWISE_IOR
;
281 op
= BINOP_LOGICAL_OR
;
286 op
= BINOP_BITWISE_AND
;
290 op
= BINOP_LOGICAL_AND
;
295 op
= BINOP_BITWISE_XOR
;
299 op
= UNOP_LOGICAL_NOT
;
311 gdb_assert (**s
== '=');
316 internal_error (__FILE__
, __LINE__
,
317 _("Invalid opcode in expression `%s' for SystemTap"
324 /* Given the bitness of the argument, represented by B, return the
325 corresponding `struct type *'. */
328 stap_get_expected_argument_type (struct gdbarch
*gdbarch
,
329 enum stap_arg_bitness b
)
333 case STAP_ARG_BITNESS_UNDEFINED
:
334 if (gdbarch_addr_bit (gdbarch
) == 32)
335 return builtin_type (gdbarch
)->builtin_uint32
;
337 return builtin_type (gdbarch
)->builtin_uint64
;
339 case STAP_ARG_BITNESS_8BIT_UNSIGNED
:
340 return builtin_type (gdbarch
)->builtin_uint8
;
342 case STAP_ARG_BITNESS_8BIT_SIGNED
:
343 return builtin_type (gdbarch
)->builtin_int8
;
345 case STAP_ARG_BITNESS_16BIT_UNSIGNED
:
346 return builtin_type (gdbarch
)->builtin_uint16
;
348 case STAP_ARG_BITNESS_16BIT_SIGNED
:
349 return builtin_type (gdbarch
)->builtin_int16
;
351 case STAP_ARG_BITNESS_32BIT_SIGNED
:
352 return builtin_type (gdbarch
)->builtin_int32
;
354 case STAP_ARG_BITNESS_32BIT_UNSIGNED
:
355 return builtin_type (gdbarch
)->builtin_uint32
;
357 case STAP_ARG_BITNESS_64BIT_SIGNED
:
358 return builtin_type (gdbarch
)->builtin_int64
;
360 case STAP_ARG_BITNESS_64BIT_UNSIGNED
:
361 return builtin_type (gdbarch
)->builtin_uint64
;
364 internal_error (__FILE__
, __LINE__
,
365 _("Undefined bitness for probe."));
370 /* Helper function to check for a generic list of prefixes. GDBARCH
371 is the current gdbarch being used. S is the expression being
372 analyzed. If R is not NULL, it will be used to return the found
373 prefix. PREFIXES is the list of expected prefixes.
375 This function does a case-insensitive match.
377 Return 1 if any prefix has been found, zero otherwise. */
380 stap_is_generic_prefix (struct gdbarch
*gdbarch
, const char *s
,
381 const char **r
, const char *const *prefixes
)
383 const char *const *p
;
385 if (prefixes
== NULL
)
393 for (p
= prefixes
; *p
!= NULL
; ++p
)
394 if (strncasecmp (s
, *p
, strlen (*p
)) == 0)
405 /* Return 1 if S points to a register prefix, zero otherwise. For a
406 description of the arguments, look at stap_is_generic_prefix. */
409 stap_is_register_prefix (struct gdbarch
*gdbarch
, const char *s
,
412 const char *const *t
= gdbarch_stap_register_prefixes (gdbarch
);
414 return stap_is_generic_prefix (gdbarch
, s
, r
, t
);
417 /* Return 1 if S points to a register indirection prefix, zero
418 otherwise. For a description of the arguments, look at
419 stap_is_generic_prefix. */
422 stap_is_register_indirection_prefix (struct gdbarch
*gdbarch
, const char *s
,
425 const char *const *t
= gdbarch_stap_register_indirection_prefixes (gdbarch
);
427 return stap_is_generic_prefix (gdbarch
, s
, r
, t
);
430 /* Return 1 if S points to an integer prefix, zero otherwise. For a
431 description of the arguments, look at stap_is_generic_prefix.
433 This function takes care of analyzing whether we are dealing with
434 an expected integer prefix, or, if there is no integer prefix to be
435 expected, whether we are dealing with a digit. It does a
436 case-insensitive match. */
439 stap_is_integer_prefix (struct gdbarch
*gdbarch
, const char *s
,
442 const char *const *t
= gdbarch_stap_integer_prefixes (gdbarch
);
443 const char *const *p
;
447 /* A NULL value here means that integers do not have a prefix.
448 We just check for a digit then. */
455 for (p
= t
; *p
!= NULL
; ++p
)
457 size_t len
= strlen (*p
);
459 if ((len
== 0 && isdigit (*s
))
460 || (len
> 0 && strncasecmp (s
, *p
, len
) == 0))
462 /* Integers may or may not have a prefix. The "len == 0"
463 check covers the case when integers do not have a prefix
464 (therefore, we just check if we have a digit). The call
465 to "strncasecmp" covers the case when they have a
477 /* Helper function to check for a generic list of suffixes. If we are
478 not expecting any suffixes, then it just returns 1. If we are
479 expecting at least one suffix, then it returns 1 if a suffix has
480 been found, zero otherwise. GDBARCH is the current gdbarch being
481 used. S is the expression being analyzed. If R is not NULL, it
482 will be used to return the found suffix. SUFFIXES is the list of
483 expected suffixes. This function does a case-insensitive
487 stap_generic_check_suffix (struct gdbarch
*gdbarch
, const char *s
,
488 const char **r
, const char *const *suffixes
)
490 const char *const *p
;
493 if (suffixes
== NULL
)
501 for (p
= suffixes
; *p
!= NULL
; ++p
)
502 if (strncasecmp (s
, *p
, strlen (*p
)) == 0)
514 /* Return 1 if S points to an integer suffix, zero otherwise. For a
515 description of the arguments, look at
516 stap_generic_check_suffix. */
519 stap_check_integer_suffix (struct gdbarch
*gdbarch
, const char *s
,
522 const char *const *p
= gdbarch_stap_integer_suffixes (gdbarch
);
524 return stap_generic_check_suffix (gdbarch
, s
, r
, p
);
527 /* Return 1 if S points to a register suffix, zero otherwise. For a
528 description of the arguments, look at
529 stap_generic_check_suffix. */
532 stap_check_register_suffix (struct gdbarch
*gdbarch
, const char *s
,
535 const char *const *p
= gdbarch_stap_register_suffixes (gdbarch
);
537 return stap_generic_check_suffix (gdbarch
, s
, r
, p
);
540 /* Return 1 if S points to a register indirection suffix, zero
541 otherwise. For a description of the arguments, look at
542 stap_generic_check_suffix. */
545 stap_check_register_indirection_suffix (struct gdbarch
*gdbarch
, const char *s
,
548 const char *const *p
= gdbarch_stap_register_indirection_suffixes (gdbarch
);
550 return stap_generic_check_suffix (gdbarch
, s
, r
, p
);
553 /* Function responsible for parsing a register operand according to
554 SystemTap parlance. Assuming:
558 RIP = register indirection prefix
559 RIS = register indirection suffix
561 Then a register operand can be:
563 [RIP] [RP] REGISTER [RS] [RIS]
565 This function takes care of a register's indirection, displacement and
566 direct access. It also takes into consideration the fact that some
567 registers are named differently inside and outside GDB, e.g., PPC's
568 general-purpose registers are represented by integers in the assembly
569 language (e.g., `15' is the 15th general-purpose register), but inside
570 GDB they have a prefix (the letter `r') appended. */
573 stap_parse_register_operand (struct stap_parse_info
*p
)
575 /* Simple flag to indicate whether we have seen a minus signal before
578 /* Flags to indicate whether this register access is being displaced and/or
580 int disp_p
= 0, indirect_p
= 0;
581 struct gdbarch
*gdbarch
= p
->gdbarch
;
582 /* Needed to generate the register name as a part of an expression. */
584 /* Variables used to extract the register name from the probe's
589 const char *gdb_reg_prefix
= gdbarch_stap_gdb_register_prefix (gdbarch
);
590 int gdb_reg_prefix_len
= gdb_reg_prefix
? strlen (gdb_reg_prefix
) : 0;
591 const char *gdb_reg_suffix
= gdbarch_stap_gdb_register_suffix (gdbarch
);
592 int gdb_reg_suffix_len
= gdb_reg_suffix
? strlen (gdb_reg_suffix
) : 0;
593 const char *reg_prefix
;
594 const char *reg_ind_prefix
;
595 const char *reg_suffix
;
596 const char *reg_ind_suffix
;
598 /* Checking for a displacement argument. */
601 /* If it's a plus sign, we don't need to do anything, just advance the
612 if (isdigit (*p
->arg
))
614 /* The value of the displacement. */
619 displacement
= strtol (p
->arg
, &endp
, 10);
622 /* Generating the expression for the displacement. */
623 write_exp_elt_opcode (&p
->pstate
, OP_LONG
);
624 write_exp_elt_type (&p
->pstate
, builtin_type (gdbarch
)->builtin_long
);
625 write_exp_elt_longcst (&p
->pstate
, displacement
);
626 write_exp_elt_opcode (&p
->pstate
, OP_LONG
);
628 write_exp_elt_opcode (&p
->pstate
, UNOP_NEG
);
631 /* Getting rid of register indirection prefix. */
632 if (stap_is_register_indirection_prefix (gdbarch
, p
->arg
, ®_ind_prefix
))
635 p
->arg
+= strlen (reg_ind_prefix
);
638 if (disp_p
&& !indirect_p
)
639 error (_("Invalid register displacement syntax on expression `%s'."),
642 /* Getting rid of register prefix. */
643 if (stap_is_register_prefix (gdbarch
, p
->arg
, ®_prefix
))
644 p
->arg
+= strlen (reg_prefix
);
646 /* Now we should have only the register name. Let's extract it and get
647 the associated number. */
650 /* We assume the register name is composed by letters and numbers. */
651 while (isalnum (*p
->arg
))
654 len
= p
->arg
- start
;
656 regname
= alloca (len
+ gdb_reg_prefix_len
+ gdb_reg_suffix_len
+ 1);
659 /* We only add the GDB's register prefix/suffix if we are dealing with
660 a numeric register. */
661 if (gdb_reg_prefix
&& isdigit (*start
))
663 strncpy (regname
, gdb_reg_prefix
, gdb_reg_prefix_len
);
664 strncpy (regname
+ gdb_reg_prefix_len
, start
, len
);
667 strncpy (regname
+ gdb_reg_prefix_len
+ len
,
668 gdb_reg_suffix
, gdb_reg_suffix_len
);
670 len
+= gdb_reg_prefix_len
+ gdb_reg_suffix_len
;
673 strncpy (regname
, start
, len
);
677 /* Is this a valid register name? */
678 if (user_reg_map_name_to_regnum (gdbarch
, regname
, len
) == -1)
679 error (_("Invalid register name `%s' on expression `%s'."),
680 regname
, p
->saved_arg
);
682 write_exp_elt_opcode (&p
->pstate
, OP_REGISTER
);
685 write_exp_string (&p
->pstate
, str
);
686 write_exp_elt_opcode (&p
->pstate
, OP_REGISTER
);
691 write_exp_elt_opcode (&p
->pstate
, BINOP_ADD
);
693 /* Casting to the expected type. */
694 write_exp_elt_opcode (&p
->pstate
, UNOP_CAST
);
695 write_exp_elt_type (&p
->pstate
, lookup_pointer_type (p
->arg_type
));
696 write_exp_elt_opcode (&p
->pstate
, UNOP_CAST
);
698 write_exp_elt_opcode (&p
->pstate
, UNOP_IND
);
701 /* Getting rid of the register name suffix. */
702 if (stap_check_register_suffix (gdbarch
, p
->arg
, ®_suffix
))
703 p
->arg
+= strlen (reg_suffix
);
705 error (_("Missing register name suffix on expression `%s'."),
708 /* Getting rid of the register indirection suffix. */
711 if (stap_check_register_indirection_suffix (gdbarch
, p
->arg
,
713 p
->arg
+= strlen (reg_ind_suffix
);
715 error (_("Missing indirection suffix on expression `%s'."),
720 /* This function is responsible for parsing a single operand.
722 A single operand can be:
724 - an unary operation (e.g., `-5', `~2', or even with subexpressions
726 - a register displacement, which will be treated as a register
727 operand (e.g., `-4(%eax)' on x86)
728 - a numeric constant, or
729 - a register operand (see function `stap_parse_register_operand')
731 The function also calls special-handling functions to deal with
732 unrecognized operands, allowing arch-specific parsers to be
736 stap_parse_single_operand (struct stap_parse_info
*p
)
738 struct gdbarch
*gdbarch
= p
->gdbarch
;
739 const char *int_prefix
= NULL
;
741 /* We first try to parse this token as a "special token". */
742 if (gdbarch_stap_parse_special_token_p (gdbarch
))
743 if (gdbarch_stap_parse_special_token (gdbarch
, p
) != 0)
745 /* If the return value of the above function is not zero,
746 it means it successfully parsed the special token.
748 If it is NULL, we try to parse it using our method. */
752 if (*p
->arg
== '-' || *p
->arg
== '~' || *p
->arg
== '+')
755 /* We use this variable to do a lookahead. */
756 const char *tmp
= p
->arg
;
759 /* Skipping signal. */
762 /* This is an unary operation. Here is a list of allowed tokens
766 - number (from register displacement)
767 - subexpression (beginning with `(')
769 We handle the register displacement here, and the other cases
771 if (p
->inside_paren_p
)
772 tmp
= skip_spaces_const (tmp
);
774 while (isdigit (*tmp
))
776 /* We skip the digit here because we are only interested in
777 knowing what kind of unary operation this is. The digit
778 will be handled by one of the functions that will be
779 called below ('stap_parse_argument_conditionally' or
780 'stap_parse_register_operand'). */
785 if (has_digit
&& stap_is_register_indirection_prefix (gdbarch
, tmp
,
788 /* If we are here, it means it is a displacement. The only
789 operations allowed here are `-' and `+'. */
791 error (_("Invalid operator `%c' for register displacement "
792 "on expression `%s'."), c
, p
->saved_arg
);
794 stap_parse_register_operand (p
);
798 /* This is not a displacement. We skip the operator, and
799 deal with it when the recursion returns. */
801 stap_parse_argument_conditionally (p
);
803 write_exp_elt_opcode (&p
->pstate
, UNOP_NEG
);
805 write_exp_elt_opcode (&p
->pstate
, UNOP_COMPLEMENT
);
808 else if (isdigit (*p
->arg
))
810 /* A temporary variable, needed for lookahead. */
811 const char *tmp
= p
->arg
;
815 /* We can be dealing with a numeric constant, or with a register
817 number
= strtol (tmp
, &endp
, 10);
820 if (p
->inside_paren_p
)
821 tmp
= skip_spaces_const (tmp
);
823 /* If "stap_is_integer_prefix" returns true, it means we can
824 accept integers without a prefix here. But we also need to
825 check whether the next token (i.e., "tmp") is not a register
826 indirection prefix. */
827 if (stap_is_integer_prefix (gdbarch
, p
->arg
, NULL
)
828 && !stap_is_register_indirection_prefix (gdbarch
, tmp
, NULL
))
830 const char *int_suffix
;
832 /* We are dealing with a numeric constant. */
833 write_exp_elt_opcode (&p
->pstate
, OP_LONG
);
834 write_exp_elt_type (&p
->pstate
,
835 builtin_type (gdbarch
)->builtin_long
);
836 write_exp_elt_longcst (&p
->pstate
, number
);
837 write_exp_elt_opcode (&p
->pstate
, OP_LONG
);
841 if (stap_check_integer_suffix (gdbarch
, p
->arg
, &int_suffix
))
842 p
->arg
+= strlen (int_suffix
);
844 error (_("Invalid constant suffix on expression `%s'."),
847 else if (stap_is_register_indirection_prefix (gdbarch
, tmp
, NULL
))
848 stap_parse_register_operand (p
);
850 error (_("Unknown numeric token on expression `%s'."),
853 else if (stap_is_integer_prefix (gdbarch
, p
->arg
, &int_prefix
))
855 /* We are dealing with a numeric constant. */
858 const char *int_suffix
;
860 p
->arg
+= strlen (int_prefix
);
861 number
= strtol (p
->arg
, &endp
, 10);
864 write_exp_elt_opcode (&p
->pstate
, OP_LONG
);
865 write_exp_elt_type (&p
->pstate
, builtin_type (gdbarch
)->builtin_long
);
866 write_exp_elt_longcst (&p
->pstate
, number
);
867 write_exp_elt_opcode (&p
->pstate
, OP_LONG
);
869 if (stap_check_integer_suffix (gdbarch
, p
->arg
, &int_suffix
))
870 p
->arg
+= strlen (int_suffix
);
872 error (_("Invalid constant suffix on expression `%s'."),
875 else if (stap_is_register_prefix (gdbarch
, p
->arg
, NULL
)
876 || stap_is_register_indirection_prefix (gdbarch
, p
->arg
, NULL
))
877 stap_parse_register_operand (p
);
879 error (_("Operator `%c' not recognized on expression `%s'."),
880 *p
->arg
, p
->saved_arg
);
883 /* This function parses an argument conditionally, based on single or
884 non-single operands. A non-single operand would be a parenthesized
885 expression (e.g., `(2 + 1)'), and a single operand is anything that
886 starts with `-', `~', `+' (i.e., unary operators), a digit, or
887 something recognized by `gdbarch_stap_is_single_operand'. */
890 stap_parse_argument_conditionally (struct stap_parse_info
*p
)
892 gdb_assert (gdbarch_stap_is_single_operand_p (p
->gdbarch
));
894 if (*p
->arg
== '-' || *p
->arg
== '~' || *p
->arg
== '+' /* Unary. */
896 || gdbarch_stap_is_single_operand (p
->gdbarch
, p
->arg
))
897 stap_parse_single_operand (p
);
898 else if (*p
->arg
== '(')
900 /* We are dealing with a parenthesized operand. It means we
901 have to parse it as it was a separate expression, without
902 left-side or precedence. */
904 p
->arg
= skip_spaces_const (p
->arg
);
907 stap_parse_argument_1 (p
, 0, STAP_OPERAND_PREC_NONE
);
911 error (_("Missign close-paren on expression `%s'."),
915 if (p
->inside_paren_p
)
916 p
->arg
= skip_spaces_const (p
->arg
);
919 error (_("Cannot parse expression `%s'."), p
->saved_arg
);
922 /* Helper function for `stap_parse_argument'. Please, see its comments to
923 better understand what this function does. */
926 stap_parse_argument_1 (struct stap_parse_info
*p
, int has_lhs
,
927 enum stap_operand_prec prec
)
929 /* This is an operator-precedence parser.
931 We work with left- and right-sides of expressions, and
932 parse them depending on the precedence of the operators
935 gdb_assert (p
->arg
!= NULL
);
937 if (p
->inside_paren_p
)
938 p
->arg
= skip_spaces_const (p
->arg
);
942 /* We were called without a left-side, either because this is the
943 first call, or because we were called to parse a parenthesized
944 expression. It doesn't really matter; we have to parse the
945 left-side in order to continue the process. */
946 stap_parse_argument_conditionally (p
);
949 /* Start to parse the right-side, and to "join" left and right sides
950 depending on the operation specified.
952 This loop shall continue until we run out of characters in the input,
953 or until we find a close-parenthesis, which means that we've reached
954 the end of a sub-expression. */
955 while (*p
->arg
!= '\0' && *p
->arg
!= ')' && !isspace (*p
->arg
))
957 const char *tmp_exp_buf
;
958 enum exp_opcode opcode
;
959 enum stap_operand_prec cur_prec
;
961 if (!stap_is_operator (p
->arg
))
962 error (_("Invalid operator `%c' on expression `%s'."), *p
->arg
,
965 /* We have to save the current value of the expression buffer because
966 the `stap_get_opcode' modifies it in order to get the current
967 operator. If this operator's precedence is lower than PREC, we
968 should return and not advance the expression buffer pointer. */
969 tmp_exp_buf
= p
->arg
;
970 opcode
= stap_get_opcode (&tmp_exp_buf
);
972 cur_prec
= stap_get_operator_prec (opcode
);
975 /* If the precedence of the operator that we are seeing now is
976 lower than the precedence of the first operator seen before
977 this parsing process began, it means we should stop parsing
982 p
->arg
= tmp_exp_buf
;
983 if (p
->inside_paren_p
)
984 p
->arg
= skip_spaces_const (p
->arg
);
986 /* Parse the right-side of the expression. */
987 stap_parse_argument_conditionally (p
);
989 /* While we still have operators, try to parse another
990 right-side, but using the current right-side as a left-side. */
991 while (*p
->arg
!= '\0' && stap_is_operator (p
->arg
))
993 enum exp_opcode lookahead_opcode
;
994 enum stap_operand_prec lookahead_prec
;
996 /* Saving the current expression buffer position. The explanation
997 is the same as above. */
998 tmp_exp_buf
= p
->arg
;
999 lookahead_opcode
= stap_get_opcode (&tmp_exp_buf
);
1000 lookahead_prec
= stap_get_operator_prec (lookahead_opcode
);
1002 if (lookahead_prec
<= prec
)
1004 /* If we are dealing with an operator whose precedence is lower
1005 than the first one, just abandon the attempt. */
1009 /* Parse the right-side of the expression, but since we already
1010 have a left-side at this point, set `has_lhs' to 1. */
1011 stap_parse_argument_1 (p
, 1, lookahead_prec
);
1014 write_exp_elt_opcode (&p
->pstate
, opcode
);
1018 /* Parse a probe's argument.
1022 LP = literal integer prefix
1023 LS = literal integer suffix
1025 RP = register prefix
1026 RS = register suffix
1028 RIP = register indirection prefix
1029 RIS = register indirection suffix
1031 This routine assumes that arguments' tokens are of the form:
1034 - [RP] REGISTER [RS]
1035 - [RIP] [RP] REGISTER [RS] [RIS]
1036 - If we find a number without LP, we try to parse it as a literal integer
1037 constant (if LP == NULL), or as a register displacement.
1038 - We count parenthesis, and only skip whitespaces if we are inside them.
1039 - If we find an operator, we skip it.
1041 This function can also call a special function that will try to match
1042 unknown tokens. It will return 1 if the argument has been parsed
1043 successfully, or zero otherwise. */
1045 static struct expression
*
1046 stap_parse_argument (const char **arg
, struct type
*atype
,
1047 struct gdbarch
*gdbarch
)
1049 struct stap_parse_info p
;
1050 struct cleanup
*back_to
;
1052 /* We need to initialize the expression buffer, in order to begin
1053 our parsing efforts. We use language_c here because we may need
1054 to do pointer arithmetics. */
1055 initialize_expout (&p
.pstate
, 10, language_def (language_c
), gdbarch
);
1056 back_to
= make_cleanup (free_current_contents
, &p
.pstate
.expout
);
1061 p
.gdbarch
= gdbarch
;
1062 p
.inside_paren_p
= 0;
1064 stap_parse_argument_1 (&p
, 0, STAP_OPERAND_PREC_NONE
);
1066 discard_cleanups (back_to
);
1068 gdb_assert (p
.inside_paren_p
== 0);
1070 /* Casting the final expression to the appropriate type. */
1071 write_exp_elt_opcode (&p
.pstate
, UNOP_CAST
);
1072 write_exp_elt_type (&p
.pstate
, atype
);
1073 write_exp_elt_opcode (&p
.pstate
, UNOP_CAST
);
1075 reallocate_expout (&p
.pstate
);
1077 p
.arg
= skip_spaces_const (p
.arg
);
1080 /* We can safely return EXPOUT here. */
1081 return p
.pstate
.expout
;
1084 /* Function which parses an argument string from PROBE, correctly splitting
1085 the arguments and storing their information in properly ways.
1087 Consider the following argument string (x86 syntax):
1091 We have two arguments, `%eax' and `$10', both with 32-bit unsigned bitness.
1092 This function basically handles them, properly filling some structures with
1093 this information. */
1096 stap_parse_probe_arguments (struct stap_probe
*probe
, struct gdbarch
*gdbarch
)
1100 gdb_assert (!probe
->args_parsed
);
1101 cur
= probe
->args_u
.text
;
1102 probe
->args_parsed
= 1;
1103 probe
->args_u
.vec
= NULL
;
1105 if (cur
== NULL
|| *cur
== '\0' || *cur
== ':')
1108 while (*cur
!= '\0')
1110 struct stap_probe_arg arg
;
1111 enum stap_arg_bitness b
;
1113 struct expression
*expr
;
1115 memset (&arg
, 0, sizeof (arg
));
1117 /* We expect to find something like:
1121 Where `N' can be [+,-][1,2,4,8]. This is not mandatory, so
1122 we check it here. If we don't find it, go to the next
1124 if ((cur
[0] == '-' && isdigit (cur
[1]) && cur
[2] == '@')
1125 || (isdigit (cur
[0]) && cur
[1] == '@'))
1129 /* Discard the `-'. */
1134 /* Defining the bitness. */
1138 b
= (got_minus
? STAP_ARG_BITNESS_8BIT_SIGNED
1139 : STAP_ARG_BITNESS_8BIT_UNSIGNED
);
1143 b
= (got_minus
? STAP_ARG_BITNESS_16BIT_SIGNED
1144 : STAP_ARG_BITNESS_16BIT_UNSIGNED
);
1148 b
= (got_minus
? STAP_ARG_BITNESS_32BIT_SIGNED
1149 : STAP_ARG_BITNESS_32BIT_UNSIGNED
);
1153 b
= (got_minus
? STAP_ARG_BITNESS_64BIT_SIGNED
1154 : STAP_ARG_BITNESS_64BIT_UNSIGNED
);
1159 /* We have an error, because we don't expect anything
1160 except 1, 2, 4 and 8. */
1161 warning (_("unrecognized bitness %s%c' for probe `%s'"),
1162 got_minus
? "`-" : "`", *cur
, probe
->p
.name
);
1169 /* Discard the number and the `@' sign. */
1173 arg
.bitness
= STAP_ARG_BITNESS_UNDEFINED
;
1175 arg
.atype
= stap_get_expected_argument_type (gdbarch
, arg
.bitness
);
1177 expr
= stap_parse_argument (&cur
, arg
.atype
, gdbarch
);
1179 if (stap_expression_debug
)
1180 dump_raw_expression (expr
, gdb_stdlog
,
1181 "before conversion to prefix form");
1183 prefixify_expression (expr
);
1185 if (stap_expression_debug
)
1186 dump_prefix_expression (expr
, gdb_stdlog
);
1190 /* Start it over again. */
1191 cur
= skip_spaces_const (cur
);
1193 VEC_safe_push (stap_probe_arg_s
, probe
->args_u
.vec
, &arg
);
1197 /* Implementation of the get_probe_address method. */
1200 stap_get_probe_address (struct probe
*probe
, struct objfile
*objfile
)
1202 return probe
->address
+ ANOFFSET (objfile
->section_offsets
,
1203 SECT_OFF_DATA (objfile
));
1206 /* Given PROBE, returns the number of arguments present in that probe's
1210 stap_get_probe_argument_count (struct probe
*probe_generic
,
1211 struct frame_info
*frame
)
1213 struct stap_probe
*probe
= (struct stap_probe
*) probe_generic
;
1214 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1216 gdb_assert (probe_generic
->pops
== &stap_probe_ops
);
1218 if (!probe
->args_parsed
)
1220 if (can_evaluate_probe_arguments (probe_generic
))
1221 stap_parse_probe_arguments (probe
, gdbarch
);
1224 static int have_warned_stap_incomplete
= 0;
1226 if (!have_warned_stap_incomplete
)
1229 "The SystemTap SDT probe support is not fully implemented on this target;\n"
1230 "you will not be able to inspect the arguments of the probes.\n"
1231 "Please report a bug against GDB requesting a port to this target."));
1232 have_warned_stap_incomplete
= 1;
1235 /* Marking the arguments as "already parsed". */
1236 probe
->args_u
.vec
= NULL
;
1237 probe
->args_parsed
= 1;
1241 gdb_assert (probe
->args_parsed
);
1242 return VEC_length (stap_probe_arg_s
, probe
->args_u
.vec
);
1245 /* Return 1 if OP is a valid operator inside a probe argument, or zero
1249 stap_is_operator (const char *op
)
1274 /* We didn't find any operator. */
1281 static struct stap_probe_arg
*
1282 stap_get_arg (struct stap_probe
*probe
, unsigned n
, struct gdbarch
*gdbarch
)
1284 if (!probe
->args_parsed
)
1285 stap_parse_probe_arguments (probe
, gdbarch
);
1287 return VEC_index (stap_probe_arg_s
, probe
->args_u
.vec
, n
);
1290 /* Implement the `can_evaluate_probe_arguments' method of probe_ops. */
1293 stap_can_evaluate_probe_arguments (struct probe
*probe_generic
)
1295 struct stap_probe
*stap_probe
= (struct stap_probe
*) probe_generic
;
1296 struct gdbarch
*gdbarch
= stap_probe
->p
.arch
;
1298 /* For SystemTap probes, we have to guarantee that the method
1299 stap_is_single_operand is defined on gdbarch. If it is not, then it
1300 means that argument evaluation is not implemented on this target. */
1301 return gdbarch_stap_is_single_operand_p (gdbarch
);
1304 /* Evaluate the probe's argument N (indexed from 0), returning a value
1305 corresponding to it. Assertion is thrown if N does not exist. */
1307 static struct value
*
1308 stap_evaluate_probe_argument (struct probe
*probe_generic
, unsigned n
,
1309 struct frame_info
*frame
)
1311 struct stap_probe
*stap_probe
= (struct stap_probe
*) probe_generic
;
1312 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1313 struct stap_probe_arg
*arg
;
1316 gdb_assert (probe_generic
->pops
== &stap_probe_ops
);
1318 arg
= stap_get_arg (stap_probe
, n
, gdbarch
);
1319 return evaluate_subexp_standard (arg
->atype
, arg
->aexpr
, &pos
, EVAL_NORMAL
);
1322 /* Compile the probe's argument N (indexed from 0) to agent expression.
1323 Assertion is thrown if N does not exist. */
1326 stap_compile_to_ax (struct probe
*probe_generic
, struct agent_expr
*expr
,
1327 struct axs_value
*value
, unsigned n
)
1329 struct stap_probe
*stap_probe
= (struct stap_probe
*) probe_generic
;
1330 struct stap_probe_arg
*arg
;
1331 union exp_element
*pc
;
1333 gdb_assert (probe_generic
->pops
== &stap_probe_ops
);
1335 arg
= stap_get_arg (stap_probe
, n
, expr
->gdbarch
);
1337 pc
= arg
->aexpr
->elts
;
1338 gen_expr (arg
->aexpr
, &pc
, expr
, value
);
1340 require_rvalue (expr
, value
);
1341 value
->type
= arg
->atype
;
1344 /* Destroy (free) the data related to PROBE. PROBE memory itself is not feed
1345 as it is allocated on an obstack. */
1348 stap_probe_destroy (struct probe
*probe_generic
)
1350 struct stap_probe
*probe
= (struct stap_probe
*) probe_generic
;
1352 gdb_assert (probe_generic
->pops
== &stap_probe_ops
);
1354 if (probe
->args_parsed
)
1356 struct stap_probe_arg
*arg
;
1359 for (ix
= 0; VEC_iterate (stap_probe_arg_s
, probe
->args_u
.vec
, ix
, arg
);
1362 VEC_free (stap_probe_arg_s
, probe
->args_u
.vec
);
1368 /* This is called to compute the value of one of the $_probe_arg*
1369 convenience variables. */
1371 static struct value
*
1372 compute_probe_arg (struct gdbarch
*arch
, struct internalvar
*ivar
,
1375 struct frame_info
*frame
= get_selected_frame (_("No frame selected"));
1376 CORE_ADDR pc
= get_frame_pc (frame
);
1377 int sel
= (int) (uintptr_t) data
;
1378 struct bound_probe pc_probe
;
1379 const struct sym_probe_fns
*pc_probe_fns
;
1382 /* SEL == -1 means "_probe_argc". */
1383 gdb_assert (sel
>= -1);
1385 pc_probe
= find_probe_by_pc (pc
);
1386 if (pc_probe
.probe
== NULL
)
1387 error (_("No SystemTap probe at PC %s"), core_addr_to_string (pc
));
1389 n_args
= get_probe_argument_count (pc_probe
.probe
, frame
);
1391 return value_from_longest (builtin_type (arch
)->builtin_int
, n_args
);
1394 error (_("Invalid probe argument %d -- probe has %u arguments available"),
1397 return evaluate_probe_argument (pc_probe
.probe
, sel
, frame
);
1400 /* This is called to compile one of the $_probe_arg* convenience
1401 variables into an agent expression. */
1404 compile_probe_arg (struct internalvar
*ivar
, struct agent_expr
*expr
,
1405 struct axs_value
*value
, void *data
)
1407 CORE_ADDR pc
= expr
->scope
;
1408 int sel
= (int) (uintptr_t) data
;
1409 struct bound_probe pc_probe
;
1410 const struct sym_probe_fns
*pc_probe_fns
;
1412 struct frame_info
*frame
= get_selected_frame (NULL
);
1414 /* SEL == -1 means "_probe_argc". */
1415 gdb_assert (sel
>= -1);
1417 pc_probe
= find_probe_by_pc (pc
);
1418 if (pc_probe
.probe
== NULL
)
1419 error (_("No SystemTap probe at PC %s"), core_addr_to_string (pc
));
1421 n_args
= get_probe_argument_count (pc_probe
.probe
, frame
);
1425 value
->kind
= axs_rvalue
;
1426 value
->type
= builtin_type (expr
->gdbarch
)->builtin_int
;
1427 ax_const_l (expr
, n_args
);
1431 gdb_assert (sel
>= 0);
1433 error (_("Invalid probe argument %d -- probe has %d arguments available"),
1436 pc_probe
.probe
->pops
->compile_to_ax (pc_probe
.probe
, expr
, value
, sel
);
1441 /* Set or clear a SystemTap semaphore. ADDRESS is the semaphore's
1442 address. SET is zero if the semaphore should be cleared, or one
1443 if it should be set. This is a helper function for `stap_semaphore_down'
1444 and `stap_semaphore_up'. */
1447 stap_modify_semaphore (CORE_ADDR address
, int set
, struct gdbarch
*gdbarch
)
1449 gdb_byte bytes
[sizeof (LONGEST
)];
1450 /* The ABI specifies "unsigned short". */
1451 struct type
*type
= builtin_type (gdbarch
)->builtin_unsigned_short
;
1457 /* Swallow errors. */
1458 if (target_read_memory (address
, bytes
, TYPE_LENGTH (type
)) != 0)
1460 warning (_("Could not read the value of a SystemTap semaphore."));
1464 value
= extract_unsigned_integer (bytes
, TYPE_LENGTH (type
),
1465 gdbarch_byte_order (gdbarch
));
1466 /* Note that we explicitly don't worry about overflow or
1473 store_unsigned_integer (bytes
, TYPE_LENGTH (type
),
1474 gdbarch_byte_order (gdbarch
), value
);
1476 if (target_write_memory (address
, bytes
, TYPE_LENGTH (type
)) != 0)
1477 warning (_("Could not write the value of a SystemTap semaphore."));
1480 /* Set a SystemTap semaphore. SEM is the semaphore's address. Semaphores
1481 act as reference counters, so calls to this function must be paired with
1482 calls to `stap_semaphore_down'.
1484 This function and `stap_semaphore_down' race with another tool changing
1485 the probes, but that is too rare to care. */
1488 stap_set_semaphore (struct probe
*probe_generic
, struct objfile
*objfile
,
1489 struct gdbarch
*gdbarch
)
1491 struct stap_probe
*probe
= (struct stap_probe
*) probe_generic
;
1494 gdb_assert (probe_generic
->pops
== &stap_probe_ops
);
1496 addr
= (probe
->sem_addr
1497 + ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
)));
1498 stap_modify_semaphore (addr
, 1, gdbarch
);
1501 /* Clear a SystemTap semaphore. SEM is the semaphore's address. */
1504 stap_clear_semaphore (struct probe
*probe_generic
, struct objfile
*objfile
,
1505 struct gdbarch
*gdbarch
)
1507 struct stap_probe
*probe
= (struct stap_probe
*) probe_generic
;
1510 gdb_assert (probe_generic
->pops
== &stap_probe_ops
);
1512 addr
= (probe
->sem_addr
1513 + ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
)));
1514 stap_modify_semaphore (addr
, 0, gdbarch
);
1517 /* Implementation of `$_probe_arg*' set of variables. */
1519 static const struct internalvar_funcs probe_funcs
=
1526 /* Helper function that parses the information contained in a
1527 SystemTap's probe. Basically, the information consists in:
1529 - Probe's PC address;
1530 - Link-time section address of `.stapsdt.base' section;
1531 - Link-time address of the semaphore variable, or ZERO if the
1532 probe doesn't have an associated semaphore;
1533 - Probe's provider name;
1535 - Probe's argument format
1537 This function returns 1 if the handling was successful, and zero
1541 handle_stap_probe (struct objfile
*objfile
, struct sdt_note
*el
,
1542 VEC (probe_p
) **probesp
, CORE_ADDR base
)
1544 bfd
*abfd
= objfile
->obfd
;
1545 int size
= bfd_get_arch_size (abfd
) / 8;
1546 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1547 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
1549 const char *probe_args
= NULL
;
1550 struct stap_probe
*ret
;
1552 ret
= obstack_alloc (&objfile
->per_bfd
->storage_obstack
, sizeof (*ret
));
1553 ret
->p
.pops
= &stap_probe_ops
;
1554 ret
->p
.arch
= gdbarch
;
1556 /* Provider and the name of the probe. */
1557 ret
->p
.provider
= (char *) &el
->data
[3 * size
];
1558 ret
->p
.name
= memchr (ret
->p
.provider
, '\0',
1559 (char *) el
->data
+ el
->size
- ret
->p
.provider
);
1560 /* Making sure there is a name. */
1561 if (ret
->p
.name
== NULL
)
1563 complaint (&symfile_complaints
, _("corrupt probe name when "
1565 objfile_name (objfile
));
1567 /* There is no way to use a probe without a name or a provider, so
1568 returning zero here makes sense. */
1574 /* Retrieving the probe's address. */
1575 ret
->p
.address
= extract_typed_address (&el
->data
[0], ptr_type
);
1577 /* Link-time sh_addr of `.stapsdt.base' section. */
1578 base_ref
= extract_typed_address (&el
->data
[size
], ptr_type
);
1580 /* Semaphore address. */
1581 ret
->sem_addr
= extract_typed_address (&el
->data
[2 * size
], ptr_type
);
1583 ret
->p
.address
+= base
- base_ref
;
1584 if (ret
->sem_addr
!= 0)
1585 ret
->sem_addr
+= base
- base_ref
;
1587 /* Arguments. We can only extract the argument format if there is a valid
1588 name for this probe. */
1589 probe_args
= memchr (ret
->p
.name
, '\0',
1590 (char *) el
->data
+ el
->size
- ret
->p
.name
);
1592 if (probe_args
!= NULL
)
1595 if (probe_args
== NULL
1596 || (memchr (probe_args
, '\0', (char *) el
->data
+ el
->size
- ret
->p
.name
)
1597 != el
->data
+ el
->size
- 1))
1599 complaint (&symfile_complaints
, _("corrupt probe argument when "
1601 objfile_name (objfile
));
1602 /* If the argument string is NULL, it means some problem happened with
1603 it. So we return 0. */
1607 ret
->args_parsed
= 0;
1608 ret
->args_u
.text
= (void *) probe_args
;
1610 /* Successfully created probe. */
1611 VEC_safe_push (probe_p
, *probesp
, (struct probe
*) ret
);
1614 /* Helper function which tries to find the base address of the SystemTap
1615 base section named STAP_BASE_SECTION_NAME. */
1618 get_stap_base_address_1 (bfd
*abfd
, asection
*sect
, void *obj
)
1620 asection
**ret
= obj
;
1622 if ((sect
->flags
& (SEC_DATA
| SEC_ALLOC
| SEC_HAS_CONTENTS
))
1623 && sect
->name
&& !strcmp (sect
->name
, STAP_BASE_SECTION_NAME
))
1627 /* Helper function which iterates over every section in the BFD file,
1628 trying to find the base address of the SystemTap base section.
1629 Returns 1 if found (setting BASE to the proper value), zero otherwise. */
1632 get_stap_base_address (bfd
*obfd
, bfd_vma
*base
)
1634 asection
*ret
= NULL
;
1636 bfd_map_over_sections (obfd
, get_stap_base_address_1
, (void *) &ret
);
1640 complaint (&symfile_complaints
, _("could not obtain base address for "
1641 "SystemTap section on objfile `%s'."),
1652 /* Helper function for `elf_get_probes', which gathers information about all
1653 SystemTap probes from OBJFILE. */
1656 stap_get_probes (VEC (probe_p
) **probesp
, struct objfile
*objfile
)
1658 /* If we are here, then this is the first time we are parsing the
1659 SystemTap probe's information. We basically have to count how many
1660 probes the objfile has, and then fill in the necessary information
1662 bfd
*obfd
= objfile
->obfd
;
1664 struct sdt_note
*iter
;
1665 unsigned save_probesp_len
= VEC_length (probe_p
, *probesp
);
1667 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
1669 /* This is a .debug file, not the objfile itself. */
1673 if (elf_tdata (obfd
)->sdt_note_head
== NULL
)
1675 /* There isn't any probe here. */
1679 if (!get_stap_base_address (obfd
, &base
))
1681 /* There was an error finding the base address for the section.
1682 Just return NULL. */
1686 /* Parsing each probe's information. */
1687 for (iter
= elf_tdata (obfd
)->sdt_note_head
;
1691 /* We first have to handle all the information about the
1692 probe which is present in the section. */
1693 handle_stap_probe (objfile
, iter
, probesp
, base
);
1696 if (save_probesp_len
== VEC_length (probe_p
, *probesp
))
1698 /* If we are here, it means we have failed to parse every known
1700 complaint (&symfile_complaints
, _("could not parse SystemTap probe(s) "
1707 stap_probe_is_linespec (const char **linespecp
)
1709 static const char *const keywords
[] = { "-pstap", "-probe-stap", NULL
};
1711 return probe_is_linespec_by_keyword (linespecp
, keywords
);
1715 stap_gen_info_probes_table_header (VEC (info_probe_column_s
) **heads
)
1717 info_probe_column_s stap_probe_column
;
1719 stap_probe_column
.field_name
= "semaphore";
1720 stap_probe_column
.print_name
= _("Semaphore");
1722 VEC_safe_push (info_probe_column_s
, *heads
, &stap_probe_column
);
1726 stap_gen_info_probes_table_values (struct probe
*probe_generic
,
1727 VEC (const_char_ptr
) **ret
)
1729 struct stap_probe
*probe
= (struct stap_probe
*) probe_generic
;
1730 struct gdbarch
*gdbarch
;
1731 const char *val
= NULL
;
1733 gdb_assert (probe_generic
->pops
== &stap_probe_ops
);
1735 gdbarch
= probe
->p
.arch
;
1737 if (probe
->sem_addr
!= 0)
1738 val
= print_core_address (gdbarch
, probe
->sem_addr
);
1740 VEC_safe_push (const_char_ptr
, *ret
, val
);
1743 /* SystemTap probe_ops. */
1745 static const struct probe_ops stap_probe_ops
=
1747 stap_probe_is_linespec
,
1749 stap_get_probe_address
,
1750 stap_get_probe_argument_count
,
1751 stap_can_evaluate_probe_arguments
,
1752 stap_evaluate_probe_argument
,
1755 stap_clear_semaphore
,
1757 stap_gen_info_probes_table_header
,
1758 stap_gen_info_probes_table_values
,
1761 /* Implementation of the `info probes stap' command. */
1764 info_probes_stap_command (char *arg
, int from_tty
)
1766 info_probes_for_ops (arg
, from_tty
, &stap_probe_ops
);
1769 void _initialize_stap_probe (void);
1772 _initialize_stap_probe (void)
1774 VEC_safe_push (probe_ops_cp
, all_probe_ops
, &stap_probe_ops
);
1776 add_setshow_zuinteger_cmd ("stap-expression", class_maintenance
,
1777 &stap_expression_debug
,
1778 _("Set SystemTap expression debugging."),
1779 _("Show SystemTap expression debugging."),
1780 _("When non-zero, the internal representation "
1781 "of SystemTap expressions will be printed."),
1783 show_stapexpressiondebug
,
1784 &setdebuglist
, &showdebuglist
);
1786 create_internalvar_type_lazy ("_probe_argc", &probe_funcs
,
1787 (void *) (uintptr_t) -1);
1788 create_internalvar_type_lazy ("_probe_arg0", &probe_funcs
,
1789 (void *) (uintptr_t) 0);
1790 create_internalvar_type_lazy ("_probe_arg1", &probe_funcs
,
1791 (void *) (uintptr_t) 1);
1792 create_internalvar_type_lazy ("_probe_arg2", &probe_funcs
,
1793 (void *) (uintptr_t) 2);
1794 create_internalvar_type_lazy ("_probe_arg3", &probe_funcs
,
1795 (void *) (uintptr_t) 3);
1796 create_internalvar_type_lazy ("_probe_arg4", &probe_funcs
,
1797 (void *) (uintptr_t) 4);
1798 create_internalvar_type_lazy ("_probe_arg5", &probe_funcs
,
1799 (void *) (uintptr_t) 5);
1800 create_internalvar_type_lazy ("_probe_arg6", &probe_funcs
,
1801 (void *) (uintptr_t) 6);
1802 create_internalvar_type_lazy ("_probe_arg7", &probe_funcs
,
1803 (void *) (uintptr_t) 7);
1804 create_internalvar_type_lazy ("_probe_arg8", &probe_funcs
,
1805 (void *) (uintptr_t) 8);
1806 create_internalvar_type_lazy ("_probe_arg9", &probe_funcs
,
1807 (void *) (uintptr_t) 9);
1808 create_internalvar_type_lazy ("_probe_arg10", &probe_funcs
,
1809 (void *) (uintptr_t) 10);
1810 create_internalvar_type_lazy ("_probe_arg11", &probe_funcs
,
1811 (void *) (uintptr_t) 11);
1813 add_cmd ("stap", class_info
, info_probes_stap_command
,
1815 Show information about SystemTap static probes.\n\
1816 Usage: info probes stap [PROVIDER [NAME [OBJECT]]]\n\
1817 Each argument is a regular expression, used to select probes.\n\
1818 PROVIDER matches probe provider names.\n\
1819 NAME matches the probe names.\n\
1820 OBJECT matches the executable or shared library name."),
1821 info_probes_cmdlist_get ());