xcode 如何在设备上使用MallocStackLogging?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5167557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:21:19  来源:igfitidea点击:

How to use MallocStackLogging on the device?

iphonexcodedebuggingmalloc-history

提问by Ortwin Gentz

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.

我想用MallocStackLogging. 该错误涉及陀螺仪,因此我必须在设备上而不是模拟器上进行调试。

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

我已经设置了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/

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?

我可以使用 Xcode Organizer 将它们传输到 Mac。但是这两个文件我该怎么办呢?

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

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

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

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

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

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

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?

有没有办法让它在(非越狱)设备上直接使用 Xcode 或在将日志传输到 Mac 后工作?

采纳答案by user3383333

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.

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

  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.

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

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

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

使用一个简短的 shell 脚本来启动你的程序,这样我们就可以保留 env。保存到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.

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

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

使用ps aux | grep YOUR_APPfind process id,gdb -p PROCESS_ID附加到进度,创建断点, try info malloc ADDRESS, malloc 历史将显示。

回答by bneely

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.

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

回答by ferdil

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.

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