Giter VIP home page Giter VIP logo

smartdump's Introduction

Introduction:

SmartDump is a flexible command line utility to capture exception logs and memory dump files against a target process based on user specified settings like filter strings or memory addresses of breakpoints. This tool also focuses on addressing several scenarios that we cannot utilize some well-known and most widely used debugging tools, for example:

1. iDNA Trace(TTT/TTD) cannot be used within Kudu console or RDP for Azure Web Sites related debugging scenarios.
2. Debug Diagnostic Tool(DebugDiag) cannot be installed and used for Kudu console or RDP as well.
3. Procdump works with Kudu but may not successfully capture managed exceptions against web hosts with .Net Core runtime.
4. For intermittent issues, capturing iDNA Trace(TTT/TTD) may not be an appropriate approach even with selective recording. 

Currently SmartDump is still under development. New features are continuously being added. Bug reports, suggestions and feedback from you will be very much appreciated.

New feature:

New feature in release 1.13.

Support new argument: -exit Dettach and exit a SmartDump instance with pid specified with -p . This is useful in situations that Ctrl-C or Ctrl-Break doesn't work. Another way is to create a config.ini file in the same path of SmartDump.exe. Create a [Runtime] section and set Exit = 1, i.e:

  [Runtime]
  Exit=1

(This works well in more specific cases like Kudu console.)

Support of .Net 6 has been added in release 1.12.

Now -v option can real-time display manage callstack when a .net exception is thrown. Moreover using function name as filter to capture memory dump is supported.

(NOTE: this feature is only available on 32bit version currently and hasn't been added into 64bit version.

SD09

How to Use:

Below is a detailed step-to-step demo.

  1. First of all, we need to open Kudu console and drag/upload the tool into the site folder.

SD01

  1. Next, we need to find the PID of our site’s w3wp.exe from Process Explorer.

    NOTE: the one with (scm) is for Kudu console. Hence we always have to focus on w3wp.exe without (scm).

SD02

  1. Then we can run SmartDump.exe and use -p option to specify the PID found in step #2.

    This makes SmartDump attach to the target process and start to monitor any exception thrown in it. By default, the tool captures 5 exceptions.

SD03

After submitting requests to generate some exceptions, SmartDump will be able to capture them within the console.

SD04

  1. If you want to see more exceptions, just use -n option to specify number of exceptions to be captured.

    NOTE: using -n 0 to start an unlimited/endless capture. However please be careful to use this in Kudu because it doesn’t support Ctrl+C to exit a process. Run inside a common cmd.exe without such issue.

    Tips: you can also add: > filename.log at the end of a command to make Kudu write output into a log file for you.

SD05

  1. To generate dump, use -d option to set number of dumps to be captured. Associating it with -f(filter include) allows you to capture dumps against specific exceptions. Also, use -fv (filter exclude) options to filter/exclude any unnecessary exceptions from output.

    • -f Filter exception based on specified string(s). Use '|' as delimiter for multiple strings.
    • -fv Exclude exceptions contain specified filter. Use '|' as delimiter for multiple strings.

SD06

  1. The tool also supports to set memory address of breakpoint to generate dump files.

    You can capture a dump first and then open it in debugger to find the code entry address of a function you interest in(or code address of any line). Then use -a option of SmartDump to set the address as breakpoint for capture:

SD07 SD08

Usage:

SmartDump x86/x64 - exception and memory dump capture utility

Options:

-p     PID of target process.

-n     Number of exceptions to be captured. Default is 5. Set to 0 means unlimited.

-d     Collect number of dumps.

-de    Collect number of dumps in 'Dump for each' mode. Dumps will be captured for each of different exception types.

-f     Filter(include) exception based on specified string(s). Use '|' as delimiter for multiple strings.

-fv    Exclude exceptions contain specified filter. Use '|' as delimiter for multiple strings.

-s     Skip the first number of exceptions for dump capture. 

-ma    Capture a manual dump.

-mn    Option to captue a mini dump. Default setting is to capture full memory dumps.

-v     Enable verbose output to list managed callstacks and function entry addresses that can be utilized to set breakpoints with -a option.

-a     Dump with address of breakpoint.

-o     Output path of dump(s).

-exit  Dettach and exit a SmartDump instance with pid specified with -p .

-h     Or -?/-help. Display usage and examples.

Examples:

    - Write a manual dump against process with id 4567:
            SmartDump.exe -ma -p 4567

    - Monitor and print 10 managed exceptions against process with id 4567:
            SmartDump.exe -p 4567 -n 10

    - Capture two dumps based on filtered strings of managed exceptions:
            SmartDump.exe -p 4567 -f "Object reference not set|ArgumentException" -n 10 -d 2

    - Exclude exceptions contain specified filter string from output:
            SmartDump.exe -p 4567 -n 10 -fv "InvalidOperationException|FileNotFoundException"
            
    - Skip the first 3 NullReferenceException. Capture a memory dump for the 4th one and specify output path to: c:\home\dump.
            SmartDump.exe -p 4567 -n 10 -f "NullReferenceException" -s 3 -d 1 -o c:\home\dump
            
    - Capture 3 mini dumps for each of the exception types: NullReferenceException, SocketException and ArgumentException
            SmartDump.exe -p 4567 -n 10 -de 3 -mn -f "NullReferenceException|SocketException|ArgumentException"                

    - Display verbose output to list managed callstacks. 
        After that, we can use function name as filter to capture dumps or utilize function entry address to set breakpoint with -a option to dump an interested call.
            SmartDump.exe -p 4567 -n 20 -v

    - Capture a dump based on specified address of breakpoint:
            SmartDump.exe -d 1 -p 4567 -a 7a64e9d0 -n 1

The following are several sample commands that uses the tool with Kudu debug console.

  1. Show options and examples

image

  1. Monitor and display exceptions

image

  1. Capture a manual dump

image

  1. Capture two exception dumps based on filter string.

image

  1. Exclude/filter uninterested exceptions based on specified strings delimited with '|'

image

  1. Collect dump based on specified address of breakpoint.

image

  1. Skip the first 3 SqlException. Capture two memory dumps for the 4th and 5th ones and specify output path to: c:\home\dump.

image

  1. Use -de 'Dump for each' option to capture 3 mini dump files for 3 specified exception types: InvalidOperationException, SqlException and ServiceOperationsProviderException.

image

  1. Use SmartDump to write a log of exceptions for your site.

image image

  1. Capture against process of onpromise environment

image

  1. Verbose(-v) option can real-time display manage callstack when a .net exception is thrown. Moreover using function name as filter to capture memory dump is supported in this build. (NOTE: this feature is only available on 32bit version currently and hasn't been added into 64bit version.

            SmartDump.exe -p 4567 -n 20 -v
    

SD09

Also a function entry address of a function can be used to dump its corresponding interested call. The frame output indicates the entry code address of the first managed call that threw the exception is 0x00007ffd`551f0eb0.

image

So we use address: 00007ffd`551f0eb0 as breakpoint to capture dump with -a option:

image

As we can see, 00007ffd`551f0eb0 is just the entry address of function: System.Data.SqlClient.SqlConnection.OnError

image

Project

This repo has been populated by an initial template to help get you started. Please make sure to update the content to build a great experience for community-building.

As the maintainer of this project, please make a few updates:

  • Improving this README.MD file to provide a great experience
  • Updating SUPPORT.MD with content about this project's support experience
  • Understanding the security reporting process in SECURITY.MD
  • Remove this section from the README

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

smartdump's People

Contributors

microsoftopensource avatar wjzhangmsft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

smartdump's Issues

Bug reports

In case you find any problem on using SmartDump, please describe details here.

Release history

SmartDump v1.12

New feature:

Support of capture .Net 6 dump and exceptions has been added.

SmartDump v1.10

New feature:

Now -v option can real-time display manage callstack when a .net exception is thrown. Moreover using function name as filter to capture memory dump is supported.

(NOTE: this feature is only available on 32bit version currently and hasn't been added into 64bit version.

SD09

SmartDump v1.09

New feature:

This build is pretty much a big milestone: now -v option can real-time display manage callstack when a .net exception is thrown. Moreover using function name as filter to capture memory dump is supported in this build.

(NOTE: this feature is only available on 32bit version currently and hasn't been added into 64bit version.

SD09

SmartDump v1.08

New feature:

Added -v option to display verbose output to list frames of managed callstack. Then we can utilize addresses from its output to set breakpoint with -a option. For example, a code entry address of a function can be used to dump its corresponding interested call:

            SmartDump.exe -p 4567 -n 20 -v

The frame output indicates the entry code address of the first managed call that threw the exception is 0x00007ffd`551f0eb0.

image

So we use address: 00007ffd`551f0eb0 as breakpoint to capture dump with -a option:

image

As we can see, 00007ffd`551f0eb0 is just the entry address of function: System.Data.SqlClient.SqlConnection.OnError

image

SmartDump v1.07

New feature:

  • Add exception information and associate it with thread context on capturing exception dump files, e.g:

image

SmartDump v1.06

New feature:

Added -mn option to support capture mini dumps. For example, the following command captures 3 mini dump files for each of the 3 specified exception types: InvalidOperationException, SqlException and ServiceOperationsProviderException .

    SmartDump.exe -p 3328 -n 40 -de 3 -mn -f "InvalidOperationException|SqlException|ServiceOperationsProviderException"

image

SmartDump v1.05

This is the first official release which is no longer a beta version.

Bug fix in this build:

  • Fixed a major problem that output within Kudu console doesn't get refreshed immediately. Now it's possible to real-time monitor exceptions in Kudu just like running inside an on-promise command line:

SD09

  • Fixed a bug that sometimes an exception message is recognized as exception type by mistake.
  • Further improved accuracy of capturing managed exceptions.
  • Fixed a bug in 32bit version that same exception object gets captured for multiple times.

SmartDump v1.04 beta

Bug fix in this build:

  • Fixed a bug that exception object's namespace may not be properly retrieved in 32bit version.
  • Added support for pressing Ctrl+Break to detach from a process but this still doesn't work inside Kudu console ( just like Ctrl+C ).
  • Code optimization .

SmartDump v1.03 beta

New feature:

  • Added -de option support. In this 'Dump for each' mode, dumps will be captured for each of different exception types. Exception types already captured will be skipped until all exception types specified in filter strings have been captured - start another round.

Example:

In the following sample, SmartDump with -de switch will capture 3 dumps for SqlException, InvalidOperationException and ServiceOperationsProviderException one by one.

image

Bug fix in this build:

  • Fixed a problem that some specific exception types defined in System.dll cannot be properly recognized in 64bit version.

SmartDump v1.02 beta

New feature:

  • Added functionality to detect target process termination and stop capturing.

Bug fix in this build:

  • Fixed the problem that filter strings and dump count didn't work well with unmanaged exceptions. Now native error codes in hex can be used to filter unmanaged exceptions, just like how filter works with managed exception:

image

SmartDump v1.01 beta

New feature:

  • Added support of pressing Ctrl+C to detach from target process. However please note Kudu console has a known limitation that doesn't support Ctrl+C to exit processes. Only copy/paste Ctrl+C/Ctrl+V is supported in Kudu.

Sample output:

20:26:44 [Managed Exception] <System.NullReferenceException> Object reference not set to an instance of an object.
User pressed Ctrl+C. Detaching from target process: 306256.

Bug fix in this build:

  • Fixed a problem that System.NullReferenceException caused by 0xc0000005 Access Violation needs to be processed specially.

SmartDump v1.00 beta

New feature:

Add -s option support.

 -s     Skip the first number of exceptions for dump capture. This option is useful when initial exceptions cannot reflect an actual issue.

Example:

  • Skip the first 3 NullReferenceException. Capture a memory dump for the 4th one and specify output path to: c:\home\dump.

          SmartDump.exe -p 4567 -n 10 -f "NullReferenceException" -s 3 -d 1 -o c:\home\dump
    

Bug fix in this build:

  1. Fixed a bug of -a option of 64bit version on displaying stacks.
  2. Limited max stack length to 30 to avoid endless loop while capturing dumps of stack overflow.
  3. Optimized the code to detect and display 64bit memory addresses.

SmartDump v0.99 alpha

New feature:

Add -fv option support.
-fv Exclude exceptions contain specified filter. Use '|' as delimiter for multiple strings.

Add multiple strings support for -f option.

Examples:

  • Capture two dumps based on filtered strings of managed exceptions:
    SmartDump.exe -p 4567 -f "Object reference not set|ArgumentException" -n 10 -d 2

  • Exclude exceptions contain specified filter string from output:
    SmartDump.exe -p 4567 -n 10 -fv "InvalidOperationException|FileNotFoundException"

Bug fix in this build:

  1. Fixed a bug of string buffer exceeded while retrieving exception types.
  2. Fixed a bug that namespace string incorrectly truncated in some specific case.

SmartDump v0.98 alpha

Recent improvements in this build:

  1. Further optimized code of retrieving managed exceptions. Far more accurate than previous builds.
  2. Fix two bugs that can lead to target process termination/crash.
  3. Default number of exceptions is set to 5 now due to limitation of Kudu console.

SmartDump v0.97 x64 alpha

Recent improvements in this build:

  1. Improved verification of user input parameters.
  2. Simplified input parameter. Number of exception to be monitored is set to 20 now(previous is unlimited). No need to specify -n by default. Set -n to 0 means unlimited.
  3. Further improved the ability to retrieve managed exception types.
  4. VC runtime library is built-in included and compiled into this build to resolve missing dependency error.

SmartDump v0.95 x64 alpha

Recent improvements in this build:

  1. 64bit process support is available now - SmartDump64.exe.
  2. New parameter to control dump count has been added.
  3. Resolved some user privilege issues on dump collection.
  4. Fix of exception number doesn’t apply to unmanaged first chance exceptions.
  5. Release build that no longer depends on Debug version of VC++ runtime library.

Procdump repro steps

[Problem]: procdump cannot successfully capture .net core exceptions inside Azure Kudu console

Repro steps of Procdump (the last version 08/18/2021)

  1. Create a new Function App on Azure portal
    image

  2. Create a new function with HTTP trigger template and leave all things as default
    image

  3. Open Kudu console and Process Explorer from Advanced tools
    image

  4. Find PID in Process Explorer.
    image

  5. Launch Procdump and attach to this PID
    image
    image

  6. Submit some invalid JSON data to the Function App to generate some exceptions
    image
    image

  7. None of exceptions are captured
    image

  8. If -g option is used, then all the exceptions are captured as generic CLR exception.
    image

  9. Compare it with the output of my tool which correctly displays the exceptions.
    image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.