Skip to content

Enter debugger more reliably in let expressions and function calls#9917

Merged
thufschmitt merged 2 commits intoNixOS:masterfrom
9999years:enter-debugger-more-reliably
Feb 8, 2024
Merged

Enter debugger more reliably in let expressions and function calls#9917
thufschmitt merged 2 commits intoNixOS:masterfrom
9999years:enter-debugger-more-reliably

Conversation

@9999years
Copy link
Contributor

@9999years 9999years commented Feb 3, 2024

Motivation

Currently, if you attempt to evaluate this file with the debugger:

let
  a = builtins.trace "before inner break" (
    builtins.break "hello"
  );
  b = builtins.trace "before outer break" (
    builtins.break a
  );
in
  b

Nix will correctly enter the debugger at builtins.break a, but if you ask it to :continue, it'll skip over the builtins.break "hello" expression entirely:

$ nix eval --file xxx-test.nix --debugger
trace: before outer break
info: breakpoint reached

      at «none»:0: (source not available)


Starting REPL to allow you to inspect the current state of the evaluator.

Welcome to Nix 2.18.1. Type :? for help.

nix-repl> :c
trace: before inner break
"hello"

This is because the set of debug traces is empty by the time Nix gets to the second call:

if (state.debugRepl && !state.debugTraces.empty()) {

With this patch, Nix will correctly enter the debugger both times:

$ nix eval --file xxx-test.nix --debugger
trace: before outer break
info: breakpoint reached


Starting REPL to allow you to inspect the current state of the evaluator.

Welcome to Nix 2.20.0pre20231222_dirty. Type :? for help.

nix-repl> :c
trace: before inner break
info: breakpoint reached


Starting REPL to allow you to inspect the current state of the evaluator.

Welcome to Nix 2.20.0pre20231222_dirty. Type :? for help.

nix-repl> :c
"hello"

Context

Fixes #6649.

Priorities and Process

Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@9999years 9999years requested a review from edolstra as a code owner February 3, 2024 03:19
@9999years 9999years changed the title Enter debugger more reliably in let expressions and calls Enter debugger more reliably in let expressions and function calls Feb 3, 2024
Comment on lines +1333 to +1334
"while evaluating a '%1%' expression",
"let"
Copy link
Member

@thufschmitt thufschmitt Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just replace that by

Suggested change
"while evaluating a '%1%' expression",
"let"
"while evaluating a 'let' expression"

and not add the formatting logic in makeDebugTraceStacker?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nvm, I didn't notice that makeDebugTraceStacker was already using hintfmt, just with a hardcoded number of 2 elements 😬 .

It makes sense to make it a bit more generic then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also colors "let" magenta like the other things in error messages.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right :) This thing is still too magical for me

@thufschmitt thufschmitt merged commit c4ed92f into NixOS:master Feb 8, 2024
@9999years 9999years deleted the enter-debugger-more-reliably branch February 8, 2024 16:36
lf- added a commit to lf-/nix that referenced this pull request Mar 6, 2024
lf- added a commit to lf-/nix that referenced this pull request Mar 6, 2024
lf- added a commit to lf-/nix that referenced this pull request Mar 6, 2024
lf- added a commit to lf-/nix that referenced this pull request Mar 10, 2024
lf- added a commit to lf-/nix that referenced this pull request Mar 10, 2024
lf- added a commit to lf-/nix that referenced this pull request Mar 13, 2024
tebowy pushed a commit to tebowy/nix that referenced this pull request Jul 11, 2024
…ably

Enter debugger more reliably in `let` expressions and function calls

(cherry picked from commit c4ed92f)
Change-Id: I16d0cad7e898feecd2399723b92ba8df67222fb4
tebowy pushed a commit to tebowy/nix that referenced this pull request Jul 11, 2024
Change-Id: Ib0591e1499c5dba5e5a83ee75a899c9d16986827
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

builtins.break doesn't break

2 participants