Skip to content

GDB stubs not working: DeSmuME process not listening to port supplied via args #938

@AleixMT

Description

@AleixMT

State your operating system:

Linux - ubuntu 20.04. gtk2

DesMuME version

master and 0.9.11

Issue

I want to use the GDB stubs of DeSmuME so I can connect with GDB / Insight and debug homebrew.

My first attempt was with the latest master version of DeSmuME, that I build myself in Docker with the GDB stubs enabled. These are the instructions that I used to build it with GDB stubs enabled:

    git clone https://github.com/TASEmulators/desmume /desmume && \
    mkdir -p /desmume/desmume/src/frontend/posix/build && \
    cd /desmume/desmume/src/frontend/posix && \
    autoreconf -i && \
    ./configure --prefix=/usr --enable-hud --enable-gdb-stub && \
    make -j"$(nproc)" && \
    cd /desmume/desmume/src/frontend/posix/gtk2 && \
    make -j"$(nproc)" && \
    cd /desmume/desmume/src/frontend/posix && \
    make DESTDIR=/tmp/DeSmuME install

After that, I start the emulator with this command:

desmume --arm9gdb-port=1000 /roms/comp_71-prog4-phase1-call1-test.nds &

The output is:

01:50 $ desmume --arm9gdb-port=1000 comp_71-prog4-phase1-call1-test.nds
Gtk-Message: 00:56:14.207: Failed to load module "canberra-gtk-module"
CPU mode: Interpreter
ALSA lib confmisc.c:855:(parse_card) cannot find card '0'
ALSA lib conf.c:5204:(_snd_config_evaluate) function snd_func_card_inum returned error: No such file or directory
ALSA lib confmisc.c:422:(snd_func_concat) error evaluating strings
ALSA lib conf.c:5204:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1342:(snd_func_refer) error evaluating name
ALSA lib conf.c:5204:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5727:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM default
Failed to open device: No such file or directory
Microphone init failed.
DeSmuME 0.9.14 git#0 dev+ x64-JIT SSE2
ALSA lib confmisc.c:855:(parse_card) cannot find card '0'
ALSA lib conf.c:5204:(_snd_config_evaluate) function snd_func_card_inum returned error: No such file or directory
ALSA lib confmisc.c:422:(snd_func_concat) error evaluating strings
ALSA lib conf.c:5204:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1342:(snd_func_refer) error evaluating name
ALSA lib conf.c:5204:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5727:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM default
Using 12 threads for video filter.
SoftRasterizer: Running using 12 additional threads. (Multithreading enabled.)

In the program windows you can see that when you pass the option --arm9gdb-port=1000 the screens are white, which I think is the expected behaviour (the ROM stops execution at the start, and you can start the debugging sessions by resuming execution from debugger). If you do not pass this option then the ROM runs normally, so the with that I have checked that the ROM is actually valid. Here is a visual example:

Image Image

So, after running desmume with desmume --arm9gdb-port=1000 comp_71-prog4-phase1-call1-test.nds, I enter inside a multiarch gdb session with gdb-multiarch in another terminal. In here, I type target remote localhost:1000 to connect to DeSmuME, which I expect to be listening in port 1000 to a GDB client. The error says "Conexión reinicializada por la máquina remota.", which in english translates to "Connection restarted by the remote machine":

01:59 $ gdb-multiarch
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.2) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) target remote localhost:1000
Remote debugging using localhost:1000
Remote communication error.  Target disconnected.: Conexión reinicializada por la máquina remota.
(gdb) 

At this point I was starting to suspect that the GDB stubs were not working, so I look up if any process is listening to port 1000, which I expect DeSmuME to be doing, but I did not find any process listening to that port.

01:50 $ netstat -tla | grep 1000

After that I thought that my building of DeSmuME for the GDB stubs was wrong, maybe I was missing runtime dependencies that I was not aware of or the GDB stubs were broken in this particular version (master). I decided to install DeSmuME from the apt packages, which come with DeSmuME version 0.9.11. I know that this version in Windows has support for GDB stubs because I have used them many times to debug homebrew, so I thought that this version should have them (even though I do not know for sure if it was built with the stubs enabled).

I tried to do the same command, now desmume pointing to desmume 0.9.11 from apt repos (notice also that I change the parameter to --arm9gdb because I am using 0.9.11):

02:15 $ desmume --arm9gdb=1000 comp_71-prog4-phase1-call1-test.nds
Gtk-Message: 02:15:53.493: Failed to load module "canberra-gtk-module"
Failed to set format: Argumento inválido
Microphone init failed.
DeSmuME 0.9.11 svn0 dev+ x64-JIT
STALL
Using 12 threads for video filter.
SoftRast Initialized with cores=12

ROM game code: ####
ROM serial: TWL-####-???
ROM chipID: FFFFFFC2
ROM internal name: HOMEBREW
ROM DSi Enhanced
ROM developer: Unknown

Slot1 auto-selected device type: Retail MC+ROM
Slot2 auto-selected device type: None (0xFF)
CPU mode: Interpreter

In this case we see the "STALL" messages in the console, but if we try to connect from GDB we get the same error as before "Connection restarted by the remote machine". I also could not see the DeSmuME process listening to port 1000 when using netstat -tl or similar.

My issue is that I do not understand why DeSmuME is not listening to the required port, since I think that this is the minimum requirement to start a GDB connection. If you have any guidance or tip on the building of DeSmuME regarding this feature, its support across the versions, runtime dependencies that I am not aware of or a mistake that I am making, please let me know. I also have some knowledge on C and assembly, so I am willing to contribute.

Thank you so much in advance for your help and thank you again for this wonderful peace of software that allowed me to play, teach and develop NDS programs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions