[PATCH] Extend SystemTap SDT probe argument parser

Sergio Durigan Junior
2013-12-11T03:56:21Z

This patch extends the current generic parser for SystemTap SDT probe
arguments. It can be almost considered a cleanup, but the main point of
it is actually to allow the generic parser to accept multiple prefixes
and suffixes for the its operands (i.e., integers, register names, and
register indirection).

I have chosen to implement this as a list of const strings, which needs
to be declared as "static const char *const *", and is provided to
gdbarch on initialization. I think it is cleaner to implement it this
way, but for a moment I wondered whether demanding the variables to be
declared as "static" is a good idea... After some thought and
discussion, I decided to leave it as is.

This patch is actually a preparation for an upcoming patch for ARM,
which implements the support for multiple integer prefixes (as defined
by ARM's asm spec). And AArch64 will also need this, for the same
reason.

This patch was regtested on all architectures that it touches (i.e.,
i386, x86_64, ARM, PPC/PPC64, s390x and IA-64). No regressions were found.

2013-12-11 Sergio Durigan Junior <sergiodj@redhat.com>

* amd64-tdep.c (amd64_init_abi): Declare SystemTap SDT probe
argument prefixes and suffixes. Initialize gdbarch with them.
* arm-linux-tdep.c (arm_linux_init_abi): Likewise.
* gdbarch.c: Regenerate.
* gdbarch.h: Regenerate.
* gdbarch.sh (stap_integer_prefix, stap_integer_suffix)
(stap_register_prefix, stap_register_suffix)
(stap_register_indirection_prefix)
(stap_register_indirection_suffix): Declare as "const char *const
*" instead of "const char *". Adjust printing function.
(pstring_list): New function.
* i386-tdep.c (i386_elf_init_abi): Declare SystemTap SDT probe
argument prefixes and suffixes. Initialize gdbarch with them.
* ia64-linux-tdep.c (ia64_linux_init_abi): Likewise.
* ppc-linux-tdep.c (ppc_linux_init_abi): Likewise.
* s390-linux-tdep.c (s390_gdbarch_init): Likewise.
* stap-probe.c (stap_is_generic_prefix): New function.
(stap_is_register_prefix): Likewise.
(stap_is_register_indirection_prefix): Likewise.
(stap_is_integer_prefix): Likewise.
(stap_generic_check_suffix): Likewise.
(stap_check_integer_suffix): Likewise.
(stap_check_register_suffix): Likewise.
(stap_check_register_indirection_suffix): Likewise.
(stap_parse_register_operand): Remove unecessary declarations for
variables holding prefix and suffix information. Use the new
functions listed above for checking for prefixes and suffixes.
(stap_parse_single_operand): Likewise.
---
gdb/ChangeLog | 31 ++++++
gdb/amd64-tdep.c | 14 ++-
gdb/arm-linux-tdep.c | 14 ++-
gdb/gdbarch.c | 71 +++++++-----
gdb/gdbarch.h | 76 +++++++++----
gdb/gdbarch.sh | 79 +++++++++++---
gdb/i386-tdep.c | 15 ++-
gdb/ia64-linux-tdep.c | 11 +-
gdb/ppc-linux-tdep.c | 11 +-
gdb/s390-linux-tdep.c | 11 +-
gdb/stap-probe.c | 291 +++++++++++++++++++++++++++++++++++++-------------
11 files changed, 466 insertions(+), 158 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 35a1d73..efda387 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,36 @@
2013-12-11 Sergio Durigan Junior <sergiodj@redhat.com>

+ * amd64-tdep.c (amd64_init_abi): Declare SystemTap SDT probe
+ argument prefixes and suffixes. Initialize gdbarch with them.
+ * arm-linux-tdep.c (arm_linux_init_abi): Likewise.
+ * gdbarch.c: Regenerate.
+ * gdbarch.h: Regenerate.
+ * gdbarch.sh (stap_integer_prefix, stap_integer_suffix)
+ (stap_register_prefix, stap_register_suffix)
+ (stap_register_indirection_prefix)
+ (stap_register_indirection_suffix): Declare as "const char *const
+ *" instead of "const char *". Adjust printing function.
+ (pstring_list): New function.
+ * i386-tdep.c (i386_elf_init_abi): Declare SystemTap SDT probe
+ argument prefixes and suffixes. Initialize gdbarch with them.
+ * ia64-linux-tdep.c (ia64_linux_init_abi): Likewise.
+ * ppc-linux-tdep.c (ppc_linux_init_abi): Likewise.
+ * s390-linux-tdep.c (s390_gdbarch_init): Likewise.
+ * stap-probe.c (stap_is_generic_prefix): New function.
+ (stap_is_register_prefix): Likewise.
+ (stap_is_register_indirection_prefix): Likewise.
+ (stap_is_integer_prefix): Likewise.
+ (stap_generic_check_suffix): Likewise.
+ (stap_check_integer_suffix): Likewise.
+ (stap_check_register_suffix): Likewise.
+ (stap_check_register_indirection_suffix): Likewise.
+ (stap_parse_register_operand): Remove unecessary declarations for
+ variables holding prefix and suffix information. Use the new
+ functions listed above for checking for prefixes and suffixes.
+ (stap_parse_single_operand): Likewise.
+
+2013-12-11 Sergio Durigan Junior <sergiodj@redhat.com>
+
* break-catch-throw.c (fetch_probe_arguments): Pass selected frame
to get_probe_argument_count and evaluate_probe_argument.
* probe.c (get_probe_argument_count): Adjust declaration to accept
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 19968fc..ec67f06 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -2832,6 +2832,10 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
const struct target_desc *tdesc = info.target_desc;
+ static const char *const stap_integer_prefix[] = { "$", NULL };
+ static const char *const stap_register_prefix[] = { "%", NULL };
+ static const char *const stap_register_indirection_prefix[] = { "(", NULL };
+ static const char *const stap_register_indirection_suffix[] = { ")", NULL };

/* AMD64 generally uses `fxsave' instead of `fsave' for saving its
floating-point registers. */
@@ -2944,10 +2948,12 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
set_gdbarch_gen_return_address (gdbarch, amd64_gen_return_address);

/* SystemTap variables and functions. */
- set_gdbarch_stap_integer_prefix (gdbarch, "$");
- set_gdbarch_stap_register_prefix (gdbarch, "%");
- set_gdbarch_stap_register_indirection_prefix (gdbarch, "(");
- set_gdbarch_stap_register_indirection_suffix (gdbarch, ")");
+ set_gdbarch_stap_integer_prefix (gdbarch, stap_integer_prefix);
+ set_gdbarch_stap_register_prefix (gdbarch, stap_register_prefix);
+ set_gdbarch_stap_register_indirection_prefix (gdbarch,
+ stap_register_indirection_prefix);
+ set_gdbarch_stap_register_indirection_suffix (gdbarch,
+ stap_register_indirection_suffix);
set_gdbarch_stap_is_single_operand (gdbarch,
i386_stap_is_single_operand);
set_gdbarch_stap_parse_special_token (gdbarch,
diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
index 9deed10..4f385b5 100644
--- a/gdb/arm-linux-tdep.c
+++ b/gdb/arm-linux-tdep.c
@@ -1235,6 +1235,10 @@ static void
arm_linux_init_abi (struct gdbarch_info info,
struct gdbarch *gdbarch)
{
+ static const char *const stap_integer_prefix[] = { "#", NULL };
+ static const char *const stap_register_prefix[] = { "r", NULL };
+ static const char *const stap_register_indirection_prefix[] = { "[", NULL };
+ static const char *const stap_register_indirection_suffix[] = { "]", NULL };
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

linux_init_abi (info, gdbarch);
@@ -1334,10 +1338,12 @@ arm_linux_init_abi (struct gdbarch_info info,
set_gdbarch_process_record (gdbarch, arm_process_record);

/* SystemTap functions. */
- set_gdbarch_stap_integer_prefix (gdbarch, "#");
- set_gdbarch_stap_register_prefix (gdbarch, "r");
- set_gdbarch_stap_register_indirection_prefix (gdbarch, "[");
- set_gdbarch_stap_register_indirection_suffix (gdbarch, "]");
+ set_gdbarch_stap_integer_prefix (gdbarch, stap_integer_prefix);
+ set_gdbarch_stap_register_prefix (gdbarch, stap_register_prefix);
+ set_gdbarch_stap_register_indirection_prefix (gdbarch,
+ stap_register_indirection_prefix);
+ set_gdbarch_stap_register_indirection_suffix (gdbarch,
+ stap_register_indirection_suffix);
set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
set_gdbarch_stap_is_single_operand (gdbarch, arm_stap_is_single_operand);
set_gdbarch_stap_parse_special_token (gdbarch,
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index fb3595f..4594f20 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -86,6 +86,29 @@ pstring (const char *string)
return string;
}

+static char *
+pstring_list (const char *const *list)
+{
+ static char ret[100];
+ const char *const *p;
+ int offset = 0;
+
+ if (list == NULL)
+ return "(null)";
+
+ ret[0] = '\0';
+ for (p = list; *p != NULL && offset < sizeof (ret); ++p)
+ {
+ xsnprintf (ret + offset, sizeof (ret) - offset, "%s, ", *p);
+ offset += 2 + strlen (*p);
+ }
+
+ if (offset > 0)
+ ret[offset - 2] = '\0';
+
+ return ret;
+}
+

/* Maintain the struct gdbarch object. */

@@ -265,12 +288,12 @@ struct gdbarch
gdbarch_get_siginfo_type_ftype *get_siginfo_type;
gdbarch_record_special_symbol_ftype *record_special_symbol;
gdbarch_get_syscall_number_ftype *get_syscall_number;
- const char * stap_integer_prefix;
- const char * stap_integer_suffix;
- const char * stap_register_prefix;
- const char * stap_register_suffix;
- const char * stap_register_indirection_prefix;
- const char * stap_register_indirection_suffix;
+ const char *const * stap_integer_prefix;
+ const char *const * stap_integer_suffix;
+ const char *const * stap_register_prefix;
+ const char *const * stap_register_suffix;
+ const char *const * stap_register_indirection_prefix;
+ const char *const * stap_register_indirection_suffix;
const char * stap_gdb_register_prefix;
const char * stap_gdb_register_suffix;
gdbarch_stap_is_single_operand_ftype *stap_is_single_operand;
@@ -1352,10 +1375,10 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
pstring (gdbarch->stap_gdb_register_suffix));
fprintf_unfiltered (file,
"gdbarch_dump: stap_integer_prefix = %s\n",
- pstring (gdbarch->stap_integer_prefix));
+ pstring_list (gdbarch->stap_integer_prefix));
fprintf_unfiltered (file,
"gdbarch_dump: stap_integer_suffix = %s\n",
- pstring (gdbarch->stap_integer_suffix));
+ pstring_list (gdbarch->stap_integer_suffix));
fprintf_unfiltered (file,
"gdbarch_dump: gdbarch_stap_is_single_operand_p() = %d\n",
gdbarch_stap_is_single_operand_p (gdbarch));
@@ -1370,16 +1393,16 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
host_address_to_string (gdbarch->stap_parse_special_token));
fprintf_unfiltered (file,
"gdbarch_dump: stap_register_indirection_prefix = %s\n",
- pstring (gdbarch->stap_register_indirection_prefix));
+ pstring_list (gdbarch->stap_register_indirection_prefix));
fprintf_unfiltered (file,
"gdbarch_dump: stap_register_indirection_suffix = %s\n",
- pstring (gdbarch->stap_register_indirection_suffix));
+ pstring_list (gdbarch->stap_register_indirection_suffix));
fprintf_unfiltered (file,
"gdbarch_dump: stap_register_prefix = %s\n",
- pstring (gdbarch->stap_register_prefix));
+ pstring_list (gdbarch->stap_register_prefix));
fprintf_unfiltered (file,
"gdbarch_dump: stap_register_suffix = %s\n",
- pstring (gdbarch->stap_register_suffix));
+ pstring_list (gdbarch->stap_register_suffix));
fprintf_unfiltered (file,
"gdbarch_dump: gdbarch_static_transform_name_p() = %d\n",
gdbarch_static_transform_name_p (gdbarch));
@@ -4004,7 +4027,7 @@ set_gdbarch_get_syscall_number (struct gdbarch *gdbarch,
gdbarch->get_syscall_number = get_syscall_number;
}

-const char *
+const char *const *
gdbarch_stap_integer_prefix (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
@@ -4016,12 +4039,12 @@ gdbarch_stap_integer_prefix (struct gdbarch *gdbarch)

void
set_gdbarch_stap_integer_prefix (struct gdbarch *gdbarch,
- const char * stap_integer_prefix)
+ const char *const * stap_integer_prefix)
{
gdbarch->stap_integer_prefix = stap_integer_prefix;
}

-const char *
+const char *const *
gdbarch_stap_integer_suffix (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
@@ -4033,12 +4056,12 @@ gdbarch_stap_integer_suffix (struct gdbarch *gdbarch)

void
set_gdbarch_stap_integer_suffix (struct gdbarch *gdbarch,
- const char * stap_integer_suffix)
+ const char *const * stap_integer_suffix)
{
gdbarch->stap_integer_suffix = stap_integer_suffix;
}

-const char *
+const char *const *
gdbarch_stap_register_prefix (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
@@ -4050,12 +4073,12 @@ gdbarch_stap_register_prefix (struct gdbarch *gdbarch)

void
set_gdbarch_stap_register_prefix (struct gdbarch *gdbarch,
- const char * stap_register_prefix)
+ const char *const * stap_register_prefix)
{
gdbarch->stap_register_prefix = stap_register_prefix;
}

-const char *
+const char *const *
gdbarch_stap_register_suffix (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
@@ -4067,12 +4090,12 @@ gdbarch_stap_register_suffix (struct gdbarch *gdbarch)

void
set_gdbarch_stap_register_suffix (struct gdbarch *gdbarch,
- const char * stap_register_suffix)
+ const char *const * stap_register_suffix)
{
gdbarch->stap_register_suffix = stap_register_suffix;
}

-const char *
+const char *const *
gdbarch_stap_register_indirection_prefix (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
@@ -4084,12 +4107,12 @@ gdbarch_stap_register_indirection_prefix (struct gdbarch *gdbarch)

void
set_gdbarch_stap_register_indirection_prefix (struct gdbarch *gdbarch,
- const char * stap_register_indirection_prefix)
+ const char *const * stap_register_indirection_prefix)
{
gdbarch->stap_register_indirection_prefix = stap_register_indirection_prefix;
}

-const char *
+const char *const *
gdbarch_stap_register_indirection_suffix (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
@@ -4101,7 +4124,7 @@ gdbarch_stap_register_indirection_suffix (struct gdbarch *gdbarch)

void
set_gdbarch_stap_register_indirection_suffix (struct gdbarch *gdbarch,
- const char * stap_register_indirection_suffix)
+ const char *const * stap_register_indirection_suffix)
{
gdbarch->stap_register_indirection_suffix = stap_register_indirection_suffix;
}
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index b58efc8..1d60f28 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -1034,37 +1034,57 @@ extern LONGEST gdbarch_get_syscall_number (struct gdbarch *gdbarch, ptid_t ptid)
extern void set_gdbarch_get_syscall_number (struct gdbarch *gdbarch, gdbarch_get_syscall_number_ftype *get_syscall_number);

/* SystemTap related fields and functions.
- Prefix used to mark an integer constant on the architecture's assembly
+ Prefix(es) used to mark an integer constant on the architecture's assembly.
For example, on x86 integer constants are written as:

$10 ;; integer constant 10

- in this case, this prefix would be the character `$'. */
+ in this case, this prefix would be the character `$'.
+
+ This variable must be declared as `static const char *const var[]',
+ and must also be NUL-terminated, like the following example:
+
+ static const char *const example[] = { "prefix1", "prefix2", NULL }; */

-extern const char * gdbarch_stap_integer_prefix (struct gdbarch *gdbarch);
-extern void set_gdbarch_stap_integer_prefix (struct gdbarch *gdbarch, const char * stap_integer_prefix);
+extern const char *const * gdbarch_stap_integer_prefix (struct gdbarch *gdbarch);
+extern void set_gdbarch_stap_integer_prefix (struct gdbarch *gdbarch, const char *const * stap_integer_prefix);

-/* Suffix used to mark an integer constant on the architecture's assembly. */
+/* Suffix(es) used to mark an integer constant on the architecture's assembly.
+
+ This variable must be declared as `static const char *const var[]',
+ and must also be NUL-terminated, like the following example:
+
+ static const char *const example[] = { "prefix1", "prefix2", NULL }; */

-extern const char * gdbarch_stap_integer_suffix (struct gdbarch *gdbarch);
-extern void set_gdbarch_stap_integer_suffix (struct gdbarch *gdbarch, const char * stap_integer_suffix);
+extern const char *const * gdbarch_stap_integer_suffix (struct gdbarch *gdbarch);
+extern void set_gdbarch_stap_integer_suffix (struct gdbarch *gdbarch, const char *const * stap_integer_suffix);

-/* Prefix used to mark a register name on the architecture's assembly.
+/* Prefix(es) used to mark a register name on the architecture's assembly.
For example, on x86 the register name is written as:

%eax ;; register eax

- in this case, this prefix would be the character `%'. */
+ in this case, this prefix would be the character `%'.
+
+ This variable must be declared as `static const char *const var[]',
+ and must also be NUL-terminated, like the following example:
+
+ static const char *const example[] = { "prefix1", "prefix2", NULL }; */

-extern const char * gdbarch_stap_register_prefix (struct gdbarch *gdbarch);
-extern void set_gdbarch_stap_register_prefix (struct gdbarch *gdbarch, const char * stap_register_prefix);
+extern const char *const * gdbarch_stap_register_prefix (struct gdbarch *gdbarch);
+extern void set_gdbarch_stap_register_prefix (struct gdbarch *gdbarch, const char *const * stap_register_prefix);

-/* Suffix used to mark a register name on the architecture's assembly */
+/* Suffix(es) used to mark a register name on the architecture's assembly
+
+ This variable must be declared as `static const char *const var[]',
+ and must also be NUL-terminated, like the following example:
+
+ static const char *const example[] = { "prefix1", "prefix2", NULL }; */

-extern const char * gdbarch_stap_register_suffix (struct gdbarch *gdbarch);
-extern void set_gdbarch_stap_register_suffix (struct gdbarch *gdbarch, const char * stap_register_suffix);
+extern const char *const * gdbarch_stap_register_suffix (struct gdbarch *gdbarch);
+extern void set_gdbarch_stap_register_suffix (struct gdbarch *gdbarch, const char *const * stap_register_suffix);

-/* Prefix used to mark a register indirection on the architecture's assembly.
+/* Prefix(es) used to mark a register indirection on the architecture's assembly.
For example, on x86 the register indirection is written as:

(%eax) ;; indirecting eax
@@ -1072,12 +1092,17 @@ extern void set_gdbarch_stap_register_suffix (struct gdbarch *gdbarch, const cha
in this case, this prefix would be the charater `('.

Please note that we use the indirection prefix also for register
- displacement, e.g., `4(%eax)' on x86. */
+ displacement, e.g., `4(%eax)' on x86.
+
+ This variable must be declared as `static const char *const var[]',
+ and must also be NUL-terminated, like the following example:
+
+ static const char *const example = { "prefix1", "prefix2", NULL }; */

-extern const char * gdbarch_stap_register_indirection_prefix (struct gdbarch *gdbarch);
-extern void set_gdbarch_stap_register_indirection_prefix (struct gdbarch *gdbarch, const char * stap_register_indirection_prefix);
+extern const char *const * gdbarch_stap_register_indirection_prefix (struct gdbarch *gdbarch);
+extern void set_gdbarch_stap_register_indirection_prefix (struct gdbarch *gdbarch, const char *const * stap_register_indirection_prefix);

-/* Suffix used to mark a register indirection on the architecture's assembly.
+/* Suffix(es) used to mark a register indirection on the architecture's assembly.
For example, on x86 the register indirection is written as:

(%eax) ;; indirecting eax
@@ -1085,12 +1110,17 @@ extern void set_gdbarch_stap_register_indirection_prefix (struct gdbarch *gdbarc
in this case, this prefix would be the charater `)'.

Please note that we use the indirection suffix also for register
- displacement, e.g., `4(%eax)' on x86. */
+ displacement, e.g., `4(%eax)' on x86.
+
+ This variable must be declared as `static const char *const var[]',
+ and must also be NUL-terminated, like the following example:
+
+ static const char *const example = { "prefix1", "prefix2", NULL }; */

-extern const char * gdbarch_stap_register_indirection_suffix (struct gdbarch *gdbarch);
-extern void set_gdbarch_stap_register_indirection_suffix (struct gdbarch *gdbarch, const char * stap_register_indirection_suffix);
+extern const char *const * gdbarch_stap_register_indirection_suffix (struct gdbarch *gdbarch);
+extern void set_gdbarch_stap_register_indirection_suffix (struct gdbarch *gdbarch, const char *const * stap_register_indirection_suffix);

-/* Prefix used to name a register using GDB's nomenclature.
+/* Prefix(es) used to name a register using GDB's nomenclature.

For example, on PPC a register is represented by a number in the assembly
language (e.g., `10' is the 10th general-purpose register). However,
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index a678a78..1d11b31 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -826,29 +826,49 @@ M:LONGEST:get_syscall_number:ptid_t ptid:ptid

# SystemTap related fields and functions.

-# Prefix used to mark an integer constant on the architecture's assembly
+# Prefix(es) used to mark an integer constant on the architecture's assembly.
# For example, on x86 integer constants are written as:
#
# \$10 ;; integer constant 10
#
# in this case, this prefix would be the character \`\$\'.
-v:const char *:stap_integer_prefix:::0:0::0:pstring (gdbarch->stap_integer_prefix)
+#
+# This variable must be declared as \`static const char *const var\[\]\',
+# and must also be NUL-terminated, like the following example:
+#
+# static const char *const example\[\] \= \{ "prefix1", "prefix2", NULL \};
+v:const char *const *:stap_integer_prefix:::0:0::0:pstring_list (gdbarch->stap_integer_prefix)

-# Suffix used to mark an integer constant on the architecture's assembly.
-v:const char *:stap_integer_suffix:::0:0::0:pstring (gdbarch->stap_integer_suffix)
+# Suffix(es) used to mark an integer constant on the architecture's assembly.
+#
+# This variable must be declared as \`static const char *const var\[\]\',
+# and must also be NUL-terminated, like the following example:
+#
+# static const char *const example\[\] \= \{ "prefix1", "prefix2", NULL \};
+v:const char *const *:stap_integer_suffix:::0:0::0:pstring_list (gdbarch->stap_integer_suffix)

-# Prefix used to mark a register name on the architecture's assembly.
+# Prefix(es) used to mark a register name on the architecture's assembly.
# For example, on x86 the register name is written as:
#
# \%eax ;; register eax
#
# in this case, this prefix would be the character \`\%\'.
-v:const char *:stap_register_prefix:::0:0::0:pstring (gdbarch->stap_register_prefix)
+#
+# This variable must be declared as \`static const char *const var\[\]\',
+# and must also be NUL-terminated, like the following example:
+#
+# static const char *const example\[\] \= \{ "prefix1", "prefix2", NULL \};
+v:const char *const *:stap_register_prefix:::0:0::0:pstring_list (gdbarch->stap_register_prefix)

-# Suffix used to mark a register name on the architecture's assembly
-v:const char *:stap_register_suffix:::0:0::0:pstring (gdbarch->stap_register_suffix)
+# Suffix(es) used to mark a register name on the architecture's assembly
+#
+# This variable must be declared as \`static const char *const var\[\]\',
+# and must also be NUL-terminated, like the following example:
+#
+# static const char *const example\[\] \= \{ "prefix1", "prefix2", NULL \};
+v:const char *const *:stap_register_suffix:::0:0::0:pstring_list (gdbarch->stap_register_suffix)

-# Prefix used to mark a register indirection on the architecture's assembly.
+# Prefix(es) used to mark a register indirection on the architecture's assembly.
# For example, on x86 the register indirection is written as:
#
# \(\%eax\) ;; indirecting eax
@@ -857,9 +877,14 @@ v:const char *:stap_register_suffix:::0:0::0:pstring (gdbarch->stap_register_suf
#
# Please note that we use the indirection prefix also for register
# displacement, e.g., \`4\(\%eax\)\' on x86.
-v:const char *:stap_register_indirection_prefix:::0:0::0:pstring (gdbarch->stap_register_indirection_prefix)
+#
+# This variable must be declared as \`static const char *const var\[\]\',
+# and must also be NUL-terminated, like the following example:
+#
+# static const char *const example \= \{ "prefix1", "prefix2", NULL \};
+v:const char *const *:stap_register_indirection_prefix:::0:0::0:pstring_list (gdbarch->stap_register_indirection_prefix)

-# Suffix used to mark a register indirection on the architecture's assembly.
+# Suffix(es) used to mark a register indirection on the architecture's assembly.
# For example, on x86 the register indirection is written as:
#
# \(\%eax\) ;; indirecting eax
@@ -868,9 +893,14 @@ v:const char *:stap_register_indirection_prefix:::0:0::0:pstring (gdbarch->stap_
#
# Please note that we use the indirection suffix also for register
# displacement, e.g., \`4\(\%eax\)\' on x86.
-v:const char *:stap_register_indirection_suffix:::0:0::0:pstring (gdbarch->stap_register_indirection_suffix)
+#
+# This variable must be declared as \`static const char *const var\[\]\',
+# and must also be NUL-terminated, like the following example:
+#
+# static const char *const example \= \{ "prefix1", "prefix2", NULL \};
+v:const char *const *:stap_register_indirection_suffix:::0:0::0:pstring_list (gdbarch->stap_register_indirection_suffix)

-# Prefix used to name a register using GDB's nomenclature.
+# Prefix(es) used to name a register using GDB's nomenclature.
#
# For example, on PPC a register is represented by a number in the assembly
# language (e.g., \`10\' is the 10th general-purpose register). However,
@@ -1481,6 +1511,29 @@ pstring (const char *string)
return string;
}

+static char *
+pstring_list (const char *const *list)
+{
+ static char ret[100];
+ const char *const *p;
+ int offset = 0;
+
+ if (list == NULL)
+ return "(null)";
+
+ ret[0] = '\0';
+ for (p = list; *p != NULL && offset < sizeof (ret); ++p)
+ {
+ xsnprintf (ret + offset, sizeof (ret) - offset, "%s, ", *p);
+ offset += 2 + strlen (*p);
+ }
+
+ if (offset > 0)
+ ret[offset - 2] = '\0';
+
+ return ret;
+}
+
EOF

# gdbarch open the gdbarch object
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index a1a4453..c01c9c2 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -3919,14 +3919,21 @@ i386_stap_parse_special_token (struct gdbarch *gdbarch,
void
i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
+ static const char *const stap_integer_prefix[] = { "$", NULL };
+ static const char *const stap_register_prefix[] = { "%", NULL };
+ static const char *const stap_register_indirection_prefix[] = { "(", NULL };
+ static const char *const stap_register_indirection_suffix[] = { ")", NULL };
+
/* We typically use stabs-in-ELF with the SVR4 register numbering. */
set_gdbarch_stab_reg_to_regnum (gdbarch, i386_svr4_reg_to_regnum);

/* Registering SystemTap handlers. */
- set_gdbarch_stap_integer_prefix (gdbarch, "$");
- set_gdbarch_stap_register_prefix (gdbarch, "%");
- set_gdbarch_stap_register_indirection_prefix (gdbarch, "(");
- set_gdbarch_stap_register_indirection_suffix (gdbarch, ")");
+ set_gdbarch_stap_integer_prefix (gdbarch, stap_integer_prefix);
+ set_gdbarch_stap_register_prefix (gdbarch, stap_register_prefix);
+ set_gdbarch_stap_register_indirection_prefix (gdbarch,
+ stap_register_indirection_prefix);
+ set_gdbarch_stap_register_indirection_suffix (gdbarch,
+ stap_register_indirection_suffix);
set_gdbarch_stap_is_single_operand (gdbarch,
i386_stap_is_single_operand);
set_gdbarch_stap_parse_special_token (gdbarch,
diff --git a/gdb/ia64-linux-tdep.c b/gdb/ia64-linux-tdep.c
index d1eb529..b73a5fb 100644
--- a/gdb/ia64-linux-tdep.c
+++ b/gdb/ia64-linux-tdep.c
@@ -135,6 +135,9 @@ static void
ia64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ static const char *const stap_register_prefix[] = { "r", NULL };
+ static const char *const stap_register_indirection_prefix[] = { "[", NULL };
+ static const char *const stap_register_indirection_suffix[] = { "]", NULL };

linux_init_abi (info, gdbarch);

@@ -157,9 +160,11 @@ ia64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
svr4_fetch_objfile_link_map);

/* SystemTap related. */
- set_gdbarch_stap_register_prefix (gdbarch, "r");
- set_gdbarch_stap_register_indirection_prefix (gdbarch, "[");
- set_gdbarch_stap_register_indirection_suffix (gdbarch, "]");
+ set_gdbarch_stap_register_prefix (gdbarch, stap_register_prefix);
+ set_gdbarch_stap_register_indirection_prefix (gdbarch,
+ stap_register_indirection_prefix);
+ set_gdbarch_stap_register_indirection_suffix (gdbarch,
+ stap_register_indirection_suffix);
set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
set_gdbarch_stap_is_single_operand (gdbarch,
ia64_linux_stap_is_single_operand);
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index fc09560..890e5e5 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -1245,6 +1245,9 @@ ppc_linux_init_abi (struct gdbarch_info info,
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
+ static const char *const stap_integer_prefix[] = { "i", NULL };
+ static const char *const stap_register_indirection_prefix[] = { "(", NULL };
+ static const char *const stap_register_indirection_suffix[] = { ")", NULL };

linux_init_abi (info, gdbarch);

@@ -1263,9 +1266,11 @@ ppc_linux_init_abi (struct gdbarch_info info,
set_gdbarch_get_syscall_number (gdbarch, ppc_linux_get_syscall_number);

/* SystemTap functions. */
- set_gdbarch_stap_integer_prefix (gdbarch, "i");
- set_gdbarch_stap_register_indirection_prefix (gdbarch, "(");
- set_gdbarch_stap_register_indirection_suffix (gdbarch, ")");
+ set_gdbarch_stap_integer_prefix (gdbarch, stap_integer_prefix);
+ set_gdbarch_stap_register_indirection_prefix (gdbarch,
+ stap_register_indirection_prefix);
+ set_gdbarch_stap_register_indirection_suffix (gdbarch,
+ stap_register_indirection_suffix);
set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
set_gdbarch_stap_is_single_operand (gdbarch, ppc_stap_is_single_operand);
set_gdbarch_stap_parse_special_token (gdbarch,
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
index cd41de5..d521c2e 100644
--- a/gdb/s390-linux-tdep.c
+++ b/gdb/s390-linux-tdep.c
@@ -3026,6 +3026,9 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
int have_linux_v1 = 0;
int have_linux_v2 = 0;
int first_pseudo_reg, last_pseudo_reg;
+ static const char *const stap_register_prefix[] = { "%", NULL };
+ static const char *const stap_register_indirection_prefix[] = { "(", NULL };
+ static const char *const stap_register_indirection_suffix[] = { ")", NULL };

/* Default ABI and register size. */
switch (info.bfd_arch_info->mach)
@@ -3358,9 +3361,11 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);

/* SystemTap functions. */
- set_gdbarch_stap_register_prefix (gdbarch, "%");
- set_gdbarch_stap_register_indirection_prefix (gdbarch, "(");
- set_gdbarch_stap_register_indirection_suffix (gdbarch, ")");
+ set_gdbarch_stap_register_prefix (gdbarch, stap_register_prefix);
+ set_gdbarch_stap_register_indirection_prefix (gdbarch,
+ stap_register_indirection_prefix);
+ set_gdbarch_stap_register_indirection_suffix (gdbarch,
+ stap_register_indirection_suffix);
set_gdbarch_stap_is_single_operand (gdbarch, s390_stap_is_single_operand);

return gdbarch;
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index 33d4569..625ec38 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -346,6 +346,171 @@ stap_get_expected_argument_type (struct gdbarch *gdbarch,
}
}

+/* Helper function to check for a generic list of prefixes. Return 1
+ if any prefix has been found, zero otherwise. */
+
+static int
+stap_is_generic_prefix (struct gdbarch *gdbarch, const char *s,
+ const char **r, const char *const *prefixes)
+{
+ const char *const *p;
+
+ if (prefixes == NULL)
+ {
+ if (r != NULL)
+ *r = "";
+
+ return 1;
+ }
+
+ for (p = prefixes; *p != NULL; ++p)
+ {
+ if (strncasecmp (s, *p, strlen (*p)) == 0)
+ {
+ if (r != NULL)
+ *r = *p;
+
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/* Return 1 if S points to a register prefix, zero otherwise. */
+
+static int
+stap_is_register_prefix (struct gdbarch *gdbarch, const char *s,
+ const char **r)
+{
+ const char *const *t = gdbarch_stap_register_prefix (gdbarch);
+
+ return stap_is_generic_prefix (gdbarch, s, r, t);
+}
+
+/* Return 1 if S points to a register indirection prefix, zero
+ otherwise. */
+
+static int
+stap_is_register_indirection_prefix (struct gdbarch *gdbarch, const char *s,
+ const char **r)
+{
+ const char *const *t = gdbarch_stap_register_indirection_prefix (gdbarch);
+
+ return stap_is_generic_prefix (gdbarch, s, r, t);
+}
+
+/* Return 1 if S points to an integer prefix, zero otherwise.
+
+ This function takes care of analyzing whether we are dealing with
+ an expected integer prefix, or, if there is no integer prefix to be
+ expected, whether we are dealing with a digit. */
+
+static int
+stap_is_integer_prefix (struct gdbarch *gdbarch, const char *s,
+ const char **r)
+{
+ const char *const *t = gdbarch_stap_integer_prefix (gdbarch);
+ const char *const *p;
+
+ if (t == NULL)
+ {
+ /* A NULL value here means that integers do not have prefix. We
+ just check for a digit then. */
+ if (r != NULL)
+ *r = "";
+
+ return isdigit (*s);
+ }
+
+ for (p = t; *p != NULL; ++p)
+ {
+ size_t len = strlen (*p);
+
+ if ((len == 0 && isdigit (*s))
+ || (len > 0 && strncasecmp (s, *p, len) == 0))
+ {
+ /* Integers may or may not have a prefix. The "len == 0"
+ check covers the case when integers do not have a prefix
+ (therefore, we just check if we have a digit). The call
+ to "strncasecmp" covers the case when they have a
+ prefix. */
+ if (r != NULL)
+ *r = *p;
+
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+/* Helper function to check for a generic list of suffixes. If we are
+ not expecting any suffixes, then it just returns 1. If we are
+ expecting at least one suffix, then it returns 1 if a suffix has
+ been found, zero otherwise. */
+
+static int
+stap_generic_check_suffix (struct gdbarch *gdbarch, const char *s,
+ const char **r, const char *const *suffixes)
+{
+ const char *const *p;
+ int found = 0;
+
+ if (suffixes == NULL)
+ {
+ if (r != NULL)
+ *r = "";
+
+ return 1;
+ }
+
+ for (p = suffixes; *p != NULL; ++p)
+ if (strncasecmp (s, *p, strlen (*p)) == 0)
+ {
+ if (r != NULL)
+ *r = *p;
+
+ found = 1;
+ break;
+ }
+
+ return found;
+}
+
+/* Return 1 if S points to an integer suffix, zero otherwise. */
+
+static int
+stap_check_integer_suffix (struct gdbarch *gdbarch, const char *s,
+ const char **r)
+{
+ const char *const *p = gdbarch_stap_integer_suffix (gdbarch);
+
+ return stap_generic_check_suffix (gdbarch, s, r, p);
+}
+
+/* Return 1 if S points to a register suffix, zero otherwise. */
+
+static int
+stap_check_register_suffix (struct gdbarch *gdbarch, const char *s,
+ const char **r)
+{
+ const char *const *p = gdbarch_stap_register_suffix (gdbarch);
+
+ return stap_generic_check_suffix (gdbarch, s, r, p);
+}
+
+/* Return 1 if S points to a register indirection suffix, zero otherwise. */
+
+static int
+stap_check_register_indirection_suffix (struct gdbarch *gdbarch, const char *s,
+ const char **r)
+{
+ const char *const *p = gdbarch_stap_register_indirection_suffix (gdbarch);
+
+ return stap_generic_check_suffix (gdbarch, s, r, p);
+}
+
/* Function responsible for parsing a register operand according to
SystemTap parlance. Assuming:

@@ -385,24 +550,14 @@ stap_parse_register_operand (struct stap_parse_info *p)
const char *start;
char *regname;
int len;
-
- /* Prefixes for the parser. */
- const char *reg_prefix = gdbarch_stap_register_prefix (gdbarch);
- const char *reg_ind_prefix
- = gdbarch_stap_register_indirection_prefix (gdbarch);
const char *gdb_reg_prefix = gdbarch_stap_gdb_register_prefix (gdbarch);
- int reg_prefix_len = reg_prefix ? strlen (reg_prefix) : 0;
- int reg_ind_prefix_len = reg_ind_prefix ? strlen (reg_ind_prefix) : 0;
int gdb_reg_prefix_len = gdb_reg_prefix ? strlen (gdb_reg_prefix) : 0;
-
- /* Suffixes for the parser. */
- const char *reg_suffix = gdbarch_stap_register_suffix (gdbarch);
- const char *reg_ind_suffix
- = gdbarch_stap_register_indirection_suffix (gdbarch);
const char *gdb_reg_suffix = gdbarch_stap_gdb_register_suffix (gdbarch);
- int reg_suffix_len = reg_suffix ? strlen (reg_suffix) : 0;
- int reg_ind_suffix_len = reg_ind_suffix ? strlen (reg_ind_suffix) : 0;
int gdb_reg_suffix_len = gdb_reg_suffix ? strlen (gdb_reg_suffix) : 0;
+ const char *reg_prefix;
+ const char *reg_ind_prefix;
+ const char *reg_suffix;
+ const char *reg_ind_suffix;

/* Checking for a displacement argument. */
if (*p->arg == '+')
@@ -438,11 +593,10 @@ stap_parse_register_operand (struct stap_parse_info *p)
}

/* Getting rid of register indirection prefix. */
- if (reg_ind_prefix
- && strncmp (p->arg, reg_ind_prefix, reg_ind_prefix_len) == 0)
+ if (stap_is_register_indirection_prefix (gdbarch, p->arg, &reg_ind_prefix))
{
indirect_p = 1;
- p->arg += reg_ind_prefix_len;
+ p->arg += strlen (reg_ind_prefix);
}

if (disp_p && !indirect_p)
@@ -450,8 +604,8 @@ stap_parse_register_operand (struct stap_parse_info *p)
p->saved_arg);

/* Getting rid of register prefix. */
- if (reg_prefix && strncmp (p->arg, reg_prefix, reg_prefix_len) == 0)
- p->arg += reg_prefix_len;
+ if (stap_is_register_prefix (gdbarch, p->arg, &reg_prefix))
+ p->arg += strlen (reg_prefix);

/* Now we should have only the register name. Let's extract it and get
the associated number. */
@@ -509,23 +663,21 @@ stap_parse_register_operand (struct stap_parse_info *p)
}

/* Getting rid of the register name suffix. */
- if (reg_suffix)
- {
- if (strncmp (p->arg, reg_suffix, reg_suffix_len) != 0)
- error (_("Missing register name suffix `%s' on expression `%s'."),
- reg_suffix, p->saved_arg);
-
- p->arg += reg_suffix_len;
- }
+ if (stap_check_register_suffix (gdbarch, p->arg, &reg_suffix))
+ p->arg += strlen (reg_suffix);
+ else
+ error (_("Missing register name suffix on expression `%s'."),
+ p->saved_arg);

/* Getting rid of the register indirection suffix. */
- if (indirect_p && reg_ind_suffix)
+ if (indirect_p)
{
- if (strncmp (p->arg, reg_ind_suffix, reg_ind_suffix_len) != 0)
- error (_("Missing indirection suffix `%s' on expression `%s'."),
- reg_ind_suffix, p->saved_arg);
-
- p->arg += reg_ind_suffix_len;
+ if (stap_check_register_indirection_suffix (gdbarch, p->arg,
+ &reg_ind_suffix))
+ p->arg += strlen (reg_ind_suffix);
+ else
+ error (_("Missing indirection suffix on expression `%s'."),
+ p->saved_arg);
}
}

@@ -548,19 +700,7 @@ static void
stap_parse_single_operand (struct stap_parse_info *p)
{
struct gdbarch *gdbarch = p->gdbarch;
-
- /* Prefixes for the parser. */
- const char *const_prefix = gdbarch_stap_integer_prefix (gdbarch);
- const char *reg_prefix = gdbarch_stap_register_prefix (gdbarch);
- const char *reg_ind_prefix
- = gdbarch_stap_register_indirection_prefix (gdbarch);
- int const_prefix_len = const_prefix ? strlen (const_prefix) : 0;
- int reg_prefix_len = reg_prefix ? strlen (reg_prefix) : 0;
- int reg_ind_prefix_len = reg_ind_prefix ? strlen (reg_ind_prefix) : 0;
-
- /* Suffixes for the parser. */
- const char *const_suffix = gdbarch_stap_integer_suffix (gdbarch);
- int const_suffix_len = const_suffix ? strlen (const_suffix) : 0;
+ const char *int_prefix = NULL;

/* We first try to parse this token as a "special token". */
if (gdbarch_stap_parse_special_token_p (gdbarch))
@@ -607,8 +747,7 @@ stap_parse_single_operand (struct stap_parse_info *p)
tmp = endp;
}

- if (!reg_ind_prefix
- || strncmp (tmp, reg_ind_prefix, reg_ind_prefix_len) != 0)
+ if (!stap_is_register_indirection_prefix (gdbarch, tmp, NULL))
{
/* This is not a displacement. We skip the operator, and deal
with it later. */
@@ -637,16 +776,23 @@ stap_parse_single_operand (struct stap_parse_info *p)
char *endp;
long number;

- /* We can be dealing with a numeric constant (if `const_prefix' is
- NULL), or with a register displacement. */
+ /* We can be dealing with a numeric constant, or with a register
+ displacement. */
number = strtol (tmp, &endp, 10);
tmp = endp;

if (p->inside_paren_p)
tmp = skip_spaces_const (tmp);
- if (!const_prefix && reg_ind_prefix
- && strncmp (tmp, reg_ind_prefix, reg_ind_prefix_len) != 0)
+
+ /* If "stap_is_integer_prefix" returns true, it means we can
+ accept integers without a prefix here. But we also need to
+ check whether the next token (i.e., "tmp") is not a register
+ indirection prefix. */
+ if (stap_is_integer_prefix (gdbarch, p->arg, NULL)
+ && !stap_is_register_indirection_prefix (gdbarch, tmp, NULL))
{
+ const char *int_suffix;
+
/* We are dealing with a numeric constant. */
write_exp_elt_opcode (OP_LONG);
write_exp_elt_type (builtin_type (gdbarch)->builtin_long);
@@ -655,30 +801,26 @@ stap_parse_single_operand (struct stap_parse_info *p)

p->arg = tmp;

- if (const_suffix)
- {
- if (strncmp (p->arg, const_suffix, const_suffix_len) == 0)
- p->arg += const_suffix_len;
- else
- error (_("Invalid constant suffix on expression `%s'."),
- p->saved_arg);
- }
+ if (stap_check_integer_suffix (gdbarch, p->arg, &int_suffix))
+ p->arg += strlen (int_suffix);
+ else
+ error (_("Invalid constant suffix on expression `%s'."),
+ p->saved_arg);
}
- else if (reg_ind_prefix
- && strncmp (tmp, reg_ind_prefix, reg_ind_prefix_len) == 0)
+ else if (stap_is_register_indirection_prefix (gdbarch, tmp, NULL))
stap_parse_register_operand (p);
else
error (_("Unknown numeric token on expression `%s'."),
p->saved_arg);
}
- else if (const_prefix
- && strncmp (p->arg, const_prefix, const_prefix_len) == 0)
+ else if (stap_is_integer_prefix (gdbarch, p->arg, &int_prefix))
{
/* We are dealing with a numeric constant. */
long number;
char *endp;
+ const char *int_suffix;

- p->arg += const_prefix_len;
+ p->arg += strlen (int_prefix);
number = strtol (p->arg, &endp, 10);
p->arg = endp;

@@ -687,19 +829,14 @@ stap_parse_single_operand (struct stap_parse_info *p)
write_exp_elt_longcst (number);
write_exp_elt_opcode (OP_LONG);

- if (const_suffix)
- {
- if (strncmp (p->arg, const_suffix, const_suffix_len) == 0)
- p->arg += const_suffix_len;
- else
- error (_("Invalid constant suffix on expression `%s'."),
- p->saved_arg);
- }
+ if (stap_check_integer_suffix (gdbarch, p->arg, &int_suffix))
+ p->arg += strlen (int_suffix);
+ else
+ error (_("Invalid constant suffix on expression `%s'."),
+ p->saved_arg);
}
- else if ((reg_prefix
- && strncmp (p->arg, reg_prefix, reg_prefix_len) == 0)
- || (reg_ind_prefix
- && strncmp (p->arg, reg_ind_prefix, reg_ind_prefix_len) == 0))
+ else if (stap_is_register_prefix (gdbarch, p->arg, NULL)
+ || stap_is_register_indirection_prefix (gdbarch, p->arg, NULL))
stap_parse_register_operand (p);
else
error (_("Operator `%c' not recognized on expression `%s'."),
--
1.7.11.7