mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-24 10:40:46 +00:00
ebacktrace1 updates:
- Updated to use StackWalk64 function call, requiring some addition of headers from MinGW-w64 to compile with MinGW. - Code added to support 64-bit executables: functionality added and one warning fixed. - New DLL binaries compiled using i686-MinGW-w64 and x86_64-MinGW-w64. (Oddly, the DLL built with MinGW is 5 MB while MinGW-w64's is 1 MB.) git-svn-id: https://svn.eduke32.com/eduke32@3299 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
7c94ee6874
commit
0f690797f5
7 changed files with 2175 additions and 37 deletions
|
@ -68,7 +68,12 @@ ifneq ($(PLATFORM),WII)
|
|||
MAPSTER32_TARGET:=$(MAPSTER32)
|
||||
endif
|
||||
|
||||
EBACKTRACEDLL ?= ebacktrace1.dll
|
||||
ifndef EBACKTRACEDLL
|
||||
EBACKTRACEDLL = ebacktrace1.dll
|
||||
ifeq ($(findstring x86_64,$(COMPILERTARGET)),x86_64)
|
||||
EBACKTRACEDLL = ebacktrace1-64.dll
|
||||
endif
|
||||
endif
|
||||
EBACKTRACEDLL_TARGET:=$(EBACKTRACEDLL)
|
||||
|
||||
ifeq ($(PLATFORM),WINDOWS)
|
||||
|
|
55
polymer/eduke32/Windows/src/_dbg_LOAD_IMAGE.h
Normal file
55
polymer/eduke32/Windows/src/_dbg_LOAD_IMAGE.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is part of the w64 mingw-runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
||||
*/
|
||||
#ifndef _dbg_LOAD_IMAGE_h
|
||||
#define _dbg_LOAD_IMAGE_h
|
||||
|
||||
#ifndef WINAPI
|
||||
#define WINAPI __stdcall
|
||||
#endif
|
||||
|
||||
#define IMAGEAPI DECLSPEC_IMPORT WINAPI
|
||||
#define DBHLP_DEPRECIATED __declspec(deprecated)
|
||||
|
||||
#define DBHLPAPI IMAGEAPI
|
||||
|
||||
#ifndef EBACKTRACE_MINGW32
|
||||
|
||||
#define IMAGE_SEPARATION (64*1024)
|
||||
|
||||
typedef struct _LOADED_IMAGE {
|
||||
PSTR ModuleName;
|
||||
HANDLE hFile;
|
||||
PUCHAR MappedAddress;
|
||||
#ifdef _IMAGEHLP64
|
||||
PIMAGE_NT_HEADERS64 FileHeader;
|
||||
#else
|
||||
PIMAGE_NT_HEADERS32 FileHeader;
|
||||
#endif
|
||||
PIMAGE_SECTION_HEADER LastRvaSection;
|
||||
ULONG NumberOfSections;
|
||||
PIMAGE_SECTION_HEADER Sections;
|
||||
ULONG Characteristics;
|
||||
BOOLEAN fSystemImage;
|
||||
BOOLEAN fDOSImage;
|
||||
BOOLEAN fReadOnly;
|
||||
UCHAR Version;
|
||||
LIST_ENTRY Links;
|
||||
ULONG SizeOfImage;
|
||||
} LOADED_IMAGE,*PLOADED_IMAGE;
|
||||
|
||||
#endif
|
||||
|
||||
#define MAX_SYM_NAME 2000
|
||||
|
||||
typedef struct _MODLOAD_DATA {
|
||||
DWORD ssize;
|
||||
DWORD ssig;
|
||||
PVOID data;
|
||||
DWORD size;
|
||||
DWORD flags;
|
||||
} MODLOAD_DATA,*PMODLOAD_DATA;
|
||||
|
||||
#endif
|
2051
polymer/eduke32/Windows/src/_dbg_common.h
Normal file
2051
polymer/eduke32/Windows/src/_dbg_common.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,17 +1,15 @@
|
|||
/*
|
||||
/*
|
||||
Copyright (c) 2010 ,
|
||||
Cloud Wu . All rights reserved.
|
||||
|
||||
|
||||
http://www.codingnow.com
|
||||
|
||||
|
||||
Use, modification and distribution are subject to the "New BSD License"
|
||||
as listed at <url: http://www.opensource.org/licenses/bsd-license.php >.
|
||||
|
||||
|
||||
filename: backtrace.c
|
||||
|
||||
compiler: gcc 3.4.5 (mingw-win32)
|
||||
|
||||
build command: gcc -O2 -shared -Wall -o backtrace.dll backtrace.c -lbfd -liberty -limagehlp
|
||||
build command: gcc -O2 -shared -Wall -o backtrace.dll backtrace.c -lbfd -liberty -limagehlp
|
||||
|
||||
how to use: Call LoadLibraryA("backtrace.dll"); at beginning of your program .
|
||||
|
||||
|
@ -19,10 +17,25 @@
|
|||
|
||||
/* modified from original for EDuke32 */
|
||||
|
||||
// warnings cleaned up and ported to 64-bit by Hendricks266
|
||||
|
||||
#define CRASH_LOG_FILE "eduke32_or_mapster32.crashlog"
|
||||
|
||||
#include <windows.h>
|
||||
#include <excpt.h>
|
||||
#include <imagehlp.h>
|
||||
|
||||
// Tenuous: MinGW provides _IMAGEHLP_H while MinGW-w64 defines _IMAGEHLP_.
|
||||
#ifdef _IMAGEHLP_H
|
||||
# define EBACKTRACE_MINGW32
|
||||
#endif
|
||||
#ifdef _IMAGEHLP_
|
||||
# define EBACKTRACE_MINGW_W64
|
||||
#endif
|
||||
#if defined(EBACKTRACE_MINGW32) && !defined(EBACKTRACE_MINGW_W64)
|
||||
# include "_dbg_common.h"
|
||||
#endif
|
||||
|
||||
#ifndef PACKAGE
|
||||
# define PACKAGE EBACKTRACE1
|
||||
#endif
|
||||
|
@ -45,6 +58,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#if defined __GNUC__ || defined __clang__
|
||||
# define ATTRIBUTE(attrlist) __attribute__(attrlist)
|
||||
#else
|
||||
|
@ -102,7 +116,7 @@ output_print(struct output_buffer *ob, const char * format, ...)
|
|||
ob->ptr = strlen(ob->buf + ob->ptr) + ob->ptr;
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
lookup_section(bfd *abfd, asection *sec, void *opaque_data)
|
||||
{
|
||||
struct find_info *data = opaque_data;
|
||||
|
@ -111,11 +125,11 @@ lookup_section(bfd *abfd, asection *sec, void *opaque_data)
|
|||
if (data->func)
|
||||
return;
|
||||
|
||||
if (!(bfd_get_section_flags(abfd, sec) & SEC_ALLOC))
|
||||
if (!(bfd_get_section_flags(abfd, sec) & SEC_ALLOC))
|
||||
return;
|
||||
|
||||
vma = bfd_get_section_vma(abfd, sec);
|
||||
if (data->counter < vma || vma + bfd_get_section_size(sec) <= data->counter)
|
||||
if (data->counter < vma || vma + bfd_get_section_size(sec) <= data->counter)
|
||||
return;
|
||||
|
||||
bfd_find_nearest_line(abfd, sec, data->symbol, data->counter - vma, &(data->file), &(data->func), &(data->line));
|
||||
|
@ -233,12 +247,18 @@ release_set(struct bfd_set *set)
|
|||
|
||||
static char procname[MAX_PATH];
|
||||
|
||||
#if defined(_M_X64) || defined(__amd64__) || defined(__x86_64__)
|
||||
# define MachineType IMAGE_FILE_MACHINE_AMD64
|
||||
#else
|
||||
# define MachineType IMAGE_FILE_MACHINE_I386
|
||||
#endif
|
||||
|
||||
static void
|
||||
_backtrace(struct output_buffer *ob, struct bfd_set *set, int depth , LPCONTEXT context)
|
||||
{
|
||||
STACKFRAME frame;
|
||||
STACKFRAME64 frame;
|
||||
HANDLE process, thread;
|
||||
char symbol_buffer[sizeof(IMAGEHLP_SYMBOL) + 255];
|
||||
char symbol_buffer[sizeof(IMAGEHLP_SYMBOL64) + 255];
|
||||
char module_name_raw[MAX_PATH];
|
||||
struct bfd_ctx *bc = NULL;
|
||||
|
||||
|
@ -246,26 +266,33 @@ _backtrace(struct output_buffer *ob, struct bfd_set *set, int depth , LPCONTEXT
|
|||
|
||||
memset(&frame,0,sizeof(frame));
|
||||
|
||||
#if defined(_M_X64) || defined(__amd64__) || defined(__x86_64__)
|
||||
frame.AddrPC.Offset = context->Rip;
|
||||
frame.AddrStack.Offset = context->Rsp;
|
||||
frame.AddrFrame.Offset = context->Rbp;
|
||||
#else
|
||||
frame.AddrPC.Offset = context->Eip;
|
||||
frame.AddrPC.Mode = AddrModeFlat;
|
||||
frame.AddrStack.Offset = context->Esp;
|
||||
frame.AddrStack.Mode = AddrModeFlat;
|
||||
frame.AddrFrame.Offset = context->Ebp;
|
||||
#endif
|
||||
|
||||
frame.AddrPC.Mode = AddrModeFlat;
|
||||
frame.AddrStack.Mode = AddrModeFlat;
|
||||
frame.AddrFrame.Mode = AddrModeFlat;
|
||||
|
||||
process = GetCurrentProcess();
|
||||
thread = GetCurrentThread();
|
||||
|
||||
while(StackWalk(IMAGE_FILE_MACHINE_I386,
|
||||
process,
|
||||
thread,
|
||||
&frame,
|
||||
context,
|
||||
0,
|
||||
SymFunctionTableAccess,
|
||||
SymGetModuleBase, 0)) {
|
||||
IMAGEHLP_SYMBOL *symbol;
|
||||
DWORD module_base;
|
||||
while(StackWalk64(MachineType,
|
||||
process,
|
||||
thread,
|
||||
&frame,
|
||||
context,
|
||||
NULL,
|
||||
SymFunctionTableAccess64,
|
||||
SymGetModuleBase64, NULL)) {
|
||||
IMAGEHLP_SYMBOL64 *symbol;
|
||||
DWORD64 module_base;
|
||||
const char * module_name = "[unknown module]";
|
||||
|
||||
const char * file = NULL;
|
||||
|
@ -276,14 +303,14 @@ _backtrace(struct output_buffer *ob, struct bfd_set *set, int depth , LPCONTEXT
|
|||
if (depth < 0)
|
||||
break;
|
||||
|
||||
symbol = (IMAGEHLP_SYMBOL *)symbol_buffer;
|
||||
symbol = (IMAGEHLP_SYMBOL64 *)symbol_buffer;
|
||||
symbol->SizeOfStruct = (sizeof *symbol) + 255;
|
||||
symbol->MaxNameLength = 254;
|
||||
|
||||
module_base = SymGetModuleBase(process, frame.AddrPC.Offset);
|
||||
module_base = SymGetModuleBase64(process, frame.AddrPC.Offset);
|
||||
|
||||
if (module_base &&
|
||||
GetModuleFileNameA((HINSTANCE)module_base, module_name_raw, MAX_PATH)) {
|
||||
if (module_base &&
|
||||
GetModuleFileNameA((HINSTANCE)(intptr_t)module_base, module_name_raw, MAX_PATH)) {
|
||||
module_name = module_name_raw;
|
||||
bc = get_bc(ob, set, module_name);
|
||||
}
|
||||
|
@ -293,8 +320,8 @@ _backtrace(struct output_buffer *ob, struct bfd_set *set, int depth , LPCONTEXT
|
|||
}
|
||||
|
||||
if (file == NULL) {
|
||||
DWORD dummy = 0;
|
||||
if (SymGetSymFromAddr(process, frame.AddrPC.Offset, &dummy, symbol)) {
|
||||
DWORD64 dummy = 0;
|
||||
if (SymGetSymFromAddr64(process, frame.AddrPC.Offset, &dummy, symbol)) {
|
||||
file = symbol->Name;
|
||||
}
|
||||
else {
|
||||
|
@ -302,13 +329,13 @@ _backtrace(struct output_buffer *ob, struct bfd_set *set, int depth , LPCONTEXT
|
|||
}
|
||||
}
|
||||
if (func == NULL) {
|
||||
output_print(ob,"0x%x : %s : %s \n",
|
||||
output_print(ob,"0x%x : %s : %s \n",
|
||||
frame.AddrPC.Offset,
|
||||
module_name,
|
||||
file);
|
||||
}
|
||||
else {
|
||||
output_print(ob,"0x%x : %s : %s (%d) : in function (%s) \n",
|
||||
output_print(ob,"0x%x : %s : %s (%d) : in function (%s) \n",
|
||||
frame.AddrPC.Offset,
|
||||
module_name,
|
||||
file,
|
||||
|
@ -321,7 +348,7 @@ _backtrace(struct output_buffer *ob, struct bfd_set *set, int depth , LPCONTEXT
|
|||
static char * g_output = NULL;
|
||||
static LPTOP_LEVEL_EXCEPTION_FILTER g_prev = NULL;
|
||||
|
||||
static LONG WINAPI
|
||||
static LONG WINAPI
|
||||
exception_filter(LPEXCEPTION_POINTERS info)
|
||||
{
|
||||
struct output_buffer ob;
|
||||
|
@ -340,7 +367,7 @@ exception_filter(LPEXCEPTION_POINTERS info)
|
|||
SymCleanup(GetCurrentProcess());
|
||||
}
|
||||
|
||||
logfd = open("eduke32_or_mapster32.crashlog", O_APPEND | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
||||
logfd = open(CRASH_LOG_FILE, O_APPEND | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
||||
|
||||
if (logfd) {
|
||||
time_t curtime;
|
||||
|
@ -389,7 +416,7 @@ backtrace_unregister(void)
|
|||
}
|
||||
}
|
||||
|
||||
BOOL WINAPI
|
||||
BOOL WINAPI
|
||||
DllMain(HANDLE hinstDLL ATTRIBUTE((unused)), DWORD dwReason, LPVOID lpvReserved ATTRIBUTE((unused)))
|
||||
{
|
||||
switch (dwReason) {
|
||||
|
|
BIN
polymer/eduke32/package/ebacktrace1-64.dll
Normal file
BIN
polymer/eduke32/package/ebacktrace1-64.dll
Normal file
Binary file not shown.
Binary file not shown.
|
@ -11,7 +11,7 @@ clean=veryclean
|
|||
# the following file paths are relative to $source
|
||||
targets=( eduke32.exe mapster32.exe )
|
||||
package=package
|
||||
not_src_packaged=( psd source/jaudiolib/third-party/vorbis.framework/Versions/A/vorbis Apple/lib $package/ebacktrace1.dll )
|
||||
not_src_packaged=( psd source/jaudiolib/third-party/vorbis.framework/Versions/A/vorbis Apple/lib )
|
||||
|
||||
# group that owns the resulting packages
|
||||
group=dukeworld
|
||||
|
|
Loading…
Reference in a new issue