The present disclosure relates to obtaining processor behavior in real time using trace information in.
To monitor central processing unit (CPU) activities in real time, a trace function of a CPU can be used so that the CPU activity information can be acquired for each CPU cycle. More specifically, a CPU has physical input/output (I/O) pins for outputting the trace information. By monitoring the details of the trace information from outside the CPU, the activity information of the CPU can be obtained. The trace information includes whether an instruction is executed or not, whether a branch is “taken” or “not taken”, and the branch address in every CPU cycle, i.e., information about an address to which a program branches.
A known method and its hardware system identify functions processed by a CPU in real time by monitoring trace information using an external monitoring apparatus. In this method, the external monitoring apparatus has the information as to which function is mapped to which logical address before running the program. Subsequently, the monitoring apparatus compares the branch address acquired from the trace information with the stored information so as to identify which function has been executed in real time.
In case of monitoring a large-scale program, not all the functions of the program are monitored. Instead, some pre-selected functions are monitored. To do so, the information as to when the functions of interest are started and ended is required. However, it is difficult to determine when the functions of interest are started and ended using only the memory spaces being used by these functions. This is because when a branch address outside the memory spaces being used by the functions of interest is observed, it cannot be determined whether the currently executed function calls a new function or it returns to the previously executed function.
As described above, there exists a method for observing the behavior of a CPU, for instance, an embedded CPU or otherwise, from trace information output from the CPU in debugging of the CPU. The trace information can include information indicating whether the CPU executed an instruction, information indicating whether a branch was taken or not taken, and information about an address to which a program branches (branch address). A CPU can output a specific address every time the branch is taken. Another type of CPU outputs a branch address only for a branch instruction whose branch address is unknown in a static program analysis and is determined at the execution thereof. An example of the second case is illustrated in
Typically, trace information and a binary image of a program that can run in an embedded CPU are stored locally in a tracing PC, the trace information is measured, and then reconstruction and analysis are carried out using both the program binary image and the trace information. However, if it is necessary to identify a currently executed address in real time for, for example, real time verification, a process of storing trace information and then performing reconstruction cannot be used because it is not real time. To identify a currently executed address from trace information in real time by a measurement device, it is necessary for the measurement device to have a binary image similar to a program to be measured and to process obtained event information in real time. To this end, the measurement device needs to have the same size of a binary image as the program. This is impracticable because it needs significantly large capacity.
For debugging an embedded CPU, the information indicating when functions of interest started and terminated is helpful. In particular, for a design using a model driven architecture, in order to visualize how the model behaved, it is helpful to trace the model states. However, known measurement devices and methods need to have the full binary image to perform the reconstruction of the execution flow even if one wants to trace only specific functions. It is thus difficult to put such a technique to practical use.
A method and apparatus such as a circuit device for detecting processor behavior in real time using instruction trace data are provided. The method, in one aspect, may comprise determining a function of a module executing in a processor to be observed; identifying one or more call addresses from which the function is called; establishing one or more end addresses of the function to be a predetermined address increment of said one or more call addresses respectively; storing said one or more call addresses and said one or more end addresses; receiving instruction trace data; and comparing a branch address contained in the instruction trace data with said stored one or more call addresses and said one or more end addresses to detect start and end of the function dynamically in real time.
A circuit device for monitoring processor behavior using instruction trace data, in one aspect, may comprise, a program counter emulator operable to trace current execution address of a processor using trace information and store said current execution address; a mapping table operable to store information associated with a function to be observed; a return address table operable to store dynamically a return address of the function during execution; and a mapping table search unit operable to compare a value in the program counter emulator with one or more values in the mapping table and the return address table to detect start and end of the function, the circuit device operable to output information in real time as to whether the function starts or ends.
Further features as well as the structure and operation of various embodiments are described in detail below with reference to the accompanying drawings. In the drawings, like reference numbers indicate identical or functionally similar elements.
A method and apparatus of the present disclosure in one embodiment obtains function transition of a target of measurement, that is, behavior of the CPU to be monitored in real time by using only trace information of the target of measurement as input. Since the function transition is restored based on the trace information, no change is required in a source code of the target of measurement in order to obtain the function transition. For instance, code for debugging need not be inserted.
Several embodiments to the method and apparatus of the present disclosure are provided to overcome the shortcomings of the known methodology and devices. In one embodiment, rather than using the ranges of the memory space being used by the functions, the start and end of the execution of each function of interest are detected by using the start address of the function of interest and a table of the return addresses. The start address and the return addresses of the function may be determined by a static analysis. The ranges of the memory spaces of all the functions need not be stored; instead only the start address and return addresses of the function of interest are stored. The table does not have to have all the address ranges of the functions that are expected to run. Therefore, the storage capacity can significantly be decreased.
The existing method is described in more detail first. The monitoring apparatus stores the ranges of the memory spaces of all of the functions in order to detect the start and end of a function by monitoring the transition of an execution address in the memory spaces of the functions and tracing the start and end of a function. Let B denote a function of interest. Then, in order to detect the start and end of Function B, Function A that calls Function B is identified. Thereafter, the transition from Function A to Function B needs to be detected.
In contrast,
The method of the present disclosure in one embodiment acquires the end of the function of interest from the trace information. In one embodiment, the method does not detect the end of the function using the information about the memory space to which the function of interest is mapped. Instead, it detects the end of the function using the return address appearing when the function of interest is ended. That is, in place of using information about the memory space of a function, the start and end of the function of interest are detected by using the top address and the return address of the function of interest in the trace information.
Table I illustrates an example of the information that a monitoring apparatus has, when it detects the function of interest, FuncB, being called in the example shown in
In such a method, if the function of interest is called by a plurality of functions, two or more return addresses equal to the number of the call points are stored in the table. However, if the function of interest is called by only one function, the number of entries remains one.
Model-driven design methodologies have become popular. Rational RoseRT is one of the tools that support model-driven design methodologies, and it is capable of automatic C/C++code generation. The generated code is ready to run on an actual system. State transitions in the model can be traced by monitoring function transitions presented in this disclosure. State transitions in the C/C++ code generated by RoseRT are usually implemented with function call schemes, in which a function is called by only one function. Consequently, the method of the present disclosure is suitable for the model-driven design.
A procedure for acquiring the start address and the return addresses according to this method is described with reference to
In another embodiment, the return addresses of the function of interest are found by statically analyzing the source code and the execution object in advance according to above first embodiment. Thereafter, the return addresses are stored in the table of the monitoring apparatus. However, an execution address at a time when a branch is taken can be detected by using the branch information contained in the trace information and the instruction execution information. If the branch address and the execution address have been acquired and a jump to one of the function of interest is observed, the return address is determined to be the address next to the address of the branch operation. Accordingly, by providing a mechanism to dynamically add a return address to the monitoring apparatus, the same advantage as that of the first embodiment can be obtained without storing the return addresses in a table before the program execution. Yet another embodiment provides a circuit configuration and a method for achieving the above-described technique.
The trace information may fall in the following two categories: 1) an instruction execution address and 2) the information as to whether or not the CPU executes the instruction. When address n is observed as the address of the instruction to be executed, and the instruction is reported as actually being executed or have been executed, the address of the instruction that follows the executed instruction is next to address n. That is, by tracing the address currently executed using the trace information, the monitoring apparatus can identify the currently executed address at any time.
When the monitoring apparatus observes the start address of the function of interest, the monitoring apparatus detects or monitors the address of the caller. The return address is the address next to the address of the instruction that called the function of interest. Accordingly, the return address, which is identified through the static analysis in the embodiment shown with reference to
Mapping Table (MT) 710 stores the identifier of the function of interest and the start address of the function of interest. This table 710 may be set by analyzing the source code before the program execution. Return Address Table (RAT) 712 is used for dynamically storing the return addresses of the functions of interest that is observed during execution.
By comparing the values in the two tables with the value of the PCE, the start and end of the function of interest can be detected. This detection is performed by MT Search Unit (MTSU) 708. If either of the start or end of the function of interest is detected, the circuit outputs information as to whether the function of interest starts or ends together with the ID of the function of interest.
The flow of the execution is described next. In Step 1, the trace information is “Execute”. Therefore, after this instruction is executed, the execution address moves to the next address 0x1008. The subsequent trace operation is described in the figure. In Step 2, since the trace information is “Execute”, the PCE is changed to the next address (0x100C). At that time, the PPCE holds the immediately previous PCE value (i.e., 0x1008). In Step 3, the CPU calls FunctionB, which is a function of interest. A branch address 0x1100 can be obtained from the trace information. Accordingly, the address information “0x1100” is stored in the PCE. The immediately previous PCE value 0x100C is stored in the PPCE. As shown at 810, 0x1100 was set in the MT before the monitoring operation starts. Accordingly, it is determined that the function represents the function of interest. Therefore, a return address is dynamically set in the RAT as shown at 812. The value of the return address is an address 0x100C+4 (=0x1010) at which the instruction next to the instruction indicated by the PPCE is stored. In this example, it is assumed that the CALL instruction of the target CPU is four bytes (32 bits) in size, and hence “+4” for the value of the return address.
Subsequently, the processes in steps 4 to n−1 are performed. In Step n, a branch operation indicated by “Return” is observed. In the case of “Return”, a branch address can be retrieved from the trace information. In this example, the branch address is 0x1010. Since this value 0x1010 is equal to the return address stored in the RAT, the end of the function of interest is detected. Immediately after the end of the function of interest is detected, the corresponding entry value in the RAT is erased. In one embodiment, the RAT behaves like a stack memory. The entry for the returned function is no longer needed, and therefore erased. A function will be called from two or more functions and thus the entry information is maintained on the fly. As described in the foregoing procedure, by dynamically generating and erasing the return address of the function of interest, the start and end of the function of interest can be detected.
It is noted that in the RiscTrace tracing system, when the CPU executes a CALL instruction, it does not output the jump target address to the trace port. The CPU only generates “Execute” information, as shown in
Yet in another embodiment, a technique is provided for identifying a function call immediately before a call of a function of interest by static analysis of source code, storing only a binary image from a return point of the immediately preceding function call to the call of the function of interest in a measurement device, and using the stored binary image to carry out reconstruction for tracing. The amount of code stored for reconstruction is reduced by selectively recording the functions of interest and the functions that call them. The size of the capacity can be further reduced by storing only an instruction that affects an address (a branch, a function call) from a partially held binary image. Still yet, a circuit that enables dynamically reconstructing an address of a function of interest using the partial binary image is provided.
The method and apparatus in one embodiment identify a portion that calls a function of interest and additionally, identify a function call immediately before the function of interest is called. The method in one embodiment exploits a characteristic that a return address is obtainable as trace information because a branch for a return occurring after completion of a function has a dynamically determined address. The method and apparatus derives partial binary image for use in reconstruction of function of interest.
One example of C code generated so as to correspond to an executable model produced by Rational Rose RT for use in a model driven design is provided as an example. In this case, tracing the behavior of the model running in the SUT in real time and analyzing it is needed. For the model driven design, trace behavior of a state machine is traced, and the behavior of the state machine can be tracked by measurement of an action at which a state transition occurs. Actions are defined as functions on software. Thus, the behavior of the model can be understood when the start and the termination of a function that corresponds to the action are traced. That is, tracing simply requires measurement of a function corresponding to this specific action.
Action functions on a model are defined as actions occurring in transition between state spaces on the model, and each action function is uniquely defined. In other words, an action function of interest is not called from many different places. For implementation of Rose RT, an action function is called from only one place on a program. Therefore, this is an example that a tracing mechanism provided by the present invention functions very effectively.
The code shown below is an example of code generated by a model actually produced by Rose RT. An action function “chain2_turnOn( )” is set as the unction of interest. In this case, “chain2_turnOn( )” is called from a function of “rtsBehavior ( )” and “getCurrentState( )” is called as a function call immediately before “chain2_turnOn( )” is called. Thus, according to a technique provided by the present disclosure in one embodiment, a measurement device stores the portion of the code existing between “getCurrentState( )” and “chain2_turnOn( )”.
The amount of code to be stored to observe a specific single function when a model was actually produced by Rose RT was estimated. For example, it was necessary to store a binary image of 44,132 steps when original code is stored without being processed. In contrast, when the technique provided by the present disclosure is used, the amount to be stored is a binary image of only 23 steps, which corresponds to the number of instructions existing between a place where a function to be measured is called and a function call that is always called immediately before the place. In addition, the amount of code to be held in measurement device exclusive of code that does not affect address was 7 steps.
As described above, the technique of the present disclosure obviates the necessity for the measurement device to store all code when a specific function is to be partially observed, and thus, it enables the measurement device to hold only small amount of code.
When trace information is supplied to a circuit, if the trace information 1204 contains address information, the address value is provided to a program counter emulator (PCE) 1206. Trace information has an address value when the CPU executes dynamic branch instruction such as RETURN. The method and system of the present disclosure in one embodiment uses this address value. Otherwise it is determined whether there is an instruction address identical with the current PCE value among the instruction addresses in the PPBT 1210. PPBT search unit 1208 determines if the current PCE value is stored in PPBT. If it is, the unit changes the PCE value to the “Branch address after execution”. Note that the partial program branch table has static branch instructions with its destination address in the partial binary image. The initial PCE value may be unknown. The method and system of the present disclosure in one embodiment gets the valid address value from the previous dynamic branch instruction that is executed before the function call of interest. If no such an identical instruction address is present, the PCE value is incremented by a quantity corresponding to one instruction at the stage when “Execute” is observed as trace information. If such an identical instruction address is found, the PCE value is overwritten with the branch address after the execution when “Execute” or “Branch taken” is observed as trace information. In one embodiment, the circuit of
The flow of this processing is shown in
The partial binary image has at least one dynamic branch address call instruction, and it generates the instruction address the CPU executes. The partial binary image also has the branch information on the dynamic branch address call instructions to the functions of interest. By using the partial binary image and trace data, this method enables to detect the functions of interest. As
Various aspects of the present disclosure may be embodied as a program, software, or computer instructions embodied in a computer or machine usable or readable medium, which causes the computer or machine to perform the steps of the method when executed on the computer, processor, and/or machine.
The system and method of the present disclosure may be implemented and run on a general-purpose computer or computer system. The computer system may be any type of known or will be known systems and may typically include a processor, memory device, a storage device, input/output devices, internal buses, and/or a communications interface for communicating with other computer systems in conjunction with communication hardware and software, etc.
The terms “computer system” and “computer network” as may be used in the present application may include a variety of combinations of fixed and/or portable computer hardware, software, peripherals, and storage devices. The computer system may include a plurality of individual components that are networked or otherwise linked to perform collaboratively, or may include one or more stand-alone components. The hardware and software components of the computer system of the present application may include and may be included within fixed and portable devices such as desktop, laptop, server. A module may be a component of a device, software, program, or system that implements some “functionality”, which can be embodied as software, hardware, firmware, electronic circuitry, or etc.
The embodiments described above are illustrative examples and it should not be construed that the present invention is limited to these particular embodiments. Thus, various changes and modifications may be effected by one skilled in the art without departing from the spirit or scope of the invention as defined in the appended claims.