# 安装 libsdl2-dev 出现下面的提示, 那么可知依赖的 systemd 版本低了, 先升级 systemd, 再安装 The following packages have unmet dependencies: udev : Breaks: systemd (< 233-4) Breaks: systemd:i386 (< 233-4) E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
" 如下的基本选项, 因为后续开发使用需要, 建议一次配齐点 set showmatch " Show matching brackets. set ignorecase " Do case insensitive matching set smartcase " Do smart case matching set incsearch " Incremental search set hidden " Hide buffers when they are abandoned set number setlocal noswapfile set hlsearch set smartindent set expandtab set softtabstop=4
" 可选项 set mouse=a set t_Co=256 set wrap set linebreak
man gcc # 我们可看到简介, gcc 通常做预处理, 编译, 汇编, 链接的工作 it normally does preprocessing, compilation, assembly and linking # 1. 预处理, 简单理解就是把源文件展开/处理成完整文件 -E Stop after the preprocessing stage; do not run the compiler proper. The output is in the form of preprocessed source code, which is sent to the standard output. gcc -E test.c # 根据说明, 预处理的内容直接会到标准输出, -o 就可以指定为文件, 思考为何需要以 ".i" 结尾呢? file test.i # C source, ASCII text
# 2. 编译, 把源码转成汇编代码, 注意最后一句话 -S Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each non-assembler input file specified. By default, the assembler file name for a source file is made by replacing the suffix ".c .i" ... with ".s"
gcc -S test.i
# 3. 汇编. 把汇编代码转成机器码 -c Compile or assemble the source files, but do not link. The linking stage simply is not done. The ultimate output is in the form of an object file for each source file.By default, the object file name for a source file is made by replacing the suffix ".c .i .s",etc with ".o"
gcc -c test.s # 默认生成为 .o 后缀 file test.o # ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
# 4. 链接. 机器码转为可执行文件 (静态链接先略) -o file Place output in file file. This applies to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.
If -o is not specified, the default is to put an executable file in a.out, the object file for source.suffix in source.o, its assembler file in source.s, a precompiled header file in source.suffix.gch, and all preprocessed C source on standard output
gcc test.o -o test# 不带 -o 也可, 根据规则生成 a.out
# 仔细观察一下 file 的输出, 对比一下与 test.o 时候区别 (默认动态链接) file test# ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, # interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0,BuildID[sha1]=xxxHash, not stripped
# 从文档里可以得知 -g 的作用类似于把源码嵌入可执行文件中, 也相当于提供调试 flag -g Produce debugging information in the OS's native format (stabs, COFF, XCOFF, or DWARF). GDB can work with this debugging information. On most systems that use stabs format, -g enables use of extra debugging information that only GDB can use; this extra information makes debugging work better in GDB but probably makes other debuggers crash or refuse to read the program. If you want to control for certain whether to generate the extra information, use -gstabs+, -gstabs, -gxcoff+, -gxcoff, or -gvms (see below). gdb test # 进入 gdb 交互界面, 先尝试随便设个断点 (行号是多少?) (gdb) break 7 No line 7 in the current file. Make breakpoint pending on future shared library load? (y or [n]) n (gdb) break 4 Breakpoint 1 at 0x63e: file test.c, line 4.
列一下 gdb 里常用的命令:
l: 显示源码
break lineNum: 添加断点
run: debug 运行
n(next): 断点下一步
如果初从 IDE 的智能图形化切换过来, 感到巨大压力和不解, 想改善一下使用体验, 可看看韦神的调教 gdb 文章, 但是不建议新手食用. 另外补充老师强力推荐的 mit 计算机缺失一环
vi ~/.tmux.conf # 加入下面几行保存 bind-key c new-window -c "#{pane_current_path}" bind-key % split-window -h -c "#{pane_current_path}" bind-key '"' split-window -c "#{pane_current_path}"
# 简单上手 tmux, 先 man 一下 (然后看看 ryf 即可) tmux # 进入 tmux 模式 tmux new -s test # 提示如下啥意思呢? sessions should be nested with care, unset$TMUX to force # unset TMUX
tmux detach # 离开当前tmux window, 但是session 内进程仍运行 tmux ls
# tmux 最简4步使用 (推荐) 1. tmux new -s test (crate a new session) 2. run some programs (like "ping github.com") 3. Ctrl+b d (detach the session, keep run bg) 4. tmux attach-session -t test (next time,reattach it, ping still runs)
# 补充开启滚动条 (重要) ctrl+b : #进入 cmd 模式输入 set -g mouse on
make run # nemu 运行后 [src/monitor/monitor.c:17 welcome] Build time: 11:00:51, Jan 10 2022 Welcome to riscv32-NEMU! For help, type"help" [src/monitor/monitor.c:20 welcome] Exercise: Please remove me in the source code and compile NEMU again. riscv32-nemu-interpreter: src/monitor/monitor.c:21: welcome: Assertion `0' failed. /home/disk3/test/os/ics2021/nemu/scripts/native.mk:22: recipe for target 'run' failed make: *** [run] Aborted (core dumped # 注释断言后, 重新编译运行, 交互界面 help (nemu) c [src/cpu/cpu-exec.c:119 cpu_exec] nemu: HIT GOOD TRAP at pc = 0x8000000c [src/cpu/cpu-exec.c:48 statistic] host time spent = 107 us [src/cpu/cpu-exec.c:49 statistic] total guest instructions = 4 [src/cpu/cpu-exec.c:50 statistic] simulation frequency = 37,383 instr/s # 调试模式要注意这是项目了 make gdb