Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Static Public Member Functions | Static Private Attributes | List of all members
Athena::DebugAids Class Reference

Utilities for debugging support. More...

#include <SealDebug.h>

Collaboration diagram for Athena::DebugAids:

Static Public Member Functions

static IOFD stacktraceFd (IOFD fd=IOFD_INVALID)
 Set and return the file descriptor for stack trace output. More...
 
static void stacktrace ATLAS_NOT_THREAD_SAFE (IOFD fd=IOFD_INVALID)
 
static void coredump (int sig,...)
 Drop a core dump and continue. More...
 
static void stacktraceLine ATLAS_NOT_THREAD_SAFE (IOFD fd, unsigned long addr)
 
static void setStackTraceAddr2Line ATLAS_NOT_THREAD_SAFE (const char *path)
 
static unsigned long enableCoreFiles ()
 Try to enable core dump files by raising the soft size limit to the hard limit. More...
 
static void disableCoreFiles ()
 Disable core dump files by setting the soft limit to 0. More...
 

Static Private Attributes

static std::atomic< IOFDs_stackTraceFd = IOFD_INVALID
 The default output file descriptor for #stacktrace(). More...
 

Detailed Description

Utilities for debugging support.


Definition at line 72 of file SealDebug.h.

Member Function Documentation

◆ ATLAS_NOT_THREAD_SAFE() [1/3]

static void setStackTraceAddr2Line Athena::DebugAids::ATLAS_NOT_THREAD_SAFE ( const char *  path)
static

◆ ATLAS_NOT_THREAD_SAFE() [2/3]

static void stacktraceLine Athena::DebugAids::ATLAS_NOT_THREAD_SAFE ( IOFD  fd,
unsigned long  addr 
)
static

◆ ATLAS_NOT_THREAD_SAFE() [3/3]

static void stacktrace Athena::DebugAids::ATLAS_NOT_THREAD_SAFE ( IOFD  fd = IOFD_INVALID)
static

◆ coredump()

void Athena::DebugAids::coredump ( int  sig,
  ... 
)
static

Drop a core dump and continue.

Creates a core file for the current program state and continues execution. sig should be the number of the signal from which the program should appear to have died; this should a fatal signal that does cause a core file to be created (or SIGUSR1).

This works by forking the process and then killing the child with the given signal; the signal is automatically unblocked in the child to make sure the sure the signal is delivered. Thus the function returns only once, in the parent process.

This function can be safely installed directly as a signal handler. #Signal::handleFatal() will do so for SIGUSR1 with suitable options.

Note that this function does not change core dump resource limits, not even for the forked child process. If core files are disabled through resource limits, no core file will be created despite your explicit request to create one.

This concept was taken from DDD, the Data Display Debugger.

Definition at line 970 of file SealDebug.cxx.

971 {
972 #ifndef _WIN32
973  // FIXME: Forking vs. threads -- need to sort out what is safe.
974  // FIXME: Provide a resource limits interface so that core
975  // resource limits can be raised?
976 
977  pid_t corepid;
978  int status;
979 
980  ::unlink ("core");
981  if ((corepid = ::fork ()) == 0)
982  {
983  // In child: re-raise the signal, thus killing the process and
984  // producing a core dump. Make sure 1) the signal is not
985  // blocked so that we won't return to the caller, 2) we have a
986  // signal that is fatal, 3) the signal falls to its default
987  // handler to produce the dump.
988 
989 #ifdef SIGUSR1
990  // SIGUSR1 does not cause a core dump; use abort() instead
991  if (sig == SIGUSR1)
992  sig = SIGABRT; // Could be SIGIOT if SIGABRT is not defined
993 #endif
994  Signal::handle (sig, (Signal::HandlerType) (void*)SIG_DFL);
995  Signal::block (sig, false);
996  Signal::raise (sig);
997 
998  // Yikes, this shouldn't happen. ASSERT isn't right here. If
999  // raise() failed to deliver the signal, abort() is unlikely
1000  // to work any better, but try it anyway. Then make sure we
1001  // die so that we won't return to the caller from the child.
1002  abort ();
1003  // cppcheck-suppress unreachableCode
1004  _exit (255);
1005  }
1006  else if (corepid > 0) {
1007  pid_t wait_pid;
1008  do {
1009  wait_pid = ::waitpid (corepid, &status, 0);
1010  } while (wait_pid == -1 && errno == EINTR);
1011  }
1012 #endif // !_WIN32
1013 }

◆ disableCoreFiles()

void Athena::DebugAids::disableCoreFiles ( )
static

Disable core dump files by setting the soft limit to 0.

This is equivalent to ulimit -Sc 0 in bash.

Definition at line 1046 of file SealDebug.cxx.

1047 {
1048  struct rlimit core_limit;
1049  core_limit.rlim_cur = 0;
1050  setrlimit(RLIMIT_CORE, &core_limit);
1051 }

◆ enableCoreFiles()

unsigned long Athena::DebugAids::enableCoreFiles ( )
static

Try to enable core dump files by raising the soft size limit to the hard limit.

There might be other reason though why the system does not produce core files, so this is only one of the prerequisites.

Returns the currently valid soft size limit.

This is equivalent to using ulimit -Sc in bash.

Definition at line 1026 of file SealDebug.cxx.

1027 {
1028  struct rlimit core_limit;
1029  getrlimit(RLIMIT_CORE, &core_limit);
1030 
1031  unsigned long old_limit = core_limit.rlim_cur;
1032  core_limit.rlim_cur = core_limit.rlim_max;
1033  if ( setrlimit(RLIMIT_CORE, &core_limit) == 0 ) {
1034  return core_limit.rlim_cur;
1035  }
1036  else {
1037  return old_limit;
1038  }
1039 }

◆ stacktraceFd()

IOFD Athena::DebugAids::stacktraceFd ( IOFD  fd = IOFD_INVALID)
static

Set and return the file descriptor for stack trace output.

If fd is the default invalid descriptor value, returns the current value without changing the setting. This value is only effective for #stacktrace(), but can be overridden by the argument given to that function.

Definition at line 603 of file SealDebug.cxx.

604 {
606  if (fd == IOFD_INVALID) {
607  if (old == IOFD_INVALID) {
608  s_stackTraceFd.compare_exchange_strong (old, STDERR_HANDLE);
609  return s_stackTraceFd;
610  }
611  }
612  else {
613  s_stackTraceFd.compare_exchange_strong (old, fd);
614  }
615  return old;
616 }

Member Data Documentation

◆ s_stackTraceFd

std::atomic< IOFD > Athena::DebugAids::s_stackTraceFd = IOFD_INVALID
staticprivate

The default output file descriptor for #stacktrace().


Definition at line 88 of file SealDebug.h.


The documentation for this class was generated from the following files:
pid_t
int32_t pid_t
Definition: FPGATrackSimTypes.h:19
Athena::Signal::raise
static int raise(int sig)
Raise the signal number sig.
Definition: SealSignal.cxx:377
IOFD
int IOFD
Type the system uses for channel descriptors.
Definition: SealCommon.h:27
python.BuildSignatureFlags.sig
sig
Definition: BuildSignatureFlags.py:219
Athena::Signal::HandlerType
void(* HandlerType)(int sig, siginfo_t *info, void *extra)
Signal handler type.
Definition: SealSignal.h:196
ReadFromCoolCompare.fd
fd
Definition: ReadFromCoolCompare.py:196
IOFD_INVALID
#define IOFD_INVALID
Invalid channel descriptor constant.
Definition: SealCommon.h:20
Athena::Signal::block
static void block(int sig, bool sense)
Block or unblock the signal number sig.
Definition: SealSignal.cxx:338
STDERR_HANDLE
#define STDERR_HANDLE
Definition: SealDebug.cxx:83
CSV_InDetExporter.old
old
Definition: CSV_InDetExporter.py:145
Athena::Signal::handle
static HandlerType handle(int sig, HandlerType handler, const sigset_t *blockMask=0)
Install a new signal handler handler for signal number sig and returns the old handler.
Definition: SealSignal.cxx:277
merge.status
status
Definition: merge.py:17
Athena::DebugAids::s_stackTraceFd
static std::atomic< IOFD > s_stackTraceFd
The default output file descriptor for #stacktrace().
Definition: SealDebug.h:88