1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 15:27:54 +00:00

Follow project coding style. Issue #2192.

This commit is contained in:
Nick Tiskov 2014-11-27 21:56:24 +03:00
parent ed829bc93a
commit ba9f6a3531
2 changed files with 206 additions and 195 deletions

View File

@ -1,22 +1,22 @@
/***************************************************************************
* Copyright (C) 2005-09 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program 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 2 of the License, or *
* (at your option) version 3. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
* Copyright (C) 2005-09 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program 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 2 of the License, or *
* (at your option) version 3. *
* *
* This program 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 this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <windows.h>
#include <dbghelp.h>
@ -24,7 +24,8 @@
#include <QTextStream>
namespace straceWin{
namespace straceWin
{
void loadHelpStackFrame(IMAGEHLP_STACK_FRAME&, const STACKFRAME64&);
BOOL CALLBACK EnumSymbolsCB(PSYMBOL_INFO, ULONG, PVOID);
BOOL CALLBACK EnumModulesCB(LPCSTR, DWORD64, PVOID);
@ -32,30 +33,33 @@ namespace straceWin{
struct EnumModulesContext;
}
void straceWin::loadHelpStackFrame(IMAGEHLP_STACK_FRAME &ihsf, const STACKFRAME64 &stackFrame) {
void straceWin::loadHelpStackFrame(IMAGEHLP_STACK_FRAME& ihsf, const STACKFRAME64& stackFrame)
{
ZeroMemory(&ihsf, sizeof(IMAGEHLP_STACK_FRAME));
ihsf.InstructionOffset = stackFrame.AddrPC.Offset;
ihsf.FrameOffset = stackFrame.AddrFrame.Offset;
}
BOOL CALLBACK straceWin::EnumSymbolsCB(PSYMBOL_INFO symInfo, ULONG size, PVOID user) {
QStringList *params = (QStringList *)user;
if(symInfo->Flags & SYMFLAG_PARAMETER) {
BOOL CALLBACK straceWin::EnumSymbolsCB(PSYMBOL_INFO symInfo, ULONG size, PVOID user)
{
QStringList* params = (QStringList*)user;
if (symInfo->Flags & SYMFLAG_PARAMETER)
params->append(symInfo->Name);
}
return TRUE;
}
struct straceWin::EnumModulesContext {
struct straceWin::EnumModulesContext
{
HANDLE hProcess;
QTextStream &stream;
EnumModulesContext(HANDLE hProcess, QTextStream &stream) : hProcess(hProcess), stream(stream) {}
QTextStream& stream;
EnumModulesContext(HANDLE hProcess, QTextStream& stream): hProcess(hProcess), stream(stream) {}
};
BOOL CALLBACK straceWin::EnumModulesCB(LPCSTR ModuleName, DWORD64 BaseOfDll, PVOID UserContext) {
BOOL CALLBACK straceWin::EnumModulesCB(LPCSTR ModuleName, DWORD64 BaseOfDll, PVOID UserContext)
{
IMAGEHLP_MODULE64 mod;
EnumModulesContext *context = (EnumModulesContext *)UserContext;
EnumModulesContext* context = (EnumModulesContext*)UserContext;
mod.SizeOfStruct = sizeof(IMAGEHLP_MODULE64);
if(SymGetModuleInfo64(context->hProcess, BaseOfDll, &mod)) {
QString moduleBase = QString("0x%1").arg(BaseOfDll, 8, 16, QLatin1Char('0'));
@ -79,14 +83,15 @@ BOOL CALLBACK straceWin::EnumModulesCB(LPCSTR ModuleName, DWORD64 BaseOfDll, PVO
#if defined( _M_IX86 ) && defined(Q_CC_MSVC)
// Disable global optimization and ignore /GS waning caused by
// inline assembly.
// not needed with mingw cause we can tell mingw which registers we use
#pragma optimize("g", off)
#pragma warning(push)
#pragma warning(disable : 4748)
// Disable global optimization and ignore /GS waning caused by
// inline assembly.
// not needed with mingw cause we can tell mingw which registers we use
#pragma optimize("g", off)
#pragma warning(push)
#pragma warning(disable : 4748)
#endif
const QString straceWin::getBacktrace() {
const QString straceWin::getBacktrace()
{
DWORD MachineType;
CONTEXT Context;
STACKFRAME64 StackFrame;
@ -97,14 +102,14 @@ const QString straceWin::getBacktrace() {
#ifdef __MINGW32__
asm("Label:\n\t"
asm ("Label:\n\t"
"movl %%ebp,%0;\n\t"
"movl %%esp,%1;\n\t"
"movl $Label,%%eax;\n\t"
"movl %%eax,%2;\n\t"
:"=r"(Context.Ebp),"=r"(Context.Esp),"=r"(Context.Eip)
://no input
:"eax");
: "=r" (Context.Ebp),"=r" (Context.Esp),"=r" (Context.Eip)
: //no input
: "eax");
#else
_asm {
Label:
@ -141,12 +146,12 @@ const QString straceWin::getBacktrace() {
StackFrame.AddrPC.Mode = AddrModeFlat;
StackFrame.AddrFrame.Offset = Context.IntSp;
StackFrame.AddrFrame.Mode = AddrModeFlat;
StackFrame.AddrBStore.Offset= Context.RsBSP;
StackFrame.AddrBStore.Offset = Context.RsBSP;
StackFrame.AddrBStore.Mode = AddrModeFlat;
StackFrame.AddrStack.Offset = Context.IntSp;
StackFrame.AddrStack.Mode = AddrModeFlat;
#else
#error "Unsupported platform"
#error "Unsupported platform"
#endif
QString log;
@ -160,7 +165,7 @@ const QString straceWin::getBacktrace() {
DWORD64 dwDisplacement;
ULONG64 buffer[(sizeof(SYMBOL_INFO) +
MAX_SYM_NAME*sizeof(TCHAR) +
MAX_SYM_NAME * sizeof(TCHAR) +
sizeof(ULONG64) - 1) / sizeof(ULONG64)];
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
@ -173,6 +178,7 @@ const QString straceWin::getBacktrace() {
ZeroMemory(&ihsf, sizeof(IMAGEHLP_STACK_FRAME));
int i = 0;
while(StackWalk64(MachineType, hProcess, hThread, &StackFrame, &Context, NULL, NULL, NULL, NULL)) {
if(i == 128)
break;
@ -188,11 +194,10 @@ const QString straceWin::getBacktrace() {
fileName = fileName.mid(slashPos + 1);
}
QString funcName;
if(SymFromAddr(hProcess, ihsf.InstructionOffset, &dwDisplacement, pSymbol)) {
if(SymFromAddr(hProcess, ihsf.InstructionOffset, &dwDisplacement, pSymbol))
funcName = QString(pSymbol->Name);
} else {
else
funcName = QString("0x%1").arg(ihsf.InstructionOffset, 8, 16, QLatin1Char('0'));
}
QStringList params;
SymSetContext(hProcess, &ihsf, NULL);
SymEnumSymbols(hProcess, 0, NULL, EnumSymbolsCB, (PVOID)&params);
@ -206,7 +211,8 @@ const QString straceWin::getBacktrace() {
.arg(params.join(", "));
logStream << debugLine << '\n';
i++;
} else {
}
else {
break; // we're at the end.
}
}
@ -218,6 +224,6 @@ const QString straceWin::getBacktrace() {
return log;
}
#if defined(_M_IX86) && defined(Q_CC_MSVC)
#pragma warning(pop)
#pragma optimize("g", on)
#pragma warning(pop)
#pragma optimize("g", on)
#endif

View File

@ -7,17 +7,22 @@
#include "libtorrent/version.hpp"
#include "ui_stacktrace_win_dlg.h"
class StraceDlg : public QDialog, private Ui::errorDialog {
class StraceDlg: public QDialog, private Ui::errorDialog
{
Q_OBJECT
public:
StraceDlg(QWidget *parent = 0): QDialog(parent) {
StraceDlg(QWidget* parent = 0): QDialog(parent)
{
setupUi(this);
}
~StraceDlg() {}
~StraceDlg()
{
}
void setStacktraceString(const QString& trace) {
void setStacktraceString(const QString& trace)
{
QString htmlStr;
QTextStream outStream(&htmlStr);
outStream << "<p align=center><b><font size=7 color=red>" <<