/none/tests/track-fds-exec-children
/none/tests/track_new
/none/tests/track_std
+/none/tests/track_bad
/none/tests/unit_debuglog
/none/tests/use_after_close
/none/tests/valgrind_cpp_test
are not entered into bugzilla tend to get forgotten about or ignored.
338803 Handling of dwz debug alt files or cross-CU is broken
+493434 Add --track-fds=bad mode (no "leak" tracking)
503098 Incorrect NAN-boxing for float registers in RISC-V
503641 close_range syscalls started failing with 3.25.0
503677 duplicated-cond compiler warning in dis_RV64M
" --vgdb-stop-at=event1,event2,... invoke gdbserver for given events [none]\n"
" where event is one of:\n"
" startup exit abexit valgrindabexit all none\n"
-" --track-fds=no|yes|all track open file descriptors? [no]\n"
-" all includes reporting inherited file descriptors\n"
+" --track-fds=no|yes|all|bad track open file descriptors? [no]\n"
+" all also reports on open inherited file\n"
+" descriptors at exit (e.g. stdin/out/err)\n"
+" bad only reports on file descriptor usage\n"
+" errors and doesn't list open file descriptors\n"
+" at exit\n"
" --modify-fds=no|yes|high modify newly open file descriptors? [no]\n"
" --time-stamp=no|yes add timestamps to log messages? [no]\n"
" --log-fd=<number> log messages to file descriptor [2=stderr]\n"
VG_(clo_track_fds) = 2;
else if (VG_(strcmp)(tmp_str, "no") == 0)
VG_(clo_track_fds) = 0;
+ else if (VG_(strcmp)(tmp_str, "bad") == 0)
+ VG_(clo_track_fds) = 3;
else
VG_(fmsg_bad_option)(arg,
"Bad argument, should be 'yes', 'all' or 'no'\n");
}
/* Print out file descriptor summary and stats. */
- if (VG_(clo_track_fds))
+ if (VG_(clo_track_fds) && VG_(clo_track_fds) < 3)
VG_(show_open_fds)("at exit");
/* Call the tool's finalisation function. This makes Memcheck's
<varlistentry id="opt.track-fds" xreflabel="--track-fds">
<term>
- <option><![CDATA[--track-fds=<yes|no|all> [default: no] ]]></option>
- </term>
- <listitem>
- <para>When enabled, Valgrind will print out a list of open file
- 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. Use <option>all</option> to
- include reporting on <computeroutput>stdin</computeroutput>,
+ <option><![CDATA[--track-fds=<yes|no|all|bad> [default: no] ]]></option>
+ </term>
+ <listitem>
+ <para>When enabled, Valgrind will track all file descriptor
+ usage. It will produce errors for bad file descriptor usage like
+ closing a file descriptor twice, using a file descriptor
+ (number) that was never created, or passing an already closed
+ file descriptor to a system call. It will also print out a list
+ of open file descriptors on exit. Or on request, via the
+ gdbserver monitor command <varname>v.info open_fds</varname>.</para>
+
+ <para>When an error is generated, or when listing the still open
+ file descriptors at exit, a stack backtrace of where the file
+ was opened is printed. If the file descriptor has already been
+ closed, it will also include a backtrace of where it was
+ previously closed. Any error will include details relating to
+ the file descriptor such as the file name or socket details.</para>
+
+ <para>Use <option>all</option> to also include reporting
+ on <computeroutput>stdin</computeroutput>,
<computeroutput>stdout</computeroutput> and
- <computeroutput>stderr</computeroutput>.</para>
+ <computeroutput>stderr</computeroutput> (or other inherited file
+ descriptors) at exit. If <option>bad</option> option is used,
+ then exclude reporting on leaked file descriptors at exit and
+ only produce errors about bad file decriptors usage.</para>
</listitem>
</varlistentry>
track_new.stderr.exp track_new.stdout.exp \
track_new.vgtest track_new.stderr.exp-illumos \
track_yes.vgtest track_high.vgtest \
- track_yes.stderr.exp track_high.stderr.exp
+ track_yes.stderr.exp track_high.stderr.exp \
+ track_bad.vgtest track_bad.stderr.exp
check_PROGRAMS = \
args \
fdbaduse \
use_after_close \
track_new \
- track_std
+ track_std \
+ track_bad
if HAVE_STATIC_LIBC
if ! VGCONF_OS_IS_LINUX
--vgdb-stop-at=event1,event2,... invoke gdbserver for given events [none]
where event is one of:
startup exit abexit valgrindabexit all none
- --track-fds=no|yes|all track open file descriptors? [no]
- all includes reporting inherited file descriptors
+ --track-fds=no|yes|all|bad track open file descriptors? [no]
+ all also reports on open inherited file
+ descriptors at exit (e.g. stdin/out/err)
+ bad only reports on file descriptor usage
+ errors and doesn't list open file descriptors
+ at exit
--modify-fds=no|yes|high modify newly open file descriptors? [no]
--time-stamp=no|yes add timestamps to log messages? [no]
--log-fd=<number> log messages to file descriptor [2=stderr]
--vgdb-stop-at=event1,event2,... invoke gdbserver for given events [none]
where event is one of:
startup exit abexit valgrindabexit all none
- --track-fds=no|yes|all track open file descriptors? [no]
- all includes reporting inherited file descriptors
+ --track-fds=no|yes|all|bad track open file descriptors? [no]
+ all also reports on open inherited file
+ descriptors at exit (e.g. stdin/out/err)
+ bad only reports on file descriptor usage
+ errors and doesn't list open file descriptors
+ at exit
--modify-fds=no|yes|high modify newly open file descriptors? [no]
--time-stamp=no|yes add timestamps to log messages? [no]
--log-fd=<number> log messages to file descriptor [2=stderr]
--vgdb-stop-at=event1,event2,... invoke gdbserver for given events [none]
where event is one of:
startup exit abexit valgrindabexit all none
- --track-fds=no|yes|all track open file descriptors? [no]
- all includes reporting inherited file descriptors
+ --track-fds=no|yes|all|bad track open file descriptors? [no]
+ all also reports on open inherited file
+ descriptors at exit (e.g. stdin/out/err)
+ bad only reports on file descriptor usage
+ errors and doesn't list open file descriptors
+ at exit
--modify-fds=no|yes|high modify newly open file descriptors? [no]
--time-stamp=no|yes add timestamps to log messages? [no]
--log-fd=<number> log messages to file descriptor [2=stderr]
--vgdb-stop-at=event1,event2,... invoke gdbserver for given events [none]
where event is one of:
startup exit abexit valgrindabexit all none
- --track-fds=no|yes|all track open file descriptors? [no]
+ --track-fds=no|yes|all|bad track open file descriptors? [no]
all includes reporting inherited file descriptors
--modify-fds=no|yes|high modify newly open file descriptors? [no]
--time-stamp=no|yes add timestamps to log messages? [no]
--- /dev/null
+#include<stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include "fdleak.h"
+
+int main(void)
+{
+ char *string = "bad\n";
+ int fd = dup(2);
+
+ /* OK. */
+ write(fd, string, 4);
+ close(fd);
+
+ /* Already closed. */
+ write(fd, string, 4);
+
+ /* Never created. */
+ write(7, string, 4);
+
+ /* Invalid. */
+ write(-7, string, 4);
+
+ /* Double double close. */
+ close(fd);
+
+ /* Invalid close. */
+ close (-7);
+
+ (void) DO( open("/dev/null", O_RDONLY) );
+
+ return 0;
+}
--- /dev/null
+bad
+File descriptor was closed already
+ at 0x........: write (in /...libc...)
+ by 0x........: main
+ Previously closed
+ at 0x........: close (in /...libc...)
+ by 0x........: main
+ Originally opened
+ at 0x........: dup (in /...libc...)
+ by 0x........: main
+File descriptor 7 was never created
+ at 0x........: write (in /...libc...)
+ by 0x........: main
+File descriptor -7 Invalid file descriptor
+ at 0x........: write (in /...libc...)
+ by 0x........: main
+File descriptor ...: ... is already closed
+ at 0x........: close (in /...libc...)
+ by 0x........: main
+ Previously closed
+ at 0x........: close (in /...libc...)
+ by 0x........: main
+ Originally opened
+ at 0x........: dup (in /...libc...)
+ by 0x........: main
+File descriptor -7 Invalid file descriptor
+ at 0x........: close (in /...libc...)
+ by 0x........: main
--- /dev/null
+prog: track_bad
+vgopts: -q --track-fds=bad
+stderr_filter: filter_fdleak