forked from kmgrant/macterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_Debugging.txt
77 lines (64 loc) · 3.15 KB
/
_Debugging.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
How to Debug MacTerm 2006-09-27
BACKGROUND
MacTerm is in many ways very easy to debug because it is
launched by a Python interpreter: code in the application can
use the simplicity of scripting where practical to test, even
taking full advantage of Python testing capabilities like
"doctest" within scripts.
However, this also brings a few complications you should be
aware of. The biggest one is that MacTerm is *not* the main
executable, *Python* is. You are therefore debugging "python"
from the point of view of MallocDebug or any other tool that
attaches to running processes. This does not change anything
in practice aside from making it slightly harder to find some
of the familiar application entry points.
INVOKING LLDB
There are scripts in the "Debug" directory that provide simple
launchers for the most common debugging needs. They have
".command" extensions so that they may be run from the Finder.
Although sub-programs such as PrefsConverter are regular
compiled executables, the MacTerm application is implemented as
a library that is loaded into a Python interpreter. To debug
MacTerm, the debugger must run against the Python interpreter.
Environment variables must be set to find dependent libraries.
The easiest way to keep all of this straight is to take
advantage of the debugging mode in the "MacTerm" executable...
First, set the environment variable "MACTERM_DEBUG" to 1. This
flag tells the "MacTerm" script to add "lldb --" to the front
of its command line.
Second, if you want to specify where "lldb" comes from (instead
of using the $PATH), set the location with the environment
variable "MACTERM_LLDB".
Now run MacTerm from the command line, e.g.
% Build/MacTerm.app/Contents/MacOS/MacTerm
Notice that "Debug/ApplicationLLDB.sh.command" does all of the
above and it also uses the default Xcode installation to find
the "lldb" executable.
THE CALL STACK
The Python interpreter has multiple threads and a moderately
deep call stack. It can be daunting to figure out where the
main event loop for MacTerm is actually invoked, so this
section helps you with that.
In MallocDebug or another program that traces the call stack,
follow start() -> Py_Main() -> PyRun_SimpleFileExFlags() and
trace as shown below down to the event loop. (Note that this
example came from Python 2.3; a future version of Python may
change the call stack a bit.)
Example:
...
#8 0x00222bcc in _wrap_Events_run_loop ()
#9 0x98a8c8e0 in PyObject_Call ()
#10 0x98aec5a4 in PyEval_GetFuncDesc ()
#11 0x98ae94f4 in PyEval_EvalCode ()
#12 0x98aea5e4 in PyEval_EvalCodeEx ()
#13 0x98aebf90 in PyEval_GetFuncDesc ()
#14 0x98aebd34 in PyEval_GetFuncDesc ()
#15 0x98ae9414 in PyEval_EvalCode ()
#16 0x98aea5e4 in PyEval_EvalCodeEx ()
#17 0x98ae6eb8 in PyEval_EvalCode ()
#18 0x98b0b08c in PyRun_FileExFlags ()
#19 0x98b0a0b0 in PyRun_SimpleFileExFlags ()
#20 0x98b14a00 in Py_Main ()
#21 0x00002574 in start ()
Kevin Grant (kmg@mac.com)
Lead Developer, MacTerm