All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Carter <jwcart2@gmail.com>
To: selinux@vger.kernel.org
Cc: nicolas.iooss@m4x.org, James Carter <jwcart2@gmail.com>
Subject: [PATCH 0/3 v3] Create secil2tree to write CIL AST
Date: Wed, 21 Apr 2021 13:21:09 -0400	[thread overview]
Message-ID: <20210421172112.13277-1-jwcart2@gmail.com> (raw)

For debugging purposes it would be useful to be able to write out
the CIL AST at various points in the build process.

This patch set creates secil2tree which can write the CIL parse tree,
the CIL AST after the build phase, or the CIL AST after the resolve
phase (with names fully-qualified).

Within CIL the function cil_print_tree() has existed from early in
CIL's development, but it was not exported in libsepol and there was no
way to use it except by adding a call to it where you wanted to print
out the CIL AST and then recompiling everything. It also used cil_log()
as its output, so other messages could be mixed in with the output. This
patch set moves all of this code to its own file, updates it, renames it
as cil_write_ast(), and adds libsepol functions that can be used to call
it after each one of the phases mentioned above.

Both the parse and build CIL AST are valid CIL policies that can be
compiled with secilc, but the resolve CIL AST is not always a valid CIL
policy. The biggest problem is that fully-qualified names can contain
dots and CIL does not allow dots in declaration names. There are other
problems as well. It would be nice to get to the point where the output
for all of the trees are valid CIL, but that is a goal for the future.

v3:
- -use "-ast-phase=<phase>" in the usage message and man pages instead
of "-ast-phase <phase>"

v2:
- Remove whitespace errors in cil_write_ast.h
- Use "const char*" instead of just "char*" when dealing with string
literals to satisfy clang.

James Carter (3):
  libsepol/cil: Create functions to write the CIL AST
  libsepol/cil: Add functions to make use of cil_write_ast()
  secilc: Create the new program called secil2tree to write out CIL AST

 libsepol/cil/include/cil/cil.h   |    3 +
 libsepol/cil/src/cil.c           |   92 ++
 libsepol/cil/src/cil_tree.c      | 1471 ----------------------------
 libsepol/cil/src/cil_tree.h      |    2 -
 libsepol/cil/src/cil_write_ast.c | 1573 ++++++++++++++++++++++++++++++
 libsepol/cil/src/cil_write_ast.h |   46 +
 libsepol/src/libsepol.map.in     |    3 +
 secilc/.gitignore                |    2 +
 secilc/Makefile                  |   20 +-
 secilc/secil2tree.8.xml          |   81 ++
 secilc/secil2tree.c              |  206 ++++
 11 files changed, 2024 insertions(+), 1475 deletions(-)
 create mode 100644 libsepol/cil/src/cil_write_ast.c
 create mode 100644 libsepol/cil/src/cil_write_ast.h
 create mode 100644 secilc/secil2tree.8.xml
 create mode 100644 secilc/secil2tree.c

-- 
2.26.3


             reply	other threads:[~2021-04-21 17:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-21 17:21 James Carter [this message]
2021-04-21 17:21 ` [PATCH 1/3 v3] libsepol/cil: Create functions to write the CIL AST James Carter
2021-04-21 17:21 ` [PATCH 2/3 v3] libsepol/cil: Add functions to make use of cil_write_ast() James Carter
2021-04-21 17:21 ` [PATCH 3/3 v3] secilc: Create the new program called secil2tree to write out CIL AST James Carter
2021-04-21 21:01 ` [PATCH 0/3 v3] Create secil2tree to write " Nicolas Iooss
2021-04-22 19:11   ` Nicolas Iooss

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210421172112.13277-1-jwcart2@gmail.com \
    --to=jwcart2@gmail.com \
    --cc=nicolas.iooss@m4x.org \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.