Exam #1 study guide
The exam is Wed, Feb 19 at 8-9pm in PHYS 112. This will be a 1-hour exam. Additional time might be permitted, at the instructor's discretion, if there is a need and the room is available. Seat assignments will be emailed to you sometime before the exam (typically in the afternoon). Before you come, ① check your email, ② use the bathroom, and ③ bring your photo ID.
You are responsible for reading the syllabus, including the section on “Exams”. Information on what is allowed and what we provide is there.
Conflicts. If you have a conflict with the exam 1 time, please send me email with subject “Exam 1 conflict - ECE 264” and your availability on Thu 2/20. Please do that by end of Sun, if possible. You should hear back with a time and place on Mon 2/17.
DRC scheduling. If you will take the exam in the DRC, please schedule it for Thu 2/20. Send me email ASAP with subject “Exam 1 conflict - ECE 264” if that is impossible.
Scope
The scope of exam 1 contains everything we've covered so far, except Vim, including the following:
- lectures up to 2/17 + HW02, HW03, HW04, HW05.
- number representations, address syntax, memory, strings, code quality, GDB, preprocessor, TDD, make, testing
- no Vim
- past exams/quizzes are on the course web site under Resources.
Format
The format of the actual questions will be similar to past exams: mostly short-answer, with the possibility of some circle/cross-out or multiple choice questions. You will not be asked to write long sections of code. However, you might be asked to write expressions or very small segments of code (e.g., a few lines).
Questions about the contents of memory may use this
memory form
or ask you to fill in the output of a GDB p/
or x/
command.
Topics
- Data representations: number bases, ASCII. You should be able to:
- Convert a number from any base to any other base (between 2 and 36). Example: convert 0x3f (hexadecimal) to base 27.
- Understand the relationship between (a) number base used to express numbers in your code, (b) representation in memory with no number base, and (c) number base used to print numbers on the screen.
- Understand the relationship between digit characters (e.g.,
'5'
) and the values they traditionally represent (e.g., the result of two plus three). - Given a single character (e.g.,
'A'
) show how it would look when stored in memory. - Explain why
6 * 8 == '0'
. - Write a
print_integer(…)
function that works with only integers between 0 and 9. - Understand that variables in memory have no base. For example, if you are given code with an
int
variable, and asked what that variable's number base is, the correct answer would be “none” or “n/a”.
You will be given an ASCII table on the exam. - Memory. You should be able to:
- Given a small program, draw the call stack, including the parameters, return address, and local variables. For the return address, it's okay to be vague (e.g., "somewhere in
main(…)
). - Given a small program, say what data is in the stack segment, data segment, and text segment. (We won't ask about the BSS for exam #1.)
- Fill in some missing values in a GDB session. For example, given an
x/…
command examining a string or array, fill in the expected output (to show that you understand what is in memory). - Read and write code that uses memory addresses, arrays, or strings, including any of the syntax in your reference sheet under addresses (pointers), arrays, and strings.
- Describe code using memory addresses in English phrases such as "__ gets the address of __," "__ gets the value at __," and "store __ at address __.".
- Given a flawed initialization (e.g.,
char* ch = 'a';
) fix it by modifying the expression (RHS) to match the type on the LHS. - Given an expression, give its type.
- Use arithmetic operators with memory addresses to find the i'th element of an array.
- Predict the output of a function that receives a memory address as a parameter and uses it to modify local variables of the caller.
- Predict the output of the
sizeof(…)
operator for a given expression (e.g.,sizeof('0')
).
- Given a small program, draw the call stack, including the parameters, return address, and local variables. For the return address, it's okay to be vague (e.g., "somewhere in
- Variadic functions. You should be able to:
- Write simple programs using variadic functions. For example, make a function that takes one or more characters as arguments and prints them as a string.
- What do variadic functions allow you to do, that wouldn't be possible by passing an array to a function?
- What can you do with an array passed to a function that would be more difficult if you used variadic arguments?
- Give an example of a variadic function that you have used before ECE 264.
- GDB. You should know all GDB commands on the reference sheet, and
be able to answer questions about memory, types, and the practice of
debugging in the context of GDB. For example:
- Explain the difference between the value of an expression (e.g., result of
p a_o
) and the data at the address returned by that expression (e.g.,x/4bx a_o
). - Explain what kinds of bugs can be found by stepping through code and inspecting stack frames in a running program. … and what kinds of bugs cannot be found in that manner.
- Give the type of an expression (e.g.,
*(a_o -> b)[2]
) in terms of the output of thewhatis
command (e.g.,whatis *(a_o -> b)[2]
). Such a question is testing your knowledge of types, not GDB. - Explain the conceptual and practical differences between breakpoints and watchpoints. (The concepts of breakpoints and watchpoints are not GDB-specific; most debuggers have them in some form.)
- Suppose you set a breakpoint and a watchpoint at the same line of code. Which will potentially lead to more stops?
- Given a bug scenario, which of the following would be most useful: breakpoints (
break
), watchpoints (watch
, etc.), or stepping through and observing (display
)? - Fill in the blanks of the
info args
andinfo locals
commands. Such a question is testing whether you can distinguish between arguments and local variables. - Write the contents of memory at some address if interpreted as chars (1 byte units), half words (2-byte units), words (4-byte units), or giant words (8-byte units), taking into account the byte order of our little endian platform. This might be phrased like “Fill in the output of
x/4wd a
.” - Given the output of a
x/
command, give the command that produced it. - Commands to know:
Start set args
Breakpoints break
,clear
,delete
,info breakpoints
Watchpoints watch
,awatch
,rwatch
,info watchpoints
Automatic display info display
,display
,undisplay
Explore the stack frame backtrace
,down
,frame
,info args
,info frame
,info locals
,list
,up
,whatis
Controlling execution continue
,finish
,jump
,next
,return
,run
,set variable
,step
,until
Reverse debugging record
,reverse-next
,reverse-step
, and so on…View variables and memory print
,x
, units (b
h
w
g
), formats (d
x
s
f
c
u
o
t
z
a
)
- Explain the difference between the value of an expression (e.g., result of
- Software engineering You should be able to:
- Code quality
- Given some poorly-written code, identify and/or fix the problems relative to the Code Quality Standards used in this class.
- Given a code quality problem, explain what kind of bugs or other problems it could lead to.
- Test-driven development
- Know the basic process described in the HW02 description and in lecture on 1/24/2020.
- Given a planned sequence of steps for constructing a program, find any flaws in the plan.
- Given a description of a program to be built, write out the first few steps, following TDD.
- Explain the benefits of TDD.
- Explain how you used (or could have used) TDD on one of the assignments so far.
- Assertions
- Given a bug scenario, show how an
assert(…)
statement could have revealed the bug sooner. - For what purposes should
assert(…)
not be used. - Given some code with several
assert(…)
statements, cross out the ones that violate the rules forassert(…)
.
- Given a bug scenario, show how an
- Make
- Diagnose an error in a Makefile.
- Given a Makefile and a make command (e.g.,
make debug
) predict what commands will be executed. - Fill in the blanks in a partially written Makefile.
- Explain the advantage of using a Makefile versus directly typing commands in bash.
- Code quality
- Preprocessor You should be able to:
- Explain the three main stages of compiling your source code to an executable (preprocessor, compiler, and linker).
- Explain what a
#define
macro can do that a regular function can't—and vice versa. - Write a
#define
macro to replace a simple function—and vice versa. - Predict the output of the preprocessor on a program including
#define
,#▒▒▒
,#ifdef
,#ifndef
,#else
,#endif
,#include
, and/or__LINE__
. - Fill in the blanks in a partially written .h file that uses the directives above.
- Add a
#include
guard to a given header file.
Not in scope
The following are not in scope for this exam.
- Vim commands
- bash commands—except that questions may assume that you understand the commands to run
gcc
,gdb
, andvalgrind
commands, and your own program, from the command line - heap,
malloc(…)
, structures (not covered yet)
Feel free to ask whether other topics not mentioned here will be "in scope" for the exam.
Updates
2/16/2020 |
|