如何在设备上使用MallocStackLogging?

发布于 2024-10-19 22:30:11 字数 1245 浏览 4 评论 0原文

我的 iPhone 应用程序出现内存问题,我想使用 MallocStackLogging。该错误涉及陀螺仪,因此我必须在设备上而不是模拟器上进行调试。

我已经设置了 MallocStackLogging 环境变量,并且 iPhone 正确记录了 mallock 堆栈日志:

MyApp(1856) malloc: recording malloc stacks to disk using standard recorder
MyApp(1856) malloc: stack logs being written into /private/var/mobile/Applications/1FD1F8D2-5D30-4AA7-B426-C52FE20266DE/tmp/stack-logs.1856.MyApp.index
MyApp(1856) malloc: Please issue: cp /private/var/mobile/Applications/1FD1F8D2-5D30-4AA7- B426-C52FE20266DE/tmp/stack-logs.1856.MyApp.e8z3IL.link /tmp/

现在我该如何使用它们?

我可以使用 Xcode Organizer 将它们传输到 Mac。但是我应该如何处理这两个文件呢?

  • stack-logs.1856.MyApp.index
  • stack-logs.1856.MyApp.e8z3IL.link

我尝试在 Mac 上移动 /tmp 中的文件并调用:

$ malloc_history 1856 -all_events
malloc_history cannot examine process 1856 because the process does not exist.

显然, malloc_history 命令查找本地计算机上正在运行的进程。我缺少手动指定日志文件的选项。

有什么方法可以让它在(非越狱)设备上直接使用 Xcode 工作,或者在将日志传输到 Mac 后工作?

I've a memory issue in an iPhone app that I'd like to debug with MallocStackLogging. The error involves the gyroscope so I have to debug on the device not the simulator.

I've set the MallocStackLogging environment variable and the iPhone properly records the mallock stack logs:

MyApp(1856) malloc: recording malloc stacks to disk using standard recorder
MyApp(1856) malloc: stack logs being written into /private/var/mobile/Applications/1FD1F8D2-5D30-4AA7-B426-C52FE20266DE/tmp/stack-logs.1856.MyApp.index
MyApp(1856) malloc: Please issue: cp /private/var/mobile/Applications/1FD1F8D2-5D30-4AA7- B426-C52FE20266DE/tmp/stack-logs.1856.MyApp.e8z3IL.link /tmp/

Now how can I work with them?

I can transfer them to the Mac using the Xcode Organizer. But what should I do with these two files?

  • stack-logs.1856.MyApp.index
  • stack-logs.1856.MyApp.e8z3IL.link

I tried moving the files in /tmp on the Mac and called:

$ malloc_history 1856 -all_events
malloc_history cannot examine process 1856 because the process does not exist.

Clearly, the malloc_history command looks for running processes on the local machine. I'm missing an option to specify the log file manually.

Is there any way to get this to work either directly working with Xcode on the (non-jailbroken) device or after transferring the logs to the Mac?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月蹉跎了容颜 2024-10-26 22:30:11

这是我如何在 idevice 上使用 malloc 堆栈历史记录调试 APP,这确实很复杂,但我没有其他方法来处理自动释放池内存问题。

  1. 您需要一个安装了开发人员工具的越狱设备,然后您就有了 gdb。

  2. 要启用malloc堆栈登录,您需要设置环境变量MallocStackLoggingNoCompact和MallocStackLogging,我们需要一些技巧来做到这一点。

首先,我们需要授予您的应用程序 root 权限。

 mv -f /User/Application/xxxxxxxxxxxxx/YOUR_APP.app /Application/YOUR_APP.app
 cd /Application
 chown -R root:wheel YOUR_APP.app
 chmod 4755 YOUR_APP.app/YOUR_APP

重命名你的程序

mv YOUR_APP.app/YOUR_APP   YOUR_APP.app/BACK_UP_NAME

使用一个简短的 shell 脚本来启动你的程序,这样我们就可以保留环境。将其保存到 YOUR_APP.app/YOUR_APP

#!/bin/bash
export MallocStackLogging=1
export MallocStackLoggingNoCompact=1

exec /Applications/YOUR_APP.app/BACK_UP_NAME

完成。

只需启动您的应用程序,触摸图标或使用打开命令,您就会在 /tmp 中看到堆栈日志文件
目录。

使用 ps aux | grep YOUR_APP 查找进程 ID,gdb -p PROCESS_ID 附加到进度,设置断点,尝试 info malloc ADDRESS,malloc 历史记录将显示。

Here is how I debug APP with malloc stack history on idevice, it's really complicate, but I have no other way to deal with an auto release pool memory problem.

  1. You need A jailbreak idevice with developer tools installed, then you have gdb.

  2. To enable malloc stack loggin, you need set environment variables MallocStackLoggingNoCompact and MallocStackLogging, we need some trick to do it.

First, we need grant your app root privilege.

 mv -f /User/Application/xxxxxxxxxxxxx/YOUR_APP.app /Application/YOUR_APP.app
 cd /Application
 chown -R root:wheel YOUR_APP.app
 chmod 4755 YOUR_APP.app/YOUR_APP

Rename your program

mv YOUR_APP.app/YOUR_APP   YOUR_APP.app/BACK_UP_NAME

Use a short shell scrip to start your program, so we can keep the env. Save it to YOUR_APP.app/YOUR_APP

#!/bin/bash
export MallocStackLogging=1
export MallocStackLoggingNoCompact=1

exec /Applications/YOUR_APP.app/BACK_UP_NAME

Done.

Just start you app, touching on the icon or use open command, you'll see a stack log file in /tmp
directory.

Use ps aux | grep YOUR_APP find process id, gdb -p PROCESS_ID attach to the progress, make a breakpoint, try info malloc ADDRESS, malloc history will show up.

岁吢 2024-10-26 22:30:11

在仪器应用程序中,可以诊断在模拟器或设备上运行的应用程序,分配仪器记录内存地址和分配历史记录。您可以按对象/分配类型或特定内存地址进行浏览。这可能是实现您想要的目标的最直接的方法。

在设备上运行 malloc_history 需要越狱以启用与设备的 ssh 连接,或者从代码中运行 malloc_history。但我不确定 iOS 设备上是否存在 malloc_history。并且 malloc_history 的帮助文本没有提到对日志文件而不是现有进程进行操作的选项,您可能已经知道这一点。

In the Instruments application, which can diagnose an app running in the simulator or on a device, the Allocations instrument records memory addresses and allocation histories. You can browse by object/allocation type or specific memory address. This is likely the most straightforward way to accomplish what you want.

Running malloc_history on the device would require either jailbreaking to enable an ssh connection to the device, or running malloc_history from within your code. But I am not certain whether malloc_history exists on an iOS device. And malloc_history's help text does not mention an option for operating on log files rather than an existing process, which you likely already know.

假装爱人 2024-10-26 22:30:11

我的意思并不是轻率,但您是否尝试过插入设备并在连接时在调试器下运行它?

我在设备上运行应用程序时进行了大量的调试。您确实需要在调试器下启动应用程序。

I don't mean to sound flippant, but have you tried plugging the device in and running it under the debugger whilst connected ?

I do extensive debugging whilst runnning the application on the device. You do need to start the application under the debugger.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文