瀏覽代碼

Init simu1

Michael Mächtel 8 年之前
父節點
當前提交
add17a3bca
共有 3 個檔案被更改,包括 84 行新增0 行删除
  1. 3
    0
      files/hw2.txt
  2. 38
    0
      hw2/README.md
  3. 43
    0
      hw2/simu1/QUESTIONS.md

+ 3
- 0
files/hw2.txt 查看文件

@@ -0,0 +1,3 @@
1
+./hw2/README.md
2
+./hw2/simu1/ANSWERS.md
3
+./hw2/simu1/QUESTIONS.md

+ 38
- 0
hw2/README.md 查看文件

@@ -0,0 +1,38 @@
1
+# hw2
2
+
3
+## Tasks
4
+To fullfill **hw2** you have to solve:
5
+
6
+- task1
7
+- task2
8
+- simu1
9
+
10
+Optional are (bonus +1P):
11
+
12
+- task3 (important: Rust idiomatic code please)
13
+
14
+## Files
15
+
16
+You find already files for earch rust task. Please remember to use cargo to create the relevant projects for each task.
17
+
18
+
19
+## ASIDE: `simu1/` dir
20
+
21
+In this homework it's not a simulation homework sitting in `simu1/` but some questions to have fun with buggy c-files. As not to interfer with rust code, questions, c-code and your answers should go into `simu1/`.
22
+
23
+## Pull-Reuest
24
+
25
+Please merge any accepted reviews into your branch. If you are ready with the homework, all tests run, please create a pull request named **hw2**.
26
+
27
+## Gradings
28
+
29
+### hw2
30
+
31
+| Task     | max. Credits | Comment |
32
+| -------- | ------------ | ------- |
33
+| task1    | 2            |         |
34
+| task2    | 1            |         |
35
+| task3    | +1           |         |
36
+| simu1    | 1            |         |
37
+| Deadline | +1           |         |
38
+| =        | 6            |         |

+ 43
- 0
hw2/simu1/QUESTIONS.md 查看文件

@@ -0,0 +1,43 @@
1
+# Questions 14-Memory-API
2
+
3
+## Overview
4
+
5
+In this task, you will gain some familiarity with memory allocation. First, you’ll write some buggy programs (fun!). Then, you’ll use some tools to help you find the bugs you inserted. Then, you will realize how awesome these tools are and use them in the future, thus making yourself more happy and productive.
6
+
7
+The first tool you’ll use is **gdb**, the debugger. There is a lot to learn about this debugger; here we’ll only scratch the surface. Here you can find a [quick reference gdb][]. Also **ddd** is installed on lab workstations.
8
+
9
+The second tool you’ll use is [valgrind][]. This tool helps find memory leaks and other insidious memory problems in your program.
10
+
11
+Please answer the questions, by giving the result and an explanation, why you got the result.  Write your answers in markdown syntax in the new file `ANSWERS.md`. Also checkin your C-Files and one Makefile for all or your C-Files, so that all binaries are build. Do NOT checkin the binaries!
12
+
13
+The installed gcc wraper on you workstations does some optimization to your code examples, which will not show some of the bugs with an "Segmentation fault". We have already disabled this behaviour by setting:
14
+
15
+```text
16
+export hardeningDisable=all
17
+```
18
+
19
+in your labshell bsys environment. So, you don't have to do any further steps to produce unoptimized code with gcc, if you want to.
20
+
21
+If you struggle with your own systems about some strange gcc optimization behaviour, maybe it helps to check for gcc-wrapper variables like these.
22
+
23
+## Questions
24
+
25
+1. First, write a simple program called `null.c` that creates a pointer to an integer, sets it to `NULL`, and then tries to dereference it. Compile this into an executable called **null**. What happens when you run this program?
26
+
27
+2. Next, compile this program with symbol information included (with the `-g` flag). Doing so let’s put more information into the executable, enabling the debugger to access more useful information about variable names and the like. Run the program under the debugger by typing `gdb null` and then, once gdb is running, typing `run`. What does gdb show you?
28
+
29
+3. Finally, use the valgrind tool on this program. We’ll use the memcheck tool that is a part of valgrind to analyze what happens. Run
30
+   this by typing in the following: `valgrind --leak-check=yes ./null`. What happens when you run this? Can you interpret the output from the tool?
31
+
32
+4. Write a simple program that allocates memory using `malloc()` but forgets to free it before exiting. What happens when this program runs? Can you use `gdb` to find any problems with it? How about `valgrind` (again with the `--leak-check=yes` flag)?
33
+
34
+5. Write aprogram that creates an array of integers of size 100 using `malloc()`; then, set `data[100]` to zero. What happens when you run this program? What happens when you run this program using `valgrind`? Is the program correct?
35
+
36
+6. Create a program that allocates an array of integers (as above),frees them, and then tries to print the value of one of the elements of the array. Does the program run? What happens when you use `valgrind` on it?
37
+
38
+7. Now pass a funny value to free (e.g., a pointer in the middle of the array you allocated above). What happens? Do you need tools to find this type of problem?
39
+
40
+
41
+
42
+[valgrind]: http://valgrind.org/downloads/current.html
43
+[quick reference gdb]: https://web.stanford.edu/class/cs107/gdb_refcard.pdf

Loading…
取消
儲存