1
This commit is contained in:
parent
a831f59035
commit
ff53825f43
@ -1,37 +0,0 @@
|
|||||||
import os
|
|
||||||
import time
|
|
||||||
import pychrome
|
|
||||||
|
|
||||||
import cmd
|
|
||||||
import scriptmgr
|
|
||||||
|
|
||||||
#os.environ['DEBUG'] = '1'
|
|
||||||
|
|
||||||
def initTab(tab):
|
|
||||||
tab.call_method("Network.enable", maxPostDataSize=65536)
|
|
||||||
tab.call_method("Page.enable")
|
|
||||||
tab.call_method("Page.getResourceTree")
|
|
||||||
tab.call_method("Profiler.enable")
|
|
||||||
tab.call_method("Runtime.enable")
|
|
||||||
tab.call_method("Debugger.enable", maxScriptsCacheSzie=1000000)
|
|
||||||
tab.call_method("DOM.enable")
|
|
||||||
tab.call_method("CSS.enable")
|
|
||||||
tab.call_method("Overlay.enable")
|
|
||||||
tab.call_method("Log.enable")
|
|
||||||
|
|
||||||
browser = pychrome.Browser(url="http://192.168.100.137:9223")
|
|
||||||
tab = browser.new_tab()
|
|
||||||
scriptmgr = scriptmgr.ScriptMgr(tab)
|
|
||||||
tab.start()
|
|
||||||
initTab(tab)
|
|
||||||
tab.call_method("Page.navigate", url="http://localhost:7456/", _timeout=5)
|
|
||||||
|
|
||||||
time.sleep(3)
|
|
||||||
cmd.processCmd(browser, tab, scriptmgr, 'b jcmatchvs.js:102')
|
|
||||||
while True:
|
|
||||||
cmdline= input('(cdb)').strip()
|
|
||||||
try:
|
|
||||||
cmd.processCmd(browser, tab, scriptmgr, cmdline)
|
|
||||||
time.sleep(0.1)
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
@ -1,105 +0,0 @@
|
|||||||
|
|
||||||
g_cmdstr = ''
|
|
||||||
|
|
||||||
def _getCmdParam():
|
|
||||||
return g_cmdstr[1:]
|
|
||||||
|
|
||||||
def _b_cmd(browser, tab, scriptmgr, params):
|
|
||||||
filename = params[0].split(':')[0]
|
|
||||||
line = int(params[0].split(':')[1])
|
|
||||||
url = scriptmgr.getUrl(filename)
|
|
||||||
print(params, url)
|
|
||||||
tab.call_method("Debugger.setBreakpointByUrl",
|
|
||||||
lineNumber=line,
|
|
||||||
url=url,
|
|
||||||
columnNumber=0,
|
|
||||||
condition=''
|
|
||||||
)
|
|
||||||
|
|
||||||
def _bc_cmd(browser, tab, scriptmgr, params):
|
|
||||||
filename = params[0].split(':')[0]
|
|
||||||
line = int(params[0].split(':')[1])
|
|
||||||
url = scriptmgr.getUrl(filename)
|
|
||||||
print(params, url)
|
|
||||||
tab.call_method("Debugger.setBreakpointByUrl",
|
|
||||||
lineNumber=line,
|
|
||||||
url=url,
|
|
||||||
columnNumber=0,
|
|
||||||
condition=''
|
|
||||||
)
|
|
||||||
|
|
||||||
def _bt_cmd(browser, tab, scriptmgr, params):
|
|
||||||
scriptmgr.dumpStack()
|
|
||||||
|
|
||||||
def _p_cmd(browser, tab, scriptmgr, params):
|
|
||||||
tab.call_method("Debugger.evaluateOnCallFrame",
|
|
||||||
callFrameId=scriptmgr.getFrameId(),
|
|
||||||
expression='console.log(' + _getCmdParam() + ')'
|
|
||||||
)
|
|
||||||
|
|
||||||
def _f_cmd(browser, tab, scriptmgr, params):
|
|
||||||
scriptmgr.curr_frame = int(params[0])
|
|
||||||
|
|
||||||
def _n_cmd(browser, tab, scriptmgr, params):
|
|
||||||
tab.call_method("Debugger.pause")
|
|
||||||
|
|
||||||
def _s_cmd(browser, tab, scriptmgr, params):
|
|
||||||
tab.call_method("Debugger.stepInto")
|
|
||||||
|
|
||||||
def _c_cmd(browser, tab, scriptmgr, params):
|
|
||||||
tab.call_method("Debugger.resume")
|
|
||||||
|
|
||||||
def _sout_cmd(browser, tab, scriptmgr, params):
|
|
||||||
tab.call_method("Debugger.stepOut")
|
|
||||||
|
|
||||||
def _sover_cmd(browser, tab, scriptmgr, params):
|
|
||||||
tab.call_method("Debugger.stepOver")
|
|
||||||
|
|
||||||
def _debugon_cmd(browser, tab, scriptmgr, params):
|
|
||||||
tab.debug = True
|
|
||||||
print('debug on')
|
|
||||||
|
|
||||||
def _debugoff_cmd(browser, tab, scriptmgr, params):
|
|
||||||
tab.debug = False
|
|
||||||
print('debug off')
|
|
||||||
|
|
||||||
def _exit_cmd(browser, tab, scriptmgr, params):
|
|
||||||
print('quit')
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
def _processCdbCmd(cmd_str, browser, tab, scriptmgr):
|
|
||||||
global g_cmdstr
|
|
||||||
g_cmdstr = cmd_str
|
|
||||||
cmdlist = cmd_str.split(' ')
|
|
||||||
if len(cmdlist) < 1:
|
|
||||||
return
|
|
||||||
cmd_hash = {
|
|
||||||
'b': _b_cmd,
|
|
||||||
'bc': _bc_cmd,
|
|
||||||
'bt': _bt_cmd,
|
|
||||||
'p': _p_cmd,
|
|
||||||
'f': _f_cmd,
|
|
||||||
'n': _n_cmd,
|
|
||||||
's': _s_cmd,
|
|
||||||
'sout': _sout_cmd,
|
|
||||||
'sover': _sover_cmd,
|
|
||||||
'c': _c_cmd,
|
|
||||||
'debugon': _debugon_cmd,
|
|
||||||
'debugoff': _debugoff_cmd,
|
|
||||||
'q': _exit_cmd,
|
|
||||||
}
|
|
||||||
if cmdlist[0] in cmd_hash:
|
|
||||||
cmd_hash[cmdlist[0]](browser, tab, scriptmgr, cmdlist[1:])
|
|
||||||
else:
|
|
||||||
print('not found %s cmd' % cmdlist[0])
|
|
||||||
|
|
||||||
def processCmd(browser, tab, scriptmgr, cmdline):
|
|
||||||
try:
|
|
||||||
if len(cmdline) > 0 :
|
|
||||||
if cmdline[0] == '!':
|
|
||||||
msg = eval(cmdline[1:])
|
|
||||||
else:
|
|
||||||
_processCdbCmd(cmdline, browser, tab, scriptmgr)
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
|
|
@ -1,72 +0,0 @@
|
|||||||
|
|
||||||
import json
|
|
||||||
import pprint
|
|
||||||
|
|
||||||
def getShortUrl(url):
|
|
||||||
return url.replace('http://localhost:7456/', '')
|
|
||||||
|
|
||||||
class ScriptMgr:
|
|
||||||
|
|
||||||
def __init__(self, tab):
|
|
||||||
self.curr_frame = 0
|
|
||||||
self.frames = []
|
|
||||||
self.scripts = []
|
|
||||||
self.tab = tab
|
|
||||||
self.tab.set_listener('Debugger.scriptParsed', self.onScriptParsed)
|
|
||||||
self.tab.set_listener('Debugger.breakpointResolved', self.onBreakpointResolved)
|
|
||||||
self.tab.set_listener('Debugger.paused', self.onPaused)
|
|
||||||
self.tab.set_listener('Debugger.resumed', self.onResumed)
|
|
||||||
self.tab.set_listener('Debugger.scriptFailedToParse', self.onScriptFailedToParse)
|
|
||||||
self.tab.set_listener('Runtime.consoleAPICalled', self.consoleAPICalled)
|
|
||||||
|
|
||||||
def onScriptParsed(self, **kwargs):
|
|
||||||
self.scripts.append(kwargs)
|
|
||||||
|
|
||||||
def onBreakpointResolved(self, **kwargs):
|
|
||||||
print('onBreakpointResolved')
|
|
||||||
|
|
||||||
def onPaused(self, **kwargs):
|
|
||||||
# print('onPaused')
|
|
||||||
self.frames = []
|
|
||||||
for frame in kwargs['callFrames']:
|
|
||||||
self.frames.append(frame)
|
|
||||||
pprint.pprint('%s:%d' %
|
|
||||||
(
|
|
||||||
getShortUrl(self.frames[0]['url']),
|
|
||||||
self.frames[0]['location']['lineNumber']
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def onResumed(self, **kwargs):
|
|
||||||
print('onResumed')
|
|
||||||
|
|
||||||
def onScriptFailedToParse(self, **kwargs):
|
|
||||||
print('onScriptFailedToParse', kwargs['url'])
|
|
||||||
|
|
||||||
def consoleAPICalled(self, **kwargs):
|
|
||||||
for prop in kwargs['args']:
|
|
||||||
if prop['type'] == 'object':
|
|
||||||
pprint.pprint(prop['preview']['properties'])
|
|
||||||
else:
|
|
||||||
print('%s' % (str(prop['value'])))
|
|
||||||
|
|
||||||
def getUrl(self, filename):
|
|
||||||
for script in self.scripts:
|
|
||||||
if filename in script['url']:
|
|
||||||
return script['url']
|
|
||||||
return None
|
|
||||||
|
|
||||||
def dumpStack(self):
|
|
||||||
for frame in self.frames:
|
|
||||||
print('%30s %s:%d' %
|
|
||||||
(
|
|
||||||
frame['functionName'] + ':' +
|
|
||||||
str(json.loads(frame['callFrameId'])['ordinal']) + ':' +
|
|
||||||
str(json.loads(frame['callFrameId'])['injectedScriptId']),
|
|
||||||
getShortUrl(frame['url']),
|
|
||||||
frame['functionLocation']['lineNumber'],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def getFrameId(self):
|
|
||||||
return self.frames[self.curr_frame]['callFrameId']
|
|
Loading…
x
Reference in New Issue
Block a user