Comments (8)
@CNchence
猜测 mono_native_thread_set_name 内部做了类似下面的事情,请参考这里
#pragma pack(pop)
void SetThreadName(DWORD dwThreadID, const char* threadName) {
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = threadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
#pragma warning(push)
#pragma warning(disable: 6320 6322)
__try{
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info);
}
__except (EXCEPTION_EXECUTE_HANDLER){
}
#pragma warning(pop)
内部调用 RaiseException 抛出了异常,被 log 库捕捉到了。
用下面这段代码,复现了你的问题:
//
// Usage: SetThreadName ((DWORD)-1, "MainThread");
//
#include <windows.h>
const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
DWORD dwType; // Must be 0x1000.
LPCSTR szName; // Pointer to name (in user addr space).
DWORD dwThreadID; // Thread ID (-1=caller thread).
DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)
void SetThreadName(DWORD dwThreadID, const char* threadName) {
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = threadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
#pragma warning(push)
#pragma warning(disable: 6320 6322)
__try{
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info);
}
__except (EXCEPTION_EXECUTE_HANDLER){
}
#pragma warning(pop)
}
from coost.
@idealvin
感谢回答和分析,我在dll工程中Release运行目标exe,打印log正常,但是直接运行目标exe就会出现.fatal文件。看fatal文件的错误,怀疑是直接运行exe时log无法拿到目标线程名导致的错误。
from coost.
co/base/stack_trace/stack_trace_win.cpp
可以在这个地方 加一行
return 0;
忽略掉异常
from coost.
仍然会有问题,相应线程调用log打印的数据仍然无法写入文件
from coost.
@CNchence 无法写日志到文件是另外一个问题,log 库捕获到异常后,调用 log::close() 关闭了写日志的线程。请更新代码,再验证一下
from coost.
from coost.
新代码验证了,没有问题
from coost.
👌
from coost.
Related Issues (20)
- json是否支持多种编码? HOT 2
- 线程频繁创建销毁出现内存泄露 HOT 2
- mkconf 导出参数默认值带有“//”时的问题 HOT 2
- 用wait_group执行计算图 HOT 2
- IOS旧设备上存在加载库就内存申请奔溃现象 HOT 2
- Windows 10使用最新版代码,程序退出时Log crash HOT 2
- Memory allocation error using co/stl containers (co::vector, co::hash_map) HOT 6
- 在armv7下运行协程会coredump HOT 3
- hook失效 HOT 15
- windows下使用CMake GUI进行配置,没有BUILD_SHARED_LIBS 选项 HOT 2
- json如何输出这种格式?转义 HOT 2
- 这个库有办法使用emscripten来编译成wasm吗?有汇编无法编译成wasm吧?
- about multiple definitions HOT 1
- 关于日志和终端输出的建议 HOT 1
- Please add Meson build script
- co::shared & co::unique 存在问题 HOT 1
- 动态库链接libco.a后无法被动态加载(Linux下)
- 1
- Windows arm64编译报错MASM not supported on this platform
- Failed to build on FreeBSD
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coost.