Skip to content

Launching in the VS Code LLDB debugger causes a panic #6788

Open

Description

@sholderbach

Describe the bug

Problem arises from a change in #6584:

Trying to launch interactive nushell via the CodeLLDB VS Code extension causes a panic on this line.

grafik

It appears that fd 0 is a valid tty and the atty crate is reporting the same thing. I don't fully grasp how we can deal with the other error cases vaguely described in https://man7.org/linux/man-pages/man3/tcgetpgrp.3.html

How to reproduce

Install VS code and the CodeLLDB VS Code extension
Setup the launch.json automatically based on the cargo workspace.
Launch the nu executable via the Debugger (F5).

Reproducibility notes: both on Ubuntu standalone and with WSL2 I was able to cause this crash (for the external and internal terminal option in the launch.json config).

Expected behavior

Any failure to get those process groups should not kill the application. Having the option to debug nushell interactively that way is valuable (even if we might deviate from some regular behavior in a documented way to achieve that).

Screenshots

No response

Configuration

key value
version 0.69.2
branch alias_fix
commit_hash f058460
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.63.0 (4b91a6ea7 2022-08-08)
rust_channel 1.63.0-x86_64-unknown-linux-gnu
cargo_version cargo 1.63.0 (fd9c4297c 2022-07-01)
pkg_version 0.69.2
build_time 2022-10-14 21:46:53 +02:00
build_rust_channel debug
features default, trash, which, zip
installed_plugins

Additional context

Launching gdb target/debug/nu was not picking up this panic if I get this correctly (but my gdb foo is not strong enough to properly launch nu in a separate terminal while being attached from the start.) Regular late attaching with gdb -p <nu pid> was not causing unexpected problems.

Activity

  1. added
    category:bug
    deprecated:platform-specific
    on Oct 17, 2022
  2. fdncred commented on Oct 17, 2022

    @fdncred
    Contributor

    @sholderbach is this still a problem even after the most recent changes by unrelentingtech #6779?

  3. sholderbach commented on Oct 17, 2022

    @sholderbach
    MemberAuthor

    Yes, the failure point

    let owner_pgid = unistd::tcgetpgrp(nix::libc::STDIN_FILENO).expect("tcgetpgrp");
    is happening before the change in #6779

  4. IanManske commented on Oct 19, 2022

    @IanManske
    Member

    I am getting the same panic/message on linux when running nu through my window manager (sway).
    (E.g., using a key binding to run a nu script.)
    By launching nu this way, I assume there is no 'controlling terminal' which is why ENOTTY is encountered.
    Correct me if I'm wrong, but I believe that encountering ENOTTY should not mean an immediate panic.
    There is even a check for this, but it is never reached due to the panic.
    Also, this is with nu version 0.70.0 (the latest package release for arch).

  5. melMass commented on Oct 28, 2022

    @melMass
    Contributor

    To add to this, to debug tty apps in VSCode you must use "console": "integratedTerminal" (source: microsoft/vscode-cpptools#3351 (comment)).

    But this seems to be ignored for Rust?:
    image

    This is my config

    launch.json
    // .vscode/launch.json
    {   
    	"version": "0.2.0",
        "configurations": [
            {
                "name": "Debug nu",
                "type": "lldb",
                "request": "launch",
                "console": "integratedTerminal", // This is supposed to make TTY debugging work.
                "cargo": {
                    "args": [
                        "run",
                        "--features=extra"
                    ]
                },
                "cwd": "${workspaceRoot}",
            }
        ]
    }
  6. rgwood commented on Oct 29, 2022

    @rgwood
    Contributor

    I tried to bisect this, but went pretty far back (July 31) and still didn't find a commit where debugging was working.

    The backtrace changed somewhere between df6a7b6 and 5959d13. On df6a7b6 and earlier, the debugger was panicking with an 'attempt to subtract with overflow' in reedline.

  7. jokeyrhyme commented on Oct 30, 2022

    @jokeyrhyme
    Contributor

    Is there a workaround in 0.70.0 to avoid the tcgetpgrp NOTTY panic? Is there an opposite of the --interactive flag that will bypass this check?

  8. Kangaxx-0 commented on Nov 23, 2022

    @Kangaxx-0
    Contributor

    This is a hard stop for me to contribute nu repo without debugging code, I spent some time and still could not make it working, tried native windows which is a such awful thing :( I am also wondering if you guys are using Mac ?

    If someone knows how to work around this issue, that would be super helpful.

  9. Kangaxx-0 commented on Nov 23, 2022

    @Kangaxx-0
    Contributor

    0.71.0 includes the ENOTTY fix: https://www.nushell.sh/blog/2022-11-08-nushell-0.71.html #7001

    Does it work for you? I built the dev binary against latest main, and it does not work

  10. jokeyrhyme commented on Nov 23, 2022

    @jokeyrhyme
    Contributor

    @Kangaxx-0 I ran into the ENOTTY bug via a different shortcut (wayland keybindings triggering nushell scripts directly), so it's possible that there is some other problem specific to VSCode

    But yes, for my use case, 0.71.0 fixes my issues

    Do you still get that ENOTTY error or is it a different error now?

    And do you set "console" as per #6788 (comment) ?

  11. Kangaxx-0 commented on Nov 23, 2022

    @Kangaxx-0
    Contributor

    @Kangaxx-0 I ran into the ENOTTY bug via a different shortcut (wayland keybindings triggering nushell scripts directly), so it's possible that there is some other problem specific to VSCode

    But yes, for my use case, 0.71.0 fixes my issues

    Do you still get that ENOTTY error or is it a different error now?

    And do you set "console" as per #6788 (comment) ?

    I've got one Linux laptop and one Azure VM, they both ended up with error no TTY for interactive shell, I did add that config and still not working, as far as I could tell, the interactive boolean is set to true, so the later fix does not really work

    		{
    			"type": "lldb",
    			"request": "launch",
    			"name": "Debug executable 'nu'",
    			"console": "integratedTerminal",
    			"cargo": {
    				"args": [
    					"build",
    					"--bin=nu",
    					"--package=nu"
    				],
    				"filter": {
    					"name": "nu",
    					"kind": "bin"
    				}
    			},
    			"args": [],
    			"cwd": "${workspaceFolder}"
    		},
    
  12. Kangaxx-0 commented on Nov 23, 2022

    @Kangaxx-0
    Contributor

    VSCode + LLDB is the only way I debug Rust code, if you guys has another way to debug day to day, I'd like to learn from you :)

  13. fdncred commented on Nov 23, 2022

    @fdncred
    Contributor

    I'd love to get this fixed but unfortunately, all I get with CodeLLDB is

    Error: there is no registered task type 'codelldb.cargo'. Did you miss installing an extension that provides a corresponding task provider?
    
  14. rgwood commented on Dec 14, 2022

    @rgwood
    Contributor

    @Kangaxx-0

    if you guys has another way to debug day to day, I'd like to learn from you :)

    gdb works. Like Stefan mentioned, you can attach it to Nu with gdb -p <nu pid>.

    I avoided gdb for a long time and this LLDB bug is forcing me to finally learn it properly 😅 , better late than never.

  15. Kangaxx-0 commented on Dec 25, 2022

    @Kangaxx-0
    Contributor

    Thanks for you guys sharing, I'd figured it out but forgot to leave some step-by-step instruction in case someone like me having the same issue

    I am taking my Linux devbox as example:

    1. Install GDB sudo apt intstall gdb, you could change the command if you are on different distro
    2. You need a compiled dev bin which is in nushell/target/dev folder
    3. Run your local nu bin ./nu, you also want to find the running PID by ps | where name =~ 'nu' | where status == 'Running'
    4. run gdb
    5. Attach nu PID by attach <PID>
    6. Set breakpoint by break <file>:<line>
  16. alesito85 commented on Feb 9, 2023

    @alesito85
    Contributor

    I'm also having issues using lldb and TTY. But it works well if I use lldb attach when I start the debug version of the built binary.

    {
        "type": "lldb",
        "request": "attach",
        "name": "Attach",
        "pid": "${command:pickMyProcess}" // use ${command:pickProcess} to pick other users' processes
    }
    
  17. sholderbach commented on Feb 10, 2023

    @sholderbach
    MemberAuthor

    @alesito85 thanks for sharing that config for reference. It certainly helps to get by with some IDE conveniences.

    While skipping the startup spares those bugs there are situations where it would be helpful to be able to debug the startup directly.

  18. alesito85 commented on Feb 16, 2023

    @alesito85
    Contributor

    @sholderbach yeah I definitely agree, but better than nothing in the mean time.

    I've been doing a bit more digging and I've found that if the whole following range is commented out and success set to true, the debugging will run well in VSCode on Mac and it will accept user input and return data.
    https://github.com/nushell/nushell/blob/main/src/terminal.rs#L62..L92

    This is obviously not ok for production, but would it be fine for debugging only/debug version?

    I'm not entirely clear on the ramifications that this would bring and I'd appreciate if someone would clear it up for me.

  19. IanManske commented on Jul 14, 2023

    @IanManske
    Member

    @alesito85 @sholderbach The commented out lines are probably only relevant if nushell is being run from within another shell. For example, the last few lines handle job handling (& in bash) and allows nushell to be sent to the background. I'm not sure why ENOTTY is being encountered. This means there was no controlling terminal for nushell. Maybe it's a bug with VS Code or LLDB? Anyways, I think it's fine to disable these lines during debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:bugdeprecated:platform-specificpanic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions