How can I debug MonoDevelop add-ins with MonoDevelop? - debugging

The topic says it all. I cannot find any information on the monodevelop site or through google.
Even adding System.Diagnostics.Debugger.Break() and running with mono --debug MonoDevelop.exe doesn't seem to do anything..

mono --debug doesn't have anything to do with the debugger, it simply causes Mono to track debug information so it can give you file/line/col information in backtraces.
The behaviour of System.Diagnostics.Debugger.Break() depends on your Mono version. AFAIK in its basic form it sets a hard breakpoint, so if your app's not running in a native hard debugger it will simply crash. If your app is running inside the Mono Soft Debugger with Mono 2.11 or later (which has not yet been released), it will set a soft breakpoint for the soft debugger and work as expected.
The basic way to enable debugging of addins is to set a custom execution command in your addin project. Open 'Project Options', got to the 'Run>Custom Commands' section, add a custom command for 'Execute'. Set the executable to MonoDevelop.exe and the working directory to be its containing directory. This means that when you run/debug your project, MD will actually execute that executable instead of executing your project directly. If MonoDevelop.exe loads your addin, then you'll be able to set breakpoints, step, etc.
The difficult part here is making MD load your addin. One way to do this would be to have your project output the addin dll into one of the directories that MD searches for addins, but that's a very hacky thing to do at development time. A better solution is to use the undocumented environment variable MONODEVELOP_DEV_ADDINS to specify an additional directory from which for MD to load addins. There isn't a UI in MD for setting env vars for custom commands, but it is supported internally - you'll have to manually edit the csproj file.
Find the part that looks like:
<CustomCommands>
<CustomCommands>
<Command type="Execute"
command="..\..\..\monodevelop\main\build\bin\MonoDevelop.exe"
workingdir="..\..\..\monodevelop\main\build\bin" />
</CustomCommands>
</CustomCommands>
And change it to:
<CustomCommands>
<CustomCommands>
<Command type="Execute"
command="..\..\..\monodevelop\main\build\bin\MonoDevelop.exe"
workingdir="..\..\..\monodevelop\main\build\bin">
<EnvironmentVariables>
<Variable name="MONODEVELOP_DEV_ADDINS" value="${TargetDir}" />
</EnvironmentVariables>
</Command>
</CustomCommands>
</CustomCommands>
If you're wondering why the <CustomCommands> elements are two-deep, that a known bug.

the soft debugger doesn't yet support System.Diagnostics.Debugger.Break(), so that won't work.
You just need to debug MonoDevelop inside MonoDevelop and set your breakpoints on the source files of your addin.

Related

visual studio code "launch json" on run, how to set debug console as default

I went to user settings to set the debug console to default (when I try to debug now the default console is terminal. I lose the small debug icons to skip, stop etc even when I manually select debug console). I am watching Python tutorials using Vs Code and his default is debug. How can I do this?
Secondly, when I try to run or debug, I am prompted to open LaunchJS, even if it is already open. I attempted to run it using the debug selection "current file, integrated terminal" and also "Python: Attach". Neither will work although the JSON file has these options. I looked at some MS videos but I am not understanding the problem.
Any help is appreciated. Thanks.
I found the answer at this link: https://code.visualstudio.com/docs/python/python-tutorial
I had not selectd a Python interpreter which establishes a python workspace. Was just trying to run with debugger. A simple program now runs. My guess is that the Python tutorial I selected is too old to follow with this version of VS Code, since I am unfamiliar with any version of VS Code.
Thanks.

Is it possible to "blackbox" or skip other extensions when debugging vscode extensions?

I have an issue where my development environment has a few large extensions in it, and debugging my own extension using the "All exceptions" and/or "Promise rejects" breakpoints will hit on them quite frequently.
I am aware of the skipFiles option in the launch configuration, and that you can use a custom "Data" folder when launching code with the --user-data-dir option, but neither of these solutions seem to work for me. I can't figure out how to find generically define the extensions folder with skipFiles, and --user-data-dir doesn't seem to work as I'd expected and doesn't seem to be for my purpose.
To put it plainly, my ideal situation would be to use the debug shortcut F5 and for a completely sterile version of vscode to launch with only my extension loaded and settings which aren't inherited from my development environment.
In the following image of a breakpoint being hit, you can see that the first party extension "git" in the path "/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/src/git.ts" is still being tracked. The command line switch --disable-extensions does not exclude this either.
You can disable all other extensions when debugging your own extension via the --disable-extensions flag. Just pass it via the args attribute in your launch.json:
"args": [
"--disable-extensions"
]

Debug.Print stopped working in Visual Studio 2015

How can I ensure reliable use of Debug.Print ?
I know there have been many solutions posted for this, but none of them work. This command just keeps on being broken, sometimes it may work for a while, but generally -- it fails (see the number of SO questions regarding this). The solutions seem to vary, and yet it keeps happening - so here it is again where none of the solutions below are fixing the problem (save for installing on a fresh computer which only works for around 10 projects then fails again)
What I have tried
1. Creating a new application from scratch
2. Using the alternative to Debug.Print
System.Diagnostics.Debug.Listeners[0].WriteLine
3 Checking my app.config which shows
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
4. Checking my settings to see if DEBUG and TRACE are enabled (they are)
5. Checking that the Immediate window is on the correct tab with [Debug] selected in the drop-down (it is)
6. Ensure that I start the application in Debug mode (it is)
7. Removing all extensions / plugins.
8. Installing on a fresh computer. (works for a short period, then fails indefinitely again)
I have no AntiVirus or "potentially" conflicting software on my boxes where I test if this issue is consistent in bare windows, or if there may be another application causing it.
Are there certain cases (in the code itself like async/await etc) which consistently cause no output for Debug.Print ?
I finally found the problem. The Output window doesn't contain this output even when Debug is selected, and my Immediate window disappeared.
How to get the Immediate window back
Click the menu on the top Debug -> Windows -> Immediate or press [CTRL]+[G]
The result showing it works
Caveat: Just because you have the immediate window shown while coding, doesn't mean it will be there when you enter Start Debugging [F5] mode, or vice-versa. It may also disappear and not be there when you restart Visual Studio or start a new application. Just follow the directions above to make it reappear, and mind the other note below.
Note : After doing this, the window appeared as a floating window which I had to dock again. After docking, I tried to clear it using right-click and instead of a context menu, Visual Studio committed suicide, and then restarted - back to the project list screen (it didn't reload my project).
This didn't work for me, what finally got it working again was Project Properties> Build Check Define DEBUG Constant
One easily overlooked possibility is that the project hasn't configured any trace listeners.
Either configure one in the config file or add:
Debug.Listeners.Add(New DefaultTraceListener)
in your code.
This will cause debug output to be written to either the output window or the immediate window depending on your Debugging settings ("Redirect all output text to the immediate window").

Debugging UDK using nFringe in Visual Studio 2005

This is a pretty niche question, so I am not expecting a huge response...
Basically, I am learning how to use the UDK by following some tutorials, namely this one:
http://forums.epicgames.com/showthread.php?p=27043379#post27043379
So far everything is going pretty well. The only real hangup I've had is getting everything to work in Visual Studio 2005 using this nFringe plugin. For a long time, couldn't get them to work at all. I've gotten into two or three chapters of the tutorial, and I've managed to use Visual Studio to edit the code, but I can't build the scripts within VS; I have to go to UDK Frontend to do that. And worse still, I can only really use Log commands in the unrealscripts to debug anything.
So my question is this: is it even possible to configure these tools in a way that I can put breakpoints in VS and have them be caught when I test the game? I feel as though I don't have something setup correctly.
Yes it is possible. Here are some info which might be useful to you.
First, both your .sln and your .ucproj files must be located in Development/src. Then, under visual studio, right-click your project (.ucproj file in the solution explorer) and open its properties.
You must set, under the General tab:
Target Game: UnrealEngine 3 Mod
UCC Path: ....\Binaries\Win32\UDK.exe
Reference Source Path: ..\Src
Under the Build tab:
check "Build debug scripts"
Under the Debug tab:
Start Game Executable: ....\Binaries\Win32\UDK.exe
Load map at startup: the name of your startup map, without path nor extension
Start with the specified game type: put your GameInfo class used for your mod, ie. MyMod.MyGameInfo
Disable startup movies can be checked to gain time at launch
Enable unpublished mods must be checked.
In your command line, the parameter -vadebug specifies that the breakpoints will be enabled.
After that, you must be able to build your script from Visual, and launch your game by pressing F5.
Breakpoints should work but you can't put them on a variable declaration, you have to put them on a function call, an assignment or a condition statement.
Hope this will help.
I havnt tried using breakpoints yet but I know its possable to build with nfringe and visual studio . You need to add a line to the
udk game / config / udk engine .ini
search for
editpackages
exactly like that , then youll see a block like this
EditPackagesInPath=....\Development\Src
EditPackages=Core
EditPackages=Engine
EditPackages=GFxUI
EditPackages=GameFramework
EditPackages=UnrealEd
EditPackages=GFxUIEditor
EditPackages=IpDrv
EditPackages=OnlineSubsystemPC
EditPackages=OnlineSubsystemGameSpy
EditPackages=OnlineSubsystemLive
EditPackages=OnlineSubsystemSteamworks
then add your own line pointing to a folder named what ever you want but make sure it has a folder in it named Classes and it has the uc files you wnat to compile in it
ModEditPackages=MyTestProject
if you used that line then you are tellign udk you have a folder named
MyTestProject
located in your development/src folder and you want it to compile everything in there

Attaching MonoDevelop debugger to NUnit test run on OS X

Question as per the title really.
I'm looking for a way to step through running unit tests using MonoDevelop on OS X in the same way you can with Visual Studio (by attaching the debugger manually to the nunit process).
If this is possible on MonoDevelop (on OS X) then it's not obvious how. Would appreciate any pointers.
Build your code as normal, then copy the exes, dlls and mdb files to your other computer.
On your debugger host set the following environment variable and run monodevelop:
$ export MONODEVELOP_SDB_TEST=1
$ monodevelop
(you might need to edit the actual script that monodevelop is launched with and add the first line)
Fire up monodevelop, load your solution, set a break point and then click Run > Debug With > Custom Mono Soft Debugger.
Once the dialog appears, replace 127.0.0.1 with the IP of your debugger. Then click "Listen"
Then, on the other host run :
$ mono --debug \
--debugger-agent=transport=dt_socket,address=IP:PORT \
nunit.console.exe yourtest.dll
Replace IP and PORT with the values given on the debugger.
So you are wanting to run NUnit and then attach to the running process?
I think the only way to debug NUnit tests are from within a MonoDevelop NUnit project. From there you can hit the Debug menu item, and it will start NUnit for you and handle your breakpoints, etc.
Note that you will have difficulty getting it to work with MonoTouch, see here.

Resources