I'm trying to find out when errno changes.
At first, I tried "watch errno" in gdb, which led to the error
Cannot find thread-local variables on this target
I was able to fix this by compiling with "-pthread". However, it still doesn't work and I now get the error
Cannot find shared library `/usr/lib/debug/lib/x86_64-linux-gnu/libc-2.13.so' in dynamic linker's load module list
when I type "watch errno". What do I need to do such that setting a watchpoint on errno works?
If GDB cannot set a hardware watchpoint, it sets a software watchpoint, which executes more slowly and reports the change in value at the next statement, not the instruction, after the change occurs. You can force GDB to use only software watchpoints with the set can-use-hw-watchpoints 0 command.
Setting breakpoints A breakpoint is like a stop sign in your code -- whenever gdb gets to a breakpoint it halts execution of your program and allows you to examine it. To set breakpoints, type "break [filename]:[linenumber]". For example, if you wanted to set a breakpoint at line 55 of main.
watch allows us to stop the execution every time the value of a variable changes. display prints variables every time the program's execution stops (i.e. at a watchpoint, breakpoint, etc…) Using both allows us to automatically stop at various points throughout a loop, and print all the relevant variables.
errno
is not just a static variable anymore. Here's how it appears to userland apps on Linux (from my local /usr/include/x86_64-linux-gnu/bits/errno.h
):
# define errno (*__errno_location ())
This is to get error state per thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With