CN111124900A - Data acquisition method and device during abnormal program operation, terminal and storage medium - Google Patents
Data acquisition method and device during abnormal program operation, terminal and storage medium Download PDFInfo
- Publication number
- CN111124900A CN111124900A CN201911267269.5A CN201911267269A CN111124900A CN 111124900 A CN111124900 A CN 111124900A CN 201911267269 A CN201911267269 A CN 201911267269A CN 111124900 A CN111124900 A CN 111124900A
- Authority
- CN
- China
- Prior art keywords
- function
- acquiring
- program
- data
- stack frame
- 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
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/362—Software debugging
- G06F11/3636—Software debugging by tracing the execution of the program
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/362—Software debugging
- G06F11/3644—Software debugging by instrumenting at runtime
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (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 data acquisition method, a device, a terminal and a storage medium when a program runs abnormally, wherein the method comprises the following steps: when a program is in an abnormal operation state, acquiring call relation data between functions corresponding to the program in the abnormal operation state; and acquiring memory data of a function corresponding to the abnormal operation state in the program. According to the method and the device, the abnormal operation state appearing in the program is obtained, and the call relation data and the memory data of the function corresponding to the abnormal operation state are further obtained, so that the abnormity can be solved according to the stored data.
Description
Technical Field
The present invention relates to the field of data acquisition technologies, and in particular, to a method, an apparatus, a terminal, and a storage medium for acquiring data when a program runs abnormally.
Background
With the continuous increase of code scale and service complexity of modern programs, a means for accurately acquiring relevant memory data and positioning codes when a program runs in error is urgently needed to achieve the purpose of rapidly solving the running error of the complex program. Especially, the shortage of system resources and debugging tools in the embedded environment further requires that the method meets the requirements of simplicity, easy realization and low resource occupation.
The core dump debugging technology of the conventional linux kernel (when a program is abnormally terminated or crashed in the running process, an operating system records the current memory state of the program and stores the memory state in a file, namely the core dump debugging technology) can indiscriminately store all memory data in the running process of the program, occupies a large amount of storage space, and is not suitable for an embedded system environment.
Thus, there is still a need for improvement and development of the prior art.
Disclosure of Invention
The present invention provides a method, an apparatus, a terminal and a storage medium for acquiring data when a program is abnormal, aiming to solve the problem that when the program is abnormal, all memory data in the program running will be saved indiscriminately and a large amount of storage space is occupied.
The technical scheme adopted by the invention for solving the technical problem is as follows:
in a first aspect, the present invention provides a data acquisition method when a program runs abnormally, wherein the method includes:
when a program is in an abnormal operation state, acquiring call relation data between functions corresponding to the program in the abnormal operation state;
and acquiring memory data of a function corresponding to the abnormal operation state in the program.
In one embodiment, the obtaining memory data of a function corresponding to the abnormal operating state in the program includes:
acquiring the abnormal operation state, and analyzing the abnormal operation state to obtain a function corresponding to the abnormal operation state;
and acquiring the calling relation data between the called function and the caller function from the functions.
In one embodiment, the obtaining, from the function, call relation data between the called function and the caller function includes:
acquiring a stack frame address of a called function, and acquiring an instruction address of a caller function from the stack frame address of the called function;
and acquiring the length of the application stack frame of the caller function from the instruction address of the caller function to obtain the data of the calling relationship between the called function and the caller function.
In one embodiment, the obtaining memory data of a function corresponding to the abnormal operating state in the program includes:
and acquiring a stack frame address corresponding to the function, and acquiring memory data from the stack frame address.
In one embodiment, the obtaining memory data from the stack frame address includes:
acquiring memory data of the called function from the stack frame address of the called function;
the method comprises the steps of obtaining a stack frame address of a caller function, and obtaining memory data of the caller function from the stack frame address of the caller function.
In one embodiment, the stack frame address of the caller function is the application stack frame length of the caller function plus the stack frame address of the called function.
In one embodiment, the obtaining of the call relation data between the called function and the caller function includes:
and repeatedly executing the steps of acquiring the stack frame address of the called function, acquiring the instruction address of the caller function from the stack frame address of the called function, and acquiring the application stack frame length of the caller function from the instruction address of the caller function until the calling relation data among all the functions are found out.
In a second aspect, the present invention further provides a device for acquiring data when a program runs abnormally, wherein the device includes:
the system comprises a first acquisition unit, a second acquisition unit and a control unit, wherein the first acquisition unit is used for acquiring call relation data between functions corresponding to a program in an abnormal operation state when the program is in the abnormal operation state;
and the second acquisition unit is used for acquiring the memory data of the function corresponding to the abnormal operation state in the program.
In a third aspect, the present invention also provides a terminal, which includes a memory, and one or more programs, where the one or more programs are stored in the memory, and the one or more programs configured to be executed by the one or more processors include a processor configured to perform the method of any one of the above aspects.
In a fourth aspect, the present invention also provides a non-transitory computer readable storage medium, wherein instructions, when executed by a processor of an electronic device, enable the electronic device to perform the method of any one of the above aspects.
The invention has the technical effects that: according to the method and the device, the abnormal operation state appearing in the program is obtained, and the call relation data and the memory data of the function corresponding to the abnormal operation state are further obtained, so that the abnormity can be solved according to the stored data.
Drawings
Fig. 1 is a flowchart of a data acquisition method when a program provided by the present invention is abnormally operated.
Fig. 2 is a first flowchart of a specific application of the data acquisition method when the program runs abnormally, according to the present invention.
Fig. 3 is a second flowchart of a specific application of the data acquisition method when the program runs abnormally, according to the present invention.
Fig. 4 is a schematic block diagram of a data acquisition device in the event of abnormal program operation according to an embodiment of the present invention.
Fig. 5 is a schematic block diagram of an internal structure of a terminal according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer and clearer, the present invention is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
It should be noted that, if directional indications (such as up, down, left, right, front, and back … …) are involved in the embodiment of the present invention, the directional indications are only used to explain the relative positional relationship between the components, the motion situation, and the like in a specific posture (as shown in the drawing), and if the specific posture is changed, the directional indications are changed accordingly.
In addition, if there is a description of "first", "second", etc. in an embodiment of the present invention, the description of "first", "second", etc. is for descriptive purposes only and is not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the feature. In addition, technical solutions between various embodiments may be combined with each other, but must be realized by a person skilled in the art, and when the technical solutions are contradictory or cannot be realized, such a combination should not be considered to exist, and is not within the protection scope of the present invention.
The method and the device aim to solve the problem that in the prior art, when a program is abnormal, all memory data in the program operation can be stored indiscriminately, and a large amount of storage space is occupied. The present embodiment provides a data acquisition method when a program runs abnormally, as shown in fig. 1, the method includes the following steps:
s100, when a program is in an abnormal operation state, acquiring call relation data between functions corresponding to the abnormal operation state in the program;
and step S200, acquiring memory data of a function corresponding to the abnormal operation state in the program.
In this embodiment, when an abnormal operation state occurs in the running process of a program, the abnormal operation state is acquired, and then the acquired abnormal operation state is analyzed, so that a function corresponding to the abnormal operation state is obtained. Since the function in the program includes the called function and the caller function, when the program is abnormal, it is necessary to further obtain the call relation data between the called function and the caller function from the functions, and obtain the relevant memory data from the called function and the caller function, so as to realize the data acquisition when the program is abnormal, so that the abnormal operation state can be analyzed and solved for the obtained data.
Because the function calling process of the program can execute two special instructions, the first special instruction applies for a stack frame address to the called function (fa), and the stack frame address stores memory data when the called function (fa) runs; the second special instruction is to store the instruction address of the caller function (fb) in the stack frame address of the called function (fa), so that the called function (fa) returns to the caller function (fb) after finishing executing to continue to execute the subsequent instructions. In this embodiment, memory data in a stack frame address corresponding to each function is obtained by analyzing a first instruction executed by each function, and a call relationship between functions when a program is running is determined by analyzing an instruction address stored by a second instruction.
Specifically, in this embodiment, a stack frame address of a called function is first obtained, and then an instruction address of a caller function is obtained from the stack frame address of the called function; and then acquiring the length of the application stack frame of the caller function from the instruction address of the caller function to obtain the data of the calling relationship between the called function and the caller function. Further, for the memory data of the function corresponding to the abnormal operation state in the program, in this embodiment, the stack frame address corresponding to the function is obtained, and the memory data is obtained from the stack frame address.
Since the functions in the program include the called function and the caller function, and the stack frame address of the called function is already acquired in this embodiment, the memory data of the called function is acquired from the stack frame address of the called function. And for the memory data of the caller function, firstly, acquiring a stack frame address of the caller function, and acquiring the memory data of the caller function from the stack frame address of the caller function, thereby acquiring the memory data corresponding to the abnormal operation state in the function. In this embodiment, the stack frame address of the caller function is the length of the application stack frame of the caller function plus the stack frame address of the called function.
In this embodiment, after obtaining the calling relationship data between the called function and the caller function, the steps of obtaining the stack frame address of the called function, obtaining the instruction address of the caller function from the stack frame address of the called function, and obtaining the application stack frame length of the caller function from the instruction address of the caller function are repeated until finding out the calling relationship data between all the functions.
Specifically, referring to fig. 2, fig. 2 illustrates a specific application of the data or the data obtained when the program runs abnormally in the present embodiment. As can be seen from fig. 2, the flow of the function code call relation and the acquisition of the memory data thereof when the program runs abnormally includes the following steps:
1. when an exception error occurs in the program, the stack frame address of the currently called function (fa) is recorded.
2. The instruction address of the caller function (fb) is found from the memory corresponding to the stack frame of the currently called function (fa).
3. The length of the application stack frame of the caller function (fb) is found from the code instruction of the caller function (fb).
4. The length of the application stack frame of the caller function (fb) plus the stack frame address of the called function (fa) is the stack frame address of the caller function (fb).
5. And (2) jumping back to the step, executing the caller function (fb) as a new called function (fa) until all function call relations and the operation in the stack frame memory corresponding to the function call relations are found.
Further, as shown in fig. 3, in this embodiment, first, a request is made to obtain a function call relationship and memory data of a running program, then an instruction address (pc) and a memory fragment base address (ba) of a currently executed function (fx) are obtained, then an instruction code of the fx application memory fragment is found according to the instruction address (pc), and a length (len) of the application memory fragment (i.e., a length of the application stack frame) is resolved. The memory fragment of fx is the memory within the range from ba to ba + len (including ba but not including ba + len), and the data in the memory fragment is derived and recorded as the data of fx function. The instruction address pc1 of the caller fx1 of the fx function is stored in the top memory ba + len-4 of the memory fragment of fx, and if there is no other function call fx, the value of pc1 is 0. Next, a determination is made as to whether pc1 is equal to 0, and if so, the process ends. If not, the base address ba1 of the memory fragment of fx1 is equal to ba + len, fx1 is taken as the characteristic fx, pc1 is taken as the pc of the new fx, and ba1 is taken as the ba of the characteristic fx, the calculation process is repeated, the process is repeatedly executed until the instruction code of the fx application memory fragment is found according to the instruction address (pc), and the length (len) of the application memory fragment is analyzed.
Based on the above embodiments, the present invention also provides a data acquisition apparatus when a program runs abnormally, as shown in fig. 4, the apparatus includes a first acquisition unit 410 and a second acquisition unit 420. Specifically, the first obtaining unit 410 is configured to, when an abnormal operation state occurs in a program, obtain call relationship data between functions in the program corresponding to the abnormal operation state. A second obtaining unit 420, configured to obtain memory data of a function in the program corresponding to the abnormal operating state.
Based on the above embodiments, the present invention further provides a terminal, and a schematic block diagram thereof may be as shown in fig. 5. The terminal comprises a processor, a memory, a network interface, a display screen and a temperature sensor which are connected through a system bus. Wherein the processor of the terminal is configured to provide computing and control capabilities. The memory of the terminal comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The network interface of the terminal is used for connecting and communicating with an external terminal through a network. The computer program is executed by a processor to implement a method for acquiring data when a program runs abnormally. The display screen of the terminal can be a liquid crystal display screen or an electronic ink display screen, and the temperature sensor of the terminal is arranged in the terminal in advance and used for detecting the operating temperature of internal equipment.
It will be appreciated by those skilled in the art that the block diagram of fig. 5 is only a block diagram of a portion of the structure associated with the inventive arrangements and does not constitute a limitation of the terminal to which the inventive arrangements are applied, and that a particular terminal may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, a terminal is provided that includes a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured for execution by the one or more processors to perform the one or more programs includes instructions for:
when a program is in an abnormal operation state, acquiring call relation data between functions corresponding to the program in the abnormal operation state;
and acquiring memory data of a function corresponding to the abnormal operation state in the program.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, databases, or other media used in embodiments provided herein may include non-volatile and/or volatile memory. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
In summary, the present invention discloses a method, an apparatus, a terminal and a storage medium for acquiring data when a program runs abnormally, wherein the method includes: when a program is in an abnormal operation state, acquiring call relation data between functions corresponding to the program in the abnormal operation state; and acquiring memory data of a function corresponding to the abnormal operation state in the program. According to the method and the device, the abnormal operation state appearing in the program is obtained, and the call relation data and the memory data of the function corresponding to the abnormal operation state are further obtained, so that the abnormity can be solved according to the stored data.
It is to be understood that the invention is not limited to the examples described above, but that modifications and variations may be effected thereto by those of ordinary skill in the art in light of the foregoing description, and that all such modifications and variations are intended to be within the scope of the invention as defined by the appended claims.
Claims (10)
1. A data acquisition method when a program runs abnormally is characterized by comprising the following steps:
when a program is in an abnormal operation state, acquiring call relation data between functions corresponding to the program in the abnormal operation state;
and acquiring memory data of a function corresponding to the abnormal operation state in the program.
2. The method according to claim 1, wherein the obtaining memory data of a function in the program corresponding to the abnormal operating state includes:
acquiring the abnormal operation state, and analyzing the abnormal operation state to obtain a function corresponding to the abnormal operation state;
and acquiring the calling relation data between the called function and the caller function from the functions.
3. The method for acquiring data during program running exception according to claim 1, wherein the acquiring call relation data between a called function and a caller function from the function comprises:
acquiring a stack frame address of a called function, and acquiring an instruction address of a caller function from the stack frame address of the called function;
and acquiring the length of the application stack frame of the caller function from the instruction address of the caller function to obtain the data of the calling relationship between the called function and the caller function.
4. The method according to claim 3, wherein the obtaining memory data of a function in the program corresponding to the abnormal operation state includes:
and acquiring a stack frame address corresponding to the function, and acquiring memory data from the stack frame address.
5. The method according to claim 4, wherein the obtaining memory data from the stack frame address includes:
acquiring memory data of the called function from the stack frame address of the called function;
the method comprises the steps of obtaining a stack frame address of a caller function, and obtaining memory data of the caller function from the stack frame address of the caller function.
6. The method as claimed in claim 5, wherein the stack frame address of the caller function is a stack frame length of the caller function plus a stack frame address of the called function.
7. The method for acquiring data when a program runs abnormally according to claim 4, wherein the acquiring of the call relation data between the called function and the caller function comprises:
and repeatedly executing the steps of acquiring the stack frame address of the called function, acquiring the instruction address of the caller function from the stack frame address of the called function, and acquiring the application stack frame length of the caller function from the instruction address of the caller function until the calling relation data among all the functions are found out.
8. A data acquisition apparatus when a program runs abnormally, the apparatus comprising:
the system comprises a first acquisition unit, a second acquisition unit and a control unit, wherein the first acquisition unit is used for acquiring call relation data between functions corresponding to a program in an abnormal operation state when the program is in the abnormal operation state;
and the second acquisition unit is used for acquiring the memory data of the function corresponding to the abnormal operation state in the program.
9. A terminal comprising a memory, and one or more programs, wherein the one or more programs are stored in the memory, and wherein the one or more programs being configured to be executed by the one or more processors comprises instructions for performing the method of any of claims 1-7.
10. A non-transitory computer readable storage medium having instructions therein, which when executed by a processor of an electronic device, enable the electronic device to perform the method of any one of claims 1-7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911267269.5A CN111124900A (en) | 2019-12-11 | 2019-12-11 | Data acquisition method and device during abnormal program operation, terminal and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911267269.5A CN111124900A (en) | 2019-12-11 | 2019-12-11 | Data acquisition method and device during abnormal program operation, terminal and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN111124900A true CN111124900A (en) | 2020-05-08 |
Family
ID=70498585
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201911267269.5A Pending CN111124900A (en) | 2019-12-11 | 2019-12-11 | Data acquisition method and device during abnormal program operation, terminal and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111124900A (en) |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101539883A (en) * | 2009-05-05 | 2009-09-23 | 北京和利时***工程有限公司 | Error tracking method of embedded system and device thereof |
CN107451045A (en) * | 2016-05-31 | 2017-12-08 | 北京信威通信技术股份有限公司 | A kind of method and device of abnormal information positioning |
-
2019
- 2019-12-11 CN CN201911267269.5A patent/CN111124900A/en active Pending
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101539883A (en) * | 2009-05-05 | 2009-09-23 | 北京和利时***工程有限公司 | Error tracking method of embedded system and device thereof |
CN107451045A (en) * | 2016-05-31 | 2017-12-08 | 北京信威通信技术股份有限公司 | A kind of method and device of abnormal information positioning |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110647320A (en) | Project framework construction method and device, computer equipment and storage medium | |
CN110928653A (en) | Cross-cluster task execution method and device, computer equipment and storage medium | |
CN111008188A (en) | Data migration method and device, computer equipment and storage medium | |
CN110851159B (en) | Business rule updating method and device, computer equipment and storage medium | |
CN111209164B (en) | Abnormality information storage method and device, electronic equipment and storage medium | |
CN111797026A (en) | Test case generation method and device, computer equipment and storage medium | |
CN110659092A (en) | Webpage screenshot method and device, computer equipment and storage medium | |
EP3905740A1 (en) | Sim card registration method and apparatus, computer device, and storage medium | |
CN108241516B (en) | Embedded system program loading method and device, computer equipment and storage medium | |
CN111177605B (en) | Single-page loading performance monitoring method and device and related equipment | |
CN111224939B (en) | Task request intercepting method and device, computer equipment and storage medium | |
CN110674145A (en) | Data consistency detection method and device, computer equipment and storage medium | |
CN112905378B (en) | Crash information analysis method, device, electronic equipment and readable storage medium | |
CN115292201B (en) | Function call stack parsing and backtracking method and device | |
CN111124900A (en) | Data acquisition method and device during abnormal program operation, terminal and storage medium | |
CN110795197A (en) | Method and device for internationalizing enumerated classes, computer equipment and storage medium | |
CN111241537A (en) | Task stack overflow detection method and system | |
CN114218188A (en) | Data migration method, device, equipment and storage medium | |
CN110704218B (en) | Data processing method, data processing device, computer equipment and storage medium | |
CN115437625A (en) | Page scaling method, container assembly, device, equipment and storage medium | |
CN111124814A (en) | SOC memory access monitoring method and device and computer equipment | |
CN114691347A (en) | Thread memory obtaining method and device, intelligent terminal and storage medium | |
CN112766067A (en) | Method and system for acquiring 3D face recognition module calibration data, computer and storage medium | |
CN112085791A (en) | Automatic positioning method, device and equipment for construction design drawing and storage medium | |
CN112181831A (en) | Script performance verification method, device and equipment based on keywords 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 |