/*--- Helper fns ---*/
/*------------------------------------------------------------*/
-// Only show core errors if the tool wants to, we're not running with -q,
+// Only show core warnings if the tool wants to, we're not running with -q,
// and were not outputting XML.
-Bool VG_(showing_core_errors)(void)
+Bool VG_(showing_core_warnings)(void)
{
return VG_(needs).core_errors && VG_(clo_verbosity) >= 1 && !VG_(clo_xml);
}
static Bool is_fd_core_error (const Error *e)
{
- return e->ekind == FdBadClose || e->ekind == FdNotClosed;
+ return e->ekind == FdBadClose || e->ekind == FdNotClosed ||
+ e->ekind == FdBadUse;
}
static Bool core_eq_Error (VgRes res, const Error *e1, const Error *e2)
return "FdBadClose";
case FdNotClosed:
return "FdNotClosed";
+ case FdBadUse:
+ return "FdBadUse";
default:
VG_(umsg)("FATAL: unknown core error kind: %d\n", err->ekind );
VG_(exit)(1);
return err->ekind == FdBadClose;
case FdNotClosedSupp:
return err->ekind == FdNotClosed;
+ case FdBadUse:
+ return err->ekind == FdBadUse;
default:
VG_(umsg)("FATAL: unknown core suppression kind: %d\n", su->skind );
VG_(exit)(1);
return VG_(mk_SysRes_Success)( 0 );
bad_signo:
- if (VG_(showing_core_errors)() && !VG_(clo_xml)) {
+ if (VG_(showing_core_warnings)()) {
VG_(umsg)("Warning: bad signal number %d in sigaction()\n", signo);
}
return VG_(mk_SysRes_Error)( VKI_EINVAL );
bad_signo_reserved:
- if (VG_(showing_core_errors)() && !VG_(clo_xml)) {
+ if (VG_(showing_core_warnings)()) {
VG_(umsg)("Warning: ignored attempt to set %s handler in sigaction();\n",
VG_(signame)(signo));
VG_(umsg)(" the %s signal is used internally by Valgrind\n",
return VG_(mk_SysRes_Error)( VKI_EINVAL );
bad_sigkill_or_sigstop:
- if (VG_(showing_core_errors)() && !VG_(clo_xml)) {
+ if (VG_(showing_core_warnings)()) {
VG_(umsg)("Warning: ignored attempt to set %s handler in sigaction();\n",
VG_(signame)(signo));
VG_(umsg)(" the %s signal is uncatchable\n",
ExeContext *where_opened; /* recordwhere the fd was opened */
};
+struct FdBadUse {
+ Int fd; /* The file descriptor */
+};
+
struct NotClosedExtra {
Int fd;
HChar *pathname;
}
VG_(emit)("%sFile descriptor %d: %s is already closed%s\n",
whatpre, bce->fd, bce->description, whatpost);
- VG_(pp_ExeContext)( VG_(get_error_where)(err) );
+ VG_(pp_ExeContext)( where );
VG_(emit)("%sPreviously closed%s\n", auxpre, auxpost);
VG_(pp_ExeContext)(bce->where_closed);
VG_(emit)("%sOriginally opened%s\n", auxpre, auxpost);
VG_(message)(Vg_UserMsg, " <inherited from parent>\n");
VG_(message)(Vg_UserMsg, "\n");
}
+ } else if (VG_(get_error_kind)(err) == FdBadUse) {
+ if (xml) VG_(emit)(" <kind>FdBadUse</kind>\n");
+ struct FdBadUse *nce = (struct FdBadUse *)
+ VG_(get_error_extra)(err);
+ if (xml) VG_(emit)(" <fd>%d</fd>\n", nce->fd);
+ VG_(emit)("%sInvalid file descriptor %d%s\n", whatpre, nce->fd, whatpost);
+ VG_(pp_ExeContext)(where);
} else {
vg_assert2 (False, "Unknown error kind: %d",
VG_(get_error_kind)(err));
return sizeof (struct BadCloseExtra);
else if (VG_(get_error_kind)(err) == FdNotClosed)
return sizeof (struct NotClosedExtra);
+ else if (VG_(get_error_kind)(err) == FdBadUse)
+ return sizeof (struct FdBadUse);
else {
vg_assert2 (False, "Unknown error kind: %d",
VG_(get_error_kind)(err));
client is exactly what we don't want. */
/* croak? */
- if ((!allowed) && VG_(showing_core_errors)() ) {
- VG_(message)(Vg_UserMsg,
- "Warning: invalid file descriptor %d in syscall %s()\n",
- fd, syscallname);
- if (fd == VG_(log_output_sink).fd && VG_(log_output_sink).fd >= 0)
- VG_(message)(Vg_UserMsg,
+ if ((!allowed) && !isNewFd) {
+ // XXX FdBadUse might want to add more info if we are going to include
+ // already closed file descriptors, then we do have a bit more info
+ if (VG_(clo_track_fds)) {
+ struct FdBadUse badfd;
+ badfd.fd = fd;
+ VG_(maybe_record_error)(tid, FdBadUse, 0,
+ "invalid file descriptor", &badfd);
+ } else if (VG_(showing_core_warnings) ()) {
+ // XXX legacy warnings, will be removed eventually
+ VG_(message)(Vg_UserMsg,
+ "Warning: invalid file descriptor %d in syscall %s()\n",
+ fd, syscallname);
+ }
+
+ if (VG_(showing_core_warnings) ()) {
+ if (fd == VG_(log_output_sink).fd && VG_(log_output_sink).fd >= 0)
+ VG_(message)(Vg_UserMsg,
" Use --log-fd=<number> to select an alternative log fd.\n");
- if (fd == VG_(xml_output_sink).fd && VG_(xml_output_sink).fd >= 0)
- VG_(message)(Vg_UserMsg,
+ if (fd == VG_(xml_output_sink).fd && VG_(xml_output_sink).fd >= 0)
+ VG_(message)(Vg_UserMsg,
" Use --xml-fd=<number> to select an alternative XML "
"output fd.\n");
- // DDD: consider always printing this stack trace, it's useful.
- // Also consider also making this a proper core error, ie.
- // suppressible and all that.
- if (VG_(clo_verbosity) > 1) {
- VG_(get_and_pp_StackTrace)(tid, VG_(clo_backtrace_size));
+
+ // XXX This is the legacy warning, will be removed eventually
+ if (VG_(clo_verbosity) > 1 && !VG_(clo_track_fds)) {
+ VG_(get_and_pp_StackTrace)(tid, VG_(clo_backtrace_size));
+ }
}
}