[libcxx-commits] [libcxx] WIP - [libc++][debugging] P2546R5: Debugging support & P2810R4: `is_debugger_present` `is_replaceable` (PR #81447)

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Mon May 20 10:55:02 PDT 2024


================
@@ -0,0 +1,184 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <__assert>
+#include <__config>
+#include <debugging>
+
+#if defined(_LIBCPP_WIN32API)
+#  define WIN32_LEAN_AND_MEAN
+#  define NOMINMAX
+#  include <windows.h>
+#else
+#  include <csignal>
+#endif
+
+#if defined(_AIX)
+#  include <charconv>
+#  include <cstring>
+#  include <fcntl.h>
+#  include <sys/mman.h>
+#  include <sys/proc.h>
+#  include <sys/procfs.h>
+#  include <sys/types.h>
+#  include <unistd.h>
+#elif defined(__APPLE__) || defined(__FreeBSD__)
+#  if defined(__FreeBSD__) // Include order matters.
+#    include <libutil.h>
+#    include <sys/param.h>
+#    include <sys/proc.h>
+#    include <sys/user.h>
+#  endif // defined(__FreeBSD__)
+#  include <array>
+#  include <sys/sysctl.h>
+#  include <sys/types.h>
+#  include <unistd.h>
+#elif defined(__linux__)
+#  include <cstdio>
+#  include <cstdlib>
+#  include <cstring>
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+// `breakpoint()` implementation
+
+_LIBCPP_EXPORTED_FROM_ABI void __breakpoint() noexcept {
+#if defined(_LIBCPP_WIN32API)
+  DebugBreak();
+#else
+  raise(SIGTRAP);
+#endif // defined(_LIBCPP_WIN32API)
+}
+
+// `is_debugger_present()` implementation
+
+#if defined(_LIBCPP_WIN32API)
+
+static bool __is_debugger_present() noexcept { return IsDebuggerPresent(); }
+
+#elif defined(_AIX)
+
+static bool __is_debugger_present() noexcept {
+  // Get the status information of a process by memory mapping the file /proc/PID/status.
+  // https://www.ibm.com/docs/en/aix/7.3?topic=files-proc-file
+  char __filename[] = "/proc/4294967295/status";
+  if (auto [__ptr, __ec] = to_chars(__filename + 6, __filename + 16, getpid()); __ec == errc()) {
----------------
mordante wrote:

For consistency please use qualified names in the dylib.
```suggestion
  if (auto [__ptr, __ec] = std::to_chars(__filename + 6, __filename + 16, getpid()); __ec == errc()) {
```

https://github.com/llvm/llvm-project/pull/81447


More information about the libcxx-commits mailing list