OS

UCB-CS162

HOMEWORK0 小结

Posted by Alen on 2021-06-24
Estimated Reading Time 2 Minutes
Words 553 In Total
Viewed Times

前言:完成了加州伯克利OS课程的第一个Homework hw0,这里做一小结,并给出自己完成的Written Question的答案。(由于162的课程Policy,代码暂不给出)


Test

Principle:

MIT 6.005 Software Construction Testing中给出了构造完备测试输入的方法
choose test cases by partitinoing
1. divide input space into subdomains
2. include boundaries in the partition

增加测试

由于课程提供的test file只有一个,因此,我根据上述方法额外构造了三个测试文件

单行文件
仅含换行的文件
空文件

words

num_words函数

不难实现,注意检查infile为空的情形

count_words函数

注意读入一个word完毕后,末尾添加’\0’后,再add_word
切记补充main函数

word_count.c文件

注意add_word函数中

区分首次和之后add_word的处理。本质上就是空链表首次添加元素和非空链表添加元素的区别
注意为struct word_count动态分配/malloc 内存后,再进行word的copy

gdb调试技巧

直接run一次,再通过backtrace定位bug

Written quetion in section “compiling, assembling and linking”

  1. Generate recurse.S and find which instruction(s) corresponds to the recursive call of recur(i-1).
    Answer:
    movl 8(%ebp), %eax
    subl $1, %eax
    subl $12, %esp
    pushl %eax
    call recur
  1. What do the .text and .data section contain?
    Answer:
    The .text section contains the code, namely instructions in binary format.
    The .data section contains the initialized static and global variables.
  1. What command do we use to view the symbols in an ELF file? (Hint: We can use objdump again,look at “man objdump” to find the right flag).
    Answer:
    objdump –syms [file]
    objdump –syms map.obj
  1. What do the g, O, F, and UND flags mean?
    Answer:
    g: the symbol is global.
    O: The symbol is the name of an object
    F: The symbol is the name of a function
    UND: the symbol is refrenced but not defined in the dumped file
  1. Vaguely describe another location where we can find the symbol for malloc.
    Answer:
    In libc.obj
  1. Where else can we find a symbol for recur? Which file is this in? Copy and paste the relevant portion of the symbol table.
    Answer:
    We can also find a symbol for “recur” in generated file of recurse.c
    It is in recurse.obj.
    00000000 g F .text 00000052 recur
  1. Examine the symbol table of the entire map program now. What has changed?
    Answer:
    The symbol table of map combine the one of map.obj and recurse.obj
    The first column of symbol table is no longer all zero now. In fact, the first line is the virtual address needed when loading.

如有错误,望批评指正!
转载请注明来源,谢谢

Diagram



If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !