@@ -75,8 +75,8 @@ class MethodMdbInfo
75
75
readonly Dictionary < EventRequest , BreakInfo > breakpoints = new Dictionary < EventRequest , BreakInfo > ( ) ;
76
76
readonly Dictionary < TypeMirror , string [ ] > type_to_source = new Dictionary < TypeMirror , string [ ] > ( ) ;
77
77
readonly Dictionary < string , long > symbolFilesTimestamps = new Dictionary < string , long > ( ) ;
78
- readonly Dictionary < string , TypeMirror > aliases = new Dictionary < string , TypeMirror > ( ) ;
79
- readonly Dictionary < string , TypeMirror > types = new Dictionary < string , TypeMirror > ( ) ;
78
+ readonly Dictionary < string , List < TypeMirror > > aliases = new Dictionary < string , List < TypeMirror > > ( ) ;
79
+ readonly Dictionary < string , List < TypeMirror > > types = new Dictionary < string , List < TypeMirror > > ( ) ;
80
80
readonly LinkedList < List < Event > > queuedEventSets = new LinkedList < List < Event > > ( ) ;
81
81
readonly Dictionary < long , long > localThreadIds = new Dictionary < long , long > ( ) ;
82
82
readonly List < BreakInfo > pending_bes = new List < BreakInfo > ( ) ;
@@ -562,17 +562,23 @@ public VirtualMachine VirtualMachine {
562
562
563
563
public TypeMirror GetType ( string fullName )
564
564
{
565
- TypeMirror tm ;
565
+ List < TypeMirror > typesList ;
566
566
567
- if ( ! types . TryGetValue ( fullName , out tm ) )
568
- aliases . TryGetValue ( fullName , out tm ) ;
569
-
570
- return tm ;
567
+ if ( ! types . TryGetValue ( fullName , out typesList ) )
568
+ aliases . TryGetValue ( fullName , out typesList ) ;
569
+ if ( typesList == null )
570
+ return null ;
571
+ if ( typesList . Count == 1 )
572
+ return typesList [ 0 ] ;
573
+ //Idea here is... If we have multiple types with same name... they must be in different .dlls
574
+ //so find 1st matching assembly with stackframes and then return type that belongs to that assembly
575
+ var assembly = current_thread . GetFrames ( ) . Select ( f => f . Method . DeclaringType . Assembly ) . FirstOrDefault ( asm => typesList . Select ( t => t . Assembly ) . Contains ( asm ) ) ;
576
+ return typesList . FirstOrDefault ( t => t . Assembly == assembly ) ?? typesList . FirstOrDefault ( ) ;
571
577
}
572
-
578
+
573
579
public IEnumerable < TypeMirror > GetAllTypes ( )
574
580
{
575
- return types . Values ;
581
+ return types . Values . SelectMany ( l => l ) ;
576
582
}
577
583
578
584
protected override bool AllowBreakEventChanges {
@@ -981,9 +987,8 @@ protected override BreakEventInfo OnInsertBreakEvent (BreakEvent breakEvent)
981
987
}
982
988
} else if ( breakEvent is Catchpoint ) {
983
989
var cp = ( Catchpoint ) breakEvent ;
984
- TypeMirror type ;
985
990
986
- if ( ! types . TryGetValue ( cp . ExceptionName , out type ) ) {
991
+ if ( ! types . ContainsKey ( cp . ExceptionName ) ) {
987
992
//
988
993
// Same as in FindLocationByFile (), fetch types matching the type name
989
994
if ( vm . Version . AtLeast ( 2 , 9 ) ) {
@@ -992,8 +997,10 @@ protected override BreakEventInfo OnInsertBreakEvent (BreakEvent breakEvent)
992
997
}
993
998
}
994
999
995
- if ( types . TryGetValue ( cp . ExceptionName , out type ) ) {
996
- InsertCatchpoint ( cp , bi , type ) ;
1000
+ List < TypeMirror > typesList ;
1001
+ if ( types . TryGetValue ( cp . ExceptionName , out typesList ) ) {
1002
+ foreach ( var type in typesList )
1003
+ InsertCatchpoint ( cp , bi , type ) ;
997
1004
bi . SetStatus ( BreakEventStatus . Bound , null ) ;
998
1005
} else {
999
1006
bi . TypeName = cp . ExceptionName ;
@@ -1932,18 +1939,21 @@ void HandleAssemblyUnloadEvents (AssemblyUnloadEvent[] events)
1932
1939
}
1933
1940
1934
1941
// Remove affected types from the loaded types list
1935
- var affectedTypes = new List < string > ( from pair in types
1936
- where PathComparer . Equals ( pair . Value . Assembly . Location , asm . Location )
1937
- select pair . Key ) ;
1942
+ var affectedTypes = types . SelectMany ( l => l . Value ) . Where ( t => t . Assembly == asm ) . ToArray ( ) ;
1938
1943
1939
- foreach ( string typeName in affectedTypes ) {
1940
- TypeMirror tm ;
1941
-
1942
- if ( types . TryGetValue ( typeName , out tm ) ) {
1943
- if ( tm . IsNested )
1944
- aliases . Remove ( NestedTypeNameToAlias ( typeName ) ) ;
1945
-
1946
- types . Remove ( typeName ) ;
1944
+ foreach ( var tm in affectedTypes ) {
1945
+ List < TypeMirror > typesList ;
1946
+ if ( tm . IsNested ) {
1947
+ if ( aliases . TryGetValue ( NestedTypeNameToAlias ( tm . FullName ) , out typesList ) ) {
1948
+ typesList . Remove ( tm ) ;
1949
+ if ( typesList . Count == 0 )
1950
+ aliases . Remove ( NestedTypeNameToAlias ( tm . FullName ) ) ;
1951
+ }
1952
+ }
1953
+ if ( types . TryGetValue ( tm . FullName , out typesList ) ) {
1954
+ typesList . Remove ( tm ) ;
1955
+ if ( typesList . Count == 0 )
1956
+ types . Remove ( tm . FullName ) ;
1947
1957
}
1948
1958
}
1949
1959
@@ -1972,8 +1982,9 @@ void HandleTypeLoadEvents (TypeLoadEvent[] events)
1972
1982
var type = events [ 0 ] . Type ;
1973
1983
if ( events . Length > 1 && events . Any ( a => a . Type != type ) )
1974
1984
throw new InvalidOperationException ( "Simultaneous TypeLoadEvents for multiple types" ) ;
1975
-
1976
- if ( ! types . ContainsKey ( type . FullName ) )
1985
+
1986
+ List < TypeMirror > typesList ;
1987
+ if ( ! ( types . TryGetValue ( type . FullName , out typesList ) && typesList . Contains ( type ) ) )
1977
1988
ResolveBreakpoints ( type ) ;
1978
1989
}
1979
1990
@@ -2294,13 +2305,21 @@ void ProcessType (TypeMirror t)
2294
2305
{
2295
2306
string typeName = t . FullName ;
2296
2307
2297
- if ( types . ContainsKey ( typeName ) )
2308
+ List < TypeMirror > typesList ;
2309
+ if ( types . TryGetValue ( typeName , out typesList ) && typesList . Contains ( t ) )
2298
2310
return ;
2299
2311
2300
- if ( t . IsNested )
2301
- aliases [ NestedTypeNameToAlias ( typeName ) ] = t ;
2302
-
2303
- types [ typeName ] = t ;
2312
+ if ( t . IsNested ) {
2313
+ var alias = NestedTypeNameToAlias ( typeName ) ;
2314
+ List < TypeMirror > aliasesList ;
2315
+ if ( aliases . TryGetValue ( alias , out aliasesList ) ) {
2316
+ aliasesList . Add ( t ) ;
2317
+ } else {
2318
+ aliases [ alias ] = new List < TypeMirror > ( new [ ] { t } ) ;
2319
+ }
2320
+ }
2321
+ types [ typeName ] = typesList ?? new List < TypeMirror > ( ) ;
2322
+ types [ typeName ] . Add ( t ) ;
2304
2323
2305
2324
//get the source file paths
2306
2325
//full paths, from GetSourceFiles (true), are only supported by sdb protocol 2.2 and later
@@ -2324,8 +2343,6 @@ void ProcessType (TypeMirror t)
2324
2343
sourceFiles [ n ] = NormalizePath ( sourceFiles [ n ] ) ;
2325
2344
2326
2345
foreach ( string s in sourceFiles ) {
2327
- List < TypeMirror > typesList ;
2328
-
2329
2346
if ( source_to_type . TryGetValue ( s , out typesList ) ) {
2330
2347
typesList . Add ( t ) ;
2331
2348
} else {
0 commit comments