I'm trying to write a Signal handler that gets everytime called when my programm crashes and than writes the informations the boost::stacktracer
api gives me into a file on my harddrive.
Writing the handler is no problem as well as crashing my programm isn't.
But now I am totally unsure what functions I can use in my handler.
The functions I'm going to use needs to be Async safe I get that but I just can't find a list for windows which functions are allowed to use I got a list for Linux which is pretty clear and pretty easy to understand but useless since the most functions are from <unistd.h>
and this does not exist in windows or atleast not in VS2017s compiler.
Since I read that <io.h>
is pretty simillar to <unistd.h>
I tried to achiev my goal with functions out of this header.
So I use _sopen_s(&fileHandle,"E:\\UslessStuff\\stacktracer.txt",_O_RDWR,_SH_DENYNO,_S_IWRITE);
to open a file and
if(_write(fileHandle,&boost::stacktrace::stacktrace(),boost::stacktrace::stacktrace().size())==-1) {
switch(errno) {
case EBADF:
perror("Bad File Discription");
break;
case ENOSPC:
perror("No Space left on Device");
break;
case EINVAL:
perror("Invalid Parameter: Buffer was NULL");
break;
default:
perror("Unexpectet Error");
break;
}
}
for writing.
So I want to no is it okay to use this functions?
Also how far can I go with strings in a Signal?
As you see I try to get informations from boost::stacktrace::stacktrace()
which gives me a perfect result when I use it with cout << boost::stacktrace::stacktrace()
but writes me just 2 RAM addresses in my Textfile when I try to write it like shown above so I think I migth need to extract the string from boost::stacktrace::stacktrace()
with creating a boost::stacktrace::frame fr
which would result in fr.source_file().c_str();
so it'd give me a std::string
back which I probably would need to pack in a char*
which really sounds like I shouldn't do it in a Signal