From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5CDB33858292; Tue, 2 Jan 2024 17:00:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5CDB33858292 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1704214818; bh=GXOtWDPf97k2q49sVhfH1PkFT0b+ArfPlaRNv1a65qM=; h=From:To:Subject:Date:From; b=QynJnEFtbBTkacoYB1oRD/FP1ZlkyN19wJlUN/3Xh2pX8K6+5uWHxzjyD+jCGtuky I7v2eauyTTF/w7zV3o0SqNrrWgVzlWDn/abk0DSCrVKdHVMIbjKtBr1XGsxF9ycwer wXnTaQOmnb38sg85VZmH4SFWAl2lUfQX1tFchWaU= From: "dominik.b.czarnota+bugzilla at gmail dot com" To: gdb-prs@sourceware.org Subject: [Bug gdb/31207] New: info proc mappings returns no maps when the main thread exitted Date: Tue, 02 Jan 2024 17:00:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: gdb X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dominik.b.czarnota+bugzilla at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31207 Bug ID: 31207 Summary: info proc mappings returns no maps when the main thread exitted Product: gdb Version: HEAD Status: UNCONFIRMED Severity: normal Priority: P2 Component: gdb Assignee: unassigned at sourceware dot org Reporter: dominik.b.czarnota+bugzilla at gmail dot com Target Milestone: --- Hi, There is a case where the /proc/$pid/maps file may return no data when the = main thread of a process exitted but other threads are still running and being debugged. This can be reproduced with the following program: ``` #include #include #include #include void *thread_function(void *arg) { sleep(2); // trigger a crash and so a GDB stop :) *(int*)(0xdeadbeef) =3D 0x1234; return NULL; } int main(void) { pthread_t thread; pthread_create(&thread, NULL, thread_function, NULL); pthread_exit(NULL); return 0; } ``` And then compiled and run the following way: ``` root@pwndbg:~/pwndbg# gcc a.c -lpthread root@pwndbg:~/pwndbg# gdb --nx --quiet ./a.out Reading symbols from ./a.out... (No debugging symbols found in ./a.out) (gdb) version Undefined command: "version". Try "help". (gdb) quit root@pwndbg:~/pwndbg# gdb --nx ./a.out GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1 Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./a.out... (No debugging symbols found in ./a.out) (gdb) run Starting program: /root/pwndbg/a.out [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". [New Thread 0x7ffff7d84640 (LWP 3392368)] [Thread 0x7ffff7d85740 (LWP 3392365) exited] Thread 2 "a.out" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7ffff7d84640 (LWP 3392368)] 0x00005555555551a8 in thread_function () (gdb) info proc mappings process 3392365 Mapped address spaces: Start Addr End Addr Size Offset Perms objfi= le (gdb) !cat /proc/3392365/maps (gdb) !ls -lah /proc/3392365/maps -r--r--r-- 1 root root 0 Jan 2 16:58 /proc/3392365/maps (gdb) !cat /proc/3392368/maps 555555554000-555555555000 r--p 00000000 fc:01 277317=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 /root/pwndbg/a.out 555555555000-555555556000 r-xp 00001000 fc:01 277317=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 /root/pwndbg/a.out 555555556000-555555557000 r--p 00002000 fc:01 277317=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 /root/pwndbg/a.out 555555557000-555555558000 r--p 00002000 fc:01 277317=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 /root/pwndbg/a.out 555555558000-555555559000 rw-p 00003000 fc:01 277317=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 /root/pwndbg/a.out 555555559000-55555557a000 rw-p 00000000 00:00 0 [h= eap] 7ffff7564000-7ffff7567000 r--p 00000000 fc:01 18111=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 7ffff7567000-7ffff757e000 r-xp 00003000 fc:01 18111=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 7ffff757e000-7ffff7582000 r--p 0001a000 fc:01 18111=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 7ffff7582000-7ffff7583000 r--p 0001d000 fc:01 18111=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 7ffff7583000-7ffff7584000 rw-p 0001e000 fc:01 18111=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 7ffff7584000-7ffff7585000 ---p 00000000 00:00 0 7ffff7585000-7ffff7d88000 rw-p 00000000 00:00 0 7ffff7d88000-7ffff7db0000 r--p 00000000 fc:01 8934=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20 /usr/lib/x86_64-linux-gnu/libc.so.6 7ffff7db0000-7ffff7f45000 r-xp 00028000 fc:01 8934=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20 /usr/lib/x86_64-linux-gnu/libc.so.6 7ffff7f45000-7ffff7f9d000 r--p 001bd000 fc:01 8934=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20 /usr/lib/x86_64-linux-gnu/libc.so.6 7ffff7f9d000-7ffff7fa1000 r--p 00214000 fc:01 8934=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20 /usr/lib/x86_64-linux-gnu/libc.so.6 7ffff7fa1000-7ffff7fa3000 rw-p 00218000 fc:01 8934=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20 /usr/lib/x86_64-linux-gnu/libc.so.6 7ffff7fa3000-7ffff7fb0000 rw-p 00000000 00:00 0 7ffff7fbb000-7ffff7fbd000 rw-p 00000000 00:00 0 7ffff7fbd000-7ffff7fc1000 r--p 00000000 00:00 0 [v= var] 7ffff7fc1000-7ffff7fc3000 r-xp 00000000 00:00 0 [v= dso] 7ffff7fc3000-7ffff7fc5000 r--p 00000000 fc:01 8929=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 7ffff7fc5000-7ffff7fef000 r-xp 00002000 fc:01 8929=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 7ffff7fef000-7ffff7ffa000 r--p 0002c000 fc:01 8929=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 7ffff7ffb000-7ffff7ffd000 r--p 00037000 fc:01 8929=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 7ffff7ffd000-7ffff7fff000 rw-p 00039000 fc:01 8929=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 7ffffffde000-7ffffffff000 rw-p 00000000 00:00 0=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 [stack] ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20 [vsyscall] (gdb) ``` As we can see, the `info proc mappings` command returns no memory mappings. This is because the kernel does not render any content of the /proc/$pid/ma= ps file since the main thread has exitted already. However, the kernel still allows us to read the memory mappings of the proc= ess from the /proc/$tid/maps file. I believe GDB should by default read that file instead and return the memory mappings of the current thread instead of always referring to current PID. --=20 You are receiving this mail because: You are on the CC list for the bug.=