Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
c36177f4
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c36177f4
编写于
4月 22, 2015
作者:
K
Kevin Halverson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2152 from KevinH-MS/CrossThreadCall
Use different mechanism for passing symbol reader to MTA...
上级
81c49e32
dc347252
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
79 addition
and
16 deletion
+79
-16
src/VisualStudio/Core/Def/Implementation/EditAndContinue/Interop/IENCSymbolReaderProvider.cs
...ation/EditAndContinue/Interop/IENCSymbolReaderProvider.cs
+1
-1
src/VisualStudio/Core/Def/Implementation/EditAndContinue/Interop/NativeMethods.cs
...f/Implementation/EditAndContinue/Interop/NativeMethods.cs
+28
-0
src/VisualStudio/Core/Def/Implementation/EditAndContinue/VsENCRebuildableProjectImpl.cs
...ementation/EditAndContinue/VsENCRebuildableProjectImpl.cs
+49
-15
src/VisualStudio/Core/Def/ServicesVisualStudio.csproj
src/VisualStudio/Core/Def/ServicesVisualStudio.csproj
+1
-0
未找到文件。
src/VisualStudio/Core/Def/Implementation/EditAndContinue/Interop/IENCSymbolReaderProvider.cs
浏览文件 @
c36177f4
...
...
@@ -10,6 +10,6 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.EditAndContinue
[
Guid
(
"B69910A9-4AD6-475F-859A-5DC0B1072A5D"
)]
internal
interface
IENCSymbolReaderProvider
{
void
GetSymbolReader
(
out
IntPtr
ppSymbolReaderMta
);
void
GetSymbolReader
(
[
MarshalAs
(
UnmanagedType
.
IUnknown
)]
out
object
ppSymbolReader
);
}
}
src/VisualStudio/Core/Def/Implementation/EditAndContinue/Interop/NativeMethods.cs
0 → 100644
浏览文件 @
c36177f4
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System
;
using
System.Runtime.InteropServices
;
namespace
Microsoft.VisualStudio.LanguageServices.Implementation.EditAndContinue.Interop
{
internal
static
class
NativeMethods
{
private
static
Guid
IID_IUnknown
=
new
Guid
(
0x00000000
,
0x0000
,
0x0000
,
0xC0
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x46
);
[
DllImport
(
"ole32.dll"
)]
private
static
extern
int
CoMarshalInterThreadInterfaceInStream
([
In
]
ref
Guid
riid
,
[
MarshalAs
(
UnmanagedType
.
IUnknown
)]
object
pUnk
,
out
IntPtr
ppStm
);
[
DllImport
(
"ole32.dll"
)]
private
static
extern
int
CoGetInterfaceAndReleaseStream
(
IntPtr
pStm
,
[
In
]
ref
Guid
riid
,
[
MarshalAs
(
UnmanagedType
.
IUnknown
)]
out
object
ppv
);
public
static
int
GetStreamForObject
(
object
pUnk
,
out
IntPtr
stream
)
{
return
CoMarshalInterThreadInterfaceInStream
(
ref
IID_IUnknown
,
pUnk
,
out
stream
);
}
public
static
int
GetObjectForStream
(
IntPtr
stream
,
out
object
pUnk
)
{
return
CoGetInterfaceAndReleaseStream
(
stream
,
ref
IID_IUnknown
,
out
pUnk
);
}
}
}
src/VisualStudio/Core/Def/Implementation/EditAndContinue/VsENCRebuildableProjectImpl.cs
浏览文件 @
c36177f4
...
...
@@ -23,6 +23,7 @@
using
Microsoft.DiaSymReader
;
using
Microsoft.VisualStudio.ComponentModelHost
;
using
Microsoft.VisualStudio.Editor
;
using
Microsoft.VisualStudio.LanguageServices.Implementation.EditAndContinue.Interop
;
using
Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
;
using
Microsoft.VisualStudio.LanguageServices.Utilities
;
using
Roslyn.Utilities
;
...
...
@@ -87,7 +88,7 @@ internal sealed class VsENCRebuildableProjectImpl
private
ISymUnmanagedReader
_pdbReader
;
private
IntPtr
_pdbReader
MtaPointer
;
private
IntPtr
_pdbReader
ObjAsStream
;
#
endregion
...
...
@@ -322,7 +323,7 @@ public int StopDebuggingPE()
_committedBaseline
=
null
;
_activeStatementIds
=
null
;
Debug
.
Assert
((
_pdbReader
==
null
)
==
(
_pdbReaderMtaPointer
==
IntPtr
.
Zero
));
Debug
.
Assert
((
_pdbReader
ObjAsStream
==
IntPtr
.
Zero
)
||
(
_pdbReader
==
null
));
if
(
_pdbReader
!=
null
)
{
...
...
@@ -330,8 +331,6 @@ public int StopDebuggingPE()
_pdbReader
=
null
;
}
_pdbReaderMtaPointer
=
IntPtr
.
Zero
;
// The HResult is ignored by the debugger.
return
VSConstants
.
S_OK
;
}
...
...
@@ -926,20 +925,20 @@ public unsafe int BuildForEnc(object pUpdatePE)
Debug
.
Assert
(
_lastEditSessionSummary
==
ProjectAnalysisSummary
.
ValidInsignificantChanges
||
_lastEditSessionSummary
==
ProjectAnalysisSummary
.
ValidChanges
);
var
updater
=
(
I
nterop
.
I
DebugUpdateInMemoryPE2
)
pUpdatePE
;
var
updater
=
(
IDebugUpdateInMemoryPE2
)
pUpdatePE
;
if
(
_committedBaseline
==
null
)
{
Interop
.
IENCDebugInfo
debugInfo
;
updater
.
GetENCDebugInfo
(
out
debugInfo
);
var
symbolReaderProvider
=
(
Interop
.
IENCSymbolReaderProvider
)
debugInfo
;
symbolReaderProvider
.
GetSymbolReader
(
out
_pdbReaderMtaPointer
);
var
hr
=
MarshalPdbReader
(
updater
,
out
_pdbReaderObjAsStream
)
;
if
(
hr
!=
VSConstants
.
S_OK
)
{
return
hr
;
}
_committedBaseline
=
EmitBaseline
.
CreateInitialBaseline
(
_metadata
,
GetBaselineEncDebugInfo
);
}
// ISymUnmanagedReader can only be accessed from an MTA thread,
// so dispatch it to one of thread pool threads, which are MTA
:
// ISymUnmanagedReader can only be accessed from an MTA thread,
// so dispatch it to one of thread pool threads, which are MTA
.
var
emitTask
=
Task
.
Factory
.
SafeStartNew
(
EmitProjectDelta
,
CancellationToken
.
None
,
TaskScheduler
.
Default
);
Deltas
delta
;
...
...
@@ -1050,9 +1049,17 @@ private EditAndContinueMethodDebugInformation GetBaselineEncDebugInfo(MethodDefi
if
(
_pdbReader
==
null
)
{
Debug
.
Assert
(
_pdbReaderMtaPointer
!=
IntPtr
.
Zero
);
object
pdbReaderObj
=
Marshal
.
GetObjectForIUnknown
(
_pdbReaderMtaPointer
);
_pdbReader
=
(
ISymUnmanagedReader
)
pdbReaderObj
;
// Unmarshal the symbol reader (being marshalled cross thread from STA -> MTA).
Debug
.
Assert
(
_pdbReaderObjAsStream
!=
IntPtr
.
Zero
);
object
pdbReaderObjMta
;
int
hr
=
NativeMethods
.
GetObjectForStream
(
_pdbReaderObjAsStream
,
out
pdbReaderObjMta
);
_pdbReaderObjAsStream
=
IntPtr
.
Zero
;
if
(
hr
!=
VSConstants
.
S_OK
)
{
log
.
Write
(
"Error unmarshaling object from stream."
);
return
default
(
EditAndContinueMethodDebugInformation
);
}
_pdbReader
=
(
ISymUnmanagedReader
)
pdbReaderObjMta
;
}
int
methodToken
=
MetadataTokens
.
GetToken
(
methodHandle
);
...
...
@@ -1138,6 +1145,33 @@ public int GetCurrentExceptionSpanPosition(uint id, VsTextSpan[] ptsNewPosition)
}
}
private
static
int
MarshalPdbReader
(
IDebugUpdateInMemoryPE2
updater
,
out
IntPtr
pdbReaderPointer
)
{
// ISymUnmanagedReader can only be accessed from an MTA thread, however, we need
// fetch the IUnknown instance (call IENCSymbolReaderProvider.GetSymbolReader) here
// in the STA. To further complicate things, we need to return synchronously from
// this method. Waiting for the MTA thread to complete so we can return synchronously
// blocks the STA thread, so we need to make sure the CLR doesn't try to marshal
// ISymUnmanagedReader calls made in an MTA back to the STA for execution (if this
// happens we'll be deadlocked). We'll use CoMarshalInterThreadInterfaceInStream to
// achieve this. First, we'll marshal the object in a Stream and pass a Stream pointer
// over to the MTA. In the MTA, we'll get the Stream from the pointer and unmarshal
// the object. The reader object was originally created on an MTA thread, and the
// instance we retrieved in the STA was a proxy. When we unmarshal the Stream in the
// MTA, it "unwraps" the proxy, allowing us to directly call the implementation.
// Another way to achieve this would be for the symbol reader to implement IAgileObject,
// but the symbol reader we use today does not. If that changes, we should consider
// removing this marshal/unmarshal code.
IENCDebugInfo
debugInfo
;
updater
.
GetENCDebugInfo
(
out
debugInfo
);
var
symbolReaderProvider
=
(
IENCSymbolReaderProvider
)
debugInfo
;
object
pdbReaderObjSta
;
symbolReaderProvider
.
GetSymbolReader
(
out
pdbReaderObjSta
);
int
hr
=
NativeMethods
.
GetStreamForObject
(
pdbReaderObjSta
,
out
pdbReaderPointer
);
Marshal
.
ReleaseComObject
(
pdbReaderObjSta
);
return
hr
;
}
#
region
Testing
#if DEBUG
...
...
src/VisualStudio/Core/Def/ServicesVisualStudio.csproj
浏览文件 @
c36177f4
...
...
@@ -24,6 +24,7 @@
<Compile
Include=
"Implementation\AnalyzerDependencyConflict.cs"
/>
<Compile
Include=
"Implementation\CompilationErrorTelemetry\CompilationErrorTelemetryIncrementalAnalyzer.cs"
/>
<Compile
Include=
"Implementation\Diagnostics\VisualStudioVenusSpanMappingService.cs"
/>
<Compile
Include=
"Implementation\EditAndContinue\Interop\NativeMethods.cs"
/>
<Compile
Include=
"Implementation\Interop\IComWrapperFactory.cs"
/>
<Compile
Include=
"Implementation\Library\FindResults\TreeItems\AbstractSourceTreeItem.cs"
/>
<Compile
Include=
"Implementation\Library\FindResults\TreeItems\MetadataDefinitionTreeItem.cs"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录