From 10de6012970e40fe4e30f7f98d78ed50a1be9ff2 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 12 Oct 2019 15:08:42 +0800 Subject: [PATCH] 1 --- scripts/cdb/cdb.py | 9 ++++++++- scripts/cdb/cmd.py | 9 ++++++--- scripts/cdb/scriptmgr.py | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/scripts/cdb/cdb.py b/scripts/cdb/cdb.py index ddefe19..5eb2eb3 100644 --- a/scripts/cdb/cdb.py +++ b/scripts/cdb/cdb.py @@ -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) diff --git a/scripts/cdb/cmd.py b/scripts/cdb/cmd.py index 0feb9c1..83e2f37 100644 --- a/scripts/cdb/cmd.py +++ b/scripts/cdb/cmd.py @@ -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] == '!': diff --git a/scripts/cdb/scriptmgr.py b/scripts/cdb/scriptmgr.py index c4bc056..7a65c6e 100644 --- a/scripts/cdb/scriptmgr.py +++ b/scripts/cdb/scriptmgr.py @@ -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'], + ) + )