none
execute windows service & Attach process at same time

    Question

  • Hi,

    Usually when I attach a process to the VS Debugger I have to start the windows service first then through services in the administrative tools of windows then go to VS and Tools->Attach process to attach the running windows service.  The problem is I have a bug in my windows services that comes up very fast and I can't attach it in time, is there a way to start the windows service and attach the process at the same time? 

    And on another question, what if I am running the windows service on a vm and attaching it through a remote debugger ( I can do it on my local machine if needed, but I was just wondering if anyone has a solution for remote debugging ) ?
    Thursday, June 21, 2007 7:31 PM

Answers

  •  

    Hello,

     

    If I understand your problem correctly there are a couple things you could try.

     

    1, If your service is managed code add a System.Diagnostics.Debugger.Break() before the code you are trying to debug. This will automatically invoke the debugger.

    2, Another option for any type of code is to insert a divide by 0 error at your desired location. This will force a crash and the JIT (Just In Time) dialog to appear, you will then be able to attach the debugger.

    3, A final option would be to introduce a sleep to the service when it starts up. This pause should allow you enough time to manually attach the debugger.

     

    All of the above solutions would work in the remote scenario.

     

    There isnt a way to get the debugger to automatically attach to your service when it starts.

     

    Hope these suggestions help.

     

    Richard Cook

    VS Debugger Team

    Thursday, June 21, 2007 9:08 PM
  • Hi,

     

    System.Diagnostics.Debugger.Break()  is for managed code such as VB, C#, MCPP or J#.

     

    Yes _asm int 3 will have the same affect in CPP code.

     

    Thanks

     

    Richard Cook

    VS Debugger Team

    Friday, June 22, 2007 10:09 PM

All replies

  •  

    Hello,

     

    If I understand your problem correctly there are a couple things you could try.

     

    1, If your service is managed code add a System.Diagnostics.Debugger.Break() before the code you are trying to debug. This will automatically invoke the debugger.

    2, Another option for any type of code is to insert a divide by 0 error at your desired location. This will force a crash and the JIT (Just In Time) dialog to appear, you will then be able to attach the debugger.

    3, A final option would be to introduce a sleep to the service when it starts up. This pause should allow you enough time to manually attach the debugger.

     

    All of the above solutions would work in the remote scenario.

     

    There isnt a way to get the debugger to automatically attach to your service when it starts.

     

    Hope these suggestions help.

     

    Richard Cook

    VS Debugger Team

    Thursday, June 21, 2007 9:08 PM
  • Hi,

    How do you  use System.Diagnostics.Debugger.Break() ?  I keep getting an error saying System isn't declared.   Is there something I need to add an include file or such? 

    Does _asm int 3; trigger the debugger to come out?
    Friday, June 22, 2007 7:57 PM
  • Hi,

     

    System.Diagnostics.Debugger.Break()  is for managed code such as VB, C#, MCPP or J#.

     

    Yes _asm int 3 will have the same affect in CPP code.

     

    Thanks

     

    Richard Cook

    VS Debugger Team

    Friday, June 22, 2007 10:09 PM
  • Does _asm int 3; still work if I put it inside a catch statement?

    like:

    try {}

    catch (...)
    {
    _asm int 3;
    }

    will it still trigger the Just In Time Debugger for VC++?  I'm just having trouble triggering my debug point, I keep getting messages like, "There is no source code available for the current location."  But I can't figure out if it's _asm int 3; failing or it's not even rearching upto that point.
    Monday, June 25, 2007 3:49 PM
  • Nevermind I found out what my problem was, I was just being careless.  The _asm int 3; statement works inside catch statements as well.  Sorry and thanks!
    Tuesday, June 26, 2007 1:48 PM