Audacity 3.2.0
Public Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
CrashReportContext Class Reference

This object is for internal usage. More...

#include <CrashReportContext.h>

Public Member Functions

bool SetSenderPathUTF8 (const std::string &path)
 
bool SetReportURL (const std::string &url)
 
bool SetParameters (const std::map< std::string, std::string > &p)
 
void StartHandler (const std::string &databasePath)
 
bool SetSenderPathUTF8 (const std::string &path)
 
bool SetReportURL (const std::string &path)
 
bool SetParameters (const std::map< std::string, std::string > &p)
 
void StartHandler (const std::string &databasePath)
 

Private Attributes

char mSenderPath [MaxBufferLength] {}
 
char mReportURL [MaxBufferLength] {}
 
char mParameters [MaxBufferLength] {}
 
wchar_t mSenderPath [MaxBufferLength] {}
 
wchar_t mReportURL [MaxBufferLength] {}
 
wchar_t mParameters [MaxBufferLength] {}
 
wchar_t mCommand [MaxCommandLength] {}
 

Static Private Attributes

static constexpr size_t MaxBufferLength { 2048 }
 
static constexpr size_t MaxCommandLength { 8192 }
 

Friends

bool SendReport (CrashReportContext *ctx, const char *minidumpPath)
 
bool MakeCommand (CrashReportContext *ctx, const wchar_t *path, const wchar_t *id)
 
bool SendReport (CrashReportContext *ctx, const wchar_t *path, const wchar_t *id)
 

Detailed Description

This object is for internal usage.


Audacity: A Digital Audio Editor

CrashReportContext.h

Vitaly Sverchinsky

Simple POD type, holds user data required to start handler. Fields are initialized with Set* methods, which may return false if internal buffer isn't large enough to store value passed as an argument. After initialization call StartHandler providing path to the database, where minidumps will be stored.

Definition at line 24 of file unix/CrashReportContext.h.

Member Function Documentation

◆ SetParameters() [1/2]

bool CrashReportContext::SetParameters ( const std::map< std::string, std::string > &  p)

Definition at line 125 of file unix/CrashReportContext.cpp.

126{
127 auto str = StringifyParameters(p);
129}
#define str(a)
char mParameters[MaxBufferLength]
static constexpr size_t MaxBufferLength
std::string StringifyParameters(const std::map< std::string, std::string > &parameters)
bool StrcpyChecked(char *dest, size_t destsz, const std::string &src)

References MaxBufferLength, mParameters, str, anonymous_namespace{CrashReportContext.cpp}::StrcpyChecked(), and anonymous_namespace{CrashReportContext.cpp}::StringifyParameters().

Here is the call graph for this function:

◆ SetParameters() [2/2]

bool CrashReportContext::SetParameters ( const std::map< std::string, std::string > &  p)

◆ SetReportURL() [1/2]

bool CrashReportContext::SetReportURL ( const std::string &  path)

◆ SetReportURL() [2/2]

bool CrashReportContext::SetReportURL ( const std::string &  url)

Definition at line 120 of file unix/CrashReportContext.cpp.

121{
123}
char mReportURL[MaxBufferLength]

References MaxBufferLength, mReportURL, and anonymous_namespace{CrashReportContext.cpp}::StrcpyChecked().

Here is the call graph for this function:

◆ SetSenderPathUTF8() [1/2]

bool CrashReportContext::SetSenderPathUTF8 ( const std::string &  path)

Definition at line 115 of file unix/CrashReportContext.cpp.

116{
117 return StrcpyChecked(mSenderPath, MaxBufferLength, path + "/" + CRASHREPORTER_PROGRAM_NAME);
118}
char mSenderPath[MaxBufferLength]

References MaxBufferLength, mSenderPath, and anonymous_namespace{CrashReportContext.cpp}::StrcpyChecked().

Referenced by BreakpadConfigurer::Start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetSenderPathUTF8() [2/2]

bool CrashReportContext::SetSenderPathUTF8 ( const std::string &  path)

◆ StartHandler() [1/2]

void CrashReportContext::StartHandler ( const std::string &  databasePath)

Definition at line 131 of file unix/CrashReportContext.cpp.

132{
133 //intentinal leak: error hooks may be useful while application is terminating
134 //CrashReportContext data should be alive too...
135#if(__APPLE__)
136 static auto handler = new google_breakpad::ExceptionHandler(
137 databasePath,
138 nullptr,
140 this,
141 true,
142 nullptr
143 );
144#else
145 google_breakpad::MinidumpDescriptor descriptor(databasePath);
146 static auto handler = new google_breakpad::ExceptionHandler(
147 descriptor,
148 nullptr,
150 this,
151 true,
152 -1
153 );
154#endif
155}
bool DumpCallback(const google_breakpad::MinidumpDescriptor &descriptor, void *context, bool succeeded)

References anonymous_namespace{CrashReportContext.cpp}::DumpCallback(), and audacity::cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler.

Here is the call graph for this function:

◆ StartHandler() [2/2]

void CrashReportContext::StartHandler ( const std::string &  databasePath)

Friends And Related Function Documentation

◆ MakeCommand

bool MakeCommand ( CrashReportContext ctx,
const wchar_t *  path,
const wchar_t *  id 
)
friend

Definition at line 72 of file win32/CrashReportContext.cpp.

73{
74 //utility path
75 auto ok = StrcpyChecked(c->mCommand, CrashReportContext::MaxCommandLength, L"\"");
76 ok = ok && StrcatChecked(c->mCommand, CrashReportContext::MaxCommandLength, c->mSenderPath);
77 ok = ok && StrcatChecked(c->mCommand, CrashReportContext::MaxCommandLength, L"\"");
78
79 //parameters: /p "..."
80 if (ok && c->mParameters[0] != 0)
81 {
82 ok = ok && StrcatChecked(c->mCommand, CrashReportContext::MaxCommandLength, L" /a \"");
83 ok = ok && StrcatChecked(c->mCommand, CrashReportContext::MaxCommandLength, c->mParameters);
84 ok = ok && StrcatChecked(c->mCommand, CrashReportContext::MaxCommandLength, L"\"");
85 }
86 //crash report URL: /u https://...
87 ok = ok && StrcatChecked(c->mCommand, CrashReportContext::MaxBufferLength, L" /u \"");
88 ok = ok && StrcatChecked(c->mCommand, CrashReportContext::MaxBufferLength, c->mReportURL);
89 ok = ok && StrcatChecked(c->mCommand, CrashReportContext::MaxBufferLength, L"\" ");
90 //minidump path: path/to/minidump.dmp
91 ok = ok && StrcatChecked(c->mCommand, CrashReportContext::MaxCommandLength, L" \"");
92 ok = ok && StrcatChecked(c->mCommand, CrashReportContext::MaxCommandLength, path);
93 ok = ok && StrcatChecked(c->mCommand, CrashReportContext::MaxCommandLength, L"\\");
94 ok = ok && StrcatChecked(c->mCommand, CrashReportContext::MaxCommandLength, id);
95 ok = ok && StrcatChecked(c->mCommand, CrashReportContext::MaxCommandLength, L".dmp\"");
96 return ok;
97}
static constexpr size_t MaxCommandLength
bool StrcpyChecked(wchar_t *dest, size_t destsz, const wchar_t *src)
bool StrcatChecked(wchar_t *dest, size_t destsz, const wchar_t *src)

◆ SendReport [1/2]

bool SendReport ( CrashReportContext ctx,
const char *  minidumpPath 
)
friend

Audacity: A Digital Audio Editor

CrashReportContext.cpp

Vitaly Sverchinsky

Some parts of the code are designed to operate while app is crashing, so there may be some restrictions on heap usage. For more information please read Breakpad documentation.

Definition at line 26 of file unix/CrashReportContext.cpp.

27{
28 auto pid = fork();
29 if(pid == 0)
30 {
31 if(c->mParameters[0] != 0)
32 {
33 execl(c->mSenderPath, CRASHREPORTER_PROGRAM_NAME, "-a", c->mParameters, "-u", c->mReportURL, minidumpPath, NULL);
34 }
35 else
36 {
37 execl(c->mSenderPath, CRASHREPORTER_PROGRAM_NAME, "-u", c->mReportURL, minidumpPath, NULL);
38 }
39 fprintf(stderr, "Failed to start handler: %s\n", strerror(errno));
40 abort();
41 }
42 return pid != -1;
43}

◆ SendReport [2/2]

bool SendReport ( CrashReportContext ctx,
const wchar_t *  path,
const wchar_t *  id 
)
friend

Definition at line 99 of file win32/CrashReportContext.cpp.

100{
101 if (!MakeCommand(c, path, id))
102 return false;
103
104 STARTUPINFOW si;
105 ZeroMemory(&si, sizeof(si));
106 si.cb = sizeof(si);
107 si.dwFlags = STARTF_USESHOWWINDOW;
108 si.wShowWindow = SW_SHOW;
109
110 PROCESS_INFORMATION pi;
111 ZeroMemory(&pi, sizeof(pi));
112
113 if (CreateProcessW(NULL, c->mCommand, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
114 {
115 CloseHandle(pi.hProcess);
116 CloseHandle(pi.hThread);
117 return true;
118 }
119 else
120 return false;
121}
friend bool MakeCommand(CrashReportContext *ctx, const wchar_t *path, const wchar_t *id)

Member Data Documentation

◆ MaxBufferLength

static constexpr size_t CrashReportContext::MaxBufferLength { 2048 }
staticconstexprprivate

Definition at line 26 of file unix/CrashReportContext.h.

Referenced by SetParameters(), SetReportURL(), and SetSenderPathUTF8().

◆ MaxCommandLength

constexpr size_t CrashReportContext::MaxCommandLength { 8192 }
staticconstexprprivate

Definition at line 27 of file win32/CrashReportContext.h.

◆ mCommand

wchar_t CrashReportContext::mCommand[MaxCommandLength] {}
private

Definition at line 34 of file win32/CrashReportContext.h.

◆ mParameters [1/2]

char CrashReportContext::mParameters[MaxBufferLength] {}
private

Definition at line 30 of file unix/CrashReportContext.h.

Referenced by SetParameters().

◆ mParameters [2/2]

wchar_t CrashReportContext::mParameters[MaxBufferLength] {}
private

Definition at line 31 of file win32/CrashReportContext.h.

◆ mReportURL [1/2]

char CrashReportContext::mReportURL[MaxBufferLength] {}
private

Definition at line 29 of file unix/CrashReportContext.h.

Referenced by SetReportURL().

◆ mReportURL [2/2]

wchar_t CrashReportContext::mReportURL[MaxBufferLength] {}
private

Definition at line 30 of file win32/CrashReportContext.h.

◆ mSenderPath [1/2]

char CrashReportContext::mSenderPath[MaxBufferLength] {}
private

Definition at line 28 of file unix/CrashReportContext.h.

Referenced by SetSenderPathUTF8().

◆ mSenderPath [2/2]

wchar_t CrashReportContext::mSenderPath[MaxBufferLength] {}
private

Definition at line 29 of file win32/CrashReportContext.h.


The documentation for this class was generated from the following files: