BusyJay commented on code in PR #2890:
URL: https://github.com/apache/brpc/pull/2890#discussion_r2019798542


##########
docs/cn/sanitizers.md:
##########
@@ -0,0 +1,32 @@
+# Sanitizers
+
+新版本的GCC/Clang支持[sanitizers](https://github.com/google/sanitizers),方便开发者排查代码中的bug。
 bRPC对sanitizers提供了一定的支持。
+
+## AddressSanitizer(ASan)
+
+ASan提供了[对协程的支持](https://reviews.llvm.org/D20913)。 
在bthread创建、切换、销毁时,让ASan知道当前bthread的栈信息,主要用于维护[fake 
stack](https://github.com/google/sanitizers/wiki/AddressSanitizerUseAfterReturn)。
+
+bRPC中启用ASan的方法:给config_brpc.sh增加`--with-glog`选项、给cmake增加`-DWITH_GLOG=ON`选项或者给bazel增加`--define
 with_asan=true`选项。

Review Comment:
   s/-DWITH_GLOG/-DWITH_ASAN/



##########
src/bthread/task_group.cpp:
##########
@@ -657,7 +715,11 @@ void TaskGroup::sched_to(TaskGroup** pg, TaskMeta* 
next_meta) {
                 g->_control->_task_tracer.set_status(TASK_STATUS_JUMPING, 
cur_meta);
                 g->_control->_task_tracer.set_status(TASK_STATUS_JUMPING, 
next_meta);
 #endif // BRPC_BTHREAD_TRACER
-                jump_stack(cur_meta->stack, next_meta->stack);
+                {
+                    BTHREAD_SCOPED_ASAN_FIBER_SWITCHER(
+                        cur_meta->stack->storage, cur_ending);

Review Comment:
   根据这里的文档,传的参数应该是 next_meta->stack->storage 吧。
   
   
https://github.com/gcc-mirror/gcc/blob/9018336252463ffed28f01badfdea2a3ca3ba5c8/libsanitizer/include/sanitizer/common_interface_defs.h#L437-L466



##########
src/bthread/task_group.cpp:
##########
@@ -255,6 +297,15 @@ int TaskGroup::init(size_t runqueue_capacity) {
     return 0;
 }
 
+#ifdef BUTIL_USE_ASAN
+void TaskGroup::asan_task_runner(intptr_t) {
+    // This is a new thread, and it doesn't have the fake stack yet. ASan will
+    // create it lazily, for now just pass NULL.
+    internal::FinishSwitchFiber(NULL);

Review Comment:
   不是应该产生了 fiber 切换才调用 finish 吗?换言之,finish 和 start 应该是成对出现的?调用一次 start 对应调用一次 
finish。



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to