日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > linux >内容正文

linux

Linux 0.11 实验环境搭建与调试

發(fā)布時(shí)間:2025/3/15 linux 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux 0.11 实验环境搭建与调试 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

緣起

之前我寫過(guò)一篇博文:Linux 0.11 實(shí)驗(yàn)環(huán)境搭建

本以為有了這個(gè)環(huán)境(gcc-3.4 & gdb-6.8),就可以調(diào)試無(wú)憂了。誰(shuí)知遇到了以下問(wèn)題:

(1)用 gdb 調(diào)試 main 函數(shù)的時(shí)候,無(wú)法輸出變量的值。總是提示:

No symbol “XXX” in current context.

(2)雖然在編譯時(shí)為 gcc 加上了-gdwarf-2 -g3這兩個(gè)選項(xiàng),但仍然無(wú)法查看宏的定義。

如下圖所示:

對(duì)于(1),因?yàn)橛?g選項(xiàng),所以 gcc 編譯后確實(shí)生成了相關(guān)符號(hào),但為什么 gdb 總說(shuō)找不到符號(hào)呢?因?yàn)?gdb 版本過(guò)低,對(duì)于較高版本的 gcc 產(chǎn)生的符號(hào)表,它根本不認(rèn)識(shí),所以說(shuō)找不到符號(hào)。解決辦法就是升級(jí) gdb.

對(duì)于(2),我本以為原因同(1)。把 gdb 升級(jí)到 8.1 還是不行,看來(lái)另有原因。

我寫了一個(gè)小程序,gcc-5.4.0 配合 gdb-8.1,調(diào)試時(shí)可以打印宏的值,info macro xxx等命令沒(méi)有問(wèn)題。所以,我打算用高版本的 gcc 編譯 Linux-0.11.

問(wèn)題來(lái)了,Linux-0.11 已經(jīng)是很古老的代碼了,用高版本的 gcc 根本編譯不過(guò),怎么辦呢?好在有很多前輩勇于探索,修改了源碼和 Makefile,使得 Linux-0.11 可以被高版本的 gcc 編譯通過(guò)。

環(huán)境搭建

他山之石,可以攻玉。搜了一波后,發(fā)現(xiàn)了一個(gè)叫“泰曉科技”的網(wǎng)站,其官網(wǎng)是http://tinylab.org/,官方代碼倉(cāng)庫(kù)是 https://github.com/tinyclub

代碼倉(cāng)庫(kù)里面有個(gè)項(xiàng)目——Linux 0.11 Lab

下載源碼

得到linux-0.11-lab-master.zip文件,解壓后進(jìn)入目錄linux-0.11-lab-master,如下圖:

用make help命令可以查看幫助信息。

—– Linux 0.11 Lab (http://tinylab.org/linux-0.11-lab) —–
:: Compile ::
make –generate a kernel floppy Image with a fs on hda1
make clean – clean the object files
make distclean – only keep the source code files
:: Test ::
make start – start the kernel in vm (qemu/bochs)
make start-fd – start the kernel with fs in floppy
make start-hd – start the kernel with fs in hard disk
make start-hd G=0 – start with curses based terminal, instead of SDL
:: Debug ::
make debug – debug the kernel in qemu/bochs & gdb at port 1234
make debug-fd – debug the kernel with fs in floppy
make debug-hd – debug the kernel with fs in hard disk
make debug DST=boot/bootsect.sym – debug bootsect
make debug DST=boot/setup.sym – debug setup
make boot BOCHS=bochs-debugger VM=bochs – debug with bochs internal debugger
make switch – switch the emulator: qemu and bochs
make boot VM=qemu|bochs – switch the emulator: qemu and bochs
:: Read ::
make cscope – genereate the cscope index databases
make tags – generate the tag file
make cg – generate callgraph of the default main entry
make cg f=func d=dir|file b=browser – generate callgraph of func in file/directory
:: More ::
>>> README.md <<<
~ Enjoy It ~
—–Linux 0.11 Lab (http://tinylab.org/linux-0.11-lab)—–
—> Linux Kernel Lab (http://tinylab.org/linux-lab) <—

安裝一些軟件

這里以 Linux Ubuntu 操作系統(tǒng)為例。作者推薦用 docker.

The docker install method is recommended for all systems, including Linux, Windows and Mac OS.

不過(guò)我沒(méi)有用 docker,還是用比較原始的辦法。

Here is the deprecated method:

  • The Linux distributions: debian and ubuntu (>= 14.04) are recommended

  • Install basic tools

    $ sudo apt-get install vim cscope exuberant-ctags build-essential qemu lxterminal
  • Optional

    $ sudo apt-get install bochs vgabios bochsbios bochs-doc bochs-x >libltdl7 bochs-sdl bochs-term $ sudo apt-get install graphviz cflow
  • 編譯

    在linux-0.11-lab-master目錄下,運(yùn)行make命令.

    運(yùn)行

    $ make start

    采用 qemu 或者 bochs 模擬器運(yùn)行 Linux-0.11,如果想切換模擬器,可以用

    $ make switch

    調(diào)試

    $ make debug

    運(yùn)行后出現(xiàn)如下界面:

    再開一個(gè)終端,還是在linux-0.11-lab-master目錄下,運(yùn)行命令

    $ gdb --quiet src/kernel.sym

    這時(shí)候,就可以用 gdb 的各種命令進(jìn)行調(diào)試了。

    如何查看宏

    正如 GDB 官網(wǎng)上說(shuō):

    We pass the -gdwarf-2 and-g3 flags to ensure the compiler includes information about preprocessor macros in the debugging information.

    所以,先要給 gcc 添加 -gdwarf-2 和-g3 選項(xiàng)。對(duì)于本實(shí)驗(yàn)環(huán)境,就是修改src 目錄下的 Makefile.head 文件。為第 29 行的CFLAGS加上 -gdwarf-2 -g3 。

    如圖:

    之后重新編譯,再次調(diào)試。

    在調(diào)試的時(shí)候,可以用p(print)命令查看宏的值,還可以用

    info macro 宏名

    例如:

    【參考資料】

    https://sourceware.org/gdb/onlinedocs/gdb/Macros.html

    https://github.com/tinyclub/linux-0.11-lab/blob/master/README.md

    總結(jié)

    以上是生活随笔為你收集整理的Linux 0.11 实验环境搭建与调试的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。