CN-121979766-A - Code debugging method and device, equipment and medium of embedded system
Abstract
Calling a trace_event component at a position to be debugged of a code for creating an API of a custom event to perform instrumentation, and simultaneously transmitting parameter data corresponding to the custom event; analyzing and formatting the parameter data through the API when compiling codes to obtain formatted event data, storing the event data in a ring buffer area, analyzing and printing the event data in the ring buffer area according to a preset format to obtain event logs corresponding to the self-defined events, and debugging codes according to the event logs. The application can meet the code debugging requirement in the embedded system with limited resources.
Inventors
- LI JIAJIAN
- LIU SIJUN
- CAI YONGHENG
Assignees
- 广州芯之联科技有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20251231
Claims (10)
- 1. A code debugging method of an embedded system, which is applied to the embedded system, comprising: calling a trace_event component at a position to be debugged of a code, performing instrumentation by using an API for creating a custom event, and simultaneously transmitting parameter data corresponding to the custom event; The parameter data is analyzed and formatted through the API when the codes are compiled, formatted event data is obtained, and the event data is stored in a ring buffer; Analyzing and printing the event data of the annular buffer zone according to a preset format to obtain an event log corresponding to the custom event, and performing code debugging according to the event log.
- 2. The code debugging method of an embedded system according to claim 1, wherein the trace_event component comprises an event type, an event attribution module, event description information and an event parameter, wherein the event type is used for defining the custom event record, the event attribution module is used for attributing the custom event, and the event description information and the event parameter describe the custom event.
- 3. The code debugging method of an embedded system of claim 2, wherein the event TYPEs comprise EV_TYPE_MARK, EV_TYPE_BEGIN, EV_TYPE_END and EV_TYPE_CNT.
- 4. The code debugging method of an embedded system of claim 1, wherein the expanding the parameter data through the API at the time of code compiling, parsing and formatting the parameter data to obtain formatted event data, and saving the event data to a ring buffer comprises: The compiler of the embedded system compiles and expands the API to obtain a macro, and the macro analyzes and formats the parameter data to obtain a data structure template and a format description document of the event data; And applying a storage space from the annular buffer according to the data structure template, and writing real-time data corresponding to the API in the compiling process into the storage space according to the format description document.
- 5. The code debugging method of an embedded system of claim 4, wherein applying for a storage space from the ring buffer according to the data structure template and writing real-time data corresponding to the API in the compiling process into the storage space according to the format description document comprises: calculating the current residual writable capacity of the annular buffer based on the positions of the write pointer and the read pointer of the annular buffer; if the residual writable capacity meets the size of the data structure template, applying for the storage space corresponding to the size of the data structure template from the annular buffer area; And writing the real-time data into the continuous storage space pointed by the write pointer according to the format description document and the layout defined by the data structure template, wherein the real-time data comprises a time stamp and an interrupt state.
- 6. The code debugging method of an embedded system according to claim 1, wherein the parsing and printing the event data of the ring buffer according to a preset format to obtain an event log corresponding to the custom event comprises: reading the event data stored in the ring buffer; Obtaining a formatted character string corresponding to the type identifier of the event data, wherein the formatted character string indicates the field layout and the type of the event data printing; extracting data to be printed from the event data according to the type; And carrying out combined printing on the data to be printed according to the field layout to obtain the event log.
- 7. The code debugging method of an embedded system of claim 6, wherein the reading the event data stored in the ring buffer comprises: Positioning a starting point according to a preset magic number on the event data of the annular buffer; determining an endpoint of the event data according to the header data of the event data; and acquiring the event data corresponding to the custom event from the annular buffer zone according to the starting point and the end point.
- 8. A code debugging device of an embedded system, applied to the embedded system, comprising: The instrumentation module is used for calling an API (application program interface) for creating the custom event at the position to be debugged of the code to perform instrumentation, and simultaneously transmitting parameter data corresponding to the custom event; the compiling module is used for expanding the parameter data during code compiling through the API, analyzing and formatting the parameter data to obtain formatted event data, and storing the event data into a ring buffer; The debugging module is used for analyzing and printing the event data of the annular buffer according to a preset format to obtain an event log corresponding to the custom event, and code debugging is carried out according to the event log.
- 9. An electronic device, comprising: At least one processor; At least one memory for storing at least one program; A code debugging method of an embedded system according to any one of claims 1 to 7, when at least one of said programs is executed by at least one of said processors.
- 10. A computer-readable storage medium storing computer-executable instructions for performing the code debugging method of the embedded system of any one of claims 1 to 7.
Description
Code debugging method and device, equipment and medium of embedded system Technical Field The present application relates to the field of fault debugging technologies, but not limited to, and in particular, to a method, an apparatus, a device, and a medium for debugging a code of an embedded system. Background For reasons of limited resources and time-sensitivity in embedded systems such as XR875, debugging code of such resource-limited and time-sensitive embedded systems is typically debugger or printf printing. However, using a debugger (e.g., JTAG/SWD) for debugging, the debugger is connected to the chip through a dedicated hardware interface (e.g., JTAG), allowing the developer to halt program operation, single step execution, view/modify variables and registers, set breakpoints, etc. for debugging, when setting breakpoints or single step execution, the CPU will stop completely, the real-time performance of the whole system is destroyed, resulting in problems such as communication timeout, etc. And the embedded system has many functions in real time, when the CPU is suspended by the debugger, the time sequence can be thoroughly disturbed, the problem can disappear (Hessenburgh) or a new abnormality can be generated, and the code cannot be debugged. If the printf (or serial port printing) is adopted for debugging, the information such as codes, printing formats, time stamps and the like need to be manually added, the dynamic switching cannot be realized, the serial port printing is time-consuming, and the code debugging requirement of the embedded system with limited resources cannot be met. Disclosure of Invention The embodiment of the application provides a code debugging method, device, equipment and medium of an embedded system, which can meet the code debugging requirement in the embedded system with limited resources. In a first aspect, an embodiment of the present application provides a code debugging method for an embedded system, which is applied to the embedded system, and includes: calling a trace_event component at a position to be debugged of a code, performing instrumentation by using an API for creating a custom event, and simultaneously transmitting parameter data corresponding to the custom event; The parameter data is analyzed and formatted through the API when the codes are compiled, formatted event data is obtained, and the event data is stored in a ring buffer; Analyzing and printing the event data of the annular buffer zone according to a preset format to obtain an event log corresponding to the custom event, and performing code debugging according to the event log. In a second aspect, a code debugging device of an embedded system according to an embodiment of the present application is applied to an embedded system, and includes: The instrumentation module is used for calling an API (application program interface) for creating the custom event at the position to be debugged of the code to perform instrumentation, and simultaneously transmitting parameter data corresponding to the custom event; the compiling module is used for expanding the parameter data during code compiling through the API, analyzing and formatting the parameter data to obtain formatted event data, and storing the event data into a ring buffer; The debugging module is used for analyzing and printing the event data of the annular buffer according to a preset format to obtain an event log corresponding to the custom event, and code debugging is carried out according to the event log. In a third aspect, an electronic device according to an embodiment of the present application includes: At least one processor; At least one memory for storing at least one program; when at least one of the programs is executed by at least one of the processors, a code debugging method of the embedded system of any of the first aspects is implemented. In a fourth aspect, according to an embodiment of the present application, there is provided a computer-readable storage medium storing computer-executable instructions for performing a code debugging method for implementing any one of the embedded systems described in the first aspect. In summary, the embodiment of the application includes calling a trace_event component at a position to be debugged of a code for creating an API of a custom event to perform instrumentation, simultaneously transmitting parameter data corresponding to the custom event, expanding the parameter data through the API when the code is compiled, analyzing and formatting the parameter data to obtain formatted event data, storing the event data in a ring buffer, analyzing and printing the event data in the ring buffer according to a preset format to obtain an event log corresponding to the custom event, and performing code debugging according to the event log. According to the embodiment of the application, firstly, the trace_event component is called at the position to be debugged of the code for creating the API