Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Windows sidebar gadgets without Visual Studio

I'm trying to create a sidebar gadget without the use of Visual Studio. I've looked around for ways to debug them, but everything says that the Visual Studio JIT debugger is the only way to do it.

Has anyone been able to debug sidebar gadgets without Visual Studio?

like image 937
bshacklett Avatar asked Feb 17 '10 20:02

bshacklett


People also ask

How do I debug a Windows Service without installing?

The original generated Main() is like the one below. To debug without installing, add the code as follow, mainly #if (! DEBUG). You will be able to step through the code when you run the Windows Service without installing.

How do I debug Windows Service on local machine?

In the Options dialog box, choose Debugging, Symbols, select the Microsoft Symbol Servers check box, and then choose the OK button. The Processes dialog box appears. Select the Show processes from all users check box. In the Available Processes section, choose the process for your service, and then choose Attach.

How do I debug a .NET service?

Start the service (you can use net start , or start it in the Services window). You should see a dialog box like the following: Select Yes, debug <service name>. In the Just-In-Time Debugger window, select the version of Visual Studio you want to use for debugging.


1 Answers

For years, I didn't use Visual Studio to work on Gadgets. There are a couple of ways you can debug gadgets without it, just not as extensively. For instance, you can't use the debugger; command without a proper debugger attached to the process. What you can do is use a program like DebugView to catch messages output by the System.Debug.outputString() method:

function test ()
{
    System.Debug.outputString("Hello, I'm a debug message");
}

This allows you to output variable dumps and other useful tidbits of information at certain stages of your code, so you can track it however you like.

As an alternative, you can roll your own debugging/script halting messages using window.prompt(). alert() was disabled for gadgets and confirm() is overridden to always return true, but they must have overlooked prompt().

function test ()
{
     // execute some code

     window.prompt(someVarToOutput, JSON.stringify(someObjectToExamine));

     // execute some more code
}

The JSON.stringify() method really helps out if you want to examine the state of an object during code execution.

Instead of window.prompt, you can also use the VBScript MsgBox() function:

window.execScript( //- Add MsgBox functionality for displaying error messages
      'Function vbsMsgBox (prompt, buttons, title)\r\n'
    + ' vbsMsgBox = MsgBox(prompt, buttons, title)\r\n'
    + 'End Function', "vbscript"
);

vbsMsgBox("Some output message", 16, "Your Gadget Name");

Finally, you can catch all errors with your script using the window.onerror event handler.

function window.onerror (msg, file, line)
{
    // Using MsgBox
    var ErrorMsg = 'An error has occurred'+(line&&file?' in '+file+' on line '+line:'')+'.  The message returned was:\r\n\r\n'+ msg + '\r\n\r\nIf the error persists, please report it.';
    vbsMsgBox(ErrorMsg, 16, "Your Gadget Name");

    // Using System.Debug.outputString
    System.Debug.outputString(line+": "+msg);

    // Using window.prompt
    window.prompt(file+": "+line, msg);        

    // Cancel the default action
    return true;
}

The window.onerror event even lets you output the line number and file (only accurate with IE8) in which the error occurred.

Good luck debugging, and remember not to leave in any window.prompts or MsgBoxes when you publish your gadget!

like image 149
Andy E Avatar answered Oct 17 '22 05:10

Andy E