Program call stack creation method and unwind stack method and apparatus
AssigneeHuawei Technologies Co., Ltd.
InventorNing Chu
Life of this patent
Estimating the term…
Abstract
This application discloses a program call stack creation method and apparatus, and an unwind stack method and apparatus. The call stack creation method includes: obtaining a first program, where the first program includes a first function, in a process of calling a runtime library to run the first program, adding a second function and creating a call stack, where the call stack includes a first stack frame, a second stack frame, and a third stack frame that are respectively corresponding to the first function, the second function, and a third function. An unwind stack performance can be improved to a maximum extent without affecting a non-stack trace scenario.
Claims20
A program call stack creation method, comprising:
- obtaining a first program, the first program comprising a first function;
- in a process of calling a runtime library to run the first program, adding a second function and creating a call stack, the call stack comprising a first stack frame corresponding to the first function, a second stack frame corresponding to the second function, and a third stack frame corresponding to a third function, there being a call relationship between the first function and the second function, there being a call relationship between the second function and the third function, the third function is a function in the runtime library or a function in the first program, and a high-level programming language corresponding to the first function is different from a high-level programming language corresponding to the third function;
- and
- storing a first return address and a label corresponding to the first return address, the first return address comprising a return address comprised in a stack frame corresponding to a function that is executed later in the first function and the third function, and the label corresponding to the first return address indicating a stack frame type of the first stack frame, a stack frame type of the second stack frame, and a stack frame type of the third stack frame, a stack frame type being related to a type of a high-level programming language of the runtime library.
An unwind stack method for a call stack, the call stack including a fourth stack frame corresponding to a fourth function, a stack frame type of the fourth stack frame including a first type, the stack frame type of the fourth stack frame being related to a type of a high-level programming language corresponding to the fourth function, a stack frame type being related to a type of a high-level programming language of a runtime library, the method comprising:
- obtaining a second return address in the fourth stack frame, the second return address pointing to a fifth function, and the fifth function comprising a function that calls the fourth function;
- and
- setting a stack frame type of a fifth stack frame to a second type when the second return address belongs to a return address set, a function pointed to by each return address in the return address set comprising a boundary function, a call function of the boundary function and a called function of the boundary function corresponding to different types of high-level programming languages, the fifth stack frame comprising a stack frame corresponding to the fifth function, the second type indicating that the fifth function comprising the boundary function, setting a stack frame type of a sixth stack frame to a third type, the sixth stack frame comprising a stack frame corresponding to a sixth function, the sixth function comprising a function that calls the fifth function, and the stack frame type of the sixth stack frame is different from the stack frame type of the fourth stack frame;
- or
- setting the stack frame type of the fifth stack frame to the first type when the second return address does not belong to the return address set, the fifth stack frame comprising the stack frame corresponding to the fifth function.
An unwind stack apparatus, comprising:
- a memory storing instructions;
- and
- at least one processor in communication with the memory, the at least one processor configured, upon execution of the instructions, to perform the following steps:
- obtaining a first program, the first program comprising a first function;
- in a process of calling a runtime library to run the first program, adding a second function and creating a call stack, the call stack comprising a first stack frame corresponding to the first function, a second stack frame corresponding to the second function, and a third stack frame corresponding to a third function, there being a call relationship between the first function and the second function, there being a call relationship between the second function and the third function, the third function is a function in the runtime library or a function in the first program, and a high-level programming language corresponding to the first function is different from a high-level programming language corresponding to the third function;
- and
- storing a first return address and a label corresponding to the first return address, the first return address comprising a return address comprised in a stack frame corresponding to a function that is executed later in the first function and the third function, the label corresponding to the first return address indicating a stack frame type of the first stack frame, a stack frame type of the second stack frame, and a stack frame type of the third stack frame, a stack frame type being related to a type of a high-level programming language of the runtime library.
A non-transitory computer-readable storage media storing computer instructions that configure at least one processor, upon execution of the instructions, to perform the following steps:
- obtaining a first program, the first program comprising a first function;
- in a process of calling a runtime library to run the first program, adding a second function and creating a call stack, the call stack comprising a first stack frame corresponding to the first function, a second stack frame corresponding to the second function, and a third stack frame corresponding to a third function, there being a call relationship between the first function and the second function, there being a call relationship between the second function and the third function, the third function is a function in the runtime library or a function in the first program, and a high-level programming language corresponding to the first function is different from a high-level programming language corresponding to the third function;
- and
- storing a first return address and a label corresponding to the first return address, the first return address comprising a return address comprised in a stack frame corresponding to a function that is executed later in the first function and the third function, the label corresponding to the first return address indicating a stack frame type of the first stack frame, a stack frame type of the second stack frame, and a stack frame type of the third stack frame, a stack frame type being related to a type of a high-level programming language of the runtime library.
Dependencies are inferred from the claim text.