# How to debug julia callback function which passed to a C lib

**URL:** https://discourse.julialang.org/t/how-to-debug-julia-callback-function-which-passed-to-a-c-lib/78007
**Category:** Tooling
**Created:** [March 17, 2022, 5:38am UTC](https://discourse.julialang.org/t/how-to-debug-julia-callback-function-which-passed-to-a-c-lib/78007 "2022-03-17T05:38:02Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![linanisyugioh](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@linanisyugioh](https://discourse.julialang.org/u/linanisyugioh)
#### Post date: [March 17, 2022, 5:38am UTC](https://discourse.julialang.org/t/how-to-debug-julia-callback-function-which-passed-to-a-c-lib/78007/1 "2022-03-17T05:38:02Z")

</div>

[![](https://global.discourse-cdn.com/julialang/original/3X/8/4/84835bdf4dc89da7567a85dccffb0bd41d041ee5.jpeg "debbug julia code") ](https://www.youtube.com/watch?v=BNpkzzSkPco)

I recorded a video to show the process of debug. In this video, you can obviously see that the debugger cannot hit the breakpoint in a Julia callback function. The definition  
of this function is showed below:

```julia
function on_exit(reason::Cint, user_data::Ptr{Cvoid})::Cvoid
    strategy_log(2, string("strategy exit, reason:", reason))
    println("This is a julia callback function passed to C lib")
    println("debugger cannot hit this breakpoint")
    println("strategy completed")
    nothing
end

#Using cfunction can pass julia callback function to c
function strategy_set_exit_callback(on_exit::Function)::Cint
    on_exit_c = @cfunction($on_exit, Cvoid, (Cint, Ptr{Cvoid}))
    user_data = Ref{Cvoid}()
    err = ccall((:strategy_set_exit_callback, lib), Int32, (Ptr{Cvoid}, Ptr{Cvoid}), on_exit_c, user_data)
    return err
end
strategy_set_exit_callback(on_exit)

```

This callback function is passed to a c lib by the macro @cfunction.  
Is there any way to debug the callback function?

---

<div class="post-metadata">

### Author: ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)
#### Post date: [March 17, 2022, 6:48am UTC](https://discourse.julialang.org/t/how-to-debug-julia-callback-function-which-passed-to-a-c-lib/78007/2 "2022-03-17T06:48:22Z")

</div>

I would be surprised if JuliaInterpreter could work across language boundaries.
