Compare commits

...

11 Commits

Author SHA1 Message Date
Jose Fonseca
4a7e249ce3 cmake: Bump to version 0.9.11. 2023-04-24 13:21:30 +01:00
oltolm
123a9eee93 cmake: modernize cmake code and remove unnecessary arguments from toolchain files. 2023-04-23 12:02:27 +01:00
oltolm
a85f4eb103 add additional test cases to test_mgwhelp.cpp 2023-04-23 11:27:17 +01:00
oltolm
45923dd10d cmake: modernize cmake code
v2: Remove troublesome chunks -- Jose
2023-04-23 11:25:13 +01:00
Jose Fonseca
5b28368407 Unbreak ARM64 processes. 2023-04-23 09:53:35 +01:00
oltolm
a36c7dcb1a fix GCC warnings 2023-04-16 15:27:57 +01:00
Jose Fonseca
c8c8680df9 ci: Use codecov github action. 2023-04-13 12:59:33 +01:00
Jose Fonseca
891b059432 ci: Temporarily disable codecov.
codecov was outright removed from pypi!
https://community.codecov.com/t/codecov-yanked-from-pypi-all-versions/4259
2023-04-12 15:49:08 +01:00
Jose Fonseca
6ac80ae8f6 cmake: Bump to version 0.9.10. 2023-04-12 15:06:59 +01:00
Jose Fonseca
4af9f7c4cd Handle X86 32bits processes on Arm. 2023-04-10 15:02:17 +01:00
Jose Fonseca
16ede70ec4 Drop Arm32 support.
According to https://learn.microsoft.com/en-us/windows/arm/arm32-to-arm64
"Support for 32-bit Arm versions of applications will be removed in a
future release of Windows 11."
2023-04-09 16:47:03 +01:00

View File

@ -20,11 +20,18 @@ jobs:
path: downloads/*.7z
key: ${{ runner.os }}-${{ matrix.target }}-mingw-12.2.0-win32-dbghelp-10.0.18362.1
- run: Get-Host | Select-Object Version
- run: python -m pip install gcovr codecov
- run: python -m pip install gcovr
- name: Build
run: .\ci\build.ps1 -target ${{ matrix.target }} -coverage
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: codecov
uses: codecov/codecov-action@v3
if: "!(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))"
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: cobertura.xml
functionalities: search
fail_ci_if_error: true
verbose: false
- name: Upload artifact
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v3
@ -101,11 +108,8 @@ jobs:
"mingw64-path=$($asset64.FullName)" >> $Env:GITHUB_OUTPUT
"mingw32-name=$($asset32.Name)" >> $Env:GITHUB_OUTPUT
"mingw64-name=$($asset64.Name)" >> $Env:GITHUB_OUTPUT
$asset32arm = Get-Item "${{ steps.download.outputs.download-path }}\drmingw-clang\armv7-w64-mingw32-clang\*.7z"
$asset64arm = Get-Item "${{ steps.download.outputs.download-path }}\drmingw-clang\aarch64-w64-mingw32-clang\*.7z"
"mingw32-arm-path=$($asset32arm.FullName)" >> $Env:GITHUB_OUTPUT
"mingw64-arm-path=$($asset64arm.FullName)" >> $Env:GITHUB_OUTPUT
"mingw32-arm-name=$($asset32arm.Name)" >> $Env:GITHUB_OUTPUT
"mingw64-arm-name=$($asset64arm.Name)" >> $Env:GITHUB_OUTPUT
- name: Create Release
id: create_release
@ -135,15 +139,6 @@ jobs:
asset_path: ${{ steps.assets.outputs.mingw64-path }}
asset_name: ${{ steps.assets.outputs.mingw64-name }}
asset_content_type: application/x-7z-compressed
- name: Upload Release Asset (32bits Arm)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.assets.outputs.mingw32-arm-path }}
asset_name: ${{ steps.assets.outputs.mingw32-arm-name }}
asset_content_type: application/x-7z-compressed
- name: Upload Release Asset (64bits Arm)
uses: actions/upload-release-asset@v1
env:

View File

@ -4,16 +4,13 @@ cmake_minimum_required (VERSION 3.16)
cmake_policy (SET CMP0091 NEW)
project (drmingw)
set (CPACK_PACKAGE_VERSION_MAJOR "0")
set (CPACK_PACKAGE_VERSION_MINOR "9")
set (CPACK_PACKAGE_VERSION_PATCH "9")
project (drmingw
VERSION 0.9.11
LANGUAGES C CXX
)
option (ENABLE_COVERAGE "Enable code coverage." OFF)
option (POSIX_THREADS "Allow posix threads." OFF)
##############################################################################
@ -44,31 +41,18 @@ set (CXX_STANDARD_REQUIRED ON)
include (CheckCXXCompilerFlag)
macro (add_compiler_flags)
string (REPLACE ";" " " _FLAGS "${ARGV}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_FLAGS}")
endmacro ()
macro (add_linker_flags)
string (REPLACE ";" " " _FLAGS "${ARGV}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_FLAGS}")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${_FLAGS}")
set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${_FLAGS}")
endmacro ()
# Adjust warnings
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror=implicit-function-declaration -Werror=missing-prototypes")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
add_compile_options (-Wall "$<$<COMPILE_LANGUAGE:C>:-Werror=implicit-function-declaration -Werror=missing-prototypes>")
# Disable strict aliasing rules
add_compiler_flags (-fno-strict-aliasing)
add_compile_options (-fno-strict-aliasing)
include (StaticCRT)
# Avoid Posix threads. Posix threads is required for support of certain C++11
# multi-threading features, but it introduces a new DLL dependency and we don't
# use those features.
# https://github.com/jrfonseca/drmingw/issues/82#issuecomment-1360081041
execute_process (
COMMAND "${CMAKE_COMMAND}" -E echo "#include <thread>\n#ifdef _GLIBCXX_HAS_GTHREADS\n#error _GLIBCXX_HAS_GTHREADS\n#endif"
COMMAND "${CMAKE_CXX_COMPILER}" -x c++ -E -
@ -77,30 +61,22 @@ execute_process (
ERROR_QUIET
)
if (NOT STATUS_CXX11_THREADS EQUAL 0)
if (POSIX_THREADS)
message (WARNING "Win32 threads recommended.")
else ()
message (SEND_ERROR "Win32 threads required.")
endif ()
message (SEND_ERROR "Win32 threads required.")
endif ()
# Enable stack protection
# XXX: Broken on https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86832
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0" OR
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "8.3")
add_compiler_flags (-fstack-protector-all)
# MinGW doesn't link against libssp automatically, and furthermore
# we want static linking.
set (SSP_LIBRARY "-Wl,-Bstatic -lssp -Wl,-Bdynamic")
set (CMAKE_C_STANDARD_LIBRARIES "${SSP_LIBRARY} ${CMAKE_C_STANDARD_LIBRARIES}")
set (CMAKE_CXX_STANDARD_LIBRARIES "${SSP_LIBRARY} ${CMAKE_CXX_STANDARD_LIBRARIES}")
add_compile_options (-fstack-protector-all)
# MinGW doesn't link against libssp automatically.
link_libraries (ssp)
endif ()
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
add_definitions (-DHAVE_WIN64=1)
add_compile_definitions (HAVE_WIN64=1)
else ()
add_linker_flags (-Wl,--enable-stdcall-fixup)
add_definitions (-DHAVE_WIN64=0)
add_compile_definitions (HAVE_WIN64=0)
endif ()
# Require Windows 10 for Windows on ARM, Windows 7 for all else
@ -115,17 +91,17 @@ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
add_definitions (
add_compile_definitions (
# http://msdn.microsoft.com/en-us/library/aa383745.aspx
-D_WIN32_WINNT=${WINNT}
-DWINVER=${WINNT}
_WIN32_WINNT=${WINNT}
WINVER=${WINNT}
# https://msdn.microsoft.com/en-gb/library/windows/desktop/ms683198.aspx
-DPSAPI_VERSION=2
PSAPI_VERSION=2
# version
-DPACKAGE_VERSION_MAJOR=${CPACK_PACKAGE_VERSION_MAJOR}
-DPACKAGE_VERSION_MINOR=${CPACK_PACKAGE_VERSION_MINOR}
-DPACKAGE_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH}
PACKAGE_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
PACKAGE_VERSION_MINOR=${PROJECT_VERSION_MINOR}
PACKAGE_VERSION_PATCH=${PROJECT_VERSION_PATCH}
)
# Macro to force using debug flags, regardless of the current build type

View File

@ -63,8 +63,7 @@ fi
for target in \
x86_64-w64-mingw32-clang \
i686-w64-mingw32-clang \
aarch64-w64-mingw32-clang \
armv7-w64-mingw32-clang
aarch64-w64-mingw32-clang
do
toolchain=$PWD/ci/toolchain/$target.cmake

View File

@ -149,9 +149,8 @@ if ($target -eq "mingw64") {
#
if ($coverage) {
Exec { gcov --version }
if (Test-Path Env:CODECOV_TOKEN) {
if ($Env:GITHUB_ACTIONS -eq "true") {
Exec { python -m gcovr --exclude-unreachable-branches --exclude-throw-branches --object-directory $buildDir --xml -o "cobertura.xml" }
Exec { python -m codecov --file cobertura.xml -X gcov search }
} else {
Exec { python -m gcovr --exclude-unreachable-branches --exclude-throw-branches --object-directory $buildDir --html-details -o "$buildDir\coverage.html" }
}

View File

@ -18,7 +18,3 @@ set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
# Statically link CRT
set (CMAKE_C_FLAGS "--start-no-unused-arguments -Wl,-Bstatic -lunwind -Wl,-Bdynamic --end-no-unused-arguments")
set (CMAKE_CXX_FLAGS "--start-no-unused-arguments -static-libstdc++ -Wl,-Bstatic -lunwind -Wl,-Bdynamic --end-no-unused-arguments")

View File

@ -1,24 +0,0 @@
# https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html
set (CMAKE_SYSTEM_NAME Windows)
set (CMAKE_SYSTEM_PROCESSOR ARM)
set (triple armv7-w64-mingw32)
set (CMAKE_C_COMPILER ${triple}-clang)
set (CMAKE_CXX_COMPILER ${triple}-clang++)
set (CMAKE_RC_COMPILER ${triple}-windres)
set (CMAKE_DLLTOOL ${triple}-dlltool)
set (CMAKE_ADDR2LINE ${triple}-addr2line)
set (CMAKE_AR ${triple}-ar)
set (CMAKE_NM ${triple}-nm)
set (CMAKE_OBJCOPY ${triple}-objcopy)
set (CMAKE_OBJDUMP ${triple}-objdump)
set (CMAKE_RANLIB ${triple}-ranlib)
set (CMAKE_READELF ${triple}-readelf)
set (CMAKE_STRIP ${triple}-strip)
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
# Statically link CRT
set (CMAKE_C_FLAGS "--start-no-unused-arguments -Wl,-Bstatic -lunwind -Wl,-Bdynamic --end-no-unused-arguments")
set (CMAKE_CXX_FLAGS "--start-no-unused-arguments -static-libstdc++ -Wl,-Bstatic -lunwind -Wl,-Bdynamic --end-no-unused-arguments")

View File

@ -18,7 +18,3 @@ set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
# Statically link CRT
set (CMAKE_C_FLAGS "--start-no-unused-arguments -Wl,-Bstatic -lunwind -Wl,-Bdynamic --end-no-unused-arguments")
set (CMAKE_CXX_FLAGS "--start-no-unused-arguments -static-libstdc++ -Wl,-Bstatic -lunwind -Wl,-Bdynamic --end-no-unused-arguments")

View File

@ -18,7 +18,3 @@ set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
# Statically link CRT
set (CMAKE_C_FLAGS "--start-no-unused-arguments -Wl,-Bstatic -lunwind -Wl,-Bdynamic --end-no-unused-arguments")
set (CMAKE_CXX_FLAGS "--start-no-unused-arguments -static-libstdc++ -Wl,-Bstatic -lunwind -Wl,-Bdynamic --end-no-unused-arguments")

View File

@ -2,35 +2,9 @@ include (CheckCXXCompilerFlag)
if (MINGW)
# Avoid depending on MinGW runtime DLLs
add_link_options (-static)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
check_cxx_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
if (HAVE_STATIC_LIBGCC_FLAG)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
endif ()
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
check_cxx_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
if (HAVE_STATIC_LIBSTDCXX_FLAG)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
endif ()
# Statically link Posix threads when detected.
execute_process (
COMMAND "${CMAKE_COMMAND}" -E echo "#include <thread>\n#ifdef _GLIBCXX_HAS_GTHREADS\n#error _GLIBCXX_HAS_GTHREADS\n#endif"
COMMAND "${CMAKE_CXX_COMPILER}" -x c++ -E -
RESULT_VARIABLE STATUS_CXX11_THREADS
OUTPUT_QUIET
ERROR_QUIET
)
if (NOT STATUS_CXX11_THREADS EQUAL 0)
# https://stackoverflow.com/a/28001271
# XXX Unfortunately this doesn't work for Release builds, https://github.com/jrfonseca/drmingw/issues/82
set (CMAKE_CXX_STANDARD_LIBRARIES "-Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic ${CMAKE_CXX_STANDARD_LIBRARIES}")
endif ()
add_link_options (-static-libgcc -static-libstdc++)
endif ()
endif ()

View File

@ -4,7 +4,7 @@ add_executable (sample
sample.cpp
)
add_dependencies (sample exchndl_implib)
target_link_libraries (sample exchndl_implib)
target_link_libraries (sample PRIVATE exchndl_implib)
install (FILES sample.cpp DESTINATION sample)
install (FILES sample.mak DESTINATION sample RENAME Makefile)

View File

@ -1,6 +1,6 @@
if (ENABLE_COVERAGE)
add_compiler_flags (--coverage)
add_linker_flags (--coverage)
add_compile_options (--coverage)
add_link_options (--coverage)
endif ()
include_directories (

View File

@ -4,7 +4,7 @@ add_library (common STATIC
symbols.cpp
)
target_link_libraries (common LINK_PRIVATE
target_link_libraries (common PRIVATE
psapi
version
)

View File

@ -91,39 +91,12 @@ dumpSourceCode(LPCSTR lpFileName, DWORD dwLineNumber);
static void
dumpContext(
#if defined(_M_ARM64) || defined(_M_ARM)
const CONTEXT *pContext
#elif defined(_WIN64)
const WOW64_CONTEXT *pContext
#else
const CONTEXT *pContext
#endif
)
dumpContext(const WOW64_CONTEXT *pContext)
{
// Show the registers
lprintf("Registers:\n");
#if defined(_M_ARM64)
if (pContext->ContextFlags & CONTEXT_INTEGER) {
for(int i = 0 ; i < 28 ; i += 4)
{
lprintf("X%d=%016I64X X%d=%016I64X X%d=%016I64X X%d=%016I64X\n", i, pContext->X[i],
i+1, pContext->X[i+1], i+2, pContext->X[i+2], i+3, pContext->X[i+3]);
}
lprintf("X%d=%016I64X\n", 28, pContext->X[28]);
}
if (pContext->ContextFlags & CONTEXT_CONTROL) {
lprintf("pc=%016I64X sp=%016I64X fp=%016I64X \n",
pContext->Pc, pContext->Sp, pContext->Fp);
}
#elif defined(_M_ARM)
#else
if (pContext->ContextFlags & CONTEXT_INTEGER) {
if (pContext->ContextFlags & WOW64_CONTEXT_INTEGER) {
lprintf("eax=%08lx ebx=%08lx ecx=%08lx edx=%08lx esi=%08lx edi=%08lx\n", pContext->Eax,
pContext->Ebx, pContext->Ecx, pContext->Edx, pContext->Esi, pContext->Edi);
}
@ -143,25 +116,57 @@ dumpContext(
pContext->EFlags & 0x00000001 ? "cy" : "nc" // CF (carry flag)
);
}
if (pContext->ContextFlags & CONTEXT_SEGMENTS) {
if (pContext->ContextFlags & WOW64_CONTEXT_SEGMENTS) {
lprintf("cs=%04lx ss=%04lx ds=%04lx es=%04lx fs=%04lx gs=%04lx", pContext->SegCs,
pContext->SegSs, pContext->SegDs, pContext->SegEs, pContext->SegFs,
pContext->SegGs);
if (pContext->ContextFlags & CONTEXT_CONTROL) {
if (pContext->ContextFlags & WOW64_CONTEXT_CONTROL) {
lprintf(" efl=%08lx", pContext->EFlags);
}
} else {
if (pContext->ContextFlags & CONTEXT_CONTROL) {
if (pContext->ContextFlags & WOW64_CONTEXT_CONTROL) {
lprintf(" "
"efl=%08lx",
pContext->EFlags);
}
}
#endif
lprintf("\n\n");
}
static void
dumpContext(const CONTEXT *pContext)
{
#if defined(_M_IX86)
dumpContext(reinterpret_cast<const WOW64_CONTEXT *>(pContext));
#elif defined(_M_X64)
// TODO
#elif defined(_M_ARM64)
if (pContext->ContextFlags & CONTEXT_INTEGER) {
for (unsigned i = 0 ; i < 28 ; i += 4) {
lprintf("X%d=%016I64X X%d=%016I64X X%d=%016I64X X%d=%016I64X\n", i, pContext->X[i],
i+1, pContext->X[i+1], i+2, pContext->X[i+2], i+3, pContext->X[i+3]);
}
lprintf("X%d=%016I64X\n", 28, pContext->X[28]);
}
if (pContext->ContextFlags & CONTEXT_CONTROL) {
lprintf("pc=%016I64X sp=%016I64X fp=%016I64X \n",
pContext->Pc, pContext->Sp, pContext->Fp);
}
lprintf("\n\n");
#else
#error
#endif
}
typedef BOOL (WINAPI * PFN_GETPROCESSINFORMATION)(HANDLE, PROCESS_INFORMATION_CLASS, LPVOID, DWORD);
void
dumpStack(HANDLE hProcess, HANDLE hThread, const CONTEXT *pContext)
{
@ -173,24 +178,63 @@ dumpStack(HANDLE hProcess, HANDLE hThread, const CONTEXT *pContext)
ZeroMemory(&StackFrame, sizeof StackFrame);
#if defined(_M_ARM64)
USHORT processArch = 0;
USHORT machineArch = 0;
IsWow64Process2(hProcess, &processArch, &machineArch);
assert((pContext->ContextFlags & CONTEXT_FULL) == CONTEXT_FULL);
MachineType = IMAGE_FILE_MACHINE_ARM64;
dumpContext(pContext);
StackFrame.AddrPC.Offset = pContext->Pc;
StackFrame.AddrStack.Offset = pContext->Sp;
StackFrame.AddrFrame.Offset = pContext->Fp;
#elif defined(_M_ARM)
assert((pContext->ContextFlags & CONTEXT_FULL) == CONTEXT_FULL);
MachineType = IMAGE_FILE_MACHINE_ARMNT;
dumpContext(pContext);
StackFrame.AddrPC.Offset = pContext->Pc;
StackFrame.AddrStack.Offset = pContext->Sp;
StackFrame.AddrFrame.Offset = pContext->R11;
USHORT processArch = IMAGE_FILE_MACHINE_UNKNOWN;
USHORT nativeArch = IMAGE_FILE_MACHINE_UNKNOWN;
BOOL bRet = IsWow64Process2(hProcess, &processArch, &nativeArch);
if (!bRet) {
lprintf("warning: IsWow64Process2 failed (0x%08lx)\n", GetLastError());
return;
}
if (processArch == IMAGE_FILE_MACHINE_UNKNOWN) {
// Not a WOW64 process -- use GetProcessInformation
// https://learn.microsoft.com/en-us/answers/questions/449019/detect-x86-64-process-on-arm64
HMODULE hKernelModule = GetModuleHandleA("kernel32");
assert(hKernelModule != nullptr);
PFN_GETPROCESSINFORMATION pfnGetProcessInformation =
(PFN_GETPROCESSINFORMATION)GetProcAddress(hKernelModule, "GetProcessInformation");
assert(pfnGetProcessInformation != nullptr);
PROCESS_MACHINE_INFORMATION processMachineInfo = { 0 };
if (pfnGetProcessInformation(hProcess, ProcessMachineTypeInfo, &processMachineInfo, sizeof processMachineInfo)) {
processArch = processMachineInfo.ProcessMachine;
} else {
processArch = nativeArch;
}
}
if (processArch == IMAGE_FILE_MACHINE_ARM64) {
assert((pContext->ContextFlags & CONTEXT_FULL) == CONTEXT_FULL);
MachineType = IMAGE_FILE_MACHINE_ARM64;
dumpContext(pContext);
StackFrame.AddrPC.Offset = pContext->Pc;
StackFrame.AddrStack.Offset = pContext->Sp;
StackFrame.AddrFrame.Offset = pContext->Fp;
} else if (processArch == IMAGE_FILE_MACHINE_AMD64) {
// XXX: Unfortunate pContext is _not_ an AMD64 context, so StackWalk will fail
assert((pContext->ContextFlags & CONTEXT_FULL) == CONTEXT_FULL);
MachineType = IMAGE_FILE_MACHINE_ARM64;
dumpContext(pContext);
StackFrame.AddrPC.Offset = pContext->Pc;
StackFrame.AddrStack.Offset = pContext->Sp;
StackFrame.AddrFrame.Offset = pContext->Fp;
} else if (processArch == IMAGE_FILE_MACHINE_I386) {
const WOW64_CONTEXT *pWow64Context = reinterpret_cast<const WOW64_CONTEXT *>(pContext);
// NOLINTNEXTLINE(clang-analyzer-core.NullDereference)
assert((pWow64Context->ContextFlags & WOW64_CONTEXT_FULL) == WOW64_CONTEXT_FULL);
dumpContext(pWow64Context);
MachineType = IMAGE_FILE_MACHINE_I386;
StackFrame.AddrPC.Offset = pWow64Context->Eip;
StackFrame.AddrStack.Offset = pWow64Context->Esp;
StackFrame.AddrFrame.Offset = pWow64Context->Ebp;
} else {
lprintf("error: unsupported process architecture 0x%04x !\n", processArch);
return;
}
#else
BOOL bWow64 = FALSE;
if (HAVE_WIN64) {
IsWow64Process(hProcess, &bWow64);
@ -199,9 +243,7 @@ dumpStack(HANDLE hProcess, HANDLE hThread, const CONTEXT *pContext)
const WOW64_CONTEXT *pWow64Context = reinterpret_cast<const WOW64_CONTEXT *>(pContext);
// NOLINTNEXTLINE(clang-analyzer-core.NullDereference)
assert((pWow64Context->ContextFlags & WOW64_CONTEXT_FULL) == WOW64_CONTEXT_FULL);
#ifdef _WIN64
dumpContext(pWow64Context);
#endif
MachineType = IMAGE_FILE_MACHINE_I386;
StackFrame.AddrPC.Offset = pWow64Context->Eip;
StackFrame.AddrStack.Offset = pWow64Context->Esp;
@ -209,9 +251,9 @@ dumpStack(HANDLE hProcess, HANDLE hThread, const CONTEXT *pContext)
} else {
// NOLINTNEXTLINE(clang-analyzer-core.NullDereference)
assert((pContext->ContextFlags & CONTEXT_FULL) == CONTEXT_FULL);
dumpContext(pContext);
#ifndef _WIN64
MachineType = IMAGE_FILE_MACHINE_I386;
dumpContext(pContext);
StackFrame.AddrPC.Offset = pContext->Eip;
StackFrame.AddrStack.Offset = pContext->Esp;
StackFrame.AddrFrame.Offset = pContext->Ebp;
@ -222,6 +264,7 @@ dumpStack(HANDLE hProcess, HANDLE hThread, const CONTEXT *pContext)
StackFrame.AddrFrame.Offset = pContext->Rbp;
#endif
}
#endif
StackFrame.AddrPC.Mode = AddrModeFlat;

View File

@ -5,8 +5,9 @@ add_executable (drmingw WIN32
resource.rc
)
set_target_properties (drmingw PROPERTIES
COMPILE_DEFINITIONS "PACKAGE=\"DrMingw\";VERSION=\"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}\""
target_compile_definitions (drmingw PRIVATE
PACKAGE="DrMingw"
VERSION="${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}"
)
add_dependencies (drmingw mgwhelp_implib)

View File

@ -25,7 +25,7 @@ target_sources (exchndl PRIVATE
add_dependencies (exchndl mgwhelp_implib)
target_link_libraries (exchndl LINK_PRIVATE
target_link_libraries (exchndl PRIVATE
common
mgwhelp_implib
)

View File

@ -90,7 +90,7 @@ GenerateExceptionReport(PEXCEPTION_POINTERS pExceptionInfo)
// XXX: In 64-bits WINE we can get context record that don't match the
// exception record somehow
#if defined(_M_ARM64) || defined(_M_ARM)
#if defined(_M_ARM64)
PVOID ip = (PVOID)pContext->Pc;
#elif defined(_WIN64)
PVOID ip = (PVOID)pContext->Rip;

View File

@ -25,7 +25,7 @@ target_sources (mgwhelp PRIVATE
version.rc
)
target_link_libraries (mgwhelp LINK_PRIVATE
target_link_libraries (mgwhelp PRIVATE
common
dwarf
libiberty

View File

@ -221,7 +221,9 @@ dwarf_pe_init(HANDLE hFile,
if (strcmp(doas.as_name, ".gnu_debuglink") == 0) {
Dwarf_Small *data;
pe_load_section(pe_obj, section_index, &data, &err);
if (DW_DLV_OK != pe_load_section(pe_obj, section_index, &data, &err)) {
continue;
}
const char *debuglink = (const char *)data;
std::vector<std::string> debugSearchDirs;

View File

@ -241,6 +241,7 @@ mgwhelp_module_create(struct mgwhelp_process *process, HANDLE hFile, PCSTR Image
if (ImageName) {
strncpy(module->LoadedImageName, ImageName, sizeof module->LoadedImageName);
module->LoadedImageName[MAX_PATH - 1] = '\0';
} else {
/* SymGetModuleInfo64 is not reliable for this, as explained in
* https://msdn.microsoft.com/en-us/library/windows/desktop/ms681336.aspx
@ -618,6 +619,7 @@ MgwSymGetLineFromAddr64(HANDLE hProcess,
if (dwarf_find_line(&module->dwarf, Offset, &info)) {
static char buf[1024];
strncpy(buf, info.filename.c_str(), sizeof buf);
buf[sizeof(buf) - 1] = '\0';
Line->FileName = buf;
Line->LineNumber = info.line;

View File

@ -188,7 +188,7 @@ if (OBJCOPY_VERSION STREQUAL "llvm-objcopy")
else ()
add_dependencies (check test_mgwhelp_zdebug)
endif ()
if (OBJCOPY_VERSION STREQUAL "llvm-objcopy" OR NOT OBJCOPY_VERSION VERSION_GREATER_EQUAL "2.34")
if (OBJCOPY_VERSION STREQUAL "llvm-objcopy" OR OBJCOPY_VERSION VERSION_LESS "2.34")
set_tests_properties (test_mgwhelp_zdebug PROPERTIES DISABLED ON)
endif ()

View File

@ -134,7 +134,7 @@ add_test_executable (ud2 ud2.c)
if (MINGW)
target_compile_options (stack_buffer_overflow PRIVATE -fstack-protector-all)
target_link_options (stack_buffer_overflow PRIVATE -fstack-protector-all)
target_link_libraries (stack_buffer_overflow PRIVATE -Wl,-Bstatic -lssp -Wl,-Bdynamic)
target_link_libraries (stack_buffer_overflow PRIVATE ssp)
endif ()
if (MSVC)
target_compile_options (stack_buffer_overflow PRIVATE /GS)

View File

@ -190,6 +190,10 @@ main(int argc, char **argv)
if (!hMgwHelpDll) {
test_line(false, "GetModuleHandleA(\"mgwhelp.dll\")");
} else {
test_line(GetProcAddress(hMgwHelpDll, "SymInitialize") != NULL, "GetProcAddress(\"SymInitialize\")");
test_line(GetProcAddress(hMgwHelpDll, "SymInitialize@12") == NULL, "!GetProcAddress(\"SymInitialize\")");
test_line(GetProcAddress(hMgwHelpDll, "EnumDirTree") != NULL, "GetProcAddress(\"EnumDirTree\")");
test_line(GetProcAddress(hMgwHelpDll, "EnumDirTree@24") == NULL, "!GetProcAddress(\"EnumDirTree\")");
test_line(GetProcAddress(hMgwHelpDll, "SymGetOptions") != NULL, "GetProcAddress(\"SymGetOptions\")");
test_line(GetProcAddress(hMgwHelpDll, "SymGetOptions@0") == NULL, "!GetProcAddress(\"SymGetOptions\")");
}

View File

@ -86,7 +86,7 @@ target_include_directories (dwarf PUBLIC
)
target_compile_definitions (dwarf PRIVATE
"PACKAGE_VERSION=\"drmingw\""
PACKAGE_VERSION="drmingw"
)
target_compile_definitions (dwarf PUBLIC
@ -98,7 +98,7 @@ target_compile_options (dwarf PRIVATE
-Wno-int-to-pointer-cast
)
target_link_libraries (dwarf z)
target_link_libraries (dwarf PRIVATE z)
install (
FILES libdwarf/src/lib/libdwarf/LIBDWARFCOPYRIGHT