上下文切换(中断)
以 fork系统调用 为例
中断描述符
00 00 ef 00
00 08 79 76
selector: 08
offset 00007976
调试脚本
cat gdb/intr.gdb
set logging file gdb_output/setup.gdb.output
set logging on
set pagination off
set print repeats 0
file tools/system
target remote :1234
b fork
info b
c
#layout asm
si
x /5i $eip
info reg cs ss esp
echo --------------\n
info reg eip cs eflags esp ss
# return addr 0x68e1
######################################
# come into intr
si
echo --------------\n
info reg cs ss esp
p stack_start
x /20bx $esp
b *0x79ef
c
x /i $eip
echo --------------\n
info reg cs ss esp
######################################
# leave intr
x /20bx $esp
si
info reg cs ss esp
调试输出
cat gdb_output/setup.gdb.output
0x0000fff0 in copy_strings (argc=0, argv=0x0 <startup_32>, page=0x0 <startup_32>, p=0, from_kmem=0) at exec.c:134
134 if (--offset < 0) {
Breakpoint 1 at 0x68da: fork. (3 locations)
Num Type Disp Enb Address What
1 breakpoint keep y <MULTIPLE>
1.1 y 0x000068da in fork at init/main.c:25
1.2 y 0x00006a29 in fork at init/main.c:25
1.3 y 0x00006ae0 in fork at init/main.c:25
Breakpoint 1, fork () at init/main.c:25
25 static inline _syscall0(int,fork)
0x000068df 25 static inline _syscall0(int,fork)
=> 0x68df <main+362>: int $0x80
0x68e1 <main+364>: mov %eax,-0xc(%ebp)
0x68e4 <main+367>: cmpl $0x0,-0xc(%ebp)
0x68e8 <main+371>: js 0x68ef <main+378>
0x68ea <main+373>: mov -0xc(%ebp),%eax
cs 0xf 15
ss 0x17 23
esp 0x29f10 0x29f10 <user_stack+4048>
--------------
eip 0x68df 0x68df <main+362>
cs 0xf 15
eflags 0x202 [ IOPL=0 IF ]
esp 0x29f10 0x29f10 <user_stack+4048>
ss 0x17 23
0x00007979 in system_call ()
--------------
cs 0x8 8
ss 0x10 16
esp 0x2420c 0x2420c <init_task+4076>
$1 = {a = 0x29f40 <hash_table>, b = 16}
0x2420c <init_task+4076>: 0xe1 0x68 0x00 0x00 0x0f 0x00 0x00 0x00
0x24214 <init_task+4084>: 0x02 0x02 0x00 0x00 0x10 0x9f 0x02 0x00
0x2421c <init_task+4092>: 0x17 0x00 0x00 0x00
Breakpoint 2 at 0x79ef
Breakpoint 2, 0x000079ef in ret_from_sys_call ()
=> 0x79ef <ret_from_sys_call+69>: iret
--------------
cs 0x8 8
ss 0x10 16
esp 0x2420c 0x2420c <init_task+4076>
0x2420c <init_task+4076>: 0xe1 0x68 0x00 0x00 0x0f 0x00 0x00 0x00
0x24214 <init_task+4084>: 0x02 0x02 0x00 0x00 0x10 0x9f 0x02 0x00
0x2421c <init_task+4092>: 0x17 0x00 0x00 0x00
0x000068e1 in fork () at init/main.c:25
25 static inline _syscall0(int,fork)
cs 0xf 15
ss 0x17 23
esp 0x29f10 0x29f10 <user_stack+4048>
Detaching from program: /home/mhlee/Work/dev/inf-tech/os/linux0.11_env/Linux-0.11-master/tools/system, process 1
Ending remote debugging.
[Inferior 1 (process 1) detached]