Put tint::debugger::Break() behind a build flag

Breaking isn't always desirable, as there are many tests that intentionally trigger ICEs, which are caught by a EXPECT_DEATH().

On Linux the break also performs IO, which will likely cause problems in Chromium's sandboxed environment.

Change-Id: Ic2e1f5d13c9e986c066eaf364ffa5759c7299f6a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/81103
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2022-02-18 18:56:43 +00:00 committed by Tint LUCI CQ
parent 16446e5b74
commit 1c6c6b19ab
4 changed files with 19 additions and 4 deletions

View File

@ -92,6 +92,8 @@ option_if_not_defined(TINT_ENABLE_MSAN "Enable memory sanitizer" OFF)
option_if_not_defined(TINT_ENABLE_ASAN "Enable address sanitizer" OFF) option_if_not_defined(TINT_ENABLE_ASAN "Enable address sanitizer" OFF)
option_if_not_defined(TINT_ENABLE_UBSAN "Enable undefined behaviour sanitizer" OFF) option_if_not_defined(TINT_ENABLE_UBSAN "Enable undefined behaviour sanitizer" OFF)
option_if_not_defined(TINT_ENABLE_BREAK_IN_DEBUGGER "Enable tint::debugger::Break()" OFF)
option_if_not_defined(TINT_EMIT_COVERAGE "Emit code coverage information" OFF) option_if_not_defined(TINT_EMIT_COVERAGE "Emit code coverage information" OFF)
option_if_not_defined(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF) option_if_not_defined(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF)

View File

@ -53,6 +53,11 @@ add_library(tint_diagnostic_utils
) )
tint_default_compile_options(tint_diagnostic_utils) tint_default_compile_options(tint_diagnostic_utils)
if (TINT_ENABLE_BREAK_IN_DEBUGGER)
set_source_files_properties(utils/debugger.cc
PROPERTIES COMPILE_DEFINITIONS "TINT_ENABLE_BREAK_IN_DEBUGGER=1" )
endif()
set(TINT_LIB_SRCS set(TINT_LIB_SRCS
../include/tint/tint.h ../include/tint/tint.h
ast/access.cc ast/access.cc

View File

@ -14,6 +14,8 @@
#include "src/utils/debugger.h" #include "src/utils/debugger.h"
#ifdef TINT_ENABLE_BREAK_IN_DEBUGGER
#ifdef _MSC_VER #ifdef _MSC_VER
#include <Windows.h> #include <Windows.h>
#elif defined(__linux__) #elif defined(__linux__)
@ -23,7 +25,7 @@
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
#define TINT_DEBUGGER_BREAK_DEFINED
void tint::debugger::Break() { void tint::debugger::Break() {
if (::IsDebuggerPresent()) { if (::IsDebuggerPresent()) {
::DebugBreak(); ::DebugBreak();
@ -32,6 +34,7 @@ void tint::debugger::Break() {
#elif defined(__linux__) #elif defined(__linux__)
#define TINT_DEBUGGER_BREAK_DEFINED
void tint::debugger::Break() { void tint::debugger::Break() {
// A process is being traced (debugged) if "/proc/self/status" contains a // A process is being traced (debugged) if "/proc/self/status" contains a
// line with "TracerPid: <non-zero-digit>...". // line with "TracerPid: <non-zero-digit>...".
@ -51,9 +54,10 @@ void tint::debugger::Break() {
raise(SIGTRAP); raise(SIGTRAP);
} }
} }
#endif // platform
#else #endif // TINT_ENABLE_BREAK_IN_DEBUGGER
#ifndef TINT_DEBUGGER_BREAK_DEFINED
void tint::debugger::Break() {} void tint::debugger::Break() {}
#endif #endif

View File

@ -16,8 +16,12 @@
#define SRC_UTILS_DEBUGGER_H_ #define SRC_UTILS_DEBUGGER_H_
namespace tint::debugger { namespace tint::debugger {
/// If debugger is attached, will break into it at the call site.
/// If debugger is attached and the `TINT_ENABLE_BREAK_IN_DEBUGGER` preprocessor
/// macro is defined for `debugger.cc`, calling `Break()` will cause the
/// debugger to break at the call site.
void Break(); void Break();
} // namespace tint::debugger } // namespace tint::debugger
#endif // SRC_UTILS_DEBUGGER_H_ #endif // SRC_UTILS_DEBUGGER_H_