Program debugging method and device, electronic equipment and storage medium

By writing the execution address of the instruction to be tested into the monitor register and detecting the user-mode register, the problem of low program debugging efficiency in the prior art is solved, and the accurate location and efficient debugging of program problems are achieved.

CN114661606BActive Publication Date: 2026-02-17LOONGSON TECH CORP
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210334226.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-31
Publication Date
2026-02-17
Estimated Expiration
2042-03-31

AI Technical Summary

Technical Problem

Existing technologies make it difficult to accurately locate problems in programs, resulting in low debugging efficiency.

Method used

The monitoring process writes the execution address of the instruction to be tested to the monitoring register and controls the debugged process of the target program to execute the instruction to be tested. Then, the monitoring process detects the specified register in the user-mode register corresponding to the target program to debug the target program.

Benefits of technology

It enables convenient location of problems in the code portion of the target program that executes the instructions to be tested, improving the accuracy and efficiency of program debugging.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114661606B_ABST
    Figure CN114661606B_ABST
Patent Text Reader

Abstract

This invention provides a program debugging method, apparatus, electronic device, and storage medium. In this method, a monitoring process writes the execution address of a test instruction to a monitoring register and controls the debugged process of the target program to execute the test instruction, which belongs to the executable instruction set of the target program. After the debugged process executes the test instruction, the monitoring process detects a specified register in the user-mode register corresponding to the target program to debug the target program. The specified register corresponds to the currently executed test instruction. This allows for convenient determination of whether there are problems in the code portion of the target program used to execute the test instruction, thus enabling relatively accurate location of problems in the target program.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of program, in particular to a program debugging method and device, electronic equipment and storage medium. BACKGROUND

[0002] At present, with the continuous development of network, more and more programs are adapted to the equipment. In order to ensure that the developed program can be used normally, it is necessary to detect whether the program has problems and locate the existing problems. Therefore, how to accurately locate the problems existing in the program has become a problem to be solved. SUMMARY

[0003] The present application provides a program debugging method, device, electronic equipment and storage medium, which can accurately locate the problems existing in the program.

[0004] In a first aspect, the present application provides a program debugging method, which comprises:

[0005] The monitoring process writes the running address of the to-be-tested instruction into the monitoring register, and controls the debugging process of the target program to execute the to-be-tested instruction; the to-be-tested instruction belongs to the instruction set executable by the target program;

[0006] After the debugging process of the target program executes the to-be-tested instruction, the monitoring process detects a specified register in the user-mode register corresponding to the target program, so as to debug the target program; the specified register corresponds to the to-be-tested instruction executed this time.

[0007] Optionally, after the control of the debugging process of the target program to execute the to-be-tested instruction, the method further comprises:

[0008] Clearing the running address currently written in the monitoring register;

[0009] Based on the monitoring process, the running address of the next to-be-tested instruction is written into the monitoring register, so as to control the debugging process of the target program to execute the next to-be-tested instruction again.

[0010] Optionally, the clearing of the running address currently written in the monitoring register comprises:

[0011] Starting an interrupt, and writing a pre-configured clearing instruction into the interrupt information of the interrupt;

[0012] In response to the interrupt, the clearing instruction written in the interrupt information is executed to clear the running address currently written in the monitoring register.

[0013] Optionally, the detecting the specified register in the user-mode register corresponding to the target program to debug the target program comprises:

[0014] obtaining a value of the specified register and comparing the value with a specified value;

[0015] if the value is inconsistent with the specified value, determining a code segment corresponding to the to-be-tested instruction in the target program as an abnormal code segment;

[0016] before the emptying the currently written running address in the monitoring register, the method further comprises: setting the value of the specified register as the specified value.

[0017] Optionally, the monitoring process implements the program debugging method by calling a debugging code module in an operating system kernel of the electronic device; the CPU of the electronic device is integrated with a monitoring register, the monitoring register is a bottom-layer register configured by the debugging code module, and a state parameter of the bottom-layer register is configured as a specified parameter.

[0018] In a second aspect, the present application provides a program debugging device, which comprises:

[0019] a control module configured to write, by a monitoring process, a running address of a to-be-tested instruction into a monitoring register and control a debugging process of a target program to execute the to-be-tested instruction; the to-be-tested instruction belongs to a set of executable instructions of the target program;

[0020] a detection module configured to detect, by the monitoring process, a specified register in a user-mode register corresponding to the target program to debug the target program after the debugging process of the target program executes the to-be-tested instruction; the specified register corresponds to the to-be-tested instruction executed this time.

[0021] Optionally, the device further comprises:

[0022] an emptying module configured to empty the currently written running address in the monitoring register after the control module controls the debugging process of the target program to execute the to-be-tested instruction;

[0023] based on the monitoring process writing a running address of a next to-be-tested instruction into the monitoring register, the debugging process of the target program is controlled to execute the next to-be-tested instruction again.

[0024] Optionally, the emptying module is specifically configured to:

[0025] start an interruption and write a pre-configured emptying instruction into interruption information of the interruption;

[0026] In response to the interrupt, the clear instruction written in the interrupt information is executed to clear the running address currently written in the monitoring register.

[0027] Optionally, the detection module is specifically configured to:

[0028] acquire the value of the specified register and compare the value with a specified value;

[0029] if the value is inconsistent with the specified value, determine the code segment corresponding to the to-be-tested instruction in the target program as an abnormal code segment;

[0030] The device further includes a setting module configured to set the value of the specified register to the specified value before the clearing module clears the running address currently written in the monitoring register.

[0031] Optionally, the monitoring process implements the function of the program debugging device by calling a debugging code module in the operating system kernel of the electronic device; the CPU of the electronic device is integrated with a monitoring register, the monitoring register is a bottom-layer register configured by the debugging code module, and a state parameter of the bottom-layer register is configured as a specified parameter.

[0032] In a third aspect, the present application provides an electronic device, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above method when executing the program.

[0033] In a fourth aspect, the present application provides a readable storage medium, when the instructions in the storage medium are executed by the processor of an electronic device, the electronic device can execute the above method.

[0034] The program debugging method provided by the embodiments of the present application writes the running address of the to-be-tested instruction into the monitoring register through the monitoring process, and controls the debugging process of the target program to execute the to-be-tested instruction, the to-be-tested instruction belonging to the executable instruction set of the target program. After the debugging process executes the to-be-tested instruction, the monitoring process detects the specified register in the user-mode register corresponding to the target program to debug the target program, the specified register corresponding to the to-be-tested instruction executed this time. In this way, in the debugging process, the running address of the to-be-tested instruction to be executed this time is written into the monitoring register, the debugging process of the target program is controlled to execute the to-be-tested instruction, and the specified register in the user-mode register corresponding to the target program is detected after execution, so that it can be determined whether the code part for executing the to-be-tested instruction in the target program has a problem, and the problem of the target program can be positioned more accurately to a certain extent. BRIEF DESCRIPTION OF DRAWINGS

[0035] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort based on these drawings.

[0036] Figure 1 is a step flow chart of a program debugging method provided by an embodiment of the present application;

[0037] Figure 2 is a flowchart provided by an embodiment of the present application;

[0038] Figure 3 is a structural block diagram of a program debugging device of the present application;

[0039] Figure 4 is a structural block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION

[0040] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative effort fall within the scope of the present application.

[0041] Figure 1 is a step flow chart of a program debugging method provided by an embodiment of the present application, which can be applied to an electronic device, and a monitoring register is integrated in the CPU of the electronic device. As shown in Figure 1 , the method can include:

[0042] Step 101: write the running address of a to-be-tested instruction into the monitoring register by a monitoring process, and control a debugging process of a target program to execute the to-be-tested instruction; the to-be-tested instruction belongs to an executable instruction set of the target program.

[0043] In the embodiment of the present application, the target program can be an application program that needs to be debugged, and the target program can be specified according to actual needs. Specifically, a monitoring process and a debugged process can be created after the target program is started and runs. For example, an executable file of the target program can be added to a preset software framework to form a main program. The main program is run in an electronic device to create the monitoring process and the debugged process. Further, the debugged process can be composed of multiple instructions, for example, the debugged process can be composed of instructions executable by the target program, and the debugged process can execute instructions in the set of instructions executable by the target program. In this way, the execution situation can be observed after the debugged process executes a certain instruction, so that debugging can be performed.

[0044] Specifically, a debugging command can be initiated to the debugged process based on the monitoring process, and accordingly, in response to the received debugging command, the monitoring process can read the running address currently written in the monitoring register, and execute the to-be-tested instruction based on the running address. The monitoring register can be a pre-specified underlying register integrated in the CPU, and is used at least to store the running address of the to-be-tested instruction. The program debugging function is implemented by configuring the monitoring register.

[0045] In step 102, after the debugged process executes the to-be-tested instruction, a specified register in a user-mode register corresponding to the target program is detected by the monitoring process to debug the target program. The specified register corresponds to the to-be-tested instruction executed this time.

[0046] In the embodiment of the present application, the user-mode register corresponding to the target program can be a register that will be used in the running of the target program, and the user-mode register is different from the monitoring register. The target program can write related parameters generated in the running process into the user-mode register. The user-mode register corresponding to the target program can be multiple, and after each instruction executable by the target program is executed, the user-mode register that is modified corresponds to the specified register corresponding to the instruction. After the debugged process executes the to-be-tested instruction, the debugged process can be in a stopped state. The state of the debugged process is detected by the monitoring process, that is, the specified register in the user-mode register corresponding to the target program is detected to determine whether the target program can normally execute the to-be-tested instruction, so that the target program is debugged. For example, if the content of the specified register in the user-mode register does not match the expected content, it is determined that there is a problem in the code part in the target program for implementing the execution of the to-be-tested instruction.

[0047] In summary, the program debugging method provided by the embodiment of the present application writes the running address of the to-be-tested instruction into the monitoring register through the monitoring process, controls the debugging process of the target program to execute the to-be-tested instruction, and the to-be-tested instruction belongs to the executable instruction set of the target program. After the debugging process executes the to-be-tested instruction, the monitoring process detects the specified register in the user state register corresponding to the target program to debug the target program. The specified register corresponds to the to-be-tested instruction executed this time. In this way, in the debugging process, the running address of the to-be-tested instruction to be executed this time is written into the monitoring register, the debugging process of the target program is controlled to execute the to-be-tested instruction, and the specified register in the user state register corresponding to the target program is detected after execution, so that whether the code part for implementing the to-be-tested instruction in the target program has a problem can be determined conveniently, and the problem of the target program can be located accurately to a certain extent.

[0048] Optionally, the program debugging method provided by the embodiment of the present application can be applied to an electronic device, and the operating system kernel of the electronic device can include a debugging code module. The program debugging method can be implemented based on the debugging code module in the operating system kernel. Specifically, the monitoring process can call the debugging code module to perform the operation of writing the running address of the to-be-tested instruction into the monitoring register, the operation of controlling the debugging process of the target program to execute the to-be-tested instruction, and the operation of detecting the specified register in the user state register corresponding to the target program to debug. That is, the operation performed by the monitoring process can be implemented by the monitoring process by calling the debugging code module in the operating system kernel. Further, the monitoring register is integrated in the CPU of the electronic device, and the monitoring register can be a bottom layer register configured by the debugging code module. The state parameter of the bottom layer register is configured as a specified parameter, and the specific bottom layer register to be configured can be predefined in the debugging code module. That is, the operating system kernel of the electronic device can provide a debugging function, and the monitoring register can be used to support the debugging operation and provide hardware support for the debugging operation. The monitoring register can be multiple, and the monitoring register specifically includes a bottom layer register for writing the running address of the to-be-tested instruction. The bottom layer register configured by the debugging code module can be predefined in hardware development. It can be understood that the bottom layer register configured by the debugging code module can be a register reserved in hardware design to implement program debugging, and the specified parameter can also be predefined. By configuring the state parameter of the bottom layer register as the specified parameter, it can be indicated that the bottom layer register has been used to implement program debugging, so as to avoid the problem of conflict caused by using the bottom layer register for other functions.

[0049] Optionally, after the debugging process of the target program executes the to-be-tested instruction, the following operation can be performed in the embodiment of the present application:

[0050] Step S21, emptying the currently written running address in the monitoring register.

[0051] In the embodiment of the present application, the currently written running address in the monitoring register can be directly deleted to achieve emptying, thereby saving space and avoiding interference with subsequent operations. The currently written running address in the monitoring register can be the running address of the last instruction to be tested.

[0052] Step S22, based on the monitoring process, writing the running address of the next instruction to be tested into the monitoring register to control the debugging process to execute the next instruction to be tested again.

[0053] The next instruction to be tested can be specified according to actual needs. For example, the next instruction to be tested can be an instruction after the last executed instruction in the execution order. In response to a specified command, the instruction indicated by the specified command can be taken as the next instruction to be tested. Specifically, the next instruction to be tested can be adjacent to the last executed instruction to be tested, or can be separated from the last executed instruction to be tested by a plurality of instructions, and the embodiment of the present application does not limit this. For example, assuming that the instructions executable by the target program are in the execution order from front to back: instruction 0, instruction 1, instruction 2, instruction 3, instruction 4, instruction 5, the last executed instruction to be tested is instruction 1, then one of instruction 2, instruction 3, instruction 4 and instruction 5 can be selected as the next instruction to be tested, for example, instruction 2 can be selected as the next instruction to be tested, or instruction 3 can be selected as the next instruction to be tested.

[0054] Further, the monitoring process can be based on the debug code module called by the monitoring process to perform the write operation to write the running address of the next instruction to be tested into the monitoring register. Specifically, the running address of the next instruction to be tested can be written into a pre-designated underlying register integrated in the CPU. Accordingly, the above-mentioned emptying operation can be emptying the written running address in the underlying register of the monitoring register for writing the running address of the instruction to be tested. It should be noted that during program debugging, the running address of the first instruction to be tested can be written after entering the debugging mode, or can be written before, and the embodiment of the present application does not limit this. The running address corresponding to each instruction can be predefined.

[0055] In the embodiment of the present application, the running address currently written in the monitoring register is emptied. The monitoring process writes the running address of the next instruction to be tested into the monitoring register, so as to control the debugging process to execute the next instruction to be tested. In this way, the debugging of multiple instructions to be tested can be performed separately, and the execution of which instruction to be tested causes the problem can be located conveniently to a certain extent.

[0056] It should be noted that after the running address of the next instruction to be tested is written into the monitoring register, the debugging command can be sent to the debugging process again to control the debugging process to execute the redefined instruction to be tested (i.e., the next instruction to be tested). Of course, after the next instruction to be tested is executed, the running address of the next instruction to be tested can be redefined continuously until each instruction to be executed is executed, the debugging operation is ended, and the debugging mode is exited. That is, the single-step debugging of each instruction to be tested can be performed in the embodiment of the present application. After the single-step debugging is completed, that is, after each instruction to be executed is executed, the monitoring process can send the stop debugging command, and the debugging process receives the stop debugging command, exits the single-step debugging mode, and continues to execute the remaining part directly, that is, continues to execute to the end.

[0057] Optionally, the operation of emptying the running address currently written in the monitoring register can specifically include the following steps.

[0058] Step S31, the interrupt is started, and the pre-configured emptying instruction is written in the interrupt information of the interrupt.

[0059] In the embodiment of the present application, the debugging code module called by the monitoring process can start the interrupt based on the interrupt service function, so that the CPU of the electronic device processes the operation indicated in the interrupt information of the interrupt. Specifically, the pre-configured emptying instruction can be written in the interrupt information of the interrupt to perform the emptying operation. The pre-configured emptying instruction can be pre-defined in the debugging code.

[0060] Step S32, in response to the interrupt, the emptying instruction written in the interrupt information is executed to empty the running address currently written in the monitoring register.

[0061] Specifically, the CPU of the electronic device can execute the emptying instruction transmitted in the interrupt information, so as to empty the running address currently written in the monitoring register.

[0062] In the embodiment of the present application, the interrupt is enabled, and a pre-configured clearing instruction is written in the interrupt information of the interrupt. In response to the interrupt, the clearing instruction written in the interrupt information is executed to clear the running address currently written in the monitoring register. In this way, it can be ensured to some extent that the clearing operation can be successfully executed, so that the running address of the to-be-tested instruction required to be executed subsequently can be successfully written, and the debugging operation can continue.

[0063] Optionally, the operation of detecting the specified register in the user-mode register corresponding to the target program to debug the target program can specifically include:

[0064] In step S41, the value in the specified register is acquired, and the value is compared with the specified value.

[0065] In the embodiment of the present application, the monitoring process can view the program parameter through the called debugging code module, that is, view the value in the specified register. The debugging code module can deliver the value in the specified register to the monitoring process. The value in the specified register can be a related parameter generated after the execution of the to-be-tested instruction, for example, a parameter representing the user-mode state. The specified value can be a value generated after the normal execution of the to-be-tested instruction, which is set in the software development process.

[0066] If the value is consistent with the specified value after comparison, it can be determined that the to-be-tested instruction can be normally executed. If the value is inconsistent with the specified value, that is, the value in the specified register is inconsistent with the specified value, it can be determined that the to-be-tested instruction cannot be normally executed, and there can be a problem.

[0067] In step S42, if the value is inconsistent with the specified value, the code segment corresponding to the to-be-tested instruction in the target program is determined as an abnormal code segment.

[0068] The code segment corresponding to the to-be-tested instruction can be a code part for executing the to-be-tested instruction. Since the value in the specified register is inconsistent with the specified value, it can be indicated to some extent that there can be a problem in this part of code. Therefore, the corresponding code segment can be determined as an abnormal code segment, so as to be modified in subsequent operations. Of course, other modification operations can also be performed, for example, viewing and modifying the memory region corresponding to the to-be-tested instruction, injecting code into the function in the debugged process, and the like.

[0069] In the embodiment of the present application, the value in the specified register is acquired, and the value is compared with the specified value. If the value is inconsistent with the specified value, the code segment corresponding to the to-be-tested instruction in the target program is determined as an abnormal code segment. In this way, the abnormal code segment can be accurately located, so as to facilitate adjustment.

[0070] Accordingly, before the operation of emptying the currently written running address in the monitoring register, the embodiment of the present application can further perform the following operation: in step S51, the value of the specified register is set to the specified value. Specifically, the value of the specified register can be set to the specified value by the called debug code module. Of course, if the value is consistent with the specified value, the operation of emptying the currently written running address in the configuration register can be directly performed.

[0071] Specifically, the value of the specified register can be emptied, and then the specified value is written to the specified register to modify the program parameters. To ensure that the instructions after the to-be-tested instruction can continue to be executed from a normal state. In this way, after the value of the specified register is set to the specified value, the operation of emptying the currently written running address in the monitoring register is performed again, so that the problem that the next to-be-tested instruction cannot be normally executed due to the abnormal value in the specified register corresponding to the last executed to-be-tested instruction can be avoided.

[0072] In the embodiment of the present application, through the execution of one instruction at a time and the tracking of the result after the execution, the error and the error source can be accurately located, so that subsequent adjustment is facilitated.

[0073] Optionally, the embodiment of the present application can further include the following steps: the monitoring process or the debug code module called by the monitoring process sends a tracking command to the debugged process, the debugged process stops running in response to the received tracking command, and returns notification information to the monitoring process after stopping running, the notification information being used to indicate that the debugged process has received the tracking command and has stopped running, to notify the monitoring process that the debugging can be initiated. Specifically, the debug code module can be called through a system call to initiate the debugging. Specifically, single-step debugging can be initiated, so that the debugged process is prevented from running all the time and the specified register in the user-mode register corresponding to the target program cannot be detected in time. It should be noted that the electronic device can perform single-step debugging in the case of supporting single-step debugging. In the case of not supporting single-step debugging, a preset number can be returned, wherein the preset number can indicate that the current device does not support single-step debugging.

[0074] Compared with the method of changing only a single register flag bit and realizing the debugging function by the code pre-configured in the hardware, in the embodiment of the present application, the address and the state parameter are configured in the underlying register, so that the debugging function can be realized based on the debug code, the method of single-step debugging of the debugging tool under the architecture adopted by the electronic device is realized, and the debug code can be given more flexibility to a certain extent.

[0075] Figure 2is a flowchart provided by an embodiment of the present application, as shown in Figure 2 The main program can be formed by adding the executable file of the target program to the preset software framework. The monitoring process and the debugged process can be generated for the main program. For example, the main program is divided into the monitoring process and the debugged process based on the preset fork function. Then, the monitoring process can initiate a tracking command to the debugged process, and the debugged process can notify the monitoring process, i.e., stop running in response to the tracking command and return the notification information to the monitoring process. After receiving the notification, the monitoring process can initiate single-step debugging to make the debugged process execute one step, i.e., execute the to-be-executed instruction currently required to be executed. Correspondingly, after the debugged process executes one step, the monitoring process can view and modify the program parameters, i.e., view the value of the specified register and write the specified value to the specified register when the value is inconsistent with the specified value. After the end, the single-step debugging mode can be exited.

[0076] In an embodiment of the present application, one process views the state and the other process performs the related debugging action. The debugging module in the kernel can hijack the call of another process. The other process refers to the aforementioned debugged process, which can be hijacked to make the debugged process enter the stop state. During program debugging, the execution of another debugged process can be observed and controlled by the monitoring process, and the specified register corresponding to the debugged process can be checked and changed, so as to realize debugging and system call tracking. Moreover, since there are many parameters in program running, these parameters will be updated. In an embodiment of the present application, the generated data points in program running can be viewed through debugging, so as to locate the problem.

[0077] Figure 3 is a structural block diagram of a program debugging device provided by an embodiment of the present application, as shown in Figure 3 The device 20 can include:

[0078] The control module 201 is configured to write the running address of a to-be-tested instruction into a monitoring register through a monitoring process, and control the debugged process of a target program to execute the to-be-tested instruction. The to-be-tested instruction belongs to a set of executable instructions of the target program.

[0079] The detection module 202 is configured to detect a specified register in a user-mode register corresponding to the target program through the monitoring process after the debugged process executes the to-be-tested instruction, so as to debug the target program. The specified register corresponds to the to-be-tested instruction executed this time.

[0080] In summary, the program debugging device provided by the embodiment of the present application writes the running address of the to-be-tested instruction into the monitoring register through the monitoring process, controls the debugging process of the target program to execute the to-be-tested instruction, and the to-be-tested instruction belongs to the executable instruction set of the target program. After the debugging process executes the to-be-tested instruction, the monitoring process detects the specified register in the user state register corresponding to the target program to debug the target program, and the specified register corresponds to the to-be-tested instruction executed this time. In this way, in the debugging process, the running address of the to-be-tested instruction to be executed this time is written into the monitoring register, the debugging process of the target program is controlled to execute the to-be-tested instruction, and the specified register in the user state register corresponding to the target program is detected after execution, and then it can be determined whether the code part for implementing the to-be-tested instruction in the target program has a problem, so that the problem of the target program can be positioned more accurately to a certain extent.

[0081] Optionally, the apparatus 20 further comprises:

[0082] The emptying module is configured to empty the running address currently written in the monitoring register after the control module controls the debugging process of the target program to execute the to-be-tested instruction.

[0083] The monitoring process writes the running address of the next to-be-tested instruction into the monitoring register to control the debugging process of the target program to execute the next to-be-tested instruction again.

[0084] Optionally, the emptying module is specifically configured to:

[0085] The interrupt is enabled, and a preconfigured emptying instruction is written into the interrupt information of the interrupt;

[0086] In response to the interrupt, the emptying instruction written in the interrupt information is executed to empty the running address currently written in the monitoring register.

[0087] Optionally, the detection module 202 is specifically configured to:

[0088] The value of the specified register is obtained, and the value is compared with a specified value;

[0089] If the value is inconsistent with the specified value, the code segment corresponding to the to-be-tested instruction in the target program is determined as an abnormal code segment;

[0090] The apparatus 20 further comprises a setting module configured to set the value of the specified register to the specified value before the emptying module empties the running address currently written in the monitoring register.

[0091] Optionally, the monitoring process implements the function of the program debugging device by calling a debugging code module in a kernel of an operating system of the electronic device; the CPU of the electronic device is integrated with a monitoring register, the monitoring register is a bottom layer register configured by the debugging code module, and a state parameter of the bottom layer register is configured as a specified parameter.

[0092] Figure 4 is a structural block diagram of an electronic device according to an exemplary embodiment. For example, the electronic device 400 can be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.

[0093] Referring to Figure 4 , the electronic device 400 can include one or more of the following components: a processing component 402, a memory 404, a power supply component 406, a multimedia component 408, an audio component 410, an input / output (I / O) interface 412, a sensor component 414, and a communication component 416, and the electronic device 400 runs an operating system, and a debugging code module (software module) is arranged in a kernel of the operating system.

[0094] The processing component 402 generally controls the overall operations of the electronic device 400, such as operations associated with display, telephone calling, data communication, camera operation, and recording operation. The processing component 402 can include one or more processors 420 to execute instructions, the processor 420 is integrated with a monitoring register, an executable file of a target program is added to a preset software framework to form a main program, a monitoring process and a debugging process are generated for the main program, the monitoring process calls a debugging code module in a kernel of an operating system to implement the program debugging method, so as to complete all or part of the steps of the above method.

[0095] In addition, the processing component 402 can include one or more modules to facilitate the interaction between the processing component 402 and other components. For example, the processing component 402 can include a multimedia module to facilitate the interaction between the multimedia component 408 and the processing component 402.

[0096] The memory 404 is configured to store various types of data to support the operation of the electronic device 400. Examples of such data include instructions for any application or method operating on the electronic device 400, contact data, phonebook data, messages, pictures, videos, etc. The memory 404 can be implemented by any type of volatile or nonvolatile memory, or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disc, or optical disc.

[0097] The power supply component 406 supplies power for various components of the electronic device 400. The power supply component 406 can include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the electronic device 400.

[0098] The multimedia component 408 includes a screen providing an output interface between the electronic device 400 and a user. In some embodiments, the screen can include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense a touch, a slide, and a gesture on the touch panel. The touch sensor can not only sense a boundary of a touching or a sliding action, but also detect duration and pressure related to the touching or sliding action. In some embodiments, the multimedia component 408 includes a front camera and / or a back camera. The front camera and / or the back camera can receive external multimedia data when the electronic device 400 is in an operation mode, such as a photographing mode or a video mode. Each of the front camera and the back camera can be a fixed optical lens system or have a focal length and optical zoom capability.

[0099] The audio component 410 is configured to output and / or input an audio signal. For example, the audio component 410 includes a microphone (MIC) configured to receive an external audio signal when the electronic device 400 is in an operation mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signal can be further stored in the memory 404 or transmitted via the communication component 416. In some embodiments, the audio component 410 also includes a speaker for outputting an audio signal.

[0100] The I / O interface 412 provides an interface between the processing component 402 and peripheral interface modules, which can be a keypad, a click wheel, buttons, etc. The buttons can include, but are not limited to, a home button, a volume button, a start button, and a lock button.

[0101] The sensor component 414 includes one or more sensors for providing status assessments for various aspects of the electronic device 400. For example, the sensor component 414 can detect an open / closed position of the electronic device 400, relative positioning of components, such as a display and a keypad of the electronic device 400, a change in position of the electronic device 400 or a component of the electronic device 400, the presence or absence of user contact with the electronic device 400, the orientation or acceleration / deceleration / g-force and a temperature change of the electronic device 400. The sensor component 414 can include an accelerometer for measuring a change in position, acceleration, orientation, and the like. The sensor component 414 can further include a proximity sensor configured to detect the presence of nearby objects without any physical touch. The sensor component 414 can also include a light sensor (e.g., a CMOS or CCD image sensor) for use in imaging applications. In some embodiments, the sensor component 414 can further include a gyroscope sensor, a magnetometer sensor, a pressure sensor, or a temperature sensor.

[0102] The communication component 416 is configured to facilitate wired or wireless communication between the electronic device 400 and other devices. The electronic device 400 can access a wireless network based on a corresponding communication standard, such as WiFi, 2G, or 3G, or a combination thereof. In an example embodiment, the communication component 416 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an example embodiment, the communication component 416 further includes a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technology.

[0103] In an example embodiment, the electronic device 400 can be implemented using one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, micro-controllers, microprocessors or other electronic modules to perform the above-described methods.

[0104] Preferably, the embodiments of the present application further provide an electronic device, including a processor, a memory, a computer program stored in the memory and executable in the processor, which, when executed by the processor, implements each process of the above-mentioned embodiments of the cascade construction method of the interrupt controller and achieves the same technical effects. To avoid repetition, details are not described herein.

[0105] The embodiment of the present application further provides a computer readable storage medium, and the computer readable storage medium stores a computer program, the computer program is executed by a processor to realize each process of the cascade construction method of the interrupt controller, and the same technical effects can be achieved, and details are not repeated here. The computer readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0106] It should be noted that in this paper, the term "comprise", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitations, the element defined by the statement "comprises a" does not exclude the presence of another identical element in the process, method, article or device including the element.

[0107] From the above description of the embodiments, those skilled in the art can clearly understand that the above-mentioned embodiment method can be realized by software and necessary general hardware platform, of course, it can also be realized by hardware, but in many cases, the former is a better embodiment. Based on this understanding, the technical solutions of the present application can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes a plurality of instructions for making a terminal (which can be a mobile phone, computer, server, air conditioner or network device) execute the method described in each embodiment of the present application.

[0108] The embodiments of the present application are described above in combination with the drawings, but the present application is not limited to the above-mentioned specific embodiments, the above-mentioned specific embodiments are only illustrative, not restrictive, and those skilled in the art can make many forms under the inspiration of the present application without departing from the purpose of the present application and the scope protected by the claims, which all belong to the protection of the present application.

Claims

1. A program debugging method characterized by comprising: The method comprises: writing, by a monitoring process, a running address of a to-be-tested instruction into a monitoring register integrated in a CPU of an electronic device, and controlling a debugging process of a target program to execute the to-be-tested instruction; the to-be-tested instruction belongs to a set of executable instructions of the target program; after the debugging process executes the to-be-tested instruction, acquiring, by the monitoring process, a value of a specified register in a user state register corresponding to the target program, and comparing the value with a specified value; if the value is inconsistent with the specified value, determining a code segment corresponding to the to-be-tested instruction in the target program as an abnormal code segment; the value is a relevant parameter generated after the to-be-tested instruction is executed, and the specified value is a value generated after the to-be-tested instruction is normally executed; the specified register corresponds to the to-be-tested instruction executed this time.

2. The method of claim 1, wherein, after the control of the debugging process of the target program to execute the to-be-tested instruction, the method further comprises: emptying the running address currently written in the monitoring register; writing, by the monitoring process, a running address of a next to-be-tested instruction into the monitoring register, so as to control the debugging process to execute the next to-be-tested instruction again.

3. The method of claim 2, wherein, the emptying of the running address currently written in the monitoring register comprises: starting an interrupt, and writing a pre-configured emptying instruction into interrupt information of the interrupt; in response to the interrupt, executing the emptying instruction written in the interrupt information to empty the running address currently written in the monitoring register.

4. The method of claim 2, wherein, before the emptying of the running address currently written in the monitoring register, the method further comprises: setting the value of the specified register to the specified value.

5. The method according to any of claims 1 to 4, characterized in that, the monitoring process implements the program debugging method by calling a debugging code module in an operating system kernel of the electronic device; the monitoring register is a bottom-layer register configured by the debugging code module, and a state parameter of the bottom-layer register is configured as a specified parameter to represent that the bottom-layer register has been used to implement the program debugging method.

6. A program debugging apparatus characterized by comprising: The device comprises: a control module configured to write, by a monitoring process, a running address of a to-be-tested instruction into a monitoring register integrated in a CPU of an electronic device, and control a debugging process of a target program to execute the to-be-tested instruction; the to-be-tested instruction belongs to a set of executable instructions of the target program; a detection module configured to, after the debugging process executes the to-be-tested instruction, acquire, by the monitoring process, a value of a specified register in a user state register corresponding to the target program, and compare the value with a specified value; if the value is inconsistent with the specified value, determine a code segment corresponding to the to-be-tested instruction in the target program as an abnormal code segment; the value is a relevant parameter generated after the to-be-tested instruction is executed, and the specified value is a value generated after the to-be-tested instruction is normally executed; the specified register corresponds to the to-be-tested instruction executed this time.

7. The apparatus of claim 6, wherein, The device further comprises an emptying module configured to empty the running address currently written in the monitoring register after the control module controls the debugging process of the target program to execute the to-be-tested instruction; and based on the monitoring process, write the running address of the next to-be-tested instruction into the monitoring register to control the debugging process to execute the next to-be-tested instruction again.

8. The apparatus of claim 7, wherein, The emptying module is specifically configured to: start an interrupt, and write a pre-configured emptying instruction into interrupt information of the interrupt; in response to the interrupt, execute the emptying instruction written in the interrupt information to empty the running address currently written in the monitoring register.

9. The device of claim 7, wherein: The device further comprises a setting module configured to set the value of the specified register to the specified value before the emptying module empties the running address currently written in the monitoring register.

10. The apparatus of any of claims 6-9, wherein, The monitoring process implements the function of the program debugging device by calling a debugging code module in an operating system kernel of the electronic device; the monitoring register is a bottom-layer register configured by the debugging code module, and a state parameter of the bottom-layer register is configured as a specified parameter to represent that the bottom-layer register has been used to implement the program debugging method.

11. An electronic device, comprising: comprise: a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method of one or more of claims 1-5 when executing the program.

12. A readable storage medium, characterized by, When the instructions in the storage medium are executed by the processor of the electronic device, the electronic device can execute the method of one or more of claims 1-5.

Citation Information

Patent Citations

  • Code checking method and device, code writing method and electronic equipment

    CN114153750A