Wii - debug through wifi

Post Reply
Yardape8000
Posts: 3
Joined: Wed Apr 25, 2012 6:12 pm

Wii - debug through wifi

Post by Yardape8000 » Wed Apr 25, 2012 6:55 pm

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.

Thanks.

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

WinterMute
Site Admin
Posts: 1385
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Wii - debug through wifi

Post by WinterMute » Sun May 06, 2012 12:06 am

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.
Help keep devkitPro toolchains free, Donate today

devkitPro IRC support
Personal Blog

tueidj
Posts: 40
Joined: Thu Dec 10, 2009 9:26 am

Re: Wii - debug through wifi

Post by tueidj » Sun May 06, 2012 5:17 am

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).

Yardape8000
Posts: 3
Joined: Wed Apr 25, 2012 6:12 pm

Re: Wii - debug through wifi

Post by Yardape8000 » Tue May 08, 2012 5:20 am

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));
	}
	else
	{
		/* 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

thoughts?

Yardape8000
Posts: 3
Joined: Wed Apr 25, 2012 6:12 pm

Re: Wii - debug through wifi

Post by Yardape8000 » Tue May 08, 2012 6:38 am

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, ... :)

DRS
Posts: 11
Joined: Fri Nov 06, 2009 1:50 pm

Re: Wii - debug through wifi

Post by DRS » Fri Aug 10, 2012 5:56 pm

Would it be possible to run a ppc version of gdb on the wii itself? Or would that suffer from the same interrupt issues?

reg,

Danny

Onion_Knight
Posts: 1
Joined: Mon Feb 24, 2014 2:57 pm

Re: Wii - debug through wifi

Post by Onion_Knight » Mon Feb 24, 2014 3:23 pm

Yardape8000,

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 ".

antidote
Posts: 12
Joined: Wed Mar 23, 2011 2:54 am

Re: Wii - debug through wifi

Post by antidote » Sun Dec 28, 2014 6:40 am

@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.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest