debugging 如何在webkit中禁用ASSERT并构建调试模式

lh80um4z  于 2023-05-18  发布在  其他
关注(0)|答案(1)|浏览(147)

启用调试选项时,webkit构建脚本通过将ndebug和ASSERT_ENABLED宏启用为1来自动启用ASSERT。
WebKit/Source/WTF/wtf/Assertions.h

#if !ASSERT_ENABLED

#define ASSERT(assertion, ...) ((void)0)
#define ASSERT_UNDER_CONSTEXPR_CONTEXT(assertion) ((void)0)
#define ASSERT_AT(assertion, file, line, function) ((void)0)
#define ASSERT_NOT_REACHED(...) ((void)0)
#define ASSERT_NOT_REACHED_UNDER_CONSTEXPR_CONTEXT(...) ((void)0)
#define ASSERT_NOT_IMPLEMENTED_YET() ((void)0)
#define ASSERT_IMPLIES(condition, assertion) ((void)0)
#define NO_RETURN_DUE_TO_ASSERT

#define ASSERT_UNUSED(variable, assertion, ...) ((void)variable)

#if ENABLE(SECURITY_ASSERTIONS)
#define ASSERT_WITH_SECURITY_IMPLICATION(assertion) \
    (!(assertion) ? \
        (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion), \
         CRASH_WITH_SECURITY_IMPLICATION()) : \
        (void)0)

#define ASSERT_WITH_SECURITY_IMPLICATION_DISABLED 0
#else /* not ENABLE(SECURITY_ASSERTIONS) */
#define ASSERT_WITH_SECURITY_IMPLICATION(assertion) ((void)0)
#define ASSERT_WITH_SECURITY_IMPLICATION_DISABLED 1
#endif /* ENABLE(SECURITY_ASSERTIONS) */

#else /* ASSERT_ENABLED */

#define ASSERT(assertion, ...) do { \
    if (!(assertion)) { \
        WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion); \
        CRASH_WITH_INFO(__VA_ARGS__); \
    } \
} while (0)

#define ASSERT_UNDER_CONSTEXPR_CONTEXT(assertion) do { \
    if (!(assertion)) { \
        WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion); \
        CRASH_UNDER_CONSTEXPR_CONTEXT(); \
    } \
} while (0)

#define ASSERT_AT(assertion, file, line, function) do { \
    if (!(assertion)) { \
        WTFReportAssertionFailure(file, line, function, #assertion); \
        CRASH(); \
    } \
} while (0)

#define ASSERT_NOT_REACHED(...) do { \
    WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 0); \
    CRASH_WITH_INFO(__VA_ARGS__); \
} while (0)

#define ASSERT_NOT_REACHED_UNDER_CONSTEXPR_CONTEXT(...) do { \
    CRASH_UNDER_CONSTEXPR_CONTEXT(); \
} while (0)

#define ASSERT_NOT_IMPLEMENTED_YET() do { \
    WTFReportNotImplementedYet(__FILE__, __LINE__, WTF_PRETTY_FUNCTION); \
    CRASH(); \
} while (0)

#define ASSERT_IMPLIES(condition, assertion) do { \
    if ((condition) && !(assertion)) { \
        WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #condition " => " #assertion); \
        CRASH(); \
    } \
} while (0)

#define ASSERT_UNUSED(variable, assertion, ...) ASSERT(assertion, __VA_ARGS__)

#define NO_RETURN_DUE_TO_ASSERT NO_RETURN_DUE_TO_CRASH

/* ASSERT_WITH_SECURITY_IMPLICATION
 
   Failure of this assertion indicates a possible security vulnerability.
   Class of vulnerabilities that it tests include bad casts, out of bounds
   accesses, use-after-frees, etc. Please file a bug using the security
   template - https://bugs.webkit.org/enter_bug.cgi?product=Security.
 
*/
#define ASSERT_WITH_SECURITY_IMPLICATION(assertion) \
    (!(assertion) ? \
        (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion), \
         CRASH_WITH_SECURITY_IMPLICATION()) : \
        (void)0)
#define ASSERT_WITH_SECURITY_IMPLICATION_DISABLED 0

#endif /* ASSERT_ENABLED */

我想禁用ASSERT(例如,ASSERT_ENABLED 0)在构建webkit与调试选项。(./Tools/Scripts/build-webkit --debug)特别是,查看webkit makefile中的以下代码,它似乎支持在发布模式下启用assert。

...
release+assert ra:
    @$(build_target_for_each_module)
...

但是,我找不到在调试模式下禁用assert的选项。如何删除Assert?

bogh5gae

bogh5gae1#

我不确定是否有一个简单的方法来做到这一点。
我目前正在做的是在调试模式下构建时应用此修补程序

diff --git a/Source/WTF/wtf/PlatformEnable.h b/Source/WTF/wtf/PlatformEnable.h
index f5f9888057a2..345c854280a6 100644
--- a/Source/WTF/wtf/PlatformEnable.h
+++ b/Source/WTF/wtf/PlatformEnable.h
@@ -65,7 +65,7 @@
 #ifdef NDEBUG
 #define ASSERT_ENABLED 0
 #else
-#define ASSERT_ENABLED 1
+#define ASSERT_ENABLED 0
 #endif
 #endif

也许另一种选择是通过编译器标志传递-DASSERT_ENABLED=0(例如,相应地设置CXXFLAGSCFLAGS环境变量)

相关问题