When examining a program, choose a tool by the evidence you need. file classifies a file from tests of its contents. strings lists printable sequences stored in it. strace observes system calls made during a run. Those views answer different questions and cannot be substituted for one another.
A system call asks the operating system to perform work, such as opening a file. A library call is an operation supplied by a programming library and may use system calls internally. The C source calls fopen; that does not by itself tell you the exact system call a later build will make. GDB is a debugger that can pause a permitted program and inspect its state.
Before you begin
- Recommended first
- An editor that works under pressure, Processes, How to read a script someone else wrote, Where practice is allowed, Compiled and interpreted, Enough C and assembly to follow a compare and a jump
- Estimated time
- 18 min reading, 16 min activity. Setup and optional practice may take longer.
- Where you work
- Read the supplied C/Python source and clearly labeled conceptual models in any current desktop or mobile browser. No compiler, binary execution, debugger, tracer or Ghidra installation is required. Function-only C sources are not standalone programs.
- Without a lab
- Trace the source or model on paper and record the condition, chosen branch and evidence limit. No matched lesson ELF, disassembly, debugger session or Ghidra export is supplied. Historical observations retain their separate context. Reading works without JavaScript. Checking requires JavaScript and a secure context; saving also requires usable storage.
After this lesson you can:
- Read the fopen path and both returns from read-note.c.
- Say what a strings card cannot show about a run.
- Name the GDB commands for a later owned stop at main, and stop before using them.
01Example
Source reading of read-note.c beside a conceptual view card. The views were not captured with file, strings, or strace.
Source calls fopen on note.txt.
If the result is 0, main returns 1.
Otherwise fclose runs and main returns 0.
Conceptual file view: missing. No binary.
Conceptual strings view: missing. The path is in the source. A binary listing was not made.
Conceptual syscall view: missing. fopen is the library call in the source. The system-call name was not recorded.02What each view can hold
Read read-note.c as source evidence. #include <stdio.h> makes standard input/output declarations available. FILE *note declares a variable for a file handle. fopen("note.txt", "r") requests reading a file; the quotes delimit strings, not extra path characters. If the returned pointer is zero, the code returns 1; otherwise it closes the handle and returns 0.
The supplied note.txt is text, but no matched read-note executable is supplied. Therefore there is no actual classifier line, strings listing or syscall trace for this program. The separate strings card is a hand-written model. It cannot establish which branch any run took.
GNU strings normally uses a minimum of four printable characters, with scan coverage depending on its options/configuration. A listed word may be part of an error path or unused data. A real strace would record call names, arguments and results from one run. Neither source text nor a manual sample supplies that observation.
Keep file, strings, and syscall evidence as different views, and read a GDB primer without starting a session.Model. A teaching model drawn by hand. It shows the idea, not real tool output.
Read the full explanation below.
Other return
/* Original teaching source. Not compiled. Not traced. */
#include <stdio.h>
int main(void) {
FILE *note;
note = fopen("note.txt", "r");
if (note == 0) {
return 1;
}
fclose(note);
return 0;
}
Syscall trace missing
Source calls fopen on note.txt.
If the result is 0, main returns 1.
Otherwise fclose runs and main returns 0.
Conceptual file view: missing. No binary.
Conceptual strings view: missing. The path is in the source. A binary listing was not made.
Conceptual syscall view: missing. fopen is the library call in the source. The system-call name was not recorded.
fopen asks to read note.txt; zero leads to return 1, otherwise fclose then return 0.
These are source paths, not observed branches.
fopen asks to read note.txt; zero leads to return 1, otherwise fclose then return 0. These are source paths, not observed branches.
Follow the explanation
- fopen asks to read note.txt; zero leads to return 1, otherwise fclose then return 0. These are source paths, not observed branches.
- The matched file, strings and syscall views are missing. Do not convert a source path or library call into captured binary or syscall evidence.
Read every state and value
1. fopen asks to read note.txt; zero leads to return 1, otherwise fclose then return 0. These are source paths, not observed branches.
- Selected parts
- Library read intent · Failed-open condition · Failure return · Close handle · Other return
- Explanation
- intent
2. The matched file, strings and syscall views are missing. Do not convert a source path or library call into captured binary or syscall evidence.
- Selected parts
- Classifier missing · Binary strings missing · Syscall trace missing
- Explanation
- missing
/* Original teaching source. Not compiled. Not traced. */
#include <stdio.h>
int main(void) {
FILE *note;
note = fopen("note.txt", "r");
if (note == 0) {
return 1;
}
fclose(note);
return 0;
}
north desk note
Conceptual views of read-note. Not tool output.
Source view, from read-note.c, which does exist:
The text calls fopen on the path note.txt.
If that call's result is 0, main returns 1.
Otherwise the text calls fclose and main returns 0.
The characters note.txt appear in the source.
File-classifier view:
Missing. No binary is included, so there is no file(1) output to read.
A later line would be a classification of that binary.
This card does not invent one.
Strings view:
Missing. There is no strings(1) output on this card.
The source contains the path note.txt.
Whether those bytes would appear in a binary is unknown until a build exists.
GNU strings prints printable sequences at least 4 characters long by default.
How it was configured can limit it to loadable, initialized data sections.
A printed sequence is not a record of which branch ran.
Syscall view:
Missing. There is no strace output on this card.
The strace manual says each trace line has the system call name, its arguments, and its return value.
The manual's sample line is from cat /dev/null. That sample is not this program.
fopen is a C library call in the source. The system call name, the return value, and any process id are unknown here.
03GDB primer
A breakpoint is a location where a debugger pauses execution. break main requests a stop at main; run starts the selected program; start starts it with a temporary stop at main. next advances to another source line while stepping over called functions, and print evaluates an expression in the current program state. quit leaves the debugger.
The -g compiler flag makes source names, lines and values available for source-level debugging. GDB can also run or inspect a program without that information, though source-level views are limited and instruction-level commands may be needed. Optimization can further change what variables and lines are visible.
The command list below is an unrun primer for a future owned build. No GDB session exists here, so there is no address, paused value or process to report. On GNU/Linux, debugger launch settings can affect address randomization; a later transcript must record the environment rather than assuming addresses match an ordinary run.
GDB primer for a future owned executable. Not a session.
No matched executable is supplied for this activity.
1. Select the owned executable when starting GDB, or through its file command.
2. break main requests a breakpoint at main when that name can be resolved.
3. run starts the selected program. start starts it with a temporary stop at main.
4. next advances to another source line while stepping over called functions.
5. print evaluates an expression using the currently available program state.
6. quit leaves the debugger.
-g requests source-level debugging information. GDB can operate without it, but source names/lines and variables may be unavailable. Optimizations can also affect those views.
The exact binary, source mapping, commands, inputs and environment must accompany a future transcript. Addresses vary; GNU/Linux launch settings can affect address randomization.
Stop before starting GDB here. No breakpoint, address, value or process was observed.
- Read the six command names. Write the job of break, run, and start in your notes.
- Check: break sets a breakpoint, run starts the program, and start stops at the beginning of main.
- Write the limit: no executable exists, so these commands are not run on this page.
- Stop before any gdb command. Do not attach to a process.
04Read the strings card
The desk-note card is a different object from read-note.c. It is an author's list standing in for a strings listing. The binary this card names is not one you need to build.
Conceptual strings card. Not strings(1) output.
The binary this card describes is not one you need to build.
Name on the card: desk-note
Sequences written by the author of the card:
success
denied
note.txt
This list is a teaching stand-in for a strings listing.
It does not show which sequence a run would use.
- List the three sequences on the card.
- Write one sentence that says the card contains both success and denied.
- Check: your sentence names both sequences and does not choose one as the path a run took.
- Stop. Do not build desk-note to settle the question.
05Optional challenge
From the primer, name the command that would stop at the beginning of main, and write the reason this page cannot show the address. About ten minutes.
06Fresh cases for the checks
Use these fictional cases for the checks below. They have different inputs from the worked examples. Read them here or make notes; no installation or external service is needed.
Inspection case A: fresh source, not runOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.
FILE *entry = fopen("ledger.txt", "r");
if (entry == 0) { return 3; }
fclose(entry);
return 0;
This snippet reads a library call; no syscall name or actual return was captured.
Inspection case B: separate authored viewsOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.
Stored-string model for an unrelated owned file includes ledger.txt.
Synthetic syscall-event model: an open request returned a failure.
Neither card is a captured run. No matched binary is supplied.
Inspection case C: later debugger plan onlyOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.
For a separately authorized owned program, plan a stop at main.
GDB commands taught: break main requests a breakpoint; run starts execution.
No debugger is started for this check.
07Explain your evidence
Optional written self-check: explain one decision using the supplied case. No tool run is required.
Check your explanation: cite the exact library-call path and branch; distinguish source, printable bytes and syscall events; label synthetic evidence and missing matched artifacts; describe the debugger sequence without claiming execution.
08Common mistakes
If the strace sample from cat is copied under read-note, the sample was treated as this program. Leave the syscall view blank.
If success on the card is treated as the outcome of every run, the second sequence was skipped. denied is on the same card.
If gdb is started with no owned executable, stop. The primer is a reading. There is no session to quit.
References
- POSIX file(1p): determine file type
Describes classifying a file using tests. No classifier output exists for the missing lesson binary.
- GNU binutils: strings
Defines printable-sequence extraction, default minimum length and scan-coverage options. A listed sequence is not a run.
- strace(1): trace system calls and signals
Describes syscall trace lines, including names, arguments and results. The source fopen call is not a recorded syscall.
- Debugging with GDB: Running Programs Under GDB
Explains running under GDB. Debug information supports source-level views; it is not a prerequisite for all debugger operation.
- Debugging with GDB: Starting your Program
Defines run and start, including program selection and temporary stopping at main.
- Debugging with GDB: Setting Breakpoints
Defines breakpoints and their locations. Manual sample addresses do not belong to these models.
- GCC manual: Options for Debugging Your Program
Explains -g debugger information and how optimization affects source-level views.
- GDB: Continuing and Stepping
Explains source-line stepping, next and instruction stepping when source-level information is unavailable.
- GDB: Examining Data
Defines print as evaluating and displaying the value of an expression in the program's language.