Skip to content

Commit

Permalink
[runtime] fix trace handler (#24)
Browse files Browse the repository at this point in the history
* [runtime] fix trace handler

* [runtime/trace] fix headers

* [runtime/trace] cleanup

* [runtime/trace] cleanup

* [runtime/trace] cleanup

* [runtime/trace] cleanup

* [cmake] cleanup

* [runtime/trace] install more handlers

* [runtime/trace] fix headers

* [runtime/trace] add header

* [runtime/trace] fix syntax

* [runtime/trace] fix syntax

* [cmake] toss in dbghelp.lib

* [cmake] fix configuration

* [cmake] only add lib on win32
  • Loading branch information
xoviat committed Dec 23, 2017
1 parent 7666f00 commit 086ca05
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1,614 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,10 @@ macro(add_flang_library name)
endif( LLVM_COMMON_DEPENDS )

llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
target_link_libraries( ${name} ${LLVM_COMMON_LIBS} )
if(WIN32)
list(APPEND LLVM_COMMON_LIBS Dbghelp.lib)
endif()
target_link_libraries( ${name} ${LLVM_COMMON_LIBS})
# link_system_libs( ${name} ) # getd of cmake warning messages

install(TARGETS ${name}
Expand Down
2 changes: 0 additions & 2 deletions runtime/flangrti/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ SET(PGC_SRC_FILES
tanh.c
trace_lin.c
trace.c
trace/c_interface.cxx
trace/StackWalker.cpp
anint.c
dnint.c
idnint.c
Expand Down
1,365 changes: 0 additions & 1,365 deletions runtime/flangrti/trace/StackWalker.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions runtime/flangrti/trace/c_interface.cxx

This file was deleted.

1 change: 0 additions & 1 deletion runtime/flangrti/trace/c_interface.h

This file was deleted.

218 changes: 0 additions & 218 deletions runtime/flangrti/trace/stackwalker.h

This file was deleted.

55 changes: 50 additions & 5 deletions runtime/flangrti/trace_lin.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,57 @@ __abort_sig_init(void)
}

#else
#include "trace/c_interface.h"
void __abort_trace(int skip)
{ }
#include <Windows.h>
#include <stdlib.h>
#include <signal.h>
#include <tchar.h>
#include <DbgHelp.h>

void
__abort_trace(int skip)
{
unsigned int i;
void * stack[ 100 ];
unsigned short frames;
SYMBOL_INFO * symbol;
HANDLE process;

process = GetCurrentProcess();

SymInitialize( process, NULL, TRUE );

frames = CaptureStackBackTrace( 0, 100, stack, NULL );
symbol = ( SYMBOL_INFO * )calloc( sizeof( SYMBOL_INFO ) + 256 * sizeof( char ), 1 );
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof( SYMBOL_INFO );

void __abort_sig_init(void)
for( i = 0; i < frames; i++ )
{
SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol );

printf( "%i: %s - 0x%0X\n", frames - i - 1, symbol->Name, symbol->Address );
}

free( symbol );

exit(1);
}

void
__abort_sig_init(void)
{
_install_win32_handlers();
signal(SIGSEGV , __abort_trace);
signal(SIGILL , __abort_trace);
signal(SIGABRT, __abort_trace);
signal(SIGFPE, __abort_trace);
/*
SIGABRT Abnormal termination
SIGFPE Floating-point error
SIGILL Illegal instruction
SIGINT CTRL+C signal
SIGSEGV Illegal storage access
SIGTERM Termination request
*/
}
#endif

0 comments on commit 086ca05

Please sign in to comment.