All of lore.kernel.org
 help / color / mirror / Atom feed
From: Karl MacMillan <kmacmillan@mentalrootkit.com>
To: SELinux Mail List <selinux@tycho.nsa.gov>
Subject: [PATCH] sepolgen: optionally generate debugging information during parsing
Date: Thu, 22 Feb 2007 17:23:35 -0500	[thread overview]
Message-ID: <45DE17E7.1070000@mentalrootkit.com> (raw)

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

This patch allows a caller to request the output of debugging 
information from the parser. This is mainly useful for development / 
debugging of the parser.

Signed-off-by: Karl MacMillan <kmacmillan@mentalrootkit.com>

[-- Attachment #2: sepolgen-parser-debug.diff --]
[-- Type: text/x-patch, Size: 2335 bytes --]

diff -r af054201710a sepolgen/src/sepolgen/refparser.py
--- a/sepolgen/src/sepolgen/refparser.py	Thu Feb 22 15:42:47 2007 -0500
+++ b/sepolgen/src/sepolgen/refparser.py	Thu Feb 22 17:07:44 2007 -0500
@@ -611,11 +611,11 @@ def prep_spt(spt):
 
 parser = None
 lexer = None
-def create_globals(module, support):
+def create_globals(module, support, debug):
     global parser, lexer, m, spt
     if not parser:
         lexer = lex.lex()
-        parser = yacc.yacc(method="LALR", debug=0, write_tables=0)
+        parser = yacc.yacc(method="LALR", debug=debug, write_tables=0)
 
     if module is not None:
         m = module
@@ -627,13 +627,13 @@ def create_globals(module, support):
     else:
         spt = support
 
-def parse(text, module=None, support=None):
-    create_globals(module, support)
+def parse(text, module=None, support=None, debug=False):
+    create_globals(module, support, debug)
     lexer.lexdata = []
     lexer.lexpos = 0
 
     try:
-        parser.parse(text, debug=0)
+        parser.parse(text, debug=debug)
     except Exception, e:
         global error
         error = "internal parser error: %s" % str(e)
@@ -670,7 +670,7 @@ def list_headers(root):
     return (modules, support_macros)
 
 
-def parse_headers(root, output=None, expand=True):
+def parse_headers(root, output=None, expand=True, debug=False):
     import util
 
     headers = refpolicy.Headers()
@@ -696,11 +696,13 @@ def parse_headers(root, output=None, exp
             output.write(msg)
 
     def parse_file(f, module, spt=None):
+        if debug:
+            o("parsing file %s\n" % f)
         try:
             fd = open(f)
             txt = fd.read()
             fd.close()
-            parse(txt, module, spt)
+            parse(txt, module, spt, debug)
         except IOError, e:
             return
         except ValueError, e:
@@ -726,7 +728,7 @@ def parse_headers(root, output=None, exp
 
         o("done.\n")
 
-    if output:
+    if output and not debug:
         status = util.ConsoleProgressBar(sys.stdout, steps=len(modules))
         status.start("Parsing interface files")
 
@@ -744,7 +746,7 @@ def parse_headers(root, output=None, exp
             continue
 
         headers.children.append(m)
-        if output:
+        if output and not debug:
             status.step()
 
     if len(failures):

             reply	other threads:[~2007-02-22 22:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-22 22:23 Karl MacMillan [this message]
2007-02-27 15:15 ` [PATCH] sepolgen: optionally generate debugging information during parsing Stephen Smalley

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=45DE17E7.1070000@mentalrootkit.com \
    --to=kmacmillan@mentalrootkit.com \
    --cc=selinux@tycho.nsa.gov \
    /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.