diff src/profile.h @ 4162:8f6a825eb3d3

[xemacs-hg @ 2007-09-04 21:20:18 by aidan] Eliminate a crash when profiling; only pass the backtrace record to profile_record_about_to_call, profile_record_just_called when it's non-nil.
author aidan
date Tue, 04 Sep 2007 21:20:26 +0000
parents 390dee4913ba
children 308d34e9f07d
line wrap: on
line diff
--- a/src/profile.h	Mon Sep 03 21:51:09 2007 +0000
+++ b/src/profile.h	Tue Sep 04 21:20:26 2007 +0000
@@ -47,11 +47,18 @@
    This ensures correct behavior (e.g. we never modify the profiling info
    when profiling is not active) because we seed and reap all functions
    currently on the stack when starting and stopping.  See
-   `start-profiling'. */
+   `start-profiling'.
+
+   We check do_backtrace to make sure that the backtrace structure is
+   initialised. If it isn't, we can enter a function with profiling turned
+   off, and exit it with it turned on, with the consequence that an
+   unitialised backtrace structure is passed to
+   profile_record_just_called. Since do_backtrace is function-local (apart
+   from in the garbage collector) this avoids that.  */
 #define PROFILE_ENTER_FUNCTION()		\
 do						\
 {						\
-  if (profiling_active)				\
+  if (profiling_active && do_backtrace)		\
     profile_record_about_to_call (&backtrace);	\
 }						\
 while (0)
@@ -59,7 +66,7 @@
 #define PROFILE_EXIT_FUNCTION()			\
 do						\
 {						\
-  if (profiling_active)				\
+  if (profiling_active && do_backtrace)		\
     profile_record_just_called (&backtrace);	\
 }						\
 while (0)