From 5e00a85fc293b4dc413215ff3c45eeb3c726e8cc Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Wed, 6 Oct 2021 00:16:41 +0000 Subject: [PATCH] [fuchsia] Add debug symbols when running test suites This also updates the Fuchsia debugging documentation instructions. Bug: 1254560 Change-Id: I1351d47762504a41557f13caa2b3fc1794789bc2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3199373 Commit-Queue: Fabrice de Gans Reviewed-by: Kevin Marshall Cr-Commit-Position: refs/heads/main@{#928433} --- build/fuchsia/common_args.py | 1 + build/fuchsia/test_runner.py | 8 ++- docs/fuchsia/debug_instructions.md | 99 ++++++++++++++++++++++-------- 3 files changed, 83 insertions(+), 25 deletions(-) diff --git a/build/fuchsia/common_args.py b/build/fuchsia/common_args.py index a357e1d1a9bc03..3b709c6aab2021 100644 --- a/build/fuchsia/common_args.py +++ b/build/fuchsia/common_args.py @@ -83,6 +83,7 @@ def AddCommonArgs(arg_parser): help=('Path to the directory in which build files are located. ' 'Defaults to current directory.')) common_args.add_argument('--fuchsia-out-dir', + default=None, help='Path to a Fuchsia build output directory. ' 'Setting the GN arg ' '"default_fuchsia_build_dir_for_installation" ' diff --git a/build/fuchsia/test_runner.py b/build/fuchsia/test_runner.py index 472d70b091df80..75b83d2cda9d4c 100755 --- a/build/fuchsia/test_runner.py +++ b/build/fuchsia/test_runner.py @@ -13,10 +13,10 @@ from common_args import AddCommonArgs, AddTargetSpecificArgs, \ ConfigureLogging, GetDeploymentTargetForArgs +from deploy_to_pkg_repo import InstallSymbols from net_test_server import SetupTestServer from run_test_package import RunTestPackage, RunTestPackageArgs from runner_exceptions import HandleExceptionAndReturnExitCode -from symbolizer import BuildIdsPaths DEFAULT_TEST_SERVER_CONCURRENCY = 4 @@ -221,6 +221,12 @@ def main(): test_server = SetupTestServer(target, test_concurrency, args.package_name, test_realms) + if args.device is not None and args.fuchsia_out_dir is not None: + build_ids_path = os.path.join(args.fuchsia_out_dir, '.build-id') + for package in args.package: + InstallSymbols(os.path.join(os.path.dirname(package), 'ids.txt'), + build_ids_path) + run_package_args = RunTestPackageArgs.FromCommonArgs(args) if args.use_run_test_component: run_package_args.test_realm_label = TEST_REALM_NAME diff --git a/docs/fuchsia/debug_instructions.md b/docs/fuchsia/debug_instructions.md index 264332bbc5daf7..023b838ef7a15a 100644 --- a/docs/fuchsia/debug_instructions.md +++ b/docs/fuchsia/debug_instructions.md @@ -1,49 +1,100 @@ # Debugging -It is possible to debug Fuchsia binaries using `zxdb`. For the sake of this -example, we will be using `base_unittests` as the test suite we wish to execute: +It is possible to debug Fuchsia binaries using `zxdb`. For the sake of these +examples, we will be using `base_unittests` as the test suite we wish to +execute. These instructions assume that your Chromium build has the following gn +arguments: + +``` +is_debug = true +is_component_build = true +target_os = "fuchsia" +symbol_level = 2 +``` + +## Manual debugging via the command line 1. (From Chromium) Install your package(s) and its symbols onto the device. ```bash - $ out/fuchsia/bin/install_base_unittests + out/fuchsia/bin/install_base_unittests --fuchsia-out-dir=/path/to/fuchsia/out/directory ``` 2. (From Fuchsia source tree) Run the debugger. - ```bash - $ fx debug - ``` + ```bash + fx debug -- --build-dir /path/to/chromium/src/out/directory + ``` 3. Set up the debugger to attach to the process. - ``` - [zxdb] attach base_unittests.cmx - ``` + ``` + [zxdb] attach base_unittests.cmx + ``` 4. Configure breakpoint(s). - ``` - [zxdb] break base::GetDefaultJob - ``` + ``` + [zxdb] break base::GetDefaultJob + ``` 5. (In another terminal, from Fuchsia source tree) Run the test package. - ```bash - $ fx shell run fuchsia-pkg://fuchsia.com/base_unittests#meta/base_unittests.cmx - ``` + ```bash + fx shell run fuchsia-pkg://fuchsia.com/base_unittests#meta/base_unittests.cmx + ``` 6. At this point, you should hit a breakpoint in `zxdb`. - ``` - [zxdb] f - ▶ 0 base::GetDefaultJob() • default_job.cc:18 - 1 base::$anon::LaunchChildTestProcessWithOptions(…) • test_launcher.cc:335 - 2 base::$anon::DoLaunchChildTestProcess(…) • test_launcher.cc:528 - 3 base::TestLauncher::LaunchChildGTestProcess(…) • test_launcher.cc:877 - ... - ``` + ``` + [zxdb] f + ▶ 0 base::GetDefaultJob() • default_job.cc:18 + 1 base::$anon::LaunchChildTestProcessWithOptions(…) • test_launcher.cc:335 + 2 base::$anon::DoLaunchChildTestProcess(…) • test_launcher.cc:528 + 3 base::TestLauncher::LaunchChildGTestProcess(…) • test_launcher.cc:877 + ... + ``` 7. Enjoy debugging! Steps 2 through 6 will also work for things like services which aren't run directly from the command line, such as WebEngine. - Run `help` inside ZXDB to see what debugger commands are available. \ No newline at end of file + Run `help` inside ZXDB to see what debugger commands are available. + +## VS Code integration + +1. Install the [zxdb](https://marketplace.visualstudio.com/items?itemName=fuchsia-authors.zxdb) + extension. + +2. Modify the `zxdb.command` setting in your Chromium workspace to this value: + + ```bash + (cd /path/to/fuchsia ; fx debug -- --enable-debug-adapter --build-dir /path/to/chromium/src/out/directory) + ``` + +3. Edit your debug launch configurations in `.vscode/launch.json`: + + ```json + { + "version": "0.2.0", + "configurations": [ + { + "name": "Attach to base_unittests", + "type": "zxdb", + "request": "attach", + "process": "base_unittests.cmx" + } + ] + } + ``` + + You can add more configurations as needed. + +4. Start the debug configuration in VS Code. You should get a terminal with zxdb + running. + +5. Launch the test suite in a terminal. + + ```bash + out/fuchsia/bin/run_base_unittests -d --fuchsia-out-dir=/path/to/fuchsia/out/directory + ``` + +6. Breakpoints set in the IDE should work.