| # 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("//build/testing/cc_test_executable.gni") | |
| static_library("lib") { | |
| sources = [ | |
| "align.cc", | |
| "align.h", | |
| "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_agent_observer.h", | |
| "debug_registers.h", | |
| "debugged_job.cc", | |
| "debugged_job.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_exception_channel_type.h", | |
| "job_exception_observer.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", | |
| ] | |
| public_deps = [ | |
| "//sdk/lib/fit", | |
| "//src/developer/debug/ipc", | |
| "//src/developer/debug/shared", | |
| "//src/lib/containers/cpp", | |
| "//third_party/googletest:gtest_prod", | |
| "//zircon/system/ulib/zx", | |
| ] | |
| deps = [ | |
| "//src/lib/elflib", | |
| "//src/lib/unwinder", | |
| ] | |
| # OS-independent architecture specific files. | |
| 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/42074048): Implement this | |
| sources += [ | |
| # "arch_riscv64.cc", | |
| # "debug_registers_riscv64.cc", | |
| ] | |
| } else { | |
| assert(false, "Un-supported CPU: ${current_cpu}") | |
| } | |
| if (is_fuchsia) { | |
| sources += [ | |
| "backtrace_utils.cc", | |
| "backtrace_utils.h", | |
| "debug_agent_server.cc", | |
| "debug_agent_server.h", | |
| "minidump_iterator.cc", | |
| "minidump_iterator.h", | |
| "process_info_iterator.cc", | |
| "process_info_iterator.h", | |
| "test_realm.cc", | |
| "test_realm.h", | |
| "zircon_arch.cc", | |
| "zircon_arch.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", | |
| ] | |
| public_deps += [ | |
| "//sdk/fidl/fuchsia.component:fuchsia.component_cpp", | |
| "//sdk/fidl/fuchsia.component.decl:fuchsia.component.decl_cpp", | |
| "//sdk/fidl/fuchsia.debugger:fuchsia.debugger_cpp", | |
| "//sdk/fidl/fuchsia.exception:fuchsia.exception_cpp", | |
| "//sdk/fidl/fuchsia.io:fuchsia.io_cpp", | |
| "//sdk/fidl/fuchsia.kernel:fuchsia.kernel_cpp", | |
| "//sdk/fidl/fuchsia.sys2:fuchsia.sys2_cpp", | |
| "//sdk/fidl/fuchsia.test.manager:fuchsia.test.manager_cpp", | |
| "//sdk/lib/async-loop:async-loop-cpp", | |
| "//sdk/lib/async-loop:async-loop-default", | |
| "//sdk/lib/component/outgoing/cpp", | |
| "//sdk/lib/syslog/cpp", | |
| "//src/lib/fxl", | |
| "//src/lib/process", | |
| "//third_party/crashpad/src/minidump", | |
| "//third_party/crashpad/src/snapshot", | |
| "//third_party/crashpad/src/util", | |
| "//zircon/system/ulib/inspector", | |
| ] | |
| deps += [ | |
| "//sdk/lib/component/incoming/cpp", | |
| "//src/lib/diagnostics/accessor2logger", | |
| ] | |
| # Fuchsia architecture-specific files. | |
| if (current_cpu == "x64") { | |
| sources += [ "zircon_arch_x64.cc" ] | |
| } else if (current_cpu == "arm64") { | |
| sources += [ "zircon_arch_arm64.cc" ] | |
| } else if (current_cpu == "riscv64") { | |
| # TODO(https://fxbug.dev/42074048): Implement this | |
| sources += [ | |
| # "zircon_arch_riscv64.cc", | |
| ] | |
| } else { | |
| assert(false, "Un-supported CPU: ${current_cpu}") | |
| } | |
| } else if (is_linux) { | |
| sources += [ | |
| "aligned_chunk.cc", | |
| "aligned_chunk.h", | |
| "linux_arch.h", | |
| "linux_binary_launcher.cc", | |
| "linux_binary_launcher.h", | |
| "linux_component_manager.cc", | |
| "linux_component_manager.h", | |
| "linux_exception_handle.cc", | |
| "linux_exception_handle.h", | |
| "linux_job_handle.cc", | |
| "linux_job_handle.h", | |
| "linux_process_handle.cc", | |
| "linux_process_handle.h", | |
| "linux_suspend_handle.h", | |
| "linux_system_interface.cc", | |
| "linux_system_interface.h", | |
| "linux_task.cc", | |
| "linux_task.h", | |
| "linux_task_observer.h", | |
| "linux_thread_handle.cc", | |
| "linux_thread_handle.h", | |
| "linux_utils.cc", | |
| "linux_utils.h", | |
| "posix/dir_reader_linux.h", | |
| "posix/eintr_wrapper.h", | |
| "posix/file_descriptor_shuffle.cc", | |
| "posix/file_descriptor_shuffle.h", | |
| ] | |
| if (current_cpu == "x64") { | |
| sources += [ "linux_arch_x64.cc" ] | |
| } else if (current_cpu == "arm64") { | |
| sources += [ "linux_arch_arm64.cc" ] | |
| } else if (current_cpu == "riscv64") { | |
| # TODO(https://fxbug.dev/42074048): Implement this: | |
| # sources += [ "linux_arch_riscv64.cc" ] | |
| } | |
| } | |
| } | |
| executable("bin") { | |
| output_name = "debug_agent" | |
| sources = [ "main.cc" ] | |
| deps = [ | |
| ":debug_agent_config", | |
| ":lib", | |
| ] | |
| } | |
| source_set("launcher") { | |
| sources = [ | |
| "launcher.cc", | |
| "launcher.h", | |
| ] | |
| public_deps = [ | |
| "//sdk/fidl/fuchsia.component:fuchsia.component_cpp", | |
| "//sdk/fidl/fuchsia.component.decl:fuchsia.component.decl_cpp", | |
| "//sdk/fidl/fuchsia.debugger:fuchsia.debugger_cpp", | |
| "//sdk/lib/component/incoming/cpp", | |
| "//sdk/lib/component/outgoing/cpp", | |
| "//sdk/lib/syslog/cpp", | |
| "//third_party/googletest:gtest_prod", | |
| ] | |
| deps = [ | |
| "//sdk/lib/async-default", | |
| "//sdk/lib/async-loop:async-loop-cpp", | |
| "//sdk/lib/async-loop:async-loop-default", | |
| ] | |
| } | |
| executable("debug_agent_launcher") { | |
| sources = [ "main_launcher.cc" ] | |
| deps = [ | |
| ":launcher", | |
| "//sdk/fidl/fuchsia.component:fuchsia.component_cpp", | |
| "//sdk/fidl/fuchsia.component.decl:fuchsia.component.decl_cpp", | |
| "//sdk/fidl/fuchsia.debugger:fuchsia.debugger_cpp", | |
| "//sdk/lib/async-default", | |
| "//sdk/lib/async-loop:async-loop-cpp", | |
| "//sdk/lib/async-loop:async-loop-default", | |
| "//sdk/lib/component/incoming/cpp", | |
| "//sdk/lib/component/outgoing/cpp", | |
| "//sdk/lib/syslog/cpp", | |
| ] | |
| } | |
| fuchsia_component_manifest("debug_agent_manifest") { | |
| component_name = "debug_agent" | |
| manifest = "meta/debug_agent.cml" | |
| } | |
| fuchsia_structured_config_cpp_elf_lib("debug_agent_config") { | |
| cm_label = ":debug_agent_manifest" | |
| } | |
| fuchsia_structured_config_values("debug_agent_config_default") { | |
| cm_label = ":debug_agent_manifest" | |
| values = { | |
| monitor_root_job = true | |
| } | |
| } | |
| fuchsia_component("debug_agent_component") { | |
| cm_label = ":debug_agent_manifest" | |
| deps = [ | |
| ":bin", | |
| ":debug_agent_config_default", | |
| ] | |
| } | |
| fuchsia_component("debug_agent_launcher_component") { | |
| component_name = "debug_agent_launcher" | |
| manifest = "meta/debug_agent_launcher.cml" | |
| deps = [ | |
| ":debug_agent_component", | |
| ":debug_agent_launcher", | |
| ] | |
| } | |
| cc_test_executable("zxdb_test_app") { | |
| sources = [ "zxdb_test_app.cc" ] | |
| deps = [ "//zircon/system/ulib/zx" ] | |
| } | |
| if (current_cpu == "riscv64") { | |
| # TODO(https://fxbug.dev/42074048): remove this empty group | |
| group("debug_agent") { | |
| } | |
| } else { | |
| fuchsia_package("debug_agent") { | |
| deps = [ | |
| ":debug_agent_component", | |
| ":debug_agent_launcher_component", | |
| ] | |
| # 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 | |
| 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", | |
| ] | |
| } | |
| } | |
| } | |
| # Common functionality used by tests. | |
| source_set("test_lib") { | |
| testonly = true | |
| sources = [ | |
| "local_stream_backend.cc", | |
| "local_stream_backend.h", | |
| "mock_component_manager.cc", | |
| "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", | |
| "//sdk/lib/syslog/cpp", | |
| "//src/developer/debug/shared:test_support", | |
| ] | |
| } | |
| test("launcher_tests") { | |
| output_name = "debug_agent_launcher_unit_tests" | |
| sources = [ "launcher_unittest.cc" ] | |
| deps = [ | |
| ":launcher", | |
| "//src/lib/fxl/test:gtest_main", | |
| "//third_party/googletest:gtest", | |
| ] | |
| } | |
| test("unit_tests") { | |
| output_name = "debug_agent_unit_tests" | |
| sources = [ "align_unittest.cc" ] | |
| deps = [ | |
| ":test_lib", | |
| "//src/lib/elflib", | |
| "//src/lib/fxl/test:gtest_main", | |
| "//third_party/googletest:gmock", | |
| "//third_party/googletest:gtest", | |
| ] | |
| if (is_fuchsia) { | |
| sources += [ | |
| "automation_instruction_executor_unittest.cc", | |
| "breakpoint_unittest.cc", | |
| "debug_agent_server_unittest.cc", | |
| "debug_agent_unittest.cc", | |
| "debugged_job_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", | |
| "minidump_iterator_unittest.cc", | |
| "process_info_iterator_unittest.cc", | |
| "software_breakpoint_unittest.cc", | |
| "system_interface_unittest.cc", | |
| "time_zircon_unittest.cc", | |
| "unwind_unittest.cc", | |
| "watchpoint_unittest.cc", | |
| "zircon_job_handle_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/42074048): Implement this. | |
| sources += [ | |
| # "arch_riscv64_unittest.cc", | |
| # "debug_registers_riscv64_unittest.cc", | |
| ] | |
| } else { | |
| assert(false, "Un-supported CPU: ${current_cpu}") | |
| } | |
| deps += [ | |
| "testing:runtime_dir_helper", | |
| "//sdk/fidl/fuchsia.component:fuchsia.component_cpp", | |
| "//sdk/fidl/fuchsia.component.decl:fuchsia.component.decl_cpp", | |
| "//sdk/lib/component/incoming/cpp", | |
| "//sdk/lib/component/outgoing/cpp", | |
| "//src/storage/lib/vfs/cpp", | |
| # Only include these here in the Fuchsia build because on the host build | |
| # they're included in the zxdb_unit_tests. | |
| "//src/developer/debug/ipc:tests", | |
| "//src/developer/debug/shared:tests", | |
| "//zircon/system/ulib/fbl", | |
| ] | |
| } else if (is_linux) { | |
| sources += [ | |
| "aligned_chunk_unittest.cc", | |
| "elf_utils_unittest.cc", | |
| "linux_utils_unittest.cc", | |
| "posix/file_descriptor_shuffle_unittest.cc", | |
| ] | |
| } | |
| } | |
| fuchsia_unittest_package("debug_agent_launcher_unit_tests") { | |
| component_name = "debug_agent_launcher_unit_tests" | |
| manifest = "meta/debug_agent_launcher_unit_tests.cml" | |
| deps = [ ":launcher_tests" ] | |
| } | |
| fuchsia_unittest_package("debug_agent_unit_tests") { | |
| component_name = "debug_agent_unit_tests" | |
| manifest = "meta/debug_agent_unit_tests.cml" | |
| deps = [ ":unit_tests" ] | |
| # required for accessing RootJob. | |
| test_type = "system" | |
| } | |
| fuchsia_unittest_package("debug_agent_integration_tests") { | |
| manifest = "meta/debug_agent_integration_tests.cml" | |
| deps = [ | |
| "integration_tests", | |
| "test_data:load_so_exe", | |
| ] | |
| # required for accessing RootJob. | |
| test_type = "system" | |
| } | |
| group("tests") { | |
| testonly = true | |
| deps = [ | |
| ":debug_agent_integration_tests", | |
| ":debug_agent_launcher_unit_tests", | |
| ":debug_agent_unit_tests", | |
| ] | |
| if (host_os == "linux") { | |
| deps += [ ":unit_tests($host_toolchain)" ] | |
| } | |
| } |