diff options
| author | Paul Eggert | 2019-04-21 23:15:42 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-04-21 23:16:48 -0700 |
| commit | b20d8a932240d5332b4f44b95b2bc1d6fc74c7b0 (patch) | |
| tree | c4966bf6b1443f3bf82680a9ab27d1b87f5d9871 | |
| parent | 1ea048f6e02e56891278a040a5b21678c661764a (diff) | |
| download | emacs-b20d8a932240d5332b4f44b95b2bc1d6fc74c7b0.tar.gz emacs-b20d8a932240d5332b4f44b95b2bc1d6fc74c7b0.zip | |
Mention AddressSanitizer etc. in etc/DEBUG
* etc/DEBUG: Modernize for AddressSanitizer etc.
* etc/NEWS: Defer to etc/DEBUG for this.
| -rw-r--r-- | etc/DEBUG | 126 | ||||
| -rw-r--r-- | etc/NEWS | 3 |
2 files changed, 82 insertions, 47 deletions
| @@ -12,24 +12,21 @@ debugging techniques. | |||
| 12 | *** Configuring Emacs for debugging | 12 | *** Configuring Emacs for debugging |
| 13 | 13 | ||
| 14 | It is best to configure and build Emacs with special options that will | 14 | It is best to configure and build Emacs with special options that will |
| 15 | make the debugging easier. Here's the configure-time options we | 15 | make the debugging easier. Here are the configure-time options we |
| 16 | recommend (they are in addition to any other options you might need, | 16 | recommend (they are in addition to any other options you might need, |
| 17 | such as --prefix): | 17 | such as --prefix): |
| 18 | 18 | ||
| 19 | ./configure --enable-checking='yes,glyphs' --enable-check-lisp-object-type \ | 19 | ./configure --enable-checking='yes,glyphs' --enable-check-lisp-object-type \ |
| 20 | CFLAGS='-O0 -g3' | 20 | CFLAGS='-O0 -g3' |
| 21 | 21 | ||
| 22 | The CFLAGS value is important: debugging optimized code can be very | 22 | The -O0 flag is important, as debugging optimized code can be hard. |
| 23 | hard. (If the problem only happens with optimized code, you may need | 23 | If the problem happens only with optimized code, you may need to |
| 24 | to enable optimizations. If that happens, try using -Og first, | 24 | enable optimizations. If that happens, try using -Og first instead of |
| 25 | instead of -O2, as the former will disable some optimizations that | 25 | -O2, as -Og disables some optimizations that make debugging some code |
| 26 | make debugging some code exceptionally hard.) | 26 | exceptionally hard. |
| 27 | 27 | ||
| 28 | Modern versions of GCC support more elaborate debug info that is | 28 | Older versions of GCC may need more than just the -g3 flag. For more, |
| 29 | available by just using the -g3 compiler switch. Try using -gdwarf-4 | 29 | search for "analyze failed assertions" below. |
| 30 | in addition to -g3, and if that fails, try -gdwarf-3. This is | ||
| 31 | especially important if you have to debug optimized code. More info | ||
| 32 | about this is available below; search for "analyze failed assertions". | ||
| 33 | 30 | ||
| 34 | The 2 --enable-* switches are optional. They don't have any effect on | 31 | The 2 --enable-* switches are optional. They don't have any effect on |
| 35 | debugging with GDB, but will compile additional code that might catch | 32 | debugging with GDB, but will compile additional code that might catch |
| @@ -184,20 +181,15 @@ Good luck! | |||
| 184 | 181 | ||
| 185 | ** When you are trying to analyze failed assertions or backtraces, it | 182 | ** When you are trying to analyze failed assertions or backtraces, it |
| 186 | is essential to compile Emacs with flags suitable for debugging. | 183 | is essential to compile Emacs with flags suitable for debugging. |
| 187 | With GCC 4.8 or later, you can invoke 'make' with CFLAGS="-Og -g3". | 184 | With GCC 4.8 or later, you can invoke 'make' with CFLAGS="-O0 -g3". |
| 188 | With older GCC or non-GCC compilers, you can use CFLAGS="-O0 -g3". | 185 | With older GCC, you can use CFLAGS="-O0 -g3 -gdwarf-4", replacing "4" |
| 186 | by the highest version of DWARF that your compiler supports; | ||
| 187 | with non-GCC compilers, "-O0 -g3" may be the best you can do. | ||
| 189 | With GCC and higher optimization levels such as -O2, the | 188 | With GCC and higher optimization levels such as -O2, the |
| 190 | -fno-omit-frame-pointer and -fno-crossjumping options are often | 189 | -fno-omit-frame-pointer and -fno-crossjumping options are often |
| 191 | essential. The latter prevents GCC from using the same abort call for | 190 | essential. The latter prevents GCC from using the same abort call for |
| 192 | all assertions in a given function, rendering the stack backtrace | 191 | all assertions in a given function, rendering the stack backtrace |
| 193 | useless for identifying the specific failed assertion. | 192 | useless for identifying the specific failed assertion. |
| 194 | Some versions of GCC support recent versions of the DWARF standard for | ||
| 195 | debugging info, but default to older versions; for example, they could | ||
| 196 | support -gdwarf-4 compiler option (for DWARF v4), but default to | ||
| 197 | version 2 of the DWARF standard. For best results in debugging | ||
| 198 | abilities, find out the highest version of DWARF your GCC can support, | ||
| 199 | and use the corresponding -gdwarf-N switch instead of just -g (you | ||
| 200 | will still need -g3, as in "-gdwarf-4 -g3"). | ||
| 201 | 193 | ||
| 202 | ** It is a good idea to run Emacs under GDB (or some other suitable | 194 | ** It is a good idea to run Emacs under GDB (or some other suitable |
| 203 | debugger) *all the time*. Then, when Emacs crashes, you will be able | 195 | debugger) *all the time*. Then, when Emacs crashes, you will be able |
| @@ -923,41 +915,83 @@ setting the new-console option before running Emacs under GDB: | |||
| 923 | (gdb) set new-console 1 | 915 | (gdb) set new-console 1 |
| 924 | (gdb) run | 916 | (gdb) run |
| 925 | 917 | ||
| 926 | ** Running Emacs built with malloc debugging packages | 918 | ** Running Emacs with undefined-behavior sanitization |
| 927 | 919 | ||
| 928 | If Emacs exhibits bugs that seem to be related to use of memory | 920 | Building Emacs with undefined-behavior sanitization can help debug |
| 929 | allocated off the heap, it might be useful to link Emacs with a | 921 | integer overflow and other undefined behavior in C code. To use |
| 930 | special debugging library, such as Electric Fence (a.k.a. efence) or | 922 | UndefinedBehaviorSanitizer with GCC and similar compilers, append |
| 931 | GNU Checker, which helps find such problems. | 923 | '-fsanitize=undefined' to CFLAGS, either when running 'configure' or |
| 924 | running 'make'. For example: | ||
| 932 | 925 | ||
| 933 | Emacs compiled with such packages might not run without some hacking, | 926 | ./configure CFLAGS='-O0 -g3 -fsanitize=undefined' |
| 934 | because Emacs replaces the system's memory allocation functions with | ||
| 935 | its own versions, and because the dumping process might be | ||
| 936 | incompatible with the way these packages use to track allocated | ||
| 937 | memory. Here are some of the changes you might find necessary: | ||
| 938 | 927 | ||
| 939 | - Make sure unexec is disabled, e.g., './configure --without-unexec'. | 928 | You may need to append '-static-libubsan' to CFLAGS if your version of |
| 929 | GCC is installed in an unusual location. | ||
| 940 | 930 | ||
| 941 | - Configure with a different --prefix= option. If you use GCC, | 931 | When using GDB to debug an executable with undefined-behavior |
| 942 | version 2.7.2 is preferred, as some malloc debugging packages | 932 | sanitization, the GDB command: |
| 943 | work a lot better with it than with 2.95 or later versions. | ||
| 944 | 933 | ||
| 945 | - Type "make" then "make -k install". | 934 | (gdb) rbreak ^__ubsan_handle_ |
| 946 | 935 | ||
| 947 | - If required, invoke the package-specific command to prepare | 936 | will let you gain control when an error is detected and before |
| 948 | src/temacs for execution. | 937 | UndefinedBehaviorSanitizer outputs to stderr or terminates the |
| 938 | program. | ||
| 949 | 939 | ||
| 950 | - cd ..; src/temacs | 940 | ** Running Emacs with address sanitization |
| 951 | 941 | ||
| 952 | (Note that this runs 'temacs' instead of the usual 'emacs' executable. | 942 | Building Emacs with address sanitization can help debug memory-use |
| 953 | This avoids problems with dumping Emacs mentioned above.) | 943 | problems. To use AddressSanitizer with GCC and similar compilers, |
| 944 | append '-fsanitize=address' to CFLAGS, either when running 'configure' | ||
| 945 | or running 'make'. Configure, build and run Emacs with | ||
| 946 | ASAN_OPTIONS='detect_leaks=0' in the environment to suppress | ||
| 947 | diagnostics of minor memory leaks in Emacs. For example: | ||
| 954 | 948 | ||
| 955 | Some malloc debugging libraries might print lots of false alarms for | 949 | export ASAN_OPTIONS='detect_leaks=0' |
| 956 | bitfields used by Emacs in some data structures. If you want to get | 950 | ./configure CFLAGS='-O0 -g3 -fsanitize=address' |
| 957 | rid of the false alarms, you will have to hack the definitions of | 951 | make |
| 958 | these data structures on the respective headers to remove the ':N' | 952 | src/emacs |
| 959 | bitfield definitions (which will cause each such field to use a full | 953 | |
| 960 | int). | 954 | You may need to append '-static-libasan' to CFLAGS if your version of |
| 955 | GCC is installed in an unusual location. | ||
| 956 | |||
| 957 | When using GDB to debug an executable with address sanitization, the | ||
| 958 | GDB command: | ||
| 959 | |||
| 960 | (gdb) rbreak ^__asan_report_ | ||
| 961 | |||
| 962 | will let you gain control when an error is detected and before | ||
| 963 | AddressSanitizer outputs to stderr or terminates the program. | ||
| 964 | |||
| 965 | Address sanitization is incompatible with undefined-behavior | ||
| 966 | sanitization, unfortunately. Address sanitization is also | ||
| 967 | incompatible with the --with-dumping=unexec option of 'configure'. | ||
| 968 | |||
| 969 | ** Running Emacs under Valgrind | ||
| 970 | |||
| 971 | Valgrind <http://valgrind.org/> is free software that can be useful | ||
| 972 | when debugging low-level Emacs problems. Unlike GCC sanitizers, | ||
| 973 | Valgrind does not need you to compile Emacs with special debugging | ||
| 974 | flags, so it can be helpful in investigating problems that vanish when | ||
| 975 | Emacs is recompiled with debugging enabled. However, by default | ||
| 976 | Valgrind generates many false alarms with Emacs, and you will need to | ||
| 977 | maintain a suppressions file to suppress these false alarms and use | ||
| 978 | Valgrind effectively. For example, you might invoke Valgrind this | ||
| 979 | way: | ||
| 980 | |||
| 981 | valgrind --suppressions=valgrind.supp ./emacs | ||
| 982 | |||
| 983 | where valgrind.supp contains groups of lines like the following, which | ||
| 984 | suppresses some Valgrind false alarms during Emacs garbage collection: | ||
| 985 | |||
| 986 | { | ||
| 987 | Fgarbage_collect Cond - conservative garbage collection | ||
| 988 | Memcheck:Cond | ||
| 989 | ... | ||
| 990 | fun:Fgarbage_collect | ||
| 991 | } | ||
| 992 | |||
| 993 | Unfortunately Valgrind suppression files tend to be system-dependent, | ||
| 994 | so you will need to keep one around that matches your system. | ||
| 961 | 995 | ||
| 962 | ** How to recover buffer contents from an Emacs core dump file | 996 | ** How to recover buffer contents from an Emacs core dump file |
| 963 | 997 | ||
| @@ -93,7 +93,8 @@ change to one of the data structures that it relies on. | |||
| 93 | ** The configure options '--enable-checking=conslist' and | 93 | ** The configure options '--enable-checking=conslist' and |
| 94 | '--enable-checking=xmallocoverrun' have been withdrawn. The former | 94 | '--enable-checking=xmallocoverrun' have been withdrawn. The former |
| 95 | made Emacs irredeemably slow, and the latter made it crash. Neither | 95 | made Emacs irredeemably slow, and the latter made it crash. Neither |
| 96 | option was useful with modern debugging tools. | 96 | option was useful with modern debugging tools such as AddressSanitizer |
| 97 | (see etc/DEBUG). | ||
| 97 | 98 | ||
| 98 | --- | 99 | --- |
| 99 | ** Emacs now requires GTK 2.24 and GTK 3.10 for the GTK 2 and GTK 3 | 100 | ** Emacs now requires GTK 2.24 and GTK 3.10 for the GTK 2 and GTK 3 |