effective-debugging
effective-debugging copied to clipboard
Page 94, Listing 4.1
The listing should be read as follows, correcting the order of the defined breakpoints.
# Define a counter variable to keep track of locks
set $nlock = 0
# Stop the execution with a backtrace on nested locks
break lock if $nlock > 0
commands
silent
echo Nested lock\n
# Display the stack trace
backtrace
# Stop the program's execution
break
end
# Stop the execution with a backtrace on duplicate unlocks
break unlock if $nlock <= 0
commands
silent
echo Duplicate unlock\n
backtrace
break
end
# When the lock routine is called, increase the counter
# Define a new breakpoint
break lock
# Commands to execute when the lock routine is called
commands
silent
# Increment counter variable
set $nlock = $nlock + 1
# Continue the program's execution
continue
end
# When the unlock routine is called, decrease the counter
break unlock
commands
silent
set $nlock = $nlock - 1
continue
end
Spotted and corrected by Naohiro Ooiwa-san.