Skip to content

Commit

Permalink
[debugger] Add ffx debug crash
Browse files Browse the repository at this point in the history
This command enables ProcessLimbo and runs the debugger, expecting
something to crash in the near future. When the debugging session
eventually ends, ProcessLimbo is disabled again.

Change-Id: Icbdadcbe24b27ba2bfa2c681af6de5272b08167a
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/965623
Reviewed-by: Adam Barth <[email protected]>
Commit-Queue: Jacob Rutherford <[email protected]>
Reviewed-by: Clayton Wilkinson <[email protected]>
  • Loading branch information
Sandlot19 authored and Rebase bot committed Jan 11, 2024
1 parent 5155304 commit dd909bc
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/developer/ffx/plugins/debug/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ffx_plugin("ffx_debug_plugin") {
plugin_deps = [
"connect:ffx_debug_connect",
"core:ffx_debug_core",
"crash:ffx_debug_crash",
"fidlcat:ffx_debug_fidlcat",
"limbo:ffx_debug_limbo",
"symbol-index:ffx_debug_symbol_index",
Expand Down
22 changes: 22 additions & 0 deletions src/developer/ffx/plugins/debug/crash/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2023 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//src/developer/ffx/build/ffx_plugin.gni")

ffx_plugin("ffx_debug_crash") {
version = "0.1.0"
edition = "2021"

args_sources = [ "src/args.rs" ]
sources = [ "src/lib.rs" ]

deps = [
"//sdk/fidl/fuchsia.debugger:fuchsia.debugger_rust",
"//sdk/fidl/fuchsia.exception:fuchsia.exception_rust",
"//src/developer/debug/ffx_zxdb",
"//src/developer/ffx/lib/fho:lib",
"//third_party/rust_crates:anyhow",
"//third_party/rust_crates:async-trait",
]
}
11 changes: 11 additions & 0 deletions src/developer/ffx/plugins/debug/crash/src/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2023 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use argh::{ArgsInfo, FromArgs};
use ffx_core::ffx_command;

#[ffx_command()]
#[derive(ArgsInfo, FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "crash", description = "catch a crashing process on the target")]
pub struct CrashCommand {}
51 changes: 51 additions & 0 deletions src/developer/ffx/plugins/debug/crash/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2023 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use anyhow::Result;
use async_trait::async_trait;
use ffx_debug_crash_args::CrashCommand;
use ffx_zxdb::Debugger;
use fho::{moniker, FfxMain, FfxTool, SimpleWriter};
use fidl_fuchsia_debugger as fdebugger;
use fidl_fuchsia_exception::ProcessLimboProxy;

#[derive(FfxTool)]
pub struct CrashTool {
#[command]
_cmd: CrashCommand,
#[with(moniker("/core/exceptions"))]
limbo_proxy: ProcessLimboProxy,
#[with(moniker("/core/debugger"))]
launcher_proxy: fdebugger::LauncherProxy,
}

fho::embedded_plugin!(CrashTool);

#[async_trait(?Send)]
impl FfxMain for CrashTool {
type Writer = SimpleWriter;

async fn main(self, mut _writer: Self::Writer) -> fho::Result<()> {
crash_tool_impl(self.limbo_proxy, self.launcher_proxy).await?;
Ok(())
}
}

async fn run_debugger(launcher_proxy: fdebugger::LauncherProxy) -> Result<()> {
let mut debugger = Debugger::launch(launcher_proxy).await?;
debugger.command.push_str("--auto-attach-limbo");
debugger.run().await
}

async fn crash_tool_impl(
limbo_proxy: ProcessLimboProxy,
launcher_proxy: fdebugger::LauncherProxy,
) -> Result<()> {
limbo_proxy.set_active(true).await?;
let run_result = run_debugger(launcher_proxy).await;
limbo_proxy.set_active(false).await?;

run_result?;
Ok(())
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ffx/debug.golden
ffx/debug/connect.golden
ffx/debug/core.golden
ffx/debug/crash.golden
ffx/debug/fidl.golden
ffx/debug/limbo.golden
ffx/debug/limbo/disable.golden
Expand Down
19 changes: 19 additions & 0 deletions src/developer/ffx/tests/cli-goldens/goldens/ffx/debug/crash.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "crash",
"description": "catch a crashing process on the target",
"examples": [],
"flags": [
{
"kind": "Switch",
"optionality": "optional",
"long": "--help",
"short": null,
"description": "display usage information",
"hidden": false
}
],
"notes": [],
"commands": [],
"positionals": [],
"error_codes": []
}

0 comments on commit dd909bc

Please sign in to comment.