# US 2010/0251220 A1 · Method and apparatus for dynamically instrumenting a program

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

- Number: US 2010/0251220 A1
- Document ID: US20100251220A1
- Status: Published application
- Kind: A1
- Application number: 12/726,705
- Filed: 2010-03-18
- Published: 2010-09-30
- Earliest claimed: 2009-03-30
- Assignees: Samsung Electronics Co., Ltd.
- Inventors: Jae-hoon JEONG
- Web page: https://patentgrep.com/patent/US20100251220A1

## CPC

- G06F 11/3644: {by instrumenting at runtime}
- G06F 9/4484: {Executing subprograms}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A dynamic instrumentation method and apparatus which may trace, debug, and profile the execution of a running program without affecting the operation of the program, are provided. According to the method, a break instruction is inserted and executed at start of execution of a first instruction and immediately after execution of the last instruction of a function constituting the program. Environment values of the function before and after execution may be identified. The program may be dynamically instrumented without being affected by any tracing or debugging operations.

## Claims

### Claim 1

A method of dynamically instrumenting a program using a dynamic instrumentation apparatus, the method comprising:
storing one or more environment values of a function before execution by inserting a break instruction at a location of a first instruction of the function included in the program and executing the break instruction at the start of execution of the first instruction; and
storing one or more environment values of the function after execution by executing a break instruction when execution proceeds to a return address after the last instruction of the function is executed.

### Claim 2 (depends on 1)

The method of claim 1, wherein, when the break instruction is executed in an application area:
a probe handler is run by an exception handler in an operating system (OS) area; and
the probe handler stores the one or more environment values of the function.

### Claim 3 (depends on 1)

The method of claim 1, wherein the storing of the one or more environment values of the function before execution comprises:
storing an instruction of the function;
replacing the instruction with a break instruction;
storing the one or more environment values of the function before execution in response to executing the break instruction; and
restoring and executing the stored instruction.

### Claim 4 (depends on 1)

The method of claim 1, wherein the storing of the one or more environment values of the function before execution comprises inserting the break instruction at a location of the first instruction of the function after storing the first instruction.

### Claim 5 (depends on 4)

The method of claim 4, wherein the storing of the one or more environment values of the function before execution further comprises:
storing a second instruction of the function;
inserting a break instruction at a location of the second instruction after storing the environment value of the function before execution; and
changing a return address of the function in response to execution of the break instruction inserted at the location of the first instruction.

### Claim 6 (depends on 5)

The method of claim 5, wherein the storing of the one or more environment values of the function before execution further comprises inserting break instructions at the location of the first instruction and a location of a third instruction of the function, when the break instruction inserted at the location of the second instruction is executed after the first instruction of the function has been restored and executed.

### Claim 7 (depends on 6)

The method of claim 6, wherein the storing of the one or more environment values of the function before execution further comprises:
inserting a break instruction at the location of the second instruction again; and
restoring and executing the third instruction, when the break instruction inserted at the location of the third instruction is executed, and after the second instruction has been restored and executed.

### Claim 8 (depends on 5)

The method of claim 5, wherein the return address of the function is set to the location of the second instruction of the function.

### Claim 9 (depends on 1)

The method of claim 1, wherein the storing of the one or more environment values of the function after execution comprises:
moving an execution location to the location of the second instruction set as the return address of the function once the last instruction of the function is executed; and
identifying the one or more environment values of the function after execution by executing the break instruction inserted at the location of the second instruction.

### Claim 10

An apparatus for dynamically instrumenting a program, the apparatus comprising:
an instruction managing unit configured to store instructions of a function of a program and to insert a break instruction at a location of each instruction; and
a probe unit configured to store one or more environment values of the function according to execution of each break instruction.

### Claim 11 (depends on 10)

The apparatus of claim 10, wherein the instruction managing unit is further configured to:
insert and execute the break instruction at a location of a first instruction of the function at the start of execution of the first instruction; and
manage the instructions such that an execution location proceeds to a return address of the function and a break instruction inserted at the return address is executed when the last instruction of the function is executed.

### Claim 12 (depends on 10)

The apparatus of claim 10, wherein the probe unit is further configured to:
identify the one or more environment values of the function before execution by executing the break instruction inserted at the location of the first instruction; and
identify the one or more environment values of the function after execution by executing the break instruction inserted at the return address.

### Claim 13

A method of an apparatus for dynamically tracing a software program, the method comprising:
determining that a first instruction of a function of a software program to be executed is not stored in memory;
substituting a break instruction in place of the first instruction;
loading to memory a corresponding page comprising the first instruction;
executing the break instruction to generate an exception; and
in response to the exception being executed, measuring and storing one or more environment values of the software program.

### Claim 14 (depends on 13)

The method of claim 13, further comprising, for each subsequent instruction of the software program:
substituting a subsequent break instruction in place of the subsequent instruction;
restoring the previous instruction;
executing the previous instruction;
changing the execution location of the program to the subsequent instruction;
inserting a previous break instruction in place of the previous instruction;
executing the subsequent break instruction to generate a subsequent exception; and
in response to the subsequent exception, measuring and storing environment values of the software program.

### Claim 15 (depends on 14)

The method of claim 14, wherein, when the subsequent instruction is the last instruction of the software program:
the environment values of the software program are measured and stored;
the last instruction is restored and executed; and
the execution location of the program is changed back to a previous instruction.

### Claim 16 (depends on 13)

The method of claim 13, wherein:
the one or more environment values comprise values that a user desires to know for detecting an error of a program; and
the environment values comprise at least one of: a register value, a location of a stack, and a location of the first instruction.

### Claim 17 (depends on 13)

The method of claim 13, wherein:
the break instruction of the program is executed in an application area; and
the environment values are measured by a probe handler that operates in an operating system area.
