linux GDB and GDB Sever

2024-01-14 10:44
文章标签 linux gdb sever

本文主要是介绍linux GDB and GDB Sever,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

概念:

GDB(GNU Debugger)是一个用于调试程序的强大工具。它是GNU项目的一部分,支持多种编程语言,包括C、C++等。GDB 提供了一组命令和功能,允许跟踪检查程序的内部状态,跟踪代码的执行过程,以及定位和修复程序中的错误。

gdb和gdb sever

GDB(GNU Debugger)

  • gdb 用于本地调试程序。它允许程序员查看程序的运行状态、检查变量和内存、设置断点等,以便在代码中找到和修复问题。
  • 使用 gdb 时,你在本地计算机上运行 gdb,并且该调试器直接与正在调试的程序进行交互。

GDB Server(gdbserver)

  • gdbserver 是 GDB 的另一部分,用于远程调试。它允许你在目标计算机上运行一个小型的 GDB 服务器,然后在本地计算机上运行gdb 与之连接。
  • 通过 gdbserver,你可以在嵌入式系统或远程计算机上调试程序,而不需要将整个 GDB 调试器放在目标系统上。
  • 这种分离的方法对于嵌入式系统等资源受限的环境非常有用,允许在目标系统上运行轻量级的 gdbserver,而在开发机上运行完整版的 gdb 进行调试。

作用

  1. 调试程序: GDB的主要作用是帮助程序员识别和解决程序中的错误(bugs)。它允许开发者在程序执行时停下来,检查变量的值,查看函数调用堆栈,设置断点,并逐步执行代码。
  2. 变量和内存查看:GDB 允许开发者检查程序运行时的变量的值和内存的内容。这对于理解程序的状态以及发现潜在问题非常有用。
  3. 设置断点: 开发者可以在程序中设置断点,使得程序在执行到达特定的位置时停下来。这有助于逐步调试程序并检查特定的代码段。
  4. 单步执行:GDB 允许开发者逐步执行程序,一次执行一行代码或一次执行一个函数。这对于追踪程序的执行流程非常有用。
  5. 追踪函数调用:GDB 能够跟踪程序中的函数调用,显示函数调用关系,帮助开发者理解程序的执行路径。
  6. 查找内存错误:GDB 能够帮助开发者查找程序中的内存错误,如访问未分配内存、内存溢出等问题。
  7. 多线程调试:GDB 支持调试多线程程序,允许开发者查看和调试不同线程的执行状态。
  8. 核心转储分析:当程序发生崩溃时,GDB 可以分析核心转储文件,帮助开发者定位问题的根本原因。

GDB和IDE差别

  • 各有好处,并且IDE在不考虑环境的情况下,更容易上手
  • 基于 Linux 服务器等的无图形界面开发,使用 Vim+GDB 可以在任意一台电脑上直接调试,不用花时间安装复杂的 IDE 环境。

主要包含如下区别:

  • 命令行界面 vs 图形用户界面
  • 功能的可视化和图形化展示
  • 集成性和便利性
  • 快捷键和工具栏
  • 平台和语言支持

总体而言,使用 GDB 和使用 IDE 中的调试工具之间的选择通常取决于个人偏好、项目需求以及开发环境。

gdb 调试段错误代码demo

#include <stdio.h>void accessInvalidMemory() {int *ptr = NULL; // 故意将指针设置为NULL*ptr = 42;       // 试图访问NULL指针
}
int main() {accessInvalidMemory(); // 调用会导致Segmentation fault的函数return 0;
}

定位流程与操作

@ubuntu:$ gcc -g Segmentation_fault.c -o Segmentation_fault
@ubuntu:GDB_debug$ gdb ./Segmentation_fault -q
Reading symbols from ./Segmentation_fault...done.
(gdb) b main
Breakpoint 1 at 0x617: file Segmentation_fault.c, line 9.
(gdb) list
1       #include <stdio.h>
2
3       void accessInvalidMemory() {
4           int *ptr = NULL; // 故意将指针设置为NULL
5           *ptr = 42;       // 试图访问NULL指针
6       }
7
8       int main() {
9           accessInvalidMemory(); // 调用会导致Segmentation fault的函数
10          return 0;
(gdb) r
Starting program: GDB_debug/Segmentation_faultBreakpoint 1, main () at Segmentation_fault.c:9
9           accessInvalidMemory(); // 调用会导致Segmentation fault的函数
(gdb) s
accessInvalidMemory () at Segmentation_fault.c:4
4           int *ptr = NULL; // 故意将指针设置为NULL
(gdb) n
5           *ptr = 42;       // 试图访问NULL指针
(gdb) nProgram received signal SIGSEGV, Segmentation fault.
0x000055555555460a in accessInvalidMemory () at Segmentation_fault.c:5
5           *ptr = 42;       // 试图访问NULL指针
(gdb) bt
#0  0x000055555555460a in accessInvalidMemory () at Segmentation_fault.c:5
#1  0x0000555555554621 in main () at Segmentation_fault.c:9
(gdb) n
Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
(gdb) n
The program is not being run.

结论
查看调用栈

(gdb) bt
#0  0x000055555555460a in accessInvalidMemory () at Segmentation_fault.c:5
#1  0x0000555555554621 in main () at Segmentation_fault.c:9

问题出在:函数accessInvalidMemory,代码的第五行

说明与解释

  • bt是backtrace的缩写,可以查看调用栈
  • r是run的缩写
  • n是next的缩写
  • s是step的缩写
  • b 是break的缩写
  • quit 退出gdb调试,缩写为q

为什么不一直用next?还用step?

  • next执行当前函数的所有指令,而step可以让进入段错误函数后再第一行停下来,可以定位到具体到某一行出现的问题

GDB多线程调试

#include <stdio.h>
#include <pthread.h>
#include <unistd.h>void *thread_function(void *arg) {for (int i = 0; i < 5; ++i) {printf("Thread %ld: Iteration %d\n", (long)arg, i);sleep(1);}return NULL;
}int main() {pthread_t thread1, thread2;// 创建两个线程pthread_create(&thread1, NULL, thread_function, (void *)1);pthread_create(&thread2, NULL, thread_function, (void *)2);// 等待线程结束pthread_join(thread1, NULL);pthread_join(thread2, NULL);return 0;
}

编译

gcc -g multithread_demo.c -o multithread_demo -lpthread

执行

gdb ./multithread_demo -q

想要完成的调试方法

1、查看整体进程中的线程执行结果

@ubuntu:$ gdb ./multithread_demo -q
Reading symbols from ./multithread_demo...done.
(gdb) b main
Breakpoint 1 at 0x81d: file multithread_demo.c, line 13.
(gdb) run
Starting program: GDB_debug/multithread_demo
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Breakpoint 1, main () at multithread_demo.c:13
13      int main() {
(gdb) n
17          pthread_create(&thread1, NULL, thread_function, (void *)1);
(gdb) n
[New Thread 0x7ffff77c2700 (LWP 335)]
18          pthread_create(&thread2, NULL, thread_function, (void *)2);
(gdb) info threads
Id   Target Id         Frame
- 1    Thread 0x7ffff7fdb740 (LWP 130537) "multithread_dem" main () at multithread_demo.c:18
(gdb) n
Thread 1: Iteration 1
Thread 2: Iteration 0
Thread 1: Iteration 2
Thread 2: Iteration 1
Thread 1: Iteration 3
Thread 2: Iteration 2
Thread 1: Iteration 4
Thread 2: Iteration 3
[Thread 0x7ffff77c2700 (LWP 335) exited]
22          pthread_join(thread2, NULL);
(gdb) n
Thread 2: Iteration 4
[Thread 0x7ffff6fc1700 (LWP 1407) exited]
24          return 0;
(gdb) n
25      }
(gdb) n
[Inferior 1 (process 130537) exited normally]
(gdb) n
The program is not being run.

2、子线程被创建后,gdb跟踪子线程及主线程


@ubuntu:GDB_debug$ gdb ./multithread_demo -q
Reading symbols from ./multithread_demo...done.
(gdb) set detach-on-fork off
(gdb) b main
Breakpoint 1 at 0x81d: file multithread_demo.c, line 13.
(gdb) run
Starting program: GDB_debug/multithread_demo
[Thread debugging using libthread_db enabled]
13      int main() {
(gdb) n
17          pthread_create(&thread1, NULL, thread_function, (void *)1);
(gdb) n
[New Thread 0x7ffff77c2700 (LWP 9522)]
Thread 1: Iteration 0
18          pthread_create(&thread2, NULL, thread_function, (void *)2);
(gdb) n
[New Thread 0x7ffff6fc1700 (LWP 9523)]
Thread 2: Iteration 0
Thread 2: Iteration 1
Thread 2: Iteration 2
Thread 2: Iteration 3
Thread 2: Iteration 4
8               sleep(1);
(gdb)
6           for (int i = 0; i < 5; ++i) {
(gdb)
7               printf("Thread %ld: Iteration %d\n", (long)arg, i);
(gdb)
Thread 1: Iteration 1
8               sleep(1);
(gdb)
6           for (int i = 0; i < 5; ++i) {
(gdb)
7               printf("Thread %ld: Iteration %d\n", (long)arg, i);
(gdb)
Thread 1: Iteration 2
8               sleep(1);
(gdb)
6           for (int i = 0; i < 5; ++i) {
(gdb)
7               printf("Thread %ld: Iteration %d\n", (long)arg, i);
(gdb)
Thread 1: Iteration 3
8               sleep(1);
(gdb)
6           for (int i = 0; i < 5; ++i) {
(gdb)
7               printf("Thread %ld: Iteration %d\n", (long)arg, i);
(gdb)
Thread 1: Iteration 4
8               sleep(1);
(gdb)
6           for (int i = 0; i < 5; ++i) {
(gdb)
10          return NULL;
(gdb)
11      }

命令解释

  • set detach-on-fork off 告诉 GDB 在子进程(或线程)分离时不要自动分离调试器,默认情况下,GDB 会在程序中发生
    fork 时自动分离调试器,这可能导致你失去对子进程的控制,所以我一般会设置为off
  • show detach-on-fork可以看当前的设置状态

GDB多进程调试

#include <stdio.h>
#include <unistd.h>
int main()
{pid_t pid = fork();if(pid == 0){int num =10;while(num==10){sleep(2);printf("this 1is child,pid = %d\n",getpid());}printf("this 2is child,pid = %d\n",getpid());printf("this 3is child,pid = %d\n",getpid());}else{int mnum=5;while(mnum==5){sleep(5);printf("this 4is parent,pid = %d\n",getpid());}}return 0;
}

编译

gcc -g multiprocess_demo_2.c -o multiprocess_demo_2

gdb 跟踪子进程

@ubuntu:GDB_debug$ gcc -g multiprocess_demo_2.c -o multiprocess_demo_2
@ubuntu:GDB_debug$ gdb ./multiprocess_demo_2 -q
Reading symbols from ./multiprocess_demo_2...done.
(gdb) b main
Breakpoint 1 at 0x722: file multiprocess_demo_2.c, line 5.
(gdb) set follow-fork-mode child
(gdb) r
Starting program: /home/xj/Desktop/huangrui/project_1/GDB_debug/multiprocess_demo_2Breakpoint 1, main () at multiprocess_demo_2.c:5
5           pid_t pid = fork();
(gdb) n
[New process 109167]
[Switching to process 109167]
main () at multiprocess_demo_2.c:6
6           if(pid == 0)
(gdb) info inferiorsNum  Description       Executable1    <null>            GDB_debug/multiprocess_demo_2
* 2    process 109167    GDB_debug/multiprocess_demo_2
(gdb) this 4is parent,pid = 109163
this 4is parent,pid = 109163
n
8               int num =10;
(gdb) n
9               while(num==10){
(gdb) this 4is parent,pid = 109163
n
10                  sleep(2);
(gdb) n
11                  printf("this 1is child,pid = %d\n",getpid());
(gdb) this 4is parent,pid = 109163
p num=this 4is parent,pid = 109163
9
$1 = 9
(gdb) n
this 1is child,pid = 109167
9               while(num==10){
(gdb) n
14              printf("this 2is child,pid = %d\n",getpid());
(gdb) n
this 2is child,pid = 109167
15              printf("this 3is child,pid = %d\n",getpid());
(gdb) this 4is parent,pid = 109163
n
this 3is child,pid = 109167
26          return 0;
(gdb) n
27      }(gdb) nthis 4is parent,pid = 109163__libc_start_main (main=0x55555555471a <main>, argc=1, argv=0x7fffffffe328, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe318)at ../csu/libc-start.c:344
344     ../csu/libc-start.c: No such file or directory.
(gdb) n
[Inferior 2 (process 109167) exited normally]
(gdb) n
The program is not being run.
(gdb) quitthis 4is parent,pid = 109163

set follow-fork-mode的作用:set follow-fork-mode parent 是 GDB 的一个命令,用于在多进程调试时控制在 fork() 调用之后 GDB 应该跟踪哪个进程。

  • set follow-fork-mode parent: 设置 GDB 在 fork()调用后继续跟踪父进程,而不是默认的子进程。这意味着在程序执行 fork() 后,GDB将继续调试父进程,而子进程将被分离(detach)。
  • set follow-fork-mode child: 设置 GDB 在 fork()调用后继续跟踪子进程,而不是默认的父进程。这意味着在程序执行 fork() 后,GDB 将继续调试子进程,而父进程将被分离。
  • set follow-fork-mode ask: 设置 GDB 在 fork() 调用后询问用户要跟踪哪个进程。GDB 将在每次 fork() 发生时等待用户输入,以确定是跟踪父进程还是子进程。

解释
在这里插入图片描述

补充:

  • 在 GDB 中,使用 p 命令(print 的缩写)不仅可以用来查看变量的值,还可以用来修改变量的值。当你执行 p num=9
    时,实际上是在给变量 num 赋予新的值。

前面是单子进程的调试

那如果我父进程创建多个子进程,应该如何调试呢?

#include <stdio.h>
#include <unistd.h>int main() {pid_t pid1, pid2;pid1 = fork();if (pid1 == 0) {// 子进程1printf("Child Process 1 (PID: %d)\n", getpid());// 子进程1的工作} else {pid2 = fork();if (pid2 == 0) {// 子进程2printf("Child Process 2 (PID: %d)\n", getpid());// 子进程2的工作} else {// 父进程printf("Parent Process (PID: %d)\n", getpid());// 父进程的工作// 父进程通常需要等待子进程结束waitpid(pid1, NULL, 0);waitpid(pid2, NULL, 0);}}return 0;
}

调试步骤(步骤有删减):

@ubuntu:GDB_debug$ gdb ./multiprocess_demo -q
Reading symbols from ./multiprocess_demo...done.
(gdb) b main
Breakpoint 1 at 0x722: file multiprocess_demo.c, line 7.
(gdb) b fork
Breakpoint 2 at 0x5f0
(gdb) set detach-on-fork off
(gdb) set follow-fork-mode child
(gdb) catch fork
Catchpoint 3 (fork)
(gdb) run
Starting program: GDB_debug/multiprocess_demoBreakpoint 1, main () at multiprocess_demo.c:7
7           pid1 = fork();
(gdb) nBreakpoint 2, __libc_fork () at ../sysdeps/nptl/fork.c:49
49      ../sysdeps/nptl/fork.c: No such file or directory.
(gdb) n
Catchpoint 3 (forked process 109279), 0x00007ffff7ac67cc in __libc_fork () at ../sysdeps/nptl/fork.c:135
135     in ../sysdeps/nptl/fork.c
(gdb)
[New process 109279]
Reading symbols from GDB_debug/multiprocess_demo...done.
Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.27.so...done.
Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/ld-2.27.so...done.
__libc_fork () at ../sysdeps/nptl/fork.c:142
142     ../sysdeps/nptl/fork.c: No such file or directory.
(gdb) info inferiorsNum  Description       Executable1    process 109275    GDB_debug/multiprocess_demo
* 2    process 109279    GDB_debug/multiprocess_demo
(gdb) n
main () at multiprocess_demo.c:8
8           if (pid1 == 0) {
(gdb)
10              printf("Child Process 1 (PID: %d)\n", getpid());
(gdb) n
Child Process 1 (PID: 109279)
28          return 0;
(gdb) n
29      }
(gdb) n
[Inferior 2 (process 109279) exited normally]
(gdb) n
The program is not being run.
(gdb) info inferiorsNum  Description       Executable1    process 109275    GDB_debug/multiprocess_demo
* 2    <null>           GDB_debug/multiprocess_demo
(gdb) inferior 1
[Switching to inferior 1 [process 109275] (GDB_debug/multiprocess_demo)]
[Switching to thread 1.1 (process 109275)]
#0  0x00007ffff7ac67cc in __libc_fork () at ../sysdeps/nptl/fork.c:135
135     ../sysdeps/nptl/fork.c: No such file or directory.
(gdb) n
main () at multiprocess_demo.c:8
8           if (pid1 == 0) {
(gdb)
13              pid2 = fork();
(gdb) n
(gdb)
[New process 109280]
Reading symbols from GDB_debug/multiprocess_demo...done.
Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.27.so...done.
Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/ld-2.27.so...done.
__libc_fork () at ../sysdeps/nptl/fork.c:142
142     ../sysdeps/nptl/fork.c: No such file or directory.(gdb)
main () at multiprocess_demo.c:14
14              if (pid2 == 0) {
(gdb)
16                  printf("Child Process 2 (PID: %d)\n", getpid());
(gdb)
Child Process 2 (PID: 109280)
28          return 0;
(gdb)
29      }
(gdb)
[Inferior 3 (process 109280) exited normally]
(gdb) info inferiorsNum  Description       Executable1    process 109275    GDB_debug/multiprocess_demo* 3    <null>            GDB_debug/multiprocess_demo
(gdb) n
The program is not being run.
(gdb) info inferiorsNum  Description       Executable1    process 109275    GDB_debug/multiprocess_demo* 3    <null>           GDB_debug/multiprocess_demo
(gdb) continue
The program is not being run.
(gdb) n
The program is not being run.
(gdb) info inferiorsNum  Description       Executable1    process 109275   GDB_debug/multiprocess_demo* 3    <null>            GDB_debug/multiprocess_demo
(gdb) inferior 1
[Switching to inferior 1 [process 109275] (GDB_debug/multiprocess_demo)]
[Switching to thread 1.1 (process 109275)]
#0  0x00007ffff7ac67cc in __libc_fork () at ../sysdeps/nptl/fork.c:135
135     ../sysdeps/nptl/fork.c: No such file or directory.
main () at multiprocess_demo.c:14
14              if (pid2 == 0) {
(gdb)
20                  printf("Parent Process (PID: %d)\n", getpid());
(gdb)
Parent Process (PID: 109275)
23                  waitpid(pid1, NULL, 0);
(gdb) n
24                  waitpid(pid2, NULL, 0);
(gdb) n
28          return 0;
(gdb) info inferiorsNum  Description       Executable* 1    process 109275    GDB_debug/multiprocess_demo
(gdb) n
29      }
(gdb) n
[Inferior 1 (process 109275) exited normally]
(gdb) n
The program is not being run.

如下是对上面的进行的备注
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

再次逻辑与命令说明

  • set follow-fork-mode child:fork后跟踪子进程
  • set detach-on-fork off不自动分离调试器
  • break fork 设置断点在 fork() 处
  • catch fork 在 fork() 处停下,并切换到子进程
  • continue 继续执行,这将在子进程中停下
  • info inferiors 查看当前进程
  • inferiors 2 切换到指定进程,例如第二个进程

这样就可以单独的调试某个进程了

gdb sever的连接调试

在这里我简单说明下连接的三个基本流程流程:

  1. 在目标机器上启动 GDB Server:gdbserver :1234 /path/to/your/target/program
  2. 在本地机器上启动 GDB 并连接到 GDB Server:gdb /path/to/your/target/program,在 GDB 中连接到 GDB Server:target remote <target_system_ip>:1234
  3. 在本地 GDB 中进行调试

这个内容的实操我会在后面的文档中体现出来,一篇文档内容过多,比较冗余

对于前面的GDB的8个作用基本就覆盖了,还差一个core dump的就让读者自己完成吧,主要就是做一个抛砖引玉的作用,嘻嘻

这篇关于linux GDB and GDB Sever的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/604890

相关文章

Linux join命令的使用及说明

《Linuxjoin命令的使用及说明》`join`命令用于在Linux中按字段将两个文件进行连接,类似于SQL的JOIN,它需要两个文件按用于匹配的字段排序,并且第一个文件的换行符必须是LF,`jo... 目录一. 基本语法二. 数据准备三. 指定文件的连接key四.-a输出指定文件的所有行五.-o指定输出

Linux jq命令的使用解读

《Linuxjq命令的使用解读》jq是一个强大的命令行工具,用于处理JSON数据,它可以用来查看、过滤、修改、格式化JSON数据,通过使用各种选项和过滤器,可以实现复杂的JSON处理任务... 目录一. 简介二. 选项2.1.2.2-c2.3-r2.4-R三. 字段提取3.1 普通字段3.2 数组字段四.

Linux kill正在执行的后台任务 kill进程组使用详解

《Linuxkill正在执行的后台任务kill进程组使用详解》文章介绍了两个脚本的功能和区别,以及执行这些脚本时遇到的进程管理问题,通过查看进程树、使用`kill`命令和`lsof`命令,分析了子... 目录零. 用到的命令一. 待执行的脚本二. 执行含子进程的脚本,并kill2.1 进程查看2.2 遇到的

Linux云服务器手动配置DNS的方法步骤

《Linux云服务器手动配置DNS的方法步骤》在Linux云服务器上手动配置DNS(域名系统)是确保服务器能够正常解析域名的重要步骤,以下是详细的配置方法,包括系统文件的修改和常见问题的解决方案,需要... 目录1. 为什么需要手动配置 DNS?2. 手动配置 DNS 的方法方法 1:修改 /etc/res

Linux创建服务使用systemctl管理详解

《Linux创建服务使用systemctl管理详解》文章指导在Linux中创建systemd服务,设置文件权限为所有者读写、其他只读,重新加载配置,启动服务并检查状态,确保服务正常运行,关键步骤包括权... 目录创建服务 /usr/lib/systemd/system/设置服务文件权限:所有者读写js,其他

Linux下利用select实现串口数据读取过程

《Linux下利用select实现串口数据读取过程》文章介绍Linux中使用select、poll或epoll实现串口数据读取,通过I/O多路复用机制在数据到达时触发读取,避免持续轮询,示例代码展示设... 目录示例代码(使用select实现)代码解释总结在 linux 系统里,我们可以借助 select、

Linux挂载linux/Windows共享目录实现方式

《Linux挂载linux/Windows共享目录实现方式》:本文主要介绍Linux挂载linux/Windows共享目录实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录文件共享协议linux环境作为服务端(NFS)在服务器端安装 NFS创建要共享的目录修改 NFS 配

linux系统中java的cacerts的优先级详解

《linux系统中java的cacerts的优先级详解》文章讲解了Java信任库(cacerts)的优先级与管理方式,指出JDK自带的cacerts默认优先级更高,系统级cacerts需手动同步或显式... 目录Java 默认使用哪个?如何检查当前使用的信任库?简要了解Java的信任库总结了解 Java 信

Linux命令rm如何删除名字以“-”开头的文件

《Linux命令rm如何删除名字以“-”开头的文件》Linux中,命令的解析机制非常灵活,它会根据命令的开头字符来判断是否需要执行命令选项,对于文件操作命令(如rm、ls等),系统默认会将命令开头的某... 目录先搞懂:为啥“-”开头的文件删不掉?两种超简单的删除方法(小白也能学会)方法1:用“--”分隔命

Linux五种IO模型的使用解读

《Linux五种IO模型的使用解读》文章系统解析了Linux的五种IO模型(阻塞、非阻塞、IO复用、信号驱动、异步),重点区分同步与异步IO的本质差异,强调同步由用户发起,异步由内核触发,通过对比各模... 目录1.IO模型简介2.五种IO模型2.1 IO模型分析方法2.2 阻塞IO2.3 非阻塞IO2.4