Lecture 4 - Debugging & Development Tools Flashcards
(36 cards)
Memory stores data, but what else?
Program code and instructions.
Is it possible to have a pointer to a function, if so what is it callled.
yes , function pointer
What is the type of a function pointer?
return_type (*)(argument_types)
When could having a function pointer be useful?
Having different print functions for node of a binary search tree.
Are function names automatically converted to pointers?
YES
What is a syntactical bug?
A grammar bug, it is something picked up by the compiler e.g. mispelling a keyword
What is a semantic bug?
Error in our logic , not flagged by the compiler, but the code doesn’t do what we want it to do .
What is a debugger?
A controlled enviroment in which we can run our program and investigate it’s execution.
What is static analysis?
When we reason about a program’s behaviour without running it.
What is dynamic analysis?
Adding instructions to program in order to be able to detect bugs at runtime.
What are the 2 most popular debuggers for C?
lldb and gdb
How to we need to compile a C program in order to be able to debug it?
With a g flag, this adds debug information to the binary exectuable
After compiling with a g flag do we simply run the program normally to debug ?
No, we start the debugger and load the program executable
EG.
gdb –argc ./program arg1 arg2
lldb – ./program arg1 arg2
How to exit a debugger?
type quit
How to set a breakpoint in the debugger?
b followed by the line number
How to execute the next line in the debugger?
n
What is a seg fault?
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
Common Seg Fault Causes?
- dangling pointers
- dereferencing a NULL pointer
- Writing to read only memory
- Buffer overflow
- stack/heap overflow
What is a dangling pointer?
A pointer that doesn’t point to a valid object of an appropriate type. E.g. deallocated memory
What does the bt command do in the debugger?
Shows the backtrace after an error. This shows program calls leading to error.
Does the compiler do some static analyses every time we compile?
YES
What is good practice when compiling C programs?
enabling -Wall -Werror
How to we invoke the static analyzer
clang –analyze –ana;yzer-output html program.c
- we have a flag
- we have an output format
What is a massive drawback of static analysis?
Quite expensive to perform, not worth to do in every build.