]> git.saurik.com Git - apple/xnu.git/blame - tools/lldbmacros/usertaskgdbserver.py
xnu-3789.51.2.tar.gz
[apple/xnu.git] / tools / lldbmacros / usertaskgdbserver.py
CommitLineData
3e170ce0
A
1from xnu import *
2import logging
3_usertaskdebugging_availabe = False
4try:
5 from usertaskdebugging import userprocess
6 from usertaskdebugging import gdbserver
7 _usertaskdebugging_availabe = True
8except ImportError:
9 pass
10
11def setupLogging(debug_level):
12 log_level = debug_level
13 log_filename = "/tmp/kdbserver.log"
14 logging.basicConfig(level=log_level,
15 format='%(asctime)s %(module)s %(levelname)s: %(message)s',
16 datefmt='%Y-%m-%d %H:%M:%S')
17
18
19@lldb_command('beginusertaskdebugging', 'DW')
20def DoUserTaskDebuggingServer(cmd_args = [], cmd_options ={}):
21 """ starts a gdb protocol server that is backed by <task_t> in kernel debugging session.
22 Usage: (lldb) beginusertaskdebugging <task_t>
23 options: -D for debug level logging
24 -W for warning level logging.
25 default is error level logging
26 """
27 if not _usertaskdebugging_availabe:
28 print "You do not have the usertask debugging files available. "
29 return
39037602
A
30 log_level = logging.ERROR
31 if '-D' in cmd_options:
32 log_level = logging.DEBUG
33 elif '-W' in cmd_options:
34 log_level = logging.WARNING
35
36 setupLogging(debug_level=log_level)
37 if not cmd_args:
38 raise ArgumentError("Please provide valid task argument.")
39
40 t = kern.GetValueFromAddress(cmd_args[0], 'task_t')
41
42 up = userprocess.UserProcess(t)
43 gbs = gdbserver.GDBServer(up)
44 print "Starting debug session for %s at localhost:%d." % (GetProcNameForTask(t), gbs.portnum)
45 gbs.run()
46 print "stopped the debug session"