|  | # Copyright 2017 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("//build/components.gni") | 
|  | import("//build/test.gni") | 
|  | import("//src/sys/core/build/core_shard.gni") | 
|  |  | 
|  | # Set manually to true to compile helper executables for manual debugger | 
|  | # testing of various conditions. Use `ffx component explore /core/debug_agent` | 
|  | # to run these executables. | 
|  | include_helper_executables = false | 
|  |  | 
|  | static_library("lib") { | 
|  | sources = [ | 
|  | "align.cc", | 
|  | "align.h", | 
|  | "arch.cc", | 
|  | "arch.h", | 
|  | "automation_handler.cc", | 
|  | "automation_handler.h", | 
|  | "automation_instruction_executor.cc", | 
|  | "automation_instruction_executor.h", | 
|  | "binary_launcher.h", | 
|  | "breakpoint.cc", | 
|  | "breakpoint.h", | 
|  | "component_manager.cc", | 
|  | "component_manager.h", | 
|  | "debug_agent.cc", | 
|  | "debug_agent.h", | 
|  | "debug_registers.h", | 
|  | "debugged_process.cc", | 
|  | "debugged_process.h", | 
|  | "debugged_thread.cc", | 
|  | "debugged_thread.h", | 
|  | "elf_utils.cc", | 
|  | "elf_utils.h", | 
|  | "exception_handle.h", | 
|  | "filter.cc", | 
|  | "filter.h", | 
|  | "general_registers.cc", | 
|  | "general_registers.h", | 
|  | "hardware_breakpoint.cc", | 
|  | "hardware_breakpoint.h", | 
|  | "job_handle.cc", | 
|  | "job_handle.h", | 
|  | "limbo_provider.h", | 
|  | "module_list.cc", | 
|  | "module_list.h", | 
|  | "process_breakpoint.cc", | 
|  | "process_breakpoint.h", | 
|  | "process_handle.h", | 
|  | "process_handle_observer.h", | 
|  | "remote_api.h", | 
|  | "remote_api_adapter.cc", | 
|  | "remote_api_adapter.h", | 
|  | "software_breakpoint.cc", | 
|  | "software_breakpoint.h", | 
|  | "stdio_handles.h", | 
|  | "system_interface.cc", | 
|  | "system_interface.h", | 
|  | "thread_handle.h", | 
|  | "time.h", | 
|  | "unwind.cc", | 
|  | "unwind.h", | 
|  | "watchpoint.cc", | 
|  | "watchpoint.h", | 
|  | "zircon_binary_launcher.cc", | 
|  | "zircon_binary_launcher.h", | 
|  | "zircon_component_manager.cc", | 
|  | "zircon_component_manager.h", | 
|  | "zircon_exception_handle.cc", | 
|  | "zircon_exception_handle.h", | 
|  | "zircon_job_handle.cc", | 
|  | "zircon_job_handle.h", | 
|  | "zircon_limbo_provider.cc", | 
|  | "zircon_limbo_provider.h", | 
|  | "zircon_process_handle.cc", | 
|  | "zircon_process_handle.h", | 
|  | "zircon_suspend_handle.cc", | 
|  | "zircon_suspend_handle.h", | 
|  | "zircon_system_interface.cc", | 
|  | "zircon_system_interface.h", | 
|  | "zircon_thread_handle.cc", | 
|  | "zircon_thread_handle.h", | 
|  | "zircon_utils.cc", | 
|  | "zircon_utils.h", | 
|  | ] | 
|  |  | 
|  | if (current_cpu == "x64") { | 
|  | sources += [ | 
|  | "arch_x64.cc", | 
|  | "debug_registers_x64.cc", | 
|  | ] | 
|  | } else if (current_cpu == "arm64") { | 
|  | sources += [ | 
|  | "arch_arm64.cc", | 
|  | "debug_registers_arm64.cc", | 
|  | ] | 
|  | } else if (current_cpu == "riscv64") { | 
|  | # TODO(https://fxbug.dev/123097): Implement this | 
|  | sources += [ | 
|  | # "arch_riscv64.cc", | 
|  | # "debug_registers_riscv64.cc", | 
|  | ] | 
|  | } else { | 
|  | assert(false, "Un-supported CPU: ${current_cpu}") | 
|  | } | 
|  |  | 
|  | deps = [ | 
|  | "//src/developer/debug/third_party/libunwindstack", | 
|  | "//src/lib/diagnostics/accessor2logger", | 
|  | "//src/lib/elflib", | 
|  | "//src/lib/unwinder", | 
|  | "//zircon/third_party/ulib/ngunwind", | 
|  | ] | 
|  |  | 
|  | public_deps = [ | 
|  | "//sdk/fidl/fuchsia.exception:fuchsia.exception_hlcpp", | 
|  | "//sdk/fidl/fuchsia.io:fuchsia.io_hlcpp", | 
|  | "//sdk/fidl/fuchsia.kernel:fuchsia.kernel_hlcpp", | 
|  | "//sdk/fidl/fuchsia.sys2:fuchsia.sys2_hlcpp", | 
|  | "//sdk/fidl/fuchsia.test.manager:fuchsia.test.manager_hlcpp", | 
|  | "//sdk/lib/fit", | 
|  | "//sdk/lib/syslog/cpp", | 
|  | "//src/developer/debug/ipc", | 
|  | "//src/developer/debug/shared", | 
|  | "//src/lib/containers/cpp", | 
|  | "//src/lib/fxl", | 
|  | "//src/lib/process", | 
|  | "//third_party/crashpad/src/minidump", | 
|  | "//third_party/crashpad/src/snapshot", | 
|  | "//third_party/crashpad/src/util", | 
|  | "//third_party/googletest:gtest_prod", | 
|  | "//zircon/system/ulib/async-loop:async-loop-cpp", | 
|  | "//zircon/system/ulib/async-loop:async-loop-default", | 
|  | "//zircon/system/ulib/zx", | 
|  | ] | 
|  |  | 
|  | # TODO(https://fxbug.dev/58162): delete the below and fix compiler warnings | 
|  | configs += [ "//build/config:Wno-conversion" ] | 
|  | } | 
|  |  | 
|  | executable("bin") { | 
|  | output_name = "debug_agent" | 
|  | sources = [ "main.cc" ] | 
|  |  | 
|  | deps = [ ":lib" ] | 
|  |  | 
|  | # TODO(https://fxbug.dev/58162): delete the below and fix compiler warnings | 
|  | configs += [ "//build/config:Wno-conversion" ] | 
|  | } | 
|  |  | 
|  | executable("launcher") { | 
|  | output_name = "debug_agent_launcher" | 
|  | sources = [ "main_launcher.cc" ] | 
|  |  | 
|  | deps = [ | 
|  | "//sdk/fidl/fuchsia.debugger:fuchsia.debugger_hlcpp", | 
|  | "//sdk/lib/sys/cpp", | 
|  | "//sdk/lib/syslog/cpp", | 
|  | "//zircon/system/ulib/async-loop:async-loop-cpp", | 
|  | "//zircon/system/ulib/async-loop:async-loop-default", | 
|  | ] | 
|  | } | 
|  |  | 
|  | fuchsia_component("debug_agent-component") { | 
|  | component_name = "debug_agent" | 
|  | manifest = "meta/debug_agent.cml" | 
|  | deps = [ | 
|  | ":bin", | 
|  | ":launcher", | 
|  | ] | 
|  | } | 
|  |  | 
|  | executable("zxdb_test_app") { | 
|  | sources = [ "zxdb_test_app.cc" ] | 
|  | deps = [ "//zircon/system/ulib/zx" ] | 
|  |  | 
|  | # TODO(https://fxbug.dev/58162): delete the below and fix compiler warnings | 
|  | configs += [ "//build/config:Wno-conversion" ] | 
|  | } | 
|  |  | 
|  | # Enabling a soft-transition, remove when complete | 
|  | # TODO(122864) Remove transitional labels | 
|  | group("for_transition") { | 
|  | public_deps = [ ":debug_agent" ] | 
|  | } | 
|  |  | 
|  | fuchsia_package("debug_agent") { | 
|  | deps = [ ":debug_agent-component" ] | 
|  |  | 
|  | if (include_helper_executables) { | 
|  | # These executables are not used by tests or the agent, but are useful for | 
|  | # replicating behaviour in development. | 
|  | deps += [ | 
|  | ":zxdb_test_app", | 
|  | "test_data:helper_executables", | 
|  | ] | 
|  | } | 
|  | } | 
|  |  | 
|  | core_shard("core_shard") { | 
|  | shard_file = "meta/debug_agent.core_shard.cml" | 
|  | } | 
|  |  | 
|  | # Common functionality used by tests. | 
|  | source_set("test_lib") { | 
|  | testonly = true | 
|  | sources = [ | 
|  | "local_stream_backend.cc", | 
|  | "local_stream_backend.h", | 
|  | "mock_component_manager.h", | 
|  | "mock_debug_agent_harness.cc", | 
|  | "mock_debug_agent_harness.h", | 
|  | "mock_exception_handle.h", | 
|  | "mock_job_handle.cc", | 
|  | "mock_job_handle.h", | 
|  | "mock_limbo_provider.cc", | 
|  | "mock_limbo_provider.h", | 
|  | "mock_process.cc", | 
|  | "mock_process.h", | 
|  | "mock_process_handle.cc", | 
|  | "mock_process_handle.h", | 
|  | "mock_stream_backend.h", | 
|  | "mock_system_interface.cc", | 
|  | "mock_system_interface.h", | 
|  | "mock_thread.cc", | 
|  | "mock_thread.h", | 
|  | "mock_thread_handle.cc", | 
|  | "mock_thread_handle.h", | 
|  | ] | 
|  |  | 
|  | public_deps = [ | 
|  | ":lib", | 
|  | "//src/developer/debug/shared:test_support", | 
|  | ] | 
|  |  | 
|  | # TODO(https://fxbug.dev/58162): delete the below and fix compiler warnings | 
|  | configs += [ "//build/config:Wno-conversion" ] | 
|  | } | 
|  |  | 
|  | test("unit_tests") { | 
|  | output_name = "debug_agent_unit_tests" | 
|  |  | 
|  | sources = [ | 
|  | "align_unittest.cc", | 
|  | "automation_instruction_executor_unittest.cc", | 
|  | "breakpoint_unittest.cc", | 
|  | "debug_agent_unittest.cc", | 
|  | "debugged_process_unittest.cc", | 
|  | "debugged_thread_breakpoint_unittest.cc", | 
|  | "debugged_thread_unittest.cc", | 
|  | "elf_utils_unittest.cc", | 
|  | "filter_unittest.cc", | 
|  | "hardware_breakpoint_unittest.cc", | 
|  | "software_breakpoint_unittest.cc", | 
|  | "system_interface_unittest.cc", | 
|  | "time_zircon_unittest.cc", | 
|  | "unwind_unittest.cc", | 
|  | "watchpoint_unittest.cc", | 
|  | "zircon_limbo_provider_unittest.cc", | 
|  | "zircon_system_interface_unittest.cc", | 
|  | ] | 
|  |  | 
|  | if (current_cpu == "x64") { | 
|  | sources += [ | 
|  | "arch_x64_unittest.cc", | 
|  | "debug_registers_x64_unittest.cc", | 
|  | ] | 
|  | } else if (current_cpu == "arm64") { | 
|  | sources += [ | 
|  | "arch_arm64_unittest.cc", | 
|  | "debug_registers_arm64_unittest.cc", | 
|  | ] | 
|  | } else if (current_cpu == "riscv64") { | 
|  | # TODO(https://fxbug.dev/123097): Implement this. | 
|  | sources += [ | 
|  | # "arch_riscv64_unittest.cc", | 
|  | # "debug_registers_riscv64_unittest.cc", | 
|  | ] | 
|  | } else { | 
|  | assert(false, "Un-supported CPU: ${current_cpu}") | 
|  | } | 
|  |  | 
|  | deps = [ | 
|  | ":test_lib", | 
|  | "//sdk/lib/sys/cpp/testing:unit", | 
|  | "//src/developer/debug/ipc:tests", | 
|  | "//src/developer/debug/shared:tests", | 
|  | "//src/lib/fxl/test:gtest_main", | 
|  | "//third_party/googletest:gmock", | 
|  | "//third_party/googletest:gtest", | 
|  | ] | 
|  |  | 
|  | # TODO(https://fxbug.dev/58162): delete the below and fix compiler warnings | 
|  | configs += [ "//build/config:Wno-conversion" ] | 
|  | } | 
|  |  | 
|  | fuchsia_unittest_package("debug_agent_unit_tests") { | 
|  | component_name = "debug_agent_unit_tests" | 
|  | manifest = "meta/debug_agent_unit_tests.cml" | 
|  | deps = [ ":unit_tests" ] | 
|  | } | 
|  |  | 
|  | fuchsia_unittest_package("debug_agent_integration_tests") { | 
|  | manifest = "meta/debug_agent_integration_tests.cml" | 
|  | deps = [ | 
|  | "integration_tests", | 
|  | "test_data:debug_agent_test_loadable_module", | 
|  |  | 
|  | # These are executables that integration tests will need in order to test | 
|  | # actual behaviour against zircon. | 
|  | "test_data:test_executables", | 
|  | ] | 
|  | } | 
|  |  | 
|  | group("tests") { | 
|  | testonly = true | 
|  |  | 
|  | deps = [ | 
|  | ":debug_agent_integration_tests", | 
|  | ":debug_agent_unit_tests", | 
|  | ] | 
|  | } |