Skip to content

Commit 9fb59d3

Browse files
author
David Karlaš
committed
Bug 33733 - Breakpoints not hit in methods with same full typename
1 parent e36f58c commit 9fb59d3

File tree

1 file changed

+50
-33
lines changed

1 file changed

+50
-33
lines changed

Mono.Debugging.Soft/SoftDebuggerSession.cs

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class MethodMdbInfo
7575
readonly Dictionary<EventRequest, BreakInfo> breakpoints = new Dictionary<EventRequest, BreakInfo> ();
7676
readonly Dictionary<TypeMirror, string[]> type_to_source = new Dictionary<TypeMirror, string[]> ();
7777
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>> ();
8080
readonly LinkedList<List<Event>> queuedEventSets = new LinkedList<List<Event>> ();
8181
readonly Dictionary<long,long> localThreadIds = new Dictionary<long, long> ();
8282
readonly List<BreakInfo> pending_bes = new List<BreakInfo> ();
@@ -562,17 +562,23 @@ public VirtualMachine VirtualMachine {
562562

563563
public TypeMirror GetType (string fullName)
564564
{
565-
TypeMirror tm;
565+
List<TypeMirror> typesList;
566566

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 ();
571577
}
572-
578+
573579
public IEnumerable<TypeMirror> GetAllTypes ()
574580
{
575-
return types.Values;
581+
return types.Values.SelectMany (l => l);
576582
}
577583

578584
protected override bool AllowBreakEventChanges {
@@ -981,9 +987,8 @@ protected override BreakEventInfo OnInsertBreakEvent (BreakEvent breakEvent)
981987
}
982988
} else if (breakEvent is Catchpoint) {
983989
var cp = (Catchpoint) breakEvent;
984-
TypeMirror type;
985990

986-
if (!types.TryGetValue (cp.ExceptionName, out type)) {
991+
if (!types.ContainsKey (cp.ExceptionName)) {
987992
//
988993
// Same as in FindLocationByFile (), fetch types matching the type name
989994
if (vm.Version.AtLeast (2, 9)) {
@@ -992,8 +997,10 @@ protected override BreakEventInfo OnInsertBreakEvent (BreakEvent breakEvent)
992997
}
993998
}
994999

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);
9971004
bi.SetStatus (BreakEventStatus.Bound, null);
9981005
} else {
9991006
bi.TypeName = cp.ExceptionName;
@@ -1932,18 +1939,21 @@ void HandleAssemblyUnloadEvents (AssemblyUnloadEvent[] events)
19321939
}
19331940

19341941
// 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 ();
19381943

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);
19471957
}
19481958
}
19491959

@@ -1972,8 +1982,9 @@ void HandleTypeLoadEvents (TypeLoadEvent[] events)
19721982
var type = events [0].Type;
19731983
if (events.Length > 1 && events.Any (a => a.Type != type))
19741984
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)))
19771988
ResolveBreakpoints (type);
19781989
}
19791990

@@ -2294,13 +2305,21 @@ void ProcessType (TypeMirror t)
22942305
{
22952306
string typeName = t.FullName;
22962307

2297-
if (types.ContainsKey (typeName))
2308+
List<TypeMirror> typesList;
2309+
if (types.TryGetValue (typeName, out typesList) && typesList.Contains (t))
22982310
return;
22992311

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);
23042323

23052324
//get the source file paths
23062325
//full paths, from GetSourceFiles (true), are only supported by sdb protocol 2.2 and later
@@ -2324,8 +2343,6 @@ void ProcessType (TypeMirror t)
23242343
sourceFiles[n] = NormalizePath (sourceFiles[n]);
23252344

23262345
foreach (string s in sourceFiles) {
2327-
List<TypeMirror> typesList;
2328-
23292346
if (source_to_type.TryGetValue (s, out typesList)) {
23302347
typesList.Add (t);
23312348
} else {

0 commit comments

Comments
 (0)