]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
gdbserver: misc fixes (#214909 c 77)
authorJulian Seward <jseward@acm.org>
Tue, 17 May 2011 17:15:07 +0000 (17:15 +0000)
committerJulian Seward <jseward@acm.org>
Tue, 17 May 2011 17:15:07 +0000 (17:15 +0000)
Fix some tests on ppc-debian6,s390x + handled Nick Nethercote, Josef
Weidendorfer comments

* improved testing & related doc
  - added option --vex-iropt-precise-memory-exns=yes to mcsig(no)pass.vgtest
    + updated manual-core.xml
  - cleanup some comments in *.vgtest
  - modified filter_gdb and filter_memcheck_monitor to
    handle specific ppc/debian6.0 mcsig(no)pass output
    handle specific s390x 'missing debug info'
  - added more information in README_DEVELOPPERS on how to
    investigate failing gdbserver tests.

* handled Nick Nethercote comment:
  Replaced kludgy ms.snapshot detailed
              by  ms.detailed_snaphot
  Updated documentation and test.

* handled Josef Weindendorfer comments:
   - do not report an error if ptrace_scope file can't be read.
     Instead, a debug trace is done if -d (debug) option given
   - added an option -l to give the list of active Valgrind
     gdbserver. Useful a.o. to support callgrind_control.
     Updated documentation
   - added ref. to  vgdb help in the vgdb --help message

(Philippe Waroquiers, philippe.waroquiers@skynet.be)

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11770

16 files changed:
coregrind/m_gdbserver/remote-utils.c
coregrind/vgdb.c
docs/xml/manual-core.xml
gdbserver_tests/README_DEVELOPPERS
gdbserver_tests/filter_gdb
gdbserver_tests/filter_memcheck_monitor
gdbserver_tests/mcbreak.vgtest
gdbserver_tests/mcinfcallRU.vgtest
gdbserver_tests/mcinfcallWSRU.vgtest
gdbserver_tests/mcsignopass.vgtest
gdbserver_tests/mcsigpass.vgtest
gdbserver_tests/mssnapshot.stderrB.exp
gdbserver_tests/mssnapshot.stdinB.gdb
gdbserver_tests/nlcontrolc.vgtest
massif/docs/ms-manual.xml
massif/ms_main.c

index eb2f011398c05753e077ef22cd9ab6f3ccaa505c..7797ff439c93f60714a6133cf25c8b1483b5b59d 100644 (file)
@@ -121,7 +121,9 @@ void set_ptracer(void)
 
    o = VG_(open) (ptrace_scope_setting_file, VKI_O_RDONLY, 0);
    if (sr_isError(o)) {
-      sr_perror(o, "error VG_(open) %s\n", ptrace_scope_setting_file);
+      if (VG_(debugLog_getLevel)() >= 1) {
+         sr_perror(o, "error VG_(open) %s\n", ptrace_scope_setting_file);
+      }
       /* can't read setting. Assuming ptrace can be called by vgdb. */
       return;
    }
index 7ddda2956c2fee72e3989f89a16bb00f3d00d716..cd315bfc2eef5c4f11f921a3be19c47ba90102f2 100644 (file)
@@ -1845,8 +1845,10 @@ void ptrace_restrictions(void)
                "blocked in a system call *after* an initial successful attach\n",
                ptrace_scope_setting_file);
    } else if (ptrace_scope == 'X') {
-      fprintf(stderr, "Could not determine ptrace scope from %s\n",
-              ptrace_scope_setting_file);
+      DEBUG (1, 
+             "PR_SET_PTRACER defined"
+             " but could not determine ptrace scope from %s\n",
+             ptrace_scope_setting_file);
    }
    if (fd >= 0)
       close (fd);
@@ -1873,7 +1875,7 @@ void usage(void)
 "     Only OPTION(s) can be given.\n"
 "\n"
 " OPTIONS are [--pid=<number>] [--vgdb-prefix=<prefix>]\n"
-"             [--max-invoke-ms=<number>] [--wait=<number>] [-d] -D]\n"
+"             [--max-invoke-ms=<number>] [--wait=<number>] [-d] [-D] [-l]\n"
 "  --pid arg must be given if multiple Valgrind gdbservers are found.\n"
 "  --vgdb-prefix arg must be given to both Valgrind and vgdb utility\n"
 "      if you want to change the default prefix for the FIFOs communication\n"
@@ -1885,13 +1887,21 @@ void usage(void)
 "           is blocked in a system call).\n"
 "  -d  arg tells to show debug info. Multiple -d args for more debug info\n"
 "  -D  arg tells to show shared mem status and then exit.\n"
+"  -l  arg tells to show the list of running Valgrind gdbserver and then exit.\n"
+"\n"
+"  -h --help shows this message\n"
+"  To get help from the Valgrind gdbserver, use vgdb help\n"
 "\n"
            );
    ptrace_restrictions();  
 }
 
-/* If arg_pid == -1, waits maximum check_trials seconds to discover
+/* If show_list, shows the list of Valgrind processes with gdbserver activated.
+                 and then exits.
+
+   else if arg_pid == -1, waits maximum check_trials seconds to discover
    a valgrind pid appearing.
+
    Otherwise verify arg_pid is valid and corresponds to a Valgrind process
    with gdbserver activated.
 
@@ -1899,7 +1909,7 @@ void usage(void)
    or exits in case of error (e.g. no pid found corresponding to arg_pid */
 
 static
-int search_arg_pid(int arg_pid, int check_trials)
+int search_arg_pid(int arg_pid, int check_trials, Bool show_list)
 {
    int i;
    int pid = -1;
@@ -1941,6 +1951,7 @@ int search_arg_pid(int arg_pid, int check_trials)
 
       /* try to find FIFOs with valid pid.
          On exit of the loop, pid is set to:
+         the last pid found if show_list (or -1 if no process was listed)
          -1 if no FIFOs matching a running process is found
          -2 if multiple FIFOs of running processes are found
          otherwise it is set to the (only) pid found that can be debugged
@@ -1980,7 +1991,10 @@ int search_arg_pid(int arg_pid, int check_trials)
                   if (*wrongpid == '\0' && newpid > 0 
                       && kill (newpid, 0) == 0) {
                      nr_valid_pid++;
-                     if (arg_pid != -1) {
+                     if (show_list) {
+                        report_pid (newpid);
+                        pid = newpid;
+                     } else if (arg_pid != -1) {
                         if (arg_pid == newpid) {
                            pid = newpid;
                         }
@@ -2014,8 +2028,10 @@ int search_arg_pid(int arg_pid, int check_trials)
       free (vgdb_dir_name);
       free (vgdb_format);
    }
-
-   if (pid == -1) {
+   
+   if (show_list) {
+      exit (1);
+   } else if (pid == -1) {
       if (arg_pid == -1)
          fprintf (stderr, "vgdb error: no FIFO found and no pid given\n");
       else
@@ -2071,12 +2087,14 @@ Bool is_opt(char* arg, char *option)
 static
 void parse_options(int argc, char** argv,
                    Bool *p_show_shared_mem,
+                   Bool *p_show_list,
                    int *p_arg_pid,
                    int *p_check_trials,
                    int *p_last_command,
                    char *commands[])
 {
    Bool show_shared_mem = False;
+   Bool show_list = False;
    int arg_pid = -1;
    int check_trials = 1;
    int last_command = -1;
@@ -2092,6 +2110,8 @@ void parse_options(int argc, char** argv,
          debuglevel++;
       } else if (is_opt(argv[i], "-D")) {
          show_shared_mem = True;
+      } else if (is_opt(argv[i], "-l")) {
+         show_list = True;
       } else if (is_opt(argv[i], "--pid=")) {
          int newpid;
          if (!numeric_val(argv[i], &newpid)) {
@@ -2143,12 +2163,35 @@ void parse_options(int argc, char** argv,
             
       }
    }
+
+   if (isatty(0) 
+       && !show_shared_mem 
+       && !show_list
+       && last_command == -1) {
+      arg_errors++;
+      fprintf (stderr, 
+               "Using vgdb standalone implies to give -D or -l or a COMMAND\n");
+   }
+
+   if (show_shared_mem && show_list) {
+      arg_errors++;
+      fprintf (stderr,
+               "Can't use both -D and -l options\n");
+   }
+
+   if (show_list && arg_pid != -1) {
+      arg_errors++;
+      fprintf (stderr,
+               "Can't use both --pid and -l options\n");
+   }
+
    if (arg_errors > 0) {
       fprintf (stderr, "args error. Try `vgdb --help` for more information\n");
       exit(1);
    }
 
    *p_show_shared_mem = show_shared_mem;
+   *p_show_list = show_list;
    *p_arg_pid = arg_pid;
    *p_check_trials = check_trials;
    *p_last_command = last_command;
@@ -2160,6 +2203,7 @@ int main(int argc, char** argv)
    int pid;
 
    Bool show_shared_mem;
+   Bool show_list;
    int arg_pid;
    int check_trials;
    int last_command;
@@ -2167,6 +2211,7 @@ int main(int argc, char** argv)
 
    parse_options(argc, argv,
                  &show_shared_mem,
+                 &show_list,
                  &arg_pid,
                  &check_trials,
                  &last_command,
@@ -2179,7 +2224,7 @@ int main(int argc, char** argv)
    if (max_invoke_ms > 0 || last_command == -1)
       install_handlers();
 
-   pid = search_arg_pid (arg_pid, check_trials);
+   pid = search_arg_pid (arg_pid, check_trials, show_list);
 
    prepare_fifos_and_shared_mem(pid);
 
index acc8f73c761cb4a1ef86fa7b25034338f5731c5e..368b20beb9b31d31189e482136b98cbc8daeb1e0 100644 (file)
@@ -2255,7 +2255,9 @@ Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
      <para> Stack unwinding on PPC32/PPC64. </para>
      <para> On PPC32/PPC64, stack unwinding for leaf functions
      (i.e. functions not calling other functions) does work properly
-     only with <option>--vex-iropt-precise-memory-exns=yes</option>
+     only with <option>--vex-iropt-precise-memory-exns=yes</option>.
+     You must also pass this option to have a precise stack when
+     a signal is trapped by gdb.
      </para>
    </listitem>
 
@@ -2522,6 +2524,11 @@ vgdb vg.set log_output -c mc.leak_check any
     shared memory used by the Valgrind gdbserver. vgdb will exit after
     having shown the Valgrind gdbserver shared memory state.</para>
   </listitem>
+
+  <listitem>
+    <para><option>-l</option> instructs vgdb to report the list of
+    the Valgrind gdbserver processes running and then exit.</para>
+  </listitem>
 </itemizedlist>
  
 </sect1>
index bde8f9c8b936f9cef310fcbe274802a081203351..5eae785e19eb2577414de04dd43c2e9fb92c5f07 100644 (file)
@@ -25,9 +25,11 @@ The minimum version to use the Valgrind gdbserver is gdb >= 6.5.
     read/write from stdin/stdout.
 
 The tests have been run on various platforms using gdb 7.2
-and on some platforms gdb 7.0.
+and on some platforms gdb 7.0 and 7.1.
 Some gdb tests implies a gdb >= 7.2. (these are automatically disabled
 if testing with a lower version).
+Test behaviour with gdb < 7.0 is unknown: some might fail,
+some might block or loop for a very long time.
 
 Some tests implies to have a vgdb "ptrace invoker" capable.
 
@@ -36,12 +38,14 @@ Each test verifies the prerequisite using the prereq: line.
 
 In case of failing tests
 ------------------------
-gdbserver tests are often failing due to (irrelevant) differences
-depending on the gdb version and/or the OS version.
+When executed with a new gdb version and/or depending on the OS version,
+gdbserver tests might often fail due to (irrelevant) differences.
 Such irrelevant differences have to be filtered by gdbserver_tests/filter_gdb.
 
-To report such problems, the best is to re-run the gdbserver tests
-the following way:
+You are welcome to fix such bugs by enhancing filter_gdb.
+
+Alternatively, to report such problems, the best is to re-run
+the gdbserver tests the following way:
    perl tests/vg_regtest --keep-unfiltered gdbserver_tests
 
 Then file a bug in bugzilla, giving the following information:
@@ -50,8 +54,24 @@ Then file a bug in bugzilla, giving the following information:
     uname -a
     cat /etc/issue
     valgrind --version (and/or svn version)
-  and attach a tar file containing all the *.out files in gdbserver_tests
-    directory
+  and attach a tar file containing all the *.out and *.diff
+  files in gdbserver_tests directory
+
+If a gdbserver test fails for other reasons, you can run the test
+manually in two windows:
+  In one window, the valgrind
+  In another window, you launch gdb yourself, and you copy paste
+  the command from xxxx.stdinB.gdb. This might help to see what is
+  wrong.
+
+Another good trick is also to execute the same kind of actions
+using a gdb connected to the gdbserver part of gdb.
+You can examine what is happening by enabling the trace
+of the packets being sent using the gdb command:
+   set debug remote 1
+Note however that the packets might be different
+(e.g. the Valgrind gdbserver understands the 'P' packet,
+which might not be understood by the gdbserver of gdb).
 
 Naming conventions:
 -------------------
index 90694703c106dd24794473d24fbd370d9240181f..42f494d13d6c7ad275a76494e97d30bf1d23ee74 100755 (executable)
@@ -42,7 +42,7 @@ $dir/filter_memcheck_monitor                                        |
 #       which registers can't be modified
 #       special transform for arm/ppc watchpoints which have an additional address
 #              at the beginning
-#       special transform for backtrace of arm division by zero which gives
+#       special transform for backtrace of arm or ppc division by zero which gives
 #             a location in the nptl lib rather than our sources (same as
 #              standard gdb gdbserver) gdb 7.0
 #       same special transform but for gdb 7.2
@@ -50,9 +50,10 @@ $dir/filter_memcheck_monitor                                        |
 #         a.o. produced by gdb 7.2 on arm (same with standard gdbserver)
 #       delete empty lines (the last line (only made of prompts) sometimes
 #           finishes with a new line, sometimes not ???).
-sed -e '/Remote debugging using/,/vgdb launched process attached/d' \
+sed -e '/Remote debugging using/,/vgdb launched process attached/d'                                   \
     -e 's/^\e\[?1034hReading symbols/Reading symbols/'                                                \
-    -e '/Missing separate debuginfos, use: debuginfo-install/d'                                       \
+    -e '/^Missing separate debuginfo/d'                                                               \
+    -e '/^Try: zypper install -C/d'                                                                   \
     -e 's/\(relaying data between gdb and process \)[0-9][0-9]*/\1..../'                              \
     -e 's/pid [0-9][0-9]*/pid ..../g'                                                                 \
     -e 's/Thread [0-9][0-9]*/Thread ..../g'                                                           \
@@ -69,8 +70,7 @@ sed -e '/Remote debugging using/,/vgdb launched process attached/d' \
     -e 's/in _dl_sysinfo_int80 () from \/lib\/ld-linux.so.*/in syscall .../'                          \
     -e 's/in _dl_sysinfo_int80 ()/in syscall .../'                                                    \
     -e '/^   from \/lib\/ld-linux.so.*$/d'                                                            \
-    -e 's/\(0x........\) in ?? () from \/lib\/ld-linux\.so\../\1 in syscall .../'                     \
-    -e 's/\(0x........\) in ?? () from \/lib64\/tls\/libc\.so\../\1 in syscall .../'                  \
+    -e 's/\(0x........\) in ?? () from \/lib.*$/\1 in syscall .../'                                   \
     -e 's/\(0x........\) in ?? ()$/\1 in syscall .../'                                                \
     -e 's/in \(.__\)\{0,1\}select () from \/.*$/in syscall .../'                                      \
     -e '/^   from \/lib\/libc.so.*$/d'                                                                \
@@ -87,10 +87,10 @@ sed -e '/Remote debugging using/,/vgdb launched process attached/d' \
     -e 's/\(ERROR changing register \).*$/\1 xxx regno y/'                                            \
     -e 's/0x........ in \(main (argc=1, argv=0x........) at watchpoints.c:[24][3689]\)/\1/'           \
     -e 's/0x........ in \(main () at clean_after_fork.c:32\)/\1/'                                     \
-    -e 's/0x........ in \*__GI_raise (sig=8)/0x........ in test4 () at faultstatus.c:120/'            \
-    -e 's/    at ..\/nptl\/sysdeps\/unix\/sysv\/linux\/raise.c:[0-9]*/120              volatile int v = 44\/zero();/' \
+    -e 's/^0x........ in \*__GI_raise (sig=8).*/0x........ in test4 () at faultstatus.c:120\n120               volatile int v = 44\/zero();/' \
+    -e '/    at ..\/nptl\/sysdeps\/unix\/sysv\/linux\/raise.c:[0-9]*/d'                               \
     -e '/      in ..\/nptl\/sysdeps\/unix\/sysv\/linux\/raise.c/d'                                   \
-    -e 's/0x........ in \.\{0,1\}raise () from \/lib[0-9]\{0,2\}\/libc\.so\../0x........ in test4 () at faultstatus.c:120\n120         volatile int v = 44\/zero();'/ \
+    -e 's/^0x........ in \.\{0,1\}raise () from \/lib[0-9]\{0,2\}\/libc\.so\../0x........ in test4 () at faultstatus.c:120\n120                volatile int v = 44\/zero();'/ \
     -e '/Cannot access memory at address 0x......../d'                                                \
     -e '/^$/d' |
 
index 9a503369755eca1147edcbaa5d056fd6bff1cd89..73eb82e99485af8dedb6e7b1378d6df86809eaf9 100755 (executable)
@@ -1,6 +1,6 @@
 #! /bin/sh
 
-# used to filter memcheck output shown by vgdb.
+# used to filter memcheck output shown by gdb/vgdb.
 
 dir=`dirname $0`
 
@@ -10,7 +10,20 @@ $dir/../memcheck/tests/filter_stderr                   |
 $dir/filter_vgdb                                       |
 
 
+
+# filter some normal error messages provided by some gdb
+#
+# gdb 7.2 sometimes tries to access address 0x0 (same as with standard gdbserver)
+#
+# filter a debian 6.0/ppc32 line
+#
+# filter some missing info msg from s390
+#
 # Bypass a s390x kernel bug which makes faultstatus test3 fail. In our case, we are
 # not interested in checking the si_code, but rather the signal passing
 # in mcsig(no)pass
-sed -e 's/Test 3:   FAIL: expected si_code==2, not 128/Test 3:   PASS/'
+sed -e '/Cannot access memory at address 0x......../d'                   \
+    -e '/^[1-9][0-9]*  \.\.\/sysdeps\/powerpc\/powerpc32\/dl-start\.S: No such file or directory\./d' \
+    -e '/^Missing separate debuginfo/d'                                  \
+    -e '/^Try: zypper install -C/d'                                      \
+    -e 's/Test 3:   FAIL: expected si_code==2, not 128/Test 3:   PASS/'
index f413268cbab23972c576129088f7170520a47940..afa6ad5838f57a84375bb3f7c3fcf7369a53ebfc 100644 (file)
@@ -4,11 +4,9 @@ prereq: test -e gdb
 prog: t
 vgopts: --tool=memcheck --vgdb=yes --vgdb-error=0 --vgdb-prefix=./vgdb-prefix-mcbreak
 stdout_filter: filter_gdb
-#stdout_filter: /bin/cat
 stderr_filter: filter_make_empty
 progB: gdb
 argsB:  --quiet -l 60 --nx ./t
 stdinB: mcbreak.stdinB.gdb
 stdoutB_filter: filter_gdb
-#stdoutB_filter: /bin/cat
 stderrB_filter: filter_memcheck_monitor
index aff2109f605b212a48cc6536285757a0b32e2af6..a193acf6b824b87b03cfb6677c90727500e7d6c9 100644 (file)
@@ -4,9 +4,7 @@ prog: sleepers
 # too much dependencies to the scheduler fairness.
 args: 1 0 2000000000 ------B-
 vgopts: --tool=memcheck --vgdb=yes --vgdb-error=0 --vgdb-prefix=./vgdb-prefix-mcinfcallRU
-# filter_gdb to replace pid and Thread numbers.
-# Well, the test will verify we have 4 calls (for each thread)
-# but no way to check that this is effectively in the 4 different threads.
+# filter_gdb to replace pid and Thread numbers in the output of the program:
 stderr_filter: filter_gdb
 # Disable on Darwin: inferior call rejected as it cannot find malloc.
 prereq: test -e gdb && ../tests/os_test linux
index 1b19cc76e78758bf7800e4d396ca78c784baa019..0bb4b6ad214db4a31e423a509c075b2da9de4302 100644 (file)
@@ -7,7 +7,7 @@ args: 100 100000000 1000000000 -S-S-SB-
 vgopts: --tool=memcheck --vgdb=yes --vgdb-error=0 --vgdb-prefix=./vgdb-prefix-mcinfcallWSRU
 # Disable on Darwin: inferior call rejected as it cannot find malloc.
 prereq: test -e gdb && ../tests/os_test linux
-# filter_gdb to replace pid and Thread numbers.
+# filter_gdb to replace pid and Thread numbers in the output of the program:
 stderr_filter: filter_gdb
 progB: gdb
 argsB:  --quiet -l 60 --nx 1>&2 ./sleepers
index 025be5f462381894139c971737209ae67a1a6804..a5a2ff6c1287b64fa1b5ce09945f9d79b40f18a2 100644 (file)
@@ -6,7 +6,7 @@
 #      are eventually passed.
 prereq: test -e gdb
 prog: ../none/tests/faultstatus
-vgopts: --tool=memcheck --vgdb=full --vgdb-error=0 --vgdb-prefix=./vgdb-prefix-mcsignopass
+vgopts: --tool=memcheck --vgdb=full --vex-iropt-precise-memory-exns=yes --vgdb-error=0 --vgdb-prefix=./vgdb-prefix-mcsignopass
 stderr_filter: filter_memcheck_monitor
 progB: gdb
 argsB: --quiet -l 60 --nx ../none/tests/faultstatus
index 3df874b4bf5c1516543a6a3640ad2d1ee8129e91..532a62e3c641639637bc6fd92914bbe438889dc5 100644 (file)
@@ -1,7 +1,7 @@
 # test the signal handling, when signals are passed to the Valgrind guest.
 prereq: test -e gdb
 prog: ../none/tests/faultstatus
-vgopts: --tool=memcheck --vgdb=full --vgdb-error=0 --vgdb-prefix=./vgdb-prefix-mcsigpass
+vgopts: --tool=memcheck --vgdb=full --vex-iropt-precise-memory-exns=yes --vgdb-error=0 --vgdb-prefix=./vgdb-prefix-mcsigpass
 stderr_filter: filter_memcheck_monitor
 progB: gdb
 argsB: --quiet -l 60 --nx ../none/tests/faultstatus
index 4b7a012d689c2661669c867d40fc559101bafb3f..b9b311de998a01985ef730f06bb74483b7e69e33 100644 (file)
@@ -13,10 +13,11 @@ general valgrind monitor commands:
   vg.set vgdb-error <errornr> : debug me at error >= <errornr> 
 
 massif monitor commands:
-  ms.snapshot [<filename>] [detailed]
-       takes a snapshot and saves it in <filename>
+  ms.snapshot [<filename>]
+  ms.detailed_snapshot [<filename>]
+       takes a snapshot (or a detailed snapshot)
+       and saves it in <filename>
              default <filename> is massif.vgdb.out
-             if present, detailed argument indicates to take a detailed snapshot
 
 monitor command request to kill this process
 Remote connection closed
index efe5a7ed78a41eed645e4ed8cbb1085da949c0e0..5c403781bda12e08ef3eb0e60d49c6b552e8689f 100644 (file)
@@ -15,7 +15,7 @@ monitor help
 #
 # test non detailed and detailed snapshot
 monitor ms.snapshot
-monitor ms.snapshot detailed
+monitor ms.detailed_snapshot
 #
 #
 monitor vg.kill
index 6a36cc238ed49ef96dd321a5739c7914f85bf0e3..64d21e317e49563927b0666f3ba366b1f2fbec61 100644 (file)
@@ -14,7 +14,5 @@ prereq: test -e gdb -a -f vgdb.ptraceinvoker
 progB: gdb
 argsB: --quiet -l 60 --nx ./sleepers
 stdinB: nlcontrolc.stdinB.gdb
-#stdoutB_filter: /bin/cat
 stdoutB_filter: filter_gdb
-#stderrB_filter: /bin/cat
 stderrB_filter: filter_make_empty
index f9cc1ff6f0f10090a74edda1f3543d0f146f98e7..1389eb9249dcfc7d6b4f43270f9578a6acc195a0 100644 (file)
@@ -866,9 +866,15 @@ gdbserver (see <xref linkend="manual-core.gdbserver-commandhandling"/>).
 
 <itemizedlist>
   <listitem>
-    <para><varname>ms.snapshot [&lt;filename&gt;] [detailed]</varname> requests to take
-    a snapshot and save it in the given &lt;filename&gt; (default massif.vgdb.out).
-    If present, the 'detailed' argument indicates to take a detailed snapshot.
+    <para><varname>ms.snapshot [&lt;filename&gt;]</varname> requests
+    to take a snapshot and save it in the given &lt;filename&gt;
+    (default massif.vgdb.out).
+    </para>
+  </listitem>
+  <listitem>
+    <para><varname>ms.detailed_snapshot [&lt;filename&gt;]</varname>
+    requests to take a detailed snapshot and save it in the given
+    &lt;filename&gt; (default massif.vgdb.out).
     </para>
   </listitem>
 </itemizedlist>
index 6bc49254f15901265f005c51b60a9009f768ffd8..08bfb380996f6002a47e2fc29dd1173510acc21b 100644 (file)
@@ -1982,10 +1982,11 @@ static void print_monitor_help ( void )
 {
    VG_(gdb_printf) ("\n");
    VG_(gdb_printf) ("massif monitor commands:\n");
-   VG_(gdb_printf) ("  ms.snapshot [<filename>] [detailed]\n");
-   VG_(gdb_printf) ("       takes a snapshot and saves it in <filename>\n");
+   VG_(gdb_printf) ("  ms.snapshot [<filename>]\n");
+   VG_(gdb_printf) ("  ms.detailed_snapshot [<filename>]\n");
+   VG_(gdb_printf) ("       takes a snapshot (or a detailed snapshot)\n");
+   VG_(gdb_printf) ("       and saves it in <filename>\n");
    VG_(gdb_printf) ("             default <filename> is massif.vgdb.out\n");
-   VG_(gdb_printf) ("             if present, detailed argument indicates to take a detailed snapshot\n");
    VG_(gdb_printf) ("\n");
 }
 
@@ -2379,6 +2380,18 @@ static void write_snapshots_array_to_file(void)
    VG_(free)(massif_out_file);
 }
 
+static handle_snapshot_monitor_command (Char *filename, Bool detailed)
+{
+   Snapshot snapshot;
+
+   clear_snapshot(&snapshot, /* do_sanity_check */ False);
+   take_snapshot(&snapshot, Normal, get_time(), detailed);
+   write_snapshots_to_file ((filename == NULL) ? (Char*) "massif.vgdb.out" : filename,
+                            &snapshot,
+                            1);
+   delete_snapshot(&snapshot);
+}
+
 static Bool handle_gdb_monitor_command (ThreadId tid, Char *req)
 {
    Char* wcmd;
@@ -2388,7 +2401,7 @@ static Bool handle_gdb_monitor_command (ThreadId tid, Char *req)
    VG_(strcpy) (s, req);
 
    wcmd = VG_(strtok_r) (s, " ", &ssaveptr);
-   switch (VG_(keyword_id) ("help ms.snapshot", 
+   switch (VG_(keyword_id) ("help ms.snapshot ms.detailed_snapshot", 
                             wcmd, kwd_report_duplicated_matches)) {
    case -2: /* multiple matches */
       return True;
@@ -2398,29 +2411,15 @@ static Bool handle_gdb_monitor_command (ThreadId tid, Char *req)
       print_monitor_help();
       return True;
    case  1: { /* ms.snapshot */
-      Char* kw;
-      Char* filename = NULL;
-      Bool detailed = False;
-      Snapshot snapshot;
-      
-      for (kw = VG_(strtok_r) (NULL, " ", &ssaveptr); 
-           kw != NULL; 
-           kw = VG_(strtok_r) (NULL, " ", &ssaveptr)) {
-        if (filename == NULL)
-           filename = kw;
-        else if (0 == VG_(strncmp)(kw, "detailed", VG_(strlen) (kw))) 
-           detailed = True;
-        else {
-           VG_(gdb_printf) ("invalid 2nd arg\n");
-           return True;
-        }
-      }
-      clear_snapshot(&snapshot, /* do_sanity_check */ False);
-      take_snapshot(&snapshot, Normal, get_time(), detailed);
-      write_snapshots_to_file ((filename == NULL) ? (Char*) "massif.vgdb.out" : filename,
-                               &snapshot,
-                               1);
-      delete_snapshot(&snapshot);
+      Char* filename;
+      filename = VG_(strtok_r) (NULL, " ", &ssaveptr);
+      handle_snapshot_monitor_command (filename, False /* detailed */);
+      return True;
+   }
+   case  2: { /* ms.detailed_snapshot */
+      Char* filename;
+      filename = VG_(strtok_r) (NULL, " ", &ssaveptr);
+      handle_snapshot_monitor_command (filename, True /* detailed */);
       return True;
    }
    default: