Stream: beginners

Topic: Is there a way to build with dbg


view this post on Zulip Oskar Hahn (Jan 31 2024 at 14:25):

Is there a way to build roc and keeping the dbg statements?

What I am trying to do is building an app with an go platform. The only way I know to do this, is building roc with roc build --no-link --output=host.o and then give the build host.o to go. But this binary object does not call dbg.

If this is currently not possible, is this something worth adding? For example an build argument like roc build --with-dbg?

view this post on Zulip Anton (Jan 31 2024 at 15:33):

I'm in favor of keeping dbg statements by default and only discarding them when the --optimize flag is used.

view this post on Zulip Brendan Hansknecht (Jan 31 2024 at 15:35):

We want to do that. Just hasn't been fixed yet

view this post on Zulip Brendan Hansknecht (Jan 31 2024 at 15:37):

Dbg is at least partially tied to expect. So the plan was update expect to also be a platform required function. (Currently expect is still stuck depending on the roc compiler in a way that stops it from being added to the build output). Then change the defaults.

view this post on Zulip Oskar Hahn (Jan 31 2024 at 15:38):

That is good to know (with the hope of a higher priority :sweat_smile:)

I am looking though the code. Here is the function, that decides if dbg statements are included: https://github.com/roc-lang/roc/blob/c63b6ca507fd401a94bde083c764e05054d9de08/crates/compiler/gen_llvm/src/llvm/build.rs#L721

Currently, there are only the modes Binary and BinaryDev (and other, that are not related). Would this mean, that a new mode BinaryOptimize has to be added?

view this post on Zulip Brendan Hansknecht (Jan 31 2024 at 15:40):

For the llvm backend, I'm pretty sure binary is optimized and binary dev is non-optimized. It is unrelated to the dev backend.

view this post on Zulip Oskar Hahn (Jan 31 2024 at 15:42):

I can only speak for my usecase. It seems, that go build --no-link uses the llvm backend. When I change the line LlvmBackendMode::Binary => false, to LlvmBackendMode::Binary => true,, then dbg works.

view this post on Zulip Brendan Hansknecht (Jan 31 2024 at 15:48):

Hmm...maybe optimize is a sub flag on binary.... anyway. Though that will work, if someone has an expect it will also generate. Which will break

view this post on Zulip Oskar Hahn (Jan 31 2024 at 15:53):

I will try this

view this post on Zulip Oskar Hahn (Jan 31 2024 at 16:18):

You are right. When I compile with the llvm backend, with the patch that includes dbg and expect, and the code contains a failing expect, then I get an error like this:

Bus error at address 0x7f8d84efd000
???:?:?: 0x55b56bebd17f in ??? (???)
Unwind error at address `:0x55b56bebd17f` (error.AddressOutOfRange), trace may be incomplete

/zig/0.11.0/files/lib/std/fmt.zig:1995:39: 0x55b56be32205 in bufPrint__anon_4972 (host)
    var fbs = std.io.fixedBufferStream(buf);
                                      ^
Abgebrochen (Speicherabzug geschrieben)

This is from a zig-platform and not the go-platform.

I don't understand why expect does not work with llvm? I would think, that it calls the same C-functions then the dev-backend.

view this post on Zulip Brendan Hansknecht (Jan 31 2024 at 16:22):

A few things are conflated here:

  1. I am pretty sure debug and expect never work with the dev backend at all. That is --dev.
  2. The llvm backend works with both dbg and expect.
  3. Only dbg has been updated to the new format where it is part of the platform as roc_dbg
  4. expect still needs to be updated. Until then, it is implement by communicating with the roc compiler binary using shared memory. So it only can work when the roc compiler binary is directly running an application.

Some context on what needs to be done is in #compiler development > roc_expect_failed

view this post on Zulip Oskar Hahn (Jan 31 2024 at 16:34):

Ahh. Ok. I understand. So for the moment, I do not use inline expects, use a patched roc binary, and hope, that someone finds the time to update the expect statement.

view this post on Zulip Brendan Hansknecht (Jan 31 2024 at 16:42):

Yeah, that works.


Last updated: Jul 06 2025 at 12:14 UTC