导读:Apache Doris 使用 C++ 语言实现了执行引擎,C++ 开发过程中,影响开发效率的一个重要因素是指针的使用,包括非法访问、泄露、强制类型转换等。本文将会通过对 Sanitizer 和 Core Dump 分析工具的介绍来为大家分享:如何快速定位 Apache Doris 中的 C++ 问题,帮助开发者提升开发效率并掌握更高效的开发技巧。
二者的对比可以参考:https://developers.redhat.com/blog/2021/05/05/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind其中 Valgrind 通过运行时软件翻译二进制指令的执行获取相关的信息,所以 Valgrind 会非常大幅度的降低程序性能,这就导致在一些大型项目比如 Apache Doris 使用 Valgrind 定位内存问题效率会很低。
Sanitizer 的算法可以参考:https://github.com/google/sanitizers/wiki/AddressSanitizerAlgorithm在 Apache Doris 中,我们通常使用 Sanirizer 来定位内存问题。LLVM 以及 GNU C++ 有多个 Sanitizer:
可以参考此处使用 Sanitizer:https://github.com/apache/doris/blob/master/be/CMakeLists.txtSanitizer 和 Core Dump 配合定位问题非常高效,默认 Sanitizer 不生成 Core Dump 文件,可以使用如下环境变量生成 Core Dump文件,建议默认打开。
可以参考:https://github.com/apache/doris/blob/master/bin/start_be.sh
说明:限于文章篇幅,示例中的栈展示不全,完整代码栈可以前往对应 Issue 中进行查看。heap buffer overflow
https://github.com/apache/doris/issues/10926异常分配
https://github.com/apache/doris/pull/3326
Fix PR 见:https://github.com/apache/doris/pull/10289UBSan 能够高效发现强制类型转换的错误,如下方 Issue 链接中描述,它能够精确的描述出强制类型转换带来错误的代码,如果不能在第一现场发现这种错误,后续因为指针错误使用,会比较难定位。
Issue:https://github.com/apache/doris/issues/9105UndefinedBehaviorSanitizer 也比 AddressSanitizer 及其它的更容易发现死锁。
比如:https://github.com/apache/doris/issues/10309程序维护内存 Pool 时 AddressSanitizer 的使用
可以参考:https://github.com/apache/doris/pull/8148当程序维护自己的内存池时,按照 https://github.com/apache/dorisw/pull/8148 中方法,use after free 错误会变成 use after poison。但是 use after poison 不能够给出地址失效的栈(https://github.com/google/sanitizers/issues/191),从而导致问题的定位分析仍然很困难。
可以参考:https://github.com/ruediger/Boost-Pretty-Printer总结
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) | Powered by Discuz! X3.4 |