This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 2/4] save itsets into file
Hi,
This patch adds a command 'save itsets' to a file, which can be used
later by command 'source'. New command 'save itsets' is similar to
command 'save breakpoints'.
gdb:
2012-08-30 Yao Qi <yao@codesourcery.com>
* itset.c: Include "completer.h" and "readline/tilde.h".
(itset_save_command): New
(_initialize_itset): Call add_cmd for "save itset" command.
gdb/testsuite:
2012-08-30 Yao Qi <yao@codesourcery.com>
* gdb.base/itset.exp (test_itset_save_restore): New.
gdb/doc:
2012-08-30 Yao Qi <yao@codesourcery.com>
* gdb.texinfo (ITSET): Document command 'save itsets'.
---
gdb/doc/gdb.texinfo | 8 ++++++
gdb/itset.c | 52 ++++++++++++++++++++++++++++++++++++++
gdb/testsuite/gdb.base/itset.exp | 37 +++++++++++++++++++++++++++
3 files changed, 97 insertions(+), 0 deletions(-)
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 5573e0d..c9228d3 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -5227,6 +5227,14 @@ When a new named itset is defined, which has already been defined before,
@value{GDBN} will overwrite the existing named itset with the new
definition.
+@kindex save itsets
+@cindex save itsets to a file for future sessions
+@item save itsets
+This command saves all current itset definitions into a file
+@file{@var{filename}} suitable for use in a later debugging session. To
+read the saved breakpoint definitions, use the @code{source} command
+(@pxref{Command Files}).
+
@item @ref{maint info itsets}
@end table
diff --git a/gdb/itset.c b/gdb/itset.c
index 6c14e6c..d3f79f7 100644
--- a/gdb/itset.c
+++ b/gdb/itset.c
@@ -28,6 +28,8 @@
#include "command.h"
#include <ctype.h>
#include "gdbcmd.h"
+#include "completer.h"
+#include "readline/tilde.h"
/* Rather than creating/destroying these dynamic itsets when
necessary, keep global copies around (itsets are refcounted). */
@@ -2352,6 +2354,49 @@ viewset_command (char *arg, int from_tty)
}
static void
+itset_save_command (char *filename, int from_tty)
+{
+ const struct named_itset *named_itset;
+ unsigned int count = 0;
+ char *pathname;
+ struct cleanup *cleanup;
+ struct ui_file *fp;
+
+ if (filename == 0 || *filename == 0)
+ error (_("Argument required (file name in which to save)"));
+
+ ALL_NAMED_ITSETS (named_itset)
+ {
+ if (named_itset->number > 0)
+ count++;
+ }
+ if (count == 0)
+ {
+ warning (_("Nothing to save."));
+ return;
+ }
+
+ pathname = tilde_expand (filename);
+ cleanup = make_cleanup (xfree, pathname);
+ fp = gdb_fopen (pathname, "w");
+ if (fp == NULL)
+ error (_("Unable to open file '%s' for saving (%s)"),
+ filename, safe_strerror (errno));
+ make_cleanup_ui_file_delete (fp);
+
+ ALL_NAMED_ITSETS (named_itset)
+ {
+ if (named_itset->number > 0)
+ fprintf_unfiltered (fp, "defset %s %s\n", itset_name (named_itset->set),
+ itset_spec (named_itset->set));
+ }
+
+ do_cleanups (cleanup);
+ if (from_tty)
+ printf_filtered (_("Saved to file '%s'.\n"), filename);
+}
+
+static void
make_internal_itset (struct itset *itset, const char *name)
{
struct named_itset *named_itset;
@@ -2418,4 +2463,11 @@ Show the style of resolving adding duplicated itset."), _("\
This setting chooses how GDB will resolve duplicated itset."),
NULL, NULL,
&setlist, &showlist);
+
+ c = add_cmd ("itsets", no_class, itset_save_command, _("\
+Save the definitions of named itsets as a script.\n\
+This includes named itset\n\
+Use the 'source' command in another debug session to restore them."),
+ &save_cmdlist);
+ set_cmd_completer (c, filename_completer);
}
diff --git a/gdb/testsuite/gdb.base/itset.exp b/gdb/testsuite/gdb.base/itset.exp
index ba72a53..5cbbbee 100644
--- a/gdb/testsuite/gdb.base/itset.exp
+++ b/gdb/testsuite/gdb.base/itset.exp
@@ -109,6 +109,41 @@ proc test_itset_without_running_process { } \
gdb_test_no_output "undefset -all"
}}
+# Test save and restore itsets.
+
+proc test_itset_save_restore { } {
+with_test_prefix "save restore" {
+ global srcdir
+ global subdir
+ global binfile
+
+ gdb_exit
+ gdb_start
+ gdb_reinitialize_dir $srcdir/$subdir
+ gdb_load ${binfile}
+
+ gdb_test "save itsets itset.txt" ".*Nothing to save.*" "nothing to save"
+
+ gdb_test_no_output "defset itset-c1 c1"
+ gdb_test_no_output "defset itset-c2 c2"
+
+ gdb_test "save itsets itset.txt" "Saved to file \'itset\.txt\'.*"
+
+ gdb_exit
+ gdb_start
+ gdb_reinitialize_dir $srcdir/$subdir
+ gdb_load ${binfile}
+
+ gdb_test "source itset.txt"
+ gdb_test_sequence "info itsets" "info itsets" {
+ "\[\n\r\]1\[ \]+itset-c1\[ \]+c1"
+ "\[\n\r\]2\[ \]+itset-c2\[ \]+c2"
+ }
+
+ remote_file host delete "itset.txt"
+}}
+
+
# Test various error messages from ITSET related commands.
proc test_itset_check_error { } \
@@ -190,6 +225,8 @@ test_itset_check_error
test_itset_check_syntax
+test_itset_save_restore
+
# Test the behaviour of ITSET in single-thread.
proc test_itset_with_running_single_thread { } \
--
1.7.7.6