有没有办法在调试会话期间按类和方法名称跟踪/跟踪和记录所有方法?

时间:2022-04-05 19:14:00

I am not interested in logging into frameworks or under the covers but only at my source level code upon entry and exit of each method. I would like it to provide Class Name and Method Name and log it to file or at least have it fly by on the screen.

我没有兴趣登录框架或在封面下,但只有在每个方法的进入和退出时我的源代码代码。我希望它提供类名和方法名称并将其记录到文件或至少让它在屏幕上飞过。

My query is if it is possible with existing Xcode/Debugger/Instruments facilities, can I implement it in an easy way other than an NSLog statement at every method entry and exit, or is there a commercial tool that provides this capability ?

我的查询是,如果可以使用现有的Xcode / Debugger / Instruments工具,我是否可以在每个方法入口和出口处以除了NSLog语句之外的简单方式实现它,或者是否有提供此功能的商业工具?

I'm talking source methods here... not execution processes or threads. Thanks.

我在这里谈论源方法......不是执行进程或线程。谢谢。

2 个解决方案

#1


9  

Dave Dribin covers precisely this in his article Tracing Objective-C messages.

Dave Dribin在他的文章Tracing Objective-C messages中正是如此。

The part you are after is probably this:

您所追求的部分可能是这样的:

If you set the NSObjCMessageLoggingEnabled environment variable to YES, the Objective-C runtime will log all dispatched Objective-C messages to a file named /tmp/msgSends-<pid>.

如果将NSObjCMessageLoggingEnabled环境变量设置为YES,则Objective-C运行时会将所有已分派的Objective-C消息记录到名为/ tmp / msgSends- 的文件中。

#2


2  

Xtrace (https://github.com/johnno1962/Xtrace) has many features and works well for tracing Objective-C. One needs source access to their project, like you appear to have, and can emit messages on entry/exit, like you appear to want.

Xtrace(https://github.com/johnno1962/Xtrace)具有许多功能,可以很好地跟踪Objective-C。一个人需要源代码访问他们的项目,就像你似乎有,并且可以在进入/退出时发出消息,就像你想要的那样。

  • Debug-time configuration - can hard-code or configure tracing while debugging
  • 调试时配置 - 可以在调试时硬编码或配置跟踪

  • Uncomplicated integration - one .mm and one .h
  • 简单的集成 - 一个.mm和一个.h

  • NSRegularExpression matching - classes, methods, types
  • NSRegularExpression匹配 - 类,方法,类型

#1


9  

Dave Dribin covers precisely this in his article Tracing Objective-C messages.

Dave Dribin在他的文章Tracing Objective-C messages中正是如此。

The part you are after is probably this:

您所追求的部分可能是这样的:

If you set the NSObjCMessageLoggingEnabled environment variable to YES, the Objective-C runtime will log all dispatched Objective-C messages to a file named /tmp/msgSends-<pid>.

如果将NSObjCMessageLoggingEnabled环境变量设置为YES,则Objective-C运行时会将所有已分派的Objective-C消息记录到名为/ tmp / msgSends- 的文件中。

#2


2  

Xtrace (https://github.com/johnno1962/Xtrace) has many features and works well for tracing Objective-C. One needs source access to their project, like you appear to have, and can emit messages on entry/exit, like you appear to want.

Xtrace(https://github.com/johnno1962/Xtrace)具有许多功能,可以很好地跟踪Objective-C。一个人需要源代码访问他们的项目,就像你似乎有,并且可以在进入/退出时发出消息,就像你想要的那样。

  • Debug-time configuration - can hard-code or configure tracing while debugging
  • 调试时配置 - 可以在调试时硬编码或配置跟踪

  • Uncomplicated integration - one .mm and one .h
  • 简单的集成 - 一个.mm和一个.h

  • NSRegularExpression matching - classes, methods, types
  • NSRegularExpression匹配 - 类,方法,类型