public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/31563] New: Problems with accessing errno
@ 2024-03-27  2:10 kevinb at redhat dot com
  2024-03-27  2:10 ` [Bug gdb/31563] " kevinb at redhat dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: kevinb at redhat dot com @ 2024-03-27  2:10 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31563

            Bug ID: 31563
           Summary: Problems with accessing errno
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: kevinb at redhat dot com
  Target Milestone: ---

Created attachment 15437
  --> https://sourceware.org/bugzilla/attachment.cgi?id=15437&action=edit
C program for demonstrating problems w/ errno

I am writing a new gdb test, gdb.base/check-errno.exp.  (Actually, it's a
rewrite of an old test written by Jan Kratochvil from a while back, perhaps as
far back as 2008.) The test compiles a simple program multiple times, each time
using different compile flags. In some cases, GDB is able to print errno
correctly and in other cases it does not. The program is named check-errno.c.

Here are the instances where GDB is unable to access errno:

1) -static:

kev@f39-1:ce$ gcc -static -g -o check-errno-static check-errno.c 
kev@f39-1:ce$ $GDB -q check-errno-static
Reading symbols from check-errno-static...
(gdb) b 24
Breakpoint 1 at 0x401794: file check-errno.c, line 24.
(gdb) run
Starting program: /tmp/ce/check-errno-static 

This GDB supports auto-downloading debuginfo from the following URLs:
  <https://debuginfod.fedoraproject.org/>
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
Downloading separate debug info for system-supplied DSO at 0x7ffff7ffd000

Breakpoint 1, main () at check-errno.c:24
24        return 0;     /* breakpoint */
(gdb) p errno
Cannot find thread-local storage for process 14409, executable file
/tmp/ce/check-errno-static:
Cannot find thread-local variables on this target

2) -static -g3:

kev@f39-1:ce$ gcc -static -g3 -o check-errno-static check-errno.c 
kev@f39-1:ce$ $GDB -q check-errno-static
Reading symbols from check-errno-static...
(gdb) b 24
Breakpoint 1 at 0x401794: file check-errno.c, line 24.
(gdb) run
Starting program: /tmp/ce/check-errno-static 

This GDB supports auto-downloading debuginfo from the following URLs:
  <https://debuginfod.fedoraproject.org/>
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.

Breakpoint 1, main () at check-errno.c:24
24        return 0;     /* breakpoint */
(gdb) p errno
'__errno_location' has unknown return type; cast the call to its declared
return type

3, 4) Same as above, but use gcore to make a core file for above two cases.

5) -lpthread -g3, from corefile:

kev@f39-1:ce$ gcc -lpthreads -g3 -o check-errno-pthreads-g3 check-errno.c 
/usr/bin/ld: cannot find -lpthreads: No such file or directory
collect2: error: ld returned 1 exit status
kev@f39-1:ce1$ gcc -lpthread -g3 -o check-errno-pthreads-g3 check-errno.c 
kev@f39-1:ce$ $GDB -q check-errno-pthreads-g3
Reading symbols from check-errno-pthreads-g3...
(gdb) b 24
Breakpoint 1 at 0x401135: file check-errno.c, line 24.
(gdb) run
Starting program: /tmp/ce/check-errno-pthreads-g3 

This GDB supports auto-downloading debuginfo from the following URLs:
  <https://debuginfod.fedoraproject.org/>
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Breakpoint 1, main () at check-errno.c:24
24        return 0;     /* breakpoint */
(gdb) p errno
$1 = 42
(gdb) gcore check-errno-pthreads-gc.core
warning: Memory read failed for corefile section, 4096 bytes at
0xffffffffff600000.
Saved corefile check-errno-pthreads-gc.core
(gdb) core check-errno-pthreads-gc.core
A program is being debugged already.  Kill it? (y or n) y
[New LWP 14550]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `/tmp/ce/check-errno-pthreads-g3'.
Program terminated with signal SIGTRAP, Trace/breakpoint trap.
#0  main () at check-errno.c:24
24        return 0;     /* breakpoint */
(gdb) p errno
You can't do that without a process to debug.

The above behavior was observed on Fedora 39, which is using the following
version of gcc:

gcc (GCC) 13.2.1 20240316 (Red Hat 13.2.1-7)

Fedora GDB has a hack which causes errno to be printed correctly for each of
these cases. However, IMO, it truly is a hack and is not acceptable for
upstream.  I would like to figure out and fix (if possible) the root cause of
each of the problems above so that the hack may be discarded.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-05-14  3:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-27  2:10 [Bug gdb/31563] New: Problems with accessing errno kevinb at redhat dot com
2024-03-27  2:10 ` [Bug gdb/31563] " kevinb at redhat dot com
2024-05-10  7:00 ` vries at gcc dot gnu.org
2024-05-10 10:56 ` pedro at palves dot net
2024-05-10 20:10 ` kevinb at redhat dot com
2024-05-13 15:05 ` pedro at palves dot net
2024-05-14  3:00 ` kevinb at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).