Skip to content

Commit dd909bc

Browse files
Sandlot19Rebase bot
authored andcommitted
[debugger] Add ffx debug crash
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 <abarth@google.com> Commit-Queue: Jacob Rutherford <jruthe@google.com> Reviewed-by: Clayton Wilkinson <wilkinsonclay@google.com>
1 parent 5155304 commit dd909bc

File tree

6 files changed

+105
-0
lines changed

6 files changed

+105
-0
lines changed

src/developer/ffx/plugins/debug/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ffx_plugin("ffx_debug_plugin") {
1212
plugin_deps = [
1313
"connect:ffx_debug_connect",
1414
"core:ffx_debug_core",
15+
"crash:ffx_debug_crash",
1516
"fidlcat:ffx_debug_fidlcat",
1617
"limbo:ffx_debug_limbo",
1718
"symbol-index:ffx_debug_symbol_index",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2023 The Fuchsia Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import("//src/developer/ffx/build/ffx_plugin.gni")
6+
7+
ffx_plugin("ffx_debug_crash") {
8+
version = "0.1.0"
9+
edition = "2021"
10+
11+
args_sources = [ "src/args.rs" ]
12+
sources = [ "src/lib.rs" ]
13+
14+
deps = [
15+
"//sdk/fidl/fuchsia.debugger:fuchsia.debugger_rust",
16+
"//sdk/fidl/fuchsia.exception:fuchsia.exception_rust",
17+
"//src/developer/debug/ffx_zxdb",
18+
"//src/developer/ffx/lib/fho:lib",
19+
"//third_party/rust_crates:anyhow",
20+
"//third_party/rust_crates:async-trait",
21+
]
22+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2023 The Fuchsia Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
use argh::{ArgsInfo, FromArgs};
6+
use ffx_core::ffx_command;
7+
8+
#[ffx_command()]
9+
#[derive(ArgsInfo, FromArgs, PartialEq, Debug)]
10+
#[argh(subcommand, name = "crash", description = "catch a crashing process on the target")]
11+
pub struct CrashCommand {}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2023 The Fuchsia Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
use anyhow::Result;
6+
use async_trait::async_trait;
7+
use ffx_debug_crash_args::CrashCommand;
8+
use ffx_zxdb::Debugger;
9+
use fho::{moniker, FfxMain, FfxTool, SimpleWriter};
10+
use fidl_fuchsia_debugger as fdebugger;
11+
use fidl_fuchsia_exception::ProcessLimboProxy;
12+
13+
#[derive(FfxTool)]
14+
pub struct CrashTool {
15+
#[command]
16+
_cmd: CrashCommand,
17+
#[with(moniker("/core/exceptions"))]
18+
limbo_proxy: ProcessLimboProxy,
19+
#[with(moniker("/core/debugger"))]
20+
launcher_proxy: fdebugger::LauncherProxy,
21+
}
22+
23+
fho::embedded_plugin!(CrashTool);
24+
25+
#[async_trait(?Send)]
26+
impl FfxMain for CrashTool {
27+
type Writer = SimpleWriter;
28+
29+
async fn main(self, mut _writer: Self::Writer) -> fho::Result<()> {
30+
crash_tool_impl(self.limbo_proxy, self.launcher_proxy).await?;
31+
Ok(())
32+
}
33+
}
34+
35+
async fn run_debugger(launcher_proxy: fdebugger::LauncherProxy) -> Result<()> {
36+
let mut debugger = Debugger::launch(launcher_proxy).await?;
37+
debugger.command.push_str("--auto-attach-limbo");
38+
debugger.run().await
39+
}
40+
41+
async fn crash_tool_impl(
42+
limbo_proxy: ProcessLimboProxy,
43+
launcher_proxy: fdebugger::LauncherProxy,
44+
) -> Result<()> {
45+
limbo_proxy.set_active(true).await?;
46+
let run_result = run_debugger(launcher_proxy).await;
47+
limbo_proxy.set_active(false).await?;
48+
49+
run_result?;
50+
Ok(())
51+
}

src/developer/ffx/tests/cli-goldens/goldens/debug_filelist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
ffx/debug.golden
22
ffx/debug/connect.golden
33
ffx/debug/core.golden
4+
ffx/debug/crash.golden
45
ffx/debug/fidl.golden
56
ffx/debug/limbo.golden
67
ffx/debug/limbo/disable.golden
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "crash",
3+
"description": "catch a crashing process on the target",
4+
"examples": [],
5+
"flags": [
6+
{
7+
"kind": "Switch",
8+
"optionality": "optional",
9+
"long": "--help",
10+
"short": null,
11+
"description": "display usage information",
12+
"hidden": false
13+
}
14+
],
15+
"notes": [],
16+
"commands": [],
17+
"positionals": [],
18+
"error_codes": []
19+
}

0 commit comments

Comments
 (0)