public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add the -catch-load and -catch-unload MI commands.
@ 2012-08-30  9:52 Mircea Gherzan
  2012-08-30 14:44 ` Marc Khouzam
  2012-09-11 16:38 ` Tom Tromey
  0 siblings, 2 replies; 8+ messages in thread
From: Mircea Gherzan @ 2012-08-30  9:52 UTC (permalink / raw)
  To: gdb-patches; +Cc: mgherzan, Mircea Gherzan

They are equivalent to "catch load" and "catch unload" from CLI.

Rationale: GUIs might be interested in catching solib load or
unload events.

Signed-off-by: Mircea Gherzan <mircea.gherzan@intel.com>
---
 gdb/ChangeLog         |   16 +++++++++
 gdb/Makefile.in       |    9 ++++-
 gdb/breakpoint.c      |   33 +++++++++++++-----
 gdb/breakpoint.h      |    3 ++
 gdb/mi/mi-cmd-catch.c |   89 +++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/mi/mi-cmds.c      |    2 +
 gdb/mi/mi-cmds.h      |    2 +
 7 files changed, 142 insertions(+), 12 deletions(-)
 create mode 100644 gdb/mi/mi-cmd-catch.c

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 6237dee..af373a0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,19 @@
+2012-08-30  Mircea Gherzan  <mircea.gherzan@intel.com>
+
+	* Makefile.in (SUBDIR_MI_OBS): Add mi-cmd-catch.o.
+	(SUBDIR_MI_SRCS): Add mi/mi-cmd-catch.c.
+	* breakpoint.c (add_solib_catchpoint): New function based on
+	that can be used by both CLI and MI, factored out from
+	catch_load_or_unload.
+	(catch_load_or_unload): Strip it down and make it use the
+	new add_solib_catchpoint.
+	* breakpoint.h (add_solib_catchpoint): Declare it.
+	* mi/mi-cmd-catch.c: New file.
+	* mi/mi-cmds.c (mi_cmds): Add the handlers for -catch-load
+	and -catch-unload.
+	* mi/mi-cmds.h: Declare the handlers for -catch-load and 
+	-catch-unload.
+
 2012-08-29  Doug Evans  <dje@google.com>
 
 	* main.c (print_gdb_help): Remove reference to
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 5d5574e..4b99125 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -200,13 +200,14 @@ SUBDIR_CLI_CFLAGS=
 #
 SUBDIR_MI_OBS = \
 	mi-out.o mi-console.o \
-	mi-cmds.o mi-cmd-env.o mi-cmd-var.o mi-cmd-break.o mi-cmd-stack.o \
+	mi-cmds.o mi-cmd-catch.o mi-cmd-env.o \
+	mi-cmd-var.o mi-cmd-break.o mi-cmd-stack.o \
 	mi-cmd-file.o mi-cmd-disas.o mi-symbol-cmds.o mi-cmd-target.o \
 	mi-cmd-info.o mi-interp.o \
 	mi-main.o mi-parse.o mi-getopt.o
 SUBDIR_MI_SRCS = \
 	mi/mi-out.c mi/mi-console.c \
-	mi/mi-cmds.c mi/mi-cmd-env.c \
+	mi/mi-cmds.c mi/mi-cmd-catch.c mi/mi-cmd-env.c \
 	mi/mi-cmd-var.c mi/mi-cmd-break.c mi/mi-cmd-stack.c \
 	mi/mi-cmd-file.c mi/mi-cmd-disas.c mi/mi-symbol-cmds.c \
 	mi/mi-cmd-target.c mi/mi-cmd-info.c mi/mi-interp.c \
@@ -1829,6 +1830,10 @@ mi-cmd-break.o: $(srcdir)/mi/mi-cmd-break.c
 	$(COMPILE) $(srcdir)/mi/mi-cmd-break.c
 	$(POSTCOMPILE)
 
+mi-cmd-catch.o: $(srcdir)/mi/mi-cmd-catch.c
+	$(COMPILE) $(srcdir)/mi/mi-cmd-catch.c
+	$(POSTCOMPILE)
+
 mi-cmd-disas.o: $(srcdir)/mi/mi-cmd-disas.c
 	$(COMPILE) $(srcdir)/mi/mi-cmd-disas.c
 	$(POSTCOMPILE)
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index b074ecc..e23c431 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -7823,20 +7823,16 @@ print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
 
 static struct breakpoint_ops catch_solib_breakpoint_ops;
 
-/* A helper function that does all the work for "catch load" and
-   "catch unload".  */
+/* Shared helper function (MI and CLI) for creating and installing
+   a shared object event catchpoint.  */
 
-static void
-catch_load_or_unload (char *arg, int from_tty, int is_load,
-		      struct cmd_list_element *command)
+int
+add_solib_catchpoint (struct gdbarch *arch, char *arg, int is_load,
+                      int is_temp)
 {
   struct solib_catchpoint *c;
-  struct gdbarch *gdbarch = get_current_arch ();
-  int tempflag;
   struct cleanup *cleanup;
 
-  tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
-
   if (!arg)
     arg = "";
   arg = skip_spaces (arg);
@@ -7860,11 +7856,28 @@ catch_load_or_unload (char *arg, int from_tty, int is_load,
     }
 
   c->is_load = is_load;
-  init_catchpoint (&c->base, gdbarch, tempflag, NULL,
+  init_catchpoint (&c->base, arch, is_temp, NULL,
 		   &catch_solib_breakpoint_ops);
 
   discard_cleanups (cleanup);
   install_breakpoint (0, &c->base, 1);
+
+  return 1;
+}
+
+/* A helper function that does all the work for "catch load" and
+   "catch unload".  */
+
+static void
+catch_load_or_unload (char *arg, int from_tty, int is_load,
+		      struct cmd_list_element *command)
+{
+  int tempflag;
+
+  tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
+
+  add_solib_catchpoint (get_current_arch (), arg, is_load,
+                        tempflag);
 }
 
 static void
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 4c6171f..b98aeff 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1404,6 +1404,9 @@ extern void disable_breakpoints_in_shlibs (void);
 /* This function returns TRUE if ep is a catchpoint.  */
 extern int is_catchpoint (struct breakpoint *);
 
+extern int add_solib_catchpoint (struct gdbarch *arch, char *arg,
+                                 int is_load, int is_temp);
+
 /* Enable breakpoints and delete when hit.  Called with ARG == NULL
    deletes all breakpoints.  */
 extern void delete_command (char *arg, int from_tty);
diff --git a/gdb/mi/mi-cmd-catch.c b/gdb/mi/mi-cmd-catch.c
new file mode 100644
index 0000000..5c4295d
--- /dev/null
+++ b/gdb/mi/mi-cmd-catch.c
@@ -0,0 +1,89 @@
+/* MI Command Set - catch commands.
+   Copyright (C) 2012 Free Software Foundation, Inc.
+
+   Contributed by Intel Corporation.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+
+#include "defs.h"
+#include "arch-utils.h"
+#include "breakpoint.h"
+#include "libiberty.h"
+#include "mi-cmds.h"
+#include "mi-getopt.h"
+
+/* Common path for the -catch-load and -catch-unload.  */
+
+static void
+mi_catch_load_unload (int load, char *argv[], int argc)
+{
+  struct gdbarch *arch = get_current_arch ();
+  char *actual_cmd = load ? "-catch-load" : "-catch-unload";
+  int temp = 0;
+  int oind = 0;
+  char *oarg;
+  enum opt
+    {
+      TEMP,
+    };
+  static const struct mi_opt opts[] =
+    {
+      { "t", TEMP, 0 },
+    };
+
+  for (;;)
+    {
+      int opt = mi_getopt (actual_cmd, argc, argv, opts,
+                           &oind, &oarg);
+
+      if (opt < 0)
+        break;
+
+      switch ((enum opt) opt)
+        {
+        case TEMP:
+          temp = 1;
+          break;
+        }
+    }
+
+  if (oind >= argc)
+    error (_("-catch-load/unload: Missing <library name>"));
+  if (oind < argc -1)
+    error (_("-catch-load/unload: Garbage following the <library name>"));
+
+  add_solib_catchpoint (arch, argv[oind], load, temp);
+}
+
+/* Handler for the -catch-load.  */
+
+void
+mi_cmd_catch_load (char *cmd, char *argv[], int argc)
+{
+  mi_catch_load_unload (1, argv, argc);
+}
+
+
+/* Handler for the -catch-unload.  */
+
+void
+mi_cmd_catch_unload (char *cmd, char *argv[], int argc)
+{
+  mi_catch_load_unload (0, argv, argc);
+}
+
diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
index 79fbba1..69e7198 100644
--- a/gdb/mi/mi-cmds.c
+++ b/gdb/mi/mi-cmds.c
@@ -45,6 +45,8 @@ struct mi_cmd mi_cmds[] =
   { "break-list", { "info break", }, NULL },
   { "break-passcount", { NULL, 0 }, mi_cmd_break_passcount},
   { "break-watch", { NULL, 0 }, mi_cmd_break_watch},
+  { "catch-load", { NULL, 0 }, mi_cmd_catch_load},
+  { "catch-unload", { NULL, 0 }, mi_cmd_catch_unload},
   { "data-disassemble", { NULL, 0 }, mi_cmd_disassemble},
   { "data-evaluate-expression", { NULL, 0 }, mi_cmd_data_evaluate_expression},
   { "data-list-changed-registers", { NULL, 0 },
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index 4d0fc9d..0064240 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -43,6 +43,8 @@ extern mi_cmd_argv_ftype mi_cmd_break_insert;
 extern mi_cmd_argv_ftype mi_cmd_break_commands;
 extern mi_cmd_argv_ftype mi_cmd_break_passcount;
 extern mi_cmd_argv_ftype mi_cmd_break_watch;
+extern mi_cmd_argv_ftype mi_cmd_catch_load;
+extern mi_cmd_argv_ftype mi_cmd_catch_unload;
 extern mi_cmd_argv_ftype mi_cmd_disassemble;
 extern mi_cmd_argv_ftype mi_cmd_data_evaluate_expression;
 extern mi_cmd_argv_ftype mi_cmd_data_list_register_names;
-- 
1.7.1

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

* RE: [PATCH] Add the -catch-load and -catch-unload MI commands.
  2012-08-30  9:52 [PATCH] Add the -catch-load and -catch-unload MI commands Mircea Gherzan
@ 2012-08-30 14:44 ` Marc Khouzam
  2012-08-30 17:47   ` Mircea Gherzan
  2012-09-11 16:38 ` Tom Tromey
  1 sibling, 1 reply; 8+ messages in thread
From: Marc Khouzam @ 2012-08-30 14:44 UTC (permalink / raw)
  To: 'Mircea Gherzan', 'gdb-patches@sourceware.org'
  Cc: 'mgherzan@gmail.com'


> -----Original Message-----
> From: gdb-patches-owner@sourceware.org 
> [mailto:gdb-patches-owner@sourceware.org] On Behalf Of Mircea Gherzan
> Sent: Thursday, August 30, 2012 5:52 AM
> To: gdb-patches@sourceware.org
> Cc: mgherzan@gmail.com; Mircea Gherzan
> Subject: [PATCH] Add the -catch-load and -catch-unload MI commands.
> 
> They are equivalent to "catch load" and "catch unload" from CLI.
> 
> Rationale: GUIs might be interested in catching solib load or
> unload events.

I think this can be done with:
 -gdb-set stop-on-solib-events 1

although I don't believe there is support for regex as
"catch load [regex]".

That being said, it may be better to have an MI command to perform the 
"catch" command intead of specifically "catch load".
For example, in Eclipse, we use "catch catch", "catch throw",
"catch exec", "catch fork", "catch vfork", "catch syscall".

Just a thought

Marc


--
This Communication is Confidential. We only send and receive email on the basis of the terms set out at www.ericsson.com/email_disclaimer 

> 
> Signed-off-by: Mircea Gherzan <mircea.gherzan@intel.com>
> ---
>  gdb/ChangeLog         |   16 +++++++++
>  gdb/Makefile.in       |    9 ++++-
>  gdb/breakpoint.c      |   33 +++++++++++++-----
>  gdb/breakpoint.h      |    3 ++
>  gdb/mi/mi-cmd-catch.c |   89 
> +++++++++++++++++++++++++++++++++++++++++++++++++
>  gdb/mi/mi-cmds.c      |    2 +
>  gdb/mi/mi-cmds.h      |    2 +
>  7 files changed, 142 insertions(+), 12 deletions(-)
>  create mode 100644 gdb/mi/mi-cmd-catch.c
> 
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 6237dee..af373a0 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,19 @@
> +2012-08-30  Mircea Gherzan  <mircea.gherzan@intel.com>
> +
> +	* Makefile.in (SUBDIR_MI_OBS): Add mi-cmd-catch.o.
> +	(SUBDIR_MI_SRCS): Add mi/mi-cmd-catch.c.
> +	* breakpoint.c (add_solib_catchpoint): New function based on
> +	that can be used by both CLI and MI, factored out from
> +	catch_load_or_unload.
> +	(catch_load_or_unload): Strip it down and make it use the
> +	new add_solib_catchpoint.
> +	* breakpoint.h (add_solib_catchpoint): Declare it.
> +	* mi/mi-cmd-catch.c: New file.
> +	* mi/mi-cmds.c (mi_cmds): Add the handlers for -catch-load
> +	and -catch-unload.
> +	* mi/mi-cmds.h: Declare the handlers for -catch-load and 
> +	-catch-unload.
> +
>  2012-08-29  Doug Evans  <dje@google.com>
>  
>  	* main.c (print_gdb_help): Remove reference to
> diff --git a/gdb/Makefile.in b/gdb/Makefile.in
> index 5d5574e..4b99125 100644
> --- a/gdb/Makefile.in
> +++ b/gdb/Makefile.in
> @@ -200,13 +200,14 @@ SUBDIR_CLI_CFLAGS=
>  #
>  SUBDIR_MI_OBS = \
>  	mi-out.o mi-console.o \
> -	mi-cmds.o mi-cmd-env.o mi-cmd-var.o mi-cmd-break.o 
> mi-cmd-stack.o \
> +	mi-cmds.o mi-cmd-catch.o mi-cmd-env.o \
> +	mi-cmd-var.o mi-cmd-break.o mi-cmd-stack.o \
>  	mi-cmd-file.o mi-cmd-disas.o mi-symbol-cmds.o mi-cmd-target.o \
>  	mi-cmd-info.o mi-interp.o \
>  	mi-main.o mi-parse.o mi-getopt.o
>  SUBDIR_MI_SRCS = \
>  	mi/mi-out.c mi/mi-console.c \
> -	mi/mi-cmds.c mi/mi-cmd-env.c \
> +	mi/mi-cmds.c mi/mi-cmd-catch.c mi/mi-cmd-env.c \
>  	mi/mi-cmd-var.c mi/mi-cmd-break.c mi/mi-cmd-stack.c \
>  	mi/mi-cmd-file.c mi/mi-cmd-disas.c mi/mi-symbol-cmds.c \
>  	mi/mi-cmd-target.c mi/mi-cmd-info.c mi/mi-interp.c \
> @@ -1829,6 +1830,10 @@ mi-cmd-break.o: $(srcdir)/mi/mi-cmd-break.c
>  	$(COMPILE) $(srcdir)/mi/mi-cmd-break.c
>  	$(POSTCOMPILE)
>  
> +mi-cmd-catch.o: $(srcdir)/mi/mi-cmd-catch.c
> +	$(COMPILE) $(srcdir)/mi/mi-cmd-catch.c
> +	$(POSTCOMPILE)
> +
>  mi-cmd-disas.o: $(srcdir)/mi/mi-cmd-disas.c
>  	$(COMPILE) $(srcdir)/mi/mi-cmd-disas.c
>  	$(POSTCOMPILE)
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index b074ecc..e23c431 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -7823,20 +7823,16 @@ print_recreate_catch_solib (struct 
> breakpoint *b, struct ui_file *fp)
>  
>  static struct breakpoint_ops catch_solib_breakpoint_ops;
>  
> -/* A helper function that does all the work for "catch load" and
> -   "catch unload".  */
> +/* Shared helper function (MI and CLI) for creating and installing
> +   a shared object event catchpoint.  */
>  
> -static void
> -catch_load_or_unload (char *arg, int from_tty, int is_load,
> -		      struct cmd_list_element *command)
> +int
> +add_solib_catchpoint (struct gdbarch *arch, char *arg, int is_load,
> +                      int is_temp)
>  {
>    struct solib_catchpoint *c;
> -  struct gdbarch *gdbarch = get_current_arch ();
> -  int tempflag;
>    struct cleanup *cleanup;
>  
> -  tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
> -
>    if (!arg)
>      arg = "";
>    arg = skip_spaces (arg);
> @@ -7860,11 +7856,28 @@ catch_load_or_unload (char *arg, int 
> from_tty, int is_load,
>      }
>  
>    c->is_load = is_load;
> -  init_catchpoint (&c->base, gdbarch, tempflag, NULL,
> +  init_catchpoint (&c->base, arch, is_temp, NULL,
>  		   &catch_solib_breakpoint_ops);
>  
>    discard_cleanups (cleanup);
>    install_breakpoint (0, &c->base, 1);
> +
> +  return 1;
> +}
> +
> +/* A helper function that does all the work for "catch load" and
> +   "catch unload".  */
> +
> +static void
> +catch_load_or_unload (char *arg, int from_tty, int is_load,
> +		      struct cmd_list_element *command)
> +{
> +  int tempflag;
> +
> +  tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
> +
> +  add_solib_catchpoint (get_current_arch (), arg, is_load,
> +                        tempflag);
>  }
>  
>  static void
> diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
> index 4c6171f..b98aeff 100644
> --- a/gdb/breakpoint.h
> +++ b/gdb/breakpoint.h
> @@ -1404,6 +1404,9 @@ extern void 
> disable_breakpoints_in_shlibs (void);
>  /* This function returns TRUE if ep is a catchpoint.  */
>  extern int is_catchpoint (struct breakpoint *);
>  
> +extern int add_solib_catchpoint (struct gdbarch *arch, char *arg,
> +                                 int is_load, int is_temp);
> +
>  /* Enable breakpoints and delete when hit.  Called with ARG == NULL
>     deletes all breakpoints.  */
>  extern void delete_command (char *arg, int from_tty);
> diff --git a/gdb/mi/mi-cmd-catch.c b/gdb/mi/mi-cmd-catch.c
> new file mode 100644
> index 0000000..5c4295d
> --- /dev/null
> +++ b/gdb/mi/mi-cmd-catch.c
> @@ -0,0 +1,89 @@
> +/* MI Command Set - catch commands.
> +   Copyright (C) 2012 Free Software Foundation, Inc.
> +
> +   Contributed by Intel Corporation.
> +
> +   This file is part of GDB.
> +
> +   This program is free software; you can redistribute it 
> and/or modify
> +   it under the terms of the GNU General Public License as 
> published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see 
> <http://www.gnu.org/licenses/>.  */
> +
> +#include <stdio.h>
> +
> +#include "defs.h"
> +#include "arch-utils.h"
> +#include "breakpoint.h"
> +#include "libiberty.h"
> +#include "mi-cmds.h"
> +#include "mi-getopt.h"
> +
> +/* Common path for the -catch-load and -catch-unload.  */
> +
> +static void
> +mi_catch_load_unload (int load, char *argv[], int argc)
> +{
> +  struct gdbarch *arch = get_current_arch ();
> +  char *actual_cmd = load ? "-catch-load" : "-catch-unload";
> +  int temp = 0;
> +  int oind = 0;
> +  char *oarg;
> +  enum opt
> +    {
> +      TEMP,
> +    };
> +  static const struct mi_opt opts[] =
> +    {
> +      { "t", TEMP, 0 },
> +    };
> +
> +  for (;;)
> +    {
> +      int opt = mi_getopt (actual_cmd, argc, argv, opts,
> +                           &oind, &oarg);
> +
> +      if (opt < 0)
> +        break;
> +
> +      switch ((enum opt) opt)
> +        {
> +        case TEMP:
> +          temp = 1;
> +          break;
> +        }
> +    }
> +
> +  if (oind >= argc)
> +    error (_("-catch-load/unload: Missing <library name>"));
> +  if (oind < argc -1)
> +    error (_("-catch-load/unload: Garbage following the 
> <library name>"));
> +
> +  add_solib_catchpoint (arch, argv[oind], load, temp);
> +}
> +
> +/* Handler for the -catch-load.  */
> +
> +void
> +mi_cmd_catch_load (char *cmd, char *argv[], int argc)
> +{
> +  mi_catch_load_unload (1, argv, argc);
> +}
> +
> +
> +/* Handler for the -catch-unload.  */
> +
> +void
> +mi_cmd_catch_unload (char *cmd, char *argv[], int argc)
> +{
> +  mi_catch_load_unload (0, argv, argc);
> +}
> +
> diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
> index 79fbba1..69e7198 100644
> --- a/gdb/mi/mi-cmds.c
> +++ b/gdb/mi/mi-cmds.c
> @@ -45,6 +45,8 @@ struct mi_cmd mi_cmds[] =
>    { "break-list", { "info break", }, NULL },
>    { "break-passcount", { NULL, 0 }, mi_cmd_break_passcount},
>    { "break-watch", { NULL, 0 }, mi_cmd_break_watch},
> +  { "catch-load", { NULL, 0 }, mi_cmd_catch_load},
> +  { "catch-unload", { NULL, 0 }, mi_cmd_catch_unload},
>    { "data-disassemble", { NULL, 0 }, mi_cmd_disassemble},
>    { "data-evaluate-expression", { NULL, 0 }, 
> mi_cmd_data_evaluate_expression},
>    { "data-list-changed-registers", { NULL, 0 },
> diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> index 4d0fc9d..0064240 100644
> --- a/gdb/mi/mi-cmds.h
> +++ b/gdb/mi/mi-cmds.h
> @@ -43,6 +43,8 @@ extern mi_cmd_argv_ftype mi_cmd_break_insert;
>  extern mi_cmd_argv_ftype mi_cmd_break_commands;
>  extern mi_cmd_argv_ftype mi_cmd_break_passcount;
>  extern mi_cmd_argv_ftype mi_cmd_break_watch;
> +extern mi_cmd_argv_ftype mi_cmd_catch_load;
> +extern mi_cmd_argv_ftype mi_cmd_catch_unload;
>  extern mi_cmd_argv_ftype mi_cmd_disassemble;
>  extern mi_cmd_argv_ftype mi_cmd_data_evaluate_expression;
>  extern mi_cmd_argv_ftype mi_cmd_data_list_register_names;
> -- 
> 1.7.1
> 
> 

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

* Re: [PATCH] Add the -catch-load and -catch-unload MI commands.
  2012-08-30 14:44 ` Marc Khouzam
@ 2012-08-30 17:47   ` Mircea Gherzan
  2012-08-30 17:52     ` Marc Khouzam
  0 siblings, 1 reply; 8+ messages in thread
From: Mircea Gherzan @ 2012-08-30 17:47 UTC (permalink / raw)
  To: Marc Khouzam
  Cc: 'gdb-patches@sourceware.org', 'mgherzan@gmail.com'

On 30.08.2012 16:43, Marc Khouzam wrote:
>
>> -----Original Message-----
>> From: gdb-patches-owner@sourceware.org
>> [mailto:gdb-patches-owner@sourceware.org] On Behalf Of Mircea Gherzan
>> Sent: Thursday, August 30, 2012 5:52 AM
>> To: gdb-patches@sourceware.org
>> Cc: mgherzan@gmail.com; Mircea Gherzan
>> Subject: [PATCH] Add the -catch-load and -catch-unload MI commands.
>>
>> They are equivalent to "catch load" and "catch unload" from CLI.
>>
>> Rationale: GUIs might be interested in catching solib load or
>> unload events.
>
> I think this can be done with:
>   -gdb-set stop-on-solib-events 1
>
> although I don't believe there is support for regex as
> "catch load [regex]".

It's precisely this kind of support that I'm aiming at.

> That being said, it may be better to have an MI command to perform the
> "catch" command intead of specifically "catch load".
> For example, in Eclipse, we use "catch catch", "catch throw",
> "catch exec", "catch fork", "catch vfork", "catch syscall".

Please, can you propose a format for such a command family? I see it like:

   -catch --load [params] <regex>
   -catch --unload [params] <regex>

Thanks,
Mircea

> Just a thought
>
> Marc
>
>
> --
> This Communication is Confidential. We only send and receive email on the basis of the terms set out at www.ericsson.com/email_disclaimer
>
>>
>> Signed-off-by: Mircea Gherzan <mircea.gherzan@intel.com>
>> ---
>>   gdb/ChangeLog         |   16 +++++++++
>>   gdb/Makefile.in       |    9 ++++-
>>   gdb/breakpoint.c      |   33 +++++++++++++-----
>>   gdb/breakpoint.h      |    3 ++
>>   gdb/mi/mi-cmd-catch.c |   89
>> +++++++++++++++++++++++++++++++++++++++++++++++++
>>   gdb/mi/mi-cmds.c      |    2 +
>>   gdb/mi/mi-cmds.h      |    2 +
>>   7 files changed, 142 insertions(+), 12 deletions(-)
>>   create mode 100644 gdb/mi/mi-cmd-catch.c
>>
>> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
>> index 6237dee..af373a0 100644
>> --- a/gdb/ChangeLog
>> +++ b/gdb/ChangeLog
>> @@ -1,3 +1,19 @@
>> +2012-08-30  Mircea Gherzan  <mircea.gherzan@intel.com>
>> +
>> +	* Makefile.in (SUBDIR_MI_OBS): Add mi-cmd-catch.o.
>> +	(SUBDIR_MI_SRCS): Add mi/mi-cmd-catch.c.
>> +	* breakpoint.c (add_solib_catchpoint): New function based on
>> +	that can be used by both CLI and MI, factored out from
>> +	catch_load_or_unload.
>> +	(catch_load_or_unload): Strip it down and make it use the
>> +	new add_solib_catchpoint.
>> +	* breakpoint.h (add_solib_catchpoint): Declare it.
>> +	* mi/mi-cmd-catch.c: New file.
>> +	* mi/mi-cmds.c (mi_cmds): Add the handlers for -catch-load
>> +	and -catch-unload.
>> +	* mi/mi-cmds.h: Declare the handlers for -catch-load and
>> +	-catch-unload.
>> +
>>   2012-08-29  Doug Evans  <dje@google.com>
>>
>>   	* main.c (print_gdb_help): Remove reference to
>> diff --git a/gdb/Makefile.in b/gdb/Makefile.in
>> index 5d5574e..4b99125 100644
>> --- a/gdb/Makefile.in
>> +++ b/gdb/Makefile.in
>> @@ -200,13 +200,14 @@ SUBDIR_CLI_CFLAGS=
>>   #
>>   SUBDIR_MI_OBS = \
>>   	mi-out.o mi-console.o \
>> -	mi-cmds.o mi-cmd-env.o mi-cmd-var.o mi-cmd-break.o
>> mi-cmd-stack.o \
>> +	mi-cmds.o mi-cmd-catch.o mi-cmd-env.o \
>> +	mi-cmd-var.o mi-cmd-break.o mi-cmd-stack.o \
>>   	mi-cmd-file.o mi-cmd-disas.o mi-symbol-cmds.o mi-cmd-target.o \
>>   	mi-cmd-info.o mi-interp.o \
>>   	mi-main.o mi-parse.o mi-getopt.o
>>   SUBDIR_MI_SRCS = \
>>   	mi/mi-out.c mi/mi-console.c \
>> -	mi/mi-cmds.c mi/mi-cmd-env.c \
>> +	mi/mi-cmds.c mi/mi-cmd-catch.c mi/mi-cmd-env.c \
>>   	mi/mi-cmd-var.c mi/mi-cmd-break.c mi/mi-cmd-stack.c \
>>   	mi/mi-cmd-file.c mi/mi-cmd-disas.c mi/mi-symbol-cmds.c \
>>   	mi/mi-cmd-target.c mi/mi-cmd-info.c mi/mi-interp.c \
>> @@ -1829,6 +1830,10 @@ mi-cmd-break.o: $(srcdir)/mi/mi-cmd-break.c
>>   	$(COMPILE) $(srcdir)/mi/mi-cmd-break.c
>>   	$(POSTCOMPILE)
>>
>> +mi-cmd-catch.o: $(srcdir)/mi/mi-cmd-catch.c
>> +	$(COMPILE) $(srcdir)/mi/mi-cmd-catch.c
>> +	$(POSTCOMPILE)
>> +
>>   mi-cmd-disas.o: $(srcdir)/mi/mi-cmd-disas.c
>>   	$(COMPILE) $(srcdir)/mi/mi-cmd-disas.c
>>   	$(POSTCOMPILE)
>> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
>> index b074ecc..e23c431 100644
>> --- a/gdb/breakpoint.c
>> +++ b/gdb/breakpoint.c
>> @@ -7823,20 +7823,16 @@ print_recreate_catch_solib (struct
>> breakpoint *b, struct ui_file *fp)
>>
>>   static struct breakpoint_ops catch_solib_breakpoint_ops;
>>
>> -/* A helper function that does all the work for "catch load" and
>> -   "catch unload".  */
>> +/* Shared helper function (MI and CLI) for creating and installing
>> +   a shared object event catchpoint.  */
>>
>> -static void
>> -catch_load_or_unload (char *arg, int from_tty, int is_load,
>> -		      struct cmd_list_element *command)
>> +int
>> +add_solib_catchpoint (struct gdbarch *arch, char *arg, int is_load,
>> +                      int is_temp)
>>   {
>>     struct solib_catchpoint *c;
>> -  struct gdbarch *gdbarch = get_current_arch ();
>> -  int tempflag;
>>     struct cleanup *cleanup;
>>
>> -  tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
>> -
>>     if (!arg)
>>       arg = "";
>>     arg = skip_spaces (arg);
>> @@ -7860,11 +7856,28 @@ catch_load_or_unload (char *arg, int
>> from_tty, int is_load,
>>       }
>>
>>     c->is_load = is_load;
>> -  init_catchpoint (&c->base, gdbarch, tempflag, NULL,
>> +  init_catchpoint (&c->base, arch, is_temp, NULL,
>>   		   &catch_solib_breakpoint_ops);
>>
>>     discard_cleanups (cleanup);
>>     install_breakpoint (0, &c->base, 1);
>> +
>> +  return 1;
>> +}
>> +
>> +/* A helper function that does all the work for "catch load" and
>> +   "catch unload".  */
>> +
>> +static void
>> +catch_load_or_unload (char *arg, int from_tty, int is_load,
>> +		      struct cmd_list_element *command)
>> +{
>> +  int tempflag;
>> +
>> +  tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
>> +
>> +  add_solib_catchpoint (get_current_arch (), arg, is_load,
>> +                        tempflag);
>>   }
>>
>>   static void
>> diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
>> index 4c6171f..b98aeff 100644
>> --- a/gdb/breakpoint.h
>> +++ b/gdb/breakpoint.h
>> @@ -1404,6 +1404,9 @@ extern void
>> disable_breakpoints_in_shlibs (void);
>>   /* This function returns TRUE if ep is a catchpoint.  */
>>   extern int is_catchpoint (struct breakpoint *);
>>
>> +extern int add_solib_catchpoint (struct gdbarch *arch, char *arg,
>> +                                 int is_load, int is_temp);
>> +
>>   /* Enable breakpoints and delete when hit.  Called with ARG == NULL
>>      deletes all breakpoints.  */
>>   extern void delete_command (char *arg, int from_tty);
>> diff --git a/gdb/mi/mi-cmd-catch.c b/gdb/mi/mi-cmd-catch.c
>> new file mode 100644
>> index 0000000..5c4295d
>> --- /dev/null
>> +++ b/gdb/mi/mi-cmd-catch.c
>> @@ -0,0 +1,89 @@
>> +/* MI Command Set - catch commands.
>> +   Copyright (C) 2012 Free Software Foundation, Inc.
>> +
>> +   Contributed by Intel Corporation.
>> +
>> +   This file is part of GDB.
>> +
>> +   This program is free software; you can redistribute it
>> and/or modify
>> +   it under the terms of the GNU General Public License as
>> published by
>> +   the Free Software Foundation; either version 3 of the License, or
>> +   (at your option) any later version.
>> +
>> +   This program is distributed in the hope that it will be useful,
>> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> +   GNU General Public License for more details.
>> +
>> +   You should have received a copy of the GNU General Public License
>> +   along with this program.  If not, see
>> <http://www.gnu.org/licenses/>.  */
>> +
>> +#include <stdio.h>
>> +
>> +#include "defs.h"
>> +#include "arch-utils.h"
>> +#include "breakpoint.h"
>> +#include "libiberty.h"
>> +#include "mi-cmds.h"
>> +#include "mi-getopt.h"
>> +
>> +/* Common path for the -catch-load and -catch-unload.  */
>> +
>> +static void
>> +mi_catch_load_unload (int load, char *argv[], int argc)
>> +{
>> +  struct gdbarch *arch = get_current_arch ();
>> +  char *actual_cmd = load ? "-catch-load" : "-catch-unload";
>> +  int temp = 0;
>> +  int oind = 0;
>> +  char *oarg;
>> +  enum opt
>> +    {
>> +      TEMP,
>> +    };
>> +  static const struct mi_opt opts[] =
>> +    {
>> +      { "t", TEMP, 0 },
>> +    };
>> +
>> +  for (;;)
>> +    {
>> +      int opt = mi_getopt (actual_cmd, argc, argv, opts,
>> +                           &oind, &oarg);
>> +
>> +      if (opt < 0)
>> +        break;
>> +
>> +      switch ((enum opt) opt)
>> +        {
>> +        case TEMP:
>> +          temp = 1;
>> +          break;
>> +        }
>> +    }
>> +
>> +  if (oind >= argc)
>> +    error (_("-catch-load/unload: Missing <library name>"));
>> +  if (oind < argc -1)
>> +    error (_("-catch-load/unload: Garbage following the
>> <library name>"));
>> +
>> +  add_solib_catchpoint (arch, argv[oind], load, temp);
>> +}
>> +
>> +/* Handler for the -catch-load.  */
>> +
>> +void
>> +mi_cmd_catch_load (char *cmd, char *argv[], int argc)
>> +{
>> +  mi_catch_load_unload (1, argv, argc);
>> +}
>> +
>> +
>> +/* Handler for the -catch-unload.  */
>> +
>> +void
>> +mi_cmd_catch_unload (char *cmd, char *argv[], int argc)
>> +{
>> +  mi_catch_load_unload (0, argv, argc);
>> +}
>> +
>> diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
>> index 79fbba1..69e7198 100644
>> --- a/gdb/mi/mi-cmds.c
>> +++ b/gdb/mi/mi-cmds.c
>> @@ -45,6 +45,8 @@ struct mi_cmd mi_cmds[] =
>>     { "break-list", { "info break", }, NULL },
>>     { "break-passcount", { NULL, 0 }, mi_cmd_break_passcount},
>>     { "break-watch", { NULL, 0 }, mi_cmd_break_watch},
>> +  { "catch-load", { NULL, 0 }, mi_cmd_catch_load},
>> +  { "catch-unload", { NULL, 0 }, mi_cmd_catch_unload},
>>     { "data-disassemble", { NULL, 0 }, mi_cmd_disassemble},
>>     { "data-evaluate-expression", { NULL, 0 },
>> mi_cmd_data_evaluate_expression},
>>     { "data-list-changed-registers", { NULL, 0 },
>> diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
>> index 4d0fc9d..0064240 100644
>> --- a/gdb/mi/mi-cmds.h
>> +++ b/gdb/mi/mi-cmds.h
>> @@ -43,6 +43,8 @@ extern mi_cmd_argv_ftype mi_cmd_break_insert;
>>   extern mi_cmd_argv_ftype mi_cmd_break_commands;
>>   extern mi_cmd_argv_ftype mi_cmd_break_passcount;
>>   extern mi_cmd_argv_ftype mi_cmd_break_watch;
>> +extern mi_cmd_argv_ftype mi_cmd_catch_load;
>> +extern mi_cmd_argv_ftype mi_cmd_catch_unload;
>>   extern mi_cmd_argv_ftype mi_cmd_disassemble;
>>   extern mi_cmd_argv_ftype mi_cmd_data_evaluate_expression;
>>   extern mi_cmd_argv_ftype mi_cmd_data_list_register_names;
>> --
>> 1.7.1
>>


-- 


Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Peter Gleissner, Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052

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

* RE: [PATCH] Add the -catch-load and -catch-unload MI commands.
  2012-08-30 17:47   ` Mircea Gherzan
@ 2012-08-30 17:52     ` Marc Khouzam
  2012-09-10 14:09       ` Pedro Alves
  0 siblings, 1 reply; 8+ messages in thread
From: Marc Khouzam @ 2012-08-30 17:52 UTC (permalink / raw)
  To: 'Mircea Gherzan'
  Cc: 'gdb-patches@sourceware.org', 'mgherzan@gmail.com'


> -----Original Message-----
> From: Mircea Gherzan [mailto:mircea.gherzan@intel.com] 
> Sent: Thursday, August 30, 2012 1:47 PM
> To: Marc Khouzam
> Cc: 'gdb-patches@sourceware.org'; 'mgherzan@gmail.com'
> Subject: Re: [PATCH] Add the -catch-load and -catch-unload MI 
> commands.
> 
> On 30.08.2012 16:43, Marc Khouzam wrote:
> >
> >> -----Original Message-----
> >> From: gdb-patches-owner@sourceware.org
> >> [mailto:gdb-patches-owner@sourceware.org] On Behalf Of 
> Mircea Gherzan
> >> Sent: Thursday, August 30, 2012 5:52 AM
> >> To: gdb-patches@sourceware.org
> >> Cc: mgherzan@gmail.com; Mircea Gherzan
> >> Subject: [PATCH] Add the -catch-load and -catch-unload MI commands.
> >>
> >> They are equivalent to "catch load" and "catch unload" from CLI.
> >>
> >> Rationale: GUIs might be interested in catching solib load or
> >> unload events.
> >
> > I think this can be done with:
> >   -gdb-set stop-on-solib-events 1
> >
> > although I don't believe there is support for regex as
> > "catch load [regex]".
> 
> It's precisely this kind of support that I'm aiming at.
> 
> > That being said, it may be better to have an MI command to 
> perform the
> > "catch" command intead of specifically "catch load".
> > For example, in Eclipse, we use "catch catch", "catch throw",
> > "catch exec", "catch fork", "catch vfork", "catch syscall".
> 
> Please, can you propose a format for such a command family? I 
> see it like:
> 
>    -catch --load [params] <regex>
>    -catch --unload [params] <regex>

The GDB experts would know better, but I'm thinking of something
like:

   -break-catch <load|unload|catch|throw|exec|fork|vfork|syscall> [regexp]

Marc

> 
> Thanks,
> Mircea
> 
> > Just a thought
> >
> > Marc
> >
> >
> > --
> > This Communication is Confidential. We only send and 
> receive email on the basis of the terms set out at 
> www.ericsson.com/email_disclaimer
> >
> >>
> >> Signed-off-by: Mircea Gherzan <mircea.gherzan@intel.com>
> >> ---
> >>   gdb/ChangeLog         |   16 +++++++++
> >>   gdb/Makefile.in       |    9 ++++-
> >>   gdb/breakpoint.c      |   33 +++++++++++++-----
> >>   gdb/breakpoint.h      |    3 ++
> >>   gdb/mi/mi-cmd-catch.c |   89
> >> +++++++++++++++++++++++++++++++++++++++++++++++++
> >>   gdb/mi/mi-cmds.c      |    2 +
> >>   gdb/mi/mi-cmds.h      |    2 +
> >>   7 files changed, 142 insertions(+), 12 deletions(-)
> >>   create mode 100644 gdb/mi/mi-cmd-catch.c
> >>
> >> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> >> index 6237dee..af373a0 100644
> >> --- a/gdb/ChangeLog
> >> +++ b/gdb/ChangeLog
> >> @@ -1,3 +1,19 @@
> >> +2012-08-30  Mircea Gherzan  <mircea.gherzan@intel.com>
> >> +
> >> +	* Makefile.in (SUBDIR_MI_OBS): Add mi-cmd-catch.o.
> >> +	(SUBDIR_MI_SRCS): Add mi/mi-cmd-catch.c.
> >> +	* breakpoint.c (add_solib_catchpoint): New function based on
> >> +	that can be used by both CLI and MI, factored out from
> >> +	catch_load_or_unload.
> >> +	(catch_load_or_unload): Strip it down and make it use the
> >> +	new add_solib_catchpoint.
> >> +	* breakpoint.h (add_solib_catchpoint): Declare it.
> >> +	* mi/mi-cmd-catch.c: New file.
> >> +	* mi/mi-cmds.c (mi_cmds): Add the handlers for -catch-load
> >> +	and -catch-unload.
> >> +	* mi/mi-cmds.h: Declare the handlers for -catch-load and
> >> +	-catch-unload.
> >> +
> >>   2012-08-29  Doug Evans  <dje@google.com>
> >>
> >>   	* main.c (print_gdb_help): Remove reference to
> >> diff --git a/gdb/Makefile.in b/gdb/Makefile.in
> >> index 5d5574e..4b99125 100644
> >> --- a/gdb/Makefile.in
> >> +++ b/gdb/Makefile.in
> >> @@ -200,13 +200,14 @@ SUBDIR_CLI_CFLAGS=
> >>   #
> >>   SUBDIR_MI_OBS = \
> >>   	mi-out.o mi-console.o \
> >> -	mi-cmds.o mi-cmd-env.o mi-cmd-var.o mi-cmd-break.o
> >> mi-cmd-stack.o \
> >> +	mi-cmds.o mi-cmd-catch.o mi-cmd-env.o \
> >> +	mi-cmd-var.o mi-cmd-break.o mi-cmd-stack.o \
> >>   	mi-cmd-file.o mi-cmd-disas.o mi-symbol-cmds.o mi-cmd-target.o \
> >>   	mi-cmd-info.o mi-interp.o \
> >>   	mi-main.o mi-parse.o mi-getopt.o
> >>   SUBDIR_MI_SRCS = \
> >>   	mi/mi-out.c mi/mi-console.c \
> >> -	mi/mi-cmds.c mi/mi-cmd-env.c \
> >> +	mi/mi-cmds.c mi/mi-cmd-catch.c mi/mi-cmd-env.c \
> >>   	mi/mi-cmd-var.c mi/mi-cmd-break.c mi/mi-cmd-stack.c \
> >>   	mi/mi-cmd-file.c mi/mi-cmd-disas.c mi/mi-symbol-cmds.c \
> >>   	mi/mi-cmd-target.c mi/mi-cmd-info.c mi/mi-interp.c \
> >> @@ -1829,6 +1830,10 @@ mi-cmd-break.o: $(srcdir)/mi/mi-cmd-break.c
> >>   	$(COMPILE) $(srcdir)/mi/mi-cmd-break.c
> >>   	$(POSTCOMPILE)
> >>
> >> +mi-cmd-catch.o: $(srcdir)/mi/mi-cmd-catch.c
> >> +	$(COMPILE) $(srcdir)/mi/mi-cmd-catch.c
> >> +	$(POSTCOMPILE)
> >> +
> >>   mi-cmd-disas.o: $(srcdir)/mi/mi-cmd-disas.c
> >>   	$(COMPILE) $(srcdir)/mi/mi-cmd-disas.c
> >>   	$(POSTCOMPILE)
> >> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> >> index b074ecc..e23c431 100644
> >> --- a/gdb/breakpoint.c
> >> +++ b/gdb/breakpoint.c
> >> @@ -7823,20 +7823,16 @@ print_recreate_catch_solib (struct
> >> breakpoint *b, struct ui_file *fp)
> >>
> >>   static struct breakpoint_ops catch_solib_breakpoint_ops;
> >>
> >> -/* A helper function that does all the work for "catch load" and
> >> -   "catch unload".  */
> >> +/* Shared helper function (MI and CLI) for creating and installing
> >> +   a shared object event catchpoint.  */
> >>
> >> -static void
> >> -catch_load_or_unload (char *arg, int from_tty, int is_load,
> >> -		      struct cmd_list_element *command)
> >> +int
> >> +add_solib_catchpoint (struct gdbarch *arch, char *arg, 
> int is_load,
> >> +                      int is_temp)
> >>   {
> >>     struct solib_catchpoint *c;
> >> -  struct gdbarch *gdbarch = get_current_arch ();
> >> -  int tempflag;
> >>     struct cleanup *cleanup;
> >>
> >> -  tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
> >> -
> >>     if (!arg)
> >>       arg = "";
> >>     arg = skip_spaces (arg);
> >> @@ -7860,11 +7856,28 @@ catch_load_or_unload (char *arg, int
> >> from_tty, int is_load,
> >>       }
> >>
> >>     c->is_load = is_load;
> >> -  init_catchpoint (&c->base, gdbarch, tempflag, NULL,
> >> +  init_catchpoint (&c->base, arch, is_temp, NULL,
> >>   		   &catch_solib_breakpoint_ops);
> >>
> >>     discard_cleanups (cleanup);
> >>     install_breakpoint (0, &c->base, 1);
> >> +
> >> +  return 1;
> >> +}
> >> +
> >> +/* A helper function that does all the work for "catch load" and
> >> +   "catch unload".  */
> >> +
> >> +static void
> >> +catch_load_or_unload (char *arg, int from_tty, int is_load,
> >> +		      struct cmd_list_element *command)
> >> +{
> >> +  int tempflag;
> >> +
> >> +  tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
> >> +
> >> +  add_solib_catchpoint (get_current_arch (), arg, is_load,
> >> +                        tempflag);
> >>   }
> >>
> >>   static void
> >> diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
> >> index 4c6171f..b98aeff 100644
> >> --- a/gdb/breakpoint.h
> >> +++ b/gdb/breakpoint.h
> >> @@ -1404,6 +1404,9 @@ extern void
> >> disable_breakpoints_in_shlibs (void);
> >>   /* This function returns TRUE if ep is a catchpoint.  */
> >>   extern int is_catchpoint (struct breakpoint *);
> >>
> >> +extern int add_solib_catchpoint (struct gdbarch *arch, char *arg,
> >> +                                 int is_load, int is_temp);
> >> +
> >>   /* Enable breakpoints and delete when hit.  Called with 
> ARG == NULL
> >>      deletes all breakpoints.  */
> >>   extern void delete_command (char *arg, int from_tty);
> >> diff --git a/gdb/mi/mi-cmd-catch.c b/gdb/mi/mi-cmd-catch.c
> >> new file mode 100644
> >> index 0000000..5c4295d
> >> --- /dev/null
> >> +++ b/gdb/mi/mi-cmd-catch.c
> >> @@ -0,0 +1,89 @@
> >> +/* MI Command Set - catch commands.
> >> +   Copyright (C) 2012 Free Software Foundation, Inc.
> >> +
> >> +   Contributed by Intel Corporation.
> >> +
> >> +   This file is part of GDB.
> >> +
> >> +   This program is free software; you can redistribute it
> >> and/or modify
> >> +   it under the terms of the GNU General Public License as
> >> published by
> >> +   the Free Software Foundation; either version 3 of the 
> License, or
> >> +   (at your option) any later version.
> >> +
> >> +   This program is distributed in the hope that it will be useful,
> >> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> >> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> >> +   GNU General Public License for more details.
> >> +
> >> +   You should have received a copy of the GNU General 
> Public License
> >> +   along with this program.  If not, see
> >> <http://www.gnu.org/licenses/>.  */
> >> +
> >> +#include <stdio.h>
> >> +
> >> +#include "defs.h"
> >> +#include "arch-utils.h"
> >> +#include "breakpoint.h"
> >> +#include "libiberty.h"
> >> +#include "mi-cmds.h"
> >> +#include "mi-getopt.h"
> >> +
> >> +/* Common path for the -catch-load and -catch-unload.  */
> >> +
> >> +static void
> >> +mi_catch_load_unload (int load, char *argv[], int argc)
> >> +{
> >> +  struct gdbarch *arch = get_current_arch ();
> >> +  char *actual_cmd = load ? "-catch-load" : "-catch-unload";
> >> +  int temp = 0;
> >> +  int oind = 0;
> >> +  char *oarg;
> >> +  enum opt
> >> +    {
> >> +      TEMP,
> >> +    };
> >> +  static const struct mi_opt opts[] =
> >> +    {
> >> +      { "t", TEMP, 0 },
> >> +    };
> >> +
> >> +  for (;;)
> >> +    {
> >> +      int opt = mi_getopt (actual_cmd, argc, argv, opts,
> >> +                           &oind, &oarg);
> >> +
> >> +      if (opt < 0)
> >> +        break;
> >> +
> >> +      switch ((enum opt) opt)
> >> +        {
> >> +        case TEMP:
> >> +          temp = 1;
> >> +          break;
> >> +        }
> >> +    }
> >> +
> >> +  if (oind >= argc)
> >> +    error (_("-catch-load/unload: Missing <library name>"));
> >> +  if (oind < argc -1)
> >> +    error (_("-catch-load/unload: Garbage following the
> >> <library name>"));
> >> +
> >> +  add_solib_catchpoint (arch, argv[oind], load, temp);
> >> +}
> >> +
> >> +/* Handler for the -catch-load.  */
> >> +
> >> +void
> >> +mi_cmd_catch_load (char *cmd, char *argv[], int argc)
> >> +{
> >> +  mi_catch_load_unload (1, argv, argc);
> >> +}
> >> +
> >> +
> >> +/* Handler for the -catch-unload.  */
> >> +
> >> +void
> >> +mi_cmd_catch_unload (char *cmd, char *argv[], int argc)
> >> +{
> >> +  mi_catch_load_unload (0, argv, argc);
> >> +}
> >> +
> >> diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
> >> index 79fbba1..69e7198 100644
> >> --- a/gdb/mi/mi-cmds.c
> >> +++ b/gdb/mi/mi-cmds.c
> >> @@ -45,6 +45,8 @@ struct mi_cmd mi_cmds[] =
> >>     { "break-list", { "info break", }, NULL },
> >>     { "break-passcount", { NULL, 0 }, mi_cmd_break_passcount},
> >>     { "break-watch", { NULL, 0 }, mi_cmd_break_watch},
> >> +  { "catch-load", { NULL, 0 }, mi_cmd_catch_load},
> >> +  { "catch-unload", { NULL, 0 }, mi_cmd_catch_unload},
> >>     { "data-disassemble", { NULL, 0 }, mi_cmd_disassemble},
> >>     { "data-evaluate-expression", { NULL, 0 },
> >> mi_cmd_data_evaluate_expression},
> >>     { "data-list-changed-registers", { NULL, 0 },
> >> diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> >> index 4d0fc9d..0064240 100644
> >> --- a/gdb/mi/mi-cmds.h
> >> +++ b/gdb/mi/mi-cmds.h
> >> @@ -43,6 +43,8 @@ extern mi_cmd_argv_ftype mi_cmd_break_insert;
> >>   extern mi_cmd_argv_ftype mi_cmd_break_commands;
> >>   extern mi_cmd_argv_ftype mi_cmd_break_passcount;
> >>   extern mi_cmd_argv_ftype mi_cmd_break_watch;
> >> +extern mi_cmd_argv_ftype mi_cmd_catch_load;
> >> +extern mi_cmd_argv_ftype mi_cmd_catch_unload;
> >>   extern mi_cmd_argv_ftype mi_cmd_disassemble;
> >>   extern mi_cmd_argv_ftype mi_cmd_data_evaluate_expression;
> >>   extern mi_cmd_argv_ftype mi_cmd_data_list_register_names;
> >> --
> >> 1.7.1
> >>
> 
> 
> -- 
> 
> 
> Intel GmbH
> Dornacher Strasse 1
> 85622 Feldkirchen/Muenchen, Deutschland
> Sitz der Gesellschaft: Feldkirchen bei Muenchen
> Geschaeftsfuehrer: Peter Gleissner, Christian Lamprechter, 
> Hannes Schwaderer, Douglas Lusk
> Registergericht: Muenchen HRB 47456
> Ust.-IdNr./VAT Registration No.: DE129385895
> Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052
> 
> 

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

* Re: [PATCH] Add the -catch-load and -catch-unload MI commands.
  2012-08-30 17:52     ` Marc Khouzam
@ 2012-09-10 14:09       ` Pedro Alves
  2012-09-10 14:48         ` Mircea Gherzan
  0 siblings, 1 reply; 8+ messages in thread
From: Pedro Alves @ 2012-09-10 14:09 UTC (permalink / raw)
  To: Marc Khouzam
  Cc: 'Mircea Gherzan', 'gdb-patches@sourceware.org',
	'mgherzan@gmail.com'

On 08/30/2012 06:52 PM, Marc Khouzam wrote:
> 
>> -----Original Message-----
>> From: Mircea Gherzan [mailto:mircea.gherzan@intel.com] 
>> Sent: Thursday, August 30, 2012 1:47 PM
>> To: Marc Khouzam
>> Cc: 'gdb-patches@sourceware.org'; 'mgherzan@gmail.com'
>> Subject: Re: [PATCH] Add the -catch-load and -catch-unload MI 
>> commands.
>>
>> On 30.08.2012 16:43, Marc Khouzam wrote:
>>>
>>>> -----Original Message-----
>>>> From: gdb-patches-owner@sourceware.org
>>>> [mailto:gdb-patches-owner@sourceware.org] On Behalf Of 
>> Mircea Gherzan
>>>> Sent: Thursday, August 30, 2012 5:52 AM
>>>> To: gdb-patches@sourceware.org
>>>> Cc: mgherzan@gmail.com; Mircea Gherzan
>>>> Subject: [PATCH] Add the -catch-load and -catch-unload MI commands.
>>>>
>>>> They are equivalent to "catch load" and "catch unload" from CLI.
>>>>
>>>> Rationale: GUIs might be interested in catching solib load or
>>>> unload events.
>>>
>>> I think this can be done with:
>>>   -gdb-set stop-on-solib-events 1
>>>
>>> although I don't believe there is support for regex as
>>> "catch load [regex]".

Yeah, and with catch load, gdb doesn't need to stop at each
and every internal libc solib event, even if nothing seemingly
interesting (in the user's perspective) happened.

>>
>> It's precisely this kind of support that I'm aiming at.
>>
>>> That being said, it may be better to have an MI command to 
>> perform the
>>> "catch" command intead of specifically "catch load".
>>> For example, in Eclipse, we use "catch catch", "catch throw",
>>> "catch exec", "catch fork", "catch vfork", "catch syscall".
>>
>> Please, can you propose a format for such a command family? I 
>> see it like:
>>
>>    -catch --load [params] <regex>
>>    -catch --unload [params] <regex>
> 
> The GDB experts would know better, but I'm thinking of something
> like:
> 
>    -break-catch <load|unload|catch|throw|exec|fork|vfork|syscall> [regexp]

I don't this would be a good idea compared to separate commands.  Each
of those catch variants takes different parameters/options.  I'm not
seeing what putting them all under the same roof would buy.

In the CLI, although "catch exec", "catch fork", "catch syscall", etc.
have the same prefix, they're really implemented as separate commands
as well.

-- 
Pedro Alves

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

* Re: [PATCH] Add the -catch-load and -catch-unload MI commands.
  2012-09-10 14:09       ` Pedro Alves
@ 2012-09-10 14:48         ` Mircea Gherzan
  2012-09-10 15:04           ` Marc Khouzam
  0 siblings, 1 reply; 8+ messages in thread
From: Mircea Gherzan @ 2012-09-10 14:48 UTC (permalink / raw)
  To: Pedro Alves
  Cc: Marc Khouzam, 'gdb-patches@sourceware.org',
	'mgherzan@gmail.com'

Hi,

Thank you for your feedback.

On 10.09.2012 16:09, Pedro Alves wrote:
 > [...]
> I don't this would be a good idea compared to separate commands.  Each
> of those catch variants takes different parameters/options.  I'm not
> seeing what putting them all under the same roof would buy.

I am still in favour of having them as separate commands, but, if the 
powers that be decide otherwise, I am willing to rework the patch.

> In the CLI, although "catch exec", "catch fork", "catch syscall", etc.
> have the same prefix, they're really implemented as separate commands
> as well.
>

Please let me know if there are any issues that prevent this patch from 
getting merged.

Thanks,
Mircea

-- 

Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Peter Gleissner, Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052

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

* RE: [PATCH] Add the -catch-load and -catch-unload MI commands.
  2012-09-10 14:48         ` Mircea Gherzan
@ 2012-09-10 15:04           ` Marc Khouzam
  0 siblings, 0 replies; 8+ messages in thread
From: Marc Khouzam @ 2012-09-10 15:04 UTC (permalink / raw)
  To: 'Mircea Gherzan', 'Pedro Alves'
  Cc: 'gdb-patches@sourceware.org', 'mgherzan@gmail.com'

> -----Original Message-----
> From: Mircea Gherzan [mailto:mircea.gherzan@intel.com] 
> Sent: Monday, September 10, 2012 10:48 AM
> To: Pedro Alves
> Cc: Marc Khouzam; 'gdb-patches@sourceware.org'; 'mgherzan@gmail.com'
> Subject: Re: [PATCH] Add the -catch-load and -catch-unload MI 
> commands.
> 
> Hi,
> 
> Thank you for your feedback.
> 
> On 10.09.2012 16:09, Pedro Alves wrote:
>  > [...]
> > I don't this would be a good idea compared to separate 
> commands.  Each
> > of those catch variants takes different parameters/options.  I'm not
> > seeing what putting them all under the same roof would buy.
> 
> I am still in favour of having them as separate commands, but, if the 
> powers that be decide otherwise, I am willing to rework the patch.
> 
> > In the CLI, although "catch exec", "catch fork", "catch 
> syscall", etc.
> > have the same prefix, they're really implemented as 
> separate commands
> > as well.
> >
> 
> Please let me know if there are any issues that prevent this 
> patch from getting merged.

An enhancement that would be nice (but may not be blocking) is
to support a '-d' flag like -break-insert does.  This would
create the catchpoint in a disabled state.

Currently, a frontend that wants to create a disabled catchpoint
must do:
 catch load
 -break-disabled 1 (assuming the catchpoint number is 1)

in non-stop mode, this can cause a race condition where the 
catchpoint could hit before it is disabled.  It would be better 
to do a single command:
  -catch-load -d

Note that I've never actually seen this happen, but I believe
the risk is there.

BTW, we have the same potential problem with watchpoints 
which use -break-watch.

Thanks for these proposed new MI commands, they will be useful
for Eclipse.

Marc



> 
> Thanks,
> Mircea
> 
> -- 
> 
> Intel GmbH
> Dornacher Strasse 1
> 85622 Feldkirchen/Muenchen, Deutschland
> Sitz der Gesellschaft: Feldkirchen bei Muenchen
> Geschaeftsfuehrer: Peter Gleissner, Christian Lamprechter, 
> Hannes Schwaderer, Douglas Lusk
> Registergericht: Muenchen HRB 47456
> Ust.-IdNr./VAT Registration No.: DE129385895
> Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052
> 
> 

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

* Re: [PATCH] Add the -catch-load and -catch-unload MI commands.
  2012-08-30  9:52 [PATCH] Add the -catch-load and -catch-unload MI commands Mircea Gherzan
  2012-08-30 14:44 ` Marc Khouzam
@ 2012-09-11 16:38 ` Tom Tromey
  1 sibling, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2012-09-11 16:38 UTC (permalink / raw)
  To: Mircea Gherzan; +Cc: gdb-patches, mgherzan

>>>>> "Mircea" == Mircea Gherzan <mircea.gherzan@intel.com> writes:

Mircea> They are equivalent to "catch load" and "catch unload" from CLI.
Mircea> Rationale: GUIs might be interested in catching solib load or
Mircea> unload events.

This looks reasonable to me.

This needs a documentation patch, to describe the new commands, and also
new test cases.

Tom

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

end of thread, other threads:[~2012-09-11 16:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-30  9:52 [PATCH] Add the -catch-load and -catch-unload MI commands Mircea Gherzan
2012-08-30 14:44 ` Marc Khouzam
2012-08-30 17:47   ` Mircea Gherzan
2012-08-30 17:52     ` Marc Khouzam
2012-09-10 14:09       ` Pedro Alves
2012-09-10 14:48         ` Mircea Gherzan
2012-09-10 15:04           ` Marc Khouzam
2012-09-11 16:38 ` 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).