Online code debugging method and device and readable storage medium
Through the online code debugging method, the target application identification and positioning method are obtained, the monitoring is judged and mounted, and debugging information is output, which solves the data preparation and operation problems of online program debugging, and realizes direct debugging of the online environment.
Patent Information
- Application Number
- CN202411471935.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2024-12-31
AI Technical Summary
In the prior art, when there is a problem with an online program, it is difficult for developers to prepare data in the local environment and run the program to the code location where the problem occurs, so as to view the variable assignment through debugging, and there are difficulties in preparing data and running the program to The problem of specifying locations.
Provide an online code debugging method, by obtaining the identification and positioning method of the target application, it determines whether the application has been mounted and listened, and outputs debugging information in the online log after the mounted and listened, including the caller and the object passed. Information to realize the debugging of online environments.
Enable developers to directly debug the online environment, avoiding the difficulty of local debugging, and solving the problem of data preparation and program running to a specified location.
Smart Images

Figure CN119226173A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software development, and in particular to an online code debugging method, device and readable storage medium. Background Art
[0002] Debugging the code is an important means for developers to troubleshoot code problems. Debugging means that when the program is running, the developer checks the running path of the code and the variable assignments at the current code location. Debugging can usually only be done in the local development environment. The developer starts the application in the local development tool (such as IDEA, eclipse) and sets breakpoints at the code where the variable assignments need to be checked. In this way, when the program executes to the code location where the breakpoint is set, the execution will be paused, and the variable assignments at the current code location (the paused location) will be displayed in the development tool. Since debugging can only be done in the local development environment, when there is a problem with the online program and you want to use debugging to check the variable assignments in order to locate the cause, the developer must first prepare the data in the local development environment (the data should be as consistent as possible with the online data), start the program locally, and find a way to make the program run to the code location where the problem occurs. Only then can the variable assignments be checked. This process is relatively difficult, and the main difficulties are as follows:
[0003] 1. Data preparation is usually difficult. Data is usually passed in by upstream programs and usually flows through multiple different application systems. Therefore, it is difficult for developers to know how the data is constructed, such as which storage (database, cache, etc.) is involved, the content of the data in each storage, etc.;
[0004] 2. It is also difficult to run the program to the code location where the problem occurs. Because the program (code) running process usually involves the call of various sub-methods, and these sub-methods may involve the call of different other applications (usually interface calls), so the developer can only start his own application locally and cannot run the program normally to the specified location. Summary of the invention
[0005] The technical problem to be solved by the present invention is to provide an online code debugging method, device and readable storage medium in view of the above-mentioned deficiencies in the prior art, so as to solve the problem in the prior art that when a problem occurs in an online program and the developer wants to view the variable assignment status through debugging in order to locate the cause, the developer needs to prepare data in the local development environment first, which results in difficulty in data preparation and it is also difficult to run the program to the code location where the problem occurs.
[0006] In a first aspect, the present invention provides an online code debugging method, the method comprising:
[0007] Obtaining the identifier of the target application and the corresponding positioning method according to the user's start instruction, wherein the target application is the application to which the online code to be debugged belongs, and the positioning method is the online method to be debugged in the target application;
[0008] Determine whether the target application has been mounted and monitored;
[0009] When the target application has been mounted and monitored, through the corresponding mounting and monitoring logic, when the positioning method is called and executed, the debugging information of the positioning method is output in the online log of the target application.
[0010] Furthermore, before obtaining the identification of the target application and the corresponding location method according to the user's opening instruction, the method also includes:
[0011] Receive the target application identifier and the corresponding positioning method input by the user on the debugging configuration new page;
[0012] Saving newly added debugging configuration information according to a newly added instruction of the user, the newly added debugging configuration information including an identifier of the target application, the positioning method, and a state of the positioning method, the state being closed by default;
[0013] Add and display the newly added debugging configuration information in the debugging configuration list page;
[0014] Receiving a start instruction triggered by a user based on the newly added debugging configuration information in the debugging configuration list page;
[0015] The state of the positioning method is modified to being enabled according to the enable instruction.
[0016] Further, the determining whether the target application has been mounted and monitored specifically includes:
[0017] Attempt to read the mount identifier representing the target application in the remote dictionary service Redis cache;
[0018] If the mount identifier can be read, it is determined that the target application has been mounted and monitored; otherwise, it is determined that the target application has not been mounted and monitored.
[0019] Furthermore, if the target application has not been mounted for monitoring, the method further includes:
[0020] A mount monitoring operation is performed on the target application through a remote command, and after the mount monitoring is successful, a mount identifier representing the target application is saved in the Redis cache.
[0021] Furthermore, the debugging information includes information of all member objects of the caller object of the positioning method and information of all member objects of each parameter passed in the positioning method, and the mounting monitoring logic includes:
[0022] Monitor all methods in the target application;
[0023] When a method is called, determine whether the method is the location method corresponding to the target application in the debugging configuration list page and whether its status is turned on. If so, obtain information on all member objects of the caller object of the location method and information on all member objects of each parameter object in the location method, and output them to the online log.
[0024] Further, the obtaining of information of all member objects of the caller object of the positioning method and information of all member objects of each parameter object in the positioning method, and outputting to the online log, specifically includes:
[0025] Obtaining the caller object of the positioning method, using reflection to obtain all member objects of the caller object, traversing all member objects, and outputting information of each member object in the online log;
[0026] Traverse all the parameter objects of the positioning method, and for each parameter object, obtain the information of all member objects of the parameter object and output it to the online log. If the parameter object has a parent class, further obtain and output the information of the inherited member objects, and recursively determine the parent class until there is no parent class.
[0027] Furthermore, the method further comprises:
[0028] Receiving a shutdown instruction triggered by a user based on the newly added debugging configuration information in the debugging configuration list page;
[0029] Modifying the state of the positioning method to closed according to the closing instruction;
[0030] It is determined whether there is a location method in the enabled state under the target application in the debugging configuration list page. If not, a corresponding remote command is executed to end the mounting monitoring of the target application.
[0031] In a second aspect, the present invention provides an online code debugging device, the device comprising:
[0032] A location processing method acquisition module, used to acquire the identifier of the target application and the corresponding location processing method according to the user's start instruction, wherein the target application is the application to which the online code to be debugged belongs, and the location processing method is the online method to be debugged in the target application;
[0033] A mounting monitoring judgment module, connected to the positioning method acquisition module, is used to judge whether the target application has been mounted and monitored;
[0034] The debugging information output module is connected to the mount monitoring judgment module and is used to output the debugging information of the positioning method in the online log of the target application when the positioning method is called and executed through the corresponding mount monitoring logic after the target application has been mounted and monitored.
[0035] In a third aspect, the present invention provides an online code debugging device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to implement the online code debugging method described in the first aspect.
[0036] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the online code debugging method described in the first aspect is implemented.
[0037] The online code debugging method, device and readable storage medium provided by the present invention. First, the identification of the target application and the corresponding positioning method are obtained according to the user's start instruction, wherein the target application is the application to which the online code to be debugged belongs, and the positioning method is the online method to be debugged in the target application; then, it is determined whether the target application has been mounted for monitoring; when the target application has been mounted for monitoring, through the corresponding mounting monitoring logic, the debugging information of the positioning method is output in the online log of the target application when the positioning method is called and executed. The present invention enables developers to debug directly in an online environment, thereby eliminating the difficulties faced by local debugging. It solves the problem in the prior art that when a problem occurs in an online program and the developer wants to view the variable assignment through debugging in order to locate the cause, the developer needs to prepare data in the local development environment first, and there are difficulties in data preparation, and it is also difficult to run the program to the code location where the problem occurs. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 This is a flow chart of an online code debugging method according to Embodiment 1 of the present invention;
[0039] Figure 2A schematic diagram of an interface for a newly added page for debugging configuration according to an embodiment of the present invention;
[0040] Figure 3 This is a schematic diagram of the interface of the debugging configuration list page of an embodiment of the present invention;
[0041] Figure 4 A schematic diagram showing some debug information in an online log according to an embodiment of the present invention;
[0042] Figure 5 This is a structural diagram of an online code debugging device according to Embodiment 2 of the present invention;
[0043] Figure 6 This is a structural diagram of an online code debugging device according to Embodiment 3 of the present invention. DETAILED DESCRIPTION
[0044] In order to enable those skilled in the art to better understand the technical solution of the present invention, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings.
[0045] It should be understood that the specific embodiments and drawings described herein are only used to explain the present invention rather than to limit the present invention.
[0046] It can be understood that, in the absence of conflict, the various embodiments of the present invention and the various features in the embodiments can be combined with each other.
[0047] It can be understood that, for the convenience of description, the drawings of the present invention only show the parts related to the present invention, while the parts irrelevant to the present invention are not shown in the drawings.
[0048] It can be understood that each unit and module involved in the embodiments of the present invention may correspond to only one physical structure, or may be composed of multiple physical structures, or multiple units and modules may be integrated into one physical structure.
[0049] It can be understood that the terms "first", "second", etc. in the embodiments of the present invention are used to distinguish different objects, or to distinguish different processing of the same object, rather than to describe a specific order of objects.
[0050] It can be understood that, in the absence of conflict, the functions and steps marked in the flowcharts and block diagrams of the present invention may occur in an order different from that marked in the drawings.
[0051] It is understood that the flowcharts and block diagrams of the present invention illustrate the possible architectures, functions, and operations of the systems, devices, equipment, and methods according to the various embodiments of the present invention. Each box in the flowchart or block diagram may represent a unit, module, program segment, or code, which contains executable instructions for implementing the specified functions. Moreover, each box or combination of boxes in the block diagram and flowchart may be implemented by a hardware-based system that implements the specified functions, or may be implemented by a combination of hardware and computer instructions.
[0052] It can be understood that the units and modules involved in the embodiments of the present invention can be implemented by software or hardware. For example, the units and modules can be located in a processor.
[0053] Embodiment 1:
[0054] This embodiment provides an online code debugging method, such as Figure 1 As shown, the method includes:
[0055] Step S101: obtaining the identifier of the target application and the corresponding positioning method according to the user's start instruction, wherein the target application is the application to which the online code to be debugged belongs, and the positioning method is the online method to be debugged in the target application.
[0056] In this embodiment, the user may be a developer or other person who needs to debug the target application. The positioning method is used to uniquely locate the specified method, including package name + class name + method name, such as: javax.servlet.http.HttpServlet.service, which represents package javax.servlet.http, class HttpServlet, and method service.
[0057] Optionally, before acquiring the identifier of the target application and the corresponding location method according to the user's start instruction, the method further includes:
[0058] Receive the target application identifier and the corresponding positioning method input by the user on the debugging configuration new page;
[0059] Saving newly added debugging configuration information according to a newly added instruction of the user, the newly added debugging configuration information including an identifier of the target application, the positioning method, and a state of the positioning method, the state being closed by default;
[0060] Add and display the newly added debugging configuration information in the debugging configuration list page;
[0061] Receiving a start instruction triggered by a user based on the newly added debugging configuration information in the debugging configuration list page;
[0062] The state of the positioning method is modified to being enabled according to the enable instruction.
[0063] In this embodiment, the debug configuration new page can be as follows Figure 2 As shown, the user fills in the identifier of the target application corresponding to the online code and the corresponding positioning method in the page, wherein the target application is the application to which the online code that needs to be debugged belongs, and the positioning method is the online method that needs to be debugged in the target application.
[0064] When the user clicks the Add button to trigger the Add command, the page will initiate a Add request to Service A (the service provided by the present invention). After receiving the request, Service A will save the newly added debugging configuration information to Redis, where the value of the Status field will be saved as Closed. At the same time, it will jump to Figure 3 The debug configuration list page shown shows the information of all currently configured methods to be located. When the user clicks the "Enable" button corresponding to the newly added debug configuration information on the page, the enable command is triggered. At this time, the status of the located method is changed to Enabled.
[0065] Step S102: Determine whether the target application has been mounted and monitored.
[0066] Specifically, an attempt may be made to read the mount identifier representing the target application in the Redis (remote dictionary service) cache; if the mount identifier can be read, it is determined that the target application has been mounted and monitored, otherwise, it is determined that the target application has not been mounted and monitored.
[0067] Optionally, if the target application has not been mounted and monitored, the method further includes:
[0068] A mount monitoring operation is performed on the target application through a remote command, and after the mount monitoring is successful, a mount identifier representing the target application is saved in the Redis cache.
[0069] In this embodiment, if the target application has not been mounted and monitored, a remote command is executed to mount and monitor the target application. The command for mounting and monitoring is: . / sandbox.sh -p 1 -d'service-monitor / debugMonit', where 1 is the process of the application, which is obtained by executing the command ps-ef|grep-i kcard-xxx|awk'{print$2}' (kcard-xxx is the name of the target application, in Figure 2page); sandbox.sh is the mount monitoring command of the jvm-sandbox installed in advance on the server where the target application is located; jvm-sandbox is a jvm-based process monitoring tool that can monitor the java process (i.e., application process) in the jvm. Similar tools include trace, arthas, etc. Therefore, if jvm-sandbox is not used, other monitoring tools can also be used to achieve the purpose of the present invention; service-monitor / debugMonit is the name of the monitoring logic implementation package provided by the present invention. When the mounting monitoring is successful, the package will be loaded, and its implementation logic will act on the process of the target application.
[0070] Step S103: After the target application has been mounted and monitored, the debugging information of the positioning method is output in the online log of the target application through the corresponding mounting and monitoring logic when the positioning method is called and executed.
[0071] In this embodiment, the debugging information includes information about all member objects of the caller object of the positioning method and information about all member objects of each parameter passed in the positioning method.
[0072] Optionally, the mount monitoring logic includes:
[0073] Monitor all methods in the target application;
[0074] When a method is called, determine whether the method is the location method corresponding to the target application in the debugging configuration list page and whether its status is turned on. If so, obtain information on all member objects of the caller object of the location method and information on all member objects of each parameter object in the location method, and output them to the online log.
[0075] In this embodiment, all methods in the target application are monitored. When a method is called, before it is executed, it is determined whether the currently called method is included in Figure 3 In the list shown (belonging to a certain positioning method) and the status is open, if so, obtain the information of all member objects of the calling object of the positioning method (that is, the currently called method) and the information of all member objects of each parameter object in the positioning method, and output them to the online log.
[0076] Optionally, the obtaining information of all member objects of the caller object of the positioning method and information of all member objects of each parameter object in the positioning method, and outputting them to the online log, specifically includes:
[0077] Obtaining the caller object of the positioning method, using reflection to obtain all member objects of the caller object, traversing all member objects, and outputting information of each member object in the online log;
[0078] Traverse all the parameter objects of the positioning method, and for each parameter object, obtain the information of all member objects of the parameter object and output it to the online log. If the parameter object has a parent class, further obtain and output the information of the inherited member objects, and recursively determine the parent class until there is no parent class.
[0079] In this embodiment, the step of obtaining and outputting the information of all member objects of the caller object of the positioning method includes: obtaining the caller object of the positioning method, using reflection to obtain all member objects of the caller object, traversing these member objects, and outputting the information of each member object in the online log (logger.info("FieldName:"+field.getName()+",Field Value:"+value)).
[0080] In this embodiment, the step of obtaining and outputting information of all member objects of each parameter passing object in the positioning method includes:
[0081] Traverse all the parameters passed to the location method, and execute the following logic for each parameter:
[0082] (1) Get all member objects of the current parameter object and output the information of each member object in the online log.
[0083] (2) Determine whether the current parameter object has a parent class:
[0084] If there is, get the class object of the parent class, and use the class object to get all member objects inherited in the current parameter object, traverse and output the information of these member objects in the online log.
[0085] Next, determine whether the parent class has a parent class:
[0086] If so, recursively execute the above logic until there is no parent class.
[0087] If there is no parent class, end the traversal of the current parameter and continue traversing the next parameter.
[0088] Optionally, the method further comprises:
[0089] Receiving a shutdown instruction triggered by a user based on the newly added debugging configuration information in the debugging configuration list page;
[0090] Modifying the state of the positioning method to closed according to the closing instruction;
[0091] It is determined whether there is a location method in the enabled state under the target application in the debugging configuration list page. If not, a corresponding remote command is executed to end the mounting monitoring of the target application.
[0092] In this embodiment, when debugging is not needed, the user clicks the "Close" button to change the status of the location method to closed, and then debugging can be ended. At the same time, if there is no location method in the open state under the target application in the debugging configuration list page, the remote command is executed to end the monitoring of the target application. The command is: . / sandbox.sh -p 1 -S, and the mount mark of the target application is deleted (such as del monitor:kcard-xxx).
[0093] It should be noted that the online code debugging method provided by the present invention allows developers to debug directly in an online environment, thereby avoiding the difficulties faced by local debugging.
[0094] In a specific embodiment, taking the user as a developer as an example, the online code debugging method may include the following steps:
[0095] 1. Developers Figure 2 Fill in the information of the method to be located on the debug configuration new page shown, and click the Add button; the information to be filled in includes the target application corresponding to the online code and the location method. The description of each part is as follows:
[0096] (1) Application, which refers to the application to which the online code that needs to be debugged belongs;
[0097] (2) Location method refers to the online method that needs to be debugged. When locating a problem, it is usually necessary to find out which method has a problem. The location method requires a complete method path, including package name + class name + method name, so that the specified method can be uniquely located. For example, javax.servlet.http.HttpServlet.service means package javax.servlet.http, class HttpServlet, and method service.
[0098] When the Add button is clicked, the page will initiate a Add request to service A (the service provided by the present invention). After receiving the request, service A will save the newly added configuration information to Redis, wherein the value of the Status field will be saved as Closed (mainly considering that developers often want to make a configuration in advance and do not need to enable it immediately, so it is closed by default).
[0099] It should be noted that since the address of the online application usually does not change, the address of the online application can be hard-coded in service A by default, and the developer does not need to configure it himself.
[0100] It should be noted that Figure 2 and Figure 3 The page can be accessed in the local browser, but the page is provided by service A, which is deployed separately on the server (not the same server as the online application).
[0101] 2. At this time, it will jump to Figure 3 The debug configuration list page shown shows the information of all currently configured methods to be located. For the newly added configuration, its status is closed. The developer can click the "Open" button to change the status to open.
[0102] Specifically, when jumping to Figure 3 When you click the "Enable" button, a query request is sent to service A. After receiving the request, service A reads all the configuration information stored in Redis and returns it to the page for display. When you click the "Enable" button, a start request is sent to service A. After receiving the request, service A executes the following logic:
[0103] (1) Determine whether the currently configured application has been mounted and monitored. If not, execute (2) first; if yes, execute (4) directly. The judgment method is to try to read the mount mark of the target application stored in Redis (such as get monitor:kcard-xxx). If the value can be read, it means that the target application has been mounted and monitored.
[0104] (2) Execute the remote command to mount the monitor on the target application. The command to mount the monitor is: . / sandbox.sh -p1 -d'service-monitor / debugMonit', where 1 is the application process, which is obtained by executing the command ps-ef|grep-i kcard-xxx|awk'{print$2}' (kcard-xxx is the name of the application, in Figure 2page); sandbox.sh is the mount monitoring command of the jvm-sandbox pre-installed on the server where the target application is located; jvm-sandbox is a jvm-based process monitoring tool that can monitor the java process (i.e., application process) in the jvm. Similar tools include trace, arthas, etc. Therefore, if jvm-sandbox is not used, other monitoring tools can also be used to achieve the purpose of the present invention; service-monitor / debugMonit is the name of the monitoring logic implementation package provided by the present invention. When the mounting monitoring is successful, the package will be loaded, and its implementation logic will act on the process of the target application; the implementation logic of service-monitor / debugMonit is as follows:
[0105] 1) Monitor all methods in the target application. When a method is called, execute the logic in 2) before it is executed.
[0106] 2) Determine whether the currently called method is included in Figure 3 In the list shown (belonging to a certain location method) and the status is enabled, if so, execute the logic of 3);
[0107] 3) Get the caller object of the method at the location (i.e. the currently called method), use reflection to get all member objects of the caller object, traverse these member objects, and output the information of each member object in the log (logger.info("Field Name:"+field.getName()+",Field Value:"+value)); then execute 4);
[0108] It should be noted that the steps to use reflection to obtain all member objects of the caller object can be as follows:
[0109] ①Get the class object of the caller object
[0110] ②Get all member objects of the class object
[0111] ③Set each member object to be visible
[0112] ④Each member object calls the get method to obtain the actual value of the member.
[0113] The specific code is:
[0114] Field[]declaredFields=
[0115] bEvent.target.getClass().getDeclaredFields();
[0116] for(Field field:declaredFields){
[0117] field.setAccessible(true); / / Allow access to private members
[0118] Object value=field.get(bEvent.target);
[0119] logger.info("Field Name:"+field.getName()+",Field Value:"+value);
[0120] }
[0121] The above process is referred to as reflection, which is a term in programming.
[0122] It should be noted that each member object has two pieces of information: the name of the member object (Field Name) and the value of the member object (Field Value). For example, the member object String phone = '18600000001', its name is phone, and its value is 18600000001. The Field here refers to the member object.
[0123] 4) Traverse all the parameters passed to the location method, and execute the following logic for each parameter:
[0124] a) Get all member objects of the current parameter object, traverse these member objects, and output the information of each member object in the online log;
[0125] b) Determine whether the current parameter object has a parent class. If so, obtain the class object of the parent class, and obtain all member objects inherited by the child object (i.e. the current parameter object) through the class object of the parent class, traverse these member objects, output the information of each member object in the online log, and then execute c); if not, end the traversal of this parameter and traverse the next parameter;
[0126] c) Determine whether the parent class has a parent class. If so, continue to obtain the class object of the parent class's parent class, and obtain all member objects inherited by the child object (i.e., the current parameter object) through the class object of the parent class's parent class. Traverse these member objects and output the information of each member object in the online log. Then recursively execute c) until there are no more parent class objects, end the recursion, end the traversal of this parameter, and then traverse the next parameter.
[0127] In general, this step obtains the value of each member object of the caller of a method and the value of each member object of each parameter passed to the method.
[0128] Take the method javax.servlet.http.HttpServlet.service as an example. Assume that the code to call this method is httpUtil.service(req,resp). Here, the calling object is httpUtil, and the parameters are req and resp. In step 3), all member objects of the httpUtil object will be obtained through reflection. Assume that httpUtil contains two member objects String url="xxxx" and Int type="yyyy", then the information of these two member objects will be output in the online log.
[0129] In step 4), each parameter (i.e., req, resp) will be traversed. For example, req is traversed first. Assuming that req belongs to the class javax.servlet.http.HttpServletRequest, which is inherited from javax.servlet.ServletRequest, then req is considered to have a parent class (i.e., javax.servlet.ServletRequest), and req is a child object of javax.servlet.ServletRequest; req itself has 4 member objects, and the parent class has 2 member objects. req will inherit the 2 member objects in the parent class, but when obtaining the member objects of req through reflection, the inherited member objects cannot be obtained, so it is necessary to obtain them through the class object of the parent class (also through reflection). Therefore, it is necessary to obtain the information of the member objects of req itself and the member objects inherited from the parent class according to the logic of a), b), and c) in 4). It should be noted here that the parent class itself may also inherit from other classes, and other classes will also have their own member objects, so it is necessary to obtain the information of all inherited member objects through recursion in c).
[0130] (3) After the monitor is mounted successfully, the mount flag of the application is saved in Redis (such as set monitor:kcard-xxx).
[0131] (4) Change the status of the configuration of the operation line to enabled (also modify the configuration information in Redis).
[0132] It should be noted that the aforementioned "enable" refers to clicking the "enable" button, and here it means changing the configuration status to "enable". In general, there are two purposes for clicking the "enable" button: one is to mount the monitor so that the logic of service-monitor / debugMonit takes effect; the other is to change the configuration status to "enable".
[0133] 3. After it is enabled, when the positioning method is called and executed, the debug information of the positioning method will be printed in the online log of the application, such as Figure 4 As shown, in the first line, cajsandbox.demo.KcardOrderModule is an identifier of the debug information given by the present invention, and target indicates that the current debug information is taken from the caller object of the method at the location; in the second line, Field Name:MULTIPART_RESOLVER_BEAN_NAME indicates that the name of the member object is MULTIPART_RESOLVER_BEAN_NAME; Field Value:multipartResolver indicates that the value of the member object is multipartResolver, and so on.
[0134] It should be noted that viewing the online log is equivalent to obtaining the debug results of the online method. Originally, the debug information (i.e., the information of these member objects) could only be viewed locally through the debugging function of the development tool. Now, through the method provided by the present invention, it can also be viewed in the log information of the online server.
[0135] It should be noted that there are usually many member objects, such as Figure 4 The information shown is only part of the member object information. No matter how many levels of parent classes there are, it is nothing more than traversing step 4) in step 2 to obtain the member object information of the parameter object itself and the member objects inherited from all levels of parent classes and then output them in the online log.
[0136] 4. When debugging is not needed, click the "Close" button to change the status of the location method to closed to end debugging.
[0137] Specifically, when the "Close" button is clicked, a close request is sent to service A. After receiving the request, service A executes the following logic:
[0138] (1) Change the configuration status of the row being operated to closed;
[0139] (2) Determine whether there is any location method in the currently configured application that is in the enabled state. If not, execute a remote command to end monitoring of the application. The command is: . / sandbox.sh -p 1 -S, and delete the mount mark of the application (such as del monitor:kcard-xxx).
[0140] The online code debugging method provided by the embodiment of the present invention first obtains the identification of the target application and the corresponding positioning method according to the user's start instruction, wherein the target application is the application to which the online code to be debugged belongs, and the positioning method is the online method to be debugged in the target application; then it is determined whether the target application has been mounted for monitoring; when the target application has been mounted for monitoring, through the corresponding mounting monitoring logic, the debugging information of the positioning method is output in the online log of the target application when the positioning method is called for execution. The present invention allows developers to debug directly in an online environment, thereby eliminating the difficulties faced by local debugging. It solves the problem in the prior art that when a problem occurs in an online program and the developer wants to view the variable assignment through debugging in order to locate the cause, the developer needs to prepare data in the local development environment first, which is difficult to prepare data, and it is also difficult to run the program to the code location where the problem occurs.
[0141] Embodiment 2:
[0142] like Figure 5 As shown, this embodiment provides an online code debugging device, which is used to execute the above-mentioned online code debugging method, including:
[0143] The positioning method acquisition module 11 is used to acquire the identifier of the target application and the corresponding positioning method according to the user's start instruction, wherein the target application is the application to which the online code to be debugged belongs, and the positioning method is the online method to be debugged in the target application;
[0144] A mounting monitoring judgment module 12, connected to the positioning method acquisition module 11, is used to judge whether the target application has been mounted and monitored;
[0145] The debugging information output module 13 is connected to the mount monitoring judgment module 12, and is used to output the debugging information of the positioning method in the online log of the target application when the positioning method is called and executed through the corresponding mount monitoring logic after the target application has been mounted and monitored.
[0146] Optionally, the device further comprises:
[0147] A new configuration acquisition module is added, which is used to receive the identifier of the target application and the corresponding positioning method input by the user on the debugging configuration new page;
[0148] A new configuration saving module is added, which is used to save the newly added debugging configuration information according to the user's new instructions, wherein the newly added debugging configuration information includes the identifier of the target application, the positioning method, and the state of the positioning method, wherein the state is closed by default;
[0149] A new configuration display module is added, which is used to add and display the newly added debugging configuration information in the debugging configuration list page;
[0150] A debugging start module, used to receive a start instruction triggered by a user based on the newly added debugging configuration information in the debugging configuration list page;
[0151] The first state modification module is used to modify the state of the positioning method to being enabled according to the enable instruction.
[0152] Optionally, the mounting monitoring judgment module 12 includes:
[0153] An attempt to read unit, used for attempting to read a mount identifier representing the target application in a remote dictionary service Redis cache;
[0154] The mount monitoring judgment unit is used to judge that the target application has been mounted and monitored if the mount identifier can be read, otherwise, judge that the target application has not been mounted and monitored.
[0155] Optionally, if the target application has not been mounted for monitoring, the device further includes:
[0156] The mount monitoring execution module is used to execute the mount monitoring operation on the target application through a remote command, and save the mount identifier representing the target application into the Redis cache after the mount monitoring is successful.
[0157] Optionally, the debugging information includes information of all member objects of the caller object of the positioning method and information of all member objects of each parameter passed in the positioning method, and the mounting monitoring logic includes:
[0158] Monitor all methods in the target application;
[0159] When a method is called, determine whether the method is the location method corresponding to the target application in the debugging configuration list page and whether its status is turned on. If so, obtain information on all member objects of the caller object of the location method and information on all member objects of each parameter object in the location method, and output them to the online log.
[0160] Optionally, the obtaining information of all member objects of the caller object of the positioning method and information of all member objects of each parameter object in the positioning method, and outputting them to the online log, specifically includes:
[0161] Obtaining the caller object of the positioning method, using reflection to obtain all member objects of the caller object, traversing all member objects, and outputting information of each member object in the online log;
[0162] Traverse all the parameter objects of the positioning method, and for each parameter object, obtain the information of all member objects of the parameter object and output it to the online log. If the parameter object has a parent class, further obtain and output the information of the inherited member objects, and recursively determine the parent class until there is no parent class.
[0163] Optionally, the device further comprises:
[0164] A debugging shutdown module, used to receive a shutdown instruction triggered by a user based on the newly added debugging configuration information in the debugging configuration list page;
[0165] A second state modification module, used for modifying the state of the positioning method to close according to the close instruction;
[0166] The mount monitoring end module is used to determine whether there is a location method with a status of being turned on under the target application in the debugging configuration list page. If not, the corresponding remote command is executed to end the mount monitoring of the target application.
[0167] Embodiment 3:
[0168] refer to Figure 6 This embodiment provides an online code debugging device, including a memory 21 and a processor 22. The memory 21 stores a computer program, and the processor 22 is configured to run the computer program to execute the online code debugging method in Example 1.
[0169] The memory 21 is connected to the processor 22. The memory 21 may be a flash memory, a read-only memory or other memory. The processor 22 may be a central processing unit or a single-chip microcomputer.
[0170] Embodiment 4:
[0171] This embodiment provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the online code debugging method in the above-mentioned embodiment 1 is implemented.
[0172] The computer-readable storage medium includes volatile or non-volatile, removable or non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, computer program modules or other data). Computer-readable storage media include, but are not limited to, RAM (Random Access Memory), ROM (Read-Only Memory), EEPROM (Electrically Erasable Programmable read only memory), flash memory or other memory technology, CD-ROM (Compact Disc Read-Only Memory), digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer.
[0173] In summary, the online code debugging method, device and readable storage medium provided by the embodiment of the present invention first obtain the identification of the target application and the corresponding positioning method according to the user's start instruction, wherein the target application is the application to which the online code to be debugged belongs, and the positioning method is the online method to be debugged in the target application; then determine whether the target application has been mounted for monitoring; when the target application has been mounted for monitoring, through the corresponding mounting monitoring logic, when the positioning method is called and executed, the debugging information of the positioning method is output in the online log of the target application. The present invention allows developers to debug directly in an online environment, thereby eliminating the difficulties faced by local debugging. It solves the problem in the prior art that when a problem occurs in an online program and the developer wants to view the variable assignment through debugging in order to locate the cause, the developer needs to prepare data in the local development environment first, and there are difficulties in data preparation, and it is also difficult to run the program to the code location where the problem occurs.
[0174] It is to be understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of the present invention, but the present invention is not limited thereto. For those of ordinary skill in the art, various modifications and improvements can be made without departing from the spirit and essence of the present invention, and these modifications and improvements are also considered to be within the scope of protection of the present invention.
Claims
1. An online code debugging method, characterized in that: The method comprises: Obtaining the identifier of the target application and the corresponding positioning method according to the user's start instruction, wherein the target application is the application to which the online code to be debugged belongs, and the positioning method is the online method to be debugged in the target application; Determine whether the target application has been mounted and monitored; When the target application has been mounted and monitored, through the corresponding mounting and monitoring logic, when the positioning method is called and executed, the debugging information of the positioning method is output in the online log of the target application.
2. The method according to claim 1, characterized in that Before obtaining the identification of the target application and the corresponding location method according to the user's opening instruction, the method also includes: Receive the target application identifier and the corresponding positioning method input by the user on the debugging configuration new page; Saving newly added debugging configuration information according to a newly added instruction of the user, the newly added debugging configuration information including an identifier of the target application, the positioning method, and a state of the positioning method, the state being closed by default; Add and display the newly added debugging configuration information in the debugging configuration list page; Receiving a start instruction triggered by a user based on the newly added debugging configuration information in the debugging configuration list page; The state of the positioning method is modified to being enabled according to the enable instruction.
3. The method according to claim 1, characterized in that The determining whether the target application has been mounted and monitored specifically includes: Attempt to read the mount identifier representing the target application in the remote dictionary service Redis cache; If the mount identifier can be read, it is determined that the target application has been mounted and monitored; otherwise, it is determined that the target application has not been mounted and monitored.
4. The method according to claim 3, characterized in that If the target application has not been mounted and monitored, the method further includes: A mount monitoring operation is performed on the target application through a remote command, and after the mount monitoring is successful, a mount identifier representing the target application is saved in the Redis cache.
5. The method according to claim 2, characterized in that: The debugging information includes information about all member objects of the caller object of the positioning method and information about all member objects of each parameter passed in the positioning method. The mounting monitoring logic includes: Monitor all methods in the target application; When a method is called, determine whether the method is the location method corresponding to the target application in the debugging configuration list page and whether its status is turned on. If so, obtain information on all member objects of the caller object of the location method and information on all member objects of each parameter object in the location method, and output them to the online log.
6. The method according to claim 5, characterized in that The obtaining of information of all member objects of the caller object of the positioning method and information of all member objects of each parameter object in the positioning method, and outputting to the online log, specifically includes: Obtaining the caller object of the positioning method, using reflection to obtain all member objects of the caller object, traversing all member objects, and outputting information of each member object in the online log; Traverse all the parameter objects of the positioning method, and for each parameter object, obtain the information of all member objects of the parameter object and output it to the online log. If the parameter object has a parent class, further obtain and output the information of the inherited member objects, and recursively determine the parent class until there is no parent class.
7. The method according to claim 2, characterized in that The method further comprises: Receiving a shutdown instruction triggered by a user based on the newly added debugging configuration information in the debugging configuration list page; Modifying the state of the positioning method to closed according to the closing instruction; It is determined whether there is a location method in the enabled state under the target application in the debugging configuration list page. If not, a corresponding remote command is executed to end the mounting monitoring of the target application.
8. An online code debugging device, characterized in that: The device comprises: A location processing method acquisition module, used to acquire the identifier of the target application and the corresponding location processing method according to the user's start instruction, wherein the target application is the application to which the online code to be debugged belongs, and the location processing method is the online method to be debugged in the target application; A mounting monitoring judgment module, connected to the positioning method acquisition module, is used to judge whether the target application has been mounted and monitored; The debugging information output module is connected to the mount monitoring judgment module and is used to output the debugging information of the positioning method in the online log of the target application when the positioning method is called and executed through the corresponding mount monitoring logic after the target application has been mounted and monitored.
9. An online code debugging device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to implement the online code debugging method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the online code debugging method according to any one of claims 1 to 7 is implemented.
