I'm trying to implement signal handling in the Electron.js application to call a custom function either in C++ code or JS code (ex. segmentation fault). In one of the node addons, I did it using std::signal method and it works for macOS but on Windows it, unfortunately, doesn't work (although works on a simple node.js environment). I get the following error on the console when the app crashes: the custom handler doesn't work.
[10208:0815/181127.900:ERROR:crashpad_client_win.cc(814)] not connected
I'm using a 3rd party library that sends an interrupt from a separate thread in the kernel (RHEL 7.9) to an interrupt handler that I am trying to debug. I'm not able to get gdb (in Eclipse 4.11.0, CDT 9.7) to stop in my interrupt handler. I'm not even able to use std::cout to print out anything inside my handler.
The vendor uses Visual Studios and is able to get the debugger to stop in his interrupt handlers but wasn't familiar enough with gdb or Linux to know if it's possible with gdb.
I've been able to get other interrupt handlers from this same library to work but am having trouble with a specific handler that I'd like to step through so that I can figure out why it's not working properly.
Is there some setting or some step that I'm missing so that I can properly walk through my interrupt handler? Maybe a different technique to try to follow along with what is actually going on inside my interrupt handler?
Edit: I've tried using std::cout to print values I'm interested and outputting to a text file but neither have worked.
I'm using Qt 4.8.x so I don't have access to the new connect interface from Qt5, but I want to be alerted better when a signal/slot connection fails because I misspelled a signal or slot name.
Currently, all Qt does is spit out an error message when the connection is attempted. However, my program has a lot of output on stdout so it is easy to miss these errors sometimes. Is it possible to force my application to crash via assert, segfault, or other method, when a connect statement fails?
Yes: set the QT_FATAL_WARNINGS environment variable to a non-zero value.
You can do this during development in Qt Creator by going to the Projects pane, click Run, then under "Run Environment" click Details, then click Add.
Edit to add: you can of course also implement some wrappers for QObject::connect, that will check its return value and assert() if it returns false.
I think at least one of the solutions in this question: Qt GUI app: warning if QObject::connect() failed? does what you need.
In particular, by using QErrorMessage::qtHandler you should be able to intercept those warnings and do whatever you want with them.
I wrote a simple application to take pictures in c++ and am guessing I probably should do some cleanup whenever CTRL+C is pressed. I am using QTCreator to write the application along with MADDE, but am not really using any Qt hooks that I know of.
How can I handle CTRL+C in my application?
Thanks,
Walter
It appears that maemo is based on linux. In linux C programs, you get an OS signal that you must write a handler for. You can go that route, but Qt seems to offer a signal that it fires when a program is ready to quit.. http://doc.qt.nokia.com/stable/qcoreapplication.html#aboutToQuit
Here is some more info about how to go about catching the OS signal in question, and then acting on it. Note that if you catch the OS signal, you probably won't get the "aboutToQuit" signal automatically anymore.
http://doc.qt.nokia.com/4.7/unix-signals.html
We have an unmanaged C++ application that utilizes 3rd party APIs to read CAD files. On certain corrupted CAD files, the 3rd party library crashes and brings our EXE down with it. Because of this our main application is a separate EXE and in this way it does not get affected by the crash. Howevever, we end up with annoying Microsoft Error Reporting dialogs.
I do not want to disable Microsoft Error Reporting system wide. Is there a way to turn off error reporting for a single application, so that if it crashes, it crashes silently without error popup dialogs?
On Vista and above, the WerAddExcludedApplication API function can be used to exclude a specified application executable from error reporting. As far as I'm aware, there's no similar option on XP and other legacy OS versions.
However, since WER will only kick in on unhandled application exceptions, you should be able to suppress it by adding a "catch-all" exception handler to your EXE. See vectored exception handling for some ideas on how to achieve that.
Note that suppressing all unhandled exceptions is generally a bad idea (and will, for example, cause your app to fail Windows Logo certification), so you should not use this technique indiscriminately...
Yeah, there's something you can do. Call SetUnhandledExceptionFilter() in your main() method to register a callback. It will be called when nobody volunteers to handle the exception, just before the Microsoft WER dialog shows up.
Actually doing something in that callback is fraught with trouble. The program has died with, invariably, something nasty like an AccessViolation exception. Which often is tripped by heap corruption. Trying to do something like displaying a message box to let the user know is troublesome when the heap is toast. Deadlock is always lurking around the corner too, ready to just lock up the program without any diagnostic at all.
The only safe thing to do is to have a helper process that guards your main process. Wake it up by signaling a named event in your callback. Give it the exception info it needs with a memory-mapped file. The helper can do pretty much anything it wants when it sees the event signaled. Including showing a message, taking a minidump. And terminating the main process.
Which is exactly how the Microsoft WerFault helper works.
Hans Passant's answer about SetUnhandledExceptionFilter is on the right track. He also makes some good points about not being able to do too much within the callback because various parts of the process could be in an unstable state.
However, from the way the issue is described, it doesn't sound like you want to do anything except tell the system not to put up the normal crash dialog. In that case, it's easy and should be safe regardless of what parts of the process the crash may have affected.
Make a function something like this:
LONG WINAPI UnhandledExceptionCallback(PEXCEPTION_POINTERS pExceptPtrs)
{
if (IsDebuggerPresent())
// Allow normal crash handling, which means the debugger will take over.
return EXCEPTION_CONTINUE_SEARCH;
else
// Say we've handled it, so that the standard crash dialog is inhibited.
return EXCEPTION_EXECUTE_HANDLER;
}
And somewhere in your program (probably as early as possible) set the callback:
SetUnhandledExceptionFilter(UnhandledExceptionCallback);
That should do what you want - allow any crashes of that particular program to die silently.
However, there's something else to note about this: Any time you bring in 3rd-party components (DLLs, OCXs, etc) there is a risk that one of them may also call SetUnhandledExceptionFilter and thus replace your callback with their own. I once encountered an ActiveX control that would set its own callback when instantiated. And even worse, it failed to restore the original callback when it was destroyed. That seemed to be a bug in their code, but regardless I had to take extra steps to ensure that my desired callback was at least restored when it was supposed to be after their control was shutdown. So if you find this doesn't appear to work for you sometimes, even when you know you've set the callback correctly, then you may be encountering something similar.
I found myself in exactly this situation while developing a Delphi application. I found that I needed two things to reliably suppress the "app has stopped working" dialog box.
Calling SetErrorMode(SEM_NOGPFAULTERRORBOX); suppresses the "app has stopped working" dialog box. But then Delphi's exception handler shows a message box with a runtime error message instead.
To suppress Delphi's exception handler I call SetUnhandledExceptionFilter with a custom handler that terminates the process by calling Halt.
So the skeleton for a Delphi client app that runs code prone to crashes becomes:
function HaltOnException(const ExceptionInfo: TExceptionPointers): Longint; stdcall;
begin
Halt;
Result := 1; // Suppress compiler warning
end;
begin
SetErrorMode(SEM_NOGPFAULTERRORBOX);
SetUnhandledExceptionFilter(#HaltOnException);
try
DoSomethingThatMightCrash;
except
on E: Exception do
TellServerWeFailed(E.Message);
end;
end.
I'm not at all sure, but perhaps SetErrorMode or SetThreadErrorMode will work for you?