[RFC,gdb/cli] Add maintenance ignore-probes
Commit Message
There's a command "disable probes", but SystemTap probes cannot be disabled.
Add a command "maintenance ignore-probes" that ignores probes during
get_probes, such that we can easily pretend to use a glibc without say,
the longjmp probe:
...
(gdb) maint ignore-probes libc longjmp$
(gdb) start ^M
Temporary breakpoint 1 at 0x4005bb: file longjmp.c, line 46.
Starting program: outputs/gdb.base/longjmp/longjmp ^M
Ignoring SystemTap probe libc longjmp in /lib64/libc.so.6.^M
Ignoring SystemTap probe libc longjmp in /lib64/libc.so.6.^M
Ignoring SystemTap probe libc longjmp in /lib64/libc.so.6.^M
^M
Breakpoint 1, main () at longjmp.c:46^M
46 volatile int i = 0;^M
(gdb)
...
Note that as with "disable probes", running "maint ignore-probes" without
arguments ignores all probes.
PR cli/27159
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27159
---
gdb/probe.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
gdb/probe.h | 5 +++++
gdb/stap-probe.c | 7 +++++++
3 files changed, 61 insertions(+)
base-commit: 58c49b3efef1833762ba4725937f8625058607f4
Comments
>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:
Tom> There's a command "disable probes", but SystemTap probes cannot be disabled.
Tom> Add a command "maintenance ignore-probes" that ignores probes during
Tom> get_probes, such that we can easily pretend to use a glibc without say,
Tom> the longjmp probe:
The idea seems sound to me.
Tom> Note that as with "disable probes", running "maint ignore-probes" without
Tom> arguments ignores all probes.
I didn't know about "disable probes" but I see now it's a DTrace thing.
Tom> +/* Implementation of the `maintenance ignore-probes' command. */
Tom> +
Tom> +static void
Tom> +ignore_probes_command (const char *arg, int from_tty)
Tom> +{
Tom> + std::string ignore_provider, ignore_probe_name, ignore_objname;
Tom> +
Tom> + parse_probe_linespec ((const char *) arg, &ignore_provider,
Tom> + &ignore_probe_name, &ignore_objname);
The cast there isn't needed. I'm going to remove the other casts like
this in a second.
Also, maybe if arg==nullptr, this could set ignore_probes_p = false?
That would give a way to undo the change.
Tom> + add_cmd ("ignore-probes", class_maintenance, ignore_probes_command, _("\
Tom> +Ignore probes.\n\
Tom> +Usage: ignore probes [PROVIDER [NAME [OBJECT]]]\n\
Missing the "-" in "ignore-probes".
Tom> +all defined probes. Only supported for SystemTap probes"),
Probably should end with a "."
Tom
On 12/13/22 16:58, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Tom> There's a command "disable probes", but SystemTap probes cannot be disabled.
> Tom> Add a command "maintenance ignore-probes" that ignores probes during
> Tom> get_probes, such that we can easily pretend to use a glibc without say,
> Tom> the longjmp probe:
>
> The idea seems sound to me.
>
> Tom> Note that as with "disable probes", running "maint ignore-probes" without
> Tom> arguments ignores all probes.
>
> I didn't know about "disable probes" but I see now it's a DTrace thing.
>
> Tom> +/* Implementation of the `maintenance ignore-probes' command. */
> Tom> +
> Tom> +static void
> Tom> +ignore_probes_command (const char *arg, int from_tty)
> Tom> +{
> Tom> + std::string ignore_provider, ignore_probe_name, ignore_objname;
> Tom> +
> Tom> + parse_probe_linespec ((const char *) arg, &ignore_provider,
> Tom> + &ignore_probe_name, &ignore_objname);
>
> The cast there isn't needed. I'm going to remove the other casts like
> this in a second.
>
Done.
> Also, maybe if arg==nullptr, this could set ignore_probes_p = false?
> That would give a way to undo the change.
>
That functionality is sort of already available as "maint ignore-probes
foobar foobar foobar", but agreed, having a reliable and concise way to
do it is better.
I've added that functionality, but as "maint ignore-probes -reset", to
not break the similarity in usage with "disable probes"
> Tom> + add_cmd ("ignore-probes", class_maintenance, ignore_probes_command, _("\
> Tom> +Ignore probes.\n\
> Tom> +Usage: ignore probes [PROVIDER [NAME [OBJECT]]]\n\
>
> Missing the "-" in "ignore-probes".
>
As well as the "maintenance" prefix, both fixed.
> Tom> +all defined probes. Only supported for SystemTap probes"),
>
> Probably should end with a "."
Done.
I've also added a -verbose option.
If you're ok with the updates, I'll add the docs part and do a proper
submission.
Thanks,
- Tom
Tom> That functionality is sort of already available as "maint
Tom> ignore-probes foobar foobar foobar", but agreed, having a reliable and
Tom> concise way to do it is better.
Hah, I didn't think of that.
Tom> If you're ok with the updates, I'll add the docs part and do a proper
Tom> submission.
Seems fine to me.
Tom
@@ -680,6 +680,45 @@ disable_probes_command (const char *arg, int from_tty)
}
}
+static bool ignore_probes_p = false;
+static gdb::optional<compiled_regex> ignore_obj_pat;
+static gdb::optional<compiled_regex> ignore_prov_pat;
+static gdb::optional<compiled_regex> ignore_probe_pat;
+
+/* See comments in probe.h. */
+
+bool ignore_probe (const char *provider, const char *name,
+ const char *objfile_name)
+{
+ return (ignore_probes_p
+ && (!ignore_obj_pat
+ || ignore_obj_pat->exec (objfile_name, 0, NULL, 0) == 0)
+ && (!ignore_prov_pat
+ || ignore_prov_pat->exec (provider, 0, NULL, 0) == 0)
+ && (!ignore_probe_pat
+ || ignore_probe_pat->exec (name, 0, NULL, 0) == 0));
+}
+
+/* Implementation of the `maintenance ignore-probes' command. */
+
+static void
+ignore_probes_command (const char *arg, int from_tty)
+{
+ std::string ignore_provider, ignore_probe_name, ignore_objname;
+
+ parse_probe_linespec ((const char *) arg, &ignore_provider,
+ &ignore_probe_name, &ignore_objname);
+
+ ignore_prov_pat.emplace (ignore_provider.c_str (), REG_NOSUB,
+ _("Invalid provider regexp"));
+ ignore_probe_pat.emplace (ignore_probe_name.c_str (), REG_NOSUB,
+ _("Invalid probe regexp"));
+ ignore_obj_pat.emplace (ignore_objname.c_str (), REG_NOSUB,
+ _("Invalid object file regexp"));
+
+ ignore_probes_p = true;
+}
+
/* See comments in probe.h. */
struct value *
@@ -931,4 +970,14 @@ If you do not specify any argument then the command will disable\n\
all defined probes."),
&disablelist);
+ add_cmd ("ignore-probes", class_maintenance, ignore_probes_command, _("\
+Ignore probes.\n\
+Usage: ignore probes [PROVIDER [NAME [OBJECT]]]\n\
+Each argument is a regular expression, used to select probes.\n\
+PROVIDER matches probe provider names.\n\
+NAME matches the probe names.\n\
+OBJECT matches the executable or shared library name.\n\
+If you do not specify any argument then the command will ignore\n\
+all defined probes. Only supported for SystemTap probes"),
+ &maintenancelist);
}
@@ -304,4 +304,9 @@ extern struct cmd_list_element **info_probes_cmdlist_get (void);
extern struct value *probe_safe_evaluate_at_pc (frame_info_ptr frame,
unsigned n);
+/* Return true if the PROVIDER/NAME probe from OBJFILE_NAME needs to be
+ ignored. */
+
+bool ignore_probe (const char *provider, const char *name,
+ const char *objfile_name);
#endif /* !defined (PROBE_H) */
@@ -1619,6 +1619,13 @@ handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
return;
}
+ if (ignore_probe (provider, name, objfile_name (objfile)))
+ {
+ gdb_printf (gdb_stdlog, _("Ignoring SystemTap probe %s %s in %s.\n"),
+ provider, name, objfile_name (objfile));
+ return;
+ }
+
stap_probe *ret = new stap_probe (std::string (name), std::string (provider),
address, gdbarch, sem_addr, probe_args);