helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
33.65k stars 2.5k forks source link

debugging c++ crashes helix #7030

Open sbromberger opened 1 year ago

sbromberger commented 1 year ago

Summary

running the debugger via space-g and selecting a binary after setting a breakpoint crashes the editor. Running the debugger without setting a breakpoint does not crash the editor.

Reproduction Steps

I tried this: 1. `hx` 2. `g`, set breakpoint, launch debug target, select full path of binary I expected this to happen: Debugger to start Instead, this happened: Helix crashed. ``` thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/seth/build/helix/helix-view/src/handlers/dap.rs:231:57 stack backtrace: 0: rust_begin_unwind at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5 1: core::panicking::panic_fmt at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14 2: core::panicking::panic at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:48:5 3: helix_view::handlers::dap::::handle_debugger_message::{{closure}} 4: helix_term::application::Application::handle_editor_event::{{closure}} 5: as core::future::future::Future>::poll 6: tokio::runtime::park::CachedParkThread::block_on 7: tokio::runtime::scheduler::multi_thread::MultiThread::block_on 8: tokio::runtime::runtime::Runtime::block_on 9: hx::main ``` ### Helix log
~/.cache/helix/helix.log ``` 2023-05-12T14:11:50.704 helix_lsp::transport [ERROR] err <- "I[14:11:50.704] clangd version 15.0.7\n" 2023-05-12T14:11:50.704 helix_lsp::transport [ERROR] err <- "I[14:11:50.704] Features: linux\n" 2023-05-12T14:11:50.704 helix_lsp::transport [ERROR] err <- "I[14:11:50.704] PID: 15950\n" 2023-05-12T14:11:50.704 helix_lsp::transport [ERROR] err <- "I[14:11:50.704] Working directory: /home/seth/dev/c++/rat\n" 2023-05-12T14:11:50.704 helix_lsp::transport [ERROR] err <- "I[14:11:50.704] argv[0]: /usr/bin/clangd\n" 2023-05-12T14:11:50.704 helix_lsp::transport [ERROR] err <- "I[14:11:50.704] Starting LSP over stdin/stdout\n" 2023-05-12T14:11:50.704 helix_lsp::transport [ERROR] err <- "I[14:11:50.704] <-- initialize(0)\n" 2023-05-12T14:11:50.705 helix_lsp::transport [ERROR] err <- "I[14:11:50.705] --> reply:initialize(0) 1 ms\n" 2023-05-12T14:11:50.706 helix_lsp::transport [ERROR] err <- "I[14:11:50.706] <-- initialized\n" 2023-05-12T14:11:50.706 helix_lsp::transport [ERROR] err <- "I[14:11:50.706] <-- workspace/didChangeConfiguration\n" 2023-05-12T14:11:50.706 helix_lsp::transport [ERROR] err <- "I[14:11:50.706] <-- textDocument/didOpen\n" 2023-05-12T14:11:50.707 helix_lsp::transport [ERROR] err <- "I[14:11:50.707] Loaded compilation database from /home/seth/dev/c++/rat/compile_flags.txt\n" 2023-05-12T14:11:50.707 helix_lsp::transport [ERROR] err <- "I[14:11:50.707] ASTWorker building file /home/seth/dev/c++/rat/main.cpp version 0 with command \n" 2023-05-12T14:11:50.707 helix_lsp::transport [ERROR] err <- "[/home/seth/dev/c++/rat]\n" 2023-05-12T14:11:50.707 helix_lsp::transport [ERROR] err <- "/usr/bin/clang-tool -std=c++17 -resource-dir=/usr/lib/clang/15.0.7 -- /home/seth/dev/c++/rat/main.cpp\n" 2023-05-12T14:11:51.019 helix_lsp::transport [ERROR] err <- "I[14:11:51.019] <-- textDocument/inlayHint(1)\n" 2023-05-12T14:11:51.042 helix_lsp::transport [ERROR] err <- "I[14:11:51.042] --> textDocument/publishDiagnostics\n" 2023-05-12T14:11:51.042 helix_lsp::transport [ERROR] err <- "I[14:11:51.042] --> reply:textDocument/inlayHint(1) 22 ms\n" 2023-05-12T14:12:08.281 helix_view::handlers::dap [WARN] Unhandled event Process(Process { name: "/home/seth/dev/c++/rat/a.out", system_process_id: Some(16497), is_local_process: Some(true), start_method: Some("launch"), pointer_size: None }) ```
### Platform void linux ### Terminal Emulator tmux via mosh/ssh, blink temrinal ### Helix Version helix 22.12-648-g92c328c0
A-Walrus commented 1 year ago

I think there are a couple things going on here. I was able to reproduce when compiling without debug symbols. When compiling with debug symbols enabled -g everything worked fine. With that being said, helix shouldn't just crash in these cases, instead it should probably report an error.

sbromberger commented 1 year ago

Oh man, thank you very much for narrowing it down. I forgot to add -g in my build. Let me give that a try.

(Edit: yup, that appeared to be the source of the crash. Thanks again.)

luca-schlecker commented 1 year ago

I am experiencing the same issue (with the same error message) even though I am compiling with -g. I am on Windows using the latest 23.05 release of Helix and the LLVM clang compiler. I tried compiling with clang++ -O0 -glldb main.cpp and clang++ -O0 -g main.cpp, but I couldn't get it to work, it always crashes when hitting a breakpoint.

roberte777 commented 1 year ago

I am experiencing the same issue (with the same error message) even though I am compiling with -g.

I am on Windows using the latest 23.05 release of Helix and the LLVM clang compiler.

I tried compiling with clang++ -O0 -glldb main.cpp and clang++ -O0 -g main.cpp, but I couldn't get it to work, it always crashes when hitting a breakpoint.

In your case, I might check and triple check you're actually compiling with debug correctly. I also compiled with -g using g++ on windows and was confused on why my editor was not debugging correctly. However, on projects where I used visual studio to compile with the debug flag, everything worked and I could debug like normal. I'm wondering if this is some windows thing where compiling from the command line is wonky with the debug flag. I could be very wrong, im far from an expert, but thought it might be relevant since I had a similar issues on windows.

luca-schlecker commented 1 year ago

I can confirm that when using MSVC's cl.exe directly using /DEBUG and /Zi to compile, Helix doesn't crash on hitting a breakpoint. Seems weird that clang++ is not working...

eric-hansen commented 1 year ago

This also happens with PHP (configured from https://github.com/helix-editor/helix/discussions/7574 ) Crash line: https://github.com/helix-editor/helix/blob/master/helix-view/src/handlers/dap.rs#L231 :

                                    breakpoints[i].line =
                                        breakpoint.line.unwrap().saturating_sub(1); // TODO: no unwrap
$ hx --version
helix 23.05 (01a1e5ec)

languages.toml file:

[[language]]
name = "php"

[language.debugger]
name = "vscode-php-debug"
transport = "stdio"
command = "node"
args = [ "/home/eric/Projects/personal/dev/vscode-php-debug/out/phpDebug.js" ]

[[language.debugger.templates]]
name = "Listen for Xdebug"
request = "launch"
completion = [ "ignored" ]
args = {serverSourceRoot="/var/www/html",localSourceRoot="/the/path/to/App"}

When I start the debugger listener it seems to work just fine. It's only when a breakpoint is hit that it crashes.

Here's what RUST_BACKTRACE=full outputs:

$ RUST_BACKTRACE=full hx .
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/eric/Projects/personal/system/helix/helix-view/src/handlers/dap.rs:231:57
stack backtrace:
   0:     0x5581ff83bd25 - std::backtrace_rs::backtrace::libunwind::trace::h32eb3e08e874dd27
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x5581ff83bd25 - std::backtrace_rs::backtrace::trace_unsynchronized::haa3f451d27bc11a5
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x5581ff83bd25 - std::sys_common::backtrace::_print_fmt::h5b94a01bb4289bb5
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x5581ff83bd25 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb070b7fa7e3175df
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x5581fed3ea6e - core::fmt::write::hd5207aebbb9a86e9
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/fmt/mod.rs:1202:17
   5:     0x5581ff835675 - std::io::Write::write_fmt::h3bd699bbd129ab8a
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/io/mod.rs:1679:15
   6:     0x5581ff83d7b3 - std::sys_common::backtrace::_print::h7a21be552fdf58da
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x5581ff83d7b3 - std::sys_common::backtrace::print::ha85c41fe4dd80b13
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x5581ff83d7b3 - std::panicking::default_hook::{{closure}}::h04cca40023d0eeca
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:295:22
   9:     0x5581ff83d4bf - std::panicking::default_hook::haa3ca8c310ed5402
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:314:9
  10:     0x5581ff83de7f - std::panicking::rust_panic_with_hook::h7b190ce1a948faac
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:702:17
  11:     0x5581ff83dcb4 - std::panicking::begin_panic_handler::{{closure}}::hbafbfdc3e1b97f68
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:586:13
  12:     0x5581ff83c22c - std::sys_common::backtrace::__rust_end_short_backtrace::hda93e5fef243b4c0
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:138:18
  13:     0x5581ff83da32 - rust_begin_unwind
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5
  14:     0x5581fec6f713 - core::panicking::panic_fmt::h8d17ca1073d9a733
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14
  15:     0x5581fec6f5dd - core::panicking::panic::hf0565452d0d0936c
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:48:5
  16:     0x5581ff657e8a - helix_view::handlers::dap::<impl helix_view::editor::Editor>::handle_debugger_message::{{closure}}::he79b76e433ad861f
  17:     0x5581ff650406 - helix_term::application::Application::run::{{closure}}::h16a432715da6a9fa
  18:     0x5581ff66cc93 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::he836aded2fa1fd2f
  19:     0x5581ff6159f8 - tokio::runtime::park::CachedParkThread::block_on::h911ce28c29d9c11c
  20:     0x5581ff616945 - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::h48fa724dcfdc5854
  21:     0x5581ff62f5d6 - tokio::runtime::runtime::Runtime::block_on::h1d8517451102f831
  22:     0x5581ff66f55a - hx::main::ha13a453bd058a774
  23:     0x5581ff61b2d3 - std::sys_common::backtrace::__rust_begin_short_backtrace::h6335a6edd26dea72
  24:     0x5581ff624979 - std::rt::lang_start::{{closure}}::h38bc4642a7fec082
  25:     0x5581ff82f08a - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hb69be6e0857c6cfb
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:283:13
  26:     0x5581ff82f08a - std::panicking::try::do_call::h396dfc441ee9c786
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492:40
  27:     0x5581ff82f08a - std::panicking::try::h6cdda972d28b3a4f
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456:19
  28:     0x5581ff82f08a - std::panic::catch_unwind::h376039ec264e8ef9
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137:14
  29:     0x5581ff82f08a - std::rt::lang_start_internal::{{closure}}::hc94720ca3d4cb727
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:148:48
  30:     0x5581ff82f08a - std::panicking::try::do_call::h2422fb95933fa2d5
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492:40
  31:     0x5581ff82f08a - std::panicking::try::h488286b5ec8333ff
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456:19
  32:     0x5581ff82f08a - std::panic::catch_unwind::h81636549836d2a25
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137:14
  33:     0x5581ff82f08a - std::rt::lang_start_internal::h6ba1bb743c1e9df9
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:148:20
  34:     0x5581ff66f658 - main
  35:     0x7f133651e1ca - <unknown>
  36:     0x7f133651e285 - __libc_start_main
  37:     0x5581fecbf9d1 - _start
  38:                0x0 - <unknown>
MAST1999 commented 1 year ago

I also get the exact same error when trying to launch the JavaScript debugger.

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', helix-term/src/commands/dap.rs:325:22
stack backtrace:
   0:     0x5653ba2c6ac5 - std::backtrace_rs::backtrace::libunwind::trace::h32eb3e08e874dd27
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x5653ba2c6ac5 - std::backtrace_rs::backtrace::trace_unsynchronized::haa3f451d27bc11a5
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x5653ba2c6ac5 - std::sys_common::backtrace::_print_fmt::h5b94a01bb4289bb5
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x5653ba2c6ac5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb070b7fa7e3175df
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x5653b97d824e - core::fmt::write::hd5207aebbb9a86e9
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/fmt/mod.rs:1202:17
   5:     0x5653ba2c0415 - std::io::Write::write_fmt::h3bd699bbd129ab8a
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/io/mod.rs:1679:15
   6:     0x5653ba2c8553 - std::sys_common::backtrace::_print::h7a21be552fdf58da
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x5653ba2c8553 - std::sys_common::backtrace::print::ha85c41fe4dd80b13
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x5653ba2c8553 - std::panicking::default_hook::{{closure}}::h04cca40023d0eeca
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:295:22
   9:     0x5653ba2c825f - std::panicking::default_hook::haa3ca8c310ed5402
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:314:9
  10:     0x5653ba2c8c1f - std::panicking::rust_panic_with_hook::h7b190ce1a948faac
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:702:17
  11:     0x5653ba2c8a54 - std::panicking::begin_panic_handler::{{closure}}::hbafbfdc3e1b97f68
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:586:13
  12:     0x5653ba2c6fcc - std::sys_common::backtrace::__rust_end_short_backtrace::hda93e5fef243b4c0
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:138:18
  13:     0x5653ba2c87d2 - rust_begin_unwind
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5
  14:     0x5653b9707713 - core::panicking::panic_fmt::h8d17ca1073d9a733
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14
  15:     0x5653b97075dd - core::panicking::panic::hf0565452d0d0936c
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:48:5
  16:     0x5653b9ee294f - helix_term::commands::dap::debug_parameter_prompt::ha868e009a81d125f
  17:     0x5653b9f268fd - core::ops::function::FnOnce::call_once{{vtable.shim}}::hd6aacdacaf0d043e
  18:     0x5653b9e1c880 - helix_term::job::Jobs::handle_callback::h174e8aff9312559a
  19:     0x5653ba0c7e4b - helix_term::application::Application::run::{{closure}}::h87db3a7f855dc089
  20:     0x5653ba0e9e47 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h2ed47801baafc7ff
  21:     0x5653ba0a202d - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::h0d9ad10ab4ee99f5
  22:     0x5653ba0b09b6 - tokio::runtime::runtime::Runtime::block_on::h90863eb65f548030
  23:     0x5653ba0feb0a - hx::main::h410c28d3bea21460
  24:     0x5653ba096933 - std::sys_common::backtrace::__rust_begin_short_backtrace::h94d69d9201602a66
  25:     0x5653ba0bc369 - std::rt::lang_start::{{closure}}::h43e2d038cff8b097
  26:     0x5653ba2b9e2a - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hb69be6e0857c6cfb
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:283:13
  27:     0x5653ba2b9e2a - std::panicking::try::do_call::h396dfc441ee9c786
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492:40
  28:     0x5653ba2b9e2a - std::panicking::try::h6cdda972d28b3a4f
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456:19
  29:     0x5653ba2b9e2a - std::panic::catch_unwind::h376039ec264e8ef9
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137:14
  30:     0x5653ba2b9e2a - std::rt::lang_start_internal::{{closure}}::hc94720ca3d4cb727
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:148:48
  31:     0x5653ba2b9e2a - std::panicking::try::do_call::h2422fb95933fa2d5
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492:40
  32:     0x5653ba2b9e2a - std::panicking::try::h488286b5ec8333ff
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456:19
  33:     0x5653ba2b9e2a - std::panic::catch_unwind::h81636549836d2a25
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137:14
  34:     0x5653ba2b9e2a - std::rt::lang_start_internal::h6ba1bb743c1e9df9
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:148:20
  35:     0x5653ba0fec08 - main
  36:     0x7fa1ec9aecd0 - <unknown>
  37:     0x7fa1ec9aed8a - __libc_start_main
  38:     0x5653b9759cc5 - _start
  39:                0x0 - <unknown>