summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2021-01-17 21:26:21 -0500
committerisanae <14251494+isanae@users.noreply.github.com>2021-01-18 08:21:42 -0500
commit6feab2ea8f96704e44a14c212a635dc17f4ba71e (patch)
treee39b12f7cb7f37cd96b3c3f451d2b527a81d4578 /src/shared
parent0d641f39776a2d5a1cd217531d3a3e39d3a3c670 (diff)
moved criticalOnTop() to uibase
changed all calls to reportError(), which now uses the main window if it exists as a parent, or calls criticalOnTop() added errors when running something from the command line for a different instance/profile removed unused crap
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/error_report.cpp64
-rw-r--r--src/shared/error_report.h44
-rw-r--r--src/shared/leaktrace.cpp68
-rw-r--r--src/shared/leaktrace.h24
-rw-r--r--src/shared/stackdata.cpp169
-rw-r--r--src/shared/stackdata.h50
6 files changed, 0 insertions, 419 deletions
diff --git a/src/shared/error_report.cpp b/src/shared/error_report.cpp
deleted file mode 100644
index 09fdcb49..00000000
--- a/src/shared/error_report.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
-Copyright (C) 2012 Sebastian Herbord. All rights reserved.
-
-This file is part of Mod Organizer.
-
-Mod Organizer is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-Mod Organizer is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "error_report.h"
-#include <sstream>
-#include <stdio.h>
-
-namespace MOShared {
-
-void reportError(LPCSTR format, ...)
-{
- char buffer[1025];
- memset(buffer, 0, sizeof(char) * 1025);
-
- va_list argList;
- va_start(argList, format);
-
- vsnprintf(buffer, 1024, format, argList);
- va_end(argList);
-
- MessageBoxA(nullptr, buffer, "Error", MB_OK | MB_ICONERROR);
-}
-
-void reportError(LPCWSTR format, ...)
-{
- WCHAR buffer[1025];
- memset(buffer, 0, sizeof(WCHAR) * 1025);
-
- va_list argList;
- va_start(argList, format);
-
- _vsnwprintf_s(buffer, 1024, format, argList);
- va_end(argList);
-
- MessageBoxW(nullptr, buffer, L"Error", MB_OK | MB_ICONERROR);
-}
-
-void criticalOnTop(const QString& message)
-{
- QMessageBox mb(QMessageBox::Critical, QObject::tr("Mod Organizer"), message);
-
- mb.show();
- mb.activateWindow();
- mb.raise();
- mb.exec();
-}
-
-} // namespace MOShared
diff --git a/src/shared/error_report.h b/src/shared/error_report.h
deleted file mode 100644
index 9343d3da..00000000
--- a/src/shared/error_report.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
-Copyright (C) 2012 Sebastian Herbord. All rights reserved.
-
-This file is part of Mod Organizer.
-
-Mod Organizer is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-Mod Organizer is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef MODORGANIZER_SHARED_ERROR_REPORT_INCLUDED
-#define MODORGANIZER_SHARED_ERROR_REPORT_INCLUDED
-
-#include <tchar.h>
-#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
-#include <string>
-
-namespace MOShared
-{
-
-void reportError(LPCSTR format, ...);
-void reportError(LPCWSTR format, ...);
-
-// shows a critical message box that's raised to the top of the zorder, useful
-// for messages without a main window, which sometimes makes them pop up behind
-// all other windows
-//
-// the dialog is not topmost, it's just raised once when shown
-//
-void criticalOnTop(const QString& message);
-
-} // namespace MOShared
-
-#endif // MODORGANIZER_SHARED_ERROR_REPORT_INCLUDED
diff --git a/src/shared/leaktrace.cpp b/src/shared/leaktrace.cpp
deleted file mode 100644
index 466162a4..00000000
--- a/src/shared/leaktrace.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-//disable warning messages 4302 , 4311 and 4312
-#pragma warning( disable : 4302 )
-#pragma warning( disable : 4311 )
-#pragma warning( disable : 4312 )
-
-#include "leaktrace.h"
-#include "stackdata.h"
-#include <Windows.h>
-#include <DbgHelp.h>
-#include <set>
-#include <map>
-#include <vector>
-#include <sstream>
-#include <algorithm>
-
-
-using namespace MOShared;
-
-
-static struct __TraceData {
- void regTrace(void *pointer, const char *functionName, int line) {
- m_Traces[reinterpret_cast<unsigned long>(pointer)] = StackData(functionName, line);
- }
- void deregTrace(void *pointer) {
- auto iter = m_Traces.find(reinterpret_cast<unsigned long>(pointer));
- if (iter != m_Traces.end()) {
- m_Traces.erase(iter);
- }
- }
-
- ~__TraceData() {
- std::map<StackData, std::vector<unsigned long> > result;
- for (auto iter = m_Traces.begin(); iter != m_Traces.end(); ++iter) {
- result[iter->second].push_back(iter->first);
- }
- for (auto iter = result.begin(); iter != result.end(); ++iter) {
- printf("-----------------------------------\n"
- "%d objects not freed, allocated at:\n%s",
- static_cast<int>(iter->second.size()), iter->first.toString().c_str());
- printf("Addresses: ");
- for (int i = 0;
- i < (std::min<int>)(5, static_cast<int>(iter->second.size())); ++i) {
- printf("%p, ", reinterpret_cast<void *>(iter->second[i]));
- }
- printf("\n");
- }
- }
-
- std::map<unsigned long, StackData> m_Traces;
-
-} __trace;
-
-
-void LeakTrace::TraceAlloc(void *ptr, const char *functionName, int line)
-{
- __trace.regTrace(ptr, functionName, line);
-}
-
-void LeakTrace::TraceDealloc(void *ptr)
-{
- __trace.deregTrace(ptr);
-}
-
-//re-enable warning messages 4302 , 4311 and 4312
-#pragma warning( default : 4302 )
-#pragma warning( default : 4311 )
-#pragma warning( default : 4312 )
-
diff --git a/src/shared/leaktrace.h b/src/shared/leaktrace.h
deleted file mode 100644
index 4985925e..00000000
--- a/src/shared/leaktrace.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef LEAKTRACE_H
-#define LEAKTRACE_H
-
-
-namespace LeakTrace {
-
-void TraceAlloc(void *ptr, const char *functionName, int line);
-void TraceDealloc(void *ptr);
-
-};
-
-#ifdef TRACE_LEAKS
-
-#define LEAK_TRACE LeakTrace::TraceAlloc(this, __FUNCTION__, __LINE__)
-#define LEAK_UNTRACE LeakTrace::TraceDealloc(this)
-
-#else // TRACE_LEAKS
-
-#define LEAK_TRACE
-#define LEAK_UNTRACE
-
-#endif // TRACE_LEAKS
-
-#endif // LEAKTRACE_H
diff --git a/src/shared/stackdata.cpp b/src/shared/stackdata.cpp
deleted file mode 100644
index b336593a..00000000
--- a/src/shared/stackdata.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-#include "stackdata.h"
-
-#include "util.h"
-#include <DbgHelp.h>
-#include <sstream>
-#include <TlHelp32.h>
-#include <set>
-#include "error_report.h"
-#include <boost/predef.h>
-
-
-using namespace MOShared;
-
-#if defined _MSC_VER
-
-static void initDbgIfNecess()
-{
- HANDLE process = ::GetCurrentProcess();
- static std::set<DWORD> initialized;
- if (initialized.find(::GetCurrentProcessId()) == initialized.end()) {
- static bool firstCall = true;
- if (firstCall) {
- ::SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS);
- firstCall = false;
- }
- if (!::SymInitialize(process, NULL, TRUE)) {
- printf("failed to initialize symbols: %lu", ::GetLastError());
- }
- initialized.insert(::GetCurrentProcessId());
- }
-}
-
-
-
-StackData::StackData()
- : m_Count(0)
- , m_Function()
- , m_Line(-1)
-{
- initTrace();
-}
-
-StackData::StackData(const char *function, int line)
- : m_Count(0)
- , m_Function(function)
- , m_Line(line)
-{
-
-}
-
-std::string StackData::toString() const {
- initDbgIfNecess();
-
- char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
- PSYMBOL_INFO symbol = (PSYMBOL_INFO)buffer;
- symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
- symbol->MaxNameLen = MAX_SYM_NAME;
-
- std::ostringstream stackStream;
-
- if (m_Function.length() > 0) {
- stackStream << "[" << m_Function << ":" << m_Line << "]\n";
- }
-
- for(unsigned int i = 0; i < m_Count; ++i) {
- DWORD64 displacement = 0;
- if (!::SymFromAddr(::GetCurrentProcess(), (DWORD64)m_Stack[i], &displacement, symbol)) {
- stackStream << m_Count - i - 1 << ": [" << m_Stack[i] << "]\n";
- } else {
- stackStream << m_Count - i - 1 << ": " << symbol->Name << "\n";
- }
- }
- return stackStream.str();
-}
-
-void StackData::load_modules(HANDLE process, DWORD processID) {
- HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processID);
- if (snap == INVALID_HANDLE_VALUE)
- return;
-
- MODULEENTRY32 entry;
- entry.dwSize = sizeof(entry);
-
- if (Module32First(snap, &entry)) {
- do {
- std::string fileName = ToString(entry.szExePath, false);
- std::string moduleName = ToString(entry.szModule, false);
- SymLoadModule64(process, NULL, fileName.c_str(), moduleName.c_str(), (DWORD64) entry.modBaseAddr, entry.modBaseSize);
- } while (Module32Next(snap, &entry));
- }
- CloseHandle(snap);
-}
-
-#pragma warning( disable : 4748 )
-
-void StackData::initTrace() {
-#ifdef _X86_
- load_modules(::GetCurrentProcess(), ::GetCurrentProcessId());
- CONTEXT context;
- std::memset(&context, 0, sizeof(CONTEXT));
- context.ContextFlags = CONTEXT_CONTROL;
- //Why only for 64 bit?
-#if BOOST_ARCH_X86_64 || defined(__clang__)
- ::RtlCaptureContext(&context);
-#else
- __asm
- {
- Label:
- mov [context.Ebp], ebp;
- mov [context.Esp], esp;
- mov eax, [Label];
- mov [context.Eip], eax;
- }
-#endif
-
- STACKFRAME64 stackFrame;
- ::ZeroMemory(&stackFrame, sizeof(STACKFRAME64));
- stackFrame.AddrPC.Offset = context.Eip;
- stackFrame.AddrPC.Mode = AddrModeFlat;
- stackFrame.AddrFrame.Offset = context.Ebp;
- stackFrame.AddrFrame.Mode = AddrModeFlat;
- stackFrame.AddrStack.Offset = context.Esp;
- stackFrame.AddrStack.Mode = AddrModeFlat;
- m_Count = 0;
- while (m_Count < FRAMES_TO_CAPTURE) {
- if (!StackWalk64(IMAGE_FILE_MACHINE_I386, ::GetCurrentProcess(),
- ::GetCurrentThread(), &stackFrame, &context, NULL,
- &SymFunctionTableAccess64, &SymGetModuleBase64, NULL)) {
- break;
- }
-
- if (stackFrame.AddrPC.Offset == 0) {
- continue;
- break;
- }
-
- m_Stack[m_Count++] = reinterpret_cast<void *>(stackFrame.AddrPC.Offset);
- }
-#endif
-}
-
-
-bool MOShared::operator==(const StackData &LHS, const StackData &RHS) {
- if (LHS.m_Count != RHS.m_Count) {
- return false;
- } else {
- for (int i = 0; i < LHS.m_Count; ++i) {
- if (LHS.m_Stack[i] != RHS.m_Stack[i]) {
- return false;
- }
- }
- }
- return true;
-}
-
-
-bool MOShared::operator<(const StackData &LHS, const StackData &RHS) {
- if (LHS.m_Count != RHS.m_Count) {
- return LHS.m_Count < RHS.m_Count;
- } else {
- for (int i = 0; i < LHS.m_Count; ++i) {
- if (LHS.m_Stack[i] != RHS.m_Stack[i]) {
- return LHS.m_Stack[i] < RHS.m_Stack[i];
- }
- }
- }
- return false;
-}
-#endif
diff --git a/src/shared/stackdata.h b/src/shared/stackdata.h
deleted file mode 100644
index 7151699c..00000000
--- a/src/shared/stackdata.h
+++ /dev/null
@@ -1,50 +0,0 @@
-#ifndef STACKDATA_H
-#define STACKDATA_H
-
-
-#include <string>
-#include <Windows.h>
-
-
-namespace MOShared {
-
-
-class StackData {
- friend bool operator==(const StackData &LHS, const StackData &RHS);
- friend bool operator<(const StackData &LHS, const StackData &RHS);
-public:
-
- StackData();
- StackData(const char *function, int line);
-
- std::string toString() const;
-
-private:
-
- void load_modules(HANDLE process, DWORD processID);
-
- void initTrace();
-
-private:
-
- static const int FRAMES_TO_SKIP = 1;
- static const int FRAMES_TO_CAPTURE = 20;
-
-private:
-
- LPVOID m_Stack[FRAMES_TO_CAPTURE];
- USHORT m_Count;
- std::string m_Function;
- int m_Line;
-
-};
-
-
-bool operator==(const StackData &LHS, const StackData &RHS);
-
-bool operator<(const StackData &LHS, const StackData &RHS);
-
-} // namespace MOShared
-
-
-#endif // STACKDATA_H