Notes
main
main
  • Introduction
  • linuxKernel
    • tips
    • make_help
    • old linux
      • compile_linux0.11
      • TestEnvironment
      • load_setup
      • get_hard_data
    • list
    • plist
    • fifo
    • idr
    • xarray
    • rbtree
    • maple_tree
    • syscall
    • bitmap
    • page
    • page_flags
    • page_size
    • page mapcount
    • page refcount
    • folio
    • slub
      • proc_slabinfo
      • slub_theory
      • kmalloc_kfree
      • kmem_cache
      • slab_alloc
      • slab_free
      • proc_meminfo_SReclaimable_SReclaimable
    • vmalloc
    • brk
    • mmap
    • mremap
    • mprotect
    • madvise
    • read
    • write
    • shmem
    • huge_page
    • page_fault
    • rmap
    • lru
    • multi-gen-LRU
    • page_reclaim
    • page_cache
    • page_table
    • rcu
    • kvm
    • aarch64_boot
    • tracing_system
    • cache_coherence_and_memory_consistency
    • cpu_speculates
    • mmap_lock
    • per-vma_lock
    • cgroup
    • symbol
    • campact
    • page_ext
    • mempool
    • kernelstack
    • filesystem
    • io_stack
    • workingset
    • ioremap
    • sched_period
  • linuxDebug
    • openocd_openjtag
    • i2c_tools
    • objdump
    • addr2line
    • gdb_useage
    • debug_linux_kernel_via_gdb
    • debug_linux_module_via_gdb
    • early_boot
    • sequentially_execute
    • dynamic_debug
    • research_linuxKernel_by_patch
    • tracefs
    • ebpf
    • bpftrace
    • perf
    • flame_graph
    • crash
    • ASAN_HWASAN_MTE_check_mem_bug
    • page_owner
    • vmtouch
    • fio
    • benchmark
  • linuxSystem
    • common
      • system_version
      • procfs
      • proc_sys_vm
      • cmd_ps
      • makefile
      • file_descriptor
      • psi
      • ulimit
      • top
      • delay_accounting
    • ubuntu
      • custom_kernel
      • get_cmd_src
      • record_ssh_info
      • log
      • run_custom_script
      • repo
      • cockpit
      • nfs
      • tftp
      • misc
    • fedora
      • system_upgrade
      • custom_kernel
      • lvextend
      • yt-dlp
      • jellyfin
  • linuxDriver
    • i2c_peripherals_driver
    • spi_peripherals_driver
    • gpio_subsystem
    • IRQ_driver
    • blockIO_unblockIO_async
    • linux_own_driver
    • misc_device
    • input_device
    • timer
    • atomic_spinlock_semaphore_mutex
    • lcd
    • touch_screen
    • debugfs
    • v4l2
    • mmap
  • hardware
    • paging_mmu_pt
    • iommu
  • process_thread_scheduler
    • scheduler01
    • scheduler02
    • scheduler03
    • scheduler04
    • scheduler05
    • scheduler06
  • memory_management
    • mm1
    • mm2
    • mm3
    • mm4
    • mm5
  • input_output_filesystem
    • io_fs_01
    • io_fs_02
    • io_fs_03
    • io_fs_04
  • lock_and_lockup_detector
    • general_lock
    • hung_task
    • softLockup_hardLockup
    • crash_experiment
  • MIT_6.S081
    • 6.S081_Operating_System_Engineering
    • Schedule.md
    • Class
      • Overview
      • Administrivia
    • Labs
      • Tools
      • Guidance
      • startup
      • syscall
      • page_table
      • Calling_Convention
      • traps
    • xv6
      • xv6
    • References.md
  • qemu
    • qemu_buildroot
    • qemu_busybox.md
    • Serial.md
    • demo_mini2440
      • 0_compilation_error_summary
      • 1_compilation_steps
      • 2_operation_mode
      • 3_transplant_tools_libraries
      • 4_tools_use
      • reference_website
  • tools
    • getKernelSourceCodeList
    • nat
    • shell
    • translating
    • YouCompleteMe
    • cscope
    • global
    • vscode
    • vim
    • binary
    • markdown
    • draw
    • git
    • tig
    • tmux
    • mail_client
    • download_patchset_from_LKML
    • minicom
    • clash
  • other
    • interview
    • interview_c_base
    • know_dontknow
    • Stop-Ask-Questions-The-Stupid-Ways
    • How-To-Ask-Questions-The-Smart-Way
    • docker
    • buildroot
    • rv32_to_rv64
Powered by GitBook
On this page
  • 作业难度
  • 调试技巧

Was this helpful?

  1. MIT_6.S081
  2. Labs

Guidance

PreviousToolsNextstartup

Last updated 3 years ago

Was this helpful?

作业难度

每一个作业都指示它的难度:

  • 容易:小于1小时。这些实验是以后面练习提供的经典热身练习

  • 中等:1~2小时

  • 困难:多于2小时。通常这些练习不要求写很多代码,但是这些代码很难完全正确

这些时间是对我们粗略的估计。对于一些可选的任务,我们没有进行估计,这是一个疯狂的猜测。如果您发现自己在一项任务上花费的时间比我们预期的要多,请联系我们

一般练习不要求写很多行代码(十行至几百行),但代码在概念上是很复杂,而且细节往往很重要。因此,在编写任何代码之前,请阅读实验指定的相关文件,查阅文档。只有当你充分理解任务和解决方案时,才开始编码。以小步骤实施解决方案(通常作业是建议将大问题拆分成较小问题)并在继续下一个步骤之前测试每个步骤是否有效。

调试技巧

这是一些调试解决方案的技巧

  • 确保理解C与指针, Kernighan and Ritchie编写"The C programming language (second edition)" 是简明描述C。这里有一些有用的,除非你已纪彻底掌握c,否则不要跳过上面指针的练习。如果你没有真正理解C语言的指针,在实验中你将遭受无穷的痛苦,然后最终通过艰难路程才能理解。相信我们,如果你不想要走此艰难路程

    一些指针常用的风格,推荐记住:

    • 如果int *p = (int*)100,则 (int)p + 1 和 (int)(p + 1) 是不同的:第一个是 101,但是第二个是 104。当一个指针加上一个整数,如第二种情况,整数 乘以 指针指向的对象的大小

    • p[i] 与*(p+i)是相同的,指p指向的内存中的第i个对象

    • &p[i]与(p+i)是相同的,指p指向的内存中第i个对象的地址

    尽管大多数 C 程序不需要在指针和整数之间进行转换,但操作系统经常这样做。每当你看到一个涉及内存地址的加法时,问问自已,是整数加法?还是指针加法?并确保执行加法后的值是否有效。

  • 如果你的练习有一部分是正常工作,可以通过提交代码来检查你的进度。如果后面你有新的想法,你能同滚到上一个提交点以更小的步骤来验证。想要学习更多Git操作,看或你能发现的用法

  • 如果你测试失败,先确定测试失败的原因。可以通过插入打印语句,直至理解失败原因。

  • 你可能会发现打印语句产生许多的输出;如果想要搜索,可以在script中运行make qemu,它将控制台所有日志都输出到一个文件中,然后你可以搜索该文件(不要忘记退出script)

  • 在许多情况下,打印语句就足够了,但是有时候单步执行一些汇编代码或检查变量是有用的。想调试 xv6 ,在一个终端中运行 make qemu-gdb,在另一个终端中运行gdb或 riscv64-linux-gnu-gdb,设置一个断点,然后执行c或continue, xv6会运行到断点为止。(有关GDB 用法,参考 )

  • 如果你想要查看通过编译器生成的内核汇编指令,或 查看指定内核地址的指令,可以查看kernel.asm文件,此文件是通过Makefile在编译内核时生成的(Makefile也为所有用户程序生成.asm文件)

  • 如果内核panics,它将打印错误消息,列出crashed时的PC值,你能够在kernel.asm查找PC所在的函数,或者你可以运行addr2line -e kernel/kernel pc-value。如果你想要获得函数回溯,重新启动 gdb :在一个终端中运行make qemu-gdb,在另一个终端中运行gdb或riscv64-linux-gnu-gdb,在panic中设置断点(b panic),然后执行c或continue。当内核到达断点时,执行bt获取函数回溯

  • 如果内核hangs(例如:死锁)或 无法继续执行(例如:执行内核指令时出现page fault),你能够使用gdb找出原因。在一个终端中运行make qemu-gdb,在另一个终端中运行gdb或riscv64-linux-gnu-gdb,然后执行c或continue。当内核hang时,在qemu-gdb终端中按Ctrl-C并执行bt以获取函数回溯。

  • qemu有一个monitor,可以让你查询模拟器的状态,可以通过执行control-a c 来获得(the "c" is for console).。一个特别有用的monitor命令是info mem来打印页表。你可能需要使用cpu命令来选择查看哪一个core的info mem 或者 在启动qemu时,使用make CPUS=1 让其只有一个core。

花时间学习上述工具是非常值得的

指针练习
Git user's manual
CS-oriented overview of Git
GNU 调试器