Skip to content

Commit

Permalink
Offer to generate .tspack from crash handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Soreepeong committed Sep 14, 2022
1 parent 921cf00 commit 8718de6
Show file tree
Hide file tree
Showing 11 changed files with 9,371 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Dalamud.Boot/DalamudStartInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void from_json(const nlohmann::json& json, DalamudStartInfo& config) {
config.Language = json.value("Language", config.Language);
config.GameVersion = json.value("GameVersion", config.GameVersion);
config.DelayInitializeMs = json.value("DelayInitializeMs", config.DelayInitializeMs);
config.TroubleshootingPackData = json.value("TroubleshootingPackData", std::string{});

config.BootLogPath = json.value("BootLogPath", config.BootLogPath);
config.BootShowConsole = json.value("BootShowConsole", config.BootShowConsole);
Expand All @@ -100,6 +101,8 @@ void from_json(const nlohmann::json& json, DalamudStartInfo& config) {
for (const auto& val : *it)
config.BootUnhookDlls.insert(unicode::convert<std::string>(val.get<std::string>(), &unicode::lower));
}

config.CrashHandlerShow = json.value("CrashHandlerShow", config.CrashHandlerShow);
}

void DalamudStartInfo::from_envvars() {
Expand Down
3 changes: 3 additions & 0 deletions Dalamud.Boot/DalamudStartInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct DalamudStartInfo {
ClientLanguage Language = ClientLanguage::English;
std::string GameVersion;
int DelayInitializeMs = 0;
std::string TroubleshootingPackData;

std::string BootLogPath;
bool BootShowConsole = false;
Expand All @@ -47,6 +48,8 @@ struct DalamudStartInfo {
std::set<std::string> BootEnabledGameFixes{};
std::set<std::string> BootUnhookDlls{};

bool CrashHandlerShow = false;

friend void from_json(const nlohmann::json&, DalamudStartInfo&);
void from_envvars();
};
Expand Down
1 change: 1 addition & 0 deletions Dalamud.Boot/crashhandler_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ struct exception_info
uint64_t nLifetime;
HANDLE hThreadHandle;
DWORD dwStackTraceLength;
DWORD dwTroubleshootingPackDataLength;
};
12 changes: 6 additions & 6 deletions Dalamud.Boot/veh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,16 @@ LONG exception_handler(EXCEPTION_POINTERS* ex)
}

exinfo.dwStackTraceLength = static_cast<DWORD>(stackTrace.size());
exinfo.dwTroubleshootingPackDataLength = static_cast<DWORD>(g_startInfo.TroubleshootingPackData.size());
if (DWORD written; !WriteFile(g_crashhandler_pipe_write, &exinfo, static_cast<DWORD>(sizeof exinfo), &written, nullptr) || sizeof exinfo != written)
return EXCEPTION_CONTINUE_SEARCH;

if (DWORD written; !WriteFile(g_crashhandler_pipe_write, &stackTrace[0], static_cast<DWORD>(std::span(stackTrace).size_bytes()), &written, nullptr) || std::span(stackTrace).size_bytes() != written)
return EXCEPTION_CONTINUE_SEARCH;

if (DWORD written; !WriteFile(g_crashhandler_pipe_write, &g_startInfo.TroubleshootingPackData[0], static_cast<DWORD>(std::span(g_startInfo.TroubleshootingPackData).size_bytes()), &written, nullptr) || std::span(g_startInfo.TroubleshootingPackData).size_bytes() != written)
return EXCEPTION_CONTINUE_SEARCH;

SuspendThread(GetCurrentThread());
return EXCEPTION_CONTINUE_SEARCH;
}
Expand Down Expand Up @@ -224,11 +228,7 @@ bool veh::add_handler(bool doFullDump, const std::string& workingDirectory)

siex.StartupInfo.cb = sizeof siex;
siex.StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
#ifdef NDEBUG
siex.StartupInfo.wShowWindow = SW_HIDE;
#else
siex.StartupInfo.wShowWindow = SW_SHOW;
#endif
siex.StartupInfo.wShowWindow = g_startInfo.CrashHandlerShow ? SW_SHOW : SW_HIDE;

// set up list of handles to inherit to child process
std::vector<char> attributeListBuf;
Expand Down Expand Up @@ -309,7 +309,7 @@ bool veh::add_handler(bool doFullDump, const std::string& workingDirectory)
}

CloseHandle(pi.hThread);

g_crashhandler_process = pi.hProcess;
g_crashhandler_pipe_write = hWritePipe->release();
logging::I("Launched DalamudCrashHandler.exe: PID {}", pi.dwProcessId);
Expand Down
8 changes: 7 additions & 1 deletion Dalamud.Injector/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public static void Main(int argc, IntPtr argvPtr)
args.Remove("--veh-full");
args.Remove("--no-plugin");
args.Remove("--no-3rd-plugin");
args.Remove("--crash-handler-console");

var mainCommand = args[1].ToLowerInvariant();
if (mainCommand.Length > 0 && mainCommand.Length <= 6 && "inject"[..mainCommand.Length] == mainCommand)
Expand Down Expand Up @@ -252,6 +253,7 @@ private static DalamudStartInfo ExtractAndInitializeStartInfoFromArguments(Dalam
var assetDirectory = startInfo.AssetDirectory;
var delayInitializeMs = startInfo.DelayInitializeMs;
var languageStr = startInfo.Language.ToString().ToLowerInvariant();
var troubleshootingData = "{\"empty\": true, \"description\": \"No troubleshooting data supplied.\"}";

for (var i = 2; i < args.Count; i++)
{
Expand All @@ -269,6 +271,8 @@ private static DalamudStartInfo ExtractAndInitializeStartInfoFromArguments(Dalam
delayInitializeMs = int.Parse(args[i][key.Length..]);
else if (args[i].StartsWith(key = "--dalamud-client-language="))
languageStr = args[i][key.Length..].ToLowerInvariant();
else if (args[i].StartsWith(key = "--dalamud-tspack-b64="))
troubleshootingData = Encoding.UTF8.GetString(Convert.FromBase64String(args[i][key.Length..]));
else
continue;

Expand Down Expand Up @@ -313,6 +317,7 @@ private static DalamudStartInfo ExtractAndInitializeStartInfoFromArguments(Dalam
startInfo.Language = clientLanguage;
startInfo.DelayInitializeMs = delayInitializeMs;
startInfo.GameVersion = null;
startInfo.TroubleshootingPackData = troubleshootingData;

// Set boot defaults
startInfo.BootShowConsole = args.Contains("--console");
Expand All @@ -329,6 +334,7 @@ private static DalamudStartInfo ExtractAndInitializeStartInfoFromArguments(Dalam
startInfo.NoLoadPlugins = args.Contains("--no-plugin");
startInfo.NoLoadThirdPartyPlugins = args.Contains("--no-third-plugin");
// startInfo.BootUnhookDlls = new List<string>() { "kernel32.dll", "ntdll.dll", "user32.dll" };
startInfo.CrashHandlerShow = args.Contains("--crash-handler-console");

return startInfo;
}
Expand Down Expand Up @@ -364,7 +370,7 @@ private static int ProcessHelpCommand(List<string> args, string? particularComma
Console.WriteLine(" [--dalamud-client-language=0-3|j(apanese)|e(nglish)|d|g(erman)|f(rench)]");

Console.WriteLine("Verbose logging:\t[-v]");
Console.WriteLine("Show Console:\t[--console]");
Console.WriteLine("Show Console:\t[--console] [--crash-handler-console]");
Console.WriteLine("Enable ETW:\t[--etw]");
Console.WriteLine("Enable VEH:\t[--veh], [--veh-full]");
Console.WriteLine("Show messagebox:\t[--msgbox1], [--msgbox2], [--msgbox3]");
Expand Down
12 changes: 12 additions & 0 deletions Dalamud/DalamudStartInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public DalamudStartInfo(DalamudStartInfo other)
this.Language = other.Language;
this.GameVersion = other.GameVersion;
this.DelayInitializeMs = other.DelayInitializeMs;
this.TroubleshootingPackData = other.TroubleshootingPackData;
this.NoLoadPlugins = other.NoLoadPlugins;
this.NoLoadThirdPartyPlugins = other.NoLoadThirdPartyPlugins;
this.BootLogPath = other.BootLogPath;
Expand All @@ -47,6 +48,7 @@ public DalamudStartInfo(DalamudStartInfo other)
this.BootDotnetOpenProcessHookMode = other.BootDotnetOpenProcessHookMode;
this.BootEnabledGameFixes = other.BootEnabledGameFixes;
this.BootUnhookDlls = other.BootUnhookDlls;
this.CrashHandlerShow = other.CrashHandlerShow;
}

/// <summary>
Expand Down Expand Up @@ -85,6 +87,11 @@ public DalamudStartInfo(DalamudStartInfo other)
[JsonConverter(typeof(GameVersionConverter))]
public GameVersion? GameVersion { get; set; }

/// <summary>
/// Gets or sets troubleshooting information to attach when generating a tspack file.
/// </summary>
public string TroubleshootingPackData { get; set; }

/// <summary>
/// Gets or sets a value that specifies how much to wait before a new Dalamud session.
/// </summary>
Expand Down Expand Up @@ -154,5 +161,10 @@ public DalamudStartInfo(DalamudStartInfo other)
/// Gets or sets a list of DLLs that should be unhooked.
/// </summary>
public List<string>? BootUnhookDlls { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to show crash handler console window.
/// </summary>
public bool CrashHandlerShow { get; set; }
}
}
Loading

0 comments on commit 8718de6

Please sign in to comment.