Debug ASP.NET Core via lldb on Ubuntu


I have been using Windbg and SOS for several years and they are really good tools to perform .Net deep debugging. With the newly released cross platform .NET Core, is there a similar way to make the same? Surely Windbg and SOS don't apply to this scenario. Fortunately, the .NET Core team has been porting the SOS functionality to Linux in the form of an extension to the LLDB debugger on Linux and this makes it possible for us to do the same in-depth debugging on .NET Core.

The LLDB debugger is similar to the native Windows debugging tools for low level command driven debugger. Part of the reason that LLDB is chosen to support .NET Core is its extensibility to create the SOS plugin. The SOS LLDB plugin contains the same commands that we have been accustomed to in the Windows world. In this post, I will demo the steps to configure the environment for LLDB SOS debugging (Ubuntu 16.04).

Install .Net Core

Follow https://www.microsoft.com/net/core#linuxubuntu, execute the below to install .Net Core

sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893
sudo apt-get update
sudo apt-get install dotnet-dev-1.0.1

Execute the below to create an empty project and run it. The application can be accessed successfully via localhost:5000.

mkdir coredemo
dotnet new web
dotnet restore
dotnet run

1

Install LLDB

Execute "sudo apt-get install lldb-3.6" to install lldb. In order to attach to the target process, we can execute "ps -ejH" to dump out the process tree shown below. Look for the child dotnet process whose process id is 10675, it is our target program (the parent dotnet process forks the child dotnet process to run the actual application).

2

Execute below to launch lldb and attach to the target process. Notice that "bt" works well to print current thread's call stack, while we can't debug the managed code yet.

sudo lldb-3.6
process attach -p 10675

3

Load SOS and Debug

Execute the below to load SOS extension and also make sure the correct libmscordaccore.so can be located.

plugin load /usr/share/dotnet/shared/Microsoft.NETCore.App/1.1.1/libsosplugin.so
setclrpath /usr/share/dotnet/shared/Microsoft.NETCore.App/1.1.1

4

Now, we can use command sos to get the available extension commands, they are almost the same to the windows peer.

5

And you can use your favorite command to perform further debugging now.

6

Comments (1)

  1. Vince Panuccio says:

    Great post, I wish there was more information regarding low level debugging like this. Good to see NixDbg making its way across to Linux. I was actually wondering how to debug Linux memory dumps with using WinDbg. More posts like this please 🙂

Skip to main content