Public bug reported:

Steps to reproduce:

1: Create a file `test.c` with the following very simple program:

    #include <stdio.h>  /* for printf */
    #include <string.h> /* for strlen */

    int main(int argc, char **argv) {
        const char *statstr = "hello there!";
        printf("%s\n", statstr);
    }

2: Save this file and compile it with `gcc -g test.c`.
3: Debug it with `gdb a.out`.
4: Run `b test.c:6` to set a breakpoint on the printf call.
5: Run `r` to start the program.
6: Run `print strlen(statstr)` to attempt to get the length of the statstr 
string.

Expected result: The length of the string should be printed like so: `$1
= 12`

Actual result: gdb segfaults.

Segfault backtrace and info:

```
(gdb) print strlen(statstr)


Fatal signal: Segmentation fault
----- Backtrace -----
0x5ac45237f077 ???
0x5ac452481859 ???
0x5ac452481a22 ???
0x72ec6204251f ???
        ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x5ac45232f020 ???
0x5ac4524d6637 ???
0x5ac45247f24a ???
0x5ac45247b827 ???
0x5ac45259e79f ???
0x5ac45259ecef ???
0x5ac4523b4654 ???
0x5ac4526aa394 ???
0x5ac4524829a4 ???
0x5ac452482d43 ???
0x5ac4524834c6 ???
0x72ec633a7e0d ???
0x5ac452481a95 ???
0x5ac452483374 ???
0x5ac45248168b ???
0x5ac452833815 ???
0x5ac452833caa ???
0x5ac45253f36c ???
0x5ac452541054 ???
0x5ac4522d715f ???
0x72ec62029d8f __libc_start_call_main
        ../sysdeps/nptl/libc_start_call_main.h:58
0x72ec62029e3f __libc_start_main_impl
        ../csu/libc-start.c:392
0x5ac4522dcbf4 ???
0xffffffffffffffff ???
---------------------
A fatal error internal to GDB has been detected, further
debugging is not possible.  GDB will now terminate.

This is a bug, please report it.  For instructions, see:
<https://www.gnu.org/software/gdb/bugs/>.

Segmentation fault (core dumped)
```

Additional info:

* You can create a function inside `test.c` that accepts a string as input and 
returns the result of running `strlen` on it. Calling that function via `print 
len(statstr)` does NOT segfault, but behaves as expected.
* If you remove the `int argc, char **argv` from the `main()` function's 
argument list, calling `strlen(statstr)` in step 6 does NOT segfault, but 
behaves as expected.

ProblemType: Bug
DistroRelease: Ubuntu 22.04
Package: gdb 12.1-0ubuntu1~22.04
ProcVersionSignature: Ubuntu 6.5.0-25.25~22.04.1-generic 6.5.13
Uname: Linux 6.5.0-25-generic x86_64
ApportVersion: 2.20.11-0ubuntu82.5
Architecture: amd64
CasperMD5CheckResult: unknown
CurrentDesktop: KDE
Date: Tue Apr 16 09:51:33 2024
InstallationDate: Installed on 2024-03-30 (17 days ago)
InstallationMedia: Kubuntu 22.04.3 LTS "Jammy Jellyfish" (20231113)
SourcePackage: gdb
UpgradeStatus: No upgrade log present (probably fresh install)

** Affects: gdb (Ubuntu)
     Importance: Undecided
         Status: New

** Affects: gdb (Ubuntu Jammy)
     Importance: Undecided
         Status: New


** Tags: amd64 apport-bug jammy

** Also affects: gdb (Ubuntu Jammy)
   Importance: Undecided
       Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2061849

Title:
  Segmentation fault when calling standard library functions via `print`
  or `call` while debugging a `main()` function that accepts arguments

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gdb/+bug/2061849/+subscriptions


-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to