test suite reviews and discussions
 help / color / mirror / Atom feed
From: Yong Liu <yong.liu@intel.com>
To: dts@dpdk.org
Subject: [dts] [PATCH 1/4] framework: add debugger module for enable debug in the running process
Date: Tue, 28 Apr 2015 22:56:29 +0800	[thread overview]
Message-ID: <1430232992-6798-2-git-send-email-yong.liu@intel.com> (raw)
In-Reply-To: <1430232992-6798-1-git-send-email-yong.liu@intel.com>

From: Marvin Liu <yong.liu@intel.com>

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 <yong.liu@intel.com>
---
 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

  reply	other threads:[~2015-04-28 14:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-28 14:56 [dts] [PATCH 0/4] Support debug mode in DTS Yong Liu
2015-04-28 14:56 ` Yong Liu [this message]
2015-04-28 14:56 ` [dts] [PATCH 2/4] framework: maintain connected session list and disable debug mode in send_expect Yong Liu
2015-04-28 14:56 ` [dts] [PATCH 3/4] framework: change alt session name for easy to distinguish Yong Liu
2015-04-28 14:56 ` [dts] [PATCH 4/4] framework: enlarge hugepage number for dpdk2.0 request more memory Yong Liu
2015-05-11  6:25 ` [dts] [PATCH] framework: add argument for debug mode enable and disable Yong Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1430232992-6798-2-git-send-email-yong.liu@intel.com \
    --to=yong.liu@intel.com \
    --cc=dts@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).