{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350 {\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fmodern\fcharset0 Courier;} {\colortbl;\red255\green255\blue255;} \margl1440\margr1440\vieww10800\viewh11200\viewkind0 \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural \f0\b\fs30 \cf0 Lisp / Cocoa Application Debugging \b0\fs24 \ \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural \cf0 \ \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural \b\fs28 \cf0 Version 1.0 February 2011 \fs30 \ \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural \b0\fs24 \cf0 \ Copyright \'a9 2011 Paul L. Krueger All rights reserved.\ \ Paul L. Krueger, Ph.D.\ \ This is a collection of miscellaneous hints that I've collected as I have debugged my own applications.\ \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural \cf0 \ \b App runs fine under IDE, but hangs when run stand-alone \b0 \ \ If your application runs fine when loaded under the IDE, but hangs when run as a stand-alone application, there are a couple of common causes.\ \ It may be that you forgot to set the App Delegate Class for your application. Assuming that you are not including IDE resources in your app and haven't created your own custom application delegate class, you should use GUI::LISP-APPLICATION-DELEGATE. \ \ It may also be the case that some required source files were not included properly. This can happen if the App Development tools load something that is also needed by your code, but which is not loaded or required anywhere in your source code. The App Development tools are NOT included in the executable for your application. In fact, if they were to be included (or you include them accidentally within your code) this will cause problems at runtime for your application. So your code must include everything that it needs.\ \ Check the console log to see what might be there to tell you what the problem is.\ \ \b I included the AltConsole, but my application hangs without showing any errors \b0 \ \ The inclusion of the AltConsole program in your application may be of only limited value. When Objective-C error output is generated when running under the IDE, it will be directed toward the AltConsole, but in a stand-alone program error output (stderr or FD 1 in C terminology) is directed to the Console and only stdout (FD 0) will go to the AltConsole. So if you add something like:\ (format t " blah blah")\ to one of your lisp functions that is invoked as part of handling an event, then "blah blah" will be shown in the AltConsole window. But if some other error occurs, output from that will be found in the system console log (use Apple's "Console" application to see it).\ \ Error information printed to the console log may be significant. It may, for example, include backtrace information. So if your application hangs and you need to "Force Quit" it, check out the console output to see what is there.\ \ \b Console output doesn't help enough, I need a backtrace from my stand-alone app \b0 \ \ If the console output is insufficient and you really want a backtrace, you may be able to achieve that by creating a stand-alone application that also includes IDE resources. It helps to understand the roles of various sorts of objects in document-based applications to do this sort of debugging. Suppose that your application hangs when trying to open a new document. You could create a stand-alone version of your application that includes IDE resources and execute it. This will open up a listener window. In that window you could do something like the following:\ \ \f1 Welcome to Clozure Common Lisp Version 1.7-dev-r14583M-trunk (DarwinX8664)!\ ? (setf dc (#/sharedDocumentController ns:ns-document-controller))\ # (#x1485C0)>\ ? (#/defaultType dc)\ #\ ? (#/documentClassForType: dc *)\ #\ ? (#/newDocument: dc (%null-ptr)) \f0 \ \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural \cf0 \ This will presumably show some sort of error and you can use :b to generate a backtrace, just as you would in an AppConsole window.\ \ In general if you find a way to call the same code from the listener that would be called in response to some event, you will have access to backtraces in the listener.\ \ \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural \b \cf0 My re-opened document is different from what it was when I saved it \b0 \ \ There are a few possible problems. You may have forgotten to define a "archive-slots" method for your document class or for some other class whose instances are contained either directly or indirectly in your instance slots. This specifies what slots in instances of that class will be saved. The default method returns a set that includes all non :foreign-type slots. This may or may not be right for your application. You may well want to include some :foreign-type slots and avoid saving some of your normal lisp slots.\ \ Another possible problem is that you needed to do some additional computation to derive values for some of the slots that are not saved, but failed to define the needed "document-did-open" method. This method can be used to finalize the initialization of a document (either new or opened from a saved file).\ \ A third possible problem is that there is some bug in the data conversion methods that are supplied which does not restore the save value that was originally in the slot. You can prove or disprove this by calling (iu::lisp-to-ns-object ) and then (iu::ns-to-lisp-object ) to see whether this succeeds. There are some additional optional arguments to these functions, so it may be the case that there are bugs here even if this test succeeds. If you believe there may be an error for some data type, email the details to plkruegercomcast.net and I'll try to resolve the problem.\ \ \ }