Win32 native Toolchain for PSPSDK

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

Post by theHobbit »

Thanks, i just installed cdt 5.0.1 and it worked fine.
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

Post by theHobbit »

Just to let you know, i have compiled successfully the simple cube demo following your tutorial, wich is really nice hope you can continue working on it, specially the debugging part.

When i start debugging the app there is some error with the sceDisplayWaitVblankStart function, it complains about something like
"GDB is unable to find the start of the function at 0x880a408", i have managed to Step into other sce functions by pointing to the corrent source path, but does not work with this function. Will take a look at it.

Anyway, thanks for your work on this..
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

theHobbit wrote:When i start debugging the app there is some error with the sceDisplayWaitVblankStart function, it complains about something like
"GDB is unable to find the start of the function at 0x880a408", i have managed to Step into other sce functions by pointing to the corrent source path, but does not work with this function.
that's exactly the part I was talking about :
There is also an issue with stepping over sce-like functions : it breaks in the stub function (jr $ra; syscall ...) and trying to step out is like resuming execution. Quite an annoyance.
can you give more information about how you deal those other sce functions ?
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

Post by theHobbit »

Well enabling the Instruction Stepping Mode in the Debug view, allows me to step over any function withow breaking the program, even the sceDisplay* or sceGe* ones, but it does show a "No source available for "" " warning with these.

Maybe because these functions are part of an external prx, like the audio and display drivers from the psp firmware?. Speaking of wich have anyone managed to debug a prx loaded at runtime?. Is it posible?.
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

theHobbit wrote:Well enabling the Instruction Stepping Mode in the Debug view, allows me to step over any function withow breaking the program, even the sceDisplay* or sceGe* ones, but it does show a "No source available for "" " warning with these.

so it is like I said :
In fact, I need to debug per instruction to be sure to follow the execution flow.
theHobbit wrote:Maybe because these functions are part of an external prx, like the audio and display drivers from the psp firmware?. Speaking of wich have anyone managed to debug a prx loaded at runtime?. Is it posible?.
kernel sce-like functions are external and are called through a stub like "jr $ra; syscall ..." and debug probably cannot find any reference to a source line as it is external (no debug description) :/.
Heimdall
Posts: 245
Joined: Thu Nov 10, 2005 1:29 am
Location: Netherlands
Contact:

Post by Heimdall »

I've updated the SDK to make alias for the GCC and G++ and the tutorial.

I've rebuilt the pspsh and usbhostfs_pc and will try it at home today and see if it interferes with firefox and can debug several times in a row...
Heimdall
Posts: 245
Joined: Thu Nov 10, 2005 1:29 am
Location: Netherlands
Contact:

Post by Heimdall »

hlide wrote:Some progress but just some. I need to close FireFox so PSPSH can run properly (displaying a prompt like "host0:>") .

And yes debugging is not working properly. When I tried cube.prx (-g -O0), it seemed to work. But with my source (-g O2), I have kind of erratic behavior in the source windows.

In fact, I need to debug per instruction to be sure to follow the execution flow. And the normal "step in", "step over" and "step out" don't seem to work as I used to with visual studio, making them mostly unusable.

There is also an issue with stepping over sce-like functions : it breaks in the stub function (jr $ra; syscal ...) and trying to step out is like resuming execution. Quite an annoyance.

Is that normal ?
So i've been trying the psplink stuff in a clean pc installation. I've installed my eclipse 5.0.1 (Ganymede SR1) setup the cube project for debugging (CFLAGS += -g) and (BUILD_PRX=1).

Setup the 2 external tools:

usbhostfs_pc and pspsh.

Then rebuild the cube projet.

Once I've the cube project compiled, I've started the external tool usbhostfs_pc, since I configured it to use the project location, I need to highlight it from the project explorer before run the tool, once I get it ok, I get on the console a connected to device.

This i just leave running all the time, so now i start the other tool, the pspsh, after the credits i type:

./cube.prx

and I see the cube rotating on the PSP, so everything is OK. I then type reset and prepare for the debugging session by typing:

debug cube.prx

I get a message saying the prx is loaded so i start my debugger from eclipse, it stops in the start of the main function and then i let it run. Everything OK here, so I stop the debugger session on the stop button.

Now, to debug again I need to go to the console window, and select the pspsh console (which you can select by using the second icon from the right to the left, if i'm not mistaken, the tooltip can lead you better) and type again:

debug cube.prx

and start the eclipse debugger and it works.

I've done this a couple of times in a row and I managed to debug as many times as I wanted.

About the stepping issues, I have the same issue and also get it if I debug native applications, so I guess... it is again either some bug on gdb or the eclipse gdb frontend, but I need to look into it further...

About firefox, I get no issues, I got however a problem in my work machine because some service was already binded to the 10000 port, make sure that your firefox has no plugin or something that binds to the ports 10000 to 10010. That could be it.
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

Heimdall wrote:About the stepping issues, I have the same issue and also get it if I debug native applications, so I guess... it is again either some bug on gdb or the eclipse gdb frontend, but I need to look into it further...
yes, those are the left issues with Eclipse debug (and when I don't run FireFox of course) right now for me.
Heimdall wrote:About firefox, I get no issues, I got however a problem in my work machine because some service was already binded to the 10000 port, make sure that your firefox has no plugin or something that binds to the ports 10000 to 10010. That could be it.
It makes sense.
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

Need help with gprof

Post by theHobbit »

Hi, i'm trying to profile some code (from timidity++) but this is all i'm getting with gprof.

Code: Select all

Flat profile:

Each sample counts as 0.001 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name    
  0.00      0.00     0.00  7755950     0.00     0.00  sceKernelRegisterExitCallback

			Call graph


granularity: each sample hit covers 2 byte(s) no time propagated

index % time    self  children    called     name
                0.00    0.00 7755950/7755950     <hicore> &#40;2&#41;
&#91;1&#93;      0.0    0.00    0.00 7755950         sceKernelRegisterExitCallback &#91;1&#93;
-----------------------------------------------

Index by function name

   &#91;1&#93; sceKernelRegisterExitCallback
I'm calling gprof_cleanup() before sceKernelExitGame() as suggested in your tutorial. Also i had to remove a call to sceKernelDeleteThread wich deletes some controller/hprm thread because it was hanging the app, and gprof complained about an unexpected end of file.
Heimdall
Posts: 245
Joined: Thu Nov 10, 2005 1:29 am
Location: Netherlands
Contact:

Post by Heimdall »

Are you compiling and linking everything with -pg ?

It looks like GCC didn't instrument the binary code to add the profilling data.

Check if you have in your CFLAGS = -pg and you did a make clean before...
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

Post by theHobbit »

Yes everything is compiled and linked with -pg. Now just to let you know, I thought gprof was already part of the pspsdk but when i tryied to compile the code there was an error about some undefined reference to _mcount and there was no gprof sample in the pspsdk samples either. So i downloaded this file http://urch.in/gprof/gprof.zip and added the prof.c and mcount.S file to the project and everything compiled fine, but i'm not getting the desired results.

Also just tryied the gprof sample from the gprof.zip file but the gmon.out file is not being created :(. Am I missing something?

[EDIT]
Ok, putting PSP_HEAP_SIZE_KB( 256 ); in the gprof sample did the trick, tryied with lower heap values but with no luck. Is this normal? I'm working with a PSP Slim 5.00 m33-6.
Heimdall
Posts: 245
Joined: Thu Nov 10, 2005 1:29 am
Location: Netherlands
Contact:

Post by Heimdall »

humm... i thought i had patched the SDK to include the gprof stuff but i guess i lost that patch, about the heap i usually always allocate all the heap i never run into that but it is a nice thing for me to add to the tutorial...
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

Post by theHobbit »

Mmm, i'm getting the same result with the gprof sample, only the sceKernelRegisterExitCallback is being profiled ...
Heimdall
Posts: 245
Joined: Thu Nov 10, 2005 1:29 am
Location: Netherlands
Contact:

Post by Heimdall »

Ok, so I've debugged this and here are my findings:

BUILD_PRX = 1 will not give you a gmon.out (profiler doesn't work, don't know why yet)

Code: Select all

TARGET = gprof
OBJS = main.o
LIBS = -lpspprof

INCDIR = 
CFLAGS = -G0 -Wall -pg
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = gprof test

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
With this makefile i managed to get the exact same gmon i used on the tutorial and this is my sample C code:

Code: Select all

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspprof.h>
#include <pspdisplay.h>
#include <stdio.h>
#include <stdlib.h>

PSP_MODULE_INFO&#40;"GPROF", 0x0000, 1, 1&#41;;
/* Define the main thread's attribute value &#40;optional&#41; */
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER&#41;;

extern void gprof_cleanup&#40;&#41;;

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41;
&#123;
    sceKernelExitGame&#40;&#41;;

    return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41;
&#123;
    int cbid;

    cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
    sceKernelRegisterExitCallback&#40;cbid&#41;;

    sceKernelSleepThreadCB&#40;&#41;;

    return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41;
&#123;
    int thid = 0;

    thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, THREAD_ATTR_USER, 0&#41;;
    if&#40;thid >= 0&#41;
    &#123;
        sceKernelStartThread&#40;thid, 0, 0&#41;;
    &#125;

    return thid;
&#125;

static int dummy = 0;
static int dummy2 = 0;

void nested&#40;&#41;
&#123;
    dummy2++;
&#125;

void loops_10_times&#40;&#41;
&#123;
    if &#40;dummy & 1&#41;
    &#123;
        nested&#40;&#41;;
    &#125;

    dummy++;
&#125;

void wait1second&#40;&#41;
&#123;
    sceKernelDelayThread&#40;1000000&#41;;
&#125;
    
void wait2seconds&#40;&#41;
&#123;
    sceKernelDelayThread&#40;2000000&#41;;
&#125;

int main&#40;void&#41;
&#123;
    int i;

    pspDebugScreenInit&#40;&#41;;
    SetupCallbacks&#40;&#41;;

    for&#40;i = 0; i < 10; i++&#41;
    &#123;
        loops_10_times&#40;&#41;;
    &#125;

    wait1second&#40;&#41;;
    wait2seconds&#40;&#41;;
    wait1second&#40;&#41;;

    gprof_cleanup&#40;&#41;;        
    sceKernelExitGame&#40;&#41;;
    return 0;
&#125;
If i enable -O2 GCC is smart enough to inline everything in the main method and I get the same result you were having, without automatic optimizations it works as expected.
theHobbit
Posts: 65
Joined: Sat Sep 30, 2006 5:26 am

Post by theHobbit »

Thanks a lot for your help, it's working as expected now. By the way if you use PSP_HEAP_SIZE_KB( 256 or higher ) in the prx, it does create a gmon file (around the same size) but with only the sceKernelRegisterExitCallback function.

Hope someone can figure it out.
willow :--)
Posts: 107
Joined: Sat Jan 13, 2007 11:50 am

Post by willow :--) »

When trying to compile one of my projects with version 0.9.3 (as found on sourceforge.net), I get the following error:

Code: Select all

C&#58;/pspsdk/psp/sdk/include/pspmpeg.h&#58;356&#58; error&#58; 'SceMpegAuMode' has not been declared

Commenting out the following lines in pspmpeg.h seems to solve my issues. Could someone confirm I'm not doing something completely stupid?

Code: Select all

// Missing API
SceInt32 sceMpegQueryPcmEsSize&#40;SceMpeg *mp, SceInt32 *iEsSize, SceInt32 *iOutSize&#41;;
SceInt32 sceMpegChangeGetAuMode&#40;SceMpeg *mp, SceMpegStream *pStream, SceMpegAuMode iAuMode&#41;;
SceInt32 sceMpegGetPcmAu&#40;SceMpeg *mp, SceMpegStream *pStream, SceMpegAu *pAu, SceInt32 *iAttr&#41;;
SceInt32 sceMpegFlushStream&#40;SceMpeg *mp, SceMpegStream *pStream&#41;;
SceInt32 sceMpegAvcDecodeDetail&#40;SceMpeg *mp, SceMpegAvcDecodeDetailInfo *pDetail&#41;;
Heimdall
Posts: 245
Joined: Thu Nov 10, 2005 1:29 am
Location: Netherlands
Contact:

Post by Heimdall »

you're not it is my fault i build the sdk with my experimental patches, sorry about that...
willow :--)
Posts: 107
Joined: Sat Jan 13, 2007 11:50 am

Post by willow :--) »

Heimdall wrote:sorry about that...
Haha, don't be, I'm very thankful for this toolchain, it's made the development process for JGE applications way easier! (JGE allows to create both a windows and a psp binary with the same code. It's easier to debug a windows application than a PSP one, but switching between Linux and windows for compilation all the time was a nightmare. And cygwin was not my cup of tea)
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

I use newest SDK version for Ubuntu 9.04, made a fresh install (!) especially for this SDK! I am making a PSP port of game Meritous. I already ported the source code from C to C++ and compiled it sucessfully, but it gives me just a black screen and popping noise. Version compiled on Ubuntu standard gcc works fine. I decided to make some log file fprintfs, but neither setbuf(log, NULL) or fflush(log) does NOT save anything to log file! I don't use any IDE. Game uses SDL, SDL_mixer and SDL_image. Here's some code:
Makefile

Code: Select all

TARGET = meritous
OBJS = 	src/levelblit.o \
		src/mapgen.o \
		src/demon.o \
		src/gamemap.o \
		src/tiles.o \
		src/save.o \
		src/help.o \
		src/audio.o \
		src/boss.o \
		src/ending.o

INCDIR = 
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS =

LIBS = -lSDL_mixer -logg -lvorbis -lvorbisenc -lvorbisidec -lvorbisfile -lSDL_image -ljpeg -lpng -lz -lSDLmain -lSDL -lm -lc

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Meritous

PSPSDK=/home/marach/pspsdk/psp/sdk
PSPBIN = $&#40;PSPSDK&#41;/../bin
CFLAGS += $&#40;shell $&#40;PSPBIN&#41;/sdl-config --cflags&#41;
LIBS += $&#40;shell $&#40;PSPBIN&#41;/sdl-config --libs&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
Beggining of main

Code: Select all

#define SCREEN_W 480

#define SCREEN_H 272
#define BPP 8
/* some code ... */
extern "C" int main&#40;int, char**&#41;

&#123;
	FILE* log = fopen&#40;"Log.txt", "w"&#41;;
	setbuf&#40;log, NULL&#41;;
	fprintf&#40;log, "App start\n"&#41;;
	fflush&#40;log&#41;;


	int on_title = 1;
	int executable_running = 1;
	SDL_Surface *title, *title_pr, *asceai;
	Uint8 *src_p, *col_p;
	int i;
	int light = 0;
	int x, y;
	int pulse&#91;SCREEN_W * SCREEN_H&#93;;
	int precalc_sine&#91;400&#93;;
	int tick = 10000000;
	int option = 0;
	int can_continue = 0;
	int maxoptions;
	
	int last_key = 0;
	int ticker_tick = 0;
	unsigned int stime = 0;
	fprintf&#40;log, "Init 1\n"&#41;;

	if &#40;&#40;RECORDING&#41; && &#40;PLAYBACK&#41;&#41; &#123;
		exit&#40;1&#41;;
	&#125;

	srand&#40;time&#40;NULL&#41;&#41;;
	if &#40;RECORDING&#41; &#123;
		record_file = fopen&#40;record_filename, "wb"&#41;;
		stime = time&#40;NULL&#41;;

		fputc&#40;stime & 0x000000FF, record_file&#41;;
		fputc&#40;&#40;stime & 0x0000FF00&#41; >> 8, record_file&#41;;
		fputc&#40;&#40;stime & 0x00FF0000&#41; >> 16, record_file&#41;;
		fputc&#40;&#40;stime & 0xFF000000&#41; >> 24, record_file&#41;;

		srand&#40;stime&#41;;
	&#125;

	if &#40;PLAYBACK&#41; &#123;
		record_file = fopen&#40;record_filename, "rb"&#41;;
		stime = fgetc&#40;record_file&#41;;
		stime |= fgetc&#40;record_file&#41; << 8;
		stime |= fgetc&#40;record_file&#41; << 16;
		stime |= fgetc&#40;record_file&#41; << 24;
		srand&#40;stime&#41;;
	&#125;
	fprintf&#40;log, "Init 2\n"&#41;;
	
	asceai = IMG_Load&#40;"dat/i/asceai.png"&#41;;
	screen = SDL_SetVideoMode&#40;SCREEN_W, SCREEN_H, BPP, SDL_SWSURFACE | SDL_FULLSCREEN&#41;;

	InitAudio&#40;&#41;;
	fprintf&#40;log, "Init 3\n"&#41;;
	text_init&#40;&#41;;

	for &#40;i = 0; i < 400; i++&#41; &#123;
		precalc_sine&#91;i&#93; = sin&#40;&#40;float&#41;i / 400 * M_PI * 2&#41;*24+24;
	&#125;

	for &#40;i = 0; i < screen->w * screen->h; i++&#41; &#123;
		x = i % SCREEN_W;
		y = i / SCREEN_W;
		pulse&#91;i&#93; = dist&#40;x, y, SCREEN_W / 2, SCREEN_H / 2&#41;;
	&#125;

	SetGreyscalePalette&#40;&#41;;
	fprintf&#40;log, "Init 4\n"&#41;;

	// asceai logo
	SDL_BlitSurface&#40;asceai, NULL, screen, NULL&#41;;
	for &#40;i = 0; i < 75; i++&#41; &#123;
		SetTitlePalette&#40;i * 5 - 375, i * 5 - 120&#41;;
		VideoUpdate&#40;&#41;;
		DummyEventPoll&#40;&#41;;
		EndCycle&#40;20&#41;;
	&#125;
	SDL_Delay&#40;500&#41;;
	for &#40;i = 0; i < 50; i++&#41; &#123;
		SetTitlePalette&#40;i * 5, 255 - &#40;i * 5&#41;&#41;;
		VideoUpdate&#40;&#41;;
		DummyEventPoll&#40;&#41;;
		EndCycle&#40;20&#41;;
	&#125;
	SDL_Delay&#40;500&#41;;
	for &#40;i = 0; i < 50; i++&#41; &#123;
		SetTitlePalette&#40;255, &#40;i * 5&#41;+5&#41;;
		VideoUpdate&#40;&#41;;
		DummyEventPoll&#40;&#41;;
		EndCycle&#40;20&#41;;
	&#125;
	fprintf&#40;log, "Init 5\n"&#41;;
Commented lines are removed, like ones for command line parameters or window icons. Repeating, log file IS CREATED, but it's EMPTY.
HELP!
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

I tried compiling on Windows (XP), same error. Newest SDK version.
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
Marach
Posts: 31
Joined: Sun May 24, 2009 7:16 pm

Post by Marach »

When I try to run the .elf file with PSPLink, it displays me:

Code: Select all

Failed to Load/Start module 'host0&#58;/meritous.elf' Error&#58; 0x80020148
Any ideas? Help please!

EDIT:
Nevermind, fixed, i had to build a prx.

BUT, when I tried to run that prx, console screen just went off and pspsh stopped responding after writing exprint. help...
EDIT:
That's wat I received in usbhostfs screen:

Code: Select all

Error reading open data cmd->extralen 9d, ret -116
Error in open command
?
Why my REAL email adress has been BANNED???
marach5 (at) gmail (dot) com ???
Heimdall
Posts: 245
Joined: Thu Nov 10, 2005 1:29 am
Location: Netherlands
Contact:

Post by Heimdall »

I think from the psplink documentation if you use an OE firmware you must use PRX elf's won't work. From the documentation (page 10):
Try and build the sprite sample now as a PRX file. Edit the Makefile and add the line BUILD_PRX=1 after the ASFLAGS line and type make clean; make. You should now have a sprite.prx file in the sample directory. NOTE: This is important when running code on 3.XOE
which only supports PRXes.
Post Reply