Debugging into C# code from other application

核能气质少年 提交于 2019-12-20 04:11:25

问题


I'm loading a dll (c#) from QTP. Is it possible to debug the c# code when the qtp test starts.


回答1:


Yes you can debug into the dll's you can, but you will need source (unless you want to look at the disassembly) and you will also need the PDBs (debug symbols) for the assembly. It is pretty easy to setup...

  1. start the QTP application
  2. start visual studio
  3. open the source code and make sure the pdb's are in the same directory as the dll
  4. in VS go to the debug menu and select attach to process
  5. In the process list, select the QTP process and click "attach"
  6. Set a breakpoint in the code
  7. Start the tests that execute the code and if all is well you should hit the breakpoint

NOTE: if the breakpoint is not hit, VS probably can't find the PDB's and you either need to add a path in options in VS (or something so it can find them).

Also, try turning off "Enable just my code" in the Tools->Options->Debugging options page if it is still not working (mostly if you are looking at release built code).

Update: Answering comment... If you go to Tools->Options... Select "Debugging" on the list on the left and expand that, then select "Symbols" you can add paths there for VS to search for symbols. Also, if you don't have the exact symbols you can right-click the breakpoint and select location and check the option that will allow the symbols to be out of sync.

Hope this helps!




回答2:


You can insert a call to Debugger.Break()and run the external application, when the break point will be reached Windows will offer you to debug the exception.

Choosing debug will enable you to run the code after the break inside Visual Studio and set break points inside your code.

In case you're using Vista/Win7 you might need to enable debugging - have a look at this post to learn how.



来源:https://stackoverflow.com/questions/1543895/debugging-into-c-sharp-code-from-other-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!