A method of recording traces and related apparatus
By adding breakpoints during the execution of business logic code in the RTOS and dynamically recording traces, the problem of low debugging efficiency in traditional trace solutions is solved. This enables trace recording at any code location, reducing development costs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHANGHAI LIXIANG AUTOMOBILE CO LTD
- Filing Date
- 2024-11-29
- Publication Date
- 2026-05-29
AI Technical Summary
Traditional tracing solutions in RTOS require pre-addition to the code and cannot be added dynamically, resulting in low code debugging efficiency and increased project development time and cost.
Add breakpoints during the execution of business logic code. When the breakpoint is triggered at the location where the log is to be recorded, jump to the exception management module to record the trace, delete the breakpoint and resume execution, thus enabling trace recording at any code location.
It improves code debugging efficiency, reduces project development time and costs, and enables dynamic addition of traces without modifying the code or recompiling.
Smart Images

Figure CN122111822A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software technology, and in particular to a method and related apparatus for recording traces. Background Technology
[0002] In RTOS (Real-Time Operating System), tracing is typically used to track system behavior in real time and record system execution trajectory logs. This allows developers to locate problems and perform performance analysis based on the recorded system execution trajectory logs. Traditional tracing methods require adding traces to the code beforehand during code debugging. When the code runs to the location of the trace, the system execution trajectory logs recorded in the trace are output.
[0003] Currently, the placement of traces in the code depends on the developer's experience and needs to be added in advance. However, often after adding a trace in the code, combined with the system runtime logs recorded by the trace, it is found that another trace needs to be added in another part of the code for auxiliary analysis. In traditional solutions, the location for adding traces is reserved in advance when writing the code, and traces cannot be added dynamically during code execution. It can only be achieved by modifying the code and recompiling the code, which leads to low code debugging efficiency and increases the development time and cost of the project. Summary of the Invention
[0004] In view of the above problems, this application provides a method and related apparatus for recording traces, so as to record traces at any code location during the execution of business logic code, thereby improving code debugging efficiency and reducing project development time and cost. The specific solution is as follows:
[0005] A method for recording traces includes:
[0006] Add breakpoints to record traces during the execution of business logic code;
[0007] The breakpoint is triggered in response to the execution of the business logic code reaching the breakpoint trigger position of the log to be recorded;
[0008] Jump from the business logic code to the target code in the exception management module that corresponds to the system exception type;
[0009] Record the trace;
[0010] Delete the breakpoint and resume execution of the business logic code.
[0011] Optionally, adding breakpoints for recording traces during the execution of business logic code includes:
[0012] During the execution of the business logic code, a breakpoint addition command sent by the host computer is obtained;
[0013] Add the breakpoint according to the log position to be recorded carried in the breakpoint addition command;
[0014] After the breakpoint is added, the business logic code continues to be executed.
[0015] Optionally, adding the breakpoint at the log location to be recorded, carried in the breakpoint addition command, includes:
[0016] The breakpoint is an execution breakpoint, which is added at the code location to be logged in the breakpoint addition command.
[0017] Or,
[0018] The breakpoint is a read / write breakpoint, and a read / write breakpoint is added to the memory location of the log to be recorded, carried in the breakpoint addition command.
[0019] Optionally, triggering the breakpoint in response to the execution of the business logic code reaching the breakpoint trigger position to be logged includes:
[0020] The breakpoint is an execution breakpoint. When the business logic code executes to the breakpoint addition position to be logged, the execution breakpoint is triggered to cause an instruction prefetching exception in the system.
[0021] Or,
[0022] The breakpoint is a read / write breakpoint, which is triggered when the business logic code accesses the memory to be logged, causing a data access exception in the system.
[0023] Optionally, recording the trace includes:
[0024] Determine the type of system anomaly;
[0025] If the system exception type is an exception triggered by an execution breakpoint, the recorded trace contains logs of the system executing the corresponding code;
[0026] If the system exception type is an exception triggered by a read / write breakpoint, the recorded trace includes logs of system access to the corresponding memory.
[0027] An apparatus for recording traces, comprising:
[0028] The breakpoint addition unit is used to add breakpoints for recording traces during the execution of business logic code;
[0029] A breakpoint triggering unit is used to trigger the breakpoint in response to the execution of the business logic code reaching the breakpoint triggering position to be logged;
[0030] The code jump unit is used to jump from the business logic code to the target code in the exception management module that corresponds to the system exception type;
[0031] A trace recording unit is used to record the trace;
[0032] The breakpoint deletion unit is used to delete the breakpoint and resume the execution of the business logic code.
[0033] An electronic device includes at least one processor and a memory connected to the processor, wherein:
[0034] The memory is used to store computer programs;
[0035] The processor is used to execute the computer program so that the electronic device can implement the above-described method for recording traces.
[0036] Optionally, the processor has a debug management function, which enables the processor to support adding breakpoints, including execution breakpoints and read / write breakpoints.
[0037] A computer program product includes computer-readable instructions that, when executed on an electronic device, cause the electronic device to perform the method of recording traces as described above.
[0038] A computer storage medium carrying one or more computer programs, which, when executed by an electronic device, enable the electronic device to implement the above-described method for recording traces.
[0039] As can be seen from the above technical solution, the method and related apparatus for recording traces provided in this application add breakpoints for recording traces during the execution of business logic code. In response to the business logic code execution reaching the breakpoint trigger position to be logged, the breakpoint is triggered, and the user jumps from the business logic code to the target code in the exception management module corresponding to the system exception type, records the trace, and resumes execution of the business logic code by deleting the breakpoint. This application can achieve trace recording at any code location during the execution of business logic code without modifying or recompiling the code, thereby improving code debugging efficiency and reducing project development time and costs. Attached Figure Description
[0040] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale.
[0041] Figure 1 A schematic diagram of a system architecture is provided for this application;
[0042] Figure 2 A schematic diagram of an optional hardware structure for a terminal provided in this application;
[0043] Figure 3 A schematic diagram of the structure of a server provided in this application;
[0044] Figure 4 A flowchart illustrating a method for recording traces provided in an embodiment of this application;
[0045] Figure 5 A flowchart illustrating a method for adding breakpoints for recording traces during the execution of business logic code, as provided in this application embodiment;
[0046] Figure 6 A schematic diagram of a device for recording traces provided in this application embodiment.
[0047] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0048] The embodiments of this application are described below with reference to the accompanying drawings. The terminology used in the implementation section of this application is for explaining specific embodiments only and is not intended to limit the scope of this application.
[0049] The embodiments of this application will now be described with reference to the accompanying drawings. Those skilled in the art will recognize that, with technological advancements and the emergence of new scenarios, the technical solutions provided in the embodiments of this application are equally applicable to similar technical problems.
[0050] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms are interchangeable where appropriate; this is merely a way of distinguishing objects with the same attributes in the embodiments of this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a series of elements is not necessarily limited to those elements, but may include other elements not explicitly listed or inherent to those processes, methods, products, or apparatuses.
[0051] See Figure 1 , Figure 1 A schematic diagram of a system architecture is shown. The system may include a terminal 100 and a server 200. The server 200 may include one or more servers (…). Figure 1 (The example includes a server), and the server 200 can provide the method provided in the embodiments of this application to one or more terminals.
[0052] The terminal 100 may have a third-party system application installed on it. The application and webpage can provide an interface. The terminal 100 can receive relevant parameters input by the user on the interface and send the parameters to the server 200. The server 200 can obtain the processing result based on the received parameters and return the processing result to the terminal 100.
[0053] It should be understood that in some optional implementations, the terminal 100 can also complete the action of obtaining the processing result based on the received parameters on its own, without the need for the server to cooperate. This application embodiment is not limited to this.
[0054] The following description Figure 1 The product form of the mid-terminal 100;
[0055] The terminal 100 in this application embodiment can be a mobile phone, tablet computer, wearable device, vehicle device, augmented reality (AR) / virtual reality (VR) device, laptop computer, ultra-mobile personal computer (UMPC), netbook, personal digital assistant (PDA), etc., and this application embodiment does not impose any restrictions on it.
[0056] Figure 2 A schematic diagram of an optional hardware structure for terminal 100 is shown.
[0057] refer to Figure 2 As shown, the terminal 100 may include a radio frequency unit 110, a memory 120, an input unit 130, a display unit 140, a camera 150 (optional), an audio circuit 160 (optional), a speaker 161 (optional), a microphone 162 (optional), a headphone jack 163 (optional), a processor 170, an external interface 180, a power supply 190, and other components. Those skilled in the art will understand that... Figure 2 These are merely examples of terminals or multi-functional devices and do not constitute a limitation on terminals or multi-functional devices. They may include more or fewer components than shown in the illustration, or combine certain components, or use different components.
[0058] The input unit 130 can be used to receive input numerical or character information, and to generate key signal inputs related to user settings and function control of the portable multi-functional device. Specifically, the input unit 130 may include a touchscreen 131 (optional) and / or other input devices 132. The touchscreen 131 can collect touch operations performed by the user on or near it (such as operations performed by the user using fingers, knuckles, styluses, or any suitable object on or near the touchscreen), and drive the corresponding connection devices according to a pre-set program. The touchscreen can detect the user's touch actions, convert the touch actions into touch signals and send them to the processor 170, and can receive and execute commands sent by the processor 170; the touch signal includes at least touch point coordinate information. The touchscreen 131 can provide an input interface and an output interface between the terminal 100 and the user. In addition, various types of touchscreens, such as resistive, capacitive, infrared, and surface acoustic wave, can be used to implement the touchscreen. Besides the touchscreen 131, the input unit 130 may also include other input devices. Specifically, other input devices 132 may include, but are not limited to, one or more of the following: physical keyboard, function keys (such as volume control buttons, power buttons, etc.), trackball, mouse, joystick, etc.
[0059] Among them, the input device 132 can receive input data, etc.
[0060] The display unit 140 can be used to display information input by the user or information provided to the user, various menus of the terminal 100, interactive interfaces, file display, and / or playback of any multimedia file.
[0061] The memory 120 can be used to store instructions and data. The memory 120 may primarily include an instruction storage area and a data storage area. The data storage area can store various types of data, such as multimedia files and text. The instruction storage area can store software units such as operating systems, applications, and instructions required for at least one function, or subsets or extended sets thereof. It may also include non-volatile random access memory. It provides the processor 170 with hardware, software, and data resources for managing the computing device, supporting control software and applications. It is also used for storing multimedia files, as well as storing running programs and applications.
[0062] The processor 170 is the control center of the terminal 100. It connects various parts of the terminal 100 via various interfaces and lines. By running or executing instructions stored in the memory 120 and calling data stored in the memory 120, it performs various functions and processes data of the terminal 100, thereby controlling the terminal device as a whole. Optionally, the processor 170 may include one or more processing units; preferably, the processor 170 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 170. In some embodiments, the processor and memory can be implemented on a single chip; in some embodiments, they can also be implemented separately on independent chips. The processor 170 can also be used to generate corresponding operation control signals, send them to the corresponding components of the computing processing device, read and process data in the software, especially read and process data and programs in the memory 120, so that the various functional modules therein perform corresponding functions, thereby controlling the corresponding components to act according to the instructions.
[0063] The memory 120 can be used to store software code related to the method of recording traces, and the processor 170 can execute the steps of the method of recording traces. It can also schedule other units (such as the input unit 130 and the display unit 140 mentioned above) to achieve the corresponding functions.
[0064] The radio frequency unit 110 (optional) can be used for receiving and transmitting signals during information transmission or calls. For example, it can receive downlink information from the base station and process it for the processor 170; additionally, it can transmit uplink data to the base station. Typically, the RF circuit includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low-noise amplifier (LNA), a duplexer, etc. Furthermore, the radio frequency unit 110 can also communicate wirelessly with network devices and other devices. This wireless communication can use any communication standard or protocol, including but not limited to Global System for Mobile Communication (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, Short Messaging Service (SMS), etc.
[0065] In this embodiment of the application, the radio frequency unit 110 can send data to the server 200 and receive the processing results sent by the server 200.
[0066] It should be understood that the radio frequency unit 110 is optional and can be replaced with other communication interfaces, such as a network port.
[0067] The terminal 100 also includes a power supply 190 (such as a battery) that supplies power to various components. Preferably, the power supply can be logically connected to the processor 170 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system.
[0068] Terminal 100 also includes an external interface 180, which can be a standard Micro USB interface or a multi-pin connector, which can be used to connect terminal 100 to other devices for communication or to connect a charger to charge terminal 100.
[0069] Although not shown, terminal 100 may also include a flash, a Wireless Fidelity (WiFi) module, a Bluetooth module, sensors with various functions, etc., which will not be described in detail here. Some or all of the methods described below can be applied to, for example... Figure 2 In the terminal 100 shown.
[0070] The following description Figure 1 The product form of the mid-range server 200;
[0071] Figure 3 A structural diagram of a server 200 is provided, as follows: Figure 3 As shown, server 200 includes bus 201, processor 202, communication interface 203, and memory 204. Processor 202, memory 204, and communication interface 203 communicate with each other via bus 201.
[0072] Bus 201 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of representation, Figure 3 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0073] The processor 202 can be any one or more of the following processors: a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0074] Memory 204 may include volatile memory, such as random access memory (RAM). Memory 204 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid state drive (SSD).
[0075] The memory 204 can be used to store software code related to the method of recording traces, and the processor 202 can execute the steps of the chip's method of recording traces, and can also schedule other units to achieve the corresponding functions.
[0076] It should be understood that the aforementioned terminal 100 and server 200 can be centralized or distributed devices. The processors (e.g., processor 170 and processor 202) in the aforementioned terminal 100 and server 200 can be hardware circuits (such as application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), general-purpose processors, DSPs, microprocessors, or microcontrollers, etc.) or combinations of these hardware circuits. For example, the processor can be a hardware system with instruction execution capabilities, such as a CPU or DSP, or a hardware system without instruction execution capabilities, such as an ASIC or FPGA, or a combination of the aforementioned hardware systems without instruction execution capabilities and hardware systems with instruction execution capabilities.
[0077] This application provides a method for recording traces, which can be applied to... Figure 1 Taking the computer device in the figure above as an example, the computer device can specifically be the terminal 100 in the figure above, or a system composed of terminal 100 and server 200. The method of recording trace according to the embodiments of this application will be described in detail below with reference to the accompanying drawings.
[0078] Reference Figure 4 , Figure 4 A flowchart illustrating a method for recording traces provided in this application embodiment is shown. This method is applied to a processor, which has an RTOS (Real-Time Operating System). The method for recording traces includes:
[0079] Step S401: Add breakpoints to record traces during the execution of business logic code.
[0080] In RTOS, trace is used to record system runtime logs, which contain information about events, behaviors, and states during system operation. This allows developers to use the recorded system runtime logs for problem localization and performance analysis. Examples include:
[0081] Event tracking: Records specific events that occur in the system, such as system startup, task switching, and interrupt triggering.
[0082] Task analysis: Track information such as task scheduling, execution time, and waiting time in order to analyze the task's runtime sequence.
[0083] Interrupt analysis: Record information such as interrupt trigger time and execution time to analyze interrupt response time and system interrupt load.
[0084] Resource analysis: Track the usage of system resources (such as memory, semaphores, message queues, etc.) in order to promptly detect problems such as resource contention and deadlock.
[0085] In this application, instead of directly adding traces during the operation of the business logic agent, breakpoints are added to record traces. These breakpoints can include execution breakpoints and read / write breakpoints.
[0086] The purpose of execution breakpoints is to prevent instruction prefetching exceptions from occurring when the system executes to a certain address.
[0087] The purpose of read / write breakpoints is to detect data access errors when the system accesses a memory address.
[0088] Based on this, users can set the address where system anomalies are required according to their actual needs.
[0089] Step S402: In response to the execution of the business logic code reaching the breakpoint trigger position of the log to be recorded, the breakpoint is triggered.
[0090] When debugging business logic code, this application adds breakpoints for recording traces during the execution of the business logic code. This allows users to set the address where the system needs to experience an exception according to their actual needs. When the execution of the business logic code reaches the breakpoint to be logged, the system can experience the corresponding exception by triggering the breakpoint.
[0091] Step S403: Jump from the business logic code to the target code in the exception management module that corresponds to the system exception type.
[0092] An exception management module is a data structure stored in a computer system that stores the code that the processor needs to execute when it encounters an exception.
[0093] Taking the exception management module as an example, which stores code for instruction prefetching exceptions and code for data access exceptions, specifically:
[0094] When the execution location of the business logic code is the same as the breakpoint added to the log to be recorded, the system will jump to the target code in the exception management module that corresponds to the instruction prefetch exception.
[0095] When business logic code accesses the memory of the log to be logged, it jumps to the target code in the exception management module corresponding to the data access exception.
[0096] Step S404: Record the trace.
[0097] This application enables the addition of breakpoints in the business logic code during its execution, allowing for the addition of trace recording points at any code location, and the recording of traces after code jumps are completed.
[0098] Step S405: Delete the breakpoint and resume execution of the business logic code.
[0099] To prevent the code from jumping back to the business logic code and then, due to the presence of breakpoints, jumping back to the target code in the exception management module corresponding to the system exception type, the breakpoints need to be deleted to ensure the resumption of execution of the business logic code.
[0100] In summary, this invention discloses a method for recording traces. Breakpoints for recording traces are added during the execution of business logic code. In response to the business logic code reaching the breakpoint trigger position for logging, the breakpoint is triggered, and the execution jumps from the business logic code to the target code in the exception management module corresponding to the system exception type, recording the trace. By deleting the breakpoint, the execution of the business logic code can be resumed. This application enables trace recording at any code location during the execution of business logic code without modifying or recompiling the code. This improves code debugging efficiency and reduces project development time and costs.
[0101] In practical applications, an exception management module can be set up in the processor's real-time operating system. Its function is to record the system exception information by recording the trace when the system operation is abnormal, so as to assist technicians in locating the location of the system exception.
[0102] The exception management module can include exception handling functions, etc. When an exception occurs during system operation, the currently executing business logic code will jump to the exception handling function corresponding to the code in the exception management module for execution.
[0103] To enable trace recording at any code location, this application extends the functionality of the exception management module through the debug management module. The debug management module is a functional module integrated into development tools or operation and maintenance platforms for debugging during code execution. It allows users to set breakpoints, step through code, view the values of variables and expressions, and output debugging information, thereby helping users better understand the code's execution flow and status, and quickly locate problems.
[0104] The Debug management module in this application provides breakpoints, meaning it enables the processor to support adding breakpoints, including execution breakpoints and read / write breakpoints. This allows users to set the addresses where system exceptions should occur, including two types:
[0105] Execution breakpoint: When the system executes to a certain address, an instruction prefetch exception occurs.
[0106] Read / write breakpoint: A data access exception occurs when the system accesses a certain memory location.
[0107] This application enables the addition of trace recording points at any code location during the execution of business logic code through the "execution breakpoint" or "read / write breakpoint" functions.
[0108] It should be noted that the name of the debug management module differs across architectures. In Infineon's Tricore series chips, the debug management module is called OCDS (On Chip Debug Support), meaning it is the debug unit on Infineon's Tricore series chips. Alternatively, in ARM (Advanced RISC Machines) series chips, the debug management module is called Debug monitor, meaning it is the debug unit on ARM series chips.
[0109] The debug management module functions similarly in Infineon's Tricore series chips and ARM series chips, both of which support adding execution breakpoints and read / write breakpoints to the chip.
[0110] In one embodiment, see Figure 5 The present invention discloses a method flowchart for adding breakpoints for recording traces during the execution of business logic code. The method includes:
[0111] Step S501: During the execution of the business logic code, obtain the breakpoint addition command sent by the host computer.
[0112] In practical applications, the system's log entry location can be set at any point in the code as needed. The host computer generates a breakpoint addition command based on the log entry location and sends the command to the processor's real-time operating system.
[0113] Step S502: Add a breakpoint for recording trace according to the log position to be recorded carried in the breakpoint addition command.
[0114] When the real-time operating system receives a breakpoint addition command, it adds a breakpoint according to the log position to be recorded carried in the breakpoint addition command.
[0115] When the breakpoint is an execution breakpoint, the location to be logged is the code location to be logged.
[0116] When the breakpoint is a read / write breakpoint, the location of the log to be recorded is the memory location of the log to be recorded.
[0117] Specifically, (1) when the breakpoint is an execution breakpoint, an execution breakpoint is added at the code location to be logged in the breakpoint addition command.
[0118] (2) When the breakpoint is a read / write breakpoint, add a read / write breakpoint at the memory location of the log to be recorded carried in the breakpoint addition command.
[0119] Therefore, the breakpoint types in this application mainly include execution breakpoints and read / write breakpoints. The log locations corresponding to different breakpoint types are different. Execution breakpoints are added to the code location where the log is to be recorded, so that traces can be recorded at any code location during the execution of business logic code. Read / write breakpoints are added to the memory location where the log is to be recorded, so that traces can be recorded at any code location during the execution of business logic code.
[0120] Step S503: After the breakpoint is added, continue executing the business logic code.
[0121] After the breakpoint is added, continue executing the business logic code until it reaches the breakpoint trigger point for logging. Figure 1 The process of recording traces is shown.
[0122] In summary, this invention, during the execution of business logic code, obtains a breakpoint addition command sent by the host computer, adds a breakpoint for recording traces based on the log position to be recorded carried in the breakpoint addition command, and continues execution of the business logic code after the breakpoint is added. This application can achieve trace recording at any code position during the execution of business logic code without modifying or recompiling the code, thereby improving code debugging efficiency and reducing project development time and cost.
[0123] In addition, this application enables trace recording when memory accesses occur at the target address by adding read / write breakpoints based on the memory location of the log to be recorded.
[0124] In one embodiment, when the breakpoint is an execution breakpoint, step S402 may specifically include:
[0125] When the execution of the business logic code reaches the breakpoint added to the log to be recorded, the execution breakpoint is triggered, causing the system to experience an instruction prefetching exception.
[0126] In one embodiment, when the breakpoint is a read / write breakpoint, step S402 may specifically include:
[0127] When business logic code accesses the memory to be logged, the read / write breakpoint is triggered, causing a data access exception in the system.
[0128] Specifically, read and write breakpoints include read breakpoints and write breakpoints.
[0129] When the breakpoint is a read breakpoint, the system will encounter a data read exception in response to the business logic code accessing the memory of the log to be recorded.
[0130] When the breakpoint is a write breakpoint, the system will encounter a data write exception in response to the business logic code accessing the memory to be logged.
[0131] In practical applications, two registers can be configured in the system: one register sets the address (denoted as the address register), and the other register sets the matching mode (denoted as the configuration register). When monitoring whether there are read or write operations in memory, the memory address corresponding to that memory can be set in the address register. The configuration register can be set to trigger conditions as read-triggered, write-triggered, or read-write-triggered. When the business logic code accesses memory and meets the set trigger conditions, the system can trigger a data access exception corresponding to the trigger conditions, including: data read exception, data write exception, and data read-write exception.
[0132] In summary, this application can achieve trace recording at any code location during the execution of business logic code without modifying or recompiling the code. This is done by adding execution breakpoints or read / write breakpoints to record traces during the execution of business logic code and executing the response functions of the execution breakpoints or read / write breakpoints. This improves code debugging efficiency and reduces project development time and cost.
[0133] In one embodiment, step S404 may specifically include:
[0134] Determine the type of system exception;
[0135] If the system exception type is an exception triggered by an execution breakpoint, the recorded trace contains logs of the system executing the corresponding code;
[0136] If the system exception type is an exception triggered by a read / write breakpoint, the recorded trace includes logs of system access to the corresponding memory.
[0137] In summary, when the breakpoint is an execution breakpoint, this application adds the execution breakpoint at the code location where the log is to be recorded. At this time, the recorded trace includes the log of the system executing the corresponding code, thereby improving code debugging efficiency and reducing project development time and cost.
[0138] When the breakpoint is a read breakpoint, this application adds a read / write breakpoint at the memory location where the log is to be recorded. At this time, the recorded trace includes the log of the system accessing the corresponding memory, which enables the recording of traces even when memory access is performed at the target address.
[0139] When the system exception type is an exception other than the exception triggered by execution breakpoints and the exception triggered by read / write breakpoints, that is, when the breakpoint does not have the additional functions of execution breakpoints and read / write breakpoints, it can be handled in the traditional system exception handling method.
[0140] The above describes a method for recording traces provided by embodiments of this application. The following describes the apparatus for performing the above-described method for recording traces.
[0141] Please see Figure 6 , Figure 6 This is a schematic diagram of a device for recording traces provided in an embodiment of this application. Figure 6 As shown, the device includes:
[0142] Breakpoint addition unit 601 is used to add breakpoints for recording traces during the execution of business logic code.
[0143] In RTOS, trace is used to record system operation trajectory logs, which are the events, behaviors, and status information during system operation. This allows developers to locate problems and perform performance analysis based on the recorded system operation trajectory logs.
[0144] In this application, instead of directly adding traces during the operation of the business logic agent, breakpoints are added to record traces. These breakpoints can include execution breakpoints and read / write breakpoints.
[0145] The purpose of execution breakpoints is to prevent instruction prefetching exceptions from occurring when the system executes to a certain address.
[0146] The purpose of read / write breakpoints is to detect data access errors when the system accesses a memory address.
[0147] Based on this, users can set the address where system anomalies are required according to their actual needs.
[0148] The breakpoint triggering unit 602 is used to trigger the breakpoint in response to the execution of the business logic code reaching the breakpoint triggering position of the log to be recorded.
[0149] When debugging business logic code, this application adds breakpoints for recording traces during the execution of the business logic code. This allows users to set the address where the system needs to experience an exception according to their actual needs. When the execution of the business logic code reaches the breakpoint to be logged, the system can experience the corresponding exception by triggering the breakpoint.
[0150] The code jump unit 603 is used to jump from the business logic code to the target code in the exception management module that corresponds to the system exception type.
[0151] An exception management module is a data structure stored in a computer system that stores the code that the processor needs to execute when it encounters an exception.
[0152] Taking the exception management module as an example, which stores code for instruction prefetching exceptions and code for data access exceptions, specifically:
[0153] When the execution location of the business logic code is the same as the breakpoint added to the log to be recorded, the system will jump to the target code in the exception management module that corresponds to the instruction prefetch exception.
[0154] When business logic code accesses the memory of the log to be logged, it jumps to the target code in the exception management module corresponding to the data access exception.
[0155] Trace recording unit 604 is used to record the trace.
[0156] This application enables the addition of breakpoints in the business logic code during its execution, allowing for the addition of trace recording points at any code location, and the recording of traces after code jumps are completed.
[0157] The breakpoint deletion unit 605 is used to delete the breakpoint and resume the execution of the business logic code.
[0158] To prevent the code from jumping back to the business logic code and then, due to the presence of breakpoints, jumping back to the target code in the exception management module corresponding to the system exception type, the breakpoints need to be deleted to ensure the resumption of execution of the business logic code.
[0159] In summary, this invention discloses a device for recording traces. Breakpoints for recording traces are added during the execution of business logic code. In response to the business logic code reaching the breakpoint trigger position for logging, the breakpoint is triggered, and the user jumps from the business logic code to the target code in the exception management module corresponding to the system exception type, recording the trace. By deleting the breakpoint, the execution of the business logic code can be resumed. This application enables trace recording at any code location during the execution of business logic code without modifying or recompiling the code. This improves code debugging efficiency and reduces project development time and costs.
[0160] In one embodiment, the breakpoint addition unit 601 specifically includes:
[0161] The command acquisition subunit is used to acquire breakpoint addition commands sent by the host computer during the execution of the business logic code.
[0162] Add a subunit, used to add the breakpoint according to the log position to be recorded carried in the breakpoint addition command;
[0163] The Continuing Execution Subunit is used to continue executing the business logic code after the breakpoint is added.
[0164] In one embodiment, adding a subunit can specifically be used for:
[0165] Add an execution breakpoint at the code location to be logged, carried in the breakpoint addition command, wherein the breakpoint includes: the execution breakpoint;
[0166] Or,
[0167] Add a read / write breakpoint at the memory location of the log to be recorded, carried in the breakpoint addition command, wherein the breakpoint includes the read / write breakpoint.
[0168] In one embodiment, the breakpoint triggering unit 602 is specifically used for:
[0169] When the execution of the business logic code reaches the breakpoint added to the log to be recorded, the execution breakpoint is triggered, causing the system to experience an instruction prefetching exception;
[0170] Or,
[0171] When business logic code accesses the memory to be logged, the read / write breakpoint is triggered, causing a data access exception in the system.
[0172] In one embodiment, the code jump unit 603 is specifically used for:
[0173] Determine the type of system anomaly;
[0174] If the system exception type is an exception triggered by an execution breakpoint, the recorded trace contains logs of the system executing the corresponding code;
[0175] If the system exception type is an exception triggered by a read / write breakpoint, the recorded trace includes logs of system access to the corresponding memory.
[0176] It should be noted that for the specific working principles of each component in the device embodiment, please refer to the corresponding section of the method embodiment, which will not be repeated here.
[0177] This application also provides an electronic device in its embodiments. (See reference...) Figure 7 The diagram illustrates a structural schematic suitable for implementing the electronic device in the embodiments of this application. The electronic device in the embodiments of this application may include, but is not limited to, fixed terminals such as mobile phones, laptops, PDAs (Personal Digital Assistants), PADs (Portable Application Devices), desktop computers, etc. Figure 7 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0178] like Figure 7 As shown, the electronic device may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 701, which can perform various appropriate actions and processes according to a program stored in ROM 702 or a program loaded into RAM 703 from storage device 708. When the electronic device is powered on, RAM 703 also stores various programs and data required for the operation of the electronic device. The processing unit 701, ROM 702, and RAM 703 are interconnected via bus 704. Input / output (I / O) interface 705 is also connected to bus 704.
[0179] Typically, the following devices can be connected to I / O interface 705: input devices 706 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 707 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 708 including, for example, memory cards, hard drives, etc.; and communication devices 709. Communication device 709 allows electronic devices to exchange data via wireless or wired communication with other devices. Although Figure 7 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown. More or fewer devices may be implemented or have alternatively.
[0180] In one embodiment, the processor has a debug management function that enables the processor to support adding breakpoints, including execution breakpoints and read / write breakpoints.
[0181] This application also provides a computer program product including computer-readable instructions, which, when executed on an electronic device, cause the electronic device to implement any of the trace recording methods provided in this application.
[0182] This application also provides a computer-readable storage medium that carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any of the trace recording methods provided in this application.
[0183] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the device embodiment drawings provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.
[0184] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, or it can be implemented by special-purpose hardware including application-specific integrated circuits, special-purpose CPUs, special-purpose memory, special-purpose components, etc. Generally, any function performed by a computer program can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often the preferred implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, training equipment, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0185] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.
[0186] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line, DSL) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs (Digital Versatile Discs)), or semiconductor media (e.g., solid-state drives (SSDs)).
Claims
1. A method for recording traces, characterized in that, include: Add breakpoints to record traces during the execution of business logic code; The breakpoint is triggered in response to the execution of the business logic code reaching the breakpoint trigger position of the log to be recorded; Jump from the business logic code to the target code in the exception management module that corresponds to the system exception type; Record the trace; Delete the breakpoint and resume execution of the business logic code.
2. The method for recording traces according to claim 1, characterized in that, The step of adding breakpoints for recording traces during the execution of business logic code includes: Obtain the breakpoint addition command sent by the host computer; Add the breakpoint according to the log position to be recorded carried in the breakpoint addition command; After the breakpoint is added, the business logic code continues to be executed.
3. The method for recording traces according to claim 2, characterized in that, Adding the breakpoint at the log location to be logged, carried in the breakpoint addition command, includes: The breakpoint is an execution breakpoint, which is added at the code location to be logged in the breakpoint addition command. Or, The breakpoint is a read / write breakpoint, which is added to the memory location of the log to be recorded, carried in the breakpoint addition command.
4. The method for recording traces according to any one of claims 1 to 3, characterized in that, The response to the business logic code executing to the breakpoint trigger position to be logged, triggering the breakpoint, includes: The breakpoint is an execution breakpoint. When the business logic code executes to the breakpoint addition position to be logged, the execution breakpoint is triggered to cause an instruction prefetching exception in the system. Or, The breakpoint is a read / write breakpoint, which is triggered when the business logic code accesses the memory to be logged, causing a data access exception in the system.
5. The method for recording traces according to any one of claims 1 to 4, characterized in that, The recording of the trace includes: Determine the type of system anomaly; If the system exception type is an exception triggered by an execution breakpoint, the recorded trace contains logs of the system executing the corresponding code; If the system exception type is an exception triggered by a read / write breakpoint, the recorded trace includes logs of system access to the corresponding memory.
6. A device for recording traces, characterized in that, include: The breakpoint addition unit is used to add breakpoints for recording traces during the execution of business logic code; A breakpoint triggering unit is used to trigger the breakpoint in response to the execution of the business logic code reaching the breakpoint triggering position to be logged; The code jump unit is used to jump from the business logic code to the target code in the exception management module that corresponds to the system exception type; A trace recording unit is used to record the trace; The breakpoint deletion unit is used to delete the breakpoint and resume the execution of the business logic code.
7. An electronic device, characterized in that, It includes at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program to enable the electronic device to implement the method of recording trace as described in any one of claims 1 to 5.
8. The electronic device according to claim 7, characterized in that, The processor has a debug management function, which enables the processor to support adding breakpoints, including execution breakpoints and read / write breakpoints.
9. A computer program product, characterized in that, Includes computer-readable instructions that, when executed on an electronic device, cause the electronic device to implement the method of recording trace as described in any one of claims 1 to 5.
10. A computer storage medium, characterized in that, The storage medium carries one or more computer programs that, when executed by an electronic device, enable the electronic device to implement the method of recording traces as described in any one of claims 1 to 5.