Skip to content

Commit

Permalink
ChmModel::HandleLink: change CrashIf() => ReportIfQuick()
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed May 21, 2024
1 parent 1695022 commit 733fca8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
8 changes: 7 additions & 1 deletion src/ChmModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "GlobalPrefs.h"
#include "ChmModel.h"

#include "utils/Log.h"

static IPageDestination* NewChmNamedDest(const char* url, int pageNo) {
if (!url) {
return nullptr;
Expand Down Expand Up @@ -223,7 +225,11 @@ void ChmModel::ScrollTo(int, RectF, float) {
}

bool ChmModel::HandleLink(IPageDestination* link, ILinkHandler*) {
CrashIf(link->GetKind() != kindDestinationScrollTo);
Kind k = link->GetKind();
if (k != kindDestinationScrollTo) {
logf("ChmModel::HandleLink: unsupported kind '%s'\n", k);
ReportIfQuick(link->GetKind() != kindDestinationScrollTo);
}
char* url = PageDestGetName(link);
if (DisplayPage(url)) {
return true;
Expand Down
30 changes: 19 additions & 11 deletions src/CrashHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,15 @@ static bool GetModules(str::Str& s, bool additionalOnly) {
return isWine;
}

static char* BuildCrashInfoText(bool forCrash, bool noCallstack) {
// if reportCond this is building for ReportIf() / ReportIfQuick()
// otherwise this is a crsah
static char* BuildCrashInfoText(const char* reportCond, bool noCallstack) {
str::Str s(16 * 1024, gCrashHandlerAllocator);
if (!forCrash) {
if (reportCond) {
s.Append("Type: debug report (not crash)\n");
s.Append("Cond: ");
s.Append(reportCond);
s.Append("\n");
}
if (gSystemInfo) {
s.Append(gSystemInfo);
Expand All @@ -144,16 +149,18 @@ static char* BuildCrashInfoText(bool forCrash, bool noCallstack) {
GetStressTestInfo(&s);
s.Append("\n");

if (forCrash) {
dbghelp::GetExceptionInfo(s, gMei.ExceptionPointers);
} else {
if (reportCond) {
// this is not a crash but debug report, we don't have an exception
if (noCallstack) {
s.Append("\r\nCrashed thread:\r\n");
// dummy line so that we don't have to
s.Append("\nCrashed thread:\n");
s.Append("00007FF79239E91A 01:000000000001D91A dummy!quick report\n");
} else {
s.Append("\r\nCrashed thread:\r\n");
s.Append("\nCrashed thread:\n");
dbghelp::GetCurrentThreadCallstack(s);
}
} else {
dbghelp::GetExceptionInfo(s, gMei.ExceptionPointers);
}

if (!noCallstack) {
Expand Down Expand Up @@ -308,13 +315,14 @@ bool CrashHandlerDownloadSymbols() {
// like crash report, but can be triggered without a crash
void _uploadDebugReport(const char* condStr, bool noCallstack) {
// we want to avoid submitting multiple reports for the same
// condition. I'm too lazy to implement tracking this granuarly
// so only allow once submition in a given session
// condition. I'm too lazy to implement tracking this granularly
// so only allow once submission in a given session
static bool didSubmitDebugReport = false;

if (didSubmitDebugReport) {
return;
}

didSubmitDebugReport = true;
// don't send report if this is me debugging
if (IsDebuggerPresent()) {
Expand Down Expand Up @@ -347,7 +355,7 @@ void _uploadDebugReport(const char* condStr, bool noCallstack) {
}
}

auto s = BuildCrashInfoText(false, noCallstack);
auto s = BuildCrashInfoText(condStr, noCallstack);
if (str::IsEmpty(s)) {
log("_uploadDebugReport(): skipping because !BuildCrashInfoText()\n");
return;
Expand Down Expand Up @@ -377,7 +385,7 @@ void TryUploadCrashReport() {
log("TryUploadCrashReport(): CrashHandlerDownloadSymbols() failed\n");
}

char* sv = BuildCrashInfoText(true, true);
char* sv = BuildCrashInfoText(nullptr, true);
if (str::IsEmpty(sv)) {
log("TryUploadCrashReport(): skipping because !BuildCrashInfoText()\n");
return;
Expand Down
4 changes: 2 additions & 2 deletions src/SumatraPDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3294,8 +3294,8 @@ static TempWStr GetFileFilterTemp() {
}
fileFilter.Append(_TRA("All files"));
fileFilter.Append("\1*.*\1");
str::TransCharsInPlace(fileFilter.Get(), "\1", "\0");
return ToWStrTemp(fileFilter.CStr());
str::TransCharsInPlace(fileFilter.CStr(), "\1", "\0");
return ToWStrTemp(fileFilter);
}

static void OpenFile(MainWindow* win) {
Expand Down
18 changes: 9 additions & 9 deletions src/utils/BaseUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,21 @@ inline void CrashIfFunc(bool cond) {
} \
} while (0)

#define ReportIf(cond) \
__analysis_assume(!(cond)); \
do { \
if (cond) { \
_uploadDebugReport(#cond, true); \
} \
} while (0)

#define ReportIfQuick(cond) \
#define ReportIf(cond) \
__analysis_assume(!(cond)); \
do { \
if (cond) { \
_uploadDebugReport(#cond, false); \
} \
} while (0)

#define ReportIfQuick(cond) \
do { \
if (cond) { \
_uploadDebugReport(#cond, true); \
} \
} while (0)

void* AllocZero(size_t count, size_t size);

template <typename T>
Expand Down

0 comments on commit 733fca8

Please sign in to comment.