'Rust panic only when launch by LLDB in vscode
summary:
- Run
cargo buildandcargo runin vscode terminal window => Success - Run created exe file in the vscode terminal window after
cargo buildmy self => Success - Build cargo from in
tasks.json=> Success - Debugging by LLDB launch in
launch.json=> Failed - Debugging by LLDB attch in
launch.jsonafter run my self => Success
I'm practicing the rust language and I'm not familiar with it yet.
Currently, I just ran the following example in vscode: https://gist.github.com/LNSEAB/29faf2cfe786c5b6f748f43f260ad1e5
It ran fine and windows worked fine. However, debugging using lldb in vscode failed.
I used the vscode rust extension to create the following syntax for launch.json:
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'rust-ex'",
"cargo": {
"args": [
"build",
"--bin=rust-ex",
"--package=rust-ex"
],
"filter": {
"name": "rust-ex",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
For reference, my project name is "rust-ex".
This launch.json entry failed to run the example in the link(winapi) above
thread 'main' panicked at 'CreateWindowEx failed', src\main.rs:51:13
This launch.json entry worked fine for the hello world example.
And build the winapi example from cargo directly in the terminal window, and run the exe directly, both work well.
This time, using the vscode LLDB extension, the following syntax was created:
{
"type": "lldb",
"request": "launch",
"name": "test",
"program": "${workspaceFolder}/target/debug/rust-ex.exe",
"args": [],
"cwd": "${workspaceFolder}"
},
This also caused the same error.
This time, using the vscode LLDB extension, the following syntax was created:
{
"type": "lldb",
"request": "attach",
"name": "Attach",
"pid": "${command:pickMyProcess}"
},
This works fine after I run it myself. (with select pid my self)
So this time I added the following to tasks.json:
{
"label": "rust test",
"type": "shell",
"command": "start",
"args": [
"${workspaceFolder}/target/debug/rust-ex.exe"
]
}
Then, in launch.json , I tried:
{
"type": "lldb",
"request": "attach",
"name": "Attach Test",
"preLaunchTask": "rust test",
"program": "${workspaceFolder}/target/debug/rust-ex.exe"
},
This works very well as I intended.
Why does the same code panic when only launch by LLDB?
What am I missing?
Solution 1:[1]
You have at least one UB in your program - the vector containing window class name gets freed before you call CreateWindowExW. You should keep that object alive until you are done using the string.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user1411900 |
