Jump to content

KSP Plugin debugging and profiling for Visual Studio and Monodevelop on all OS


Recommended Posts

  • 1 month later...

Thanks alot for the KspDevModPatcher.

The following changes are required for 1.0.4 :

- Patching MapView is no longer needed (has no .cctor anymore)

- Patching PhysicsGlobals changed to "\u0013\u0002" (was "\u000A\u0002")

Link to comment
Share on other sites

  • 2 weeks later...
What version of Unity does KSP 1.0.4 use? Also, at this point, do we still need to use the angrilov mono lib?

Initialize engine version: 4.6.4f1

It's always the first line in the output_log file.

Link to comment
Share on other sites

Could someone upload the 1.0.4 compatible patcher tool? I'm having trouble building it myself. It keeps throwing exceptions when running the patches on HighLogic...

You can grab a copy from my GitHub repo at https://github.com/seanmcdougall/KspDevModePatcher/releases/download/v1.0.4/KspDevModePatcher.zip

It contains rhjoerg's changes, and I've used it successfully with 1.0.4.

Link to comment
Share on other sites

  • 1 month later...

I'm a bit new to this and I followed the instruction step by step (including the 1.0 patcher tool) but when I go to create my mdb it fails. Can anyone help me out with this?


C:\Kerbal Space Program Dev\GameData>"C:\Program Files (x86)\Unity\Editor\Data\MonoBleedingEdge\bin\cli.bat" "C:\Program Files (x86)\Unity\Editor\Data\MonoBleedingEdge\lib\mono\4.0\pdb2mdb.exe" Categories.dll
Fatal error:
Microsoft.Cci.Pdb.PdbDebugException: Unknown custom metadata item kind: 6
at Microsoft.Cci.Pdb.PdbFunction.ReadCustomMetadata (Microsoft.Cci.Pdb.BitAccess bits) [0x00000] in <filename unknown>:0
at Microsoft.Cci.Pdb.PdbFunction..ctor (System.String module, ManProcSym proc, Microsoft.Cci.Pdb.BitAccess bits) [0x00000] in <filename unknown>:0
at Microsoft.Cci.Pdb.PdbFunction.LoadManagedFunctions (System.String module, Microsoft.Cci.Pdb.BitAccess bits, UInt32 limit, Boolean readStrings) [0x00000] in <filename unknown>:0
at Microsoft.Cci.Pdb.PdbFile.LoadFuncsFromDbiModule (Microsoft.Cci.Pdb.BitAccess bits, Microsoft.Cci.Pdb.DbiModuleInfo info, Microsoft.Cci.Pdb.IntHashTable names, System.Collections.ArrayList funcList, Boolean readStrings, Microsoft.Cci.Pdb.MsfDirectory dir, System.Collections.Generic.Dictionary`2 nameIndex, Microsoft.Cci.Pdb.PdbReader reader) [0x00000] in <filename unknown>:0
at Microsoft.Cci.Pdb.PdbFile.LoadFunctions (System.IO.Stream read, Microsoft.Cci.Pdb.BitAccess bits, Boolean readAllStrings) [0x00000] in <filename unknown>:0
at Microsoft.Cci.Pdb.PdbFile.LoadFunctions (System.IO.Stream read, Boolean readAllStrings) [0x00000] in <filename unknown>:0
at Pdb2Mdb.Driver.Convert (Mono.Cecil.AssemblyDefinition assembly, System.IO.Stream pdb, Mono.CompilerServices.SymbolWriter.MonoSymbolWriter mdb) [0x00000] in <filename unknown>:0

Edited by Alshain
Link to comment
Share on other sites

I'm a bit new to this and I followed the instruction step by step (including the 1.0 patcher tool) but when I go to create my mdb it fails. Can anyone help me out with this?


C:\Kerbal Space Program Dev\GameData>"C:\Program Files (x86)\Unity\Editor\Data\MonoBleedingEdge\bin\cli.bat" "C:\Program Files (x86)\Unity\Editor\Data\MonoBleedingEdge\lib\mono\4.0\pdb2mdb.exe" Categories.dll
Fatal error:
Microsoft.Cci.Pdb.PdbDebugException: Unknown custom metadata item kind: 6
at Microsoft.Cci.Pdb.PdbFunction.ReadCustomMetadata (Microsoft.Cci.Pdb.BitAccess bits) [0x00000] in <filename unknown>:0
at Microsoft.Cci.Pdb.PdbFunction..ctor (System.String module, ManProcSym proc, Microsoft.Cci.Pdb.BitAccess bits) [0x00000] in <filename unknown>:0
at Microsoft.Cci.Pdb.PdbFunction.LoadManagedFunctions (System.String module, Microsoft.Cci.Pdb.BitAccess bits, UInt32 limit, Boolean readStrings) [0x00000] in <filename unknown>:0
at Microsoft.Cci.Pdb.PdbFile.LoadFuncsFromDbiModule (Microsoft.Cci.Pdb.BitAccess bits, Microsoft.Cci.Pdb.DbiModuleInfo info, Microsoft.Cci.Pdb.IntHashTable names, System.Collections.ArrayList funcList, Boolean readStrings, Microsoft.Cci.Pdb.MsfDirectory dir, System.Collections.Generic.Dictionary`2 nameIndex, Microsoft.Cci.Pdb.PdbReader reader) [0x00000] in <filename unknown>:0
at Microsoft.Cci.Pdb.PdbFile.LoadFunctions (System.IO.Stream read, Microsoft.Cci.Pdb.BitAccess bits, Boolean readAllStrings) [0x00000] in <filename unknown>:0
at Microsoft.Cci.Pdb.PdbFile.LoadFunctions (System.IO.Stream read, Boolean readAllStrings) [0x00000] in <filename unknown>:0
at Pdb2Mdb.Driver.Convert (Mono.Cecil.AssemblyDefinition assembly, System.IO.Stream pdb, Mono.CompilerServices.SymbolWriter.MonoSymbolWriter mdb) [0x00000] in <filename unknown>:0

Are you using Visual Studio 2015 by any chance? There seems to be an incompatibility between VS 2015 and pdb2mdb.exe. I'm using VS 2013 Community Edition and it works great, so it looks like you might have to downgrade.

Link to comment
Share on other sites

Are you using Visual Studio 2015 by any chance? There seems to be an incompatibility between VS 2015 and pdb2mdb.exe. I'm using VS 2013 Community Edition and it works great, so it looks like you might have to downgrade.

Yes, I am using 2015. That is unfortunate, I really don't want to downgrade for other reasons outside of KSP. I may just have to wait, presumably an updated converter is in the Unity 5 package.

Edited by Alshain
Link to comment
Share on other sites

  • 3 weeks later...

Just want to say thanks to everyone here. I was able to grab the Advanced Fly-By-Wire mod's source code and get it to run with VS2015 debug capabilities using the tips in this thread and belpyro's other reply here.

One small deviation - instead of using pdb2mdb.bat my build events look something like this:

...

"C:\Program Files (x86)\mono\bin\mono.exe" "C:\Program Files (x86)\mono\lib\mono\4.5\pdb2mdb.exe" ksp-advanced-flybywire.dll

xcopy /Y ksp-advanced-flybywire.pdb "C:\Program Files (x86)\Games\Kerbal Space Program\GameData\ksp-advanced-flybywire\"

xcopy /Y ksp-advanced-flybywire.dll.mdb "C:\Program Files (x86)\Games\Kerbal Space Program\GameData\ksp-advanced-flybywire\"

When I referenced the bat file, I think it wasn't waiting for the command to complete before moving onto the next one (or something like that - no time to investigate - did try using start /wait).

Now a question: I don't suppose anyone's figured out a way to achieve Edit-And-Continue capabilities?

I know that feature is precluded when you attach to processes. I don't know much about Unity, but came across this link talking about some kind of ability to serialize game-state, recompile, then deserialize, to effectively achieve on-the-fly code updates:

http://answers.unity3d.com/questions/532242/editing-code-in-debug-mode.html

Wondering if there's any hope here, e.g. some wild ideas...

- load a DLL that's hosted in Visual Studio devenv

- dynamically load a new version of a DLL into the game without restarting it

- write a clever DLL that can then dynamically load/unload a child one (or delegate the bulk of the code to some kind of embedded scripting language)

Edited by Fwiffo
Link to comment
Share on other sites

it does reload the dlls but since you can't write over them while they are open...

Harvester said KSP 1.1 will use shadow copy so we may be able to hot load/reload mods dll. We will have to wait before we see how/if we can use it for that.

Link to comment
Share on other sites

  • 2 weeks later...
it does reload the dlls but since you can't write over them while they are open...

Harvester said KSP 1.1 will use shadow copy so we may be able to hot load/reload mods dll. We will have to wait before we see how/if we can use it for that.

Cool! I realize this isn't a high priority for the developers but it sure would be convenient. In the meantime I was pondering writing a "shim" DLL that delegates the heavy lifting out to some other module (e.g. DLL loaded in a separate AppDomain so we can tear it down and load in a new version, scripting language with the shim using Reflection to ferry SDK calls between the module and the API, etc). But it's all kind of pie in the sky at the moment.

(ps. On another note - I'm a bit wary of Shadow Copy ever since having all kinds of VSS issues on servers with various backup software we use. In the early days it just seemed to get corrupted a lot and required a bunch of manual intervention to sort out and get working again. Hope they've fixed the problems. I do believe .NET can load / unload assemblies dynamically though and release the file locks without requiring VSS)

Link to comment
Share on other sites

In the meantime I was pondering writing a "shim" DLL that delegates the heavy lifting out to some other module (e.g. DLL loaded in a separate AppDomain so we can tear it down and load in a new version, scripting language with the shim using Reflection to ferry SDK calls between the module and the API, etc).

I was working on something along these lines when I had my eureka moment that lead to the birth of AssemblyReloader. Have a look at the WIP thread if you're interested, I'd love any feedback

Link to comment
Share on other sites

Does anyone know how to get Xamarin on OSX to connect to unity runtime to debug?

I have got all this working under a Windows 7 VM and I have successfully got the DEV mode KSP to work, but I can't get Xamarin to connect to it (there doesn't seem to be a way?). I found tools for Xamarin to do this that work with Unity 5, but has anyone got this working under OSX to connect Xamarin to the runtime unity for current version (4.6.4)?

Link to comment
Share on other sites

  • 1 month later...

Everything works for me, except the Debugging itself. I don't get any errors creating the mdb file or something like this, and attaching the unity debugger also works fine. But it simply does not debug. It doesn't care about breaking points, or doesnt even show function calls, or values of variables. Do I miss something obvius here? what I have done so far:

I followed you instructions on installing (I guess nothing has gone wrong here, since I would have problems earlier)

1. Set breaking points in my mod.cs file

2. Build the Project, and get a dll and pdb file

3. Build the dll.mdb file using this line in a bat file: "D:\Programme\Unity4_6_4f1\Editor\Data\MonoBleedingEdge\bin\cli.bat" "D:\Programme\Unity4_6_4f1\Editor\Data\MonoBleedingEdge\lib\mono\4.0\pdb2mdb.exe" mod.dll

4. Copy dll ptb and mdb files into GameData/Mod/Plugins

5. start the game

6 attach debugger

KSP runs normal, the mod functionality works normal, I just can't debug stuff. Do I set the Breakpoints right? I can bring the whole game to a halt btw, but that isnt very usefull :D

Link to comment
Share on other sites

You will have to provide more info. VS version, unity VS version and a log. I m not sure I have time to look into it much today but I ll do soon.

You do attach with the "Attach Unity debugger" option right ?

Edit : if you use VS 2015 make sure to install Mono 4 somewhere and read this post to change how the mdb is generated

Edited by sarbian
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...