Debugging Flashcards

1
Q

What is the problem with printf for debugging

A
  • Lots of work
  • output is buffered
  • trave statements mess up output
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you use lldb(mac) or gdb(linux)?

A

Compiling:

clang -g -O0

Then run the executable in the debugger:

lldb a.out

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

What are the basic lldb commands?

A
  • r - run
  • b 18 - breakpoint set
  • s - step - stepping in to functions
  • n - next: stepping over function calls
  • c - continue execution
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why use a a Makefile?

A

Single-file programs do not work well when code gets large

  • compilation can be slow
  • hard to collaborate between multiple programmers
  • cumbersome to edit

Large programs are split into multiple files:

  • each file represents a partial program or module
  • modules can be compiled separately or together
  • modules can be shared between multiple programs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are bad ways to compile programs with modules?

A
  • Includning .c files
  • multifile compilation (.c and .o files)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you work around having similar variables or function names when compiling multiple files

A
  • static is the preferred method(like private in Java)
  • use static for functions you odnt want exposed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How is static used for variables/functions and inside functions

A

static used on variable or function makes it not visible or accessable by other files.

Inside a function makes the variable maintain it’s value and doesn’t reset after function calls

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

What is make?

A

A utility for automatically compiling executables and libraries from source code

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

What is makefile?

A
  • a script file that defines rules for what must be compiled and how to compile it
  • compare file modification dates and to rebuild any file A dependant on another file B that has changed more recently than A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the makefile rule/syntax

A
  1. Command line but be indented by a single tab(spaces don’t work)
  2. make target - uses the file named Makefile in the current dir
  3. find rules for Makefile for building target
    • if the file needs to be updated, it is
  4. alt
    1. make (builds first target in Makefile
    2. make -f makefilename, make -f makefilename target
      • uses a filename other than Makefile
  5. clean:
    • rm file1.o file2.0 file3.0 myprog
    • is convention for removing all compiled files(but not source or header files)
  6. all: myprog myprog2
    • has no commands but depends on myprog and myprog2
    • make all ensures that myprog, myprog2 are up to date
    • all rule often put first, so that typing make will build everything
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do makefile variables work?

A

define a variable:

NAME = value

$(NAME)

OBJFILES = file.0 file2.0 file3.0

PROGRAM = myprog

$(PROGRAM): $(OBJFILES)

clang -g -Wall -o $(PROGRAM) $(OBJFILES)

clean:

rm $(OBJFILES) $(PROGRAM)

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

How do you tell a makefile where your header files are located?

A

clang -I ./include

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

What are the common causes of errors during linking?

A
  • missspellings
  • missing files
  • missing libraries
How well did you know this?
1
Not at all
2
3
4
5
Perfectly