From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id ADB0D3858C2A for ; Tue, 5 Dec 2023 12:25:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ADB0D3858C2A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ADB0D3858C2A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::32f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701779158; cv=none; b=sH/glk/e+QRQv6E8ikZbSS1xr4moyQ6ij4JVVLHzbdCAhep8z35Ep44RRUw0/HwgFwe+xNEbsRwh7IeQ4yns75ByKgB55aH/E8glgF0upCwfDDutSol7/vVAILXc5qO9ajMlwRqDuS9iKX0bgEJmxkNBdUMO0Nxgc4EgAkPZWO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701779158; c=relaxed/simple; bh=EPstfcoJqu/W58wLuIerUfNznyc8X+V001RFgkTH+Bo=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=kxOeCQcJ/7h1uecKBLgJLwKNhhxK1ZpOPuHUsP3A/ZxNncAlvJcf19+4gtAKD7nQqaWNShXwRor8mD3bB7/Gl42pTHrPKK26lFCHlvhMwSxMYSxHMnwAhOPKyjI+l8v8x4EmON125X0iSd0QloW1PtnRIDI1VmJVEUk1NpGz4Oc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-6d84ddd642fso3041163a34.0 for ; Tue, 05 Dec 2023 04:25:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701779156; x=1702383956; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=OUgXCWGo7Cuq2SAYt2/10TJkXt+8JW2yw6dHAJUhJ3A=; b=fw0JmxdLZbPaNTslPMtM1YvbKupRCT523ajrrepM+qwbP6qFwmBpoZIKseOBfVdzRI q3dpZ6/BkViBi4lbb8yfyd04I7cr4TVlEEr8CLDRHuSf7oDBFBrSRWAkdSoehHDuus7e VyGniQp9ZFhQiiXaJTlMt/OrKrsPArRNC9CekhxbPjRkKE22F7gCxR2qFm8ebUDGQtQU RB35pnE8C8yLC3by7JmsswMNK3cf6+JTqOvQuDeqQE4l7/hidxWbW7EZl8iiR5mWLMnV XLR53+n9u1gW4c5Ln5i/V8C8vW9LCF2Sga0ppqZm/N+zjZ3sgGggqHMTWORpmO1qhc7j P4lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701779156; x=1702383956; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OUgXCWGo7Cuq2SAYt2/10TJkXt+8JW2yw6dHAJUhJ3A=; b=S/iqyjhNnsrWdvN6hAbBseT2voq7y3w+vFN5sf0lQkA1jA/opORQsV02YXc5+bhtZt wIgvcC38avNfe1Z9Yea26hJpIEfrVAxBaUqYTDshweshLdUeWDRsp8AhXshuFV78CE3z VktQbVbouU6TW3qijmFhuvhjM9ufpuMxVOECIMxuZe7PNBmEWpHXz39MArwnJmmUan4k jFSLLDDMHNbBH0NCUfP743H308hcMBdmlgQbmsYGMlueFd08Lfn4vUVKjDOOouVmbJMa fABX9PePK3qXMZvwBrRzlbzxLhV6HTj47Z8Rz8msVhHMhiT99iPuCExHVMeOotYzvNbw rpJg== X-Gm-Message-State: AOJu0YzcFrHAIZH8mohTJSjLyAd8nRHyEeaesONCS5W++V5jlWtmEPhd gtkPZbOTMkp+PDnLk7hIRjxauQpiaJ+tXO479TY= X-Google-Smtp-Source: AGHT+IHfpHCywOshGtobnHrY25pui9wKK/MLjsrkep3CDA/53DJUiCTSccg38h8JrCvHr7SN0kikKLqkw15Orrdc3Qw= X-Received: by 2002:a05:6870:b621:b0:1fb:75c:4016 with SMTP id cm33-20020a056870b62100b001fb075c4016mr6837300oab.118.1701779155728; Tue, 05 Dec 2023 04:25:55 -0800 (PST) MIME-Version: 1.0 References: <8b22544e8e2add89a36eb19120777b6878542291.camel@redhat.com> In-Reply-To: From: Stan Srednyak Date: Tue, 5 Dec 2023 07:25:46 -0500 Message-ID: Subject: Re: Debugging the tree object constructed by cp_parser To: David Malcolm Cc: gcc@gcc.gnu.org Content-Type: multipart/alternative; boundary="000000000000103dd9060bc25641" X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000103dd9060bc25641 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi David, Thanks for your suggestion. I really appreciate it. But I would like to modify the trees as they are constructed. So the first step is to understand how to print them out ( using debug_tree() or even printf()) from inside cp_parser.cc. I think it is a reasonable question: where are the ASTs ( or parts that correspond to translation units, or something smaller) stored as they are constructed by the parser. thanks, sincerely yours, Stan On Mon, Dec 4, 2023 at 10:46=E2=80=AFAM David Malcolm = wrote: > On Mon, 2023-12-04 at 10:09 -0500, Stan Srednyak wrote: > > Hi David, thanks for your email. I really appreciate it. > > > > Your notes are certainly of help, but I also had a specific question: > > how > > to access the trees as they are being constructed by the front end. > > Do you > > have an answer to this? > > You could try putting a breakpoint on "make_node", and then > conditionalizing it so it only fires when code =3D=3D > TRANSLATION_UNIT_DECL: > > (gdb) break make_node > Breakpoint 5 at 0x1675250: file ../../src/gcc/tree.cc, line 1188. > > (gdb) cond 5 code=3D=3DTRANSLATION_UNIT_DECL > > (gdb) run > The program being debugged has been started already. > Start it from the beginning? (y or n) y > > [...snip...] > > Breakpoint 5, make_node (code=3DTRANSLATION_UNIT_DECL) at > ../../src/gcc/tree.cc:1188 > 1188 { > > (gdb) bt > #0 make_node (code=3DTRANSLATION_UNIT_DECL) at > ../../src/gcc/tree.cc:1188 > #1 0x0000000001675aae in build_decl (loc=3D0, > code=3DTRANSLATION_UNIT_DECL, name=3D /tmp/t.c>, type=3D) > at ../../src/gcc/tree.cc:5379 > #2 0x000000000169644c in build_translation_unit_decl (name=3D out>) at ../../src/gcc/tree.cc:5432 > #3 0x0000000000b1e181 in cxx_init_decl_processing () at > ../../src/gcc/tree.h:3749 > #4 0x0000000000b6b904 in cxx_init () at ../../src/gcc/cp/lex.cc:336 > #5 0x0000000000a4e23a in lang_dependent_init (name=3D0x34bd820 > "/tmp/t.c") at ../../src/gcc/toplev.cc:1838 > #6 do_compile () at ../../src/gcc/toplev.cc:2136 > #7 toplev::main (this=3Dthis@entry=3D0x7fffffffdd6e, argc=3D, > argc@entry=3D22, argv=3D, argv@entry=3D0x7fffffffde78) > at ../../src/gcc/toplev.cc:2307 > #8 0x0000000000a502f5 in main (argc=3D22, argv=3D0x7fffffffde78) at > ../../src/gcc/main.cc:39 > > > Dave > > > > > I looked into GCC internals docs. The section on the front end (sec > > 5) is > > wonderfully concise, of course, but it does not answer this question. > > Do > > you know any sources where this is documented? > > > > best regards, > > Stan > > > > On Sun, Dec 3, 2023 at 1:00=E2=80=AFPM David Malcolm > > wrote: > > > > > On Sat, 2023-12-02 at 17:41 -0500, Stan Srednyak via Gcc wrote: > > > > Dear GCC community, > > > > > > > > I am assigned the task to debug the trees as being produced by > > > > the > > > > cp_parser. I was able to print some of the trees using the > > > > debug_tree() > > > > function. But I am still confused as to where is the tree object > > > > that > > > > corresponds to the translation unit being parsed. There is no > > > > such > > > > field in > > > > cp_parser, and in the few tiers of functions calls starting from > > > > parse_file() function that I followed so far, I was not able to > > > > find > > > > any > > > > variable remotely similar to the AST of functions/structs etc. > > > > that > > > > must be > > > > constructed by this great piece of software. I would very much > > > > appreciate > > > > any explanation from the great experts in gcc on this mailing > > > > list. I > > > > posted a thread at gcc-help, but apparently it is too obvious of > > > > a > > > > question > > > > to be addressed there. > > > > > > Hi Stan > > > > > > FWIW I've written some notes on debugging GCC: > > > https://gcc-newbies-guide.readthedocs.io/en/latest/debugging.html > > > > > > and in particular you might find the following useful: > > > > > > > https://gcc-newbies-guide.readthedocs.io/en/latest/debugging.html#how-do-= i-find-where-a-particular-tree-was-created > > > > > > Hope this is helpful > > > Dave > > > > > > > > --000000000000103dd9060bc25641--