Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a watchpoint on errno in gdb

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?

like image 224
Hermann Speiche Avatar asked May 18 '12 18:05

Hermann Speiche


People also ask

How do I add a watchpoint in GDB?

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.

How do you set breakpoints in GDB?

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.

How does watch work in GDB?

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.


1 Answers

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.

like image 164
Nikolai Fetissov Avatar answered Nov 09 '22 17:11

Nikolai Fetissov