aboutsummaryrefslogtreecommitdiff
path: root/tools/autodebugger_c.py
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-10-13 17:33:16 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-10-13 17:33:16 -0700
commit04eda45157c20ed666d102ac7ae621dee09463aa (patch)
tree7ec3b9ad33c1feb6b55adcaa7b10664b7ea00772 /tools/autodebugger_c.py
parente23882c91f4d87078be958d6278c024b9a518f82 (diff)
C autodebugger improvements
Diffstat (limited to 'tools/autodebugger_c.py')
-rw-r--r--tools/autodebugger_c.py42
1 files changed, 23 insertions, 19 deletions
diff --git a/tools/autodebugger_c.py b/tools/autodebugger_c.py
index 0876e054..5d41faf0 100644
--- a/tools/autodebugger_c.py
+++ b/tools/autodebugger_c.py
@@ -1,29 +1,33 @@
'''
Processes a C source file, adding debugging information.
-Similar to autodebugger.py, but runs on .c files
+Similar to autodebugger.py, but runs on .c files. Will
+overwrite the files it is given!
'''
import os, sys, re
-filename, ofilename = sys.argv[1], sys.argv[2]
-f = open(filename, 'r')
-data = f.read()
-f.close()
-
-lines = data.split('\n')
-for i in range(len(lines)):
- m = re.match('^ [ ]*([\w\d \[\]]+) = +([^;]+);$', lines[i])
- if m and (' if ' not in lines[i-1] or '{' in lines[i-1]) and \
- (' if ' not in lines[i+1] or '{' in lines[i+1]) and \
- (' else' not in lines[i-1] or '{' in lines[i-1]) and \
- (' else' not in lines[i+1] or '{' in lines[i+1]):
- var = m.groups(1)[0].rstrip().split(' ')[-1]
- lines[i] += ''' printf("%d:%s=%%d\\n", %s);''' % (i+1, var, var)
-
-f = open(ofilename, 'w')
-f.write('\n'.join(lines))
-f.close()
+filenames = sys.argv[1:]
+for filename in filenames:
+ print '..%s..' % filename
+
+ f = open(filename, 'r')
+ data = f.read()
+ f.close()
+
+ lines = data.split('\n')
+ for i in range(len(lines)):
+ m = re.match('^ [ ]*([\w\d \[\]]+) = +([^;]+);$', lines[i])
+ if m and (' if ' not in lines[i-1] or '{' in lines[i-1]) and \
+ (' if ' not in lines[i+1] or '{' in lines[i+1]) and \
+ (' else' not in lines[i-1] or '{' in lines[i-1]) and \
+ (' else' not in lines[i+1] or '{' in lines[i+1]):
+ var = m.groups(1)[0].rstrip().split(' ')[-1]
+ lines[i] += ''' printf("%s:%d:%s=%%d\\n", %s);''' % (filename, i+1, var, var)
+
+ f = open(filename, 'w')
+ f.write('\n'.join(lines))
+ f.close()
print 'Success.'