[Lldb-commits] [lldb] r326374 - Add ability to collect memory limit.

Han Ming Ong via lldb-commits lldb-commits at lists.llvm.org
Wed Feb 28 14:18:45 PST 2018


Author: hanming
Date: Wed Feb 28 14:18:45 2018
New Revision: 326374

URL: http://llvm.org/viewvc/llvm-project?rev=326374&view=rev
Log:
Add ability to collect memory limit.

Reviewer: Jason Molenda

<rdar://problem/37686560>

Modified:
    lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj
    lldb/trunk/tools/debugserver/source/DNBDefs.h
    lldb/trunk/tools/debugserver/source/MacOSX/MachTask.mm
    lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.cpp
    lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.h
    lldb/trunk/tools/debugserver/source/debugserver-entitlements.plist

Modified: lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj?rev=326374&r1=326373&r2=326374&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj Wed Feb 28 14:18:45 2018
@@ -875,6 +875,8 @@
 					"$(LLDB_COMPRESSION_CFLAGS)",
 					"$(LLDB_ZLIB_CFLAGS)",
 					"$(LLDB_OS_LOG_CFLAGS)",
+					"-isystem",
+					"$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders",
 				);
 				"OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)";
 				OTHER_LDFLAGS = "";
@@ -973,6 +975,8 @@
 					"$(LLDB_COMPRESSION_CFLAGS)",
 					"$(LLDB_ZLIB_CFLAGS)",
 					"$(LLDB_OS_LOG_CFLAGS)",
+					"-isystem",
+					"$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders",
 				);
 				"OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)";
 				OTHER_LDFLAGS = "";
@@ -1070,6 +1074,8 @@
 					"$(LLDB_COMPRESSION_CFLAGS)",
 					"$(LLDB_ZLIB_CFLAGS)",
 					"$(LLDB_OS_LOG_CFLAGS)",
+					"-isystem",
+					"$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders",
 				);
 				"OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)";
 				OTHER_LDFLAGS = "";
@@ -1504,6 +1510,8 @@
 					"$(LLDB_COMPRESSION_CFLAGS)",
 					"$(LLDB_ZLIB_CFLAGS)",
 					"$(LLDB_OS_LOG_CFLAGS)",
+					"-isystem",
+					"$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders",
 				);
 				"OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)";
 				"OTHER_LDFLAGS[sdk=iphoneos*][arch=*]" = (
@@ -1644,6 +1652,8 @@
 					"$(LLDB_COMPRESSION_CFLAGS)",
 					"$(LLDB_ZLIB_CFLAGS)",
 					"$(LLDB_OS_LOG_CFLAGS)",
+					"-isystem",
+					"$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders",
 				);
 				"OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)";
 				"OTHER_LDFLAGS[sdk=iphoneos*][arch=*]" = (
@@ -1855,6 +1865,8 @@
 					"$(LLDB_COMPRESSION_CFLAGS)",
 					"$(LLDB_ZLIB_CFLAGS)",
 					"$(LLDB_OS_LOG_CFLAGS)",
+					"-isystem",
+					"$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders",
 				);
 				"OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)";
 				OTHER_LDFLAGS = "";
@@ -1987,6 +1999,8 @@
 					"$(LLDB_COMPRESSION_CFLAGS)",
 					"$(LLDB_ZLIB_CFLAGS)",
 					"$(LLDB_OS_LOG_CFLAGS)",
+					"-isystem",
+					"$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders",
 				);
 				"OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)";
 				"OTHER_LDFLAGS[sdk=iphoneos*][arch=*]" = (

Modified: lldb/trunk/tools/debugserver/source/DNBDefs.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNBDefs.h?rev=326374&r1=326373&r2=326374&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/DNBDefs.h (original)
+++ lldb/trunk/tools/debugserver/source/DNBDefs.h Wed Feb 28 14:18:45 2018
@@ -353,6 +353,8 @@ enum DNBProfileDataScanType {
 
   eProfileEnergy = (1 << 9),
 
+  eProfileMemoryCap = (1 << 15),
+
   eProfileAll = 0xffffffff
 };
 

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachTask.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachTask.mm?rev=326374&r1=326373&r2=326374&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachTask.mm (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachTask.mm Wed Feb 28 14:18:45 2018
@@ -349,12 +349,14 @@ std::string MachTask::GetProfileData(DNB
   }
 
   vm_statistics64_data_t vminfo;
-  uint64_t physical_memory;
-  mach_vm_size_t anonymous = 0;
-  mach_vm_size_t phys_footprint = 0;
+  uint64_t physical_memory = 0;
+  uint64_t anonymous = 0;
+  uint64_t phys_footprint = 0;
+  uint64_t memory_cap = 0;
   if (m_vm_memory.GetMemoryProfile(scanType, task, task_info,
                                    m_process->GetCPUType(), pid, vminfo,
-                                   physical_memory, anonymous, phys_footprint)) {
+                                   physical_memory, anonymous,
+                                   phys_footprint, memory_cap)) {
     std::ostringstream profile_data_stream;
 
     if (scanType & eProfileHostCPU) {
@@ -419,6 +421,10 @@ std::string MachTask::GetProfileData(DNB
       profile_data_stream << "phys_footprint:" << phys_footprint << ';';
     }
     
+    if (scanType & eProfileMemoryCap) {
+      profile_data_stream << "mem_cap:" << memory_cap << ';';
+    }
+    
 #ifdef LLDB_ENERGY
     if (scanType & eProfileEnergy) {
       struct rusage_info_v2 info;

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.cpp?rev=326374&r1=326373&r2=326374&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.cpp Wed Feb 28 14:18:45 2018
@@ -19,6 +19,12 @@
 #include <mach/shared_region.h>
 #include <sys/sysctl.h>
 
+#if defined(WITH_FBS) || defined(WITH_BKS)
+extern "C" {
+#import <sys/kern_memorystatus.h>
+}
+#endif
+
 static const vm_size_t kInvalidPageSize = ~0;
 
 MachVMMemory::MachVMMemory() : m_page_size(kInvalidPageSize), m_err(0) {}
@@ -116,7 +122,8 @@ static uint64_t GetPhysicalMemory() {
 nub_bool_t MachVMMemory::GetMemoryProfile(
     DNBProfileDataScanType scanType, task_t task, struct task_basic_info ti,
     cpu_type_t cputype, nub_process_t pid, vm_statistics64_data_t &vminfo,
-    uint64_t &physical_memory, mach_vm_size_t &anonymous, mach_vm_size_t &phys_footprint)
+    uint64_t &physical_memory, uint64_t &anonymous,
+    uint64_t &phys_footprint, uint64_t &memory_cap)
 {
   if (scanType & eProfileHostMemory)
     physical_memory = GetPhysicalMemory();
@@ -142,6 +149,16 @@ nub_bool_t MachVMMemory::GetMemoryProfil
     }
   }
 
+#if defined(WITH_FBS) || defined(WITH_BKS)
+  if (scanType & eProfileMemoryCap) {
+    memorystatus_memlimit_properties_t memlimit_properties;
+    memset(&memlimit_properties, 0, sizeof(memlimit_properties));
+    if (memorystatus_control(MEMORYSTATUS_CMD_GET_MEMLIMIT_PROPERTIES, pid, 0, &memlimit_properties, sizeof(memlimit_properties)) == 0) {
+        memory_cap = memlimit_properties.memlimit_active;
+    }
+  }
+#endif
+
   return true;
 }
 

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.h?rev=326374&r1=326373&r2=326374&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachVMMemory.h Wed Feb 28 14:18:45 2018
@@ -32,7 +32,8 @@ public:
   nub_bool_t GetMemoryProfile(DNBProfileDataScanType scanType, task_t task,
                               struct task_basic_info ti, cpu_type_t cputype,
                               nub_process_t pid, vm_statistics64_data_t &vminfo,
-                              uint64_t &physical_memory, mach_vm_size_t &anonymous, mach_vm_size_t &phys_footprint);
+                              uint64_t &physical_memory, uint64_t &anonymous,
+                              uint64_t &phys_footprint, uint64_t &memory_cap);
 
 protected:
   nub_size_t MaxBytesLeftInPage(task_t task, nub_addr_t addr, nub_size_t count);

Modified: lldb/trunk/tools/debugserver/source/debugserver-entitlements.plist
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/debugserver-entitlements.plist?rev=326374&r1=326373&r2=326374&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/debugserver-entitlements.plist (original)
+++ lldb/trunk/tools/debugserver/source/debugserver-entitlements.plist Wed Feb 28 14:18:45 2018
@@ -24,5 +24,7 @@
     <true/>
     <key>com.apple.security.network.client</key>
     <true/>
+    <key>com.apple.private.memorystatus</key>
+    <true/>
 </dict>
 </plist>




More information about the lldb-commits mailing list