psp-addr2line question / help

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

Moderators: cheriff, TyRaNiD

Post Reply
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

psp-addr2line question / help

Post by coolkehon »

i have no idea how to use this so can someone explain it and i've looked it up and not really sure of the options etc

now the main reason is my app consit of alot of prx's can psp-addr2line find out which file/line the problem occured on if it occures in a prx and not in the main

how can i use psplink with eclipse on ubuntu 9.04 to debug this app with its prxs because debugging is becomming a pain
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Post by jojojoris »

When you use PSPLINK and your app is crashing you gat an exeption.

If you type right after the crash:
calc $epc-$mod

you get an number like:
0x00015A45

Now you can run:
psp-addr2line -e appname.elf 0x00015A45

The program will output the line in your code which causes the crash.

Code: Select all

int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

well i added -g option and got this when trying to compile

got that same error above with the relocation and i cant figure out how to fix any suggestion would be appreciated

Code:

Code: Select all

relocation truncated to fit: R_MIPS_GPREL16 against `_ftext'

full:
Code:

Code: Select all

exception/exception.o: In function `ExceptionHandler':
exception.c:(.text+0xa8): relocation truncated to fit: R_MIPS_GPREL16 against `_ftext'
collect2: ld returned 1 exit status
make: *** [make.elf] Error 1
here is the thing i'm using for exception handling

Code: Select all

#include <pspkernel.h>
#include <pspsdk.h>
#include <pspctrl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

PspDebugRegBlock exception_regs;

extern SceModule module_info;
extern int _ftext;

static const char *codeTxt&#91;32&#93; =
&#123;
    "Interrupt", "TLB modification", "TLB load/inst fetch", "TLB store",
    "Address load/inst fetch", "Address store", "Bus error &#40;instr&#41;",
    "Bus error &#40;data&#41;", "Syscall", "Breakpoint", "Reserved instruction",
    "Coprocessor unusable", "Arithmetic overflow", "Unknown 14",
    "Unknown 15", "Unknown 16", "Unknown 17", "Unknown 18", "Unknown 19",
    "Unknown 20", "Unknown 21", "Unknown 22", "Unknown 23", "Unknown 24",
    "Unknown 25", "Unknown 26", "Unknown 27", "Unknown 28", "Unknown 29",
    "Unknown 31"
&#125;;

static const unsigned char regName&#91;32&#93;&#91;5&#93; =
&#123;
    "zr", "at", "v0", "v1", "a0", "a1", "a2", "a3",
    "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
    "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
    "t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra"
&#125;;

void ExceptionHandler&#40;PspDebugRegBlock * regs&#41;
&#123;
    int i;
    SceCtrlData pad;

    pspDebugScreenInit&#40;&#41;;
    pspDebugScreenSetBackColor&#40;0x00FF0000&#41;;
    pspDebugScreenSetTextColor&#40;0xFFFFFFFF&#41;;
    pspDebugScreenClear&#40;&#41;;
    pspDebugScreenPrintf&#40;"Your PSP has just crashed!\n"&#41;;
    pspDebugScreenPrintf&#40;"Exception details&#58;\n\n"&#41;;

    pspDebugScreenPrintf&#40;"Exception - %s\n", codeTxt&#91;&#40;regs->cause >> 2&#41; & 31&#93;&#41;;
    pspDebugScreenPrintf&#40;"EPC       - %08X / %s.text + %08X\n", &#40;int&#41;regs->epc, module_info.modname, &#40;unsigned int&#41;&#40;regs->epc-&#40;int&#41;&_ftext&#41;&#41;;
    pspDebugScreenPrintf&#40;"Cause     - %08X\n", &#40;int&#41;regs->cause&#41;;
    pspDebugScreenPrintf&#40;"Status    - %08X\n", &#40;int&#41;regs->status&#41;;
    pspDebugScreenPrintf&#40;"BadVAddr  - %08X\n", &#40;int&#41;regs->badvaddr&#41;;
    for&#40;i=0; i<32; i+=4&#41; pspDebugScreenPrintf&#40;"%s&#58;%08X %s&#58;%08X %s&#58;%08X %s&#58;%08X\n", regName&#91;i&#93;, &#40;int&#41;regs->r&#91;i&#93;, regName&#91;i+1&#93;, &#40;int&#41;regs->r&#91;i+1&#93;, regName&#91;i+2&#93;, &#40;int&#41;regs->r&#91;i+2&#93;, regName&#91;i+3&#93;, &#40;int&#41;regs->r&#91;i+3&#93;&#41;;

    sceKernelDelayThread&#40;1000000&#41;;
    pspDebugScreenPrintf&#40;"\n\nPress X to dump information on file exception.log and quit"&#41;;
    pspDebugScreenPrintf&#40;"\nPress O to quit"&#41;;

    for &#40;;;&#41;&#123;
        sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
        if &#40;pad.Buttons & PSP_CTRL_CROSS&#41;&#123;
            FILE *log = fopen&#40;"exception.log", "w"&#41;;
            if &#40;log != NULL&#41;&#123;
                char testo&#91;512&#93;;
                snprintf&#40;testo, sizeof&#40;testo&#41;, "Exception details&#58;\n\n"&#41;;
                fwrite&#40;testo, 1, strlen&#40;testo&#41;, log&#41;;
                snprintf&#40;testo, sizeof&#40;testo&#41;, "Exception - %s\n", codeTxt&#91;&#40;regs->cause >> 2&#41; & 31&#93;&#41;;
                fwrite&#40;testo, 1, strlen&#40;testo&#41;, log&#41;;
                snprintf&#40;testo, sizeof&#40;testo&#41;, "EPC       - %08X / %s.text + %08X\n", &#40;int&#41;regs->epc, module_info.modname, &#40;unsigned int&#41;&#40;regs->epc-&#40;int&#41;&_ftext&#41;&#41;;
                fwrite&#40;testo, 1, strlen&#40;testo&#41;, log&#41;;
                snprintf&#40;testo, sizeof&#40;testo&#41;, "Cause     - %08X\n", &#40;int&#41;regs->cause&#41;;
                fwrite&#40;testo, 1, strlen&#40;testo&#41;, log&#41;;
                snprintf&#40;testo, sizeof&#40;testo&#41;, "Status    - %08X\n", &#40;int&#41;regs->status&#41;;
                fwrite&#40;testo, 1, strlen&#40;testo&#41;, log&#41;;
                snprintf&#40;testo, sizeof&#40;testo&#41;, "BadVAddr  - %08X\n", &#40;int&#41;regs->badvaddr&#41;;
                fwrite&#40;testo, 1, strlen&#40;testo&#41;, log&#41;;
                for&#40;i=0; i<32; i+=4&#41;&#123;
                    snprintf&#40;testo, sizeof&#40;testo&#41;, "%s&#58;%08X %s&#58;%08X %s&#58;%08X %s&#58;%08X\n", regName&#91;i&#93;, &#40;int&#41;regs->r&#91;i&#93;, regName&#91;i+1&#93;, &#40;int&#41;regs->r&#91;i+1&#93;, regName&#91;i+2&#93;, &#40;int&#41;regs->r&#91;i+2&#93;, regName&#91;i+3&#93;, &#40;int&#41;regs->r&#91;i+3&#93;&#41;;
                    fwrite&#40;testo, 1, strlen&#40;testo&#41;, log&#41;;
                &#125;
                fclose&#40;log&#41;;
            &#125;
            break;
        &#125;else if &#40;pad.Buttons & PSP_CTRL_CIRCLE&#41;&#123;
            break;
        &#125;
		sceKernelDelayThread&#40;100000&#41;;
    &#125;
    sceKernelExitGame&#40;&#41;;
&#125;

void initExceptionHandler&#40;&#41;
&#123;
   SceKernelLMOption option;
   int args&#91;2&#93;, fd, modid;

   memset&#40;&option, 0, sizeof&#40;option&#41;&#41;;
   option.size = sizeof&#40;option&#41;;
   option.mpidtext = PSP_MEMORY_PARTITION_KERNEL;
   option.mpiddata = PSP_MEMORY_PARTITION_KERNEL;
   option.position = 0;
   option.access = 1;

   if&#40;&#40;modid = sceKernelLoadModule&#40;"exception.prx", 0, &option&#41;&#41; >= 0&#41;
   &#123;
      args&#91;0&#93; = &#40;int&#41;ExceptionHandler;
      args&#91;1&#93; = &#40;int&#41;&exception_regs;
      sceKernelStartModule&#40;modid, 8, args, &fd, NULL&#41;;
   &#125;
&#125;
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

What's the makefile look like?

Specifically the -G* flag.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

makefile:

Code: Select all

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
PSPBIN = $&#40;PSPSDK&#41;/../bin
MAKE = $&#40;shell make&#41;

TARGET = make
 
EVENTS = events/Callbacks.o \
		 events/sys_redraw.o \
		 events/control_callbacks.o 
		 
IMPORTS = ../controls/control_bridge.o \
		  ../initconf/initconf_lib.o 
		  
EXPORTS = exports/exports.o \
		  exports/graphics.o 

OBJS = 	main.o \
		exception/exception.o \
		global.o \
		MagnificentG.o \
		Logger.o \
		MagControls.o \
		$&#40;IMPORTS&#41; \
		$&#40;EVENTS&#41; \
		$&#40;EXPORTS&#41; 

INCDIR =
LIBDIR =

#CFLAGS = -O3 -frename-registers -ffast-math -fomit-frame-pointer -g -G0 -Wall
CFLAGS = -Wall -g -G0
CXXFLAGS = $&#40;CFLAGS&#41; -fexceptions -frtti 
#-fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;  

LDFLAGS =

INCS = -I/usr/local/pspdev/include \
	   -I/usr/local/pspdev/psp/include \
	   -I/usr/local/pspdev/psp/sdk/include 

CFLAGS &#58;= $&#40;INCS&#41;

STDLIBS = 
STDLIBS += -lGL -lpspvfpu -lpspirkeyb 
STDLIBS += -lpspctrl -lpspumd -lpsprtc -lpsppower 
STDLIBS += -lpspaudio -lpsphprm -lpspgu -lpspgum 
STDLIBS += -lpspmpeg -lpsprtc -lpspsdk -lmikmod 
STDLIBS += -lpspaudiocodec -lpspatrac3 -lpng 
STDLIBS += -lAac -lFLAC -lvorbisidec -lmad 
STDLIBS += -lpspusb -lpspusbstor -lpspkubridge 
STDLIBS += -lpspsystemctrl_user -lpspinit 
STDLIBS += -lc -lm -lz -lstdc++ -ljpeg 

YOURLIBS = -lSDL_image -lSDL_gfx -lSDL_ttf -lSDL -lconfig++ -lanytype -lunzip 

LIBS = $&#40;YOURLIBS&#41; $&#40;STDLIBS&#41; 

PSP_FW_VERSION = 500
BUILD_PRX = 1
PRX_EXPORTS = exports.exp

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = MagnificentG
PSP_EBOOT_ICON = NULL

include ../locations.mak
include $&#40;PSPSDK&#41;/lib/build.mak

dump&#58; $&#40;shell psp-objdump -t make.elf > objdump.txt&#41;

s_file&#58;	
	$&#40;shell psp-build-exports -s exports.exp&#41;

install&#58;
	mkdir -p $&#40;MAIN_LOC&#41;
	cp -fT EBOOT.PBP $&#40;MAIN_DEST&#41;
	 
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

i did that and i got

Code: Select all

host0&#58;/> Exception - Bus error &#40;data&#41;
Thread ID - 0x04DB5479
Th Name   - user_main
Module ID - 0x00CDFA6D
Mod Name  - "desktop"
EPC       - 0x08F5565C
Cause     - 0x1000001C
BadVAddr  - 0x80020166
Status    - 0x20008613
zr&#58;0x00000000 at&#58;0x09040000 v0&#58;0x00000000 v1&#58;0x00000078
a0&#58;0x09046890 a1&#58;0x00000001 a2&#58;0x09F7FE10 a3&#58;0x00000154
t0&#58;0x00000078 t1&#58;0x00000000 t2&#58;0x00000000 t3&#58;0x00000000
t4&#58;0x0000003F t5&#58;0x0904C490 t6&#58;0x00000000 t7&#58;0x00000078
s0&#58;0x0904C450 s1&#58;0x09020000 s2&#58;0x00000000 s3&#58;0x09F7FEE0
s4&#58;0x09030000 s5&#58;0x00000013 s6&#58;0xDEADBEEF s7&#58;0xDEADBEEF
t8&#58;0x00000154 t9&#58;0x880107E0 k0&#58;0x09F7FF00 k1&#58;0x00000000
gp&#58;0x09026C00 sp&#58;0x09F7FDE8 fp&#58;0x09F7FEA0 ra&#58;0x08F55950
calc $epc-$mod
Unknown register 'mod'
Error could not calculate address
Post Reply