1package {
2    default_applicable_licenses: ["Android-Apache-2.0"],
3}
4
5cc_defaults {
6    name: "debuggerd_defaults",
7    cflags: [
8        "-Wall",
9        "-Wextra",
10        "-Werror",
11        "-Wno-gcc-compat",
12        "-Wno-unused-argument",
13        "-Wno-unused-function",
14        "-Wno-nullability-completeness",
15        "-Os",
16        "-fno-finite-loops",
17        "-DANDROID_DEBUGGABLE=0",
18    ],
19
20    local_include_dirs: ["include"],
21    product_variables: {
22        debuggable: {
23            cflags: ["-UANDROID_DEBUGGABLE", "-DANDROID_DEBUGGABLE=1"],
24        }
25    },
26}
27
28cc_library_headers {
29    name: "libdebuggerd_common_headers",
30    export_include_dirs: ["common/include"],
31    recovery_available: true,
32    vendor_ramdisk_available: true,
33    apex_available: [
34        "com.android.virt",
35        "//apex_available:platform",
36   ],
37}
38
39cc_library_shared {
40    name: "libtombstoned_client",
41    defaults: ["debuggerd_defaults"],
42    srcs: [
43        "tombstoned/tombstoned_client.cpp",
44        "util.cpp",
45    ],
46
47    header_libs: ["libdebuggerd_common_headers"],
48
49    static_libs: [
50        "libasync_safe",
51    ],
52
53    shared_libs: [
54        "libbase",
55        "libcutils",
56    ],
57    apex_available: [
58        "com.android.virt",
59        "//apex_available:platform",
60    ],
61
62    export_header_lib_headers: ["libdebuggerd_common_headers"],
63    export_include_dirs: ["tombstoned/include"],
64}
65
66// Utility library to talk to tombstoned and get an output fd.
67cc_library_static {
68    name: "libtombstoned_client_static",
69    defaults: ["debuggerd_defaults"],
70    recovery_available: true,
71    vendor_ramdisk_available: true,
72    srcs: [
73        "tombstoned/tombstoned_client.cpp",
74        "util.cpp",
75    ],
76
77    header_libs: ["libdebuggerd_common_headers"],
78
79    whole_static_libs: [
80        "libasync_safe",
81        "libcutils",
82        "libbase",
83    ],
84
85    export_header_lib_headers: ["libdebuggerd_common_headers"],
86    export_include_dirs: ["tombstoned/include"],
87}
88
89// Core implementation, linked into libdebuggerd_handler and the dynamic linker.
90cc_library_static {
91    name: "libdebuggerd_handler_core",
92    defaults: ["debuggerd_defaults"],
93    recovery_available: true,
94    vendor_ramdisk_available: true,
95    srcs: ["handler/debuggerd_handler.cpp"],
96
97    header_libs: [
98        "libbase_headers",
99        "libdebuggerd_common_headers",
100        "bionic_libc_platform_headers",
101        "gwp_asan_headers",
102    ],
103
104    whole_static_libs: [
105        "libasync_safe",
106        "libcutils",
107        "libdebuggerd",
108    ],
109
110    export_header_lib_headers: ["libdebuggerd_common_headers"],
111    export_include_dirs: ["include"],
112}
113
114// Implementation with a no-op fallback.
115cc_library_static {
116    name: "libdebuggerd_handler",
117    defaults: ["debuggerd_defaults"],
118    srcs: ["handler/debuggerd_fallback_nop.cpp"],
119
120    header_libs: ["bionic_libc_platform_headers"],
121    export_header_lib_headers: ["bionic_libc_platform_headers"],
122
123    whole_static_libs: [
124        "libdebuggerd_handler_core",
125    ],
126
127    export_include_dirs: ["include"],
128}
129
130// Fallback implementation, for use in the Bionic linker only.
131cc_library_static {
132    name: "libdebuggerd_handler_fallback",
133    visibility: ["//bionic/linker"],
134    apex_available: [
135        "com.android.runtime",
136        "//apex_available:platform",
137    ],
138    defaults: ["debuggerd_defaults"],
139    recovery_available: true,
140    vendor_ramdisk_available: true,
141    srcs: [
142        "handler/debuggerd_fallback.cpp",
143    ],
144
145    whole_static_libs: [
146        "libdebuggerd_handler_core",
147        "libtombstoned_client_static",
148        "libasync_safe",
149        "libbase",
150        "libdebuggerd",
151        "libunwindstack_no_dex",
152        "liblzma",
153        "libcutils",
154    ],
155
156    header_libs: ["bionic_libc_platform_headers"],
157    export_header_lib_headers: ["bionic_libc_platform_headers"],
158
159    export_include_dirs: ["include"],
160}
161
162cc_library {
163    name: "libdebuggerd_client",
164    defaults: ["debuggerd_defaults"],
165    srcs: [
166        "client/debuggerd_client.cpp",
167        "util.cpp",
168    ],
169
170    shared_libs: [
171        "libbase",
172        "libcutils",
173        "libprocinfo",
174    ],
175
176    header_libs: [
177        "libdebuggerd_common_headers",
178        "bionic_libc_platform_headers",
179    ],
180    export_header_lib_headers: [
181        "libdebuggerd_common_headers",
182        "bionic_libc_platform_headers",
183    ],
184
185    export_include_dirs: ["include"],
186}
187
188cc_library_static {
189    name: "libdebuggerd",
190    defaults: ["debuggerd_defaults"],
191    recovery_available: true,
192    vendor_ramdisk_available: true,
193
194    srcs: [
195        "libdebuggerd/backtrace.cpp",
196        "libdebuggerd/gwp_asan.cpp",
197        "libdebuggerd/open_files_list.cpp",
198        "libdebuggerd/tombstone.cpp",
199        "libdebuggerd/tombstone_proto.cpp",
200        "libdebuggerd/tombstone_proto_to_text.cpp",
201        "libdebuggerd/utility.cpp",
202    ],
203
204    local_include_dirs: ["libdebuggerd/include"],
205    export_include_dirs: ["libdebuggerd/include"],
206
207    include_dirs: [
208        // Needed for private/bionic_fdsan.h
209        "bionic/libc",
210    ],
211    header_libs: [
212        "bionic_libc_platform_headers",
213        "gwp_asan_headers",
214        "liblog_headers",
215    ],
216
217    static_libs: [
218        "libdexfile_support",  // libunwindstack dependency
219        "libunwindstack",
220        "liblzma",
221        "libbase",
222        "libcutils",
223    ],
224    runtime_libs: [
225        "libdexfile",           // libdexfile_support dependency
226    ],
227
228    whole_static_libs: [
229        "libasync_safe",
230        "gwp_asan_crash_handler",
231        "libtombstone_proto",
232        "libprocinfo",
233        "libprotobuf-cpp-lite",
234    ],
235
236    target: {
237        recovery: {
238            exclude_static_libs: [
239                "libdexfile_support",
240            ],
241            exclude_runtime_libs: [
242                "libdexfile",
243            ],
244        },
245        vendor_ramdisk: {
246            exclude_static_libs: [
247                "libdexfile_support",
248            ],
249            exclude_runtime_libs: [
250                "libdexfile",
251            ],
252        },
253    },
254
255    product_variables: {
256        debuggable: {
257            cflags: ["-DROOT_POSSIBLE"],
258        },
259
260        malloc_not_svelte: {
261            cflags: ["-DUSE_SCUDO"],
262            whole_static_libs: ["libscudo"],
263            srcs: ["libdebuggerd/scudo.cpp"],
264            header_libs: ["scudo_headers"],
265        },
266    },
267}
268
269cc_binary {
270    name: "pbtombstone",
271    defaults: ["debuggerd_defaults"],
272    srcs: ["pbtombstone.cpp"],
273    static_libs: [
274        "libbase",
275        "libdebuggerd",
276        "liblog",
277        "libprotobuf-cpp-lite",
278        "libtombstone_proto",
279        "libunwindstack",
280    ],
281}
282
283cc_test_library {
284    name: "libcrash_test",
285    defaults: ["debuggerd_defaults"],
286    srcs: ["crash_test.cpp"],
287}
288
289cc_test {
290    name: "debuggerd_test",
291    defaults: ["debuggerd_defaults"],
292    require_root: true,
293
294    cflags: ["-Wno-missing-field-initializers"],
295    srcs: [
296        "libdebuggerd/test/dump_memory_test.cpp",
297        "libdebuggerd/test/elf_fake.cpp",
298        "libdebuggerd/test/log_fake.cpp",
299        "libdebuggerd/test/open_files_list_test.cpp",
300        "libdebuggerd/test/utility_test.cpp",
301    ],
302
303    target: {
304        android: {
305            srcs: [
306                "client/debuggerd_client_test.cpp",
307                "debuggerd_test.cpp",
308            ],
309            static_libs: [
310                "libasync_safe",
311                "libtombstoned_client_static",
312            ],
313        },
314    },
315
316    shared_libs: [
317        "libbase",
318        "libcutils",
319        "libdebuggerd_client",
320        "liblog",
321        "libnativehelper",
322        "libunwindstack",
323    ],
324
325    static_libs: [
326        "libdebuggerd",
327        "libgmock",
328        "libminijail",
329    ],
330
331    header_libs: [
332        "bionic_libc_platform_headers",
333        "gwp_asan_headers",
334    ],
335
336    local_include_dirs: [
337        "libdebuggerd",
338    ],
339
340    compile_multilib: "both",
341    multilib: {
342        lib32: {
343            stem: "debuggerd_test32",
344        },
345        lib64: {
346            stem: "debuggerd_test64",
347        },
348    },
349
350    data: [
351        ":libcrash_test",
352    ],
353
354    test_suites: ["device-tests"],
355}
356
357cc_benchmark {
358    name: "debuggerd_benchmark",
359    defaults: ["debuggerd_defaults"],
360    srcs: ["debuggerd_benchmark.cpp"],
361    shared_libs: [
362        "libbase",
363        "libdebuggerd_client",
364    ],
365}
366
367cc_binary {
368    name: "crash_dump",
369    srcs: [
370        "crash_dump.cpp",
371        "tombstone_handler.cpp",
372        "util.cpp",
373    ],
374    defaults: ["debuggerd_defaults"],
375
376    compile_multilib: "both",
377    multilib: {
378        lib32: {
379            suffix: "32",
380        },
381        lib64: {
382            suffix: "64",
383        },
384    },
385
386    header_libs: [
387        "bionic_libc_platform_headers",
388    ],
389
390    static_libs: [
391        "libtombstoned_client_static",
392        "libdebuggerd",
393        "libcutils",
394
395        "libtombstone_proto",
396        "libprotobuf-cpp-lite",
397    ],
398
399    shared_libs: [
400        "libbase",
401        "liblog",
402        "libprocinfo",
403        "libunwindstack",
404    ],
405
406    apex_available: [
407        "com.android.runtime",
408    ],
409
410    // Required for tests.
411    required: ["crash_dump.policy"],
412}
413
414cc_binary {
415    name: "debuggerd",
416    srcs: [
417        "debuggerd.cpp",
418    ],
419    defaults: ["debuggerd_defaults"],
420
421    shared_libs: [
422        "libbase",
423        "libdebuggerd_client",
424        "liblog",
425        "libprocinfo",
426    ],
427
428    local_include_dirs: ["include"],
429}
430
431cc_defaults {
432    name: "tombstoned_defaults",
433    srcs: [
434        "util.cpp",
435        "tombstoned/intercept_manager.cpp",
436        "tombstoned/tombstoned.cpp",
437    ],
438    defaults: ["debuggerd_defaults"],
439
440    header_libs: [
441        "bionic_libc_platform_headers",
442        "libdebuggerd_common_headers"
443    ],
444
445    static_libs: [
446        "libbase",
447        "libcutils",
448        "libevent",
449        "liblog",
450    ],
451}
452
453cc_binary {
454    name: "tombstoned",
455    defaults: ["tombstoned_defaults"],
456    init_rc: ["tombstoned/tombstoned.rc"],
457}
458
459cc_binary {
460    name: "tombstoned.microdroid",
461    defaults: ["tombstoned_defaults"],
462    init_rc: ["tombstoned/tombstoned.microdroid.rc"],
463}
464
465prebuilt_etc {
466    name: "crash_dump.policy",
467    sub_dir: "seccomp_policy",
468    filename_from_src: true,
469    arch: {
470        arm: {
471            src: "seccomp_policy/crash_dump.arm.policy",
472            required: [
473                "crash_dump.policy_other",
474            ],
475        },
476        arm64: {
477            src: "seccomp_policy/crash_dump.arm64.policy",
478            required: [
479                "crash_dump.policy_other",
480            ],
481        },
482        riscv64: {
483            src: "seccomp_policy/crash_dump.riscv64.policy",
484        },
485        x86: {
486            src: "seccomp_policy/crash_dump.x86.policy",
487            required: [
488                "crash_dump.policy_other",
489            ],
490        },
491        x86_64: {
492            src: "seccomp_policy/crash_dump.x86_64.policy",
493            required: [
494                "crash_dump.policy_other",
495            ],
496        },
497    },
498}
499
500
501// This installs the "other" architecture (so 32-bit on 64-bit device).
502prebuilt_etc {
503    name: "crash_dump.policy_other",
504    sub_dir: "seccomp_policy",
505    filename_from_src: true,
506    arch: {
507        arm: {
508            src: "seccomp_policy/crash_dump.arm64.policy",
509        },
510        arm64: {
511            src: "seccomp_policy/crash_dump.arm.policy",
512        },
513        riscv64: {
514            enabled: false,
515        },
516        x86: {
517            src: "seccomp_policy/crash_dump.x86_64.policy",
518        },
519        x86_64: {
520            src: "seccomp_policy/crash_dump.x86.policy",
521        },
522    },
523}
524