blob: 2d0e5fd1b11bf209ca615594b5e7d22babf64b8b [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2021 The Chromium Authors
Hwanseung Lee56e45ca2021-04-16 14:16:202// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/debug/debugger.h"
6
7#include <lib/zx/process.h>
8#include <stdlib.h>
9#include <unistd.h>
10#include <zircon/process.h>
11#include <zircon/syscalls.h>
12
Hwanseung Lee56e45ca2021-04-16 14:16:2013#include "base/debug/alias.h"
14
Hwanseung Lee56e45ca2021-04-16 14:16:2015namespace base {
16namespace debug {
17
18bool BeingDebugged() {
Joshua Seatonc0e57ccc72021-05-26 18:29:4919 zx_info_process_t info = {};
Hwanseung Lee56e45ca2021-04-16 14:16:2020 // Ignore failures. The 0-initialization above will result in "false" for
21 // error cases.
Peter Kasting134ef9af2024-12-28 02:30:0922 zx::process::self()->get_info(ZX_INFO_PROCESS, &info, sizeof(info), nullptr,
23 nullptr);
Hwanseung Lee56e45ca2021-04-16 14:16:2024 return (info.flags & ZX_INFO_PROCESS_FLAG_DEBUGGER_ATTACHED) != 0;
25}
26
Benoit Lize33a16522021-09-13 20:15:1427void BreakDebuggerAsyncSafe() {
Hwanseung Lee56e45ca2021-04-16 14:16:2028 // NOTE: This code MUST be async-signal safe (it's used by in-process
29 // stack dumping signal handler). NO malloc or stdio is allowed here.
30
31 // Linker's ICF feature may merge this function with other functions with the
32 // same definition (e.g. any function whose sole job is to call abort()) and
33 // it may confuse the crash report processing system. http://crbug.com/508489
34 static int static_variable_to_make_this_function_unique = 0;
35 Alias(&static_variable_to_make_this_function_unique);
36
37 abort();
38}
39
Hwanseung Lee56e45ca2021-04-16 14:16:2040void VerifyDebugger() {}
41
42} // namespace debug
43} // namespace base