Change generation for NonGC objects for debugger (#89927)
authorEgor Bogatov <egorbo@gmail.com>
Tue, 8 Aug 2023 08:10:39 +0000 (10:10 +0200)
committerGitHub <noreply@github.com>
Tue, 8 Aug 2023 08:10:39 +0000 (10:10 +0200)
src/coreclr/debug/daccess/dacdbiimpl.cpp
src/coreclr/debug/daccess/request_svr.cpp
src/coreclr/inc/cordebug.idl
src/coreclr/pal/prebuilt/inc/cordebug.h

index 06ab494..67d5b1e 100644 (file)
@@ -6743,7 +6743,7 @@ HRESULT DacHeapWalker::InitHeapDataWks(HeapData *&pHeaps, size_t &pCount)
         seg = gen2.start_segment;
         for (; seg && (i < count); ++i)
         {
-            pHeaps[0].Segments[i].Generation = 2;
+            pHeaps[0].Segments[i].Generation = seg->flags & HEAP_SEGMENT_FLAGS_READONLY ? CorDebug_NonGC : CorDebug_Gen2;
             pHeaps[0].Segments[i].Start = (CORDB_ADDRESS)seg->mem;
             pHeaps[0].Segments[i].End = (CORDB_ADDRESS)seg->allocated;
 
@@ -6752,7 +6752,7 @@ HRESULT DacHeapWalker::InitHeapDataWks(HeapData *&pHeaps, size_t &pCount)
         seg = gen1.start_segment;
         for (; seg && (i < count); ++i)
         {
-            pHeaps[0].Segments[i].Generation = 1;
+            pHeaps[0].Segments[i].Generation = CorDebug_Gen1;
             pHeaps[0].Segments[i].Start = (CORDB_ADDRESS)seg->mem;
             pHeaps[0].Segments[i].End = (CORDB_ADDRESS)seg->allocated;
 
@@ -6771,7 +6771,7 @@ HRESULT DacHeapWalker::InitHeapDataWks(HeapData *&pHeaps, size_t &pCount)
             {
                 pHeaps[0].Segments[i].End = (CORDB_ADDRESS)seg->allocated;
             }
-            pHeaps[0].Segments[i].Generation = 0;
+            pHeaps[0].Segments[i].Generation = CorDebug_Gen0;
 
             seg = seg->next;
         }
@@ -6785,13 +6785,13 @@ HRESULT DacHeapWalker::InitHeapDataWks(HeapData *&pHeaps, size_t &pCount)
             if (seg.GetAddr() == (TADDR)*g_gcDacGlobals->ephemeral_heap_segment)
             {
                 pHeaps[0].Segments[i].End = (CORDB_ADDRESS)*g_gcDacGlobals->alloc_allocated;
-                pHeaps[0].Segments[i].Generation = 1;
+                pHeaps[0].Segments[i].Generation = CorDebug_Gen1;
                 pHeaps[0].EphemeralSegment = i;
             }
             else
             {
                 pHeaps[0].Segments[i].End = (CORDB_ADDRESS)seg->allocated;
-                pHeaps[0].Segments[i].Generation = 2;
+                pHeaps[0].Segments[i].Generation = seg->flags & HEAP_SEGMENT_FLAGS_READONLY ? CorDebug_NonGC : CorDebug_Gen2;
             }
 
             seg = seg->next;
@@ -6802,7 +6802,7 @@ HRESULT DacHeapWalker::InitHeapDataWks(HeapData *&pHeaps, size_t &pCount)
     seg = loh.start_segment;
     for (; seg && (i < count); ++i)
     {
-        pHeaps[0].Segments[i].Generation = 3;
+        pHeaps[0].Segments[i].Generation = CorDebug_LOH;
         pHeaps[0].Segments[i].Start = (CORDB_ADDRESS)seg->mem;
         pHeaps[0].Segments[i].End = (CORDB_ADDRESS)seg->allocated;
 
@@ -6813,7 +6813,7 @@ HRESULT DacHeapWalker::InitHeapDataWks(HeapData *&pHeaps, size_t &pCount)
     seg = poh.start_segment;
     for (; seg && (i < count); ++i)
     {
-        pHeaps[0].Segments[i].Generation = 4;
+        pHeaps[0].Segments[i].Generation = CorDebug_POH;
         pHeaps[0].Segments[i].Start = (CORDB_ADDRESS)seg->mem;
         pHeaps[0].Segments[i].End = (CORDB_ADDRESS)seg->allocated;
 
@@ -6995,13 +6995,13 @@ HRESULT DacDbiInterfaceImpl::GetHeapSegments(OUT DacDbiArrayList<COR_SEGMENT> *p
             }
             else
             {
-                // Otherwise, we have a gen2 or gen3 (LOH) segment
+                // Otherwise, we have a gen2, POH, LOH or NonGC
                 _ASSERTE(curr < total);
                 COR_SEGMENT &seg = (*pSegments)[curr++];
                 seg.start = heaps[i].Segments[j].Start;
                 seg.end = heaps[i].Segments[j].End;
 
-                _ASSERTE(heaps[i].Segments[j].Generation <= CorDebug_POH);
+                _ASSERTE(heaps[i].Segments[j].Generation <= CorDebug_NonGC);
                 seg.type = (CorDebugGenerationTypes)heaps[i].Segments[j].Generation;
                 seg.heap = (ULONG)i;
             }
index 3955d8f..ac0010e 100644 (file)
@@ -377,7 +377,7 @@ HRESULT DacHeapWalker::InitHeapDataSvr(HeapData *&pHeaps, size_t &pCount)
             seg = gen2.start_segment;
             for (; seg && (j < count); ++j)
             {
-                pHeaps[i].Segments[j].Generation = 2;
+                pHeaps[i].Segments[j].Generation = seg->flags & HEAP_SEGMENT_FLAGS_READONLY ? CorDebug_NonGC : CorDebug_Gen2;;
                 pHeaps[i].Segments[j].Start = (CORDB_ADDRESS)seg->mem;
                 pHeaps[i].Segments[j].End = (CORDB_ADDRESS)seg->allocated;
 
@@ -386,7 +386,7 @@ HRESULT DacHeapWalker::InitHeapDataSvr(HeapData *&pHeaps, size_t &pCount)
             seg = gen1.start_segment;
             for (; seg && (j < count); ++j)
             {
-                pHeaps[i].Segments[j].Generation = 1;
+                pHeaps[i].Segments[j].Generation = CorDebug_Gen1;
                 pHeaps[i].Segments[j].Start = (CORDB_ADDRESS)seg->mem;
                 pHeaps[i].Segments[j].End = (CORDB_ADDRESS)seg->allocated;
 
@@ -400,12 +400,12 @@ HRESULT DacHeapWalker::InitHeapDataSvr(HeapData *&pHeaps, size_t &pCount)
                 {
                     pHeaps[i].Segments[j].End = (CORDB_ADDRESS)pHeap->alloc_allocated;
                     pHeaps[i].EphemeralSegment = j;
-                    pHeaps[i].Segments[j].Generation = 0;
+                    pHeaps[i].Segments[j].Generation = CorDebug_Gen0;
                 }
                 else
                 {
                     pHeaps[i].Segments[j].End = (CORDB_ADDRESS)seg->allocated;
-                    pHeaps[i].Segments[j].Generation = 2;
+                    pHeaps[i].Segments[j].Generation = seg->flags & HEAP_SEGMENT_FLAGS_READONLY ? CorDebug_NonGC : CorDebug_Gen2;;
                 }
 
                 seg = seg->next;
@@ -421,12 +421,12 @@ HRESULT DacHeapWalker::InitHeapDataSvr(HeapData *&pHeaps, size_t &pCount)
                 {
                     pHeaps[i].Segments[j].End = (CORDB_ADDRESS)pHeap->alloc_allocated;
                     pHeaps[i].EphemeralSegment = j;
-                    pHeaps[i].Segments[j].Generation = 1;
+                    pHeaps[i].Segments[j].Generation = CorDebug_Gen1;
                 }
                 else
                 {
                     pHeaps[i].Segments[j].End = (CORDB_ADDRESS)seg->allocated;
-                    pHeaps[i].Segments[j].Generation = 2;
+                    pHeaps[i].Segments[j].Generation = seg->flags & HEAP_SEGMENT_FLAGS_READONLY ? CorDebug_NonGC : CorDebug_Gen2;;
                 }
 
                 seg = seg->next;
@@ -437,7 +437,7 @@ HRESULT DacHeapWalker::InitHeapDataSvr(HeapData *&pHeaps, size_t &pCount)
         seg = loh.start_segment;
         for (; seg && (j < count); ++j)
         {
-            pHeaps[i].Segments[j].Generation = 3;
+            pHeaps[i].Segments[j].Generation = CorDebug_LOH;
             pHeaps[i].Segments[j].Start = (CORDB_ADDRESS)seg->mem;
             pHeaps[i].Segments[j].End = (CORDB_ADDRESS)seg->allocated;
 
@@ -448,7 +448,7 @@ HRESULT DacHeapWalker::InitHeapDataSvr(HeapData *&pHeaps, size_t &pCount)
         seg = poh.start_segment;
         for (; seg && (j < count); ++j)
         {
-            pHeaps[i].Segments[j].Generation = 4;
+            pHeaps[i].Segments[j].Generation = CorDebug_POH;
             pHeaps[i].Segments[j].Start = (CORDB_ADDRESS)seg->mem;
             pHeaps[i].Segments[j].End = (CORDB_ADDRESS)seg->allocated;
 
index 18a1865..af3f6eb 100644 (file)
@@ -2513,6 +2513,7 @@ typedef enum CorDebugGenerationTypes
     CorDebug_Gen2 = 2,
     CorDebug_LOH  = 3,
     CorDebug_POH  = 4,
+    CorDebug_NonGC = 0x7FFFFFFF,
 } CorDebugGenerationTypes;
 
 typedef struct _COR_SEGMENT
index 7888daf..a9ec5ff 100644 (file)
@@ -6538,7 +6538,8 @@ enum CorDebugGenerationTypes
         CorDebug_Gen1   = 1,
         CorDebug_Gen2   = 2,
         CorDebug_LOH    = 3,
-        CorDebug_POH    = 4
+        CorDebug_POH    = 4,
+        CorDebug_NonGC  = 0x7FFFFFFF
     }   CorDebugGenerationTypes;
 
 typedef struct _COR_SEGMENT