Lecture 4 - Debugging & Development Tools Flashcards

1
Q

Memory stores data, but what else?

A

Program code and instructions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Is it possible to have a pointer to a function, if so what is it callled.

A

yes , function pointer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the type of a function pointer?

A

return_type (*)(argument_types)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When could having a function pointer be useful?

A

Having different print functions for node of a binary search tree.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Are function names automatically converted to pointers?

A

YES

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a syntactical bug?

A

A grammar bug, it is something picked up by the compiler e.g. mispelling a keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a semantic bug?

A

Error in our logic , not flagged by the compiler, but the code doesn’t do what we want it to do .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a debugger?

A

A controlled enviroment in which we can run our program and investigate it’s execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is static analysis?

A

When we reason about a program’s behaviour without running it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is dynamic analysis?

A

Adding instructions to program in order to be able to detect bugs at runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the 2 most popular debuggers for C?

A

lldb and gdb

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to we need to compile a C program in order to be able to debug it?

A

With a g flag, this adds debug information to the binary exectuable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

After compiling with a g flag do we simply run the program normally to debug ?

A

No, we start the debugger and load the program executable

EG.
gdb –argc ./program arg1 arg2
lldb – ./program arg1 arg2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to exit a debugger?

A

type quit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to set a breakpoint in the debugger?

A

b followed by the line number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to execute the next line in the debugger?

A

n

17
Q

What is a seg fault?

A

An error raised by the hardware notigying the OS that our program has attempted to access a restricted area of memory
-> os immediately terminates program execution

18
Q

Common Seg Fault Causes?

A
  • dangling pointers
  • dereferencing a NULL pointer
  • Writing to read only memory
  • Buffer overflow
  • stack/heap overflow
19
Q

What is a dangling pointer?

A

A pointer that doesn’t point to a valid object of an appropriate type. E.g. deallocated memory

20
Q

What does the bt command do in the debugger?

A

Shows the backtrace after an error. This shows program calls leading to error.

21
Q

Does the compiler do some static analyses every time we compile?

A

YES

22
Q

What is good practice when compiling C programs?

A

enabling -Wall -Werror

23
Q

How to we invoke the static analyzer

A

clang –analyze –ana;yzer-output html program.c

  • we have a flag
  • we have an output format
24
Q

What is a massive drawback of static analysis?

A

Quite expensive to perform, not worth to do in every build.

25
Q

What does the analyzer report contain?

A

Potential bugs and their explanations

26
Q

What is clang-tidy?

A

It is a linter tool, that allows us to enfodce coding guidelines and modernize source code.

27
Q

How is clang tidy turned on?

A

Including – somewhere in our command

28
Q

What are the 5 most important sanitizers?

A
  • AddressSanitizer
  • MemorySanitizer
  • LeakSanitizer
  • UndefinedBehaviourSanitizer
  • ThreadSanitizer
29
Q

What is the address sanitizer?

A

A memory error detector
-> out of bounds access
-> use after free
-> double free

30
Q

What is a memory sanitizer?

A

a detector of uninitialized reads

31
Q

What is a leak sanitizer?

A

a memory leak detector

32
Q

What is a undefined behaviour sanitizer?

A

detector of undefined behaviour

33
Q

What is a thread sanitizer?

A

a data race detector

34
Q

What is undefined behaviour?

A

These are semantic bugs (fault in our logic). These are due to the fact the compiler doesn’t enforce a certain behaviour (e.g. dereferencing a NULL pointer).

e.g integer overflow

35
Q

Are C and C++ considered safe languages?

A

No

36
Q

What does it mean to be an unsafe language ?

A

executing an erroneous operation causes the entire program to be meaningless, as opposed to just the erroneous operation having an unpredictable result.