在Xcode/lldb中查看内存分配的一种方法 [英] A way to view memory allocation in Xcode / lldb

查看:402
本文介绍了在Xcode/lldb中查看内存分配的一种方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的程序,并设置了一个断点,以查看如何在调试界面(而不是例如valgrind)中监视内存分配:

I have a simple program and set a breakpoint to see how to monitor memory allocation within a debugging interface (instead of, for example, with valgrind):

以上程序应分配大量内存.似乎左侧的内存"图标与动态内存分配无关(也许与Xcode本身正在使用的内存量有关).是否有一条命令可以查看lldb中已分配了多少内存(例如,类似于(gdb) call malloc_stats())?我知道有一个Instruments应用程序(我已经使用过),但是我更感兴趣能够在调试过程中逐步了解总内存使用情况.或者,是否有一些GUI命令/面板会显示此内容?

The above program should allocate a lot of memory. It seems like the "Memory" icon on the left is unrelated to dynamic memory allocation (perhaps it's related to the amount of memory Xcode itself is using). Is there a command to see how much memory has been allocated within lldb, for example, similar to (gdb) call malloc_stats()? I know there is the Instruments application (which I've used), but I'm more interested in being able to step through the total memory usage while debugging it. Or, is there some GUI command/panel that will show this?

推荐答案

内存量表确实反映了程序分配的内存.如果您按照Jason的建议进行操作,则会发现随着分配更多的内存而增加.

The memory gauge does reflect the memory your program allocates. If you do what Jason suggests, you will see that rise as you allocate more memory.

有两个命令:内存区域"和"malloc_info",它们将告诉您分配历史记录或包含特定地址的内存状态.但是lldb没有通用的显示所有分配的内存区域"命令,例如malloc_stats.

There are a couple of commands: "memory region" and "malloc_info", that will tell you the allocation history or state of memory containing a particular address. But lldb doesn't have a general "show me all allocated memory regions" command, like malloc_stats.

您还可以使用Xcode的调试内存图"按钮查看程序中的内存分配-包括所有Malloc块.

You can also use the Xcode "Debug Memory Graph" button to view the memory allocations - including all the Malloc blocks - in your program.

这篇关于在Xcode/lldb中查看内存分配的一种方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆