www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - suggestion of backtrace in phobos

reply "shinichiro.h" <hamaji nii.ac.jp> writes:
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/
Dec 09 2006
next sibling parent reply "shinichiro.h" <hamaji nii.ac.jp> writes:
 http://shinh.skr.jp/tmp/backtrace.zip
 http://shinh.skr.jp/tmp/phobos.patch

Ahh I missed the release 0.177. I've put the new version of backtrace phobos. But there seems to be something strange on Windows. http://shinh.skr.jp/tmp/backtrace0_177.zip You can check with the following command: % dmd.exe signal_test.d -L/Map -g -debug % ./signal_test.exe Error: Access Violation Backtrace: 00402019 void signal_test.func() 00402028 __Dmain 0040211f _main 004107c9 _mainCRTStartup 7ee7eede ??? b7ed9567 ???
Dec 09 2006
parent reply Charlie <charlies nowhere.com> writes:
Does this work with libraries ?  I can't seem to get a MAP file 
generated for a library I am building, and when I link against the 
library I get ???  for all symbols.

I missed the last discussion on backtrace, but I would definitely argue 
that this get added, as long as there is an easy way to turn it off for 
release builds.

Charlie

shinichiro.h wrote:
 http://shinh.skr.jp/tmp/backtrace.zip
 http://shinh.skr.jp/tmp/phobos.patch

Ahh I missed the release 0.177. I've put the new version of backtrace phobos. But there seems to be something strange on Windows. http://shinh.skr.jp/tmp/backtrace0_177.zip You can check with the following command: % dmd.exe signal_test.d -L/Map -g -debug % ./signal_test.exe Error: Access Violation Backtrace: 00402019 void signal_test.func() 00402028 __Dmain 0040211f _main 004107c9 _mainCRTStartup 7ee7eede ??? b7ed9567 ???

Dec 09 2006
parent Charlie <charlies nowhere.com> writes:
No you are right, I made a simple test and it does work, I must be doing 
something else wrong.

Yes this should really should be added !


shinichiro.h wrote:
 Hi,
 
 Does this work with libraries ?  I can't seem to get a MAP file 
 generated for a library I am building, and when I link against the 
 library I get ???  for all symbols.

Hmm... didn't you forget to use -L/Map option? Or if you are using linux, you should run the nm command: % nm throw_test > throw_test.nm If you forget nothing, it will be a bug...

Dec 09 2006
prev sibling next sibling parent "shinichiro.h" <hamaji nii.ac.jp> writes:
Hi,

 Does this work with libraries ?  I can't seem to get a MAP file 
 generated for a library I am building, and when I link against the 
 library I get ???  for all symbols.

Hmm... didn't you forget to use -L/Map option? Or if you are using linux, you should run the nm command: % nm throw_test > throw_test.nm If you forget nothing, it will be a bug...
Dec 09 2006
prev sibling next sibling parent Chad J <gamerChad _spamIsBad_gmail.com> writes:
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!
Dec 09 2006
prev sibling next sibling parent Charlie <charlies nowhere.com> writes:
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/

How can I programatically call backtrace ? From within my catch block for example. Charlie
Dec 09 2006
prev sibling parent "shinichiro.h" <hamaji nii.ac.jp> writes:
Hi,

 How can I programatically call backtrace ?  From within my catch block 
 for example.

I didn't create the programmatically interface yet. I wanted to leave the interface design to the newsgroup and Walter if the internal mechanism is accepted. Anyway I created the char[][] getBacktrace(Object) function in class Exception experimentally. You can see the example in catch_test.d now. I think the code of catch_test is still ugly. We should discuss about the interfaces if we will have backtrace in phobos. http://shinh.skr.jp/tmp/backtrace0_177_2.zip
Dec 09 2006