Skip to content

debugger support for dx #3814

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
276 changes: 242 additions & 34 deletions packages/cli/src/build/builder.rs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions packages/cli/src/build/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ pub enum BuilderUpdate {
ProcessExited {
status: ExitStatus,
},

/// Waiting for the process failed. This might be because it's hung or being debugged.
/// This is not the same as the process exiting, so it should just be logged but not treated as an error.
ProcessWaitFailed {
err: std::io::Error,
},
}

impl BuildContext {
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/build/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,12 @@ impl BuildRequest {
));
}

// for debuggability, we need to make sure android studio can properly understand our build
// https://stackoverflow.com/questions/68481401/debugging-a-prebuilt-shared-library-in-android-studio
if self.platform == Platform::Android {
cargo_args.push("-Clink-arg=-Wl,--build-id=sha1".to_string());
}

// Our fancy hot-patching engine needs a lot of customization to work properly.
//
// These args are mostly intended to be passed when *fat* linking but are generally fine to
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ impl RunArgs {

break;
}
BuilderUpdate::ProcessWaitFailed { .. } => {}
}
}
_ => {}
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/src/serve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@
tracing::error!("Application [{platform}] exited with error: {status}");
}
}
BuilderUpdate::ProcessWaitFailed { err } => {
tracing::warn!(
"Failed to wait for process - maybe it's hung or beng debugged?: {err}"

Check warning on line 178 in packages/cli/src/serve/mod.rs

View workflow job for this annotation

GitHub Actions / Check for typos

"beng" should be "being".
);
}
}
}

Expand Down Expand Up @@ -202,6 +207,10 @@
)
}

ServeUpdate::OpenDebugger { id } => {
builder.open_debugger(&devserver, id).await;
}

ServeUpdate::Exit { error } => {
_ = builder.shutdown().await;
_ = devserver.shutdown().await;
Expand Down
12 changes: 11 additions & 1 deletion packages/cli/src/serve/output.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
serve::{ansi_buffer::AnsiStringLine, ServeUpdate, WebServer},
BuildStage, BuilderUpdate, Platform, TraceContent, TraceMsg, TraceSrc,
BuildId, BuildStage, BuilderUpdate, Platform, TraceContent, TraceMsg, TraceSrc,
};
use crossterm::{
cursor::{Hide, Show},
Expand Down Expand Up @@ -244,6 +244,16 @@ impl Output {
self.trace = !self.trace;
tracing::info!("Tracing is now {}", if self.trace { "on" } else { "off" });
}
KeyCode::Char('D') => {
return Ok(Some(ServeUpdate::OpenDebugger {
id: BuildId::SERVER,
}));
}
KeyCode::Char('d') => {
return Ok(Some(ServeUpdate::OpenDebugger {
id: BuildId::CLIENT,
}));
}

KeyCode::Char('c') => {
stdout()
Expand Down
19 changes: 17 additions & 2 deletions packages/cli/src/serve/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ impl AppServer {
// Always open the server first after the client has been built
if let Some(server) = self.server.as_mut() {
tracing::debug!("Opening server build");
server.soft_kill().await;
// server.soft_kill().await;
server
.open(
devserver_ip,
Expand All @@ -548,7 +548,7 @@ impl AppServer {
}

// Start the new app before we kill the old one to give it a little bit of time
self.client.soft_kill().await;
// self.client.soft_kill().await;
self.client
.open(
devserver_ip,
Expand Down Expand Up @@ -970,6 +970,21 @@ impl AppServer {

server.compiled_crates as f64 / server.expected_crates as f64
}

// todo: add a way to open the server's debugger too
pub(crate) async fn open_debugger(&mut self, dev: &WebServer, build: BuildId) {
match build {
BuildId::CLIENT => {
_ = self.client.open_debugger(dev).await;
}
BuildId::SERVER => {
if let Some(server) = self.server.as_mut() {
_ = server.open_debugger(dev).await;
}
}
_ => {}
}
}
}

/// Bind a listener to any point and return it
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/serve/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub(crate) struct ConnectedWsClient {
socket: WebSocket,
build_id: Option<BuildId>,
aslr_reference: Option<u64>,
_pid: Option<u32>,
}

impl WebServer {
Expand Down Expand Up @@ -261,6 +262,7 @@ impl WebServer {
BuilderUpdate::StdoutReceived { .. } => {}
BuilderUpdate::StderrReceived { .. } => {}
BuilderUpdate::ProcessExited { .. } => {}
BuilderUpdate::ProcessWaitFailed { .. } => {}
}
}

Expand Down Expand Up @@ -495,6 +497,7 @@ fn build_devserver_router(
struct ConnectionQuery {
aslr_reference: Option<u64>,
build_id: Option<BuildId>,
pid: Option<u32>,
}

// Setup websocket endpoint - and pass in the extension layer immediately after
Expand All @@ -506,7 +509,7 @@ fn build_devserver_router(
get(
|ws: WebSocketUpgrade, ext: Extension<UnboundedSender<ConnectedWsClient>>, query: Query<ConnectionQuery>| async move {
tracing::debug!("New devtool websocket connection: {:?}", query);
ws.on_upgrade(move |socket| async move { _ = ext.0.unbounded_send(ConnectedWsClient { socket, aslr_reference: query.aslr_reference, build_id: query.build_id }) })
ws.on_upgrade(move |socket| async move { _ = ext.0.unbounded_send(ConnectedWsClient { socket, aslr_reference: query.aslr_reference, build_id: query.build_id, _pid: query.pid }) })
},
),
)
Expand All @@ -515,7 +518,7 @@ fn build_devserver_router(
"/build_status",
get(
|ws: WebSocketUpgrade, ext: Extension<UnboundedSender<ConnectedWsClient>>| async move {
ws.on_upgrade(move |socket| async move { _ = ext.0.unbounded_send(ConnectedWsClient { socket, aslr_reference: None, build_id: None }) })
ws.on_upgrade(move |socket| async move { _ = ext.0.unbounded_send(ConnectedWsClient { socket, aslr_reference: None, build_id: None, _pid: None }) })
},
),
)
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/serve/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ pub(crate) enum ServeUpdate {

ToggleShouldRebuild,

OpenDebugger {
id: BuildId,
},

Redraw,

TracingLog {
Expand Down
5 changes: 3 additions & 2 deletions packages/devtools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ pub fn connect_subsecond() {
pub fn connect_at(endpoint: String, mut callback: impl FnMut(DevserverMsg) + Send + 'static) {
std::thread::spawn(move || {
let uri = format!(
"{endpoint}?aslr_reference={}&build_id={}",
"{endpoint}?aslr_reference={}&build_id={}&pid={}",
subsecond::__aslr_reference(),
dioxus_cli_config::build_id()
dioxus_cli_config::build_id(),
std::process::id()
);

let (mut websocket, _req) = match tungstenite::connect(uri) {
Expand Down
1 change: 1 addition & 0 deletions packages/extension/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ tsconfig.lsif.json
*.lsif
*.db
*.vsix
pkg/
2 changes: 1 addition & 1 deletion packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dioxus",
"displayName": "Dioxus",
"description": "Useful tools for working with Dioxus",
"version": "0.6.0",
"version": "0.7.0",
"publisher": "DioxusLabs",
"private": true,
"license": "MIT",
Expand Down
15 changes: 15 additions & 0 deletions packages/extension/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export async function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand('extension.formatRsxDocument', formatRsxDocument),
vscode.workspace.onWillSaveTextDocument(fmtDocumentOnSave)
);

context.subscriptions.push(vscode.window.registerUriHandler(new UriLaunchServer()));

}

function translate(component: boolean) {
Expand Down Expand Up @@ -171,3 +174,15 @@ function fmtDocument(document: vscode.TextDocument) {
vscode.window.showWarningMessage(`Errors occurred while formatting. Make sure you have the most recent Dioxus-CLI installed! \n${error}`);
}
}

class UriLaunchServer implements vscode.UriHandler {
handleUri(uri: vscode.Uri): vscode.ProviderResult<void> {
if (uri.path === '/debugger') {
let query = decodeURIComponent(uri.query);
let params = new URLSearchParams(query);
let route = params.get('uri');
vscode.window.showInformationMessage(`Opening Chrome debugger: ${route}`);
vscode.commands.executeCommand('extension.js-debug.debugLink', route);
}
}
}
Loading