# US 10,956,304 B2 · Dynamic diagnostic code instrumentation over a historic program execution

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 10,956,304 B2
- Document ID: US10956304B2
- Status: Granted
- Kind: B2
- Application number: 16/258,291
- Filed: 2019-01-25
- Published: 2020-07-30
- Granted: 2021-03-23
- Earliest claimed: 2019-01-25
- Assignees: Microsoft Technology Licensing, LLC
- Applicants: Microsoft Technology Licensing, LLC
- Inventors: Jackson Michael Davis; Patrick Lothian Nelson; Andrew R. Sterland; Jordi Mola; Del Myers; Leslie Yvette Richardson; Thomas Lai
- Web page: https://patentgrep.com/patent/US10956304B2

## CPC

- G06F 11/3644: {by instrumenting at runtime}
- G06F 11/3698: Environments for analysis, debugging or testing of software
- G06F 9/455: Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
- G06F 11/366: {using diagnostics (G06F11/0703 takes precedence)}
- G06F 11/0778: {Dumping, i.e. gathering error/state information after a fault for later diagnosis}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Dynamically instrumenting code that executes based on a historic execution of a subject executable entity. Historic execution information for a subject executable entity is accessed. The historic execution information includes execution state information for at least one point in time in the historic execution the executable entity. Diagnostic code instruction(s) are identified, for instrumenting subject code instruction(s) of the executable entity. The subject code instruction(s) are virtually executed based at least on supplying the subject code instruction(s) with data from the historic execution information. While virtually executing the identified executable code instruction(s), the diagnostic code instruction(s) are also executed. The diagnostic code instruction(s) collecting diagnostic data regarding the virtual execution of the subject code instruction(s), or override at least one of a value or an execution behavior of the subject code instruction(s).

## Claims

### Claim 1

A method, implemented at a computer system that includes one or more processors, for dynamically instrumenting code of a subject executable entity that is executing based on replaying a prior execution of the subject executable entity from a trace, the method comprising:
accessing historic execution information recording a prior execution of the subject executable entity, the historic execution information including execution state information for at least one point in the prior execution of the subject executable entity that is usable to replay the at least one point in the prior execution of the subject executable entity;
based at least on accessing the historic execution information, identifying one or more diagnostic code instructions for instrumenting one or more subject code instructions of the subject executable entity during replay of the subject executable entity, the one or more diagnostic code instructions having not been originally executed as part of a code stream of the subject executable entity during the prior execution of the subject executable entity;
replaying the prior execution of the subject execution entity by virtually executing the one or more subject code instructions of the subject executable entity using the historic execution information, including supplying the one or more subject code instructions of the subject executable entity with data from the historic execution information, wherein virtually executing the one or more subject code instructions of the subject executable entity using the historic execution information establishes a prior execution context based on the historic execution information;
in connection with virtually executing the one or more subject code instructions of the subject executable entity using the historic execution information, executing the identified one or more diagnostic code instructions within the established prior execution context as part of the code stream of the subject executable entity; and
based on executing the identified one or more diagnostic code instructions within the established prior execution context, performing at least one of:
collecting diagnostic data regarding the virtual execution of the one or more subject code instructions of the subject executable entity; or
overriding at least one of a value or an execution behavior of the one or more subject code instructions of the subject executable entity.

### Claim 2 (depends on 1)

The method of claim 1, wherein the historic execution information comprises at least one of:
trace data enabling time-travel debugging;
a dump or snapshot enabling branch trace debugging;
a plurality of snapshots enabling replay and snapshot debugging; or
a single snapshot from which a virtual execution can be continued.

### Claim 3 (depends on 1)

The method of claim 1, wherein the one or more subject code instructions of the subject executable entity are accessed from least one of (i) the historic execution information, or (ii) a binary image from which the subject executable entity executed.

### Claim 4 (depends on 1)

The method of claim 1, wherein virtually executing the one or more subject code instructions of the subject executable entity comprises at least one of (i) executing the one or more subject code instructions using a managed code runtime, or (ii) executing the one or more subject code instructions using a native code interpreter.

### Claim 5 (depends on 1)

The method of claim 1, wherein executing the identified one or more diagnostic code instructions comprises at least one of:
executing the identified one or more diagnostic code instructions based on triggering of an execution hook;
injecting the one or more diagnostic code instructions into the code stream of the subject executable entity, the code stream including the one or more subject code instructions of the subject executable entity, and executing the one or more diagnostic code instructions and the one or more subject code instructions in a managed runtime; or
injecting the one or more diagnostic code instructions into the code stream of the subject executable entity, the code stream including the one or more subject code instructions, and executing the one or more diagnostic code instructions and the one or more subject code instructions in a native code interpreter.

### Claim 6 (depends on 5)

The method of claim 5, wherein executing the identified one or more diagnostic code instructions based on triggering of the execution hook comprises at least one of:
executing the one or more diagnostic code instructions by a managed runtime; or
interpreting the one or more diagnostic code instructions so they appear to be executed by the managed runtime when they actually execute outside of the managed runtime.

### Claim 7 (depends on 1)

The method of claim 1, wherein the method collects the diagnostic data regarding the virtual execution of the one or more subject code instructions of the subject executable entity, the diagnostic data including at least one of:
data regarding control flow of the one or more subject code instructions;
at least one data value obtained from the historic execution information;
at least one data value generated by the virtual execution of the one or more subject code instructions;
a snapshot of a heap used for executing the one or more subject code instructions; or
performance data relating to execution of the one or more subject code instructions.

### Claim 8 (depends on 1)

The method of claim 1, wherein the method overrides at least one execution behavior of the one or more subject code instructions of the subject executable entity based on at least one of:
overriding a data value supplied as an input to at least one of the one or more subject code instructions;
overriding a data value generated as an output by at least one of the one or more subject code instructions; or
altering a target jump location for at least one of the one or more subject code instructions.

### Claim 9 (depends on 1)

The method of claim 1, wherein the one or more diagnostic code instructions perform at least one of: collecting a data value corresponding to an identified code element, logging execution of an identified loop, or logging calling of an identified function.

### Claim 10

A computer system, comprising:
one or more processors; and
one or more computer-readable media having stored thereon computer-executable instructions that are executable by the one or more processors to cause the computer system to dynamically instrument code of a subject executable entity that is executing based on replaying a prior execution of the subject executable entity from a trace, the computer-executable instructions including instructions that are executable by the one or more processors to:
access historic execution information recording a prior execution of the subject executable entity, the historic execution information including execution state information for at least one point in the prior execution of the subject executable entity that is usable to replay the at least one point in the prior execution of the subject executable entity;
based at least on accessing the historic execution information, identify one or more diagnostic code instructions for instrumenting one or more subject code instructions of the subject executable entity during replay of the subject executable entity, the one or more diagnostic code instructions having not been originally executed as part of a code stream of the subject executable entity during the prior execution of the subject executable entity;
replay the prior execution of the subject execution entity by virtually executing the one or more subject code instructions of the subject executable entity using the historic execution information, including supplying the one or more subject code instructions of the subject executable entity with data from the historic execution information, wherein virtually executing the one or more subject code instructions of the subject executable entity using the historic execution information establishes a prior execution context based on the historic execution information;
in connection with virtually executing the one or more subject code instructions of the subject executable entity using the historic execution information, execute the identified one or more diagnostic code instructions within the established prior execution context as part of the code stream of the subject executable entity; and
based on executing the identified one or more diagnostic code instructions within the established prior execution context, perform at least one of:
collecting diagnostic data regarding the virtual execution of the one or more subject code instructions of the subject executable entity; or
overriding at least one of a value or an execution behavior of the one or more subject code instructions of the subject executable entity.

### Claim 11 (depends on 10)

The computer system of claim 10, wherein the historic execution information comprises at least one of:
trace data enabling time-travel debugging;
a dump or snapshot enabling branch trace debugging;
a plurality of snapshots enabling replay and snapshot debugging; or
a single snapshot from which a virtual execution can be continued.

### Claim 12 (depends on 10)

The computer system of claim 10, wherein the one or more subject code instructions of the subject executable entity are accessed from least one of (i) the historic execution information, or (ii) a binary image from which the subject executable entity executed.

### Claim 13 (depends on 10)

The computer system of claim 10, wherein virtually executing the one or more subject code instructions of the subject executable entity comprises at least one of (i) executing the one or more subject code instructions using a managed code runtime, or (ii) executing the one or more subject code instructions using a native code interpreter.

### Claim 14 (depends on 10)

The computer system of claim 10, wherein executing the identified one or more diagnostic code instructions comprises at least one of:
executing the identified one or more diagnostic code instructions based on triggering of an execution hook;
injecting the one or more diagnostic code instructions into the code stream of the subject executable entity, the code stream including the one or more subject code instructions of the subject executable entity, and executing the one or more diagnostic code instructions and the one or more subject code instructions in a managed runtime; or
injecting the one or more diagnostic code instructions into the code stream of the subject executable entity, the code stream including the one or more subject code instructions, and executing the one or more diagnostic code instructions and the one or more subject code instructions in a native code interpreter.

### Claim 15 (depends on 10)

The computer system of claim 10, wherein the computer system collects the diagnostic data regarding the virtual execution of the one or more subject code instructions of the subject executable entity, the diagnostic data including at least one of:
data regarding control flow of the one or more subject code instructions;
at least one data value obtained from the historic execution information;
at least one data value generated by the virtual execution of the one or more subject code instructions;
a snapshot of a heap used for executing the one or more subject code instructions; or
performance data relating to execution of the one or more subject code instructions.

### Claim 16 (depends on 10)

The computer system of claim 10, wherein the computer system overrides at least one execution behavior of the one or more subject code instructions of the subject executable entity based on at least one of:
overriding a data value supplied as an input to at least one of the one or more subject code instructions;
overriding a data value generated as an output by at least one of the one or more subject code instructions; or
altering a target jump location for at least one of the one or more subject code instructions.

### Claim 17

One or more hardware storage devices having stored thereon computer-executable instructions that are executable by one or more processors to cause a computer system to dynamically instrument code of a subject executable entity that is executing based on replaying a prior execution of the subject executable entity from a trace, the computer-executable instructions including instructions that are executable by the one or more processors to:
access historic execution information recording a prior execution of the subject executable entity, the historic execution information including execution state information for at least one point in the prior execution of the subject executable entity that is usable to replay the at least one point in the prior execution of the subject executable entity;
based at least on accessing the historic execution information, identify one or more diagnostic code instructions for instrumenting one or more subject code instructions of the subject executable entity during replay of the subject executable entity, the one or more diagnostic code instructions having not been originally executed as part of a code stream of the subject executable entity during the prior execution of the subject executable entity;
replay the prior execution of the subject execution entity by virtually executing the one or more subject code instructions of the subject executable entity using the historic execution information, including supplying the one or more subject code instructions of the subject executable entity with data from the historic execution information, wherein virtually executing the one or more subject code instructions of the subject executable entity using the historic execution information establishes a prior execution context based on the historic execution information;
in connection with virtually executing the one or more subject code instructions of the subject executable entity using the historic execution information, execute the identified one or more diagnostic code instructions within the established prior execution context as part of the code stream of the subject executable entity; and
based on executing the identified one or more diagnostic code instructions within the established prior execution context, perform at least one of:
collecting diagnostic data regarding the virtual execution of the one or more subject code instructions of the subject executable entity; or
overriding at least one of a value or an execution behavior of the one or more subject code instructions of the subject executable entity.

### Claim 18 (depends on 17)

The one or more hardware storage devices of claim 17, wherein the historic execution information comprises at least one of:
trace data enabling time-travel debugging;
a dump or snapshot enabling branch trace debugging;
a plurality of snapshots enabling replay and snapshot debugging; or
a single snapshot from which a virtual execution can be continued.

### Claim 19 (depends on 17)

The one or more hardware storage devices of claim 17, wherein the one or more subject code instructions of the subject executable entity are accessed from least one of (i) the historic execution information, or (ii) a binary image from which the subject executable entity executed.

### Claim 20 (depends on 17)

The one or more hardware storage devices of claim 17, wherein virtually executing the one or more subject code instructions of the subject executable entity comprises at least one of (i) executing the one or more subject code instructions using a managed code runtime, or (ii) executing the one or more subject code instructions using a native code interpreter.

### Claim 21 (depends on 17)

The one or more hardware storage devices of claim 17, wherein executing the identified one or more diagnostic code instructions comprises at least one of:
executing the identified one or more diagnostic code instructions based on triggering of an execution hook;
injecting the one or more diagnostic code instructions into the one or more subject code instructions of the subject executable entity, and executing the one or more diagnostic code instructions and the one or more subject code instructions in a managed runtime; or
injecting the one or more diagnostic code instructions into the one or more subject code instructions, and executing the one or more diagnostic code instructions and the one or more subject code instructions in a native code interpreter.
