diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-08-24 17:13:55 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-08-24 17:13:55 -0700 |
commit | a2ec0b906f91e5adcf3e6c7488a7d53e24bf1448 (patch) | |
tree | abd55791e3421131ebcc4f7ebb647d160bece2ff | |
parent | 66bd589944ccdb9b9c9f6278784b92dac5eb1085 (diff) |
autodebugger_c tool
-rw-r--r-- | tools/autodebugger_c.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/autodebugger_c.py b/tools/autodebugger_c.py new file mode 100644 index 00000000..0876e054 --- /dev/null +++ b/tools/autodebugger_c.py @@ -0,0 +1,29 @@ +''' +Processes a C source file, adding debugging information. + +Similar to autodebugger.py, but runs on .c files +''' + +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() + +print 'Success.' + |