Debug file not receiving characters

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

Moderators: cheriff, TyRaNiD

Post Reply
platform
Posts: 13
Joined: Wed Aug 26, 2009 5:53 pm

Debug file not receiving characters

Post by platform »

I'm building my app using kxploit and installing it on 3.52 M33 firmware to the PSP/GAME150 directory.

I use the following code to print to a debug file:

Code: Select all

FILE * g_DbgFile;

void DBG_Init() 
{
#ifdef DBG_TO_FILE
	g_DbgFile = fopen ("./simpleplatformdbg.txt","w");
	fprintf ( g_DbgFile, "Debug file opened" );
#endif
}
Once I run the app the txt file appears in the application directory but there is no text within it.

What am I doing wrong?
platform
Posts: 13
Joined: Wed Aug 26, 2009 5:53 pm

Post by platform »

I've tried adding a fflush incase that was the problem but still no joy.

One thought I've had is to use the SceIo API instead. This raises a couple of questions in my mind.

(i) Should I expect fprintf to work on the PSP?

(ii) This is an SDL app. Will this interfere with the SceIo API?
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

Did you close the file?
platform
Posts: 13
Joined: Wed Aug 26, 2009 5:53 pm

Post by platform »

Yes, closing the file writes everything to it.

But this isn't a very good solution since I'm trying to debug a problem that crashes the PSP necessitating a power up.

Surely I don't have to close and reopen the file each time I want to log to it.

Or is there a way of trapping the crash so that I can close the file appropriately?
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

>Surely I don't have to close and reopen the file each time I want to log to it.
What's wrong with that?
You could use psplink and print to stderr to see your debug info

>Or is there a way of trapping the crash so that I can close the file appropriately?
Install an exception handler
Link
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

You really shouldn't be doing anything with the 1.50 kernel anymore. There is simply NO need for it for almost any homebrew application.
platform
Posts: 13
Joined: Wed Aug 26, 2009 5:53 pm

Post by platform »

Torch wrote:You really shouldn't be doing anything with the 1.50 kernel anymore. There is simply NO need for it for almost any homebrew application.
Thanks for the tip. The deal is I've picked up a project from a couple of years ago so my setup is outdated.

If someone could link me to a thread summarising the most current stable environment (toolchain, firmware, etc.) it would be most appreciated.
platform
Posts: 13
Joined: Wed Aug 26, 2009 5:53 pm

Post by platform »

psPea wrote:>Surely I don't have to close and reopen the file each time I want to log to it.
What's wrong with that?
Isn't that innefficient?
ab5000
Posts: 74
Joined: Tue May 06, 2008 2:37 am

Post by ab5000 »

platform wrote:
psPea wrote:>Surely I don't have to close and reopen the file each time I want to log to it.
What's wrong with that?
Isn't that innefficient?
i read it's not possible to do a fflush on psp. You can do a devctl to memorystick to fulsh ALL the files. opening, writing and closing is more efficient ;)

Code: Select all

%&#58;include<stdio.h>
int _&#40;int __,int ___,int ____,int _____&#41;
<%for&#40;;____<___;_____=_____*__,____++&#41;;
return _____;%>main&#40;&#41;<%printf
&#40;"%d\n",_&#40;2,5,0,1&#41;&#41;;%>
platform
Posts: 13
Joined: Wed Aug 26, 2009 5:53 pm

Post by platform »

ab5000 wrote:
platform wrote:
psPea wrote:>Surely I don't have to close and reopen the file each time I want to log to it.
What's wrong with that?
Isn't that innefficient?
i read it's not possible to do a fflush on psp. You can do a devctl to memorystick to fulsh ALL the files. opening, writing and closing is more efficient ;)
ab - thanks for the tip, looks like I'll get my head around installing the exception handler.

pea - when I try the open, write, close regime I find two problems
On the development machine I keep getting a crash on the fprintf after 10 secs or so.
Execution on the PSP is horribly slow and eventually I get the crash.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

As pointed out if you get psplink running it comes with its own exception handler so you dont need to set up anything else and will help in development and debugging to boot.
ab5000
Posts: 74
Joined: Tue May 06, 2008 2:37 am

Post by ab5000 »

BTW, this is from pspsdk/src/libc/stdio.c:

Code: Select all

int fflush&#40;FILE *stream&#41;
&#123;
  int ret = EOF; // Same as default case below.

  switch&#40;LOCAL_FILE&#40;stream&#41;->type&#41; &#123;
    case STD_IOBUF_TYPE_GE&#58;
    case STD_IOBUF_TYPE_STDOUTHOST&#58;
      /* stdout & stderr are never buffered. */
    case STD_IOBUF_TYPE_UMD&#58;
      /* cd-rom files are read-only so no write buffer to flush. */
      ret = 0;
      break;
    case STD_IOBUF_TYPE_MS&#58;
      if &#40;LOCAL_FILE&#40;stream&#41;->flag & &#40;_IOWRT | _IORW&#41;&#41; &#123;
        //if &#40;ret != 0&#41; ret = EOF;
		  /* Need to implement sync or something */
      &#125;
      else ret = 0;
      break;
    case STD_IOBUF_TYPE_HOST&#58;
      /* flush host file write buffer. */
      if &#40;LOCAL_FILE&#40;stream&#41;->flag & &#40;_IOWRT | _IORW&#41;&#41; ret = 0;
      else ret = 0;
      break;
    default&#58;
      /* unknown/invalid I/O buffer type. */
      ret = EOF;
  &#125;
  return &#40;ret&#41;;
&#125;
as you can see, flushing isn't implemented for MS ;)

Code: Select all

%&#58;include<stdio.h>
int _&#40;int __,int ___,int ____,int _____&#41;
<%for&#40;;____<___;_____=_____*__,____++&#41;;
return _____;%>main&#40;&#41;<%printf
&#40;"%d\n",_&#40;2,5,0,1&#41;&#41;;%>
platform
Posts: 13
Joined: Wed Aug 26, 2009 5:53 pm

Post by platform »

TyRaNiD wrote:As pointed out if you get psplink running it comes with its own exception handler so you dont need to set up anything else and will help in development and debugging to boot.
OK, so I'm now trying to install the most recent toolchain but I can't find libusb-dev for OSX anywhere. Does anyone know where this is?
m0skit0
Posts: 191
Joined: Tue Jun 02, 2009 8:58 pm

Post by m0skit0 »

Why don't you just do this:

- Open as append
- Write data
- Close

That's how i do it, and in combination with psplink it works like a charm ;)
The Incredible Bill Gates wrote:The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
Post Reply