diff options
| author | Paul Eggert | 2012-09-04 11:29:04 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-09-04 11:29:04 -0700 |
| commit | cf29dd84d205e1c78fed5d1ea0006a382658598c (patch) | |
| tree | 7e6806fdd94ef53cda78db6b29a4df0276408eb4 /src/sysdep.c | |
| parent | 972debf2e7381b4fd2c70f9c1fd585d8bd137917 (diff) | |
| download | emacs-cf29dd84d205e1c78fed5d1ea0006a382658598c.tar.gz emacs-cf29dd84d205e1c78fed5d1ea0006a382658598c.zip | |
Give more-useful info on a fatal error (Bug#12328).
* doc/emacs/trouble.texi (Crashing): New section, documenting this.
* etc/NEWS: Document the change.
* src/alloc.c [ENABLE_CHECKING]: Do not include <execinfo.h>.
(die) [ENABLE_CHECKING]: Call fatal_error_backtrace instead
of doing the work ourselves.
* src/emacs.c (fatal_error_signal): Let fatal_error_backtrace
do most of the work.
(fatal_error_backtrace): New function, taken from the guts
of the old fatal_error_signal, but with a new option to output
a backtrace.
(shut_down_emacs) [!DOS_NT]: Use strsignal to give more-useful
info about the signal than just its number.
* src/lisp.h (fatal_error_backtrace, emacs_backtrace): New decls.
* src/sysdep.c: Include <execinfo.h>
(emacs_backtrace): New function, taken partly from the previous
code of the 'die' function.
(emacs_abort): Call fatal_error_backtrace rather than abort.
Diffstat (limited to 'src/sysdep.c')
| -rw-r--r-- | src/sysdep.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/sysdep.c b/src/sysdep.c index 78164a8f02a..1f4de194c64 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -21,6 +21,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 21 | 21 | ||
| 22 | #define SYSTIME_INLINE EXTERN_INLINE | 22 | #define SYSTIME_INLINE EXTERN_INLINE |
| 23 | 23 | ||
| 24 | #include <execinfo.h> | ||
| 24 | #include <signal.h> | 25 | #include <signal.h> |
| 25 | #include <stdio.h> | 26 | #include <stdio.h> |
| 26 | #include <setjmp.h> | 27 | #include <setjmp.h> |
| @@ -1856,12 +1857,30 @@ snprintf (char *buf, size_t bufsize, char const *format, ...) | |||
| 1856 | } | 1857 | } |
| 1857 | #endif | 1858 | #endif |
| 1858 | 1859 | ||
| 1860 | /* If a backtrace is available, output the top lines of it to stderr. | ||
| 1861 | Do not output more than BACKTRACE_LIMIT or BACKTRACE_LIMIT_MAX lines. | ||
| 1862 | This function may be called from a signal handler, so it should | ||
| 1863 | not invoke async-unsafe functions like malloc. */ | ||
| 1864 | void | ||
| 1865 | emacs_backtrace (int backtrace_limit) | ||
| 1866 | { | ||
| 1867 | enum { BACKTRACE_LIMIT_MAX = 500 }; | ||
| 1868 | void *buffer[BACKTRACE_LIMIT_MAX + 1]; | ||
| 1869 | int bounded_limit = min (backtrace_limit, BACKTRACE_LIMIT_MAX); | ||
| 1870 | int npointers = backtrace (buffer, bounded_limit + 1); | ||
| 1871 | if (npointers) | ||
| 1872 | ignore_value (write (STDERR_FILENO, "\nBacktrace:\n", 12)); | ||
| 1873 | backtrace_symbols_fd (buffer, bounded_limit, STDERR_FILENO); | ||
| 1874 | if (bounded_limit < npointers) | ||
| 1875 | ignore_value (write (STDERR_FILENO, "...\n", 4)); | ||
| 1876 | } | ||
| 1877 | |||
| 1859 | #ifndef HAVE_NTGUI | 1878 | #ifndef HAVE_NTGUI |
| 1860 | /* Using emacs_abort lets GDB return from a breakpoint here. */ | 1879 | /* Using emacs_abort lets GDB return from a breakpoint here. */ |
| 1861 | void | 1880 | void |
| 1862 | emacs_abort (void) | 1881 | emacs_abort (void) |
| 1863 | { | 1882 | { |
| 1864 | abort (); | 1883 | fatal_error_backtrace (SIGABRT, 10); |
| 1865 | } | 1884 | } |
| 1866 | #endif | 1885 | #endif |
| 1867 | 1886 | ||