public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Debugging the tree object constructed by cp_parser
@ 2023-12-02 22:41 Stan Srednyak
  2023-12-03 18:00 ` David Malcolm
  0 siblings, 1 reply; 5+ messages in thread
From: Stan Srednyak @ 2023-12-02 22:41 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 815 bytes --]

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.

Thanks in advance,
sincerely yours,

Stan Srednyak

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Debugging the tree object constructed by cp_parser
  2023-12-02 22:41 Debugging the tree object constructed by cp_parser Stan Srednyak
@ 2023-12-03 18:00 ` David Malcolm
  2023-12-04 15:09   ` Stan Srednyak
  0 siblings, 1 reply; 5+ messages in thread
From: David Malcolm @ 2023-12-03 18:00 UTC (permalink / raw)
  To: Stan Srednyak, gcc

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Debugging the tree object constructed by cp_parser
  2023-12-03 18:00 ` David Malcolm
@ 2023-12-04 15:09   ` Stan Srednyak
  2023-12-04 15:45     ` David Malcolm
  0 siblings, 1 reply; 5+ messages in thread
From: Stan Srednyak @ 2023-12-04 15:09 UTC (permalink / raw)
  To: David Malcolm; +Cc: gcc

[-- Attachment #1: Type: text/plain, Size: 1824 bytes --]

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?

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 PM David Malcolm <dmalcolm@redhat.com> 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
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Debugging the tree object constructed by cp_parser
  2023-12-04 15:09   ` Stan Srednyak
@ 2023-12-04 15:45     ` David Malcolm
  2023-12-05 12:25       ` Stan Srednyak
  0 siblings, 1 reply; 5+ messages in thread
From: David Malcolm @ 2023-12-04 15:45 UTC (permalink / raw)
  To: Stan Srednyak; +Cc: gcc

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 ==
TRANSLATION_UNIT_DECL:

(gdb) break make_node
Breakpoint 5 at 0x1675250: file ../../src/gcc/tree.cc, line 1188.

(gdb) cond 5 code==TRANSLATION_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=TRANSLATION_UNIT_DECL) at
../../src/gcc/tree.cc:1188
1188	{

(gdb) bt
#0  make_node (code=TRANSLATION_UNIT_DECL) at
../../src/gcc/tree.cc:1188
#1  0x0000000001675aae in build_decl (loc=0,
code=TRANSLATION_UNIT_DECL, name=<identifier_node 0x7fffea664b00
/tmp/t.c>, type=<tree 0x0>)
    at ../../src/gcc/tree.cc:5379
#2  0x000000000169644c in build_translation_unit_decl (name=<optimized
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=0x34bd820
"/tmp/t.c") at ../../src/gcc/toplev.cc:1838
#6  do_compile () at ../../src/gcc/toplev.cc:2136
#7  toplev::main (this=this@entry=0x7fffffffdd6e, argc=<optimized out>,
argc@entry=22, argv=<optimized out>, argv@entry=0x7fffffffde78)
    at ../../src/gcc/toplev.cc:2307
#8  0x0000000000a502f5 in main (argc=22, argv=0x7fffffffde78) 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 PM David Malcolm <dmalcolm@redhat.com>
> 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
> > 
> > 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Debugging the tree object constructed by cp_parser
  2023-12-04 15:45     ` David Malcolm
@ 2023-12-05 12:25       ` Stan Srednyak
  0 siblings, 0 replies; 5+ messages in thread
From: Stan Srednyak @ 2023-12-05 12:25 UTC (permalink / raw)
  To: David Malcolm; +Cc: gcc

[-- Attachment #1: Type: text/plain, Size: 4260 bytes --]

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 AM David Malcolm <dmalcolm@redhat.com> 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 ==
> TRANSLATION_UNIT_DECL:
>
> (gdb) break make_node
> Breakpoint 5 at 0x1675250: file ../../src/gcc/tree.cc, line 1188.
>
> (gdb) cond 5 code==TRANSLATION_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=TRANSLATION_UNIT_DECL) at
> ../../src/gcc/tree.cc:1188
> 1188    {
>
> (gdb) bt
> #0  make_node (code=TRANSLATION_UNIT_DECL) at
> ../../src/gcc/tree.cc:1188
> #1  0x0000000001675aae in build_decl (loc=0,
> code=TRANSLATION_UNIT_DECL, name=<identifier_node 0x7fffea664b00
> /tmp/t.c>, type=<tree 0x0>)
>     at ../../src/gcc/tree.cc:5379
> #2  0x000000000169644c in build_translation_unit_decl (name=<optimized
> 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=0x34bd820
> "/tmp/t.c") at ../../src/gcc/toplev.cc:1838
> #6  do_compile () at ../../src/gcc/toplev.cc:2136
> #7  toplev::main (this=this@entry=0x7fffffffdd6e, argc=<optimized out>,
> argc@entry=22, argv=<optimized out>, argv@entry=0x7fffffffde78)
>     at ../../src/gcc/toplev.cc:2307
> #8  0x0000000000a502f5 in main (argc=22, argv=0x7fffffffde78) 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 PM David Malcolm <dmalcolm@redhat.com>
> > 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
> > >
> > >
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-12-05 12:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-02 22:41 Debugging the tree object constructed by cp_parser Stan Srednyak
2023-12-03 18:00 ` David Malcolm
2023-12-04 15:09   ` Stan Srednyak
2023-12-04 15:45     ` David Malcolm
2023-12-05 12:25       ` Stan Srednyak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).