Changeset 32347 in vbox
- Timestamp:
- Sep 9, 2010 12:18:38 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/coredumper.h
r31860 r32347 37 37 */ 38 38 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 39 47 /** 40 48 * Take a core dump of the current process without terminating it. … … 43 51 * @param pszOutputFile Name of the core file. If NULL use the 44 52 * 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(). 45 57 */ 46 RTDECL(int) RTCoreDumperTakeDump(const char *pszOutputFile );58 RTDECL(int) RTCoreDumperTakeDump(const char *pszOutputFile, bool fLiveCore); 47 59 48 60 /** … … 61 73 * @param pszBaseName Base file name, no directory. If NULL the 62 74 * dumper will generate an appropriate name. 63 * @param fFlags Reserved for later, MBZ.75 * @param fFlags Setup flags, see RTCOREDUMPER_FLAGS_*. 64 76 */ 65 77 RTDECL(int) RTCoreDumperSetup(const char *pszOutputDir, uint32_t fFlags); -
trunk/src/VBox/Runtime/r3/solaris/coredumper-solaris.cpp
r32235 r32347 45 45 # include <syslog.h> 46 46 # include <signal.h> 47 # include <stdlib.h> 47 48 # include <unistd.h> 48 49 # include <errno.h> … … 64 65 volatile static bool g_fCoreDumpDeliberate = false; 65 66 volatile static bool g_fCoreDumpInProgress = false; 67 volatile static bool g_fCoreDumpLiveCore = false; 66 68 volatile static uint32_t g_fCoreDumpFlags = 0; 67 69 static char g_szCoreDumpDir[PATH_MAX] = { 0 }; … … 2135 2137 2136 2138 if (RT_FAILURE(rc)) 2137 {2138 /*2139 * If it is NOT a deliberate dump taken by us & our handler fails we assume the2140 * worst, try to use the system signal handler and abort the process.2141 */2142 2139 CORELOGRELSYS((CORELOG_NAME "TakeDump failed! rc=%Rrc\n", rc)); 2143 if (ASMAtomicReadBool(&g_fCoreDumpDeliberate) == false)2144 fCallSystemDump = true;2145 }2146 2140 } 2147 2141 else 2148 2142 { 2149 2143 /* 2150 * Core dumping is already in 2144 * Core dumping is already in progress and we've somehow ended up being 2151 2145 * signalled again. 2152 2146 */ … … 2163 2157 CORELOGRELSYS((CORELOG_NAME "SignalHandler: Core dump already in progress! Waiting before signalling Sig=%d.\n", Sig)); 2164 2158 int64_t iTimeout = 10000; /* timeout (ms) */ 2165 while (ASMAtomic UoReadBool(&g_fCoreDumpInProgress) == true)2159 while (ASMAtomicReadBool(&g_fCoreDumpInProgress) == true) 2166 2160 { 2167 2161 RTThreadSleep(200); … … 2178 2172 } 2179 2173 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(); 2184 2195 } 2185 2196 } … … 2192 2203 * @param pszOutputFile Name of the core file. If NULL use the 2193 2204 * 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 */ 2210 RTDECL(int) RTCoreDumperTakeDump(const char *pszOutputFile, bool fLiveCore) 2211 { 2212 /* 2213 * Validate input. 2214 */ 2197 2215 if (ASMAtomicReadBool(&g_fCoreDumpSignalSetup) == false) 2198 2216 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; 2199 2224 2200 2225 RT_ZERO(g_szCoreDumpFile); … … 2203 2228 2204 2229 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 2206 2240 ASMAtomicWriteBool(&g_fCoreDumpDeliberate, false); 2207 2241 return VINF_SUCCESS; … … 2224 2258 * @param pszBaseName Base file name, no directory. If NULL the 2225 2259 * dumper will generate an appropriate name. 2226 * @param fFlags Reserved for later, MBZ.2260 * @param fFlags Setup flags, see RTCOREDUMPER_FLAGS_*. 2227 2261 */ 2228 2262 RTDECL(int) RTCoreDumperSetup(const char *pszOutputDir, uint32_t fFlags) … … 2231 2265 * Validate flags. 2232 2266 */ 2233 AssertReturn(!fFlags, VERR_INVALID_PARAMETER); 2267 AssertReturn(!(fFlags & ~( RTCOREDUMPER_FLAGS_OVERRIDE_SYS_DUMPER 2268 | RTCOREDUMPER_FLAGS_LIVE_CORE)), 2269 VERR_INVALID_PARAMETER); 2234 2270 2235 2271 /* … … 2237 2273 */ 2238 2274 struct sigaction sigAct; 2275 RT_ZERO(sigAct); 2239 2276 sigAct.sa_sigaction = &rtCoreDumperSignalHandler; 2240 2277 sigemptyset(&sigAct.sa_mask); 2241 2278 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); 2244 2288 2245 2289 ASMAtomicWriteBool(&g_fCoreDumpSignalSetup, true); -
trunk/src/VBox/Runtime/testcase/tstRTCoreDump.cpp
r31913 r32347 56 56 * Setup core dumping. 57 57 */ 58 int rc = RTCoreDumperSetup(NULL, 0);58 int rc = RTCoreDumperSetup(NULL, RTCOREDUMPER_FLAGS_OVERRIDE_SYS_DUMPER | RTCOREDUMPER_FLAGS_LIVE_CORE); 59 59 if (RT_SUCCESS(rc)) 60 60 { … … 76 76 } 77 77 RTPrintf("Spawned %d threads.\n", i); 78 78 79 79 /* 80 80 * Write the core to disk. 81 81 */ 82 rc = RTCoreDumperTakeDump(NULL );82 rc = RTCoreDumperTakeDump(NULL, false /* fLiveCore*/); 83 83 if (RT_FAILURE(rc)) 84 84 {
Note:
See TracChangeset
for help on using the changeset viewer.