debug.txt 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. *debug.txt* Nvim
  2. VIM REFERENCE MANUAL by Bram Moolenaar
  3. Debugging Vim *debug-vim*
  4. This is for debugging Vim itself, when it doesn't work properly.
  5. For debugging Vim scripts, functions, etc. see |debug-scripts|
  6. Type |gO| to see the table of contents.
  7. ==============================================================================
  8. 1. Location of a crash, using gcc and gdb *debug-gcc* *gdb*
  9. When Vim crashes in one of the test files, and you are using gcc for
  10. compilation, here is what you can do to find out exactly where Vim crashes.
  11. This also applies when using the MingW tools.
  12. 1. Compile Vim with the "-g" option (there is a line in the src/Makefile for
  13. this, which you can uncomment). Also make sure "strip" is disabled (do not
  14. install it, or use the line "STRIP = /bin/true").
  15. 2. Execute these commands (replace "11" with the test that fails): >
  16. cd testdir
  17. gdb ../vim
  18. run -u unix.vim -U NONE -s dotest.in test11.in
  19. 3. Check where Vim crashes, gdb should give a message for this.
  20. 4. Get a stack trace from gdb with this command: >
  21. where
  22. < You can check out different places in the stack trace with: >
  23. frame 3
  24. < Replace "3" with one of the numbers in the stack trace.
  25. ==============================================================================
  26. 2. Locating memory leaks *debug-leaks* *valgrind*
  27. If you suspect Vim is leaking memory and you are using Linux, the valgrind
  28. tool is very useful to pinpoint memory leaks.
  29. First of all, build Vim with EXITFREE defined. Search for this in MAKEFILE
  30. and uncomment the line.
  31. Use this command to start Vim:
  32. >
  33. valgrind --log-file=valgrind.log --leak-check=full ./vim
  34. Note: Vim will run much slower. If your vimrc is big or you have several
  35. plugins you need to be patient for startup, or run with the "-u NONE"
  36. argument.
  37. There are often a few leaks from libraries, such as getpwuid() and
  38. XtVaAppCreateShell(). Those are unavoidable. The number of bytes should be
  39. very small a Kbyte or less.
  40. ==============================================================================
  41. 3. Windows Bug Reporting *debug-win32*
  42. If the Windows version of Vim crashes in a reproducible manner, you can take
  43. some steps to provide a useful bug report.
  44. 3.1 GENERIC ~
  45. You must obtain the debugger symbols (PDB) file for your executable: gvim.pdb
  46. for gvim.exe, or vim.pdb for vim.exe. The PDB should be available from the
  47. same place that you obtained the executable. Be sure to use the PDB that
  48. matches the EXE (same date).
  49. If you built the executable yourself with the Microsoft Visual C++ compiler,
  50. then the PDB was built with the EXE.
  51. If you have Visual Studio, use that instead of the VC Toolkit and WinDbg.
  52. For other compilers, you should always use the corresponding debugger: gdb
  53. (see above |debug-gcc|) for the Cygwin and MinGW compilers.
  54. *debug-vs2005*
  55. 3.2 Debugging Vim crashes with Visual Studio 2005/Visual C++ 2005 Express ~
  56. First launch vim.exe or gvim.exe and then launch Visual Studio. (If you don't
  57. have Visual Studio, follow the instructions at |get-ms-debuggers| to obtain a
  58. free copy of Visual C++ 2005 Express Edition.)
  59. On the Tools menu, click Attach to Process. Choose the Vim process.
  60. In Vim, reproduce the crash. A dialog will appear in Visual Studio, telling
  61. you about the unhandled exception in the Vim process. Click Break to break
  62. into the process.
  63. Visual Studio will pop up another dialog, telling you that no symbols are
  64. loaded and that the source code cannot be displayed. Click OK.
  65. Several windows will open. Right-click in the Call Stack window. Choose Load
  66. Symbols. The Find Symbols dialog will open, looking for (g)vim.pdb. Navigate
  67. to the directory where you have the PDB file and click Open.
  68. At this point, you should have a full call stack with vim function names and
  69. line numbers. Double-click one of the lines and the Find Source dialog will
  70. appear. Navigate to the directory where the Vim source is (if you have it.)
  71. If you don't know how to debug this any further, follow the instructions
  72. at ":help bug-report". Paste the call stack into the bug report.
  73. If you have a non-free version of Visual Studio, you can save a minidump via
  74. the Debug menu and send it with the bug report. A minidump is a small file
  75. (<100KB), which contains information about the state of your process.
  76. Visual C++ 2005 Express Edition cannot save minidumps and it cannot be
  77. installed as a just-in-time debugger. Use WinDbg, |debug-windbg|, if you
  78. need to save minidumps or you want a just-in-time (postmortem) debugger.
  79. *debug-windbg*
  80. 3.3 Debugging Vim crashes with WinDbg ~
  81. See |get-ms-debuggers| to obtain a copy of WinDbg.
  82. As with the Visual Studio IDE, you can attach WinDbg to a running Vim process.
  83. You can also have your system automatically invoke WinDbg as a postmortem
  84. debugger. To set WinDbg as your postmortem debugger, run "windbg -I".
  85. To attach WinDbg to a running Vim process, launch WinDbg. On the File menu,
  86. choose Attach to a Process. Select the Vim process and click OK.
  87. At this point, choose Symbol File Path on the File menu, and add the folder
  88. containing your Vim PDB to the sympath. If you have Vim source available,
  89. use Source File Path on the File menu. You can now open source files in WinDbg
  90. and set breakpoints, if you like. Reproduce your crash. WinDbg should open the
  91. source file at the point of the crash. Using the View menu, you can examine
  92. the call stack, local variables, watch windows, and so on.
  93. If WinDbg is your postmortem debugger, you do not need to attach WinDbg to
  94. your Vim process. Simply reproduce the crash and WinDbg will launch
  95. automatically. As above, set the Symbol File Path and the Source File Path.
  96. To save a minidump, type the following at the WinDbg command line: >
  97. .dump vim.dmp
  98. <
  99. *debug-minidump*
  100. 3.4 Opening a Minidump ~
  101. If you have a minidump file, you can open it in Visual Studio or in WinDbg.
  102. In Visual Studio 2005: on the File menu, choose Open, then Project/Solution.
  103. Navigate to the .dmp file and open it. Now press F5 to invoke the debugger.
  104. Follow the instructions in |debug-vs2005| to set the Symbol File Path.
  105. In WinDbg: choose Open Crash Dump on the File menu. Follow the instructions in
  106. |debug-windbg| to set the Symbol File Path.
  107. *get-ms-debuggers*
  108. 3.5 Obtaining Microsoft Debugging Tools ~
  109. Visual Studio 2017 Community Edition can be downloaded for free from:
  110. https://visualstudio.microsoft.com/downloads/
  111. =========================================================================
  112. vim:tw=78:ts=8:noet:ft=help:norl: