Home > Software engineering >  How can we script dotnet dump analyze commands?
How can we script dotnet dump analyze commands?

Time:04-12

When debugging windows dumps I often use cdb scripts. Such a script loads the dump, does all the necessary preparations (like setting up the symbols and loading sosex) and then:

  1. Opens a log file
  2. Runs the desired command
  3. Closes the log file

For example:

...
.imgscan /l
.load e:\utils\sosex\64\sosex.dll
!lhi
.logopen "D:\tmp\dumpheap-stat.txt"
!dumpheap -stat
.logclose

Now with the linux dump I would like to follow the same methodology, namely - scripting and dumping results to files. Is it possible?

CodePudding user response:

I'm using this commands to run predefined commands for dotnet-dump analyze and save the output to a text file:

/tools/dotnet-dump collect -p 1 --type Full -o $dumpfile
/tools/dotnet-dump analyze $dumpfile < /tools/dumpcommands > $dumpfile.txt

Put the command you need into the dumpcommands file, one sos command per line. The last one should be exit:

clrstack -all
clrthreads
syncblk
dumpheap -stat
exit

Ignore the absolute paths. I have to run it within a docker container

CodePudding user response:

I have a problem with dotnet dump analyze - for some reason gcroot does not work - it just hangs forever on our 10GB dump.

However, I saw that Tess Ferrandez was using lldb and I gave it a try and it is very good. Here is my worklow:

  1. Install lldb
  2. Install dotnet-symbol
  3. Run dotnet symbol --host-only TheCoreDumpFilePath

The last command downloads the relevant dotnet executable. Next we can debug:

  1. lldb -c TheCoreDumpFilePath dotnet

Now lldb can run commands from file or given on the command line. This gives us ability to script it. Now I understand that dotnet dump analyze can be scripted too as shown in the respective answer.

I hope we can leverage the lldb Python API, though currently I do not see how one can invoke custom commands from it as per my other SO question here - How to run sos extension commands through the lldb python API?

  • Related