Some weeks ago I managed to get some progress.
I've found this thread where megaman show how to use regular linux gdb with a patched version of ps2gdb :
http://forums.ps2dev.org/viewtopic.php?t=4430
So I've apply the patches to the sources of svn://svn.ps2dev.org/ps2/trunk/ps2gdb (it was the first time I had to work with patched under linux) and it compiled fine.
Accordingly to ps2gdbStub.c : "This project no longer contains a main function. Instead, link it into your own project and call gdb_stub_main from your own main function." - so that's why there is no ps2gdb.elf file anymore, just the library libps2gdbStub.a to be linked to your target .ELF.
So the next step where to make a simple executable, manage to link it to the libps2gdbStub.a (again, first time to link with a library) ensure it calls the gdb_stub_main.
The example makefile :
Code: Select all
EE_BIN = hello.elf
EE_OBJS = hello.o
EE_CFLAGS = -g
EE_INCS = -I$(PS2GDB)/ee
EE_LDFLAGS = -L$(PS2GDB)/lib
EE_LIBS = -lps2gdbStub -lps2ip -ldebug
all: $(EE_BIN)
clean:
rm -f *.elf *.o
include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal
Beginners should note that you must set an environment variable called PS2GDB pointing to the ps2gdb sources. Mine points to /usr/local/ps2dev/ps2gdb .
Also, please note that in the line :
Code: Select all
EE_LIBS = -lps2gdbStub -lps2ip -ldebug
the -lps2gdbStub
should be the first specified, otherwise it will not link! I just hate gcc and makefiles...
The example source (hello.c) :
Code: Select all
#include <stdio.h>
int gdb_stub_main( int argc, char *argv[] );
int main( int argc, char *argv[] )
{
int i=0;
int j;
printf("1\n");
j = gdb_stub_main(argc, argv);
printf("2\n");
while(1)
{
i++;
}
return 0;
}
So, after hitting make, just be sure to copy ps2ips.irx from the sdk to the project folder since it will be loaded when executing hello.elf.
Now I needed to use gdb at linux side, and configured to talk to mips32 target. Since on my ubuntu distro I didn't have the sources of gdb in order to rebuild it after issuing a ./configure I had to get those and do the ./configure step. After successful compiling, I've this after hitting ./gdb :
Code: Select all
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=mips32".
Setting up the environment for debugging gdb.
No symbol table is loaded. Use the "file" command.
No symbol table is loaded. Use the "file" command.
/home/user/Desktop/gdb6.6/gdb-6.6/gdb/.gdbinit:8: Error in sourced command file:
No breakpoint number 0.
(gdb)
Notice the "This GDB was configured as "--host=i686-pc-linux-gnu --target=mips32".".
OK, next step : copying the hello.c, hello.elf and ps2gdbStub.c into a folder and call gdb from there later.
I then executed hello.elf on the PS2 using ps2link and run gdb under linux at my laptop.
As megaman suggested, I typed "set endian little" and tell it to connect to my PS2's IP : "target remote 192.168.1.5:12" and got :
Code: Select all
(gdb) set endian little
The target endianness is set automatically (currently little endian)
(gdb) target remote 192.168.1.5:12
Remote debugging using 192.168.1.5:12
0x00000000 in ?? ()
I then load the hello example at the gdb using the file command :
Code: Select all
(gdb) file hello.elf
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from /home/user/Desktop/gdb6.6/gdb-6.6/gdb/hello.elf...done.
During symbol reading, invalid pointer size 4.
Here is the first problem I currently have : That warning info may explains why I cannot see the contents of the hello example program... But let's proceed.
Issuing a 'ni' and a 'step' command I get the info the execution is at line 1481 of ps2gdbStub.c - so actually, I needed to step out of ps2gdbStub.c in order to reach the hello sources.
Before doing that, we can inspect any variable at the scope : 'print thread_id_g' will show the contents of that variable of the gdbstub_init() function, so it seems gdb didn't have any problem getting the symbols for the ps2gdb library...
Code: Select all
(gdb) ni
1344 }
(gdb) step
gdbstub_init (argc=1088544, argv=0x185) at ps2gdbStub.c:1481
1481 return 0;
(gdb) print thread_id_g
$1 = 37
(gdb) step
1482 }
(gdb) step
gdb_stub_main (argc=1, argv=0xeac08) at ps2gdbStub.c:1518
1518 return 0;
(gdb) list
1513 if( gdbstub_init( argc, argv ) == -1 ) {
1514 gdbstub_error("INIT FAILED\n");
1515 ExitDeleteThread();
1516 return -1;
1517 }
1518 return 0;
1519 }
1520
1521 ///
1522 //
(gdb) step 2
main (argc=1, argv=0xeac08) at hello.c:25
25 printf("2\n");
(gdb) list
20 int i=0;
21 int j;
22
23 printf("1\n");
24 j = gdb_stub_main(argc, argv);
25 printf("2\n");
26
27 while(1)
28 {
29 i++;
(gdb) print i
No symbol "i" in current context.
(gdb) print j
No symbol "j" in current context.
So has you can see above, it's possible to do normal gdb stuff like stepping through the source, get the listing, inspect variables and of course, set breakpoints (although I didn't above).
The only problem is that I cannot inspect any variable at the example hello... (what's the reason for the 'During symbol reading, invalid pointer size 4' warning?)
Anyone willing to help?
The patched ps2gdb sources are at :
http://www.mediafire.com/?v10mdv0h9gx
and the binaries I build for this example at:
http://www.mediafire.com/?iqqdimevx0n