Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build error on VS 2022 #117

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sleepy.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
2 changes: 1 addition & 1 deletion src/copyfiles.bat
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if errorlevel 1 ((@echo Failed to copy dbghelp_*) & (exit /b 1))

if not exist "%DBGHELPERS%\dbghelpw.dll" copy /y "thirdparty\wine\dlls\dbghelp\vs\bin\%PLATFORM%\%CONFIGURATION%\dbghelpw.dll" "%DEST%"
if errorlevel 1 ((@echo Failed to copy dbghelpw.dll) & (exit /b 1))
if %PLATFORM%==x64 if not exist "%DBGHELPERS%\dbghelpw_wow64.dll" copy /y "thirdparty\wine\dlls\dbghelp\vs\bin\%PLATFORM%\%CONFIGURATION% - Wow64\dbghelpw.dll" "%DEST%\dbghelpw_wow64.dll"
if %PLATFORM%==x64 if not exist "%DBGHELPERS%\dbghelpw_wow64.dll" copy /y "thirdparty\wine\dlls\dbghelp\vs\bin\%PLATFORM%\%CONFIGURATION%\dbghelpw.dll" "%DEST%\dbghelpw_wow64.dll"
if errorlevel 1 ((@echo Failed to copy dbghelpw_wow64.dll) & (exit /b 1))

if %PLATFORM%==Win32 set PLATFORM_BITS=32
Expand Down
4 changes: 4 additions & 0 deletions src/crashback/badapp/badapp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
4 changes: 4 additions & 0 deletions src/crashback/client/crashback.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,23 @@
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>false</WholeProgramOptimization>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>false</WholeProgramOptimization>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
4 changes: 4 additions & 0 deletions src/crashback/crashreport/crashreport.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>NotSet</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>NotSet</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>NotSet</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>NotSet</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
79 changes: 78 additions & 1 deletion src/profiler/processinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,83 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../utils/osutils.h"
#include "../utils/except.h"
#include <windows.h>
#include <winternl.h>
#include <tlhelp32.h>

#ifndef STATUS_SUCCESS
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
#endif

static std::wstring GetProcessCommandLine(HANDLE processHandle)
{
std::wstring commandLine;
do {
// NtQueryInformationProcess is an internal function, So, we need to get the address of the function from ntdll
auto pNtQueryInformationProcess = reinterpret_cast<decltype(&::NtQueryInformationProcess)>(
GetProcAddress(GetModuleHandle(L"ntdll"), "NtQueryInformationProcess"));
if (!pNtQueryInformationProcess) break;

PROCESS_BASIC_INFORMATION pbi;
if (pNtQueryInformationProcess(processHandle, ProcessBasicInformation, &pbi, sizeof(pbi), nullptr) != STATUS_SUCCESS)
{
break;
}

// Reading the PEB structure of the process
PEB peb;
if (!ReadProcessMemory(processHandle, pbi.PebBaseAddress, &peb, sizeof(peb), nullptr))
{
break;
}

// Reading the process parameters structure
RTL_USER_PROCESS_PARAMETERS upp;
if (!ReadProcessMemory(processHandle, peb.ProcessParameters, &upp, sizeof(upp), nullptr))
{
break;
}

commandLine.resize(upp.CommandLine.Length);
ReadProcessMemory(processHandle, upp.CommandLine.Buffer, &commandLine[0], upp.CommandLine.Length, nullptr);
} while (0);

return commandLine;
}

static bool IsMainWindow(HWND hWnd)
{
return GetWindow(hWnd, GW_OWNER) == nullptr && IsWindowVisible(hWnd);
}

struct EnumWindowInfo
{
DWORD pid;
HWND hWndFound;
};

static BOOL CALLBACK EnumWindowsCallback(HWND hWnd, LPARAM lParam)
{
EnumWindowInfo* info = reinterpret_cast<EnumWindowInfo*>(lParam);
DWORD pid = 0;
GetWindowThreadProcessId(hWnd, &pid);

if (pid != info->pid) return TRUE;
if (!IsMainWindow(hWnd)) return TRUE;
info->hWndFound = hWnd;
return FALSE;
}

std::wstring GetProcessMainWindowTitle(DWORD pid)
{
EnumWindowInfo info = {pid, nullptr};
EnumWindows(EnumWindowsCallback, reinterpret_cast<LPARAM>(&info));
if (info.hWndFound == nullptr) return {};
std::wstring title(256, '\0');
int len = GetWindowTextW(info.hWndFound, &title[0], static_cast<int>(title.size()));
title.resize(len);
return title;
}

ProcessInfo::ProcessInfo(DWORD id_, const std::wstring& name_, HANDLE process_handle_)
: id(id_),
name(name_),
Expand All @@ -40,6 +115,8 @@ ProcessInfo::ProcessInfo(DWORD id_, const std::wstring& name_, HANDLE process_ha
#ifdef _WIN64
is64Bits = Is64BitProcess(process_handle);
#endif
title = GetProcessMainWindowTitle(id);
commandLine = GetProcessCommandLine(process_handle);
}

ProcessInfo::~ProcessInfo()
Expand Down Expand Up @@ -133,4 +210,4 @@ ProcessInfo ProcessInfo::FindProcessById(DWORD process_id)
return process;
}
throw SleepyException("Could not found process with specified id: " + std::to_string((unsigned long long) process_id));
}
}
4 changes: 4 additions & 0 deletions src/profiler/processinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class ProcessInfo
#ifdef _WIN64
bool getIs64Bits() const { return is64Bits; }
#endif
const std::wstring& getTitle() const { return title; }
const std::wstring& getCommandLine() const { return commandLine; }
FILETIME prevKernelTime, prevUserTime;
int cpuUsage;
__int64 totalCpuTimeMs;
Expand All @@ -69,6 +71,8 @@ class ProcessInfo
#ifdef _WIN64
bool is64Bits;
#endif
std::wstring title;
std::wstring commandLine;
};


Expand Down
6 changes: 3 additions & 3 deletions src/profiler/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void applyHacks(HANDLE process_handle, CONTEXT32 &context)

// First, skip over any stub functions (a useless push/mov/pop header, followed by a jump).
// Move instead to the jump target.
if (ReadProcessMemory(process_handle, (LPCVOID)context.Eip, tmp, 16, &numRead) && numRead >= 16)
if (ReadProcessMemory(process_handle, (LPCVOID)(DWORD64)context.Eip, tmp, 16, &numRead) && numRead >= 16)
{
int n = 0;

Expand All @@ -136,13 +136,13 @@ void applyHacks(HANDLE process_handle, CONTEXT32 &context)
}

// Skip over any jmp [__imp__blah] thunks.
if (ReadProcessMemory(process_handle, (LPCVOID)context.Eip, tmp, 16, &numRead) && numRead >= 16)
if (ReadProcessMemory(process_handle, (LPCVOID)(DWORD64)context.Eip, tmp, 16, &numRead) && numRead >= 16)
{
// Look for "jmp [foo]", and move the IP forward to '[foo]'.
if (tmp[0] == 0xff && tmp[1] == 0x25)
{
DWORD ptr = (tmp[5] << 24) | (tmp[4] << 16) | (tmp[3] << 8) | (tmp[2] << 0);
if (ReadProcessMemory(process_handle, (LPCVOID)ptr, tmp, 4, &numRead) && numRead >= 4)
if (ReadProcessMemory(process_handle, (LPCVOID)(DWORD64)ptr, tmp, 4, &numRead) && numRead >= 4)
{
context.Eip = (tmp[3] << 24) | (tmp[2] << 16) | (tmp[1] << 8) | (tmp[0] << 0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/profiler/symbolinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void SymbolInfo::loadSymbolsUsing(DbgHelp* dbgHelp, const std::wstring& sympath)
{
// This is a secondary dbgHelp, so just complement debug
// information for modules that have none.

for (size_t m=0;m<modules.size();m++)
{
Module &mod = modules[m];
Expand Down
15 changes: 11 additions & 4 deletions src/utils/except.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,37 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#pragma once

#include <codecvt>
#include <locale>
#include <stdexcept>
#include <string>

class SleepyException : public std::runtime_error
{
std::wstring _what;

std::string helper(const wchar_t *what)
std::string helper(const std::wstring& what)
{
// Need a temporary to build std::string.
// Can't use _what in initialization-list because
// it will always be initialized after the superclass.
// Can't use _what here because it is still not initialized
// and contains junk.
std::wstring ws(what);
return std::string(ws.begin(), ws.end());

// setup converter
using convert_type = std::codecvt_utf8<wchar_t>;
std::wstring_convert<convert_type, wchar_t> converter;

// use converter (.to_bytes: wstr->str, .from_bytes: str->wstr)
return converter.to_bytes(what);;
}

public:
SleepyException(const std::string &what)
: std::runtime_error(what), _what(std::wstring(what.begin(), what.end())) {}

SleepyException(const std::wstring &what)
: std::runtime_error(std::string(what.begin(), what.end())), _what(what) {}
: std::runtime_error(helper(what)), _what(what) {}

SleepyException(const wchar_t *what)
: std::runtime_error(helper(what)), _what(what) {}
Expand Down
51 changes: 51 additions & 0 deletions src/wxProfilerGUI/processlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ ProcessList::ProcessList(wxWindow *parent, const wxPoint& pos,
InsertColumn(COL_TOTALCPU, itemCol);
itemCol.m_text = _T("PID");
InsertColumn(COL_PID, itemCol);
itemCol.m_text = _T("Title");
InsertColumn(COL_TITLE, itemCol);
itemCol.m_text = _T("Command Line");
InsertColumn(COL_COMMANDLINE, itemCol);

SetColumnWidth(COL_NAME, FromDIP(270));
#ifdef _WIN64
Expand All @@ -71,6 +75,8 @@ ProcessList::ProcessList(wxWindow *parent, const wxPoint& pos,
SetColumnWidth(COL_CPUUSAGE, FromDIP(50));
SetColumnWidth(COL_TOTALCPU, FromDIP(70));
SetColumnWidth(COL_PID, FromDIP(50));
SetColumnWidth(COL_TITLE, FromDIP(200));
SetColumnWidth(COL_COMMANDLINE, FromDIP(500));

sort_column = COL_CPUUSAGE;
sort_dir = SORT_DOWN;
Expand Down Expand Up @@ -232,6 +238,30 @@ struct TypeDescPred { bool operator () (const ProcessInfo &a, const ProcessInfo
} };
#endif

struct TitleAscPred {
bool operator () (const ProcessInfo& a, const ProcessInfo& b) {
return wcsicmp(a.getTitle().c_str(), b.getTitle().c_str()) < 0;
}
};

struct TitleDescPred {
bool operator () (const ProcessInfo& a, const ProcessInfo& b) {
return wcsicmp(a.getTitle().c_str(), b.getTitle().c_str()) > 0;
}
};

struct CommandLineAscPred {
bool operator () (const ProcessInfo& a, const ProcessInfo& b) {
return wcsicmp(a.getCommandLine().c_str(), b.getCommandLine().c_str()) < 0;
}
};

struct CommandLineDescPred {
bool operator () (const ProcessInfo& a, const ProcessInfo& b) {
return wcsicmp(a.getCommandLine().c_str(), b.getCommandLine().c_str()) > 0;
}
};

void ProcessList::sortByName()
{
if (sort_dir == SORT_UP)
Expand Down Expand Up @@ -273,6 +303,23 @@ void ProcessList::sortByType()
std::stable_sort(processes.begin(), processes.end(), TypeDescPred());
}
#endif

void ProcessList::sortByTitle()
{
if (sort_dir == SORT_UP)
std::stable_sort(processes.begin(), processes.end(), TitleAscPred());
else
std::stable_sort(processes.begin(), processes.end(), TitleDescPred());
}

void ProcessList::sortByCommandLine()
{
if (sort_dir == SORT_UP)
std::stable_sort(processes.begin(), processes.end(), CommandLineAscPred());
else
std::stable_sort(processes.begin(), processes.end(), CommandLineDescPred());
}

void ProcessList::OnSort(wxListEvent& event)
{
SetSortImage(sort_column, SORT_NONE);
Expand Down Expand Up @@ -301,6 +348,8 @@ void ProcessList::updateSorting()
#ifdef _WIN64
case COL_TYPE: sortByType(); break;
#endif
case COL_TITLE: sortByTitle(); break;
case COL_COMMANDLINE: sortByCommandLine(); break;
}
fillList();
}
Expand Down Expand Up @@ -334,6 +383,8 @@ void ProcessList::fillList()
SetItem(i,COL_TYPE,"32-bit");
}
#endif
this->SetItem(i, COL_TITLE, processes[i].getTitle());
this->SetItem(i, COL_COMMANDLINE, processes[i].getCommandLine());
}
Thaw();
}
Expand Down
Loading