public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFC] [gdb/cli] Add maintenance ignore-probes
@ 2022-12-07  9:00 Tom de Vries
  2022-12-13 15:58 ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Tom de Vries @ 2022-12-07  9:00 UTC (permalink / raw)
  To: gdb-patches

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(+)

diff --git a/gdb/probe.c b/gdb/probe.c
index ec8845219fa..631f35ecd1f 100644
--- a/gdb/probe.c
+++ b/gdb/probe.c
@@ -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);
 }
diff --git a/gdb/probe.h b/gdb/probe.h
index 598f43a238e..3637ea9cc10 100644
--- a/gdb/probe.h
+++ b/gdb/probe.h
@@ -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) */
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index 6f91d87846a..f244d85bb3d 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -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);
 

base-commit: 58c49b3efef1833762ba4725937f8625058607f4
-- 
2.35.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-13 23:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-07  9:00 [RFC] [gdb/cli] Add maintenance ignore-probes Tom de Vries
2022-12-13 15:58 ` Tom Tromey
2022-12-13 21:50   ` Tom de Vries
2022-12-13 23:39     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).