2012-12-16 05:45:29 +00:00
|
|
|
/*
|
2011-09-21 22:38:24 +00:00
|
|
|
Copyright (c) 2010 ,
|
|
|
|
Cloud Wu . All rights reserved.
|
2012-12-16 05:45:29 +00:00
|
|
|
|
2011-09-21 22:38:24 +00:00
|
|
|
http://www.codingnow.com
|
2012-12-16 05:45:29 +00:00
|
|
|
|
2011-09-21 22:38:24 +00:00
|
|
|
Use, modification and distribution are subject to the "New BSD License"
|
|
|
|
as listed at <url: http://www.opensource.org/licenses/bsd-license.php >.
|
|
|
|
|
2012-12-16 05:45:29 +00:00
|
|
|
filename: backtrace.c
|
2011-09-21 22:38:24 +00:00
|
|
|
|
2012-12-16 05:45:29 +00:00
|
|
|
build command: gcc -O2 -shared -Wall -o backtrace.dll backtrace.c -lbfd -liberty -limagehlp
|
2011-09-21 22:38:24 +00:00
|
|
|
|
|
|
|
how to use: Call LoadLibraryA("backtrace.dll"); at beginning of your program .
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* modified from original for EDuke32 */
|
|
|
|
|
2012-12-16 05:45:29 +00:00
|
|
|
// warnings cleaned up and ported to 64-bit by Hendricks266
|
|
|
|
|
2013-03-29 15:59:20 +00:00
|
|
|
#define CRASH_LOG_FILE "eduke32_or_mapster32.crash.log"
|
2012-12-16 05:45:29 +00:00
|
|
|
|
2011-09-21 22:38:24 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <excpt.h>
|
|
|
|
#include <imagehlp.h>
|
2012-11-24 09:11:06 +00:00
|
|
|
|
2012-12-16 05:45:29 +00:00
|
|
|
// 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
|
|
|
|
|
2012-11-24 09:11:06 +00:00
|
|
|
#ifndef PACKAGE
|
|
|
|
# define PACKAGE EBACKTRACE1
|
|
|
|
#endif
|
|
|
|
#ifndef PACKAGE_VERSION
|
|
|
|
# define PACKAGE_VERSION 1
|
|
|
|
#endif
|
|
|
|
|
2011-09-21 22:38:24 +00:00
|
|
|
#include <bfd.h>
|
|
|
|
#include <psapi.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2011-09-22 16:52:55 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
Win64 support! (Meaning it works, not that we recommend it for everyday use.)
This includes a complete Windows header and library refresh, including the addition of 64-bit compiled libs:
*libogg 1.3.0
*libvorbis 1.3.3
*zlib 1.2.7
*libpng 1.5.13
*libvpx 9a3de881c0e681ba1a79a166a86308bbc84b4acd
*SDL_mixer 1.2.12 (for RENDERTYPE=SDL)
*DirectX import libraries: dsound and dxguid (now included)
To build in 64-bit, you essentially need MinGW's MSYS (but not MinGW itself) and MinGW-w64 at the top of your PATH. The target is automatically detected using `$(CC) -dumpmachine`. The EDukeWiki will get detailed instrucitons.
All compiler and linker warnings when building in 64-bit mode have been fixed.
Remaining 64-bit to-do:
- The ebacktrace dll does not build under 64-bit. It uses code specific to the format of 32-bit executables and will have to be ported to work with 64-bit executables. A future 64-bit version will be named ebacktrace1-64.dll.
- RENDERTYPE=SDL crashes in SDL_mixer's Mix_Linked_Version().
- DirectInput gives an error and does not function. This only affects joysticks, and the error never happens without any plugged in.
- Port the classic renderer ASM to 64-bit. (Just kidding, this is way out of my league.)
This commit includes a fair bit of Makefile development spanning all platforms, including simplifying the SDLCONFIG code, fixing build on Mac OS X (thanks rhoenie!), globally factoring Apple brew/port inclusion, enforcing that all -L come before all -l, and ensuring that $(shell ) is always :='d.
In addition, I have resurrected the old GCC_MAJOR and GCC_MINOR detection using `$(CC) -dumpversion`, but I have made it failsafe in case the command fails or the version is manually specified. I have applied this new fine-grained detection where applicable, including allowing LTO, and restraining -W's to versions that support them.
git-svn-id: https://svn.eduke32.com/eduke32@3278 1a8010ca-5511-0410-912e-c29ae57300e0
2012-12-13 02:37:20 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2012-12-16 05:45:29 +00:00
|
|
|
|
Win64 support! (Meaning it works, not that we recommend it for everyday use.)
This includes a complete Windows header and library refresh, including the addition of 64-bit compiled libs:
*libogg 1.3.0
*libvorbis 1.3.3
*zlib 1.2.7
*libpng 1.5.13
*libvpx 9a3de881c0e681ba1a79a166a86308bbc84b4acd
*SDL_mixer 1.2.12 (for RENDERTYPE=SDL)
*DirectX import libraries: dsound and dxguid (now included)
To build in 64-bit, you essentially need MinGW's MSYS (but not MinGW itself) and MinGW-w64 at the top of your PATH. The target is automatically detected using `$(CC) -dumpmachine`. The EDukeWiki will get detailed instrucitons.
All compiler and linker warnings when building in 64-bit mode have been fixed.
Remaining 64-bit to-do:
- The ebacktrace dll does not build under 64-bit. It uses code specific to the format of 32-bit executables and will have to be ported to work with 64-bit executables. A future 64-bit version will be named ebacktrace1-64.dll.
- RENDERTYPE=SDL crashes in SDL_mixer's Mix_Linked_Version().
- DirectInput gives an error and does not function. This only affects joysticks, and the error never happens without any plugged in.
- Port the classic renderer ASM to 64-bit. (Just kidding, this is way out of my league.)
This commit includes a fair bit of Makefile development spanning all platforms, including simplifying the SDLCONFIG code, fixing build on Mac OS X (thanks rhoenie!), globally factoring Apple brew/port inclusion, enforcing that all -L come before all -l, and ensuring that $(shell ) is always :='d.
In addition, I have resurrected the old GCC_MAJOR and GCC_MINOR detection using `$(CC) -dumpversion`, but I have made it failsafe in case the command fails or the version is manually specified. I have applied this new fine-grained detection where applicable, including allowing LTO, and restraining -W's to versions that support them.
git-svn-id: https://svn.eduke32.com/eduke32@3278 1a8010ca-5511-0410-912e-c29ae57300e0
2012-12-13 02:37:20 +00:00
|
|
|
#if defined __GNUC__ || defined __clang__
|
|
|
|
# define ATTRIBUTE(attrlist) __attribute__(attrlist)
|
|
|
|
#else
|
|
|
|
# define ATTRIBUTE(attrlist)
|
|
|
|
#endif
|
2012-03-04 09:31:02 +00:00
|
|
|
|
2011-09-21 22:38:24 +00:00
|
|
|
#define BUFFER_MAX (16*1024)
|
|
|
|
|
|
|
|
struct bfd_ctx {
|
|
|
|
bfd * handle;
|
|
|
|
asymbol ** symbol;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bfd_set {
|
|
|
|
char * name;
|
|
|
|
struct bfd_ctx * bc;
|
|
|
|
struct bfd_set *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct find_info {
|
|
|
|
asymbol **symbol;
|
|
|
|
bfd_vma counter;
|
|
|
|
const char *file;
|
|
|
|
const char *func;
|
|
|
|
unsigned line;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct output_buffer {
|
|
|
|
char * buf;
|
|
|
|
size_t sz;
|
|
|
|
size_t ptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
output_init(struct output_buffer *ob, char * buf, size_t sz)
|
|
|
|
{
|
|
|
|
ob->buf = buf;
|
|
|
|
ob->sz = sz;
|
|
|
|
ob->ptr = 0;
|
|
|
|
ob->buf[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
output_print(struct output_buffer *ob, const char * format, ...)
|
|
|
|
{
|
2012-11-05 02:50:12 +00:00
|
|
|
va_list ap;
|
|
|
|
|
2011-09-21 22:38:24 +00:00
|
|
|
if (ob->sz == ob->ptr)
|
|
|
|
return;
|
|
|
|
ob->buf[ob->ptr] = '\0';
|
|
|
|
va_start(ap,format);
|
|
|
|
vsnprintf(ob->buf + ob->ptr , ob->sz - ob->ptr , format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
ob->ptr = strlen(ob->buf + ob->ptr) + ob->ptr;
|
|
|
|
}
|
|
|
|
|
2012-12-16 05:45:29 +00:00
|
|
|
static void
|
2011-09-21 22:38:24 +00:00
|
|
|
lookup_section(bfd *abfd, asection *sec, void *opaque_data)
|
|
|
|
{
|
|
|
|
struct find_info *data = opaque_data;
|
2012-11-05 02:50:12 +00:00
|
|
|
bfd_vma vma;
|
2011-09-21 22:38:24 +00:00
|
|
|
|
|
|
|
if (data->func)
|
|
|
|
return;
|
|
|
|
|
2012-12-16 05:45:29 +00:00
|
|
|
if (!(bfd_get_section_flags(abfd, sec) & SEC_ALLOC))
|
2011-09-21 22:38:24 +00:00
|
|
|
return;
|
|
|
|
|
2012-11-05 02:50:12 +00:00
|
|
|
vma = bfd_get_section_vma(abfd, sec);
|
2012-12-16 05:45:29 +00:00
|
|
|
if (data->counter < vma || vma + bfd_get_section_size(sec) <= data->counter)
|
2011-09-21 22:38:24 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
bfd_find_nearest_line(abfd, sec, data->symbol, data->counter - vma, &(data->file), &(data->func), &(data->line));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
find(struct bfd_ctx * b, DWORD offset, const char **file, const char **func, unsigned *line)
|
|
|
|
{
|
|
|
|
struct find_info data;
|
|
|
|
data.func = NULL;
|
|
|
|
data.symbol = b->symbol;
|
|
|
|
data.counter = offset;
|
|
|
|
data.file = NULL;
|
|
|
|
data.func = NULL;
|
|
|
|
data.line = 0;
|
|
|
|
|
|
|
|
bfd_map_over_sections(b->handle, &lookup_section, &data);
|
|
|
|
if (file) {
|
|
|
|
*file = data.file;
|
|
|
|
}
|
|
|
|
if (func) {
|
|
|
|
*func = data.func;
|
|
|
|
}
|
|
|
|
if (line) {
|
|
|
|
*line = data.line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
init_bfd_ctx(struct bfd_ctx *bc, const char * procname, struct output_buffer *ob)
|
|
|
|
{
|
2012-11-05 02:50:12 +00:00
|
|
|
int r1, r2, r3;
|
|
|
|
bfd *b;
|
|
|
|
void *symbol_table;
|
|
|
|
unsigned dummy = 0;
|
2011-09-21 22:38:24 +00:00
|
|
|
bc->handle = NULL;
|
|
|
|
bc->symbol = NULL;
|
|
|
|
|
2012-11-05 02:50:12 +00:00
|
|
|
b = bfd_openr(procname, 0);
|
2011-09-21 22:38:24 +00:00
|
|
|
if (!b) {
|
|
|
|
output_print(ob,"Failed to open bfd from (%s)\n" , procname);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-11-05 02:50:12 +00:00
|
|
|
r1 = bfd_check_format(b, bfd_object);
|
|
|
|
r2 = bfd_check_format_matches(b, bfd_object, NULL);
|
|
|
|
r3 = bfd_get_file_flags(b) & HAS_SYMS;
|
2011-09-21 22:38:24 +00:00
|
|
|
|
|
|
|
if (!(r1 && r2 && r3)) {
|
|
|
|
bfd_close(b);
|
|
|
|
output_print(ob,"Failed to init bfd from (%s): %d %d %d\n", procname, r1,r2,r3);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bfd_read_minisymbols(b, FALSE, &symbol_table, &dummy) == 0) {
|
|
|
|
if (bfd_read_minisymbols(b, TRUE, &symbol_table, &dummy) < 0) {
|
|
|
|
free(symbol_table);
|
|
|
|
bfd_close(b);
|
|
|
|
output_print(ob,"Failed to read symbols from (%s)\n", procname);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bc->handle = b;
|
|
|
|
bc->symbol = symbol_table;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
close_bfd_ctx(struct bfd_ctx *bc)
|
|
|
|
{
|
|
|
|
if (bc) {
|
|
|
|
if (bc->symbol) {
|
|
|
|
free(bc->symbol);
|
|
|
|
}
|
|
|
|
if (bc->handle) {
|
|
|
|
bfd_close(bc->handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct bfd_ctx *
|
|
|
|
get_bc(struct output_buffer *ob , struct bfd_set *set , const char *procname)
|
|
|
|
{
|
2012-11-05 02:50:12 +00:00
|
|
|
struct bfd_ctx bc;
|
2011-09-21 22:38:24 +00:00
|
|
|
while(set->name) {
|
|
|
|
if (strcmp(set->name , procname) == 0) {
|
|
|
|
return set->bc;
|
|
|
|
}
|
|
|
|
set = set->next;
|
|
|
|
}
|
|
|
|
if (init_bfd_ctx(&bc, procname , ob)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
set->next = calloc(1, sizeof(*set));
|
|
|
|
set->bc = malloc(sizeof(struct bfd_ctx));
|
|
|
|
memcpy(set->bc, &bc, sizeof(bc));
|
|
|
|
set->name = strdup(procname);
|
|
|
|
|
|
|
|
return set->bc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
release_set(struct bfd_set *set)
|
|
|
|
{
|
|
|
|
while(set) {
|
|
|
|
struct bfd_set * temp = set->next;
|
|
|
|
free(set->name);
|
|
|
|
close_bfd_ctx(set->bc);
|
|
|
|
free(set);
|
|
|
|
set = temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static char procname[MAX_PATH];
|
|
|
|
|
2012-12-16 05:45:29 +00:00
|
|
|
#if defined(_M_X64) || defined(__amd64__) || defined(__x86_64__)
|
|
|
|
# define MachineType IMAGE_FILE_MACHINE_AMD64
|
2012-12-18 09:15:39 +00:00
|
|
|
# define MAYBE64(x) x ## 64
|
2012-12-16 05:45:29 +00:00
|
|
|
#else
|
|
|
|
# define MachineType IMAGE_FILE_MACHINE_I386
|
2012-12-18 09:15:39 +00:00
|
|
|
# define MAYBE64(x) x
|
2012-12-16 05:45:29 +00:00
|
|
|
#endif
|
|
|
|
|
2011-09-21 22:38:24 +00:00
|
|
|
static void
|
|
|
|
_backtrace(struct output_buffer *ob, struct bfd_set *set, int depth , LPCONTEXT context)
|
|
|
|
{
|
2012-12-18 09:15:39 +00:00
|
|
|
MAYBE64(STACKFRAME) frame;
|
2012-11-05 02:50:12 +00:00
|
|
|
HANDLE process, thread;
|
2012-12-18 09:15:39 +00:00
|
|
|
char symbol_buffer[sizeof(MAYBE64(IMAGEHLP_SYMBOL)) + 255];
|
2012-11-05 02:50:12 +00:00
|
|
|
char module_name_raw[MAX_PATH];
|
2011-09-21 22:38:24 +00:00
|
|
|
struct bfd_ctx *bc = NULL;
|
|
|
|
|
2012-11-05 02:50:12 +00:00
|
|
|
GetModuleFileNameA(NULL, procname, sizeof procname);
|
|
|
|
|
2011-09-21 22:38:24 +00:00
|
|
|
memset(&frame,0,sizeof(frame));
|
|
|
|
|
2012-12-16 05:45:29 +00:00
|
|
|
#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
|
2011-09-21 22:38:24 +00:00
|
|
|
frame.AddrPC.Offset = context->Eip;
|
|
|
|
frame.AddrStack.Offset = context->Esp;
|
|
|
|
frame.AddrFrame.Offset = context->Ebp;
|
2012-12-16 05:45:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
frame.AddrPC.Mode = AddrModeFlat;
|
|
|
|
frame.AddrStack.Mode = AddrModeFlat;
|
2011-09-21 22:38:24 +00:00
|
|
|
frame.AddrFrame.Mode = AddrModeFlat;
|
|
|
|
|
2012-11-05 02:50:12 +00:00
|
|
|
process = GetCurrentProcess();
|
|
|
|
thread = GetCurrentThread();
|
2011-09-21 22:38:24 +00:00
|
|
|
|
2012-12-18 09:15:39 +00:00
|
|
|
while(MAYBE64(StackWalk)(MachineType,
|
2012-12-16 05:45:29 +00:00
|
|
|
process,
|
|
|
|
thread,
|
|
|
|
&frame,
|
|
|
|
context,
|
|
|
|
NULL,
|
2012-12-18 09:15:39 +00:00
|
|
|
MAYBE64(SymFunctionTableAccess),
|
|
|
|
MAYBE64(SymGetModuleBase), NULL)) {
|
|
|
|
MAYBE64(IMAGEHLP_SYMBOL) *symbol;
|
|
|
|
MAYBE64(DWORD) module_base;
|
2012-11-05 02:50:12 +00:00
|
|
|
const char * module_name = "[unknown module]";
|
|
|
|
|
|
|
|
const char * file = NULL;
|
|
|
|
const char * func = NULL;
|
|
|
|
unsigned line = 0;
|
2011-09-21 22:38:24 +00:00
|
|
|
|
|
|
|
--depth;
|
|
|
|
if (depth < 0)
|
|
|
|
break;
|
|
|
|
|
2012-12-18 09:15:39 +00:00
|
|
|
symbol = (MAYBE64(IMAGEHLP_SYMBOL) *)symbol_buffer;
|
2011-09-21 22:38:24 +00:00
|
|
|
symbol->SizeOfStruct = (sizeof *symbol) + 255;
|
|
|
|
symbol->MaxNameLength = 254;
|
|
|
|
|
2012-12-18 09:15:39 +00:00
|
|
|
module_base = MAYBE64(SymGetModuleBase)(process, frame.AddrPC.Offset);
|
2011-09-21 22:38:24 +00:00
|
|
|
|
2012-12-16 05:45:29 +00:00
|
|
|
if (module_base &&
|
|
|
|
GetModuleFileNameA((HINSTANCE)(intptr_t)module_base, module_name_raw, MAX_PATH)) {
|
2011-09-21 22:38:24 +00:00
|
|
|
module_name = module_name_raw;
|
|
|
|
bc = get_bc(ob, set, module_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bc) {
|
|
|
|
find(bc,frame.AddrPC.Offset,&file,&func,&line);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file == NULL) {
|
2012-12-18 09:15:39 +00:00
|
|
|
MAYBE64(DWORD) dummy = 0;
|
|
|
|
if (MAYBE64(SymGetSymFromAddr)(process, frame.AddrPC.Offset, &dummy, symbol)) {
|
2011-09-21 22:38:24 +00:00
|
|
|
file = symbol->Name;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
file = "[unknown file]";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (func == NULL) {
|
2012-12-16 05:45:29 +00:00
|
|
|
output_print(ob,"0x%x : %s : %s \n",
|
2011-09-21 22:38:24 +00:00
|
|
|
frame.AddrPC.Offset,
|
|
|
|
module_name,
|
|
|
|
file);
|
|
|
|
}
|
|
|
|
else {
|
2012-12-16 05:45:29 +00:00
|
|
|
output_print(ob,"0x%x : %s : %s (%d) : in function (%s) \n",
|
2011-09-21 22:38:24 +00:00
|
|
|
frame.AddrPC.Offset,
|
|
|
|
module_name,
|
|
|
|
file,
|
|
|
|
line,
|
|
|
|
func);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static char * g_output = NULL;
|
2014-05-17 12:35:46 +00:00
|
|
|
static PVOID g_prev = NULL;
|
2011-09-21 22:38:24 +00:00
|
|
|
|
2012-12-16 05:45:29 +00:00
|
|
|
static LONG WINAPI
|
2011-09-21 22:38:24 +00:00
|
|
|
exception_filter(LPEXCEPTION_POINTERS info)
|
|
|
|
{
|
|
|
|
struct output_buffer ob;
|
2012-11-05 02:50:12 +00:00
|
|
|
int logfd, written;
|
2011-09-21 22:38:24 +00:00
|
|
|
output_init(&ob, g_output, BUFFER_MAX);
|
|
|
|
|
|
|
|
if (!SymInitialize(GetCurrentProcess(), 0, TRUE)) {
|
|
|
|
output_print(&ob,"Failed to init symbol context\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
struct bfd_set *set = calloc(1,sizeof(*set));
|
2012-11-05 02:50:12 +00:00
|
|
|
bfd_init();
|
2011-09-21 22:38:24 +00:00
|
|
|
_backtrace(&ob , set , 128 , info->ContextRecord);
|
|
|
|
release_set(set);
|
|
|
|
|
|
|
|
SymCleanup(GetCurrentProcess());
|
|
|
|
}
|
|
|
|
|
2012-12-16 05:45:29 +00:00
|
|
|
logfd = open(CRASH_LOG_FILE, O_APPEND | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
2011-09-21 22:38:24 +00:00
|
|
|
|
|
|
|
if (logfd) {
|
2012-11-05 02:50:12 +00:00
|
|
|
time_t curtime;
|
|
|
|
struct tm *curltime;
|
|
|
|
const char *theasctime;
|
|
|
|
const char *finistr = "---------------\n";
|
|
|
|
|
2011-09-21 22:38:24 +00:00
|
|
|
while ((written = write(logfd, g_output, strlen(g_output)))) {
|
|
|
|
g_output += written;
|
|
|
|
}
|
2011-09-22 16:52:55 +00:00
|
|
|
|
2012-11-05 02:50:12 +00:00
|
|
|
curtime = time(NULL);
|
|
|
|
curltime = localtime(&curtime);
|
|
|
|
theasctime = curltime ? asctime(curltime) : NULL;
|
2011-09-22 16:52:55 +00:00
|
|
|
|
|
|
|
if (theasctime)
|
|
|
|
write(logfd, theasctime, strlen(theasctime));
|
|
|
|
write(logfd, finistr, strlen(finistr));
|
2011-09-21 22:38:24 +00:00
|
|
|
close(logfd);
|
|
|
|
}
|
|
|
|
|
|
|
|
//fputs(g_output, stderr);
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
backtrace_register(void)
|
|
|
|
{
|
|
|
|
if (g_output == NULL) {
|
|
|
|
g_output = malloc(BUFFER_MAX);
|
2014-05-17 12:35:46 +00:00
|
|
|
g_prev = AddVectoredExceptionHandler(1, exception_filter);
|
2011-09-21 22:38:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
backtrace_unregister(void)
|
|
|
|
{
|
|
|
|
if (g_output) {
|
|
|
|
free(g_output);
|
2014-05-17 12:35:46 +00:00
|
|
|
RemoveVectoredExceptionHandler(g_prev);
|
2011-09-21 22:38:24 +00:00
|
|
|
g_prev = NULL;
|
|
|
|
g_output = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-16 05:45:29 +00:00
|
|
|
BOOL WINAPI
|
2013-10-07 10:02:33 +00:00
|
|
|
DllMain(HINSTANCE hinstDLL ATTRIBUTE((unused)), DWORD dwReason, LPVOID lpvReserved ATTRIBUTE((unused)))
|
2011-09-21 22:38:24 +00:00
|
|
|
{
|
|
|
|
switch (dwReason) {
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
backtrace_register();
|
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
backtrace_unregister();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* cut dependence on libintl... libbfd needs this */
|
2012-03-04 09:31:02 +00:00
|
|
|
char *libintl_dgettext (const char *domain_name ATTRIBUTE((unused)), const char *msgid ATTRIBUTE((unused)))
|
2011-09-21 22:38:24 +00:00
|
|
|
{
|
|
|
|
static char buf[1024] = "XXX placeholder XXX";
|
|
|
|
return buf;
|
|
|
|
}
|
2012-03-05 07:25:55 +00:00
|
|
|
|
2013-10-07 10:02:33 +00:00
|
|
|
int __printf__ ( const char * format, ... );
|
2012-03-05 07:25:55 +00:00
|
|
|
int libintl_fprintf ( FILE * stream, const char * format, ... );
|
|
|
|
int libintl_sprintf ( char * str, const char * format, ... );
|
|
|
|
int libintl_snprintf ( char *buffer, int buf_size, const char *format, ... );
|
|
|
|
int libintl_vprintf ( const char * format, va_list arg );
|
|
|
|
int libintl_vfprintf ( FILE * stream, const char * format, va_list arg );
|
|
|
|
int libintl_vsprintf ( char * str, const char * format, va_list arg );
|
|
|
|
|
2013-10-07 10:02:33 +00:00
|
|
|
int __printf__ ( const char * format, ... )
|
|
|
|
{
|
|
|
|
int value;
|
|
|
|
va_list arg;
|
|
|
|
va_start(arg, format);
|
|
|
|
value = vprintf ( format, arg );
|
|
|
|
va_end(arg);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2012-03-05 07:25:55 +00:00
|
|
|
int libintl_fprintf ( FILE * stream, const char * format, ... )
|
|
|
|
{
|
|
|
|
int value;
|
|
|
|
va_list arg;
|
|
|
|
va_start(arg, format);
|
|
|
|
value = vfprintf ( stream, format, arg );
|
|
|
|
va_end(arg);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
int libintl_sprintf ( char * str, const char * format, ... )
|
|
|
|
{
|
|
|
|
int value;
|
|
|
|
va_list arg;
|
|
|
|
va_start(arg, format);
|
|
|
|
value = vsprintf ( str, format, arg );
|
|
|
|
va_end(arg);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
int libintl_snprintf ( char *buffer, int buf_size, const char *format, ... )
|
|
|
|
{
|
|
|
|
int value;
|
|
|
|
va_list arg;
|
|
|
|
va_start(arg, format);
|
|
|
|
value = vsnprintf ( buffer, buf_size, format, arg );
|
|
|
|
va_end(arg);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
int libintl_vprintf ( const char * format, va_list arg )
|
|
|
|
{
|
|
|
|
return vprintf ( format, arg );
|
|
|
|
}
|
|
|
|
int libintl_vfprintf ( FILE * stream, const char * format, va_list arg )
|
|
|
|
{
|
|
|
|
return vfprintf ( stream, format, arg );
|
|
|
|
}
|
|
|
|
int libintl_vsprintf ( char * str, const char * format, va_list arg )
|
|
|
|
{
|
|
|
|
return vsprintf ( str, format, arg );
|
|
|
|
}
|
2013-10-07 10:02:33 +00:00
|
|
|
|
|
|
|
/* cut dependence on zlib... libbfd needs this */
|
|
|
|
|
|
|
|
int compress (unsigned char *dest ATTRIBUTE((unused)), unsigned long destLen ATTRIBUTE((unused)), const unsigned char source ATTRIBUTE((unused)), unsigned long sourceLen ATTRIBUTE((unused)))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
unsigned long compressBound (unsigned long sourceLen)
|
|
|
|
{
|
|
|
|
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + (sourceLen >> 25) + 13;
|
|
|
|
}
|
|
|
|
int inflateEnd(void *strm ATTRIBUTE((unused)))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int inflateInit_(void *strm ATTRIBUTE((unused)), const char *version ATTRIBUTE((unused)), int stream_size ATTRIBUTE((unused)))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int inflateReset(void *strm ATTRIBUTE((unused)))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int inflate(void *strm ATTRIBUTE((unused)), int flush ATTRIBUTE((unused)))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|