[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-discuss] How to GDB step debug a dynamically linked executable
From: |
Ciro Santilli |
Subject: |
Re: [Qemu-discuss] How to GDB step debug a dynamically linked executable in QEMU user mode? |
Date: |
Sat, 14 Jul 2018 22:01:55 +0100 |
OK, I rediscovered: https://bugs.launchpad.net/qemu/+bug/1528239
On Fri, Jul 13, 2018 at 10:32 AM, Ciro Santilli <address@hidden>
wrote:
> https://stackoverflow.com/questions/51310756/how-to-gdb-
> step-debug-a-dynamically-linked-executable-in-qemu-user-mode
>
> For example for ARM, if I compile statically, all works fine:
>
> sudo apt-get install gdb-multiarch gcc-arm-linux-gnueabihf qemu-user
> printf '
> #include <stdio.h>
> #include <stdlib.h>
>
> int main() {
> puts("hello world");
> return EXIT_SUCCESS;
> }
> ' > hello_world.c
> arm-linux-gnueabihf-gcc -ggdb3 -static -o hello_world hello_world.c
> qemu-arm -L /usr/arm-linux-gnueabihf -g 1234 ./hello_world
>
> On another terminal:
>
> gdb-multiarch -q --nh \
> -ex 'set architecture arm' \
> -ex 'set sysroot /usr/arm-linux-gnueabihf' \
> -ex 'file hello_world' \
> -ex 'target remote localhost:1234' \
> -ex 'break main' \
> -ex continue \
> ;
>
> This leaves me at `main`, and I can see the source and step debug as usual.
>
> However, if I remove the `-static`, and keep everything else unchanged, my
> breakpoint never gets hit, and the program runs until completion:
>
> The target architecture is assumed to be arm
> Reading symbols from hello_world...done.
> Remote debugging using localhost:1234
> Reading symbols from
> /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3...(no
> debugging symbols found)...done.
> 0xff7b3b80 in ?? () from /usr/arm-linux-gnueabihf/lib/
> ld-linux-armhf.so.3
> Breakpoint 1 at 0x50c: file hello_world.c, line 5.
> Continuing.
> [Inferior 1 (Remote target) exited normally]
>
> The executable itself does work fine however:
>
> qemu-arm -L /usr/arm-linux-gnueabihf ./hello_world
>
> prints:
>
> hello world
>
> I have seen: https://stackoverflow.com/questions/20590155/how-to-
> single-step-arm-assembler-in-gdb-on-qemu but it didn't cover the case of
> dynamically linked executables specifically.
>
> Tested on Ubuntu 18.04, gdb-multiarch 8.1-0ubuntu3,
> gcc-arm-linux-gnueabihf 4:7.3.0-3ubuntu2, qemu-user 1:2.11+dfsg-1ubuntu7.3.
>