CN113342563A - Method and device for positioning source code during program operation error and computing equipment - Google Patents

Method and device for positioning source code during program operation error and computing equipment Download PDF

Info

Publication number
CN113342563A
CN113342563A CN202110701031.XA CN202110701031A CN113342563A CN 113342563 A CN113342563 A CN 113342563A CN 202110701031 A CN202110701031 A CN 202110701031A CN 113342563 A CN113342563 A CN 113342563A
Authority
CN
China
Prior art keywords
function
name
error
instruction
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.)
Pending
Application number
CN202110701031.XA
Other languages
Chinese (zh)
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.)
Wuhan Deepin Technology Co ltd
Original Assignee
Wuhan Deepin Technology 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 Wuhan Deepin Technology Co ltd filed Critical Wuhan Deepin Technology Co ltd
Priority to CN202110701031.XA priority Critical patent/CN113342563A/en
Publication of CN113342563A publication Critical patent/CN113342563A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0703Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
    • G06F11/079Root cause analysis, i.e. error or fault diagnosis

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Health & Medical Sciences (AREA)
  • Biomedical Technology (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a method for positioning source codes when a program runs wrongly, which is executed in a reduced instruction set computing device and comprises the following steps: acquiring an address of an error instruction according to a program name of a program and error prompt information obtained from a corresponding call stack when the program runs wrongly; according to the address of the error instruction, acquiring the name of a mixed name function of a function where the error instruction is located and the line number of a source code corresponding to the error instruction in a source file of the source code; and if the name of the mixing function of the function where the error instruction is located is different from the name of the mixing function of the error function, updating the address of the error instruction, and repeating the steps of obtaining the name of the mixing function and the number of lines until the obtained name of the mixing function is the same as the name of the mixing function of the error function, and taking the obtained number of lines as the number of lines of the error source code in the target file. The invention also discloses a corresponding device, a computing device and a readable storage medium. The method for positioning the source code can quickly and accurately position the error position in the source code.

Description

Method and device for positioning source code during program operation error and computing equipment
This application is a divisional application of the invention patent application 2021104569350 filed on 27/4/2021.
Technical Field
The present invention relates to the field of computers, and in particular, to a method, an apparatus, a computing device, and a readable storage medium for locating a source code when a program runs incorrectly.
Background
The computer program is obtained by compiling source code written by a developer into an executable program including binary instructions by software such as a compiler. Developers often use C, C + + or the like when writing source code. When writing a C or C + + program, a developer typically calls some functions in a development library (e.g., glibc, stdc + +, etc. developed by the C or C + + language) to implement some functions, such as string processing, file processing, etc., and sometimes also uses macros in a third-party library. Where the call stack formed using macros is different from the call stack formed by calling functions.
For example, when a function f1 in the source code file a.cpp calls a function f2 in an x.cpp file in the development library, the current call stack of the program is an f2 function, the corresponding source code file is x.cpp, and the caller is an f1 function. But when the function f1 in the source code file a.cpp uses the macro m1 in the y.cpp file in the development library, the current call stack of the program is still in the function f1, except that the corresponding source code file is also the y.cpp in the development library.
Thus, if the program crashes while running the macro code m1, the source code file y.cpp in the development library is located according to the instruction address in the call stack, although the call stack shows the function f1 as an error. That is, if the program makes an error while running the macro code m1, the erroneous source code in the function f1 cannot be located based on the instruction address in the call stack.
In this case, based on the current prior art, only an attempt can be made to add a breakpoint into the source code program, and the problem is reproduced by a single-step execution manner, so as to find out the source code with an error in the source code file. Obviously, this method is time consuming, labor intensive and costly. Moreover, for those probabilistic program errors, since they are difficult to reproduce, the error position in the program source code file cannot be found at all.
Disclosure of Invention
To this end, the present invention provides a method, apparatus, computing device and readable storage medium for locating source code when a program runs in error in an attempt to solve, or at least alleviate, the problems identified above.
According to one aspect of the invention, there is provided a method of locating source code in the event of a program execution error, adapted to be executed in a reduced instruction set computing device, the method comprising: acquiring an address of an error instruction according to a program name of a program and error prompt information acquired from a corresponding call stack when the program runs wrongly, wherein the error prompt information comprises a function name of the error function and an offset of the error instruction, and the offset of the error instruction is the offset of the address of the error instruction relative to the address of the error function; according to the address of the error instruction, acquiring the mixed name function name of the function where the error instruction is located and the line number of the source code corresponding to the error instruction in the source file of the function, wherein the mixed name function name of the function where the error instruction is located is the name of the function name mixed name of the function where the error instruction is located; and if the name of the mixing function of the function where the error instruction is located is different from the name of the mixing function of the error function, updating the address of the error instruction, and repeating the steps of obtaining the name of the mixing function and the number of lines until the obtained name of the mixing function is the same as the name of the mixing function of the error function, wherein the obtained number of lines is used as the number of lines of an error source code in a target file, and the target file is a source file corresponding to the program.
Optionally, in the method for locating a source code when a program runs incorrectly according to the present invention, in the step of updating the address of the faulty instruction, the address of the faulty instruction is updated by subtracting a preset value from the address of the faulty instruction, where the preset value is a number of bytes occupied by one instruction.
Optionally, in the method for locating a source code when a program runs an error according to the present invention, the step of obtaining an address of an error instruction according to a program name of the program and error hint information obtained from a call stack corresponding to the program when the program runs the error includes: acquiring the address of the error function according to the program name of the program and the function name of the error function; and acquiring the address of the error instruction according to the address of the error function and the offset of the error instruction.
Optionally, in the method for locating a source code when a program runs an error according to the present invention, the step of obtaining an address of an error function according to a program name of the program and a function name of the error function includes: acquiring a target mixed-name function name and a function address corresponding to the target mixed-name function name according to the program name of the program and the function name of the error function, wherein the target mixed-name function name is the mixed-name function name containing the function name; acquiring a function signature of a function corresponding to the target mixed name function name according to the target mixed name function name; and if the function signature of the function corresponding to the target mixed name function name is the same as the function signature of the error function, taking the address of the function corresponding to the target mixed name function name as the address of the error function.
Optionally, in the method for locating a source code when a program runs an error according to the present invention, the step of obtaining a target mixed-name function name and an address of a function corresponding to the target mixed-name function name according to the program name of the program and the function name of the error function includes: acquiring a symbol table in an executable file according to the program name of the program; and acquiring the target mixed name function name and the address of the function corresponding to the target mixed name function name from the symbol table according to the function name of the error function.
Alternatively, in the method of locating a source code when a program runs in error according to the present invention, in the step of obtaining the symbol table in the executable file according to the program name of the program, the symbol table in the executable file is obtained by a parsing file tool adapted to print out the symbol table in the executable file according to the inputted program name.
Alternatively, in the method of locating a source code when a program runs an error according to the present invention, in the step of acquiring the target mixed-name function name and the address of the function corresponding to the target mixed-name function name from the symbol table based on the function name of the function in error, the target mixed-name function name and the address of the function corresponding to the target mixed-name function name are acquired from the symbol table by a lookup character string tool adapted to print out a line containing the input character string in the symbol table based on the input character string.
Alternatively, in the method of locating source code when a program runs an error according to the present invention, in the step of obtaining a function signature of a function corresponding to the target mix-name function name from the target mix-name function name, the function signature of the function corresponding to the target mix-name function name is obtained by a decomplexing tool adapted to output the function signature of the function from the mix-name function name of the function.
Optionally, in the method for locating a source code when a program runs incorrectly according to the present invention, in the step of obtaining, according to an address of the error instruction, a name of a mixed-name function of a function where the error instruction is located and a number of lines of a source code corresponding to the error instruction in a source file thereof, the name of the mixed-name function of the function where the error instruction is located and the number of lines of the source code corresponding to the error instruction in the source file thereof are obtained by an address location tool, and the address location tool is adapted to convert the address of the instruction into the name of the mixed-name function of the function where the instruction is located and the number of lines of the source code corresponding to the instruction in the source file thereof.
According to yet another aspect of the present invention, there is provided an apparatus for locating source code when a program runs in error, the apparatus residing in a reduced instruction set computing device, the apparatus comprising: the first obtaining module is suitable for obtaining an address of an error instruction according to a program name of a program and error prompt information obtained from a corresponding call stack when the program runs wrongly, wherein the error prompt information comprises a function name of the error function and an offset of the error instruction, and the offset of the error instruction is the offset of the address of the error instruction relative to the address of the error function; the second acquisition module is suitable for acquiring the mixed name function name of the function where the error instruction is located and the line number of the source code corresponding to the error instruction in the source file of the function according to the address of the error instruction, wherein the mixed name function name of the function where the error instruction is located is the name of the function where the error instruction is located after the function name is mixed; and the updating module is suitable for updating the address of the error instruction if the name of the mixing function of the function where the error instruction is located is different from the name of the mixing function of the error function, repeating the execution action of the second acquiring module until the acquired name of the mixing function is the same as the name of the mixing function of the error function, and taking the acquired line number as the line number of the error source code in the target file which is the source file corresponding to the program.
According to yet another aspect of the invention, there is provided a computing device comprising: at least one processor; and a memory storing program instructions, wherein the program instructions are configured to be executed by the at least one processor, the program instructions comprising instructions for performing a method of locating source code when a program according to the present invention runs in error.
According to yet another aspect of the present invention, there is provided a readable storage medium storing program instructions which, when read and executed by a computing device, cause the computing device to perform a method of locating source code when a program according to the present invention runs in error.
According to the method for positioning the source code when the program runs in error, firstly, the address of an error instruction is obtained according to the program name of the program and error prompt information obtained from a corresponding call stack when the program runs in error. And then, acquiring the name of the mixed name function of the function where the error instruction is located and the line number of the source code corresponding to the error instruction in the source file of the function according to the address of the error instruction. And if the name of the mixing function of the function where the error instruction is located is different from the name of the mixing function of the error function, updating the address of the error instruction, repeating the steps of obtaining the name of the mixing function and the number of lines until the obtained name of the mixing function is the same as the name of the mixing function of the error function, and taking the obtained number of lines as the number of lines of the error source code in the source file corresponding to the program. Therefore, based on the reverse instruction searching method, even if a macro in a development library is running when a program runs incorrectly, the line number of the error code in the program source code file can be quickly and accurately positioned, so that a developer can be helped to quickly repair the software defect.
Drawings
To the accomplishment of the foregoing and related ends, certain illustrative aspects are described herein in connection with the following description and the annexed drawings, which are indicative of various ways in which the principles disclosed herein may be practiced, and all aspects and equivalents thereof are intended to be within the scope of the claimed subject matter. The above and other objects, features and advantages of the present disclosure will become more apparent from the following detailed description read in conjunction with the accompanying drawings. Throughout this disclosure, like reference numerals generally refer to like parts or elements.
FIG. 1 shows a block diagram of a computing device 100, according to one embodiment of the invention;
FIG. 2 illustrates a flow diagram of a method 200 for locating source code in the event of a program execution error, according to one embodiment of the invention;
fig. 3 is a block diagram of an apparatus 300 for locating source code when a program is in error according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
When a program crashes (namely, the program runs wrongly), the call stack displays error prompt information of the program, and a developer positions the error code in the source code file of the program based on the prompt information. The call stack is shown below for a program crash.
(()+0x145882c)[0x2000245882c]
(()+0x19890)[0x2000b987890]
(RedShop::ExTable::reshuffle(KeyValueStore*,
std::shared_ptr<KeyValueStore::TransImpl>)+0x2df0)[0x2000229da60]
(RedShop::_txc_write_nodes(RedShop::TransContext*,
std::shared_ptr<KeyValueStore::TransImpl>)+0x218)[0x2000229f888]
...
From this call stack, the following can be obtained: when the program crashes, the program runs right into the reshuffle function, the absolute address of the error instruction is 0x2000229da60, and the offset of the address of the error instruction relative to the address of the error function reshuffle (the first address of the error function reshuffle) is 0x2df 0.
If the running code of the program is written by the developer when the program crashes, the line number of the error code in the source code file corresponding to the program can be located based on the function name reshuffle and the offset of the error instruction address.
However, if the function reshuffle in the program uses a certain macro in the development library, and it is this macro in the development library that it runs when the program crashes, then, as described above, based on the function name reshuffle and the offset of the error instruction address, the offset is located to the row number that will no longer be the error code in the source code file to which the program corresponds, but a specific row number in a certain source code file in the development library. That is, if the program crashes while running a macro in the development library, the developer can only know the error function in the source code of the program according to the error prompt information in the call stack, and cannot locate the specific error position.
Aiming at the problem, the invention provides a reverse instruction searching method based on the characteristic that instructions in a simplified instruction set are equal in length. Specifically, when a specific number of lines in a certain source code file in the development library is located according to the address of the error instruction, the address of the error instruction is updated based on the length of one instruction in the reduced instruction set, and the error instruction is relocated until the specific number of lines in the program source code is located (namely the number of lines of the error code in the program source code is obtained). Therefore, based on the reverse instruction searching method, even if a macro in a development library is running when a program crashes, the error source code file and the corresponding code line number in the source code program can be quickly and accurately positioned, so that developers can be helped to quickly find the defects of the software.
FIG. 1 shows a block diagram of a computing device 100, according to one embodiment of the invention. It should be noted that the computing device 100 shown in fig. 1 is only an example, and in practice, the computing device for implementing the method for locating source code when a program runs in error may be any type of device, and the hardware configuration thereof may be the same as the computing device 100 shown in fig. 1 or different from the computing device 100 shown in fig. 1. In practice, the computing device for implementing the method for locating source code when the program runs in error according to the present invention may add or delete the hardware components of the computing device 100 shown in fig. 1, and the present invention does not limit the specific hardware configuration of the computing device.
As shown in FIG. 1, in a basic configuration 102, a computing device 100 typically includes a system memory 106 and one or more processors 104. A memory bus 108 may be used for communication between the processor 104 and the system memory 106.
Depending on the desired configuration, the processor 104 may be any type of processing, including but not limited to: a microprocessor (μ P), a microcontroller (μ C), a Digital Signal Processor (DSP), or any combination thereof. The processor 104 may include one or more levels of cache, such as a level one cache 110 and a level two cache 112, a processor core 114, and registers 116. The example processor core 114 may include an Arithmetic Logic Unit (ALU), a Floating Point Unit (FPU), a digital signal processing core (DSP core), or any combination thereof. The example memory controller 118 may be used with the processor 104, or in some implementations the memory controller 118 may be an internal part of the processor 104.
Depending on the desired configuration, system memory 106 may be any type of memory, including but not limited to: volatile memory (such as RAM), non-volatile memory (such as ROM, flash memory, etc.), or any combination thereof. The physical memory in the computing device is usually referred to as a volatile memory RAM, and data in the disk needs to be loaded into the physical memory to be read by the processor 104. System memory 106 may include an operating system 120, one or more applications 122, and program data 124. In some implementations, the application 122 can be arranged to execute instructions on an operating system with program data 124 by one or more processors 104. Operating system 120 may be, for example, Linux, Windows, etc., which includes program instructions for handling basic system services and performing hardware dependent tasks. The application 122 includes program instructions for implementing various user-desired functions, and the application 122 may be, for example, but not limited to, a browser, instant messenger, a software development tool (e.g., an integrated development environment IDE, a compiler, etc.), and the like. When the application 122 is installed into the computing device 100, a driver module may be added to the operating system 120.
When the computing device 100 is started, the processor 104 reads program instructions of the operating system 120 from the memory 106 and executes them. The application 122 runs on top of the operating system 120, utilizing the operating system 120 and interfaces provided by the underlying hardware to implement various user-desired functions. When the user starts the application 122, the application 122 is loaded into the memory 106, and the processor 104 reads the program instructions of the application 122 from the memory 106 and executes the program instructions.
The computing device 100 also includes a storage device 132, the storage device 132 including removable storage 136 and non-removable storage 138, the removable storage 136 and the non-removable storage 138 each connected to the storage interface bus 134.
Computing device 100 may also include an interface bus 140 that facilitates communication from various interface devices (e.g., output devices 142, peripheral interfaces 144, and communication devices 146) to the basic configuration 102 via the bus/interface controller 130. The example output device 142 includes a graphics processing unit 148 and an audio processing unit 150. They may be configured to facilitate communication with various external devices, such as a display or speakers, via one or more a/V ports 152. Example peripheral interfaces 144 may include a serial interface controller 154 and a parallel interface controller 156, which may be configured to facilitate communication with external devices such as input devices (e.g., keyboard, mouse, pen, voice input device, touch input device) or other peripherals (e.g., printer, scanner, etc.) via one or more I/O ports 158. An example communication device 146 may include a network controller 160, which may be arranged to facilitate communications with one or more other computing devices 162 over a network communication link via one or more communication ports 164.
A network communication link may be one example of a communication medium. Communication media may typically be embodied by computer readable instructions, data structures, program modules, and may include any information delivery media, such as carrier waves or other transport mechanisms, in a modulated data signal. A "modulated data signal" may be a signal that has one or more of its data set or its changes made in such a manner as to encode information in the signal. By way of non-limiting example, communication media may include wired media such as a wired network or private-wired network, and various wireless media such as acoustic, Radio Frequency (RF), microwave, Infrared (IR), or other wireless media. The term computer readable media as used herein may include both storage media and communication media.
In a computing device 100 according to the present invention, application 122 includes instructions for performing method of locating source code when a program of the present invention runs an error 200, which may instruct processor 104 to perform the method of locating source code when a program of the present invention runs an error. It will be appreciated by those skilled in the art that the application 122 may include other applications 126 for implementing other functions in addition to the instructions for performing the method 200 for locating source code when a program runs in error.
FIG. 2 illustrates a flow diagram of a method 200 for locating source code in the event of a program execution error, the method 200 adapted to be executed in a reduced instruction set computing device (e.g., the computing device 100 shown in FIG. 1), according to one embodiment of the invention. Among the main features of the instruction set in a reduced instruction set computing device is that each instruction is the same length. The current world's mainstream processors using RISC include ARM, MIPS, RISC-V, etc. processors, all of which have an instruction length of four bytes.
As shown in FIG. 2, the method 200 for locating source code when a program runs in error starts at step S210. In step S210, the address of the error instruction is acquired according to the program name of the program and the error prompt information obtained from the call stack corresponding to the program operation error. The error prompt information comprises a function name of the error function and an offset of the error instruction, and the offset of the error instruction is an offset of an address of the error instruction relative to an address of the error function. Taking the call stack shown above as an example, the function name of the error function available from the call stack is reshuffle, and the offset of the address of the error instruction in the error function reshuffle from the error function reshuffle is 0x2df 0. Therefore, information such as the function name of the faulting function and the offset of the faulting instruction can be obtained from the call stack.
According to an embodiment of the present invention, after the function name of the error function and the offset of the error instruction are obtained from the call stack, the address of the error function may be obtained according to the program name of the crash program (i.e., the program in which the error occurs in the running) and the function name of the error function. The address of the error function refers to the location of the error function in the executable file, that is, the address is mapped to the memory according to the original address without randomization. It should be noted that, here, the address of the error function refers to the first address of the error function. According to one embodiment, the address of the error function may be obtained by the following steps.
First, a target mixed-name function name and a function address corresponding to the target mixed-name function name are obtained according to a program name of a crash program and a function name of an error function, wherein the target mixed-name function name refers to a mixed-name function name containing the function name of the error function. That is, this step is to obtain the mixed name function name containing the function name of the error function in the crash program and the address of the function corresponding to the mixed name function name according to the program name of the crash program and the function name of the error function.
Specifically, according to the program name of the crash program, a symbol table in the executable file is acquired. Wherein, the symbol table in the executable file can be obtained by a file parsing tool. The parse file tool is adapted to print out a symbol table in the executable file according to the inputted program name. Therefore, according to the program name (i.e., executable file name) of the crash program, the symbol table in the execution file corresponding to the crash program can be printed by using the file analysis tool. For example, under the Linux operating system, a readelf command may be used to obtain a symbol table in an executable file. As an example, assuming that the program name of the program corresponding to the call stack shown above is execute, under the Linux operating system, the symbol table in the EXECUTABLE file execute may be obtained by executing the following commands:
readelf-s--wide EXECUTABLE
after the symbol table in the executable file is acquired, the target mixed name function name and the address of the function corresponding to the target mixed name function name are acquired from the symbol table according to the function name of the error function. The target mixed name function name and the address of the function corresponding to the target mixed name function name can be obtained from the symbol table by searching a character string tool. The find string tool is adapted to print out a row in the symbol table containing the entered string based on the entered string. Therefore, according to the function name of the error function, the line containing the function name of the error function in the symbol table can be printed by utilizing a character string searching tool, and the target mixed-name function name and the address of the function corresponding to the target mixed-name function name can be obtained from the line.
For example, the grep command may be used to obtain the target hash function name and the address of the function corresponding to the target hash function name from the symbol table. Taking the above-illustrated call stack as an example, if the program name of the crash program is execute, and the function name of the error function is reshuffle, then the following commands may be executed under the Linux operating system to print out the row containing reshuffle in the symbol table of the EXECUTABLE file execute:
readelf-s--wide EXECUTABLE|grep reshuffle
as an example, the following output is obtained after executing the above command:
7166:000000000129ac70 18940 FUNC GLOBAL DEFAULT[<other>:88]13_ZN7RedShop7ExTable9reshuffleEP13KeyValueStoreSt10shared_ptrINS1_9TransImplEE
wherein, _ ZN7RedShop7ExTable9 reshuffleP 13KeyValueStoreST10shared _ ptrINS1_9TransImPLEE is the name of function name reshuffle mixed according to C + + naming rules, namely the mixed name function name containing reshuffle. 000000000129ac70 is the address of the function corresponding to the name of the mixed name function _ ZN7RedShop7ExTable9reshuffleEP13KeyValueStoreST10shared _ ptrINS1_9 TransImPLEE. Obviously, the name of the mixing function containing reshuffle and the address of the corresponding function can be obtained by executing the above command readelf-s-wide EXECUTABLE | grep reshuffle.
Then, a function signature of a function corresponding to the target mixed name function name (i.e., a name before the target mixed name function name is obtained) is obtained from the target mixed name function name. The function signature of the function corresponding to the target mixed name function name can be obtained through a demixing tool. The anti-aliasing tool is adapted to output a function signature for a function according to a hash function name of the function. For example, the C + + filt command may be utilized in a C + + program to perform the demixing. As an example, taking the obtained target mixed-name function name _ ZN7RedShop7ExTable9reshuffle ep13KeyValueStoreSt10shared _ ptrINS1_9 transmiplee as an example, the function signature of the function corresponding to the target mixed-name function name can be obtained by executing the following commands:
c++filt_ZN7RedShop7ExTable9reshuffleEP13KeyValueStoreSt10shared_ptrINS1_9TransImplEE
as an example, the character string output after the command is executed is:
RedShop::ExTable::reshuffle(KeyValueStore*,std::shared_ptr<KeyValueStore::TransImpl>)
wherein RedShop:: ExTable:: reshuffle (KeyValueStore:: std:: shared _ ptr < KeyValueStore:: TransImpl >) is the name before the name of the target mixed name function _ ZN7RedShop7ExTable9 reshuffleP 13 KeyValueStore:10shared _ ptrINS1_9TransImPLEE mixed name, namely the function signature of the function corresponding to the target mixed name function name.
And finally, if the function signature of the function corresponding to the target mixed name function name is the same as the function signature of the error function, taking the address of the function corresponding to the target mixed name function name as the address of the error function. This is because if the function signature of the function corresponding to the target hash function name is the same as the function signature of the error function, it indicates that the function corresponding to the target hash function name is the error function, and therefore the function address of the function corresponding to the target hash function name is determined to be the address of the error function. Wherein the function signature of the faulting function can be obtained from the call stack. For example, the function of the error function reshuffle is signed by (RedShop:: ExTable:: reshuffle (KeyValueStore:: std:: shared _ ptr:: TransImpl >) in the call stack shown above.
Taking the above-described call stack and the function signature of the function corresponding to the obtained target mixed name function name as an example, comparing the function signature RedShop:: ExTable:: reshuffle (keyvalue store:: std:: shared _ ptr < keyvalue store:: fransipll >) of the function corresponding to the obtained target mixed name function name with the function signature (RedShop:: ExTable:: reshuffle (keyvalue store:: std:: shared _ ptr < keyvalue store:: fransipll >) in the call stack, and finding that the two signatures are the same, it indicates that the function corresponding to the target mixed name function name is determined to be an error function reshuffle, and therefore, the address of the error function reshuffle is 000000000129ac 70.
And after the address of the error function is obtained, obtaining the address of the error instruction in the error function according to the address of the error function and the offset of the error instruction obtained from the call stack. Specifically, the address of the faulting function is added to the offset of the faulting instruction, and the obtained address is the address of the faulting instruction. Continuing with the call stack example shown above, the address of the faulting function is 0x000000000129ac70, and the offset of the faulting instruction is 0x2df0, then the address of the faulting instruction in the faulting function can be obtained by executing the following commands:
python-c"print hex(0x000000000129ac70+0x2df0)"
after executing the above command, the result 0x129da60 is obtained, i.e. the address of the error function is 0x129da 60.
And then, step S220 is performed, in which, according to the address of the error instruction, the mixed-name function name of the function where the error instruction is located and the line number of the source code corresponding to the error instruction in the source file thereof are obtained, and the mixed-name function name of the function where the error instruction is located is the name obtained after the mixed-name function name of the function where the error instruction is located.
The name of the mixed name function of the function where the error instruction is located and the line number of the source code corresponding to the error instruction in the source file of the function can be obtained through the address positioning tool. The address location tool is suitable for converting the address of the instruction into the name of the mixed name function of the function where the instruction is located and the line number of the source code corresponding to the instruction in the source file. For example, the addr2line command may be used to obtain the name of the mixed-name function of the function where the faulting instruction is located and the location of the source code corresponding to the faulting instruction. As an example, taking the obtained address of the error instruction as an example, the following commands may be executed to obtain the name of the hash function of the function where the error instruction is located and the number of lines of the source code corresponding to the error instruction in the source file of the function:
addr2line-af 0x129da60-e EXECUTABLE
as an example, the following output is obtained after executing the above command:
0x000000000129da60
_ZNSt13__atomic_baseIiEppEv
/usr/include/c++/x.y/bits/atomic_base.h:296
the output first line is the address of the error instruction, the name of the mixed name function of the second error instruction, and the third line is the file name of the source file of the source code corresponding to the error instruction and the line number of the source code corresponding to the error instruction in the source file. As can be seen, by executing the above-mentioned command addr2line-af 0x129da60-e EXECUTABLE, the name of the function in which the faulting instruction is located and the number of lines of the source code in the source file corresponding to the faulting instruction can be obtained.
After the mixed name function name of the function where the error instruction is located is obtained, whether the mixed name function name of the function where the error instruction is located is the same as the mixed name function name of the error function is judged. And the name of the mixed name function of the error function is the name of the target mixed name function which is the same as the signature of the function of the error function after the mixed name is reversed.
If the name of the mixed name function of the function where the error instruction is located is the same as that of the error function, it is indicated that the source file where the source code corresponding to the error instruction is located is the source file where the error function is located, that is, the source file corresponding to the crash program, and therefore the obtained line number (i.e., the line number of the source code corresponding to the error instruction in the source file thereof) is the line number of the error source code in the source file corresponding to the crash program.
If the name of the mixing function of the function where the error instruction is located is different from the name of the mixing function of the error function, the method proceeds to step S230, the address of the error instruction is updated, the obtaining step of the name and the number of lines of the mixing function (namely, step S220) is repeated until the obtained name of the mixing function is the same as the name of the mixing function of the error function, the obtained number of lines is used as the number of lines of the error source code in the target file, and the target file is the source file corresponding to the program.
If the name of the mixed name function of the function where the error instruction is located is different from the name of the mixed name function of the error function, the source code corresponding to the current error instruction is not the code written by a developer but the source code in a certain source file in a development library. At this time, the address of the error instruction can be updated to obtain the name of the mixing function of the function where the error instruction is located after updating and the number of lines of the source code corresponding to the error instruction in the source file, and whether the obtained mixing function name is the same as the name of the mixing function of the error function or not is judged. And repeating the updating-obtaining-judging steps until the name of the mixed name function of the function where the error instruction is located is the same as that of the error function, and taking the number of lines obtained at the last time as the number of lines of the error code in the source file corresponding to the crash program.
Because the instructions in the simplified instruction set are all equal in length, when the name of the mixed-name function of the function where the error instruction is located is different from the name of the mixed-name function of the error function, the address of the previous instruction can be obtained by subtracting the byte number occupied by one instruction from the address of the current error instruction. That is, the address of the faulting instruction may be updated by subtracting the address of the faulting instruction by the number of bytes occupied by one instruction.
The current world's mainstream processors using RISC include ARM, MIPS, RISC-V, etc. processors, all of which have an instruction length of four bytes. Thus, according to one embodiment of the invention, the address of the faulting instruction may be updated by subtracting four from the address of the faulting instruction.
According to one embodiment of the present invention, the core code of step S230 is as follows:
Figure BDA0003125421120000131
it can be seen that the program repeatedly calls the addr2line command to locate the source code information corresponding to the current instruction address (addr-a × 4), until the second line output by the addr2line command contains the function name after the mixed name, at which point the loop is terminated and the source code file and the line number are printed. Otherwise, the current instruction address is continued to be subtracted by 4, i.e., the instruction is traced back forward, until finally found.
By using the method for positioning the source code when the program runs wrongly, the line number of the error code in the program source code file can be obtained only by inputting the name of the executable file, the function signature of the error function and the offset of the error instruction, so that the method is convenient and quick and has low cost. For the convenience of understanding, the call stack shown above is taken as an example, and assuming that the method for locating the source code when the program runs an error is P, the number of lines of the error code in the source code file of the program can be obtained by executing the following commands: p EXECUTABLE-f 'RedShop:: ExTable:: reshuffle (KeyValueStore:: shared _ ptr:: TransImpl >)' -o 0x2df0
FIG. 3 is a block diagram of an apparatus 300 for locating source code in the event of a program execution error, adapted to reside in the reduced instruction set computing device 100, according to one embodiment of the invention. As shown in fig. 3, the apparatus 300 for locating source code includes a first obtaining module 310, a second obtaining module 320, and an updating module 330.
The first obtaining module 310 is adapted to obtain an address of the error instruction according to the program name of the program and error prompt information obtained from a corresponding call stack when the program runs in error, where the error prompt information includes a function name of the error function and an offset of the error instruction, and the offset of the error instruction is an offset of the address of the error instruction relative to the address of the error function.
The second obtaining module 320 is adapted to obtain, according to the address of the error instruction, a mixed-name function name of the function where the error instruction is located and a line number of the source code corresponding to the error instruction in the source file thereof, where the mixed-name function name of the function where the error instruction is located is a name obtained by mixing the function names of the functions where the error instruction is located.
The updating module 330 is adapted to update the address of the error instruction if the name of the mixing function of the function where the error instruction is located is different from the name of the mixing function of the error function, and repeat the execution action of the second obtaining module until the obtained name of the mixing function is the same as the name of the mixing function of the error function, and use the obtained line number as the line number of the error source code in the target file, where the target file is the source file corresponding to the program.
According to the method for positioning the source code when the program runs in error, firstly, the address of an error instruction is obtained according to the program name of the program and error prompt information obtained from a corresponding call stack when the program runs in error. And then, acquiring the name of the mixed name function of the function where the error instruction is located and the line number of the source code corresponding to the error instruction in the source file of the function according to the address of the error instruction. And if the name of the mixing function of the function where the error instruction is located is different from the name of the mixing function of the error function, updating the address of the error instruction, repeating the steps of obtaining the name of the mixing function and the number of lines until the obtained name of the mixing function is the same as the name of the mixing function of the error function, and taking the obtained number of lines as the number of lines of the error source code in the source file corresponding to the program. Therefore, based on the reverse instruction searching method, even if a macro in a development library is running when a program runs incorrectly, the wrong source code file in the source code program and the corresponding code line number can be quickly and accurately positioned, so that developers can be helped to quickly repair software defects.
The various techniques described herein may be implemented in connection with hardware or software or, alternatively, with a combination of both. Thus, the methods and apparatus of the present invention, or certain aspects or portions thereof, may take the form of program code (i.e., instructions) embodied in tangible media, such as removable hard drives, U.S. disks, floppy disks, CD-ROMs, or any other machine-readable storage medium, wherein, when the program is loaded into and executed by a machine, such as a computer, the machine becomes an apparatus for practicing the invention.
In the case of program code execution on programmable computers, the computing device will generally include a processor, a storage medium readable by the processor (including volatile and non-volatile memory and/or storage elements), at least one input device, and at least one output device. Wherein the memory is configured to store program code; the processor is configured to execute the document loading method of the present invention according to instructions in the program code stored in the memory.
By way of example, and not limitation, readable media may comprise readable storage media and communication media. Readable storage media store information such as computer readable instructions, data structures, program modules or other data. Communication media typically embodies computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism and includes any information delivery media. Combinations of any of the above are also included within the scope of readable media.
In the description provided herein, algorithms and displays are not inherently related to any particular computer, virtual system, or other apparatus. Various general purpose systems may also be used with examples of this invention. The required structure for constructing such a system will be apparent from the description above. Moreover, the present invention is not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best mode of the invention.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
It should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that the invention as claimed requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention.
Those skilled in the art will appreciate that the modules or units or components of the devices in the examples disclosed herein may be arranged in a device as described in this embodiment or alternatively may be located in one or more devices different from the devices in this example. The modules in the foregoing examples may be combined into one module or may be further divided into multiple sub-modules.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments described herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
Furthermore, some of the described embodiments are described herein as a method or combination of method elements that can be performed by a processor of a computer system or by other means of performing the described functions. A processor having the necessary instructions for carrying out the method or method elements thus forms a means for carrying out the method or method elements. Further, the elements of the apparatus embodiments described herein are examples of the following apparatus: the apparatus is used to implement the functions performed by the elements for the purpose of carrying out the invention.
As used herein, unless otherwise specified the use of the ordinal adjectives "first", "second", "third", etc., to describe a common object, merely indicate that different instances of like objects are being referred to, and are not intended to imply that the objects so described must be in a given sequence, either temporally, spatially, in ranking, or in any other manner.
While the invention has been described with respect to a limited number of embodiments, those skilled in the art, having benefit of this description, will appreciate that other embodiments can be devised which do not depart from the scope of the invention as described herein. Furthermore, it should be noted that the language used in the specification has been principally selected for readability and instructional purposes, and may not have been selected to delineate or circumscribe the inventive subject matter. Accordingly, many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the appended claims. The present invention has been disclosed in an illustrative rather than a restrictive sense, and the scope of the present invention is defined by the appended claims.

Claims (9)

1. A method of locating source code when a program runs in error, adapted to be executed in a reduced instruction set computing device, the method comprising:
acquiring the address of the error function according to the program name of the program and the function name of the error function acquired from the corresponding call stack when the program runs wrongly;
acquiring the address of the error instruction according to the address of the error function and the offset of the error instruction acquired from a corresponding call stack when a program is in error, wherein the offset of the error instruction is the offset of the address of the error instruction relative to the address of the error function;
according to the address of the error instruction, acquiring a mixed function name of a function where the error instruction is located and the line number of a source code corresponding to the error instruction in a source file thereof by an address positioning tool, wherein the mixed function name of the function where the error instruction is located is a name obtained after the mixed function name of the function where the error instruction is located, and the address positioning tool is suitable for converting the address of the instruction into the mixed function name of the function where the instruction is located and the line number of the source code corresponding to the instruction in the source file thereof;
and if the name of the mixed name function of the function where the error instruction is located is different from the name of the mixed name function of the error function, updating the address of the error instruction, and repeating the acquiring steps of the name of the mixed name function and the number of lines until the acquired name of the mixed name function is the same as the name of the mixed name function of the error function, wherein the acquired number of lines is used as the number of lines of an error source code in a target file, and the target file is a source file corresponding to the program.
2. The method of claim 1, wherein in the updating the address of the faulting instruction, the address of the faulting instruction is updated by subtracting a preset value from the address of the faulting instruction, the preset value being a number of bytes occupied by one instruction.
3. The method according to claim 1 or 2, wherein the step of obtaining the address of the faulting function from the program name of the program and the function name of the faulting function comprises:
acquiring a target mixed-name function name and a function address corresponding to the target mixed-name function name according to the program name of the program and the function name of the error function, wherein the target mixed-name function name is the mixed-name function name containing the function name;
acquiring a function signature of a function corresponding to the target mixed name function name according to the target mixed name function name;
and if the function signature of the function corresponding to the target mixed name function name is the same as the function signature of the error function, taking the address of the function corresponding to the target mixed name function name as the address of the error function.
4. The method of claim 3, wherein the step of obtaining a target mixed-name function name and an address of a function corresponding to the target mixed-name function name according to a program name of the program and a function name of an error function comprises:
acquiring a symbol table in an executable file according to the program name of the program;
and acquiring a target mixed-name function name and a function address corresponding to the target mixed-name function name from the symbol table according to the function name of the error function.
5. The method according to claim 4, wherein in the step of obtaining the symbol table in the executable file according to the program name of the program, the symbol table in the executable file is obtained by a parsing file tool adapted to print out the symbol table in the executable file according to the inputted program name;
in the step of obtaining the target mixed-name function name and the address of the function corresponding to the target mixed-name function name from the symbol table according to the function name of the error function, the target mixed-name function name and the address of the function corresponding to the target mixed-name function name are obtained from the symbol table through a character string searching tool, and the character string searching tool is suitable for printing a line containing an input character string in the symbol table according to the input character string.
6. The method according to any one of claims 3-5, wherein in the step of obtaining the function signature of the function corresponding to the target hash function name from the target hash function name, the function signature of the function corresponding to the target hash function name is obtained by a demixing tool adapted to output the function signature of the function from the hash function name of the function.
7. An apparatus for locating source code when a program runs in error, the apparatus residing in a reduced instruction set computing device, the apparatus comprising:
the first obtaining module is suitable for obtaining the address of the error function according to the program name of the program and the function name of the error function obtained from the corresponding call stack when the program is in error, and is also suitable for obtaining the address of the error instruction according to the address of the error function and the offset of the error instruction obtained from the corresponding call stack when the program is in error, wherein the offset of the error instruction is the offset of the address of the error instruction relative to the address of the error function;
the second obtaining module is suitable for obtaining a mixed function name of a function where the error instruction is located and the line number of a source code corresponding to the error instruction in a source file of the function according to the address of the error instruction through an address positioning tool, the mixed function name of the function where the error instruction is located is a name obtained after the mixed function name of the function where the error instruction is located is mixed, and the address positioning tool is suitable for converting the address of the instruction into the mixed function name of the function where the instruction is located and the line number of the source code corresponding to the instruction in the source file of the function where the instruction is located;
and the updating module is suitable for updating the address of the error instruction if the mixed name function name of the function where the error instruction is located is different from the mixed name function name of the error function, and repeating the execution action of the second acquisition module until the acquired mixed name function name is the same as the mixed name function name of the error function, and taking the acquired line number as the line number of the error source code in the target file, wherein the target file is the source file corresponding to the program.
8. A computing device, comprising:
at least one processor; and
a memory storing program instructions, wherein the program instructions are configured to be executed by the at least one processor, the program instructions comprising instructions for performing the method of any of claims 1-6.
9. A readable storage medium storing program instructions that, when read and executed by a computing device, cause the computing device to perform the method of any of claims 1-6.
CN202110701031.XA 2021-04-27 2021-04-27 Method and device for positioning source code during program operation error and computing equipment Pending CN113342563A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110701031.XA CN113342563A (en) 2021-04-27 2021-04-27 Method and device for positioning source code during program operation error and computing equipment

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110456935.0A CN112860473B (en) 2021-04-27 2021-04-27 Method and device for positioning source code during program operation error and computing equipment
CN202110701031.XA CN113342563A (en) 2021-04-27 2021-04-27 Method and device for positioning source code during program operation error and computing equipment

Related Parent Applications (1)

Application Number Title Priority Date Filing Date
CN202110456935.0A Division CN112860473B (en) 2021-04-27 2021-04-27 Method and device for positioning source code during program operation error and computing equipment

Publications (1)

Publication Number Publication Date
CN113342563A true CN113342563A (en) 2021-09-03

Family

ID=75992929

Family Applications (2)

Application Number Title Priority Date Filing Date
CN202110456935.0A Active CN112860473B (en) 2021-04-27 2021-04-27 Method and device for positioning source code during program operation error and computing equipment
CN202110701031.XA Pending CN113342563A (en) 2021-04-27 2021-04-27 Method and device for positioning source code during program operation error and computing equipment

Family Applications Before (1)

Application Number Title Priority Date Filing Date
CN202110456935.0A Active CN112860473B (en) 2021-04-27 2021-04-27 Method and device for positioning source code during program operation error and computing equipment

Country Status (1)

Country Link
CN (2) CN112860473B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113626308A (en) * 2021-07-06 2021-11-09 深圳点猫科技有限公司 Code debugging method and device, electronic equipment and storage medium
CN116521411B (en) * 2023-03-27 2023-11-17 广东保伦电子股份有限公司 Method, device and medium for detecting program error and resetting embedded device
CN117555720B (en) * 2024-01-11 2024-04-26 腾讯科技(深圳)有限公司 Code repairing method, device, equipment and medium

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1329836C (en) * 2004-05-26 2007-08-01 华为技术有限公司 Method for locating program abnormity
CN100535870C (en) * 2006-12-29 2009-09-02 中兴通讯股份有限公司 Embedded system progress abnormal tracking position-finding method
US20080244322A1 (en) * 2007-03-27 2008-10-02 Tim Kelso Program Test System
CN101340314A (en) * 2008-08-11 2009-01-07 中兴通讯股份有限公司 Real-time debugging positioning method of embedded system and apparatus thereof
CN101539883B (en) * 2009-05-05 2011-11-16 北京和利时系统工程有限公司 Error tracking method of embedded system and device thereof
US9645869B2 (en) * 2010-12-01 2017-05-09 Ncr Corporation Using exception information
JP6451417B2 (en) * 2015-03-10 2019-01-16 日本電気株式会社 Debug support device, debug support system, debug support method, and debug support program
CN106201892B (en) * 2016-07-20 2019-02-01 中国航空工业集团公司航空动力控制系统研究所 Abnormal interrupt source position finding and detection method for embedded software
CN110764945B (en) * 2019-10-23 2023-06-30 北京博睿宏远数据科技股份有限公司 Crash log processing method, device, equipment and storage medium
CN112256570B (en) * 2020-10-19 2023-08-11 网易(杭州)网络有限公司 Remote debugging method, device, equipment and storage medium

Also Published As

Publication number Publication date
CN112860473A (en) 2021-05-28
CN112860473B (en) 2021-07-30

Similar Documents

Publication Publication Date Title
CN112860473B (en) Method and device for positioning source code during program operation error and computing equipment
JPH0836488A (en) Method and device for checking run-time error using dynamic patching
JP2000347872A (en) Method and device for processing exception as regular control flow
CN112379888A (en) Code change analysis method
CN113885936A (en) Solution method for software package dependence in customized mirror image
WO2022156277A1 (en) Application program installation method and apparatus, and computing device and readable storage medium
CN113238760A (en) Software migration method and device, computing equipment and readable storage medium
CN113204385A (en) Plug-in loading method and device, computing equipment and readable storage medium
CN113805971B (en) Application program running method, computing device and storage medium
CN114780173B (en) Method for loading plug-in application, computing device and storage medium
CN113821272B (en) Application program running method, computing device and storage medium
CN110688103B (en) Code writing method, device, electronic equipment and computer readable storage medium
CN110308933B (en) Access instruction determining method, device and storage medium
CN114168489B (en) Function information acquisition method, computing device and storage medium
CN113485712A (en) Kernel cutting method and computing device
CN111984451A (en) Error correction method, system, device and storage medium for table data
US8683455B1 (en) Method and system for optimizing an executable program by selectively merging identical program entities
CN114328273B (en) Debugging method and device for application program control and computing equipment
CN113835927B (en) Instruction execution method, computing device and storage medium
CN114189880B (en) Method and device for generating occupation file for base station test
CN113821273B (en) Application program running method, computing device and storage medium
JP5067705B2 (en) Abnormal test support device, abnormal test support method, and program
CN114003282A (en) Instruction execution method based on global lock, computing device and storage medium
CN114281685A (en) Statistical method for memory leakage of application, computing device and readable storage medium
CN114741116A (en) Program transplanting method and device

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