Problem: exception thrown when debugging cl.exe x64 build with LLDB (#4129)

* Problem: exception thrown when debugging
cl.exe x64 build with LLDB

Solution: Use __try __except with cl.exe and
use pthread_setname_np with MinGW.
Remove usage of pushing exception handler
to TIB->ExceptionList.
This commit is contained in:
Lingqiao Zhao
2021-01-27 18:39:48 +08:00
committed by GitHub
parent 16af1bd622
commit cc65a9ec93
2 changed files with 43 additions and 29 deletions

15
RELICENSE/c-zhao-3g.md Normal file
View File

@@ -0,0 +1,15 @@
# Permission to Relicense under MPLv2 or any other OSI approved license chosen by the current ZeroMQ BDFL
This is a statement by Lingqiao Zhao
that grants permission to relicense its copyrights in the libzmq C++
library (ZeroMQ) under the Mozilla Public License v2 (MPLv2) or any other
Open Source Initiative approved license chosen by the current ZeroMQ
BDFL (Benevolent Dictator for Life).
A portion of the commits made by the Github handle "s-zhao-3g", with
commit author "s-zhao-3g <forever.3g@hotmail.com>", are copyright of Lingqiao Zhao.
This document hereby grants the libzmq project team to relicense libzmq,
including all past, present and future contributions of the author listed above.
Lingqiao Zhao
2021/01/26

View File

@@ -36,6 +36,10 @@
#include <winnt.h> #include <winnt.h>
#endif #endif
#ifdef __MINGW32__
#include "pthread.h"
#endif
bool zmq::thread_t::get_started () const bool zmq::thread_t::get_started () const
{ {
return _started; return _started;
@@ -111,6 +115,8 @@ void zmq::thread_t::
// not implemented // not implemented
} }
#ifdef _MSC_VER
namespace namespace
{ {
#pragma pack(push, 8) #pragma pack(push, 8)
@@ -124,22 +130,7 @@ struct thread_info_t
#pragma pack(pop) #pragma pack(pop)
} }
struct MY_EXCEPTION_REGISTRATION_RECORD #endif
{
typedef EXCEPTION_DISPOSITION (NTAPI *HandlerFunctionType) (
EXCEPTION_RECORD *, void *, CONTEXT *, void *);
MY_EXCEPTION_REGISTRATION_RECORD *Next;
HandlerFunctionType Handler;
};
static EXCEPTION_DISPOSITION NTAPI continue_execution (EXCEPTION_RECORD *rec,
void *frame,
CONTEXT *ctx,
void *disp)
{
return ExceptionContinueExecution;
}
void zmq::thread_t:: void zmq::thread_t::
applyThreadName () // to be called in secondary thread context applyThreadName () // to be called in secondary thread context
@@ -147,28 +138,36 @@ void zmq::thread_t::
if (!_name[0] || !IsDebuggerPresent ()) if (!_name[0] || !IsDebuggerPresent ())
return; return;
#ifdef _MSC_VER
thread_info_t thread_info; thread_info_t thread_info;
thread_info._type = 0x1000; thread_info._type = 0x1000;
thread_info._name = _name; thread_info._name = _name;
thread_info._thread_id = -1; thread_info._thread_id = -1;
thread_info._flags = 0; thread_info._flags = 0;
NT_TIB *tib = ((NT_TIB *) NtCurrentTeb ()); __try {
MY_EXCEPTION_REGISTRATION_RECORD rec;
rec.Next = (MY_EXCEPTION_REGISTRATION_RECORD *) tib->ExceptionList;
rec.Handler = continue_execution;
// push our handler, raise, and finally pop our handler
tib->ExceptionList = (_EXCEPTION_REGISTRATION_RECORD *) &rec;
const DWORD MS_VC_EXCEPTION = 0x406D1388; const DWORD MS_VC_EXCEPTION = 0x406D1388;
RaiseException (MS_VC_EXCEPTION, 0, RaiseException (MS_VC_EXCEPTION, 0,
sizeof (thread_info) / sizeof (ULONG_PTR), sizeof (thread_info) / sizeof (ULONG_PTR),
(ULONG_PTR *) &thread_info); (ULONG_PTR *) &thread_info);
tib->ExceptionList =
(_EXCEPTION_REGISTRATION_RECORD
*) (((MY_EXCEPTION_REGISTRATION_RECORD *) tib->ExceptionList)->Next);
} }
__except (EXCEPTION_CONTINUE_EXECUTION) {
}
#elif defined(__MINGW32__)
int rc = pthread_setname_np (pthread_self (), _name);
if (rc)
return;
#else
// not implemented
#endif
}
#elif defined ZMQ_HAVE_VXWORKS #elif defined ZMQ_HAVE_VXWORKS