From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#60237: 30.0.50; tree sitter core dumps when I edebug view a node Date: Sat, 25 Feb 2023 18:01:07 -0800 Message-ID: <574817C4-3FD8-43EA-B53C-B2BCB60A6D0A@gmail.com> References: <9FCDA5B7-D216-45B1-8051-35B05633BEFB@gmail.com> <83sfeukwsb.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.400.51.1.1\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5100"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Po Lu , Mickey Petersen , 60237@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 26 03:02:16 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 1pW6Mh-00014C-1p for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 26 Feb 2023 03:02:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pW6Ma-0007d0-Sr; Sat, 25 Feb 2023 21:02:08 -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 1pW6MV-0007b6-OJ for bug-gnu-emacs@gnu.org; Sat, 25 Feb 2023 21:02: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 1pW6MT-0003hq-No for bug-gnu-emacs@gnu.org; Sat, 25 Feb 2023 21:02:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pW6MT-0000od-If for bug-gnu-emacs@gnu.org; Sat, 25 Feb 2023 21:02:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 26 Feb 2023 02:02: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.16773768873086 (code B ref 60237); Sun, 26 Feb 2023 02:02:01 +0000 Original-Received: (at 60237) by debbugs.gnu.org; 26 Feb 2023 02:01:27 +0000 Original-Received: from localhost ([127.0.0.1]:41981 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pW6Lu-0000ni-Vj for submit@debbugs.gnu.org; Sat, 25 Feb 2023 21:01:27 -0500 Original-Received: from mail-pl1-f182.google.com ([209.85.214.182]:40635) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pW6Lt-0000nQ-H2 for 60237@debbugs.gnu.org; Sat, 25 Feb 2023 21:01:25 -0500 Original-Received: by mail-pl1-f182.google.com with SMTP id u14so3393732ple.7 for <60237@debbugs.gnu.org>; Sat, 25 Feb 2023 18:01:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=gs6cJGvJITHHOeNTE4ys82ogQBOC6RMcYIzCo76NfAo=; b=YZR499Q6T6+t9Y8LTiml8crkTiMSblKPNLQi920jx0atU7QdQqvFfKxdUi+WXGla2I V/40PTh7PBgHsCDJgHJtx+wc0d/ZURPletGP0nOZziFJ0Ibk5RTfqGh0e16qfVkdnKMr +HTqH8ay2ExfDC/7mGJBXJllDynKAXLG4y/nGqZCB7/LZyEZeOvqewlpYqBrxHoniuPd 9aG/j9jFpoUNUi4ZvsHj/7oei3K7VRa7/MvhHGQF2EUqrfwb8IlmD9+NLiG9Jn0R/XBt 1m71egzDgdYIyyVPtCuM2SJN8SVMh/iHeCz/jnxj9OPE/Wxgz9BijcJGfMejn3K00f36 g5DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gs6cJGvJITHHOeNTE4ys82ogQBOC6RMcYIzCo76NfAo=; b=mXQuFn4ACtbtBfTKTPBo57kI8bdx8vIDfnPP9VcV2gnFBHeDTcbFDf+1JORCm1b2lQ R85jeojOqAl8EqVAsrUwiJowmjEWjlIref2AzHQO1VlOlV+aWTqFaHnY81x+Xref+irq W8i6OVY/W45hjSN6kej5hbLKAl93K52ouag/xXSkT/+ePuDIk6npwFfC2KiXQsRPLlG0 tLg8dXeeJ/mhBVZJmxlmcCErtvL/XORHw+qOjsxJhmEAxWSMpbt55EQqlVpPwhAZhM6r IHhJmvcTxCyq/jmPJ64Q98+l3nnyqz9HSAAbwW0Rfbcz525TQjQWleyP5/RHJlXXJjQY Vd9g== X-Gm-Message-State: AO0yUKUn9vHnGM+gby5u8IBCvpWwEgggOhPpgILnLtsMjecKmb33+LDA 4Oubn9UYaiernzLfDYxqm1o= X-Google-Smtp-Source: AK7set8pWSdWTOWSO54i4klqQChS1xzImIs6IDlpcK1DSLB0AtdArRu7lIxHcUHB5lDwtvD1atNwbg== X-Received: by 2002:a17:902:eccc:b0:19c:eda7:e0fd with SMTP id a12-20020a170902eccc00b0019ceda7e0fdmr4117019plh.59.1677376879570; Sat, 25 Feb 2023 18:01:19 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id e5-20020a170902b78500b0019c922911a2sm1850880pls.40.2023.02.25.18.01.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Feb 2023 18:01:19 -0800 (PST) In-Reply-To: <83sfeukwsb.fsf@gnu.org> X-Mailer: Apple Mail (2.3731.400.51.1.1) 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:256757 Archived-At: > 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. >=20 > 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.=20 Therefore, deleting a tree is not simply free(). Instead, you decrement = the refcount of the subtree, and if the count =3D=3D 0, free the data = and traverse the subtree and decrementing each children=E2=80=99s = refcount, and delete them if the count =3D=3D 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. Yuan=