WO2012106871A1 - 一种操作系统内核调试方法和虚拟调试服务模块 - Google Patents

一种操作系统内核调试方法和虚拟调试服务模块 Download PDF

Info

Publication number
WO2012106871A1
WO2012106871A1 PCT/CN2011/076910 CN2011076910W WO2012106871A1 WO 2012106871 A1 WO2012106871 A1 WO 2012106871A1 CN 2011076910 W CN2011076910 W CN 2011076910W WO 2012106871 A1 WO2012106871 A1 WO 2012106871A1
Authority
WO
WIPO (PCT)
Prior art keywords
operating system
breakpoint
debugging
debugged
virtual
Prior art date
Application number
PCT/CN2011/076910
Other languages
English (en)
French (fr)
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 华为技术有限公司
Priority to PCT/CN2011/076910 priority Critical patent/WO2012106871A1/zh
Priority to CN2011800016502A priority patent/CN102301344B/zh
Publication of WO2012106871A1 publication Critical patent/WO2012106871A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging

Definitions

  • the present invention relates to the field of operating systems, and in particular, to a virtualized operating system kernel debugging method and a virtual debugging service module.
  • Kernel debugging has always been a technical bottleneck in the development of operating system kernels.
  • the existing Linux system kernel debugging methods include KDB, kprobe, pintk, KGDB, etc. Most of these kernel debugging methods need to put a specific patch (patch) into the Linux system kernel to debug, and this debugging method is equivalent to The operating system debugs itself, so it can only support the debugging functions of the single-sheet, such as viewing the kernel data structure, printing the scene information, etc., and cannot implement advanced debugging functions such as single-step debugging and setting endpoints.
  • GDB debugging can provide some advanced debugging features, it must be debugged by two hosts.
  • the embodiment of the invention provides an operating system kernel debugging method and a virtual debugging service module, so as to solve the problem that the debugging means is single and the number of hosts required for debugging is large.
  • An embodiment of the present invention provides a debugging method of an operating system kernel, where a main control operating system and a debugged operating system are run on a virtual machine, and the method includes:
  • the virtual debugging service module receives a breakpoint insertion request inserted by the debugging module in the main control operating system and inserts at least one breakpoint, where the breakpoint insertion request includes location information of the insertion breakpoint;
  • the virtual debug service module inserts a breakpoint at a corresponding position in the debugged operating system according to the position information of the inserted breakpoint in the breakpoint insertion request, and records the position of the inserted breakpoint in the debug breakpoint information table;
  • the virtual debug service module captures a breakpoint exception triggered during execution of the debugged operating system, and compares the captured feature of the breakpoint exception with the location of the breakpoint recorded in the debug breakpoint information table. If it matches, the pause is Debug the operation of the operating system.
  • Another aspect of the present invention further provides a virtual debugging service module, which is built in a virtual machine, where the virtual operating machine runs a main control operating system and a debugged operating system, and the virtual debugging service module includes: a breakpoint insertion request receiving unit, configured to receive a breakpoint insertion request inserted by the debugging module in the main control operating system and inserting at least one breakpoint, where the breakpoint insertion request includes a location letter of inserting a breakpoint
  • a breakpoint insertion unit configured to insert a breakpoint at a corresponding position in the debugged operating system according to the position information of the inserted breakpoint in the breakpoint insertion request, and record the position of the inserted breakpoint in the debug breakpoint information table ;
  • a breakpoint exception capture unit is configured to capture a breakpoint exception triggered during execution of the debugged operating system
  • a feature comparison unit configured to compare the captured feature of the breakpoint exception with a position of the breakpoint recorded in the debug breakpoint information table, and if the match is successful, trigger the pause unit to work; the pause unit is used to trigger The debugged operating system is suspended.
  • a virtual debugging module is implemented in the virtual machine, and the virtual debugging module can implement the debugging of the breakpoint of the debugged operating system, and optionally, the single-step debugging can be implemented, and the debugging method is more. Moreover, the embodiment of the present invention only needs one host to complete in the process of debugging.
  • FIG. 1 is a schematic flowchart of a debugging method of an operating system kernel according to an embodiment of the present invention
  • FIG. 2 is a system hierarchy diagram based on a debugging method of an operating system kernel in Embodiment 1 of the present invention
  • FIG. 3 is a schematic flowchart of a debugging method of an operating system kernel according to Embodiment 1 of the present invention
  • FIG. 4 is a schematic flowchart of a debugging method of an operating system kernel according to Embodiment 2 of the present invention
  • FIG. Schematic diagram of the debugging service module is a schematic flowchart of a debugging method of an operating system kernel according to Embodiment 1 of the present invention.
  • a virtual debugging service (vir_gdbServer) module is implemented in a virtual machine running between a hardware entity and an operating system, and the virtual machine can realize hardware sharing through virtualization, and simultaneously run multiple operating systems on one set of hardware.
  • the operating system and the debugged operating system are mastered, and the main control operating system interacts with the client, and is an operating system responsible for debugging.
  • the virtual debug service module can communicate with a debug module (such as gdb) in the master operating system for real Now the debugging commands of the module are debugged.
  • the debugging module in the main control operating system interacts with the virtual debugging service module by using a general debugging protocol (for example: gdb serial protocol, or encryption protocol to provide security).
  • a general debugging protocol for example: gdb serial protocol, or encryption protocol to provide security.
  • an embodiment of the present invention provides a debugging method of an operating system kernel. As shown in FIG. 1, the method includes:
  • Step S101 The virtual debugging service module receives a breakpoint insertion request sent by the debugging module in the main control operating system, where the breakpoint insertion request includes location information for requesting insertion of a breakpoint.
  • a breakpoint insertion request can be sent to the debug module through the master operating system, and the breakpoint insertion request contains the location information of each breakpoint that the user wants to insert.
  • Step S102 The virtual debugging service module inserts a breakpoint at a corresponding position in the debugged operating system according to the position information of the inserted breakpoint in the breakpoint insertion request, and records the position of the inserted breakpoint in the debug breakpoint information table. .
  • the debugged operating system can be run.
  • a breakpoint exception is triggered.
  • the breakpoint exception may be caused by executing the breakpoint inserted for debugging in step S102, or may be executed. Generated by other interrupts defined by the operating system itself.
  • Step S103 The virtual debugging service module captures a breakpoint exception triggered during execution of the debugged operating system.
  • Step S104 The virtual debug service module compares the captured feature of the breakpoint exception with the location of the breakpoint recorded in the debug breakpoint information table, and if it matches, suspends the operation of the debugged operating system.
  • the reason why the captured breakpoint exception is compared with the breakpoint position in the debug breakpoint information table is because, as described above, the captured breakpoint exception may be due to execution for debugging in step S102.
  • the breakpoint is generated, or may be generated by other interrupts defined by the operating system itself, but the embodiment of the present invention only needs to perform subsequent processing on the abnormality caused by executing the breakpoint for debugging, and is generated for other reasons.
  • the breakpoint exception is not processed; therefore, after the breakpoint exception is caught, its feature needs to be compared with the breakpoint position in the debug breakpoint information table. If it matches, the breakpoint exception is the debugged operating system. Executed after the breakpoint inserted before.
  • the characteristics of the above-mentioned breakpoint abnormality include the address at which the abnormality occurs.
  • the feature of the breakpoint anomaly may also include an anomaly vector.
  • the breakpoint exception is because the execution of the breakpoint for debugging inserted in step S102 is performed, and the exception vector should be the same one. The value is fixed, so in the present invention, it is also possible to simultaneously verify whether the exception vector is equal to the interrupt vector that should be generated by the debug operating system when performing a breakpoint to user debugging.
  • step S105 may be further included: after suspending operation of the debugged operating system, the virtual debug service module receives a lookup request sent by the debug module in the main control operating system to consult status information of the debugged operating system;
  • Step S106 The virtual debugging service module feeds back the status information in the debugged operating system to the debugging module in the main operating system according to the referral request in step S105.
  • the above status information may include one or any combination of information in a register of the debugged operating system, information in the stack, and global variables.
  • the above method implements a virtual debugging service module in the virtual machine, which can easily implement breakpoint debugging of the debugged operating system.
  • Fig. 2 shows a hierarchical structure diagram on which the present embodiment is based.
  • GOS1 is the master operating system and GOS2 is the debugged operating system.
  • GOS1 and GOS2 run together on the same virtual machine.
  • a virtual debug service module ( vir_gdbserver ) is built into the virtual machine.
  • gdb debugging module
  • gdb communicates with vir_gdbserver.
  • a virtual device Virtual device
  • the debug module gdb in the master operating system GOS1 communicates with the virtual debug service module vir_gdbserver in the virtual machine through the virtual device.
  • the debugging method of the operating system kernel includes the following steps: Step S301: gdb in GOS1 sends a breakpoint insertion request through a virtual debugging service module vir_gdbserver module in the virtual device virtual machine, requesting to A breakpoint for debugging is inserted in the debug operating system GOS2.
  • Step S302 After receiving the breakpoint insertion request, the vir_gdbserver module inserts a breakpoint into the corresponding position in the GOS2 according to the position information of the inserted breakpoint included therein, and records the position of the inserted breakpoint in the debug breakpoint information table. in.
  • the specific implementation of inserting a breakpoint can be to write a breakpoint instruction to the location where the breakpoint is to be inserted.
  • INT 3 which is 0xCC.
  • the debug breakpoint information table can be stored in the form of a linked list.
  • Step S303 Running GOS2, during the running process, GOS2 will trigger a breakpoint exception.
  • Step S304 The vir_gdbserver module captures a breakpoint exception triggered during the running of the GOS2, and compares the feature of the breakpoint exception with the breakpoint position in the debug breakpoint information table. If the match is successful, the breakpoint exception is GOS2 execution. If it is triggered after the breakpoint inserted for debugging before, the operation of GOS2 is suspended. If it does not match, no processing is done, and the subsequent breakpoint exceptions are continuously captured by the vir_gdbserver module.
  • the vir_gdbserver module can feed back the status information in GOS2 to gdb in GOS1 according to the lookup request sent by GOS1.
  • the status information here can be
  • the virtual debug service module (vir_gdbserver module) further receives a request from the host operating system to construct a debug environment, and the virtual debug service module constructs an operating environment of the debugged operating system according to the request.
  • the user can simulate the debugging process of the debugged operating system in various extreme operating environments. For example, when the user knows the condition of the fault, but does not know why the condition will occur, that is, the condition is completely random and uncontrollable, the environment that satisfies the condition can be artificially constructed to achieve the fault input. The purpose is to provide a basis for debugging to further overcome this fault.
  • the build debug environment here can be done before the debugged operating system runs, or it can be run when the debugged operating system runs to a breakpoint and is suspended.
  • the communication process between the gdb and the vir_gdbserver module in the above GOS1 is preferably performed by using a key to enhance the security of the system.
  • a virtual debugging service module is implemented in the virtual machine, which can easily implement breakpoint debugging of the debugged operating system, and can also implement single-step execution through breakpoint debugging. Debugging.
  • FIG. 4 is a schematic diagram showing a debugging method of the operating system kernel provided in this embodiment. As shown in FIG. 4, the method includes the following steps:
  • Step S401 When it is necessary to perform single-step debugging, determine whether the hardware supports single-step execution. If the decision result in the step S401 is YES, the step S402 is performed, otherwise the step S40X is executed.
  • Step S402 The gdb in the GOS1 sends a control command to the vir_gdb server module in the virtual machine, and requests the debug operating system GOS2 to be placed in the single-step execution mode.
  • Step S403 When the GOS2 is running, the vir_gdbserver module will run the CPU of the GOS2.
  • the flag bit in EFLAGS for controlling the step-by-step execution of the debug mode switch is set to indicate "on" state, so that GOS2 generates a single step exception after each step.
  • the flag bit used to control the single-step execution of the debug mode switch can be the TF flag bit in the flag register EFLAGS.
  • the TF flag bit When the value of the TF flag bit is set to "1", the single-step execution debug mode of the CPU is turned on, and the TF flag bit is set. When the value is set to "0", it means that the single-step execution debugging mode of the CPU is turned off.
  • Step S404 When the GOS2 is running, each time an instruction is executed, a single-step exception is generated.
  • the vir_gdbserver module may feed back the status information in GOS2 to gdb in GOS1 according to the lookup request sent by GOS1, where the status information may be information in each register in GOS2, stack information. Any one or any combination of global variables.
  • step S401 If the result of the determination in step S401 is NO, it indicates that the hardware does not support single-step debugging, and step S406 is directly performed.
  • Step S406 The debug module gdb in the GOS1 sends a breakpoint insertion request to the vir_gdb server module to insert a breakpoint at each step of the GOS2 execution, and performs subsequent steps.
  • Step S407 After receiving the breakpoint insertion request, the vir_gdbserver module according to the included Insert the position information of the breakpoint, insert a breakpoint after each step in GOS2, and record the position of the inserted breakpoint in the debug breakpoint information table.
  • the specific implementation of inserting a breakpoint may be to write a breakpoint instruction INT 3, ie 0xCC, to the location where the breakpoint is to be inserted.
  • debug breakpoint information table described above may be stored in the form of a linked list.
  • Step S408 Running GOS2, during the running process, a breakpoint exception is triggered every time one step is executed.
  • the vir_gdbserver module may feed back the status information in GOS2 to gdb in GOS1 according to the lookup request sent by GOS1, where the status information may be information in each register in GOS2, stack information. Any one or any combination of global variables.
  • the virtual debug service module (vir_gdbserver module) further receives a request from the host operating system to construct a debug environment, and the virtual debug service module constructs an operating environment of the debugged operating system according to the request.
  • the user can simulate the debugging process of the debugged operating system in various extreme operating environments. For example, when the user knows the condition of the fault, but does not know why the condition will occur, that is, the condition is completely random and uncontrollable, the environment that satisfies the condition can be artificially constructed to achieve the fault input. The purpose is to provide a basis for debugging to further overcome this fault.
  • the build debug environment here can be done before the debugged operating system runs, or it can be run when the debugged operating system runs to a breakpoint and is suspended.
  • the communication process between the gdb and the vir_gdbserver module in the above GOS1 is preferably performed by using a key to enhance the security of the system.
  • a virtual debugging service module is implemented in the virtual machine, which can easily implement breakpoint debugging of the debugged operating system and single-step debugging.
  • Another embodiment of the present invention further provides a virtual debugging service module, and the virtual debugging service module The block is built in a virtual machine, and the virtual operating machine runs the main operating system and the debugged operating system.
  • the virtual debugging service module 50 includes a breakpoint insertion request receiving unit 501, a breakpoint insertion unit 502, and a break. Point exception capture unit 503, feature comparison unit 504, and pause unit 505.
  • the breakpoint insertion request receiving unit 501 is configured to receive a breakpoint insertion request for inserting at least one breakpoint sent by the debug module in the main control operating system, where the breakpoint insertion request includes location information of the inserted breakpoint.
  • the breakpoint insertion unit 502 is configured to insert a breakpoint at a corresponding position in the debugged operating system according to the position information of the inserted breakpoint in the breakpoint insertion request, and record the position of the inserted breakpoint in the debug breakpoint information table. .
  • the breakpoint exception capture unit 503 is used to capture a breakpoint exception triggered during execution of the debugged operating system.
  • the feature comparison unit 504 is configured to compare the feature of the captured breakpoint exception with the position of the breakpoint recorded in the debug breakpoint information table, and if the match is successful, trigger the pause unit 505 to operate.
  • the suspending unit 505 is used to trigger the suspended operating system to be suspended.
  • the virtual debugging service module may further include: a single-step execution support determining unit 506, configured to pre-determine whether the hardware supports single-step execution when the single-step debugging is required;
  • the step-by-step breakpoint insertion unit 507 is configured to notify the debug module in the master operating system to send the virtual debug service module to each step executed by the debugged operating system when the single-step execution support determination unit 506 determines that the result is no. Point breakpoint insertion request.
  • the above virtual debugging service module may further include:
  • the flag setting unit 508 is configured to, when the single-step execution support determination unit determines that the result is YES, when the debugged operating system is running, use the flag register of the central processor that runs the debugged operating system to control the single step execution.
  • the flag of the debug mode switch is set to indicate "on" state, so that the debugged operating system generates a single-step exception after each step of operation.
  • the single-step exception capture unit 509 is configured to capture a single-step exception generated by the debugged operating system after each step of running, and when the virtual debug service module confirms that the current step of the debugged operating system is executed, triggering the suspending unit 505 to perform jobs.
  • the method further includes a checking unit 506, configured to receive, after the running of the debugged operating system, the sending of the debugging module in the main operating system. Reviewing the lookup request of the status information of the debugged operating system, and feeding back the status information of the debugged operating system to the debugging in the main control operating system according to the referral request.
  • the module, the status information of the debugged operating system herein may include any one or any combination of information in the registers of the debugged operating system, information in the stack, and global variables.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

一种操作系统内核的调试方法和虚拟调试服务模块,该方法包括:虚拟调试服务模块接收主控操作系统中的调试模块发送的插入至少一个断点的断点插入请求,断点插入请求中包括插入断点的位置信息;虚拟调试服务模块根据断点插入请求中的插入断点的位置信息,在被调试操作系统中的相应位置处插入断点,并将插入断点的位置记录在调试断点信息表中;虚拟调试服务模块捕获被调试操作系统执行过程中触发的断点异常,并将捕获到的断点异常的特征与调试断点信息表中记录的断点的位置进行比较,如果匹配,则暂停被调试操作系统的运行。

Description

一种操作系统内核调试方法和虚拟调试服务模块 技术领域
本发明涉及操作系统领域,尤其涉及一种基于虚拟化的操作系统内核调试 方法和虚拟调试服务模块。
背景技术
一直以来,内核调试都是操作系统内核开发的一个技术瓶颈。现有的 Linux 系统内核调试手段包括 KDB、 kprobe, pintk、 KGDB等, 这些内核调试手段 中大多需要给 Linux系统内核植入特定的补丁( Patch )才能进行调试, 而且而 且这种调试方式相当于在操作系统调试自身, 因此只能支持艮筒单的调试功 能, 例如查看内核数据结构、 打印现场信息等, 无法实现单步调试和设置端点 等高级调试功能。 虽然 GDB调试手段可以提供一些高级的调试的功能, 但是 必须由两台主机才能完成调试。
发明内容
本发明实施例提供一种操作系统内核调试方法和虚拟调试服务模块,以解 决调试手段单一、 调试所需的主机数量多的问题。
本发明实施例一方面提供一种操作系统内核的调试方法,虚拟机上运行主 控操作系统和被调试操作系统, 该方法包括:
虚拟调试服务模块接收主控操作系统中的调试模块发送的插入至少一个 断点的断点插入请求, 所述断点插入请求中包括插入断点的位置信息;
虚拟调试服务模块根据断点插入请求中的插入断点的位置信息,在被调试 操作系统中的相应位置处插入断点,并将插入断点的位置记录在调试断点信息 表中;
虚拟调试服务模块捕获被调试操作系统执行过程中触发的断点异常,并将 捕获到的断点异常的特征与调试断点信息表中记录的断点的位置进行比较,如 果匹配, 则暂停被调试操作系统的运行。
本发明另一方面还提供一种虚拟调试服务模块, 其构建在虚拟机中, 所述 虚拟机上运行主控操作系统和被调试操作系统, 该虚拟调试服务模块包括: 断点插入请求接收单元,用于接收主控操作系统中的调试模块发送的插入 至少一个断点的断点插入请求, 所述断点插入请求中包括插入断点的位置信
断点插入单元, 用于根据断点插入请求中的插入断点的位置信息, 在被调 试操作系统中的相应位置处插入断点,并将插入断点的位置记录在调试断点信 息表中;
断点异常捕获单元, 用于捕获被调试操作系统执行过程中触发的断点异 常;
特征比较单元,用于将所述捕获到的断点异常的特征与调试断点信息表中 记录的断点的位置进行比较, 如果匹配成功, 则触发暂停单元进行工作; 暂停单元, 用于触发被调试操作系统暂停运行。
本发明实施例中在虚拟机中实现一个虚拟调试模块,借助该虚拟调试模块 可以实现对被调试操作系统的断点调试, 可选地还可以实现单步执行调试,调 试的手段更多。而且本发明实施例在进行调试的过程中只需要一台主机即可完 成。
附图说明
图 1是本发明实施例提供的操作系统内核的调试方法的流程示意图; 图 2是本发明实施例一中的操作系统内核的调试方法所基于的系统层次 架构图;
图 3是本发明实施例一提供的操作系统内核的调试方法的流程示意图; 图 4是本发明实施例二提供的操作系统内核的调试方法的流程示意图; 图 5是本发明实施例提供的虚拟调试服务模块的结构示意图。
具体实施方式
本发明实施例在运行在硬件实体和操作系统之间的虚拟机中实现了一个 虚拟调试服务( vir_gdbServer )模块, 虚拟机通过虚拟化可以实现硬件共享, 在一套硬件上同时运行多个操作系统,在本发明实施例中主控操作系统和被调 试操作系统, 主控操作系统与客户进行交互, 是负责调试的操作系统。 虚拟调 试服务模块可以与主控操作系统中的调试模块(例如 gdb )进行通信, 用于实 现调试模块的控制命令,主控操作系统中的调试模块利用通用调试协议(例如: gdb串行协议、 或加密协议提供安全性)通过虚拟调试服务模块进行交互。
基于上述架构, 本发明的一个实施例提供一种操作系统内核的调试方法, 如图 1所示, 该方法包括:
步骤 S101 : 虚拟调试服务模块接收主控操作系统中的调试模块发送的断 点插入请求, 该断点插入请求中包括请求插入断点的位置信息。
当用户想要在被调试操作系统中插入断点时,可以通过主控操作系统向调 试模块发送断点插入请求,该断点插入请求中包含了用户想要插入的各个断点 的位置信息。
步骤 S102: 虚拟调试服务模块根据断点插入请求中的插入断点的位置信 息,在被调试操作系统中的相应位置处插入断点, 并将插入断点的位置记录在 调试断点信息表中。
而后可以运行被调试操作系统,当被调试操作系统在运行过程中会触发断 点异常, 该断点异常可能是因为执行到步骤 S102中插入的用于调试的断点产 生的, 也可能是执行到操作系统本身定义的其他中断产生的。
步骤 S103: 虚拟调试服务模块捕获被调试操作系统执行过程中触发的断 点异常。
步骤 S104: 虚拟调试服务模块将捕获到的断点异常的特征与调试断点信 息表中记录的断点位置进行比较, 如果匹配则暂停被调试操作系统的运行。
之所以要将捕获到的断点异常与调试断点信息表中的断点位置进行比较, 是因为正如前文所述, 捕获到的断点异常可能是因为执行到步骤 S102中插入 的用于调试的断点产生的,也可能是执行到操作系统本身定义的其他中断产生 的,而本发明实施例只需要对因执行到用于调试的断点而发生的异常进行后续 处理, 对于其他原因产生的断点异常不做处理; 所以, 在捕获到断点异常后, 还需将其特征与调试断点信息表中的断点位置进行比较,如果匹配,说明该断 点异常是被调试操作系统执行到之前插入的断点后产生的。
上述断点异常的特征包括发生异常的地址。此外,为了增强比较的严谨性, 断点异常的特征中还可以包括异常向量。 对于断点异常是因为执行到步骤 S102 中插入的用于调试的断点产生的情况, 该异常向量应该是相同的一个特 定值,所以本发明中还可以同时验证该异常向量是否等于执行到用户调试的断 点时被调试操作系统应该产生的中断向量。
此外, 还可以包括步骤 S105: 在暂停被调试操作系统的运行以后, 虚拟 调试服务模块接收主控操作系统中的调试模块发送的查阅被调试操作系统的 状态信息的查阅请求;
步骤 S106: 虚拟调试服务模块根据步骤 S105中的查阅请求, 将被调试操 作系统中的状态信息反馈至主控操作系统中的调试模块。
上述状态信息可以包括被调试操作系统的寄存器中的信息、堆栈中的信息 和全局变量其中的一个或者任意组合。
由此可见, 上述方法在虚拟机中实现了一个虚拟调试服务模块, 可以轻松 实现被调试操作系统的断点调试。
实施例一
图 2示出了本实施例所基于的层次架构图。 如图 2所示, GOS1为主控操 作系统, GOS2为被调试操作系统。 GOS1和 GOS2共同运行在同一个虚拟机 上。 在虚拟机中构建了一个虚拟调试服务模块( vir_gdbserver )。 在 GOSl中具 有调试模块(gdb ), gdb与 vir_gdbserver进行通信, 在实际中, 为了使得上层 的调试功能不依赖于底层的虚拟机的实现方式,在虚拟机中还构建一个虚拟设 备(Virtual device ), 主控操作系统 GOS1中的调试模块 gdb通过该虚拟设备 与虚拟机中的虚拟调试服务模块 vir_gdbserver进行通信。
如图 3所示, 本实施例中提供的操作系统内核的调试方法包括如下步骤: 步骤 S301 : GOS1 中的 gdb通过虚拟设备虚拟机中的虚拟调试服务模块 vir_gdbserver模块发送断点插入请求,请求向被调试操作系统 GOS2中插入用 于调试的断点。
步骤 S302: vir_gdbserver模块接收到该断点插入请求后,根据其中包含的 插入断点的位置信息, 向 GOS2中的相应位置处插入断点, 并将插入断点的位 置记录在调试断点信息表中。
插入断点的具体实现方式可以是向要插入断点的位置处写入断点指令 INT 3, 即 0xCC。
在实际中, 该调试断点信息表可以以链表的形式进行存储。
步骤 S303: 运行 GOS2, 运行过程中, GOS2会触发断点异常。
步骤 S304: vir_gdbserver模块捕获 GOS2运行过程中触发的断点异常,并 将该断点异常的特征与调试断点信息表中的断点位置进行比较, 如果匹配成 功,说明该断点异常是 GOS2执行到之前插入的用于调试的断点后触发的, 则 暂停 GOS2的运行。 如果不能匹配, 则不做任何处理, 由 vir_gdbserver模块继 续捕获后续的断点异常。
在暂停 GOS2的运行以后, vir_gdbserver模块可以根据 GOS1发送的查阅 请求, 将 GOS2中的状态信息反馈至 GOS1中的 gdb, 这里的状态信息可以是
GOS2中的各个寄存器内的信息、 堆栈信息和全局变量中的任意一个或者任意 组合。 只需要通过 GOS1向 vir_gdbserver模块发送请求在 GOS2执行的每一步后都插 入断点的请求即可, 这时, 在 GOS2运行过程中, 每执行完一步就触发一次断 点异常, 然后暂停 GOS2的运行, 供用户进行单步执行的断点调试。
此外, 在一个优选的实施例中, 虚拟调试服务模块(vir_gdbserver模块) 还接收主控操作系统请求构造调试环境的请求, 虚拟调试服务模块根据该请 求, 构造被调试操作系统的运行环境。 利用该手段, 用户可以模拟被调试操作 系统在各种极端运行环境下的调试过程。 例如, 当用户知道出现故障的条件, 但是不知道为什么该条件会出现,也就是说该条件的出现完全是随机的不可控 的, 此时可以将满足该条件的环境通过人为构造, 达到故障输入的目的, 为进 一步克服该故障提供调试的基础。这里构造调试环境可以是在被调试操作系统 运行之前进行,也可以是在被调试操作系统运行到断点时被暂停运行的时候进 行。
另夕卜,上述 GOS1中的 gdb与 vir_gdbserver模块之间的通信过程优选采用 密钥来完成, 以增强系统的安全性。
由此可见, 本实施例中在虚拟机中实现了一个虚拟调试服务模块, 可以轻 松实现被调试操作系统的断点调试,还可以通过断点调试的方式实现单步执行 调试。
实施例二
本实施例仍然基于图 中的层次架构图。本实施例中提供的操作系统内核 的调试方法用来完成单步执行调试的目的。图 4示出了本实施例提供的操作系 统内核的调试方法的示意图, 如图 4所示, 该方法包括如下步骤:
步骤 S401: 当需要进行单步执行调试时, 判断硬件是否支持单步执行。 如果步骤 S401的判断结果为是时,则执行步骤 S402,否则执行步骤 S40X。 步骤 S402: GOS1中的 gdb向虚拟机中的 vir_gdb server模块发送控制命令, 要求将被调试操作系统 GOS2置于单步执行模式。
步骤 S403: 当 GOS2运行时, vir_gdbserver模块将运行该 GOS2的 CPU
(中央处理器) 中的标志寄存器 EFLAGS 中的用于控制单步执行调试模式开 关的标志位设置为表示 "开启" 的状态, 以使 GOS2在运行每一步后都产生单 步异常。
这里的用于控制单步执行调试模式开关的标志位可以为标志寄存器 EFLAGS中的 TF标志位, TF标志位的值设为 "1"时表示开启 CPU的单步执 行调试模式, TF标志位的值设为 "0" 时表示关闭 CPU的单步执行调试模式。
步骤 S404: GOS2在运行时,每执行完一条指令,就会产生一个单步异常。 步骤 S405: vir_gdbserver模块捕获到 GOS2运行过程中产生的单步异常, 当确认 GOS2运行的当前步(或者说当前运行的一条指令)执行完毕后, 暂停 GOS2的运行。
在步骤 S405中暂停 GOS2的运行以后, vir_gdbserver模块可以根据 GOS1 发送的查阅请求, 将 GOS2中的状态信息反馈至 GOS1中的 gdb, 这里的状态 信息可以是 GOS2中的各个寄存器内的信息、堆栈信息和全局变量中的任意一 个或者任意组合。
如果步骤 S401的判断结果为否时, 表明硬件不支持单步执行调试, 则直 接执行步骤 S406。
步骤 S406: GOS1 中的调试模块 gdb向 vir_gdb server模块发送在 GOS2 执行每一步均插入断点的断点插入请求, 并执行后续步骤。
步骤 S407: vir_gdbserver模块接收到该断点插入请求后,根据其中包含的 插入断点的位置信息, 向 GOS2中的每一步后面均插入断点, 并将插入断点的 位置记录在调试断点信息表中。
插入断点的具体实现方式可以是向要插入断点的位置处写入断点指令 INT 3, 即 0xCC。
在实际中, 上述调试断点信息表可以以链表的形式进行存储。
步骤 S408:运行 GOS2,运行过程中,每执行完一步就触发一次断点异常。 步骤 S409: vir_gdbserver模块捕获 GOS2运行过程中触发的断点异常,并 将该断点异常的特征与调试断点信息表中的断点位置进行比较,如果匹配,说 明该断点异常是 GOS2执行到之前插入的用于调试的断点后触发的, 则暂停 GOS2的运行。
在步骤 S409中暂停 GOS2的运行以后, vir_gdbserver模块可以根据 GOS1 发送的查阅请求, 将 GOS2中的状态信息反馈至 GOS1中的 gdb, 这里的状态 信息可以是 GOS2中的各个寄存器内的信息、堆栈信息和全局变量中的任意一 个或者任意组合。
此外, 在一个优选的实施例中, 虚拟调试服务模块(vir_gdbserver模块) 还接收主控操作系统请求构造调试环境的请求, 虚拟调试服务模块根据该请 求, 构造被调试操作系统的运行环境。 利用该手段, 用户可以模拟被调试操作 系统在各种极端运行环境下的调试过程。 例如, 当用户知道出现故障的条件, 但是不知道为什么该条件会出现,也就是说该条件的出现完全是随机的不可控 的, 此时可以将满足该条件的环境通过人为构造, 达到故障输入的目的, 为进 一步克服该故障提供调试的基础。这里构造调试环境可以是在被调试操作系统 运行之前进行,也可以是在被调试操作系统运行到断点时被暂停运行的时候进 行。
另夕卜,上述 GOS1中的 gdb与 vir_gdbserver模块之间的通信过程优选采用 密钥来完成, 以增强系统的安全性。
由此可见, 本实施例中在虚拟机中实现了一个虚拟调试服务模块, 可以轻 松实现被调试操作系统的断点调试以及单步执行调试。 本发明另一实施例还相应提供一种虚拟调试服务模块,该虚拟调试服务模 块构建在虚拟机中, 该虚拟机上运行主控操作系统和被调试操作系统, 如图 5 所示, 该虚拟调试服务模块 50包括断点插入请求接收单元 501、 断点插入单 元 502、 断点异常捕获单元 503、 特征比较单元 504和暂停单元 505。
其中,断点插入请求接收单元 501用于接收主控操作系统中的调试模块发 送的插入至少一个断点的断点插入请求,上述断点插入请求中包括插入断点的 位置信息。 断点插入单元 502 用于根据断点插入请求中的插入断点的位置信 息,在被调试操作系统中的相应位置处插入断点, 并将插入断点的位置记录在 调试断点信息表中。断点异常捕获单元 503用于捕获被调试操作系统执行过程 中触发的断点异常。特征比较单元 504用于将上述捕获到的断点异常的特征与 调试断点信息表中记录的断点的位置进行比较,如果匹配成功, 则触发暂停单 元 505进行工作。 暂停单元 505用于触发被调试操作系统暂停运行。
为了进行单步执行调试, 优选地, 虚拟调试服务模块还可以包括: 单步执行支持判断单元 506, 用于在需要进行单步执行调试时, 预先判断 硬件是否支持单步执行;
逐步断点插入单元 507, 用于在单步执行支持判断单元 506判断结果为否 时,通知主控操作系统中的调试模块向虚拟调试服务模块发送在被调试操作系 统执行的每一步均插入断点的断点插入请求。
此外, 上述虚拟调试服务模块还可以包括:
标志位设置单元 508, 用于在单步执行支持判断单元判断结果为是时, 在 被调试操作系统运行时,将运行该被调试操作系统的中央处理器的标志寄存器 中用于控制单步执行调试模式开关的标志位设置为表示 "开启" 的状态, 以使 被调试操作系统在运行每一步后都产生单步异常。
单步异常捕获单元 509, 用于捕获被调试操作系统在运行每一步后所产生 的单步异常,当虚拟调试服务模块确认被调试操作系统运行的当前步执行完毕 后, 触发上述暂停单元 505进行工作。
此外, 为了方便用户在暂停运行被调试操作系统的运行状态信息,优选地 还包括查阅单元 506, 用于用于在暂停被调试操作系统的运行以后, 接收主控 操作系统中的调试模块发送的查阅被调试操作系统的状态信息的查阅请求,并 根据该查阅请求,将被调试操作系统的状态信息反馈至主控操作系统中的调试 模块,这里被调试操作系统的状态信息可以包括被调试操作系统的寄存器中的 信息、 堆栈中的信息和全局变量中的任何一个或者任意组合。 以上公开的仅为本发明的几个具体实施例,但本发明并非局限于此,任何 本领域的技术人员能思之的变化, 都应落在本发明的保护范围内。

Claims

权 利 要 求
1、 一种操作系统内核的调试方法, 其特征在于, 虚拟机上运行主控操作 系统和被调试操作系统, 该方法包括:
虚拟调试服务模块接收主控操作系统中的调试模块发送的断点插入请求, 所述断点插入请求中包括插入断点的位置信息;
所述虚拟调试服务模块根据断点插入请求中的插入断点的位置信息,在被 调试操作系统中的相应位置处插入断点,并将插入断点的位置记录在调试断点 信息表中;
所述虚拟调试服务模块捕获被调试操作系统执行过程中触发的断点异常, 并将捕获到的断点异常的特征与调试断点信息表中记录的断点的位置进行匹 配比较, 如果匹配, 则暂停被调试操作系统的运行。
2、 根据权利要求 1所述的操作系统内核的调试方法, 其特征在于, 还包 括, 当需要进行单步执行调试时, 预先判断硬件是否支持单步执行, 如果不支 持,则主控操作系统中的调试模块向虚拟调试服务模块发送在被调试操作系统 执行的每一步均插入断点的断点插入请求。
3、 根据权利要求 2所述的操作系统内核的调试方法, 其特征在于, 还包 括, 如果硬件支持单步执行, 贝' J :
在被调试操作系统运行时,所述虚拟调试服务模块将运行该被调试操作系 统的中央处理器中的标志寄存器中用于控制单步执行调试模式开关的标志位 设置为表示 "开启" 的状态, 以使被调试操作系统在运行每一步后都产生单步 异常;
所述虚拟调试服务模块捕获被调试操作系统在运行每一步后所产生的单 步异常;
所述虚拟调试服务模块确认被调试操作系统运行的当前步执行完毕后,则 暂停被调试操作系统的运行。
4、 根据权利要求 3所述的操作系统内核的调试方法, 其特征在于, 所述 用于控制单步执行调试模式开关的标志位为 TF标志位。
5、 根据权利要求 1至 4中, 限定比较匹配过程的特征信息, 包括异常地 址和异常向量。
6、 根据权利要求 1至 4中任意一项所述的操作系统内核的调试方法, 其 特征在于, 还包括: 在暂停被调试操作系统的运行以后, 虚拟调试服务模块接 收主控操作系统中的调试模块发送的查阅被调试操作系统的状态信息的查阅 请求, 并根据查阅请求,将被调试操作系统的状态信息反馈至主控操作系统中 的调试模块;
所述被调试操作系统的状态信息包括被调试操作系统的寄存器中的信息、 堆栈中的信息和全局变量中的任意一个或者任意组合。
7、 一种虚拟调试服务模块, 其特征在于, 其构建在虚拟机中, 所述虚拟 机上运行主控操作系统和被调试操作系统, 该虚拟调试服务模块包括:
断点插入请求接收单元,用于接收主控操作系统中的调试模块发送的断点 插入请求, 所述断点插入请求中包括插入断点的位置信息;
断点插入单元, 用于根据断点插入请求中的插入断点的位置信息, 在被调 试操作系统中的相应位置处插入断点,并将插入断点的位置记录在调试断点信 息表中;
断点异常捕获单元, 用于捕获被调试操作系统执行过程中触发的断点异 常;
特征比较单元,用于将所述捕获到的断点异常的特征与调试断点信息表中 记录的断点的位置进行比较, 如果匹配成功, 则触发暂停单元进行工作; 暂停单元, 用于触发被调试操作系统暂停运行。
8、 根据权利要求 7所述的虚拟调试服务模块, 其特征在于, 还包括: 单 步执行支持判断单元, 用于在需要进行单步执行调试时,预先判断硬件是否支 持单步执行;
逐步断点插入单元, 用于在单步执行支持判断单元判断结果为否时, 通知 主控操作系统中的调试模块向虚拟调试服务模块发送在被调试操作系统执行 的每一步均插入断点的断点插入请求。
9、 根据权利要求 8所述的虚拟调试服务模块, 其特征在于, 还包括: 标志位设置单元, 用于在单步执行支持判断单元判断结果为是时, 在被调 试操作系统运行时,将运行该被调试操作系统的中央处理器的标志寄存器中用 于控制单步执行调试模式开关的标志位设置为表示 "开启" 的状态, 以使被调 试操作系统在运行每一步后都产生单步异常。
单步异常捕获单元,用于捕获被调试操作系统在运行每一步后所产生的单 步异常, 当虚拟调试服务模块确认被调试操作系统运行的当前步执行完毕后, 触发所述暂停单元进行工作。
10、根据权利要求 7至 9中任意一项所述的虚拟调试服务模块, 其特征在 于, 还包括:
查阅单元, 用于在暂停被调试操作系统的运行以后,接收主控操作系统中 的调试模块发送的查阅被调试操作系统的状态信息的查阅请求,并根据该查阅 请求, 将被调试操作系统的状态信息反馈至主控操作系统中的调试模块; 所述被调试操作系统的状态信息包括被调试操作系统的寄存器中的信息、 堆栈中的信息和全局变量中的任意一个或者任意组合。
PCT/CN2011/076910 2011-07-06 2011-07-06 一种操作系统内核调试方法和虚拟调试服务模块 WO2012106871A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
PCT/CN2011/076910 WO2012106871A1 (zh) 2011-07-06 2011-07-06 一种操作系统内核调试方法和虚拟调试服务模块
CN2011800016502A CN102301344B (zh) 2011-07-06 2011-07-06 一种操作系统内核调试方法和虚拟调试服务模块

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2011/076910 WO2012106871A1 (zh) 2011-07-06 2011-07-06 一种操作系统内核调试方法和虚拟调试服务模块

Publications (1)

Publication Number Publication Date
WO2012106871A1 true WO2012106871A1 (zh) 2012-08-16

Family

ID=45360524

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2011/076910 WO2012106871A1 (zh) 2011-07-06 2011-07-06 一种操作系统内核调试方法和虚拟调试服务模块

Country Status (2)

Country Link
CN (1) CN102301344B (zh)
WO (1) WO2012106871A1 (zh)

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104077220A (zh) * 2014-06-10 2014-10-01 中标软件有限公司 Mips架构操作系统内核的调试方法和装置
CN105159819B (zh) * 2015-09-01 2018-03-13 汉柏科技有限公司 一种记录内核异常栈及调试信息的方法及系统
CN106126431A (zh) * 2016-08-23 2016-11-16 腾讯科技(深圳)有限公司 性能测试方法及系统
CN107341107B (zh) * 2017-07-04 2022-04-29 飞天诚信科技股份有限公司 一种嵌入式开发的自动化测试方法及测试主机
CN109800159B (zh) * 2018-12-27 2021-02-23 百富计算机技术(深圳)有限公司 程序调试方法、程序调试装置、终端设备及存储介质
CN109977633B (zh) * 2019-03-28 2023-04-07 武汉斗鱼鱼乐网络科技有限公司 一种程序保护方法及相关装置
CN110096888B (zh) * 2019-04-18 2021-02-09 苏州浪潮智能科技有限公司 一种加快验证及分析smm安全隐患的方法及系统
CN115794313B (zh) * 2022-12-26 2024-04-09 科东(广州)软件科技有限公司 一种虚拟机调试方法、系统、电子设备及存储介质
CN116089316B (zh) * 2023-04-07 2023-06-09 武汉凌久微电子有限公司 一种基于动态断点的内核驱动数据调试方法
CN116662157B (zh) * 2023-04-26 2024-02-02 北京计算机技术及应用研究所 一种针对tms320 c28x指令集模拟器的虚拟化调试系统设计方法

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070022322A1 (en) * 2005-07-19 2007-01-25 Microsoft Corporation Fast data breakpoint emulation
US20070266376A1 (en) * 2006-05-11 2007-11-15 Samsung Electronics Co., Ltd. Kernel-aware debugging system, medium, and method
CN101281488A (zh) * 2007-04-06 2008-10-08 上海宇梦通信科技有限公司 Linux操作系统的内核调试方法
CN101609429A (zh) * 2009-07-22 2009-12-23 大唐微电子技术有限公司 一种调试嵌入式操作系统的方法和装置

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100365590C (zh) * 2005-01-31 2008-01-30 浙江大学 在嵌入式系统模拟器上调试应用程序的方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070022322A1 (en) * 2005-07-19 2007-01-25 Microsoft Corporation Fast data breakpoint emulation
US20070266376A1 (en) * 2006-05-11 2007-11-15 Samsung Electronics Co., Ltd. Kernel-aware debugging system, medium, and method
CN101281488A (zh) * 2007-04-06 2008-10-08 上海宇梦通信科技有限公司 Linux操作系统的内核调试方法
CN101609429A (zh) * 2009-07-22 2009-12-23 大唐微电子技术有限公司 一种调试嵌入式操作系统的方法和装置

Also Published As

Publication number Publication date
CN102301344B (zh) 2013-12-04
CN102301344A (zh) 2011-12-28

Similar Documents

Publication Publication Date Title
WO2012106871A1 (zh) 一种操作系统内核调试方法和虚拟调试服务模块
JP6857193B2 (ja) 仮想化環境においてネットワークトラフィックを解読するためのシステムおよび方法
JP5160176B2 (ja) 仮想マシンのための多数コンフィギュレーションによる通信管理のためのシステム、方法、およびプログラム
US8468288B2 (en) Method for efficient guest operating system (OS) migration over a network
TWI727988B (zh) 用於在封閉商品設備上建立可信診斷/調試代理的系統和方法
JP7220163B2 (ja) ハードウェア仮想化のための方法及び装置
US10678913B2 (en) Apparatus and method for enhancing security of data on a host computing device and a peripheral device
US20160323427A1 (en) A dual-machine hot standby disaster tolerance system and method for network services in virtualilzed environment
US9471355B2 (en) Secure operations for virtual machines
US6687817B1 (en) Configuration of a network device via the network
TWI421698B (zh) 用以促進至少一個客體處理系統之輸入/輸出(i/o)處理之電腦程式產品、方法及系統
US9019978B2 (en) Port mirroring at a network interface device
US20160315838A1 (en) Virtual Intelligent Platform Management Interface for Hardware Components
CN107077412B (zh) 单层或n层应用的自动化根本原因分析
US9423956B2 (en) Emulating a stretched storage device using a shared storage device
WO2018131547A1 (ja) ポート切替プログラム、ポート切替方法、および情報処理装置
WO2018153027A1 (zh) 一种数据迁移方法及装置
CN109656488A (zh) 用于可信计算的多节点中枢
WO2018112862A1 (zh) 设备检测方法、系统、电子设备、云端机器人系统和计算机程序产品
US20090271165A1 (en) Simultaneous Parameter-Driven and Deterministic Simulation With or Without Synchronization
WO2017084402A1 (zh) 一种多应用程序的调试系统和方法
WO2024040846A1 (zh) 数据处理方法、装置、电子设备及存储介质
JP2001051871A (ja) リモートデバッグ装置
CN112711527A (zh) 一种实时进程的调试方法、装置、目标机和存储介质
JP2014229301A (ja) マルチノードを用いるスマート端末ファジング装置およびその方法

Legal Events

Date Code Title Description
WWE Wipo information: entry into national phase

Ref document number: 201180001650.2

Country of ref document: CN

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 11858044

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 11858044

Country of ref document: EP

Kind code of ref document: A1