suggestion of backtrace in phobos

Chad J gamerChad at _spamIsBad_gmail.com
Sat Dec 9 11:07:50 PST 2006


shinichiro.h wrote:
> Hi, all,
> 
> I want to suggest the feature of the backtrace for phobos with my
> phobos.patch.
> 
> http://shinh.skr.jp/tmp/backtrace.zip
> http://shinh.skr.jp/tmp/phobos.patch
> 
> It supports each of win32 and linux on x86. But the output of the
> current implementation is not as good as my hacked phobos
> (http://shinh.skr.jp/d/backtrace.zip). I will describe the reason
> later.
> 
> (Perhaps my discussion is out of date. I'm sorry that I could not
>  follow recent discussions about backtrace. And I'm sorry my English
>  may be not good. Please ask me if the suggestion is not clear.)
> 
> You can try the package like following on Win32,
> 
> % dmd.exe throw_test.d -L/Map
> % throw_test.exe
> Error: err
> Backtrace:
> 00402034 void throw_test.func()
> 004107f9 _mainCRTStartup
> 7ee7eede ???
> b7ed9567 ???
> 
> And on Linux,
> 
> % dmd -c throw_test.d
> % gcc throw_test.o -o throw_test libphobos.a -lpthread -lm
> % nm throw_test > throw_test.nm
> % ./throw_test
> Error: err
> Backtrace:
> 0804a8f0 void throw_test.func()
> 0804a8fc _Dmain
> 0804c42c main
> 
> The changes of the phobos are the following:
> 
> * add void*[] Exception.backtrace
> * add Exception.print(Object)
> 
> The member backtrace is the array of addresses. And print(Object) is
> the member to show the backtrace. I will describe later of this post
> what the argument Object is.
> 
> * add internal/backtrace_win32.d
> * edit _d_throw in deh.c/deh2.d
> 
> Edit Exception.backtrace member in them.
> 
> * add std.symtable
> 
> I think we cannot choose one backtrace showing strategy. When I am
> debugging, I want to get detailed message. But I don't want to get
> detailed message in release version since the informations for the
> message enlarges the release binary.
> 
> We can choose the strategy of showing backtrace using overrided
> Symtable.lookupName member. 'othertbl.test.d' in the package is a very
> simple example of the overriding.
> 
> There is only one strategy in my current implementation of
> Symtable. Symtable reads the map file of executable in the current
> directory, and show the demangled function name of backtrace. I think
> I can implement to show the line number in function like my hacked
> phobos. I will implement it if this suggestion is accepted.
> 
> And I think the std.symtable module will be also useful for
> reflection. See my old work on pseudo reflection:
> 
> http://www.digitalmars.com/d/archives/digitalmars/D/8174.html
> 
> * edit main in dmain2.d
> 
> Add signal handler for linux. And the exception handler search the map
> file in the current directory and use it if it is found.
> 
> 
> I'm sorry I only changed linux.mak since I'm a linux person. The
> Makefile in the package will work only on linux.
> 
> This suggestion and my implementation may be not good enough. I'm glad
> if I got some comments and modifications.
> 
> ------------------
>  shinichiro.h
>   hamaji _at_ nii.ac.jp
>   http://shinh.skr.jp/

It would be great to see this in phobos.

I have been using your backtrace for some time already.  It is very 
useful.  Thank you for your efforts!



More information about the Digitalmars-d mailing list