CN113220334B - Program fault positioning method, terminal equipment and computer readable storage medium - Google Patents

Program fault positioning method, terminal equipment and computer readable storage medium Download PDF

Info

Publication number
CN113220334B
CN113220334B CN202110573162.4A CN202110573162A CN113220334B CN 113220334 B CN113220334 B CN 113220334B CN 202110573162 A CN202110573162 A CN 202110573162A CN 113220334 B CN113220334 B CN 113220334B
Authority
CN
China
Prior art keywords
function
target
program
target program
address
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110573162.4A
Other languages
Chinese (zh)
Other versions
CN113220334A (en
Inventor
董时舫
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
PAX Computer Technology Shenzhen Co Ltd
Original Assignee
PAX Computer Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by PAX Computer Technology Shenzhen Co Ltd filed Critical PAX Computer Technology Shenzhen Co Ltd
Priority to CN202110573162.4A priority Critical patent/CN113220334B/en
Publication of CN113220334A publication Critical patent/CN113220334A/en
Application granted granted Critical
Publication of CN113220334B publication Critical patent/CN113220334B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/53Decompilation; Disassembly

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application is applicable to the technical field of computers, and provides a program fault positioning method, a device, terminal equipment and a computer readable storage medium, wherein the method comprises the following steps: when a dead loop fault occurs in a target program, acquiring a first function of a breakpoint in the target program through an interrupt program; determining a return address corresponding to the first function in the target program; determining a relative call address of the first function in the target program according to a return address corresponding to the first function; determining a second function of the first function in the target program according to the relative call address of the first function in the target program; and locating the fault position of the target program according to the second function. By the method, the defect that the upper function of the called function cannot be acquired when the dead loop occurs in the public function in the prior art is overcome, and the accuracy of program dead loop fault positioning is improved.

Description

Program fault positioning method, terminal equipment and computer readable storage medium
Technical Field
The application belongs to the technical field of computers, and particularly relates to a program fault positioning method, a program fault positioning device, terminal equipment and a computer readable storage medium.
Background
The dead loop fault is that the program stays in a certain state all the time, and is not executed to a preset subsequent program under the appointed triggering condition, but the underlying system and the input and output equipment thereof are still in normal operation or normal operation state. The dead-loop fault not only can affect the normal operation of the program, but also can consume system resources. Therefore, eliminating the dead-cycle failure is a problem that needs to be solved.
In the prior art, an interrupt program is generally utilized to detect a dead loop fault, namely, interrupt is specifically triggered in the dead loop process, and the position of the dead loop fault is judged by acquiring the address of an interrupt breakpoint. However, when the dead loop code contains calls to common functions which take longer time, the accurate position of the dead loop fault still cannot be defined because the high probability of the address of the interrupt breakpoint falls in the common functions and the places where the common functions are called in the whole program are many.
Disclosure of Invention
The embodiment of the application provides a program fault positioning method, a program fault positioning device, terminal equipment and a computer readable storage medium, which can improve the accuracy of program endless loop fault positioning.
In a first aspect, an embodiment of the present application provides a program fault location method, including:
when a dead loop fault occurs in a target program, acquiring a first function of a breakpoint in the target program through an interrupt program;
determining a return address corresponding to the first function in the target program;
determining a relative call address of the first function in the target program according to a return address corresponding to the first function;
determining a second function of the first function in the target program according to the relative call address of the first function in the target program;
and locating the fault position of the target program according to the second function.
In the embodiment of the application, after determining the first function in which the interrupt occurs currently through the interrupt program, determining the return address of the first function, determining the relative call address of the first function in the target program according to the return address, and finally determining the upper call function (i.e. the second function) of the first function according to the relative call address. By the method, the defect that in the prior art, when dead circulation occurs in a public function, an accurate dead circulation part cannot be determined because a superior function of a called function cannot be acquired is overcome, and therefore the accuracy of program dead circulation fault positioning is improved.
In a possible implementation manner of the first aspect, the determining, according to a return address corresponding to the first function, a relative call address of the first function in the target program includes:
determining an absolute call address of the first function in a target memory according to a return address corresponding to the first function, wherein the target memory is a storage space for loading the target program in an operating system running the target program;
and determining the relative call address of the first function in the target program according to the absolute call address of the first function in the target memory.
In a possible implementation manner of the first aspect, the determining, according to a return address corresponding to the first function, an absolute call address of the first function in the target memory includes:
acquiring the instruction length of a target calling instruction, wherein the target calling instruction is an instruction used for calling the first function in the operating system;
and calculating the absolute call address of the first function in the target memory according to the return address corresponding to the first function and the instruction length.
In a possible implementation manner of the first aspect, the determining, according to an absolute call address of the first function in a target memory, a relative call address of the first function in the target program includes:
acquiring a starting address for loading the target program in the target memory;
and calculating the relative call address of the first function in the target program according to the absolute call address of the first function in the target memory and the starting address.
In a possible implementation manner of the first aspect, the determining, according to a relative call address of the first function in the target program, a second function to which the first function belongs in the target program includes:
generating disassembly codes of the target program;
searching an object function to which a relative call address of the first function in the object program belongs in the disassembled code;
the objective function is determined as the second function.
In a possible implementation manner of the first aspect, the locating the fault location of the target program according to the second function includes:
if the first function does not fall in the dead loop code body of the second function, determining a third function to which the second function belongs in the target program;
and positioning the fault position of the target program according to the third function until a preset condition is met.
In a possible implementation manner of the first aspect, the locating the fault location of the target program according to the second function includes:
if the first function falls in the dead loop code body of the second function, acquiring an absolute call address of the second function in a target memory, wherein the target memory is a storage space for loading the target program in an operating system running the target program;
and determining the fault position of the target program according to the absolute calling address of the second function in the target memory.
In a second aspect, an embodiment of the present application provides a program fault locating device, including:
the function acquisition unit is used for acquiring a first function of a breakpoint in the target program through an interrupt program when a dead loop fault occurs in the target program;
a return address determining unit, configured to determine a return address corresponding to the first function in the target program;
the call address determining unit is used for determining the relative call address of the first function in the target program according to the return address corresponding to the first function;
a function determining unit, configured to determine a second function to which the first function belongs in the target program according to a relative call address of the first function in the target program;
and the fault locating unit is used for locating the fault position of the target program according to the second function.
In a third aspect, an embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and capable of running on the processor, where the processor implements the program fault location method according to any one of the first aspect when executing the computer program.
In a fourth aspect, embodiments of the present application provide a computer readable storage medium, where a computer program is stored, where the computer program is executed by a processor to implement a program fault location method according to any one of the first aspects.
In a fifth aspect, embodiments of the present application provide a computer program product, which when run on a terminal device, causes the terminal device to perform the program fault localization method according to any one of the first aspects.
It will be appreciated that the advantages of the second to fifth aspects may be found in the relevant description of the first aspect, and are not described here again.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required for the embodiments or the description of the prior art will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flow chart of a program fault locating method according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a storage space provided in an embodiment of the present application;
FIG. 3 is a schematic diagram of a procedure for performing fault location according to an embodiment of the present application;
FIG. 4 is a block diagram of a program fault locating device according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of a terminal device provided in an embodiment of the present application.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system configurations, techniques, etc. in order to provide a thorough understanding of the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
It should be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
As used in this specification and the appended claims, the term "if" may be construed as "when..once" or "in response to a determination" or "in response to detection" depending on the context.
In addition, in the description of the present application and the appended claims, the terms "first," "second," "third," and the like are used merely to distinguish between descriptions and are not to be construed as indicating or implying relative importance.
Reference in the specification to "one embodiment" or "some embodiments" or the like means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," and the like in the specification are not necessarily all referring to the same embodiment, but mean "one or more but not all embodiments" unless expressly specified otherwise.
First, a technical background of a program fault positioning method provided by the embodiment of the present application is described.
A dead loop fault refers to a program staying in a certain state all the time, and under a stipulated trigger condition, the program is not executed to a preset subsequent flow, but the underlying system and its input and output devices (such as keys and serial ports) are still in normal operation or can be in normal operation.
Common functions refer to functions that provide a common basic service for numerous other higher-level functions and are called by these functions whenever they need to be.
A time consuming public function refers to a public function that takes a relatively long time from a single entry function to an exit function.
The multi-level nested call refers to a multi-level call relation formed by the nesting of a function calling the next-level function and the next-level function calling the next-level function.
In software running on a computer system, a system program or an application program sometimes has a dead-loop fault, and a location where the dead-loop fault occurs needs to be located. In the prior art, a break point address is generally collected by using an interrupt mechanism provided by a processor and an interrupt service routine provided by system software, so as to locate the occurrence position of a dead loop fault. But when the dead loop code contains calls to a common function, especially a time consuming common function, the collected breakpoint address falls within the common function with a high probability. However, a great deal of common functions are often called in the currently running program, so that the upper-level functions of the interrupted common functions also need to be found out to find out the dead loop code body, thereby determining the exact position of the dead loop fault.
The system programs or applications are typically written based on a high-level language (e.g., C language, c++ language, etc.). The functions in the high-level language are relatively independent code bodies, and the names of the upper-level functions of one function are generally not known. Therefore, when the endless loop code contains multiple levels of nested calls, the fault location cannot be located accurately.
In order to solve the above problems, an embodiment of the present application provides a program fault location method to solve the problem of fault location of a dead loop code including a multi-level nested call. A schematic flow chart of a program fault locating method provided in an embodiment of the present application may refer to fig. 1, and by way of example and not limitation, the method may include the following steps:
s101, when a dead loop fault occurs in the target program, acquiring a first function of the breakpoint in the target program through the interrupt program.
The target program in the embodiment of the present application refers to a program that an operating system is currently running. The target program may be a system program or an application program.
The interrupt program is based on the processor of the operating system, the interrupt service program provided by the system software, through which the breakpoint address at the time of interrupt triggering can be collected. The first function to which the breakpoint address belongs in the target program can be retrieved against the design and data structure of the operating system.
Since there may be multiple locations in the object program to call the first function, and there is only one breakpoint location where the interrupt occurs, it is necessary to determine which function the current caller of the first function (i.e., the upper level function) is by using the method in S102-S104 described below.
S102, determining a return address corresponding to the first function in the target program.
The concepts of absolute and relative addresses in the embodiments of the present application need to be presented herein. After one software module is compiled, the software module becomes a relatively independent whole; the relative address refers to an offset address of one address in the software module relative to the beginning of the module. The object program, in this case, refers to the selected software module. When the target program needs to be run, the operating system loads the target program into the running space allocated for the target program, that is, runs the target program in the running space. When a certain public function needs to be called in the target program, the processor jumps to the running space where the public function is located to run. The actual running address after the code is loaded into the running space is called the absolute address of the code.
Exemplary, referring to fig. 2, a schematic diagram of a storage space provided in an embodiment of the present application is shown. As shown in fig. 2 (a), the code aaa in the common function has an offset address of 02500 with respect to the start of the module, that is, a relative address of 02500; similarly, the relative addresses in the belonging module before the PUBLIC function PUBLIC is unloaded to run are 02000 to 03000. As shown in fig. 2 (b), the running space allocated for the target program in the memory of the operating system has addresses 10000 to 90000. Then the code aaa is currently running with a corresponding running space address of 10000+02500=12500, i.e. the absolute address of code aaa in the running space is 12500. The absolute address and the relative address described above are examples, and the numerical values are not particularly limited.
The return address in the embodiment of the present application refers to an absolute address of an instruction in the target memory that is continuously executed by the target program after returning from the first function. The target memory is a running space for running the target program in the memory of the operating system.
For a fixed compiler, it follows fixed or code line-specified rules when compiling function parameter passes and call procedures, such as: before a function is called, the entry parameters are written into a fixed register or pushed onto the current stack, or a combination of the two; writing the return address when executing the function into a specific address register or pushing the return address into a stack, and agreeing to be one of the two; the stacking of entry parameters and return addresses also follows a contracted order, such as: the return address is pushed first and then the entry parameters are pushed. Thus, according to the compilation rules, lower level language (e.g., assembly language) code may be embedded in the called first function to obtain the return address of the first function.
S103, determining the relative call address of the first function in the target program according to the return address corresponding to the first function.
In one embodiment, the step of S103 may include:
determining an absolute call address of the first function in the target memory according to the return address corresponding to the first function; and determining the relative call address of the first function in the target program according to the absolute call address of the first function in the target memory.
The relative call address refers to the relative address of the target call instruction, and the absolute call address refers to the absolute address of the target call instruction. The target call instruction is an instruction in the target program for calling the first function. For example: in the X86 system, the call instruction is call.
Optionally, the determining manner of the absolute call address of the first function in the target memory may include:
acquiring the instruction length of a target call instruction; and calculating the absolute call address of the first function in the target memory according to the return address corresponding to the first function and the instruction length.
Specifically, subtracting the instruction length of the target call instruction from the return address corresponding to the first function to obtain the absolute call address of the first function in the target memory. For example: in an ARM 32-bit system, the length of a machine instruction for calling a function is 4, and then: call address = return address-4.
Optionally, the determining manner of the relative call address of the first function in the target program may include:
acquiring a starting address of a loading target program in a target memory; and calculating the relative call address of the first function in the target program according to the absolute call address and the initial address of the first function in the target memory.
Specifically, the starting address of the target program to which the breakpoint belongs, which is loaded into the target memory, is obtained through the interrupt program; subtracting the initial address from the absolute call address of the first function in the target memory to obtain the relative call address of the first target function in the target program.
If the target program is a system program and the target program is loaded into the memory together with the operating system kernel as a part of the operating system kernel, the starting address is generally the starting address of the entire kernel loaded; if the target program is dynamically loaded into the memory by the operating system, the starting address is the starting address of the loaded target program. If the target program is an application program, the target program is put into a spare temporary continuous logic memory when being loaded into the memory by the operating system, and then is operated in a new process mode, and the starting address of the target program is the starting address of the loaded process.
In practice, address acquisition program code implemented in a lower level language may be embedded at the beginning of the first function in the target program. And acquiring the return address of the first function through an address acquisition program, and further acquiring the relative call address of the first function. The obtained relative call address can be output through an output program and displayed to a user. The address acquisition procedure may be embedded after the return address acquisition procedure or may be placed before the output procedure.
The processing flow of the address acquisition program may include:
1) One common register is selected as working register 1 and the other common register is selected as working register 2.
2) The current content of the working register is pushed to backup the original value of the working register.
3) The address of the global variable ai is stored into the working register 1.
Here, the value of the array index i should be determined according to the traced function layer number. In principle, the values of the different functional layers should be different so that the values do not overlap each other. The function i at the lowest layer may be set to 0, and i at the next upper layer increases by one in turn.
4) According to the mode of writing the return address when the compiler calls the function, the following assignment processing is carried out:
if the return address is written to a specific address register, the value of that address register is assigned to the working register 2.
If the return address is pushed onto the stack, the value of the pushed return address is read from the corresponding offset in the stack into the working register 2.
5) The absolute call address is calculated from the return address in the working register 2 and is restored in the working register 2.
6) The value of the working register 2 is stored in the working register 1 ai.
7) And popping the work register value which is just pushed onto the stack to restore the original value of the work register.
8) And converting the absolute call address in A [ i ] into a relative call address.
9) Address information is output.
For example, assuming that the hardware platform is an ARM-series CPU (in which a return address is written into a specific address register lr), the first function located is_delay_us (), then an address acquisition program is embedded at the start position of_delay_us (), as follows:
s104, determining a second function of the first function in the target program according to the relative call address of the first function in the target program.
Optionally, the determining manner of the second function may include:
generating disassembly codes of the target program; searching a target function to which a relative call address of the first function in the target program belongs in the disassembled code; an objective function is determined as a second function.
Usually, the relative address of the code is displayed in the disassembled code, so that the second function to which the first function belongs can be determined according to the code range by searching the disassembled code for the position of the relative call address of the first function and then determining the code range in which the position is located.
Illustratively, as shown below, is a piece of disassembled code of a system program, with each left-most 8 characters of a line being the relative address of the code:
200ae1a0<_delay_us>:
200ae1a0:e24dd008 sub sp,sp,#8;0x8
200ae1a4:e92d0006 stmdb sp!,{r1,r2}
200ae1a8:e59f1078 ldr r1,[pc,#120];200ae228<.text+0xae228>
200ae1ac:e24e2004 sub r2,lr,#4;0x4
200ae1b0:e5812000 str r2,[r1]
200ae1b4:e8bd0006 ldmia sp!,{r1,r2}
200ae1b8:e3a01000 mov r1,#0;0x0
200ae1bc:e58d1004 str r1,[sp,#4]
200ae1c0:e58d1000 str r1,[sp]
200ae1c4:e58d1004 str r1,[sp,#4]
200ae1c8:e59d3004 ldr r3,[sp,#4]
200ae1cc:e59f2050 ldr r2,[pc,#80];200ae224<.text+0xae224>
200ae1d0:e1500003 cmp r0,r3
200ae1d4:e5820000 str r0,[r2]
200ae1d8:9a00000f bls 200ae21c<_delay_us+0x7c>
200ae1dc:e58d1000 str r1,[sp]
200ae1e0:e59d3000 ldr r3,[sp]
200ae1e4:e3530010 cmp r3,#16;0x10
200ae1e8:8a000005 bhi 200ae204<_delay_us+0x64>
200ae1ec:e59d3000 ldr r3,[sp]
200ae1f0:e2833001 add r3,r3,#1;0x1
200ae1f4:e58d3000 str r3,[sp]
200ae1f8:e59d2000 ldr r2,[sp]
200ae1fc:e3520010 cmp r2,#16;0x10
200ae200:9afffff9 bls 200ae1ec<_delay_us+0x4c>
200ae204:e59d3004 ldr r3,[sp,#4]
200ae208:e2833001 add r3,r3,#1;0x1
200ae20c:e58d3004 str r3,[sp,#4]
200ae210:e59d2004 ldr r2,[sp,#4]
200ae214:e1500002 cmp r0,r2
200ae218:8affffef bhi 200ae1dc<_delay_us+0x3c>
200ae21c:e28dd008 add sp,sp,#8;0x8
200ae220:e12fff1e bx lr
200ae224:2025534c eorcs r5,r5,ip,asr#6
200ae228:20255354 eorcs r5,r5,r4,asr r3
200ae22c<DelayUs>:
200ae22c:e52de004 str lr,[sp,#-4]!
200ae230:ebffffda bl 200ae1a0<_delay_us>
200ae234:e49de004 ldr lr,[sp],#4
200ae238:eaffff8d b 200ae074<GetMs>
through the steps S101 to S104, address information is output:
the outputted first set of breakpoint information:
Interruped APP:Kernel
Relative InterrupedAddress:200ae208
Relative CallAddress0:200ae230
second set of breakpoint information:
Interruped APP:Kernel
Relative InterrupedAddress:200ae1f8
Relative CallAddress0:200ae230
third set of breakpoint information:
Interruped APP:Kernel
Relative InterrupedAddress:200ae1fc
Relative CallAddress0:200ae230
in the breakpoint information, the term "interconnected APP: kernel" refers to the name of the located target program, kernel, "Relative InterrupedAddress" refers to the relative address of the breakpoint, and "Relative CallAddress0" refers to the determined relative call address of the first function.
Specifically, from the breakpoint addresses (200 ae208, 200ae1f8, 200ae1 fc) and the disassembly code of the target program, it can be seen that these addresses are all located within the code body of the function_delay_us (), so it can be judged that the program continues to run within the function_delay_us (), i.e., the first function is_delay_us ().
Next, the relative call address (200 ae 230) of the first function is obtained according to the method in S102-S104, and it can be seen that the address falls within the code body range of the function DelayUs (), so the name of the second function to which the first function belongs is DelayUs.
S105, locating the fault position of the target program according to the second function.
In one embodiment, it is checked whether the first function falls within the dead loop code body of the second function, and it is determined whether an accurate fault location is found based on the check result. Dead loop code volumes typically come in the form of loop structures in which the number of loops is indefinite, may be infinitely large or may take infinitely long, such as loop volumes formed by statements such as for, while, goto in the C language.
Specifically, the implementation of S105 may include the following two cases:
I. the first function does not fall within the dead loop code body of the second function.
The so-called first function does not fall within the dead loop code body of the second function, including the following: the self code body of the second function does not exist a circulating code body; at least one loop code body exists in the own code body of the second function, but the first function is not contained by any loop code body; at least one loop code body exists in the own code body of the second function, and the first function is contained by one loop code body, but the loop times of the loop code body are definite, limited and can be rapidly operated to finish.
Determining a third function to which the second function belongs in the target program; and positioning the fault position of the target program according to the third function until a preset condition is met.
The method of determining the third function to which the second function belongs in the target program can be referred to as steps S102-S105. Specifically, a lower language address acquisition program may be embedded in the second function to acquire the relative call address of the second function. Continuing with the example in S104, where the second function is Delayus (), still a common function, then an address acquisition procedure is embedded at the beginning of Delayus (), as follows:
void DelayUs(uint us)
{
the following is an address acquisition procedure for acquiring the relative call address of the previous stage
__ asm ("stmdb sp +| { r1, r2 }); r1, r2 are chosen as working registers and pushed onto the stack
__ asm ("LDR r1, =a"); the term// and the following terms are addresses taking the global variable ai where i=1
__asm("ADD r1,r1,#4");
__ asm ("sub 2, lr, # 4"); calculating call addresses from return addresses
__ asm ("STR r2, [ r1 ]"); writing/calling address values to global variables ai
__ asm ("ldmia sp |, { r1, r2 }); value of work register is restored by means of// pop
The following is the original code
_delay_us(us);
GetMs();
}
The upper level calling function (i.e., the third function) of the second function can be obtained by the address acquisition program, and then the fault location of the target program is located according to the third function (i.e., whether the second function falls within the dead loop code body of the third function is checked). And sequentially circulating until the preset condition is met.
The preset conditions in the embodiment of the application are as follows: the current function falls within the dead loop code body of the upper level function to which the current function belongs.
II. The first function falls within the dead loop code body of the second function.
Acquiring an absolute call address of the second function in the target memory; and determining the fault position of the target program according to the absolute call address of the second function in the target memory.
Exemplary, referring to fig. 3, a schematic flow chart of implementation of program fault location is provided in an embodiment of the present application. As shown in fig. 3, the interrupt service routine provided by the running system software locates the public function (i.e., the first function) to which the breakpoint belongs; embedding an address acquisition program in the located public function; outputting address information; generating disassembly codes of the target program; determining a superior function (namely a second function) of the current public function according to the address information and the disassembly code; checking whether the current public function falls in the dead loop code body of the upper function of the current public function; if yes, stopping positioning; if not, continuing to embed the address acquisition program in the upper function.
In the embodiment of the application, the relative call address of the positioned function is acquired by embedding the low-level language code in the high-level language code, so that the problem that the call address of the function of the upper level is difficult to acquire in the function by adopting the high-level language alone is solved, and further, the dead loop part is accurately and efficiently positioned. In addition, the method provided by the embodiment of the application does not need to add a large number of debug sentences, does not need to carry out a large number of revisions on the original code, and has the advantages of small code modification quantity, small influence on the original running condition of the program and higher positioning efficiency.
It should be understood that the sequence number of each step in the foregoing embodiment does not mean that the execution sequence of each process should be determined by the function and the internal logic of each process, and should not limit the implementation process of the embodiment of the present application in any way.
Corresponding to the program failure positioning method described in the above embodiments, fig. 4 is a block diagram of the program failure positioning device provided in the embodiment of the present application, and for convenience of explanation, only the portions related to the embodiment of the present application are shown.
Referring to fig. 4, the apparatus includes:
the function obtaining unit 41 is configured to obtain, when a dead loop fault occurs in a target program, a first function to which a breakpoint belongs in the target program by interrupting the program.
A return address determining unit 42, configured to determine a return address corresponding to the first function in the target program.
And the call address determining unit 43 is configured to determine a relative call address of the first function in the target program according to a return address corresponding to the first function.
A function determining unit 44, configured to determine a second function to which the first function belongs in the target program according to a relative call address of the first function in the target program.
A fault locating unit 45, configured to locate a fault location of the target program according to the second function.
Optionally, the call address determining unit 43 includes:
the absolute address determining module is used for determining an absolute call address of the first function in a target memory according to a return address corresponding to the first function, wherein the target memory is a storage space for loading the target program in an operating system running the target program.
And the relative address determining module is used for determining the relative call address of the first function in the target program according to the absolute call address of the first function in the target memory.
Optionally, the absolute address determining module is further configured to:
acquiring the instruction length of a target calling instruction, wherein the target calling instruction is an instruction used for calling the first function in the operating system; and calculating the absolute call address of the first function in the target memory according to the return address corresponding to the first function and the instruction length.
Optionally, the relative address determining module is further configured to:
acquiring a starting address for loading the target program in the target memory; and calculating the relative call address of the first function in the target program according to the absolute call address of the first function in the target memory and the starting address.
Optionally, the function determining unit 44 is further configured to:
generating disassembly codes of the target program; searching an object function to which a relative call address of the first function in the object program belongs in the disassembled code; the objective function is determined as the second function.
Optionally, the fault location unit 45 is further configured to:
if the first function does not fall in the dead loop code body of the second function, determining a third function to which the second function belongs in the target program; and positioning the fault position of the target program according to the third function until a preset condition is met.
Optionally, the fault location unit 45 is further configured to:
if the first function falls in the dead loop code body of the second function, acquiring an absolute call address of the second function in a target memory, wherein the target memory is a storage space for loading the target program in an operating system running the target program; and determining the fault position of the target program according to the absolute calling address of the second function in the target memory.
It should be noted that, because the content of information interaction and execution process between the above devices/units is based on the same concept as the method embodiment of the present application, specific functions and technical effects thereof may be referred to in the method embodiment section, and will not be described herein again.
In addition, the program fault locating device shown in fig. 4 may be a software unit, a hardware unit, or a unit combining soft and hard, which are built in an existing terminal device, may be integrated into the terminal device as an independent pendant, or may exist as an independent terminal device.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-described division of the functional units and modules is illustrated, and in practical application, the above-described functional distribution may be performed by different functional units and modules according to needs, i.e. the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-described functions. The functional units and modules in the embodiment may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit, where the integrated units may be implemented in a form of hardware or a form of a software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working process of the units and modules in the above system may refer to the corresponding process in the foregoing method embodiment, which is not described herein again.
Fig. 5 is a schematic structural diagram of a terminal device provided in an embodiment of the present application. As shown in fig. 5, the terminal device 5 of this embodiment includes: at least one processor 50 (only one processor is shown in fig. 5), a memory 51 and a computer program 52 stored in the memory 51 and executable on the at least one processor 50, the processor 50 implementing the steps in any of the various program fault localization method embodiments described above when executing the computer program 52.
The terminal equipment can be computing equipment such as a desktop computer, a notebook computer, a palm computer, a cloud server and the like. The terminal device may include, but is not limited to, a processor, a memory. It will be appreciated by those skilled in the art that fig. 5 is merely an example of the terminal device 5 and is not meant to be limiting as the terminal device 5, and may include more or fewer components than shown, or may combine certain components, or different components, such as may also include input-output devices, network access devices, etc.
The processor 50 may be a central processing unit (Central Processing Unit, CPU), the processor 50 may also be other general purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), off-the-shelf programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 51 may in some embodiments be an internal storage unit of the terminal device 5, such as a hard disk or a memory of the terminal device 5. The memory 51 may in other embodiments also be an external storage device of the terminal device 5, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card) or the like, which are provided on the terminal device 5. Further, the memory 51 may also include both an internal storage unit and an external storage device of the terminal device 5. The memory 51 is used for storing an operating system, application programs, boot loader (BootLoader), data, other programs, etc., such as program codes of the computer program. The memory 51 may also be used to temporarily store data that has been output or is to be output.
Embodiments of the present application also provide a computer readable storage medium storing a computer program which, when executed by a processor, implements steps that may implement the various method embodiments described above.
The present embodiments provide a computer program product which, when run on a terminal device, causes the terminal device to perform steps that enable the respective method embodiments described above to be implemented.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the present application implements all or part of the flow of the method of the above embodiments, and may be implemented by a computer program to instruct related hardware, where the computer program may be stored in a computer readable storage medium, where the computer program, when executed by a processor, may implement the steps of each of the method embodiments described above. Wherein the computer program comprises computer program code which may be in source code form, object code form, executable file or some intermediate form etc. The computer readable medium may include at least: any entity or device capable of carrying computer program code to an apparatus/terminal device, recording medium, computer Memory, read-Only Memory (ROM), random access Memory (RAM, random Access Memory), electrical carrier signals, telecommunications signals, and software distribution media. Such as a U-disk, removable hard disk, magnetic or optical disk, etc. In some jurisdictions, computer readable media may not be electrical carrier signals and telecommunications signals in accordance with legislation and patent practice.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and in part, not described or illustrated in any particular embodiment, reference is made to the related descriptions of other embodiments.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus/terminal device and method may be implemented in other manners. For example, the apparatus/terminal device embodiments described above are merely illustrative, e.g., the division of the modules or units is merely a logical function division, and there may be additional divisions in actual implementation, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection via interfaces, devices or units, which may be in electrical, mechanical or other forms.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
The above embodiments are only for illustrating the technical solution of the present application, and are not limiting; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present application, and are intended to be included in the scope of the present application.

Claims (8)

1. A program failure positioning method, characterized by comprising:
when a dead loop fault occurs in a target program, acquiring a first function of a breakpoint in the target program through an interrupt program;
determining a return address corresponding to the first function in the target program; the return address refers to an absolute address of an instruction which is continuously executed by the target program in a target memory after the return from the first function;
determining a relative call address of the first function in the target program according to a return address corresponding to the first function;
determining a second function of the first function in the target program according to the relative call address of the first function in the target program;
locating a fault location of the target program according to the second function;
the locating the fault location of the target program according to the second function includes:
if the first function does not fall in the dead loop code body of the second function, determining a third function to which the second function belongs in the target program;
positioning the fault position of the target program according to the third function until a preset condition is met;
if the first function falls in the dead loop code body of the second function, acquiring an absolute call address of the second function in a target memory, wherein the target memory is a storage space for loading the target program in an operating system running the target program;
and determining the fault position of the target program according to the absolute calling address of the second function in the target memory.
2. The program fault locating method as claimed in claim 1, wherein said determining a relative call address of the first function in the target program according to a return address corresponding to the first function includes:
determining an absolute call address of the first function in a target memory according to a return address corresponding to the first function, wherein the target memory is a storage space for loading the target program in an operating system running the target program;
and determining the relative call address of the first function in the target program according to the absolute call address of the first function in the target memory.
3. The program fault locating method as claimed in claim 2, wherein said determining an absolute call address of the first function in the target memory according to the return address corresponding to the first function comprises:
acquiring the instruction length of a target calling instruction, wherein the target calling instruction is an instruction used for calling the first function in the operating system;
and calculating the absolute call address of the first function in the target memory according to the return address corresponding to the first function and the instruction length.
4. The program fault location method as claimed in claim 2, wherein said determining a relative call address of said first function in said target program based on an absolute call address of said first function in a target memory comprises:
acquiring a starting address for loading the target program in the target memory;
and calculating the relative call address of the first function in the target program by the absolute call address of the first function in the target memory and the starting address.
5. The program trouble shooting method according to claim 1, wherein the determining a second function to which the first function belongs in the target program based on a relative call address of the first function in the target program includes:
generating disassembly codes of the target program;
searching an object function to which a relative call address of the first function in the object program belongs in the disassembled code;
the objective function is determined as the second function.
6. A program failure positioning device, characterized by comprising:
the function acquisition unit is used for acquiring a first function of a breakpoint in the target program through an interrupt program when a dead loop fault occurs in the target program;
a return address determining unit, configured to determine a return address corresponding to the first function in the target program; the return address refers to an absolute address of an instruction which is continuously executed by the target program in a target memory after the return from the first function;
the call address determining unit is used for determining the relative call address of the first function in the target program according to the return address corresponding to the first function;
a function determining unit, configured to determine a second function to which the first function belongs in the target program according to a relative call address of the first function in the target program;
a fault locating unit, configured to locate a fault location of the target program according to the second function;
the fault locating unit is used for:
if the first function does not fall in the dead loop code body of the second function, determining a third function to which the second function belongs in the target program; positioning the fault position of the target program according to the third function until a preset condition is met;
if the first function falls in the dead loop code body of the second function, acquiring an absolute call address of the second function in a target memory, wherein the target memory is a storage space for loading the target program in an operating system running the target program; and determining the fault position of the target program according to the absolute calling address of the second function in the target memory.
7. A terminal device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the method according to any of claims 1 to 5 when executing the computer program.
8. A computer readable storage medium storing a computer program, characterized in that the computer program when executed by a processor implements the method according to any one of claims 1 to 5.
CN202110573162.4A 2021-05-25 2021-05-25 Program fault positioning method, terminal equipment and computer readable storage medium Active CN113220334B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110573162.4A CN113220334B (en) 2021-05-25 2021-05-25 Program fault positioning method, terminal equipment and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110573162.4A CN113220334B (en) 2021-05-25 2021-05-25 Program fault positioning method, terminal equipment and computer readable storage medium

Publications (2)

Publication Number Publication Date
CN113220334A CN113220334A (en) 2021-08-06
CN113220334B true CN113220334B (en) 2024-04-16

Family

ID=77099476

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110573162.4A Active CN113220334B (en) 2021-05-25 2021-05-25 Program fault positioning method, terminal equipment and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN113220334B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2017107576A1 (en) * 2015-12-25 2017-06-29 华为技术有限公司 Method and device for generating fault record of processor
CN107220175A (en) * 2017-05-08 2017-09-29 百富计算机技术(深圳)有限公司 Application program endless loop localization method, device, computer equipment and storage medium
CN109766273A (en) * 2018-12-27 2019-05-17 百富计算机技术(深圳)有限公司 Localization method, device, computer equipment and the storage medium of endless loop
CN110750450A (en) * 2019-09-19 2020-02-04 深圳震有科技股份有限公司 Method, device and system for positioning software endless loop and storage medium
CN110928778A (en) * 2019-11-19 2020-03-27 百富计算机技术(深圳)有限公司 Endless loop positioning method and device, computer equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2017107576A1 (en) * 2015-12-25 2017-06-29 华为技术有限公司 Method and device for generating fault record of processor
CN107220175A (en) * 2017-05-08 2017-09-29 百富计算机技术(深圳)有限公司 Application program endless loop localization method, device, computer equipment and storage medium
CN109766273A (en) * 2018-12-27 2019-05-17 百富计算机技术(深圳)有限公司 Localization method, device, computer equipment and the storage medium of endless loop
CN110750450A (en) * 2019-09-19 2020-02-04 深圳震有科技股份有限公司 Method, device and system for positioning software endless loop and storage medium
CN110928778A (en) * 2019-11-19 2020-03-27 百富计算机技术(深圳)有限公司 Endless loop positioning method and device, computer equipment and storage medium

Also Published As

Publication number Publication date
CN113220334A (en) 2021-08-06

Similar Documents

Publication Publication Date Title
US8769504B2 (en) Method and apparatus for dynamically instrumenting a program
CN110287702B (en) Binary vulnerability clone detection method and device
CN106933733B (en) Method and device for determining memory leak position
US9753730B2 (en) Decoding instructions from multiple instructions sets
CN112015491B (en) Method, device and computer storage medium for realizing function jump
US20190087208A1 (en) Method and apparatus for loading elf file of linux system in windows system
CN109271789B (en) Malicious process detection method and device, electronic equipment and storage medium
US9639451B2 (en) Debugger system, method and computer program product for utilizing hardware breakpoints for debugging instructions
US7539979B1 (en) Method and system for forcing context-switch during mid-access to non-atomic variables
CN109582542B (en) Method for dumping core of embedded system
CN106502707B (en) Code generation method and device
CN111338864B (en) Memory problem detection method, device, computer equipment and storage medium
CN113220334B (en) Program fault positioning method, terminal equipment and computer readable storage medium
CN116521414A (en) Fault code positioning method, cloud server, system and storage medium
US9182990B1 (en) Method and apparatus for detecting execution of unsupported instructions while testing multiversioned code
CN108959915B (en) Rootkit detection method, rootkit detection device and server
US20110144958A1 (en) Detection of design redundancy
CN111190658A (en) System for supporting dynamic loading of application program on SoC (system on chip) without MMU (memory management unit) based on-chip execution
US8359456B2 (en) Generating random addresses for verification of distributed computerized devices
CN113031956A (en) Program compiling method and device and program running method and device
CN112527660B (en) Static detection method and device for codes
JP2016029547A (en) Execution module generation apparatus and electronic control unit
US11989572B2 (en) Computer system enabled with runtime software module tracking
CN112612471B (en) Code processing method, device, equipment and storage medium
CN112860224B (en) Function execution environment construction method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant