Page 1 of 1

Exception-Handling in D (gdc, phobos)

Posted: Fri Mar 26, 2010 11:19 am
by hrniels
Hi,

I'm trying to port phobos to my OS (for userspace). The basics work but now I'm stuck at the exception-handling-stuff.
I'm using this as basis: http://switch.dl.sourceforge.net/projec ... rc.tar.bz2
As it seems internal/deh2.d is used for exception-handling-support on linux. I think I can port it without many changes; the only problem is (as far as I know now) that I don't know the origin of the symbols _deh_beg and _deh_end.
They are used here:

Code: Select all

/*******************************************
 * Given address that is inside a function,
 * figure out which function it is in.
 * Return DHandlerTable if there is one, NULL if not.
 */
DHandlerTable *__eh_finddata(void *address)
{
	FuncTable *ft;
	for (ft = cast(FuncTable *)&_deh_beg;
		 ft < cast(FuncTable *)&_deh_end;
		 ft++)
	{
		if (ft.fptr <= address &&
			address < cast(void *)(cast(char *)ft.fptr + ft.fsize))
		{
			return ft.handlertable;
		}
	}
	return null;
}
FuncTable is declared as:

Code: Select all

// One of these is generated for each function with try-catch or try-finally
struct FuncTable
{
	void *fptr;						// pointer to start of function
	DHandlerTable *handlertable; // eh data for this function
	uint fsize;				// size of function in bytes
}
So, as far as I understand it, its simply a table of "catch-handlers" and whenever an exception should be thrown we look through these handlers until we find the one for our function.

I've searched quite a bit now and tried very much but I haven't found out where this table is. I guess the linker puts it in a separate section or something like that? But I couldn't find usefull information about it :/
Has anybody a hint where to look or knows how this works?

Thanks!
hrniels

PS: I'm not sure if the forum "General programming" fits better. Feel free to move it :)

Re: Exception-Handling in D (gdc, phobos)

Posted: Sun Mar 28, 2010 11:03 am
by hrniels
Just for your information: The problem doesn't exist anymore. I've decided not to use gdc since its still a bit buggy and the project seems to be dead (?). Therefore this makes no sense. Instead I'm using dmd now.

(Yes, exception-handling works already with dmd. And dmd defines the symbols _deh_beg and _deh_end, so I guess this was a not finished corner of gdc? :))