Subject: Re: bug#60237: 30.0.50; tree sitter core dumps when I edebug view a node

From: Po Lu <[email-masked]>
Date: Sat, 11 Mar 2023 07:52:40 +0800

Stefan Monnier <[email-masked]> writes:

>>> I tried cargo-culting the cpu_gc_count stuff for the memory profiler,
>>> see the patch below.  However, something is amiss: this assertion in
>>> profiler.el sometimes triggers:
>>>
>>>     (maphash
>>>      (lambda (backtrace _count)
>>>        (let* ((max (1- (length backtrace)))
>>>               (head (aref backtrace max))
>>>               (best-parent nil)
>>>               (best-match (1+ max))
>>>               (parents (gethash head fun-map)))
>>>          (pcase-dolist (`(,i . ,parent) parents)
>>>            (when t ;; (<= (- max i) best-match) ;Else, it can't be better.
>>>              (let ((match max)
>>>                    (imatch i))
>>>                (cl-assert (>= match imatch))  <<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>                (cl-assert (function-equal (aref backtrace max)
>>>                                           (aref parent i)))
>>>
>>> I cannot reliably reproduce this, and don't understand what causes the
>>> assertion.  Any hints?
>>
>> Hmm... I just took a look but can't see neither why your change would
>> be more likely to trigger this error than the existing code for the
>> `cpu` case, nor why this assertion should always be true.
>
> I can imagine corner cases where this could trigger, but they all
> involve funny business where we change `profiler-max-stack-depth` during
> a single profiling run (I think you'd need to write ad-hoc ELisp code
> for that).  The only other explanation I can see is that we
> somehow end up with a backtrace that includes `Automatic_GC` somewhere
> not at the top (maybe this can happen with a `post-gc-hook`?).

What about gc_in_progress? Why can't we use that?
This should avoid everything related to post-gc-hook.

Thanks.