Debugging FFI Calls

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Debugging FFI Calls

Eliot Miranda-2
Hi All,

    the latest VMs support a new facility which catches and reports exceptions during FFI calls as primitive failures.  That means that if you have the relevant support code loaded (described below) and depending on dialect, you write your FFI interface method to contain an error code, or you're using the UnifiedFFI which uses invokeWithArguments:, then any exception that occurs during the FFI call will be caught and reported to use with the error code bound to an instance of ExceptionInFFICall, which contains a platform-specific error code and the pc at which it occurred.

To use this facility you'll need to download a VM built yesterday or later (it should be derived from VMMaker.oscog-eem.2435 or later), or build your own from the tip of the Cog branch in opensmalltalk/vm.  You'll then need to update the image code to install ExceptionInFFICall appropriately:
in Pharo6 load SLICE 22367
in Squeak load the latest FFI code from source.squeak.org/FFI and update your image from trunk
in Cuis, you'll need to adapt these changes to Cuis (sorry!!)

There are two command-line flags to override the default behavior.  [-]-failonffiexception causes the handling to be applied to all FFI calls, so if a method doesn't contain an error, you'll just see a primitive failure, and if ExceptionInFFICall is not installed you'll see only an error number in the call's error code.

[-]-nofailonffiexception ignores exceptions during FFI calls, hence defaulting to the old behavior of crashing the VM (which may be useful if one is using a low-level debugger to debug the VM and/or external code).

HTH
_,,,^..^,,,_
best, Eliot


Reply | Threaded
Open this post in threaded view
|

Re: [Cuis-dev] Debugging FFI Calls

Juan Vuletich-3
Thanks Eliot!

The Cuis FFI package is now updated with your code, just taken from Squeak FFI package.

Cheers,
-- 
Juan Vuletich
www.cuis-smalltalk.org
https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev
https://github.com/jvuletich
https://www.linkedin.com/in/juan-vuletich-75611b3
@JuanVuletich

On 8/27/2018 6:36 PM, Eliot Miranda via Cuis-dev wrote:
Hi All,

    the latest VMs support a new facility which catches and reports exceptions during FFI calls as primitive failures.  That means that if you have the relevant support code loaded (described below) and depending on dialect, you write your FFI interface method to contain an error code, or you're using the UnifiedFFI which uses invokeWithArguments:, then any exception that occurs during the FFI call will be caught and reported to use with the error code bound to an instance of ExceptionInFFICall, which contains a platform-specific error code and the pc at which it occurred.

To use this facility you'll need to download a VM built yesterday or later (it should be derived from VMMaker.oscog-eem.2435 or later), or build your own from the tip of the Cog branch in opensmalltalk/vm.  You'll then need to update the image code to install ExceptionInFFICall appropriately:
in Pharo6 load SLICE 22367
in Squeak load the latest FFI code from source.squeak.org/FFI and update your image from trunk
in Cuis, you'll need to adapt these changes to Cuis (sorry!!)

There are two command-line flags to override the default behavior.  [-]-failonffiexception causes the handling to be applied to all FFI calls, so if a method doesn't contain an error, you'll just see a primitive failure, and if ExceptionInFFICall is not installed you'll see only an error number in the call's error code.

[-]-nofailonffiexception ignores exceptions during FFI calls, hence defaulting to the old behavior of crashing the VM (which may be useful if one is using a low-level debugger to debug the VM and/or external code).

HTH
_,,,^..^,,,_
best, Eliot