I'm learning intel pin now.
I wanna catch the crash env(registers),but I don't find any API on this after looking through the PIN's User Guide.
Checking each BBLs' eip before jump seems to be a solution to this,but is there any useful API could soulve this gracefully?
Thx a lot for any help:)
There is an exception handler.
typedef VOID(* LEVEL_PINCLIENT::CONTEXT_CHANGE_CALLBACK)(THREADID threadIndex, CONTEXT_CHANGE_REASON reason, const CONTEXT *from, CONTEXT *to, INT32 info, VOID *v)
Related
The documentation page for cudaStreamAddCallback says that it is "slated for eventual deprecation and removal" and to use cudaLaunchHostFunc instead. However, documentation for cudaLaunchHostFunc says that the host functions is not allowed to make any CUDA calls. The callback for cudaLaunchHostFunc also is of type
typedef void (CUDART_CB *cudaHostFn_t)(void *userData);
instead of
typedef void (CUDART_CB *cudaStreamCallback_t)(cudaStream_t stream, cudaError_t status, void *userData);
that cudaStreamAddCallBack accepts. I can include the stream information in void* userData but how am I supposed to recover if an error occurs after the callback is attached?
I was told by CUDA folks that even though cudaAddStreamCallback is marked as deprecated there is currently no alternative to it and that cudaAddStreamCallback is not going to be removed until some alternative arrives.
In Lablgtk, whenever there is an exception in a callback, the exception is automatically caught and an error message is printed in the console, such as:
(prog:12345) LablGTK-CRITICAL **: gtk_tree_model_foreach_func:
callback raised an exception
This gives no stack trace and no details about the exception, and because it is caught I cannot retrieve this information myself.
Can I enable more detailed logging information for this case? Or prevent the exception from being caught automatically?
I guess the best way to do so is to catch your exception manually and handle it yourself.
let callback_print_exn f () =
try f () with
e -> my_exn_printer e
Assuming val my_exn_printer : exn -> unit is your custom exception printer, you can simply print your callbacks exceptions by replacing ~callback:f by ~callback:(callback_print_exn f) in your code.
Of course, you can also with that method send that exception to another
thread, register a "callback id" that would be passed along with your exception...
About the stack trace, I'm not sure you can retrieve it easily. As it's launched as a callback, you probably want to know the signal used and that can be stored in your callback handler.
I had another similar issue, but this time it was harder to find where to put the calls to intercept the exception.
Fortunately, this time there was a very specific error message coming from the Glib C code:
GLib-CRITICAL **: Source ID ... was not found when attempting to remove it`
Stack Overflow + grep led me to the actual C function, but I could not find which of the several Lablgtk functions bound to this code was the culprit.
So I downloaded the Glib source, added an explicit segmentation fault to the code, compiled it and used LD_LIBRARY_PATH to force my modified Glib version to be loaded.
Then I ran the OCaml binary with gdb, and I got my stack trace, with the precise line number where the Lablgtk function was being called. And from there it was a quick 3-line patch.
Hacks like this one (which was still faster than trying to find where to intercept the call) could be avoided by having a "strict mode" preventing exceptions from being automatically caught. I still believe such a switch should be available for Lablgtk users, and hope it will eventually be available.
I tried many ways but nothing works fine. I am novice at programming and multuthreading operations is steel hard for me to understand.
In Windows Metro i can use:
Appcallbacks.instance.InvokeOnAppThread
How can i do it in wp8?
This work, but throw C++ exception, and i know that it's not right way
Deployment.Current.Dispatcher.BeginInvoke(()=>UnityApp.BeginInvoke(new UnityPlayer.Action(() => { my functions })));
Unity3d is not thread safe and you can't call it from any other thread, other than the main thread: http://answers.unity3d.com/questions/7524/is-the-unity-api-threadsafe.html
You must compile a native WP8 dll and invoke the Dispatcher from there. Make a static WP8 method with a callback that Unity code can use.
I'm trying to handle network failure exceptions when using Google Drive SDK and I have the following problem.
I'm disconnecting my network and running this code
try
{
FilesResource.InsertRequest r = service_.Files.Insert(body);
r.Fetch();
} catch
{
Console.WriteLine("Error");
}
but instead of printing "Error" the application is terminated due to unhandled exception.
Debugger shows the following stack trace
Unable to connect to the remote server
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult)
at Google.Apis.Requests.Request.EndAttachBody(IAsyncResult asyncResult) in c:\code.google.com\google-api-dotnet-client\default_release\Tools\BuildRelease\bin\Debug\output\default\Src\GoogleApis\Apis\Requests\Request.cs:line 714
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.HttpWebRequest.SetResponse(Exception E)
at System.Net.HttpWebRequest.SetAndOrProcessResponse(Object responseOrException)
at System.Net.ConnectionReturnResult.SetResponses(ConnectionReturnResult returnResult)
Looks like Fetch() does some asynchronous operations inside and the exception is not handled. So I can't find a way handling this exception. It always terminates my application. How can I fix that?
update
I found this line of code
Stream bodyStream = request.EndGetRequestStream(asyncResult);
in Src\GoogleApis.Tests\Apis\Requests\RequestTest.cs:731
EndGetRequestStream throws an exception which is unhandled by the thread, so it looks like this is a bug in Client API. Am I right? Any workarounds?
update
Any answers? That's very important. My application crashes every time I disconnect the network and this cannot be solved without touching Google API source codes. I changed BeginGetResponse() to GetResponse() and recompiled the code, so currently it works for me and Fetch() throws an exception as expected, but synchronous and asynchronous operations are sharing a common code (synchronous operation executes asynchronous and waits) so currently I can't do async fetch. Will you guys fix this?
update
Google says We support the Google Drive SDK on Stack Overflow.
Guys, do you really provide kind of support for your SDK? I'm waiting for ANY answer almost 5 days. Is there anybody?
Sorry for the delay.
It looks like a bug and I just opened a new issue in our issue tracker - you can add more details to it here.
We will try to fix it in the next release.
In the next couple of weeks we are going to publish version 1.4.0-beta which has a fix for this problem. Just to let you know, the new version of Google.Apis core library will be PCL. It requires upgrading the .NET framework to 4.0, and there is a great usage of TPL.
I have an MFC application compiled with /clr and I'm trying to implement a final handler for otherwise un-caught managed exceptions. For native exceptions, overriding CWinApp::ProcessWndProcException works.
The two events suggested in Jeff's CodeProject article,Application.ThreadException and AppDomain.CurrentDomain.UnhandledException, are not raised.
Can anyone suggest a way to provide a final managed exception handler for a mixed executable?
Update:
It appears that these exception handlers are only triggered downstream of Application.Run or similar (there's a worker thread flavor, can't remember the name.) If you want to truly globally catch a managed exception you do need to install an SEH filter. You're not going to get a System.Exception and if you want a callstack you're going to have to roll your own walker.
In an MSDN forum question on this topic it was suggested to override a sufficiently low-level point of the main MFC thread in a try ... catch (Exception^). For instance, CWinApp::Run. This may be a good solution but I haven't looked at any perf or stability implications. You'll get a chance to log with a call stack before you bail and you can avoid the default windows unahndled exception behavior.
Taking a look around the internets, you'll find that you need to install a filter to get the unmanaged exceptions passing the filters on their way to your AppDomain. From CLR and Unhandled Exception Filters:
The CLR relies on the SEH unhandled exception filter mechanism to catch unhandled exceptions.
Using those two exception handlers should work.
Why "should?"
The events are not raised using the below:
extern "C" void wWinMainCRTStartup();
// managed entry point
[System::STAThread]
int managedEntry( void )
{
FinalExceptionHandler^ handler = gcnew FinalExceptionHandler();
Application::ThreadException += gcnew System::Threading::ThreadExceptionEventHandler(
handler,
&FinalExceptionHandler::OnThreadException);
AppDomain::CurrentDomain->UnhandledException += gcnew UnhandledExceptionEventHandler(
handler,
&FinalExceptionHandler::OnAppDomainException);
wWinMainCRTStartup();
return 0;
}
// final thread exception handler implementation
void FinalExceptionHandler::OnThreadException( Object^ /* sender */, System::Threading::ThreadExceptionEventArgs^ t )
{
LogWrapper::log->Error( "Unhandled managed thread exception.", t->Exception );
}
// final appdomain exception handler implementation
void FinalExceptionHandler::OnAppDomainException(System::Object ^, UnhandledExceptionEventArgs ^args)
{
LogWrapper::log->Error( "Unhandled managed appdomain exception.", (Exception^)(args->ExceptionObject) );
}
BOOL CMyApp::InitInstance()
{
throw gcnew Exception("test unhandled");
return TRUE;
}
Using those two exception handlers should work. Are you sure you've added them in a place where they're going to be called and properly set (ie, in your application's managed entry point -- you did put one in, right?)