Search code examples
gdbqemuddd-debugger

How can I pass `-gdb tcp::1234` argument for qemu from the linux command line?


This question is related to How can I debug qemu code and the application on the qemu machine at the same time? . Though I can set the arguments for ddd inside ddd's command window, it would be convenient if I could give ddd the whole arguments from the linux command line.
The problem is, if launch ddd with ddd qemu-system-aarch64 command, and I give this command inside the ddd's command window, the qemu program understands it.

set args -machine ab21q,gic-version=max,secure=on,virtualization=true -cpu max -device loader,file=spl/u-boot-spl,addr=0x4000000 -m 1G -nographic -device loader,file=../../LinuxDevDrv/linux-5.15.68/arch/arm64/boot/Image,addr=0x80200000 -gdb tcp::1235 -S

But if I give this arg list in the linux command shell like this,

$ ddd --args ../../QEMU/qemu-6.2.0/build-baremetal/qemu-system-aarch64 -machine ab21q,gic-version=max,secure=on,virtualization=true -cpu max -device loader,file=spl/u-boot-spl,addr=0x4000000 -m 1G -nographic -device loader,file=../../LinuxDevDrv/linux-5.15.68/arch/arm64/boot/Image,addr=0x80200000 -gdb tcp::1235 -S

then, ddd gives me this error inside its command window.

qemu-system-aarch64: tcp::1235: Unknown protocol 'tcp'

Surely -gdb tcp::1235 is the argument for qemu and if I give it inside the ddd command window, ddd understands it, but if I pass it with other arguments with --args for the ddd, qemu doesn't understand it. It looks like the -gdb part is intercepted by ddd and only tcp::1235 is being passed to qemu. How can I get around this problem??


Solution

  • You can stop ddd from processing further arguments using '--'; everything after that it will hand to what it calls the "inferior debugger", which is gdb. '--args' is a gdb option, and everything after that is the command to run and its arguments. So you want a command line like:

    ddd [arguments for ddd] -- [arguments for gdb] --args [qemu binary] [arguments for qemu]
    

    It's probably most reliable to keep a strict separation between gdb arguments and dd arguments; discussion in comments suggests that if ddd finds a gdb argument before '--' it doesn't put it in the right place on the gdb command line.