lockdep: print more info for the unbalance unlock case

* print a lock type
* print a list of taken locks

PiperOrigin-RevId: 454310284
This commit is contained in:
Andrei Vagin
2022-06-11 00:22:29 -07:00
committed by gVisor bot
parent 1822dfa7ac
commit 605841baad
2 changed files with 22 additions and 1 deletions
+8 -1
View File
@@ -117,6 +117,7 @@ func AddGLock(class *MutexClass, subclass uint32) {
// DelGLock deletes a lock from the current goroutine.
func DelGLock(class *MutexClass, subclass uint32) {
origClass := class
if subclass != 0 {
class = class.subclasses.Load(subclass)
}
@@ -126,7 +127,13 @@ func DelGLock(class *MutexClass, subclass uint32) {
panic("the current goroutine doesn't have locks")
}
if _, ok := (*currentLocks)[class]; !ok {
panic("unlock of an unknown lock")
var b strings.Builder
fmt.Fprintf(&b, "unbalance unlock: %s:%d:\n", *classMap.Load(origClass), subclass)
fmt.Fprintf(&b, "Current locks:\n")
for c := range *currentLocks {
fmt.Fprintf(&b, "\t%s\n", *classMap.Load(c))
}
panic(b.String())
}
delete(*currentLocks, class)
+14
View File
@@ -104,3 +104,17 @@ func TestReverseNested(t *testing.T) {
t.Error("The reverse lock order hasn't been detected")
}
func TestUnknownLock(t *testing.T) {
m1 := testMutex{}
m2 := test2RWMutex{}
m1.Lock()
m2.Lock()
defer func() {
if r := recover(); r != nil {
t.Logf("Got expected panic: %s", r)
}
}()
m2.NestedUnlock()
t.Error("An unknown lock has not been detected.")
}