From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#60237: 30.0.50; tree sitter core dumps when I edebug view a node Date: Sun, 26 Feb 2023 08:14:00 +0200 Message-ID: <83mt51j6mv.fsf@gnu.org> References: <9FCDA5B7-D216-45B1-8051-35B05633BEFB@gmail.com> <83sfeukwsb.fsf@gnu.org> <574817C4-3FD8-43EA-B53C-B2BCB60A6D0A@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1230"; mail-complaints-to="usenet@ciao.gmane.io" Cc: luangruo@yahoo.com, mickey@masteringemacs.org, 60237@debbugs.gnu.org To: Yuan Fu , Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 26 07:15:20 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pWAJc-0000Ae-O6 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 26 Feb 2023 07:15:20 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pWAJP-0001Fr-C8; Sun, 26 Feb 2023 01:15:07 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pWAJK-0001FY-Ot for bug-gnu-emacs@gnu.org; Sun, 26 Feb 2023 01:15:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pWAJK-00017S-3W for bug-gnu-emacs@gnu.org; Sun, 26 Feb 2023 01:15:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pWAJJ-0001Sl-QO for bug-gnu-emacs@gnu.org; Sun, 26 Feb 2023 01:15:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 26 Feb 2023 06:15:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60237 X-GNU-PR-Package: emacs Original-Received: via spool by 60237-submit@debbugs.gnu.org id=B60237.16773920445533 (code B ref 60237); Sun, 26 Feb 2023 06:15:01 +0000 Original-Received: (at 60237) by debbugs.gnu.org; 26 Feb 2023 06:14:04 +0000 Original-Received: from localhost ([127.0.0.1]:42186 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pWAIO-0001RB-6o for submit@debbugs.gnu.org; Sun, 26 Feb 2023 01:14:04 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:60506) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pWAIM-0001Qa-IA for 60237@debbugs.gnu.org; Sun, 26 Feb 2023 01:14:03 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pWAIG-00012B-Vn; Sun, 26 Feb 2023 01:13:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=GXMlQAhlTZm2i5DbCG7ITZqSuiJtKhxmg/e01hHT+uU=; b=f5NhsHgKhORWyEklhoRW JVi7AQhZRfEeb1fLjginTb+qOo9no4xO4KorRnFUdS9jVlzirPm/KAToh+m0a6SOJgAxak7dnq5Rj ebM4mwodWYdg12Wk8Zyo3ablMl5ARHTyGLdG7ePS6Q4CPqN6zE1UryQMlsIEGRWm71PpjNaA8MwPF zd6R7igVMlEF52UKhvXZS3+pweg/17klx1H7DUeQfohIN+cGpC5FpYLlhC7q5LJ0EZFb2wcgiFzDC lmh7bSFDDxvZ6mxpxcj13YrXmgkpT9MI5eBINnFN3BG1gRv0fz5svl+KANx/GsVgiekNNuHTrImxq lR0rXa0hP1xz2Q==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pWAIG-0006bX-Cd; Sun, 26 Feb 2023 01:13:56 -0500 In-Reply-To: <574817C4-3FD8-43EA-B53C-B2BCB60A6D0A@gmail.com> (message from Yuan Fu on Sat, 25 Feb 2023 18:01:07 -0800) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:256768 Archived-At: > From: Yuan Fu > Date: Sat, 25 Feb 2023 18:01:07 -0800 > Cc: Mickey Petersen , > 60237@debbugs.gnu.org, > Po Lu > > > GC has historically never called xmalloc, so the profiler will likely > > crash upon growing the mark stack as well. I guess another important > > question is why ts_delete_parser is calling xmalloc. > > > As you see, when we call ts_tree_delete, it calls ts_subtree_release, > > which in turn calls malloc (redirected into our xmalloc). Is this > > expected? Can you look in the tree-sitter sources and verify that > > this is OK? > > I had a look, and it seems legit. In tree-sitter, a TSTree (or more precisely, a Subtree) is just some inlined data plus a refcounted pointer to the complete data. This way multiple trees share common subtrees/nodes. Eg, when incrementally parsing, you pass in an old tree and get a new tree, these two trees will share the unchanged part of the tree. > > Therefore, deleting a tree is not simply free(). Instead, you decrement the refcount of the subtree, and if the count == 0, free the data and traverse the subtree and decrementing each children’s refcount, and delete them if the count == 0, and so on. To traverse the tree, the function uses an array as a stack, which calls array_push to push new elements, which may call malloc. Stefan, could it be a problem for us if garbage-collecting an object calls xmalloc? Including if the "memory" profiler is running at the time of that GC?