Last active
August 29, 2015 14:03
-
-
Save venkateshshukla/64d009c81dfa1fe1b909 to your computer and use it in GitHub Desktop.
While debugging, print the name of functions as they are called.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
name = sys.argv[1] | |
f = open(name, 'r') | |
g = open(name + '.temp', 'w') | |
text = f.read() | |
if '#include <stdio.h>' not in text: | |
g.write('#include <stdio.h>\n') | |
f.seek(0, 0) | |
g.write('#define FDEBUG(x) fprintf(stderr, \"' + name + '\\t:\\t%s\\n\", x)\n') | |
def get_fn_name(s): | |
s = s.replace('extern ', '') | |
s = s.replace('static ', '') | |
s = s.replace('const ', '') | |
s = s.replace('void ', '') | |
s = s.replace('int ', '') | |
s = s.replace('char ', '') | |
s = s.replace('double ', '') | |
s = s.replace('long ', '') | |
s = s.replace('unsigned ', '') | |
s = s.replace('signed ', '') | |
s = s.replace('short ', '') | |
s = s.replace('signed ', '') | |
s = s.replace('float ', '') | |
s = s.replace('bool ', '') | |
s = s.replace('\"C\"', '') | |
s = s.strip(' *') | |
return s[:s.index('(')] | |
prev = '' | |
for l in f: | |
g.write(l) | |
if l == "{\n": | |
if '(' in prev and ')' in prev: | |
fnname = get_fn_name(prev) | |
g.write('\tFDEBUG (\"' + fnname + '\");\n') | |
prev = l | |
f.close() | |
g.close() | |
os.remove(name) | |
os.rename(name + '.temp', name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
name = sys.argv[1] | |
f = open(name, 'r') | |
g = open(name + '.temp', 'w') | |
text = f.read() | |
if '#include <QtDebug>' not in text: | |
g.write('#include <QtDebug>\n') | |
f.seek(0, 0) | |
def get_fn_name(s): | |
s = s.replace('extern ', '') | |
s = s.replace('static ', '') | |
s = s.replace('const ', '') | |
s = s.replace('void ', '') | |
s = s.replace('int ', '') | |
s = s.replace('char ', '') | |
s = s.replace('double ', '') | |
s = s.replace('long ', '') | |
s = s.replace('unsigned ', '') | |
s = s.replace('signed ', '') | |
s = s.replace('short ', '') | |
s = s.replace('signed ', '') | |
s = s.replace('float ', '') | |
s = s.replace('bool ', '') | |
s = s.replace('\"C\"', '') | |
s = s.strip(' *') | |
return s[:s.index('(')] | |
prev = '' | |
for l in f: | |
g.write(l) | |
if l == "{\n": | |
if '(' in prev and ')' in prev: | |
fnname = get_fn_name(prev) | |
g.write('\tqDebug()<< \"' + name + '\\t:\\t' + fnname + '\";\n') | |
prev = l | |
f.close() | |
g.close() | |
os.remove(name) | |
os.rename(name + '.temp', name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment