Skip to content
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

Unable to debug Rust with Amethyst library #410

Closed
GuiAmPm opened this issue Jan 31, 2021 · 16 comments
Closed

Unable to debug Rust with Amethyst library #410

GuiAmPm opened this issue Jan 31, 2021 · 16 comments
Labels
waiting for info Waiting for the issue author to provide more information.

Comments

@GuiAmPm
Copy link

GuiAmPm commented Jan 31, 2021

OS: Windows 10 - 64x
VSCode version: 1.52.1
Extension version: 1.6.1
Compiler: Rustc 1.49.0
Build target: stable-x86_64-pc-windows-msvc

I'm unable to debug in Rust using the Amethyst game library. Trying to do so makes a message appear with the text: "Oops! The debug adapter has terminated abnormally."

main.rs
fn main() -> amethyst::Result<()> {
    amethyst::start_logger(Default::default());
    let _app_root = amethyst::utils::application_root_dir()?; // commenting this line makes it work
    Ok(())
}
Cargo.toml
[package]
name = "test_rust"
version = "0.1.0"
edition = "2018"

[dependencies.amethyst]
git = "https://github.com/amethyst/amethyst.git"
branch = "main"
features = ["vulkan"]
launch.json

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'test_rust'",
"cargo": {
"args": [
"build",
"--bin=test_rust",
"--package=test_rust"
],
"filter": {
"name": "test_rust",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'test_rust'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=test_rust",
"--package=test_rust"
],
"filter": {
"name": "test_rust",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}

Debug log
Running `cargo build --bin=test_rust --package=test_rust --message-format=json`...
   Compiling test_rust v0.1.0 (E:\source\test_rust)
    Finished dev [unoptimized + debuginfo] target(s) in 2.47s
Raw artifacts:
{
  fileName: 'e:\\source\\test_rust\\target\\debug\\test_rust.exe',
  name: 'test_rust',
  kind: 'bin'
}
Filtered artifacts: 
{
  fileName: 'e:\\source\\test_rust\\target\\debug\\test_rust.exe',
  name: 'test_rust',
  kind: 'bin'
}
configuration: {
  type: 'lldb',
  request: 'launch',
  name: "Debug executable 'test_rust'",
  args: [],
  cwd: '${workspaceFolder}',
  __configurationTarget: 5,
  relativePathBase: 'e:\\source\\test_rust',
  program: 'e:\\source\\test_rust\\target\\debug\\test_rust.exe',
  sourceLanguages: [ 'rust' ]
}
liblldb: c:\Users\my_usr\.vscode\extensions\vadimcn.vscode-lldb-1.6.0\lldb\bin\liblldb.dll
environment: { LLDB_CAPTURE_REPRODUCER: '1' }
params: { sourceLanguages: [ 'rust' ] }
Listening on port 52111
[2021-01-31T04:17:28Z DEBUG codelldb] New debug session
INFO(Python) 05:17:28 formatters: Initializing
INFO(Python) 05:17:28 formatters.rust: Initializing
[2021-01-31T04:17:28Z DEBUG codelldb::dap_codec] --> {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"lldb","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en-gb","supportsProgressReporting":true,"supportsInvalidatedEvent":true},"type":"request","seq":1}
[2021-01-31T04:17:28Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":1,"success":true,"command":"initialize","body":{"exceptionBreakpointFilters":[{"default":true,"filter":"rust_panic","label":"Rust: on panic"}],"supportTerminateDebuggee":true,"supportsCancelRequest":true,"supportsCompletionsRequest":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDataBreakpoints":true,"supportsDelayedStackTraceLoading":true,"supportsEvaluateForHovers":true,"supportsFunctionBreakpoints":true,"supportsGotoTargetsRequest":true,"supportsHitConditionalBreakpoints":true,"supportsLogPoints":true,"supportsReadMemoryRequest":true,"supportsRestartFrame":true,"supportsSetVariable":true}}
[2021-01-31T04:17:28Z DEBUG codelldb::dap_codec] --> {"command":"launch","arguments":{"type":"lldb","request":"launch","name":"Debug executable 'test_rust'","args":[],"cwd":"E:\\source\\test_rust","__configurationTarget":5,"relativePathBase":"e:\\source\\test_rust","program":"e:\\source\\test_rust\\target\\debug\\test_rust.exe","sourceLanguages":["rust"],"_adapterSettings":{"displayFormat":"auto","showDisassembly":"auto","dereferencePointers":true,"suppressMissingSourceFiles":true,"evaluationTimeout":5,"consoleMode":"commands","sourceLanguages":null,"terminalPromptClear":null},"__sessionId":"5a6f234e-b41d-469d-8bea-d9e8c8be42f9"},"type":"request","seq":2}
[2021-01-31T04:17:29Z DEBUG codelldb::dap_codec] <-- {"type":"event","seq":1,"event":"initialized"}
[2021-01-31T04:17:29Z DEBUG codelldb::dap_codec] <-- {"type":"request","seq":2,"command":"runInTerminal","arguments":{"args":["c:\\Users\\my_usr\\.vscode\\extensions\\vadimcn.vscode-lldb-1.6.0\\adapter\\codelldb.exe","terminal-agent","--port=52113"],"cwd":"","kind":"integrated","title":"Debug executable 'test_rust'"}}
[2021-01-31T04:17:29Z DEBUG codelldb::dap_codec] --> {"command":"setBreakpoints","arguments":{"source":{"name":"main.rs","path":"e:\\source\\test_rust\\src\\main.rs"},"lines":[6],"breakpoints":[{"line":6}],"sourceModified":false},"type":"request","seq":3}
[2021-01-31T04:17:30Z DEBUG codelldb::dap_codec] --> {"type":"response","seq":4,"command":"runInTerminal","request_seq":2,"success":true,"body":{"shellProcessId":2340}}
[2021-01-31T04:17:30Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":3,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"id":1,"message":"Locations: 0","verified":false}]}}
[2021-01-31T04:17:30Z DEBUG codelldb::dap_codec] --> {"command":"setFunctionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":5}
[2021-01-31T04:17:30Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":5,"success":true,"command":"setFunctionBreakpoints","body":{"breakpoints":[]}}
[2021-01-31T04:17:30Z DEBUG codelldb::dap_codec] --> {"command":"setDataBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":6}
[2021-01-31T04:17:30Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":6,"success":true,"command":"setDataBreakpoints","body":{"breakpoints":[]}}
[2021-01-31T04:17:30Z DEBUG codelldb::dap_codec] --> {"command":"setExceptionBreakpoints","arguments":{"filters":["rust_panic"]},"type":"request","seq":7}
Debug adapter exit code=3221225620, signal=null.

@vadimcn
Copy link
Owner

vadimcn commented Feb 15, 2021

Compiled your example, but could not reproduce the problem.

@vadimcn vadimcn added the waiting for info Waiting for the issue author to provide more information. label Feb 15, 2021
@Rob2309
Copy link

Rob2309 commented Feb 19, 2021

I have the exact same issue with a different project. Trying to debug the project shown by @GuiAmPm produces the following output:

Output
Running `cargo build --bin=test_project --package=test_project --message-format=json`...
    Finished dev [unoptimized + debuginfo] target(s) in 0.55s
Raw artifacts:
{
  fileName: 'd:\\DEV\\RustLearning\\test_project\\target\\debug\\test_project.exe',
  name: 'test_project',
  kind: 'bin'
}
Filtered artifacts: 
{
  fileName: 'd:\\DEV\\RustLearning\\test_project\\target\\debug\\test_project.exe',
  name: 'test_project',
  kind: 'bin'
}
configuration: {
  type: 'lldb',
  request: 'launch',
  name: "Debug executable 'test_project'",
  args: [],
  cwd: '${workspaceFolder}',
  __configurationTarget: 5,
  relativePathBase: 'd:\\DEV\\RustLearning\\test_project',
  program: 'd:\\DEV\\RustLearning\\test_project\\target\\debug\\test_project.exe',
  sourceLanguages: [ 'rust' ]
}
liblldb: c:\Users\Rob\.vscode\extensions\vadimcn.vscode-lldb-1.6.1\lldb\bin\liblldb.dll
environment: {}
params: {
  evaluateForHovers: true,
  commandCompletions: true,
  sourceLanguages: [ 'rust' ]
}
Listening on port 57351
[2021-02-19T12:16:32Z DEBUG codelldb] New debug session
INFO(Python) 13:16:32 formatters: Initializing
INFO(Python) 13:16:32 formatters.rust: Initializing
[2021-02-19T12:16:32Z DEBUG codelldb::dap_codec] --> {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"lldb","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en-us","supportsProgressReporting":true,"supportsInvalidatedEvent":true},"type":"request","seq":1}
[2021-02-19T12:16:32Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":1,"success":true,"command":"initialize","body":{"exceptionBreakpointFilters":[{"default":true,"filter":"rust_panic","label":"Rust: on panic"}],"supportTerminateDebuggee":true,"supportsCancelRequest":true,"supportsCompletionsRequest":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDataBreakpoints":true,"supportsDelayedStackTraceLoading":true,"supportsEvaluateForHovers":true,"supportsFunctionBreakpoints":true,"supportsGotoTargetsRequest":true,"supportsHitConditionalBreakpoints":true,"supportsLogPoints":true,"supportsReadMemoryRequest":true,"supportsRestartFrame":true,"supportsSetVariable":true}}
[2021-02-19T12:16:32Z DEBUG codelldb::dap_codec] --> {"command":"launch","arguments":{"type":"lldb","request":"launch","name":"Debug executable 'test_project'","args":[],"cwd":"D:\\DEV\\RustLearning\\test_project","__configurationTarget":5,"relativePathBase":"d:\\DEV\\RustLearning\\test_project","program":"d:\\DEV\\RustLearning\\test_project\\target\\debug\\test_project.exe","sourceLanguages":["rust"],"_adapterSettings":{"displayFormat":"auto","showDisassembly":"auto","dereferencePointers":true,"suppressMissingSourceFiles":true,"evaluationTimeout":5,"consoleMode":"commands","sourceLanguages":null,"terminalPromptClear":null,"evaluateForHovers":true,"commandCompletions":true},"__sessionId":"b9189045-d7a8-4566-ad55-ceb07c5b0e9b"},"type":"request","seq":2}
[2021-02-19T12:16:32Z DEBUG codelldb::dap_codec] <-- {"type":"event","seq":1,"event":"capabilities","body":{"capabilities":{"exceptionBreakpointFilters":[{"default":true,"filter":"rust_panic","label":"Rust: on panic"}],"supportTerminateDebuggee":true,"supportsCancelRequest":true,"supportsCompletionsRequest":true,"supportsConditionalBreakpoints":true,"supportsConfigurationDoneRequest":true,"supportsDataBreakpoints":true,"supportsDelayedStackTraceLoading":true,"supportsEvaluateForHovers":true,"supportsFunctionBreakpoints":true,"supportsGotoTargetsRequest":true,"supportsHitConditionalBreakpoints":true,"supportsLogPoints":true,"supportsReadMemoryRequest":true,"supportsRestartFrame":true,"supportsSetVariable":true}}}
[2021-02-19T12:16:33Z DEBUG codelldb::dap_codec] <-- {"type":"event","seq":2,"event":"initialized"}
[2021-02-19T12:16:33Z DEBUG codelldb::dap_codec] <-- {"type":"request","seq":3,"command":"runInTerminal","arguments":{"args":["c:\\Users\\Rob\\.vscode\\extensions\\vadimcn.vscode-lldb-1.6.1\\adapter\\codelldb.exe","terminal-agent","--port=57353"],"cwd":"","kind":"integrated","title":"Debug executable 'test_project'"}}
[2021-02-19T12:16:33Z DEBUG codelldb::dap_codec] --> {"command":"setFunctionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":3}
[2021-02-19T12:16:33Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":3,"success":true,"command":"setFunctionBreakpoints","body":{"breakpoints":[]}}
[2021-02-19T12:16:33Z DEBUG codelldb::dap_codec] --> {"command":"setDataBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":4}
[2021-02-19T12:16:33Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":4,"success":true,"command":"setDataBreakpoints","body":{"breakpoints":[]}}
[2021-02-19T12:16:33Z DEBUG codelldb::dap_codec] --> {"command":"setExceptionBreakpoints","arguments":{"filters":["rust_panic"]},"type":"request","seq":5}
Debug adapter exit code=3221225620, signal=null.

The project I first discovered this issue on is https://github.com/michidk/vulkan-engine. When trying to debug that project, the exact same sequence of commands can be observed in the output console. It seems to always crash after the "setExceptionBreakpoints" command.

@GuiAmPm
Copy link
Author

GuiAmPm commented Feb 19, 2021

I've included the launch.json file on the original comment just in case.

@vadimcn I'm trying to compile the project locally to see if I can debug the issue myself. I can't figure out what zip file is expected to be used as LLDB_PACKAGE during the make command, though. What LLDB files should it contain?

@vadimcn
Copy link
Owner

vadimcn commented Feb 19, 2021

@GuiAmPm: look in $HOME/.vscode/extensions/vadimcn.vscode-lldb-1.6.1/lldb - these are the files needed.
If you build LLDB locally, you could probably just comment out unzip stuff in lldb/CMakeLists.txt and override liblldb location via lldb.library in workspace settings (point it directly to $LLDB_BUILD/bin/liblldb.dll).

@GuiAmPm
Copy link
Author

GuiAmPm commented Feb 20, 2021

I wasn't very successful debugging it, because the issue seems to be happening in the adapter, but I will add more information here.
This only happens on Windows, I have installed Ubuntu on a VM and this example I provided works fine.
The adapter seems to be unable to connect? I get this error from it:

When it builds this command:
c:\Users\user.vscode\extensions\vadimcn.vscode-lldb-1.6.1\adapter\codelldb.exe terminal-agent --port=56261

terminal_agent.rs#24: Error: Os { code: 10061, kind: ConnectionRefused, message: "No connection could be made because the target machine actively refused it." }

I don't get why the port (or maybe the whole service?) is not available when terminal.rs#54 runs the command. I will investigate more.

@vadimcn
Copy link
Owner

vadimcn commented Feb 20, 2021

terminal_agent.rs#24: Error: Os { code: 10061, kind: ConnectionRefused, message: "No connection could be made because the target machine actively refused it." }

I've seen reports of this one, but was never able to reproduce it. Some windows firewall shenanigans?
In any case, this only affects terminal output and should not prevent debugging. You can suppress this message by adding "terminal": "console" attribute to the launch config.

@vadimcn
Copy link
Owner

vadimcn commented Feb 20, 2021

Also, you might not even need to build the extension. The crash most likely occurs in LLDB, so if you just redirect liblldb as described above, you should be able to debug with installed extension version.

@GuiAmPm
Copy link
Author

GuiAmPm commented Feb 21, 2021

I've seen reports of this one, but was never able to reproduce it. Some windows firewall shenanigans?
Doesn't seems to be the root cause, it seems to me that the terminal-agent can't connect because the adapter can't open the socket for whatever reason or the port is already closed.

Changing "terminal" to any of the options we have also doesn't work. If I select "external" all I see is a CMD with the text "Press any key to continue"

Also, you might not even need to build the extension.

Yes, this seems to be a problem not with the extension itself, but maybe the adapter or LLDB itself.


More of my investigation:
DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":6,"success":true,"command":"setExceptionBreakpoints"}
On the example above this is where the adapter stops, so the issue seems to be happening at this point setExceptionBreakpoints

I filled the adapter's code with debug statements and I was able to isolate the line that breaks things:
sbtarget.rs#115: cpp!(unsafe [self as "SBTarget*", name as "const char*"] -> SBBreakpoint as "SBBreakpoint" {
name is "rust_panic"
So I added a println before and after, on any working code, both are printed in the Output window.
On the code posted here it always stops before.

Maybe this is not the line cause we are dealing with tokyo::threads and it's stopping here by luck.

To test that I did this:

try {
   return self->BreakpointCreateByName(name);
} catch (...) {
   return self->BreakpointCreateByName("rust_panic_attack"); // I used any string just to check if this would work :P
}

Now the adapter doesn't stop early!

But it now it does hangs forever for some reason (probably, because the string I put makes no sense?) at this point:

[2021-02-21T13:43:33Z DEBUG codelldb::dap_codec] <--| {"type":"response","request_seq":5,"success":true,"command":"setExceptionBreakpoints"}
[2021-02-21T13:43:33Z DEBUG codelldb::dap_codec] |--> {"command":"configurationDone","type":"request","seq":6}
[2021-02-21T13:43:33Z DEBUG codelldb::dap_codec] <--| {"type":"response","request_seq":6,"success":true,"command":"configurationDone"}
[2021-02-21T13:43:33Z DEBUG codelldb::dap_codec] |--> {"command":"threads","type":"request","seq":7}
[2021-02-21T13:43:33Z DEBUG codelldb::dap_codec] <--| {"type":"response","request_seq":7,"success":true,"command":"threads","body":{"threads":[]}}
[2021-02-21T13:43:35Z DEBUG codelldb::dap_codec] |--> {"type":"response","seq":8,"command":"runInTerminal","request_seq":3,"success":true,"body":{"shellProcessId":16116}}
[adapter\src\terminal.rs:101] FreeConsole() = 1
[2021-02-21T13:43:35Z DEBUG codelldb::dap_codec] <--| {"type":"event","seq":4,"event":"output","body":{"output":"Launching: e:\\source\\test_rust\\target\\debug\\test_rust.exe\n"}}
[adapter\src\terminal.rs:102] AttachConsole(pid) = 1
[2021-02-21T13:44:19Z DEBUG codelldb::dap_codec] |--> {"command":"disconnect","arguments":{"restart":false},"type":"request","seq":9}
/// hangs here, nothing happens and the adapter doesn't stop

I unfortunatelly can't get further because I don't know how to read what exception is. This is the first time I had to deal with C++ code inside a Rust code. The results though tells me that the method self->BreakpointCreateByName(name); is throwing an exception for 'rust_panic' as name, but ONLY when I'm running the code I sent.

@GuiAmPm
Copy link
Author

GuiAmPm commented Feb 26, 2021

image

This is the uncaught exception by the way.

@vadimcn
Copy link
Owner

vadimcn commented Feb 26, 2021

Looks like a crash in MS PDB parser library. Not much I can do here, unfortunately.
Is it feasible for you to use the *-windows-gnu build target?

@GuiAmPm
Copy link
Author

GuiAmPm commented Jun 16, 2021

This was fixed sometime between my last post and now.
I'm closing this as it seems solved.

@GuiAmPm GuiAmPm closed this as completed Jun 16, 2021
@wzgy
Copy link

wzgy commented Oct 21, 2021

I have the same problem.
Thanks to @GuiAmPm, I have solved it.
The reason is that I have installed NVIDIA Nsight.
As shown below, the msdia140.dll for Nsight has been loaded by codelldb.

msdia140

Run PowerShell as administrator. Execute the command below to register the component. Then codelldb works.
regsvr32.exe C:\Users\【user name】\.vscode\extensions\vadimcn.vscode-lldb-1.6.8\lldb\bin\msdia140.dll

regsvr32

@RundownRhino
Copy link

RundownRhino commented May 27, 2022

I have the same problem. Thanks to @GuiAmPm, I have solved it. The reason is that I have installed NVIDIA Nsight. As shown below, the msdia140.dll for Nsight has been loaded by codelldb.

This solved my issue, though for 1.7.0 the path to msdia140.dll has changed - the command is now

regsvr32.exe %USERPROFILE%\.vscode\extensions\vadimcn.vscode-lldb-1.7.0\adapter\msdia140.dll

Some more symptoms of my issue, for those that also need it:

  • In LLDB's output I was getting Debug adapter exit code=3221225620 at the last line.
  • In console output, I was just getting No connection could be made because the target machine actively refused it.
  • As a popup, I got Oops! The debug adapter has terminated abnormally.

@jhugard
Copy link

jhugard commented Jun 30, 2022

Path above still isn't quite right (missing backslash)... try:

from PowerShell (admin)

regsvr32 "${env:USERPROFILE}\.vscode\extensions\vadimcn.vscode-lldb-1.7.0\adapter\msdia140.dll"

from cmd (admin)

regsvr32 "%USERPROFILE%\.vscode\extensions\vadimcn.vscode-lldb-1.7.0\adapter\msdia140.dll"

Fixes the issue immediately! No need to reload vscode, either.

@RundownRhino
Copy link

RundownRhino commented Jul 5, 2022

Oof, thanks, edited my reply to insert the missing \.

@everdrone
Copy link

Tried the regsvr32 solution against codelldb 1.8.1 and 1.9.0 but it still does not work.

This is the error:

error: Stable Diffusion Editor.exe :: Class 'std::strong_ordering' has a member 'less' of type 'std::strong_ordering' which does not have a complete definition.
error: Stable Diffusion Editor.exe :: Class 'std::partial_ordering' has a member 'less' of type 'std::partial_ordering' which does not have a complete definition.
error: Stable Diffusion Editor.exe :: Class 'std::weak_ordering' has a member 'less' of type 'std::weak_ordering' which does not have a complete definition.
Debug adapter exit code=3221225477 (0xc0000005), signal=null.

It seems to originate from std::chrono

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for info Waiting for the issue author to provide more information.
Projects
None yet
Development

No branches or pull requests

7 participants