swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

R:objc_trace


From: Ferraris
Subject: R:objc_trace
Date: Mon, 12 Jul 1999 07:09:22 +0200

        Hi,

        I have been wonking with Swarm since last October, to write a 
generalized
application based on Classifier Systems for my dissertation in ecomomics
(University of Turin, Italy). 

        To have a trace of my code, I have found very useful to employ a macro 
to
enable or disable a lot of print-statements, previously inserted in the
code. Using the macro, traces of the object work can be easy obtained.
 
I use a file, named Trace.h in my applications; it contains statements fo
the compiler. as:

#define TRACEx(A) //

The suffix "x" is intended to diversify macroes to trace single objects or
operations. 

All the objects in the project include Trace.h, with the statement:

#import "Trace.h"

At the top of the code of each method (in the .m file), after variable
declaration, we have to place:

TRACEx(printf("\n%8X obj-name entry selector: %y \n",self,parm1-var-name);)
TRACEx(printf("                       second-parm-name:
%y\n",parm2-var-name);)

At the end of the method, just before the return statement, another
trace-statement can be coded: 

TRACEx(printf("%8X obj-name exit selector: %y\n",self,return-var-name);)

where %y is the appropriate format to print the variables; parm-var-name
are the names of the variables that contain input-values, sent to the
object, and return-var-name is the variable that contains the value
returned by the method. The format %8X is used to print the address of the
object, contained in self, as an hexadecimal value.
  
Note that the printf-statements showed before are an example: any
instruction, can be inserted as argument of TRACE. 

Compiling the programs each TRACEx is handled as a comment: no
print-instructions are inserted in the executable file. When traces are
needed, the appropriate macroes have to be modified as follows:

#define TRACEx(A) //         becomes       #define TRACEx(A) A
     
Then the project has to be compiled: this way the compiler will transform
each macro in the value of the argument, i.e. the print-statement; running
the program, information are printend on standard output. In this case I
suggest of  sending the outputs to a file with the command:

executable-name > filename.

IN this way, the trace can be printed or sent to other people.  

The advantages are: 

- It is possible to put, as argument of the macro, any statement, also
computing-instructions and object-calls;
- No 'if statements' are required to control the activity.
- All trace-statements can be left in the source-code, also in distribuited
versions without any problem.
- It is possible to obtain traces about single objects or specific
operations.   

In objective-c is also possible to send the address of a variable, instead
the value. In this case I use a special object to print the contents of the
storage, from the sent address for a certain length, in hexadecimal form,
that I have called Dump; using dump no information about the original
casting of the variable are requested. 
If anyone is interested to that object, please mail me and I will be happy
to send the source  and more detailed information. 

Gigi

Gianluigi Ferraris via Sidoli 1 10135 TORINO  Tel +039 011 3176381 
Email: address@hidden   


----------
Da:     Gary Polhill[SMTP:address@hidden
Inviato:        venerdì 9 luglio 1999 13.41
A:      Swarm Support
Oggetto:        objc_trace


This is probably a question better directed elsewhere, but anyway ...

In objc-api.h, there is a rather nice looking variable called objc_trace:

/*
** Set this variable nonzero to print a line describing each
** message that is sent.  (this is currently disabled)
*/
extern BOOL objc_trace;

I tried setting objc_trace = YES in main.m of one of my Swarm simulations,
(with a #import <objc/objc-api.h>) and when it came to link time, I got the
rather disappointing error message:

Undefined                       first referenced
 symbol                             in file
objc_trace                          main.o

The gcc command did have a -lobjc in it -- though I did an nm of libobjc.a
and didn't find objc_trace. I'm wondering if anyone out there knows
anything about this -- like whether the "currently disabled" means "not
available at all" instead of "currently set to NO", as I had hoped.

Gary


-- 

Macaulay Land Use Research Institute, Craigiebuckler, Aberdeen. AB15 8QH
Tel: +44 (0) 1224 318611               Email: address@hidden

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.

<<application/ms-tnef>>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]