站長(zhǎng)資訊網(wǎng)
        最全最豐富的資訊網(wǎng)站

        linux oops是什么意思

        linux oops的意思是指當(dāng)Linux內(nèi)核在發(fā)生“kernel panic”時(shí),打印出的Oops信息,然后會(huì)把目前的寄存器狀態(tài)、堆棧內(nèi)容、以及完整的Call trace都show給我們看,這樣就可以幫助我們定位錯(cuò)誤。

        linux oops是什么意思

        本教程操作環(huán)境:linux5.9.8系統(tǒng)、Dell G3電腦。

        linux oops是什么意思?

        Linux內(nèi)核的Oops介紹

        什么是Oops?從語(yǔ)言學(xué)的角度說(shuō),Oops應(yīng)該是一個(gè)擬聲詞。當(dāng)出了點(diǎn)小事故,或者做了比較尷尬的事之后,你可以說(shuō)"Oops",翻譯成中國(guó)話就叫做“哎呦”。“哎呦,對(duì)不起,對(duì)不起,我真不是故意打碎您的杯子的”。看,Oops就是這個(gè)意思。

        在Linux內(nèi)核開(kāi)發(fā)中的Oops是什么呢?其實(shí),它和上面的解釋也沒(méi)什么本質(zhì)的差別,只不過(guò)說(shuō)話的主角變成了Linux。當(dāng)某些比較致命的問(wèn)題出現(xiàn)時(shí),我們的Linux內(nèi)核也會(huì)抱歉的對(duì)我們說(shuō):“哎呦(Oops),對(duì)不起,我把事情搞砸了”。Linux內(nèi)核在發(fā)生kernel panic時(shí)會(huì)打印出Oops信息,把目前的寄存器狀態(tài)、堆棧內(nèi)容、以及完整的Call trace都show給我們看,這樣就可以幫助我們定位錯(cuò)誤。

        下面,我們來(lái)看一個(gè)實(shí)例。為了突出本文的主角–Oops,這個(gè)例子唯一的作用就是造一個(gè)空指針引用錯(cuò)誤。

        #include <linux/kernel.h> #include <linux/module.h>  static int __init hello_init(void) { 	int *p = 0; 	 	*p = 1;	 	return 0; }  static void __exit hello_exit(void) { 	return; }  module_init(hello_init); module_exit(hello_exit);  MODULE_LICENSE("GPL");
        登錄后復(fù)制

        很明顯,錯(cuò)誤的地方就是第8行。

        接下來(lái),我們把這個(gè)模塊編譯出來(lái),再用insmod來(lái)插入到內(nèi)核空間,正如我們預(yù)期的那樣,Oops出現(xiàn)了。

        [ 100.243737] BUG: unable to handle kernel NULL pointer dereference at (null)

        [ 100.244985] IP: [<f82d2005>] hello_init+0x5/0x11 [hello]

        [ 100.262266] *pde = 00000000

        [ 100.288395] Oops: 0002 [#1] SMP

        [ 100.305468] last sysfs file: /sys/devices/virtual/sound/timer/uevent

        [ 100.325955] Modules linked in: hello(+) vmblock vsock vmmemctl vmhgfs acpiphp snd_ens1371 gameport snd_ac97_codec ac97_bus snd_pcm_oss snd_mixer_oss snd_pcm snd_seq_dummy snd_seq_oss snd_seq_midi snd_rawmidi snd_seq_midi_event snd_seq snd_timer snd_seq_device ppdev psmouse serio_raw fbcon tileblit font bitblit softcursor snd parport_pc soundcore snd_page_alloc vmci i2c_piix4 vga16fb vgastate intel_agp agpgart shpchp lp parport floppy pcnet32 mii mptspi mptscsih mptbase scsi_transport_spi vmxnet

        [ 100.472178] [ 100.494931] Pid: 1586, comm: insmod Not tainted (2.6.32-21-generic #32-Ubuntu) VMware Virtual Platform

        [ 100.540018] EIP: 0060:[<f82d2005>] EFLAGS: 00010246 CPU: 0

        [ 100.562844] EIP is at hello_init+0x5/0x11 [hello]

        [ 100.584351] EAX: 00000000 EBX: fffffffc ECX: f82cf040 EDX: 00000001

        [ 100.609358] ESI: f82cf040 EDI: 00000000 EBP: f1b9ff5c ESP: f1b9ff5c

        [ 100.631467] DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068

        [ 100.657664] Process insmod (pid: 1586, ti=f1b9e000 task=f137b340 task.ti=f1b9e000)

        [ 100.706083] Stack:

        [ 100.731783] f1b9ff88 c0101131 f82cf040 c076d240 fffffffc f82cf040 0072cff4 f82d2000

        [ 100.759324] <0> fffffffc f82cf040 0072cff4 f1b9ffac c0182340 f19638f8 f137b340 f19638c0

        [ 100.811396] <0> 00000004 09cc9018 09cc9018 00020000 f1b9e000 c01033ec 09cc9018 00015324

        [ 100.891922] Call Trace:

        [ 100.916257] [<c0101131>] ? do_one_initcall+0x31/0x190

        [ 100.943670] [<f82d2000>] ? hello_init+0x0/0x11 [hello]

        [ 100.970905] [<c0182340>] ? sys_init_module+0xb0/0x210

        [ 100.995542] [<c01033ec>] ? syscall_call+0x7/0xb

        [ 101.024087] Code: <c7> 05 00 00 00 00 01 00 00 00 5d c3 00 00 00 00 00 00 00 00 00 00

        [ 101.079592] EIP: [<f82d2005>] hello_init+0x5/0x11 [hello] SS:ESP 0068:f1b9ff5c

        [ 101.134682] CR2: 0000000000000000

        [ 101.158929] —[ end trace e294b69a66d752cb ]—

        Oops首先描述了這是一個(gè)什么樣的bug,然后指出了發(fā)生bug的位置,即“IP: [<f82d2005>] hello_init+0x5/0x11 [hello]”。

        在這里,我們需要用到一個(gè)輔助工具objdump來(lái)幫助分析問(wèn)題。objdump可以用來(lái)反匯編,命令格式如下:

        objdump -S hello.o

        下面是hello.o反匯編的結(jié)果,而且是和C代碼混排的,非常的直觀。

        hello.o:     file format elf32-i386   Disassembly of section .init.text:  00000000 <init_module>: #include <linux/kernel.h> #include <linux/module.h>  static int __init hello_init(void) {    0:	55                   	push   %ebp 	int *p = 0; 	 	*p = 1; 	 	return 0; }    1:	31 c0                	xor    %eax,%eax #include <linux/kernel.h> #include <linux/module.h>  static int __init hello_init(void) {    3:	89 e5                	mov    %esp,%ebp 	int *p = 0; 	 	*p = 1;    5:	c7 05 00 00 00 00 01 	movl   $0x1,0x0    c:	00 00 00  	 	return 0; }    f:	5d                   	pop    %ebp   10:	c3                   	ret      Disassembly of section .exit.text:  00000000 <cleanup_module>:  static void __exit hello_exit(void) {    0:	55                   	push   %ebp    1:	89 e5                	mov    %esp,%ebp    3:	e8 fc ff ff ff       	call   4 <cleanup_module+0x4> 	return; }    8:	5d                   	pop    %ebp    9:	c3                   	ret
        登錄后復(fù)制

        對(duì)照Oops的提示,我們可以很清楚的看到,出錯(cuò)的位置hello_init+0x5的匯編代碼是:

        5:c7 05 00 00 00 00 01 movl   $0x1,0x0
        登錄后復(fù)制

        這句代碼的作用是把數(shù)值1存入0這個(gè)地址,這個(gè)操作當(dāng)然是非法的。

        我們還能看到它對(duì)應(yīng)的c代碼是:

        *p = 1;
        登錄后復(fù)制

        Bingo!在Oops的幫助下我們很快就解決了問(wèn)題。

        我們?cè)倩剡^(guò)頭來(lái)檢查一下上面的Oops,看看Linux內(nèi)核還有沒(méi)有給我們留下其他的有用信息。

        Oops: 0002 [#1]

        這里面,0002表示Oops的錯(cuò)誤代碼(寫(xiě)錯(cuò)誤,發(fā)生在內(nèi)核空間),#1表示這個(gè)錯(cuò)誤發(fā)生一次。

        Oops的錯(cuò)誤代碼根據(jù)錯(cuò)誤的原因會(huì)有不同的定義,本文中的例子可以參考下面的定義(如果發(fā)現(xiàn)自己遇到的Oops和下面無(wú)法對(duì)應(yīng)的話,最好去內(nèi)核代碼里查找):

        * error_code:
        * bit 0 == 0 means no page found, 1 means protection fault
        * bit 1 == 0 means read, 1 means write
        * bit 2 == 0 means kernel, 1 means user-mode
        * bit 3 == 0 means data, 1 means instruction

        有時(shí)候,Oops還會(huì)打印出Tainted信息。這個(gè)信息用來(lái)指出內(nèi)核是因何種原因被tainted(直譯為“玷污”)。具體的定義如下:

        1: 'G' if all modules loaded have a GPL or compatible license, 'P' if any proprietary module has been loaded. Modules without a MODULE_LICENSE or with a MODULE_LICENSE that is not recognised by insmod as GPL compatible are assumed to be proprietary.
        2: 'F' if any module was force loaded by "insmod -f", ' ' if all modules were loaded normally.
        3: 'S' if the oops occurred on an SMP kernel running on hardware that hasn't been certified as safe to run multiprocessor. Currently this occurs only on various Athlons that are not SMP capable.
        4: 'R' if a module was force unloaded by "rmmod -f", ' ' if all modules were unloaded normally.
        5: 'M' if any processor has reported a Machine Check Exception, ' ' if no Machine Check Exceptions have occurred.
        6: 'B' if a page-release function has found a bad page reference or some unexpected page flags.
        7: 'U' if a user or user application specifically requested that the Tainted flag be set, ' ' otherwise.
        8: 'D' if the kernel has died recently, i.e. there was an OOPS or BUG.
        9: 'A' if the ACPI table has been overridden.
        10: 'W' if a warning has previously been issued by the kernel. (Though some warnings may set more specific taint flags.)
        11: 'C' if a staging driver has been loaded.
        12: 'I' if the kernel is working around a severe bug in the platform firmware (BIOS or similar).

        基本上,這個(gè)Tainted信息是留給內(nèi)核開(kāi)發(fā)者看的。用戶在使用Linux的過(guò)程中如果遇到Oops,可以把Oops的內(nèi)容發(fā)送給內(nèi)核開(kāi)發(fā)者去debug,內(nèi)核開(kāi)發(fā)者根據(jù)這個(gè)Tainted信息大概可以判斷出kernel panic時(shí)內(nèi)核運(yùn)行的環(huán)境。如果我們只是debug自己的驅(qū)動(dòng),這個(gè)信息就沒(méi)什么意義了。

        本文的這個(gè)例子非常簡(jiǎn)單,Oops發(fā)生以后沒(méi)有造成宕機(jī),這樣我們就可以從dmesg中查看到完整的信息。但

        贊(0)
        分享到: 更多 (0)
        網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)
        主站蜘蛛池模板: 久久精品亚洲欧美日韩久久| 无码人妻精品中文字幕免费 | 国产精品无码一区二区在线| 久热这里只有精品视频6| 精品国产三级a乌鸦在线观看| 99久久99久久久精品齐齐| 亚洲精品一品区二品区三品区| 国产精品原创巨作?v网站| 青青草原综合久久大伊人精品| 国产精品毛片VA一区二区三区| 午夜精品久久久久久99热| 香港三级精品三级在线专区| 国内精品久久久久久久coent| 91久久精品无码一区二区毛片| 国产精品爽爽va在线观看网站| 人人妻人人澡人人爽精品日本| 亚洲一区精品伊人久久伊人| 久久精品国产只有精品66| 国产免费久久精品丫丫| 亚洲国产精品第一区二区| 国产精品久久波多野结衣| 久久99精品久久久久久久久久| 中文字幕精品无码久久久久久3D日动漫| 精品一区二区三区免费观看| 国产精品伦理久久久久久| 国产福利91精品一区二区| 大伊香蕉精品一区视频在线 | 国产精品白浆在线观看免费| 亚洲AV无码成人精品区在线观看| 亚洲精品一级无码鲁丝片| 少妇亚洲免费精品| 日本精品夜色视频一区二区| 日韩三级精品| 亚洲AⅤ永久无码精品AA| 亚洲精品无码av天堂| 亚洲精品视频免费| 亚洲欧美一级久久精品| 在线精品亚洲一区二区三区| 亚洲欧美国产∧v精品综合网| 偷拍精品视频一区二区三区| 亚洲精品无码成人片在线观看 |