Table of contents
- 1. Requirements
- 2. Ways to start the debugger
- 3. Debugging Release Builds
- 4. Creating a Visual C++ project for Mozilla
- 5. Changing/setting the executable to debug
- 6. Command line parameters and environment variables
- 7. Setting breakpoints in DLLs which are not yet loaded in memory
- 8. Displaying Unicode string
- 9. Customizing the debugger's variable value view
- 10. Avoiding stepping into certain functions
- 11. Obtaining stdout and other FILE handles
- 12. Disabling ASSERTIONS
- 12.1. Environment variable
- 12.2. Changing running code
- 13. Automatically handling ASSERTIONS without a debugger attached
- 14. Debugging optimized builds
- 15. Running two instances of Mozilla simultaneously
- 16. Debugging JavaScript
- 17. Got a tip?
This document tries to answer the most common questions about how to effectively debug Mozilla on a 32-bit Microsoft Windows system. It assumes you already know how to use the Microsoft Visual C++ development environment and debugger.
These instructions were originally written for VC++ 6.0. Started adding notes where things are different with VC++ 7.0+ aka Visual Studio .NET 2003 and newer. VC++ 7.0 notes are still incomplete, so please add new instructions for VC++ 7.0.
Requirements
See the Windows Build Prerequisites.
Ways to start the debugger
Launch MSDEV, select File > Open Workspace... (Open Solution... in VC++ 7.0) and select a Mozilla executable. This will also create a Mozilla project. You can start a debug run by pressing F5.
From the command line using VC6/7, type msdev <program name>
. You might need to be in the same directory as the executable?
From the command line using VC8/9, type devenv /debugexe <program name> <program arguments>
. Once Visual Studio opens, select 'Start Debugging' from the 'Debug' menu.
Run the program until you hit an assertion. You will get a dialog box asking if you would like to debug. Hit "Cancel". The MSDEV IDE will launch and load the file where the assertion happened. This will also create a Visual C++ Mozilla project in the directory of the executable by default.
Debugging Release Builds
Beginning with Firefox 3.0a5, Mozilla maintains a symbol server for nightly and release builds.
Creating a Visual C++ project for Mozilla
This may no longer work:
You probably want to create a Mozilla project in the mozilla root directory. You do this by selecting File > Open Workspace... and opening client.mak
. Visual C++ compains that it cannot read this project, and you can ignore this. It will also ask you to name the project file it should create. You probably want to say "mozilla". If you do File > Open Workspace... (Open Solution... in VC++ 7.0) and select an executable to open, VC++ creates a project in the directory of the executable by default. Once you have the project, do "Save All" to save all the workspace information. You will want to do this whenever you change some Visual C++ options. Before you actually start using the project it probably makes sense to set some options etc. so read on.
Changing/setting the executable to debug
VC++ 6.0: To change or set the executable to debug, go to Project > Settings..., Debug tab and select General from the drop down list. "Executable for debug session:" should show the executable you are debugging. If it is empty or incorrect, use the arrow button and select Browse... to locate the executable.
Command line parameters and environment variables
VC++ 6.0: To change or set the command line options, go to Project > Settings..., Debug tab and select General from the drop down list. "Program arguments:" should show the options.
Some common options would be the URL of the file you want the browser to open as soon as it starts, starting the Profile Manager, or selecting a profile. You can also redirect the console output to a file (by adding "> filename.txt
" for example, without the quotes).
In VC 7 and 8 this option is called Project > Properties > Debugging > Command Arguments. VC 8 also allows you to set environment variables there.
Setting breakpoints in DLLs which are not yet loaded in memory
VC++ 6.0: Go to Project > Settings..., Debug tab and select "Additional DLLs" from the drop down list. Check "Locate Additional DLLs" option. For each DLL, click the "New" button which creates a new entry and then hit the "..." buttons which lets you browse to the DLL. You will only be able to add one DLL at a time.
VC++ 7.0 automatically finds additional DLLs.
Displaying Unicode string
VC++ 6.0: Select Tools > Options..., find Debug tab, and check the option "Display Unicode Strings".
VC++ 7.0 automatically displays Unicode strings.
Customizing the debugger's variable value view
You can customize how Visual C++ displays classes in the variable view. By default VC++ displays "{...}" and you need to click the small + icon to expand the members. You can change this behaviour, and make Visual C++ display whatever data member you want in whatever order, formatter however you like instead of just "{...}".
You need to locate a file called "AUTOEXP.DAT" in your Visual C++ installation. By default it will be:
VC++ 6.0:
C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin\AUTOEXP.DAT
VC++ 7.0:
C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Packages\Debugger\AUTOEXP.DAT
The file has information about the format in the beginning, and after a little practice you should be well on your way. Here are some entries that will make your life easier:
;; Mozilla (1.7beta and later) nsAutoString=<mData,su> nsString=<mData,su> nsCString=<mData,s> nsCAutoString=<mData,s> nsRect=x=<x,d> y=<y,d> width=<width,d>; height=<height,d> nsStaticAtomWrapper=<mStaticAtom->mString,s> nsIAtom=<mString,su> ; the following are not necessary in vc8 nsCOMPtr<*>=<mRawPtr,x> nsRefPtr=<mRawPtr,x> nsAutoPtr=<mRawPtr,x>
After you have made the changes and saved the file, you will need to restart Visual C++ for the changes to take effect.
For XPCOM Strings (the "external" string API) you can use the following values:
;; Mozilla (1.9) ; Internal Strings nsAString_internal=<mData,su>, length=<mLength,u> nsACString_internal=<mData,s>, length=<mLength,u> ; XPCOM Strings nsAString=<nsStringContainer.v,su>, length=<nsStringContainer.d1,u> nsACString=<nsCStringContainer.v,s>, length=<nsCStringContainer.d1,u> nsStringContainer=<v,su>, length=<d1,u> nsCStringContainer=<v,s>, length=<d1,u>
There is a more extensive version of this file in progress in AutoExpForVC8.
Avoiding stepping into certain functions
You can avoid stepping into certain functions, such as nsCOMPtr methods, using an undocumented feature of VC. See [1] for details.
Here are some wildcards you can use (tested with VC 8):
nsCOMPtr.*\:\:.*=NoStepInto (nsG|g)etter_*AddRefs.*=NoStepInto NS_ConvertUTF.* ; Might be too broad: (ns|Promise)[^\:]*[sS]tring.* ...add common functions to this list
Obtaining stdout
and other FILE
handles
Running the following command in the Command Window in Visual Studio returns the value of stdout
, which can be used with various debugging methods (such as nsGenericElement::List
) that take a FILE*
param:
Debug.EvaluateStatement {,,msvcr80d}(&__iob_func()[1])
(Alternatively you can evaluate {,,msvcr80d}(&__iob_func()[1])
in the QuickWatch window)
Similarly, you can open a file on the disk using fopen
:
>Debug.EvaluateStatement {,,msvcr80d}fopen("c:\\123", "w") 0x10311dc0 { ..snip.. } >Debug.EvaluateStatement ((nsGenericElement*)0x03f0e710)->List((FILE*)0x10311dc0, 1) <void> >Debug.EvaluateStatement {,,msvcr80d}fclose((FILE*)0x10311dc0) 0x00000000
Note that you may not see the debugging output until you flush or close the file handle.
Disabling ASSERTIONS
There are basically two ways to disable assertions. One requires setting an environment variable, while the other affects only the currently running program instance in memory.
Environment variable
There is an environment variable that can disable breaking for assertions. This is how you would normally set it:
set XPCOM_DEBUG_BREAK=warn
The environment variable takes also other values besides warn
, see XPCOM_DEBUG_BREAK
for more details. Note, that unlike unix, the default for Windows is not warn, it's to pop up a dialog.
Changing running code
You normally shouldn't need to do this (just quit the application, set the environment variable described above, and run it again). And this can be dangerous (like trashing your hard disc and corrupting your system). So unless you feel comfortable with this, don't do it. You have been warned!
It is possible to change the interrupt code in memory (which causes you to break into debugger) to be a NOP (no operation).
You do this by running the program in the debugger until you hit an assertion. You should see some assembly code. One assemly code instruction reads "int 3". Check the memory address for that line. Now open memory view. Type/copy/drag the memory address of "int 3" into the memory view to get it to update on that part of the memory. Change the value of the memory to "90", close the memory view and hit "F5" to continue.
Confused? See the screenshot below:
VC++ 7.0?
Automatically handling ASSERTIONS without a debugger attached
When an assertion happens and there is not a debugger attached, a small helper application (windbgdlg.exe
) is run. That application can automatically select a response to the "Do you want to debug" dialog instead of prompting if you configure it, for more info, see windbgdlg.exe
.
Debugging optimized builds
To effectively debug optimized builds, you should enable debugging information which effectively leaves the debug symbols in optimized code so you can still set breakpoints etc. Because the code is optimized, stepping through the code may occasionally provide small surpises when the debugger jumps over something.
You need to make sure this configure parameter is set:
--enable-debugger-info-modules=yes
You can also choose to include or exclude specific modules. This is particularly useful to avoid linking layout with debugging information.
Running two instances of Mozilla simultaneously
You can run two instances of Mozilla (e.g. debug and optimized) simultaneously by setting the environment variable MOZ_NO_REMOTE
:
set MOZ_NO_REMOTE=1
Or, starting with Firefox 2 and other Gecko 1.8.1-based applications, you can use the -no-remote
command-line switch instead (implemented in bug 325509 ).
You can also specify the profile to use with the -P profile_name
command-line argument.
Debugging JavaScript
Use Venkman, the JavaScript Debugger for Mozilla.
You can use helper functions from nsXPConnect.cpp to inspect and modify the state of JavaScript code from the MSVS debugger.
For example, to print curent JavaScript stack to stdout, evaluate this in QuickWatch window:
{,,xpc3250}DumpJSStack()
Got a tip?
If you think you know a cool Mozilla debugging trick, feel free to discuss it with #developers and then post it here.
Originally by Heikki Toivonen.
출처 : https://developer.mozilla.org/en/Debugging_Mozilla_on_Windows_FAQ