In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces you how to write ClrMD plug-ins for WinDbg, the content is very detailed, interested friends can refer to, hope to be helpful to you.
When migrating to Linux, because LLDB is the universal debugger for the .NET network core on Linux, I decided to write a compatibility layer so that I could load the extension in the new environment.
What is a ClrMD plug-in
How do I create an extension for WinDbg and LLDB? The first step is still to create a new class library project. Both the .NET Framework and the .NET Standard are fine, but there are a few things to note:
1. If you choose the .NET Framework, make sure you do not use any features that are not compatible with the .NET Core (such as AppDomain), otherwise you will not be able to run the extension in LLDB
two。 If you choose .NET Standard, remember to publish the project to include all dependencies in one folder, as this is not done by default at compile time
After you create the project, add a reference to the ClrMDExports nuget package. It automatically takes ClrMD and UnmanagedExports.Repack as dependencies. UnmanagedExports.Repack is a branch of UnmanagedExports that increases compatibility with .NET Framework 4.7 + and .NET Standard, and supports PackageReference.
Note that the new Init.cs file will be added to your project (if you use a package reference, you should not see it). Do not make any changes to this file. It is overwritten every time the nuget package is updated.
The Init file is responsible for exporting the DebugExtensionInitialize methods required by WinDbg and setting up everything so that as long as the dependencies are in the same folder as the extension, they can be loaded correctly.
The next step is to add custom commands. You need to create a static method for each command and use the following signature:
Public static void HelloWorld (IntPtr client, [MarshalAs (UnmanagedType.LPStr)] string args) {}
Then decorate it with the DllExport attribute that comes with UnmanagedExports. You can use the parameters of the ExportName property to define the name of the command visible to WinDbg / LLDB. Remember, names are case sensitive!
[DllExport ("helloworld")] public static void HelloWorld (IntPtr client, [MarshalAs (UnmanagedType.LPStr)] string args) {}
In this method, you should only call the methods provided by DebuggingContext.Execute by ClrMDExports. It accepts the values of client and args as parameters, as well as a delegate of another static method with (ClrRuntime runtime, string args) signature. In the static callback method, the command is implemented.
[DllExport ("helloworld")] public static void HelloWorld (IntPtr client, [MarshalAs (UnmanagedType.LPStr)] string args) {DebuggingContext.Execute (client, args, HelloWorld);} private static void HelloWorld (ClrRuntime runtime, string args) {Console.WriteLine ("The first 10 types on the heap are:"); foreach (var type in runtime.Heap.EnumerateTypes (). Take (10)) {Console.WriteLine (type);}
For convenience, console output is automatically redirected to the debugger.
You can load and use your extension directly in WinDbg:
Run LLDB on Linux
Because the extension is written for WinDbg API, it cannot be loaded directly into LLDB. Instead, I wrote a plug-in for translation.
First, download the latest version of the LLDB-LoadManaged meta-plug-in and extract it into a folder.
Then start LLDB and attach to the target:
. / lldb-c dump.dmp
Next, load the meta plug-in:
Plugin load. / loadmanaged/libloadmanaged.so
Make sure that the Mono.Cecil.dll and PluginInterop.dll files are in the same folder as libloadmanaged.so.
After loading, LLDB-LoadManaged will try to locate the CoreCLR by browsing the modules loaded in the debug target. If it fails (for example, because you are running lldb on a machine that is different from the target), you can set the path manually by calling the following command SetClrPath:
SetClrPath / usr/local/share/dotnet/shared/Microsoft.NETCore.App/2.2.0/
Finally, load the WinDbg extension using the following LoadManaged command:
LoadManaged / home/k.gosse/TestExtension.dll
(the LoadManaged command does not yet support relative paths)
okay! You can now call the extender as you would in WinDbg.
WinDbg's ClrMD extension runs perfectly in LLDB on Linux
Note: both libloadmanaged.so and libsosplugin.so host CLR according to their own needs. However,. NET Core CLR does not support side-by-side solutions. This means that we cannot use both LoadManaged and SOS plug-ins. This can be said to be a limitation, which is unlikely to be fixed on the .NET Core side. We have a workaround here to load and replace the SOS managed version of libsosplugin.so through LoadManaged.
On how to write ClrMD plug-ins for WinDbg to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.