Skip to content

Commit

Permalink
add CrashHanlderNoOp.cpp to be used with non-Sumatra executables
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed May 29, 2024
1 parent 42f882f commit d8c382e
Show file tree
Hide file tree
Showing 35 changed files with 228 additions and 208 deletions.
73 changes: 14 additions & 59 deletions premake5.files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function preview_test_files()
})
files {
"src/tools/preview_test.cpp",
"src/CrashHandlerNoOp.cpp",
}
end

Expand Down Expand Up @@ -1121,6 +1122,7 @@ function efi_files()
"tools/efi/*.h",
"tools/efi/*.cpp",
"src/utils/BaseUtil*",
"CrashHandlerNoOp.cpp",
"src/utils/BitManip.h",
"src/utils/Dict*",
"src/utils/StrUtil.*",
Expand All @@ -1130,6 +1132,7 @@ end
function sizer_files()
files {
"tools/sizer/*",
"src/CrashHandlerNoOp.cpp",
}
end

Expand Down Expand Up @@ -1170,6 +1173,7 @@ function test_util_files()
files_in_dir("src", {
--"StressTesting.*",
--"AppTools.*",
"CrashHandlerNoOp.cpp",
"DisplayMode.*",
"Flags.*",
"SumatraConfig.*",
Expand All @@ -1181,6 +1185,7 @@ end

function engine_dump_files()
files_in_dir("src", {
"CrashHandlerNoOp.cpp",
"EngineDump.cpp",
"SumatraConfig.*",
"FzImgReader.*",
Expand All @@ -1189,6 +1194,13 @@ function engine_dump_files()
})
end

function plugin_test_files()
files {
"src/tools/plugin-test.cpp",
"src/CrashHandlerNoOp.cpp"
}
end

function pdf_preview_files()
files_in_dir("src/previewer", {
"PdfPreview.*",
Expand All @@ -1200,6 +1212,7 @@ function pdf_preview_files()
"utils/Log.*",
"mui/Mui.*",
"mui/TextRender.*",
"CrashHandlerNoOp.cpp",
"ChmFile.*",
"DocProperties.*",
"EbookDoc.*",
Expand Down Expand Up @@ -1232,6 +1245,7 @@ function search_filter_files()
files_in_dir("src", {
"utils/Log.*",
"MUPDF_Exports.cpp",
"CrashHandlerNoOp.cpp",
"DocProperties.*",
"EbookDoc.*",
"EngineBase.*",
Expand All @@ -1256,65 +1270,6 @@ function search_filter_files()
filter {}
end


--[[
function wdl_files()
files_in_dir("ext/WDL", {
"projectcontext.cpp",
})
files_in_dir("ext/WDL/tinyxml", {
"*.cpp",
"*.c",
"*.h",
})
files_in_dir("ext/WDL/lice", {
"lice.*",
"lice_arc.cpp",
"lice_bezier.h",
-- "lice_bmp.cpp",
"lice_colorspace.*",
"lice_combine.h",
"lice_extended.h",
-- "lice_gif.cpp",
-- "lice_gif_write.cpp",
-- "lice_gl_ctx.*",
-- "lice_glbitmap.*",
-- "lice_ico.cpp",
-- "lice_image.cpp",
"lice_import.h",
-- "lice_jpg.cpp",
-- "lice_jpg_write.cpp",
-- "lice_lcf.*",
"lice_line.cpp",
"lice_lvg.cpp",
"lice_palette.cpp",
-- "lice_pcx.cpp",
-- "lice_png.cpp",
-- "lice_png_write.cpp",
"lice_svg.cpp",
-- "lice_texgen.cpp",
"lice_text.*",
"lice_textnew.cpp",
})
files_in_dir("ext/WDL/wingui", {
"dlgitemborder.h",
"membitmap.h",
"riceditctrl.h",
"virtwnd.*",
"virtwnd-controls.h",
"virtwnd-iaccessible.cpp",
"virtwnd-iconbutton.cpp",
"virtwnd-listbox.cpp",
"virtwnd-skin.h",
"virtwnd-slider.cpp",
"wndsize.*",
})
end
--]]

function gumbo_files()
files_in_dir("ext/gumbo-parser/src", {
"*.c",
Expand Down
6 changes: 2 additions & 4 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ workspace "SumatraPDF"
cppdialect "C++latest"
regconf()
includedirs { "src", "mupdf/include"}
files { "src/tools/signfile.cpp" }
files { "src/tools/signfile.cpp", "src/CrashHandlerNoOp.cpp" }
links { "utils", "mupdf" }
links { "crypt32", "shlwapi", "version", "Comctl32", "wininet" }

Expand All @@ -672,7 +672,7 @@ workspace "SumatraPDF"
regconf()
entrypoint "WinMainCRTStartup"
includedirs { "src" }
files { "src/tools/plugin-test.cpp" }
plugin_test_files()
links { "utils", "mupdf" }
links { "shlwapi", "version", "comctl32", "wininet" }

Expand Down Expand Up @@ -790,7 +790,6 @@ workspace "SumatraPDF"

defines { "_CRT_SECURE_NO_WARNINGS" }
defines { "DISABLE_DOCUMENT_RESTRICTIONS" }
defines { "ENABLE_CRASH_REPORTING" }

filter "configurations:ReleaseAnalyze"
-- TODO: somehow /analyze- is default which creates warning about
Expand Down Expand Up @@ -844,7 +843,6 @@ workspace "SumatraPDF"

defines { "_CRT_SECURE_NO_WARNINGS" }
defines { "DISABLE_DOCUMENT_RESTRICTIONS" }
defines { "ENABLE_CRASH_REPORTING" }

filter "configurations:ReleaseAnalyze"
-- TODO: somehow /analyze- is default which creates warning about
Expand Down
20 changes: 10 additions & 10 deletions src/CommandPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ static bool IsOpenExternalViewerCommand(i32 cmdId) {
}

static bool AllowCommand(const CommandPaletteBuildCtx& ctx, i32 cmdId) {
switch (cmdId) {
case CmdDebugCorruptMemory:
case CmdDebugCrashMe:
case CmdDebugDownloadSymbols:
case CmdDebugTestApp:
case CmdDebugShowNotif:
case CmdDebugStartStressTest:
return gIsDebugBuild;
}

if (IsCmdInList(gBlacklistCommandsFromPalette)) {
return false;
}
Expand Down Expand Up @@ -321,16 +331,6 @@ static bool AllowCommand(const CommandPaletteBuildCtx& ctx, i32 cmdId) {
if ((cmdId == CmdToggleScrollbars) && !gGlobalPrefs->fixedPageUI.hideScrollbars) {
return false;
}

switch (cmdId) {
case CmdDebugTestApp:
case CmdDebugShowNotif:
case CmdDebugStartStressTest:
case CmdDebugCorruptMemory:
case CmdDebugCrashMe: {
return gIsDebugBuild;
}
}
return true;
}

Expand Down
12 changes: 6 additions & 6 deletions src/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,6 @@ Cmd* enum (e.g. CmdOpen) and a human-readable name (not used yet).
V(CmdFavoriteDel, "Delete Favorite") \
V(CmdFavoriteToggle, "Toggle Favorites") \
V(CmdToggleLinks, "Toggle Show Links") \
V(CmdDebugCrashMe, "Debug: Crash Me") \
V(CmdDebugCorruptMemory, "Debug: Corrupt Memory") \
V(CmdDebugDownloadSymbols, "Debug: Download Symbols") \
V(CmdDebugTestApp, "Debug: Test App") \
V(CmdDebugShowNotif, "Debug: Show Notification") \
V(CmdDebugStartStressTest, "Debug: Start Stress Test") \
V(CmdCreateAnnotText, "Create Text Annotation") \
V(CmdCreateAnnotLink, "Create Link Annotation") \
V(CmdCreateAnnotFreeText, "Create Free Text Annotation") \
Expand Down Expand Up @@ -183,6 +177,12 @@ Cmd* enum (e.g. CmdOpen) and a human-readable name (not used yet).
V(CmdSelectNextTheme, "Select next theme") \
V(CmdToggleFrequentlyRead, "Toggle Frequently Read") \
V(CmdInvokeInverseSearch, "Invoke Inverse Search") \
V(CmdDebugCorruptMemory, "Debug: Corrupt Memory") \
V(CmdDebugCrashMe, "Debug: Crash Me") \
V(CmdDebugDownloadSymbols, "Debug: Download Symbols") \
V(CmdDebugTestApp, "Debug: Test App") \
V(CmdDebugShowNotif, "Debug: Show Notification") \
V(CmdDebugStartStressTest, "Debug: Start Stress Test") \
V(CmdNone, "Do nothing")

//V(CmdSelectAnnotation, "Select Annotation") \
Expand Down
23 changes: 14 additions & 9 deletions src/CrashHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2022 the SumatraPDF project authors (see AUTHORS file).
/* Copyright 2024 the SumatraPDF project authors (see AUTHORS file).
License: Simplified BSD */

#include "utils/BaseUtil.h"
Expand Down Expand Up @@ -116,7 +116,7 @@ static bool GetModules(str::Str& s, bool additionalOnly) {
return isWine;
}

static char* BuildCrashInfoText(const char* condStr, bool isCrash, bool captureCallstack) {
char* BuildCrashInfoText(const char* condStr, bool isCrash, bool captureCallstack) {
str::Str s(16 * 1024, gCrashHandlerAllocator);
if (!isCrash) {
captureCallstack = true;
Expand Down Expand Up @@ -170,15 +170,15 @@ static char* BuildCrashInfoText(const char* condStr, bool isCrash, bool captureC
return s.StealData();
}

static void SaveCrashInfo(const ByteSlice& d) {
void SaveCrashInfo(const ByteSlice& d) {
if (!gCrashFilePath) {
return;
}
dir::CreateForFile(gCrashFilePath);
file::WriteFile(gCrashFilePath, d);
}

static void UploadCrashReport(const ByteSlice& d) {
void UploadCrashReport(const ByteSlice& d) {
log("UploadCrashReport()\n");
if (d.empty()) {
return;
Expand Down Expand Up @@ -305,7 +305,7 @@ bool InitializeDbgHelp(bool force) {
return true;
}

static bool DownloadSymbolsIfNeeded() {
bool DownloadSymbolsIfNeeded() {
logf("DownloadSymbolsIfNeeded(), gSymbolsDir: '%s'\n", gSymbolsDir);
if (!AreSymbolsDownloaded(gSymbolsDir)) {
bool ok = CrashHandlerDownloadSymbols();
Expand All @@ -316,6 +316,11 @@ static bool DownloadSymbolsIfNeeded() {
return InitializeDbgHelp(false);
}

#if !defined(UPLOAD_REPORT)
void _uploadDebugReport(const char*, bool, bool) {
// no-op in
}
#else
// like crash report, but can be triggered without a crash
void _uploadDebugReport(const char* condStr, bool isCrash, bool captureCallstack) {
// we want to avoid submitting multiple reports for the same
Expand Down Expand Up @@ -380,6 +385,7 @@ void _uploadDebugReport(const char* condStr, bool isCrash, bool captureCallstack
log(s);
log("_uploadDebugReport() finished\n");
}
#endif

static DWORD WINAPI CrashDumpThread(LPVOID) {
WaitForSingleObject(gDumpEvent, INFINITE);
Expand Down Expand Up @@ -544,21 +550,20 @@ static void GetSystemInfo(str::Str& s) {
GetProcessorName(s);

{

MEMORYSTATUSEX ms;
ms.dwLength = sizeof(ms);
GlobalMemoryStatusEx(&ms);

float physMemGB = (float)ms.ullTotalPhys / (float)(1024 * 1024 * 1024);
float totalPageGB = (float)ms.ullTotalPageFile / (float)(1024 * 1024 * 1024);
DWORD usedPerc = ms.dwMemoryLoad;
s.AppendFmt("Physical Memory: %.2f GB\nCommit Charge Limit: %.2f GB\nMemory Used: %d%%\n", physMemGB, totalPageGB,
usedPerc);
s.AppendFmt("Physical Memory: %.2f GB\nCommit Charge Limit: %.2f GB\nMemory Used: %d%%\n", physMemGB,
totalPageGB, usedPerc);
}
{
TempStr ver = GetWebView2VersionTemp();
if (str::IsEmpty(ver)) {
ver = (TempStr)"no WebView2 installed";
ver = (TempStr) "no WebView2 installed";
}
s.AppendFmt("WebView2: %s\n", ver);
}
Expand Down
6 changes: 6 additions & 0 deletions src/CrashHandlerNoOp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* Copyright 2024 the SumatraPDF project authors (see AUTHORS file).
License: Simplified BSD */

void _uploadDebugReport(const char*, bool, bool) {
// no-op in
}
5 changes: 0 additions & 5 deletions src/Flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
V(AllUsers, "all-users") \
V(AllUsers2, "allusers") \
V(RunInstallNow, "run-install-now") \
V(TestBrowser, "test-browser") \
V(Adobe, "a") \
V(DDE, "dde") \
V(SetColorRange, "set-color-range")
Expand Down Expand Up @@ -480,10 +479,6 @@ void ParseFlags(const WCHAR* cmdLine, Flags& i) {
i.runInstallNow = true;
continue;
}
if (arg == Arg::TestBrowser) {
i.testBrowser = true;
continue;
}
if ((arg == Arg::AllUsers) || (arg == Arg::AllUsers2)) {
i.allUsers = true;
continue;
Expand Down
2 changes: 0 additions & 2 deletions src/Flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ struct Flags {
// before proceeding
int sleepMs = 0;

bool testBrowser = false;

Flags() = default;
~Flags();
};
Expand Down
12 changes: 0 additions & 12 deletions src/Scratch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@

// ----------------

void TestUngzip() {
const char* pathGz = R"(C:\Users\kjk\Downloads\AUTOSAR_TPS_SoftwareComponentTemplate.synctex.gz)";
const char* path = R"(C:\Users\kjk\Downloads\AUTOSAR_TPS_SoftwareComponentTemplate.synctex)";
ByteSlice uncomprFile = file::ReadFile(path);
ReportIf(uncomprFile.empty());
ByteSlice compr = file::ReadFile(pathGz);
ReportIf(compr.empty());
ByteSlice uncompr = Ungzip(compr);
bool same = IsEqual(uncomprFile, uncompr);
ReportIf(!same);
}

struct BrowserTestWnd : Wnd {
Webview2Wnd* webView = nullptr;
LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) override;
Expand Down
4 changes: 3 additions & 1 deletion src/SumatraPDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5642,7 +5642,9 @@ static LRESULT FrameOnCommand(MainWindow* win, HWND hwnd, UINT msg, WPARAM wp, L
#if defined(DEBUG)
case CmdDebugTestApp:
extern void TestApp(HINSTANCE hInstance);
TestApp(GetModuleHandle(nullptr));
extern void TestBrowser();
// TestApp(GetModuleHandle(nullptr));
TestBrowser();
break;

case CmdDebugStartStressTest: {
Expand Down
Loading

0 comments on commit d8c382e

Please sign in to comment.