-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNotes.rtf
179 lines (157 loc) · 11.4 KB
/
Notes.rtf
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
{\rtf1\ansi\ansicpg1252\cocoartf2512
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fnil\fcharset0 Monaco;\f1\fnil\fcharset0 Menlo-Regular;\f2\fmodern\fcharset0 Courier;
}
{\colortbl;\red255\green255\blue255;\red38\green71\blue75;\red100\green56\blue32;\red196\green26\blue22;
\red170\green13\blue145;\red46\green13\blue110;\red0\green116\blue0;\red92\green38\blue153;\red28\green0\blue207;
}
{\*\expandedcolortbl;;\csgenericrgb\c14902\c27843\c29412;\csgenericrgb\c39216\c21961\c12549;\csgenericrgb\c76863\c10196\c8627;
\csgenericrgb\c66667\c5098\c56863;\csgenericrgb\c18039\c5098\c43137;\csgenericrgb\c0\c45490\c0;\csgenericrgb\c36078\c14902\c60000;\csgenericrgb\c10980\c0\c81176;
}
\viewkind0
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0
\f0\fs32 \cf0 Saved Document State\
\fs20 \
If you save a document, it it saved as a plist file containing a dictionary. This includes the text as RTF, but also the definitions of functions and variables.\
\fs32 \
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0
\fs20 \cf0 \
\fs32 Shadowing the calculator state\
\fs20 \
Both the app and the task have a CalcState. Thus, if the task crashes, I can make a new one and initialize its state to the last function and variable values.\
\
When the calculator task returns
\f1\fs22 \cf2 \CocoaLigature0 kCalcResult_DefinedFunction
\f0\fs20 \cf0 \CocoaLigature1 , the app passes the line to its own CalcState.\
\
When the calculator task returns
\f1\fs22 \cf2 \CocoaLigature0 kCalcResult_Calculated
\f0\fs20 \cf0 \CocoaLigature1 , use the symbol name returned from ParseCalcLine, and set that symbol (if any) and
\f1\fs22 \CocoaLigature0 last
\f0\fs20 \CocoaLigature1 to the computed value, using SetCalcVariable.\
\
\fs32 To prevent a process from triggering the crash reporter\
\f2\fs28 \
\pard\tx560\pardeftab560\pardirnatural\partightenfactor0
\f1\fs22 \cf3 \CocoaLigature0 #import \cf4 <signal.h>\cf3 \
#import \cf4 <stdlib.h>\cf3 \
\pard\tx560\pardeftab560\pardirnatural\partightenfactor0
\cf5 \
static\cf0 \cf5 void\cf0 sighandler( \cf5 int\cf0 theSig )\
\{\
\cf6 exit\cf0 ( theSig );\
\}\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0
\f2\fs28 \cf0 \CocoaLigature1 \
\pard\tx560\pardeftab560\pardirnatural\partightenfactor0
\f1\fs22 \cf0 \CocoaLigature0 \cf7 // Set up alternate stack for stack overflow case\cf0 \
stack_t sigstk;\
sigstk.\cf8 ss_sp\cf0 = \cf6 malloc\cf0 (\cf3 SIGSTKSZ\cf0 );\
sigstk.ss_size = \cf3 SIGSTKSZ\cf0 ;\
sigstk.ss_flags = \cf9 0\cf0 ;\
\cf6 sigaltstack\cf0 ( &sigstk, \cf5 NULL\cf0 );\
\
\cf7 // Set up signal handlers\cf0 \
\cf5 struct\cf0 sigaction act;\
act.\cf3 sa_handler\cf0 = sighandler;\
\cf6 sigemptyset\cf0 ( &act.\cf8 sa_mask\cf0 );\
act.\cf8 sa_flags\cf0 = \cf3 SA_ONSTACK\cf0 ;\
\
\cf5 int\cf0 sa_res = \cf6 sigaction\cf0 ( \cf3 SIGBUS\cf0 , &act, \cf5 NULL\cf0 );\
\cf7 // and so on for SIGFPE, SIGSEGV, etc\cf0 \
\pard\pardeftab720\partightenfactor0
\f0\fs20 \cf0 \CocoaLigature1 \
\
How do I run a child process and either retrieve its status or kill it?\
Could use NSTask, if it is a command line process.\
\
What happens if NSTask runs a command that crashes? The task sends a notification that it terminated, and [theTask terminationStatus] gives the error code such as SIGSEGV.\
\
\
\fs32 Communicating with the task
\fs20 \
\
To initialize the variables and functions, pass dictionary property list XML in command line args.\
\
Hook up pipes to stdin, stdout.\
\
App to task: App writes a LF-terminated string to be evaluated. The task can repeatedly call getchar(), watching for LF or EOF, otherwise appending to a buffer.\
\
Task to app: dictionary property list XML. The dictionary would contain: Key @"ResultKind", value ECalcResult; key @"Result", value NSNumber containing double; key @"Stop", value NSNumber containing int; key @"Symbol", value NSString. The app can tell when it has the whole thing by looking for </plist>.\
\
\
\fs32 Crashes in Debugger
\fs20 \
\
If I do a crashing calculation and then a timeout, I usually get EXC_SOFTWARE.\
A backtrace:\
\
\pard\tx480\tx960\tx1440\tx1920\tx2400\tx2880\tx3360\tx3840\tx4320\tx4800\tx5280\tx5760\tx6240\tx6720\tx7200\tx7680\tx8160\tx8640\tx9120\tx9600\tx10080\tx10560\tx11040\tx11520\tx12000\tx12480\tx12960\tx13440\tx13920\tx14400\tx14880\tx15360\tx15840\tx16320\tx16800\tx17280\tx17760\tx18240\tx18720\tx19200\tx19680\tx20160\tx20640\tx21120\tx21600\tx22080\tx22560\tx23040\tx23520\tx24000\tx24480\tx24960\tx25440\tx25920\tx26400\tx26880\tx27360\tx27840\tx28320\tx28800\tx29280\tx29760\tx30240\tx30720\tx31200\tx31680\tx32160\tx32640\tx33120\tx33600\tx34080\tx34560\tx35040\tx35520\tx36000\tx36480\tx36960\tx37440\tx37920\tx38400\tx38880\tx39360\tx39840\tx40320\tx40800\tx41280\tx41760\tx42240\tx42720\tx43200\tx43680\tx44160\tx44640\tx45120\tx45600\tx46080\tx46560\tx47040\tx47520\tx48000\pardirnatural\partightenfactor0
\f2\fs24 \cf0 \CocoaLigature0 #0 0x943a3d46 in CFUniCharDecompose ()\
#1 0x94398610 in CFStringGetFileSystemRepresentation ()\
#2 0x9439855f in _CFStringGetFileSystemRepresentation ()\
#3 0x98d40975 in -[NSFileManager getFileSystemRepresentation:maxLength:withPath:] ()\
#4 0x98d4a9b0 in -[NSFileManager fileSystemRepresentationWithPath:] ()\
#5 0x98d4a8db in -[NSString(NSPathUtilities) fileSystemRepresentation] ()\
#6 0x98da3aa5 in -[NSConcreteTask launchWithDictionary:] ()\
#7 0x98da36e4 in -[NSConcreteTask launch] ()\
\pard\pardeftab720\partightenfactor0
\f0\fs20 \cf0 \CocoaLigature1 \
Here's a different backtrace:\
\
\pard\tx480\tx960\tx1440\tx1920\tx2400\tx2880\tx3360\tx3840\tx4320\tx4800\tx5280\tx5760\tx6240\tx6720\tx7200\tx7680\tx8160\tx8640\tx9120\tx9600\tx10080\tx10560\tx11040\tx11520\tx12000\tx12480\tx12960\tx13440\tx13920\tx14400\tx14880\tx15360\tx15840\tx16320\tx16800\tx17280\tx17760\tx18240\tx18720\tx19200\tx19680\tx20160\tx20640\tx21120\tx21600\tx22080\tx22560\tx23040\tx23520\tx24000\tx24480\tx24960\tx25440\tx25920\tx26400\tx26880\tx27360\tx27840\tx28320\tx28800\tx29280\tx29760\tx30240\tx30720\tx31200\tx31680\tx32160\tx32640\tx33120\tx33600\tx34080\tx34560\tx35040\tx35520\tx36000\tx36480\tx36960\tx37440\tx37920\tx38400\tx38880\tx39360\tx39840\tx40320\tx40800\tx41280\tx41760\tx42240\tx42720\tx43200\tx43680\tx44160\tx44640\tx45120\tx45600\tx46080\tx46560\tx47040\tx47520\tx48000\pardirnatural\partightenfactor0
\f2\fs24 \cf0 \CocoaLigature0 #0 0x904091a4 in spin_unlock ()\
#1 0x9042fc4b in szone_force_unlock ()\
#2 0x9042fbc5 in _malloc_fork_parent ()\
#3 0x9042fb32 in _cthread_fork_parent ()\
#4 0x9042f93f in fork ()\
#5 0x98da36e4 in -[NSConcreteTask launch] ()\
\
#0 0x904038da in mach_msg_trap ()\
#1 0x90404047 in mach_msg ()\
#2 0x90427515 in mach_port_type ()\
#3 0x943c2a6f in _CFMachPortCreateWithPort2 ()\
#4 0x943c2a05 in CFMachPortCreateWithPort ()\
#5 0x98d82c5a in -[NSMachPort initWithMachPort:options:] ()\
#6 0x98d82b0f in -[NSMachPort init] ()\
#7 0x98da580a in +[NSPort port] ()\
#8 0x98da42a9 in -[NSConcreteTask launchWithDictionary:] ()\
#9 0x98da36e4 in -[NSConcreteTask launch] ()\
\
\pard\pardeftab720\partightenfactor0
\f0\fs20 \cf0 \CocoaLigature1 If I just do the crash but not the timeout, then when I try to close the window, I get EXC_BAD_ACCESS. There is no backtrace. If I make the tool exit with a nonzero code without crashing, this does not happen.\
\
One time, after just the crash, I got EXC_SOFTWARE a few seconds later:\
\
\pard\tx480\tx960\tx1440\tx1920\tx2400\tx2880\tx3360\tx3840\tx4320\tx4800\tx5280\tx5760\tx6240\tx6720\tx7200\tx7680\tx8160\tx8640\tx9120\tx9600\tx10080\tx10560\tx11040\tx11520\tx12000\tx12480\tx12960\tx13440\tx13920\tx14400\tx14880\tx15360\tx15840\tx16320\tx16800\tx17280\tx17760\tx18240\tx18720\tx19200\tx19680\tx20160\tx20640\tx21120\tx21600\tx22080\tx22560\tx23040\tx23520\tx24000\tx24480\tx24960\tx25440\tx25920\tx26400\tx26880\tx27360\tx27840\tx28320\tx28800\tx29280\tx29760\tx30240\tx30720\tx31200\tx31680\tx32160\tx32640\tx33120\tx33600\tx34080\tx34560\tx35040\tx35520\tx36000\tx36480\tx36960\tx37440\tx37920\tx38400\tx38880\tx39360\tx39840\tx40320\tx40800\tx41280\tx41760\tx42240\tx42720\tx43200\tx43680\tx44160\tx44640\tx45120\tx45600\tx46080\tx46560\tx47040\tx47520\tx48000\pardirnatural\partightenfactor0
\f2\fs24 \cf0 \CocoaLigature0 #0 0x904038da in mach_msg_trap ()\
#1 0x90404047 in mach_msg ()\
#2 0x943c677f in __CFRunLoopRun ()\
#3 0x943c5864 in CFRunLoopRunSpecific ()\
#4 0x943c5691 in CFRunLoopRunInMode ()\
#5 0x926f5f0c in RunCurrentEventLoopInMode ()\
#6 0x926f5cc3 in ReceiveNextEventCommon ()\
#7 0x926f5b48 in BlockUntilNextEventMatchingListInMode ()\
#8 0x94779ac5 in _DPSNextEvent ()\
#9 0x94779306 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()\
#10 0x9473b49f in -[NSApplication run] ()\
\pard\pardeftab720\partightenfactor0
\f0\fs20 \cf0 \CocoaLigature1 \
Sometimes there are weird debugger messages:\
\
\pard\tx480\tx960\tx1440\tx1920\tx2400\tx2880\tx3360\tx3840\tx4320\tx4800\tx5280\tx5760\tx6240\tx6720\tx7200\tx7680\tx8160\tx8640\tx9120\tx9600\tx10080\tx10560\tx11040\tx11520\tx12000\tx12480\tx12960\tx13440\tx13920\tx14400\tx14880\tx15360\tx15840\tx16320\tx16800\tx17280\tx17760\tx18240\tx18720\tx19200\tx19680\tx20160\tx20640\tx21120\tx21600\tx22080\tx22560\tx23040\tx23520\tx24000\tx24480\tx24960\tx25440\tx25920\tx26400\tx26880\tx27360\tx27840\tx28320\tx28800\tx29280\tx29760\tx30240\tx30720\tx31200\tx31680\tx32160\tx32640\tx33120\tx33600\tx34080\tx34560\tx35040\tx35520\tx36000\tx36480\tx36960\tx37440\tx37920\tx38400\tx38880\tx39360\tx39840\tx40320\tx40800\tx41280\tx41760\tx42240\tx42720\tx43200\tx43680\tx44160\tx44640\tx45120\tx45600\tx46080\tx46560\tx47040\tx47520\tx48000\pardirnatural\partightenfactor0
\f2\fs24 \cf0 \CocoaLigature0 The program is not being run.\
\
Previous frame inner to this frame (gdb could not unwind past this frame)\
\pard\tx480\tx960\tx1440\tx1920\tx2400\tx2880\tx3360\tx3840\tx4320\tx4800\tx5280\tx5760\tx6240\tx6720\tx7200\tx7680\tx8160\tx8640\tx9120\tx9600\tx10080\tx10560\tx11040\tx11520\tx12000\tx12480\tx12960\tx13440\tx13920\tx14400\tx14880\tx15360\tx15840\tx16320\tx16800\tx17280\tx17760\tx18240\tx18720\tx19200\tx19680\tx20160\tx20640\tx21120\tx21600\tx22080\tx22560\tx23040\tx23520\tx24000\tx24480\tx24960\tx25440\tx25920\tx26400\tx26880\tx27360\tx27840\tx28320\tx28800\tx29280\tx29760\tx30240\tx30720\tx31200\tx31680\tx32160\tx32640\tx33120\tx33600\tx34080\tx34560\tx35040\tx35520\tx36000\tx36480\tx36960\tx37440\tx37920\tx38400\tx38880\tx39360\tx39840\tx40320\tx40800\tx41280\tx41760\tx42240\tx42720\tx43200\tx43680\tx44160\tx44640\tx45120\tx45600\tx46080\tx46560\tx47040\tx47520\tx48000\pardirnatural\partightenfactor0
\f0\fs20 \cf0 \CocoaLigature1 \
\pard\pardeftab720\partightenfactor0
\cf0 New in version 2.3:\
\
* The size and position of the window is now stored with documents.\
* There is a Preferences dialog where you can set text colors and a timeout.\
* The % sign is a built-in constant whose value is 0.01, so that for instance you can write 73% instead of 0.73.\
* Improper recursive functions will no longer freeze or crash PlainCalc; instead, you will get a message saying "Timed Out" or "Calculation Crashed".\
* If your language preferences specify that the decimal separator is a comma rather than a period, then PlainCalc expects you to enter decimals using the comma, and reports results that way. In this case, you must separate the parameters of a multi-parameter function using semicolons rather than commas.\
\
\
}