Skip to content

Instantly share code, notes, and snippets.

@meeuw
Last active August 29, 2015 13:55
Show Gist options
  • Save meeuw/8742359 to your computer and use it in GitHub Desktop.
Save meeuw/8742359 to your computer and use it in GitHub Desktop.
Script to inject error_log debug backtrace to create xrefs in PHP scripts
#!/usr/bin/python
import sys
import fileinput
import re
for line in fileinput.input(inplace=True):
if fileinput.isfirstline():
function = False
interface = False
class_name = ""
comment = False
matchline = line
if '*/' in line:
comment = False
matchline = re.sub('.*\*/', '', matchline)
if '/*' in line:
comment = True
matchline = re.sub('/\* .*', '', matchline)
matchline = re.sub('//.*', '', matchline)
if 'interface ' in matchline: interface = True
m = re.match('.*class +([A-Za-z][A-Za-z0-9_]*).*', matchline)
if (not(comment) and m):
class_name = m.group(1)
function = False
interface = False
m = re.match('.*function +([A-Za-z_][A-Za-z0-9_]*).*', matchline)
if not(comment) and not(interface) and m and class_name:
print >> sys.stderr, class_name, m.group(1)
function = True
if not(comment) and function and '{' in matchline:
print line.replace('{', "{ dmdbt(debug_backtrace());"),
function = False
else: print line,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment