Changeset 267b543


Ignore:
Timestamp:
Jan 13, 2025, 1:03:07 PM (7 days ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
6a6e205
Parents:
9b9d3f9
Message:

Add basic gdb navigation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/dev/getting-started.md

    r9b9d3f9 r267b543  
    2727-----------------
    2828
    29 Read and do the instructions in cfa-cc/INSTALL, to get a working CFA compiler built from source.
     29Read and do the instructions in cfa-cc/INSTALL, to get a working CFA compiler built from source.  Many members of the core team do this (and much general work) on plg2.
    3030
    3131The program `cfa` is the driver, which acts like a command-line stand-in to the `gcc` command.  Its source starts from cfa-cc/src/driver/cfa.cc.
     
    3333The driver runs `cfa-cpp`, which is the actual Cforall to C transpiler, while cfa is a wrapper command which runs the preprocessor, cfa-cc, and then the rest of the gcc compilation chain. The `cfa-cpp` source code starts from cfa-cc/src/main.cpp.
    3434
    35 Most CFA programs rely on `libcfa`, the CFA core runtime library.  Its source is in cfa-cc/libcfa/src.  It gets compiled while building CFA.  Your test programs link with it.
     35Most CFA programs rely on `libcfa`, the CFA core runtime library.  Its source is in `cfa-cc/libcfa/src`.  It gets compiled while building CFA, into `(where-ran-configure)/libcfa/x64-debug/src/.libs/libcfa.so` and `libcfathread.so`.  Your test programs link with it.
    3636
    37 Most CFA programs rely on "the prelude", which is a collection of headers that your test programs implicitly import.  Its source is in cfa-cc/libcfa/prelude.  It gets preprocessed while building CFA, and the result is compiled within your test programs.
     37Most CFA programs rely on "the prelude", which is a collection of headers that your test programs implicitly import.  Its source is in cfa-cc/libcfa/prelude.  It gets preprocessed while building CFA into `(where-ran-configure)/libcfa/x64-debug/prelude`, which is is compiled within your test programs.
    3838
    39 A variety of example CFA programs is available in cfa-cc/tests/**/*.cfa.  They compile and run in a test-suite invocation as described in cfa-cf/INSTALL, as occurs under a Jenkins build, or as some prefer to run manually:
     39A variety of example CFA programs is available in cfa-cc/tests/**/*.cfa.  They compile and run in a test-suite invocation as described in cfa-cc/INSTALL, as occurs under a Jenkins build, or as some prefer to run manually:
    4040    pwd # assert in a build folder
    4141    ./tests/test.py --all -j8
    4242    ./tests/test.py exceptions/hotpotato # just one test
    43       # cfa-cc/tests/exceptions/hotpotato.cfa: source code
    44       # cfa-cc/tests/exceptions/.expect/hotpotato.txt: running its ./a.out should print this
     43    # see cfa-cc/tests/exceptions/hotpotato.cfa: source code
     44    # see cfa-cc/tests/exceptions/.expect/hotpotato.txt: running its ./a.out should print this
    4545
    4646Manual full test-program compilation, broken into stages:
     
    4848    cfa test.cfa -CFA > test.lowered.c
    4949    gcc -c test.lowered.c
    50     cfa test.lowered.o  # have us do the linking, to get libcfa
     50    cfa test.lowered.o  # link via our driver, to get libcfa
    5151    ./a.out
    5252
    53 Lowering step, abbreviated to be readable:
     53Lowering step, abbreviated to be more readable:
    5454
    5555    cfa test.cfa -CFA -XCFA,-p
     
    7070    gdb -args ./build/driver/cfa-cpp test.preprocessed.cfa -p --prelude-dir ./build/libcfa/x64-debug/prelude
    7171
    72 Debugging the cfa-cpp program is most productive in a configuration purpose-build for it.  (Whereas, working on libcfa changes is more productive in a cfa-cc/INSTALL "vanilla" configuration.)  An example of creating such a configuration, and repeating the above gdb invoation within this configuration (again, in the side-by-side style):
     72Debugging the cfa-cpp program is most productive in a "debug" configuration.  (Whereas working on libcfa changes is more productive in a cfa-cc/INSTALL "vanilla" configuration.)  An example of creating such a configuration, repeating the above gdb invocation within this configuration, and doing a basic tour of cfa-cpp data structures:
    7373
    7474    mkdir build-gdb
    7575    cd build-gdb
    7676    ../cfa-cc/configure --with-target-hosts=host:debug CXXFLAGS='-O0 -g'
     77    make -j8
    7778    gdb -args ./driver/cfa-cpp ../test.preprocessed.cfa -p --prelude-dir ./libcfa/x64-debug/prelude
     79   
     80    b ResolvExpr::resolve
     81    run
     82    # stopped at breakpoint
     83    fini
     84    # in main, at the "rough halfway point" of -Pexpranly
     85    p transUnit.decls.size()                                    # top-level: preulde+includes+yours
     86    set $lastDecl = transUnit.decls.back().get()                # probably from your code: main?
     87    call CodeGen::generate( $lastDecl, std::cerr )              # like -XCFA,-Pexpranly,-Pascodegen
     88    call ast::print( std::cerr, $lastDecl, (Indenter){0,2} )    # like -XCFA,-Pexpranly
     89   
     90    # assuming $lastDecl is your program main, with argc/argv declared ...
     91    p *$lastDecl                                                # assert an ast::FunctionDecl
     92    p  ((ast::FunctionDecl*)$lastDecl)->params.size()           # assert 2
     93    set $argc_d = ((ast::FunctionDecl*)$lastDecl)->params[0].get()
     94    call CodeGen::generate( $argc_d, std::cerr )
     95    call ast::print( std::cerr, $argc_d, (Indenter){0,2} )
     96   
     97    # digging into argv gives sense of AST's granularity, utility of `call print` over dig-cast-`p`
     98    set $argv_d = ((ast::FunctionDecl*)$lastDecl)->params[1].get()
     99    call ast::print( std::cerr, $argv_d, (Indenter){0,2} )
     100    p *$argv_d                                                  # assert an ast::ObjectDecl
     101    set $argv_t0 = ((ast::ObjectDecl*)$argv_d)->type.get()
     102    p *$argv_t0                                                 # assert an ast::PointerType
     103    set $argv_t1 = ((ast::PointerType*)$argv_t0)->base.get()
     104    p *$argv_t1                                                 # assert an ast::PointerType
     105    set $argv_t2 = ((ast::PointerType*)$argv_t1)->base.get()
     106    p *$argv_t2                                                 # assert an ast::BasicType
     107    p ((ast::BasicType*)$argv_t2)->kind                         # assert ast::Char
Note: See TracChangeset for help on using the changeset viewer.