def runVdb(vivgui, pid=None): try: db = vdb.Vdb() extendVdb(db, vivgui) vgui = vdb_qt_main.VdbWindow(db) vgui.show() if pid != None: fireattach(db.trace, pid) except Exception as e: vivgui.vw.vprint('Error Running VDB: %s' % e)
def main(): parser = argparse.ArgumentParser(prog='vdbbin', usage='%(prog)s [options] [platformopt=foo, ...]') parser.add_argument('-c', '--cmd', dest='command', default=None, help='Debug a fired command') parser.add_argument('-p', '--process', dest='process', default=None, help='Attach to process by name or pid') parser.add_argument('-Q', '--qt', dest='doqt', default=False, action='store_true', help='Run the QT gui') parser.add_argument('-R', '--remote', dest='remotehost', default=None, help='Attach to remote VDB server') parser.add_argument('-r', '--run', dest='dorunagain', default=False, action='store_true', help='Do not stop on attach') parser.add_argument('-s', '--snapshot', dest='snapshot', default=None, help='Load a vtrace snapshot file') parser.add_argument('-S', '--server', dest='doserver', default=False, action='store_true') parser.add_argument('-v', '--verbose', dest='doverbose', default=False, action='store_true') parser.add_argument('-t', '--target', dest='target', default=None, help='Activate special vdb target ( -t ? for list )') parser.add_argument('--android', dest='doandroid', default=False, action='store_true', help='Debug Android with ADB!') parser.add_argument('-e', '--eventid', dest='eventid', default=None, type=int, help='Used for Windows JIT') parser.add_argument('-w', '--waitfor', dest='waitfor', default=None, help='Wait for process with name') parser.add_argument('platargs', nargs='*') args = parser.parse_args() # Handle some options before we even create a trace. vtrace.remote = args.remotehost # None by default platargs = {} for arg in args.platargs: if arg.find('=') == -1: continue k, v = arg.split('=', 1) if v.isdigit(): v = int(v) platargs[k.lower()] = v if args.doandroid: import vdb.tools.android as v_utils_android v_utils_android.runVdbOnDroid() return if args.target == '?': targetusage() trace = None if args.snapshot: print('Loading process snapshot...') trace = vt_snap.loadSnapshot(args.snapshot) if trace == None: trace = vtrace.getTrace(target=args.target, **platargs) db = vdb.Vdb(trace) db.runagain = args.dorunagain db.windows_jit_event = args.eventid if args.waitfor: while True: newest_pid = 0 for pid, pname in trace.ps(): pname = pname.split(' ')[0] if pname.find(args.waitfor) != -1: newest_pid = pid if newest_pid != 0: trace.attach(newest_pid) break if args.doqt: import vqt.main as vq_main import vdb.qt.main as vdb_q_main import vqt.colors as vq_colors vq_main.startup(css=vq_colors.qt_matrix) qgui = vdb_q_main.VdbWindow(db) qgui.show() if args.doserver: db.do_server('') if args.process: db.do_attach(args.process) elif args.command: trace.execute(args.command) if args.eventid: db.trace.setMeta('WindowsJitEvent', args.eventid) if args.doqt: vq_main.main() else: while not db.shutdown.isSet(): try: db.cmdloop() except KeyboardInterrupt: if db.trace.isRunning(): db.trace.sendBreak() except SystemExit: break except: traceback.print_exc()