读《软件调试》第九章
今日读了张银奎老师的《软件调试》,前面的CPU和硬件相关的部分离得比较远,所以从第九章操作系统读起,今天的读书笔记: 9.2采集调试消息 调试事件分为8种 typedef enum _DBGKM_APINUMBER { DbgkmExceptionApi = 0, // 异常 DbgkmCreateThreadApi = 1, //
今日读了张银奎老师的《软件调试》,前面的CPU和硬件相关的部分离得比较远,所以从第九章操作系统读起,今天的读书笔记:
9.2采集调试消息
调试事件分为8种
typedef enum _DBGKM_APINUMBER
{
DbgkmExceptionApi = 0, // 异常
DbgkmCreateThreadApi = 1, // 创建线程
DbgkmCreateProcessApi = 2, // 创建进程
DbgkmExitThreadApi = 3, // 退出线程
DbgkmExitProcessApi = 4, // 进程退出
DbgkmLoadDllApi = 5, // 映射DLL
DbgkmUnloadDllApi = 6, // 反映射DLL
DbgkmErrorReportApi = 7, // 内部错误
DbgkmMaxApiNumber = 8, // 这组常量的最大值
} DBGKM_APINUMBER;
9.2.2 进程和线程创建消息
操作系统就支持向调试系统发送消息,这个我是没有想到的,具体过程如下:
创建用户态windows线程时,首先为线程建立必要的内核对象和数据结构,并分配栈(stack)空间,这些工作完成后,
该线程处于挂起状态(CREATE_SUSPEND), 而后进程管理器会通知环境子系统,环境子系统会作必要的设置和登记,最后
进程管理器会调用PspUserThreadStartup例程,准备启动该线程。
为了支持调试,PspUserThreadStartup总是会调用调试子系统的内核函数DbgkCreateThread,以便让调试子系统得到处理机会。
DbgkCreateThread会检查新创建线程所在的进程是否正在被调试(根据DebugPort是否为空),如果不是,便立即返回,
如果是,则会继续检查该进程的用户态运行时间(UserTime)是否为0,目的是判断该线程是否是进程中的第一个线程,如果是,
则通过DbgkSendApiMessage()函数向DebugPort发送DbgkmCreateProcessApi消息,如果不是,
则发送DbgkmCreateThreadApi消息。
调试器收到的进程创建(CREATE_PROCESS_DEBUG_EVENT,值为3)和线程创建(CREATE_THREAD_DEBUG_EVENT,值为2)事件就是源于这两个消息。
9.2.3 进程和线程退出消息 --- 与上面类似
9.2.4 模块映射和反映射消息
DLL(Dynamic-link Library)是Windows中使用最多的技术之一。如:
Windows内核文件NTOSKRNL.EXE虽然是EXE后缀,其实质是一个DLL;
NTDLL.DLL是连接用户态和操作系统内核的桥梁,用户态代码通过它访问内核服务;
Windows子系统DLL(KERNEL32.DLL,ADVAPI32.DLL,USER32.DLL,GDI32.DLL)是Windows API的载体;
观察进程中的DLL:
1.运行notepad.exe
2.启动VC6,通过Build>Start Debug>Attatch to Process...菜单弹出Attach Process对话框,然后选择notepad.
3. 通过Debug>Modules...菜单弹出模块列表,便可以看到notepad进程中的DLL了。
第二列是该模块在进程空间中的地址(虚拟地址,均小于0x80000000),可见这些模块都是位于用户空间中的。
存在于多个进程空间中的DLL,是否会重复占用内存?
否!当LoadLibrary()和LoadLibraryEx() API加载一个DLL时,会首先判断该DLL是否已经加载过,如果是,则不会重复加载,
只是将该DLL对应的内存页面映射(map)到目标进程的内存空间,并把该DLL的引用次数加1.
当进程退出或调用FreeLibrary() API要卸载一个DLL时,Windows会从进程的虚拟内存空间中把该DLL的映射删除(unmap),
并递减该DLL的引用次数,如果引用次数变为0,那么该DLL会被彻底移出内存。
9.2.5 异常消息
为了支持调试,系统会把被调试程序中发生的所有异常发送给调试器。
内核中KiDispatchException函数是分发异常的枢纽,它会给每个异常安排最多两轮被处理的机会,
对于每一轮处理机会,它都会调用调试子系统的DbgkForwardException函数来通知调试子系统。
总结:
系统的进程管理器、内存管理器和异常分发函数会调用调试子系统的Dbgk采集例程,来向调试子系统通报调试消息,
这些例程被调用后会根据当前进程的DebugPort字段来判断当前进程是否处于被调试状态。
如果不是,便忽略这次调用,直接返回;
如果是,便产生一个DBGKM_APIMSG结构,然后调用下一节将介绍的DbgkSendApiMessage函数来发送调试消息。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

It's common for games to slow down your computer because they consume a lot of resources. It's crucial to understand your CPU usage when gaming so you can avoid overloading it. Therefore, keeping track of appropriate CPU usage is key to keeping your gaming experience smooth. In this article, we'll look at the appropriate CPU usage you should achieve while your game is running. CPU utilization during gaming CPU utilization is an important indicator of processor workload and depends on the performance specifications of the CPU. More powerful CPUs generally have higher usage. A CPU with more cores and threads can improve the overall performance of your system. Multi-threading support helps unleash the full potential of your CPU. In games, CPU usage depends on processor utilization, which can affect the game

Many users find that the computer is not running smoothly enough when using the Win11 system. They want to improve CPU performance, but they don't know how to do it. The following will introduce in detail how to set the CPU performance to the highest level in Win11 system to make your computer more efficient. Setting method: 1. Right-click "This PC" on the desktop and select "Properties" in the option list. 2. After entering the new interface, click "Advanced System Settings" in "Related Links". 3. In the window that opens, click the "Advanced" tab at the top, then click the & at the bottom of "Performance"

Intel XTU is a powerful application that allows you to easily manage your computer's performance. You can fix overheating issues by adjusting the CPU voltage, or boost performance by overclocking. In this article, we'll look at how you can take advantage of Intel XTU to optimize your computer's performance, whether that's adjusting voltage or overclocking. What effect do undervolting and overclocking have on the CPU? Before we move on to learning how to undervolt and overclock a CPU, we first have to understand what they are. Undervolting refers to gradually reducing the voltage required by the CPU. This process helps reduce heat emissions, as high voltage results in higher temperatures. By reducing the voltage supply to the CPU, the temperature can be effectively reduced. If your laptop starts to slow down after getting hot, you should solve the problem promptly.

The differences between boxed and bulk CPUs: 1. Quality; 2. Warranty period; 3. Fan; 4. Price; 5. Packaging; 6. Sales channels. Detailed introduction: 1. Quality, whether it is boxed or bulk, there is no difference in the quality of the CPU itself. They are all manufactured by the same manufacturer and undergo the same quality testing and quality control process; 2. Warranty period, boxed CPU A longer warranty period is usually provided, usually three years, while bulk CPUs usually only have a one-year warranty, this is because boxed CPUs are usually sold by official or authorized dealers, etc.

1. First, we right-click the blank space of the taskbar and select the [Task Manager] option, or right-click the start logo, and then select the [Task Manager] option. 2. In the opened Task Manager interface, we click the [Services] tab on the far right. 3. In the opened [Service] tab, click the [Open Service] option below. 4. In the [Services] window that opens, right-click the [InternetConnectionSharing(ICS)] service, and then select the [Properties] option. 5. In the properties window that opens, change [Open with] to [Disabled], click [Apply] and then click [OK]. 6. Click the start logo, then click the shutdown button, select [Restart], and complete the computer restart.

According to news from this website on July 28, foreign media TechRader reported that Fujitsu introduced in detail the FUJITSU-MONAKA (hereinafter referred to as MONAKA) processor planned to be shipped in 2027. MONAKACPU is based on the "cloud native 3D many-core" architecture and adopts the Arm instruction set. It is oriented to the data center, edge and telecommunications fields. It is suitable for AI computing and can realize mainframe-level RAS1. Fujitsu said that MONAKA will achieve a leap in energy efficiency and performance: thanks to technologies such as ultra-low voltage (ULV) technology, the CPU can achieve 2 times the energy efficiency of competing products in 2027, and cooling does not require water cooling; in addition, the application performance of the processor It can also reach twice as much as your opponent. In terms of instructions, MONAKA is equipped with vector

How to Overclock Computer CPUs With the continuous advancement of technology, people's demand for computer performance is also getting higher and higher. An effective way to improve computer performance is to increase the CPU's operating frequency through overclocking. Overclocking allows the CPU to process data faster, providing higher computing power. So, how to overclock a computer CPU? The following will introduce you to the basic principles and specific operation methods of overclocking. First, let's understand how overclocking works. The operating frequency of the CPU is determined by the crystal oscillator on the motherboard

IntelArrowLakeisexpectedtobebasedonthesameprocessorarchitectureasLunarLake,meaningthatIntel'sbrandnewLionCoveperformancecoreswillbecombinedwiththeeconomicalSkymontefficiencycores.WhileLunarLakeisonlyavailableasava
