Data code debugging method and system
By creating the first and second version codes, the function fingerprint information is used to separate functions and debugging logic, the problem of mixed debugging code and functional code is solved, the security and flexibility of code debugging are improved, and the reliable recording of debugging information is ensured.
Patent Information
- Application Number
- CN202510238723.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-03
- Publication Date
- 2025-07-25
AI Technical Summary
In the prior art, debugging codes and functional codes are mixed, resulting in performance impact, high risk of sensitive information leakage and untimely recording of debugging information.
Create the first version code and the second version code, generate function fingerprint information by exporting the first function template, and the second version code captures the function call data and performs debugging operations, and the result is returned to the preset function of the first version code.
The separation of functional logic and debugging logic is achieved, which reduces the risk of sensitive information leakage and improves debugging flexibility and reliability. The second version of the code can record debugging information even if the first version crashes.
Smart Images

Figure CN120371685A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of code debugging, and particularly relates to a method and system for data code debugging. Background Art
[0002] In programming, debug output is a common method for checking the running status and behavior of a program. Rich debug functions are provided in the IDE, such as functions like breakpoints, variable monitoring, call stack viewing, etc., which facilitate the discovery and repair of program vulnerabilities. After determining that the program is stable, these debug statements will be removed or disabled in the production environment to avoid leaking sensitive information or affecting performance.
[0003] However, there are differences between the normal version code and the debug version code. The debug version comes with debug information, and its performance is affected by the debug output, thus affecting the functional performance. That is, the existing debugging controls the output through switches and enhances the output code in the compilation environment. It is equivalent that part of the program bloat is caused by the debug code. And a large amount of key data is contained in the debugging, which is easily analyzed by reverse engineering tools such as IDA. At the same time, since the debugging itself is the program itself, when a code error is found, the log may not be recorded in time before the program crashes, and there is a situation where errors cannot be recorded in time. Summary of the Invention
[0004] The technical problem to be solved by the present invention is: to provide a method and system for data code debugging, which can improve the security and flexibility of code debugging and ensure the reliability of data recording during the debugging process.
[0005] To solve the above technical problem, the technical solution adopted by the present invention is: A method for data code debugging, comprising the steps of: Creating a first version code for executing functions and a second version code for debugging; Exporting a first function template of the function code from the first version code, and obtaining function fingerprint information of the first version code according to the first function template; Obtaining the function fingerprint information from the second version code, and generating a second function template according to the function fingerprint information, where the second function template includes function structure information of the function code; When the first version code calls a function, the second version code captures the function call data of the first version based on the function structure information, so that the second version code performs corresponding function debugging according to the function call data, records the execution result, and returns the execution result to a preset function of the first version code.
[0006] To solve the above technical problem, another technical solution adopted by the present invention is: A system for debugging data code, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein when the processor executes the computer program, each step of the above-mentioned method for debugging data code is implemented.
[0007] The beneficial effects of the present invention are as follows: By creating the first version of the code and the second version of the code, the separation of the functional logic and the debugging logic is achieved, avoiding the problem of the mixing of the debugging code and the functional code in the traditional debugging method; By exporting the first function template and generating function fingerprint information, the second version of the code can accurately identify the function calls of the first version of the code, capture the call data, perform debugging operations according to the call data, and finally return the execution result to the preset function of the first version of the code. In this way, the debugging information is no longer directly embedded in the first version of the code, reducing the risk of sensitive information leakage and reducing the amount of debugging code in the first version of the code. Moreover, the second version of the code is independent of the main program. Even if the first version of the code crashes, the debugging information can still be captured and recorded. Therefore, the second version of the code can flexibly monitor and change the function call process of the first version of the code without affecting the normal operation of the first version of the code. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] Figure 1 It is a flowchart of a method for debugging data code according to an embodiment of the present invention; Figure 2 It is a schematic diagram of a system for debugging data code according to an embodiment of the present invention; Figure 3 It is an execution flowchart of two versions of code according to an embodiment of the present invention; Figure 4 It is an execution flowchart of the first version of the code according to an embodiment of the present invention; Figure 5 It is an execution flowchart of the second version of the code according to an embodiment of the present invention; Figure 6 It is a call flowchart of the first version of the code and the second version of the code according to an embodiment of the present invention; Reference Numeral Explanation: 1. A system for debugging data code; 2. Memory; 3. Processor. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0009] To describe in detail the technical content, the achieved objectives and the effects of the present invention, the following is described in conjunction with the embodiments and with reference to the accompanying drawings.
[0010] Please refer to Figure 1 , an embodiment of the present invention provides a method for debugging data code, including the steps of: Create a first version of the code for executing functions and a second version of the code for debugging; A first function template for exporting functional code from the first version of the code, and obtaining function fingerprint information of the first version of the code according to the first function template; Obtaining the function fingerprint information from the second version of the code, and generating a second function template according to the function fingerprint information, where the second function template includes function structure information of the functional code; When the first version of the code calls a function, the second version of the code captures function call data of the first version based on the function structure information, so that the second version of the code executes corresponding function debugging according to the function call data, records the execution result, and returns the execution result to a preset function of the first version of the code.
[0011] As can be seen from the above description, the beneficial effects of the present invention are as follows: By creating the first version of the code and the second version of the code, the separation of functional logic and debugging logic is achieved, avoiding the problem of mixing debugging code and functional code in traditional debugging methods; By exporting the first function template and generating function fingerprint information, the second version of the code can accurately identify function calls of the first version of the code, capture call data, perform debugging operations according to the call data, and finally return the execution result to a preset function of the first version of the code. In this way, debugging information is no longer directly embedded in the first version of the code, reducing the risk of sensitive information leakage and reducing the amount of debugging code in the first version of the code. Moreover, the second version of the code is independent of the main program. Even if the first version of the code crashes, debugging information can still be captured and recorded. Therefore, the second version of the code can flexibly monitor and change the function call process of the first version of the code without affecting the normal operation of the first version of the code.
[0012] Further, obtaining the function fingerprint information of the first version of the code according to the first function template includes: The first version of the code obtains the corresponding function name, function call method, and function address according to the first function template, and calculates a function hash value through hash calculation by combining the function name and the function address; Taking the function name, the function address, the function call method, and the function hash value as function fingerprint information.
[0013] As can be seen from the above description, by generating function fingerprint information by combining the function name, function address, function call method, and function hash value, the uniqueness and accuracy of the function fingerprint are ensured. Even if there are functions with the same name, they can be distinguished by the function address and hash value, avoiding conflicts in function identification.
[0014] Further, recording the execution result and returning the execution result to a preset function of the first version of the code includes: Record the execution result and return the execution result to the function called by the first version of the code or to the function executed after the function called by the first version of the code.
[0015] As can be seen from the above description, the second version of the code can return the execution result to the function called by the first version of the code or to the function executed after that function. This flexible call return enables the second version of the code to dynamically adjust the execution flow of the first version of the code according to requirements, enhancing the practicality of debugging. The cooperation between the second version of the code and the first version of the code is seamlessly connected, and the debugging result can be directly returned to the preset function of the first version of the code, and it can also ensure that the execution flow of the first version of the code is not disturbed.
[0016] Furthermore, when the second version of the code performs corresponding function debugging according to the function call data, it further includes: When the second version of the code performs corresponding function debugging according to the function call data, disable the execution flow of the calling function corresponding to the first version of the code.
[0017] As can be seen from the above description, when the second version of the code performs debugging, the execution flow of the calling function corresponding to the first version of the code can be disabled, enabling the second version of the code to completely take over the function call of the first version of the code, facilitating in-depth debugging and problem troubleshooting.
[0018] Furthermore, after the second version of the code captures the function call data of the first version based on the function structure information, it includes: The second version of the code determines whether to process the function call data of the first version according to the preset processing requirements. If so, the second version of the code performs corresponding function debugging according to the function call data. If not, the function call data is directly returned to the preset function of the first version of the code.
[0019] As can be seen from the above description, the second version of the code can determine whether to process the call data of the first version of the code according to the preset processing requirements, enabling the second version of the code to flexibly choose whether to intervene in debugging according to actual needs, improving the efficiency and pertinence of debugging.
[0020] Please refer to Figure 2 , another embodiment of the present invention provides a system for debugging data code, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, it implements each step of the above method for debugging data code.
[0021] The above-mentioned method and system for debugging data codes of the present invention are applicable to improving the security and flexibility of code debugging and ensuring the reliability of data records during the debugging process. The following is an explanation through specific implementation manners: Please refer to Figure 1 , the first embodiment of the present invention is as follows: A method for debugging data codes includes the steps of: S1. Create a first version of code for executing functions and a second version of code for debugging.
[0022] Specifically, please refer to Figure 3 , in this embodiment, the first version of code is the A version, and the second version of code is the B version. The A version is the function version, which only performs functions without any debugging information; the B version is the debugging version, which has all the mirror functions of the A version, and the B version can only run when the A version exists.
[0023] S2. Export a first function template of the function code from the first version of code, and obtain function fingerprint information of the first version of code according to the first function template.
[0024] Specifically, the A version exports the function template and uses it as the template to be debugged for the B version. In this embodiment, the function template can be regarded as a relay end.
[0025] Among them, the corresponding function name and function address are obtained from the first version of code according to the first function template, and the function hash value is obtained through hash calculation by combining the function name and the function address. The function name, the function address, and the function hash value are used as function fingerprint information.
[0026] Please refer to Figure 4 , in this embodiment, the function fingerprints exported by the A version include the function name, the function hash value, the function call method, and the function address. The function name is the function's functional name; the function hash value is composed of the function address and the function name, which is used to distinguish the situation where the names are the same but the addresses are different; the function call method can be the input and output parameter types of the function; the function address is the address of the function, which is used for the B version to call and return.
[0027] S3. Obtain the function fingerprint information from the second version of code, and generate a second function template according to the function fingerprint information. The second function template includes function structure information of the function code.
[0028] Please refer to Figure 5, Version B generates a function header identical to that in the functional code function of Version A based on the function fingerprint information, i.e., the function name and the types of function input and output parameters. Specifically, by obtaining the function fingerprint information, Version B can obtain the function call method in Version A, so as to facilitate Version B to obtain the data in the function address of Version A from the address later.
[0029] In this embodiment, when Version B obtains the fingerprint, it reads the function address to ensure that after Version B completes the relay task, it passes the original function address of Version A, thereby realizing the flexible transfer of the code of the two versions.
[0030] S4. When the first version of the code calls a function, the second version of the code captures the function call data of the first version based on the function structure information, so that the second version of the code executes corresponding function debugging according to the function call data, records the execution result, and returns the execution result to a preset function of the first version of the code.
[0031] S41. When the first version of the code calls a function, the second version of the code captures the function call data of the first version based on the function structure information, and the second version of the code determines whether to process the function call data of the first version according to the preset processing requirements. If so, step S42 is executed; if not, the function call data is directly returned to a preset function of the first version of the code.
[0032] In this embodiment, Version A is a normal program. Compared with other programs, it has a function fingerprint template. And when Version B runs, Version A actively sends call data, that is, transmits function data parameters, to Version B. It is equivalent to that when Version A encounters Version B, it tells Version B what Version A is currently doing inside, and whether Version B needs to participate. And Version B has all the function templates of Version A. The template is the function structure information of Version A, but it does not have the functions of Version A. In this way, as long as Version B has the corresponding function structure of Version A, it knows the data of the function.
[0033] After receiving the data call from Version A, Version B can choose to process it or not, and then return the result data to Version A for further processing.
[0034] S42. When the second version of the code executes corresponding function debugging according to the function call data, disable the execution process of the calling function corresponding to the first version of the code.
[0035] S43. Record the execution result and return the execution result to the function called by the first version of the code or the function executed after the function called by the first version of the code.
[0036] Please refer to Figure 6, since the second version of the code captures function call data and has the function address of version A, it can be used to point the execution result back or to other functions. When the second version of the code executes the corresponding function debugging according to the function call data, it is equivalent to disabling the execution process of version A functions. Moreover, version B can determine the returned function call process, whether to go back to the original function 1 or directly point to the subsequent function 2 or function 3.
[0037] Therefore, the two versions of the code in the data code debugging method of this embodiment belong to the relationship of active and passive. The constructed function template plays a relay role, relaying the control of the function process, operation turning, etc. That is, this embodiment "relays" the monitoring by constructing the template address, and can debug the specific data from function to function for the personalized program template.
[0038] Please refer to Figure 2 , Embodiment 2 of the present invention is as follows: A data code debugging system 1 includes a memory 2, a processor 3, and a computer program stored on the memory 2 and executable on the processor 3. When the processor 3 executes the computer program, it implements each step of the data code debugging method of Embodiment 1.
[0039] In summary, the data code debugging method and system provided by the present invention create the first version of the code and the second version of the code, realizing the separation of the functional logic and the debugging logic, and avoiding the problem of the mixing of the debugging code and the functional code in the traditional debugging method; by exporting the first function template and generating the function fingerprint information, the second version of the code can accurately identify the function calls of the first version of the code, capture the call data, perform debugging operations according to the call data, and finally return the execution result to the preset function of the first version of the code. In this way, the debugging information is no longer directly embedded in the first version of the code, reducing the risk of sensitive information leakage and reducing the amount of debugging code in the first version of the code. And the second version of the code is independent of the main program. Even if the first version of the code crashes, the debugging information can still be captured and recorded. Therefore, the second version of the code can flexibly monitor and change the function call process of the first version of the code without affecting the normal operation of the first version of the code.
[0040] The above are only the embodiments of the present invention, and do not limit the patent scope of the present invention. All equivalent transformations made using the content of the specification and drawings of the present invention, or directly or indirectly applied in related technical fields, are equally included in the patent protection scope of the present invention.
Claims
1. A method for debugging data codes, characterized in that, Including the steps: Create the first version of the code for performing functions and the second version of the code for debugging; Derive the first function template of the function code from the first version of the code, and obtain the function fingerprint information of the first version of the code according to the first function template; Obtain the function fingerprint information from the second version of the code, and generate the second function template according to the function fingerprint information, where the second function template includes the function structure information of the function code; When the first version of the code calls a function, the second version of the code captures the function call data of the first version based on the function structure information, so that the second version of the code performs corresponding function debugging according to the function call data, records the execution result, and returns the execution result to a preset function of the first version of the code.
2. The method for debugging a data code according to claim 1, characterized in that Obtaining the function fingerprint information of the first version of the code according to the first function template includes: The first version of the code obtains the corresponding function name, function call method, and function address according to the first function template, and calculates the function hash value through hash calculation by combining the function name and the function address; Use the function name, the function address, the function call method, and the function hash value as the function fingerprint information.
3. A method for debugging data codes according to claim 1, characterized in that, Recording the execution result and returning the execution result to a preset function of the first version of the code includes: Record the execution result and return the execution result to the function called by the first version of the code or to the function executed after the function called by the first version of the code.
4. A method for debugging data codes according to any one of claims 1 to 3, characterized in that, The second version of the code performing corresponding function debugging according to the function call data further includes: When the second version of the code performs corresponding function debugging according to the function call data, disable the execution process of the function called by the first version of the code.
5. A method for debugging data codes according to claim 1, characterized in that After the second version of the code captures the function call data of the first version based on the function structure information, it includes: The second version of the code determines whether to process the function call data of the first version according to the preset processing requirements. If so, the second version of the code performs corresponding function debugging according to the function call data. If not, the function call data is directly returned to a preset function of the first version of the code.
6. A system for debugging data codes, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the computer program, the following steps are implemented: Create the first version of the code for performing functions and the second version of the code for debugging; Derive the first function template of the function code from the first version of the code, and obtain the function fingerprint information of the first version of the code according to the first function template; Obtain the function fingerprint information from the second version of the code, and generate the second function template according to the function fingerprint information, where the second function template includes the function structure information of the function code; When the first version of the code calls a function, the second version of the code captures the function call data of the first version based on the function structure information, so that the second version of the code performs corresponding function debugging according to the function call data, records the execution result, and returns the execution result to a preset function of the first version of the code.
7. A system for debugging data codes according to claim 6, characterized in that, Obtain the function fingerprint information of the first version of code according to the first function template, including: The first version of code obtains the corresponding function name, function call method, and function address according to the first function template, and calculates the function hash value through hash calculation by combining the function name and the function address; Use the function name, the function address, the function call method, and the function hash value as the function fingerprint information.
8. A system for debugging data codes according to claim 6, characterized in that, Record the execution result and return the execution result to the preset function of the first version of code, including: Record the execution result, and return the execution result to the function called by the first version of code or the function executed after the function called by the first version of code.
9. A system for debugging data codes according to any one of claims 6 to 8, characterized in that The second version of code performs corresponding function debugging according to the function call data, and further includes: When the second version of code performs corresponding function debugging according to the function call data, disable the execution process of the calling function corresponding to the first version of code.
10. A system for debugging data codes according to claim 6, characterized in that, The second version of code captures the function call data of the first version based on the function structure information, and then includes: The second version of code determines whether to process the function call data of the first version according to the preset processing requirements. If so, the second version of code performs corresponding function debugging according to the function call data. If not, directly return the function call data to the preset function of the first version of code.