WO2024088053A1 - Code debugging method, electronic device, and computer readable storage medium - Google Patents

Code debugging method, electronic device, and computer readable storage medium Download PDF

Info

Publication number
WO2024088053A1
WO2024088053A1 PCT/CN2023/123606 CN2023123606W WO2024088053A1 WO 2024088053 A1 WO2024088053 A1 WO 2024088053A1 CN 2023123606 W CN2023123606 W CN 2023123606W WO 2024088053 A1 WO2024088053 A1 WO 2024088053A1
Authority
WO
WIPO (PCT)
Prior art keywords
function
debugging
code
electronic device
address
Prior art date
Application number
PCT/CN2023/123606
Other languages
French (fr)
Chinese (zh)
Inventor
翁长成
李勇彪
余美杰
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2024088053A1 publication Critical patent/WO2024088053A1/en

Links

Abstract

Provided are a code debugging method, an electronic device, and a computer readable storage medium. The method comprises: in response to a received debugging command, running a program code to be debugged; in the process of running the program code, detecting a trigger event of calling a function in a second code segment by means of a first function call statement; on the basis of an association relationship between the first function call statement and the called first function in the second code segment, determining that the address of the first function meets a trigger condition for adding a breakpoint; and adding the breakpoint at the address of the first function. The objective of automatically setting a breakpoint in a code segment to be debugged and checked can be achieved, and when a program code resumes execution and hits a breakpoint, a corresponding code debugging interface can display codes of a code segment corresponding to the breakpoint for a user to check, thereby improving the debugging efficiency.

Description

代码调试方法、电子设备及计算机可读存储介质Code debugging method, electronic device and computer readable storage medium
本申请要求于2022年10月25日提交中国专利局、申请号为202211313299.7、申请名称为“代码调试方法、电子设备及计算机可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims priority to the Chinese patent application filed with the China Patent Office on October 25, 2022, with application number 202211313299.7 and application name “Code debugging method, electronic device and computer-readable storage medium”, the entire contents of which are incorporated by reference in this application.
技术领域Technical Field
本发明涉及计算机技术领域,具体涉及一种代码调试方法、电子设备及计算机可读存储介质。The present invention relates to the field of computer technology, and in particular to a code debugging method, an electronic device and a computer-readable storage medium.
背景技术Background technique
在进行应用程序(application,App)开发时,开发者常常采用集成开发环境(integrated developmentenvironment,IDE)实现。IDE是集成多种开发工具的、用于提供程序开发环境的应用程序,一般包括编辑器、编译器、调试器和图形用户界面等工具。When developing applications (Apps), developers often use an integrated development environment (IDE). An IDE is an application that integrates multiple development tools to provide a program development environment, generally including editors, compilers, debuggers, and graphical user interfaces.
目前,IDE的发展方向是支持多编程语言,如C/C++、Java、JavaScript、Python等等。对于应用到不同操作系统中的应用程序,开发时所采用的多编程语言组合方式也会有所区别。例如,在鸿蒙TM操作系统(HarmonyOSTM)的应用程序开发过程中,通常采用JavaScript语言来编写用户界面(user interface,UI)相关逻辑代码,而对性能要求较高的应用程序功能部分可以使用C/C++语言来编写相关代码。如此,这些应用程序的开发过程则可以涉及C/C++和JavaScript两种编程语言组合的多语言混合开发场景。而在多语言混合开发场景中,调试应用程序各部分的代码时则需要面临包括JavaScript与C/C++两种编程语言的跨语言调试的情形。如何在跨语言调试过程中快速发现JavaScript和C/C++相关代码中的问题并及时解决,也是多语言混合开发场景中亟需解决的问题之一。At present, the development direction of IDE is to support multiple programming languages, such as C/C++, Java, JavaScript, Python, etc. For applications applied to different operating systems, the combination of multiple programming languages used during development will also be different. For example, in the application development process of the Hongmeng TM operating system (HarmonyOS TM ), JavaScript is usually used to write user interface (UI) related logic code, while the application function part with higher performance requirements can use C/C++ language to write related code. In this way, the development process of these applications can involve a multi-language mixed development scenario combining C/C++ and JavaScript programming languages. In the multi-language mixed development scenario, when debugging the code of each part of the application, it is necessary to face the situation of cross-language debugging including JavaScript and C/C++ two programming languages. How to quickly discover problems in JavaScript and C/C++ related codes during cross-language debugging and solve them in time is also one of the problems that need to be solved in the multi-language mixed development scenario.
目前,在上述多语言混合的过程中,开发者需要频繁进行转换编程语言进行调试,过程十分繁琐且不利于快速、准确地定位到具体问题。例如,在一些应用程序的JavaScript文件中可能会存在调用C/C++函数的情况,此时如果需要停在C/C++文件的运行界面上检查代码问题,则需要人工先分析出上述JavaScript到C/C++的调用关系并查找对应文件,进而可以在查找到的C/C++文件中某行代码处添加断点,即打断点。如此,待被调试的应用程序执行到C/C++文件中断点标记的代码行才可以停下来。当上述这种跨语言的代码调用情况较多时,调试工程量也必然会增大,调试效率也会较低。At present, in the process of multi-language mixing, developers need to frequently switch programming languages for debugging, which is very cumbersome and not conducive to quickly and accurately locating specific problems. For example, in the JavaScript files of some applications, there may be a situation where a C/C++ function is called. At this time, if you need to stop at the running interface of the C/C++ file to check the code problem, you need to manually analyze the calling relationship from the JavaScript to C/C++ and find the corresponding file, and then you can add a breakpoint at a line of code in the found C/C++ file, that is, a breakpoint. In this way, the application to be debugged can only stop when it executes to the line of code marked by the breakpoint in the C/C++ file. When there are many cross-language code calls, the debugging workload will inevitably increase and the debugging efficiency will be low.
发明内容Summary of the invention
本申请实施例提供了一种代码调试方法、电子设备及计算机可读存储介质,能够简化用户在调试应用程序代码过程中的操作,实现在待检查的代码段自动打断点,以利于用户快速定位到待检查的代码段,快速查找代码问题,提高调试效率。The embodiments of the present application provide a code debugging method, an electronic device, and a computer-readable storage medium, which can simplify the user's operations in the process of debugging application code and realize automatic breakpoints in the code segment to be checked, so as to help the user quickly locate the code segment to be checked, quickly find code problems, and improve debugging efficiency.
第一方面,本申请实施例提供了一种代码调试方法,应用于电子设备,电子设备上运行被调试的程序代码包括第一语言编写的第一代码段,第一代码段中包括调用第二语言编写的第二代码段的第一函数调用语句,并且该方法包括:响应于接收到的调试命令,运行被调试的程序代码;在运行程序代码的过程中,检测到通过第一函数调用语句调用第二代码段中函数的触发事件;基于第一函数调用语句与第二代码段中被调用的第一函数之间的关联关系,确定第一函数的地址满足打断点的触发条件;在第一函数的地址上打断点。In a first aspect, an embodiment of the present application provides a code debugging method, which is applied to an electronic device, wherein a program code to be debugged running on the electronic device includes a first code segment written in a first language, the first code segment includes a first function call statement that calls a second code segment written in a second language, and the method includes: in response to a received debugging command, running the program code to be debugged; in the process of running the program code, detecting a triggering event of calling a function in the second code segment through a first function call statement; based on the association relationship between the first function call statement and the first function called in the second code segment, determining that the address of the first function meets the triggering condition of a breakpoint; and setting a breakpoint at the address of the first function.
例如,上述第一代码段可以是JavaScript代码段,上述第二代码段可以是C/C++代码段,上述触发事件可以是相应线程运行至JavaScript代码段中的本地函数调用语句跳转至C/C++代码段中对应关联的第一函数所触发的本地函数调用事件。因此,上述第一方面提供的代码调试方法即在检测到本地函数调用事件时,可以基于预先确定的第一函数调用语句(存在于第一代码段中,例如JavaScript代码段)与第一函数(存在于第二代码段中,例如C/C++代码段)之间的关联关系,确定第一函数满足打断点的触发条件,进而在在第一函数的地址上打断点。For example, the first code segment may be a JavaScript code segment, the second code segment may be a C/C++ code segment, and the trigger event may be a local function call event triggered by the corresponding thread running to the local function call statement in the JavaScript code segment to jump to the corresponding associated first function in the C/C++ code segment. Therefore, the code debugging method provided in the first aspect above can determine that the first function meets the triggering condition of the breakpoint based on the association relationship between the predetermined first function call statement (existing in the first code segment, such as the JavaScript code segment) and the first function (existing in the second code segment, such as the C/C++ code segment) when a local function call event is detected, and then set a breakpoint at the address of the first function.
如此,例如可以通过预定义代码段来预先确定第一函数调用语句与被调用的第一函数之间的关联关系,实现在待调试检查的第二代码段(例如C/C++代码段)中自动设置断点的目的,该断点可以在程序代码恢复执行命中断点时,自动停在C/C++代码段中该第一函数的入口处,相应地连接该电子设备的集成开发环境(IDE)的界面上也可以显示命中断点的C/C++代码段,还可以高亮显示该第一函数的入口地址等,便于用户检查,有利于提高调试效率。 In this way, for example, a predefined code segment can be used to predetermine the association relationship between the first function call statement and the called first function, thereby achieving the purpose of automatically setting a breakpoint in the second code segment to be debugged and checked (for example, a C/C++ code segment). When the program code resumes execution and hits the breakpoint, the breakpoint can automatically stop at the entry of the first function in the C/C++ code segment. Correspondingly, the C/C++ code segment that hits the breakpoint can also be displayed on the interface of the integrated development environment (IDE) connected to the electronic device, and the entry address of the first function can also be highlighted, which is convenient for users to check and helps to improve debugging efficiency.
在上述第一方面的一种可能的实现中,第一函数调用语句与第二代码段中被调用的第一函数之间的关联关系,通过以下方式确定:In a possible implementation of the first aspect, the association relationship between the first function call statement and the first function called in the second code segment is determined in the following manner:
在所述第二代码段中定义导出对象,并为所述导出对象定义并初始化第一属性,其中所述第一属性与所述第一代码段中的第一函数调用语句相对应;defining an export object in the second code segment, and defining and initializing a first attribute for the export object, wherein the first attribute corresponds to a first function call statement in the first code segment;
将所述第二代码段中被调用的所述第一函数设置为所述第一属性的回调函数,建立所述第一属性与所述第一函数之间的关联关系;Setting the first function called in the second code segment as a callback function of the first attribute, and establishing an association relationship between the first attribute and the first function;
在所述第一代码段中加载所述导出对象的第一属性,确定所述第一函数调用语句与所述第二代码段中被调用的第一函数之间的关联关系。The first attribute of the export object is loaded in the first code segment, and the association relationship between the first function call statement and the first function called in the second code segment is determined.
例如,上述导出对象例如可以是exports对象,上述第一属性可以是add属性。因而,上述为导出对象定义并初始化第一属性的函数例如可以是Init函数,即通过Init函数可以将预先定义的exports对象属性定义为add属性。上述第一函数调用语句可以是JavaScript代码段中的“testNapi.add(1,2);”,上述第一函数可以是C/C++代码段中的Add函数。上述在第一代码段中加载导出对象的第一属性,例如可以通过定义一个本地模块(napi_module),例如定义一个本地模块为“demoModule”,并将该本地模块的初始化函数设置为Init函数。进而,利用模块注册函数(例如RegisterHelloModule)来注册该本地模块。如此,当JavaScript代码段中通过上述第一函数调用语句加载exports对象属性add并初始化时,便可以确定该第一函数调用语句与对应的C/C++代码段中的Add函数之间的对应关系。可以理解,上述用于确定关联关系的方式可以通过一段预定义代码段实现,该预定义代码段例如可以是下文图2所示例的代码段。For example, the export object may be an exports object, and the first attribute may be an add attribute. Therefore, the function for defining and initializing the first attribute for the export object may be an Init function, that is, the predefined exports object attribute may be defined as the add attribute through the Init function. The first function call statement may be "testNapi.add(1,2);" in the JavaScript code segment, and the first function may be the Add function in the C/C++ code segment. The first attribute of the export object may be loaded in the first code segment, for example, by defining a local module (napi_module), for example, defining a local module as "demoModule", and setting the initialization function of the local module to the Init function. Then, the local module is registered using a module registration function (for example, RegisterHelloModule). Thus, when the exports object attribute add is loaded and initialized through the first function call statement in the JavaScript code segment, the corresponding relationship between the first function call statement and the Add function in the corresponding C/C++ code segment may be determined. It can be understood that the above method for determining the association relationship may be implemented by a predefined code segment, and the predefined code segment may be, for example, the code segment illustrated in FIG. 2 below.
在上述第一方面的一种可能的实现中,满足打断点的触发条件包括:确定第一函数的地址在预先确定的第二代码段的地址范围内,其中第二代码段的地址范围基于电子设备加载的程序代码对应的共享库相关属性确定。In a possible implementation of the first aspect above, satisfying the triggering condition of the breakpoint includes: determining that the address of the first function is within a predetermined address range of a second code segment, wherein the address range of the second code segment is determined based on a shared library-related attribute corresponding to the program code loaded by the electronic device.
例如,上述第二代码段的地址范围可以是C/C++代码段对应的第一地址范围。该地址范围可以基于电子设备的系统加载的共享库(SO)的相关属性确定。该相关属性可以包括但不限于SO文件的名称、加载地址、以及被调用的C/C++代码段的地址范围等,在此不做限制。For example, the address range of the second code segment may be the first address range corresponding to the C/C++ code segment. The address range may be determined based on the relevant attributes of the shared library (SO) loaded by the system of the electronic device. The relevant attributes may include, but are not limited to, the name of the SO file, the load address, and the address range of the called C/C++ code segment, etc., which are not limited here.
在上述第一方面的一种可能的实现中,电子设备与集成开发环境之间建立有调试会话,调试命令为集成开发环境响应于用户操作通过调试会话向电子设备发送的命令,并且,检测到通过第一函数调用语句调用第二代码段中函数的触发事件,包括:电子设备向集成开发环境上报检测到的触发事件,并暂停执行用于运行程序代码的线程。In a possible implementation of the first aspect above, a debugging session is established between the electronic device and the integrated development environment, the debugging command is a command sent by the integrated development environment to the electronic device through the debugging session in response to a user operation, and a triggering event of calling a function in the second code segment through a first function call statement is detected, including: the electronic device reports the detected triggering event to the integrated development environment, and suspends execution of a thread for running program code.
例如,用户需要对电子设备上安装的应用程序代码进行调试时,可以将该电子设备接入集成开发环境(IDE),该IDE可以运行在另一电子设备上。如此,用户便可以在IDE的调试界面上控制调试进度,例如点击单步进入调试(StepInto)控件。进而,IDE可以向电子设备发送上述调试命令,触发电子设备单步进入调试等。当电子设备运行至第一函数调用语句触发调用第二代码段中的第一函数时,即触发本地函数调用事件时,则可以向IDE上报该事件。完成上报后,可以暂停应用进程中的相应线程的执行。For example, when a user needs to debug the application code installed on an electronic device, the electronic device can be connected to an integrated development environment (IDE), which can run on another electronic device. In this way, the user can control the debugging progress on the debugging interface of the IDE, such as clicking the StepInto control. Furthermore, the IDE can send the above-mentioned debugging command to the electronic device, triggering the electronic device to step into debugging, etc. When the electronic device runs to the first function call statement that triggers the call to the first function in the second code segment, that is, when a local function call event is triggered, the event can be reported to the IDE. After the report is completed, the execution of the corresponding thread in the application process can be suspended.
在上述第一方面的一种可能的实现中,集成开发环境基于电子设备通过加载完成事件向集成开发环境上报的共享库相关属性确定第二代码段的地址范围,并且,在第一函数的地址上打断点,包括:集成开发环境基于接收到的触发事件,确定第一函数的地址;集成开发环境判断第一函数的地址在第二代码段的地址范围内,生成向电子设备发送的断点设置命令,断点设置命令用于指示电子设备在第一函数的地址上打断点;电子设备响应于接收到的断点设置命令,在第一函数的地址上打断点。In a possible implementation of the first aspect above, the integrated development environment determines the address range of the second code segment based on the shared library related attributes reported by the electronic device to the integrated development environment through a loading completion event, and sets a breakpoint at the address of the first function, including: the integrated development environment determines the address of the first function based on the received trigger event; the integrated development environment determines that the address of the first function is within the address range of the second code segment, and generates a breakpoint setting command sent to the electronic device, the breakpoint setting command is used to instruct the electronic device to set a breakpoint at the address of the first function; the electronic device responds to the received breakpoint setting command and sets a breakpoint at the address of the first function.
例如,集成开发环境(IDE)可以基于电子设备加载应用程序的程序代码文件,例如共享库(SO)文件时,预先确定该SO文件对应的C/C++代码段的地址范围。进而,在接收到电子设备上报的本地函数调用事件时,集成开发环境(IDE)可以判断该本地函数调用事件对应被调用的第一函数的地址(例如C/C++函数地址)是否在上述预先确定的地址范围内。若在,则表明该第一函数的地址可以定位到待检查的C/C++代码段,因而可以确定在该第一函数的地址上打断点。可以理解,该打断点是指在上述C/C++函数地址上自动设置虚拟断点。当该断点被命中时,IDE的调试界面上可以高亮显示该C/C++函数地址对应的代码行,并且显示相应的C/C++代码段。For example, the integrated development environment (IDE) can predetermine the address range of the C/C++ code segment corresponding to the SO file when the program code file of the application is loaded by the electronic device, such as a shared library (SO) file. Furthermore, when receiving a local function call event reported by the electronic device, the integrated development environment (IDE) can determine whether the address of the first function called corresponding to the local function call event (e.g., the C/C++ function address) is within the above-mentioned predetermined address range. If it is, it indicates that the address of the first function can be located to the C/C++ code segment to be checked, so it can be determined to breakpoint at the address of the first function. It can be understood that the breakpoint refers to automatically setting a virtual breakpoint on the above-mentioned C/C++ function address. When the breakpoint is hit, the code line corresponding to the C/C++ function address can be highlighted on the debugging interface of the IDE, and the corresponding C/C++ code segment is displayed.
在上述第一方面的一种可能的实现中,在第一函数的地址上打断点,包括:集成开发环境将确定的第二代码段的地址范围发送给电子设备;电子设备判断第一函数的地址在第二代码段的地址范围内,向 集成开发环境上报第一函数的地址;集成开发环境基于第一函数的地址,生成向电子设备发送的断点设置命令;电子设备响应于接收到的断点设置命令,在第一函数的地址上打断点。In a possible implementation of the first aspect, setting a breakpoint at the address of the first function includes: the integrated development environment sends the determined address range of the second code segment to the electronic device; the electronic device determines that the address of the first function is within the address range of the second code segment, and sends a The integrated development environment reports the address of the first function; based on the address of the first function, the integrated development environment generates a breakpoint setting command to be sent to the electronic device; and the electronic device sets a breakpoint at the address of the first function in response to the received breakpoint setting command.
例如,集成开发环境(IDE)也可以将基于电子设备加载的共享库(SO)文件预先确定该SO文件对应的C/C++代码段的地址范围,发送给电子设备。进而电子设备可以在检测到本地函数调用事件时,确定该本地函数调用事件对应被调用的第一函数的地址(例如C/C++函数地址)是否在上述预先确定的地址范围内。若在,则表明该第一函数的地址可以定位到待检查的C/C++代码段,可以向IDE上报该C/C++函数地址。IDE可以基于上报的C/C++函数地址生成向电子设备发送的断点设置命令,即设置断点的命令。然后,电子设备可以基于接收到的断点设置命令,在该本地函数调用事件对应被调用的C/C++函数地址上打断点。For example, the integrated development environment (IDE) may also predetermine the address range of the C/C++ code segment corresponding to the shared library (SO) file loaded by the electronic device and send it to the electronic device. Then, when the electronic device detects a local function call event, it may determine whether the address of the first function called corresponding to the local function call event (e.g., the C/C++ function address) is within the above-mentioned predetermined address range. If so, it indicates that the address of the first function can be located to the C/C++ code segment to be checked, and the C/C++ function address can be reported to the IDE. The IDE may generate a breakpoint setting command, i.e., a command to set a breakpoint, to be sent to the electronic device based on the reported C/C++ function address. Then, based on the received breakpoint setting command, the electronic device may set a breakpoint at the C/C++ function address called corresponding to the local function call event.
在上述第一方面的一种可能的实现中,在第一函数的地址上打断点之后,方法还包括;接收到集成开发环境发送的恢复线程执行的命令;响应于恢复线程执行的命令,恢复运行程序代码的线程的执行。In a possible implementation of the first aspect above, after setting a breakpoint at the address of the first function, the method further includes: receiving a command to resume thread execution sent by the integrated development environment; and resuming execution of the thread running the program code in response to the command to resume thread execution.
在上述第一方面的一种可能的实现中,在恢复运行程序代码的线程的执行之后,方法还包括;检测到线程运行至第一函数命中断点,控制线程停在第一函数在第二代码段中的函数入口处。In a possible implementation of the first aspect above, after resuming execution of the thread running the program code, the method further includes: detecting that the thread runs to the first function and hitting a breakpoint, and controlling the thread to stop at the function entry of the first function in the second code segment.
第二方面,本申请实施例提供了一种电子设备,包括:一个或多个处理器;一个或多个存储器;一个或多个存储器存储有一个或多个程序,当一个或者多个程序被一个或多个处理器执行时,使得电子设备执行上述第一方面以及第一方面的各种可能的实现中提供的代码调试方法。In a second aspect, an embodiment of the present application provides an electronic device, comprising: one or more processors; one or more memories; one or more memories storing one or more programs, and when the one or more programs are executed by one or more processors, the electronic device executes the code debugging method provided in the above-mentioned first aspect and various possible implementations of the first aspect.
第三方面,本申请实施例提供了一种计算机可读存储介质,存储介质上存储有指令,指令在计算机上执行时使计算机执行上述第一方面以及第一方面的各种可能的实现中提供的代码调试方法。In a third aspect, an embodiment of the present application provides a computer-readable storage medium having instructions stored thereon. When the instructions are executed on a computer, the computer executes the code debugging method provided in the above-mentioned first aspect and various possible implementations of the first aspect.
第四方面,本申请实施例提供了一种计算机程序产品,包括计算机程序/指令,该计算机程序/指令被处理器执行时实现上述第一方面以及第一方面的各种可能的实现中提供的代码调试方法。In a fourth aspect, an embodiment of the present application provides a computer program product, including a computer program/instruction, which, when executed by a processor, implements the code debugging method provided in the above-mentioned first aspect and various possible implementations of the first aspect.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
图1a所示为一种跨语言的调试场景示意图。FIG1a is a schematic diagram of a cross-language debugging scenario.
图1b所示为一种跨语言的调试场景中被调用代码文件对应的代码显示界面示意图。FIG. 1 b is a schematic diagram showing a code display interface corresponding to a called code file in a cross-language debugging scenario.
图2所示为本申请实施例1提供的一种预定义代码段的代码示例。FIG2 shows a code example of a predefined code segment provided in Example 1 of the present application.
图3a所示为本申请实施例提供的一种电子设备100的系统架构示意图。FIG. 3 a is a schematic diagram of a system architecture of an electronic device 100 provided in an embodiment of the present application.
图3b所示为本申请实施例提供的一种调试系统示意图。FIG3 b is a schematic diagram of a debugging system provided in an embodiment of the present application.
图4所示为本申请实施例1提供的一种代码调试方法对应实施的交互流程。FIG4 shows an interactive process corresponding to the implementation of a code debugging method provided in Example 1 of the present application.
图5所示为本申请实施例1提供的一种显示JavaScript代码的调试界面示意图。FIG5 is a schematic diagram of a debugging interface for displaying JavaScript code provided in Example 1 of the present application.
图6所示为本申请实施例1提供的一种显示C/C++代码的调试界面示意图。FIG6 is a schematic diagram of a debugging interface for displaying C/C++ code provided in Example 1 of the present application.
图7所示为本申请实施例1提供的电子设备100与电子设备200之间的交互过程示意图。FIG. 7 is a schematic diagram showing the interaction process between the electronic device 100 and the electronic device 200 provided in Embodiment 1 of the present application.
图8所示为本申请实施例2提供的一种代码调试方法对应实施的交互流程。FIG8 shows an interactive process corresponding to an implementation of a code debugging method provided in Example 2 of the present application.
图9所示为本申请实施例提供的一种电子设备100的硬件结构示意图。FIG9 is a schematic diagram showing the hardware structure of an electronic device 100 provided in an embodiment of the present application.
具体实施方式Detailed ways
为了使本申请实施例的目的、技术方案和优点更加清楚,下面将结合说明书附图以及具体的实施方式对本申请实施例中的技术方案进行详细的说明。In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.
为了便于本领域技术人员理解本申请实施例中的方案,下面先对本申请实施例涉及到的一些概念和术语进行解释说明。In order to facilitate those skilled in the art to understand the solutions in the embodiments of the present application, some concepts and terms involved in the embodiments of the present application are explained below.
(1)调试会话(session)(1) Debug session
建立调试会话是单步进入调试的必须步骤。在调试会话建立以前,除了少数选项设置和用于建立调试会话的命令可以执行外,其它大多数命令都是被禁止的。因此,当使用集成开发环境(IDE)对用户使用的终端电子设备上安装的应用程序进行代码调试时,需要与该电子设备上安装/配置的调试服务中对应的调试器先建立调试会话,进而集成开发环境(IDE)才可以向该电子设备上的调试服务发送各种命令。Establishing a debugging session is a necessary step to single-step into debugging. Before the debugging session is established, most commands are prohibited except for a few option settings and commands for establishing the debugging session. Therefore, when using an integrated development environment (IDE) to debug the code of an application installed on a terminal electronic device used by a user, it is necessary to first establish a debugging session with a debugger corresponding to the debugging service installed/configured on the electronic device, and then the integrated development environment (IDE) can send various commands to the debugging service on the electronic device.
(2)共享库(Share Object,SO)(2) Shared Object (SO)
共享库文件以.so结尾,在程序链接的时候可以作些标记,然后在程序开始启动运行的时候,动态地加载所需的模块。因此,应用程序在运行的时候仍然需要共享库的支持,共享库也称为动态库。应用程序打包时会包含开发者编译的用户SO文件,而该应用程序运行所需的系统SO文件可以在电子设备的 系统中直接调用。The shared library file ends with .so. You can mark it when linking the program, and then dynamically load the required modules when the program starts running. Therefore, the application still needs the support of shared libraries when running. Shared libraries are also called dynamic libraries. When the application is packaged, it will contain the user SO file compiled by the developer, and the system SO file required for the application to run can be found in the electronic device. Directly call the system.
可以理解,在代码编译阶段,通过IDE编译的应用程序源代码,可以采用不同的语言编译,相应地编译工具以及输出的编译产物也会有所不同。例如JavaScript语言和C/C++语言编译的应用程序代码中,JavaScript代码可以对应生成“.abc”的文件,C/C++代码可以对应生成SO文件。其中,开发者开发应用程序时编写的C/C++代码对应生成的SO文件,通常还可以称为用户SO文件,在此不做赘述。It is understandable that during the code compilation phase, the application source code compiled by the IDE can be compiled in different languages, and the corresponding compilation tools and output compilation products will also be different. For example, in the application code compiled by JavaScript language and C/C++ language, the JavaScript code can generate a ".abc" file, and the C/C++ code can generate an SO file. Among them, the SO file generated by the C/C++ code written by the developer when developing the application is usually also called a user SO file, which will not be elaborated here.
在调试/运行阶段,上述应用程序运行在目标设备上时,该应用所需的用户SO就会被加载执行。During the debugging/running phase, when the above application is run on the target device, the user SO required by the application will be loaded and executed.
可以理解,该调试/运行阶段如果开发者检查到了IDE中的源代码中部分代码段存在问题,也可以在IDE上修改源代码中的相应代码段,例如修改C/C++代码,重新编译后可以生成新的共享库(SO)文件,该SO文件可以被重新打包到应用程序安装包中,例如安卓TM应用安装包(android application package,apk)或者鸿蒙TM应用安装包(harmonyos ability package,hap)等。重新调试应用程序代码时,可以重新安装更新的安装包,在此不做赘述。It is understandable that during the debugging/running phase, if the developer detects problems with some code segments in the source code in the IDE, the developer can also modify the corresponding code segments in the source code on the IDE, such as modifying the C/C++ code, and recompiling to generate a new shared library (SO) file, which can be repackaged into an application installation package, such as an Android TM application installation package (apk) or a Harmony OS application installation package (hap). When re-debugging the application code, the updated installation package can be reinstalled, which will not be elaborated here.
目标设备系统在加载完应用所需的SO后,相应的调试服务(例如lldb-server)就会上报library-loaded事件给IDE。因此,IDE侧可以收到加载完成事件(library-loaded)上报的SO文件,过滤出来其中属于用户SO的地址范围,可以通过新增的协议发送给被调试应用所运行的电子设备中的JS调试服务。After the target device system has loaded the SO required by the application, the corresponding debugging service (such as lldb-server) will report the library-loaded event to the IDE. Therefore, the IDE side can receive the SO file reported by the loading completion event (library-loaded), filter out the address range belonging to the user's SO, and send it to the JS debugging service in the electronic device where the debugged application is running through the newly added protocol.
图1a至图1b示出了一种跨语言的调试场景示意图。FIG. 1a and FIG. 1b are schematic diagrams showing a cross-language debugging scenario.
在此需声明的是,本申请实施例所提供的代码调试方法所适用的电子设备的用户通常可以是应用程序代码的开发者,在此不做限制。如非特别说明,在本申请实施例中,“用户”与“开发者”所指代的内容一致,均指有对应用程序代码进行调试的需求的人。It should be noted that the user of the electronic device to which the code debugging method provided in the embodiment of the present application is applicable can generally be the developer of the application code, and this is not limited here. Unless otherwise specified, in the embodiment of the present application, "user" and "developer" refer to the same content, both referring to a person who has a need to debug the application code.
如图1a所示,调试场景可以包括被调试应用所运行的电子设备100和集成开发环境(IDE)所运行的电子设备200。As shown in FIG. 1 a , the debugging scenario may include an electronic device 100 on which a debugged application is running and an electronic device 200 on which an integrated development environment (IDE) is running.
以电子设备100为手机、电子设备200为个人计算机(personal computer,PC)为例,参考图1a所示,手机100上安装的被调试应用可以是一个或多个,例如图1a所示的App01、App02、App03、App04等。当需要对手机100上的某个应用程序进行调试时,例如需要对App01进行调试时,可以将手机100与PC 200通过具有调试端口的数据线或者其他通信方式建立连接,并可以在PC 200所运行的集成开发环境(IDE)的调试界面210上选择接入设备。参考图1a所示的操作①,开发者可以在调试界面210的设备选项控件211下选择手机100作为接入设备。Taking the electronic device 100 as a mobile phone and the electronic device 200 as a personal computer (PC) as an example, as shown in FIG1a, the debugged application installed on the mobile phone 100 may be one or more, such as App01, App02, App03, App04, etc. shown in FIG1a. When it is necessary to debug a certain application on the mobile phone 100, for example, when it is necessary to debug App01, the mobile phone 100 and the PC 200 may be connected through a data cable with a debugging port or other communication methods, and the access device may be selected on the debugging interface 210 of the integrated development environment (IDE) running on the PC 200. Referring to operation ① shown in FIG1a, the developer may select the mobile phone 100 as the access device under the device option control 211 of the debugging interface 210.
进而,开发者可以操作手机100运行App01,并在调试界面210上点击单步进入调试控件212对App01的应用程序代码进行调试。调试界面210上显示被调试应用程序代码的区域213可以对应显示正在调试运行的代码。Furthermore, the developer can operate the mobile phone 100 to run App01, and click the step into debugging control 212 on the debugging interface 210 to debug the application code of App01. The area 213 displaying the debugged application code on the debugging interface 210 can correspondingly display the code being debugged.
在上述图1a所示的调试场景中,如果被调试的应用程序代码包括跨语言调用关系,例如图1a所示的JavaScript文件中第16行代码中的函数调用语句“testNapi.add(1,2);”表示在JavaScript语言中增加了对C/C++函数的调用。因此,在该应用程序代码的调试过程中,如果不添加断点,则当代码执行到图1a所示的JavaScript文件中第16行代码时,便会切换到对应调用的C/C++函数继续执行相应代码。In the debugging scenario shown in FIG. 1a above, if the debugged application code includes a cross-language call relationship, for example, the function call statement "testNapi.add(1,2);" in the 16th line of code in the JavaScript file shown in FIG. 1a indicates that a call to a C/C++ function is added in the JavaScript language. Therefore, during the debugging of the application code, if no breakpoint is added, when the code is executed to the 16th line of code in the JavaScript file shown in FIG. 1a, it will switch to the corresponding C/C++ function to continue executing the corresponding code.
此时IDE的调试界面可以切换至显示C/C++文件中的代码,例如图1b所示调试界面220中区域213显示的代码。当该C/C++文件中的代码执行完毕后,手机100可以继续执行JavaScript文件中的代码以继续调试过程,例如继续图1a所示的JavaScript文件中第17行代码,IDE的调试界面210中区域213相应切换回显示JavaScript文件中的代码。At this time, the debugging interface of the IDE can be switched to display the code in the C/C++ file, such as the code displayed in area 213 of the debugging interface 220 shown in FIG. 1b. When the code in the C/C++ file is executed, the mobile phone 100 can continue to execute the code in the JavaScript file to continue the debugging process, such as continuing the 17th line of code in the JavaScript file shown in FIG. 1a, and area 213 in the debugging interface 210 of the IDE switches back to display the code in the JavaScript file accordingly.
在上述图1a至图1b所示的调试场景中,如果开发者需要在IDE的调试界面上检查可能存在问题的代码文件,例如检查App01对应的程序代码是否有问题时,则需要在图1a所示的JavaScript代码中分析第16行代码对应调用的C/C++函数,并查找到该函数对应在C/C++文件中的位置,即函数地址。然后,开发者可以在IDE的调试界面上打开相应的C/C++文件,并在相应的C/C++函数地址上打断点。In the debugging scenario shown in Figures 1a and 1b above, if the developer needs to check the code files that may have problems on the debugging interface of the IDE, for example, to check whether the program code corresponding to App01 has problems, it is necessary to analyze the C/C++ function called by the 16th line of code in the JavaScript code shown in Figure 1a, and find the location of the function in the C/C++ file, that is, the function address. Then, the developer can open the corresponding C/C++ file on the debugging interface of the IDE and set a breakpoint on the corresponding C/C++ function address.
参考图1b所示,例如开发者可以在IDE显示的C/C++文件的第3行代码上点击一次,参考图1b所示的操作②,完成一次打断点的过程。相应地,被打上断点的第3行代码可以显示断点标记230。进而,开发者可以再次点击图1b所示调试界面220上的StepInto控件221,触发手机100运行App01以继续调试过程。进而,当App01的程序代码运行至JavaScript文件中第16行并跳转至C/C++文件中第3行 时,便会停下来。IDE也可以对应停在图1b所示的调试界面220上,此时开发者便可以检查C/C++文件中的代码是否有问题。As shown in FIG1b, for example, the developer can click once on the third line of code of the C/C++ file displayed by the IDE, and refer to operation ② shown in FIG1b to complete the process of setting a breakpoint. Accordingly, the third line of code with a breakpoint can display a breakpoint mark 230. Furthermore, the developer can click the StepInto control 221 on the debugging interface 220 shown in FIG1b again to trigger the mobile phone 100 to run App01 to continue the debugging process. Furthermore, when the program code of App01 runs to line 16 in the JavaScript file and jumps to line 3 in the C/C++ file, IDE can also stop at the debugging interface 220 shown in FIG. 1 b , and the developer can check whether there is any problem with the code in the C/C++ file.
但是,目前的这种需要开发者参与分析调用关系、查找相应文件以及手动点击代码行这种打断点的方式,在对一些涉及较多的JavaScript或者Java、Python等语言到C/C++跨语言调用的应用程序代码进行调试的过程中,调试效率比较低下,需要开发者参与较多,调试工作量也较大。However, the current method of breaking points, which requires developers to analyze call relationships, find corresponding files, and manually click code lines, is inefficient in debugging application codes that involve cross-language calls from languages such as JavaScript, Java, Python, etc. to C/C++. It requires more developer participation and a large debugging workload.
为了解决上述问题,本申请提供了一种代码调试方法,应用于电子设备。具体地,该方法预先在提供被调用函数(如上述图1b所示调试场景中调试界面220的区域213所显示的C/C++代码)所属的第二代码文件(如C/C++代码文件)中设置预定义代码段,该预定义代码段能够使上述提供被调用函数的第二代码文件与使用上述被调用函数的第一代码文件(如上述图1a所示调试场景中调试界面210的区域213所显示的JavaScript代码对应的JavaScript文件)进行关联。具体地,例如,对于图1a和图1b所示的场景,预定义代码可以将上述第二代码文件中被调用的C/C++函数地址、与上述第一代码文件(如JavaScript文件)中调用该C/C++函数的函数调用语句(如图1a所示的第16行代码对应的字段)之间建立关联关系。如此,基于上述过程所建立的关联关系,在运行被调试应用的程序代码过程中,当电子设备执行到JavaScript文件中的函数调用语句时可以自动识别出C/C++文件中与该字段相关联的C/C++函数地址,进而可以在该函数地址上自动设置虚拟断点,而无需开发者自己在JavaScript代码段中分析函数调用关系来确定需要打断点的C/C++函数的地址。In order to solve the above problems, the present application provides a code debugging method, which is applied to electronic devices. Specifically, the method pre-sets a predefined code segment in the second code file (such as a C/C++ code file) that provides the called function (such as the C/C++ code displayed in area 213 of the debugging interface 220 in the debugging scene shown in Figure 1b above), and the predefined code segment can associate the second code file that provides the called function with the first code file that uses the called function (such as the JavaScript file corresponding to the JavaScript code displayed in area 213 of the debugging interface 210 in the debugging scene shown in Figure 1a above). Specifically, for example, for the scenarios shown in Figures 1a and 1b, the predefined code can establish an association relationship between the address of the C/C++ function called in the second code file and the function call statement that calls the C/C++ function in the first code file (such as a JavaScript file) (such as the field corresponding to the 16th line of code shown in Figure 1a). In this way, based on the association relationship established by the above process, when the electronic device executes a function call statement in the JavaScript file during the running of the program code of the debugged application, it can automatically identify the C/C++ function address associated with the field in the C/C++ file, and then automatically set a virtual breakpoint at the function address, without the developer having to analyze the function call relationship in the JavaScript code segment to determine the address of the C/C++ function that needs a breakpoint.
如此,当恢复执行被调试应用的程序代码命中上述设置的虚拟断点时,电子设备所连接的集成开发环境(IDE)对应显示的测试界面上则显示C/C++代码(如图1b所示的代码段),并自动停在该断点所在地址对应的函数的入口处(如图1b所示的C/C++代码段中第3行代码开始的位置),从而便于调试人员或者开发者检查C/C++文件中的各行代码。例如,开发者则可以在上述图1b所示的IDE的调试界面220上检查当前显示的C/C++文件中的C/C++代码段是否存在待修复的漏洞等问题。In this way, when the program code of the debugged application is resumed and hits the virtual breakpoint set above, the C/C++ code (the code segment shown in FIG1b) is displayed on the corresponding test interface of the integrated development environment (IDE) to which the electronic device is connected, and the C/C++ code is automatically stopped at the entry of the function corresponding to the address where the breakpoint is located (the position where the third line of code in the C/C++ code segment shown in FIG1b begins), so that it is convenient for the debugger or developer to check each line of code in the C/C++ file. For example, the developer can check whether the C/C++ code segment in the currently displayed C/C++ file has vulnerabilities to be repaired on the debugging interface 220 of the IDE shown in FIG1b above.
作为示例,图2根据本申请实施例示出了一种预定义代码段的代码示例。As an example, FIG2 shows a code example of a predefined code segment according to an embodiment of the present application.
如图2所示,该预定义代码段包括定义导出对象属性以及对本地模块(Native Module)注册及初始化的相关代码示例。具体地,该代码段中定义了导出对象属性add及其C/C++的回调函数Add,因此在JavaScript中通过函数调用语句“testNapi.add(1,2);”调用add属性,最终会回调到C/C++中的Add函数。具体过程可以包括以下3步:As shown in Figure 2, the predefined code segment includes code examples for defining export object properties and registering and initializing native modules. Specifically, the code segment defines the export object property add and its C/C++ callback function Add. Therefore, calling the add property in JavaScript through the function call statement "testNapi.add(1,2);" will eventually call back to the Add function in C/C++. The specific process can include the following three steps:
①在C/C++代码段中预定义exports对象并添加属性,并且关联到C/C++代码文件中被调用的C/C++函数。例如在exports对象中定义add属性,并关联至C/C++代码段中的Add函数,其中Add函数作为add的回调函数。① Predefine the exports object in the C/C++ code segment and add properties, and associate it with the C/C++ function called in the C/C++ code file. For example, define the add property in the exports object and associate it with the Add function in the C/C++ code segment, where the Add function serves as the callback function of add.
②定义类型为napi_module的变量,例如demoModule,并赋值正确的属性,例如图2所示的“.nm_register_func”属性。② Define a variable of type napi_module, such as demoModule, and assign the correct attributes, such as the ".nm_register_func" attribute shown in Figure 2.
③定义模块注册函数,例如定义RegisterHelloModule函数,该函数可以通过NAPI接口注册上述定义的demoModule。③ Define the module registration function, for example, define the RegisterHelloModule function, which can register the demoModule defined above through the NAPI interface.
基于上述关联过程,在调试运行应用程序代码时,如果JavaScript代码中的“import”部分包括对SO文件的加载,例如图2所示的“import testNapi from“libentry.so””。此时系统则会加载libenrty.so,并在加载的时候运行RegisterHelloModule函数,该函数则会调用通过属性“.nm_register_func”赋值的“Init”函数。进而,Init函数则在exports对象定义了add属性,并返回。如此,import执行完后的就可以通过testNapi对应的函数调用语句来加载exports对象属性add。Based on the above association process, when debugging and running the application code, if the "import" part in the JavaScript code includes the loading of the SO file, such as "import testNapi from "libentry.so"" as shown in Figure 2, the system will load libenrty.so and run the RegisterHelloModule function when loading. The function will call the "Init" function assigned by the attribute ".nm_register_func". Furthermore, the Init function defines the add attribute in the exports object and returns. In this way, after the import is executed, the exports object attribute add can be loaded through the function call statement corresponding to testNapi.
例如,基于图2所示的预定义代码段,图1a所示JavaScript代码段中第16行代码对应的函数调用语句“testNapi.add(1,2);”中对exports对象属性add的加载调用,则可以直接关联至图1b所示的C/C++代码段中第3行代码中的被调用函数“Add(napi_env env,napi_callback_info info)”对应的地址。即绑定了JavaScript代码中的add属性和C/C++代码中的函数Add之间的关联关系,因此在JavaScript中调用add属性,会回调到C/C++中的Add函数。For example, based on the predefined code segment shown in FIG2, the load call of the exports object attribute add in the function call statement "testNapi.add(1,2);" corresponding to the 16th line of code in the JavaScript code segment shown in FIG1a can be directly associated with the address corresponding to the called function "Add(napi_env env,napi_callback_info info)" in the 3rd line of code in the C/C++ code segment shown in FIG1b. That is, the association between the add attribute in the JavaScript code and the function Add in the C/C++ code is bound, so calling the add attribute in JavaScript will call back to the Add function in C/C++.
参考图2所示,Init函数中通过在exports对象上定义的属性,在JavaScript中可通过import语句获得导出对象,进而可实现在JavaScript中调用C/C++函数。例如图2中,通过napi_property_descriptor声明了add属性,并设置回调函数为C/C++函数Add,最后通过napi_define_properties在exports对象上定义属性。 As shown in Figure 2, in the Init function, the properties defined on the exports object can be used in JavaScript through the import statement to obtain the export object, and then the C/C++ function can be called in JavaScript. For example, in Figure 2, the add property is declared through napi_property_descriptor, and the callback function is set to the C/C++ function Add, and finally the properties are defined on the exports object through napi_define_properties.
另外,上述图2所示的代码段中还包括对加载上述导出对象(exports对象)的示例模块(demoModule)的相关属性进行赋值的代码段。例如图2所示的“.nm_register_func=Init”等,以用于IDE在获取到图2所示代码时可以基于上述参数运行示例模块,从而初始化包括add与Add之间关联关系的调试环境。例如,在执行JavaScript代码中的导入函数“import”时可以触发注册模块(register_moudle),调用上述属性“.nm_register_func=Init”对应的函数(例如Init)。In addition, the code segment shown in FIG. 2 also includes a code segment for assigning relevant properties of the example module (demoModule) that loads the above export object (exports object). For example, ".nm_register_func = Init" shown in FIG. 2 is used for the IDE to run the example module based on the above parameters when obtaining the code shown in FIG. 2, thereby initializing the debugging environment including the association relationship between add and Add. For example, when the import function "import" in the JavaScript code is executed, the registration module (register_moudle) can be triggered, and the function corresponding to the above attribute ".nm_register_func = Init" (for example, Init) can be called.
可以理解,上述第一代码文件和第二代码文件均为被调用代码的程序代码组成部分,第一代码文件例如可以是JavaScript语言或者Java、Python等编程语言的编译产物。第二代码文件例如可以是C/C++语言等本地语言的编译产物,例如被调试应用的开发者通过集成开发环境IDE等编译得到的用户SO。在本申请实施例中,上述第一代码文件中的函数调用语句对应表达的对预先定义的导出对象属性的调用可以称为本地函数调用。上述第二代码文件中与第一代码文件中的函数调用语句所调用的导出对象属性相关联的函数,可以称为本地函数。It can be understood that the above-mentioned first code file and the second code file are both program code components of the called code, and the first code file can be, for example, a compiled product of a programming language such as JavaScript or Java, Python, etc. The second code file can be, for example, a compiled product of a native language such as C/C++, such as a user SO compiled by the developer of the debugged application through an integrated development environment IDE, etc. In an embodiment of the present application, the call to the pre-defined export object attribute expressed by the function call statement in the above-mentioned first code file can be called a local function call. The function in the above-mentioned second code file that is associated with the export object attribute called by the function call statement in the first code file can be called a local function.
可以理解,上述基于关联关系自动识别出与函数调用语句相关联的函数地址的过程,例如可以通过识别被调试应用的程序代码运行过程中上报的本地函数调用事件对应的第二代码函数地址是否在预设的地址范围内来实现。例如,基于上述第一代码文件中对第二代码文件的函数调用语句与第二代码文件中相应的函数地址之间建立的关联关系,电子设备或者电子设备所连接的IDE能够预先确定第二代码文件中的该关联关系中的函数地址对应在第二代码文件中的代码段地址范围。进而,当获取到被调试应用的程序代码运行过程中上报的本地函数调用事件时,便可以通过识别该事件对应调用的函数地址是否在上述确定的代码段地址范围内,进而该事件对应调用的函数地址是否为需要设置断点的第二代码文件中的函数地址。It can be understood that the process of automatically identifying the function address associated with the function call statement based on the association relationship can be achieved, for example, by identifying whether the second code function address corresponding to the local function call event reported during the running of the program code of the debugged application is within a preset address range. For example, based on the association relationship established between the function call statement of the second code file in the first code file and the corresponding function address in the second code file, the electronic device or the IDE to which the electronic device is connected can predetermine that the function address in the association relationship in the second code file corresponds to the code segment address range in the second code file. Furthermore, when the local function call event reported during the running of the program code of the debugged application is obtained, it can be determined whether the function address corresponding to the event is within the above-determined code segment address range, and then whether the function address corresponding to the event is the function address in the second code file for which a breakpoint needs to be set.
可以理解,基于本申请实施例提供的上述方案,能够有效简化开发者在调试应用程序代码的过程中需要对跨语言调用的代码分析调用关系、查找被调用的代码文件并打开该代码文件进行检查的繁琐过程。当需要在被调试应用的程序代码中对使用C/C++语言等本地语言编译的代码段或者代码文件设置断点时,基于本申请实施例提供的上述方案能够在运行的使用方代码(即上述第一代码)的过程中自动识别出提供方代码(即上述第二代码)中需要设置断点的函数地址,并完成自动打断点的过程,从而有利于提高调试效率。It can be understood that the above scheme provided based on the embodiment of the present application can effectively simplify the cumbersome process of developers analyzing the calling relationship of the code called across languages, finding the called code file and opening the code file for inspection in the process of debugging the application code. When it is necessary to set breakpoints for code segments or code files compiled in native languages such as C/C++ in the program code of the debugged application, the above scheme provided based on the embodiment of the present application can automatically identify the function address of the provider code (i.e., the second code) that needs to set breakpoints during the running of the user code (i.e., the first code) and complete the process of automatically setting breakpoints, thereby helping to improve debugging efficiency.
下面以第一代码对应的编码语言为JavaScript语言、第二代码对应的编码语言为C/C++语言为例,结合附图详细介绍本申请实施例提供的代码调试方法的具体实现过程。The following takes the example that the coding language corresponding to the first code is JavaScript language and the coding language corresponding to the second code is C/C++ language as an example, and describes in detail the specific implementation process of the code debugging method provided in the embodiment of the present application in combination with the accompanying drawings.
可以理解,本申请实施例所提供的代码调试方法,所适用的运行被调试应用的电子设备100可以包括但不限于手机、平板电脑、桌面型、膝上型、手持计算机、上网本,以及增强现实(augmentedreality,AR)\虚拟现实(virtual reality,VR)设备、智能电视、智能手表等可穿戴设备、服务器、移动电子邮件设备、车机设备、便携式游戏机、便携式音乐播放器、阅读器设备、其中嵌入或耦接有一个或多个处理器的电视机、或能够访问网络的其他电子设备。It can be understood that the code debugging method provided in the embodiment of the present application is applicable to the electronic device 100 running the debugged application, which may include but is not limited to mobile phones, tablet computers, desktops, laptops, handheld computers, netbooks, as well as augmented reality (AR) and virtual reality (VR) devices, smart TVs, smart watches and other wearable devices, servers, mobile email devices, car equipment, portable game consoles, portable music players, reader devices, televisions in which one or more processors are embedded or coupled, or other electronic devices that can access the Internet.
另外,本申请实施例所提供的代码调试方法,所适用的运行IDE的电子设备200可以包括但不限于个人计算机(personal computer,PC)、平板电脑、桌面型、膝上型、手持计算机、上网本、服务器、其中嵌入或耦接有一个或多个具有较强处理能力处理器的其他电子设备。In addition, the code debugging method provided in the embodiment of the present application may be applicable to an electronic device 200 running an IDE, including but not limited to a personal computer (PC), a tablet computer, a desktop computer, a laptop computer, a handheld computer, a netbook, a server, or other electronic devices embedded or coupled with one or more processors with relatively strong processing capabilities.
图3a根据本申请实施例示出了一种电子设备100的系统架构示意图。FIG3 a shows a schematic diagram of a system architecture of an electronic device 100 according to an embodiment of the present application.
如图3a所示,电子设备100可以搭载分布式系统架构。该分布式系统架构可以包括应用层、应用框架层、系统服务层以及内核层。可以理解,图3a所示的分布式系统架构可以是HarmonyOSTM或者其他具有类似图3a所示软件结构的分布式系统,在此不做限制。As shown in Figure 3a, the electronic device 100 can be equipped with a distributed system architecture. The distributed system architecture may include an application layer, an application framework layer, a system service layer, and a kernel layer. It is understood that the distributed system architecture shown in Figure 3a can be HarmonyOS TM or other distributed systems with a software structure similar to that shown in Figure 3a, and is not limited here.
其中,应用层可以包括被调试的应用程序,即被调试应用。被调试应用可以包括本地模块(Native模块,例如JavaScript Native Module)以及本地代码(例如JavaScript代码)。其中,Native模块用于提供Native接口给JavaScript代码。The application layer may include an application being debugged, i.e., a debugged application. The debugged application may include a native module (e.g., a JavaScript Native Module) and native code (e.g., JavaScript code). The Native module is used to provide a Native interface to the JavaScript code.
应用框架层,为应用程序提供Java/C/C++/JS等多语言的用户程序框架和元能力(Ability)框架,以及各种软硬件服务对外开放的多语言框架API。例如,可以为同样采用分布式系统架构的设备提供C/C++/JS等多语言的框架API,不同设备支持的API与系统的组件化裁剪程度相关。应用框架层还可以为应用程序提供用户界面框架(例如ArkUI框架)等,在此不做限制。The application framework layer provides the application with a multi-language user program framework and meta-capability framework in Java/C/C++/JS, as well as a multi-language framework API for various software and hardware services. For example, a multi-language framework API in C/C++/JS can be provided for devices that also use a distributed system architecture. The APIs supported by different devices are related to the degree of componentization of the system. The application framework layer can also provide a user interface framework (such as the ArkUI framework) for the application, which is not limited here.
其中,ArkUI框架是一套构建分布式应用界面的声明式UI开发框架。ArkUI框架可以包括本地应用 程序编程接口组件(Native Application Programming Interface,NAPI)。该NAPI组件是一套对外接口基于Node.js N-API规范开发的原生模块扩展开发框架,用于提供接口给C/C++,以提供访问底层JS引擎的能力。在本申请实施例中,本地函数调用由该模块检测并通知给JS引擎,并由其进一步通知给JS调试服务。Among them, the ArkUI framework is a declarative UI development framework for building distributed application interfaces. The ArkUI framework can include local applications Native Application Programming Interface (NAPI). The NAPI component is a native module extension development framework with an external interface based on the Node.js N-API specification, which is used to provide an interface to C/C++ to provide access to the underlying JS engine. In the embodiment of the present application, the local function call is detected by the module and notified to the JS engine, which further notifies the JS debugging service.
系统服务层,为分布式系统的核心能力集合,通过应用框架层对应用程序提供服务。系统服务层包括系统基本能力子系统集,为分布式应用程序在具有图3a所示分布式系统的多设备上的运行、调度、迁移等操作提供了基础能力。系统基本能力子系统集可以包括方舟多语言运行时子系统(简称方舟运行时)、公共基础库子系统等,用于提供多语言调试服务。其中,方舟运行时提供了C/C++/JS多语言运行时和基础的系统类库,也为使用方舟编译器静态化的Java程序(即应用程序或框架层中使用Java语言开发的部分)提供运行时。例如,方舟运行时可以提供JS调试服务(JavaScript debugger,JS debugger)、以及JS引擎等。其中,JS调试服务用于提供对JavaScript代码文件的调试能力,负责处理JavaScript线程的调试。The system service layer is a set of core capabilities of the distributed system, and provides services to applications through the application framework layer. The system service layer includes a set of system basic capability subsystems, which provide basic capabilities for the operation, scheduling, migration, and other operations of distributed applications on multiple devices with the distributed system shown in Figure 3a. The system basic capability subsystem set may include the Ark multi-language runtime subsystem (referred to as the Ark runtime), the public basic library subsystem, etc., which are used to provide multi-language debugging services. Among them, the Ark runtime provides C/C++/JS multi-language runtime and basic system class libraries, and also provides runtime for Java programs statically generated using the Ark compiler (i.e., the part developed using the Java language in the application or framework layer). For example, the Ark runtime can provide JS debugging services (JavaScript debugger, JS debugger), as well as JS engines, etc. Among them, the JS debugging service is used to provide debugging capabilities for JavaScript code files and is responsible for handling the debugging of JavaScript threads.
公共基础库子系统则可以用于提供C/C++调试服务(low level debugger-sever,lldb-server),用于提供对C/C++代码文件的调试能力,负责处理C/C++线程的调试。The public basic library subsystem can be used to provide C/C++ debugging services (low level debugger-sever, lldb-server), which is used to provide debugging capabilities for C/C++ code files and is responsible for handling the debugging of C/C++ threads.
可以理解,上述JS调试服务、C/C++调试服务等多语言调试服务负责与被调试应用程序的各代码文件执行线程进行交互。It can be understood that the multi-language debugging services such as the above-mentioned JS debugging service and C/C++ debugging service are responsible for interacting with the execution threads of each code file of the debugged application.
系统服务层还可以包括调试协议处理模块(图中未示出),用于负责与IDE或调试客户端进行交互,该调试客户端例如可以是上述图1a所示场景中电子设备200。例如,调试协议处理模块负责接收IDE或调试客户端传入的调试命令等信息。调试协议处理模块可以对符合通用调试接口协议的调试命令进行解析,并将解析后的合法的调试命令发送至多语言核心模块进行处理,调试协议处理模块还用于接收多语言核心模块返回的调试响应信息,并基于通用调试接口协议翻译并封装该调试响应信息,然后将封装后的调试响应信息返回至IDE或调试客户端。The system service layer may also include a debugging protocol processing module (not shown in the figure), which is responsible for interacting with the IDE or debugging client, and the debugging client may be, for example, the electronic device 200 in the scenario shown in FIG. 1a above. For example, the debugging protocol processing module is responsible for receiving information such as debugging commands passed in by the IDE or debugging client. The debugging protocol processing module can parse debugging commands that comply with the universal debugging interface protocol, and send the parsed legal debugging commands to the multilingual core module for processing. The debugging protocol processing module is also used to receive debugging response information returned by the multilingual core module, and translate and encapsulate the debugging response information based on the universal debugging interface protocol, and then return the encapsulated debugging response information to the IDE or debugging client.
可以理解,在本申请实施例中,被调试应用程序对应的进程可以包括JavaScript(JS)线程1、C/C++线程1、JS线程2、C/C++线程2等。在另一些实施例中,被调试应用程序对应的进程还可以包括Java线程1、Java线程2、Python线程1、Python线程2等,在此不做限制。It can be understood that in the embodiment of the present application, the process corresponding to the debugged application may include JavaScript (JS) thread 1, C/C++ thread 1, JS thread 2, C/C++ thread 2, etc. In other embodiments, the process corresponding to the debugged application may also include Java thread 1, Java thread 2, Python thread 1, Python thread 2, etc., which is not limited here.
在一些实施例中,多语言调试服务还可以具有识别当前加载或调试运行的地址是否在预设的地址范围内的运算能力。例如,C/C++调试服务可以在加载被调试应用对应的共享库时预设对应的C/C++代码文件中各行C/C++代码的地址范围。进而,在接收到IDE发来的本地函数调用事件对应调用的C/C++函数地址时,能够判断该地址是否在上述预设的地址范围内。进而C/C++调试服务能够自动识别IDE发来的本地函数调用事件对应调用的C/C++函数地址,并且可以在该地址对应的代码位置上设置虚拟断点。具体可以参考下文相关描述,在此不做赘述。In some embodiments, the multi-language debugging service may also have the computing capability to identify whether the address currently loaded or debugged is within a preset address range. For example, the C/C++ debugging service may preset the address range of each line of C/C++ code in the corresponding C/C++ code file when loading the shared library corresponding to the debugged application. Furthermore, upon receiving the address of the C/C++ function corresponding to the local function call event sent by the IDE, it is possible to determine whether the address is within the above-mentioned preset address range. Furthermore, the C/C++ debugging service can automatically identify the address of the C/C++ function corresponding to the local function call event sent by the IDE, and can set a virtual breakpoint at the code position corresponding to the address. For details, please refer to the relevant description below, which will not be repeated here.
内核层,包括内核子系统和驱动子系统。其中,内核子系统支持针对不同资源受限设备选用适合的OS内核。驱动子系统,则用于提供统一外设访问能力和驱动开发、管理框架。内核层还包括内核抽象层(Kernel Abstract Layer,KAL)通过屏蔽多内核差异,对上层提供基础的内核能力,包括进程/线程管理、内存管理、文件系统、网络管理和外设管理等。在此不做赘述。The kernel layer includes the kernel subsystem and the driver subsystem. The kernel subsystem supports the selection of suitable OS kernels for different resource-constrained devices. The driver subsystem is used to provide unified peripheral access capabilities and driver development and management frameworks. The kernel layer also includes the kernel abstract layer (KAL), which shields the differences between multiple kernels and provides basic kernel capabilities to the upper layer, including process/thread management, memory management, file system, network management, and peripheral management. I will not go into details here.
基于上述图3a所示的系统架构,下面结合部分流程图、部分电子设备100与IDE之间的交互示意图以及部分IDE界面示意图,详细说明本申请实施例提供的应用程序调试方法的具体实施过程。Based on the system architecture shown in FIG. 3a above, the specific implementation process of the application debugging method provided in the embodiment of the present application is described in detail below in combination with some flow charts, some schematic diagrams of the interaction between the electronic device 100 and the IDE, and some schematic diagrams of the IDE interface.
还需声明的是,本申请实施例中对方法、流程中的步骤进行编号是为了便于引用,而不是限定先后顺序,各步骤之间如有先后顺序,当以文字说明为准。It should also be stated that the steps in the methods and processes in the embodiments of the present application are numbered for ease of reference, rather than to limit the order of precedence. If there is an order between the steps, the text description shall prevail.
图3b根据本申请实施例示出了一种调试系统示意图。FIG3 b shows a schematic diagram of a debugging system according to an embodiment of the present application.
如图3b所示,该调试系统可以包括电子设备100和电子设备200。其中,电子设备100可以是搭载了上述图3a所示分布式系统架构的设备。故而,电子设备100可以包括系统服务及应用框架层的调试服务310、NAPI组件320、JS引擎330以及应用层的被调试应用340。As shown in FIG3b, the debugging system may include an electronic device 100 and an electronic device 200. The electronic device 100 may be a device equipped with the distributed system architecture shown in FIG3a. Therefore, the electronic device 100 may include a debugging service 310, a NAPI component 320, a JS engine 330 of the system service and application framework layer, and a debugged application 340 of the application layer.
其中,调试服务310可以包括上述JS调试服务311、C/C++调试服务312。NAPI组件320可以包括本地引擎(NativeEngine),例如JS引擎抽象层,用于统一JS引擎330在NAPI层的接口行为。被调试应用340可以包括Native模块341以及JavaScript代码342。该JavaScript代码342可以通过JS引擎330解释执行,而C/C++代码可以被打包成共享库(SO)文件被系统加载执行。 Among them, the debugging service 310 may include the above-mentioned JS debugging service 311 and C/C++ debugging service 312. The NAPI component 320 may include a native engine (NativeEngine), such as a JS engine abstraction layer, which is used to unify the interface behavior of the JS engine 330 at the NAPI layer. The debugged application 340 may include a Native module 341 and a JavaScript code 342. The JavaScript code 342 may be interpreted and executed by the JS engine 330, and the C/C++ code may be packaged into a shared library (SO) file to be loaded and executed by the system.
可以理解,在另一些实施例中,上述JS调试服务311也可以是对Java、Python等代码进行调试的调试器,在此不做限制。It is understandable that in other embodiments, the above-mentioned JS debugging service 311 can also be a debugger for debugging Java, Python and other codes, which is not limited here.
以上电子设备100中的调试服务310和被调试应用340所包括的各结构功能,可以参考上述图3a相关描述,在此不做赘述。The various structural functions included in the debugging service 310 and the debugged application 340 in the above electronic device 100 can refer to the relevant description of Figure 3a above, and will not be repeated here.
继续如图3b所示,电子设备200上可以运行集成开发环境IDE 201,对当前连接的电子设备100中的被调试应用340进行应用程序代码调试。可以理解,该IDE 201可以包括调试协议处理模块、以及JS调试核心(JavaScript debug core)和Native调试核心等多语言调试核心。这些调试核心可以用于接收调试协议处理模块(图中未示出)传入的调试命令,对被相应的调试线程进行相关的调试运行等操作,并将操作的结果进一步反馈给调试协议处理模块进行处理。而电子设备200上运行的IDE 201中的调试协议处理模块可以与电子设备100上的调试服务所包括的调试协议处理模块互通反馈信息等。Continuing as shown in FIG. 3b , the electronic device 200 can run an integrated development environment IDE 201 to debug the application code of the debugged application 340 in the currently connected electronic device 100. It can be understood that the IDE 201 may include a debugging protocol processing module, as well as multi-language debugging cores such as JS debugging core (JavaScript debug core) and Native debugging core. These debugging cores can be used to receive debugging commands passed in by the debugging protocol processing module (not shown in the figure), perform related debugging operations on the corresponding debugging thread, and further feed back the results of the operation to the debugging protocol processing module for processing. The debugging protocol processing module in the IDE 201 running on the electronic device 200 can communicate feedback information with the debugging protocol processing module included in the debugging service on the electronic device 100.
基于上述图3b所示的调试系统,下面先结合实施例1说明在上述调试系统中,电子设备100运行的调试服务310(包括JS调试服务311、C/C++调试服务312)、被调试应用340与电子设备200上运行的IDE 201之间的一种交互实现方式。Based on the debugging system shown in FIG. 3b , the following first describes in combination with Example 1 an interactive implementation method among the debugging service 310 (including JS debugging service 311 and C/C++ debugging service 312) run by the electronic device 100, the debugged application 340 and the IDE 201 run by the electronic device 200 in the above debugging system.
实施例1Example 1
图4根据本申请实施例示出了一种实施应用程序调试方法的交互流程。FIG. 4 shows an interactive process for implementing an application debugging method according to an embodiment of the present application.
如图4所示,该交互流程涉及上述图3b所示的调试系统中电子设备200运行的IDE 201、与电子设备100中调试服务310所包括的JS调试服务311、C/C++调试服务312、以及被调试应用340所包括的NAPI组件320、JS引擎330之间的交互。As shown in Figure 4, the interaction process involves the interaction between the IDE 201 running on the electronic device 200 in the debugging system shown in Figure 3b above, the JS debugging service 311 and C/C++ debugging service 312 included in the debugging service 310 in the electronic device 100, and the NAPI component 320 and JS engine 330 included in the debugged application 340.
具体地,该交互流程包括以下步骤:Specifically, the interaction process includes the following steps:
401:IDE 201与JS调试服务311建立调试会话,并向JS调试服务311发送设置混合调试开关的命令。401: IDE 201 establishes a debugging session with JS debugging service 311, and sends a command to JS debugging service 311 to set the hybrid debugging switch.
示例性地,电子设备100连接至电子设备200时,电子设备200上运行的IDE 201便也可以与电子设备100之间建立通信,进而与电子设备100上配置的调试服务310中的JS调试服务311建立调试会话。进一步地,IDE 201与JS调试服务311建立调试会话后,可以通过以下协议命令向JS调试服务311发送设置混合调试开关的命令:Exemplarily, when the electronic device 100 is connected to the electronic device 200, the IDE 201 running on the electronic device 200 can also establish communication with the electronic device 100, and then establish a debugging session with the JS debugging service 311 in the debugging service 310 configured on the electronic device 100. Further, after the IDE 201 establishes a debugging session with the JS debugging service 311, a command for setting a hybrid debugging switch can be sent to the JS debugging service 311 through the following protocol command:
{"method":"Debugger.setMixedDebugEnabled","params":{"enabled":true}}{"method":"Debugger.setMixedDebugEnabled","params":{"enabled":true}}
其中,上述混合调试开关可以用于控制JS调试服务311是否向IDE 201上报检测到的本地函数调用(NativeCalling)事件。Among them, the above-mentioned hybrid debugging switch can be used to control whether the JS debugging service 311 reports the detected native function call (NativeCalling) event to the IDE 201.
可以理解,在另一些实施例中,IDE 201向JS调试服务311发送设置命令的协议命令也可以采用其他命令形式,在此不做限制。It can be understood that in other embodiments, the protocol command for the IDE 201 to send the setting command to the JS debugging service 311 may also adopt other command forms, which are not limited here.
402:JS调试服务311设置混合调试开关。402: JS debugging service 311 sets the hybrid debugging switch.
示例性地,JS调试服务311响应于接收到的命令,即IDE 201执行上述步骤401发来的设置混合调试开关的命令,设置上述混合调试开关。Exemplarily, the JS debugging service 311 responds to the received command, i.e., the IDE 201 executes the command for setting the hybrid debugging switch sent in the above step 401, and sets the above hybrid debugging switch.
之后,当JS调试服务311接收到JS引擎330上报的本地函数调用事件时,则可以将C/C++函数地址通过本地函数调用事件对应上报给IDE 201,具体可以参考下述步骤409至411的执行过程,在此不做赘述。其中,上述本地函数调用事件用于调用本地代码,在本申请实施例中,本地代码可以是在C/C++语言下开发的代码,而调用C/C++语言下开发的本地代码的JavaScript代码可以是应用程序开发所使用的主要语言。因此,在JavaScript代码中调用Native模块导出的函数可以被称为本地函数调用。Afterwards, when the JS debugging service 311 receives the local function call event reported by the JS engine 330, the C/C++ function address can be reported to the IDE 201 through the local function call event. For details, please refer to the execution process of the following steps 409 to 411, which will not be repeated here. Among them, the above-mentioned local function call event is used to call the native code. In the embodiment of the present application, the native code can be the code developed in the C/C++ language, and the JavaScript code that calls the native code developed in the C/C++ language can be the main language used for application development. Therefore, calling the function exported by the Native module in the JavaScript code can be called a local function call.
403:IDE 201与C/C++调试服务312建立调试会话。403: IDE 201 establishes a debugging session with C/C++ debugging service 312.
示例性地,电子设备200上运行的IDE 201便也可以与电子设备100之间建立通信后,IDE 201如果想要给C/C++调试服务312发送命令,也可以建立与C/C++调试服务312建立调试会话。在此不做赘述。Exemplarily, after the IDE 201 running on the electronic device 200 establishes communication with the electronic device 100, if the IDE 201 wants to send a command to the C/C++ debugging service 312, it can also establish a debugging session with the C/C++ debugging service 312. No further details will be given here.
404:C/C++调试服务312监听到应用进程所依赖的共享库(SO)加载完成后,上报所加载的SO相关属性。404: After the C/C++ debugging service 312 monitors that the shared library (SO) that the application process depends on has been loaded, it reports the relevant properties of the loaded SO.
示例性地,上述共享库(SO)一般是C/C++语言或者rust语言等编译型语言的编码产物,因此在基于JavaScript/C/C++语言开发的应用程序代码中,SO中的代码一般为C/C++代码。也就是说,上述C/C++调试服务312所加载的SO可以是C/C++代码,并且通常是应用程序的开发者所编写的用户SO。 C/C++调试服务312可以获取应用进程所加载的共享库(SO)相关属性,并通过library-loaded上报。因此,本步骤404的执行过程即:IDE 201与C/C++调试服务312建立本地(Native)调试会话之后,该调试会话包括混合调试和本地调试,C/C++调试服务312会上IDE 201上报SO加载完成事件(library-loaded),该事件上报的内容包括so名称、加载地址、代码段地址范围。并且,该共享库(SO)对应的C/C++代码段中可以预先定义的导出对象以及对应添加的属性,JavaScript代码段中可以对应包括导入预先定义的导出对象的函数调用语句。即,JavaScript代码段中的函数调用语句与C/C++代码段中相应的函数地址已建立关联关系。因此,C/C++调试服务312通过library-loaded上报的共享库(SO)相关属性,可以包括SO文件的名称、加载地址、以及被调用的C/C++代码段的地址范围等属性。For example, the shared library (SO) is generally a coding product of a compiled language such as C/C++ or rust, so in the application code developed based on JavaScript/C/C++, the code in the SO is generally C/C++ code. In other words, the SO loaded by the C/C++ debugging service 312 can be C/C++ code, and is usually a user SO written by the developer of the application. The C/C++ debugging service 312 can obtain the related properties of the shared library (SO) loaded by the application process and report it through library-loaded. Therefore, the execution process of this step 404 is: after the IDE 201 and the C/C++ debugging service 312 establish a native debugging session, the debugging session includes mixed debugging and native debugging, and the C/C++ debugging service 312 reports the SO loading completion event (library-loaded) to the IDE 201, and the content reported by the event includes the so name, loading address, and code segment address range. In addition, the C/C++ code segment corresponding to the shared library (SO) can pre-define the export object and the corresponding added properties, and the JavaScript code segment can correspond to the function call statement that imports the pre-defined export object. That is, the function call statement in the JavaScript code segment has established an association relationship with the corresponding function address in the C/C++ code segment. Therefore, the shared library (SO) related attributes reported by the C/C++ debugging service 312 through library-loaded may include attributes such as the name of the SO file, the loading address, and the address range of the called C/C++ code segment.
调试应用时,C/C++调试器312可以监听到系统对共享库的加载,并将加载的SO相关属性,例如SO文件的名称、加载地址、代码段的地址范围等属性,通过library-loaded事件上报给IDE 201。When debugging an application, the C/C++ debugger 312 can monitor the system's loading of shared libraries, and report the loaded SO-related properties, such as the name of the SO file, the loading address, the address range of the code segment, and other properties, to the IDE 201 through the library-loaded event.
405:C/C++调试服务312向IDE 201上报加载完成事件。405: C/C++ debugging service 312 reports the loading completion event to IDE 201.
示例性地,C/C++调试服务312完成加载共享库(SO)后,可以向IDE 201上报加载完成(library-loaded)事件。其中,C/C++调试服务312上报library-loaded事件的内容可以参考以下示例:library-loaded,hostname="\data\storage\el1\bundle\libs\arm\libentry.so",loaded_addr="0x00000000d4c41000",codeRange="0x00000000d4c43c44~0x00000000d4c480e0"Exemplarily, after the C/C++ debugging service 312 completes loading of the shared library (SO), it can report a loading completion (library-loaded) event to the IDE 201. The content of the library-loaded event reported by the C/C++ debugging service 312 can refer to the following example: library-loaded, hostname = "\data\storage\el1\bundle\libs\arm\libentry.so", loaded_addr = "0x00000000d4c41000", codeRange = "0x00000000d4c43c44 ~ 0x00000000d4c480e0"
其中,hostname对应上报的电子设备中存储libentry.so文件的路径。loaded_addr对应上报的是libentry.so加载的首地址。codeRange对应上报的是C/C++代码段对应的地址范围。上述地址或地址范围的表示方式采用的是十六进制,在另一些实施例中,上述首地址或地址范围也可以采用十进制或者其他位数的进制来表示,在此不做限制。Among them, hostname corresponds to the path of the libentry.so file stored in the electronic device reported. loaded_addr corresponds to the first address of libentry.so loaded. codeRange corresponds to the address range corresponding to the C/C++ code segment reported. The above address or address range is expressed in hexadecimal. In other embodiments, the above first address or address range can also be expressed in decimal or other digits, which is not limited here.
406:IDE 201确定所加载的C/C++代码段对应的第一地址范围。406: IDE 201 determines the first address range corresponding to the loaded C/C++ code segment.
示例性地,IDE 201可以基于接收到的C/C++调试服务312上报的加载完成(library-loaded)事件,获取C/C++代码段对应的地址范围,作为第一地址范围。该地址范围可以在执行下述步骤413的判断过程中,作为判断的依据,具体可以参考下述步骤413中相关描述,在此不做赘述。Exemplarily, IDE 201 can obtain the address range corresponding to the C/C++ code segment as the first address range based on the received loading completion (library-loaded) event reported by the C/C++ debugging service 312. The address range can be used as a basis for judgment in the judgment process of executing the following step 413. For details, please refer to the relevant description in the following step 413, which will not be repeated here.
作为示例,继续参考前述例子,上述IDE 201所确定的第一地址范围例如可以是"0x00000000d4c43c44~0x00000000d4c480e0",该范围可以基于上述步骤405中C/C++调试服务312上报的加载完成事件(library-loaded)中的codeRange="0x00000000d4c43c44~0x00000000d4c480e0"来确定。As an example, continuing to refer to the aforementioned example, the first address range determined by the above IDE 201 may be, for example, "0x00000000d4c43c44~0x00000000d4c480e0", which may be determined based on codeRange="0x00000000d4c43c44~0x00000000d4c480e0" in the loading completion event (library-loaded) reported by the C/C++ debugging service 312 in the above step 405.
407:IDE 201检测到单步进入调试的用户操作。407: IDE 201 detected a user operation of single-stepping into debugging.
示例性地,例如用户可以在电子设备200运行IDE时显示的调试界面上点击“StepInto”控件,即单步进入调试控件/按钮,相应地,IDE 201则可以检测到单步进入调试的用户操作。其中,上述向IDE201输入操作的用户,例如可以是上述开发者。For example, a user can click a "StepInto" control on the debugging interface displayed when the electronic device 200 runs the IDE, i.e., a single-step into debugging control/button, and accordingly, the IDE 201 can detect the user operation of single-step into debugging. The user who inputs the operation to the IDE 201 can be, for example, the developer.
作为示例,图5根据本申请实施例示出了一种显示JavaScript代码的调试界面示意图。As an example, FIG5 shows a schematic diagram of a debugging interface for displaying JavaScript code according to an embodiment of the present application.
如图5所示,电子设备200运行IDE 201连接被调试应用340所运行的设备之后,可以显示调试界面510。IDE 201在执行完上述步骤401以及403等步骤之后,如果用户点击调试界面510上的StepInto控件511,则可以启动对目标应用程序即被调试应用的调试过程。此时,电子设备200所运行IDE 201则可以对应检测到单步进入调试的用户操作。As shown in FIG5 , after the electronic device 200 runs the IDE 201 and connects to the device where the debugged application 340 runs, the debugging interface 510 can be displayed. After the IDE 201 executes the above steps 401 and 403, if the user clicks the StepInto control 511 on the debugging interface 510, the debugging process of the target application, i.e., the debugged application, can be started. At this time, the IDE 201 running on the electronic device 200 can detect the user operation of single-step into debugging.
可以理解,用户可以在图5所示调试界面510上显示的JavaScript代码段中选中第16行代码,再点击StepInto控件511。用户也可以预先在该行代码上手动添加断点,该调试界面510上可以相应地显示断点标记512。在另一些实施例中,在JavaScript代码段中的函数调用语句对应位置(例如上述第16行代码)触发单步进入调试的操作也可以为其他,在此不做限制。It is understood that the user can select the 16th line of code in the JavaScript code segment displayed on the debugging interface 510 shown in FIG5 , and then click the StepInto control 511. The user can also manually add a breakpoint on the line of code in advance, and the breakpoint mark 512 can be displayed accordingly on the debugging interface 510. In other embodiments, the operation of triggering the single-step into debugging at the corresponding position of the function call statement in the JavaScript code segment (such as the 16th line of code mentioned above) can also be other, which is not limited here.
408:IDE 201向JS调试服务311发送单步进入(StepInto)命令。408: IDE 201 sends a StepInto command to JS debugging service 311.
示例性地,IDE 201在检测到StepInto操作后,可以向电子设备100中调试服务提供的JS调试服务311发送调试命令。该调试命令可实现在被调用函数入口处停住。Exemplarily, after detecting the StepInto operation, the IDE 201 may send a debugging command to the JS debugging service 311 provided by the debugging service in the electronic device 100. The debugging command may stop at the entrance of the called function.
409:NAPI组件320检测到本地函数调用,产生本地函数调用事件。409: The NAPI component 320 detects a local function call and generates a local function call event.
如上所述,Native模块321通常是C/C++开发的模块,其作用是提供本地(Native)接口给JavaScript代码。JavaScript则通过“import”导入Native模块的exports对象,通过该对象回调到 C/C++函数。进而,JS调试服务311在调试运行JavaScript代码至上述本地函数调用处时,便可以触发该接口获取被调试应用340上报的本地函数调用(NativeCalling)事件。As mentioned above, the Native module 321 is usually a module developed in C/C++, and its function is to provide a native interface to the JavaScript code. JavaScript imports the exports object of the Native module through "import" and calls back to the C/C++ function. Furthermore, when the JS debugging service 311 debugs and runs the JavaScript code to the above-mentioned native function call, it can trigger the interface to obtain the native function call (NativeCalling) event reported by the debugged application 340.
410:NAPI组件320通过JS引擎330向JS调试服务311上报本地函数调用事件。410 : The NAPI component 320 reports the local function call event to the JS debugging service 311 through the JS engine 330 .
示例性地,NAPI组件320可以将检测到本地函数调用而产生的本地函数调用事件,通过JS引擎330上报给JS调试服务311。作为示例,上报本地函数调用事件的方式例如可以参考以下示例:Exemplarily, the NAPI component 320 may report the local function call event generated by detecting the local function call to the JS debugging service 311 through the JS engine 330. As an example, the method of reporting the local function call event may refer to the following example:
{"method":"Debugger.NativeCalling","params":{"NativeAddress":0xd4c43de8}}{"method":"Debugger.NativeCalling","params":{"NativeAddress":0xd4c43de8}}
其中,"NativeAddress":0xd4c43de8表示将要调用的C/C++函数的内存地址。在另一些实施例中,上报本地函数调用事件的方式也可以为其他,在此不做限制。Among them, "NativeAddress": 0xd4c43de8 represents the memory address of the C/C++ function to be called. In other embodiments, the method of reporting the native function call event can also be other, which is not limited here.
411:JS调试服务311向IDE 201上报本地函数调用事件。411: JS debugging service 311 reports local function call events to IDE 201.
示例性地,JS调试服务311接收到JS引擎330上报的本地函数调用事件后,基于上述步骤402中设置的混合调试开关为开启状态的指示,可以继续将该本地函数调用事件上报给IDE 204。Exemplarily, after the JS debugging service 311 receives the local function call event reported by the JS engine 330, based on the indication that the hybrid debugging switch set in the above step 402 is in the on state, it can continue to report the local function call event to the IDE 204.
412:JS调试服务311暂停线程执行。412: JS debugging service 311 suspends thread execution.
示例性地,JS调试服务311响应于接收到的本地函数调用事件,执行上述步骤411之后,可以进一步暂停线程执行。这是由于JS调试服务311在执行上述步骤411上报地址后,通常需要IDE设置对即将调用的C/C++函数设置完虚拟断点之后,才能继续让线程继续执行,即调用对应C/C++回调函数。因此JS调试服务311可以在执行完上述步骤411的上报地址过程后,执行本步骤412暂停线程的执行。Exemplarily, the JS debugging service 311 can further suspend the thread execution after executing the above step 411 in response to the received local function call event. This is because after the JS debugging service 311 reports the address in the above step 411, the IDE usually needs to set a virtual breakpoint for the C/C++ function to be called before the thread can continue to execute, that is, call the corresponding C/C++ callback function. Therefore, the JS debugging service 311 can execute this step 412 to suspend the thread execution after completing the address reporting process in the above step 411.
可以理解,上述暂停执行的方式,例如可以通过执行sleep等方式实现,在此不做限制。It can be understood that the above-mentioned method of suspending execution can be achieved, for example, by executing sleep, etc., and is not limited here.
413:IDE 201判断基于本地函数调用事件确定的C/C++函数地址是否在第一地址范围内。若判断结果为是,即C/C++函数地址在上述第一地址范围内时,则可以执行下述步骤414;若判断结果为否,即C/C++函数地址不在上述第一地址范围内时,则可以执行下述步骤415。413: IDE 201 determines whether the C/C++ function address determined based on the local function call event is within the first address range. If the determination result is yes, that is, the C/C++ function address is within the first address range, the following step 414 may be executed; if the determination result is no, that is, the C/C++ function address is not within the first address range, the following step 415 may be executed.
示例性地,IDE 201可以在接收到JS调试服务311上报的本地函数调用事件后,基于该事件中上报的C/C++函数地址,进而确定该地址是否在用户SO的代码段地址范围(即上述第一地址范围)内,其中该地址范围是通过上述library-loaded事件上报给IDE 201的。Exemplarily, after receiving a local function call event reported by the JS debugging service 311, IDE 201 can determine whether the address is within the code segment address range of the user SO (i.e., the first address range mentioned above) based on the C/C++ function address reported in the event, wherein the address range is reported to IDE 201 via the above-mentioned library-loaded event.
参考上述图2所示,C/C++函数可以为Add函数,该函数作为JavaScript代码中add的Native回调函数,而add是JavaScript代码中通过“import”导入的对象的属性。参考前述步骤410中的示例,上述C/C++函数地址例如可以是“0xd4c43de8”,该地址其实为十六进制表示的地址“0x0000000d4c43de8”。在另一些实施例中,JS调试服务311上报的C/C++函数地址例如也可以是十进制等表示的地址,在此不做限制。Referring to FIG. 2 above, the C/C++ function may be the Add function, which is the native callback function of add in the JavaScript code, and add is the property of the object imported by "import" in the JavaScript code. Referring to the example in the aforementioned step 410, the C/C++ function address may be, for example, "0xd4c43de8", which is actually the hexadecimal address "0x0000000d4c43de8". In other embodiments, the C/C++ function address reported by the JS debugging service 311 may also be, for example, an address expressed in decimal, etc., which is not limited here.
进一步地,在确定上述C/C++函数地址后,IDE 201则可以将该地址与执行上述步骤406时确定的第一地址范围进行比较,以确定该C/C++函数地址是否在该第一地址范围内。Furthermore, after determining the above-mentioned C/C++ function address, IDE 201 can compare the address with the first address range determined when executing the above-mentioned step 406 to determine whether the C/C++ function address is within the first address range.
作为示例,继续参考前述例子,IDE 201在先确定的第一地址范围例如是"0x00000000d4c43c44~0x00000000d4c480e0",IDE 201接收到的C/C++函数地址例如是“0xd4c43de8”,即“0x0000000d4c43de8”。则通过比较“0x0000000d4c43de8”与第一地址范围的下限阈值“0x00000000d4c43c44”的大小、以及与第一地址范围的上限阈值“0x00000000d4c480e0”的大小,可以确定该C/C++函数地址在第一地址范围内。因此,IDE 201可以继续执行下述步骤414发送设置断点的命令。As an example, referring to the above example, the first address range previously determined by IDE 201 is, for example, "0x00000000d4c43c44~0x00000000d4c480e0", and the C/C++ function address received by IDE 201 is, for example, "0xd4c43de8", i.e., "0x0000000d4c43de8". By comparing the size of "0x0000000d4c43de8" with the lower limit threshold "0x00000000d4c43c44" of the first address range, and with the upper limit threshold "0x00000000d4c480e0" of the first address range, it can be determined that the C/C++ function address is within the first address range. Therefore, IDE 201 can continue to execute the following step 414 to send a command to set a breakpoint.
414:IDE 201向C/C++调试服务312发送设置断点的命令。414: IDE 201 sends a command to set a breakpoint to C/C++ debugging service 312.
示例性地,IDE 201在执行上述步骤413确定接收到的C/C++函数地址在第一地址范围内时,可以向已建立调试会话的C/C++调试服务312发送设置断点的命令。Exemplarily, when IDE 201 executes the above step 413 to determine that the received C/C++ function address is within the first address range, it can send a command to set a breakpoint to the C/C++ debugging service 312 that has established a debugging session.
相应地,C/C++调试服务312响应于接收到的命令,可以在在被调试进程对应地址打上断点。Accordingly, in response to the received command, the C/C++ debugging service 312 may set a breakpoint at the corresponding address of the debugged process.
发送设置断点命令,完成打断点之后,IDE 201可以继续执行下述步骤416,发送回复线程执行的命令。After sending the breakpoint setting command and completing the breakpoint setting, IDE 201 can continue to execute the following step 416 and send the reply thread execution command.
415:IDE 201忽略接收到的C/C++函数地址。415: IDE 201 ignored the received C/C++ function address.
示例性地,IDE 201在执行上述步骤413确定接收到的C/C++函数地址不在第一地址范围内时,则可以忽略接收到的C/C++函数地址。此时,IDE 201可以继续执行下述步骤416,向JS调试服务311发送恢复线程执行的命令。Exemplarily, when IDE 201 determines that the received C/C++ function address is not within the first address range during the execution of step 413, the received C/C++ function address may be ignored. At this time, IDE 201 may continue to execute step 416 to send a command to resume thread execution to JS debugging service 311.
416:IDE 201向JS调试服务311发送恢复线程执行的命令。 416: IDE 201 sends a command to resume thread execution to JS debugging service 311.
示例性地,IDE 201在执行完上述步骤414或者415之后,可以继续执行本步骤416,向JS调试服务311发送恢复线程执行的命令,指示JS调试服务311恢复线程执行。Exemplarily, after executing the above step 414 or 415, IDE 201 may continue to execute this step 416, sending a command to resume thread execution to JS debugging service 311, instructing JS debugging service 311 to resume thread execution.
417:JS调试服务311恢复线程执行。417: JS debugging service 311 resumes thread execution.
示例性地,JS调试服务311可以响应于接收到的恢复执行线程执行的命令,继续运行JavaScript代码文件或者运行C/C++代码。在此不做赘述。Exemplarily, the JS debugging service 311 may continue to run the JavaScript code file or run the C/C++ code in response to the received command to resume the execution of the execution thread, which will not be described in detail here.
418:C/C++调试服务312向IDE 201上报命中断点的消息。418: The C/C++ debugging service 312 reports the message of hitting the breakpoint to the IDE 201.
示例性地,线程恢复执行后,运行至C/C++回调函数,命中虚拟断点。具体地,线程恢复执行后,可以继续运行之前被暂停的C/C++回调函数,如果IDE 201执行上述步骤414后C/C++调试服务312在上述函数对应地址设置断点,则可命中该断点。此时C/C++调试服务312可以通过已建立的调试会话向IDE 201上报命中断点的消息。命中断点后,IDE 201的调试界面对应的C/C++函数入口行可以高亮或以其他醒目方式显示。Exemplarily, after the thread resumes execution, it runs to the C/C++ callback function and hits the virtual breakpoint. Specifically, after the thread resumes execution, the previously suspended C/C++ callback function can continue to run. If the C/C++ debugging service 312 sets a breakpoint at the address corresponding to the above function after IDE 201 executes the above step 414, the breakpoint can be hit. At this time, the C/C++ debugging service 312 can report the message of hitting the breakpoint to IDE 201 through the established debugging session. After the breakpoint is hit, the C/C++ function entry line corresponding to the debugging interface of IDE 201 can be highlighted or displayed in other eye-catching ways.
可以理解,上述“命中”虚拟断点或者断点,顾名思义是指执行该断点对应标记的行的代码时,C/C++调试服务(lldb-server)识别到了断点,并暂停线程执行。上述“虚拟断点”与“断点”可以理解为具有相同功能的标记形式可能不同也可能相同的停止标记。在此不做赘述。It can be understood that the above-mentioned "hitting" virtual breakpoint or breakpoint, as the name implies, means that when the code of the line marked by the breakpoint is executed, the C/C++ debugging service (lldb-server) recognizes the breakpoint and pauses the thread execution. The above-mentioned "virtual breakpoint" and "breakpoint" can be understood as stop marks with the same function, which may or may not be the same in different marking forms. I will not elaborate on them here.
图6根据本申请实施例示出了一种显示C/C++代码的调试界面示意图。FIG6 shows a schematic diagram of a debugging interface for displaying C/C++ codes according to an embodiment of the present application.
如图6所示,电子设备200运行的IDE 201接收到命中断点的反馈消息时,IDE 201的调试界面可以自动停在C/C++回调函数的入口地址对应的代码行,并显示C/C++文件中的代码段,例如6所示的调试界面610所显示的C/C++代码段。同时,命中断点时C/C++回调函数的入口地址对应的代码行可以高亮显示或以其他醒目形式显示。As shown in FIG6 , when the IDE 201 running on the electronic device 200 receives a feedback message of hitting a breakpoint, the debugging interface of the IDE 201 can automatically stop at the code line corresponding to the entry address of the C/C++ callback function and display the code segment in the C/C++ file, such as the C/C++ code segment displayed by the debugging interface 610 shown in FIG6 . At the same time, the code line corresponding to the entry address of the C/C++ callback function when the breakpoint is hit can be highlighted or displayed in other eye-catching forms.
419:IDE 201向C/C++调试服务312发送删除断点的命令。419: IDE 201 sends a command to delete the breakpoint to C/C++ debugging service 312.
示例性地,IDE 201在接收到的JS调试服务311上报的命中断点的消息之后,也可以向C/C++调试服务312发送删除已设置的断点的命令。如此,可以在调试过程中及时清除第二代码文件或C/C++代码文件中设置的断点标记,以避免在对检查出代码问题完成修复后再次运行JavaScript代码文件或C/C++代码文件时,JS调试服务311反复停止断点标记的位置导致调试效率降低的问题。Exemplarily, after receiving the message of the breakpoint being hit reported by the JS debugging service 311, the IDE 201 may also send a command to delete the set breakpoint to the C/C++ debugging service 312. In this way, the breakpoint mark set in the second code file or the C/C++ code file can be cleared in time during the debugging process, so as to avoid the problem that when the JavaScript code file or the C/C++ code file is run again after the code problem is repaired, the JS debugging service 311 repeatedly stops at the position of the breakpoint mark, resulting in reduced debugging efficiency.
可以理解,在一些实施例中,一次代码调试完成,如果未关闭混合调试开关,则执行完上述步骤418之后,可以不执行上述步骤419,以便于再次调试运行该应用程序代码时,可以自动停在已设置的虚拟断点上,有利于提高反复调试的效率。在另一些实施例中,一次代码调试完成,如果混合调试开关关闭,则执行完上述步骤418之后,可以继续执行上述步骤419,删除断点,以便于再次调试运行该应用程序代码时,能够重新执行上述步骤401至418,完成自动添加断点以及命中断点等过程,有利于提高调试效率。It can be understood that in some embodiments, after a code debugging is completed, if the hybrid debugging switch is not turned off, then after executing the above step 418, the above step 419 may not be executed, so that when the application code is debugged and run again, it can automatically stop at the set virtual breakpoint, which is conducive to improving the efficiency of repeated debugging. In other embodiments, after a code debugging is completed, if the hybrid debugging switch is turned off, then after executing the above step 418, the above step 419 can be continued to be executed to delete the breakpoint, so that when the application code is debugged and run again, the above steps 401 to 418 can be re-executed to complete the process of automatically adding breakpoints and hitting breakpoints, which is conducive to improving debugging efficiency.
上述图4所示步骤401至419的交互流程可以总结为下述图7所示的电子设备100与电子设备200之间的交互过程示意图。The interaction process of steps 401 to 419 shown in FIG. 4 can be summarized as a schematic diagram of the interaction process between the electronic device 100 and the electronic device 200 shown in FIG. 7 below.
图7根据本申请实施例示出了一种调试系统内电子设备100与电子设备200之间的交互过程。FIG. 7 shows an interaction process between an electronic device 100 and an electronic device 200 in a debugging system according to an embodiment of the present application.
可以理解,被调试应用的进程可以包括多个线程,对于多语言编写的被调试应用,各个线程在执行的过程中可以包括跨语言的代码调用,例如某个执行JavaScript代码的线程中可以包括对C/C++函数的调用。在另一些实施例中,跨语言的代码调用也可以发生在跨线程的运行场景中,在此不做限制。It is understood that the process of the debugged application may include multiple threads. For the debugged application written in multiple languages, each thread may include cross-language code calls during execution. For example, a thread executing JavaScript code may include a call to a C/C++ function. In other embodiments, cross-language code calls may also occur in cross-threaded running scenarios, which are not limited here.
作为示例,被调试应用进程中某个线程对应运行的JavaScript代码中包括对C/C++代码的调用,因此该线程的执行过程例如可以是先执行JavaScript代码段、执行至本地函数调用位置时可以跳转至执行被调用的C/C++代码段,完成执行后再跳转回执行JavaScript代码等过程。这种场景下,图7所示的交互过程主要包括以下四个阶段:As an example, the JavaScript code running in a thread of the debugged application process includes a call to C/C++ code, so the execution process of the thread may be, for example, to first execute the JavaScript code segment, and when the execution reaches the local function call position, it may jump to execute the called C/C++ code segment, and then jump back to execute the JavaScript code after the execution is completed. In this scenario, the interaction process shown in FIG7 mainly includes the following four stages:
阶段①:电子设备200上运行的集成开发环境(IDE)在与电子设备100上运行的JS调试服务(JS debugger)之间建立调试会话后,可以向JS调试服务发送协议命令指示JS debugger设置混合调试开关。相应地,JS调试服务完成混合调试开关的设置后,可以将该开关置为“开”的状态,当不需要执行调试任务时该开关可以置为“关”。Phase ①: After the integrated development environment (IDE) running on the electronic device 200 establishes a debugging session with the JS debugging service (JS debugger) running on the electronic device 100, it can send a protocol command to the JS debugging service to instruct the JS debugger to set the hybrid debugging switch. Accordingly, after the JS debugging service completes the setting of the hybrid debugging switch, the switch can be set to the "on" state, and the switch can be set to "off" when the debugging task does not need to be performed.
阶段②:IDE在与电子设备100上运行的C/C++调试服务(lldb-server)之间建立调试会话后,lldb-server可以向IDE上报完成加载共享库(SO)的加载完成事件。相应地,IDE可以获取被调试应用进程所加载的所有共享库(SO)信息,这些SO包括系统SO以及开发者开发的用户SO。 Phase ②: After the IDE establishes a debugging session with the C/C++ debugging service (lldb-server) running on the electronic device 100, the lldb-server can report to the IDE the loading completion event of the shared library (SO). Accordingly, the IDE can obtain information about all shared libraries (SO) loaded by the debugged application process, including system SOs and user SOs developed by developers.
阶段③:调试过程中,当用户点击IDE调试界面上的单步进入调试控件(StepInto)时,如果电子设备100中的JS引擎运行JavaScript代码期间检测到本地函数调用,则可以向IDE上报一个本地函数调用(NativeCalling)事件。并且,JS调试服务可以在上报的事件中把该C/C++函数对应的地址发给IDE,并挂起线程,暂停执行代码。在另一些实施例中,JS调试服务在上报本地函数调用事件后,IDE也可以向JS调试服务发送停止线程执行的命令,例如debugger.pause命令,指示JS调试服务停止线程执行,在此不做限制。Phase ③: During the debugging process, when the user clicks the single-step into the debugging control (StepInto) on the IDE debugging interface, if the JS engine in the electronic device 100 detects a native function call during the execution of the JavaScript code, a native function call (NativeCalling) event can be reported to the IDE. In addition, the JS debugging service can send the address corresponding to the C/C++ function to the IDE in the reported event, and suspend the thread and pause the execution of the code. In other embodiments, after the JS debugging service reports the native function call event, the IDE can also send a command to stop the thread execution to the JS debugging service, such as the debugger.pause command, to instruct the JS debugging service to stop the thread execution, which is not limited here.
阶段④:IDE在接收到的JS debugger上报的NativeCalling事件后,可以判断随该事件上报的C/C++函数地址是否在已确定的用户SO的代码段地址范围内。若是则IDE可以通过lldb-server在该地址对应的代码位置例如C/C++函数的入口处设置虚拟断点。之后,IDE可以向JS debugger发送恢复(resume)命令。恢复线程执行,运行到JavaScript方法对应C/C++回调函数,则会命中上述断点,线程再次暂停运行,并停在函数入口处。Phase ④: After receiving the NativeCalling event reported by the JS debugger, the IDE can determine whether the C/C++ function address reported with the event is within the determined code segment address range of the user SO. If so, the IDE can set a virtual breakpoint at the code location corresponding to the address, such as the entry of the C/C++ function, through the lldb-server. After that, the IDE can send a resume command to the JS debugger. When the thread execution is resumed and runs to the C/C++ callback function corresponding to the JavaScript method, the above breakpoint will be hit, and the thread will be suspended again and stop at the function entry.
可以理解,基于上述图4所示交互流程的执行过程或者图7所示调试系统内电子设备100与电子设备200之间的交互过程,本申请实施例提供的代码调试方法能够实现在使用IDE调试应用程序代码的过程中,自动为多语言编写的应用程序代码设置断点。如此,可以在使调试过程使IDE的调试界面自动停在被调用的C/C++等代码文件中,例如停在本地函数调用位置。It can be understood that based on the execution process of the interaction flow shown in FIG. 4 or the interaction process between the electronic device 100 and the electronic device 200 in the debugging system shown in FIG. 7, the code debugging method provided in the embodiment of the present application can realize the process of using the IDE to debug the application code, and automatically set breakpoints for the application code written in multiple languages. In this way, the debugging process can make the debugging interface of the IDE automatically stop at the called C/C++ code file, for example, stop at the local function call location.
对应指示的代码位置处,并显示被调用的C/C++函数对应的C/C++文件中的代码,从而便于开发者快速定位跨语言的程序代码检查代码问题进行修复,有利于提高调试效率。The corresponding indicated code position and the code in the C/C++ file corresponding to the called C/C++ function are displayed, so that developers can quickly locate cross-language program code, check code problems and repair them, which is conducive to improving debugging efficiency.
基于上述图3b所示的调试系统,下面先结合实施例2说明在上述调试系统中,电子设备100运行的调试服务310、被调试应用340与电子设备200上运行的IDE 201之间的另一种交互实现方式。Based on the debugging system shown in FIG. 3b , another interaction implementation method between the debugging service 310 running on the electronic device 100, the debugged application 340 and the IDE 201 running on the electronic device 200 in the above debugging system will be described below in conjunction with Example 2.
实施例2Example 2
与上述实施例1中图4所示交互流程不同的是,在本申请实施例中,运行被调试应用340的电子设备100侧可以执行上述图4所示的步骤406以及步骤413至415的相关过程。Different from the interaction process shown in FIG. 4 in the above-mentioned embodiment 1, in the embodiment of the present application, the electronic device 100 running the debugged application 340 can execute the related processes of step 406 and steps 413 to 415 shown in the above-mentioned FIG. 4 .
具体地,如图8所示,该交互流程可以包括以下步骤:Specifically, as shown in FIG8 , the interaction process may include the following steps:
图8根据本申请实施例示出了一种实施应用程序调试方法的交互流程。FIG8 shows an interactive process for implementing an application debugging method according to an embodiment of the present application.
如图8所示,该交互流程涉及上述图3b所示的调试系统中电子设备200运行的IDE 201、与电子设备100中调试服务310所包括的JS调试服务311、C/C++调试服务312、以及系统提供的NAPI组件320、JS引擎模块330之间的交互。As shown in Figure 8, the interaction process involves the interaction between the IDE 201 running on the electronic device 200 in the debugging system shown in Figure 3b above, the JS debugging service 311 and C/C++ debugging service 312 included in the debugging service 310 in the electronic device 100, and the NAPI component 320 and JS engine module 330 provided by the system.
具体地,该交互流程包括以下步骤:Specifically, the interaction process includes the following steps:
801:IDE 201与JS调试服务311建立调试会话,并向JS调试服务311发送设置混合调试开关的命令。801: IDE 201 establishes a debugging session with JS debugging service 311, and sends a command to JS debugging service 311 to set the hybrid debugging switch.
802:JS调试服务311设置混合调试开关。802: JS debugging service 311 sets the hybrid debugging switch.
803:IDE 201与C/C++调试服务312建立调试会话。803: IDE 201 establishes a debugging session with C/C++ debugging service 312.
804:C/C++调试服务312监听到应用进程所依赖的共享库(SO)加载完成后,上报所加载的SO相关属性。804: After the C/C++ debugging service 312 monitors that the shared library (SO) that the application process depends on has been loaded, it reports the relevant properties of the loaded SO.
805:C/C++调试服务312向IDE 201上报加载完成事件。805: C/C++ debugging service 312 reports the loading completion event to IDE 201.
上述步骤801至805的执行过程与上述实施例1中的步骤401至405的执行过程相同,具体可以参考上述实施例1中步骤401至405中相关描述,在此不做赘述。The execution process of the above steps 801 to 805 is the same as the execution process of steps 401 to 405 in the above embodiment 1. For details, please refer to the relevant descriptions of steps 401 to 405 in the above embodiment 1, and no further details will be given here.
806:IDE 201向JS调试服务311发送基于加载完成事件确定的C/C++代码段对应的第一地址范围。806: IDE 201 sends the first address range corresponding to the C/C++ code segment determined based on the loading completion event to the JS debugging service 311.
示例性地,IDE 201响应于接收到的加载完成事件,可以从中确定出C/C++调试服务312所加载的共享库(即用户SO)对应的代码段地址范围,在本申请实施例中,该用户SO例如为C/C++代码。因此,IDE 201所确定的地址范围即为C/C++代码段对应的第一地址范围。进而,IDE 201可以将该第一地址范围发送给JS调试服务311,以用于执行下述步骤814,具体可以参考下述步骤814中相关描述,在此不做赘述。Exemplarily, in response to the received loading completion event, IDE 201 can determine the code segment address range corresponding to the shared library (i.e., user SO) loaded by the C/C++ debugging service 312. In the embodiment of the present application, the user SO is, for example, C/C++ code. Therefore, the address range determined by IDE 201 is the first address range corresponding to the C/C++ code segment. Furthermore, IDE 201 can send the first address range to JS debugging service 311 for executing the following step 814. For details, please refer to the relevant description in the following step 814, which will not be repeated here.
807:IDE 201检测到单步进入调试的用户操作。807: IDE 201 detected a user operation to single-step into debugging.
808:IDE 201向JS调试服务311发送单步进入(StepInto)命令。808: IDE 201 sends a StepInto command to JS debugging service 311.
809:NAPI组件320检测到本地函数调用,产生本地函数调用事件。809: The NAPI component 320 detects a local function call and generates a local function call event.
810:NAPI组件320通过JS引擎330向JS调试服务311上报本地函数调用事件。 810 : The NAPI component 320 reports the local function call event to the JS debugging service 311 through the JS engine 330 .
811:JS调试服务311向IDE 201上报本地函数调用事件。811: JS debugging service 311 reports local function call events to IDE 201.
812:JS调试服务311暂停线程执行。812: JS debugging service 311 suspends thread execution.
上述步骤807至812的执行过程与上述实施例1中的步骤407至412的执行过程相同,具体可以参考上述实施例1中步骤407至412中相关描述,在此不做赘述。The execution process of the above steps 807 to 812 is the same as the execution process of steps 407 to 412 in the above embodiment 1. For details, please refer to the relevant descriptions of steps 407 to 412 in the above embodiment 1, and no further details will be given here.
813:IDE 201向JS调试服务311发送基于本地函数调用事件确定的C/C++函数地址。813: IDE 201 sends the C/C++ function address determined based on the local function call event to the JS debugging service 311.
示例性地,在本申请实施例中IDE 201基于JS调试服务311上报的本地函数调用事件,可以确定该事件对应上报的检测到的C/C++函数地址,并将该地址转发给JS调试服务311,以供JS调试服务311继续执行下述步骤814的判断过程。Exemplarily, in the embodiment of the present application, IDE 201 can determine the detected C/C++ function address corresponding to the local function call event reported by the JS debugging service 311 based on the event, and forward the address to the JS debugging service 311, so that the JS debugging service 311 can continue to execute the judgment process of the following step 814.
814:JS调试服务311判断C/C++函数地址是否在第一地址范围内。若判断结果为是,即C/C++函数地址在上述第一地址范围内时,则可以执行下述步骤815;若判断结果为否,即C/C++函数地址不在上述第一地址范围内时,则可以执行下述步骤817。814: The JS debugging service 311 determines whether the C/C++ function address is within the first address range. If the determination result is yes, that is, the C/C++ function address is within the first address range, the following step 815 may be executed; if the determination result is no, that is, the C/C++ function address is not within the first address range, the following step 817 may be executed.
示例性地,JS调试服务311可以将接收到的C/C++函数地址,与执行上述步骤806时确定的第一地址范围进行比较,以确定该C/C++函数地址是否在该第一地址范围内。具体示例可以参考上述实施例1的步骤413中相关描述,在此不做赘述。Exemplarily, the JS debugging service 311 may compare the received C/C++ function address with the first address range determined when executing the above step 806 to determine whether the C/C++ function address is within the first address range. For specific examples, reference may be made to the relevant description in step 413 of the above embodiment 1, which will not be described in detail here.
815:JS调试服务311向IDE 201上报本地函数地址。815: JS debugging service 311 reports the local function address to IDE 201.
示例性地,JS调试服务311可以在确定C/C++函数地址在上述第一地址范围内,即执行上述步骤814对应的判断结果为是时,确定本地函数地址(NativeAddress),即上述C/C++函数对应在C/C++代码段中的地址。此时,JS调试服务311则可以向IDE 201上报该本地函数地址。Exemplarily, when the JS debugging service 311 determines that the C/C++ function address is within the first address range, that is, when the judgment result corresponding to the above step 814 is yes, it determines the native function address (NativeAddress), that is, the address of the above C/C++ function in the C/C++ code segment. At this time, the JS debugging service 311 can report the native function address to the IDE 201.
816:IDE 201向C/C++调试服务312发送设置断点的命令。816: IDE 201 sends a command to set a breakpoint to C/C++ debugging service 312.
上述步骤816的执行过程与上述实施例1中的步骤414的执行过程相同,具体可以参考上述实施例1中步骤414中相关描述,在此不做赘述。The execution process of the above step 816 is the same as the execution process of step 414 in the above embodiment 1. For details, please refer to the relevant description of step 414 in the above embodiment 1, which will not be repeated here.
发送设置断点命令,完成打断点之后,IDE 201可以继续执行下述步骤818,发送回复线程执行的命令。After sending the breakpoint setting command and completing the breakpoint setting, IDE 201 can continue to execute the following step 818 and send the reply thread execution command.
817:JS调试服务311忽略接收到的C/C++函数地址。817: The JS debugging service 311 ignores the received C/C++ function address.
示例性地,JS调试服务311在执行上述步骤814确定接收到的C/C++函数地址不在第一地址范围内时,则可以忽略接收到的C/C++函数地址。此时,IDE 201可以继续执行下述步骤818,向JS调试服务311发送恢复线程执行的命令。Exemplarily, when the JS debugging service 311 determines that the received C/C++ function address is not within the first address range during the execution of the above step 814, the received C/C++ function address may be ignored. At this time, the IDE 201 may continue to execute the following step 818 to send a command to the JS debugging service 311 to resume thread execution.
818:IDE 201向JS调试服务311发送恢复线程执行的命令。818: IDE 201 sends a command to resume thread execution to JS debugging service 311.
上述步骤818的执行过程与上述实施例1中的步骤416的执行过程相同,具体可以参考上述实施例1中步骤416中相关描述,在此不做赘述。The execution process of the above step 818 is the same as the execution process of step 416 in the above embodiment 1. For details, please refer to the relevant description of step 416 in the above embodiment 1, which will not be repeated here.
819:JS调试服务311恢复线程执行。819: JS debugging service 311 resumes thread execution.
上述步骤819的执行过程与上述实施例1中的步骤417的执行过程相同,具体可以参考上述实施例1中步骤417中相关描述,在此不做赘述。The execution process of the above step 819 is the same as the execution process of step 417 in the above embodiment 1. For details, please refer to the relevant description of step 417 in the above embodiment 1, which will not be repeated here.
820:JS调试服务311向IDE 201上报命中断点的消息。820: JS debugging service 311 reports the message of hitting the breakpoint to IDE 201.
上述步骤820的执行过程与上述实施例1中的步骤418的执行过程相同,具体可以参考上述实施例1中步骤418中相关描述,在此不做赘述。The execution process of the above step 820 is the same as the execution process of step 418 in the above embodiment 1. For details, please refer to the relevant description of step 418 in the above embodiment 1, which will not be repeated here.
821:IDE 201向C/C++调试服务312发送删除断点的命令。821: IDE 201 sends a command to delete the breakpoint to C/C++ debugging service 312.
上述步骤820的执行过程与上述实施例1中的步骤419的执行过程相同,具体可以参考上述实施例1中步骤419中相关描述,在此不做赘述。The execution process of the above step 820 is the same as the execution process of step 419 in the above embodiment 1. For details, please refer to the relevant description of step 419 in the above embodiment 1, which will not be repeated here.
可以理解,基于上述图8所示交互流程的执行过程,本申请实施例提供的代码调试方法同样能够实现在使用IDE调试应用程序代码的过程中,自动为多语言编写的应用程序代码设置断点。如此,可以在使调试过程使IDE的调试界面自动停在被调用的C/C++等代码文件中,例如停在本地函数调用位置对应指示的代码位置处,并显示被调用的C/C++函数对应的C/C++文件中的代码,从而便于开发者快速定位跨语言的程序代码检查代码问题进行修复,有利于提高调试效率。It can be understood that based on the execution process of the interactive flow shown in FIG8 above, the code debugging method provided in the embodiment of the present application can also realize the process of using IDE to debug application code, automatically setting breakpoints for application code written in multiple languages. In this way, the debugging process can make the debugging interface of the IDE automatically stop at the called C/C++ and other code files, for example, stop at the code position corresponding to the indicated local function call position, and display the code in the C/C++ file corresponding to the called C/C++ function, so as to facilitate developers to quickly locate cross-language program code, check code problems and repair them, which is conducive to improving debugging efficiency.
图9根据本申请实施例示出了一种电子设备100的硬件结构示意图。FIG9 shows a schematic diagram of the hardware structure of an electronic device 100 according to an embodiment of the present application.
电子设备100可以包括处理器110,外部存储器接口120,内部存储器121,通用串行总线(universal serial bus,USB)接口130,充电管理模块140,电源管理模块141,电池142,天线1,天线2,移动 通信模块150,无线通信模块160,音频模块170,扬声器170A,受话器170B,麦克风170C,耳机接口170D,传感器模块180,按键190,马达191,指示器192,摄像头193,显示屏194,以及用户标识模块(subscriber identification module,SIM)卡接口195等。其中传感器模块180可以包括压力传感器180A,陀螺仪传感器180B,气压传感器180C,磁传感器180D,加速度传感器180E,距离传感器180F,接近光传感器180G,指纹传感器180H,温度传感器180J,触摸传感器180K,环境光传感器180L等。The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile Communication module 150, wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, sensor module 180, button 190, motor 191, indicator 192, camera 193, display screen 194, and subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, etc.
可以理解的是,本发明实施例示意的结构并不构成对电子设备100的具体限定。在本申请另一些实施例中,电子设备100可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。It is to be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
另外,可以理解的是,上述图3b所示调试系统中电子设备200也可以具备图9所示的硬件结构部件,或者具备比图9所示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。在此不做限制。In addition, it is understandable that the electronic device 200 in the debugging system shown in FIG. 3 b may also have the hardware structural components shown in FIG. 9 , or may have more or fewer components than those shown in FIG. 9 , or may combine certain components, or may split certain components, or may have different component arrangements. This is not limited here.
处理器110可以包括一个或多个处理单元,例如:处理器110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and/or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated in one or more processors.
控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.
在本申请实施例中,电子设备100的处理器110可以通过控制器产生控制信号,来控制上述实施例1或实施例2提供的电子设备100在于电子设备200运行的IDE交互的过程中,实现代码调试方法的各交互步骤。具体可以参考上述实施例1中图4所示交互流程或上述实施例2中图8所示交互流程中的相关描述,在此不做赘述。In the embodiment of the present application, the processor 110 of the electronic device 100 can generate a control signal through the controller to control the electronic device 100 provided in the above embodiment 1 or embodiment 2 to implement each interaction step of the code debugging method during the interaction with the IDE running on the electronic device 200. For details, please refer to the relevant description of the interaction process shown in Figure 4 of the above embodiment 1 or the interaction process shown in Figure 8 of the above embodiment 2, which will not be repeated here.
处理器110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器110中的存储器为高速缓冲存储器。该存储器可以保存处理器110刚用过或循环使用的指令或数据。如果处理器110需要再次使用该指令或数据,可从上述存储器中直接调用。避免了重复存取,减少了处理器110的等待时间,因而提高了系统的效率。The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
在一些实施例中,处理器110可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuit sound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purpose input/output,GPIO)接口,用户标识模块(subscriber identity module,SIM)接口,和/或通用串行总线(universal serial bus,USB)接口等。In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver/transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input/output (GPIO) interface, a subscriber identity module (SIM) interface, and/or a universal serial bus (USB) interface, etc.
USB接口130是符合USB标准规范的接口,具体可以是Mini USB接口,Micro USB接口,USB Type C接口等。USB接口130可以用于连接充电器为电子设备100充电,也可以用于电子设备100与外围设备之间传输数据。The USB interface 130 is an interface that complies with USB standard specifications, and may be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 may be used to connect a charger to charge the electronic device 100, and may also be used to transmit data between the electronic device 100 and a peripheral device.
可以理解的是,本发明实施例示意的各模块间的接口连接关系,只是示意性说明,并不构成对电子设备100的结构限定。在本申请另一些实施例中,电子设备100也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present invention is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
充电管理模块140用于从充电器接收充电输入。电源管理模块141用于连接电池142,充电管理模块140与处理器110。电源管理模块141接收电池142和/或充电管理模块140的输入,为处理器110,内部存储器121,显示屏194,摄像头193,和无线通信模块160等供电。The charging management module 140 is used to receive charging input from the charger. The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and/or the charging management module 140 to power the processor 110, the internal memory 121, the display screen 194, the camera 193, and the wireless communication module 160.
电子设备100的无线通信功能可以通过天线1,天线2,移动通信模块150,无线通信模块160,调制解调处理器以及基带处理器等实现。The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.
天线1和天线2用于发射和接收电磁波信号。电子设备100中的每个天线可用于覆盖单个或多个通信频带。不同的天线还可以复用,以提高天线的利用率。例如:可以将天线1复用为无线局域网的分集天线。在另外一些实施例中,天线可以和调谐开关结合使用。Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.
移动通信模块150可以提供应用在电子设备100上的包括2G/3G/4G/5G等无线通信的解决方案。无线通信模块160可以提供应用在电子设备100上的包括无线局域网(wireless local area networks, WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),全球导航卫星系统(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。The mobile communication module 150 can provide solutions for wireless communications including 2G/3G/4G/5G etc. applied to the electronic device 100. The wireless communication module 160 can provide solutions including wireless local area networks (WLANs, Wireless communication solutions such as WLAN (such as wireless fidelity (Wi-Fi) network), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared technology (IR), etc.
在一些实施例中,电子设备100的天线1和移动通信模块150耦合,天线2和无线通信模块160耦合,使得电子设备100可以通过无线通信技术与网络以及其他设备通信。上述无线通信技术可以包括全球移动通讯系统(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(code division multiple access,CDMA),宽带码分多址(wideband code division multiple access,WCDMA),时分码分多址(time-division code division multiple access,TD-SCDMA),长期演进(long term evolution,LTE),BT,GNSS,WLAN,NFC,FM,和/或IR技术等。上述GNSS可以包括全球卫星定位系统(global positioning system,GPS),全球导航卫星系统(global navigation satellite system,GLONASS),北斗卫星导航系统(beidou navigation satellite system,BDS),准天顶卫星系统(quasi-zenith satellite system,QZSS)和/或星基增强系统(satellite based augmentation systems,SBAS)。In some embodiments, the antenna 1 of the electronic device 100 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the electronic device 100 can communicate with the network and other devices through wireless communication technology. The above wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and/or IR technology. The above-mentioned GNSS may include the global positioning system (GPS), the global navigation satellite system (GLONASS), the Beidou navigation satellite system (BDS), the quasi-zenith satellite system (QZSS) and/or the satellite based augmentation system (SBAS).
电子设备100通过GPU,显示屏194,以及应用处理器等实现显示功能。The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor.
显示屏194用于显示图像,视频等。显示屏194包括显示面板。在一些实施例中,电子设备100可以包括1个或N个显示屏194,N为大于1的正整数。The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
电子设备100可以通过ISP,摄像头193,视频编解码器,GPU,显示屏194以及应用处理器等实现拍摄功能。The electronic device 100 can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor.
ISP用于处理摄像头193反馈的数据。摄像头193用于捕获静态图像或视频。在一些实施例中,电子设备100可以包括1个或N个摄像头193,N为大于1的正整数。The ISP is used to process data fed back by the camera 193. The camera 193 is used to capture static images or videos. In some embodiments, the electronic device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.
外部存储器接口120可以用于连接外部存储卡,例如Micro SD卡,实现扩展电子设备100的存储能力。外部存储卡通过外部存储器接口120与处理器110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部存储卡中。The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, files such as music and videos can be stored in the external memory card.
内部存储器121可以用于存储计算机可执行程序代码,该可执行程序代码包括指令。内部存储器121可以包括存储程序区和存储数据区。其中,存储程序区可存储操作系统,至少一个功能所需的应用程序(比如声音播放功能,图像播放功能等)等。存储数据区可存储电子设备100使用过程中所创建的数据(比如音频数据,电话本等)等。此外,内部存储器121可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件,闪存器件,通用闪存存储器(universal flash storage,UFS)等。处理器110通过运行存储在内部存储器121的指令,和/或存储在设置于处理器中的存储器的指令,执行电子设备100的各种功能应用以及数据处理。The internal memory 121 can be used to store computer executable program codes, which include instructions. The internal memory 121 can include a program storage area and a data storage area. Among them, the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area can store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (universal flash storage, UFS), etc. The processor 110 executes various functional applications and data processing of the electronic device 100 by running instructions stored in the internal memory 121 and/or instructions stored in a memory provided in the processor.
在本申请实施例中,电子设备100的处理器110可以通过运行存储在内部存储器121、或存储在设置于处理器中的存储器中的用于调试应用程序代码的相关指令,来实现上述实施例1或实施例2提供的电子设备100中的调试服务以及被调试应用中的各模块功能,这些功能可以用于实施本申请实施例提供的代码调试方法。In an embodiment of the present application, the processor 110 of the electronic device 100 can implement the debugging service in the electronic device 100 and the functions of each module in the debugged application provided in the above-mentioned embodiment 1 or embodiment 2 by running relevant instructions for debugging application code stored in the internal memory 121 or stored in a memory provided in the processor. These functions can be used to implement the code debugging method provided in the embodiment of the present application.
电子设备100可以通过音频模块170,扬声器170A,受话器170B,麦克风170C,耳机接口170D,以及应用处理器等实现音频功能。例如音乐播放,录音等。The electronic device 100 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.
压力传感器180A用于感受压力信号,可以将压力信号转换成电信号。在一些实施例中,压力传感器180A可以设置于显示屏194。压力传感器180A的种类很多,如电阻式压力传感器,电感式压力传感器,电容式压力传感器等。电容式压力传感器可以是包括至少两个具有导电材料的平行板。当有力作用于压力传感器180A,电极之间的电容改变。电子设备100根据电容的变化确定压力的强度。当有触摸操作作用于显示屏194,电子设备100根据压力传感器180A检测该触摸操作的强度。电子设备100也可以根据压力传感器180A的检测信号计算触摸的位置。在一些实施例中,作用于相同触摸位置,但不同触摸操作强度的触摸操作,可以对应不同的操作指令。例如:当有触摸操作强度小于第一压力阈值的触摸操作作用于短消息应用图标时,执行查看短消息的指令。当有触摸操作强度大于或等于第一压力阈值的触摸操作作用于短消息应用图标时,执行新建短消息的指令。The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. The capacitive pressure sensor can be a parallel plate including at least two conductive materials. When a force acts on the pressure sensor 180A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure according to the change in capacitance. When a touch operation acts on the display screen 194, the electronic device 100 detects the intensity of the touch operation according to the pressure sensor 180A. The electronic device 100 can also calculate the position of the touch according to the detection signal of the pressure sensor 180A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on the short message application icon, an instruction to create a new short message is executed.
加速度传感器180E可检测电子设备100在各个方向上(一般为三轴)加速度的大小。当电子设备100静止时可检测出重力的大小及方向。还可以用于识别电子设备姿态,应用于横竖屏切换,计步器等应用。 The acceleration sensor 180E can detect the magnitude of the acceleration of the electronic device 100 in all directions (generally three axes). When the electronic device 100 is stationary, the magnitude and direction of gravity can be detected. It can also be used to identify the posture of the electronic device and is applied to applications such as horizontal and vertical screen switching and pedometers.
指纹传感器180H用于采集指纹。电子设备100可以利用采集的指纹特性实现指纹解锁,访问应用锁,指纹拍照,指纹接听来电等。The fingerprint sensor 180H is used to collect fingerprints. The electronic device 100 can use the collected fingerprint characteristics to implement fingerprint unlocking, access application locks, fingerprint photography, fingerprint call answering, etc.
触摸传感器180K,也称“触控器件”。触摸传感器180K可以设置于显示屏194,由触摸传感器180K与显示屏194组成触摸屏,也称“触控屏”。触摸传感器180K用于检测作用于其上或附近的触摸操作。触摸传感器可以将检测到的触摸操作传递给应用处理器,以确定触摸事件类型。可以通过显示屏194提供与触摸操作相关的视觉输出。在另一些实施例中,触摸传感器180K也可以设置于电子设备100的表面,与显示屏194所处的位置不同。The touch sensor 180K is also called a "touch control device". The touch sensor 180K can be set on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also called a "touch control screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180K can also be set on the surface of the electronic device 100, which is different from the position of the display screen 194.
按键190包括开机键,音量键等。按键190可以是机械按键。也可以是触摸式按键。电子设备100可以接收按键输入,产生与电子设备100的用户设置以及功能控制有关的键信号输入。The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The electronic device 100 may receive key input and generate key signal input related to user settings and function control of the electronic device 100.
马达191可以产生振动提示。马达191可以用于来电振动提示,也可以用于触摸振动反馈。Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback.
指示器192可以是指示灯,可以用于指示充电状态,电量变化,也可以用于指示消息,未接来电,通知等。The indicator 192 may be an indicator light, which may be used to indicate the charging status, power changes, messages, missed calls, notifications, etc.
SIM卡接口195用于连接SIM卡。SIM卡可以通过插入SIM卡接口195,或从SIM卡接口195拔出,实现和电子设备100的接触和分离。The SIM card interface 195 is used to connect a SIM card. The SIM card can be connected to or disconnected from the electronic device 100 by inserting the SIM card into or removing the SIM card from the SIM card interface 195 .
在说明书对“一个实施例”或“实施例”的引用意指结合实施例所描述的具体特征、结构或特性被包括在根据本申请实施例公开的至少一个范例实施方案或技术中。说明书中的各个地方的短语“在一个实施例中”的出现不一定全部指代同一个实施例。References to "one embodiment" or "an embodiment" in the specification mean that the specific features, structures, or characteristics described in conjunction with the embodiment are included in at least one exemplary implementation or technology disclosed according to the embodiment of the present application. The appearance of the phrase "in one embodiment" in various places in the specification does not necessarily all refer to the same embodiment.
本申请实施例的公开还涉及用于执行文本中的操作装置。该装置可以专门处于所要求的目的而构造或者其可以包括被存储在计算机中的计算机程序选择性地激活或者重新配置的通用计算机。这样的计算机程序可以被存储在计算机可读介质中,诸如,但不限于任何类型的盘,包括软盘、光盘、CD-ROM、磁光盘、只读存储器(ROM)、随机存取存储器(RAM)、EPROM、EEPROM、磁或光卡、专用集成电路(ASIC)或者适于存储电子指令的任何类型的介质,并且每个可以被耦合到计算机系统总线。此外,说明书中所提到的计算机可以包括单个处理器或者可以是采用针对增加的计算能力的多个处理器涉及的架构。The disclosure of the embodiment of the present application also relates to an operating device for executing the text. The device can be specially constructed for the required purpose or it can include a general-purpose computer selectively activated or reconfigured by a computer program stored in the computer. Such a computer program can be stored in a computer-readable medium, such as, but not limited to any type of disk, including a floppy disk, an optical disk, a CD-ROM, a magneto-optical disk, a read-only memory (ROM), a random access memory (RAM), an EPROM, an EEPROM, a magnetic or optical card, an application-specific integrated circuit (ASIC) or any type of medium suitable for storing electronic instructions, and each can be coupled to a computer system bus. In addition, the computer mentioned in the specification may include a single processor or may be an architecture involving multiple processors for increased computing power.
另外,在本说明书所使用的语言已经主要被选择用于可读性和指导性的目的并且可能未被选择为描绘或限制所公开的主题。因此,本申请实施例公开旨在说明而非限制本文所讨论的概念的范围。 In addition, the language used in this specification has been primarily selected for readability and instructional purposes and may not be selected to describe or limit the disclosed subject matter. Therefore, the present application embodiment disclosure is intended to illustrate rather than limit the scope of the concepts discussed herein.

Claims (10)

  1. 一种代码调试方法,应用于电子设备,所述电子设备上运行被调试的程序代码包括第一语言编写的第一代码段,所述第一代码段中包括调用第二语言编写的第二代码段的第一函数调用语句,并且,A code debugging method is applied to an electronic device, wherein a program code to be debugged running on the electronic device includes a first code segment written in a first language, the first code segment includes a first function call statement that calls a second code segment written in a second language, and
    所述方法包括:The method comprises:
    响应于接收到的调试命令,运行所述被调试的程序代码;In response to the received debugging command, running the debugged program code;
    在运行所述程序代码的过程中,检测到通过第一函数调用语句调用所述第二代码段中函数的触发事件;During the execution of the program code, a triggering event of calling a function in the second code segment through a first function call statement is detected;
    基于所述第一函数调用语句与所述第二代码段中被调用的第一函数之间的关联关系,确定所述第一函数的地址满足打断点的触发条件;Determining, based on an association relationship between the first function call statement and the first function called in the second code segment, whether the address of the first function satisfies a breakpoint triggering condition;
    在所述第一函数的地址上打断点。Set a breakpoint at the address of the first function.
  2. 根据权利要求1所述的方法,其特征在于,所述第一函数调用语句与所述第二代码段中被调用的第一函数之间的关联关系,通过以下方式确定:The method according to claim 1, characterized in that the association relationship between the first function call statement and the first function called in the second code segment is determined by:
    在所述第二代码段中定义导出对象,并为所述导出对象定义并初始化第一属性,其中所述第一属性与所述第一代码段中的第一函数调用语句相对应;defining an export object in the second code segment, and defining and initializing a first attribute for the export object, wherein the first attribute corresponds to a first function call statement in the first code segment;
    将所述第二代码段中被调用的所述第一函数设置为所述第一属性的回调函数,建立所述第一属性与所述第一函数之间的关联关系;Setting the first function called in the second code segment as a callback function of the first attribute, and establishing an association relationship between the first attribute and the first function;
    在所述第一代码段中加载所述导出对象的第一属性,确定所述第一函数调用语句与所述第二代码段中被调用的第一函数之间的关联关系。The first attribute of the export object is loaded in the first code segment, and the association relationship between the first function call statement and the first function called in the second code segment is determined.
  3. 根据权利要求2所述的方法,其特征在于,所述满足打断点的触发条件包括:The method according to claim 2, wherein the triggering condition for satisfying the breakpoint includes:
    确定所述第一函数的地址在预先确定的所述第二代码段的地址范围内,其中所述第二代码段的地址范围基于所述电子设备加载的所述程序代码对应的共享库相关属性确定。It is determined that the address of the first function is within a predetermined address range of the second code segment, wherein the address range of the second code segment is determined based on a shared library-related attribute corresponding to the program code loaded by the electronic device.
  4. 根据权利要求3所述的方法,其特征在于,所述电子设备与集成开发环境之间建立有调试会话,所述调试命令为所述集成开发环境响应于用户操作通过所述调试会话向所述电子设备发送的命令,并且,The method according to claim 3 is characterized in that a debugging session is established between the electronic device and the integrated development environment, the debugging command is a command sent by the integrated development environment to the electronic device through the debugging session in response to a user operation, and
    所述检测到通过第一函数调用语句调用所述第二代码段中函数的触发事件,包括:The detecting a triggering event of calling a function in the second code segment through a first function calling statement comprises:
    所述电子设备向所述集成开发环境上报检测到的所述触发事件,并暂停执行用于运行所述程序代码的线程。The electronic device reports the detected trigger event to the integrated development environment and suspends execution of a thread for running the program code.
  5. 根据权利要求4所述的方法,其特征在于,所述集成开发环境基于所述电子设备通过加载完成事件向所述集成开发环境上报的共享库相关属性确定所述第二代码段的地址范围,并且,The method according to claim 4, characterized in that the integrated development environment determines the address range of the second code segment based on the shared library related attributes reported by the electronic device to the integrated development environment through the loading completion event, and
    所述在所述第一函数的地址上打断点,包括:Setting a breakpoint at the address of the first function includes:
    所述集成开发环境基于接收到的所述触发事件,确定所述第一函数的地址;The integrated development environment determines the address of the first function based on the received trigger event;
    所述集成开发环境判断所述第一函数的地址在所述第二代码段的地址范围内,生成向所述电子设备发送的断点设置命令,所述断点设置命令用于指示所述电子设备在所述第一函数的地址上打断点;The integrated development environment determines that the address of the first function is within the address range of the second code segment, and generates a breakpoint setting command to be sent to the electronic device, wherein the breakpoint setting command is used to instruct the electronic device to set a breakpoint at the address of the first function;
    所述电子设备响应于接收到的所述断点设置命令,在所述第一函数的地址上打断点。The electronic device sets a breakpoint at the address of the first function in response to the received breakpoint setting command.
  6. 根据权利要求5所述的方法,其特征在于,所述在所述第一函数的地址上打断点,包括:The method according to claim 5, characterized in that setting a breakpoint at the address of the first function comprises:
    所述集成开发环境将确定的所述第二代码段的地址范围发送给所述电子设备;The integrated development environment sends the determined address range of the second code segment to the electronic device;
    所述电子设备判断所述第一函数的地址在所述第二代码段的地址范围内,向所述集成开发环境上报所述第一函数的地址;The electronic device determines that the address of the first function is within the address range of the second code segment, and reports the address of the first function to the integrated development environment;
    所述集成开发环境基于所述第一函数的地址,生成向所述电子设备发送的断点设置命令;The integrated development environment generates a breakpoint setting command to be sent to the electronic device based on the address of the first function;
    所述电子设备响应于接收到的所述断点设置命令,在所述第一函数的地址上打断点。In response to the received breakpoint setting command, the electronic device sets a breakpoint at the address of the first function.
  7. 根据权利要求4至6中任一项所述的方法,其特征在于,在所述第一函数的地址上打断点之后,所述方法还包括;The method according to any one of claims 4 to 6, characterized in that, after setting a breakpoint on the address of the first function, the method further comprises:
    接收到所述集成开发环境发送的恢复线程执行的命令;receiving a command for resuming thread execution sent by the integrated development environment;
    响应于所述恢复线程执行的命令,恢复运行所述程序代码的线程的执行。In response to the command to resume thread execution, execution of the thread running the program code is resumed.
  8. 根据权利要求1至7中任一项所述的方法,其特征在于,在恢复运行所述程序代码的线程的执行之后,所述方法还包括;The method according to any one of claims 1 to 7, characterized in that after resuming execution of the thread running the program code, the method further comprises:
    检测到所述线程运行至所述第一函数命中所述断点,控制所述线程停在所述第一函数在所述第二代码段中的函数入口处。 It is detected that the thread runs to the first function and hits the breakpoint, and the thread is controlled to stop at the function entry of the first function in the second code segment.
  9. 一种电子设备,其特征在于,包括:一个或多个处理器;一个或多个存储器;所述一个或多个存储器存储有一个或多个程序,当所述一个或者多个程序被所述一个或多个处理器执行时,使得所述电子设备执行权利要求1至8中任一项所述的代码调试方法。An electronic device, characterized in that it comprises: one or more processors; one or more memories; the one or more memories store one or more programs, and when the one or more programs are executed by the one or more processors, the electronic device executes the code debugging method described in any one of claims 1 to 8.
  10. 一种计算机可读存储介质,其特征在于,所述存储介质上存储有指令,所述指令在计算机上执行时使所述计算机执行权利要求1至8中任一项所述的代码调试方法。 A computer-readable storage medium, characterized in that instructions are stored on the storage medium, and when the instructions are executed on a computer, the computer executes the code debugging method according to any one of claims 1 to 8.
PCT/CN2023/123606 2022-10-25 2023-10-09 Code debugging method, electronic device, and computer readable storage medium WO2024088053A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202211313299.7 2022-10-25
CN202211313299.7A CN117971635A (en) 2022-10-25 2022-10-25 Code debugging method, electronic device and computer readable storage medium

Publications (1)

Publication Number Publication Date
WO2024088053A1 true WO2024088053A1 (en) 2024-05-02

Family

ID=90829996

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/123606 WO2024088053A1 (en) 2022-10-25 2023-10-09 Code debugging method, electronic device, and computer readable storage medium

Country Status (2)

Country Link
CN (1) CN117971635A (en)
WO (1) WO2024088053A1 (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040230955A1 (en) * 2003-02-26 2004-11-18 Bea Systems, Inc. System for multi-language debugging
CN111176626A (en) * 2019-08-05 2020-05-19 腾讯科技(深圳)有限公司 Cross-programming-language code calling method and device, medium and equipment
CN113407160A (en) * 2021-05-17 2021-09-17 江苏航天七零六信息科技有限公司 Multi-language debugger design method oriented to domestic operating system and hardware platform
CN114356779A (en) * 2021-05-06 2022-04-15 深圳希施玛数据科技有限公司 Programming language debugging method and device and terminal equipment
CN115114142A (en) * 2021-03-19 2022-09-27 华为技术有限公司 Multi-language hybrid debugging method and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040230955A1 (en) * 2003-02-26 2004-11-18 Bea Systems, Inc. System for multi-language debugging
CN111176626A (en) * 2019-08-05 2020-05-19 腾讯科技(深圳)有限公司 Cross-programming-language code calling method and device, medium and equipment
CN115114142A (en) * 2021-03-19 2022-09-27 华为技术有限公司 Multi-language hybrid debugging method and device
CN114356779A (en) * 2021-05-06 2022-04-15 深圳希施玛数据科技有限公司 Programming language debugging method and device and terminal equipment
CN113407160A (en) * 2021-05-17 2021-09-17 江苏航天七零六信息科技有限公司 Multi-language debugger design method oriented to domestic operating system and hardware platform

Also Published As

Publication number Publication date
CN117971635A (en) 2024-05-03

Similar Documents

Publication Publication Date Title
CN107276789B (en) Log uploading method and device and computer readable storage medium
EP3402160B1 (en) Service processing method and apparatus
CN108182131B (en) Method and device for monitoring application running state, storage medium and electronic equipment
CN111191224B (en) Countermeasure method and device for virtual machine detection and computer readable storage medium
WO2018077041A1 (en) Method and apparatus for running application
CN109308241B (en) Method and device for monitoring starting process of application program, terminal equipment and storage medium
EP3614250A1 (en) Data processing method and electronic device
WO2013159632A1 (en) Method, firewall, terminal and readable storage medium for implementing security protection
CN110837473A (en) Application program debugging method, device, terminal and storage medium
CN110225048B (en) Data transmission method and device, first terminal and storage medium
CN111723002A (en) Code debugging method and device, electronic equipment and storage medium
CN108090345B (en) Linux system external command execution method and device
WO2021027772A1 (en) Method for switching running of application and device
CN110046497B (en) Function hook realization method, device and storage medium
CN111209122A (en) Interface calling method and device, electronic equipment and storage medium
CN108984259B (en) Interface display method and device and terminal
CN116431044A (en) Method and device for starting application program and terminal equipment
CN107861827B (en) Card screen detection method, mobile terminal and computer readable storage medium
EP4024208A1 (en) Method for launching quick application, and related device
CN112363950A (en) Application program debugging method and device
WO2024088053A1 (en) Code debugging method, electronic device, and computer readable storage medium
CN109145598B (en) Virus detection method and device for script file, terminal and storage medium
CN108132817B (en) Object management method and device
CN111897726B (en) Abnormality positioning method, abnormality positioning device, storage medium and mobile terminal
CN110569037B (en) Data writing method and device