Repository navigation
Closed
Closed
Copy link
Description
This potential issue is found by code review.
The VerifyObject call here is used to power the !VerifyObj command.
diagnostics/src/SOS/Strike/gcroot.cpp
Lines 1703 to 1716 in 24cfdb2
| BOOL VerifyObject(const GCHeapDetails &heap, DWORD_PTR objAddr, DWORD_PTR MTAddr, size_t objSize, BOOL bVerifyMember) | |
| { | |
| // This is only used by the other VerifyObject function if bVerifyMember is true, | |
| // so we only initialize it if we need it for verifying object members. | |
| DacpHeapSegmentData seg; | |
| if (bVerifyMember) | |
| { | |
| // if we fail to find the segment, we cannot verify the object's members | |
| bVerifyMember = FindSegment(heap, seg, objAddr); | |
| } | |
| return VerifyObject(heap, seg, objAddr, MTAddr, objSize, bVerifyMember); | |
| } |
If I read the code correctly, bVerifyMember is reset to FALSE if FindSegment fails. Now FindSegment searches only from the small object heap segments.
diagnostics/src/SOS/Strike/gcroot.cpp
Lines 1642 to 1701 in 24cfdb2
| BOOL FindSegment(const GCHeapDetails &heap, DacpHeapSegmentData &seg, CLRDATA_ADDRESS addr) | |
| { | |
| if (heap.has_regions) | |
| { | |
| CLRDATA_ADDRESS dwAddrSeg; | |
| for (UINT n = 0; n <= GetMaxGeneration(); n++) | |
| { | |
| dwAddrSeg = (DWORD_PTR)heap.generation_table[n].start_segment; | |
| while (dwAddrSeg != 0) | |
| { | |
| if (IsInterrupt()) | |
| return FALSE; | |
| if (seg.Request(g_sos, dwAddrSeg, heap.original_heap_details) != S_OK) | |
| { | |
| ExtOut("Error requesting heap segment %p\n", SOS_PTR(dwAddrSeg)); | |
| return FALSE; | |
| } | |
| if (addr >= TO_TADDR(seg.mem) && | |
| addr < (dwAddrSeg == heap.ephemeral_heap_segment ? heap.alloc_allocated : TO_TADDR(seg.allocated))) | |
| { | |
| break; | |
| } | |
| dwAddrSeg = (DWORD_PTR)seg.next; | |
| } | |
| if (dwAddrSeg != 0) | |
| break; | |
| } | |
| } | |
| else | |
| { | |
| CLRDATA_ADDRESS dwAddrSeg = heap.generation_table[GetMaxGeneration()].start_segment; | |
| // Request the inital segment. | |
| if (seg.Request(g_sos, dwAddrSeg, heap.original_heap_details) != S_OK) | |
| { | |
| ExtOut("Error requesting heap segment %p.\n", SOS_PTR(dwAddrSeg)); | |
| return FALSE; | |
| } | |
| // Loop while the object is not in range of the segment. | |
| while (addr < TO_TADDR(seg.mem) || | |
| addr >= (dwAddrSeg == heap.ephemeral_heap_segment ? heap.alloc_allocated : TO_TADDR(seg.allocated))) | |
| { | |
| // get the next segment | |
| dwAddrSeg = seg.next; | |
| // We reached the last segment without finding the object. | |
| if (dwAddrSeg == NULL) | |
| return FALSE; | |
| if (seg.Request(g_sos, dwAddrSeg, heap.original_heap_details) != S_OK) | |
| { | |
| ExtOut("Error requesting heap segment %p.\n", SOS_PTR(dwAddrSeg)); | |
| return FALSE; | |
| } | |
| } | |
| } | |
| return TRUE; | |
| } |
Yes, the region case has a bug, ignore it for now ...
As GetMaxGeneration() returns 2, this will never search for the large object heap or the pinned object heap. I do not believe this restriction is intentional, since gc_heap::verify_heap in gc.cpp explicitly includes them.
Activity
tommcdon commentedon Apr 22, 2021
@cshung feel free to submit a PR
Maoni0 commentedon Apr 23, 2021
I agree this should include LOH and POH if present. I was looking at this code and noticed that the other check, before we can verify members wrt BGC, also needs to be updated for regions, I've filed issue #2208 to track it.
cshung commentedon Jul 13, 2021
This comment is meant to explain the work better for the community.
To get started, it is helpful to explain what this work is for. This work is an enhancement of the
dotnet-sostool used for debugging .NET Core applications. Here is a brief instruction on how to get started.Since we are working on the debugger (technically, just a debugger extension), we do not need to change .NET Core itself, which means we can simply install one online. Here is a link for downloading .NET Core.
We will need a build for this repo, to build this repo, simply use the
Build.cmdcommand.This description assumes the work is done on Windows.
Once .NET Core is installed, we can create a new HelloWorld project as follow:
This creates a HelloWorld console application. To reproduce the bug, we modify the code as follow:
This program intentionally pause right after creating a large object, giving us opportunity to reproduce the bug.
It should be straightforward to try it out:
Next, we wanted to debug it. To do that, we install the Debugger Tools for Windows.
After installation, we can debug the process as follow:
The debugger windows should pop up with a command window, just hit g (stands for go) to continue executing the process, the process would launch and then stop at break.
So far, these are all capabilities of the Debugger Tools for Windows. Next, we want to exercise our own code. The component we are using here is named Son of Strike, or
sosfor short. It is an extension of the Debugger Tools for Windows. By default, the installation comes with a version of it, and we want to use our, therefore, we will unload the one come with the installation first by typing this into the command window:Next, we want to load our own, so we type this into the command window:
At this point, we will be running our own version of
sos.dll. Now let's inspect the objects:First, we look at the stack to find out where is the object array, it should be the non-null local
As we expect, the object array has one element and it is the big object we are looking for:
The string
sis currently null, as expected, now we will intentionally corrupt the object by writing garbage in it and then we confirm the object is indeed corrupted.Finally, we get to repro our bug.
!VerifyObjis unable to detect the corruption.The initial bug description should explain why we have this bug, good luck fixing it :)
leculver commentedon Mar 10, 2023
Hello! I'm working on verifyobject as part of #3736, so I've assigned this to myself, thanks!