zoukankan      html  css  js  c++  java
  • 构建调试Linux内核网络代码的环境MenuOS系统

    1.下载内核

    mkdir linux_kernel_5.0.1  #建立目录文件
    cd linux_kernel_5.0.1
    wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.0.1.tar.xz #下载linux-5.0.1内核压缩包
    xz -d linux-5.0.1.tar.xz
    tar -xvf linux-5.0.1.tar #解压
    cd linux-5.0.1
    

    2.安装内核编译工具

    sudo apt install build-essential flex bison libssl-dev libelf-dev libncurses-dev
    

    3.配置编译内核

    make x86_64_defconfig #生成64位配置文件
    make menuconfig #开启文本菜单选项,对窗口有限制,尽量调大窗口,不然会报如下错误
    
    • 运行此命令时出现如下error,提示窗口太小
    Your display is too small to run Menuconfig!
    It must be at least 19 lines by 80 columns.
    make[1]: *** [menuconfig] Error 1
    make: *** [menuconfig] Error 2
    
    • 我的ubuntu在虚拟机上,不能全屏显示,用这两条命令解决
    sudo apt-get install open-vm-tools
    sudo apt-get install open-vm*
    
    • 再配置带调试内核
    make menuconfig
    #配置参数,回车选择进入,按y在前面加*选择此项,连续esc退出
    #Kernel hacking -> Compile-time checks and compiler options -> [*] Compile the kernel with debug info
    make #编译,时间较长
    
    • 选择Compile the kernel with debug info

    • 编译完成

    4.安装qemu并启动内核

    sudo apt install qemu #安装qemu命令
    cd linux_kernel_5.0.1#进入目录
    git clone https://github.com/mengning/menu.git
    mkdir rootfs
    cd menu
    sudo apt-get install libc6-dev-i386 #在64位环境下编译32位程序需安装
    vim Makefile #将Makefile中"qemu..."那一行进行对应修改,把版本号更改为5.0.1即可,如下
    #qemu -kernel ../linux-5.0.1/arch/x86/boot/bzImage -initrd ../rootfs.img 
    make rootfs
    

    出现

    fatal error: bits/libc-header-start.h: No such file or directory
    

    用下列命令完善环境

    sudo apt-get install gcc-multilib
    
    • 将qemu行的3.8.16改为5.0.1

    • make rootfs出现错误

    • sudo apt-get install gcc-multilib 解决

    • make rootfs 出现下图表示成功

    5.gdb调试

    qemu -kernel ../linux-5.0.1/arch/x86/boot/bzImage -initrd ../rootfs.img -append  nokaslr -s -S #在qemu中启动gdb server
    #可以看到新打开的qemu虚拟机显示黑屏,此时它正在等待gdb的链接
    gdb #在另外一个终端运行gdb
    file linux-5.0.1/vmlinux #加载符号表
    break start_kernel #在start_kernel处设置断点
    target remote:1234 #建立gdb与gdbserver之间的连接
    c
    list #显示断点处相关源代码
    
    • 启动gdb server

    • 终端运行gdb,加载符号表,设置断点

    • 执行断点,查看信息

    6.测试MenuOS网络

    cd linux_kernel_5.0.1
    git clone https://github.com/mengning/linuxnet.git
    cd linuxnet/lab2 #打开TCP网络通信server端程序目录
    make
    cd ../../menu/
    make rootfs
    cd ../linuxnet/lab3 #打开TCP网络通信client端程序目录
    vim Makefile #修改Makefile
    make rootfs
    
    • make rootfs

    • 通过help,用hello/hi测试网络

  • 相关阅读:
    【剧透高亮】最最最完整剧透加剧情详细解析
    iOS十六进制和字符串的相互转换
    Swift函数编程之Map、Filter、Reduce
    Swift中的Masonry第三方库——SnapKit
    swift中第三方网络请求库Alamofire的安装与使用
    针对苹果最新审核要求为应用兼容IPv6
    使用 Fastlane 实现 IOS 持续集成
    Fastlane为iOS带来持续部署
    @OBJC 和 DYNAMIC
    swift基本用法-数组array
  • 原文地址:https://www.cnblogs.com/yingjiehuang/p/12031741.html
Copyright © 2011-2022 走看看