Maybe psp-gdb or psp-gcc buged or I do something wrong.

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

Moderators: cheriff, TyRaNiD

Post Reply
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Maybe psp-gdb or psp-gcc buged or I do something wrong.

Post by Cy-4AH »

The problem is that in psp-gdb breakpoints break program in incorrect places and in running by steps program enter in unrealizable conditions and jump over some lines. But I know that program work like it must to work because on psp screen I see right behavior.
I have that problem before and thinked that it's psp-gdb bug, but yesterday I complelety reinstalled toolchain with gdb and problem stayed.
Maybe I do somethins wrong, can you correct me?
So, there is soure of my program:
File main.cpp:

Code: Select all

#include "../CyLib/Include/CyLib.h"

#define getPad sceCtrlReadBufferPositive
#define getLatch sceCtrlReadLatch

PSP_MODULE_INFO("Control Test", PSP_MODULE_USER, 1, 1);

int main()
{
    pspDebugScreenInit();
    SetupCallbacks();

    printf("Control Test Programm\n");
    int cycle = 200000;
    sceCtrlSetSamplingCycle(cycle);
    sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);
    
    SceCtrlData pad_data;
    SceCtrlLatch pad_latch;
    while (gRunning)
    {
        int cyr_cycle;
        char x;
        getPad(&pad_data, 1);
        getLatch(&pad_latch);
        sceCtrlGetSamplingCycle(&cyr_cycle);
        pspDebugScreenSetXY(0, 0);
        if (pad_data.Buttons & PSP_CTRL_RIGHT) cycle += 10;
        if (pad_data.Buttons & PSP_CTRL_LEFT && cycle >= 10) cycle -= 10;
        if (pad_data.Buttons & PSP_CTRL_UP) cycle += 100;
        if (pad_data.Buttons & PSP_CTRL_DOWN && cycle >= 100) cycle -= 100;
        if (pad_data.Buttons & PSP_CTRL_RTRIGGER)
        	cycle += 1000;    //  <- Line 33 I know it exactly
        if &#40;pad_data.Buttons & PSP_CTRL_LTRIGGER && cycle >= 1000&#41;
        	cycle -= 1000;     //  <-  Line 35
        if &#40;pad_data.Buttons & PSP_CTRL_TRIANGLE&#41; break;
         x = pad_data.Buttons & PSP_CTRL_CROSS ? 'X' &#58; 'O';
        if &#40;cycle >= 1&#41; cycle--;

        printf&#40;"Current sampling cycle&#58;  %8d\nCurrent value try cycle&#58; %8d\nX &#91;%c&#93;\n", cyr_cycle, cycle, x&#41;;
        printf&#40;"Latch&#58; MAKE&#58; %8X BREAK %8X PRESS %8X RELEASE %8X\n", pad_latch.uiMake, pad_latch.uiBreak, pad_latch.uiPress, pad_latch.uiRelease&#41;;
        sceCtrlSetSamplingCycle&#40;cycle&#41;;
    &#125;
    sceKernelExitGame&#40;&#41;;
&#125;
File CyLib.h:

Code: Select all

#ifndef _CY_LIB_
#define _CY_LIB_

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>

#define printf pspDebugScreenPrintf

int exit_callback&#40;int arg1, int arg2, void *common&#41;;
int CallbackThread&#40;SceSize args, void *argp&#41;;
int SetupCallbacks&#40;&#41;;
extern bool gRunning;

#endif
File CyLib.cpp

Code: Select all

#include "../Include/CyLib.h"

bool gRunning;

int exit_callback&#40;int arg1, int arg2, void *common&#41;
&#123;
	gRunning = false;
    return 1;
&#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;&#41;
&#123;
    int thid = 0;
    gRunning = true;

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

Code: Select all

TARGET = Control_Tst
OBJS = main.o ../CyLib/Src/CyLib.o

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

#LIBS=-lstdc++

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Control Test

#PSPSDK = c&#58;/cygwin/usr/local/pspdev/psp/sdk
PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
I work in windows.
I added to PATH variable value C:\cygwin\bin, so I run all executables not via bash just like ordinal exe file.
PSP FW is 3.03OE-C
In psplink.ini enabled usbhost, usbshell, usbgdb.
So when I get Control_Tst.elf compiled I do:
Run usbshell -v.
Run pcterm.
In pcterm type debug Contrl_Tst.elf.
Run psp-gdb Control_Tst.elf.
In psp-gdb type:
target remote localhost:10001 //all is work, successfully connected
break main
c //successfully breaked on main entry point
break 35
c //program run until left trigger pressed, it is correct behavior
//when left trigger pressed psp-gdb write ... stoped... at line cycle-=1000;
//then when program stoped I type:
break 33
c //and program instantly stop and psp-gdb write ...stoped .. at line cycle+=1000
c
c
c //always the same
But! RTRIGGER wasn't pressed and on psp screen I see that cycle not increased by 1000.
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Post by Cy-4AH »

Of course sorry for my english. But anyone have any ideas?
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

One thing to bear in mind when debugging is due to optimisation (which can utterly screw up MIPS stuff) then steping and breaking inside code can sometimes cause problem. Try changing your CFLAGS from -O2 to -O0 and see if that helps any.
gbj1
Posts: 45
Joined: Thu Feb 08, 2007 6:39 pm

Post by gbj1 »

gdb is still buggy, I think. I can see almost every one week there is an update to the psp-gdb on the svn.
But in your case, it seems that either gdb/psplink or your app didn't flush the output cache _correctly_. It was probably caused by code optimizion, but it rarely happens if the compilers/debuggers are fully bug-fixed, try to update your toolchain and see what happens. Also, you can try to add some output status on the psp screen( I mean, not only cycles but 'L_PRESSED' , 'R_PRESSED', 'CYCLE CHANGED FROM N TO N') along with gdb breakpoints, that would be another solution for now.
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Post by Cy-4AH »

Thx, TyRaNiD. It's helped.
Post Reply