Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
0e6372f5
Commit
0e6372f5
authored
9 years ago
by
Nicolas Noble
Browse files
Options
Downloads
Plain Diff
Merge pull request #5770 from ctiller/win
Get callstacks for test failures on Windows
parents
0b3e515c
2ed1a9e3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/core/util/test_config.c
+133
-16
133 additions, 16 deletions
test/core/util/test_config.c
with
133 additions
and
16 deletions
test/core/util/test_config.c
+
133
−
16
View file @
0e6372f5
/*
/*
*
*
* Copyright 2015, Google Inc.
* Copyright 2015
-2016
, Google Inc.
* All rights reserved.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
...
@@ -33,11 +33,13 @@
...
@@ -33,11 +33,13 @@
#include
"test/core/util/test_config.h"
#include
"test/core/util/test_config.h"
#include
<grpc/support/port_platform.h>
#include
<grpc/support/log.h>
#include
<grpc/support/log.h>
#include
"src/core/support/string.h"
#include
<grpc/support/port_platform.h>
#include
<stdlib.h>
#include
<signal.h>
#include
<signal.h>
#include
<stdbool.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
"src/core/support/string.h"
double
g_fixture_slowdown_factor
=
1
.
0
;
double
g_fixture_slowdown_factor
=
1
.
0
;
...
@@ -52,14 +54,125 @@ static unsigned seed(void) { return _getpid(); }
...
@@ -52,14 +54,125 @@ static unsigned seed(void) { return _getpid(); }
#endif
#endif
#if GPR_WINDOWS_CRASH_HANDLER
#if GPR_WINDOWS_CRASH_HANDLER
LONG
crash_handler
(
struct
_EXCEPTION_POINTERS
*
ex_info
)
{
#include
<windows.h>
gpr_log
(
GPR_DEBUG
,
"Exception handler called, dumping information"
);
while
(
ex_info
->
ExceptionRecord
)
{
#include
<tchar.h>
DWORD
code
=
ex_info
->
ExceptionRecord
->
ExceptionCode
;
DWORD
flgs
=
ex_info
->
ExceptionRecord
->
ExceptionFlags
;
// disable warning 4091 - dbghelp.h is broken for msvc2015
PVOID
addr
=
ex_info
->
ExceptionRecord
->
ExceptionAddress
;
#pragma warning(disable : 4091)
gpr_log
(
"code: %x - flags: %d - address: %p"
,
code
,
flgs
,
addr
);
#define DBGHELP_TRANSLATE_TCHAR
ex_info
->
ExceptionRecord
=
ex_info
->
ExceptionRecord
->
ExceptionRecord
;
#include
<dbghelp.h>
#ifdef _MSC_VER
#pragma comment(lib, "dbghelp.lib")
#endif
static
void
print_current_stack
()
{
typedef
USHORT
(
WINAPI
*
CaptureStackBackTraceType
)(
__in
ULONG
,
__in
ULONG
,
__out
PVOID
*
,
__out_opt
PULONG
);
CaptureStackBackTraceType
func
=
(
CaptureStackBackTraceType
)(
GetProcAddress
(
LoadLibrary
(
_T
(
"kernel32.dll"
)),
"RtlCaptureStackBackTrace"
));
if
(
func
==
NULL
)
return
;
// WOE 29.SEP.2010
// Quote from Microsoft Documentation:
// ## Windows Server 2003 and Windows XP:
// ## The sum of the FramesToSkip and FramesToCapture parameters must be less
// than 63.
#define MAX_CALLERS 62
void
*
callers_stack
[
MAX_CALLERS
];
unsigned
short
frames
;
SYMBOL_INFOW
*
symbol
;
HANDLE
process
;
process
=
GetCurrentProcess
();
SymInitialize
(
process
,
NULL
,
TRUE
);
frames
=
(
func
)(
0
,
MAX_CALLERS
,
callers_stack
,
NULL
);
symbol
=
(
SYMBOL_INFOW
*
)
calloc
(
sizeof
(
SYMBOL_INFOW
)
+
256
*
sizeof
(
wchar_t
),
1
);
symbol
->
MaxNameLen
=
255
;
symbol
->
SizeOfStruct
=
sizeof
(
SYMBOL_INFOW
);
const
unsigned
short
MAX_CALLERS_SHOWN
=
32
;
frames
=
frames
<
MAX_CALLERS_SHOWN
?
frames
:
MAX_CALLERS_SHOWN
;
for
(
unsigned
int
i
=
0
;
i
<
frames
;
i
++
)
{
SymFromAddrW
(
process
,
(
DWORD64
)(
callers_stack
[
i
]),
0
,
symbol
);
fwprintf
(
stderr
,
L"*** %d: %016I64X %ls - %016I64X
\n
"
,
i
,
(
DWORD64
)
callers_stack
[
i
],
symbol
->
Name
,
(
DWORD64
)
symbol
->
Address
);
}
free
(
symbol
);
}
static
void
print_stack_from_context
(
CONTEXT
c
)
{
STACKFRAME
s
;
// in/out stackframe
memset
(
&
s
,
0
,
sizeof
(
s
));
DWORD
imageType
;
#ifdef _M_IX86
// normally, call ImageNtHeader() and use machine info from PE header
imageType
=
IMAGE_FILE_MACHINE_I386
;
s
.
AddrPC
.
Offset
=
c
.
Eip
;
s
.
AddrPC
.
Mode
=
AddrModeFlat
;
s
.
AddrFrame
.
Offset
=
c
.
Ebp
;
s
.
AddrFrame
.
Mode
=
AddrModeFlat
;
s
.
AddrStack
.
Offset
=
c
.
Esp
;
s
.
AddrStack
.
Mode
=
AddrModeFlat
;
#elif _M_X64
imageType
=
IMAGE_FILE_MACHINE_AMD64
;
s
.
AddrPC
.
Offset
=
c
.
Rip
;
s
.
AddrPC
.
Mode
=
AddrModeFlat
;
s
.
AddrFrame
.
Offset
=
c
.
Rsp
;
s
.
AddrFrame
.
Mode
=
AddrModeFlat
;
s
.
AddrStack
.
Offset
=
c
.
Rsp
;
s
.
AddrStack
.
Mode
=
AddrModeFlat
;
#elif _M_IA64
imageType
=
IMAGE_FILE_MACHINE_IA64
;
s
.
AddrPC
.
Offset
=
c
.
StIIP
;
s
.
AddrPC
.
Mode
=
AddrModeFlat
;
s
.
AddrFrame
.
Offset
=
c
.
IntSp
;
s
.
AddrFrame
.
Mode
=
AddrModeFlat
;
s
.
AddrBStore
.
Offset
=
c
.
RsBSP
;
s
.
AddrBStore
.
Mode
=
AddrModeFlat
;
s
.
AddrStack
.
Offset
=
c
.
IntSp
;
s
.
AddrStack
.
Mode
=
AddrModeFlat
;
#else
#error "Platform not supported!"
#endif
HANDLE
process
=
GetCurrentProcess
();
HANDLE
thread
=
GetCurrentThread
();
SYMBOL_INFOW
*
symbol
=
(
SYMBOL_INFOW
*
)
calloc
(
sizeof
(
SYMBOL_INFOW
)
+
256
*
sizeof
(
wchar_t
),
1
);
symbol
->
MaxNameLen
=
255
;
symbol
->
SizeOfStruct
=
sizeof
(
SYMBOL_INFOW
);
while
(
StackWalk
(
imageType
,
process
,
thread
,
&
s
,
&
c
,
0
,
SymFunctionTableAccess
,
SymGetModuleBase
,
0
))
{
BOOL
has_symbol
=
SymFromAddrW
(
process
,
(
DWORD64
)(
s
.
AddrPC
.
Offset
),
0
,
symbol
);
fwprintf
(
stderr
,
L"*** %016I64X %ls - %016I64X
\n
"
,
(
DWORD64
)(
s
.
AddrPC
.
Offset
),
has_symbol
?
symbol
->
Name
:
L"<<no symbol>>"
,
(
DWORD64
)
symbol
->
Address
);
}
free
(
symbol
);
}
static
LONG
crash_handler
(
struct
_EXCEPTION_POINTERS
*
ex_info
)
{
fprintf
(
stderr
,
"Exception handler called, dumping information
\n
"
);
bool
try_to_print_stack
=
true
;
PEXCEPTION_RECORD
exrec
=
ex_info
->
ExceptionRecord
;
while
(
exrec
)
{
DWORD
code
=
exrec
->
ExceptionCode
;
DWORD
flgs
=
exrec
->
ExceptionFlags
;
PVOID
addr
=
exrec
->
ExceptionAddress
;
if
(
code
==
EXCEPTION_STACK_OVERFLOW
)
try_to_print_stack
=
false
;
fprintf
(
stderr
,
"code: %x - flags: %d - address: %p
\n
"
,
code
,
flgs
,
addr
);
exrec
=
exrec
->
ExceptionRecord
;
}
if
(
try_to_print_stack
)
{
print_stack_from_context
(
*
ex_info
->
ContextRecord
);
}
}
if
(
IsDebuggerPresent
())
{
if
(
IsDebuggerPresent
())
{
__debugbreak
();
__debugbreak
();
...
@@ -69,8 +182,9 @@ LONG crash_handler(struct _EXCEPTION_POINTERS *ex_info) {
...
@@ -69,8 +182,9 @@ LONG crash_handler(struct _EXCEPTION_POINTERS *ex_info) {
return
EXCEPTION_EXECUTE_HANDLER
;
return
EXCEPTION_EXECUTE_HANDLER
;
}
}
void
abort_handler
(
int
sig
)
{
static
void
abort_handler
(
int
sig
)
{
gpr_log
(
GPR_DEBUG
,
"Abort handler called."
);
fprintf
(
stderr
,
"Abort handler called.
\n
"
);
print_current_stack
(
NULL
);
if
(
IsDebuggerPresent
())
{
if
(
IsDebuggerPresent
())
{
__debugbreak
();
__debugbreak
();
}
else
{
}
else
{
...
@@ -79,17 +193,20 @@ void abort_handler(int sig) {
...
@@ -79,17 +193,20 @@ void abort_handler(int sig) {
}
}
static
void
install_crash_handler
()
{
static
void
install_crash_handler
()
{
if
(
!
SymInitialize
(
GetCurrentProcess
(),
NULL
,
TRUE
))
{
fprintf
(
stderr
,
"SymInitialize failed: %d
\n
"
,
GetLastError
());
}
SetUnhandledExceptionFilter
((
LPTOP_LEVEL_EXCEPTION_FILTER
)
crash_handler
);
SetUnhandledExceptionFilter
((
LPTOP_LEVEL_EXCEPTION_FILTER
)
crash_handler
);
_set_abort_behavior
(
0
,
_WRITE_ABORT_MSG
);
_set_abort_behavior
(
0
,
_WRITE_ABORT_MSG
);
_set_abort_behavior
(
0
,
_CALL_REPORTFAULT
);
_set_abort_behavior
(
0
,
_CALL_REPORTFAULT
);
signal
(
SIGABRT
,
abort_handler
);
signal
(
SIGABRT
,
abort_handler
);
}
}
#elif GPR_POSIX_CRASH_HANDLER
#elif GPR_POSIX_CRASH_HANDLER
#include
<errno.h>
#include
<execinfo.h>
#include
<execinfo.h>
#include
<grpc/support/useful.h>
#include
<stdio.h>
#include
<stdio.h>
#include
<string.h>
#include
<string.h>
#include
<grpc/support/useful.h>
#include
<errno.h>
static
char
g_alt_stack
[
MINSIGSTKSZ
];
static
char
g_alt_stack
[
MINSIGSTKSZ
];
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment