VirtualBox

Changeset 32347 in vbox


Ignore:
Timestamp:
Sep 9, 2010 12:18:38 PM (14 years ago)
Author:
vboxsync
Message:

Runtime/r3/coredumper: Setup SIGUSR2 and flags, allow taking live cores.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/coredumper.h

    r31860 r32347  
    3737 */
    3838
     39/** @name RTCoreDumperSetup flags
     40 * @{ */
     41/** Override system core dumper. */
     42#define RTCOREDUMPER_FLAGS_OVERRIDE_SYS_DUMPER     RT_BIT(0)
     43/** Allow taking live process dumps (without killing process). */
     44#define RTCOREDUMPER_FLAGS_LIVE_CORE               RT_BIT(1)
     45/** @}  */
     46
    3947/**
    4048 * Take a core dump of the current process without terminating it.
     
    4351 * @param   pszOutputFile       Name of the core file.  If NULL use the
    4452 *                              default naming scheme.
     53 * @param   fLiveCore           When true, the process is not killed after
     54 *                              taking a core. Otherwise it will be killed. This
     55 *                              works in conjuction with the flags set during
     56 *                              RTCoreDumperSetup().
    4557 */
    46 RTDECL(int) RTCoreDumperTakeDump(const char *pszOutputFile);
     58RTDECL(int) RTCoreDumperTakeDump(const char *pszOutputFile, bool fLiveCore);
    4759
    4860/**
     
    6173 * @param   pszBaseName         Base file name, no directory.  If NULL the
    6274 *                              dumper will generate an appropriate name.
    63  * @param   fFlags              Reserved for later, MBZ.
     75 * @param   fFlags              Setup flags, see RTCOREDUMPER_FLAGS_*.
    6476 */
    6577RTDECL(int) RTCoreDumperSetup(const char *pszOutputDir, uint32_t fFlags);
  • trunk/src/VBox/Runtime/r3/solaris/coredumper-solaris.cpp

    r32235 r32347  
    4545# include <syslog.h>
    4646# include <signal.h>
     47# include <stdlib.h>
    4748# include <unistd.h>
    4849# include <errno.h>
     
    6465volatile static bool       g_fCoreDumpDeliberate = false;
    6566volatile static bool       g_fCoreDumpInProgress = false;
     67volatile static bool       g_fCoreDumpLiveCore = false;
    6668volatile static uint32_t   g_fCoreDumpFlags = 0;
    6769static char                g_szCoreDumpDir[PATH_MAX] = { 0 };
     
    21352137
    21362138        if (RT_FAILURE(rc))
    2137         {
    2138             /*
    2139              * If it is NOT a deliberate dump taken by us & our handler fails we assume the
    2140              * worst, try to use the system signal handler and abort the process.
    2141              */
    21422139            CORELOGRELSYS((CORELOG_NAME "TakeDump failed! rc=%Rrc\n", rc));
    2143             if (ASMAtomicReadBool(&g_fCoreDumpDeliberate) == false)
    2144                 fCallSystemDump = true;
    2145         }
    21462140    }
    21472141    else
    21482142    {
    21492143        /*
    2150          * Core dumping is already in  progress and we've somehow ended up being
     2144         * Core dumping is already in progress and we've somehow ended up being
    21512145         * signalled again.
    21522146         */
     
    21632157            CORELOGRELSYS((CORELOG_NAME "SignalHandler: Core dump already in progress! Waiting before signalling Sig=%d.\n", Sig));
    21642158            int64_t iTimeout = 10000;  /* timeout (ms) */
    2165             while (ASMAtomicUoReadBool(&g_fCoreDumpInProgress) == true)
     2159            while (ASMAtomicReadBool(&g_fCoreDumpInProgress) == true)
    21662160            {
    21672161                RTThreadSleep(200);
     
    21782172    }
    21792173
    2180     if (fCallSystemDump)
    2181     {
    2182         signal(Sig, SIG_DFL);
    2183         raise(Sig);
     2174    if (ASMAtomicReadBool(&g_fCoreDumpLiveCore) == false)
     2175    {
     2176        /*
     2177         * Reset signal handlers, we're not a live core we will be blown away
     2178         * one way or another.
     2179         */
     2180        signal(SIGSEGV, SIG_DFL);
     2181        signal(SIGBUS, SIG_DFL);
     2182
     2183        /*
     2184         * Hard terminate the process if this is not a live dump without invoking
     2185         * the system core dumping behaviour.
     2186         */
     2187        if (RT_SUCCESS(rc))
     2188            raise(SIGKILL);
     2189
     2190        /*
     2191         * Something went wrong, fall back to the system core dumper.
     2192         */
     2193        if (fCallSystemDump)
     2194            abort();
    21842195    }
    21852196}
     
    21922203 * @param   pszOutputFile       Name of the core file.  If NULL use the
    21932204 *                              default naming scheme.
    2194  */
    2195 RTDECL(int) RTCoreDumperTakeDump(const char *pszOutputFile)
    2196 {
     2205 * @param   fLiveCore           When true, the process is not killed after
     2206 *                              taking a core. Otherwise it will be killed. This
     2207 *                              works in conjuction with the flags set during
     2208 *                              RTCoreDumperSetup().
     2209 */
     2210RTDECL(int) RTCoreDumperTakeDump(const char *pszOutputFile, bool fLiveCore)
     2211{
     2212    /*
     2213     * Validate input.
     2214     */
    21972215    if (ASMAtomicReadBool(&g_fCoreDumpSignalSetup) == false)
    21982216        return VERR_WRONG_ORDER;
     2217
     2218    uint32_t fFlags = ASMAtomicReadU32(&g_fCoreDumpFlags);
     2219    if (fLiveCore && !(fFlags & RTCOREDUMPER_FLAGS_LIVE_CORE))
     2220        return VERR_INVALID_PARAMETER;
     2221
     2222    if (!fLiveCore && !(fFlags & RTCOREDUMPER_FLAGS_OVERRIDE_SYS_DUMPER))
     2223        return VERR_INVALID_PARAMETER;
    21992224
    22002225    RT_ZERO(g_szCoreDumpFile);
     
    22032228
    22042229    ASMAtomicWriteBool(&g_fCoreDumpDeliberate, true);
    2205     raise(SIGSEGV);
     2230    ASMAtomicWriteBool(&g_fCoreDumpLiveCore, fLiveCore);
     2231
     2232    if (fLiveCore == false)
     2233        raise(SIGSEGV);
     2234    else
     2235    {
     2236        raise(SIGUSR2);
     2237        ASMAtomicWriteBool(&g_fCoreDumpLiveCore, false);
     2238    }
     2239
    22062240    ASMAtomicWriteBool(&g_fCoreDumpDeliberate, false);
    22072241    return VINF_SUCCESS;
     
    22242258 * @param   pszBaseName         Base file name, no directory.  If NULL the
    22252259 *                              dumper will generate an appropriate name.
    2226  * @param   fFlags              Reserved for later, MBZ.
     2260 * @param   fFlags              Setup flags, see RTCOREDUMPER_FLAGS_*.
    22272261 */
    22282262RTDECL(int) RTCoreDumperSetup(const char *pszOutputDir, uint32_t fFlags)
     
    22312265     * Validate flags.
    22322266     */
    2233     AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
     2267    AssertReturn(!(fFlags & ~(  RTCOREDUMPER_FLAGS_OVERRIDE_SYS_DUMPER
     2268                              | RTCOREDUMPER_FLAGS_LIVE_CORE)),
     2269                 VERR_INVALID_PARAMETER);
    22342270
    22352271    /*
     
    22372273     */
    22382274    struct sigaction sigAct;
     2275    RT_ZERO(sigAct);
    22392276    sigAct.sa_sigaction = &rtCoreDumperSignalHandler;
    22402277    sigemptyset(&sigAct.sa_mask);
    22412278    sigAct.sa_flags = SA_RESTART | SA_SIGINFO;
    2242     sigaction(SIGSEGV, &sigAct, NULL);
    2243     sigaction(SIGBUS, &sigAct, NULL);
     2279
     2280    if (fFlags & RTCOREDUMPER_FLAGS_OVERRIDE_SYS_DUMPER)
     2281    {
     2282        sigaction(SIGSEGV, &sigAct, NULL);
     2283        sigaction(SIGBUS, &sigAct, NULL);
     2284    }
     2285
     2286    if (fFlags & RTCOREDUMPER_FLAGS_LIVE_CORE)
     2287        sigaction(SIGUSR2, &sigAct, NULL);
    22442288
    22452289    ASMAtomicWriteBool(&g_fCoreDumpSignalSetup, true);
  • trunk/src/VBox/Runtime/testcase/tstRTCoreDump.cpp

    r31913 r32347  
    5656     * Setup core dumping.
    5757     */
    58     int rc = RTCoreDumperSetup(NULL, 0);
     58    int rc = RTCoreDumperSetup(NULL, RTCOREDUMPER_FLAGS_OVERRIDE_SYS_DUMPER | RTCOREDUMPER_FLAGS_LIVE_CORE);
    5959    if (RT_SUCCESS(rc))
    6060    {
     
    7676        }
    7777        RTPrintf("Spawned %d threads.\n", i);
    78    
     78
    7979        /*
    8080         * Write the core to disk.
    8181         */
    82         rc = RTCoreDumperTakeDump(NULL);
     82        rc = RTCoreDumperTakeDump(NULL, false /* fLiveCore*/);
    8383        if (RT_FAILURE(rc))
    8484        {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette