Re: RFC: add some static probes to libstdc++
Jonathan == Jonathan Wakely jwakely@gmail.com writes: Marc I thought you were going to suggest enhancing the configure test Marc so it fails on old systemtap (detects it as absent). Jonathan Ah yes, that's a much better idea! Here's a patch to do that. I tested it on x86-64 Fedora 18. I tested the failing path by using an old sdt.h. This required a number of iterations to ensure that the test failed for the right reasons. Ok? I think it should go on the 4.8 branch as well. Tom 2013-04-09 Tom Tromey tro...@redhat.com * configure, config.h.in: Rebuild. * configure.ac: Use GLIBCXX_CHECK_SDT_H. Don't check for sys/sdt.h. * acinclude.m4 (GLIBCXX_CHECK_SDT_H): New defun. diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 4d06b20..619fff0 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -3660,6 +3660,36 @@ AC_DEFUN([GLIBCXX_ENABLE_WERROR], [ ]) +dnl +dnl Check to see if sys/sdt.h exists and that it is suitable for use. +dnl Some versions of sdt.h were not compatible with C++11. +dnl +AC_DEFUN([GLIBCXX_CHECK_SDT_H], [ + AC_MSG_RESULT([for suitable sys/sdt.h]) + # Note that this test has to be run with the C language. + # Otherwise, sdt.h will try to include some headers from + # libstdc++ itself. + AC_LANG_SAVE + AC_LANG_C + AC_CACHE_VAL(glibcxx_cv_sys_sdt_h, [ +# Because we have to run the test in C, we use grep rather +# than the compiler to check for the bug. The bug is that +# were strings without trailing whitespace, causing g++ +# to look for operator. The pattern searches for the fixed +# output. +AC_EGREP_CPP([ \,\ ], [ + #include sys/sdt.h + int f() { STAP_PROBE(hi, bob); } +], [glibcxx_cv_sys_sdt_h=yes], [glibcxx_cv_sys_sdt_h=no]) + ]) + AC_LANG_RESTORE + if test $glibcxx_cv_sys_sdt_h = yes; then +AC_DEFINE(HAVE_SYS_SDT_H, 1, + [Define to 1 if you have a suitable sys/sdt.h header file]) + fi + AC_MSG_RESULT($glibcxx_cv_sys_sdt_h) +]) + # Macros from the top-level gcc directory. m4_include([../config/gc++filt.m4]) m4_include([../config/tls.m4]) diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index de66406..73d430a 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -211,12 +211,13 @@ GLIBCXX_CHECK_SC_NPROCESSORS_ONLN GLIBCXX_CHECK_SC_NPROC_ONLN GLIBCXX_CHECK_PTHREADS_NUM_PROCESSORS_NP GLIBCXX_CHECK_SYSCTL_HW_NCPU +GLIBCXX_CHECK_SDT_H # Check for available headers. AC_CHECK_HEADERS([endian.h execinfo.h float.h fp.h ieeefp.h inttypes.h \ locale.h machine/endian.h machine/param.h nan.h stdint.h stdlib.h string.h \ strings.h sys/ipc.h sys/isa_defs.h sys/machine.h sys/param.h \ -sys/resource.h sys/sdt.h sys/sem.h sys/stat.h sys/time.h sys/types.h unistd.h \ +sys/resource.h sys/sem.h sys/stat.h sys/time.h sys/types.h unistd.h \ wchar.h wctype.h]) # Only do link tests if native. Else, hardcode.
Re: RFC: add some static probes to libstdc++
On 9 April 2013 18:47, Tom Tromey wrote: Jonathan == Jonathan Wakely jwakely@gmail.com writes: Marc I thought you were going to suggest enhancing the configure test Marc so it fails on old systemtap (detects it as absent). Jonathan Ah yes, that's a much better idea! Here's a patch to do that. I tested it on x86-64 Fedora 18. I tested the failing path by using an old sdt.h. This required a number of iterations to ensure that the test failed for the right reasons. Ah yes, tricky. Ok? I think it should go on the 4.8 branch as well. OK for trunk and 4.8, thanks.
Re: RFC: add some static probes to libstdc++
Jonathan == Jonathan Wakely jwakely@gmail.com writes: Jonathan On 2 April 2013 16:39, Marc Glisse wrote: On Tue, 2 Apr 2013, Jonathan Wakely wrote: Should we update the prerequisites documentation to say that if Systemtap is installed it needs to be at least version X? I thought you were going to suggest enhancing the configure test so it fails on old systemtap (detects it as absent). Jonathan Ah yes, that's a much better idea! Sorry about the delay on this. I've been away. I will try to write a fix this week. Tom
Re: RFC: add some static probes to libstdc++
On 15 March 2013 08:55, Jakub Jelinek ja...@redhat.com wrote: On Thu, Feb 28, 2013 at 08:32:02AM -0700, Tom Tromey wrote: 2013-02-27 Tom Tromey tro...@redhat.com * libsupc++/unwind-cxx.h: Include sys/sdt.h if detected. (PROBE2): New macro. * libsupc++/eh_throw.cc (__cxa_throw, __cxa_rethrow): Add probe. * libsupc++/eh_catch.cc (__cxa_begin_catch): Add probe. * configure.ac: Check for sys/sdt.h. * configure, config.h.in: Rebuild. This is ok. As we are close to 4.8.0-rc1, I went ahead and committed it for you. Jakub This change is causing a few problems, it looks as though older versions of Systemtap headers are incompatible with C++11 due to the UDL/whitespace issues described at http://gcc.gnu.org/gcc-4.7/porting_to.html e.g. http://gcc.gnu.org/ml/gcc-help/2013-04/msg00011.html Should we update the prerequisites documentation to say that if Systemtap is installed it needs to be at least version X?
Re: RFC: add some static probes to libstdc++
On Tue, 2 Apr 2013, Jonathan Wakely wrote: On 15 March 2013 08:55, Jakub Jelinek ja...@redhat.com wrote: On Thu, Feb 28, 2013 at 08:32:02AM -0700, Tom Tromey wrote: 2013-02-27 Tom Tromey tro...@redhat.com * libsupc++/unwind-cxx.h: Include sys/sdt.h if detected. (PROBE2): New macro. * libsupc++/eh_throw.cc (__cxa_throw, __cxa_rethrow): Add probe. * libsupc++/eh_catch.cc (__cxa_begin_catch): Add probe. * configure.ac: Check for sys/sdt.h. * configure, config.h.in: Rebuild. This is ok. As we are close to 4.8.0-rc1, I went ahead and committed it for you. Jakub This change is causing a few problems, it looks as though older versions of Systemtap headers are incompatible with C++11 due to the UDL/whitespace issues described at http://gcc.gnu.org/gcc-4.7/porting_to.html e.g. http://gcc.gnu.org/ml/gcc-help/2013-04/msg00011.html Should we update the prerequisites documentation to say that if Systemtap is installed it needs to be at least version X? I thought you were going to suggest enhancing the configure test so it fails on old systemtap (detects it as absent). -- Marc Glisse
Re: RFC: add some static probes to libstdc++
On 2 April 2013 16:39, Marc Glisse wrote: On Tue, 2 Apr 2013, Jonathan Wakely wrote: Should we update the prerequisites documentation to say that if Systemtap is installed it needs to be at least version X? I thought you were going to suggest enhancing the configure test so it fails on old systemtap (detects it as absent). Ah yes, that's a much better idea!
Re: RFC: add some static probes to libstdc++
On Thu, Feb 28, 2013 at 08:32:02AM -0700, Tom Tromey wrote: 2013-02-27 Tom Tromey tro...@redhat.com * libsupc++/unwind-cxx.h: Include sys/sdt.h if detected. (PROBE2): New macro. * libsupc++/eh_throw.cc (__cxa_throw, __cxa_rethrow): Add probe. * libsupc++/eh_catch.cc (__cxa_begin_catch): Add probe. * configure.ac: Check for sys/sdt.h. * configure, config.h.in: Rebuild. This is ok. As we are close to 4.8.0-rc1, I went ahead and committed it for you. Jakub
Re: RFC: add some static probes to libstdc++
Tom 2013-02-27 Tom Tromey tro...@redhat.com Tom* libsupc++/unwind-cxx.h: Include sys/sdt.h if detected. Tom(PROBE2): New macro. Tom* libsupc++/eh_throw.cc (__cxa_throw, __cxa_rethrow): Add probe. Tom* libsupc++/eh_catch.cc (__cxa_begin_catch): Add probe. Tom* configure.ac: Check for sys/sdt.h. Tom* configure, config.h.in: Rebuild. FWIW the gdb patches relying on this have all been submitted. They are pending comments, but also this patch going in. In particular: Using the probes in gdb: http://sourceware.org/ml/gdb-patches/2013-03/msg00242.html Using the probes to implement the $_exception convenience variable: http://sourceware.org/ml/gdb-patches/2013-03/msg00243.html Using the probes to implement filtering for exception catchpoints: http://sourceware.org/ml/gdb-patches/2013-03/msg00245.html Tom
Re: RFC: add some static probes to libstdc++
On 27/02/2013 21:52, Tom Tromey wrote: I'm posting this now to get reactions to the probe before cleaning up the corresponding gdb patches for submission. I've built it both with and without sys/sdt.h, but I haven't yet run the test suite. How did it build in the without sys/sdt.h case? +#ifdef HAVE_SYS_SDT_H +#include sys/sdt.h +/* We only want to use stap probes starting with v3. Earlier versions + added too much startup cost. */ +#if defined (STAP_PROBE2) _SDT_NOTE_TYPE = 3 +#define PROBE2(name, arg1, arg2) STAP_PROBE2 (libstdcxx, name, arg1, arg2) +#else +#define PROBE2(name, arg1, arg2) +#endif +#endif + Without HAVE_SYS_SDT_H, there's no definition of PROBE2 at all, but you use it unconditionally in eh_{catch,throw}.cc. Am I missing something? cheers, DaveK
Re: RFC: add some static probes to libstdc++
Dave == Dave Korn dave.korn.cyg...@gmail.com writes: Dave How did it build in the without sys/sdt.h case? Dave Without HAVE_SYS_SDT_H, there's no definition of PROBE2 at all, Dave but you use it unconditionally in eh_{catch,throw}.cc. Am I Dave missing something? Ugh. I must have made some mistake in my testing. I will fix it up. Tom
Re: RFC: add some static probes to libstdc++
Dave How did it build in the without sys/sdt.h case? Sorry about that again. I must have made some change after testing it. Here is an updated version. One thing I found out while fixing this up is that changes to unwind-cxx.h do not cause anything to rebuild if I just run make. I have to make clean each time. On the plus side, while digging around after being confused by this, I found that I didn't actually need ../config.h -- the code now checks _GLIBCXX_HAVE_SYS_SDT_H instead. Tom 2013-02-27 Tom Tromey tro...@redhat.com * libsupc++/unwind-cxx.h: Include sys/sdt.h if detected. (PROBE2): New macro. * libsupc++/eh_throw.cc (__cxa_throw, __cxa_rethrow): Add probe. * libsupc++/eh_catch.cc (__cxa_begin_catch): Add probe. * configure.ac: Check for sys/sdt.h. * configure, config.h.in: Rebuild. diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index a64fee2..de66406 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -216,7 +216,7 @@ GLIBCXX_CHECK_SYSCTL_HW_NCPU AC_CHECK_HEADERS([endian.h execinfo.h float.h fp.h ieeefp.h inttypes.h \ locale.h machine/endian.h machine/param.h nan.h stdint.h stdlib.h string.h \ strings.h sys/ipc.h sys/isa_defs.h sys/machine.h sys/param.h \ -sys/resource.h sys/sem.h sys/stat.h sys/time.h sys/types.h unistd.h \ +sys/resource.h sys/sdt.h sys/sem.h sys/stat.h sys/time.h sys/types.h unistd.h \ wchar.h wctype.h]) # Only do link tests if native. Else, hardcode. diff --git a/libstdc++-v3/libsupc++/eh_catch.cc b/libstdc++-v3/libsupc++/eh_catch.cc index 779f5a3..43e875a 100644 --- a/libstdc++-v3/libsupc++/eh_catch.cc +++ b/libstdc++-v3/libsupc++/eh_catch.cc @@ -80,6 +80,9 @@ __cxxabiv1::__cxa_begin_catch (void *exc_obj_in) _GLIBCXX_NOTHROW } objectp = __gxx_caught_object(exceptionObject); + + PROBE2 (catch, objectp, header-exceptionType); + #ifdef __ARM_EABI_UNWINDER__ _Unwind_Complete(exceptionObject); #endif diff --git a/libstdc++-v3/libsupc++/eh_throw.cc b/libstdc++-v3/libsupc++/eh_throw.cc index 297aa04..a79a025 100644 --- a/libstdc++-v3/libsupc++/eh_throw.cc +++ b/libstdc++-v3/libsupc++/eh_throw.cc @@ -60,6 +60,8 @@ extern C void __cxxabiv1::__cxa_throw (void *obj, std::type_info *tinfo, void (_GLIBCXX_CDTOR_CALLABI *dest) (void *)) { + PROBE2 (throw, obj, tinfo); + // Definitely a primary. __cxa_refcounted_exception *header = __get_refcounted_exception_header_from_obj (obj); @@ -97,7 +99,12 @@ __cxxabiv1::__cxa_rethrow () if (!__is_gxx_exception_class(header-unwindHeader.exception_class)) globals-caughtExceptions = 0; else - header-handlerCount = -header-handlerCount; + { + header-handlerCount = -header-handlerCount; + // Only notify probe for C++ exceptions. + PROBE2 (rethrow, __get_object_from_ambiguous_exception(header), + header-exceptionType); + } #ifdef _GLIBCXX_SJLJ_EXCEPTIONS _Unwind_SjLj_Resume_or_Rethrow (header-unwindHeader); diff --git a/libstdc++-v3/libsupc++/unwind-cxx.h b/libstdc++-v3/libsupc++/unwind-cxx.h index e2b945d..ed4eea5 100644 --- a/libstdc++-v3/libsupc++/unwind-cxx.h +++ b/libstdc++-v3/libsupc++/unwind-cxx.h @@ -37,6 +37,19 @@ #include bits/atomic_word.h #include cxxabi.h +#ifdef _GLIBCXX_HAVE_SYS_SDT_H +#include sys/sdt.h +/* We only want to use stap probes starting with v3. Earlier versions + added too much startup cost. */ +#if defined (STAP_PROBE2) _SDT_NOTE_TYPE = 3 +#define PROBE2(name, arg1, arg2) STAP_PROBE2 (libstdcxx, name, arg1, arg2) +#endif +#endif + +#ifndef PROBE2 +#define PROBE2(name, arg1, arg2) +#endif + #pragma GCC visibility push(default) namespace __cxxabiv1
RFC: add some static probes to libstdc++
I've been working a bit on improving exception-related features in gdb. I had two goals which led to this particular patch. First, I wanted to be able to implement type-name-based filtering for catch catch and friends. (This feature was documented in the past, but never implemented, and occasionally people run across the old docs and are disappointed that it doesn't work.) Second, I wanted to be able to expose the currently-thrown-or-caught exception to the gdb user as a convenience variable. I thought this would make it simpler to write more sophisticated catch/throw condition expressions. After digging into libsupc++ a bit, I found that I needed some extra information to be exposed. The best way I know of to do that is to add some static probes to the library. These are cheap, work well with gdb, and do not require debuginfo in order to work. Note that this kind of probe is already in use in libgcc. So, accepting them into libstdc++ doesn't mean any extra dependencies or the like. I needed 3 probes, one each for catch, throw, and rethrow. SDT probes take both a provider (I chose libstdcxx) and a name (I chose the obvious ones). The arguments to the probes are chosen so that they expose the information gdb needs, namely a pointer to the exception object and a pointer to the exception's type_info. I'm not totally sure if the unwind-cxx.h changes are written the best way possible. I'm posting this now to get reactions to the probe before cleaning up the corresponding gdb patches for submission. I've built it both with and without sys/sdt.h, but I haven't yet run the test suite. Tom 2013-02-27 Tom Tromey tro...@redhat.com * libsupc++/unwind-cxx.h: Include ../config.h, sys/sdt.h. (PROBE2): New macro. * libsupc++/eh_throw.cc (__cxa_throw, __cxa_rethrow): Add probe. * libsupc++/eh_catch.cc (__cxa_begin_catch): Add probe. * configure.ac: Check for sys/sdt.h. * configure, config.h.in: Rebuild. diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index 66164a2..d0b8c27 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -216,7 +216,7 @@ GLIBCXX_CHECK_SYSCTL_HW_NCPU AC_CHECK_HEADERS([endian.h execinfo.h float.h fp.h ieeefp.h inttypes.h \ locale.h machine/endian.h machine/param.h nan.h stdint.h stdlib.h string.h \ strings.h sys/ipc.h sys/isa_defs.h sys/machine.h sys/param.h \ -sys/resource.h sys/sem.h sys/stat.h sys/time.h sys/types.h unistd.h \ +sys/resource.h sys/sdt.h sys/sem.h sys/stat.h sys/time.h sys/types.h unistd.h \ wchar.h wctype.h]) # Only do link tests if native. Else, hardcode. diff --git a/libstdc++-v3/libsupc++/eh_catch.cc b/libstdc++-v3/libsupc++/eh_catch.cc index 779f5a3..43e875a 100644 --- a/libstdc++-v3/libsupc++/eh_catch.cc +++ b/libstdc++-v3/libsupc++/eh_catch.cc @@ -80,6 +80,9 @@ __cxxabiv1::__cxa_begin_catch (void *exc_obj_in) _GLIBCXX_NOTHROW } objectp = __gxx_caught_object(exceptionObject); + + PROBE2 (catch, objectp, header-exceptionType); + #ifdef __ARM_EABI_UNWINDER__ _Unwind_Complete(exceptionObject); #endif diff --git a/libstdc++-v3/libsupc++/eh_throw.cc b/libstdc++-v3/libsupc++/eh_throw.cc index 297aa04..a79a025 100644 --- a/libstdc++-v3/libsupc++/eh_throw.cc +++ b/libstdc++-v3/libsupc++/eh_throw.cc @@ -60,6 +60,8 @@ extern C void __cxxabiv1::__cxa_throw (void *obj, std::type_info *tinfo, void (_GLIBCXX_CDTOR_CALLABI *dest) (void *)) { + PROBE2 (throw, obj, tinfo); + // Definitely a primary. __cxa_refcounted_exception *header = __get_refcounted_exception_header_from_obj (obj); @@ -97,7 +99,12 @@ __cxxabiv1::__cxa_rethrow () if (!__is_gxx_exception_class(header-unwindHeader.exception_class)) globals-caughtExceptions = 0; else - header-handlerCount = -header-handlerCount; + { + header-handlerCount = -header-handlerCount; + // Only notify probe for C++ exceptions. + PROBE2 (rethrow, __get_object_from_ambiguous_exception(header), + header-exceptionType); + } #ifdef _GLIBCXX_SJLJ_EXCEPTIONS _Unwind_SjLj_Resume_or_Rethrow (header-unwindHeader); diff --git a/libstdc++-v3/libsupc++/unwind-cxx.h b/libstdc++-v3/libsupc++/unwind-cxx.h index e2b945d..69a0c16 100644 --- a/libstdc++-v3/libsupc++/unwind-cxx.h +++ b/libstdc++-v3/libsupc++/unwind-cxx.h @@ -28,6 +28,8 @@ #ifndef _UNWIND_CXX_H #define _UNWIND_CXX_H 1 +#include ../config.h + // Level 2: C++ ABI #include typeinfo @@ -37,6 +39,17 @@ #include bits/atomic_word.h #include cxxabi.h +#ifdef HAVE_SYS_SDT_H +#include sys/sdt.h +/* We only want to use stap probes starting with v3. Earlier versions + added too much startup cost. */ +#if defined (STAP_PROBE2) _SDT_NOTE_TYPE = 3 +#define PROBE2(name, arg1, arg2) STAP_PROBE2 (libstdcxx, name, arg1, arg2) +#else +#define PROBE2(name, arg1, arg2) +#endif +#endif + #pragma GCC visibility push(default) namespace __cxxabiv1