[Bug 287829] lldb prints the wrong value of errno in multi-threaded processes

From: <bugzilla-noreply_at_freebsd.org>
Date: Sat, 28 Jun 2025 10:44:39 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=287829

--- Comment #2 from Greg Becker <becker.greg@att.net> ---
Curious..  gcc+gdb on linux seems show the errno from the current gdb thread
context:

$ cc --version
cc (GCC) 15.1.1 20250425 (Red Hat 15.1.1-1)

$ gdb --version
GNU gdb (Fedora Linux) 16.3-1.fc42

$ cc -Wall -O0 -g3 lldb-errno-bug.c -lpthread

$ gdb a.out
GNU gdb (Fedora Linux) 16.3-1.fc42
Reading symbols from a.out...
(gdb) r
Starting program: /home/greg/a.out 

Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
main: gvar 8, tlvar 6, errno 0
[New Thread 0x7ffff7dc36c0 (LWP 40042)]
ptstart: 1: gvar 8, tlvar 5, errno 0
ptstart: 2: gvar 8, tlvar 5, errno 22

Thread 2 "a.out" received signal SIGABRT, Aborted.
[Switching to Thread 0x7ffff7dc36c0 (LWP 40042)]
__pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6,
no_tid=no_tid@entry=0) at pthread_kill.c:44
44            return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO
(ret) : 0;
(gdb) bt
#0  __pthread_kill_implementation (threadid=<optimized out>,
signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007ffff7e3a1e3 in __pthread_kill_internal (threadid=<optimized out>,
signo=6) at pthread_kill.c:89
#2  0x00007ffff7de0afe in __GI_raise (sig=sig@entry=6) at
../sysdeps/posix/raise.c:26
#3  0x00007ffff7dc86d0 in __GI_abort () at abort.c:73
#4  0x000000000040057a in ptstart (arg=0x0) at lldb-errno-bug.c:18
#5  0x00007ffff7e381d4 in start_thread (arg=<optimized out>) at
pthread_create.c:448
#6  0x00007ffff7ebacec in __GI___clone3 () at
../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

(gdb) f 4
#4  0x000000000040057a in ptstart (arg=0x0) at lldb-errno-bug.c:18
18              abort();

(gdb) p errno
$1 = 22

(gdb) p tlvar
$2 = 5



(gdb) t 1
[Switching to thread 1 (Thread 0x7ffff7dc4740 (LWP 40039))]
Downloading source file
/usr/src/debug/glibc-2.41-5.fc42.x86_64/nptl/../sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S
#0  __syscall_cancel_arch () at
../sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S:56                           
56              ret

(gdb) p errno
$3 = 2

(gdb) p tlvar
$3 = 6



Note that I changed the access() call in the attached program to access("", -1)
to eliminate the compiler warning...

-- 
You are receiving this mail because:
You are the assignee for the bug.