Your message dated Sun, 03 Aug 2025 16:39:29 -0400
with message-id <[email protected]>
and subject line Re: Bug#1022056: gdb: Cannot return a specified value from a 
shared library function using the 'return' command
has caused the Debian Bug report #1022056,
regarding gdb: Cannot return a specified value from a shared library function 
using the 'return' command
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)


-- 
1022056: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1022056
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
Package: gdb
Version: 12.1-4
Severity: minor
X-Debbugs-Cc: [email protected]


Hello.
The issue happens when I specific a return value to the 'return' command in
gdb(1), in order to return from a shared library function with my specified
return value.

The following example uses function geteuid(2) from libc.so.6:

        root@debian:~/src# cat rval-test.c
        #include <unistd.h>
        #include <stdio.h>
        
        int main() {
                while(1) {
                        printf("geteuid returned %u\n", (unsigned 
int)geteuid());
                        sleep(1);
                }
        }
        root@debian:~/src# gcc -Wall -g rval-test.c -o rval-test   
        root@debian:~/src# gdb rval-test 
        GNU gdb (Debian 12.1-4) 12.1
        Copyright (C) 2022 Free Software Foundation, Inc.
        License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html>
        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 "powerpc64le-linux-gnu".
        Type "show configuration" for configuration details.
        For bug reporting instructions, please see:
        <https://www.gnu.org/software/gdb/bugs/>.
        Find the GDB manual and other documentation resources online at:
            <http://www.gnu.org/software/gdb/documentation/>.
        
        For help, type "help".
        Type "apropos word" to search for commands related to "word"...
        Reading symbols from rval-test...
        (gdb) b geteuid
        Breakpoint 1 at 0x960
        (gdb) r
        Starting program: /root/src/rval-test 
        [Thread debugging using libthread_db enabled]
        Using host libthread_db library 
"/lib/powerpc64le-linux-gnu/libthread_db.so.1".
        
        Breakpoint 1, 0x00007ffff7e12ea0 in __GI_geteuid () at 
../sysdeps/unix/syscall-template.S:91
        91      ../sysdeps/unix/syscall-template.S: No such file or directory.
        (gdb) c
        Continuing.
        geteuid returned 0
        
        Breakpoint 1, 0x00007ffff7e12ea0 in __GI_geteuid () at 
../sysdeps/unix/syscall-template.S:91
        91      in ../sysdeps/unix/syscall-template.S
        (gdb) return 111111
        Make __GI_geteuid return now? (y or n) y
        #0  0x00000001000008dc in main () at rval-test.c:6
        6                       printf("geteuid returned %u\n", (unsigned 
int)geteuid());
        (gdb) c
        Continuing.
        geteuid returned 0
        
        Breakpoint 1, 0x00007ffff7e12ea0 in __GI_geteuid () at 
../sysdeps/unix/syscall-template.S:91
        91      ../sysdeps/unix/syscall-template.S: No such file or directory.
        (gdb) return (uint32_t)111111
        Make __GI_geteuid return now? (y or n) y
        #0  0x00000001000008dc in main () at rval-test.c:6
        6                       printf("geteuid returned %u\n", (unsigned 
int)geteuid());
        (gdb) c
        Continuing.
        geteuid returned 0


As shown in this example, I'm trying to make this function to return 111111
instead, but this didn't work.

Manually changing the register for return value (r3) worked:

        Breakpoint 1, 0x00007ffff7e12ea0 in __GI_geteuid () at 
../sysdeps/unix/syscall-template.S:91
        91      ../sysdeps/unix/syscall-template.S: No such file or directory.
        (gdb) p $r3
        $1 = 0
        (gdb) p $r3 = (uint32_t)111111
        $2 = 111111
        (gdb) return
        Make __GI_geteuid return now? (y or n) y
        #0  0x00000001000008dc in main () at rval-test.c:6
        6                       printf("geteuid returned %u\n", (unsigned 
int)geteuid());
        (gdb) c
        Continuing.
        geteuid returned 111111
        ...


So this method could be used as a workaround.


-- System Information:
Debian Release: bookworm/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: ppc64el (ppc64le)

Kernel: Linux 5.4.0-113-generic (SMP w/128 CPU threads)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE, 
TAINT_UNSIGNED_MODULE
Locale: LANG=C, LC_CTYPE=C.UTF-8 (charmap=UTF-8), 
LANGUAGE=zh_TW:zh_CN:en_GB:en_US
Shell: /bin/sh linked to /usr/bin/dash
Init: unable to detect

Versions of packages gdb depends on:
ii  libbabeltrace1          1.5.8-2+b2
ii  libc6                   2.35-3
ii  libdebuginfod1          0.187-1
ii  libexpat1               2.4.8-1
ii  libgcc-s1               12.1.0-7
ii  libgmp10                2:6.2.1+dfsg1-1
ii  liblzma5                5.2.5-2.1
ii  libmpfr6                4.1.0-3
ii  libncursesw6            6.3+20220423-2
ii  libpython3.10           3.10.5-1
ii  libreadline8            8.1.2-1.2
ii  libsource-highlight4v5  3.1.9-4.1+b1
ii  libstdc++6              12.1.0-7
ii  libtinfo6               6.3+20220423-2
ii  libxxhash0              0.8.1-1
ii  zlib1g                  1:1.2.11.dfsg-4

Versions of packages gdb recommends:
ii  libc6-dbg [libc-dbg]  2.35-3

Versions of packages gdb suggests:
pn  gdb-doc    <none>
pn  gdbserver  <none>

-- no debconf information

--- End Message ---
--- Begin Message ---
On Wednesday, October 19 2022, WHR wrote:

> Hello.
> The issue happens when I specific a return value to the 'return' command in
> gdb(1), in order to return from a shared library function with my specified
> return value.

Thanks for filing a bug report, and apologies for taking so long to
reply.  I can't reproduce this bug anymore with the latest GDB (16.1):

--8<---------------cut here---------------start------------->8---
(gdb) b geteuid
Breakpoint 1 at 0x960
(gdb) r
Starting program: /home/sergiodj/rval-test 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/powerpc64le-linux-gnu/libthread_db.so.1".

Breakpoint 1, 0x00007ffff7d17608 in geteuid () from 
/lib/powerpc64le-linux-gnu/libc.so.6
(gdb) c
Continuing.
geteuid returned 3422

Breakpoint 1, 0x00007ffff7d17608 in geteuid () from 
/lib/powerpc64le-linux-gnu/libc.so.6
(gdb) return 11111
Return value type not available for selected stack frame.
Please use an explicit cast of the value to return.
(gdb) return (int) 11111
Make selected stack frame return now? (y or n) y
#0  0x00000001000008dc in main () at rval-test.c:6
6                               printf("geteuid returned %u\n", (unsigned 
int)geteuid());
(gdb) n
geteuid returned 11111
7                               sleep(1);
--8<---------------cut here---------------end--------------->8---

Therefore, I'm closing this bug.  Feel free to reopen if it's still
applicable.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
https://sergiodj.net/

Attachment: signature.asc
Description: PGP signature


--- End Message ---

Reply via email to