• windbg 命令 gchandles


    使用windbg导出dump文件

    .dump /ma D: estdump.dmp

    gchandles命令列出句柄,同时列出句柄引用的对象,演示代码如下:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Data;
    using System.Runtime.InteropServices;
    
    public class Example
    {
        static void Main(string[] args)
        {
            int[] arry = new int[10];
            for (int i = 0; i < 10; i++)
            {
                arry[i] = i;
            }
            GCHandle h1 = GCHandle.Alloc(arry, GCHandleType.Pinned);
            Console.ReadKey();
        }
    }


    windbg附加后,运行至ReadKey处,运行GCHandles

    0:000> !gchandles
              Handle Type                  Object     Size             Data Type
    00000000000a13a8 Strong      00000000027f2070       64                  System.Security.PermissionSet
    00000000000a13b0 Strong      00000000027f1440       48                  System.SharedStatics
    00000000000a13b8 Strong      00000000027f1368      160                  System.Threading.ThreadAbortException
    00000000000a13c0 Strong      00000000027f12c8      160                  System.Threading.ThreadAbortException
    00000000000a13c8 Strong      00000000027f1228      160                  System.ExecutionEngineException
    00000000000a13d0 Strong      00000000027f1188      160                  System.StackOverflowException
    00000000000a13d8 Strong      00000000027f10e8      160                  System.OutOfMemoryException
    00000000000a13e0 Strong      00000000027f1048      160                  System.Exception
    00000000000a13f8 Strong      00000000027f1538      216                  System.AppDomain
    00000000000a17d0 Pinned      00000000027f2ca8       64                  System.Int32[]
    00000000000a17d8 Pinned      00000000127f5710    16352                  System.Object[]
    00000000000a17e0 Pinned      00000000127f36f0     8192                  System.Object[]
    00000000000a17e8 Pinned      00000000127f32b0     1056                  System.Object[]
    00000000000a17f0 Pinned      00000000027f1408       24                  System.Object
    00000000000a17f8 Pinned      00000000127f1038     8792                  System.Object[]

     此时,可以看到对象是00000000027f2ca8 ,持有他的句柄是00000000000a17d0

    看下句柄内容:

    0:000> dd 00000000000a17d0
    00000000`000a17d0  027f2ca8 00000000 127f5710 00000000
    00000000`000a17e0  127f36f0 00000000 127f32b0 00000000
    00000000`000a17f0  027f1408 00000000 127f1038 00000000
    00000000`000a1800  00000000 00000000 00000000 00000000
    00000000`000a1810  00000000 00000000 00000000 00000000
    00000000`000a1820  00000000 00000000 00000000 00000000
    00000000`000a1830  00000000 00000000 00000000 00000000
    00000000`000a1840  00000000 00000000 00000000 00000000

     句柄中的前8个字节正好是持有的对象;

    补充:Pined句柄表示被固定不会被移动的对象。

  • 相关阅读:
    你敢说自己了解单例模式?
    关于线程池,那些你还不知道的事
    Dubbo透传traceId/logid的一种思路
    当BeanUtils遇到泛型
    Oval框架如何校验枚举类型的一种思路
    HttpClient(4.5.x)正确的使用姿势
    HttpClient官方sample代码的深入分析(连接池)
    Jaxb如何优雅的处理CData
    JAXB性能优化
    Jaxb对xml报文头的小修小改
  • 原文地址:https://www.cnblogs.com/thaughtZhao/p/4227151.html
Copyright © 2020-2023  润新知