How to debug using QEMU in Debian 10

Viewed 131

Here is my program:

#include <stdio.h>

int main(void) {
    printf("Hello world\n");
    return 0;
}

That's how I compile it

aarch64-linux-gnu-gcc -O0 -g3 main.c

I started the a.out like this:

qemu-aarch64-static -L /usr/aarch64-linux-gnu -singlestep -g 1234 ./a.out

And then I started gdb

$ gdb-multiarch -q ./a.out
Reading symbols from ./a.out...done.
(gdb) set sysroot /usr/aarch64-linux-gnu/
(gdb) target remote :1234
Remote debugging using :1234
Reading symbols from /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1...(no debugging symbols found)...done.
0x0000004000814040 in ?? ()
   from /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1
(gdb) break main
Breakpoint 1 at 0x76c: file main.c, line 4.
(gdb) c
Continuing.
[Inferior 1 (Remote target) exited normally]

My question: why gdb didn't stop on main entrance and program just finished without any break? What am I do wrong?

I've repeated these steps on Ubuntu 20.04 and everything works fine. To be fair, I use ubuntu for a long time and could just forget what I did before, but Debian is fresh.

Versions info:

  • OS: Debian GNU/Linux 10 (buster)
  • QEMU: qemu-aarch64 version 3.1.0 (Debian 1:3.1+dfsg-8+deb10u8)
  • GDB: GNU gdb (Debian 8.2.1-2+b3) 8.2.1
  • GCC: aarch64-linux-gnu-gcc (Debian 8.3.0-2) 8.3.0
0 Answers
Related