xref: /vim-8.2.3635/runtime/doc/debug.txt (revision 98056533)
1*98056533SBram Moolenaar*debug.txt*     For Vim version 8.2.  Last change: 2019 May 07
2e344beadSBram Moolenaar
3e344beadSBram Moolenaar
4e344beadSBram Moolenaar		  VIM REFERENCE MANUAL    by Bram Moolenaar
5e344beadSBram Moolenaar
6e344beadSBram Moolenaar
7e344beadSBram MoolenaarDebugging Vim						*debug-vim*
8e344beadSBram Moolenaar
9e344beadSBram MoolenaarThis is for debugging Vim itself, when it doesn't work properly.
10acf53459SBram MoolenaarFor debugging Vim scripts, functions, etc. see |debug-scripts|
11e344beadSBram Moolenaar
12e344beadSBram Moolenaar1. Location of a crash, using gcc and gdb	|debug-gcc|
138f3f58f2SBram Moolenaar2. Locating memory leaks			|debug-leaks|
148f3f58f2SBram Moolenaar3. Windows Bug Reporting			|debug-win32|
15e344beadSBram Moolenaar
16e344beadSBram Moolenaar==============================================================================
17e344beadSBram Moolenaar
185dc6252dSBram Moolenaar1. Location of a crash, using gcc and gdb		*debug-gcc* *gdb*
19e344beadSBram Moolenaar
20e344beadSBram MoolenaarWhen Vim crashes in one of the test files, and you are using gcc for
21e344beadSBram Moolenaarcompilation, here is what you can do to find out exactly where Vim crashes.
22e344beadSBram MoolenaarThis also applies when using the MingW tools.
23e344beadSBram Moolenaar
242a8a3ecbSBram Moolenaar1. Compile Vim with the "-g" option (there is a line in the src/Makefile for
252a8a3ecbSBram Moolenaar   this, which you can uncomment).  Also make sure "strip" is disabled (do not
2624ea3babSBram Moolenaar   install it, or use the line "STRIP = /bin/true").
27e344beadSBram Moolenaar
28e344beadSBram Moolenaar2. Execute these commands (replace "11" with the test that fails): >
29e344beadSBram Moolenaar	cd testdir
30e344beadSBram Moolenaar	gdb ../vim
31e344beadSBram Moolenaar	run -u unix.vim -U NONE -s dotest.in test11.in
32e344beadSBram Moolenaar
33e344beadSBram Moolenaar3. Check where Vim crashes, gdb should give a message for this.
34e344beadSBram Moolenaar
35e344beadSBram Moolenaar4. Get a stack trace from gdb with this command: >
36e344beadSBram Moolenaar	where
37e344beadSBram Moolenaar<  You can check out different places in the stack trace with: >
38e344beadSBram Moolenaar	frame 3
39e344beadSBram Moolenaar<  Replace "3" with one of the numbers in the stack trace.
40e344beadSBram Moolenaar
41e344beadSBram Moolenaar==============================================================================
42e344beadSBram Moolenaar
43164fca39SBram Moolenaar2. Locating memory leaks			*debug-leaks* *valgrind*
448f3f58f2SBram Moolenaar
458f3f58f2SBram MoolenaarIf you suspect Vim is leaking memory and you are using Linux, the valgrind
468f3f58f2SBram Moolenaartool is very useful to pinpoint memory leaks.
478f3f58f2SBram Moolenaar
488f3f58f2SBram MoolenaarFirst of all, build Vim with EXITFREE defined.  Search for this in MAKEFILE
498f3f58f2SBram Moolenaarand uncomment the line.
508f3f58f2SBram Moolenaar
51164fca39SBram MoolenaarUse this command to start Vim:
528f3f58f2SBram Moolenaar>
53164fca39SBram Moolenaar	valgrind --log-file=valgrind.log --leak-check=full ./vim
548f3f58f2SBram Moolenaar
558f3f58f2SBram MoolenaarNote: Vim will run much slower.  If your .vimrc is big or you have several
56c4da113eSBram Moolenaarplugins you need to be patient for startup, or run with the "--clean"
578f3f58f2SBram Moolenaarargument.
588f3f58f2SBram Moolenaar
59164fca39SBram MoolenaarThere are often a few leaks from libraries, such as getpwuid() and
60164fca39SBram MoolenaarXtVaAppCreateShell().  Those are unavoidable.  The number of bytes should be
61164fca39SBram Moolenaarvery small a Kbyte or less.
62164fca39SBram Moolenaar
638f3f58f2SBram Moolenaar==============================================================================
648f3f58f2SBram Moolenaar
658f3f58f2SBram Moolenaar3. Windows Bug Reporting				*debug-win32*
66e344beadSBram Moolenaar
67f9393ef5SBram MoolenaarIf the Windows version of Vim crashes in a reproducible manner, you can take
68f9393ef5SBram Moolenaarsome steps to provide a useful bug report.
69e344beadSBram Moolenaar
70f9393ef5SBram Moolenaar
7124ea3babSBram Moolenaar3.1 GENERIC ~
72f9393ef5SBram Moolenaar
73f9393ef5SBram MoolenaarYou must obtain the debugger symbols (PDB) file for your executable: gvim.pdb
74d68071d8SBram Moolenaarfor gvim.exe, or vim.pdb for vim.exe. The PDB should be available from the
75d68071d8SBram Moolenaarsame place that you obtained the executable. Be sure to use the PDB that
76d68071d8SBram Moolenaarmatches the EXE (same date).
77e344beadSBram Moolenaar
78e344beadSBram MoolenaarIf you built the executable yourself with the Microsoft Visual C++ compiler,
79e344beadSBram Moolenaarthen the PDB was built with the EXE.
80e344beadSBram Moolenaar
81f9393ef5SBram MoolenaarIf you have Visual Studio, use that instead of the VC Toolkit and WinDbg.
82f9393ef5SBram Moolenaar
83eae1b91fSBram MoolenaarFor other compilers, you should always use the corresponding debugger: gdb
84eae1b91fSBram Moolenaar(see above |debug-gcc|) for the Cygwin and MinGW compilers.
85f9393ef5SBram Moolenaar
86f9393ef5SBram Moolenaar
87d68071d8SBram Moolenaar								*debug-vs2005*
8824ea3babSBram Moolenaar3.2 Debugging Vim crashes with Visual Studio 2005/Visual C++ 2005 Express ~
89f9393ef5SBram Moolenaar
90f9393ef5SBram MoolenaarFirst launch vim.exe or gvim.exe and then launch Visual Studio.  (If you don't
91d68071d8SBram Moolenaarhave Visual Studio, follow the instructions at |get-ms-debuggers| to obtain a
92f9393ef5SBram Moolenaarfree copy of Visual C++ 2005 Express Edition.)
93f9393ef5SBram Moolenaar
94f9393ef5SBram MoolenaarOn the Tools menu, click Attach to Process.  Choose the Vim process.
95f9393ef5SBram Moolenaar
96f9393ef5SBram MoolenaarIn Vim, reproduce the crash.  A dialog will appear in Visual Studio, telling
97f9393ef5SBram Moolenaaryou about the unhandled exception in the Vim process.  Click Break to break
98f9393ef5SBram Moolenaarinto the process.
99f9393ef5SBram Moolenaar
100f9393ef5SBram MoolenaarVisual Studio will pop up another dialog, telling you that no symbols are
101f9393ef5SBram Moolenaarloaded and that the source code cannot be displayed.  Click OK.
102f9393ef5SBram Moolenaar
103f9393ef5SBram MoolenaarSeveral windows will open.  Right-click in the Call Stack window.  Choose Load
104f9393ef5SBram MoolenaarSymbols.  The Find Symbols dialog will open, looking for (g)vim.pdb.  Navigate
105f9393ef5SBram Moolenaarto the directory where you have the PDB file and click Open.
106f9393ef5SBram Moolenaar
107f9393ef5SBram MoolenaarAt this point, you should have a full call stack with vim function names and
108f9393ef5SBram Moolenaarline numbers.  Double-click one of the lines and the Find Source dialog will
109f9393ef5SBram Moolenaarappear.  Navigate to the directory where the Vim source is (if you have it.)
110f9393ef5SBram Moolenaar
111f9393ef5SBram MoolenaarIf you don't know how to debug this any further, follow the instructions
112f9393ef5SBram Moolenaarat ":help bug-reports".  Paste the call stack into the bug report.
113f9393ef5SBram Moolenaar
114f9393ef5SBram MoolenaarIf you have a non-free version of Visual Studio, you can save a minidump via
115f9393ef5SBram Moolenaarthe Debug menu and send it with the bug report.  A minidump is a small file
116f9393ef5SBram Moolenaar(<100KB), which contains information about the state of your process.
117d68071d8SBram MoolenaarVisual C++ 2005 Express Edition cannot save minidumps and it cannot be
118d68071d8SBram Moolenaarinstalled as a just-in-time debugger. Use WinDbg, |debug-windbg|, if you
119d68071d8SBram Moolenaarneed to save minidumps or you want a just-in-time (postmortem) debugger.
120f9393ef5SBram Moolenaar
121d68071d8SBram Moolenaar								*debug-windbg*
12224ea3babSBram Moolenaar3.3 Debugging Vim crashes with WinDbg ~
123f9393ef5SBram Moolenaar
124d68071d8SBram MoolenaarSee |get-ms-debuggers| to obtain a copy of WinDbg.
125f9393ef5SBram Moolenaar
126d68071d8SBram MoolenaarAs with the Visual Studio IDE, you can attach WinDbg to a running Vim process.
127d68071d8SBram MoolenaarYou can also have your system automatically invoke WinDbg as a postmortem
128d68071d8SBram Moolenaardebugger. To set WinDbg as your postmortem debugger, run "windbg -I".
129e344beadSBram Moolenaar
130d68071d8SBram MoolenaarTo attach WinDbg to a running Vim process, launch WinDbg. On the File menu,
131d68071d8SBram Moolenaarchoose Attach to a Process. Select the Vim process and click OK.
132d68071d8SBram Moolenaar
133d68071d8SBram MoolenaarAt this point, choose Symbol File Path on the File menu, and add the folder
134d68071d8SBram Moolenaarcontaining your Vim PDB to the sympath. If you have Vim source available,
135d68071d8SBram Moolenaaruse Source File Path on the File menu. You can now open source files in WinDbg
136d68071d8SBram Moolenaarand set breakpoints, if you like. Reproduce your crash. WinDbg should open the
137d68071d8SBram Moolenaarsource file at the point of the crash. Using the View menu, you can examine
138d68071d8SBram Moolenaarthe call stack, local variables, watch windows, and so on.
139d68071d8SBram Moolenaar
140d68071d8SBram MoolenaarIf WinDbg is your postmortem debugger, you do not need to attach WinDbg to
141d68071d8SBram Moolenaaryour Vim process. Simply reproduce the crash and WinDbg will launch
142d68071d8SBram Moolenaarautomatically. As above, set the Symbol File Path and the Source File Path.
143d68071d8SBram Moolenaar
144d68071d8SBram MoolenaarTo save a minidump, type the following at the WinDbg command line: >
145d68071d8SBram Moolenaar        .dump vim.dmp
146d68071d8SBram Moolenaar<
147d68071d8SBram Moolenaar							*debug-minidump*
14824ea3babSBram Moolenaar3.4 Opening a Minidump ~
149d68071d8SBram Moolenaar
150d68071d8SBram MoolenaarIf you have a minidump file, you can open it in Visual Studio or in WinDbg.
151d68071d8SBram Moolenaar
152d68071d8SBram MoolenaarIn Visual Studio 2005: on the File menu, choose Open, then Project/Solution.
153d68071d8SBram MoolenaarNavigate to the .dmp file and open it. Now press F5 to invoke the debugger.
154d68071d8SBram MoolenaarFollow the instructions in |debug-vs2005| to set the Symbol File Path.
155d68071d8SBram Moolenaar
156d68071d8SBram MoolenaarIn WinDbg: choose Open Crash Dump on the File menu. Follow the instructions in
157d68071d8SBram Moolenaar|debug-windbg| to set the Symbol File Path.
158d68071d8SBram Moolenaar
159d68071d8SBram Moolenaar							*get-ms-debuggers*
16024ea3babSBram Moolenaar3.5 Obtaining Microsoft Debugging Tools ~
161d68071d8SBram Moolenaar
162d68071d8SBram MoolenaarThe Debugging Tools for Windows (including WinDbg) can be downloaded from
163e344beadSBram Moolenaar    http://www.microsoft.com/whdc/devtools/debugging/default.mspx
164e344beadSBram MoolenaarThis includes the WinDbg debugger.
165e344beadSBram Moolenaar
166d68071d8SBram MoolenaarVisual C++ 2005 Express Edition can be downloaded for free from:
167d68071d8SBram Moolenaar    http://msdn.microsoft.com/vstudio/express/visualC/default.aspx
168e344beadSBram Moolenaar
169e344beadSBram Moolenaar=========================================================================
17091f84f6eSBram Moolenaar vim:tw=78:ts=8:noet:ft=help:norl:
171