-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
debugger backtrace tests, fixes, ordering #8986
base: master
Are you sure you want to change the base?
Conversation
Ok I think this is ready for review. I removed the 'withTrace' code and didn't see a difference from that in the lang test output. We gained some additional stack locations in the lang test traces because of primop pos being available again. |
@bburdette have you considered using expect to script interaction with the debugger? |
I looked at expect for about an hour or so. Hard to tell how to use it for this case. I patterned the testRepl function in this after similar code in repl.sh. If expect is a requirement to land this I can delve deeper I suppose. One aspect here is the output from the repl includes some hex addresses from the nix program, which will vary depending on the build. So you can't count on a specific output being emitted, it has to be filtered. |
Well, the script would spawn Nix to evaluate a file that contains
I am just interested in the debugger, not a Nix maintainer, so I am not in a position to define requirements. I just genuinely think that expect would be a good fit.
Yeah, you can match output with regular expressions, and you can also skip matching output when it's not required. See https://stackoverflow.com/a/37255077 It's late in my timezone now, but I could write one of your tests as an expect script tomorrow (in 12-20 hours) so that you have a concrete example. Do you think that would help you? |
It seems like expect must not be used elsewhere in the nix tests, since they have their own expect/expectstderr functions in vars-and-functions.sh. That might need to be addressed. If you feel like making an example I'd be interested to see it. On that expect documentation page you referenced, most of the links are broken, particularly to the book and for 'expect for unix'. Do you have links for those, or some other more systematic introduction to expect/tcl besides just the man page? |
#! /usr/bin/env -S nix shell nixpkgs#expect --command expect
spawn nix eval --debugger --file debugger/debugger-attr-bad.nix
# NOTE: To tell Nix to not output any color, try this.
# However, REPL output will still be colored, so it's not
# as useful...
#spawn env NO_COLOR=true nix eval --debugger --file debugger/debugger-attr-bad.nix
expect "Starting REPL"
# NOTE: We wait for the prompt of the REPL,
# and then send a command.
expect "nix-repl> "
send ":bt\n"
# NOTE: Using regex matching here, because the ANSI escape codes
# for colors in the output must be matched, and I am too lazy
# to encode the colors here...
expect -re {0.*error:.*cannot add.*a string.*to an integer}
# NOTE: Here, you could add expect calls to check that other
# stack frames are mentioned.
expect "nix-repl> "
send ":q\n"
expect "… while evaluating the file"
There are lots of tutorials, I can't recommend any one in particular. Maybe start with those at https://wiki.tcl-lang.org/page/Expect+Tutorials Maybe using
would be helpful. |
That's somewhat similar to what I ended up with, though I'm still hazy on some aspects. Time being limited, my inclination right now is to get this in as-is if possible, and take a look at expect/pexpect etc for a separate PR. I agree it does seem like a good fit for the interactive features of the debugger. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/prs-ready-for-review/3032/2946 |
If you've not got around to this yet, I have looked into The idea is that you can essentially write a test that is an annotated transcript of a repl session. |
@lf- is there any previous discussion regarding the use of cram? It was last released on 2016-02-24, compared to pexpect which was last released on 2023-11-05. |
I'm not using cram, I'm writing something very similar in C++ integrated with Nix. |
Motivation
The debugger got a little bit broken from PR 6204. Also, roberth requested some testing. This PR fixes a few debugger problems and adds a simple test for backtrace sequence.
This is by no means a complete test suite for the debugger. But its a start.
What was changed:
error:
with printing the verbosity of an error in the backtrace. this is nice because builtins.break shows asinfo:
instead oferror:
.I changed that code to use a new datastructure 'WithFrame' to store location outside the DebugTrace stack.(removed altogether now)