debugger_fuchsia.cc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/debug/debugger.h"
  5. #include <lib/zx/process.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <zircon/process.h>
  9. #include <zircon/syscalls.h>
  10. #include "base/debug/alias.h"
  11. namespace base {
  12. namespace debug {
  13. bool BeingDebugged() {
  14. zx_info_process_t info = {};
  15. // Ignore failures. The 0-initialization above will result in "false" for
  16. // error cases.
  17. zx::process::self()->get_info(ZX_INFO_PROCESS, &info, sizeof(info),
  18. nullptr, nullptr);
  19. return (info.flags & ZX_INFO_PROCESS_FLAG_DEBUGGER_ATTACHED) != 0;
  20. }
  21. void BreakDebuggerAsyncSafe() {
  22. // NOTE: This code MUST be async-signal safe (it's used by in-process
  23. // stack dumping signal handler). NO malloc or stdio is allowed here.
  24. // Linker's ICF feature may merge this function with other functions with the
  25. // same definition (e.g. any function whose sole job is to call abort()) and
  26. // it may confuse the crash report processing system. http://crbug.com/508489
  27. static int static_variable_to_make_this_function_unique = 0;
  28. Alias(&static_variable_to_make_this_function_unique);
  29. abort();
  30. }
  31. void VerifyDebugger() {}
  32. } // namespace debug
  33. } // namespace base