首页 > 解决方案 > Windbg Linq 用于托管对象

问题描述

为了迭代原生对象,我可以将其存储在 windbg 变量中,然后linq对 windbg 中的字段进行查询以过滤有趣的对象。

>  dx @$usedSessions = (*((FabricRuntime!std::unordered_map<unsigned __int64,std::shared_ptr<Store::EseLocalStore::EsePoolItem>,std::hash<unsigned __int64>,std::equal_to<unsigned __int64>,std::allocator<std::pair<unsigned __int64 const ,std::shared_ptr<Store::EseLocalStore::EsePoolItem> > > > *)0x1dfff35f1a8))
> dx @$usedSessions.Take(2).Select(s => s.second->session_->sessionId_)

但是dxwindbg 命令对于sos命令失败:

0:045> dx @$Txs = !dumpheap -live -type System.Fabric.Transaction
Error: Unexpected token at 'System.Fabric.Transaction'

我可以在 windbg 中使用 Linq 迭代托管对象吗?

标签: c#linqwindbgsos

解决方案


如果您不喜欢与 结合使用的 WinDbg.foreach循环,!dumpheap -short我能想到的最接近的是NetExt WinDbg Extension

它可以像

!wfrom -type *.HttpContext 
  where ( ($contains(_request._url.m_String, "http:")) && (_response._statuscode != 0n200) ) 
  select $addr(), _request._url.m_String, _response._statusCode

来源:NetExt 文档示例


推荐阅读