Fix 308644 vgdb command for having the info for the track-fds option
authorphilippe <philippe@a5019735-40e9-0310-863c-91ae7b9d1cf9>
Sun, 21 Oct 2012 14:37:14 +0000 (14:37 +0000)
committerphilippe <philippe@a5019735-40e9-0310-863c-91ae7b9d1cf9>
Sun, 21 Oct 2012 14:37:14 +0000 (14:37 +0000)
(allows to have the list of opened fds and the associated info
on request from GDB or from the shell, using vgdb)

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13072 a5019735-40e9-0310-863c-91ae7b9d1cf9

NEWS
coregrind/m_gdbserver/server.c
coregrind/m_main.c
coregrind/m_syswrap/syswrap-generic.c
coregrind/pub_core_syswrap.h
docs/xml/manual-core-adv.xml
docs/xml/manual-core.xml
gdbserver_tests/mchelp.stdoutB.exp
gdbserver_tests/mssnapshot.stderrB.exp

diff --git a/NEWS b/NEWS
index 33d550b76ea9522ec6d8a8594546ead26d3efbbb..36121a2ddd9095f1612a8f66b1fd53c8c26f9a68 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,9 @@ Release 3.9.0 (?? ?????? 201?)
 
 * ==================== OTHER CHANGES ====================
 
+  - Addition of GDB server monitor command 'v.info open_fds' that gives the
+    list of open file descriptors and additional details.
+
 * ==================== FIXED BUGS ====================
 
 The following bugs have been fixed or resolved.  Note that "n-i-bz"
@@ -34,6 +37,7 @@ m = merged into 3_8_BRANCH
 307155    [390] filter_gdb should filter out syscall-template.S T_PSEUDO
 308321    [390] testsuite memcheck filter interferes with gdb_filter 
 308341    [390] vgdb should report process exit (or fatal signal)
+308644    [390] vgdb command for having the info for the track-fds option
 n-i-bz    [390] report error for vgdb snapshot requested before execution
 n-i-bz    [390] Some wrong command line options could be ignored
 
index ef18d7708507bf78667c0f73fdcb2a4c9dad5f31..64db90d6873d287bc11e290265be9ad614077fbe 100644 (file)
@@ -160,11 +160,12 @@ int handle_gdb_valgrind_command (char* mon, OutputSink* sink_wanted_at_return)
 
       VG_(gdb_printf) (
 "general valgrind monitor commands:\n"
-"  help [debug]             : monitor command help. With debug: + debugging commands\n"
+"  help [debug]            : monitor command help. With debug: + debugging commands\n"
 "  v.wait [<ms>]           : sleep <ms> (default 0) then continue\n"
 "  v.info all_errors       : show all errors found so far\n"
 "  v.info last_error       : show last error found\n"
 "  v.info n_errs_found     : show the nr of errors found so far\n"
+"  v.info open_fds         : show open file descriptors (only if --track-fds=yes)\n"
 "  v.kill                  : kill the Valgrind process\n"
 "  v.set gdb_output        : set valgrind output to gdb\n"
 "  v.set log_output        : set valgrind output to log\n"
@@ -239,7 +240,7 @@ int handle_gdb_valgrind_command (char* mon, OutputSink* sink_wanted_at_return)
       wcmd = strtok_r (NULL, " ", &ssaveptr);
       switch (kwdid = VG_(keyword_id) 
               ("all_errors n_errs_found last_error gdbserver_status memory"
-               " scheduler",
+               " scheduler open_fds",
                wcmd, kwd_report_all)) {
       case -2:
       case -1: 
@@ -282,6 +283,15 @@ int handle_gdb_valgrind_command (char* mon, OutputSink* sink_wanted_at_return)
          VG_(show_sched_status) ();
          ret = 1;
          break;
+      case  6: /* open_fds */
+         if (VG_(clo_track_fds))
+            VG_(show_open_fds) ("");
+         else
+            VG_(gdb_printf)
+               ("Valgrind must be started with --track-fds=yes"
+                " to show open fds\n");
+         ret = 1;
+         break;
       default:
          vg_assert(0);
       }
index 8e0b9d3d50f9a02359874e9f3cfa41bf5054fef1..9496428a8f47e79535bb09d7d6af35e07bfdadea 100644 (file)
@@ -2491,7 +2491,7 @@ void shutdown_actions_NORETURN( ThreadId tid,
 
    /* Print out file descriptor summary and stats. */
    if (VG_(clo_track_fds))
-      VG_(show_open_fds)();
+      VG_(show_open_fds)("at exit");
 
    /* Call the tool's finalisation function.  This makes Memcheck's
       leak checker run, and possibly chuck a bunch of leak errors into
index eb27b87f6af5965ad71c688b1c1c344336ebe01c..3d45a30c9c42a38d8c0ef320c3435a0f5c99030d 100644 (file)
@@ -691,11 +691,11 @@ getsockdetails(Int fd)
 
 
 /* Dump out a summary, and a more detailed list, of open file descriptors. */
-void VG_(show_open_fds) (void)
+void VG_(show_open_fds) (HChar* when)
 {
    OpenFd *i = allocated_fds;
 
-   VG_(message)(Vg_UserMsg, "FILE DESCRIPTORS: %d open at exit.\n", fd_count);
+   VG_(message)(Vg_UserMsg, "FILE DESCRIPTORS: %d open %s.\n", fd_count, when);
 
    while (i) {
       if (i->pathname) {
index 04a22dfc9406679a8d23e2da75d9c706d9a4e65f..b3056eb19bd231b0c98ef5424cfa062ec628a060 100644 (file)
@@ -63,7 +63,7 @@ extern void VG_(cleanup_thread) ( ThreadArchState* );
 
 /* fd leakage calls. */
 extern void VG_(init_preopened_fds) ( void );
-extern void VG_(show_open_fds) ( void );
+extern void VG_(show_open_fds) ( HChar* when );
 
 // When the final thread is done, where shall I call to shutdown the
 // system cleanly?  Is set once at startup (in m_main) and never
index f30b7d5f7bd9c7a71078839cf1af8aec72dcd0b0..36eb8bb55a479ce9914a515d4ca75eef40e02eaa 100644 (file)
@@ -1273,6 +1273,13 @@ command (see <xref linkend="manual-core-adv.gdbserver-commandhandling"/>). </par
     value of the <option>--vgdb-error</option> argument.</para>
   </listitem>
 
+  <listitem>
+    <para><varname>v.info open_fds</varname> shows the list of open file
+    descriptors and details related to the file descriptor.
+    This only works if <option>--track-fds=yes</option>
+    was given at Valgrind startup.</para>
+  </listitem>
+
   <listitem>
     <para><varname>v.set {gdb_output | log_output |
     mixed_output}</varname> allows redirection of the Valgrind output
index 96356760c11693eaf493bc77a813a796664a3d01..c39a9f1d1184b417be18434fd2154dff9080ca50 100644 (file)
@@ -773,10 +773,11 @@ in most cases.  We group the available options by rough categories.</para>
     </term>
     <listitem>
       <para>When enabled, Valgrind will print out a list of open file
-      descriptors on exit.  Along with each file descriptor is printed a
-      stack backtrace of where the file was opened and any details
-      relating to the file descriptor such as the file name or socket
-      details.</para>
+      descriptors on exit or on request, via the gdbserver monitor
+      command <varname>v.info open_fds</varname>.  Along with each
+      file descriptor is printed a stack backtrace of where the file
+      was opened and any details relating to the file descriptor such
+      as the file name or socket details.</para>
     </listitem>
   </varlistentry>
 
index 44070dfcd621778e176354e9b619dbef9ac290ec..24b27c86dc0d962bbf68ad86b3d85ee535d30865 100644 (file)
@@ -1,9 +1,10 @@
 general valgrind monitor commands:
-  help [debug]             : monitor command help. With debug: + debugging commands
+  help [debug]            : monitor command help. With debug: + debugging commands
   v.wait [<ms>]           : sleep <ms> (default 0) then continue
   v.info all_errors       : show all errors found so far
   v.info last_error       : show last error found
   v.info n_errs_found     : show the nr of errors found so far
+  v.info open_fds         : show open file descriptors (only if --track-fds=yes)
   v.kill                  : kill the Valgrind process
   v.set gdb_output        : set valgrind output to gdb
   v.set log_output        : set valgrind output to log
@@ -36,11 +37,12 @@ memcheck monitor commands:
          with len > 1, will also show "interior pointers")
 
 general valgrind monitor commands:
-  help [debug]             : monitor command help. With debug: + debugging commands
+  help [debug]            : monitor command help. With debug: + debugging commands
   v.wait [<ms>]           : sleep <ms> (default 0) then continue
   v.info all_errors       : show all errors found so far
   v.info last_error       : show last error found
   v.info n_errs_found     : show the nr of errors found so far
+  v.info open_fds         : show open file descriptors (only if --track-fds=yes)
   v.kill                  : kill the Valgrind process
   v.set gdb_output        : set valgrind output to gdb
   v.set log_output        : set valgrind output to log
index 12a029200086aa829f9c1dc00a23f00336aeafc0..451d62206157ca263e39d7d87bd336c457f8dd9d 100644 (file)
@@ -1,11 +1,12 @@
 relaying data between gdb and process ....
 vgdb-error value changed from 0 to 999999
 general valgrind monitor commands:
-  help [debug]             : monitor command help. With debug: + debugging commands
+  help [debug]            : monitor command help. With debug: + debugging commands
   v.wait [<ms>]           : sleep <ms> (default 0) then continue
   v.info all_errors       : show all errors found so far
   v.info last_error       : show last error found
   v.info n_errs_found     : show the nr of errors found so far
+  v.info open_fds         : show open file descriptors (only if --track-fds=yes)
   v.kill                  : kill the Valgrind process
   v.set gdb_output        : set valgrind output to gdb
   v.set log_output        : set valgrind output to log