mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
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:
@@ -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)
|
||||
|
||||
@@ -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.")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user