Debugging a segfault with lldb

I’m trying to find out why RadeonProRender.jl segfaults on Mac.

I put the code at the bottom into a script rpr.jl and then ran this:

lldb julia -- rpr.jl
(lldb) target create "julia"
Current executable set to 'julia' (arm64).
(lldb) settings set -- target.run-args  "rpr.jl"
(lldb) run
Process 84928 launched: '/Users/.../.juliaup/bin/julia' (arm64)
┌ Warning: The Pkg REPL mode is intended for interactive use only, and should not be used from scripts. It is recommended to use the functional API instead.
└ @ Pkg.REPLMode /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-x64-6.0/build/default-macmini-x64-6-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/Pkg/src/REPLMode/REPLMode.jl:379
  Activating project at `~/.julia/environments/radeon`

signal (11): Segmentation fault: 11
Process 84928 exited with status = 1 (0x00000001)
(lldb) bt
error: invalid thread
(lldb)

So my problem seems to be that the debugger doesn’t stop when the segfault is hit, instead the process exits with status = 1 and then obviously lldb commands like bt don’t work. I thought that lldb would automatically stop the process when a segfault is hit, why is this not the case here?

The script:

using Pkg
pkg"activate @radeon"
using RadeonProRender, GeometryBasics, Colors
const RPR = RadeonProRender

context = RPR.Context(resource=RPR.RPR_CREATION_FLAGS_ENABLE_CPU)
scene = RPR.Scene(context)
matsys = RPR.MaterialSystem(context, 0)
camera = RPR.Camera(context)
lookat!(camera, Vec3f(8, 0, 5), Vec3f(2, 0, 2), Vec3f(0, 0, 1))
RPR.rprCameraSetFocalLength(camera, 45.0)
set!(scene, camera)
set!(context, scene)
env_light = RadeonProRender.EnvironmentLight(context)
image_path = RPR.assetpath("studio026.exr")
img = RPR.Image(context, image_path)
set!(env_light, img)
setintensityscale!(env_light, 1.1)
push!(scene, env_light)

light = RPR.PointLight(context)
transform!(light, Float32[1.0 0.0 0.0 2.0; 0.0 1.0 0.0 0.0; 0.0 0.0 1.0 5.0; 0.0 0.0 0.0 1.0])
f = 20
RPR.setradiantpower!(light, 500 / f, 641 / f, 630 / f)
push!(scene, light)

function add_shape!(scene, context, matsys, mesh; material=RPR.RPR_MATERIAL_NODE_DIFFUSE,
                    color=colorant"green", roughness=0.01)
    rpr_mesh = RadeonProRender.Shape(context, mesh)
    push!(scene, rpr_mesh)
    m = RPR.MaterialNode(matsys, material)
    set!(m, RPR.RPR_MATERIAL_INPUT_COLOR, color)
    set!(m, RPR.RPR_MATERIAL_INPUT_ROUGHNESS, roughness, roughness, roughness, roughness)
    set!(rpr_mesh, m)
    return rpr_mesh, m
end

mesh, mat = add_shape!(scene, context, matsys, Rect3f(Vec3f(-10, -10, -1), Vec3f(20, 20, 1));
                       color=colorant"white")
mesh, mat = add_shape!(scene, context, matsys, Rect3f(Vec3f(0, -10, 0), Vec3f(0.1, 20, 5));
                       color=colorant"white")
mesh, mat = add_shape!(scene, context, matsys, Rect3f(Vec3f(0, -2, 0), Vec3f(5, 0.1, 5));
                       color=colorant"white")
mesh, mat = add_shape!(scene, context, matsys, Rect3f(Vec3f(0, 2, 0), Vec3f(5, 0.1, 5));
                       color=colorant"white")

mesh, mat_sphere = add_shape!(scene, context, matsys, Tesselation(Sphere(Point3f(2, 0, 2), 1.0f0), 100);
                              material=RPR.RPR_MATERIAL_NODE_MICROFACET, roughness=0.2, color=colorant"red")
fb_size = (800, 600)
frame_buffer = RPR.FrameBuffer(context, RGBA, fb_size)
frame_bufferSolved = RPR.FrameBuffer(context, RGBA, fb_size)
set!(context, RPR.RPR_AOV_COLOR, frame_buffer)
set_standard_tonemapping!(context)
clear!(frame_buffer)
path = joinpath(@__DIR__, "test.png")
RPR.rprContextSetParameterByKey1u(context, RPR.RPR_CONTEXT_ITERATIONS, 1)
@time RPR.render(context)

Try setting a breakpoint on jl_critical_error.

Hmm I built latest master with make debug but still I get:

(lldb) breakpoint set -n jl_critical_error
Breakpoint 2: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.

Actually the autocomplete feature doesn’t show anything that starts with jl, but there should be lots.

Edit: Ah ok I need to start over anyway, RPR doesn’t have an ARM jll but my build was for that.