Skip to content

Debug breakpoint is hit when it shouldn't be #19443

@lawrence-laz

Description

@lawrence-laz

Zig Version

0.12.0-dev.2809+f3bd17772
0.12.0-dev.3439+31a7f22b8

Steps to Reproduce and Observed Behavior

Create a simple repro by running:

mkdir repro && cd repro
zig init
cat <<EOT > src/main.zig
const std = @import("std");

pub fn main() !void {
    var i: usize = 0;
    while (i < 100) : (i += 1) {
        if (i == 90) {
            std.debug.print("It's 90!", .{});
        } else if (i == 50) {
            std.debug.print("It's 50!", .{});
        }
    }
}
EOT
zig build
cd zig-out/bin/
lldb repro

Then in lldb console:

(lldb) b main.zig:9
Breakpoint 1: where = repro`main.main + 188 at main.zig:9:28, address = 0x0000000100000824
(lldb) run
Process 4864 launched: '~/zig/repro/zig-out/bin/repro' (arm64)
Process 4864 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100000824 repro`main.main at main.zig:9:28
   6            if (i == 90) {
   7                std.debug.print("It's 90!", .{});
   8            } else if (i == 50) {
-> 9                std.debug.print("It's 50!", .{});
   10           }
   11       }
   12   }
Target 0: (repro) stopped.
(lldb) var i
(unsigned long) i = 0
(lldb) continue
Process 4864 resuming
Process 4864 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100000824 repro`main.main at main.zig:9:28
   6            if (i == 90) {
   7                std.debug.print("It's 90!", .{});
   8            } else if (i == 50) {
-> 9                std.debug.print("It's 50!", .{});
   10           }
   11       }
   12   }
Target 0: (repro) stopped.
(lldb) var i
(unsigned long) i = 1

Notice how the breakpoint gets hit every cycle, even though the i == 50 should happen only once. Reading the i variable it prints 0, 1, etc.

Expected Behavior

Breakpoint should hit only once when i == 50.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend-llvmThe LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behaviordebug-infoDebug information of binary generated by Zig is not as expected.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions