Page 1 of 1

Wii - debug through wifi

Posted: Wed Apr 25, 2012 6:55 pm
by Yardape8000
Since the new Wiis no longer have a gamecube port for gecko debugging, what is the feasability of wifi debugging?

It seems like you should be able to put a server into GDB and route the gecko routines to it.

I imagine if it was this simple, then it would have been done by now, so I am wondering what makes this not feasible? It should be able to be a least used for some printf debugging.


(my first post disappeared, so if this gets double posted, sorry.)

Re: Wii - debug through wifi

Posted: Sun May 06, 2012 12:06 am
by WinterMute
Wifi on the Wii is handled entirely by starlet (including the tcp/ip layer) and the powerpc communicates with starlet using interrupts. This makes it rather difficult to implement a reliable gdb stub since it obviously can't communicate with the host gdb when interrupts are disabled. Enabling interrupts will obviously allow parts of your application to continue running which is then likely to cause the whole thing to fall apart when the stub is waiting for commands while halted.

I'm not saying it's impossible but all tests so far have failed quite badly - stepping and continuing between breakpoints just freezes after several iterations.

Re: Wii - debug through wifi

Posted: Sun May 06, 2012 5:17 am
by tueidj
Communication to starlet doesn't require interrupts, you can poll the IPC register to see if a response is ready. But there are also other issues that need to be fixed to make the debug stub more reliable overall (don't rely on the stack being usable in the default exception handler, don't use r2/r13 relative accesses inside the debug stub code, etc).

Re: Wii - debug through wifi

Posted: Tue May 08, 2012 5:20 am
by Yardape8000
I have just been trying wifi code from elsewhere and it seems to work:

The section on "run the net_print server" does not work as is. The code supplied in wii_dev_debug\net_print\sockettest\source\net_print.c does not work as is with IP addresses.

Easily fixed with this code:

Code: Select all

static int clientsocket(const char *rhost, unsigned short port)
  struct hostent *ptrh;  /* pointer to a host table entry     */
  struct sockaddr_in sad;/* structure to hold server's address*/
  int    fd;             /* socket descriptor                 */

  memset((char *)&sad, 0, sizeof(sad)); /* clear sockaddr structure */
  sad.sin_port = htons((u_short)port); 

	struct in_addr myaddr;

	if (inet_aton(rhost, &myaddr))
		// setup 'sa' with binarified address and a couple other things
		sad.sin_family= PF_INET;
		sad.sin_len = sizeof (struct sockaddr_in);
		sad.sin_port= htons (port);
		memcpy ((char *) &sad.sin_addr, &myaddr.s_addr, sizeof(struct in_addr));
		/* Convert host name to equivalent IP address and copy sad */
		sad.sin_family = AF_INET;  /* set family to Internet */
		ptrh = net_gethostbyname(rhost);
		if (((char *)ptrh) == NULL)
			fprintf(stderr, "invalid host: %s\n", rhost);
			return (-1);
		memcpy(&sad.sin_addr, ptrh->h_addr, ptrh->h_length);
  /* Create a socket */
  fd = net_socket(PF_INET, SOCK_STREAM, 0);
  if (fd < 0) {
    fprintf(stderr, "socket creation failed\n");
    return (-1);;
  /* Connect the socket to the specified server */
  if (net_connect(fd, (struct sockaddr *)&sad, sizeof(sad)) < 0) {
    fprintf(stderr, "connect failed\n");
    return (-1);

  return fd;
But that code does not really matter, it is just a sample. All we care about is the debug library.

The library supplied overwrites the normal libdb.a. A better way world be to merge in the code and add it a DEBUG_Init device_type. Maybe called GDBSTUB_DEVICE_WII_TCP


Re: Wii - debug through wifi

Posted: Tue May 08, 2012 6:38 am
by Yardape8000
Further testing of that code shows that it seems to work if the program is well behaved. Stack dumps cause problems for it. And it does seem to loose sync with the tcip on occasion. :(

Oh well, at least I might be able to use the net print stuff to do some printf debugging. Beats getting up, removing the SD card with my fprintf logs, putting it in the computer, ... :)

Re: Wii - debug through wifi

Posted: Fri Aug 10, 2012 5:56 pm
by DRS
Would it be possible to run a ppc version of gdb on the wii itself? Or would that suffer from the same interrupt issues?



Re: Wii - debug through wifi

Posted: Mon Feb 24, 2014 3:23 pm
by Onion_Knight

Did you manage to actually get GDB client to communicate to the wii? My GDB is dumping a message, " unrecognized item "timeout" in "qsupported" fixed in linux ".

Re: Wii - debug through wifi

Posted: Sun Dec 28, 2014 6:40 am
by antidote
@DRS, you can't run your program and gdb at the same time on the Wii. The Wii "os" isn't designed to be multitasking.