Inessential Debugging^{∗}

(Revision: 1.1 )

BLEED ON ME

The Student Information Processing Board

Gregory S. Stark

July 26, 1994

∗Copyright \begin{matrix}c \\ ◯ \end{matrix} 1993 Student Information Processing Board of the Massachusetts Institute of Technology

Contents

1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 Debugging Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

2.1 The Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2.2 Multi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2.3 Codecentre . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2.4 lint? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

List of Figures

ii

Inessential LaTEX

1 Introduction

This is not intended to be a guide of how to program. This is intended a guide to some of the debugging tools available on Athena and to some of the basic techniques good programmers use to avoid and eliminate bugs. BLOOD

2 Debugging Tools

2.1 The Compiler

That’s right, the compiler is the first debugging tool. After all few other programs will everknow as much about your program as it does, you may as well get it on your side.

Compilers print messages whenever there’s a parse error, or other compile-time error, but many errors, even typos, can still be legal code, especially with C. Most compilers, can optionally detect many such situations and still print messages called “warnings”. Turning on such warnings is what I meant by getting the compiler on your side. Enabling warnings is like asking for the compiler to do a lot of the debugging work for you.

To turn on a generous set of warnings with “gcc” ^{1} use the “-Wall” option.

Also to use a debugger later you’ll need to use the “-g” option. Even if you don’t know how to use a debugger there’s no reason not to use it. BLOOD

BLOOD I don’t know anything about dbx or any other debuggers. If the following is completely wrong for them then they shold either be each separate subsections or maybe subsubsections.

Debuggers let you watch your program run, stop them at specific points, look at variables, etc. To run gdb or dbx on a program, say a.out, type:

                                athena% gdb a.out

or if you have a core dump file from a previous run:

                              athena% gdb a.out core

The following commands are a basic set of useful debugging commands:

BLOOD

2.2 Multi

2.3 Codecentre

2.4 lint?

MIT SIPB  1  Revision: 1.1

1Gcc is the gnu compiler and is strongly recommended. Gcc is better than most other C compilers and means you’ll only have to learn one set of cryptic error and warning messages