[solved]tinyxml bus error

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

Moderators: cheriff, TyRaNiD

Post Reply
foxss
Posts: 6
Joined: Sun Dec 07, 2008 2:00 pm

[solved]tinyxml bus error

Post by foxss »

Hi,

I tried to parse a utf-8 xml file with tinyxml while get a bus error.
main.cpp

Code: Select all

#include "tinyxml.h"
#include <pspkernel.h>

PSP_MODULE_INFO&#40;"sample", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER | THREAD_ATTR_VFPU&#41;;
PSP_HEAP_SIZE_KB&#40;20*1024&#41;;

TiXmlDocument* doc;

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
    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, PSP_THREAD_ATTR_USER, 0&#41;;
    if&#40;thid >= 0&#41;
        sceKernelStartThread&#40;thid, 0, 0&#41;;
    return thid;
&#125;

bool LoadMenu&#40;&#41;&#123;
  doc = new TiXmlDocument&#40;"test.xml"&#41;;
  return doc->LoadFile&#40;&#41;;
&#125;


void GenUI&#40;TiXmlElement *elem&#41;&#123;
    return;
&#125;

void ParseMenu&#40;TiXmlDocument* doc1&#41;&#123;
  
  TiXmlElement* ele = doc1->FirstChildElement&#40;"Item"&#41;;
  do&#123;
    GenUI&#40;ele&#41;;
    ele = ele->NextSiblingElement&#40;&#41;;
  &#125;while&#40;ele&#41;;
  
  return;
&#125;

int main&#40;&#41; &#123;
    SetupCallbacks&#40;&#41;;
    
    if&#40;!LoadMenu&#40;&#41;&#41;&#123;
        //when config file missing, exit program
        sceKernelExitGame&#40;&#41;;
        return 0;
    &#125;
    ParseMenu&#40;doc&#41;;
    sceKernelExitGame&#40;&#41;;
    return 0;
&#125;

Code: Select all

host0&#58;/> ./VersiPSP.prx
Load/Start host0&#58;/VersiPSP.prx UID&#58; 0x045EFC39 Name&#58; "s
host0&#58;/> Exception - Bus error &#40;data&#41;
Thread ID - 0x045E7745
Th Name   - user_main
Module ID - 0x045EFC39
Mod Name  - "sample"
EPC       - 0x088047D4
Cause     - 0x1000001C
BadVAddr  - 0x10500440
Status    - 0x40088613
zr&#58;0x00000000 at&#58;0xDEADBEEF v0&#58;0x00000001 v1&#58;0x00000A59
a0&#58;0x00000000 a1&#58;0x00000021 a2&#58;0x00000A58 a3&#58;0x08828984
t0&#58;0x00000020 t1&#58;0x088355A8 t2&#58;0x0882DDF8 t3&#58;0x088355BC
t4&#58;0x00000000 t5&#58;0xDEADBEEF t6&#58;0xDEADBEEF t7&#58;0xDEADBEEF
s0&#58;0x00000000 s1&#58;0x08835330 s2&#58;0x00000001 s3&#58;0x0BBBFEE0
s4&#58;0x00000014 s5&#58;0x00000013 s6&#58;0xDEADBEEF s7&#58;0xDEADBEEF
t8&#58;0xDEADBEEF t9&#58;0xDEADBEEF k0&#58;0x0BBBFF00 k1&#58;0x00000000
gp&#58;0x088364A0 sp&#58;0x0BBBFE08 fp&#58;0x0BBBFEA0 ra&#58;0x08804454
0x088047D4&#58; 0x8C83001C '....' - lw         $v1, 28&#40;$a0&#41;
Is someone know what this about?
I can't get clue over this.

Thanks,
Last edited by foxss on Mon Dec 28, 2009 12:31 pm, edited 1 time in total.
ps2dev.org rocks!
Love eReader/XReader
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

You're trying to derefeence a null pointer at 0x3d4

lw $v1, 28($a0)
a0:0x00000000
EPC:0x088047D4

lw destinationRegister, offset(sourceRegester) # load contents of RAM at offset from sourceRegister into register destinationRegister: destinationRegister = *(destinationRegister+offset)

To calculate where the error occurs type in psplink
calc $epc-$mod
then use that address in psp-address
psp-address2line -fCe your_module.elf address
This will give you the file and the line the error occurs(for this to work need to have -g in CFLAGS in your makefile)


Okay I see 2 places where your crash could have happened
return doc->LoadFile();
ele = ele->NextSiblingElement();

Edit:
I'll go with "return doc->LoadFile();" since LoadFile() is the 8th member of TiXmlDocument. You should make sure you classes are created before you use them.
foxss
Posts: 6
Joined: Sun Dec 07, 2008 2:00 pm

Post by foxss »

Thanks, psPea!

I finally find crash caused as ele is a null pointer. I should be more defensive, check it before using...

Code: Select all

ele = ele->NextSiblingElement&#40;&#41;;
psPea wrote:You're trying to derefeence a null pointer at 0x3d4

lw $v1, 28($a0)
a0:0x00000000
EPC:0x088047D4

lw destinationRegister, offset(sourceRegester) # load contents of RAM at offset from sourceRegister into register destinationRegister: destinationRegister = *(destinationRegister+offset)

To calculate where the error occurs type in psplink
calc $epc-$mod
then use that address in psp-address
psp-address2line -fCe your_module.elf address
This will give you the file and the line the error occurs(for this to work need to have -g in CFLAGS in your makefile)


Okay I see 2 places where your crash could have happened
return doc->LoadFile();
ele = ele->NextSiblingElement();

Edit:
I'll go with "return doc->LoadFile();" since LoadFile() is the 8th member of TiXmlDocument. You should make sure you classes are created before you use them.
ps2dev.org rocks!
Love eReader/XReader
Post Reply