USPatent applicationPatented

Preserving program context when adding probe routine calls for program instrumentation

Granted 12 Sep 2006 · 2 office actions

Current assignee: HTC Corporation · originally Hewlett Packard Enterprise

Law firm: Law firm · Log in to unlock

Attorney: Attorney · Log in to unlock

Inventors: Vinodha Ramasamy, Jenn-Yuan Tsai · Examiner: Wei Zhen · AU 2191 · TC 2100

Life of the application

12 dated events
⤢ drag to zoom20022004200620082010201220142016201820202022ProsecutionOwnershipTerm & fees
ProsecutionOwnershipTerm & feeshover for detail · click to open

Abstract

Method and apparatus for preserving program context when causing execution of a probe routine from a target routine of an executable computer program code. Executable code for the probe routine is created such that the probe routine does not reference a first set of registers that are usable by the target routine. A modified version of the target routine is created to cause execution of the probe routine. The modified version of the target routine is performed instead of the original version when the target routine is called during program execution. A second set of registers on the processor register stack is allocated when the probe routine is invoked. The second set of registers is not manipulated by the probe routine so as to avoid changing contents of registers of the register stack that are used by the target routine.

Description

6 parts
›FIELD OF THE INVENTION

The present invention generally relates to instrumentation of executable computer programs, and more particularly to insertion of probe routine calls in instrumenting programs.

›BACKGROUND

Functions and procedures are well-known constructs that are used in creating modular programs. Nesting function and procedure calls further supports hierarchical program designs, thereby supporting multiple levels of design abstraction.

Functions and procedures often include parameters for passing data. A function typically has only input parameters, and a call to the function often returns a value. A procedure may have both input and output parameters. For ease of reference, functions and procedures are referenced herein as “routines.”

Many processor architectures use a register stack and a register renaming mechanism to pass parameter values between routine calls. The processor associates selected registers with parameters of a routine when a routine is called. The register stack includes multiple registers and a stack pointer that references the set of registers at the top of the stack for the most recently called routine. With each nested routine call, additional registers from the register stack are associated with the parameters of the called routine. Other registers that a routine uses during execution for temporary storage of data are referred to as “scratch” registers.

Tools that support analysis of an executing program must account for behavior of the register stack and a routine's usage of scratch registers in order to avoid corrupting data referenced by the routines in the program. Analysis of binary executable programs is performed to analyze program performance, verify correctness, and test correct runtime operation, for example. Some analyses are performed prior to runtime (static analysis), while other analyses are performed during runtime (dynamic analysis). For both static and dynamic analysis, however, the analysis is often performed at the routine level.

One category of analysis performed on executable programs is “instrumentation”. Instrumentation is generally used to gather runtime characteristics of a program. For example, the number of times that a routine is executed while the application is executing is determined through instrumentation. Such instrumentation is sometimes accomplished by inserting a call to a probe routine at a selected point in the program. The probe routine performs instrumentation-related operations.

When inserting a probe routine call, the instrumentation tool must preserve the contents of the register stack so that invocation of the probe routine does not corrupt the contents of the registers, which are associated with parameters of the routine from which the probe routine was called. One approach to preserving the register stack is to save the contents of registers on the memory stack of the calling routine. However, this is costly in terms of execution time, especially if the routine from which the probe routine was invoked is called many times during program execution.

A system and method that address the aforementioned problems, as well as other related problems, are therefore desirable.

›SUMMARY OF THE INVENTION

The present invention preserves program context when causing execution of a probe routine from a target routine of an executable computer program code. Executable code for the probe routine is created such that the probe routine does not reference a first set of registers that are usable by the target routine. A modified version of the target routine is created to cause execution of the probe routine. The modified version of the target routine is performed instead of the original version when the target routine is called during program execution. A second set of registers on the processor register stack is allocated when the probe routine is invoked. The second set of registers is not manipulated by the probe routine so as to avoid changing contents of registers of the register stack that are used by the target routine.

Various example embodiments are set forth in the Detailed Description and claims which follow.

›BRIEF DESCRIPTION OF THE DRAWINGS

Various aspects and advantages of the invention will become apparent upon review of the following detailed description and upon reference to the drawings in which:

FIG. 1A is a block diagram that illustrates an example executable program that includes a routine foo( );

FIG. 1B illustrates the executable program after having been instrumented;

FIG. 1C illustrates memory space used in support of instrumenting the executable program in accordance with one embodiment of the invention;

FIG. 2 illustrates a register stack, parameters associated with routine calls, and a probe routine call inserted in target routine f 1 ( );

FIG. 3 illustrates a register stack and a routine call sequence in which target routine f 1 ( ) is instrumented by a probe routine, and the context of f 1 ( ) is preserved in accordance with one embodiment of the invention;

FIG. 4 is a flowchart of an example process for instrumenting a routine while preserving the context of the routine during instrumentation;

FIG. 5 is a flowchart of an example process performed by a stub routine in support of preserving the context of an instrumented routine; and

FIG. 6 illustrates a register stack and a routine call sequence in which target routine f 1 ( ) is instrumented by a probe routine, and the context of f 1 ( ) is preserved in accordance with another embodiment of the invention.

›DETAILED DESCRIPTION · 1 of 2

FIG. 1A is a block diagram that illustrates an example executable program that includes a routine foo( ) 104 . A typical scenario for instrumenting a routine is to insert a call to a probe routine that performs some desired processing relative to the routine. For example, the probe routine may simply count the number of times that the instrumented routine is called. Some instrumentation tools create a modified version of the routine to be instrumented. The routine to be instrumented is referenced herein as the “target” routine. In creating the modified version of the target routine, the target routine itself is modified such that when the target routine is invoked during program execution, the modified version of the routine is performed instead of the performing the target routine.

FIG. 1B illustrates the executable program after having been instrumented. Target routine foo( )′ 104 ′ has its first instruction replaced with a branch to foo( )″ 104 ″ in relocation address space 112 of FIG. 1C . Routine foo( )″ is the instrumented version of foo( ) and branches to stub routine 122 . The location in foo( )″ at which the branch to the stub routine is inserted depends on the code of the target routine and on the particular instrumentation processing of the probe routine. The stub( ) routine 122 saves and restores the context of foo( )″ so that when the probe( ) routine 132 is complete and control is returned to foo( )″,foo( )″ has the same data after execution of the probe( ) routine as before execution of the probe( ) routine. Specifically, all relevant registers remain unmodified.

Some processors, for example, the IA-64 processor architecture by Hewlett-Packard, have different sets of registers that are used for different purposes during program execution. A first set of registers can be used by a routine as “scratch” registers for the purpose of temporary storage of data during execution of the routine. Another set of registers is used by the processor for passing parameters between caller and called routines. One approach to saving the context of a routine is to save the contents of all the registers in the calling routine's memory stack. However, this approach is costly in terms of program execution time. In one embodiment of the invention, the probe( ) routine is created such that no scratch registers are used, for example, by compiling the routine with special compiler options. This reduces the context information that needs to be saved.

The stub( ) routine saves the contents of other registers, for example, the return-address register which stores the address to which control is to be returned (in the routine that called foo( )). The stub( ) routine also allocates extra registers of the type used in passing parameters (“parameter registers”). These additional parameter registers are not used by either the stub( ) or probe( ) routines and serve as placeholders on the processor's register stack.

FIG. 2 illustrates a register stack 200 , parameters associated with routine calls, and a probe( ) routine call inserted in target routine f 1 ( ). The call sequence illustrates how parameter registers are mapped to the register stack, and how an inserted probe( ) routine call affects the parameter registers if actions are not taken to preserve the parameter registers. In the example IA-64 processor architecture, general registers numbered 32 through 127 form a register stack that is automatically managed across procedure calls and returns. For each routine call, a frame of the register stack is divided into two dynamically-sized regions—one for input parameters and local variables and another for output parameters. On a routine call, the registers are automatically renamed by the processor so that the calling routine's output registers form the base of the called routine's register stack frame. On return to the calling routine the registers are restored to the previous state so that input and local registers are preserved across the routine call. An alloc instruction is used at the beginning of a routine to allocate the input, local, and output registers.

Routine f 1 has allocated registers 32 – 24 for input parameters and local registers (i 1 –i 3 ) and registers 35 – 37 for output parameters (o 1 –o 3 ). If a call to probe( ) is inserted in f 1 and probe is called, the processor bases the register stack frame for probe at the register ( 35 ) of the first output parameter of f 1 . Note that the stack frame pointer 202 references the base of the register stack frame associated with the most recently called routine. If probe has one input parameter and one output parameter, the input parameter i 1 of probe overlaps the output parameter o 1 of f 1 . Thus, if probe modifies registers 35 and 36 , data provided by f 1 may be corrupted. In one embodiment of the invention, the stub( ) routine allocates additional parameter registers so that the registers manipulated by the probe routine do not overlap the output registers of the target routine.

FIG. 3 illustrates a register stack and a routine call sequence in which target routine f 1 ( ) is instrumented by a probe routine, and the context of f 1 ( ) is preserved in accordance with one embodiment of the invention. Instead of inserting call to probe directly in the code of f 1 , a call to stub is inserted, and stub allocates dummy input parameter registers before calling probe. The number of dummy input registers that are allocated is architecture dependent. In the example embodiment, 8 dummy registers are allocated because the architecture allows at most 8 registers to be used for parameter passing. Thus, if a target routine has 8 output parameters, the 8 dummy registers of stub would overlap the 8 output register of the target routine. In the example of FIG. 3 , dummy input parameters di 1 , di 2 , and di 3 overlap output parameters o 1 , o 2 , and o 3 , respectively, for registers 35 , 36 , and 37 .

The stub routine calls probe, which has one input parameter (i 1 ) and one output parameter (o 1 ). The input parameter i 1 of probe is aligned with the first output parameter o 1 of stub in using register 43 . It will be appreciated that the stub code would generally not have output parameters. However, in this example the stub routine is shown as having an output parameter o 1 for purposes of illustration, and i 1 of probe is aligned with register 43 , which is after the input registers of stub.

›DETAILED DESCRIPTION · 2 of 2

FIG. 4 is a flowchart of an example process for instrumenting a routine while preserving the context of the routine during instrumentation. The probe routine to be used to instrument a target routine is compiled (step 302 ) with options that cause the compiler to generate code that does not use scratch registers available from the processor. It will be appreciated that other processor architectures may have other types of registers whose use can be limited through compilation or other techniques.

The executable code for the probe routine is made available for execution by the target routine (step 304 ). In one embodiment, relocation address space is created by an instrumentation tool that controls execution of the program to be instrumented. The relocation address space is used to store instrumented versions of routines and the executable code of the probe routine. In one embodiment, the present invention uses the techniques described in the patent/application entitled, “DYNAMIC INSTRUMENTATION OF AN EXECUTABLE PROGRAM” by Hundt et al., filed on Apr. 11, 2001, and having patent Ser. No. 09/833,248, which is incorporated herein by reference, to allocate memory. In another embodiment, the executable code of the probe routine is stored to the memory stack space associated with the target routine. In yet another embodiment, the executable code of the probe routine is stored to the heap memory space allocated by the target routine.

The stub routine is made available for execution from the instrumented target routine at step 306 . As with the probe routine, the stub routine may be stored in relocation address space, memory stack space, or heap memory space. It will be appreciated that a stub routine is created only once for a probe routine. Thus, wherever execution of the probe routine is desired in the program, a call to the stub routine can be inserted.

A modified version of the target routine is created (step 308 ) to include a call to the stub routine. The modified version of the target routine is stored in relocation address space, which is shared by the instrumentation tool and the executable program. The instrumentation tool lastly modifies the target routine in the executable program so that the modified version of the target routine is executed instead of the original target routine (step 310 ).

FIG. 5 is a flowchart of an example process performed by a stub routine in support of preserving the context of an instrumented routine. The stub routine allocates dummy input registers sufficient in number to avoid overlap of input or local registers used by the probe routine with output registers of the instrumented target routine (step 352 ). Another set of registers, termed “special,” are saved at step 354 . The special registers are those other than the scratch registers (which are not used by the probe function ) and the input parameter, local, and output parameter registers. In the example processor architecture, the special registers include the return-branch register and the ar.pfs register. The contents of the special registers are saved in memory associated with the stub routine.

The stub routine then calls the probe routine (step 356 ), and upon return from the probe routine the saved contents of the special registers are restored (step 358 ) before control is returned to the instrumented target function.

FIG. 6 illustrates a register stack and a routine call sequence in which target routine f 1 ( ) is instrumented by a probe routine, and the context of f 1 ( ) is preserved in accordance with another embodiment of the invention. The embodiment of FIG. 6 also involves the allocation of registers that are unused by probe. However, the registers are allocated by way of dummy input parameters that are included in the specification of probe. The probe routine does not use the dummy parameters (di 1 –di 8 ), and the number of dummy parameters is the same as the number of additional registers allocated by the stub routine in the embodiment illustrated in FIG. 3 . The stack pointer 402 references the base of the register stack frame for probe, which is register 35 . Even though the stack pointer references registers used by f 1 for output parameters, the fact that probe does not use the dummy registers eliminates the possibility of corrupting the register contents.

Other aspects and embodiments of the present invention will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. It is intended that the specification and illustrated embodiments be considered as examples only, with a true scope and spirit of the invention being indicated by the following claims.

Claims as granted

19 claims

Log in to read the claims of this application.

Log in to unlock

Classifications

6 codes
IPC · International Patent Classification
Section G — Physics
  • G06F9/44
  • G06F9/40
USPC · US Patent Classification
717/127717/130717/129717/128

Claim changes

Soon
Coming soonHow the claims changed between publication and grant

See which claims were amended, added or cancelled during examination, with every added and removed word marked.

AmendedAddedCancelledUnchanged

The published claims of this application are not paired with the granted ones in what we hold.

File wrapper

⤢ drag to zoomJul 2002Jan 2003Jul 2003Jan 2004Jul 2004Jan 2005Jul 2005Jan 2006Jul 2006USPTOApplicantNon-final rejectionFinal rejectionNotice of allowance
USPTOApplicanthover for detail · click to open
Pendency
4.3 y
1,587 days filing → grant
Office actions
2
non-final + final
Responses
1
no RCE
Interviews
1
examiner interview summaries
Examiner
Wei Zhen
art unit 2191 · TC 2100
Citations: 28 back · 7 forward

See the full prosecution history — every USPTO and applicant action on this file, in order.

Log in to unlock

Documents

Log in to open the documents of this file: the application as filed, every office action and response, the notice of allowance.

Log in to unlock

Chain of title

⤢ drag to zoom20022004200620082010201220142016201820202022Owner 2Owner 3
Titlehover for detail · click to open

See the full assignment history — every owner this patent has passed through, with recordation dates and reel/frame numbers.

Log in to unlock