This commit is contained in:
aozhiwei 2019-10-12 15:08:42 +08:00
parent 014ae40f07
commit 10de601297
3 changed files with 35 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import os
import time
import pychrome
import cmd
@ -25,5 +26,11 @@ 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:
cmd.processCmd(browser, tab, scriptmgr)
cmdline= input('(cdb)').strip()
try:
cmd.processCmd(browser, tab, scriptmgr, cmdline)
except Exception as e:
print(e)

View File

@ -4,7 +4,7 @@ def _b_cmd(browser, tab, scriptmgr, params):
line = int(params[0].split(':')[1])
url = scriptmgr.getUrl(filename)
print(params, url)
tab.debug = True
# tab.debug = True
tab.call_method("Debugger.setBreakpointByUrl",
lineNumber=line,
url=url,
@ -12,6 +12,9 @@ def _b_cmd(browser, tab, scriptmgr, params):
condition=''
)
def _bt_cmd(browser, tab, scriptmgr, params):
scriptmgr.dumpStack()
def _p_cmd(browser, tab, scriptmgr, params):
pass
@ -21,6 +24,7 @@ def _processCdbCmd(cmd_str, browser, tab, scriptmgr):
return
cmd_hash = {
'b': _b_cmd,
'bt': _bt_cmd,
'p': None,
}
print(cmdlist)
@ -29,8 +33,7 @@ def _processCdbCmd(cmd_str, browser, tab, scriptmgr):
else:
print('not found %s cmd' % cmdlist[0])
def processCmd(browser, tab, scriptmgr):
cmdline= input('').strip()
def processCmd(browser, tab, scriptmgr, cmdline):
try:
if len(cmdline) > 0 :
if cmdline[0] == '!':

View File

@ -1,7 +1,13 @@
import json
def getShortUrl(url):
return url.replace('http://localhost:7456/', '')
class ScriptMgr:
def __init__(self, tab):
self.frames = []
self.scripts = []
self.tab = tab
self.tab.set_listener('Debugger.scriptParsed', self.onScriptParsed)
@ -18,6 +24,9 @@ class ScriptMgr:
def onPaused(self, **kwargs):
print('onPaused')
self.frames = []
for frame in kwargs['callFrames']:
self.frames.append(frame)
def onResumed(self, **kwargs):
print('onResumed')
@ -30,3 +39,15 @@ class ScriptMgr:
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'],
)
)