views:

193

answers:

2

I have a page that has a byzantine amount of javascript running. In IE only, and only version 8, I get a long-script warning that I can reliably reproduce. I suspect it is event handlers triggering themselves in an infinite loop.

The Developer Tools are limping horribly under the weight of the script running, but I do seem to be able to get the log to tell me what line of script it was executing when I aborted, but it is inevitably some of the deep plumbing of the ExtJS code we use, and I can't tell where it is in my stack of code.

A way of seeing the call stack would work, but preferably I'd like to be able to just break into the debugger when I get the long script warning so I can just step through the stack.

There is a similar question posted, but the answers given were for a not-the-right-tool, or the not terribly helpful advice to eliminate half my code at a time on a binary hunt for the infinite loop. If my code were simple enough that I could do that, it probably wouldn't have gotten the infinite loop in the first place. If I could reproduce the problem in firebug, I'd probably be a lot happier too.

A: 

I've run in to this before and have had some luck with enableing the developer tools along with VisualStudio. When an error is encountered the page loading is haulted and I could then load up VisualStudio to see the specific line causing the trouble.

This site has some information on using VisualStudio along with the IE debugger: http://www.codeproject.com/KB/scripting/UsingVSToDebugJavascript.aspx

Woody2143
+1  A: 

Here is what I would do:

  1. Go to http://www.microsoft.com/whdc/devtools/debugging/default.mspx and install the Debugging Tools for Windows. You want to run WinDBG when this is installed.

  2. Follow the steps outlined at http://www.microsoft.com/whdc/devtools/debugging/debugstart.mspx#a to setup the symbol server connection and have the symbols automatically downloaded to your local drive (c:\websymbols -- or whatever).

  3. Run IEXPLORE.EXE under WinDBG. The help file should give you assistance in doing this if necessary. You need a couple of commands once you get IE running and such. First, go ahead and get that large script going.

  4. Break into the debugger (CTRL-SCROLLLOCK to break).
    a. Do a LN to "list nearest" to get the dll's that are loaded. Hopefully, you'll have JSCRIPT.DLL loaded in memory.
    b. Type .reload /f to force the reloading of all of the symbols. This will take a while. Now, after this is done, type LN again and you should see that the proper JSCRIPT.PDB has been downloaded to your system in the symbols directory you setup earlier.

  5. Depending on what you want to do, you may need to restart the debugger, but you can do this: After the initial break on WINDBG load, you can type "sxe ld jscript.dll" and it will break when jscript.dll loads.

  6. This is the tricky part, because once this loads, you don't have the code for jscript.dll but you have the proper symbols (if they are not loaded, then reload them with .reload /f). You can view the functions available by typeing "x!jscript" and you'll get a full list of all of the functions and variables.

  7. Pick one, set a break point, and then you should be able to track what is happening to your script.

  8. If nothing else is accomplished, by using the .reload /f process, you can get the appropriate jscript.pdb files loaded on your system. It's possible you could use these in conjunction with Visual Studio to do additional debugging in that manner, but I'm not so sure how well that will work.

Dan7el