From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id A8BCFC60E for ; Tue, 28 Apr 2015 16:56:42 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 28 Apr 2015 07:56:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,664,1422950400"; d="scan'208";a="486717796" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by FMSMGA003.fm.intel.com with ESMTP; 28 Apr 2015 07:56:40 -0700 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id t3SEudZR029884; Tue, 28 Apr 2015 22:56:39 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t3SEuaOk006841; Tue, 28 Apr 2015 22:56:38 +0800 Received: (from yliu84x@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t3SEua5G006837; Tue, 28 Apr 2015 22:56:36 +0800 From: Yong Liu To: dts@dpdk.org Date: Tue, 28 Apr 2015 22:56:29 +0800 Message-Id: <1430232992-6798-2-git-send-email-yong.liu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1430232992-6798-1-git-send-email-yong.liu@intel.com> References: <1430232992-6798-1-git-send-email-yong.liu@intel.com> Subject: [dts] [PATCH 1/4] framework: add debugger module for enable debug in the running process X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Apr 2015 14:56:43 -0000 From: Marvin Liu There're only few commands supported in debug mode. They're listed below. help(): show help message list(): list all connected sessions connect(name): connect to session directly exit(): exit dts quit(): quit debug mode and into noraml mode debug(): call python debug module Signed-off-by: Marvin Liu --- framework/debugger.py | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 framework/debugger.py diff --git a/framework/debugger.py b/framework/debugger.py new file mode 100644 index 0000000..a2bfe7f --- /dev/null +++ b/framework/debugger.py @@ -0,0 +1,147 @@ +# BSD LICENSE +# +# Copyright(c) 2010-2015 Intel Corporation. All rights reserved. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + +import sys +import os +import signal +import code +import time +import dts + + +console = None # global console object +debug_cmd = '' # global debug state + + +def help_command(): + console.push('print \'Help on debug module\'') + console.push('print \'DESCRIPTION\'') + console.push('print \'DTS debug module support few debug commands\'') + console.push('print \' - help: help messages\'') + console.push('print \' - list: list all connections\'') + console.push('print \' - connect: bind to specified connection\'') + console.push('print \' - : connect(\"dut\")\'') + console.push('print \' - quit: quit debug module\'') + console.push('print \' - exit: exit processing procedure\'') + console.push('print \' - debug: call python debug module for further debug\'') + + +def list_command(): + """ + List all connection sessions and can be reference of connect command. + """ + index = 0 + from ssh_connection import CONNECTIONS + for connection in CONNECTIONS: + for name, session in connection.items(): + console.push('print \'connect %d: %10s\'' % (index, name)) + index += 1 + + +def connect_command(connect): + """ + Connect to ssh session and give control to user. + """ + from ssh_connection import CONNECTIONS + for connection in CONNECTIONS: + for name, session in connection.items(): + if name == connect: + session.session.interact() + + +def exit_command(): + """ + Exit dts framework. + """ + global debug_cmd + debug_cmd = 'exit' + sys.exit(0) + + +def debug_command(): + """ + Give control to python debugger pdb. + """ + global debug_cmd + debug_cmd = 'debug' + sys.exit(0) + + +def capture_handle(signum, frame): + """ + Capture keyboard interrupt in the process of send_expect. + """ + global debug_cmd + debug_cmd = 'waiting' + + +def keyboard_handle(signum, frame): + """ + Interrupt handler for SIGINT and call code module create python interpreter. + """ + global console + console = code.InteractiveConsole() + command = {} + command['list'] = list_command + command['exit'] = exit_command + command['debug'] = debug_command + command['help'] = help_command + command['connect'] = connect_command + console.push('print \"Use help command for detail information\"') + try: + code.interact(local=command) + except SystemExit: + # reopen sys.stdin for after exit function stdin will be closed + fd = os.open('/dev/stdin', 600) + sys.stdin = os.fdopen(fd, 'r') + + global debug_cmd + if debug_cmd == 'debug': + # call pyton debugger + import pdb + pdb.set_trace() + elif debug_cmd == 'exit': + sys.exit(0) + + debug_cmd = '' + + +def ignore_keyintr(): + """ + Temporary disable interrupt handler. + """ + global debug_cmd + signal.siginterrupt(signal.SIGINT, True) + # if there's waiting request, first handler it + if debug_cmd == 'waiting': + keyboard_handle(signal.SIGINT, None) + + return signal.signal(signal.SIGINT, capture_handle) + + +def aware_keyintr(): + """ + Reenable interrupt handler. + """ + return signal.signal(signal.SIGINT, keyboard_handle) -- 1.9.3