microsoft / ConcordExtensibilitySamples

Visual Studio Debug Engine Extensibility Samples
Other
122 stars 50 forks source link

C# implemented IDkmCustomVisualizer broken in worker processes in VS 2019 #47

Closed CsabaStupak closed 5 years ago

CsabaStupak commented 5 years ago

We are using a C++ visualizer which visualized the class content to DataTip using IDkmCustomVisualizer. The extension is written in C# and worked beautiful in VS 2017. Since we switched to VS 2019 it stopped working due to new mechanism introduced in VS 2019 (external process).

I was studying the C++ extension example. Unfortunately I was not able to get it work. Apparently change my vsdconfigxml WorkerProcessSupported="true" is not enough. If I disable the Load debug symbols in external process (native only) option my extension starts to work. However our project is huge and we like the new external process.

Unfortunately without a guidance/example/tutorial I don't know how to update my extension. Could you point me to some project from which I can decipher how to get this work?

Thanks for any help, Csaba

gregg-miskelly commented 5 years ago

Have you seen these --

What happens after you add WorkerProcessSupported="true"? Does everything build successful, but you are seeing problems when running? Or you are running into build problems?

If you are running into problems when running: is your extension loading in the worker process? In case you are not aware: the easiest way to debug this would be to launch devenv.exe under either a native or mixed-mode debugger (ex: Enable 'Unmanaged code debugging' in your launching project's project properties), and use the Microsoft Child Process Debugging Power Tool to automatically debug the msvsmon process for managed-only debugging.

CsabaStupak commented 5 years ago

Thanks for the hints. I will try the Child Process Debugging Power tool. Meanwhile I did some progress :-)

If add WorkerProcessSupported="true" to vsdconfigxml my IDkmCustomVisualizer is loaded to the external process.I was able to find that it is "msvsmon". So I attached VS to this process and indeed my EvaluateVisualizedExpression is called.

However my method is pretty complex and I work here with (PDB) symbols and do additional evaluations. For example I call DkmLanguageExpression.Create and DkmVisualizedExpression.EvaluateExpressionCallback for which I get exception saying that I can't call these methods from external process.

Now it is starting to make sense that I need to communicate with my VS extension process via DkmCustomMessage (from the article). However for me it is crucial to work with active instance of DkmVisualizedExpression (root/children).

How can I transfer it to VS extension process so it will be active? Or how can I call expression evaluations from VS extension process? E.g.

"pGeom!", "pGeom->size()" or "((MyGeomClass*)0x0ffff2342)->size()"

gregg-miskelly commented 5 years ago

Both DkmLanguageExpression.Create and EvaluateExpressionCallback should be callable from within a worker process. Are you creating your own DkmInspectionContext? If so, make sure to call the new overload that has a 'SymbolsConnection' argument.

If that isn't it, can you share more details of where you are seeing the exception? Either copy/paste the arguments you are passing, or save a dump file to drop box/one drive/etc and email me (greggm on the microsoft.com email server) a link to it.

brunov28 commented 5 years ago

Hi,

I have a similar problem with our IDkmCustomVisualizer extension. It is working fine when Load debug symbols in external process is unchecked but when it is checked I get this warning

Warning: IDkmCustomVisualizer::EvaluateVisualizedExpression() failed. The object will be formatted without the custom visualizer.

Our extension dll and vsdconfig is deployed here C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Packages\Debugger.

I have tried to add Debugger.Lauch() call in every entry point of our dll but none gets called. I also tried using Microsoft Child Process Debugging Power Tool without success.

Here is a sample of my vsdconfig.xml

<?xml version="1.0" encoding="utf-8" ?>

Any help would really help as we like to use the new out of process debugging feature.

CsabaStupak commented 5 years ago

Hi Bruno,

I believe your extension is loaded to VS external process - like my is loaded if I adjust the vsdconfig.xml WorkerProcessSupported="true". The key point is here that you should attach your debugger to msvsmon process which is automatically created by VS when you launch your target application. That process contains your loaded extension as well - at least in my case it works fine. You can try Microsoft Child Process Debugging Power Tool (extension to VS) referred above, which does this automatically.

However we are apparently limited what VS API methods can be called in this process. In my case I can't call DkmLanguageExpression.Create nor DkmSuccessEvaluationResult.Create. They throw exception E_XAPI_METHOD_UNAVAIL_IN_WORKER_PROCESS. This is blocker in my case, because when VS asks to visualize the expression I do sometimes raw expression evaluation or some other kind of expression evaluation (e.g. function calls). Without these methods my visualization is impossible - or I was not able to find an alternative.

Hope this helps :-) Csaba

gregg-miskelly commented 5 years ago

Thanks. I was able to track down the problem. There isn't a good work around right now aside from either disabling out-of-process symbols, or implementing your custom visualizer in C++. We will work on getting this addressed in a future update of Visual Studio 2019.

brunov28 commented 5 years ago

Hi Csaba,

My extensions needs to call DkmLanguageExpression.Create and DkmSuccessEvaluationResult.Create. So I have the same problem. Thanks for the heads-up.

Looking forward for a fix in a future update of VS2019.

Bruno

gregg-miskelly commented 5 years ago

I have committed a fix for this. Baring something unexpected, it should ship in VS 2019 version 16.2 preview 3.

gregg-miskelly commented 5 years ago

VS 2019 16.2 preview 3 has now shipped in the Visual Studio Preview Channel. This contains my fix for this issue. If you were running into this problem, please install the preview channel and test out your scenarios.

brunov28 commented 5 years ago

Now that 16.2 has officially shipped I tried to use our custom visualizer with worker process but it did not work. The extension work if I disable the load debug symbols in external process but if it is enable I get this warning.

Natvis: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Packages\Debugger\Visualizers\CustomPlugin.natvis(4,4): Warning: IDkmCustomVisualizer::EvaluateVisualizedExpression() failed. The object will be formatted without the custom visualizer. Error code: 0x8ede0023.

Anyway to debug this or is there any sample that I can look at.

Thanks.

gregg-miskelly commented 5 years ago

@brunov28 lets close this issue and open a new one. The failure you are running into is E_XAPI_COMPONENT_DLL_NOT_FOUND. So please include how you are installing your extension, and how it is implemented. See links above and in the wiki for information on how to install for worker process support, and a sample c++ custom visualizers implemented in C++.

brunov28 commented 5 years ago

Sure created a new issue https://github.com/microsoft/ConcordExtensibilitySamples/issues/48