• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to log arguments in runtime?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to log arguments in runtime?


  • Subject: How to log arguments in runtime?
  • From: Guillermo Moral <email@hidden>
  • Date: Wed, 22 Jun 2011 11:40:31 -0300

I created a new function to log every method from a class in runtime.


The problem that I have is in this line :


id value = va_arg(stackFrame, id);


Doesn`t convert the type of object inside the arguments.


Any idea on what I'm doing wrong? Is there another way to do this?


   void InitDebug ( id self, SEL _cmd, ...)

{

 id receiver = self;

    SEL receiverSelector = _cmd;

 va_list stackFrame;

 va_start(stackFrame, _cmd);

 NSString* threadString = [NSString stringWithFormat:@"%@", [NSThread
currentThread]];

 NSMutableString* logString = [NSMutableString string];

 [logString appendString:[NSString stringWithFormat: @"After - Thread:%@ -
Class:%@ - Method:%@",

      threadString,

      NSStringFromClass([receiver class]),

      NSStringFromSelector(receiverSelector)]];

 NSMethodSignature *signature

    = [receiver methodSignatureForSelector:receiverSelector];



    NSUInteger count = [signature numberOfArguments];

 if (count == 2)

    {

 [logString appendString:[NSString stringWithFormat:@" None"]];

}

     NSUInteger index = 2;

     for (; index < count; index++)

    {

        const char *argType = [signature getArgumentTypeAtIndex:index];



        if ((strlen(argType) > 1)

 && (strchr("{^", argType[0]) == NULL)

 && (strcmp("@?", argType) != 0))

        {

            [NSException raise:NSInvalidArgumentException

                        format:@"Cannot handle argument type '%s'.",
argType];

        }

#define IS_EQUAL 0

        if (strcmp(argType, @encode(id)) == IS_EQUAL)

        {

            id value = va_arg(stackFrame, id);

            if (!value)

            {



            }

        }

    }

 NSLog(@"%@",logString);

 va_end(stackFrame);

 }


--
Guillermo Moral
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: How to log arguments in runtime?
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: Synthesised properties and additional actions
  • Next by Date: Re: Help Book question
  • Previous by thread: Re: tooltips not firing on first try
  • Next by thread: Re: How to log arguments in runtime?
  • Index(es):
    • Date
    • Thread