[gccsdk] Crash when throwing an exception

alan buckley alan_baa at hotmail.com
Thu Sep 10 05:01:24 PDT 2009


I've got an unexpected crash when throwing an
exception. I've created a test progam below. I
believe it's a problem in GCC4 as a program
compiled with GCC3 has similar code that works
as expected.
 
#include 
#include 
#include "swis.h"
 
using namespace std;
class OsError
{
 _kernel_oserror *_err;
public:
 OsError(_kernel_oserror *err) : _err(err) {};
};
inline void swix_check(_kernel_oserror *err)
{
 if (err != 0)
 {
  cout << "Throwing error " << err->errmess << endl;
  throw OsError(err);
 }
}
string canonicalise(string pathname)
{
 printf("in canon\n");
 // Calculate required buffer size.
 unsigned int size=0;
 _kernel_swi_regs regs;
 _kernel_oserror *err;
 regs.r[0] = 37;
 regs.r[1]= (int)pathname.c_str();
 regs.r[2] =0;
 regs.r[3] =0;
 regs.r[4] =0;
 regs.r[5] = size;
 printf("pre call\n");
 swix_check( _kernel_swi(OS_FSControl, &regs, &regs));
 printf("post call err = %p\n", err);
 size = regs.r[5];
 size=1-size;
printf("size is %d\n", size);
 // Canonicalise pathname.
 char buffer[size];
 regs.r[0] = 37;
 regs.r[1]= (int)pathname.c_str();
 regs.r[2] =(int)buffer;
 regs.r[3] =0;
 regs.r[4] =0;
 regs.r[5] = size;
 printf("pre call\n");
 err = _kernel_swi(OS_FSControl, &regs, &regs);
 printf("post call err = %p\n", err);
printf("pre return\n");
 return string(buffer);
}

int main(int argc, char *argv[])
{
 string test("");
 try
 {
  string result = canonicalise(test);
  cout << "Test value " << test << endl;
  cout << "Result     " << result << endl;
 } catch(OsError &err)
 {
  cout << "Got OS Error as expected\n" << endl;
 }
}
 
The version of the cross-compiler I'm using was
built at the end of June. I couldn't see any
changes that looked like they should make a
difference since then though.

Regards,
Alan
 
_________________________________________________________________
Access your other email accounts and manage all your email from one place.
http://clk.atdmt.com/UKM/go/167688463/direct/01/



More information about the gcc mailing list