Skip to content

Commit cb1e8ac

Browse files
Bug 1386760 - Add a crash annotation containing the last executable we launched r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D12643 --HG-- extra : moz-landing-system : lando
1 parent 5d300fd commit cb1e8ac

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

toolkit/crashreporter/CrashAnnotations.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ EventLoopNestingLevel:
268268
type: integer
269269
ping: true
270270

271+
ExecutableName:
272+
description: >
273+
The name of the last executable that was launched via the nsIProcess class.
274+
Multiple executables can be launched at the same time from one or more
275+
threads so this annotation might not always contain the correct value. To
276+
be removed once bug 1386760 is fixed.
277+
type: string
278+
271279
ExpectedStreamLen:
272280
description: >
273281
Expected length of an IPC proxy stream.

xpcom/threads/nsProcess.h

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class nsProcess final : public nsIProcess, public nsIObserver {
4646
private:
4747
~nsProcess();
4848
static void Monitor(void* aArg);
49+
static void RemoveExecutableCrashAnnotation();
4950
void ProcessComplete();
5051
nsresult CopyArgsAndRunProcess(bool aBlocking, const char** aArgs,
5152
uint32_t aCount, nsIObserver* aObserver,
@@ -56,6 +57,7 @@ class nsProcess final : public nsIProcess, public nsIObserver {
5657
// The 'args' array is null-terminated.
5758
nsresult RunProcess(bool aBlocking, char** aArgs, nsIObserver* aObserver,
5859
bool aHoldWeak, bool aArgsUTF8);
60+
void AddExecutableCrashAnnotation();
5961

6062
PRThread* mThread;
6163
mozilla::Mutex mLock;

xpcom/threads/nsProcessCommon.cpp

+36-14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "mozilla/ArrayUtils.h"
1616

1717
#include "nsCOMPtr.h"
18+
#include "nsExceptionHandler.h"
1819
#include "nsAutoPtr.h"
1920
#include "nsMemory.h"
2021
#include "nsProcess.h"
@@ -245,19 +246,7 @@ void nsProcess::Monitor(void* aArg) {
245246
exitCode = -1;
246247
}
247248
}
248-
249-
// Lock in case Kill or GetExitCode are called during this
250-
{
251-
MutexAutoLock lock(process->mLock);
252-
CloseHandle(process->mProcess);
253-
process->mProcess = nullptr;
254-
process->mExitValue = exitCode;
255-
if (process->mShutdown) {
256-
return;
257-
}
258-
}
259-
#else
260-
#ifdef XP_UNIX
249+
#elif defined(XP_UNIX)
261250
int exitCode = -1;
262251
int status = 0;
263252
pid_t result;
@@ -278,9 +267,15 @@ void nsProcess::Monitor(void* aArg) {
278267
}
279268
#endif
280269

270+
// The application has finished executing once we reach this point
271+
RemoveExecutableCrashAnnotation();
272+
281273
// Lock in case Kill or GetExitCode are called during this
282274
{
283275
MutexAutoLock lock(process->mLock);
276+
#if defined(PROCESSMODEL_WINAPI)
277+
CloseHandle(process->mProcess);
278+
#endif
284279
#if !defined(XP_UNIX)
285280
process->mProcess = nullptr;
286281
#endif
@@ -289,7 +284,6 @@ void nsProcess::Monitor(void* aArg) {
289284
return;
290285
}
291286
}
292-
#endif
293287

294288
// If we ran a background thread for the monitor then notify on the main
295289
// thread
@@ -547,6 +541,8 @@ nsresult nsProcess::RunProcess(bool aBlocking, char** aMyArgv,
547541
mPid = ptrProc->pid;
548542
#endif
549543

544+
AddExecutableCrashAnnotation();
545+
550546
NS_ADDREF_THIS();
551547
mBlocking = aBlocking;
552548
if (aBlocking) {
@@ -584,6 +580,32 @@ nsProcess::GetIsRunning(bool* aIsRunning) {
584580
return NS_OK;
585581
}
586582

583+
void nsProcess::AddExecutableCrashAnnotation() {
584+
#if defined(XP_WIN)
585+
nsAutoCString executableName;
586+
if (NS_FAILED(mExecutable->GetNativeLeafName(executableName))) {
587+
return;
588+
}
589+
590+
// The following executables might be launched during shutdown and lead to a
591+
// shutdown hang. We're adding this annotation to try and detect which is the
592+
// culprit of bug 1386760
593+
if (executableName.EqualsLiteral("minidump-analyzer.exe") ||
594+
executableName.EqualsLiteral("pingsender.exe") ||
595+
executableName.EqualsLiteral("updater.exe")) {
596+
CrashReporter::AnnotateCrashReport(
597+
CrashReporter::Annotation::ExecutableName, executableName.get());
598+
}
599+
#endif // defined(XP_WIN)
600+
}
601+
602+
/* static */ void nsProcess::RemoveExecutableCrashAnnotation() {
603+
#if defined(XP_WIN)
604+
CrashReporter::RemoveCrashReportAnnotation(
605+
CrashReporter::Annotation::ExecutableName);
606+
#endif // defined(XP_WIN)
607+
}
608+
587609
NS_IMETHODIMP
588610
nsProcess::GetStartHidden(bool* aStartHidden) {
589611
*aStartHidden = mStartHidden;

0 commit comments

Comments
 (0)