Exception handling method, device, equipment and storage medium for smart wearable device
By eliminating local variables and formal parameters in the task stack information in the smart wearable device, only the register value is retained, and the function call relationship is analyzed, the analysis failure problem of smart wearable device exceptions is solved, and the exception is accurately positioned.
Patent Information
- Application Number
- CN202111645676.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-29
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2041-12-29
AI Technical Summary
When smart wearable devices are abnormal, parsing log files is prone to failure, resulting in difficulty in locating abnormalities.
After obtaining the task stack information, local variables and formal parameters are eliminated, only the register value that is pressed is retained, and exception processing is performed by analyzing the function call relationship.
Ensure the parsing is correct, and the exception is accurately positioned, avoiding the failure of log file parsing.
Smart Images

Figure CN114296982B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of smart wearable technology, and more specifically, to a method and apparatus for handling exceptions in a smart wearable device, an electronic device, and a computer-readable storage medium. Background Art
[0002] Smart wearable devices such as smart watches and smart bracelets are now widely used. During user use, abnormalities can cause problems such as freezing, restarting, and bricking. However, since the product is already in the user's hands, developers lack access to online debugging cables. This is why offline logging is so crucial.
[0003] In related technologies, when an abnormal situation occurs during product use, the task stack information is saved in a log file, and the log file is parsed to locate the abnormality and analyze the problem scenario. However, parsing log files is prone to parsing failures.
[0004] Therefore, how to avoid the failure of parsing log files when the smart wearable device is abnormal is a technical problem that needs to be solved by those skilled in the art. Summary of the Invention
[0005] The purpose of this application is to provide an exception handling method and device for a smart wearable device, an electronic device, and a computer-readable storage medium to avoid failure in parsing log files when an exception occurs in the smart wearable device.
[0006] To achieve the above objectives, the present application provides an exception handling method for a smart wearable device, comprising:
[0007] Get the task stack information of tasks in smart wearable devices;
[0008] Eliminating local variables and formal parameters in the task stack information to obtain target task stack information; wherein the target task stack information only includes the pushed register values;
[0009] Parsing the target task stack information to obtain a function call relationship;
[0010] Exception handling is performed based on the function call relationship.
[0011] The removing of local variables and formal parameters from the task stack information includes:
[0012] Eliminate machine codes whose lowest bits in the task stack information are even numbers.
[0013] The removing of local variables and formal parameters from the task stack information includes:
[0014] Determine the encoding rules for function jump instructions;
[0015] Eliminate machine codes that do not comply with the encoding rules in the task stack information.
[0016] The step of removing the machine code that does not comply with the encoding rule from the task stack information includes:
[0017] Disassembling the task stack information to obtain assembly language code;
[0018] Determining target assembly language code that does not conform to the encoding rule in the assembly language code;
[0019] The machine code obtained by assembling the target assembly language code from the task stack information is removed.
[0020] The target task stack information is parsed to obtain a function call relationship, including:
[0021] Determine the address range of all functions;
[0022] Comparing the instructions in the target task stack information with the address ranges of the functions respectively to determine the target functions corresponding to the instructions in the target task stack information respectively;
[0023] A function call relationship is determined based on target functions corresponding to the instructions in the target task stack information.
[0024] The step of comparing the instructions in the target task stack information with the address range of the function includes:
[0025] Determine the instruction size, sequentially retrieve the instruction size information from the target task stack information, and compare it with the address range of the function.
[0026] The performing of exception handling based on the function call relationship includes:
[0027] The abnormal time and abnormal position are obtained, and the code at the abnormal position is modified based on the function call relationship.
[0028] To achieve the above objectives, the present application provides an exception handling device for a smart wearable device, comprising:
[0029] The acquisition module is used to obtain the task stack information of the tasks in the smart wearable device;
[0030] A removal module is used to remove local variables and formal parameters in the task stack information to obtain target task stack information; wherein the target task stack information only includes the register values pushed onto the stack;
[0031] A parsing module, configured to parse the target task stack information to obtain a function call relationship;
[0032] A processing module is used to perform exception processing based on the function call relationship.
[0033] To achieve the above objectives, the present application provides an electronic device, comprising:
[0034] memory for storing computer programs;
[0035] A processor is used to implement the steps of the above-mentioned exception handling method for the smart wearable device when executing the computer program.
[0036] To achieve the above-mentioned purpose, the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the exception handling method for the smart wearable device as described above are implemented.
[0037] From the above scheme, it can be seen that the exception handling method of an intelligent wearable device provided in the present application includes: obtaining task stack information of a task in the intelligent wearable device; removing local variables and formal parameters in the task stack information to obtain target task stack information; wherein, the target task stack information only contains the pushed register values; parsing the target task stack information to obtain a function call relationship; and performing exception handling based on the function call relationship.
[0038] The exception handling method for a smart wearable device provided in this application obtains task stack information by removing local variables and formal parameters, saving only the pushed register values, and obtaining target task stack information. This method ensures correct parsing of the target task stack information, and locates the exception through the parsed function call relationships. This application also discloses an exception handling device for a smart wearable device, an electronic device, and a computer-readable storage medium, all of which can achieve the aforementioned technical effects.
[0039] It should be understood that the foregoing general description and the following detailed description are merely illustrative and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following will briefly introduce the drawings required for the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. The drawings are used to provide a further understanding of the present disclosure and constitute part of the specification. Together with the following specific embodiments, they are used to explain the present disclosure, but do not constitute a limitation of the present disclosure. In the drawings:
[0041] Figure 1 This is a flowchart of a method for handling an exception in a smart wearable device according to an exemplary embodiment.
[0042] Figure 2 1 is a structural diagram of an exception handling device for a smart wearable device according to an exemplary embodiment;
[0043] Figure 3 The figure is a structural diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0044] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application. In addition, in the embodiments of the present application, "first", "second", etc. are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0045] The embodiment of the present application discloses an exception handling method for a smart wearable device, which avoids failure in parsing log files when the smart wearable device is abnormal.
[0046] See also Figure 1 , according to an exemplary embodiment, a flowchart of a method for handling an exception of a smart wearable device is shown, as shown in FIG. Figure 1 Shown, including:
[0047] S101: Obtaining task stack information of tasks in the smart wearable device;
[0048] The purpose of this embodiment is to locate the abnormality of the smart wearable device. In the specific implementation, when the smart wearable device has an abnormality, the task stack information of each task therein is saved in the log file. Of course, the abnormal time and abnormal location of the abnormality can also be saved in the log file, that is, the location of the function running the error.
[0049] S102: removing local variables and formal parameters from the task stack information to obtain target task stack information; wherein the target task stack information only includes the pushed register values;
[0050] It's important to note that log file parsing involves comparing task stack information with the address ranges of all functions stored in the map file. Because task stack information includes not only the pushed register values corresponding to the functions but also local variables and formal parameters, parsing can interpret these local variables and formal parameters as functions, confusing the function call chain and causing parsing failure. In other words, even though local variables and function parameters aren't particularly critical data, their presence in the task stack information can cause log file parsing failures.
[0051] Therefore, in this embodiment, the local variables and formal parameters in the task stack information are removed to obtain the target task stack information, and only the pushed register values are retained in the target task stack information, thereby ensuring that the subsequent parsing of the target task stack information is correct.
[0052] As a feasible implementation manner, removing local variables and formal parameters in the task stack information includes: removing machine codes whose lowest bits in the task stack information are even numbers.
[0053] It's understandable that due to the differences between the ARM (Advanced RISC Machines) and Thumb instruction sets, ARMv6-M and ARMv7-M only support the Thumb instruction set in unprivileged mode. This allows for the elimination of variables from task stack information. The ARM instruction set is a 32-bit instruction set characterized by high execution efficiency. The Thumb instruction set is a 16-bit instruction set, a subset of the ARM instruction set. The Thumb instruction set offers higher code density, significantly saving memory space. However, this instruction set is not a complete set; a processor cannot support only the Thumb instruction set without the ARM instruction set. The ARM instruction set is used during an exception interrupt, while the Thumb instruction set is used in unprivileged mode. Thumb-2 technology adds some instructions to the Thumb instruction set that are identical to the ARM instruction set (mostly 32-bit instructions), reducing the operational constraints of the Thumb instruction set and reducing the switching between Thumb and ARM instructions when switching between privileged and unprivileged modes. It's important to note that Thumb instructions are 2-byte aligned, while ARM instructions are 4-byte aligned. To distinguish Thumb instructions from ARM instructions, the ARM core encodes the lowest bit of Thumb instructions as an odd number, while the lowest bit of ARM instructions is an even number. Therefore, variables and instructions can be filtered out based on the odd and even number distinction. That is, in the ARMv6-M and ARMv7-M architectures, only odd numbers represent the machine code for the instruction set in the task stack, while even numbers represent the machine code for variables or formal parameters. This means that machine codes with even lowest bits in the task stack are discarded, retaining only those with odd lowest bits, thus retaining only the instructions in the task stack.
[0054] As another feasible implementation, the removing of local variables and formal parameters in the task stack information includes: determining encoding rules for function jump instructions; and removing machine codes in the task stack information that do not comply with the encoding rules.
[0055] In a specific implementation, non-register values can be filtered out based on the encoding rules of jump instructions BL and BLX, and machine code in the task stack information that does not conform to the encoding rules for jump instructions can be removed. Specifically, the task stack information is disassembled to obtain assembly language code, and target assembly language code that does not conform to the encoding rules for jump instructions is identified within the assembly language code, and the machine code assembled from the target assembly language code in the task stack information is removed.
[0056] S103: parsing the target task stack information to obtain a function call relationship;
[0057] In this step, the target task stack information, which only retains register values, is parsed to obtain a function call relationship. As a feasible implementation method, this step includes: determining the address range of all functions; comparing the instructions in the target task stack information with the address range of the functions to determine the target functions corresponding to the instructions in the target task stack information; and determining the function call relationship based on the target functions corresponding to the instructions in the target task stack information.
[0058] It is understandable that parsing requires a map file and a log file. The map file records the address range of all functions, which can be recorded in the form of the function's starting address and size. The log file records the target task stack information, exception time, and exception location. In specific implementation, the exception time and exception location are parsed according to the log file, and then the target task stack information is taken out from the log file, and the instruction size information is taken out in turn, and compared with the address range of each function in the map file to obtain the function corresponding to each instruction, and then determine the function call relationship. For example, if the instruction size is 4 bytes, 4 bytes of information are taken out from the target task stack information in turn and compared with the address range of each function.
[0059] S104: Perform exception handling based on the function call relationship.
[0060] In a specific implementation, the exception time, exception location and function call relationship are parsed according to the log file, and the exception is handled based on the function call relationship. As a feasible implementation method, the code at the exception location is modified based on the function call relationship.
[0061] The exception handling method for a smart wearable device provided in an embodiment of the present application, after obtaining the task stack information, removes the local variables and formal parameters therein, saves only the register values pushed on the stack, and obtains the target task stack information. When parsing the target task stack information, the correct parsing can be ensured, and the exception is located through the parsed function call relationship.
[0062] The following introduces an exception handling device for a smart wearable device provided in an embodiment of the present application. The exception handling device for a smart wearable device described below and the exception handling method for a smart wearable device described above can be referenced to each other.
[0063] See also Figure 2 , according to an exemplary embodiment, a structural diagram of an exception handling device for a smart wearable device is shown, such as Figure 2 Shown, including:
[0064] An acquisition module 201 is used to acquire task stack information of tasks in the smart wearable device;
[0065] The elimination module 202 is used to eliminate local variables and formal parameters in the task stack information to obtain target task stack information; wherein the target task stack information only includes the pushed register values;
[0066] The parsing module 203 is used to parse the target task stack information to obtain a function call relationship;
[0067] The processing module 204 is configured to perform exception processing based on the function call relationship.
[0068] The exception handling device for a smart wearable device provided in an embodiment of the present application, after obtaining the task stack information, removes the local variables and formal parameters therein, saves only the register values pushed on the stack, and obtains the target task stack information. When parsing the target task stack information, it can ensure that the parsing is correct, and the exception is located through the parsed function call relationship.
[0069] Based on the above embodiment, as a preferred implementation, the rejection module 202 includes:
[0070] The first elimination unit is configured to eliminate machine codes whose lowest bits in the task stack information are even numbers.
[0071] Based on the above embodiment, as a preferred implementation, the rejection module 202 includes:
[0072] The second elimination unit is used to determine the encoding rules of the function jump instructions and eliminate the machine codes that do not comply with the encoding rules in the task stack information.
[0073] Based on the above embodiment, as a preferred implementation mode, the second elimination unit specifically determines the encoding rules of the function jump instruction, disassembles the task stack information to obtain the assembly language code, determines the target assembly language code that does not comply with the encoding rules in the assembly language code, and eliminates the unit of the machine code assembled from the target assembly language code in the task stack information.
[0074] Based on the above embodiment, as a preferred implementation, the parsing module 203 includes:
[0075] A first determining unit, configured to determine the address range of all functions;
[0076] A comparing unit, configured to compare the instructions in the target task stack information with the address ranges of the functions respectively, to determine target functions corresponding to the instructions in the target task stack information respectively;
[0077] The second determining unit is configured to determine a function call relationship based on target functions corresponding to the instructions in the target task stack information.
[0078] Based on the above embodiments, as a preferred implementation, the comparison unit specifically determines the instruction size, takes out the instruction size information from the target task stack information in sequence, and compares it with the address range of the function to determine the modules of the target function corresponding to the instructions in the target task stack information.
[0079] Based on the above embodiment, as a preferred implementation, the processing module 204 is specifically a module for obtaining the abnormal time and abnormal location, and modifying the code at the abnormal location based on the function call relationship.
[0080] Regarding the apparatus in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0081] Based on the hardware implementation of the above program modules, and in order to implement the method of the embodiment of the present application, the embodiment of the present application further provides an electronic device, Figure 3 FIG. 1 is a structural diagram of an electronic device according to an exemplary embodiment. Figure 3 As shown, the electronic equipment includes:
[0082] Communication interface 1, capable of exchanging information with other devices such as network devices;
[0083] The processor 2 is connected to the communication interface 1 to implement information exchange with other devices and is used to execute the exception handling method of the smart wearable device provided by one or more of the above technical solutions when running a computer program. The computer program is stored in the memory 3.
[0084] Of course, in actual application, the various components in the electronic device are coupled together through the bus system 4. It can be understood that the bus system 4 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 4 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, Figure 3 Various buses are labeled as bus system 4.
[0085] The memory 3 in the embodiment of the present application is used to store various types of data to support the operation of the electronic device. Examples of such data include: any computer program used to operate on the electronic device.
[0086] It is understood that the memory 3 can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a flash memory, a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM); the magnetic surface memory can be a magnetic disk memory or a magnetic tape memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), synchronous static random access memory (SSRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct rambus random access memory (DRRAM).The memory 3 described in the embodiments of the present application is intended to include but is not limited to these and any other suitable types of memories.
[0087] The method disclosed in the above-mentioned embodiment of the present application can be applied to processor 2 or implemented by processor 2. Processor 2 may be an integrated circuit chip with signal processing capabilities. During the implementation process, each step of the above-mentioned method can be completed by the integrated logic circuit of the hardware in processor 2 or instructions in the form of software. The above-mentioned processor 2 can be a general-purpose processor, DSP, or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Processor 2 can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiment of the present application can be directly embodied as being executed by a hardware decoding processor, or being executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium, which is located in memory 3. Processor 2 reads the program in memory 3 and completes the steps of the above-mentioned method in combination with its hardware.
[0088] When the processor 2 executes the program, the corresponding processes in the various methods of the embodiments of the present application are implemented. For the sake of brevity, they are not repeated here.
[0089] In an exemplary embodiment, the present application also provides a storage medium, namely, a computer storage medium, specifically a computer-readable storage medium, such as a memory 3 storing a computer program. The computer program can be executed by a processor 2 to perform the steps of the aforementioned method. The computer-readable storage medium can be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, Flash Memory, magnetic surface storage, optical disk, or CD-ROM.
[0090] Those skilled in the art will understand that all or part of the steps of implementing the above-mentioned method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above-mentioned method embodiment; and the aforementioned storage medium includes: mobile storage devices, ROM, RAM, disks or optical disks, etc. Various media that can store program codes.
[0091] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions for enabling an electronic device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.
[0092] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
Claims
1. A method for handling exceptions in a smart wearable device, characterized in that: include: Get the task stack information of tasks in smart wearable devices; Eliminating local variables and formal parameters in the task stack information to obtain target task stack information; wherein the target task stack information only includes the pushed register values; Parsing the target task stack information to obtain a function call relationship; Perform exception handling based on the function call relationship; The removing of local variables and formal parameters from the task stack information includes: Determine the encoding rules for function jump instructions; The machine code that does not comply with the encoding rule is removed from the task stack information.
2. The exception handling method according to claim 1, characterized in that: The removing of local variables and formal parameters from the task stack information includes: Eliminate machine codes whose lowest bits in the task stack information are even numbers.
3. The exception handling method according to claim 1, characterized in that: The removing of machine codes that do not comply with the encoding rules from the task stack information includes: Disassembling the task stack information to obtain assembly language code; Determining target assembly language code that does not conform to the encoding rule in the assembly language code; The machine code obtained by assembling the target assembly language code from the task stack information is removed.
4. The exception handling method according to claim 1, characterized in that: Parsing the target task stack information to obtain a function call relationship includes: Determine the address range of all functions; Comparing the instructions in the target task stack information with the address ranges of the functions respectively to determine the target functions corresponding to the instructions in the target task stack information respectively; A function call relationship is determined based on target functions corresponding to the instructions in the target task stack information.
5. The exception handling method according to claim 4, characterized in that: Comparing the instructions in the target task stack information with the address range of the function respectively includes: Determine the instruction size, sequentially retrieve the instruction size information from the target task stack information, and compare it with the address range of the function.
6. The exception handling method according to claim 1, characterized in that: The performing exception handling based on the function call relationship includes: The abnormal time and abnormal position are obtained, and the code at the abnormal position is modified based on the function call relationship.
7. An abnormality handling device for a smart wearable device, characterized in that: include: The acquisition module is used to obtain the task stack information of the tasks in the smart wearable device; A removal module is used to remove local variables and formal parameters in the task stack information to obtain target task stack information; wherein the target task stack information only includes the register values pushed onto the stack; A parsing module, configured to parse the target task stack information to obtain a function call relationship; A processing module, configured to perform exception handling based on the function call relationship; The elimination module is specifically used to determine the encoding rules of function jump instructions; and eliminate machine codes that do not comply with the encoding rules in the task stack information.
8. An electronic device, characterized in that: include: memory for storing computer programs; A processor, configured to implement the steps of the exception handling method for a smart wearable device according to any one of claims 1 to 6 when executing the computer program.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, the steps of the exception handling method for the smart wearable device according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Error tracking method of embedded system and device thereof
CN101539883A