Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDB and gdbserver cannot step on Linux targets #631

Open
kolerov opened this issue Jun 28, 2024 · 5 comments
Open

GDB and gdbserver cannot step on Linux targets #631

kolerov opened this issue Jun 28, 2024 · 5 comments
Assignees

Comments

@kolerov
Copy link
Collaborator

kolerov commented Jun 28, 2024

A sample program:

#include <stdio.h>

int main()
{
        printf("Hello, World!\n");
        return 0;
}

Try to perform step on ARC HS3x/4x Linux host using native GDB:

# gdb -q main-hs4x-glibc
Reading symbols from main-hs4x-glibc...
(gdb) b main
warning: could not convert 'main' from the host encoding (ANSI_X3.4-1968) to UTF-32.
This normally should not happen, please file a bug report.
Breakpoint 1 at 0x540: file main.c, line 5.
(gdb) run
Starting program: /root/main-hs4x-glibc
Breakpoint 1, main () at main.c:5
warning: Source file is more recent than executable.
5               printf("Hello, World!\n");
(gdb) step
Warning:
Cannot insert breakpoint 0.
Cannot access memory at address 0x0

0x200629b8 in ?? ()

Try to perform stepi on ARC HS3x/4x Linux host using native GDB:

# gdb -q main-hs4x-glibc
Reading symbols from main-hs4x-glibc...
(gdb) b main
warning: could not convert 'main' from the host encoding (ANSI_X3.4-1968) to UTF-32.
This normally should not happen, please file a bug report.
Breakpoint 1 at 0x540: file main.c, line 5.
(gdb) run
Starting program: /root/main-hs4x-glibc
Breakpoint 1, main () at main.c:5
warning: Source file is more recent than executable.
5               printf("Hello, World!\n");
(gdb) stepi
0x40000548      5               printf("Hello, World!\n");
(gdb) stepi
0x4000054a      5               printf("Hello, World!\n");

The same issue exists when debugging using gdbserver on a target system. The issue may be reproduced at least for arc-2023.09 release and later.

@kolerov kolerov self-assigned this Jun 28, 2024
@shahab-vahedi shahab-vahedi self-assigned this Jun 28, 2024
@kolerov
Copy link
Collaborator Author

kolerov commented Jul 2, 2024

The issue may be reproduced both on QEMU and HSDK.

@shahab-vahedi shahab-vahedi removed their assignment Jul 8, 2024
@shahab-vahedi
Copy link
Member

shahab-vahedi commented Jul 11, 2024

I cannot reproduce this on a linux image that I built in march for ebpf testing. gdb is still version 14.2.

gdb

@kolerov
Copy link
Collaborator Author

kolerov commented Jul 11, 2024

I face the issue when stepping (using just step) over simple assignments, local function calls, etc., but not when stepping over glibc functions. stepi, next and nexti work fine.

@shahab-vahedi
Copy link
Member

I can confirm that I do see incorrect behaviour with step but not as bad as what was described (simple assignments, functions calls, etc.). Unless more solid examples are provided, I'm afraid not much can be done.

Anyhow, this is the incorrect behaviour I observe:

(gdb) c
Continuing.

Breakpoint 1, main () at test.c:26
26          fprintf(stdout, "solved.\n");
(gdb) n
28          return 0;

vs.

Breakpoint 1, main () at test.c:26
26          fprintf(stdout, "solved.\n");
(gdb) s
[Inferior 1 (process 138) exited normally]
(gdb)

Here, when about to execute the fprintf(), using n leads to the next line, which is return 0. However, issuing s under the same circumstances, does not stop the process anymore. I think this can be generalised to "stepping into functions without debug symbols makes ARC gdb misbehave".

@shahab-vahedi
Copy link
Member

shahab-vahedi commented Jul 12, 2024

This is how a native x86_64 gdb behaves:

(gdb) n
14	  fprintf(stdout, "solved.\n");
(gdb) s
__GI__IO_fwrite (buf=..., size=1, count=8, fp=... <_IO_2_1_stdout_>)
    at ./libio/iofwrite.c:32
warning: 32	./libio/iofwrite.c: No such file or directory
(gdb) fin
Run till exit from #0  __GI__IO_fwrite (buf=..., size=1, count=8,
    fp=... <_IO_2_1_stdout_>) at ./libio/iofwrite.c:32
solved.
main () at file.c:16
16	  return 0;
Value returned is $1 = 8
(gdb) i r rax
rax            0x8                 8
(gdb)

It steps into the unknown (__GI__IO_fwrite (buf=..., size=1, count=8, fp=... <_IO_2_1_stdout_>) at ./libio/iofwrite.c:32 without any source information) and it's possible to finish it off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants