diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2024-12-24 08:40:56 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-24 08:40:56 +0000 |
| commit | 417dcc41437bf9a4d093316791740df8ad61496a (patch) | |
| tree | 9b4ee06530f0db4d1a2c119da32e0e68aa4abafc /src/tools/rust-analyzer | |
| parent | 8dbdcc03ebfd5d3c21671d8a021669dc79d93038 (diff) | |
| parent | 5e7ce339669d059014898c610771d0e96a5d3ab1 (diff) | |
| download | rust-417dcc41437bf9a4d093316791740df8ad61496a.tar.gz rust-417dcc41437bf9a4d093316791740df8ad61496a.zip | |
Merge pull request #18749 from PrototypeNM1/windows-debugger-wait
minor: Break out of waiting for debugger on Windows using native debugger check API.
Diffstat (limited to 'src/tools/rust-analyzer')
| -rw-r--r-- | src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml | 2 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs | 30 |
2 files changed, 25 insertions, 7 deletions
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml b/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml index fa9ff6b56df..d06130ce8c5 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml +++ b/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml @@ -76,7 +76,7 @@ vfs.workspace = true paths.workspace = true [target.'cfg(windows)'.dependencies] -windows-sys = { version = "0.52", features = ["Win32_System_Threading"] } +windows-sys = { version = "0.52", features = ["Win32_System_Diagnostics_Debug", "Win32_System_Threading"] } [target.'cfg(not(target_env = "msvc"))'.dependencies] jemallocator = { version = "0.5.0", package = "tikv-jemallocator", optional = true } diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs index a753621eca8..caa42dd62cd 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs @@ -10,7 +10,7 @@ extern crate rustc_driver as _; mod rustc_wrapper; -use std::{env, fs, path::PathBuf, process::ExitCode, sync::Arc}; +use std::{env, fs, path::PathBuf, process::ExitCode, sync::Arc, thread::sleep}; use anyhow::Context; use lsp_server::Connection; @@ -44,11 +44,7 @@ fn actual_main() -> anyhow::Result<ExitCode> { #[cfg(debug_assertions)] if flags.wait_dbg || env::var("RA_WAIT_DBG").is_ok() { - #[allow(unused_mut)] - let mut d = 4; - while d == 4 { - d = 4; - } + wait_for_debugger(); } if let Err(e) = setup_logging(flags.log_file.clone()) { @@ -96,6 +92,28 @@ fn actual_main() -> anyhow::Result<ExitCode> { Ok(ExitCode::SUCCESS) } +#[cfg(debug_assertions)] +fn wait_for_debugger() { + #[cfg(target_os = "windows")] + { + use windows_sys::Win32::System::Diagnostics::Debug::IsDebuggerPresent; + // SAFETY: WinAPI generated code that is defensively marked `unsafe` but + // in practice can not be used in an unsafe way. + while unsafe { IsDebuggerPresent() } == 0 { + sleep(std::time::Duration::from_millis(100)); + } + } + #[cfg(not(target_os = "windows"))] + { + #[allow(unused_mut)] + let mut d = 4; + while d == 4 { + d = 4; + sleep(std::time::Duration::from_millis(100)); + } + } +} + fn setup_logging(log_file_flag: Option<PathBuf>) -> anyhow::Result<()> { if cfg!(windows) { // This is required so that windows finds our pdb that is placed right beside the exe. |
