Christian Brabandt | 1c5728e | 2024-05-11 11:12:40 +0200 | [diff] [blame] | 1 | *debug.txt* For Vim version 9.1. Last change: 2024 May 11 |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 2 | |
| 3 | |
| 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
| 5 | |
| 6 | |
| 7 | Debugging Vim *debug-vim* |
| 8 | |
| 9 | This is for debugging Vim itself, when it doesn't work properly. |
Bram Moolenaar | acf5345 | 2005-12-17 22:06:52 +0000 | [diff] [blame] | 10 | For debugging Vim scripts, functions, etc. see |debug-scripts| |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 11 | |
| 12 | 1. Location of a crash, using gcc and gdb |debug-gcc| |
Bram Moolenaar | 8f3f58f | 2010-01-06 20:52:26 +0100 | [diff] [blame] | 13 | 2. Locating memory leaks |debug-leaks| |
| 14 | 3. Windows Bug Reporting |debug-win32| |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 15 | |
| 16 | ============================================================================== |
| 17 | |
Bram Moolenaar | 5dc6252 | 2012-02-13 00:05:22 +0100 | [diff] [blame] | 18 | 1. Location of a crash, using gcc and gdb *debug-gcc* *gdb* |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 19 | |
| 20 | When Vim crashes in one of the test files, and you are using gcc for |
| 21 | compilation, here is what you can do to find out exactly where Vim crashes. |
| 22 | This also applies when using the MingW tools. |
| 23 | |
Bram Moolenaar | 2a8a3ec | 2011-01-08 16:06:37 +0100 | [diff] [blame] | 24 | 1. Compile Vim with the "-g" option (there is a line in the src/Makefile for |
| 25 | this, which you can uncomment). Also make sure "strip" is disabled (do not |
Bram Moolenaar | 24ea3ba | 2010-09-19 19:01:21 +0200 | [diff] [blame] | 26 | install it, or use the line "STRIP = /bin/true"). |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 27 | |
| 28 | 2. Execute these commands (replace "11" with the test that fails): > |
| 29 | cd testdir |
| 30 | gdb ../vim |
| 31 | run -u unix.vim -U NONE -s dotest.in test11.in |
| 32 | |
| 33 | 3. Check where Vim crashes, gdb should give a message for this. |
| 34 | |
| 35 | 4. Get a stack trace from gdb with this command: > |
| 36 | where |
| 37 | < You can check out different places in the stack trace with: > |
| 38 | frame 3 |
| 39 | < Replace "3" with one of the numbers in the stack trace. |
| 40 | |
| 41 | ============================================================================== |
| 42 | |
Bram Moolenaar | 164fca3 | 2010-07-14 13:58:07 +0200 | [diff] [blame] | 43 | 2. Locating memory leaks *debug-leaks* *valgrind* |
Bram Moolenaar | 8f3f58f | 2010-01-06 20:52:26 +0100 | [diff] [blame] | 44 | |
| 45 | If you suspect Vim is leaking memory and you are using Linux, the valgrind |
| 46 | tool is very useful to pinpoint memory leaks. |
| 47 | |
| 48 | First of all, build Vim with EXITFREE defined. Search for this in MAKEFILE |
| 49 | and uncomment the line. |
| 50 | |
Bram Moolenaar | 164fca3 | 2010-07-14 13:58:07 +0200 | [diff] [blame] | 51 | Use this command to start Vim: |
Bram Moolenaar | 8f3f58f | 2010-01-06 20:52:26 +0100 | [diff] [blame] | 52 | > |
Bram Moolenaar | 164fca3 | 2010-07-14 13:58:07 +0200 | [diff] [blame] | 53 | valgrind --log-file=valgrind.log --leak-check=full ./vim |
Bram Moolenaar | 8f3f58f | 2010-01-06 20:52:26 +0100 | [diff] [blame] | 54 | |
| 55 | Note: Vim will run much slower. If your .vimrc is big or you have several |
Bram Moolenaar | c4da113 | 2017-07-15 19:39:43 +0200 | [diff] [blame] | 56 | plugins you need to be patient for startup, or run with the "--clean" |
Bram Moolenaar | 8f3f58f | 2010-01-06 20:52:26 +0100 | [diff] [blame] | 57 | argument. |
| 58 | |
Bram Moolenaar | 164fca3 | 2010-07-14 13:58:07 +0200 | [diff] [blame] | 59 | There are often a few leaks from libraries, such as getpwuid() and |
| 60 | XtVaAppCreateShell(). Those are unavoidable. The number of bytes should be |
| 61 | very small a Kbyte or less. |
| 62 | |
Bram Moolenaar | 8f3f58f | 2010-01-06 20:52:26 +0100 | [diff] [blame] | 63 | ============================================================================== |
| 64 | |
| 65 | 3. Windows Bug Reporting *debug-win32* |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 66 | |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 67 | If the Windows version of Vim crashes in a reproducible manner, you can take |
| 68 | some steps to provide a useful bug report. |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 69 | |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 70 | |
Bram Moolenaar | 24ea3ba | 2010-09-19 19:01:21 +0200 | [diff] [blame] | 71 | 3.1 GENERIC ~ |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 72 | |
| 73 | You must obtain the debugger symbols (PDB) file for your executable: gvim.pdb |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 74 | for gvim.exe, or vim.pdb for vim.exe. The PDB should be available from the |
| 75 | same place that you obtained the executable. Be sure to use the PDB that |
| 76 | matches the EXE (same date). |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 77 | |
| 78 | If you built the executable yourself with the Microsoft Visual C++ compiler, |
| 79 | then the PDB was built with the EXE. |
| 80 | |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 81 | If you have Visual Studio, use that instead of the VC Toolkit and WinDbg. |
| 82 | |
Bram Moolenaar | eae1b91 | 2019-05-09 15:12:55 +0200 | [diff] [blame] | 83 | For other compilers, you should always use the corresponding debugger: gdb |
| 84 | (see above |debug-gcc|) for the Cygwin and MinGW compilers. |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 85 | |
| 86 | |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 87 | *debug-vs2005* |
Bram Moolenaar | 24ea3ba | 2010-09-19 19:01:21 +0200 | [diff] [blame] | 88 | 3.2 Debugging Vim crashes with Visual Studio 2005/Visual C++ 2005 Express ~ |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 89 | |
| 90 | First launch vim.exe or gvim.exe and then launch Visual Studio. (If you don't |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 91 | have Visual Studio, follow the instructions at |get-ms-debuggers| to obtain a |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 92 | free copy of Visual C++ 2005 Express Edition.) |
| 93 | |
| 94 | On the Tools menu, click Attach to Process. Choose the Vim process. |
| 95 | |
| 96 | In Vim, reproduce the crash. A dialog will appear in Visual Studio, telling |
| 97 | you about the unhandled exception in the Vim process. Click Break to break |
| 98 | into the process. |
| 99 | |
| 100 | Visual Studio will pop up another dialog, telling you that no symbols are |
| 101 | loaded and that the source code cannot be displayed. Click OK. |
| 102 | |
| 103 | Several windows will open. Right-click in the Call Stack window. Choose Load |
| 104 | Symbols. The Find Symbols dialog will open, looking for (g)vim.pdb. Navigate |
| 105 | to the directory where you have the PDB file and click Open. |
| 106 | |
| 107 | At this point, you should have a full call stack with vim function names and |
| 108 | line numbers. Double-click one of the lines and the Find Source dialog will |
| 109 | appear. Navigate to the directory where the Vim source is (if you have it.) |
| 110 | |
| 111 | If you don't know how to debug this any further, follow the instructions |
| 112 | at ":help bug-reports". Paste the call stack into the bug report. |
| 113 | |
| 114 | If you have a non-free version of Visual Studio, you can save a minidump via |
| 115 | the Debug menu and send it with the bug report. A minidump is a small file |
| 116 | (<100KB), which contains information about the state of your process. |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 117 | Visual C++ 2005 Express Edition cannot save minidumps and it cannot be |
| 118 | installed as a just-in-time debugger. Use WinDbg, |debug-windbg|, if you |
| 119 | need to save minidumps or you want a just-in-time (postmortem) debugger. |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 120 | |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 121 | *debug-windbg* |
Bram Moolenaar | 24ea3ba | 2010-09-19 19:01:21 +0200 | [diff] [blame] | 122 | 3.3 Debugging Vim crashes with WinDbg ~ |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 123 | |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 124 | See |get-ms-debuggers| to obtain a copy of WinDbg. |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 125 | |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 126 | As with the Visual Studio IDE, you can attach WinDbg to a running Vim process. |
| 127 | You can also have your system automatically invoke WinDbg as a postmortem |
| 128 | debugger. To set WinDbg as your postmortem debugger, run "windbg -I". |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 129 | |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 130 | To attach WinDbg to a running Vim process, launch WinDbg. On the File menu, |
| 131 | choose Attach to a Process. Select the Vim process and click OK. |
| 132 | |
| 133 | At this point, choose Symbol File Path on the File menu, and add the folder |
| 134 | containing your Vim PDB to the sympath. If you have Vim source available, |
| 135 | use Source File Path on the File menu. You can now open source files in WinDbg |
| 136 | and set breakpoints, if you like. Reproduce your crash. WinDbg should open the |
| 137 | source file at the point of the crash. Using the View menu, you can examine |
| 138 | the call stack, local variables, watch windows, and so on. |
| 139 | |
| 140 | If WinDbg is your postmortem debugger, you do not need to attach WinDbg to |
| 141 | your Vim process. Simply reproduce the crash and WinDbg will launch |
| 142 | automatically. As above, set the Symbol File Path and the Source File Path. |
| 143 | |
| 144 | To save a minidump, type the following at the WinDbg command line: > |
| 145 | .dump vim.dmp |
| 146 | < |
| 147 | *debug-minidump* |
Bram Moolenaar | 24ea3ba | 2010-09-19 19:01:21 +0200 | [diff] [blame] | 148 | 3.4 Opening a Minidump ~ |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 149 | |
| 150 | If you have a minidump file, you can open it in Visual Studio or in WinDbg. |
| 151 | |
| 152 | In Visual Studio 2005: on the File menu, choose Open, then Project/Solution. |
| 153 | Navigate to the .dmp file and open it. Now press F5 to invoke the debugger. |
| 154 | Follow the instructions in |debug-vs2005| to set the Symbol File Path. |
| 155 | |
| 156 | In WinDbg: choose Open Crash Dump on the File menu. Follow the instructions in |
| 157 | |debug-windbg| to set the Symbol File Path. |
| 158 | |
| 159 | *get-ms-debuggers* |
Bram Moolenaar | 24ea3ba | 2010-09-19 19:01:21 +0200 | [diff] [blame] | 160 | 3.5 Obtaining Microsoft Debugging Tools ~ |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 161 | |
| 162 | The Debugging Tools for Windows (including WinDbg) can be downloaded from |
Christian Brabandt | 1c5728e | 2024-05-11 11:12:40 +0200 | [diff] [blame] | 163 | https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-download-tools |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 164 | This includes the WinDbg debugger. |
| 165 | |
Bram Moolenaar | d68071d | 2006-05-02 22:08:30 +0000 | [diff] [blame] | 166 | Visual C++ 2005 Express Edition can be downloaded for free from: |
| 167 | http://msdn.microsoft.com/vstudio/express/visualC/default.aspx |
Bram Moolenaar | e344bea | 2005-09-01 20:46:49 +0000 | [diff] [blame] | 168 | |
| 169 | ========================================================================= |
Bram Moolenaar | 91f84f6 | 2018-07-29 15:07:52 +0200 | [diff] [blame] | 170 | vim:tw=78:ts=8:noet:ft=help:norl: |