private void AddInterferences(LockCritialData methodCalling, LockCritialData methodCalled) { var intersections = methodCalling.lockObjects.Intersect(methodCalled.lockObjects).ToList(); foreach (MemberReference intersection in intersections) { StringBuilder strb = new StringBuilder(); foreach (var mi in callHierarchy.Reverse().ToList()) { strb.AppendLine(FormatMethod(mi)); } warningList.Add(new LockCriticalWarning(intersection.Name, strb.ToString())); } }
private void GetCriticalMethods(TypeDefinition typDef) { criticalMethods.Clear(); foreach (var method in typDef.Methods) { if (!method.HasBody) { continue; } LockCritialData lcd = null; foreach (var instruction in method.Body.Instructions) { // we only search calls, Monitor calls to be precise if (instruction.OpCode != OpCodes.Call) { continue; } // see if we can resolve the call MethodReference metDefCalled = instruction.Operand as MethodReference; if (metDefCalled == null) { continue; } // see if we can resolve the declaring type of the call TypeReference typRefCalled = metDefCalled.DeclaringType; if (typRefCalled == null) { continue; } // if its not a monitor we dont want it if (typRefCalled.FullName != "System.Threading.Monitor") { continue; } if (metDefCalled.Name == "Enter") { if (lcd == null) { lcd = new LockCritialData(method); } MemberReference memref = GetPushStackObj(instruction, metDefCalled.Parameters.Count == 1 ? MONITOR_ENTER_1 : MONITOR_ENTER_2); if (memref != null) { lcd.lockObjects.Add(memref); } else { lcd.isAnyMonitor = true; } } } if (lcd != null) { criticalMethods.Add(lcd); } } }